Bluetooth: Add driver setup stage for early init
authorMarcel Holtmann <marcel@holtmann.org>
Mon, 12 Nov 2012 05:02:14 +0000 (14:02 +0900)
committerJohan Hedberg <johan.hedberg@intel.com>
Thu, 4 Apr 2013 16:16:12 +0000 (19:16 +0300)
Some drivers require a special stage for their early init. This is
always specific to the driver or transport. So call back into driver to
allow bringing up the device.

The advantage with this stage is that the Bluetooth core is actually
handling the HCI layer now. This means that command and event processing
is available.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
include/net/bluetooth/hci_core.h
net/bluetooth/hci_core.c

index 47129b1ee20bf4c9407fa084d1ee684c981ac170..395e8f6982f9b60990a3f0c68b243c0ca5f61ee3 100644 (file)
@@ -293,6 +293,7 @@ struct hci_dev {
        int (*open)(struct hci_dev *hdev);
        int (*close)(struct hci_dev *hdev);
        int (*flush)(struct hci_dev *hdev);
+       int (*setup)(struct hci_dev *hdev);
        int (*send)(struct sk_buff *skb);
        void (*notify)(struct hci_dev *hdev, unsigned int evt);
        int (*ioctl)(struct hci_dev *hdev, unsigned int cmd, unsigned long arg);
index 9567e32a1f0c43b9e494370a57ac58bb750ae208..0f00b8bc279f6437ec2accd39b462164315e839f 100644 (file)
@@ -1127,26 +1127,33 @@ int hci_dev_open(__u16 dev)
                goto done;
        }
 
-       if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks))
-               set_bit(HCI_RAW, &hdev->flags);
-
-       /* Treat all non BR/EDR controllers as raw devices if
-          enable_hs is not set */
-       if (hdev->dev_type != HCI_BREDR && !enable_hs)
-               set_bit(HCI_RAW, &hdev->flags);
-
        if (hdev->open(hdev)) {
                ret = -EIO;
                goto done;
        }
 
-       if (!test_bit(HCI_RAW, &hdev->flags)) {
-               atomic_set(&hdev->cmd_cnt, 1);
-               set_bit(HCI_INIT, &hdev->flags);
-               ret = __hci_init(hdev);
-               clear_bit(HCI_INIT, &hdev->flags);
+       atomic_set(&hdev->cmd_cnt, 1);
+       set_bit(HCI_INIT, &hdev->flags);
+
+       if (hdev->setup && test_bit(HCI_SETUP, &hdev->dev_flags))
+               ret = hdev->setup(hdev);
+
+       if (!ret) {
+               /* Treat all non BR/EDR controllers as raw devices if
+                * enable_hs is not set.
+                */
+               if (hdev->dev_type != HCI_BREDR && !enable_hs)
+                       set_bit(HCI_RAW, &hdev->flags);
+
+               if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks))
+                       set_bit(HCI_RAW, &hdev->flags);
+
+               if (!test_bit(HCI_RAW, &hdev->flags))
+                       ret = __hci_init(hdev);
        }
 
+       clear_bit(HCI_INIT, &hdev->flags);
+
        if (!ret) {
                hci_dev_hold(hdev);
                set_bit(HCI_UP, &hdev->flags);