blob: c85bf8f678dc5f1456788d3ebce5212627211912 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* Bluetooth HCI driver model support. */
2
Linus Torvalds1da177e2005-04-16 15:20:36 -07003#include <linux/kernel.h>
4#include <linux/init.h>
5
Marcel Holtmann27d35282006-07-03 10:02:37 +02006#include <linux/platform_device.h>
7
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <net/bluetooth/bluetooth.h>
9#include <net/bluetooth/hci_core.h>
10
11#ifndef CONFIG_BT_HCI_CORE_DEBUG
12#undef BT_DBG
13#define BT_DBG(D...)
14#endif
Dave Youngb6c06322008-01-29 21:14:08 -080015static struct workqueue_struct *btaddconn;
16static struct workqueue_struct *btdelconn;
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Marcel Holtmann4d0eb002006-07-06 12:34:41 +020018static inline char *typetostr(int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -070019{
Marcel Holtmann4d0eb002006-07-06 12:34:41 +020020 switch (type) {
Marcel Holtmann0ac53932006-07-08 13:57:15 +020021 case HCI_VIRTUAL:
Marcel Holtmann4d0eb002006-07-06 12:34:41 +020022 return "VIRTUAL";
23 case HCI_USB:
24 return "USB";
25 case HCI_PCCARD:
26 return "PCCARD";
27 case HCI_UART:
28 return "UART";
29 case HCI_RS232:
30 return "RS232";
31 case HCI_PCI:
32 return "PCI";
Marcel Holtmann0ac53932006-07-08 13:57:15 +020033 case HCI_SDIO:
34 return "SDIO";
Marcel Holtmann4d0eb002006-07-06 12:34:41 +020035 default:
36 return "UNKNOWN";
37 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070038}
39
Marcel Holtmanna91f2e32006-07-03 10:02:41 +020040static ssize_t show_type(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041{
Marcel Holtmanna91f2e32006-07-03 10:02:41 +020042 struct hci_dev *hdev = dev_get_drvdata(dev);
Marcel Holtmann4d0eb002006-07-06 12:34:41 +020043 return sprintf(buf, "%s\n", typetostr(hdev->type));
Linus Torvalds1da177e2005-04-16 15:20:36 -070044}
45
Marcel Holtmanna9de9242007-10-20 13:33:56 +020046static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf)
47{
48 struct hci_dev *hdev = dev_get_drvdata(dev);
49 char name[249];
50 int i;
51
52 for (i = 0; i < 248; i++)
53 name[i] = hdev->dev_name[i];
54
55 name[248] = '\0';
56 return sprintf(buf, "%s\n", name);
57}
58
59static ssize_t show_class(struct device *dev, struct device_attribute *attr, char *buf)
60{
61 struct hci_dev *hdev = dev_get_drvdata(dev);
62 return sprintf(buf, "0x%.2x%.2x%.2x\n",
63 hdev->dev_class[2], hdev->dev_class[1], hdev->dev_class[0]);
64}
65
Marcel Holtmanna91f2e32006-07-03 10:02:41 +020066static ssize_t show_address(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
Marcel Holtmanna91f2e32006-07-03 10:02:41 +020068 struct hci_dev *hdev = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 bdaddr_t bdaddr;
70 baswap(&bdaddr, &hdev->bdaddr);
71 return sprintf(buf, "%s\n", batostr(&bdaddr));
72}
73
Marcel Holtmanna9de9242007-10-20 13:33:56 +020074static ssize_t show_features(struct device *dev, struct device_attribute *attr, char *buf)
75{
76 struct hci_dev *hdev = dev_get_drvdata(dev);
77
78 return sprintf(buf, "0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
79 hdev->features[0], hdev->features[1],
80 hdev->features[2], hdev->features[3],
81 hdev->features[4], hdev->features[5],
82 hdev->features[6], hdev->features[7]);
83}
84
Marcel Holtmann1143e5a2006-09-23 09:57:20 +020085static ssize_t show_manufacturer(struct device *dev, struct device_attribute *attr, char *buf)
86{
87 struct hci_dev *hdev = dev_get_drvdata(dev);
88 return sprintf(buf, "%d\n", hdev->manufacturer);
89}
90
91static ssize_t show_hci_version(struct device *dev, struct device_attribute *attr, char *buf)
92{
93 struct hci_dev *hdev = dev_get_drvdata(dev);
94 return sprintf(buf, "%d\n", hdev->hci_ver);
95}
96
97static ssize_t show_hci_revision(struct device *dev, struct device_attribute *attr, char *buf)
98{
99 struct hci_dev *hdev = dev_get_drvdata(dev);
100 return sprintf(buf, "%d\n", hdev->hci_rev);
101}
102
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200103static ssize_t show_inquiry_cache(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104{
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200105 struct hci_dev *hdev = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 struct inquiry_cache *cache = &hdev->inq_cache;
107 struct inquiry_entry *e;
108 int n = 0;
109
110 hci_dev_lock_bh(hdev);
111
112 for (e = cache->list; e; e = e->next) {
113 struct inquiry_data *data = &e->data;
114 bdaddr_t bdaddr;
115 baswap(&bdaddr, &data->bdaddr);
Marcel Holtmanna8bd28b2008-07-14 20:13:49 +0200116 n += sprintf(buf + n, "%s %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %u\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 batostr(&bdaddr),
Marcel Holtmanna8bd28b2008-07-14 20:13:49 +0200118 data->pscan_rep_mode, data->pscan_period_mode,
119 data->pscan_mode, data->dev_class[2],
120 data->dev_class[1], data->dev_class[0],
121 __le16_to_cpu(data->clock_offset),
122 data->rssi, data->ssp_mode, e->timestamp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 }
124
125 hci_dev_unlock_bh(hdev);
126 return n;
127}
128
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200129static ssize_t show_idle_timeout(struct device *dev, struct device_attribute *attr, char *buf)
Marcel Holtmann04837f62006-07-03 10:02:33 +0200130{
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200131 struct hci_dev *hdev = dev_get_drvdata(dev);
Marcel Holtmann04837f62006-07-03 10:02:33 +0200132 return sprintf(buf, "%d\n", hdev->idle_timeout);
133}
134
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200135static ssize_t store_idle_timeout(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Marcel Holtmann04837f62006-07-03 10:02:33 +0200136{
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200137 struct hci_dev *hdev = dev_get_drvdata(dev);
Marcel Holtmann04837f62006-07-03 10:02:33 +0200138 char *ptr;
139 __u32 val;
140
141 val = simple_strtoul(buf, &ptr, 10);
142 if (ptr == buf)
143 return -EINVAL;
144
145 if (val != 0 && (val < 500 || val > 3600000))
146 return -EINVAL;
147
148 hdev->idle_timeout = val;
149
150 return count;
151}
152
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200153static ssize_t show_sniff_max_interval(struct device *dev, struct device_attribute *attr, char *buf)
Marcel Holtmann04837f62006-07-03 10:02:33 +0200154{
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200155 struct hci_dev *hdev = dev_get_drvdata(dev);
Marcel Holtmann04837f62006-07-03 10:02:33 +0200156 return sprintf(buf, "%d\n", hdev->sniff_max_interval);
157}
158
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200159static ssize_t store_sniff_max_interval(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Marcel Holtmann04837f62006-07-03 10:02:33 +0200160{
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200161 struct hci_dev *hdev = dev_get_drvdata(dev);
Marcel Holtmann04837f62006-07-03 10:02:33 +0200162 char *ptr;
163 __u16 val;
164
165 val = simple_strtoul(buf, &ptr, 10);
166 if (ptr == buf)
167 return -EINVAL;
168
169 if (val < 0x0002 || val > 0xFFFE || val % 2)
170 return -EINVAL;
171
172 if (val < hdev->sniff_min_interval)
173 return -EINVAL;
174
175 hdev->sniff_max_interval = val;
176
177 return count;
178}
179
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200180static ssize_t show_sniff_min_interval(struct device *dev, struct device_attribute *attr, char *buf)
Marcel Holtmann04837f62006-07-03 10:02:33 +0200181{
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200182 struct hci_dev *hdev = dev_get_drvdata(dev);
Marcel Holtmann04837f62006-07-03 10:02:33 +0200183 return sprintf(buf, "%d\n", hdev->sniff_min_interval);
184}
185
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200186static ssize_t store_sniff_min_interval(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Marcel Holtmann04837f62006-07-03 10:02:33 +0200187{
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200188 struct hci_dev *hdev = dev_get_drvdata(dev);
Marcel Holtmann04837f62006-07-03 10:02:33 +0200189 char *ptr;
190 __u16 val;
191
192 val = simple_strtoul(buf, &ptr, 10);
193 if (ptr == buf)
194 return -EINVAL;
195
196 if (val < 0x0002 || val > 0xFFFE || val % 2)
197 return -EINVAL;
198
199 if (val > hdev->sniff_max_interval)
200 return -EINVAL;
201
202 hdev->sniff_min_interval = val;
203
204 return count;
205}
206
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200207static DEVICE_ATTR(type, S_IRUGO, show_type, NULL);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200208static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
209static DEVICE_ATTR(class, S_IRUGO, show_class, NULL);
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200210static DEVICE_ATTR(address, S_IRUGO, show_address, NULL);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200211static DEVICE_ATTR(features, S_IRUGO, show_features, NULL);
Marcel Holtmann1143e5a2006-09-23 09:57:20 +0200212static DEVICE_ATTR(manufacturer, S_IRUGO, show_manufacturer, NULL);
213static DEVICE_ATTR(hci_version, S_IRUGO, show_hci_version, NULL);
214static DEVICE_ATTR(hci_revision, S_IRUGO, show_hci_revision, NULL);
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200215static DEVICE_ATTR(inquiry_cache, S_IRUGO, show_inquiry_cache, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200217static DEVICE_ATTR(idle_timeout, S_IRUGO | S_IWUSR,
Marcel Holtmann04837f62006-07-03 10:02:33 +0200218 show_idle_timeout, store_idle_timeout);
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200219static DEVICE_ATTR(sniff_max_interval, S_IRUGO | S_IWUSR,
Marcel Holtmann04837f62006-07-03 10:02:33 +0200220 show_sniff_max_interval, store_sniff_max_interval);
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200221static DEVICE_ATTR(sniff_min_interval, S_IRUGO | S_IWUSR,
Marcel Holtmann04837f62006-07-03 10:02:33 +0200222 show_sniff_min_interval, store_sniff_min_interval);
223
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200224static struct device_attribute *bt_attrs[] = {
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200225 &dev_attr_type,
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200226 &dev_attr_name,
227 &dev_attr_class,
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200228 &dev_attr_address,
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200229 &dev_attr_features,
Marcel Holtmann1143e5a2006-09-23 09:57:20 +0200230 &dev_attr_manufacturer,
231 &dev_attr_hci_version,
232 &dev_attr_hci_revision,
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200233 &dev_attr_inquiry_cache,
234 &dev_attr_idle_timeout,
235 &dev_attr_sniff_max_interval,
236 &dev_attr_sniff_min_interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 NULL
238};
239
Marcel Holtmannb219e3a2006-07-06 12:38:46 +0200240static ssize_t show_conn_type(struct device *dev, struct device_attribute *attr, char *buf)
241{
242 struct hci_conn *conn = dev_get_drvdata(dev);
243 return sprintf(buf, "%s\n", conn->type == ACL_LINK ? "ACL" : "SCO");
244}
245
246static ssize_t show_conn_address(struct device *dev, struct device_attribute *attr, char *buf)
247{
248 struct hci_conn *conn = dev_get_drvdata(dev);
249 bdaddr_t bdaddr;
250 baswap(&bdaddr, &conn->dst);
251 return sprintf(buf, "%s\n", batostr(&bdaddr));
252}
253
Marcel Holtmanna8bd28b2008-07-14 20:13:49 +0200254static ssize_t show_conn_features(struct device *dev, struct device_attribute *attr, char *buf)
255{
256 struct hci_conn *conn = dev_get_drvdata(dev);
257
258 return sprintf(buf, "0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
259 conn->features[0], conn->features[1],
260 conn->features[2], conn->features[3],
261 conn->features[4], conn->features[5],
262 conn->features[6], conn->features[7]);
263}
264
Marcel Holtmannb219e3a2006-07-06 12:38:46 +0200265#define CONN_ATTR(_name,_mode,_show,_store) \
266struct device_attribute conn_attr_##_name = __ATTR(_name,_mode,_show,_store)
267
268static CONN_ATTR(type, S_IRUGO, show_conn_type, NULL);
269static CONN_ATTR(address, S_IRUGO, show_conn_address, NULL);
Marcel Holtmanna8bd28b2008-07-14 20:13:49 +0200270static CONN_ATTR(features, S_IRUGO, show_conn_features, NULL);
Marcel Holtmannb219e3a2006-07-06 12:38:46 +0200271
272static struct device_attribute *conn_attrs[] = {
273 &conn_attr_type,
274 &conn_attr_address,
Marcel Holtmanna8bd28b2008-07-14 20:13:49 +0200275 &conn_attr_features,
Marcel Holtmannb219e3a2006-07-06 12:38:46 +0200276 NULL
277};
278
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200279struct class *bt_class = NULL;
Marcel Holtmannbe9d1222005-11-08 09:57:38 -0800280EXPORT_SYMBOL_GPL(bt_class);
281
Marcel Holtmann27d35282006-07-03 10:02:37 +0200282static struct bus_type bt_bus = {
283 .name = "bluetooth",
284};
285
286static struct platform_device *bt_platform;
287
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200288static void bt_release(struct device *dev)
289{
Marcel Holtmannb219e3a2006-07-06 12:38:46 +0200290 void *data = dev_get_drvdata(dev);
291 kfree(data);
292}
293
David Howellsc4028952006-11-22 14:57:56 +0000294static void add_conn(struct work_struct *work)
Marcel Holtmannb219e3a2006-07-06 12:38:46 +0200295{
David Howellsc4028952006-11-22 14:57:56 +0000296 struct hci_conn *conn = container_of(work, struct hci_conn, work);
Marcel Holtmannb219e3a2006-07-06 12:38:46 +0200297 int i;
298
Dave Youngb6c06322008-01-29 21:14:08 -0800299 flush_workqueue(btdelconn);
Dave Young5396c932008-01-31 18:33:10 -0800300
Marcel Holtmannc8937792007-01-08 02:16:38 +0100301 if (device_add(&conn->dev) < 0) {
Marcel Holtmanndf5c37e2006-10-15 17:30:45 +0200302 BT_ERR("Failed to register connection device");
303 return;
304 }
Marcel Holtmannb219e3a2006-07-06 12:38:46 +0200305
306 for (i = 0; conn_attrs[i]; i++)
Marcel Holtmanndf5c37e2006-10-15 17:30:45 +0200307 if (device_create_file(&conn->dev, conn_attrs[i]) < 0)
308 BT_ERR("Failed to create connection attribute");
Marcel Holtmannb219e3a2006-07-06 12:38:46 +0200309}
310
311void hci_conn_add_sysfs(struct hci_conn *conn)
312{
313 struct hci_dev *hdev = conn->hdev;
Marcel Holtmannb219e3a2006-07-06 12:38:46 +0200314
315 BT_DBG("conn %p", conn);
316
Marcel Holtmanne52726d2006-11-18 22:14:05 +0100317 conn->dev.bus = &bt_bus;
318 conn->dev.parent = &hdev->dev;
319
Marcel Holtmannb219e3a2006-07-06 12:38:46 +0200320 conn->dev.release = bt_release;
321
Marcel Holtmann7d0db0a2008-07-14 20:13:51 +0200322 snprintf(conn->dev.bus_id, BUS_ID_SIZE, "%s:%d",
323 hdev->name, conn->handle);
Marcel Holtmannb219e3a2006-07-06 12:38:46 +0200324
325 dev_set_drvdata(&conn->dev, conn);
326
Marcel Holtmannc8937792007-01-08 02:16:38 +0100327 device_initialize(&conn->dev);
328
David Howellsc4028952006-11-22 14:57:56 +0000329 INIT_WORK(&conn->work, add_conn);
Marcel Holtmannb219e3a2006-07-06 12:38:46 +0200330
Dave Youngb6c06322008-01-29 21:14:08 -0800331 queue_work(btaddconn, &conn->work);
Marcel Holtmannb219e3a2006-07-06 12:38:46 +0200332}
333
Dave Young8ac62dc2008-02-18 20:45:41 -0800334/*
335 * The rfcomm tty device will possibly retain even when conn
336 * is down, and sysfs doesn't support move zombie device,
337 * so we should move the device before conn device is destroyed.
338 */
Dave Youngacea6852008-01-21 22:35:21 -0800339static int __match_tty(struct device *dev, void *data)
340{
Dave Young8ac62dc2008-02-18 20:45:41 -0800341 return !strncmp(dev->bus_id, "rfcomm", 6);
Dave Youngacea6852008-01-21 22:35:21 -0800342}
343
David Howellsc4028952006-11-22 14:57:56 +0000344static void del_conn(struct work_struct *work)
Marcel Holtmannb219e3a2006-07-06 12:38:46 +0200345{
David Howellsc4028952006-11-22 14:57:56 +0000346 struct hci_conn *conn = container_of(work, struct hci_conn, work);
Dave Young0cd63c82008-02-18 20:44:01 -0800347 struct hci_dev *hdev = conn->hdev;
Dave Youngacea6852008-01-21 22:35:21 -0800348
David S. Miller988d0092008-02-18 00:20:50 -0800349 while (1) {
350 struct device *dev;
351
352 dev = device_find_child(&conn->dev, NULL, __match_tty);
353 if (!dev)
354 break;
Dave Youngacea6852008-01-21 22:35:21 -0800355 device_move(dev, NULL);
356 put_device(dev);
357 }
Dave Young0cd63c82008-02-18 20:44:01 -0800358
Marcel Holtmannb219e3a2006-07-06 12:38:46 +0200359 device_del(&conn->dev);
Dave Young38b7da02007-12-29 19:17:47 -0800360 put_device(&conn->dev);
Dave Young0cd63c82008-02-18 20:44:01 -0800361 hci_dev_put(hdev);
Marcel Holtmannb219e3a2006-07-06 12:38:46 +0200362}
363
364void hci_conn_del_sysfs(struct hci_conn *conn)
365{
366 BT_DBG("conn %p", conn);
367
Marcel Holtmannc8937792007-01-08 02:16:38 +0100368 if (!device_is_registered(&conn->dev))
369 return;
370
David Howellsc4028952006-11-22 14:57:56 +0000371 INIT_WORK(&conn->work, del_conn);
Marcel Holtmannb219e3a2006-07-06 12:38:46 +0200372
Dave Youngb6c06322008-01-29 21:14:08 -0800373 queue_work(btdelconn, &conn->work);
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200374}
375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376int hci_register_sysfs(struct hci_dev *hdev)
377{
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200378 struct device *dev = &hdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 unsigned int i;
380 int err;
381
382 BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type);
383
Marcel Holtmann53c1d4b2007-05-05 00:36:03 +0200384 dev->bus = &bt_bus;
Marcel Holtmanne9c4bec2006-10-15 17:30:50 +0200385 dev->parent = hdev->parent;
Marcel Holtmann27d35282006-07-03 10:02:37 +0200386
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200387 strlcpy(dev->bus_id, hdev->name, BUS_ID_SIZE);
Marcel Holtmann27d35282006-07-03 10:02:37 +0200388
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200389 dev->release = bt_release;
390
391 dev_set_drvdata(dev, hdev);
392
393 err = device_register(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 if (err < 0)
395 return err;
396
397 for (i = 0; bt_attrs[i]; i++)
Marcel Holtmanndf5c37e2006-10-15 17:30:45 +0200398 if (device_create_file(dev, bt_attrs[i]) < 0)
399 BT_ERR("Failed to create device attribute");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
401 return 0;
402}
403
404void hci_unregister_sysfs(struct hci_dev *hdev)
405{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type);
407
Marcel Holtmann4d0eb002006-07-06 12:34:41 +0200408 device_del(&hdev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409}
410
411int __init bt_sysfs_init(void)
412{
Marcel Holtmann27d35282006-07-03 10:02:37 +0200413 int err;
414
Dave Youngb6c06322008-01-29 21:14:08 -0800415 btaddconn = create_singlethread_workqueue("btaddconn");
416 if (!btaddconn) {
417 err = -ENOMEM;
418 goto out;
419 }
Dave Young5396c932008-01-31 18:33:10 -0800420
Dave Youngb6c06322008-01-29 21:14:08 -0800421 btdelconn = create_singlethread_workqueue("btdelconn");
422 if (!btdelconn) {
423 err = -ENOMEM;
424 goto out_del;
425 }
426
Marcel Holtmann27d35282006-07-03 10:02:37 +0200427 bt_platform = platform_device_register_simple("bluetooth", -1, NULL, 0);
Dave Youngb6c06322008-01-29 21:14:08 -0800428 if (IS_ERR(bt_platform)) {
429 err = PTR_ERR(bt_platform);
430 goto out_platform;
431 }
Marcel Holtmann27d35282006-07-03 10:02:37 +0200432
433 err = bus_register(&bt_bus);
Dave Youngb6c06322008-01-29 21:14:08 -0800434 if (err < 0)
435 goto out_bus;
Marcel Holtmann27d35282006-07-03 10:02:37 +0200436
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200437 bt_class = class_create(THIS_MODULE, "bluetooth");
438 if (IS_ERR(bt_class)) {
Dave Youngb6c06322008-01-29 21:14:08 -0800439 err = PTR_ERR(bt_class);
440 goto out_class;
Marcel Holtmann27d35282006-07-03 10:02:37 +0200441 }
442
443 return 0;
Dave Youngb6c06322008-01-29 21:14:08 -0800444
445out_class:
446 bus_unregister(&bt_bus);
447out_bus:
448 platform_device_unregister(bt_platform);
449out_platform:
450 destroy_workqueue(btdelconn);
451out_del:
452 destroy_workqueue(btaddconn);
453out:
454 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455}
456
Arnaud Patard860e13b2006-09-28 15:29:37 -0700457void bt_sysfs_cleanup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458{
Dave Youngb6c06322008-01-29 21:14:08 -0800459 destroy_workqueue(btaddconn);
Dave Young5396c932008-01-31 18:33:10 -0800460
Dave Youngb6c06322008-01-29 21:14:08 -0800461 destroy_workqueue(btdelconn);
Dave Young5396c932008-01-31 18:33:10 -0800462
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200463 class_destroy(bt_class);
Dave Young5396c932008-01-31 18:33:10 -0800464
Marcel Holtmann27d35282006-07-03 10:02:37 +0200465 bus_unregister(&bt_bus);
Dave Young5396c932008-01-31 18:33:10 -0800466
Marcel Holtmann27d35282006-07-03 10:02:37 +0200467 platform_device_unregister(bt_platform);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468}