3 * Bluetooth HCI UART driver for Broadcom devices
5 * Copyright (C) 2015 Intel Corporation
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <linux/kernel.h>
25 #include <linux/errno.h>
26 #include <linux/skbuff.h>
27 #include <linux/firmware.h>
28 #include <linux/module.h>
29 #include <linux/acpi.h>
31 #include <linux/property.h>
32 #include <linux/platform_device.h>
33 #include <linux/clk.h>
34 #include <linux/gpio/consumer.h>
35 #include <linux/tty.h>
36 #include <linux/interrupt.h>
37 #include <linux/dmi.h>
38 #include <linux/pm_runtime.h>
39 #include <linux/serdev.h>
41 #include <net/bluetooth/bluetooth.h>
42 #include <net/bluetooth/hci_core.h>
47 #define BCM_NULL_PKT 0x00
48 #define BCM_NULL_SIZE 0
50 #define BCM_LM_DIAG_PKT 0x07
51 #define BCM_LM_DIAG_SIZE 63
53 #define BCM_TYPE49_PKT 0x31
54 #define BCM_TYPE49_SIZE 0
56 #define BCM_TYPE52_PKT 0x34
57 #define BCM_TYPE52_SIZE 0
59 #define BCM_AUTOSUSPEND_DELAY 5000 /* default autosleep delay */
61 /* device driver resources */
63 /* Must be the first member, hci_serdev.c expects this. */
64 struct hci_uart serdev_hu
;
65 struct list_head list
;
70 struct gpio_desc
*device_wakeup
;
71 struct gpio_desc
*shutdown
;
83 bool is_suspended
; /* suspend/resume flag */
87 /* generic bcm uart resources */
89 struct sk_buff
*rx_skb
;
90 struct sk_buff_head txq
;
92 struct bcm_device
*dev
;
95 /* List of BCM BT UART devices */
96 static DEFINE_MUTEX(bcm_device_lock
);
97 static LIST_HEAD(bcm_device_list
);
99 static int irq_polarity
= -1;
100 module_param(irq_polarity
, int, 0444);
101 MODULE_PARM_DESC(irq_polarity
, "IRQ polarity 0: active-high 1: active-low");
103 static inline void host_set_baudrate(struct hci_uart
*hu
, unsigned int speed
)
106 serdev_device_set_baudrate(hu
->serdev
, speed
);
108 hci_uart_set_baudrate(hu
, speed
);
111 static int bcm_set_baudrate(struct hci_uart
*hu
, unsigned int speed
)
113 struct hci_dev
*hdev
= hu
->hdev
;
115 struct bcm_update_uart_baud_rate param
;
117 if (speed
> 3000000) {
118 struct bcm_write_uart_clock_setting clock
;
120 clock
.type
= BCM_UART_CLOCK_48MHZ
;
122 bt_dev_dbg(hdev
, "Set Controller clock (%d)", clock
.type
);
124 /* This Broadcom specific command changes the UART's controller
125 * clock for baud rate > 3000000.
127 skb
= __hci_cmd_sync(hdev
, 0xfc45, 1, &clock
, HCI_INIT_TIMEOUT
);
129 int err
= PTR_ERR(skb
);
130 bt_dev_err(hdev
, "BCM: failed to write clock (%d)",
138 bt_dev_dbg(hdev
, "Set Controller UART speed to %d bit/s", speed
);
140 param
.zero
= cpu_to_le16(0);
141 param
.baud_rate
= cpu_to_le32(speed
);
143 /* This Broadcom specific command changes the UART's controller baud
146 skb
= __hci_cmd_sync(hdev
, 0xfc18, sizeof(param
), ¶m
,
149 int err
= PTR_ERR(skb
);
150 bt_dev_err(hdev
, "BCM: failed to write update baudrate (%d)",
160 /* bcm_device_exists should be protected by bcm_device_lock */
161 static bool bcm_device_exists(struct bcm_device
*device
)
166 /* Devices using serdev always exist */
167 if (device
&& device
->hu
&& device
->hu
->serdev
)
171 list_for_each(p
, &bcm_device_list
) {
172 struct bcm_device
*dev
= list_entry(p
, struct bcm_device
, list
);
181 static int bcm_gpio_set_power(struct bcm_device
*dev
, bool powered
)
183 if (powered
&& !IS_ERR(dev
->clk
) && !dev
->clk_enabled
)
184 clk_prepare_enable(dev
->clk
);
186 gpiod_set_value(dev
->shutdown
, powered
);
187 gpiod_set_value(dev
->device_wakeup
, powered
);
189 if (!powered
&& !IS_ERR(dev
->clk
) && dev
->clk_enabled
)
190 clk_disable_unprepare(dev
->clk
);
192 dev
->clk_enabled
= powered
;
198 static irqreturn_t
bcm_host_wake(int irq
, void *data
)
200 struct bcm_device
*bdev
= data
;
202 bt_dev_dbg(bdev
, "Host wake IRQ");
204 pm_runtime_get(bdev
->dev
);
205 pm_runtime_mark_last_busy(bdev
->dev
);
206 pm_runtime_put_autosuspend(bdev
->dev
);
211 static int bcm_request_irq(struct bcm_data
*bcm
)
213 struct bcm_device
*bdev
= bcm
->dev
;
216 mutex_lock(&bcm_device_lock
);
217 if (!bcm_device_exists(bdev
)) {
222 if (bdev
->irq
<= 0) {
227 err
= devm_request_irq(bdev
->dev
, bdev
->irq
, bcm_host_wake
,
228 bdev
->irq_active_low
? IRQF_TRIGGER_FALLING
:
234 device_init_wakeup(bdev
->dev
, true);
236 pm_runtime_set_autosuspend_delay(bdev
->dev
,
237 BCM_AUTOSUSPEND_DELAY
);
238 pm_runtime_use_autosuspend(bdev
->dev
);
239 pm_runtime_set_active(bdev
->dev
);
240 pm_runtime_enable(bdev
->dev
);
243 mutex_unlock(&bcm_device_lock
);
248 static const struct bcm_set_sleep_mode default_sleep_params
= {
249 .sleep_mode
= 1, /* 0=Disabled, 1=UART, 2=Reserved, 3=USB */
250 .idle_host
= 2, /* idle threshold HOST, in 300ms */
251 .idle_dev
= 2, /* idle threshold device, in 300ms */
252 .bt_wake_active
= 1, /* BT_WAKE active mode: 1 = high, 0 = low */
253 .host_wake_active
= 0, /* HOST_WAKE active mode: 1 = high, 0 = low */
254 .allow_host_sleep
= 1, /* Allow host sleep in SCO flag */
255 .combine_modes
= 1, /* Combine sleep and LPM flag */
256 .tristate_control
= 0, /* Allow tri-state control of UART tx flag */
257 /* Irrelevant USB flags */
259 .usb_resume_timeout
= 0,
260 .pulsed_host_wake
= 0,
264 static int bcm_setup_sleep(struct hci_uart
*hu
)
266 struct bcm_data
*bcm
= hu
->priv
;
268 struct bcm_set_sleep_mode sleep_params
= default_sleep_params
;
270 sleep_params
.host_wake_active
= !bcm
->dev
->irq_active_low
;
272 skb
= __hci_cmd_sync(hu
->hdev
, 0xfc27, sizeof(sleep_params
),
273 &sleep_params
, HCI_INIT_TIMEOUT
);
275 int err
= PTR_ERR(skb
);
276 bt_dev_err(hu
->hdev
, "Sleep VSC failed (%d)", err
);
281 bt_dev_dbg(hu
->hdev
, "Set Sleep Parameters VSC succeeded");
286 static inline int bcm_request_irq(struct bcm_data
*bcm
) { return 0; }
287 static inline int bcm_setup_sleep(struct hci_uart
*hu
) { return 0; }
290 static int bcm_set_diag(struct hci_dev
*hdev
, bool enable
)
292 struct hci_uart
*hu
= hci_get_drvdata(hdev
);
293 struct bcm_data
*bcm
= hu
->priv
;
296 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
299 skb
= bt_skb_alloc(3, GFP_KERNEL
);
303 skb_put_u8(skb
, BCM_LM_DIAG_PKT
);
304 skb_put_u8(skb
, 0xf0);
305 skb_put_u8(skb
, enable
);
307 skb_queue_tail(&bcm
->txq
, skb
);
308 hci_uart_tx_wakeup(hu
);
313 static int bcm_open(struct hci_uart
*hu
)
315 struct bcm_data
*bcm
;
318 bt_dev_dbg(hu
->hdev
, "hu %p", hu
);
320 if (!hci_uart_has_flow_control(hu
))
323 bcm
= kzalloc(sizeof(*bcm
), GFP_KERNEL
);
327 skb_queue_head_init(&bcm
->txq
);
331 mutex_lock(&bcm_device_lock
);
334 serdev_device_open(hu
->serdev
);
335 bcm
->dev
= serdev_device_get_drvdata(hu
->serdev
);
342 list_for_each(p
, &bcm_device_list
) {
343 struct bcm_device
*dev
= list_entry(p
, struct bcm_device
, list
);
345 /* Retrieve saved bcm_device based on parent of the
346 * platform device (saved during device probe) and
347 * parent of tty device used by hci_uart
349 if (hu
->tty
->dev
->parent
== dev
->dev
->parent
) {
360 hu
->init_speed
= bcm
->dev
->init_speed
;
361 hu
->oper_speed
= bcm
->dev
->oper_speed
;
362 bcm_gpio_set_power(bcm
->dev
, true);
365 mutex_unlock(&bcm_device_lock
);
369 static int bcm_close(struct hci_uart
*hu
)
371 struct bcm_data
*bcm
= hu
->priv
;
372 struct bcm_device
*bdev
= NULL
;
374 bt_dev_dbg(hu
->hdev
, "hu %p", hu
);
376 /* Protect bcm->dev against removal of the device or driver */
377 mutex_lock(&bcm_device_lock
);
380 serdev_device_close(hu
->serdev
);
381 bdev
= serdev_device_get_drvdata(hu
->serdev
);
382 } else if (bcm_device_exists(bcm
->dev
)) {
390 bcm_gpio_set_power(bdev
, false);
392 pm_runtime_disable(bdev
->dev
);
393 pm_runtime_set_suspended(bdev
->dev
);
396 devm_free_irq(bdev
->dev
, bdev
->irq
, bdev
);
397 device_init_wakeup(bdev
->dev
, false);
401 mutex_unlock(&bcm_device_lock
);
403 skb_queue_purge(&bcm
->txq
);
404 kfree_skb(bcm
->rx_skb
);
411 static int bcm_flush(struct hci_uart
*hu
)
413 struct bcm_data
*bcm
= hu
->priv
;
415 bt_dev_dbg(hu
->hdev
, "hu %p", hu
);
417 skb_queue_purge(&bcm
->txq
);
422 static int bcm_setup(struct hci_uart
*hu
)
424 struct bcm_data
*bcm
= hu
->priv
;
426 const struct firmware
*fw
;
430 bt_dev_dbg(hu
->hdev
, "hu %p", hu
);
432 hu
->hdev
->set_diag
= bcm_set_diag
;
433 hu
->hdev
->set_bdaddr
= btbcm_set_bdaddr
;
435 err
= btbcm_initialize(hu
->hdev
, fw_name
, sizeof(fw_name
));
439 err
= request_firmware(&fw
, fw_name
, &hu
->hdev
->dev
);
441 bt_dev_info(hu
->hdev
, "BCM: Patch %s not found", fw_name
);
445 err
= btbcm_patchram(hu
->hdev
, fw
);
447 bt_dev_info(hu
->hdev
, "BCM: Patch failed (%d)", err
);
451 /* Init speed if any */
453 speed
= hu
->init_speed
;
454 else if (hu
->proto
->init_speed
)
455 speed
= hu
->proto
->init_speed
;
460 host_set_baudrate(hu
, speed
);
462 /* Operational speed if any */
464 speed
= hu
->oper_speed
;
465 else if (hu
->proto
->oper_speed
)
466 speed
= hu
->proto
->oper_speed
;
471 err
= bcm_set_baudrate(hu
, speed
);
473 host_set_baudrate(hu
, speed
);
477 release_firmware(fw
);
479 err
= btbcm_finalize(hu
->hdev
);
483 if (!bcm_request_irq(bcm
))
484 err
= bcm_setup_sleep(hu
);
489 #define BCM_RECV_LM_DIAG \
490 .type = BCM_LM_DIAG_PKT, \
491 .hlen = BCM_LM_DIAG_SIZE, \
494 .maxlen = BCM_LM_DIAG_SIZE
496 #define BCM_RECV_NULL \
497 .type = BCM_NULL_PKT, \
498 .hlen = BCM_NULL_SIZE, \
501 .maxlen = BCM_NULL_SIZE
503 #define BCM_RECV_TYPE49 \
504 .type = BCM_TYPE49_PKT, \
505 .hlen = BCM_TYPE49_SIZE, \
508 .maxlen = BCM_TYPE49_SIZE
510 #define BCM_RECV_TYPE52 \
511 .type = BCM_TYPE52_PKT, \
512 .hlen = BCM_TYPE52_SIZE, \
515 .maxlen = BCM_TYPE52_SIZE
517 static const struct h4_recv_pkt bcm_recv_pkts
[] = {
518 { H4_RECV_ACL
, .recv
= hci_recv_frame
},
519 { H4_RECV_SCO
, .recv
= hci_recv_frame
},
520 { H4_RECV_EVENT
, .recv
= hci_recv_frame
},
521 { BCM_RECV_LM_DIAG
, .recv
= hci_recv_diag
},
522 { BCM_RECV_NULL
, .recv
= hci_recv_diag
},
523 { BCM_RECV_TYPE49
, .recv
= hci_recv_diag
},
524 { BCM_RECV_TYPE52
, .recv
= hci_recv_diag
},
527 static int bcm_recv(struct hci_uart
*hu
, const void *data
, int count
)
529 struct bcm_data
*bcm
= hu
->priv
;
531 if (!test_bit(HCI_UART_REGISTERED
, &hu
->flags
))
534 bcm
->rx_skb
= h4_recv_buf(hu
->hdev
, bcm
->rx_skb
, data
, count
,
535 bcm_recv_pkts
, ARRAY_SIZE(bcm_recv_pkts
));
536 if (IS_ERR(bcm
->rx_skb
)) {
537 int err
= PTR_ERR(bcm
->rx_skb
);
538 bt_dev_err(hu
->hdev
, "Frame reassembly failed (%d)", err
);
541 } else if (!bcm
->rx_skb
) {
542 /* Delay auto-suspend when receiving completed packet */
543 mutex_lock(&bcm_device_lock
);
544 if (bcm
->dev
&& bcm_device_exists(bcm
->dev
)) {
545 pm_runtime_get(bcm
->dev
->dev
);
546 pm_runtime_mark_last_busy(bcm
->dev
->dev
);
547 pm_runtime_put_autosuspend(bcm
->dev
->dev
);
549 mutex_unlock(&bcm_device_lock
);
555 static int bcm_enqueue(struct hci_uart
*hu
, struct sk_buff
*skb
)
557 struct bcm_data
*bcm
= hu
->priv
;
559 bt_dev_dbg(hu
->hdev
, "hu %p skb %p", hu
, skb
);
561 /* Prepend skb with frame type */
562 memcpy(skb_push(skb
, 1), &hci_skb_pkt_type(skb
), 1);
563 skb_queue_tail(&bcm
->txq
, skb
);
568 static struct sk_buff
*bcm_dequeue(struct hci_uart
*hu
)
570 struct bcm_data
*bcm
= hu
->priv
;
571 struct sk_buff
*skb
= NULL
;
572 struct bcm_device
*bdev
= NULL
;
574 mutex_lock(&bcm_device_lock
);
576 if (bcm_device_exists(bcm
->dev
)) {
578 pm_runtime_get_sync(bdev
->dev
);
579 /* Shall be resumed here */
582 skb
= skb_dequeue(&bcm
->txq
);
585 pm_runtime_mark_last_busy(bdev
->dev
);
586 pm_runtime_put_autosuspend(bdev
->dev
);
589 mutex_unlock(&bcm_device_lock
);
595 static int bcm_suspend_device(struct device
*dev
)
597 struct bcm_device
*bdev
= dev_get_drvdata(dev
);
599 bt_dev_dbg(bdev
, "");
601 if (!bdev
->is_suspended
&& bdev
->hu
) {
602 hci_uart_set_flow_control(bdev
->hu
, true);
604 /* Once this returns, driver suspends BT via GPIO */
605 bdev
->is_suspended
= true;
608 /* Suspend the device */
609 gpiod_set_value(bdev
->device_wakeup
, false);
610 bt_dev_dbg(bdev
, "suspend, delaying 15 ms");
616 static int bcm_resume_device(struct device
*dev
)
618 struct bcm_device
*bdev
= dev_get_drvdata(dev
);
620 bt_dev_dbg(bdev
, "");
622 gpiod_set_value(bdev
->device_wakeup
, true);
623 bt_dev_dbg(bdev
, "resume, delaying 15 ms");
626 /* When this executes, the device has woken up already */
627 if (bdev
->is_suspended
&& bdev
->hu
) {
628 bdev
->is_suspended
= false;
630 hci_uart_set_flow_control(bdev
->hu
, false);
637 #ifdef CONFIG_PM_SLEEP
638 /* suspend callback */
639 static int bcm_suspend(struct device
*dev
)
641 struct bcm_device
*bdev
= dev_get_drvdata(dev
);
644 bt_dev_dbg(bdev
, "suspend: is_suspended %d", bdev
->is_suspended
);
647 * When used with a device instantiated as platform_device, bcm_suspend
648 * can be called at any time as long as the platform device is bound,
649 * so it should use bcm_device_lock to protect access to hci_uart
650 * and device_wake-up GPIO.
652 mutex_lock(&bcm_device_lock
);
657 if (pm_runtime_active(dev
))
658 bcm_suspend_device(dev
);
660 if (device_may_wakeup(dev
) && bdev
->irq
> 0) {
661 error
= enable_irq_wake(bdev
->irq
);
663 bt_dev_dbg(bdev
, "BCM irq: enabled");
667 mutex_unlock(&bcm_device_lock
);
672 /* resume callback */
673 static int bcm_resume(struct device
*dev
)
675 struct bcm_device
*bdev
= dev_get_drvdata(dev
);
677 bt_dev_dbg(bdev
, "resume: is_suspended %d", bdev
->is_suspended
);
680 * When used with a device instantiated as platform_device, bcm_resume
681 * can be called at any time as long as platform device is bound,
682 * so it should use bcm_device_lock to protect access to hci_uart
683 * and device_wake-up GPIO.
685 mutex_lock(&bcm_device_lock
);
690 if (device_may_wakeup(dev
) && bdev
->irq
> 0) {
691 disable_irq_wake(bdev
->irq
);
692 bt_dev_dbg(bdev
, "BCM irq: disabled");
695 bcm_resume_device(dev
);
698 mutex_unlock(&bcm_device_lock
);
700 pm_runtime_disable(dev
);
701 pm_runtime_set_active(dev
);
702 pm_runtime_enable(dev
);
708 static const struct acpi_gpio_params int_last_device_wakeup_gpios
= { 0, 0, false };
709 static const struct acpi_gpio_params int_last_shutdown_gpios
= { 1, 0, false };
710 static const struct acpi_gpio_params int_last_host_wakeup_gpios
= { 2, 0, false };
712 static const struct acpi_gpio_mapping acpi_bcm_int_last_gpios
[] = {
713 { "device-wakeup-gpios", &int_last_device_wakeup_gpios
, 1 },
714 { "shutdown-gpios", &int_last_shutdown_gpios
, 1 },
715 { "host-wakeup-gpios", &int_last_host_wakeup_gpios
, 1 },
719 static const struct acpi_gpio_params int_first_host_wakeup_gpios
= { 0, 0, false };
720 static const struct acpi_gpio_params int_first_device_wakeup_gpios
= { 1, 0, false };
721 static const struct acpi_gpio_params int_first_shutdown_gpios
= { 2, 0, false };
723 static const struct acpi_gpio_mapping acpi_bcm_int_first_gpios
[] = {
724 { "device-wakeup-gpios", &int_first_device_wakeup_gpios
, 1 },
725 { "shutdown-gpios", &int_first_shutdown_gpios
, 1 },
726 { "host-wakeup-gpios", &int_first_host_wakeup_gpios
, 1 },
731 /* IRQ polarity of some chipsets are not defined correctly in ACPI table. */
732 static const struct dmi_system_id bcm_active_low_irq_dmi_table
[] = {
733 { /* Handle ThinkPad 8 tablets with BCM2E55 chipset ACPI ID */
734 .ident
= "Lenovo ThinkPad 8",
736 DMI_EXACT_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
737 DMI_EXACT_MATCH(DMI_PRODUCT_VERSION
, "ThinkPad 8"),
741 .ident
= "MINIX Z83-4",
743 DMI_EXACT_MATCH(DMI_SYS_VENDOR
, "MINIX"),
744 DMI_MATCH(DMI_PRODUCT_NAME
, "Z83-4"),
750 static int bcm_resource(struct acpi_resource
*ares
, void *data
)
752 struct bcm_device
*dev
= data
;
753 struct acpi_resource_extended_irq
*irq
;
754 struct acpi_resource_gpio
*gpio
;
755 struct acpi_resource_uart_serialbus
*sb
;
757 switch (ares
->type
) {
758 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
759 irq
= &ares
->data
.extended_irq
;
760 if (irq
->polarity
!= ACPI_ACTIVE_LOW
)
761 dev_info(dev
->dev
, "ACPI Interrupt resource is active-high, this is usually wrong, treating the IRQ as active-low\n");
762 dev
->irq_active_low
= true;
765 case ACPI_RESOURCE_TYPE_GPIO
:
766 gpio
= &ares
->data
.gpio
;
767 if (gpio
->connection_type
== ACPI_RESOURCE_GPIO_TYPE_INT
)
768 dev
->irq_active_low
= gpio
->polarity
== ACPI_ACTIVE_LOW
;
771 case ACPI_RESOURCE_TYPE_SERIAL_BUS
:
772 sb
= &ares
->data
.uart_serial_bus
;
773 if (sb
->type
== ACPI_RESOURCE_SERIAL_TYPE_UART
) {
774 dev
->init_speed
= sb
->default_baud_rate
;
775 dev
->oper_speed
= 4000000;
785 #endif /* CONFIG_ACPI */
787 static int bcm_get_resources(struct bcm_device
*dev
)
789 dev
->name
= dev_name(dev
->dev
);
791 dev
->clk
= devm_clk_get(dev
->dev
, NULL
);
793 /* Handle deferred probing */
794 if (dev
->clk
== ERR_PTR(-EPROBE_DEFER
))
795 return PTR_ERR(dev
->clk
);
797 dev
->device_wakeup
= devm_gpiod_get_optional(dev
->dev
, "device-wakeup",
799 if (IS_ERR(dev
->device_wakeup
))
800 return PTR_ERR(dev
->device_wakeup
);
802 dev
->shutdown
= devm_gpiod_get_optional(dev
->dev
, "shutdown",
804 if (IS_ERR(dev
->shutdown
))
805 return PTR_ERR(dev
->shutdown
);
807 /* IRQ can be declared in ACPI table as Interrupt or GpioInt */
809 struct gpio_desc
*gpio
;
811 gpio
= devm_gpiod_get_optional(dev
->dev
, "host-wakeup",
814 return PTR_ERR(gpio
);
816 dev
->irq
= gpiod_to_irq(gpio
);
819 dev_info(dev
->dev
, "BCM irq: %d\n", dev
->irq
);
824 static int bcm_acpi_probe(struct bcm_device
*dev
)
826 LIST_HEAD(resources
);
827 const struct dmi_system_id
*dmi_id
;
828 const struct acpi_gpio_mapping
*gpio_mapping
= acpi_bcm_int_last_gpios
;
829 const struct acpi_device_id
*id
;
830 struct resource_entry
*entry
;
833 /* Retrieve GPIO data */
834 id
= acpi_match_device(dev
->dev
->driver
->acpi_match_table
, dev
->dev
);
836 gpio_mapping
= (const struct acpi_gpio_mapping
*) id
->driver_data
;
838 ret
= devm_acpi_dev_add_driver_gpios(dev
->dev
, gpio_mapping
);
842 /* Retrieve UART ACPI info */
843 ret
= acpi_dev_get_resources(ACPI_COMPANION(dev
->dev
),
844 &resources
, bcm_resource
, dev
);
848 resource_list_for_each_entry(entry
, &resources
) {
849 if (resource_type(entry
->res
) == IORESOURCE_IRQ
) {
850 dev
->irq
= entry
->res
->start
;
854 acpi_dev_free_resource_list(&resources
);
856 if (irq_polarity
!= -1) {
857 dev
->irq_active_low
= irq_polarity
;
858 dev_warn(dev
->dev
, "Overwriting IRQ polarity to active %s by module-param\n",
859 dev
->irq_active_low
? "low" : "high");
861 dmi_id
= dmi_first_match(bcm_active_low_irq_dmi_table
);
863 dev_warn(dev
->dev
, "%s: Overwriting IRQ polarity to active low",
865 dev
->irq_active_low
= true;
872 static int bcm_acpi_probe(struct bcm_device
*dev
)
876 #endif /* CONFIG_ACPI */
878 static int bcm_of_probe(struct bcm_device
*bdev
)
880 device_property_read_u32(bdev
->dev
, "max-speed", &bdev
->oper_speed
);
884 static int bcm_probe(struct platform_device
*pdev
)
886 struct bcm_device
*dev
;
889 dev
= devm_kzalloc(&pdev
->dev
, sizeof(*dev
), GFP_KERNEL
);
893 dev
->dev
= &pdev
->dev
;
894 dev
->irq
= platform_get_irq(pdev
, 0);
896 if (has_acpi_companion(&pdev
->dev
)) {
897 ret
= bcm_acpi_probe(dev
);
902 ret
= bcm_get_resources(dev
);
906 platform_set_drvdata(pdev
, dev
);
908 dev_info(&pdev
->dev
, "%s device registered.\n", dev
->name
);
910 /* Place this instance on the device list */
911 mutex_lock(&bcm_device_lock
);
912 list_add_tail(&dev
->list
, &bcm_device_list
);
913 mutex_unlock(&bcm_device_lock
);
915 bcm_gpio_set_power(dev
, false);
920 static int bcm_remove(struct platform_device
*pdev
)
922 struct bcm_device
*dev
= platform_get_drvdata(pdev
);
924 mutex_lock(&bcm_device_lock
);
925 list_del(&dev
->list
);
926 mutex_unlock(&bcm_device_lock
);
928 dev_info(&pdev
->dev
, "%s device unregistered.\n", dev
->name
);
933 static const struct hci_uart_proto bcm_proto
= {
937 .init_speed
= 115200,
942 .set_baudrate
= bcm_set_baudrate
,
944 .enqueue
= bcm_enqueue
,
945 .dequeue
= bcm_dequeue
,
949 static const struct acpi_device_id bcm_acpi_match
[] = {
950 { "BCM2E1A", (kernel_ulong_t
)&acpi_bcm_int_last_gpios
},
951 { "BCM2E39", (kernel_ulong_t
)&acpi_bcm_int_last_gpios
},
952 { "BCM2E3A", (kernel_ulong_t
)&acpi_bcm_int_last_gpios
},
953 { "BCM2E3D", (kernel_ulong_t
)&acpi_bcm_int_last_gpios
},
954 { "BCM2E3F", (kernel_ulong_t
)&acpi_bcm_int_last_gpios
},
955 { "BCM2E40", (kernel_ulong_t
)&acpi_bcm_int_last_gpios
},
956 { "BCM2E54", (kernel_ulong_t
)&acpi_bcm_int_last_gpios
},
957 { "BCM2E55", (kernel_ulong_t
)&acpi_bcm_int_last_gpios
},
958 { "BCM2E64", (kernel_ulong_t
)&acpi_bcm_int_last_gpios
},
959 { "BCM2E65", (kernel_ulong_t
)&acpi_bcm_int_last_gpios
},
960 { "BCM2E67", (kernel_ulong_t
)&acpi_bcm_int_last_gpios
},
961 { "BCM2E71", (kernel_ulong_t
)&acpi_bcm_int_last_gpios
},
962 { "BCM2E7B", (kernel_ulong_t
)&acpi_bcm_int_last_gpios
},
963 { "BCM2E7C", (kernel_ulong_t
)&acpi_bcm_int_last_gpios
},
964 { "BCM2E7E", (kernel_ulong_t
)&acpi_bcm_int_first_gpios
},
965 { "BCM2E95", (kernel_ulong_t
)&acpi_bcm_int_first_gpios
},
966 { "BCM2E96", (kernel_ulong_t
)&acpi_bcm_int_first_gpios
},
967 { "BCM2EA4", (kernel_ulong_t
)&acpi_bcm_int_first_gpios
},
970 MODULE_DEVICE_TABLE(acpi
, bcm_acpi_match
);
973 /* suspend and resume callbacks */
974 static const struct dev_pm_ops bcm_pm_ops
= {
975 SET_SYSTEM_SLEEP_PM_OPS(bcm_suspend
, bcm_resume
)
976 SET_RUNTIME_PM_OPS(bcm_suspend_device
, bcm_resume_device
, NULL
)
979 static struct platform_driver bcm_driver
= {
981 .remove
= bcm_remove
,
984 .acpi_match_table
= ACPI_PTR(bcm_acpi_match
),
989 static int bcm_serdev_probe(struct serdev_device
*serdev
)
991 struct bcm_device
*bcmdev
;
994 bcmdev
= devm_kzalloc(&serdev
->dev
, sizeof(*bcmdev
), GFP_KERNEL
);
998 bcmdev
->dev
= &serdev
->dev
;
1000 bcmdev
->hu
= &bcmdev
->serdev_hu
;
1002 bcmdev
->serdev_hu
.serdev
= serdev
;
1003 serdev_device_set_drvdata(serdev
, bcmdev
);
1005 if (has_acpi_companion(&serdev
->dev
))
1006 err
= bcm_acpi_probe(bcmdev
);
1008 err
= bcm_of_probe(bcmdev
);
1012 err
= bcm_get_resources(bcmdev
);
1016 bcm_gpio_set_power(bcmdev
, false);
1018 return hci_uart_register_device(&bcmdev
->serdev_hu
, &bcm_proto
);
1021 static void bcm_serdev_remove(struct serdev_device
*serdev
)
1023 struct bcm_device
*bcmdev
= serdev_device_get_drvdata(serdev
);
1025 hci_uart_unregister_device(&bcmdev
->serdev_hu
);
1029 static const struct of_device_id bcm_bluetooth_of_match
[] = {
1030 { .compatible
= "brcm,bcm43438-bt" },
1033 MODULE_DEVICE_TABLE(of
, bcm_bluetooth_of_match
);
1036 static struct serdev_device_driver bcm_serdev_driver
= {
1037 .probe
= bcm_serdev_probe
,
1038 .remove
= bcm_serdev_remove
,
1040 .name
= "hci_uart_bcm",
1041 .of_match_table
= of_match_ptr(bcm_bluetooth_of_match
),
1042 .acpi_match_table
= ACPI_PTR(bcm_acpi_match
),
1047 int __init
bcm_init(void)
1049 /* For now, we need to keep both platform device
1050 * driver (ACPI generated) and serdev driver (DT).
1052 platform_driver_register(&bcm_driver
);
1053 serdev_device_driver_register(&bcm_serdev_driver
);
1055 return hci_uart_register_proto(&bcm_proto
);
1058 int __exit
bcm_deinit(void)
1060 platform_driver_unregister(&bcm_driver
);
1061 serdev_device_driver_unregister(&bcm_serdev_driver
);
1063 return hci_uart_unregister_proto(&bcm_proto
);