[Blackfin] arch: Fix gpio label handling
[safe/jmp/linux-2.6] / net / bluetooth / hci_sysfs.c
index 58df436..17f7fb7 100644 (file)
@@ -16,7 +16,7 @@
 static inline char *typetostr(int type)
 {
        switch (type) {
-       case HCI_VHCI:
+       case HCI_VIRTUAL:
                return "VIRTUAL";
        case HCI_USB:
                return "USB";
@@ -28,6 +28,8 @@ static inline char *typetostr(int type)
                return "RS232";
        case HCI_PCI:
                return "PCI";
+       case HCI_SDIO:
+               return "SDIO";
        default:
                return "UNKNOWN";
        }
@@ -39,6 +41,26 @@ static ssize_t show_type(struct device *dev, struct device_attribute *attr, char
        return sprintf(buf, "%s\n", typetostr(hdev->type));
 }
 
+static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       struct hci_dev *hdev = dev_get_drvdata(dev);
+       char name[249];
+       int i;
+
+       for (i = 0; i < 248; i++)
+               name[i] = hdev->dev_name[i];
+
+       name[248] = '\0';
+       return sprintf(buf, "%s\n", name);
+}
+
+static ssize_t show_class(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       struct hci_dev *hdev = dev_get_drvdata(dev);
+       return sprintf(buf, "0x%.2x%.2x%.2x\n",
+                       hdev->dev_class[2], hdev->dev_class[1], hdev->dev_class[0]);
+}
+
 static ssize_t show_address(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct hci_dev *hdev = dev_get_drvdata(dev);
@@ -47,6 +69,35 @@ static ssize_t show_address(struct device *dev, struct device_attribute *attr, c
        return sprintf(buf, "%s\n", batostr(&bdaddr));
 }
 
+static ssize_t show_features(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       struct hci_dev *hdev = dev_get_drvdata(dev);
+
+       return sprintf(buf, "0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
+                               hdev->features[0], hdev->features[1],
+                               hdev->features[2], hdev->features[3],
+                               hdev->features[4], hdev->features[5],
+                               hdev->features[6], hdev->features[7]);
+}
+
+static ssize_t show_manufacturer(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       struct hci_dev *hdev = dev_get_drvdata(dev);
+       return sprintf(buf, "%d\n", hdev->manufacturer);
+}
+
+static ssize_t show_hci_version(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       struct hci_dev *hdev = dev_get_drvdata(dev);
+       return sprintf(buf, "%d\n", hdev->hci_ver);
+}
+
+static ssize_t show_hci_revision(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       struct hci_dev *hdev = dev_get_drvdata(dev);
+       return sprintf(buf, "%d\n", hdev->hci_rev);
+}
+
 static ssize_t show_inquiry_cache(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct hci_dev *hdev = dev_get_drvdata(dev);
@@ -150,7 +201,13 @@ static ssize_t store_sniff_min_interval(struct device *dev, struct device_attrib
 }
 
 static DEVICE_ATTR(type, S_IRUGO, show_type, NULL);
+static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
+static DEVICE_ATTR(class, S_IRUGO, show_class, NULL);
 static DEVICE_ATTR(address, S_IRUGO, show_address, NULL);
+static DEVICE_ATTR(features, S_IRUGO, show_features, NULL);
+static DEVICE_ATTR(manufacturer, S_IRUGO, show_manufacturer, NULL);
+static DEVICE_ATTR(hci_version, S_IRUGO, show_hci_version, NULL);
+static DEVICE_ATTR(hci_revision, S_IRUGO, show_hci_revision, NULL);
 static DEVICE_ATTR(inquiry_cache, S_IRUGO, show_inquiry_cache, NULL);
 
 static DEVICE_ATTR(idle_timeout, S_IRUGO | S_IWUSR,
@@ -162,7 +219,13 @@ static DEVICE_ATTR(sniff_min_interval, S_IRUGO | S_IWUSR,
 
 static struct device_attribute *bt_attrs[] = {
        &dev_attr_type,
+       &dev_attr_name,
+       &dev_attr_class,
        &dev_attr_address,
+       &dev_attr_features,
+       &dev_attr_manufacturer,
+       &dev_attr_hci_version,
+       &dev_attr_hci_revision,
        &dev_attr_inquiry_cache,
        &dev_attr_idle_timeout,
        &dev_attr_sniff_max_interval,
@@ -211,15 +274,19 @@ static void bt_release(struct device *dev)
        kfree(data);
 }
 
-static void add_conn(void *data)
+static void add_conn(struct work_struct *work)
 {
-       struct hci_conn *conn = data;
+       struct hci_conn *conn = container_of(work, struct hci_conn, work);
        int i;
 
-       device_register(&conn->dev);
+       if (device_add(&conn->dev) < 0) {
+               BT_ERR("Failed to register connection device");
+               return;
+       }
 
        for (i = 0; conn_attrs[i]; i++)
-               device_create_file(&conn->dev, conn_attrs[i]);
+               if (device_create_file(&conn->dev, conn_attrs[i]) < 0)
+                       BT_ERR("Failed to create connection attribute");
 }
 
 void hci_conn_add_sysfs(struct hci_conn *conn)
@@ -229,7 +296,9 @@ void hci_conn_add_sysfs(struct hci_conn *conn)
 
        BT_DBG("conn %p", conn);
 
-       conn->dev.parent  = &hdev->dev;
+       conn->dev.bus = &bt_bus;
+       conn->dev.parent = &hdev->dev;
+
        conn->dev.release = bt_release;
 
        snprintf(conn->dev.bus_id, BUS_ID_SIZE,
@@ -240,22 +309,45 @@ void hci_conn_add_sysfs(struct hci_conn *conn)
 
        dev_set_drvdata(&conn->dev, conn);
 
-       INIT_WORK(&conn->work, add_conn, (void *) conn);
+       device_initialize(&conn->dev);
+
+       INIT_WORK(&conn->work, add_conn);
 
        schedule_work(&conn->work);
 }
 
-static void del_conn(void *data)
+static int __match_tty(struct device *dev, void *data)
 {
-       struct hci_conn *conn = data;
+       /* The rfcomm tty device will possibly retain even when conn
+        * is down, and sysfs doesn't support move zombie device,
+        * so we should move the device before conn device is destroyed.
+        * Due to the only child device of hci_conn dev is rfcomm
+        * tty_dev, here just return 1
+        */
+       return 1;
+}
+
+static void del_conn(struct work_struct *work)
+{
+       struct device *dev;
+       struct hci_conn *conn = container_of(work, struct hci_conn, work);
+
+       while (dev = device_find_child(&conn->dev, NULL, __match_tty)) {
+               device_move(dev, NULL);
+               put_device(dev);
+       }
        device_del(&conn->dev);
+       put_device(&conn->dev);
 }
 
 void hci_conn_del_sysfs(struct hci_conn *conn)
 {
        BT_DBG("conn %p", conn);
 
-       INIT_WORK(&conn->work, del_conn, (void *) conn);
+       if (!device_is_registered(&conn->dev))
+               return;
+
+       INIT_WORK(&conn->work, del_conn);
 
        schedule_work(&conn->work);
 }
@@ -268,12 +360,8 @@ int hci_register_sysfs(struct hci_dev *hdev)
 
        BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type);
 
-       dev->class = bt_class;
-
-       if (hdev->parent)
-               dev->parent = hdev->parent;
-       else
-               dev->parent = &bt_platform->dev;
+       dev->bus = &bt_bus;
+       dev->parent = hdev->parent;
 
        strlcpy(dev->bus_id, hdev->name, BUS_ID_SIZE);
 
@@ -286,7 +374,12 @@ int hci_register_sysfs(struct hci_dev *hdev)
                return err;
 
        for (i = 0; bt_attrs[i]; i++)
-               device_create_file(dev, bt_attrs[i]);
+               if (device_create_file(dev, bt_attrs[i]) < 0)
+                       BT_ERR("Failed to create device attribute");
+
+       if (sysfs_create_link(&bt_class->subsys.kobj,
+                               &dev->kobj, kobject_name(&dev->kobj)) < 0)
+               BT_ERR("Failed to create class symlink");
 
        return 0;
 }
@@ -295,6 +388,9 @@ void hci_unregister_sysfs(struct hci_dev *hdev)
 {
        BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type);
 
+       sysfs_remove_link(&bt_class->subsys.kobj,
+                                       kobject_name(&hdev->dev.kobj));
+
        device_del(&hdev->dev);
 }
 
@@ -322,7 +418,7 @@ int __init bt_sysfs_init(void)
        return 0;
 }
 
-void __exit bt_sysfs_cleanup(void)
+void bt_sysfs_cleanup(void)
 {
        class_destroy(bt_class);