diff options
author | David S. Miller <davem@davemloft.net> | 2018-01-11 13:58:36 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-01-11 13:58:36 -0500 |
commit | 3d93e33780b059e7e95d78491692df40b18ceb5c (patch) | |
tree | 749a9c9414a94f9990d1818e0ea287ac648f67ce | |
parent | 297a6961ffb8ff4dc66c9fbf53b924bd1dda05d5 (diff) | |
parent | ff8759609d021c0e85945fcc4a148a0e55ace70f (diff) |
Merge branch 'for-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next
Johan Hedberg says:
====================
pull request: bluetooth-next 2018-01-11
Here's likely the last bluetooth-next pull request for the 4.16 kernel.
- Added support for Bluetooth on 2015+ MacBook (Pro)
- Fix to QCA Rome suspend/resume handling
- Two new QCA_ROME USB IDs in btusb
- A few other minor fixes
Please let me know if there are any issues pulling. Thanks.
====================
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | drivers/bluetooth/Kconfig | 4 | ||||
-rw-r--r-- | drivers/bluetooth/bpa10x.c | 2 | ||||
-rw-r--r-- | drivers/bluetooth/btbcm.h | 2 | ||||
-rw-r--r-- | drivers/bluetooth/btintel.c | 2 | ||||
-rw-r--r-- | drivers/bluetooth/btusb.c | 22 | ||||
-rw-r--r-- | drivers/bluetooth/hci_bcm.c | 239 |
6 files changed, 207 insertions, 64 deletions
diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig index 45a2f59cd935..07e55cd8f8c8 100644 --- a/drivers/bluetooth/Kconfig +++ b/drivers/bluetooth/Kconfig | |||
@@ -77,6 +77,7 @@ config BT_HCIBTSDIO | |||
77 | config BT_HCIUART | 77 | config BT_HCIUART |
78 | tristate "HCI UART driver" | 78 | tristate "HCI UART driver" |
79 | depends on SERIAL_DEV_BUS || !SERIAL_DEV_BUS | 79 | depends on SERIAL_DEV_BUS || !SERIAL_DEV_BUS |
80 | depends on NVMEM || !NVMEM | ||
80 | depends on TTY | 81 | depends on TTY |
81 | help | 82 | help |
82 | Bluetooth HCI UART driver. | 83 | Bluetooth HCI UART driver. |
@@ -107,6 +108,7 @@ config BT_HCIUART_NOKIA | |||
107 | tristate "UART Nokia H4+ protocol support" | 108 | tristate "UART Nokia H4+ protocol support" |
108 | depends on BT_HCIUART | 109 | depends on BT_HCIUART |
109 | depends on BT_HCIUART_SERDEV | 110 | depends on BT_HCIUART_SERDEV |
111 | depends on GPIOLIB | ||
110 | depends on PM | 112 | depends on PM |
111 | select BT_HCIUART_H4 | 113 | select BT_HCIUART_H4 |
112 | select BT_BCM | 114 | select BT_BCM |
@@ -168,6 +170,7 @@ config BT_HCIUART_3WIRE | |||
168 | config BT_HCIUART_INTEL | 170 | config BT_HCIUART_INTEL |
169 | bool "Intel protocol support" | 171 | bool "Intel protocol support" |
170 | depends on BT_HCIUART | 172 | depends on BT_HCIUART |
173 | depends on GPIOLIB | ||
171 | select BT_HCIUART_H4 | 174 | select BT_HCIUART_H4 |
172 | select BT_INTEL | 175 | select BT_INTEL |
173 | help | 176 | help |
@@ -181,6 +184,7 @@ config BT_HCIUART_BCM | |||
181 | depends on BT_HCIUART | 184 | depends on BT_HCIUART |
182 | depends on BT_HCIUART_SERDEV | 185 | depends on BT_HCIUART_SERDEV |
183 | depends on (!ACPI || SERIAL_DEV_CTRL_TTYPORT) | 186 | depends on (!ACPI || SERIAL_DEV_CTRL_TTYPORT) |
187 | depends on GPIOLIB | ||
184 | select BT_HCIUART_H4 | 188 | select BT_HCIUART_H4 |
185 | select BT_BCM | 189 | select BT_BCM |
186 | help | 190 | help |
diff --git a/drivers/bluetooth/bpa10x.c b/drivers/bluetooth/bpa10x.c index 7971bfbd4321..801ea4ca65e4 100644 --- a/drivers/bluetooth/bpa10x.c +++ b/drivers/bluetooth/bpa10x.c | |||
@@ -259,7 +259,7 @@ static int bpa10x_flush(struct hci_dev *hdev) | |||
259 | 259 | ||
260 | static int bpa10x_setup(struct hci_dev *hdev) | 260 | static int bpa10x_setup(struct hci_dev *hdev) |
261 | { | 261 | { |
262 | const u8 req[] = { 0x07 }; | 262 | static const u8 req[] = { 0x07 }; |
263 | struct sk_buff *skb; | 263 | struct sk_buff *skb; |
264 | 264 | ||
265 | BT_DBG("%s", hdev->name); | 265 | BT_DBG("%s", hdev->name); |
diff --git a/drivers/bluetooth/btbcm.h b/drivers/bluetooth/btbcm.h index d9e6b41658e5..cfe6ad4cc621 100644 --- a/drivers/bluetooth/btbcm.h +++ b/drivers/bluetooth/btbcm.h | |||
@@ -44,8 +44,8 @@ struct bcm_set_sleep_mode { | |||
44 | __u8 tristate_control; | 44 | __u8 tristate_control; |
45 | __u8 usb_auto_sleep; | 45 | __u8 usb_auto_sleep; |
46 | __u8 usb_resume_timeout; | 46 | __u8 usb_resume_timeout; |
47 | __u8 pulsed_host_wake; | ||
48 | __u8 break_to_host; | 47 | __u8 break_to_host; |
48 | __u8 pulsed_host_wake; | ||
49 | } __packed; | 49 | } __packed; |
50 | 50 | ||
51 | struct bcm_set_pcm_int_params { | 51 | struct bcm_set_pcm_int_params { |
diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c index 4459555c9d88..07f00e422e85 100644 --- a/drivers/bluetooth/btintel.c +++ b/drivers/bluetooth/btintel.c | |||
@@ -75,7 +75,7 @@ EXPORT_SYMBOL_GPL(btintel_check_bdaddr); | |||
75 | 75 | ||
76 | int btintel_enter_mfg(struct hci_dev *hdev) | 76 | int btintel_enter_mfg(struct hci_dev *hdev) |
77 | { | 77 | { |
78 | const u8 param[] = { 0x01, 0x00 }; | 78 | static const u8 param[] = { 0x01, 0x00 }; |
79 | struct sk_buff *skb; | 79 | struct sk_buff *skb; |
80 | 80 | ||
81 | skb = __hci_cmd_sync(hdev, 0xfc11, 2, param, HCI_CMD_TIMEOUT); | 81 | skb = __hci_cmd_sync(hdev, 0xfc11, 2, param, HCI_CMD_TIMEOUT); |
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 808c249845db..29977ebfd031 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c | |||
@@ -23,6 +23,7 @@ | |||
23 | 23 | ||
24 | #include <linux/module.h> | 24 | #include <linux/module.h> |
25 | #include <linux/usb.h> | 25 | #include <linux/usb.h> |
26 | #include <linux/usb/quirks.h> | ||
26 | #include <linux/firmware.h> | 27 | #include <linux/firmware.h> |
27 | #include <linux/of_device.h> | 28 | #include <linux/of_device.h> |
28 | #include <linux/of_irq.h> | 29 | #include <linux/of_irq.h> |
@@ -264,6 +265,7 @@ static const struct usb_device_id blacklist_table[] = { | |||
264 | /* QCA ROME chipset */ | 265 | /* QCA ROME chipset */ |
265 | { USB_DEVICE(0x0cf3, 0xe007), .driver_info = BTUSB_QCA_ROME }, | 266 | { USB_DEVICE(0x0cf3, 0xe007), .driver_info = BTUSB_QCA_ROME }, |
266 | { USB_DEVICE(0x0cf3, 0xe009), .driver_info = BTUSB_QCA_ROME }, | 267 | { USB_DEVICE(0x0cf3, 0xe009), .driver_info = BTUSB_QCA_ROME }, |
268 | { USB_DEVICE(0x0cf3, 0xe010), .driver_info = BTUSB_QCA_ROME }, | ||
267 | { USB_DEVICE(0x0cf3, 0xe300), .driver_info = BTUSB_QCA_ROME }, | 269 | { USB_DEVICE(0x0cf3, 0xe300), .driver_info = BTUSB_QCA_ROME }, |
268 | { USB_DEVICE(0x0cf3, 0xe301), .driver_info = BTUSB_QCA_ROME }, | 270 | { USB_DEVICE(0x0cf3, 0xe301), .driver_info = BTUSB_QCA_ROME }, |
269 | { USB_DEVICE(0x0cf3, 0xe360), .driver_info = BTUSB_QCA_ROME }, | 271 | { USB_DEVICE(0x0cf3, 0xe360), .driver_info = BTUSB_QCA_ROME }, |
@@ -271,6 +273,7 @@ static const struct usb_device_id blacklist_table[] = { | |||
271 | { USB_DEVICE(0x0489, 0xe09f), .driver_info = BTUSB_QCA_ROME }, | 273 | { USB_DEVICE(0x0489, 0xe09f), .driver_info = BTUSB_QCA_ROME }, |
272 | { USB_DEVICE(0x0489, 0xe0a2), .driver_info = BTUSB_QCA_ROME }, | 274 | { USB_DEVICE(0x0489, 0xe0a2), .driver_info = BTUSB_QCA_ROME }, |
273 | { USB_DEVICE(0x04ca, 0x3011), .driver_info = BTUSB_QCA_ROME }, | 275 | { USB_DEVICE(0x04ca, 0x3011), .driver_info = BTUSB_QCA_ROME }, |
276 | { USB_DEVICE(0x04ca, 0x3015), .driver_info = BTUSB_QCA_ROME }, | ||
274 | { USB_DEVICE(0x04ca, 0x3016), .driver_info = BTUSB_QCA_ROME }, | 277 | { USB_DEVICE(0x04ca, 0x3016), .driver_info = BTUSB_QCA_ROME }, |
275 | 278 | ||
276 | /* Broadcom BCM2035 */ | 279 | /* Broadcom BCM2035 */ |
@@ -388,9 +391,8 @@ static const struct usb_device_id blacklist_table[] = { | |||
388 | #define BTUSB_FIRMWARE_LOADED 7 | 391 | #define BTUSB_FIRMWARE_LOADED 7 |
389 | #define BTUSB_FIRMWARE_FAILED 8 | 392 | #define BTUSB_FIRMWARE_FAILED 8 |
390 | #define BTUSB_BOOTING 9 | 393 | #define BTUSB_BOOTING 9 |
391 | #define BTUSB_RESET_RESUME 10 | 394 | #define BTUSB_DIAG_RUNNING 10 |
392 | #define BTUSB_DIAG_RUNNING 11 | 395 | #define BTUSB_OOB_WAKE_ENABLED 11 |
393 | #define BTUSB_OOB_WAKE_ENABLED 12 | ||
394 | 396 | ||
395 | struct btusb_data { | 397 | struct btusb_data { |
396 | struct hci_dev *hdev; | 398 | struct hci_dev *hdev; |
@@ -3121,9 +3123,9 @@ static int btusb_probe(struct usb_interface *intf, | |||
3121 | 3123 | ||
3122 | /* QCA Rome devices lose their updated firmware over suspend, | 3124 | /* QCA Rome devices lose their updated firmware over suspend, |
3123 | * but the USB hub doesn't notice any status change. | 3125 | * but the USB hub doesn't notice any status change. |
3124 | * Explicitly request a device reset on resume. | 3126 | * explicitly request a device reset on resume. |
3125 | */ | 3127 | */ |
3126 | set_bit(BTUSB_RESET_RESUME, &data->flags); | 3128 | interface_to_usbdev(intf)->quirks |= USB_QUIRK_RESET_RESUME; |
3127 | } | 3129 | } |
3128 | 3130 | ||
3129 | #ifdef CONFIG_BT_HCIBTUSB_RTL | 3131 | #ifdef CONFIG_BT_HCIBTUSB_RTL |
@@ -3134,7 +3136,7 @@ static int btusb_probe(struct usb_interface *intf, | |||
3134 | * but the USB hub doesn't notice any status change. | 3136 | * but the USB hub doesn't notice any status change. |
3135 | * Explicitly request a device reset on resume. | 3137 | * Explicitly request a device reset on resume. |
3136 | */ | 3138 | */ |
3137 | set_bit(BTUSB_RESET_RESUME, &data->flags); | 3139 | interface_to_usbdev(intf)->quirks |= USB_QUIRK_RESET_RESUME; |
3138 | } | 3140 | } |
3139 | #endif | 3141 | #endif |
3140 | 3142 | ||
@@ -3303,14 +3305,6 @@ static int btusb_suspend(struct usb_interface *intf, pm_message_t message) | |||
3303 | enable_irq(data->oob_wake_irq); | 3305 | enable_irq(data->oob_wake_irq); |
3304 | } | 3306 | } |
3305 | 3307 | ||
3306 | /* Optionally request a device reset on resume, but only when | ||
3307 | * wakeups are disabled. If wakeups are enabled we assume the | ||
3308 | * device will stay powered up throughout suspend. | ||
3309 | */ | ||
3310 | if (test_bit(BTUSB_RESET_RESUME, &data->flags) && | ||
3311 | !device_may_wakeup(&data->udev->dev)) | ||
3312 | data->udev->reset_resume = 1; | ||
3313 | |||
3314 | return 0; | 3308 | return 0; |
3315 | } | 3309 | } |
3316 | 3310 | ||
diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c index 47fc58c9eb49..64800cd2796c 100644 --- a/drivers/bluetooth/hci_bcm.c +++ b/drivers/bluetooth/hci_bcm.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include <linux/acpi.h> | 29 | #include <linux/acpi.h> |
30 | #include <linux/of.h> | 30 | #include <linux/of.h> |
31 | #include <linux/property.h> | 31 | #include <linux/property.h> |
32 | #include <linux/platform_data/x86/apple.h> | ||
32 | #include <linux/platform_device.h> | 33 | #include <linux/platform_device.h> |
33 | #include <linux/clk.h> | 34 | #include <linux/clk.h> |
34 | #include <linux/gpio/consumer.h> | 35 | #include <linux/gpio/consumer.h> |
@@ -52,7 +53,37 @@ | |||
52 | 53 | ||
53 | #define BCM_AUTOSUSPEND_DELAY 5000 /* default autosleep delay */ | 54 | #define BCM_AUTOSUSPEND_DELAY 5000 /* default autosleep delay */ |
54 | 55 | ||
55 | /* device driver resources */ | 56 | /** |
57 | * struct bcm_device - device driver resources | ||
58 | * @serdev_hu: HCI UART controller struct | ||
59 | * @list: bcm_device_list node | ||
60 | * @dev: physical UART slave | ||
61 | * @name: device name logged by bt_dev_*() functions | ||
62 | * @device_wakeup: BT_WAKE pin, | ||
63 | * assert = Bluetooth device must wake up or remain awake, | ||
64 | * deassert = Bluetooth device may sleep when sleep criteria are met | ||
65 | * @shutdown: BT_REG_ON pin, | ||
66 | * power up or power down Bluetooth device internal regulators | ||
67 | * @set_device_wakeup: callback to toggle BT_WAKE pin | ||
68 | * either by accessing @device_wakeup or by calling @btlp | ||
69 | * @set_shutdown: callback to toggle BT_REG_ON pin | ||
70 | * either by accessing @shutdown or by calling @btpu/@btpd | ||
71 | * @btlp: Apple ACPI method to toggle BT_WAKE pin ("Bluetooth Low Power") | ||
72 | * @btpu: Apple ACPI method to drive BT_REG_ON pin high ("Bluetooth Power Up") | ||
73 | * @btpd: Apple ACPI method to drive BT_REG_ON pin low ("Bluetooth Power Down") | ||
74 | * @clk: clock used by Bluetooth device | ||
75 | * @clk_enabled: whether @clk is prepared and enabled | ||
76 | * @init_speed: default baudrate of Bluetooth device; | ||
77 | * the host UART is initially set to this baudrate so that | ||
78 | * it can configure the Bluetooth device for @oper_speed | ||
79 | * @oper_speed: preferred baudrate of Bluetooth device; | ||
80 | * set to 0 if @init_speed is already the preferred baudrate | ||
81 | * @irq: interrupt triggered by HOST_WAKE_BT pin | ||
82 | * @irq_active_low: whether @irq is active low | ||
83 | * @hu: pointer to HCI UART controller struct, | ||
84 | * used to disable flow control during runtime suspend and system sleep | ||
85 | * @is_suspended: whether flow control is currently disabled | ||
86 | */ | ||
56 | struct bcm_device { | 87 | struct bcm_device { |
57 | /* Must be the first member, hci_serdev.c expects this. */ | 88 | /* Must be the first member, hci_serdev.c expects this. */ |
58 | struct hci_uart serdev_hu; | 89 | struct hci_uart serdev_hu; |
@@ -63,6 +94,11 @@ struct bcm_device { | |||
63 | const char *name; | 94 | const char *name; |
64 | struct gpio_desc *device_wakeup; | 95 | struct gpio_desc *device_wakeup; |
65 | struct gpio_desc *shutdown; | 96 | struct gpio_desc *shutdown; |
97 | int (*set_device_wakeup)(struct bcm_device *, bool); | ||
98 | int (*set_shutdown)(struct bcm_device *, bool); | ||
99 | #ifdef CONFIG_ACPI | ||
100 | acpi_handle btlp, btpu, btpd; | ||
101 | #endif | ||
66 | 102 | ||
67 | struct clk *clk; | 103 | struct clk *clk; |
68 | bool clk_enabled; | 104 | bool clk_enabled; |
@@ -74,7 +110,7 @@ struct bcm_device { | |||
74 | 110 | ||
75 | #ifdef CONFIG_PM | 111 | #ifdef CONFIG_PM |
76 | struct hci_uart *hu; | 112 | struct hci_uart *hu; |
77 | bool is_suspended; /* suspend/resume flag */ | 113 | bool is_suspended; |
78 | #endif | 114 | #endif |
79 | }; | 115 | }; |
80 | 116 | ||
@@ -170,11 +206,21 @@ static bool bcm_device_exists(struct bcm_device *device) | |||
170 | 206 | ||
171 | static int bcm_gpio_set_power(struct bcm_device *dev, bool powered) | 207 | static int bcm_gpio_set_power(struct bcm_device *dev, bool powered) |
172 | { | 208 | { |
173 | if (powered && !IS_ERR(dev->clk) && !dev->clk_enabled) | 209 | int err; |
174 | clk_prepare_enable(dev->clk); | ||
175 | 210 | ||
176 | gpiod_set_value(dev->shutdown, powered); | 211 | if (powered && !IS_ERR(dev->clk) && !dev->clk_enabled) { |
177 | gpiod_set_value(dev->device_wakeup, powered); | 212 | err = clk_prepare_enable(dev->clk); |
213 | if (err) | ||
214 | return err; | ||
215 | } | ||
216 | |||
217 | err = dev->set_shutdown(dev, powered); | ||
218 | if (err) | ||
219 | goto err_clk_disable; | ||
220 | |||
221 | err = dev->set_device_wakeup(dev, powered); | ||
222 | if (err) | ||
223 | goto err_revert_shutdown; | ||
178 | 224 | ||
179 | if (!powered && !IS_ERR(dev->clk) && dev->clk_enabled) | 225 | if (!powered && !IS_ERR(dev->clk) && dev->clk_enabled) |
180 | clk_disable_unprepare(dev->clk); | 226 | clk_disable_unprepare(dev->clk); |
@@ -182,6 +228,13 @@ static int bcm_gpio_set_power(struct bcm_device *dev, bool powered) | |||
182 | dev->clk_enabled = powered; | 228 | dev->clk_enabled = powered; |
183 | 229 | ||
184 | return 0; | 230 | return 0; |
231 | |||
232 | err_revert_shutdown: | ||
233 | dev->set_shutdown(dev, !powered); | ||
234 | err_clk_disable: | ||
235 | if (powered && !IS_ERR(dev->clk) && !dev->clk_enabled) | ||
236 | clk_disable_unprepare(dev->clk); | ||
237 | return err; | ||
185 | } | 238 | } |
186 | 239 | ||
187 | #ifdef CONFIG_PM | 240 | #ifdef CONFIG_PM |
@@ -191,9 +244,7 @@ static irqreturn_t bcm_host_wake(int irq, void *data) | |||
191 | 244 | ||
192 | bt_dev_dbg(bdev, "Host wake IRQ"); | 245 | bt_dev_dbg(bdev, "Host wake IRQ"); |
193 | 246 | ||
194 | pm_runtime_get(bdev->dev); | 247 | pm_request_resume(bdev->dev); |
195 | pm_runtime_mark_last_busy(bdev->dev); | ||
196 | pm_runtime_put_autosuspend(bdev->dev); | ||
197 | 248 | ||
198 | return IRQ_HANDLED; | 249 | return IRQ_HANDLED; |
199 | } | 250 | } |
@@ -218,8 +269,10 @@ static int bcm_request_irq(struct bcm_data *bcm) | |||
218 | bdev->irq_active_low ? IRQF_TRIGGER_FALLING : | 269 | bdev->irq_active_low ? IRQF_TRIGGER_FALLING : |
219 | IRQF_TRIGGER_RISING, | 270 | IRQF_TRIGGER_RISING, |
220 | "host_wake", bdev); | 271 | "host_wake", bdev); |
221 | if (err) | 272 | if (err) { |
273 | bdev->irq = err; | ||
222 | goto unlock; | 274 | goto unlock; |
275 | } | ||
223 | 276 | ||
224 | device_init_wakeup(bdev->dev, true); | 277 | device_init_wakeup(bdev->dev, true); |
225 | 278 | ||
@@ -247,8 +300,8 @@ static const struct bcm_set_sleep_mode default_sleep_params = { | |||
247 | /* Irrelevant USB flags */ | 300 | /* Irrelevant USB flags */ |
248 | .usb_auto_sleep = 0, | 301 | .usb_auto_sleep = 0, |
249 | .usb_resume_timeout = 0, | 302 | .usb_resume_timeout = 0, |
303 | .break_to_host = 0, | ||
250 | .pulsed_host_wake = 0, | 304 | .pulsed_host_wake = 0, |
251 | .break_to_host = 0 | ||
252 | }; | 305 | }; |
253 | 306 | ||
254 | static int bcm_setup_sleep(struct hci_uart *hu) | 307 | static int bcm_setup_sleep(struct hci_uart *hu) |
@@ -304,6 +357,7 @@ static int bcm_open(struct hci_uart *hu) | |||
304 | { | 357 | { |
305 | struct bcm_data *bcm; | 358 | struct bcm_data *bcm; |
306 | struct list_head *p; | 359 | struct list_head *p; |
360 | int err; | ||
307 | 361 | ||
308 | bt_dev_dbg(hu->hdev, "hu %p", hu); | 362 | bt_dev_dbg(hu->hdev, "hu %p", hu); |
309 | 363 | ||
@@ -318,7 +372,10 @@ static int bcm_open(struct hci_uart *hu) | |||
318 | mutex_lock(&bcm_device_lock); | 372 | mutex_lock(&bcm_device_lock); |
319 | 373 | ||
320 | if (hu->serdev) { | 374 | if (hu->serdev) { |
321 | serdev_device_open(hu->serdev); | 375 | err = serdev_device_open(hu->serdev); |
376 | if (err) | ||
377 | goto err_free; | ||
378 | |||
322 | bcm->dev = serdev_device_get_drvdata(hu->serdev); | 379 | bcm->dev = serdev_device_get_drvdata(hu->serdev); |
323 | goto out; | 380 | goto out; |
324 | } | 381 | } |
@@ -346,17 +403,30 @@ out: | |||
346 | if (bcm->dev) { | 403 | if (bcm->dev) { |
347 | hu->init_speed = bcm->dev->init_speed; | 404 | hu->init_speed = bcm->dev->init_speed; |
348 | hu->oper_speed = bcm->dev->oper_speed; | 405 | hu->oper_speed = bcm->dev->oper_speed; |
349 | bcm_gpio_set_power(bcm->dev, true); | 406 | err = bcm_gpio_set_power(bcm->dev, true); |
407 | if (err) | ||
408 | goto err_unset_hu; | ||
350 | } | 409 | } |
351 | 410 | ||
352 | mutex_unlock(&bcm_device_lock); | 411 | mutex_unlock(&bcm_device_lock); |
353 | return 0; | 412 | return 0; |
413 | |||
414 | err_unset_hu: | ||
415 | #ifdef CONFIG_PM | ||
416 | bcm->dev->hu = NULL; | ||
417 | #endif | ||
418 | err_free: | ||
419 | mutex_unlock(&bcm_device_lock); | ||
420 | hu->priv = NULL; | ||
421 | kfree(bcm); | ||
422 | return err; | ||
354 | } | 423 | } |
355 | 424 | ||
356 | static int bcm_close(struct hci_uart *hu) | 425 | static int bcm_close(struct hci_uart *hu) |
357 | { | 426 | { |
358 | struct bcm_data *bcm = hu->priv; | 427 | struct bcm_data *bcm = hu->priv; |
359 | struct bcm_device *bdev = NULL; | 428 | struct bcm_device *bdev = NULL; |
429 | int err; | ||
360 | 430 | ||
361 | bt_dev_dbg(hu->hdev, "hu %p", hu); | 431 | bt_dev_dbg(hu->hdev, "hu %p", hu); |
362 | 432 | ||
@@ -374,16 +444,17 @@ static int bcm_close(struct hci_uart *hu) | |||
374 | } | 444 | } |
375 | 445 | ||
376 | if (bdev) { | 446 | if (bdev) { |
377 | bcm_gpio_set_power(bdev, false); | 447 | if (IS_ENABLED(CONFIG_PM) && bdev->irq > 0) { |
378 | #ifdef CONFIG_PM | ||
379 | pm_runtime_disable(bdev->dev); | ||
380 | pm_runtime_set_suspended(bdev->dev); | ||
381 | |||
382 | if (device_can_wakeup(bdev->dev)) { | ||
383 | devm_free_irq(bdev->dev, bdev->irq, bdev); | 448 | devm_free_irq(bdev->dev, bdev->irq, bdev); |
384 | device_init_wakeup(bdev->dev, false); | 449 | device_init_wakeup(bdev->dev, false); |
450 | pm_runtime_disable(bdev->dev); | ||
385 | } | 451 | } |
386 | #endif | 452 | |
453 | err = bcm_gpio_set_power(bdev, false); | ||
454 | if (err) | ||
455 | bt_dev_err(hu->hdev, "Failed to power down"); | ||
456 | else | ||
457 | pm_runtime_set_suspended(bdev->dev); | ||
387 | } | 458 | } |
388 | mutex_unlock(&bcm_device_lock); | 459 | mutex_unlock(&bcm_device_lock); |
389 | 460 | ||
@@ -512,11 +583,8 @@ static int bcm_recv(struct hci_uart *hu, const void *data, int count) | |||
512 | } else if (!bcm->rx_skb) { | 583 | } else if (!bcm->rx_skb) { |
513 | /* Delay auto-suspend when receiving completed packet */ | 584 | /* Delay auto-suspend when receiving completed packet */ |
514 | mutex_lock(&bcm_device_lock); | 585 | mutex_lock(&bcm_device_lock); |
515 | if (bcm->dev && bcm_device_exists(bcm->dev)) { | 586 | if (bcm->dev && bcm_device_exists(bcm->dev)) |
516 | pm_runtime_get(bcm->dev->dev); | 587 | pm_request_resume(bcm->dev->dev); |
517 | pm_runtime_mark_last_busy(bcm->dev->dev); | ||
518 | pm_runtime_put_autosuspend(bcm->dev->dev); | ||
519 | } | ||
520 | mutex_unlock(&bcm_device_lock); | 588 | mutex_unlock(&bcm_device_lock); |
521 | } | 589 | } |
522 | 590 | ||
@@ -566,6 +634,7 @@ static struct sk_buff *bcm_dequeue(struct hci_uart *hu) | |||
566 | static int bcm_suspend_device(struct device *dev) | 634 | static int bcm_suspend_device(struct device *dev) |
567 | { | 635 | { |
568 | struct bcm_device *bdev = dev_get_drvdata(dev); | 636 | struct bcm_device *bdev = dev_get_drvdata(dev); |
637 | int err; | ||
569 | 638 | ||
570 | bt_dev_dbg(bdev, ""); | 639 | bt_dev_dbg(bdev, ""); |
571 | 640 | ||
@@ -577,27 +646,37 @@ static int bcm_suspend_device(struct device *dev) | |||
577 | } | 646 | } |
578 | 647 | ||
579 | /* Suspend the device */ | 648 | /* Suspend the device */ |
580 | if (bdev->device_wakeup) { | 649 | err = bdev->set_device_wakeup(bdev, false); |
581 | gpiod_set_value(bdev->device_wakeup, false); | 650 | if (err) { |
582 | bt_dev_dbg(bdev, "suspend, delaying 15 ms"); | 651 | if (bdev->is_suspended && bdev->hu) { |
583 | mdelay(15); | 652 | bdev->is_suspended = false; |
653 | hci_uart_set_flow_control(bdev->hu, false); | ||
654 | } | ||
655 | return -EBUSY; | ||
584 | } | 656 | } |
585 | 657 | ||
658 | bt_dev_dbg(bdev, "suspend, delaying 15 ms"); | ||
659 | msleep(15); | ||
660 | |||
586 | return 0; | 661 | return 0; |
587 | } | 662 | } |
588 | 663 | ||
589 | static int bcm_resume_device(struct device *dev) | 664 | static int bcm_resume_device(struct device *dev) |
590 | { | 665 | { |
591 | struct bcm_device *bdev = dev_get_drvdata(dev); | 666 | struct bcm_device *bdev = dev_get_drvdata(dev); |
667 | int err; | ||
592 | 668 | ||
593 | bt_dev_dbg(bdev, ""); | 669 | bt_dev_dbg(bdev, ""); |
594 | 670 | ||
595 | if (bdev->device_wakeup) { | 671 | err = bdev->set_device_wakeup(bdev, true); |
596 | gpiod_set_value(bdev->device_wakeup, true); | 672 | if (err) { |
597 | bt_dev_dbg(bdev, "resume, delaying 15 ms"); | 673 | dev_err(dev, "Failed to power up\n"); |
598 | mdelay(15); | 674 | return err; |
599 | } | 675 | } |
600 | 676 | ||
677 | bt_dev_dbg(bdev, "resume, delaying 15 ms"); | ||
678 | msleep(15); | ||
679 | |||
601 | /* When this executes, the device has woken up already */ | 680 | /* When this executes, the device has woken up already */ |
602 | if (bdev->is_suspended && bdev->hu) { | 681 | if (bdev->is_suspended && bdev->hu) { |
603 | bdev->is_suspended = false; | 682 | bdev->is_suspended = false; |
@@ -632,7 +711,7 @@ static int bcm_suspend(struct device *dev) | |||
632 | if (pm_runtime_active(dev)) | 711 | if (pm_runtime_active(dev)) |
633 | bcm_suspend_device(dev); | 712 | bcm_suspend_device(dev); |
634 | 713 | ||
635 | if (device_may_wakeup(dev)) { | 714 | if (device_may_wakeup(dev) && bdev->irq > 0) { |
636 | error = enable_irq_wake(bdev->irq); | 715 | error = enable_irq_wake(bdev->irq); |
637 | if (!error) | 716 | if (!error) |
638 | bt_dev_dbg(bdev, "BCM irq: enabled"); | 717 | bt_dev_dbg(bdev, "BCM irq: enabled"); |
@@ -648,6 +727,7 @@ unlock: | |||
648 | static int bcm_resume(struct device *dev) | 727 | static int bcm_resume(struct device *dev) |
649 | { | 728 | { |
650 | struct bcm_device *bdev = dev_get_drvdata(dev); | 729 | struct bcm_device *bdev = dev_get_drvdata(dev); |
730 | int err = 0; | ||
651 | 731 | ||
652 | bt_dev_dbg(bdev, "resume: is_suspended %d", bdev->is_suspended); | 732 | bt_dev_dbg(bdev, "resume: is_suspended %d", bdev->is_suspended); |
653 | 733 | ||
@@ -662,19 +742,21 @@ static int bcm_resume(struct device *dev) | |||
662 | if (!bdev->hu) | 742 | if (!bdev->hu) |
663 | goto unlock; | 743 | goto unlock; |
664 | 744 | ||
665 | if (device_may_wakeup(dev)) { | 745 | if (device_may_wakeup(dev) && bdev->irq > 0) { |
666 | disable_irq_wake(bdev->irq); | 746 | disable_irq_wake(bdev->irq); |
667 | bt_dev_dbg(bdev, "BCM irq: disabled"); | 747 | bt_dev_dbg(bdev, "BCM irq: disabled"); |
668 | } | 748 | } |
669 | 749 | ||
670 | bcm_resume_device(dev); | 750 | err = bcm_resume_device(dev); |
671 | 751 | ||
672 | unlock: | 752 | unlock: |
673 | mutex_unlock(&bcm_device_lock); | 753 | mutex_unlock(&bcm_device_lock); |
674 | 754 | ||
675 | pm_runtime_disable(dev); | 755 | if (!err) { |
676 | pm_runtime_set_active(dev); | 756 | pm_runtime_disable(dev); |
677 | pm_runtime_enable(dev); | 757 | pm_runtime_set_active(dev); |
758 | pm_runtime_enable(dev); | ||
759 | } | ||
678 | 760 | ||
679 | return 0; | 761 | return 0; |
680 | } | 762 | } |
@@ -771,25 +853,84 @@ static int bcm_resource(struct acpi_resource *ares, void *data) | |||
771 | 853 | ||
772 | return 0; | 854 | return 0; |
773 | } | 855 | } |
856 | |||
857 | static int bcm_apple_set_device_wakeup(struct bcm_device *dev, bool awake) | ||
858 | { | ||
859 | if (ACPI_FAILURE(acpi_execute_simple_method(dev->btlp, NULL, !awake))) | ||
860 | return -EIO; | ||
861 | |||
862 | return 0; | ||
863 | } | ||
864 | |||
865 | static int bcm_apple_set_shutdown(struct bcm_device *dev, bool powered) | ||
866 | { | ||
867 | if (ACPI_FAILURE(acpi_evaluate_object(powered ? dev->btpu : dev->btpd, | ||
868 | NULL, NULL, NULL))) | ||
869 | return -EIO; | ||
870 | |||
871 | return 0; | ||
872 | } | ||
873 | |||
874 | static int bcm_apple_get_resources(struct bcm_device *dev) | ||
875 | { | ||
876 | struct acpi_device *adev = ACPI_COMPANION(dev->dev); | ||
877 | const union acpi_object *obj; | ||
878 | |||
879 | if (!adev || | ||
880 | ACPI_FAILURE(acpi_get_handle(adev->handle, "BTLP", &dev->btlp)) || | ||
881 | ACPI_FAILURE(acpi_get_handle(adev->handle, "BTPU", &dev->btpu)) || | ||
882 | ACPI_FAILURE(acpi_get_handle(adev->handle, "BTPD", &dev->btpd))) | ||
883 | return -ENODEV; | ||
884 | |||
885 | if (!acpi_dev_get_property(adev, "baud", ACPI_TYPE_BUFFER, &obj) && | ||
886 | obj->buffer.length == 8) | ||
887 | dev->init_speed = *(u64 *)obj->buffer.pointer; | ||
888 | |||
889 | dev->set_device_wakeup = bcm_apple_set_device_wakeup; | ||
890 | dev->set_shutdown = bcm_apple_set_shutdown; | ||
891 | |||
892 | return 0; | ||
893 | } | ||
894 | #else | ||
895 | static inline int bcm_apple_get_resources(struct bcm_device *dev) | ||
896 | { | ||
897 | return -EOPNOTSUPP; | ||
898 | } | ||
774 | #endif /* CONFIG_ACPI */ | 899 | #endif /* CONFIG_ACPI */ |
775 | 900 | ||
901 | static int bcm_gpio_set_device_wakeup(struct bcm_device *dev, bool awake) | ||
902 | { | ||
903 | gpiod_set_value(dev->device_wakeup, awake); | ||
904 | return 0; | ||
905 | } | ||
906 | |||
907 | static int bcm_gpio_set_shutdown(struct bcm_device *dev, bool powered) | ||
908 | { | ||
909 | gpiod_set_value(dev->shutdown, powered); | ||
910 | return 0; | ||
911 | } | ||
912 | |||
776 | static int bcm_get_resources(struct bcm_device *dev) | 913 | static int bcm_get_resources(struct bcm_device *dev) |
777 | { | 914 | { |
778 | dev->name = dev_name(dev->dev); | 915 | dev->name = dev_name(dev->dev); |
779 | 916 | ||
917 | if (x86_apple_machine && !bcm_apple_get_resources(dev)) | ||
918 | return 0; | ||
919 | |||
780 | dev->clk = devm_clk_get(dev->dev, NULL); | 920 | dev->clk = devm_clk_get(dev->dev, NULL); |
781 | 921 | ||
782 | dev->device_wakeup = devm_gpiod_get_optional(dev->dev, | 922 | dev->device_wakeup = devm_gpiod_get(dev->dev, "device-wakeup", |
783 | "device-wakeup", | 923 | GPIOD_OUT_LOW); |
784 | GPIOD_OUT_LOW); | ||
785 | if (IS_ERR(dev->device_wakeup)) | 924 | if (IS_ERR(dev->device_wakeup)) |
786 | return PTR_ERR(dev->device_wakeup); | 925 | return PTR_ERR(dev->device_wakeup); |
787 | 926 | ||
788 | dev->shutdown = devm_gpiod_get_optional(dev->dev, "shutdown", | 927 | dev->shutdown = devm_gpiod_get(dev->dev, "shutdown", GPIOD_OUT_LOW); |
789 | GPIOD_OUT_LOW); | ||
790 | if (IS_ERR(dev->shutdown)) | 928 | if (IS_ERR(dev->shutdown)) |
791 | return PTR_ERR(dev->shutdown); | 929 | return PTR_ERR(dev->shutdown); |
792 | 930 | ||
931 | dev->set_device_wakeup = bcm_gpio_set_device_wakeup; | ||
932 | dev->set_shutdown = bcm_gpio_set_shutdown; | ||
933 | |||
793 | /* IRQ can be declared in ACPI table as Interrupt or GpioInt */ | 934 | /* IRQ can be declared in ACPI table as Interrupt or GpioInt */ |
794 | if (dev->irq <= 0) { | 935 | if (dev->irq <= 0) { |
795 | struct gpio_desc *gpio; | 936 | struct gpio_desc *gpio; |
@@ -802,7 +943,7 @@ static int bcm_get_resources(struct bcm_device *dev) | |||
802 | dev->irq = gpiod_to_irq(gpio); | 943 | dev->irq = gpiod_to_irq(gpio); |
803 | } | 944 | } |
804 | 945 | ||
805 | dev_info(dev->dev, "BCM irq: %d\n", dev->irq); | 946 | dev_dbg(dev->dev, "BCM irq: %d\n", dev->irq); |
806 | return 0; | 947 | return 0; |
807 | } | 948 | } |
808 | 949 | ||
@@ -892,7 +1033,9 @@ static int bcm_probe(struct platform_device *pdev) | |||
892 | list_add_tail(&dev->list, &bcm_device_list); | 1033 | list_add_tail(&dev->list, &bcm_device_list); |
893 | mutex_unlock(&bcm_device_lock); | 1034 | mutex_unlock(&bcm_device_lock); |
894 | 1035 | ||
895 | bcm_gpio_set_power(dev, false); | 1036 | ret = bcm_gpio_set_power(dev, false); |
1037 | if (ret) | ||
1038 | dev_err(&pdev->dev, "Failed to power down\n"); | ||
896 | 1039 | ||
897 | return 0; | 1040 | return 0; |
898 | } | 1041 | } |
@@ -994,7 +1137,9 @@ static int bcm_serdev_probe(struct serdev_device *serdev) | |||
994 | if (err) | 1137 | if (err) |
995 | return err; | 1138 | return err; |
996 | 1139 | ||
997 | bcm_gpio_set_power(bcmdev, false); | 1140 | err = bcm_gpio_set_power(bcmdev, false); |
1141 | if (err) | ||
1142 | dev_err(&serdev->dev, "Failed to power down\n"); | ||
998 | 1143 | ||
999 | return hci_uart_register_device(&bcmdev->serdev_hu, &bcm_proto); | 1144 | return hci_uart_register_device(&bcmdev->serdev_hu, &bcm_proto); |
1000 | } | 1145 | } |