libnvdimm/altmap: Track namespace boundaries in altmap
[linux-2.6-block.git] / drivers / uwb / driver.c
CommitLineData
04672fe6 1// SPDX-License-Identifier: GPL-2.0-only
183b9b59
IPG
2/*
3 * Ultra Wide Band
4 * Driver initialization, etc
5 *
6 * Copyright (C) 2005-2006 Intel Corporation
7 * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
8 *
183b9b59
IPG
9 * FIXME: docs
10 *
11 * Life cycle: FIXME: explain
12 *
13 * UWB radio controller:
14 *
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
17 * kind of allocation)
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()
22 * 5. free it.
23 *
24 * Make sure you have a reference to the uwb_rc before calling
25 * any of the UWB API functions.
26 *
27 * TODO:
28 *
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.
33 */
34
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>
a01777ec 42
183b9b59
IPG
43#include "uwb-internal.h"
44
45
46/* UWB stack attributes (or 'global' constants) */
47
48
49/**
25985edc 50 * If a beacon disappears for longer than this, then we consider the
183b9b59
IPG
51 * device who was represented by that beacon to be gone.
52 *
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.
59 */
60unsigned long beacon_timeout_ms = 500;
61
62static
28812fe1
AK
63ssize_t beacon_timeout_ms_show(struct class *class,
64 struct class_attribute *attr,
65 char *buf)
183b9b59
IPG
66{
67 return scnprintf(buf, PAGE_SIZE, "%lu\n", beacon_timeout_ms);
68}
69
70static
71ssize_t beacon_timeout_ms_store(struct class *class,
28812fe1 72 struct class_attribute *attr,
183b9b59
IPG
73 const char *buf, size_t size)
74{
75 unsigned long bt;
76 ssize_t result;
77 result = sscanf(buf, "%lu", &bt);
78 if (result != 1)
79 return -EINVAL;
80 beacon_timeout_ms = bt;
81 return size;
82}
84c317ea 83static CLASS_ATTR_RW(beacon_timeout_ms);
183b9b59 84
84c317ea
GKH
85static struct attribute *uwb_class_attrs[] = {
86 &class_attr_beacon_timeout_ms.attr,
87 NULL,
183b9b59 88};
84c317ea 89ATTRIBUTE_GROUPS(uwb_class);
183b9b59
IPG
90
91/** Device model classes */
92struct class uwb_rc_class = {
93 .name = "uwb_rc",
84c317ea 94 .class_groups = uwb_class_groups,
183b9b59
IPG
95};
96
97
98static int __init uwb_subsys_init(void)
99{
100 int result = 0;
101
102 result = uwb_est_create();
103 if (result < 0) {
104 printk(KERN_ERR "uwb: Can't initialize EST subsystem\n");
105 goto error_est_init;
106 }
107
108 result = class_register(&uwb_rc_class);
109 if (result < 0)
110 goto error_uwb_rc_class_register;
84887934
TP
111
112 /* Register the UWB bus */
113 result = bus_register(&uwb_bus_type);
114 if (result) {
115 pr_err("%s - registering bus driver failed\n", __func__);
116 goto exit_bus;
117 }
118
9d53b1be 119 uwb_dbg_init();
183b9b59
IPG
120 return 0;
121
84887934
TP
122exit_bus:
123 class_unregister(&uwb_rc_class);
183b9b59
IPG
124error_uwb_rc_class_register:
125 uwb_est_destroy();
126error_est_init:
127 return result;
128}
129module_init(uwb_subsys_init);
130
131static void __exit uwb_subsys_exit(void)
132{
9d53b1be 133 uwb_dbg_exit();
84887934 134 bus_unregister(&uwb_bus_type);
183b9b59
IPG
135 class_unregister(&uwb_rc_class);
136 uwb_est_destroy();
137 return;
138}
139module_exit(uwb_subsys_exit);
140
141MODULE_AUTHOR("Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>");
142MODULE_DESCRIPTION("Ultra Wide Band core");
143MODULE_LICENSE("GPL");