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_AUTOSUSPEND_DELAY 5000 /* default autosleep delay */
55 /* device driver resources */
57 /* Must be the first member, hci_serdev.c expects this. */
58 struct hci_uart serdev_hu
;
59 struct list_head list
;
64 struct gpio_desc
*device_wakeup
;
65 struct gpio_desc
*shutdown
;
77 bool is_suspended
; /* suspend/resume flag */
81 /* generic bcm uart resources */
83 struct sk_buff
*rx_skb
;
84 struct sk_buff_head txq
;
86 struct bcm_device
*dev
;
89 /* List of BCM BT UART devices */
90 static DEFINE_MUTEX(bcm_device_lock
);
91 static LIST_HEAD(bcm_device_list
);
93 static inline void host_set_baudrate(struct hci_uart
*hu
, unsigned int speed
)
96 serdev_device_set_baudrate(hu
->serdev
, speed
);
98 hci_uart_set_baudrate(hu
, speed
);
101 static int bcm_set_baudrate(struct hci_uart
*hu
, unsigned int speed
)
103 struct hci_dev
*hdev
= hu
->hdev
;
105 struct bcm_update_uart_baud_rate param
;
107 if (speed
> 3000000) {
108 struct bcm_write_uart_clock_setting clock
;
110 clock
.type
= BCM_UART_CLOCK_48MHZ
;
112 bt_dev_dbg(hdev
, "Set Controller clock (%d)", clock
.type
);
114 /* This Broadcom specific command changes the UART's controller
115 * clock for baud rate > 3000000.
117 skb
= __hci_cmd_sync(hdev
, 0xfc45, 1, &clock
, HCI_INIT_TIMEOUT
);
119 int err
= PTR_ERR(skb
);
120 bt_dev_err(hdev
, "BCM: failed to write clock (%d)",
128 bt_dev_dbg(hdev
, "Set Controller UART speed to %d bit/s", speed
);
130 param
.zero
= cpu_to_le16(0);
131 param
.baud_rate
= cpu_to_le32(speed
);
133 /* This Broadcom specific command changes the UART's controller baud
136 skb
= __hci_cmd_sync(hdev
, 0xfc18, sizeof(param
), ¶m
,
139 int err
= PTR_ERR(skb
);
140 bt_dev_err(hdev
, "BCM: failed to write update baudrate (%d)",
150 /* bcm_device_exists should be protected by bcm_device_lock */
151 static bool bcm_device_exists(struct bcm_device
*device
)
155 /* Devices using serdev always exist */
156 if (device
&& device
->hu
&& device
->hu
->serdev
)
159 list_for_each(p
, &bcm_device_list
) {
160 struct bcm_device
*dev
= list_entry(p
, struct bcm_device
, list
);
169 static int bcm_gpio_set_power(struct bcm_device
*dev
, bool powered
)
171 if (powered
&& !IS_ERR(dev
->clk
) && !dev
->clk_enabled
)
172 clk_prepare_enable(dev
->clk
);
174 gpiod_set_value(dev
->shutdown
, powered
);
175 gpiod_set_value(dev
->device_wakeup
, powered
);
177 if (!powered
&& !IS_ERR(dev
->clk
) && dev
->clk_enabled
)
178 clk_disable_unprepare(dev
->clk
);
180 dev
->clk_enabled
= powered
;
186 static irqreturn_t
bcm_host_wake(int irq
, void *data
)
188 struct bcm_device
*bdev
= data
;
190 bt_dev_dbg(bdev
, "Host wake IRQ");
192 pm_runtime_get(bdev
->dev
);
193 pm_runtime_mark_last_busy(bdev
->dev
);
194 pm_runtime_put_autosuspend(bdev
->dev
);
199 static int bcm_request_irq(struct bcm_data
*bcm
)
201 struct bcm_device
*bdev
= bcm
->dev
;
204 mutex_lock(&bcm_device_lock
);
205 if (!bcm_device_exists(bdev
)) {
210 if (bdev
->irq
<= 0) {
215 err
= devm_request_irq(bdev
->dev
, bdev
->irq
, bcm_host_wake
,
216 bdev
->irq_active_low
? IRQF_TRIGGER_FALLING
:
222 device_init_wakeup(bdev
->dev
, true);
224 pm_runtime_set_autosuspend_delay(bdev
->dev
,
225 BCM_AUTOSUSPEND_DELAY
);
226 pm_runtime_use_autosuspend(bdev
->dev
);
227 pm_runtime_set_active(bdev
->dev
);
228 pm_runtime_enable(bdev
->dev
);
231 mutex_unlock(&bcm_device_lock
);
236 static const struct bcm_set_sleep_mode default_sleep_params
= {
237 .sleep_mode
= 1, /* 0=Disabled, 1=UART, 2=Reserved, 3=USB */
238 .idle_host
= 2, /* idle threshold HOST, in 300ms */
239 .idle_dev
= 2, /* idle threshold device, in 300ms */
240 .bt_wake_active
= 1, /* BT_WAKE active mode: 1 = high, 0 = low */
241 .host_wake_active
= 0, /* HOST_WAKE active mode: 1 = high, 0 = low */
242 .allow_host_sleep
= 1, /* Allow host sleep in SCO flag */
243 .combine_modes
= 1, /* Combine sleep and LPM flag */
244 .tristate_control
= 0, /* Allow tri-state control of UART tx flag */
245 /* Irrelevant USB flags */
247 .usb_resume_timeout
= 0,
248 .pulsed_host_wake
= 0,
252 static int bcm_setup_sleep(struct hci_uart
*hu
)
254 struct bcm_data
*bcm
= hu
->priv
;
256 struct bcm_set_sleep_mode sleep_params
= default_sleep_params
;
258 sleep_params
.host_wake_active
= !bcm
->dev
->irq_active_low
;
260 skb
= __hci_cmd_sync(hu
->hdev
, 0xfc27, sizeof(sleep_params
),
261 &sleep_params
, HCI_INIT_TIMEOUT
);
263 int err
= PTR_ERR(skb
);
264 bt_dev_err(hu
->hdev
, "Sleep VSC failed (%d)", err
);
269 bt_dev_dbg(hu
->hdev
, "Set Sleep Parameters VSC succeeded");
274 static inline int bcm_request_irq(struct bcm_data
*bcm
) { return 0; }
275 static inline int bcm_setup_sleep(struct hci_uart
*hu
) { return 0; }
278 static int bcm_set_diag(struct hci_dev
*hdev
, bool enable
)
280 struct hci_uart
*hu
= hci_get_drvdata(hdev
);
281 struct bcm_data
*bcm
= hu
->priv
;
284 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
287 skb
= bt_skb_alloc(3, GFP_KERNEL
);
291 skb_put_u8(skb
, BCM_LM_DIAG_PKT
);
292 skb_put_u8(skb
, 0xf0);
293 skb_put_u8(skb
, enable
);
295 skb_queue_tail(&bcm
->txq
, skb
);
296 hci_uart_tx_wakeup(hu
);
301 static int bcm_open(struct hci_uart
*hu
)
303 struct bcm_data
*bcm
;
306 bt_dev_dbg(hu
->hdev
, "hu %p", hu
);
308 bcm
= kzalloc(sizeof(*bcm
), GFP_KERNEL
);
312 skb_queue_head_init(&bcm
->txq
);
316 mutex_lock(&bcm_device_lock
);
319 serdev_device_open(hu
->serdev
);
320 bcm
->dev
= serdev_device_get_drvdata(hu
->serdev
);
327 list_for_each(p
, &bcm_device_list
) {
328 struct bcm_device
*dev
= list_entry(p
, struct bcm_device
, list
);
330 /* Retrieve saved bcm_device based on parent of the
331 * platform device (saved during device probe) and
332 * parent of tty device used by hci_uart
334 if (hu
->tty
->dev
->parent
== dev
->dev
->parent
) {
345 hu
->init_speed
= bcm
->dev
->init_speed
;
346 hu
->oper_speed
= bcm
->dev
->oper_speed
;
347 bcm_gpio_set_power(bcm
->dev
, true);
350 mutex_unlock(&bcm_device_lock
);
354 static int bcm_close(struct hci_uart
*hu
)
356 struct bcm_data
*bcm
= hu
->priv
;
357 struct bcm_device
*bdev
= NULL
;
359 bt_dev_dbg(hu
->hdev
, "hu %p", hu
);
361 /* Protect bcm->dev against removal of the device or driver */
362 mutex_lock(&bcm_device_lock
);
365 serdev_device_close(hu
->serdev
);
366 bdev
= serdev_device_get_drvdata(hu
->serdev
);
367 } else if (bcm_device_exists(bcm
->dev
)) {
375 bcm_gpio_set_power(bdev
, false);
377 pm_runtime_disable(bdev
->dev
);
378 pm_runtime_set_suspended(bdev
->dev
);
380 if (device_can_wakeup(bdev
->dev
)) {
381 devm_free_irq(bdev
->dev
, bdev
->irq
, bdev
);
382 device_init_wakeup(bdev
->dev
, false);
386 mutex_unlock(&bcm_device_lock
);
388 skb_queue_purge(&bcm
->txq
);
389 kfree_skb(bcm
->rx_skb
);
396 static int bcm_flush(struct hci_uart
*hu
)
398 struct bcm_data
*bcm
= hu
->priv
;
400 bt_dev_dbg(hu
->hdev
, "hu %p", hu
);
402 skb_queue_purge(&bcm
->txq
);
407 static int bcm_setup(struct hci_uart
*hu
)
409 struct bcm_data
*bcm
= hu
->priv
;
411 const struct firmware
*fw
;
415 bt_dev_dbg(hu
->hdev
, "hu %p", hu
);
417 hu
->hdev
->set_diag
= bcm_set_diag
;
418 hu
->hdev
->set_bdaddr
= btbcm_set_bdaddr
;
420 err
= btbcm_initialize(hu
->hdev
, fw_name
, sizeof(fw_name
));
424 err
= request_firmware(&fw
, fw_name
, &hu
->hdev
->dev
);
426 bt_dev_info(hu
->hdev
, "BCM: Patch %s not found", fw_name
);
430 err
= btbcm_patchram(hu
->hdev
, fw
);
432 bt_dev_info(hu
->hdev
, "BCM: Patch failed (%d)", err
);
436 /* Init speed if any */
438 speed
= hu
->init_speed
;
439 else if (hu
->proto
->init_speed
)
440 speed
= hu
->proto
->init_speed
;
445 host_set_baudrate(hu
, speed
);
447 /* Operational speed if any */
449 speed
= hu
->oper_speed
;
450 else if (hu
->proto
->oper_speed
)
451 speed
= hu
->proto
->oper_speed
;
456 err
= bcm_set_baudrate(hu
, speed
);
458 host_set_baudrate(hu
, speed
);
462 release_firmware(fw
);
464 err
= btbcm_finalize(hu
->hdev
);
468 if (!bcm_request_irq(bcm
))
469 err
= bcm_setup_sleep(hu
);
474 #define BCM_RECV_LM_DIAG \
475 .type = BCM_LM_DIAG_PKT, \
476 .hlen = BCM_LM_DIAG_SIZE, \
479 .maxlen = BCM_LM_DIAG_SIZE
481 #define BCM_RECV_NULL \
482 .type = BCM_NULL_PKT, \
483 .hlen = BCM_NULL_SIZE, \
486 .maxlen = BCM_NULL_SIZE
488 static const struct h4_recv_pkt bcm_recv_pkts
[] = {
489 { H4_RECV_ACL
, .recv
= hci_recv_frame
},
490 { H4_RECV_SCO
, .recv
= hci_recv_frame
},
491 { H4_RECV_EVENT
, .recv
= hci_recv_frame
},
492 { BCM_RECV_LM_DIAG
, .recv
= hci_recv_diag
},
493 { BCM_RECV_NULL
, .recv
= hci_recv_diag
},
496 static int bcm_recv(struct hci_uart
*hu
, const void *data
, int count
)
498 struct bcm_data
*bcm
= hu
->priv
;
500 if (!test_bit(HCI_UART_REGISTERED
, &hu
->flags
))
503 bcm
->rx_skb
= h4_recv_buf(hu
->hdev
, bcm
->rx_skb
, data
, count
,
504 bcm_recv_pkts
, ARRAY_SIZE(bcm_recv_pkts
));
505 if (IS_ERR(bcm
->rx_skb
)) {
506 int err
= PTR_ERR(bcm
->rx_skb
);
507 bt_dev_err(hu
->hdev
, "Frame reassembly failed (%d)", err
);
510 } else if (!bcm
->rx_skb
) {
511 /* Delay auto-suspend when receiving completed packet */
512 mutex_lock(&bcm_device_lock
);
513 if (bcm
->dev
&& bcm_device_exists(bcm
->dev
)) {
514 pm_runtime_get(bcm
->dev
->dev
);
515 pm_runtime_mark_last_busy(bcm
->dev
->dev
);
516 pm_runtime_put_autosuspend(bcm
->dev
->dev
);
518 mutex_unlock(&bcm_device_lock
);
524 static int bcm_enqueue(struct hci_uart
*hu
, struct sk_buff
*skb
)
526 struct bcm_data
*bcm
= hu
->priv
;
528 bt_dev_dbg(hu
->hdev
, "hu %p skb %p", hu
, skb
);
530 /* Prepend skb with frame type */
531 memcpy(skb_push(skb
, 1), &hci_skb_pkt_type(skb
), 1);
532 skb_queue_tail(&bcm
->txq
, skb
);
537 static struct sk_buff
*bcm_dequeue(struct hci_uart
*hu
)
539 struct bcm_data
*bcm
= hu
->priv
;
540 struct sk_buff
*skb
= NULL
;
541 struct bcm_device
*bdev
= NULL
;
543 mutex_lock(&bcm_device_lock
);
545 if (bcm_device_exists(bcm
->dev
)) {
547 pm_runtime_get_sync(bdev
->dev
);
548 /* Shall be resumed here */
551 skb
= skb_dequeue(&bcm
->txq
);
554 pm_runtime_mark_last_busy(bdev
->dev
);
555 pm_runtime_put_autosuspend(bdev
->dev
);
558 mutex_unlock(&bcm_device_lock
);
564 static int bcm_suspend_device(struct device
*dev
)
566 struct bcm_device
*bdev
= dev_get_drvdata(dev
);
568 bt_dev_dbg(bdev
, "");
570 if (!bdev
->is_suspended
&& bdev
->hu
) {
571 hci_uart_set_flow_control(bdev
->hu
, true);
573 /* Once this returns, driver suspends BT via GPIO */
574 bdev
->is_suspended
= true;
577 /* Suspend the device */
578 if (bdev
->device_wakeup
) {
579 gpiod_set_value(bdev
->device_wakeup
, false);
580 bt_dev_dbg(bdev
, "suspend, delaying 15 ms");
587 static int bcm_resume_device(struct device
*dev
)
589 struct bcm_device
*bdev
= dev_get_drvdata(dev
);
591 bt_dev_dbg(bdev
, "");
593 if (bdev
->device_wakeup
) {
594 gpiod_set_value(bdev
->device_wakeup
, true);
595 bt_dev_dbg(bdev
, "resume, delaying 15 ms");
599 /* When this executes, the device has woken up already */
600 if (bdev
->is_suspended
&& bdev
->hu
) {
601 bdev
->is_suspended
= false;
603 hci_uart_set_flow_control(bdev
->hu
, false);
610 #ifdef CONFIG_PM_SLEEP
611 /* suspend callback */
612 static int bcm_suspend(struct device
*dev
)
614 struct bcm_device
*bdev
= dev_get_drvdata(dev
);
617 bt_dev_dbg(bdev
, "suspend: is_suspended %d", bdev
->is_suspended
);
620 * When used with a device instantiated as platform_device, bcm_suspend
621 * can be called at any time as long as the platform device is bound,
622 * so it should use bcm_device_lock to protect access to hci_uart
623 * and device_wake-up GPIO.
625 mutex_lock(&bcm_device_lock
);
630 if (pm_runtime_active(dev
))
631 bcm_suspend_device(dev
);
633 if (device_may_wakeup(dev
)) {
634 error
= enable_irq_wake(bdev
->irq
);
636 bt_dev_dbg(bdev
, "BCM irq: enabled");
640 mutex_unlock(&bcm_device_lock
);
645 /* resume callback */
646 static int bcm_resume(struct device
*dev
)
648 struct bcm_device
*bdev
= dev_get_drvdata(dev
);
650 bt_dev_dbg(bdev
, "resume: is_suspended %d", bdev
->is_suspended
);
653 * When used with a device instantiated as platform_device, bcm_resume
654 * can be called at any time as long as platform device is bound,
655 * so it should use bcm_device_lock to protect access to hci_uart
656 * and device_wake-up GPIO.
658 mutex_lock(&bcm_device_lock
);
663 if (device_may_wakeup(dev
)) {
664 disable_irq_wake(bdev
->irq
);
665 bt_dev_dbg(bdev
, "BCM irq: disabled");
668 bcm_resume_device(dev
);
671 mutex_unlock(&bcm_device_lock
);
673 pm_runtime_disable(dev
);
674 pm_runtime_set_active(dev
);
675 pm_runtime_enable(dev
);
681 static const struct acpi_gpio_params int_last_device_wakeup_gpios
= { 0, 0, false };
682 static const struct acpi_gpio_params int_last_shutdown_gpios
= { 1, 0, false };
683 static const struct acpi_gpio_params int_last_host_wakeup_gpios
= { 2, 0, false };
685 static const struct acpi_gpio_mapping acpi_bcm_int_last_gpios
[] = {
686 { "device-wakeup-gpios", &int_last_device_wakeup_gpios
, 1 },
687 { "shutdown-gpios", &int_last_shutdown_gpios
, 1 },
688 { "host-wakeup-gpios", &int_last_host_wakeup_gpios
, 1 },
692 static const struct acpi_gpio_params int_first_host_wakeup_gpios
= { 0, 0, false };
693 static const struct acpi_gpio_params int_first_device_wakeup_gpios
= { 1, 0, false };
694 static const struct acpi_gpio_params int_first_shutdown_gpios
= { 2, 0, false };
696 static const struct acpi_gpio_mapping acpi_bcm_int_first_gpios
[] = {
697 { "device-wakeup-gpios", &int_first_device_wakeup_gpios
, 1 },
698 { "shutdown-gpios", &int_first_shutdown_gpios
, 1 },
699 { "host-wakeup-gpios", &int_first_host_wakeup_gpios
, 1 },
704 /* IRQ polarity of some chipsets are not defined correctly in ACPI table. */
705 static const struct dmi_system_id bcm_active_low_irq_dmi_table
[] = {
707 .ident
= "Asus T100TA",
709 DMI_EXACT_MATCH(DMI_SYS_VENDOR
,
710 "ASUSTeK COMPUTER INC."),
711 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "T100TA"),
715 .ident
= "Asus T100CHI",
717 DMI_EXACT_MATCH(DMI_SYS_VENDOR
,
718 "ASUSTeK COMPUTER INC."),
719 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "T100CHI"),
722 { /* Handle ThinkPad 8 tablets with BCM2E55 chipset ACPI ID */
723 .ident
= "Lenovo ThinkPad 8",
725 DMI_EXACT_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
726 DMI_EXACT_MATCH(DMI_PRODUCT_VERSION
, "ThinkPad 8"),
730 .ident
= "MINIX Z83-4",
732 DMI_EXACT_MATCH(DMI_SYS_VENDOR
, "MINIX"),
733 DMI_MATCH(DMI_PRODUCT_NAME
, "Z83-4"),
739 static int bcm_resource(struct acpi_resource
*ares
, void *data
)
741 struct bcm_device
*dev
= data
;
742 struct acpi_resource_extended_irq
*irq
;
743 struct acpi_resource_gpio
*gpio
;
744 struct acpi_resource_uart_serialbus
*sb
;
746 switch (ares
->type
) {
747 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
748 irq
= &ares
->data
.extended_irq
;
749 dev
->irq_active_low
= irq
->polarity
== ACPI_ACTIVE_LOW
;
752 case ACPI_RESOURCE_TYPE_GPIO
:
753 gpio
= &ares
->data
.gpio
;
754 if (gpio
->connection_type
== ACPI_RESOURCE_GPIO_TYPE_INT
)
755 dev
->irq_active_low
= gpio
->polarity
== ACPI_ACTIVE_LOW
;
758 case ACPI_RESOURCE_TYPE_SERIAL_BUS
:
759 sb
= &ares
->data
.uart_serial_bus
;
760 if (sb
->type
== ACPI_RESOURCE_SERIAL_TYPE_UART
) {
761 dev
->init_speed
= sb
->default_baud_rate
;
762 dev
->oper_speed
= 4000000;
772 #endif /* CONFIG_ACPI */
774 static int bcm_get_resources(struct bcm_device
*dev
)
776 dev
->name
= dev_name(dev
->dev
);
778 dev
->clk
= devm_clk_get(dev
->dev
, NULL
);
780 dev
->device_wakeup
= devm_gpiod_get_optional(dev
->dev
,
783 if (IS_ERR(dev
->device_wakeup
))
784 return PTR_ERR(dev
->device_wakeup
);
786 dev
->shutdown
= devm_gpiod_get_optional(dev
->dev
, "shutdown",
788 if (IS_ERR(dev
->shutdown
))
789 return PTR_ERR(dev
->shutdown
);
791 /* IRQ can be declared in ACPI table as Interrupt or GpioInt */
793 struct gpio_desc
*gpio
;
795 gpio
= devm_gpiod_get_optional(dev
->dev
, "host-wakeup",
798 return PTR_ERR(gpio
);
800 dev
->irq
= gpiod_to_irq(gpio
);
803 dev_info(dev
->dev
, "BCM irq: %d\n", dev
->irq
);
808 static int bcm_acpi_probe(struct bcm_device
*dev
)
810 LIST_HEAD(resources
);
811 const struct dmi_system_id
*dmi_id
;
812 const struct acpi_gpio_mapping
*gpio_mapping
= acpi_bcm_int_last_gpios
;
813 const struct acpi_device_id
*id
;
814 struct resource_entry
*entry
;
817 /* Retrieve GPIO data */
818 id
= acpi_match_device(dev
->dev
->driver
->acpi_match_table
, dev
->dev
);
820 gpio_mapping
= (const struct acpi_gpio_mapping
*) id
->driver_data
;
822 ret
= devm_acpi_dev_add_driver_gpios(dev
->dev
, gpio_mapping
);
826 /* Retrieve UART ACPI info */
827 ret
= acpi_dev_get_resources(ACPI_COMPANION(dev
->dev
),
828 &resources
, bcm_resource
, dev
);
832 resource_list_for_each_entry(entry
, &resources
) {
833 if (resource_type(entry
->res
) == IORESOURCE_IRQ
) {
834 dev
->irq
= entry
->res
->start
;
838 acpi_dev_free_resource_list(&resources
);
840 dmi_id
= dmi_first_match(bcm_active_low_irq_dmi_table
);
842 dev_warn(dev
->dev
, "%s: Overwriting IRQ polarity to active low",
844 dev
->irq_active_low
= true;
850 static int bcm_acpi_probe(struct bcm_device
*dev
)
854 #endif /* CONFIG_ACPI */
856 static int bcm_of_probe(struct bcm_device
*bdev
)
858 device_property_read_u32(bdev
->dev
, "max-speed", &bdev
->oper_speed
);
862 static int bcm_probe(struct platform_device
*pdev
)
864 struct bcm_device
*dev
;
867 dev
= devm_kzalloc(&pdev
->dev
, sizeof(*dev
), GFP_KERNEL
);
871 dev
->dev
= &pdev
->dev
;
872 dev
->irq
= platform_get_irq(pdev
, 0);
874 if (has_acpi_companion(&pdev
->dev
)) {
875 ret
= bcm_acpi_probe(dev
);
880 ret
= bcm_get_resources(dev
);
884 platform_set_drvdata(pdev
, dev
);
886 dev_info(&pdev
->dev
, "%s device registered.\n", dev
->name
);
888 /* Place this instance on the device list */
889 mutex_lock(&bcm_device_lock
);
890 list_add_tail(&dev
->list
, &bcm_device_list
);
891 mutex_unlock(&bcm_device_lock
);
893 bcm_gpio_set_power(dev
, false);
898 static int bcm_remove(struct platform_device
*pdev
)
900 struct bcm_device
*dev
= platform_get_drvdata(pdev
);
902 mutex_lock(&bcm_device_lock
);
903 list_del(&dev
->list
);
904 mutex_unlock(&bcm_device_lock
);
906 dev_info(&pdev
->dev
, "%s device unregistered.\n", dev
->name
);
911 static const struct hci_uart_proto bcm_proto
= {
915 .init_speed
= 115200,
920 .set_baudrate
= bcm_set_baudrate
,
922 .enqueue
= bcm_enqueue
,
923 .dequeue
= bcm_dequeue
,
927 static const struct acpi_device_id bcm_acpi_match
[] = {
928 { "BCM2E1A", (kernel_ulong_t
)&acpi_bcm_int_last_gpios
},
929 { "BCM2E39", (kernel_ulong_t
)&acpi_bcm_int_last_gpios
},
930 { "BCM2E3A", (kernel_ulong_t
)&acpi_bcm_int_last_gpios
},
931 { "BCM2E3D", (kernel_ulong_t
)&acpi_bcm_int_last_gpios
},
932 { "BCM2E3F", (kernel_ulong_t
)&acpi_bcm_int_last_gpios
},
933 { "BCM2E40", (kernel_ulong_t
)&acpi_bcm_int_last_gpios
},
934 { "BCM2E54", (kernel_ulong_t
)&acpi_bcm_int_last_gpios
},
935 { "BCM2E55", (kernel_ulong_t
)&acpi_bcm_int_last_gpios
},
936 { "BCM2E64", (kernel_ulong_t
)&acpi_bcm_int_last_gpios
},
937 { "BCM2E65", (kernel_ulong_t
)&acpi_bcm_int_last_gpios
},
938 { "BCM2E67", (kernel_ulong_t
)&acpi_bcm_int_last_gpios
},
939 { "BCM2E71", (kernel_ulong_t
)&acpi_bcm_int_last_gpios
},
940 { "BCM2E7B", (kernel_ulong_t
)&acpi_bcm_int_last_gpios
},
941 { "BCM2E7C", (kernel_ulong_t
)&acpi_bcm_int_last_gpios
},
942 { "BCM2E95", (kernel_ulong_t
)&acpi_bcm_int_first_gpios
},
943 { "BCM2E96", (kernel_ulong_t
)&acpi_bcm_int_first_gpios
},
944 { "BCM2EA4", (kernel_ulong_t
)&acpi_bcm_int_first_gpios
},
947 MODULE_DEVICE_TABLE(acpi
, bcm_acpi_match
);
950 /* suspend and resume callbacks */
951 static const struct dev_pm_ops bcm_pm_ops
= {
952 SET_SYSTEM_SLEEP_PM_OPS(bcm_suspend
, bcm_resume
)
953 SET_RUNTIME_PM_OPS(bcm_suspend_device
, bcm_resume_device
, NULL
)
956 static struct platform_driver bcm_driver
= {
958 .remove
= bcm_remove
,
961 .acpi_match_table
= ACPI_PTR(bcm_acpi_match
),
966 static int bcm_serdev_probe(struct serdev_device
*serdev
)
968 struct bcm_device
*bcmdev
;
971 bcmdev
= devm_kzalloc(&serdev
->dev
, sizeof(*bcmdev
), GFP_KERNEL
);
975 bcmdev
->dev
= &serdev
->dev
;
976 bcmdev
->hu
= &bcmdev
->serdev_hu
;
977 bcmdev
->serdev_hu
.serdev
= serdev
;
978 serdev_device_set_drvdata(serdev
, bcmdev
);
980 if (has_acpi_companion(&serdev
->dev
))
981 err
= bcm_acpi_probe(bcmdev
);
983 err
= bcm_of_probe(bcmdev
);
987 err
= bcm_get_resources(bcmdev
);
991 bcm_gpio_set_power(bcmdev
, false);
993 return hci_uart_register_device(&bcmdev
->serdev_hu
, &bcm_proto
);
996 static void bcm_serdev_remove(struct serdev_device
*serdev
)
998 struct bcm_device
*bcmdev
= serdev_device_get_drvdata(serdev
);
1000 hci_uart_unregister_device(&bcmdev
->serdev_hu
);
1004 static const struct of_device_id bcm_bluetooth_of_match
[] = {
1005 { .compatible
= "brcm,bcm43438-bt" },
1008 MODULE_DEVICE_TABLE(of
, bcm_bluetooth_of_match
);
1011 static struct serdev_device_driver bcm_serdev_driver
= {
1012 .probe
= bcm_serdev_probe
,
1013 .remove
= bcm_serdev_remove
,
1015 .name
= "hci_uart_bcm",
1016 .of_match_table
= of_match_ptr(bcm_bluetooth_of_match
),
1017 .acpi_match_table
= ACPI_PTR(bcm_acpi_match
),
1022 int __init
bcm_init(void)
1024 /* For now, we need to keep both platform device
1025 * driver (ACPI generated) and serdev driver (DT).
1027 platform_driver_register(&bcm_driver
);
1028 serdev_device_driver_register(&bcm_serdev_driver
);
1030 return hci_uart_register_proto(&bcm_proto
);
1033 int __exit
bcm_deinit(void)
1035 platform_driver_unregister(&bcm_driver
);
1036 serdev_device_driver_unregister(&bcm_serdev_driver
);
1038 return hci_uart_unregister_proto(&bcm_proto
);