Lines Matching +full:ddc +full:- +full:tx
1 // SPDX-License-Identifier: GPL-2.0-or-later
109 struct intel_data *intel = hu->priv; in intel_wait_booting()
112 err = wait_on_bit_timeout(&intel->flags, STATE_BOOTING, in intel_wait_booting()
116 if (err == -EINTR) { in intel_wait_booting()
117 bt_dev_err(hu->hdev, "Device boot interrupted"); in intel_wait_booting()
118 return -EINTR; in intel_wait_booting()
122 bt_dev_err(hu->hdev, "Device boot timeout"); in intel_wait_booting()
123 return -ETIMEDOUT; in intel_wait_booting()
132 struct intel_data *intel = hu->priv; in intel_wait_lpm_transaction()
135 err = wait_on_bit_timeout(&intel->flags, STATE_LPM_TRANSACTION, in intel_wait_lpm_transaction()
139 if (err == -EINTR) { in intel_wait_lpm_transaction()
140 bt_dev_err(hu->hdev, "LPM transaction interrupted"); in intel_wait_lpm_transaction()
141 return -EINTR; in intel_wait_lpm_transaction()
145 bt_dev_err(hu->hdev, "LPM transaction timeout"); in intel_wait_lpm_transaction()
146 return -ETIMEDOUT; in intel_wait_lpm_transaction()
155 struct intel_data *intel = hu->priv; in intel_lpm_suspend()
158 if (!test_bit(STATE_LPM_ENABLED, &intel->flags) || in intel_lpm_suspend()
159 test_bit(STATE_SUSPENDED, &intel->flags)) in intel_lpm_suspend()
162 if (test_bit(STATE_TX_ACTIVE, &intel->flags)) in intel_lpm_suspend()
163 return -EAGAIN; in intel_lpm_suspend()
165 bt_dev_dbg(hu->hdev, "Suspending"); in intel_lpm_suspend()
169 bt_dev_err(hu->hdev, "Failed to alloc memory for LPM packet"); in intel_lpm_suspend()
170 return -ENOMEM; in intel_lpm_suspend()
176 set_bit(STATE_LPM_TRANSACTION, &intel->flags); in intel_lpm_suspend()
179 skb_queue_head(&intel->txq, skb); in intel_lpm_suspend()
185 clear_bit(STATE_LPM_TRANSACTION, &intel->flags); in intel_lpm_suspend()
187 if (!test_bit(STATE_SUSPENDED, &intel->flags)) { in intel_lpm_suspend()
188 bt_dev_err(hu->hdev, "Device suspend error"); in intel_lpm_suspend()
189 return -EINVAL; in intel_lpm_suspend()
192 bt_dev_dbg(hu->hdev, "Suspended"); in intel_lpm_suspend()
201 struct intel_data *intel = hu->priv; in intel_lpm_resume()
204 if (!test_bit(STATE_LPM_ENABLED, &intel->flags) || in intel_lpm_resume()
205 !test_bit(STATE_SUSPENDED, &intel->flags)) in intel_lpm_resume()
208 bt_dev_dbg(hu->hdev, "Resuming"); in intel_lpm_resume()
214 bt_dev_err(hu->hdev, "Failed to alloc memory for LPM packet"); in intel_lpm_resume()
215 return -ENOMEM; in intel_lpm_resume()
220 set_bit(STATE_LPM_TRANSACTION, &intel->flags); in intel_lpm_resume()
223 skb_queue_head(&intel->txq, skb); in intel_lpm_resume()
229 clear_bit(STATE_LPM_TRANSACTION, &intel->flags); in intel_lpm_resume()
231 if (test_bit(STATE_SUSPENDED, &intel->flags)) { in intel_lpm_resume()
232 bt_dev_err(hu->hdev, "Device resume error"); in intel_lpm_resume()
233 return -EINVAL; in intel_lpm_resume()
236 bt_dev_dbg(hu->hdev, "Resumed"); in intel_lpm_resume()
245 struct intel_data *intel = hu->priv; in intel_lpm_host_wake()
250 clear_bit(STATE_SUSPENDED, &intel->flags); in intel_lpm_host_wake()
254 bt_dev_err(hu->hdev, "Failed to alloc memory for LPM packet"); in intel_lpm_host_wake()
255 return -ENOMEM; in intel_lpm_host_wake()
262 skb_queue_head(&intel->txq, skb); in intel_lpm_host_wake()
265 bt_dev_dbg(hu->hdev, "Resumed by controller"); in intel_lpm_host_wake()
274 dev_info(&idev->pdev->dev, "hci_intel irq\n"); in intel_irq()
276 mutex_lock(&idev->hu_lock); in intel_irq()
277 if (idev->hu) in intel_irq()
278 intel_lpm_host_wake(idev->hu); in intel_irq()
279 mutex_unlock(&idev->hu_lock); in intel_irq()
282 pm_runtime_get(&idev->pdev->dev); in intel_irq()
283 pm_runtime_mark_last_busy(&idev->pdev->dev); in intel_irq()
284 pm_runtime_put_autosuspend(&idev->pdev->dev); in intel_irq()
292 int err = -ENODEV; in intel_set_power()
294 if (!hu->tty->dev) in intel_set_power()
303 if (hu->tty->dev->parent != idev->pdev->dev.parent) in intel_set_power()
306 if (!idev->reset) { in intel_set_power()
307 err = -ENOTSUPP; in intel_set_power()
312 hu, dev_name(&idev->pdev->dev), powered); in intel_set_power()
314 gpiod_set_value(idev->reset, powered); in intel_set_power()
321 mutex_lock(&idev->hu_lock); in intel_set_power()
322 idev->hu = powered ? hu : NULL; in intel_set_power()
323 mutex_unlock(&idev->hu_lock); in intel_set_power()
325 if (idev->irq < 0) in intel_set_power()
328 if (powered && device_can_wakeup(&idev->pdev->dev)) { in intel_set_power()
329 err = devm_request_threaded_irq(&idev->pdev->dev, in intel_set_power()
330 idev->irq, NULL, in intel_set_power()
333 "bt-host-wake", idev); in intel_set_power()
335 BT_ERR("hu %p, unable to allocate irq-%d", in intel_set_power()
336 hu, idev->irq); in intel_set_power()
340 device_wakeup_enable(&idev->pdev->dev); in intel_set_power()
342 pm_runtime_set_active(&idev->pdev->dev); in intel_set_power()
343 pm_runtime_use_autosuspend(&idev->pdev->dev); in intel_set_power()
344 pm_runtime_set_autosuspend_delay(&idev->pdev->dev, in intel_set_power()
346 pm_runtime_enable(&idev->pdev->dev); in intel_set_power()
347 } else if (!powered && device_may_wakeup(&idev->pdev->dev)) { in intel_set_power()
348 devm_free_irq(&idev->pdev->dev, idev->irq, idev); in intel_set_power()
349 device_wakeup_disable(&idev->pdev->dev); in intel_set_power()
351 pm_runtime_disable(&idev->pdev->dev); in intel_set_power()
366 if (!intel->hu->tty->dev) in intel_busy_work()
372 if (intel->hu->tty->dev->parent == idev->pdev->dev.parent) { in intel_busy_work()
373 pm_runtime_get(&idev->pdev->dev); in intel_busy_work()
374 pm_runtime_mark_last_busy(&idev->pdev->dev); in intel_busy_work()
375 pm_runtime_put_autosuspend(&idev->pdev->dev); in intel_busy_work()
389 return -EOPNOTSUPP; in intel_open()
393 return -ENOMEM; in intel_open()
395 skb_queue_head_init(&intel->txq); in intel_open()
396 INIT_WORK(&intel->busy_work, intel_busy_work); in intel_open()
398 intel->hu = hu; in intel_open()
400 hu->priv = intel; in intel_open()
403 set_bit(STATE_BOOTING, &intel->flags); in intel_open()
410 struct intel_data *intel = hu->priv; in intel_close()
414 cancel_work_sync(&intel->busy_work); in intel_close()
418 skb_queue_purge(&intel->txq); in intel_close()
419 kfree_skb(intel->rx_skb); in intel_close()
422 hu->priv = NULL; in intel_close()
428 struct intel_data *intel = hu->priv; in intel_flush()
432 skb_queue_purge(&intel->txq); in intel_flush()
445 return -ENOMEM; in inject_cmd_complete()
448 hdr->evt = HCI_EV_CMD_COMPLETE; in inject_cmd_complete()
449 hdr->plen = sizeof(*evt) + 1; in inject_cmd_complete()
452 evt->ncmd = 0x01; in inject_cmd_complete()
453 evt->opcode = cpu_to_le16(opcode); in inject_cmd_complete()
464 struct intel_data *intel = hu->priv; in intel_set_baudrate()
465 struct hci_dev *hdev = hu->hdev; in intel_set_baudrate()
475 clear_bit(STATE_BOOTING, &intel->flags); in intel_set_baudrate()
478 if (err && err != -ETIMEDOUT) in intel_set_baudrate()
486 return -EINVAL; in intel_set_baudrate()
503 return -ENOMEM; in intel_set_baudrate()
511 skb_queue_tail(&intel->txq, skb); in intel_set_baudrate()
525 struct intel_data *intel = hu->priv; in intel_setup()
526 struct hci_dev *hdev = hu->hdev; in intel_setup()
542 hu->hdev->set_diag = btintel_set_diag; in intel_setup()
543 hu->hdev->set_bdaddr = btintel_set_bdaddr; in intel_setup()
553 if (hu->init_speed) in intel_setup()
554 init_speed = hu->init_speed; in intel_setup()
556 init_speed = hu->proto->init_speed; in intel_setup()
558 if (hu->oper_speed) in intel_setup()
559 oper_speed = hu->oper_speed; in intel_setup()
561 oper_speed = hu->proto->oper_speed; in intel_setup()
569 clear_bit(STATE_BOOTING, &intel->flags); in intel_setup()
572 if (err && err != -ETIMEDOUT) in intel_setup()
575 set_bit(STATE_BOOTLOADER, &intel->flags); in intel_setup()
591 return -EINVAL; in intel_setup()
608 return -EINVAL; in intel_setup()
627 clear_bit(STATE_BOOTLOADER, &intel->flags); in intel_setup()
638 return -ENODEV; in intel_setup()
655 return -EINVAL; in intel_setup()
663 set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks); in intel_setup()
670 * The firmware filename is ibt-<hw_variant>-<dev_revid>.sfi. in intel_setup()
683 * ibt-<hw_variant>-<hw_revision>-<fw_revision>.sfi. in intel_setup()
689 snprintf(fwname, sizeof(fwname), "intel/ibt-%u-%u.sfi", in intel_setup()
693 snprintf(fwname, sizeof(fwname), "intel/ibt-%u-%u-%u.sfi", in intel_setup()
699 return -EINVAL; in intel_setup()
702 err = request_firmware(&fw, fwname, &hdev->dev); in intel_setup()
711 /* Save the DDC file name for later */ in intel_setup()
715 snprintf(fwname, sizeof(fwname), "intel/ibt-%u-%u.ddc", in intel_setup()
719 snprintf(fwname, sizeof(fwname), "intel/ibt-%u-%u-%u.ddc", in intel_setup()
725 return -EINVAL; in intel_setup()
728 if (fw->size < 644) { in intel_setup()
730 fw->size); in intel_setup()
731 err = -EBADF; in intel_setup()
735 set_bit(STATE_DOWNLOADING, &intel->flags); in intel_setup()
742 set_bit(STATE_FIRMWARE_LOADED, &intel->flags); in intel_setup()
757 err = wait_on_bit_timeout(&intel->flags, STATE_DOWNLOADING, in intel_setup()
760 if (err == -EINTR) { in intel_setup()
762 err = -EINTR; in intel_setup()
768 err = -ETIMEDOUT; in intel_setup()
772 if (test_bit(STATE_FIRMWARE_FAILED, &intel->flags)) { in intel_setup()
774 err = -ENOEXEC; in intel_setup()
787 /* Check if there was an error and if is not -EALREADY which means the in intel_setup()
790 if (err < 0 && err != -EALREADY) in intel_setup()
802 set_bit(STATE_BOOTING, &intel->flags); in intel_setup()
821 clear_bit(STATE_BOOTING, &intel->flags); in intel_setup()
829 /* Enable LPM if matching pdev with wakeup enabled, set TX active in intel_setup()
830 * until further LPM TX notification. in intel_setup()
834 if (!hu->tty->dev) in intel_setup()
836 if (hu->tty->dev->parent == idev->pdev->dev.parent) { in intel_setup()
837 if (device_may_wakeup(&idev->pdev->dev)) { in intel_setup()
838 set_bit(STATE_LPM_ENABLED, &intel->flags); in intel_setup()
839 set_bit(STATE_TX_ACTIVE, &intel->flags); in intel_setup()
846 /* Ignore errors, device can work without DDC parameters */ in intel_setup()
862 clear_bit(STATE_BOOTLOADER, &intel->flags); in intel_setup()
870 struct intel_data *intel = hu->priv; in intel_recv_event()
873 if (!test_bit(STATE_BOOTLOADER, &intel->flags) && in intel_recv_event()
874 !test_bit(STATE_BOOTING, &intel->flags)) in intel_recv_event()
877 hdr = (void *)skb->data; in intel_recv_event()
883 if (skb->len == 7 && hdr->evt == 0xff && hdr->plen == 0x05 && in intel_recv_event()
884 skb->data[2] == 0x06) { in intel_recv_event()
885 if (skb->data[3] != 0x00) in intel_recv_event()
886 set_bit(STATE_FIRMWARE_FAILED, &intel->flags); in intel_recv_event()
888 if (test_and_clear_bit(STATE_DOWNLOADING, &intel->flags) && in intel_recv_event()
889 test_bit(STATE_FIRMWARE_LOADED, &intel->flags)) in intel_recv_event()
890 wake_up_bit(&intel->flags, STATE_DOWNLOADING); in intel_recv_event()
896 } else if (skb->len == 9 && hdr->evt == 0xff && hdr->plen == 0x07 && in intel_recv_event()
897 skb->data[2] == 0x02) { in intel_recv_event()
898 if (test_and_clear_bit(STATE_BOOTING, &intel->flags)) in intel_recv_event()
899 wake_up_bit(&intel->flags, STATE_BOOTING); in intel_recv_event()
908 struct intel_data *intel = hu->priv; in intel_recv_lpm_notify()
910 bt_dev_dbg(hdev, "TX idle notification (%d)", value); in intel_recv_lpm_notify()
913 set_bit(STATE_TX_ACTIVE, &intel->flags); in intel_recv_lpm_notify()
914 schedule_work(&intel->busy_work); in intel_recv_lpm_notify()
916 clear_bit(STATE_TX_ACTIVE, &intel->flags); in intel_recv_lpm_notify()
922 struct hci_lpm_pkt *lpm = (void *)skb->data; in intel_recv_lpm()
924 struct intel_data *intel = hu->priv; in intel_recv_lpm()
926 switch (lpm->opcode) { in intel_recv_lpm()
928 if (lpm->dlen < 1) { in intel_recv_lpm()
929 bt_dev_err(hu->hdev, "Invalid LPM notification packet"); in intel_recv_lpm()
932 intel_recv_lpm_notify(hdev, lpm->data[0]); in intel_recv_lpm()
935 set_bit(STATE_SUSPENDED, &intel->flags); in intel_recv_lpm()
936 if (test_and_clear_bit(STATE_LPM_TRANSACTION, &intel->flags)) in intel_recv_lpm()
937 wake_up_bit(&intel->flags, STATE_LPM_TRANSACTION); in intel_recv_lpm()
940 clear_bit(STATE_SUSPENDED, &intel->flags); in intel_recv_lpm()
941 if (test_and_clear_bit(STATE_LPM_TRANSACTION, &intel->flags)) in intel_recv_lpm()
942 wake_up_bit(&intel->flags, STATE_LPM_TRANSACTION); in intel_recv_lpm()
945 bt_dev_err(hdev, "Unknown LPM opcode (%02x)", lpm->opcode); in intel_recv_lpm()
970 struct intel_data *intel = hu->priv; in intel_recv()
972 if (!test_bit(HCI_UART_REGISTERED, &hu->flags)) in intel_recv()
973 return -EUNATCH; in intel_recv()
975 intel->rx_skb = h4_recv_buf(hu->hdev, intel->rx_skb, data, count, in intel_recv()
978 if (IS_ERR(intel->rx_skb)) { in intel_recv()
979 int err = PTR_ERR(intel->rx_skb); in intel_recv()
981 bt_dev_err(hu->hdev, "Frame reassembly failed (%d)", err); in intel_recv()
982 intel->rx_skb = NULL; in intel_recv()
991 struct intel_data *intel = hu->priv; in intel_enqueue()
996 if (!hu->tty->dev) in intel_enqueue()
1004 if (hu->tty->dev->parent == idev->pdev->dev.parent) { in intel_enqueue()
1005 pm_runtime_get_sync(&idev->pdev->dev); in intel_enqueue()
1006 pm_runtime_mark_last_busy(&idev->pdev->dev); in intel_enqueue()
1007 pm_runtime_put_autosuspend(&idev->pdev->dev); in intel_enqueue()
1013 skb_queue_tail(&intel->txq, skb); in intel_enqueue()
1020 struct intel_data *intel = hu->priv; in intel_dequeue()
1023 skb = skb_dequeue(&intel->txq); in intel_dequeue()
1027 if (test_bit(STATE_BOOTLOADER, &intel->flags) && in intel_dequeue()
1029 struct hci_command_hdr *cmd = (void *)skb->data; in intel_dequeue()
1030 __u16 opcode = le16_to_cpu(cmd->opcode); in intel_dequeue()
1038 inject_cmd_complete(hu->hdev, opcode); in intel_dequeue()
1077 mutex_lock(&idev->hu_lock); in intel_suspend_device()
1078 if (idev->hu) in intel_suspend_device()
1079 intel_lpm_suspend(idev->hu); in intel_suspend_device()
1080 mutex_unlock(&idev->hu_lock); in intel_suspend_device()
1089 mutex_lock(&idev->hu_lock); in intel_resume_device()
1090 if (idev->hu) in intel_resume_device()
1091 intel_lpm_resume(idev->hu); in intel_resume_device()
1092 mutex_unlock(&idev->hu_lock); in intel_resume_device()
1104 enable_irq_wake(idev->irq); in intel_suspend()
1114 disable_irq_wake(idev->irq); in intel_resume()
1129 { "reset-gpios", &reset_gpios, 1, ACPI_GPIO_QUIRK_ONLY_GPIOIO },
1130 { "host-wake-gpios", &host_wake_gpios, 1, ACPI_GPIO_QUIRK_ONLY_GPIOIO },
1139 idev = devm_kzalloc(&pdev->dev, sizeof(*idev), GFP_KERNEL); in intel_probe()
1141 return -ENOMEM; in intel_probe()
1143 mutex_init(&idev->hu_lock); in intel_probe()
1145 idev->pdev = pdev; in intel_probe()
1147 ret = devm_acpi_dev_add_driver_gpios(&pdev->dev, acpi_hci_intel_gpios); in intel_probe()
1149 dev_dbg(&pdev->dev, "Unable to add GPIO mapping table\n"); in intel_probe()
1151 idev->reset = devm_gpiod_get(&pdev->dev, "reset", GPIOD_OUT_LOW); in intel_probe()
1152 if (IS_ERR(idev->reset)) { in intel_probe()
1153 dev_err(&pdev->dev, "Unable to retrieve gpio\n"); in intel_probe()
1154 return PTR_ERR(idev->reset); in intel_probe()
1157 idev->irq = platform_get_irq(pdev, 0); in intel_probe()
1158 if (idev->irq < 0) { in intel_probe()
1161 dev_err(&pdev->dev, "No IRQ, falling back to gpio-irq\n"); in intel_probe()
1163 host_wake = devm_gpiod_get(&pdev->dev, "host-wake", GPIOD_IN); in intel_probe()
1165 dev_err(&pdev->dev, "Unable to retrieve IRQ\n"); in intel_probe()
1169 idev->irq = gpiod_to_irq(host_wake); in intel_probe()
1170 if (idev->irq < 0) { in intel_probe()
1171 dev_err(&pdev->dev, "No corresponding irq for gpio\n"); in intel_probe()
1176 /* Only enable wake-up/irq when controller is powered */ in intel_probe()
1177 device_set_wakeup_capable(&pdev->dev, true); in intel_probe()
1178 device_wakeup_disable(&pdev->dev); in intel_probe()
1185 list_add_tail(&idev->list, &intel_device_list); in intel_probe()
1188 dev_info(&pdev->dev, "registered, gpio(%d)/irq(%d).\n", in intel_probe()
1189 desc_to_gpio(idev->reset), idev->irq); in intel_probe()
1198 device_wakeup_disable(&pdev->dev); in intel_remove()
1201 list_del(&idev->list); in intel_remove()
1204 dev_info(&pdev->dev, "unregistered.\n"); in intel_remove()