1 // SPDX-License-Identifier: GPL-2.0-only
4 * Driver initialization, etc
6 * Copyright (C) 2005-2006 Intel Corporation
7 * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
11 * Life cycle: FIXME: explain
13 * UWB radio controller:
15 * 1. alloc a uwb_rc, zero it
16 * 2. call uwb_rc_init() on it to set it up + ops (won't do any
18 * 3. register (now it is owned by the UWB stack--deregister before
19 * freeing/destroying).
20 * 4. It lives on it's own now (UWB stack handles)--when it
21 * disconnects, call unregister()
24 * Make sure you have a reference to the uwb_rc before calling
25 * any of the UWB API functions.
29 * 1. Locking and life cycle management is crappy still. All entry
30 * points to the UWB HCD API assume you have a reference on the
31 * uwb_rc structure and that it won't go away. They mutex lock it
32 * before doing anything.
35 #include <linux/kernel.h>
36 #include <linux/init.h>
37 #include <linux/module.h>
38 #include <linux/device.h>
39 #include <linux/err.h>
40 #include <linux/kdev_t.h>
41 #include <linux/random.h>
43 #include "uwb-internal.h"
46 /* UWB stack attributes (or 'global' constants) */
50 * If a beacon disappears for longer than this, then we consider the
51 * device who was represented by that beacon to be gone.
53 * ECMA-368[17.2.3, last para] establishes that a device must not
54 * consider a device to be its neighbour if he doesn't receive a beacon
55 * for more than mMaxLostBeacons. mMaxLostBeacons is defined in
56 * ECMA-368[17.16] as 3; because we can get only one beacon per
57 * superframe, that'd be 3 * 65ms = 195 ~ 200 ms. Let's give it time
58 * for jitter and stuff and make it 500 ms.
60 unsigned long beacon_timeout_ms
= 500;
63 ssize_t
beacon_timeout_ms_show(struct class *class,
64 struct class_attribute
*attr
,
67 return scnprintf(buf
, PAGE_SIZE
, "%lu\n", beacon_timeout_ms
);
71 ssize_t
beacon_timeout_ms_store(struct class *class,
72 struct class_attribute
*attr
,
73 const char *buf
, size_t size
)
77 result
= sscanf(buf
, "%lu", &bt
);
80 beacon_timeout_ms
= bt
;
83 static CLASS_ATTR_RW(beacon_timeout_ms
);
85 static struct attribute
*uwb_class_attrs
[] = {
86 &class_attr_beacon_timeout_ms
.attr
,
89 ATTRIBUTE_GROUPS(uwb_class
);
91 /** Device model classes */
92 struct class uwb_rc_class
= {
94 .class_groups
= uwb_class_groups
,
98 static int __init
uwb_subsys_init(void)
102 result
= uwb_est_create();
104 printk(KERN_ERR
"uwb: Can't initialize EST subsystem\n");
108 result
= class_register(&uwb_rc_class
);
110 goto error_uwb_rc_class_register
;
112 /* Register the UWB bus */
113 result
= bus_register(&uwb_bus_type
);
115 pr_err("%s - registering bus driver failed\n", __func__
);
123 class_unregister(&uwb_rc_class
);
124 error_uwb_rc_class_register
:
129 module_init(uwb_subsys_init
);
131 static void __exit
uwb_subsys_exit(void)
134 bus_unregister(&uwb_bus_type
);
135 class_unregister(&uwb_rc_class
);
139 module_exit(uwb_subsys_exit
);
141 MODULE_AUTHOR("Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>");
142 MODULE_DESCRIPTION("Ultra Wide Band core");
143 MODULE_LICENSE("GPL");