Lines Matching +full:fw +full:- +full:gpios
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
63 * struct bcm_device - device driver resources
138 static int irq_polarity = -1;
140 MODULE_PARM_DESC(irq_polarity, "IRQ polarity 0: active-high 1: active-low");
144 if (hu->serdev) in host_set_baudrate()
145 serdev_device_set_baudrate(hu->serdev, speed); in host_set_baudrate()
152 struct hci_dev *hdev = hu->hdev; in bcm_set_baudrate()
206 if (device && device->hu && device->hu->serdev) in bcm_device_exists()
224 if (powered && !IS_ERR(dev->clk) && !dev->clk_enabled) { in bcm_gpio_set_power()
225 err = clk_prepare_enable(dev->clk); in bcm_gpio_set_power()
230 err = dev->set_shutdown(dev, powered); in bcm_gpio_set_power()
234 err = dev->set_device_wakeup(dev, powered); in bcm_gpio_set_power()
238 if (!powered && !IS_ERR(dev->clk) && dev->clk_enabled) in bcm_gpio_set_power()
239 clk_disable_unprepare(dev->clk); in bcm_gpio_set_power()
241 dev->clk_enabled = powered; in bcm_gpio_set_power()
246 dev->set_shutdown(dev, !powered); in bcm_gpio_set_power()
248 if (powered && !IS_ERR(dev->clk) && !dev->clk_enabled) in bcm_gpio_set_power()
249 clk_disable_unprepare(dev->clk); in bcm_gpio_set_power()
260 pm_runtime_get(bdev->dev); in bcm_host_wake()
261 pm_runtime_mark_last_busy(bdev->dev); in bcm_host_wake()
262 pm_runtime_put_autosuspend(bdev->dev); in bcm_host_wake()
269 struct bcm_device *bdev = bcm->dev; in bcm_request_irq()
274 err = -ENODEV; in bcm_request_irq()
278 if (bdev->irq <= 0) { in bcm_request_irq()
279 err = -EOPNOTSUPP; in bcm_request_irq()
283 err = devm_request_irq(bdev->dev, bdev->irq, bcm_host_wake, in bcm_request_irq()
284 bdev->irq_active_low ? IRQF_TRIGGER_FALLING : in bcm_request_irq()
288 bdev->irq = err; in bcm_request_irq()
292 bdev->irq_acquired = true; in bcm_request_irq()
294 device_init_wakeup(bdev->dev, true); in bcm_request_irq()
296 pm_runtime_set_autosuspend_delay(bdev->dev, in bcm_request_irq()
298 pm_runtime_use_autosuspend(bdev->dev); in bcm_request_irq()
299 pm_runtime_set_active(bdev->dev); in bcm_request_irq()
300 pm_runtime_enable(bdev->dev); in bcm_request_irq()
316 .tristate_control = 0, /* Allow tri-state control of UART tx flag */
326 struct bcm_data *bcm = hu->priv; in bcm_setup_sleep()
330 sleep_params.host_wake_active = !bcm->dev->irq_active_low; in bcm_setup_sleep()
332 skb = __hci_cmd_sync(hu->hdev, 0xfc27, sizeof(sleep_params), in bcm_setup_sleep()
336 bt_dev_err(hu->hdev, "Sleep VSC failed (%d)", err); in bcm_setup_sleep()
341 bt_dev_dbg(hu->hdev, "Set Sleep Parameters VSC succeeded"); in bcm_setup_sleep()
353 struct bcm_data *bcm = hu->priv; in bcm_set_diag()
356 if (!test_bit(HCI_RUNNING, &hdev->flags)) in bcm_set_diag()
357 return -ENETDOWN; in bcm_set_diag()
361 return -ENOMEM; in bcm_set_diag()
367 skb_queue_tail(&bcm->txq, skb); in bcm_set_diag()
379 bt_dev_dbg(hu->hdev, "hu %p", hu); in bcm_open()
382 return -EOPNOTSUPP; in bcm_open()
386 return -ENOMEM; in bcm_open()
388 skb_queue_head_init(&bcm->txq); in bcm_open()
390 hu->priv = bcm; in bcm_open()
394 if (hu->serdev) { in bcm_open()
395 bcm->dev = serdev_device_get_drvdata(hu->serdev); in bcm_open()
399 if (!hu->tty->dev) in bcm_open()
409 if (hu->tty->dev->parent == dev->dev->parent) { in bcm_open()
410 bcm->dev = dev; in bcm_open()
412 dev->hu = hu; in bcm_open()
419 if (bcm->dev) { in bcm_open()
420 hu->init_speed = bcm->dev->init_speed; in bcm_open()
421 hu->oper_speed = bcm->dev->oper_speed; in bcm_open()
422 err = bcm_gpio_set_power(bcm->dev, true); in bcm_open()
432 if (!hu->serdev) in bcm_open()
433 bcm->dev->hu = NULL; in bcm_open()
436 hu->priv = NULL; in bcm_open()
443 struct bcm_data *bcm = hu->priv; in bcm_close()
447 bt_dev_dbg(hu->hdev, "hu %p", hu); in bcm_close()
449 /* Protect bcm->dev against removal of the device or driver */ in bcm_close()
452 if (hu->serdev) { in bcm_close()
453 bdev = serdev_device_get_drvdata(hu->serdev); in bcm_close()
454 } else if (bcm_device_exists(bcm->dev)) { in bcm_close()
455 bdev = bcm->dev; in bcm_close()
457 bdev->hu = NULL; in bcm_close()
462 if (IS_ENABLED(CONFIG_PM) && bdev->irq_acquired) { in bcm_close()
463 devm_free_irq(bdev->dev, bdev->irq, bdev); in bcm_close()
464 device_init_wakeup(bdev->dev, false); in bcm_close()
465 pm_runtime_disable(bdev->dev); in bcm_close()
470 bt_dev_err(hu->hdev, "Failed to power down"); in bcm_close()
472 pm_runtime_set_suspended(bdev->dev); in bcm_close()
476 skb_queue_purge(&bcm->txq); in bcm_close()
477 kfree_skb(bcm->rx_skb); in bcm_close()
480 hu->priv = NULL; in bcm_close()
486 struct bcm_data *bcm = hu->priv; in bcm_flush()
488 bt_dev_dbg(hu->hdev, "hu %p", hu); in bcm_flush()
490 skb_queue_purge(&bcm->txq); in bcm_flush()
497 struct bcm_data *bcm = hu->priv; in bcm_setup()
499 const struct firmware *fw; in bcm_setup() local
503 bt_dev_dbg(hu->hdev, "hu %p", hu); in bcm_setup()
505 hu->hdev->set_diag = bcm_set_diag; in bcm_setup()
506 hu->hdev->set_bdaddr = btbcm_set_bdaddr; in bcm_setup()
508 err = btbcm_initialize(hu->hdev, fw_name, sizeof(fw_name), false); in bcm_setup()
512 err = request_firmware(&fw, fw_name, &hu->hdev->dev); in bcm_setup()
514 bt_dev_info(hu->hdev, "BCM: Patch %s not found", fw_name); in bcm_setup()
518 err = btbcm_patchram(hu->hdev, fw); in bcm_setup()
520 bt_dev_info(hu->hdev, "BCM: Patch failed (%d)", err); in bcm_setup()
525 if (hu->init_speed) in bcm_setup()
526 speed = hu->init_speed; in bcm_setup()
527 else if (hu->proto->init_speed) in bcm_setup()
528 speed = hu->proto->init_speed; in bcm_setup()
536 if (hu->oper_speed) in bcm_setup()
537 speed = hu->oper_speed; in bcm_setup()
538 else if (hu->proto->oper_speed) in bcm_setup()
539 speed = hu->proto->oper_speed; in bcm_setup()
550 release_firmware(fw); in bcm_setup()
552 err = btbcm_finalize(hu->hdev); in bcm_setup()
602 struct bcm_data *bcm = hu->priv; in bcm_recv()
604 if (!test_bit(HCI_UART_REGISTERED, &hu->flags)) in bcm_recv()
605 return -EUNATCH; in bcm_recv()
607 bcm->rx_skb = h4_recv_buf(hu->hdev, bcm->rx_skb, data, count, in bcm_recv()
609 if (IS_ERR(bcm->rx_skb)) { in bcm_recv()
610 int err = PTR_ERR(bcm->rx_skb); in bcm_recv()
611 bt_dev_err(hu->hdev, "Frame reassembly failed (%d)", err); in bcm_recv()
612 bcm->rx_skb = NULL; in bcm_recv()
614 } else if (!bcm->rx_skb) { in bcm_recv()
615 /* Delay auto-suspend when receiving completed packet */ in bcm_recv()
617 if (bcm->dev && bcm_device_exists(bcm->dev)) { in bcm_recv()
618 pm_runtime_get(bcm->dev->dev); in bcm_recv()
619 pm_runtime_mark_last_busy(bcm->dev->dev); in bcm_recv()
620 pm_runtime_put_autosuspend(bcm->dev->dev); in bcm_recv()
630 struct bcm_data *bcm = hu->priv; in bcm_enqueue()
632 bt_dev_dbg(hu->hdev, "hu %p skb %p", hu, skb); in bcm_enqueue()
636 skb_queue_tail(&bcm->txq, skb); in bcm_enqueue()
643 struct bcm_data *bcm = hu->priv; in bcm_dequeue()
649 if (bcm_device_exists(bcm->dev)) { in bcm_dequeue()
650 bdev = bcm->dev; in bcm_dequeue()
651 pm_runtime_get_sync(bdev->dev); in bcm_dequeue()
655 skb = skb_dequeue(&bcm->txq); in bcm_dequeue()
658 pm_runtime_mark_last_busy(bdev->dev); in bcm_dequeue()
659 pm_runtime_put_autosuspend(bdev->dev); in bcm_dequeue()
675 if (!bdev->is_suspended && bdev->hu) { in bcm_suspend_device()
676 hci_uart_set_flow_control(bdev->hu, true); in bcm_suspend_device()
679 bdev->is_suspended = true; in bcm_suspend_device()
683 err = bdev->set_device_wakeup(bdev, false); in bcm_suspend_device()
685 if (bdev->is_suspended && bdev->hu) { in bcm_suspend_device()
686 bdev->is_suspended = false; in bcm_suspend_device()
687 hci_uart_set_flow_control(bdev->hu, false); in bcm_suspend_device()
689 return -EBUSY; in bcm_suspend_device()
705 err = bdev->set_device_wakeup(bdev, true); in bcm_resume_device()
715 if (bdev->is_suspended && bdev->hu) { in bcm_resume_device()
716 bdev->is_suspended = false; in bcm_resume_device()
718 hci_uart_set_flow_control(bdev->hu, false); in bcm_resume_device()
732 bt_dev_dbg(bdev, "suspend: is_suspended %d", bdev->is_suspended); in bcm_suspend()
738 * and device_wake-up GPIO. in bcm_suspend()
742 if (!bdev->hu) in bcm_suspend()
748 if (device_may_wakeup(dev) && bdev->irq > 0) { in bcm_suspend()
749 error = enable_irq_wake(bdev->irq); in bcm_suspend()
766 bt_dev_dbg(bdev, "resume: is_suspended %d", bdev->is_suspended); in bcm_resume()
772 * and device_wake-up GPIO. in bcm_resume()
776 if (!bdev->hu) in bcm_resume()
779 if (device_may_wakeup(dev) && bdev->irq > 0) { in bcm_resume()
780 disable_irq_wake(bdev->irq); in bcm_resume()
804 { "device-wakeup-gpios", &first_gpio, 1 },
805 { "shutdown-gpios", &second_gpio, 1 },
806 { "host-wakeup-gpios", &third_gpio, 1 },
811 { "host-wakeup-gpios", &first_gpio, 1 },
812 { "device-wakeup-gpios", &second_gpio, 1 },
813 { "shutdown-gpios", &third_gpio, 1 },
817 /* Some firmware reports an IRQ which does not work (wrong pin in fw table?) */
839 switch (ares->type) { in bcm_resource()
841 irq = &ares->data.extended_irq; in bcm_resource()
842 if (irq->polarity != ACPI_ACTIVE_LOW) in bcm_resource()
843 …dev_info(dev->dev, "ACPI Interrupt resource is active-high, this is usually wrong, treating the IR… in bcm_resource()
844 dev->irq_active_low = true; in bcm_resource()
848 gpio = &ares->data.gpio; in bcm_resource()
849 if (gpio->connection_type == ACPI_RESOURCE_GPIO_TYPE_INT) { in bcm_resource()
850 dev->gpio_int_idx = dev->gpio_count; in bcm_resource()
851 dev->irq_active_low = gpio->polarity == ACPI_ACTIVE_LOW; in bcm_resource()
853 dev->gpio_count++; in bcm_resource()
857 sb = &ares->data.uart_serial_bus; in bcm_resource()
858 if (sb->type == ACPI_RESOURCE_SERIAL_TYPE_UART) { in bcm_resource()
859 dev->init_speed = sb->default_baud_rate; in bcm_resource()
860 dev->oper_speed = 4000000; in bcm_resource()
873 if (ACPI_FAILURE(acpi_execute_simple_method(dev->btlp, NULL, !awake))) in bcm_apple_set_device_wakeup()
874 return -EIO; in bcm_apple_set_device_wakeup()
881 if (ACPI_FAILURE(acpi_evaluate_object(powered ? dev->btpu : dev->btpd, in bcm_apple_set_shutdown()
883 return -EIO; in bcm_apple_set_shutdown()
890 struct acpi_device *adev = ACPI_COMPANION(dev->dev); in bcm_apple_get_resources()
894 ACPI_FAILURE(acpi_get_handle(adev->handle, "BTLP", &dev->btlp)) || in bcm_apple_get_resources()
895 ACPI_FAILURE(acpi_get_handle(adev->handle, "BTPU", &dev->btpu)) || in bcm_apple_get_resources()
896 ACPI_FAILURE(acpi_get_handle(adev->handle, "BTPD", &dev->btpd))) in bcm_apple_get_resources()
897 return -ENODEV; in bcm_apple_get_resources()
900 obj->buffer.length == 8) in bcm_apple_get_resources()
901 dev->init_speed = *(u64 *)obj->buffer.pointer; in bcm_apple_get_resources()
903 dev->set_device_wakeup = bcm_apple_set_device_wakeup; in bcm_apple_get_resources()
904 dev->set_shutdown = bcm_apple_set_shutdown; in bcm_apple_get_resources()
911 return -EOPNOTSUPP; in bcm_apple_get_resources()
917 gpiod_set_value_cansleep(dev->device_wakeup, awake); in bcm_gpio_set_device_wakeup()
923 gpiod_set_value_cansleep(dev->shutdown, powered); in bcm_gpio_set_shutdown()
931 dev->name = dev_name(dev->dev); in bcm_get_resources()
936 dev->clk = devm_clk_get(dev->dev, NULL); in bcm_get_resources()
939 if (dev->clk == ERR_PTR(-EPROBE_DEFER)) in bcm_get_resources()
940 return PTR_ERR(dev->clk); in bcm_get_resources()
942 dev->device_wakeup = devm_gpiod_get_optional(dev->dev, "device-wakeup", in bcm_get_resources()
944 if (IS_ERR(dev->device_wakeup)) in bcm_get_resources()
945 return PTR_ERR(dev->device_wakeup); in bcm_get_resources()
947 dev->shutdown = devm_gpiod_get_optional(dev->dev, "shutdown", in bcm_get_resources()
949 if (IS_ERR(dev->shutdown)) in bcm_get_resources()
950 return PTR_ERR(dev->shutdown); in bcm_get_resources()
952 dev->set_device_wakeup = bcm_gpio_set_device_wakeup; in bcm_get_resources()
953 dev->set_shutdown = bcm_gpio_set_shutdown; in bcm_get_resources()
956 if (dev->irq <= 0) { in bcm_get_resources()
959 gpio = devm_gpiod_get_optional(dev->dev, "host-wakeup", in bcm_get_resources()
964 dev->irq = gpiod_to_irq(gpio); in bcm_get_resources()
969 dev_info(dev->dev, "%s: Has a broken IRQ config, disabling IRQ support / runtime-pm\n", in bcm_get_resources()
970 dmi_id->ident); in bcm_get_resources()
971 dev->irq = 0; in bcm_get_resources()
974 dev_dbg(dev->dev, "BCM irq: %d\n", dev->irq); in bcm_get_resources()
987 dev->gpio_int_idx = -1; in bcm_acpi_probe()
988 ret = acpi_dev_get_resources(ACPI_COMPANION(dev->dev), in bcm_acpi_probe()
994 if (resource_type(entry->res) == IORESOURCE_IRQ) { in bcm_acpi_probe()
995 dev->irq = entry->res->start; in bcm_acpi_probe()
1002 * only 2 GPIO resources, we use the irq-last mapping for this, since in bcm_acpi_probe()
1005 if (dev->irq) in bcm_acpi_probe()
1007 else if (dev->gpio_int_idx == 0) in bcm_acpi_probe()
1009 else if (dev->gpio_int_idx == 2) in bcm_acpi_probe()
1012 dev_warn(dev->dev, "Unexpected ACPI gpio_int_idx: %d\n", in bcm_acpi_probe()
1013 dev->gpio_int_idx); in bcm_acpi_probe()
1016 if (dev->gpio_count != (dev->irq ? 2 : 3)) in bcm_acpi_probe()
1017 dev_warn(dev->dev, "Unexpected number of ACPI GPIOs: %d\n", in bcm_acpi_probe()
1018 dev->gpio_count); in bcm_acpi_probe()
1020 ret = devm_acpi_dev_add_driver_gpios(dev->dev, gpio_mapping); in bcm_acpi_probe()
1024 if (irq_polarity != -1) { in bcm_acpi_probe()
1025 dev->irq_active_low = irq_polarity; in bcm_acpi_probe()
1026 dev_warn(dev->dev, "Overwriting IRQ polarity to active %s by module-param\n", in bcm_acpi_probe()
1027 dev->irq_active_low ? "low" : "high"); in bcm_acpi_probe()
1035 return -EINVAL; in bcm_acpi_probe()
1041 device_property_read_u32(bdev->dev, "max-speed", &bdev->oper_speed); in bcm_of_probe()
1050 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); in bcm_probe()
1052 return -ENOMEM; in bcm_probe()
1054 dev->dev = &pdev->dev; in bcm_probe()
1055 dev->irq = platform_get_irq(pdev, 0); in bcm_probe()
1057 if (has_acpi_companion(&pdev->dev)) { in bcm_probe()
1069 dev_info(&pdev->dev, "%s device registered.\n", dev->name); in bcm_probe()
1073 list_add_tail(&dev->list, &bcm_device_list); in bcm_probe()
1078 dev_err(&pdev->dev, "Failed to power down\n"); in bcm_probe()
1088 list_del(&dev->list); in bcm_remove()
1091 dev_info(&pdev->dev, "%s device unregistered.\n", dev->name); in bcm_remove()
1305 bcmdev = devm_kzalloc(&serdev->dev, sizeof(*bcmdev), GFP_KERNEL); in bcm_serdev_probe()
1307 return -ENOMEM; in bcm_serdev_probe()
1309 bcmdev->dev = &serdev->dev; in bcm_serdev_probe()
1311 bcmdev->hu = &bcmdev->serdev_hu; in bcm_serdev_probe()
1313 bcmdev->serdev_hu.serdev = serdev; in bcm_serdev_probe()
1316 if (has_acpi_companion(&serdev->dev)) in bcm_serdev_probe()
1327 if (!bcmdev->shutdown) { in bcm_serdev_probe()
1328 dev_warn(&serdev->dev, in bcm_serdev_probe()
1330 bcmdev->oper_speed = bcmdev->init_speed; in bcm_serdev_probe()
1335 dev_err(&serdev->dev, "Failed to power down\n"); in bcm_serdev_probe()
1337 return hci_uart_register_device(&bcmdev->serdev_hu, &bcm_proto); in bcm_serdev_probe()
1344 hci_uart_unregister_device(&bcmdev->serdev_hu); in bcm_serdev_remove()
1349 { .compatible = "brcm,bcm43438-bt" },