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)
156 /* Devices using serdev always exist */
157 if (device && device->hu && device->hu->serdev)
161 list_for_each(p, &bcm_device_list) {
162 struct bcm_device *dev = list_entry(p, struct bcm_device, list);
171 static int bcm_gpio_set_power(struct bcm_device *dev, bool powered)
173 if (powered && !IS_ERR(dev->clk) && !dev->clk_enabled)
174 clk_prepare_enable(dev->clk);
176 gpiod_set_value(dev->shutdown, powered);
177 gpiod_set_value(dev->device_wakeup, powered);
179 if (!powered && !IS_ERR(dev->clk) && dev->clk_enabled)
180 clk_disable_unprepare(dev->clk);
182 dev->clk_enabled = powered;
188 static irqreturn_t bcm_host_wake(int irq, void *data)
190 struct bcm_device *bdev = data;
192 bt_dev_dbg(bdev, "Host wake IRQ");
194 pm_runtime_get(bdev->dev);
195 pm_runtime_mark_last_busy(bdev->dev);
196 pm_runtime_put_autosuspend(bdev->dev);
201 static int bcm_request_irq(struct bcm_data *bcm)
203 struct bcm_device *bdev = bcm->dev;
206 mutex_lock(&bcm_device_lock);
207 if (!bcm_device_exists(bdev)) {
212 if (bdev->irq <= 0) {
217 err = devm_request_irq(bdev->dev, bdev->irq, bcm_host_wake,
218 bdev->irq_active_low ? IRQF_TRIGGER_FALLING :
224 device_init_wakeup(bdev->dev, true);
226 pm_runtime_set_autosuspend_delay(bdev->dev,
227 BCM_AUTOSUSPEND_DELAY);
228 pm_runtime_use_autosuspend(bdev->dev);
229 pm_runtime_set_active(bdev->dev);
230 pm_runtime_enable(bdev->dev);
233 mutex_unlock(&bcm_device_lock);
238 static const struct bcm_set_sleep_mode default_sleep_params = {
239 .sleep_mode = 1, /* 0=Disabled, 1=UART, 2=Reserved, 3=USB */
240 .idle_host = 2, /* idle threshold HOST, in 300ms */
241 .idle_dev = 2, /* idle threshold device, in 300ms */
242 .bt_wake_active = 1, /* BT_WAKE active mode: 1 = high, 0 = low */
243 .host_wake_active = 0, /* HOST_WAKE active mode: 1 = high, 0 = low */
244 .allow_host_sleep = 1, /* Allow host sleep in SCO flag */
245 .combine_modes = 1, /* Combine sleep and LPM flag */
246 .tristate_control = 0, /* Allow tri-state control of UART tx flag */
247 /* Irrelevant USB flags */
249 .usb_resume_timeout = 0,
250 .pulsed_host_wake = 0,
254 static int bcm_setup_sleep(struct hci_uart *hu)
256 struct bcm_data *bcm = hu->priv;
258 struct bcm_set_sleep_mode sleep_params = default_sleep_params;
260 sleep_params.host_wake_active = !bcm->dev->irq_active_low;
262 skb = __hci_cmd_sync(hu->hdev, 0xfc27, sizeof(sleep_params),
263 &sleep_params, HCI_INIT_TIMEOUT);
265 int err = PTR_ERR(skb);
266 bt_dev_err(hu->hdev, "Sleep VSC failed (%d)", err);
271 bt_dev_dbg(hu->hdev, "Set Sleep Parameters VSC succeeded");
276 static inline int bcm_request_irq(struct bcm_data *bcm) { return 0; }
277 static inline int bcm_setup_sleep(struct hci_uart *hu) { return 0; }
280 static int bcm_set_diag(struct hci_dev *hdev, bool enable)
282 struct hci_uart *hu = hci_get_drvdata(hdev);
283 struct bcm_data *bcm = hu->priv;
286 if (!test_bit(HCI_RUNNING, &hdev->flags))
289 skb = bt_skb_alloc(3, GFP_KERNEL);
293 skb_put_u8(skb, BCM_LM_DIAG_PKT);
294 skb_put_u8(skb, 0xf0);
295 skb_put_u8(skb, enable);
297 skb_queue_tail(&bcm->txq, skb);
298 hci_uart_tx_wakeup(hu);
303 static int bcm_open(struct hci_uart *hu)
305 struct bcm_data *bcm;
308 bt_dev_dbg(hu->hdev, "hu %p", hu);
310 bcm = kzalloc(sizeof(*bcm), GFP_KERNEL);
314 skb_queue_head_init(&bcm->txq);
318 mutex_lock(&bcm_device_lock);
321 serdev_device_open(hu->serdev);
322 bcm->dev = serdev_device_get_drvdata(hu->serdev);
329 list_for_each(p, &bcm_device_list) {
330 struct bcm_device *dev = list_entry(p, struct bcm_device, list);
332 /* Retrieve saved bcm_device based on parent of the
333 * platform device (saved during device probe) and
334 * parent of tty device used by hci_uart
336 if (hu->tty->dev->parent == dev->dev->parent) {
347 hu->init_speed = bcm->dev->init_speed;
348 hu->oper_speed = bcm->dev->oper_speed;
349 bcm_gpio_set_power(bcm->dev, true);
352 mutex_unlock(&bcm_device_lock);
356 static int bcm_close(struct hci_uart *hu)
358 struct bcm_data *bcm = hu->priv;
359 struct bcm_device *bdev = NULL;
361 bt_dev_dbg(hu->hdev, "hu %p", hu);
363 /* Protect bcm->dev against removal of the device or driver */
364 mutex_lock(&bcm_device_lock);
367 serdev_device_close(hu->serdev);
368 bdev = serdev_device_get_drvdata(hu->serdev);
369 } else if (bcm_device_exists(bcm->dev)) {
377 bcm_gpio_set_power(bdev, false);
379 pm_runtime_disable(bdev->dev);
380 pm_runtime_set_suspended(bdev->dev);
382 if (device_can_wakeup(bdev->dev)) {
383 devm_free_irq(bdev->dev, bdev->irq, bdev);
384 device_init_wakeup(bdev->dev, false);
388 mutex_unlock(&bcm_device_lock);
390 skb_queue_purge(&bcm->txq);
391 kfree_skb(bcm->rx_skb);
398 static int bcm_flush(struct hci_uart *hu)
400 struct bcm_data *bcm = hu->priv;
402 bt_dev_dbg(hu->hdev, "hu %p", hu);
404 skb_queue_purge(&bcm->txq);
409 static int bcm_setup(struct hci_uart *hu)
411 struct bcm_data *bcm = hu->priv;
413 const struct firmware *fw;
417 bt_dev_dbg(hu->hdev, "hu %p", hu);
419 hu->hdev->set_diag = bcm_set_diag;
420 hu->hdev->set_bdaddr = btbcm_set_bdaddr;
422 err = btbcm_initialize(hu->hdev, fw_name, sizeof(fw_name));
426 err = request_firmware(&fw, fw_name, &hu->hdev->dev);
428 bt_dev_info(hu->hdev, "BCM: Patch %s not found", fw_name);
432 err = btbcm_patchram(hu->hdev, fw);
434 bt_dev_info(hu->hdev, "BCM: Patch failed (%d)", err);
438 /* Init speed if any */
440 speed = hu->init_speed;
441 else if (hu->proto->init_speed)
442 speed = hu->proto->init_speed;
447 host_set_baudrate(hu, speed);
449 /* Operational speed if any */
451 speed = hu->oper_speed;
452 else if (hu->proto->oper_speed)
453 speed = hu->proto->oper_speed;
458 err = bcm_set_baudrate(hu, speed);
460 host_set_baudrate(hu, speed);
464 release_firmware(fw);
466 err = btbcm_finalize(hu->hdev);
470 if (!bcm_request_irq(bcm))
471 err = bcm_setup_sleep(hu);
476 #define BCM_RECV_LM_DIAG \
477 .type = BCM_LM_DIAG_PKT, \
478 .hlen = BCM_LM_DIAG_SIZE, \
481 .maxlen = BCM_LM_DIAG_SIZE
483 #define BCM_RECV_NULL \
484 .type = BCM_NULL_PKT, \
485 .hlen = BCM_NULL_SIZE, \
488 .maxlen = BCM_NULL_SIZE
490 static const struct h4_recv_pkt bcm_recv_pkts[] = {
491 { H4_RECV_ACL, .recv = hci_recv_frame },
492 { H4_RECV_SCO, .recv = hci_recv_frame },
493 { H4_RECV_EVENT, .recv = hci_recv_frame },
494 { BCM_RECV_LM_DIAG, .recv = hci_recv_diag },
495 { BCM_RECV_NULL, .recv = hci_recv_diag },
498 static int bcm_recv(struct hci_uart *hu, const void *data, int count)
500 struct bcm_data *bcm = hu->priv;
502 if (!test_bit(HCI_UART_REGISTERED, &hu->flags))
505 bcm->rx_skb = h4_recv_buf(hu->hdev, bcm->rx_skb, data, count,
506 bcm_recv_pkts, ARRAY_SIZE(bcm_recv_pkts));
507 if (IS_ERR(bcm->rx_skb)) {
508 int err = PTR_ERR(bcm->rx_skb);
509 bt_dev_err(hu->hdev, "Frame reassembly failed (%d)", err);
512 } else if (!bcm->rx_skb) {
513 /* Delay auto-suspend when receiving completed packet */
514 mutex_lock(&bcm_device_lock);
515 if (bcm->dev && bcm_device_exists(bcm->dev)) {
516 pm_runtime_get(bcm->dev->dev);
517 pm_runtime_mark_last_busy(bcm->dev->dev);
518 pm_runtime_put_autosuspend(bcm->dev->dev);
520 mutex_unlock(&bcm_device_lock);
526 static int bcm_enqueue(struct hci_uart *hu, struct sk_buff *skb)
528 struct bcm_data *bcm = hu->priv;
530 bt_dev_dbg(hu->hdev, "hu %p skb %p", hu, skb);
532 /* Prepend skb with frame type */
533 memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1);
534 skb_queue_tail(&bcm->txq, skb);
539 static struct sk_buff *bcm_dequeue(struct hci_uart *hu)
541 struct bcm_data *bcm = hu->priv;
542 struct sk_buff *skb = NULL;
543 struct bcm_device *bdev = NULL;
545 mutex_lock(&bcm_device_lock);
547 if (bcm_device_exists(bcm->dev)) {
549 pm_runtime_get_sync(bdev->dev);
550 /* Shall be resumed here */
553 skb = skb_dequeue(&bcm->txq);
556 pm_runtime_mark_last_busy(bdev->dev);
557 pm_runtime_put_autosuspend(bdev->dev);
560 mutex_unlock(&bcm_device_lock);
566 static int bcm_suspend_device(struct device *dev)
568 struct bcm_device *bdev = dev_get_drvdata(dev);
570 bt_dev_dbg(bdev, "");
572 if (!bdev->is_suspended && bdev->hu) {
573 hci_uart_set_flow_control(bdev->hu, true);
575 /* Once this returns, driver suspends BT via GPIO */
576 bdev->is_suspended = true;
579 /* Suspend the device */
580 if (bdev->device_wakeup) {
581 gpiod_set_value(bdev->device_wakeup, false);
582 bt_dev_dbg(bdev, "suspend, delaying 15 ms");
589 static int bcm_resume_device(struct device *dev)
591 struct bcm_device *bdev = dev_get_drvdata(dev);
593 bt_dev_dbg(bdev, "");
595 if (bdev->device_wakeup) {
596 gpiod_set_value(bdev->device_wakeup, true);
597 bt_dev_dbg(bdev, "resume, delaying 15 ms");
601 /* When this executes, the device has woken up already */
602 if (bdev->is_suspended && bdev->hu) {
603 bdev->is_suspended = false;
605 hci_uart_set_flow_control(bdev->hu, false);
612 #ifdef CONFIG_PM_SLEEP
613 /* suspend callback */
614 static int bcm_suspend(struct device *dev)
616 struct bcm_device *bdev = dev_get_drvdata(dev);
619 bt_dev_dbg(bdev, "suspend: is_suspended %d", bdev->is_suspended);
622 * When used with a device instantiated as platform_device, bcm_suspend
623 * can be called at any time as long as the platform device is bound,
624 * so it should use bcm_device_lock to protect access to hci_uart
625 * and device_wake-up GPIO.
627 mutex_lock(&bcm_device_lock);
632 if (pm_runtime_active(dev))
633 bcm_suspend_device(dev);
635 if (device_may_wakeup(dev)) {
636 error = enable_irq_wake(bdev->irq);
638 bt_dev_dbg(bdev, "BCM irq: enabled");
642 mutex_unlock(&bcm_device_lock);
647 /* resume callback */
648 static int bcm_resume(struct device *dev)
650 struct bcm_device *bdev = dev_get_drvdata(dev);
652 bt_dev_dbg(bdev, "resume: is_suspended %d", bdev->is_suspended);
655 * When used with a device instantiated as platform_device, bcm_resume
656 * can be called at any time as long as platform device is bound,
657 * so it should use bcm_device_lock to protect access to hci_uart
658 * and device_wake-up GPIO.
660 mutex_lock(&bcm_device_lock);
665 if (device_may_wakeup(dev)) {
666 disable_irq_wake(bdev->irq);
667 bt_dev_dbg(bdev, "BCM irq: disabled");
670 bcm_resume_device(dev);
673 mutex_unlock(&bcm_device_lock);
675 pm_runtime_disable(dev);
676 pm_runtime_set_active(dev);
677 pm_runtime_enable(dev);
683 static const struct acpi_gpio_params int_last_device_wakeup_gpios = { 0, 0, false };
684 static const struct acpi_gpio_params int_last_shutdown_gpios = { 1, 0, false };
685 static const struct acpi_gpio_params int_last_host_wakeup_gpios = { 2, 0, false };
687 static const struct acpi_gpio_mapping acpi_bcm_int_last_gpios[] = {
688 { "device-wakeup-gpios", &int_last_device_wakeup_gpios, 1 },
689 { "shutdown-gpios", &int_last_shutdown_gpios, 1 },
690 { "host-wakeup-gpios", &int_last_host_wakeup_gpios, 1 },
694 static const struct acpi_gpio_params int_first_host_wakeup_gpios = { 0, 0, false };
695 static const struct acpi_gpio_params int_first_device_wakeup_gpios = { 1, 0, false };
696 static const struct acpi_gpio_params int_first_shutdown_gpios = { 2, 0, false };
698 static const struct acpi_gpio_mapping acpi_bcm_int_first_gpios[] = {
699 { "device-wakeup-gpios", &int_first_device_wakeup_gpios, 1 },
700 { "shutdown-gpios", &int_first_shutdown_gpios, 1 },
701 { "host-wakeup-gpios", &int_first_host_wakeup_gpios, 1 },
706 /* IRQ polarity of some chipsets are not defined correctly in ACPI table. */
707 static const struct dmi_system_id bcm_active_low_irq_dmi_table[] = {
709 .ident = "Asus T100TA",
711 DMI_EXACT_MATCH(DMI_SYS_VENDOR,
712 "ASUSTeK COMPUTER INC."),
713 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TA"),
717 .ident = "Asus T100CHI",
719 DMI_EXACT_MATCH(DMI_SYS_VENDOR,
720 "ASUSTeK COMPUTER INC."),
721 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100CHI"),
724 { /* Handle ThinkPad 8 tablets with BCM2E55 chipset ACPI ID */
725 .ident = "Lenovo ThinkPad 8",
727 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
728 DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "ThinkPad 8"),
732 .ident = "MINIX Z83-4",
734 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "MINIX"),
735 DMI_MATCH(DMI_PRODUCT_NAME, "Z83-4"),
741 static int bcm_resource(struct acpi_resource *ares, void *data)
743 struct bcm_device *dev = data;
744 struct acpi_resource_extended_irq *irq;
745 struct acpi_resource_gpio *gpio;
746 struct acpi_resource_uart_serialbus *sb;
748 switch (ares->type) {
749 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
750 irq = &ares->data.extended_irq;
751 dev->irq_active_low = irq->polarity == ACPI_ACTIVE_LOW;
754 case ACPI_RESOURCE_TYPE_GPIO:
755 gpio = &ares->data.gpio;
756 if (gpio->connection_type == ACPI_RESOURCE_GPIO_TYPE_INT)
757 dev->irq_active_low = gpio->polarity == ACPI_ACTIVE_LOW;
760 case ACPI_RESOURCE_TYPE_SERIAL_BUS:
761 sb = &ares->data.uart_serial_bus;
762 if (sb->type == ACPI_RESOURCE_SERIAL_TYPE_UART) {
763 dev->init_speed = sb->default_baud_rate;
764 dev->oper_speed = 4000000;
774 #endif /* CONFIG_ACPI */
776 static int bcm_get_resources(struct bcm_device *dev)
778 dev->name = dev_name(dev->dev);
780 dev->clk = devm_clk_get(dev->dev, NULL);
782 dev->device_wakeup = devm_gpiod_get_optional(dev->dev,
785 if (IS_ERR(dev->device_wakeup))
786 return PTR_ERR(dev->device_wakeup);
788 dev->shutdown = devm_gpiod_get_optional(dev->dev, "shutdown",
790 if (IS_ERR(dev->shutdown))
791 return PTR_ERR(dev->shutdown);
793 /* IRQ can be declared in ACPI table as Interrupt or GpioInt */
795 struct gpio_desc *gpio;
797 gpio = devm_gpiod_get_optional(dev->dev, "host-wakeup",
800 return PTR_ERR(gpio);
802 dev->irq = gpiod_to_irq(gpio);
805 dev_info(dev->dev, "BCM irq: %d\n", dev->irq);
810 static int bcm_acpi_probe(struct bcm_device *dev)
812 LIST_HEAD(resources);
813 const struct dmi_system_id *dmi_id;
814 const struct acpi_gpio_mapping *gpio_mapping = acpi_bcm_int_last_gpios;
815 const struct acpi_device_id *id;
816 struct resource_entry *entry;
819 /* Retrieve GPIO data */
820 id = acpi_match_device(dev->dev->driver->acpi_match_table, dev->dev);
822 gpio_mapping = (const struct acpi_gpio_mapping *) id->driver_data;
824 ret = devm_acpi_dev_add_driver_gpios(dev->dev, gpio_mapping);
828 /* Retrieve UART ACPI info */
829 ret = acpi_dev_get_resources(ACPI_COMPANION(dev->dev),
830 &resources, bcm_resource, dev);
834 resource_list_for_each_entry(entry, &resources) {
835 if (resource_type(entry->res) == IORESOURCE_IRQ) {
836 dev->irq = entry->res->start;
840 acpi_dev_free_resource_list(&resources);
842 dmi_id = dmi_first_match(bcm_active_low_irq_dmi_table);
844 dev_warn(dev->dev, "%s: Overwriting IRQ polarity to active low",
846 dev->irq_active_low = true;
852 static int bcm_acpi_probe(struct bcm_device *dev)
856 #endif /* CONFIG_ACPI */
858 static int bcm_of_probe(struct bcm_device *bdev)
860 device_property_read_u32(bdev->dev, "max-speed", &bdev->oper_speed);
864 static int bcm_probe(struct platform_device *pdev)
866 struct bcm_device *dev;
869 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
873 dev->dev = &pdev->dev;
874 dev->irq = platform_get_irq(pdev, 0);
876 if (has_acpi_companion(&pdev->dev)) {
877 ret = bcm_acpi_probe(dev);
882 ret = bcm_get_resources(dev);
886 platform_set_drvdata(pdev, dev);
888 dev_info(&pdev->dev, "%s device registered.\n", dev->name);
890 /* Place this instance on the device list */
891 mutex_lock(&bcm_device_lock);
892 list_add_tail(&dev->list, &bcm_device_list);
893 mutex_unlock(&bcm_device_lock);
895 bcm_gpio_set_power(dev, false);
900 static int bcm_remove(struct platform_device *pdev)
902 struct bcm_device *dev = platform_get_drvdata(pdev);
904 mutex_lock(&bcm_device_lock);
905 list_del(&dev->list);
906 mutex_unlock(&bcm_device_lock);
908 dev_info(&pdev->dev, "%s device unregistered.\n", dev->name);
913 static const struct hci_uart_proto bcm_proto = {
917 .init_speed = 115200,
922 .set_baudrate = bcm_set_baudrate,
924 .enqueue = bcm_enqueue,
925 .dequeue = bcm_dequeue,
929 static const struct acpi_device_id bcm_acpi_match[] = {
930 { "BCM2E1A", (kernel_ulong_t)&acpi_bcm_int_last_gpios },
931 { "BCM2E39", (kernel_ulong_t)&acpi_bcm_int_last_gpios },
932 { "BCM2E3A", (kernel_ulong_t)&acpi_bcm_int_last_gpios },
933 { "BCM2E3D", (kernel_ulong_t)&acpi_bcm_int_last_gpios },
934 { "BCM2E3F", (kernel_ulong_t)&acpi_bcm_int_last_gpios },
935 { "BCM2E40", (kernel_ulong_t)&acpi_bcm_int_last_gpios },
936 { "BCM2E54", (kernel_ulong_t)&acpi_bcm_int_last_gpios },
937 { "BCM2E55", (kernel_ulong_t)&acpi_bcm_int_last_gpios },
938 { "BCM2E64", (kernel_ulong_t)&acpi_bcm_int_last_gpios },
939 { "BCM2E65", (kernel_ulong_t)&acpi_bcm_int_last_gpios },
940 { "BCM2E67", (kernel_ulong_t)&acpi_bcm_int_last_gpios },
941 { "BCM2E71", (kernel_ulong_t)&acpi_bcm_int_last_gpios },
942 { "BCM2E7B", (kernel_ulong_t)&acpi_bcm_int_last_gpios },
943 { "BCM2E7C", (kernel_ulong_t)&acpi_bcm_int_last_gpios },
944 { "BCM2E7E", (kernel_ulong_t)&acpi_bcm_int_first_gpios },
945 { "BCM2E95", (kernel_ulong_t)&acpi_bcm_int_first_gpios },
946 { "BCM2E96", (kernel_ulong_t)&acpi_bcm_int_first_gpios },
947 { "BCM2EA4", (kernel_ulong_t)&acpi_bcm_int_first_gpios },
950 MODULE_DEVICE_TABLE(acpi, bcm_acpi_match);
953 /* suspend and resume callbacks */
954 static const struct dev_pm_ops bcm_pm_ops = {
955 SET_SYSTEM_SLEEP_PM_OPS(bcm_suspend, bcm_resume)
956 SET_RUNTIME_PM_OPS(bcm_suspend_device, bcm_resume_device, NULL)
959 static struct platform_driver bcm_driver = {
961 .remove = bcm_remove,
964 .acpi_match_table = ACPI_PTR(bcm_acpi_match),
969 static int bcm_serdev_probe(struct serdev_device *serdev)
971 struct bcm_device *bcmdev;
974 bcmdev = devm_kzalloc(&serdev->dev, sizeof(*bcmdev), GFP_KERNEL);
978 bcmdev->dev = &serdev->dev;
980 bcmdev->hu = &bcmdev->serdev_hu;
982 bcmdev->serdev_hu.serdev = serdev;
983 serdev_device_set_drvdata(serdev, bcmdev);
985 if (has_acpi_companion(&serdev->dev))
986 err = bcm_acpi_probe(bcmdev);
988 err = bcm_of_probe(bcmdev);
992 err = bcm_get_resources(bcmdev);
996 bcm_gpio_set_power(bcmdev, false);
998 return hci_uart_register_device(&bcmdev->serdev_hu, &bcm_proto);
1001 static void bcm_serdev_remove(struct serdev_device *serdev)
1003 struct bcm_device *bcmdev = serdev_device_get_drvdata(serdev);
1005 hci_uart_unregister_device(&bcmdev->serdev_hu);
1009 static const struct of_device_id bcm_bluetooth_of_match[] = {
1010 { .compatible = "brcm,bcm43438-bt" },
1013 MODULE_DEVICE_TABLE(of, bcm_bluetooth_of_match);
1016 static struct serdev_device_driver bcm_serdev_driver = {
1017 .probe = bcm_serdev_probe,
1018 .remove = bcm_serdev_remove,
1020 .name = "hci_uart_bcm",
1021 .of_match_table = of_match_ptr(bcm_bluetooth_of_match),
1022 .acpi_match_table = ACPI_PTR(bcm_acpi_match),
1027 int __init bcm_init(void)
1029 /* For now, we need to keep both platform device
1030 * driver (ACPI generated) and serdev driver (DT).
1032 platform_driver_register(&bcm_driver);
1033 serdev_device_driver_register(&bcm_serdev_driver);
1035 return hci_uart_register_proto(&bcm_proto);
1038 int __exit bcm_deinit(void)
1040 platform_driver_unregister(&bcm_driver);
1041 serdev_device_driver_unregister(&bcm_serdev_driver);
1043 return hci_uart_unregister_proto(&bcm_proto);