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