Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* Bluetooth HCI driver model support. */ |
| 2 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | #include <linux/kernel.h> |
| 4 | #include <linux/init.h> |
| 5 | |
Marcel Holtmann | 27d3528 | 2006-07-03 10:02:37 +0200 | [diff] [blame] | 6 | #include <linux/platform_device.h> |
| 7 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #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 |
| 15 | |
Marcel Holtmann | 4d0eb00 | 2006-07-06 12:34:41 +0200 | [diff] [blame] | 16 | static inline char *typetostr(int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | { |
Marcel Holtmann | 4d0eb00 | 2006-07-06 12:34:41 +0200 | [diff] [blame] | 18 | switch (type) { |
Marcel Holtmann | 0ac5393 | 2006-07-08 13:57:15 +0200 | [diff] [blame] | 19 | case HCI_VIRTUAL: |
Marcel Holtmann | 4d0eb00 | 2006-07-06 12:34:41 +0200 | [diff] [blame] | 20 | return "VIRTUAL"; |
| 21 | case HCI_USB: |
| 22 | return "USB"; |
| 23 | case HCI_PCCARD: |
| 24 | return "PCCARD"; |
| 25 | case HCI_UART: |
| 26 | return "UART"; |
| 27 | case HCI_RS232: |
| 28 | return "RS232"; |
| 29 | case HCI_PCI: |
| 30 | return "PCI"; |
Marcel Holtmann | 0ac5393 | 2006-07-08 13:57:15 +0200 | [diff] [blame] | 31 | case HCI_SDIO: |
| 32 | return "SDIO"; |
Marcel Holtmann | 4d0eb00 | 2006-07-06 12:34:41 +0200 | [diff] [blame] | 33 | default: |
| 34 | return "UNKNOWN"; |
| 35 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 38 | static ssize_t show_type(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | { |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 40 | struct hci_dev *hdev = dev_get_drvdata(dev); |
Marcel Holtmann | 4d0eb00 | 2006-07-06 12:34:41 +0200 | [diff] [blame] | 41 | return sprintf(buf, "%s\n", typetostr(hdev->type)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 44 | static ssize_t show_address(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | { |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 46 | struct hci_dev *hdev = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | bdaddr_t bdaddr; |
| 48 | baswap(&bdaddr, &hdev->bdaddr); |
| 49 | return sprintf(buf, "%s\n", batostr(&bdaddr)); |
| 50 | } |
| 51 | |
Marcel Holtmann | 1143e5a | 2006-09-23 09:57:20 +0200 | [diff] [blame] | 52 | static ssize_t show_manufacturer(struct device *dev, struct device_attribute *attr, char *buf) |
| 53 | { |
| 54 | struct hci_dev *hdev = dev_get_drvdata(dev); |
| 55 | return sprintf(buf, "%d\n", hdev->manufacturer); |
| 56 | } |
| 57 | |
| 58 | static ssize_t show_hci_version(struct device *dev, struct device_attribute *attr, char *buf) |
| 59 | { |
| 60 | struct hci_dev *hdev = dev_get_drvdata(dev); |
| 61 | return sprintf(buf, "%d\n", hdev->hci_ver); |
| 62 | } |
| 63 | |
| 64 | static ssize_t show_hci_revision(struct device *dev, struct device_attribute *attr, char *buf) |
| 65 | { |
| 66 | struct hci_dev *hdev = dev_get_drvdata(dev); |
| 67 | return sprintf(buf, "%d\n", hdev->hci_rev); |
| 68 | } |
| 69 | |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 70 | static ssize_t show_inquiry_cache(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | { |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 72 | struct hci_dev *hdev = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | struct inquiry_cache *cache = &hdev->inq_cache; |
| 74 | struct inquiry_entry *e; |
| 75 | int n = 0; |
| 76 | |
| 77 | hci_dev_lock_bh(hdev); |
| 78 | |
| 79 | for (e = cache->list; e; e = e->next) { |
| 80 | struct inquiry_data *data = &e->data; |
| 81 | bdaddr_t bdaddr; |
| 82 | baswap(&bdaddr, &data->bdaddr); |
| 83 | n += sprintf(buf + n, "%s %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %u\n", |
| 84 | batostr(&bdaddr), |
| 85 | data->pscan_rep_mode, data->pscan_period_mode, data->pscan_mode, |
| 86 | data->dev_class[2], data->dev_class[1], data->dev_class[0], |
| 87 | __le16_to_cpu(data->clock_offset), data->rssi, e->timestamp); |
| 88 | } |
| 89 | |
| 90 | hci_dev_unlock_bh(hdev); |
| 91 | return n; |
| 92 | } |
| 93 | |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 94 | static ssize_t show_idle_timeout(struct device *dev, struct device_attribute *attr, char *buf) |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 95 | { |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 96 | struct hci_dev *hdev = dev_get_drvdata(dev); |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 97 | return sprintf(buf, "%d\n", hdev->idle_timeout); |
| 98 | } |
| 99 | |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 100 | static ssize_t store_idle_timeout(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 101 | { |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 102 | struct hci_dev *hdev = dev_get_drvdata(dev); |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 103 | char *ptr; |
| 104 | __u32 val; |
| 105 | |
| 106 | val = simple_strtoul(buf, &ptr, 10); |
| 107 | if (ptr == buf) |
| 108 | return -EINVAL; |
| 109 | |
| 110 | if (val != 0 && (val < 500 || val > 3600000)) |
| 111 | return -EINVAL; |
| 112 | |
| 113 | hdev->idle_timeout = val; |
| 114 | |
| 115 | return count; |
| 116 | } |
| 117 | |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 118 | static ssize_t show_sniff_max_interval(struct device *dev, struct device_attribute *attr, char *buf) |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 119 | { |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 120 | struct hci_dev *hdev = dev_get_drvdata(dev); |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 121 | return sprintf(buf, "%d\n", hdev->sniff_max_interval); |
| 122 | } |
| 123 | |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 124 | static ssize_t store_sniff_max_interval(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 125 | { |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 126 | struct hci_dev *hdev = dev_get_drvdata(dev); |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 127 | char *ptr; |
| 128 | __u16 val; |
| 129 | |
| 130 | val = simple_strtoul(buf, &ptr, 10); |
| 131 | if (ptr == buf) |
| 132 | return -EINVAL; |
| 133 | |
| 134 | if (val < 0x0002 || val > 0xFFFE || val % 2) |
| 135 | return -EINVAL; |
| 136 | |
| 137 | if (val < hdev->sniff_min_interval) |
| 138 | return -EINVAL; |
| 139 | |
| 140 | hdev->sniff_max_interval = val; |
| 141 | |
| 142 | return count; |
| 143 | } |
| 144 | |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 145 | static ssize_t show_sniff_min_interval(struct device *dev, struct device_attribute *attr, char *buf) |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 146 | { |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 147 | struct hci_dev *hdev = dev_get_drvdata(dev); |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 148 | return sprintf(buf, "%d\n", hdev->sniff_min_interval); |
| 149 | } |
| 150 | |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 151 | static ssize_t store_sniff_min_interval(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 152 | { |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 153 | struct hci_dev *hdev = dev_get_drvdata(dev); |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 154 | char *ptr; |
| 155 | __u16 val; |
| 156 | |
| 157 | val = simple_strtoul(buf, &ptr, 10); |
| 158 | if (ptr == buf) |
| 159 | return -EINVAL; |
| 160 | |
| 161 | if (val < 0x0002 || val > 0xFFFE || val % 2) |
| 162 | return -EINVAL; |
| 163 | |
| 164 | if (val > hdev->sniff_max_interval) |
| 165 | return -EINVAL; |
| 166 | |
| 167 | hdev->sniff_min_interval = val; |
| 168 | |
| 169 | return count; |
| 170 | } |
| 171 | |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 172 | static DEVICE_ATTR(type, S_IRUGO, show_type, NULL); |
| 173 | static DEVICE_ATTR(address, S_IRUGO, show_address, NULL); |
Marcel Holtmann | 1143e5a | 2006-09-23 09:57:20 +0200 | [diff] [blame] | 174 | static DEVICE_ATTR(manufacturer, S_IRUGO, show_manufacturer, NULL); |
| 175 | static DEVICE_ATTR(hci_version, S_IRUGO, show_hci_version, NULL); |
| 176 | static DEVICE_ATTR(hci_revision, S_IRUGO, show_hci_revision, NULL); |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 177 | static DEVICE_ATTR(inquiry_cache, S_IRUGO, show_inquiry_cache, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 179 | static DEVICE_ATTR(idle_timeout, S_IRUGO | S_IWUSR, |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 180 | show_idle_timeout, store_idle_timeout); |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 181 | static DEVICE_ATTR(sniff_max_interval, S_IRUGO | S_IWUSR, |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 182 | show_sniff_max_interval, store_sniff_max_interval); |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 183 | static DEVICE_ATTR(sniff_min_interval, S_IRUGO | S_IWUSR, |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 184 | show_sniff_min_interval, store_sniff_min_interval); |
| 185 | |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 186 | static struct device_attribute *bt_attrs[] = { |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 187 | &dev_attr_type, |
| 188 | &dev_attr_address, |
Marcel Holtmann | 1143e5a | 2006-09-23 09:57:20 +0200 | [diff] [blame] | 189 | &dev_attr_manufacturer, |
| 190 | &dev_attr_hci_version, |
| 191 | &dev_attr_hci_revision, |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 192 | &dev_attr_inquiry_cache, |
| 193 | &dev_attr_idle_timeout, |
| 194 | &dev_attr_sniff_max_interval, |
| 195 | &dev_attr_sniff_min_interval, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | NULL |
| 197 | }; |
| 198 | |
Marcel Holtmann | b219e3a | 2006-07-06 12:38:46 +0200 | [diff] [blame] | 199 | static ssize_t show_conn_type(struct device *dev, struct device_attribute *attr, char *buf) |
| 200 | { |
| 201 | struct hci_conn *conn = dev_get_drvdata(dev); |
| 202 | return sprintf(buf, "%s\n", conn->type == ACL_LINK ? "ACL" : "SCO"); |
| 203 | } |
| 204 | |
| 205 | static ssize_t show_conn_address(struct device *dev, struct device_attribute *attr, char *buf) |
| 206 | { |
| 207 | struct hci_conn *conn = dev_get_drvdata(dev); |
| 208 | bdaddr_t bdaddr; |
| 209 | baswap(&bdaddr, &conn->dst); |
| 210 | return sprintf(buf, "%s\n", batostr(&bdaddr)); |
| 211 | } |
| 212 | |
| 213 | #define CONN_ATTR(_name,_mode,_show,_store) \ |
| 214 | struct device_attribute conn_attr_##_name = __ATTR(_name,_mode,_show,_store) |
| 215 | |
| 216 | static CONN_ATTR(type, S_IRUGO, show_conn_type, NULL); |
| 217 | static CONN_ATTR(address, S_IRUGO, show_conn_address, NULL); |
| 218 | |
| 219 | static struct device_attribute *conn_attrs[] = { |
| 220 | &conn_attr_type, |
| 221 | &conn_attr_address, |
| 222 | NULL |
| 223 | }; |
| 224 | |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 225 | struct class *bt_class = NULL; |
Marcel Holtmann | be9d122 | 2005-11-08 09:57:38 -0800 | [diff] [blame] | 226 | EXPORT_SYMBOL_GPL(bt_class); |
| 227 | |
Marcel Holtmann | 27d3528 | 2006-07-03 10:02:37 +0200 | [diff] [blame] | 228 | static struct bus_type bt_bus = { |
| 229 | .name = "bluetooth", |
| 230 | }; |
| 231 | |
| 232 | static struct platform_device *bt_platform; |
| 233 | |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 234 | static void bt_release(struct device *dev) |
| 235 | { |
Marcel Holtmann | b219e3a | 2006-07-06 12:38:46 +0200 | [diff] [blame] | 236 | void *data = dev_get_drvdata(dev); |
| 237 | kfree(data); |
| 238 | } |
| 239 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 240 | static void add_conn(struct work_struct *work) |
Marcel Holtmann | b219e3a | 2006-07-06 12:38:46 +0200 | [diff] [blame] | 241 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 242 | struct hci_conn *conn = container_of(work, struct hci_conn, work); |
Marcel Holtmann | b219e3a | 2006-07-06 12:38:46 +0200 | [diff] [blame] | 243 | int i; |
| 244 | |
Marcel Holtmann | c893779 | 2007-01-08 02:16:38 +0100 | [diff] [blame] | 245 | if (device_add(&conn->dev) < 0) { |
Marcel Holtmann | df5c37e | 2006-10-15 17:30:45 +0200 | [diff] [blame] | 246 | BT_ERR("Failed to register connection device"); |
| 247 | return; |
| 248 | } |
Marcel Holtmann | b219e3a | 2006-07-06 12:38:46 +0200 | [diff] [blame] | 249 | |
| 250 | for (i = 0; conn_attrs[i]; i++) |
Marcel Holtmann | df5c37e | 2006-10-15 17:30:45 +0200 | [diff] [blame] | 251 | if (device_create_file(&conn->dev, conn_attrs[i]) < 0) |
| 252 | BT_ERR("Failed to create connection attribute"); |
Marcel Holtmann | b219e3a | 2006-07-06 12:38:46 +0200 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | void hci_conn_add_sysfs(struct hci_conn *conn) |
| 256 | { |
| 257 | struct hci_dev *hdev = conn->hdev; |
| 258 | bdaddr_t *ba = &conn->dst; |
| 259 | |
| 260 | BT_DBG("conn %p", conn); |
| 261 | |
Marcel Holtmann | e52726d | 2006-11-18 22:14:05 +0100 | [diff] [blame] | 262 | conn->dev.bus = &bt_bus; |
| 263 | conn->dev.parent = &hdev->dev; |
| 264 | |
Marcel Holtmann | b219e3a | 2006-07-06 12:38:46 +0200 | [diff] [blame] | 265 | conn->dev.release = bt_release; |
| 266 | |
| 267 | snprintf(conn->dev.bus_id, BUS_ID_SIZE, |
| 268 | "%s%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X", |
| 269 | conn->type == ACL_LINK ? "acl" : "sco", |
| 270 | ba->b[5], ba->b[4], ba->b[3], |
| 271 | ba->b[2], ba->b[1], ba->b[0]); |
| 272 | |
| 273 | dev_set_drvdata(&conn->dev, conn); |
| 274 | |
Marcel Holtmann | c893779 | 2007-01-08 02:16:38 +0100 | [diff] [blame] | 275 | device_initialize(&conn->dev); |
| 276 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 277 | INIT_WORK(&conn->work, add_conn); |
Marcel Holtmann | b219e3a | 2006-07-06 12:38:46 +0200 | [diff] [blame] | 278 | |
| 279 | schedule_work(&conn->work); |
| 280 | } |
| 281 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 282 | static void del_conn(struct work_struct *work) |
Marcel Holtmann | b219e3a | 2006-07-06 12:38:46 +0200 | [diff] [blame] | 283 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 284 | struct hci_conn *conn = container_of(work, struct hci_conn, work); |
Marcel Holtmann | b219e3a | 2006-07-06 12:38:46 +0200 | [diff] [blame] | 285 | device_del(&conn->dev); |
| 286 | } |
| 287 | |
| 288 | void hci_conn_del_sysfs(struct hci_conn *conn) |
| 289 | { |
| 290 | BT_DBG("conn %p", conn); |
| 291 | |
Marcel Holtmann | c893779 | 2007-01-08 02:16:38 +0100 | [diff] [blame] | 292 | if (!device_is_registered(&conn->dev)) |
| 293 | return; |
| 294 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 295 | INIT_WORK(&conn->work, del_conn); |
Marcel Holtmann | b219e3a | 2006-07-06 12:38:46 +0200 | [diff] [blame] | 296 | |
| 297 | schedule_work(&conn->work); |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 298 | } |
| 299 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | int hci_register_sysfs(struct hci_dev *hdev) |
| 301 | { |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 302 | struct device *dev = &hdev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | unsigned int i; |
| 304 | int err; |
| 305 | |
| 306 | BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type); |
| 307 | |
Marcel Holtmann | 53c1d4b | 2007-05-05 00:36:03 +0200 | [diff] [blame] | 308 | dev->bus = &bt_bus; |
Marcel Holtmann | e9c4bec | 2006-10-15 17:30:50 +0200 | [diff] [blame] | 309 | dev->parent = hdev->parent; |
Marcel Holtmann | 27d3528 | 2006-07-03 10:02:37 +0200 | [diff] [blame] | 310 | |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 311 | strlcpy(dev->bus_id, hdev->name, BUS_ID_SIZE); |
Marcel Holtmann | 27d3528 | 2006-07-03 10:02:37 +0200 | [diff] [blame] | 312 | |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 313 | dev->release = bt_release; |
| 314 | |
| 315 | dev_set_drvdata(dev, hdev); |
| 316 | |
| 317 | err = device_register(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | if (err < 0) |
| 319 | return err; |
| 320 | |
| 321 | for (i = 0; bt_attrs[i]; i++) |
Marcel Holtmann | df5c37e | 2006-10-15 17:30:45 +0200 | [diff] [blame] | 322 | if (device_create_file(dev, bt_attrs[i]) < 0) |
| 323 | BT_ERR("Failed to create device attribute"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
Linus Torvalds | d12db0b | 2007-05-07 17:32:08 -0700 | [diff] [blame^] | 325 | if (sysfs_create_link(&bt_class->subsys.kobj, |
Marcel Holtmann | 53c1d4b | 2007-05-05 00:36:03 +0200 | [diff] [blame] | 326 | &dev->kobj, kobject_name(&dev->kobj)) < 0) |
| 327 | BT_ERR("Failed to create class symlink"); |
| 328 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | return 0; |
| 330 | } |
| 331 | |
| 332 | void hci_unregister_sysfs(struct hci_dev *hdev) |
| 333 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type); |
| 335 | |
Linus Torvalds | d12db0b | 2007-05-07 17:32:08 -0700 | [diff] [blame^] | 336 | sysfs_remove_link(&bt_class->subsys.kobj, |
Marcel Holtmann | 53c1d4b | 2007-05-05 00:36:03 +0200 | [diff] [blame] | 337 | kobject_name(&hdev->dev.kobj)); |
| 338 | |
Marcel Holtmann | 4d0eb00 | 2006-07-06 12:34:41 +0200 | [diff] [blame] | 339 | device_del(&hdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | int __init bt_sysfs_init(void) |
| 343 | { |
Marcel Holtmann | 27d3528 | 2006-07-03 10:02:37 +0200 | [diff] [blame] | 344 | int err; |
| 345 | |
| 346 | bt_platform = platform_device_register_simple("bluetooth", -1, NULL, 0); |
| 347 | if (IS_ERR(bt_platform)) |
| 348 | return PTR_ERR(bt_platform); |
| 349 | |
| 350 | err = bus_register(&bt_bus); |
| 351 | if (err < 0) { |
| 352 | platform_device_unregister(bt_platform); |
| 353 | return err; |
| 354 | } |
| 355 | |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 356 | bt_class = class_create(THIS_MODULE, "bluetooth"); |
| 357 | if (IS_ERR(bt_class)) { |
Marcel Holtmann | 27d3528 | 2006-07-03 10:02:37 +0200 | [diff] [blame] | 358 | bus_unregister(&bt_bus); |
| 359 | platform_device_unregister(bt_platform); |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 360 | return PTR_ERR(bt_class); |
Marcel Holtmann | 27d3528 | 2006-07-03 10:02:37 +0200 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Arnaud Patard | 860e13b | 2006-09-28 15:29:37 -0700 | [diff] [blame] | 366 | void bt_sysfs_cleanup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | { |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 368 | class_destroy(bt_class); |
Marcel Holtmann | 27d3528 | 2006-07-03 10:02:37 +0200 | [diff] [blame] | 369 | |
| 370 | bus_unregister(&bt_bus); |
| 371 | |
| 372 | platform_device_unregister(bt_platform); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | } |