Lines Matching +full:bcm4330 +full:- +full:bt

1 // SPDX-License-Identifier: GPL-2.0-or-later
52 * struct bcm_device_data - device specific data
61 * struct bcm_device - device driver resources
140 /* List of BCM BT UART devices */
144 static int irq_polarity = -1;
146 MODULE_PARM_DESC(irq_polarity, "IRQ polarity 0: active-high 1: active-low");
150 if (hu->serdev) in host_set_baudrate()
151 serdev_device_set_baudrate(hu->serdev, speed); in host_set_baudrate()
158 struct hci_dev *hdev = hu->hdev; in bcm_set_baudrate()
212 if (device && device->hu && device->hu->serdev) in bcm_device_exists()
230 if (powered && !dev->res_enabled) { in bcm_gpio_set_power()
234 if (dev->supplies[0].supply) { in bcm_gpio_set_power()
236 dev->supplies); in bcm_gpio_set_power()
242 err = clk_set_rate(dev->lpo_clk, 32768); in bcm_gpio_set_power()
244 dev_err(dev->dev, "Could not set LPO clock rate\n"); in bcm_gpio_set_power()
248 err = clk_prepare_enable(dev->lpo_clk); in bcm_gpio_set_power()
252 err = clk_prepare_enable(dev->txco_clk); in bcm_gpio_set_power()
257 err = dev->set_shutdown(dev, powered); in bcm_gpio_set_power()
261 err = dev->set_device_wakeup(dev, powered); in bcm_gpio_set_power()
265 if (!powered && dev->res_enabled) { in bcm_gpio_set_power()
266 clk_disable_unprepare(dev->txco_clk); in bcm_gpio_set_power()
267 clk_disable_unprepare(dev->lpo_clk); in bcm_gpio_set_power()
272 if (dev->supplies[0].supply) in bcm_gpio_set_power()
274 dev->supplies); in bcm_gpio_set_power()
280 dev->res_enabled = powered; in bcm_gpio_set_power()
285 dev->set_shutdown(dev, !powered); in bcm_gpio_set_power()
287 if (powered && !dev->res_enabled) in bcm_gpio_set_power()
288 clk_disable_unprepare(dev->txco_clk); in bcm_gpio_set_power()
290 if (powered && !dev->res_enabled) in bcm_gpio_set_power()
291 clk_disable_unprepare(dev->lpo_clk); in bcm_gpio_set_power()
293 if (powered && !dev->res_enabled) in bcm_gpio_set_power()
294 regulator_bulk_disable(BCM_NUM_SUPPLIES, dev->supplies); in bcm_gpio_set_power()
305 pm_runtime_get(bdev->dev); in bcm_host_wake()
306 pm_runtime_mark_last_busy(bdev->dev); in bcm_host_wake()
307 pm_runtime_put_autosuspend(bdev->dev); in bcm_host_wake()
314 struct bcm_device *bdev = bcm->dev; in bcm_request_irq()
319 err = -ENODEV; in bcm_request_irq()
323 if (bdev->irq <= 0) { in bcm_request_irq()
324 err = -EOPNOTSUPP; in bcm_request_irq()
328 err = devm_request_irq(bdev->dev, bdev->irq, bcm_host_wake, in bcm_request_irq()
329 bdev->irq_active_low ? IRQF_TRIGGER_FALLING : in bcm_request_irq()
333 bdev->irq = err; in bcm_request_irq()
337 bdev->irq_acquired = true; in bcm_request_irq()
339 device_init_wakeup(bdev->dev, true); in bcm_request_irq()
341 pm_runtime_set_autosuspend_delay(bdev->dev, in bcm_request_irq()
343 pm_runtime_use_autosuspend(bdev->dev); in bcm_request_irq()
344 pm_runtime_set_active(bdev->dev); in bcm_request_irq()
345 pm_runtime_enable(bdev->dev); in bcm_request_irq()
361 .tristate_control = 0, /* Allow tri-state control of UART tx flag */
371 struct bcm_data *bcm = hu->priv; in bcm_setup_sleep()
375 sleep_params.host_wake_active = !bcm->dev->irq_active_low; in bcm_setup_sleep()
377 skb = __hci_cmd_sync(hu->hdev, 0xfc27, sizeof(sleep_params), in bcm_setup_sleep()
381 bt_dev_err(hu->hdev, "Sleep VSC failed (%d)", err); in bcm_setup_sleep()
386 bt_dev_dbg(hu->hdev, "Set Sleep Parameters VSC succeeded"); in bcm_setup_sleep()
398 struct bcm_data *bcm = hu->priv; in bcm_set_diag()
401 if (!test_bit(HCI_RUNNING, &hdev->flags)) in bcm_set_diag()
402 return -ENETDOWN; in bcm_set_diag()
406 return -ENOMEM; in bcm_set_diag()
412 skb_queue_tail(&bcm->txq, skb); in bcm_set_diag()
424 bt_dev_dbg(hu->hdev, "hu %p", hu); in bcm_open()
427 return -EOPNOTSUPP; in bcm_open()
431 return -ENOMEM; in bcm_open()
433 skb_queue_head_init(&bcm->txq); in bcm_open()
435 hu->priv = bcm; in bcm_open()
439 if (hu->serdev) { in bcm_open()
440 bcm->dev = serdev_device_get_drvdata(hu->serdev); in bcm_open()
444 if (!hu->tty->dev) in bcm_open()
454 if (hu->tty->dev->parent == dev->dev->parent) { in bcm_open()
455 bcm->dev = dev; in bcm_open()
457 dev->hu = hu; in bcm_open()
464 if (bcm->dev) { in bcm_open()
465 if (bcm->dev->drive_rts_on_open) in bcm_open()
468 hu->init_speed = bcm->dev->init_speed; in bcm_open()
473 if (!bcm->dev->no_early_set_baudrate) in bcm_open()
474 hu->oper_speed = bcm->dev->oper_speed; in bcm_open()
476 err = bcm_gpio_set_power(bcm->dev, true); in bcm_open()
478 if (bcm->dev->drive_rts_on_open) in bcm_open()
490 if (!hu->serdev) in bcm_open()
491 bcm->dev->hu = NULL; in bcm_open()
494 hu->priv = NULL; in bcm_open()
501 struct bcm_data *bcm = hu->priv; in bcm_close()
505 bt_dev_dbg(hu->hdev, "hu %p", hu); in bcm_close()
507 /* Protect bcm->dev against removal of the device or driver */ in bcm_close()
510 if (hu->serdev) { in bcm_close()
511 bdev = serdev_device_get_drvdata(hu->serdev); in bcm_close()
512 } else if (bcm_device_exists(bcm->dev)) { in bcm_close()
513 bdev = bcm->dev; in bcm_close()
515 bdev->hu = NULL; in bcm_close()
520 if (IS_ENABLED(CONFIG_PM) && bdev->irq_acquired) { in bcm_close()
521 devm_free_irq(bdev->dev, bdev->irq, bdev); in bcm_close()
522 device_init_wakeup(bdev->dev, false); in bcm_close()
523 pm_runtime_disable(bdev->dev); in bcm_close()
528 bt_dev_err(hu->hdev, "Failed to power down"); in bcm_close()
530 pm_runtime_set_suspended(bdev->dev); in bcm_close()
534 skb_queue_purge(&bcm->txq); in bcm_close()
535 kfree_skb(bcm->rx_skb); in bcm_close()
538 hu->priv = NULL; in bcm_close()
544 struct bcm_data *bcm = hu->priv; in bcm_flush()
546 bt_dev_dbg(hu->hdev, "hu %p", hu); in bcm_flush()
548 skb_queue_purge(&bcm->txq); in bcm_flush()
555 struct bcm_data *bcm = hu->priv; in bcm_setup()
560 bt_dev_dbg(hu->hdev, "hu %p", hu); in bcm_setup()
562 hu->hdev->set_diag = bcm_set_diag; in bcm_setup()
563 hu->hdev->set_bdaddr = btbcm_set_bdaddr; in bcm_setup()
565 err = btbcm_initialize(hu->hdev, &fw_load_done); in bcm_setup()
573 if (hu->init_speed) in bcm_setup()
574 speed = hu->init_speed; in bcm_setup()
575 else if (hu->proto->init_speed) in bcm_setup()
576 speed = hu->proto->init_speed; in bcm_setup()
584 if (hu->oper_speed) in bcm_setup()
585 speed = hu->oper_speed; in bcm_setup()
586 else if (bcm->dev && bcm->dev->oper_speed) in bcm_setup()
587 speed = bcm->dev->oper_speed; in bcm_setup()
588 else if (hu->proto->oper_speed) in bcm_setup()
589 speed = hu->proto->oper_speed; in bcm_setup()
600 if (bcm->dev && bcm->dev->pcm_int_params[0] != 0xff) { in bcm_setup()
603 btbcm_read_pcm_int_params(hu->hdev, &params); in bcm_setup()
605 memcpy(&params, bcm->dev->pcm_int_params, 5); in bcm_setup()
606 btbcm_write_pcm_int_params(hu->hdev, &params); in bcm_setup()
609 err = btbcm_finalize(hu->hdev, &fw_load_done); in bcm_setup()
617 set_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hu->hdev->quirks); in bcm_setup()
665 struct bcm_data *bcm = hu->priv; in bcm_recv()
667 if (!test_bit(HCI_UART_REGISTERED, &hu->flags)) in bcm_recv()
668 return -EUNATCH; in bcm_recv()
670 bcm->rx_skb = h4_recv_buf(hu->hdev, bcm->rx_skb, data, count, in bcm_recv()
672 if (IS_ERR(bcm->rx_skb)) { in bcm_recv()
673 int err = PTR_ERR(bcm->rx_skb); in bcm_recv()
674 bt_dev_err(hu->hdev, "Frame reassembly failed (%d)", err); in bcm_recv()
675 bcm->rx_skb = NULL; in bcm_recv()
677 } else if (!bcm->rx_skb) { in bcm_recv()
678 /* Delay auto-suspend when receiving completed packet */ in bcm_recv()
680 if (bcm->dev && bcm_device_exists(bcm->dev)) { in bcm_recv()
681 pm_runtime_get(bcm->dev->dev); in bcm_recv()
682 pm_runtime_mark_last_busy(bcm->dev->dev); in bcm_recv()
683 pm_runtime_put_autosuspend(bcm->dev->dev); in bcm_recv()
693 struct bcm_data *bcm = hu->priv; in bcm_enqueue()
695 bt_dev_dbg(hu->hdev, "hu %p skb %p", hu, skb); in bcm_enqueue()
699 skb_queue_tail(&bcm->txq, skb); in bcm_enqueue()
706 struct bcm_data *bcm = hu->priv; in bcm_dequeue()
712 if (bcm_device_exists(bcm->dev)) { in bcm_dequeue()
713 bdev = bcm->dev; in bcm_dequeue()
714 pm_runtime_get_sync(bdev->dev); in bcm_dequeue()
718 skb = skb_dequeue(&bcm->txq); in bcm_dequeue()
721 pm_runtime_mark_last_busy(bdev->dev); in bcm_dequeue()
722 pm_runtime_put_autosuspend(bdev->dev); in bcm_dequeue()
738 if (!bdev->is_suspended && bdev->hu) { in bcm_suspend_device()
739 hci_uart_set_flow_control(bdev->hu, true); in bcm_suspend_device()
741 /* Once this returns, driver suspends BT via GPIO */ in bcm_suspend_device()
742 bdev->is_suspended = true; in bcm_suspend_device()
746 err = bdev->set_device_wakeup(bdev, false); in bcm_suspend_device()
748 if (bdev->is_suspended && bdev->hu) { in bcm_suspend_device()
749 bdev->is_suspended = false; in bcm_suspend_device()
750 hci_uart_set_flow_control(bdev->hu, false); in bcm_suspend_device()
752 return -EBUSY; in bcm_suspend_device()
768 err = bdev->set_device_wakeup(bdev, true); in bcm_resume_device()
778 if (bdev->is_suspended && bdev->hu) { in bcm_resume_device()
779 bdev->is_suspended = false; in bcm_resume_device()
781 hci_uart_set_flow_control(bdev->hu, false); in bcm_resume_device()
795 bt_dev_dbg(bdev, "suspend: is_suspended %d", bdev->is_suspended); in bcm_suspend()
801 * and device_wake-up GPIO. in bcm_suspend()
805 if (!bdev->hu) in bcm_suspend()
811 if (device_may_wakeup(dev) && bdev->irq > 0) { in bcm_suspend()
812 error = enable_irq_wake(bdev->irq); in bcm_suspend()
829 bt_dev_dbg(bdev, "resume: is_suspended %d", bdev->is_suspended); in bcm_resume()
835 * and device_wake-up GPIO. in bcm_resume()
839 if (!bdev->hu) in bcm_resume()
842 if (device_may_wakeup(dev) && bdev->irq > 0) { in bcm_resume()
843 disable_irq_wake(bdev->irq); in bcm_resume()
882 { "device-wakeup-gpios", &first_gpio, 1 },
883 { "shutdown-gpios", &second_gpio, 1 },
884 { "host-wakeup-gpios", &third_gpio, 1 },
889 { "host-wakeup-gpios", &first_gpio, 1 },
890 { "device-wakeup-gpios", &second_gpio, 1 },
891 { "shutdown-gpios", &third_gpio, 1 },
902 switch (ares->type) { in bcm_resource()
904 irq = &ares->data.extended_irq; in bcm_resource()
905 if (irq->polarity != ACPI_ACTIVE_LOW) in bcm_resource()
906 …dev_info(dev->dev, "ACPI Interrupt resource is active-high, this is usually wrong, treating the IR… in bcm_resource()
907 dev->irq_active_low = true; in bcm_resource()
911 gpio = &ares->data.gpio; in bcm_resource()
912 if (gpio->connection_type == ACPI_RESOURCE_GPIO_TYPE_INT) { in bcm_resource()
913 dev->gpio_int_idx = dev->gpio_count; in bcm_resource()
914 dev->irq_active_low = gpio->polarity == ACPI_ACTIVE_LOW; in bcm_resource()
916 dev->gpio_count++; in bcm_resource()
920 sb = &ares->data.uart_serial_bus; in bcm_resource()
921 if (sb->type == ACPI_RESOURCE_SERIAL_TYPE_UART) { in bcm_resource()
922 dev->init_speed = sb->default_baud_rate; in bcm_resource()
923 dev->oper_speed = 4000000; in bcm_resource()
936 if (ACPI_FAILURE(acpi_execute_simple_method(dev->btlp, NULL, !awake))) in bcm_apple_set_device_wakeup()
937 return -EIO; in bcm_apple_set_device_wakeup()
944 if (ACPI_FAILURE(acpi_evaluate_object(powered ? dev->btpu : dev->btpd, in bcm_apple_set_shutdown()
946 return -EIO; in bcm_apple_set_shutdown()
953 struct acpi_device *adev = ACPI_COMPANION(dev->dev); in bcm_apple_get_resources()
957 ACPI_FAILURE(acpi_get_handle(adev->handle, "BTLP", &dev->btlp)) || in bcm_apple_get_resources()
958 ACPI_FAILURE(acpi_get_handle(adev->handle, "BTPU", &dev->btpu)) || in bcm_apple_get_resources()
959 ACPI_FAILURE(acpi_get_handle(adev->handle, "BTPD", &dev->btpd))) in bcm_apple_get_resources()
960 return -ENODEV; in bcm_apple_get_resources()
963 obj->buffer.length == 8) in bcm_apple_get_resources()
964 dev->init_speed = *(u64 *)obj->buffer.pointer; in bcm_apple_get_resources()
966 dev->set_device_wakeup = bcm_apple_set_device_wakeup; in bcm_apple_get_resources()
967 dev->set_shutdown = bcm_apple_set_shutdown; in bcm_apple_get_resources()
974 return -EOPNOTSUPP; in bcm_apple_get_resources()
980 gpiod_set_value_cansleep(dev->device_wakeup, awake); in bcm_gpio_set_device_wakeup()
986 gpiod_set_value_cansleep(dev->shutdown, powered); in bcm_gpio_set_shutdown()
997 if (!IS_ERR(clk) || PTR_ERR(clk) == -EPROBE_DEFER) in bcm_get_txco()
1002 if (!IS_ERR(clk) || PTR_ERR(clk) == -EPROBE_DEFER) in bcm_get_txco()
1014 dev->name = dev_name(dev->dev); in bcm_get_resources()
1019 dev->txco_clk = bcm_get_txco(dev->dev); in bcm_get_resources()
1022 if (dev->txco_clk == ERR_PTR(-EPROBE_DEFER)) in bcm_get_resources()
1023 return PTR_ERR(dev->txco_clk); in bcm_get_resources()
1026 if (IS_ERR(dev->txco_clk)) in bcm_get_resources()
1027 dev->txco_clk = NULL; in bcm_get_resources()
1029 dev->lpo_clk = devm_clk_get(dev->dev, "lpo"); in bcm_get_resources()
1030 if (dev->lpo_clk == ERR_PTR(-EPROBE_DEFER)) in bcm_get_resources()
1031 return PTR_ERR(dev->lpo_clk); in bcm_get_resources()
1033 if (IS_ERR(dev->lpo_clk)) in bcm_get_resources()
1034 dev->lpo_clk = NULL; in bcm_get_resources()
1037 if (dev->lpo_clk && clk_is_match(dev->lpo_clk, dev->txco_clk)) { in bcm_get_resources()
1038 devm_clk_put(dev->dev, dev->txco_clk); in bcm_get_resources()
1039 dev->txco_clk = NULL; in bcm_get_resources()
1042 dev->device_wakeup = devm_gpiod_get_optional(dev->dev, "device-wakeup", in bcm_get_resources()
1044 if (IS_ERR(dev->device_wakeup)) in bcm_get_resources()
1045 return PTR_ERR(dev->device_wakeup); in bcm_get_resources()
1047 dev->shutdown = devm_gpiod_get_optional(dev->dev, "shutdown", in bcm_get_resources()
1049 if (IS_ERR(dev->shutdown)) in bcm_get_resources()
1050 return PTR_ERR(dev->shutdown); in bcm_get_resources()
1052 dev->set_device_wakeup = bcm_gpio_set_device_wakeup; in bcm_get_resources()
1053 dev->set_shutdown = bcm_gpio_set_shutdown; in bcm_get_resources()
1055 dev->supplies[0].supply = "vbat"; in bcm_get_resources()
1056 dev->supplies[1].supply = "vddio"; in bcm_get_resources()
1057 err = devm_regulator_bulk_get(dev->dev, BCM_NUM_SUPPLIES, in bcm_get_resources()
1058 dev->supplies); in bcm_get_resources()
1063 if (dev->irq <= 0) { in bcm_get_resources()
1066 gpio = devm_gpiod_get_optional(dev->dev, "host-wakeup", in bcm_get_resources()
1071 dev->irq = gpiod_to_irq(gpio); in bcm_get_resources()
1076 dev_info(dev->dev, "%s: Has a broken IRQ config, disabling IRQ support / runtime-pm\n", in bcm_get_resources()
1077 dmi_id->ident); in bcm_get_resources()
1078 dev->irq = 0; in bcm_get_resources()
1081 dev_dbg(dev->dev, "BCM irq: %d\n", dev->irq); in bcm_get_resources()
1094 dev->gpio_int_idx = -1; in bcm_acpi_probe()
1095 ret = acpi_dev_get_resources(ACPI_COMPANION(dev->dev), in bcm_acpi_probe()
1101 if (resource_type(entry->res) == IORESOURCE_IRQ) { in bcm_acpi_probe()
1102 dev->irq = entry->res->start; in bcm_acpi_probe()
1109 * only 2 GPIO resources, we use the irq-last mapping for this, since in bcm_acpi_probe()
1112 if (dev->irq) in bcm_acpi_probe()
1114 else if (dev->gpio_int_idx == 0) in bcm_acpi_probe()
1116 else if (dev->gpio_int_idx == 2) in bcm_acpi_probe()
1119 dev_warn(dev->dev, "Unexpected ACPI gpio_int_idx: %d\n", in bcm_acpi_probe()
1120 dev->gpio_int_idx); in bcm_acpi_probe()
1123 if (dev->gpio_count != (dev->irq ? 2 : 3)) in bcm_acpi_probe()
1124 dev_warn(dev->dev, "Unexpected number of ACPI GPIOs: %d\n", in bcm_acpi_probe()
1125 dev->gpio_count); in bcm_acpi_probe()
1127 ret = devm_acpi_dev_add_driver_gpios(dev->dev, gpio_mapping); in bcm_acpi_probe()
1131 if (irq_polarity != -1) { in bcm_acpi_probe()
1132 dev->irq_active_low = irq_polarity; in bcm_acpi_probe()
1133 dev_warn(dev->dev, "Overwriting IRQ polarity to active %s by module-param\n", in bcm_acpi_probe()
1134 dev->irq_active_low ? "low" : "high"); in bcm_acpi_probe()
1142 return -EINVAL; in bcm_acpi_probe()
1148 device_property_read_u32(bdev->dev, "max-speed", &bdev->oper_speed); in bcm_of_probe()
1149 device_property_read_u8_array(bdev->dev, "brcm,bt-pcm-int-params", in bcm_of_probe()
1150 bdev->pcm_int_params, 5); in bcm_of_probe()
1151 bdev->irq = of_irq_get_byname(bdev->dev->of_node, "host-wakeup"); in bcm_of_probe()
1152 bdev->irq_active_low = irq_get_trigger_type(bdev->irq) in bcm_of_probe()
1162 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); in bcm_probe()
1164 return -ENOMEM; in bcm_probe()
1166 dev->dev = &pdev->dev; in bcm_probe()
1167 dev->irq = platform_get_irq(pdev, 0); in bcm_probe()
1170 dev->pcm_int_params[0] = 0xff; in bcm_probe()
1172 if (has_acpi_companion(&pdev->dev)) { in bcm_probe()
1184 dev_info(&pdev->dev, "%s device registered.\n", dev->name); in bcm_probe()
1188 list_add_tail(&dev->list, &bcm_device_list); in bcm_probe()
1193 dev_err(&pdev->dev, "Failed to power down\n"); in bcm_probe()
1203 list_del(&dev->list); in bcm_remove()
1206 dev_info(&pdev->dev, "%s device unregistered.\n", dev->name); in bcm_remove()
1421 bcmdev = devm_kzalloc(&serdev->dev, sizeof(*bcmdev), GFP_KERNEL); in bcm_serdev_probe()
1423 return -ENOMEM; in bcm_serdev_probe()
1425 bcmdev->dev = &serdev->dev; in bcm_serdev_probe()
1427 bcmdev->hu = &bcmdev->serdev_hu; in bcm_serdev_probe()
1429 bcmdev->serdev_hu.serdev = serdev; in bcm_serdev_probe()
1433 bcmdev->pcm_int_params[0] = 0xff; in bcm_serdev_probe()
1435 if (has_acpi_companion(&serdev->dev)) in bcm_serdev_probe()
1446 if (!bcmdev->shutdown) { in bcm_serdev_probe()
1447 dev_warn(&serdev->dev, in bcm_serdev_probe()
1449 bcmdev->oper_speed = bcmdev->init_speed; in bcm_serdev_probe()
1454 dev_err(&serdev->dev, "Failed to power down\n"); in bcm_serdev_probe()
1456 data = device_get_match_data(bcmdev->dev); in bcm_serdev_probe()
1458 bcmdev->no_early_set_baudrate = data->no_early_set_baudrate; in bcm_serdev_probe()
1459 bcmdev->drive_rts_on_open = data->drive_rts_on_open; in bcm_serdev_probe()
1462 return hci_uart_register_device(&bcmdev->serdev_hu, &bcm_proto); in bcm_serdev_probe()
1469 hci_uart_unregister_device(&bcmdev->serdev_hu); in bcm_serdev_remove()
1483 { .compatible = "brcm,bcm4329-bt" },
1485 { .compatible = "brcm,bcm4330-bt" },
1486 { .compatible = "brcm,bcm43438-bt", .data = &bcm43438_device_data },
1487 { .compatible = "brcm,bcm43540-bt", .data = &bcm4354_device_data },