2019-05-29 21:12:42 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2008-09-17 22:34:06 +07:00
|
|
|
/*
|
|
|
|
* Ultra Wide Band
|
|
|
|
* Driver initialization, etc
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005-2006 Intel Corporation
|
|
|
|
* Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
|
|
|
|
*
|
|
|
|
* FIXME: docs
|
|
|
|
*
|
|
|
|
* Life cycle: FIXME: explain
|
|
|
|
*
|
|
|
|
* UWB radio controller:
|
|
|
|
*
|
|
|
|
* 1. alloc a uwb_rc, zero it
|
|
|
|
* 2. call uwb_rc_init() on it to set it up + ops (won't do any
|
|
|
|
* kind of allocation)
|
|
|
|
* 3. register (now it is owned by the UWB stack--deregister before
|
|
|
|
* freeing/destroying).
|
|
|
|
* 4. It lives on it's own now (UWB stack handles)--when it
|
|
|
|
* disconnects, call unregister()
|
|
|
|
* 5. free it.
|
|
|
|
*
|
|
|
|
* Make sure you have a reference to the uwb_rc before calling
|
|
|
|
* any of the UWB API functions.
|
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
*
|
|
|
|
* 1. Locking and life cycle management is crappy still. All entry
|
|
|
|
* points to the UWB HCD API assume you have a reference on the
|
|
|
|
* uwb_rc structure and that it won't go away. They mutex lock it
|
|
|
|
* before doing anything.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/kdev_t.h>
|
|
|
|
#include <linux/random.h>
|
2008-12-23 01:30:29 +07:00
|
|
|
|
2008-09-17 22:34:06 +07:00
|
|
|
#include "uwb-internal.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* UWB stack attributes (or 'global' constants) */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2011-03-31 08:57:33 +07:00
|
|
|
* If a beacon disappears for longer than this, then we consider the
|
2008-09-17 22:34:06 +07:00
|
|
|
* device who was represented by that beacon to be gone.
|
|
|
|
*
|
|
|
|
* ECMA-368[17.2.3, last para] establishes that a device must not
|
|
|
|
* consider a device to be its neighbour if he doesn't receive a beacon
|
|
|
|
* for more than mMaxLostBeacons. mMaxLostBeacons is defined in
|
|
|
|
* ECMA-368[17.16] as 3; because we can get only one beacon per
|
|
|
|
* superframe, that'd be 3 * 65ms = 195 ~ 200 ms. Let's give it time
|
|
|
|
* for jitter and stuff and make it 500 ms.
|
|
|
|
*/
|
|
|
|
unsigned long beacon_timeout_ms = 500;
|
|
|
|
|
|
|
|
static
|
2010-01-05 18:48:07 +07:00
|
|
|
ssize_t beacon_timeout_ms_show(struct class *class,
|
|
|
|
struct class_attribute *attr,
|
|
|
|
char *buf)
|
2008-09-17 22:34:06 +07:00
|
|
|
{
|
|
|
|
return scnprintf(buf, PAGE_SIZE, "%lu\n", beacon_timeout_ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
ssize_t beacon_timeout_ms_store(struct class *class,
|
2010-01-05 18:48:07 +07:00
|
|
|
struct class_attribute *attr,
|
2008-09-17 22:34:06 +07:00
|
|
|
const char *buf, size_t size)
|
|
|
|
{
|
|
|
|
unsigned long bt;
|
|
|
|
ssize_t result;
|
|
|
|
result = sscanf(buf, "%lu", &bt);
|
|
|
|
if (result != 1)
|
|
|
|
return -EINVAL;
|
|
|
|
beacon_timeout_ms = bt;
|
|
|
|
return size;
|
|
|
|
}
|
2017-06-08 15:12:36 +07:00
|
|
|
static CLASS_ATTR_RW(beacon_timeout_ms);
|
2008-09-17 22:34:06 +07:00
|
|
|
|
2017-06-08 15:12:36 +07:00
|
|
|
static struct attribute *uwb_class_attrs[] = {
|
|
|
|
&class_attr_beacon_timeout_ms.attr,
|
|
|
|
NULL,
|
2008-09-17 22:34:06 +07:00
|
|
|
};
|
2017-06-08 15:12:36 +07:00
|
|
|
ATTRIBUTE_GROUPS(uwb_class);
|
2008-09-17 22:34:06 +07:00
|
|
|
|
|
|
|
/** Device model classes */
|
|
|
|
struct class uwb_rc_class = {
|
|
|
|
.name = "uwb_rc",
|
2017-06-08 15:12:36 +07:00
|
|
|
.class_groups = uwb_class_groups,
|
2008-09-17 22:34:06 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int __init uwb_subsys_init(void)
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
result = uwb_est_create();
|
|
|
|
if (result < 0) {
|
|
|
|
printk(KERN_ERR "uwb: Can't initialize EST subsystem\n");
|
|
|
|
goto error_est_init;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = class_register(&uwb_rc_class);
|
|
|
|
if (result < 0)
|
|
|
|
goto error_uwb_rc_class_register;
|
2014-09-17 03:53:08 +07:00
|
|
|
|
|
|
|
/* Register the UWB bus */
|
|
|
|
result = bus_register(&uwb_bus_type);
|
|
|
|
if (result) {
|
|
|
|
pr_err("%s - registering bus driver failed\n", __func__);
|
|
|
|
goto exit_bus;
|
|
|
|
}
|
|
|
|
|
2008-09-17 22:34:34 +07:00
|
|
|
uwb_dbg_init();
|
2008-09-17 22:34:06 +07:00
|
|
|
return 0;
|
|
|
|
|
2014-09-17 03:53:08 +07:00
|
|
|
exit_bus:
|
|
|
|
class_unregister(&uwb_rc_class);
|
2008-09-17 22:34:06 +07:00
|
|
|
error_uwb_rc_class_register:
|
|
|
|
uwb_est_destroy();
|
|
|
|
error_est_init:
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
module_init(uwb_subsys_init);
|
|
|
|
|
|
|
|
static void __exit uwb_subsys_exit(void)
|
|
|
|
{
|
2008-09-17 22:34:34 +07:00
|
|
|
uwb_dbg_exit();
|
2014-09-17 03:53:08 +07:00
|
|
|
bus_unregister(&uwb_bus_type);
|
2008-09-17 22:34:06 +07:00
|
|
|
class_unregister(&uwb_rc_class);
|
|
|
|
uwb_est_destroy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
module_exit(uwb_subsys_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>");
|
|
|
|
MODULE_DESCRIPTION("Ultra Wide Band core");
|
|
|
|
MODULE_LICENSE("GPL");
|