Lines Matching +full:fw +full:- +full:init +full:- +full:baudrate
1 // SPDX-License-Identifier: GPL-2.0-or-later
92 /* Bluetooth vendor command : Set operational baudrate */
159 const struct firmware *fw; member
194 #define NXP_HDR_RX_TIMEOUT 0x0003 /* FW Header chunk not received */
195 #define NXP_DATA_RX_TIMEOUT 0x0004 /* FW Data chunk not received */
259 #define INIT 0x00000001 macro
310 struct ps_data *psdata = &nxpdev->psdata; in nxp_drv_send_cmd()
316 psdata->driver_sent_cmd = true; in nxp_drv_send_cmd()
318 psdata->driver_sent_cmd = false; in nxp_drv_send_cmd()
325 if (schedule_work(&nxpdev->tx_work)) in btnxpuart_tx_wakeup()
326 set_bit(BTNXPUART_TX_STATE_ACTIVE, &nxpdev->tx_state); in btnxpuart_tx_wakeup()
332 struct ps_data *psdata = &nxpdev->psdata; in ps_start_timer()
337 if (psdata->cur_psmode == PS_MODE_ENABLE) in ps_start_timer()
338 mod_timer(&psdata->ps_timer, jiffies + msecs_to_jiffies(psdata->h2c_ps_interval)); in ps_start_timer()
340 if (psdata->ps_state == PS_STATE_AWAKE && psdata->ps_cmd == PS_CMD_ENTER_PS) in ps_start_timer()
341 cancel_work_sync(&psdata->work); in ps_start_timer()
346 struct ps_data *psdata = &nxpdev->psdata; in ps_cancel_timer()
348 flush_work(&psdata->work); in ps_cancel_timer()
349 timer_shutdown_sync(&psdata->ps_timer); in ps_cancel_timer()
355 struct ps_data *psdata = &nxpdev->psdata; in ps_control()
358 if (psdata->ps_state == ps_state || in ps_control()
359 !test_bit(BTNXPUART_SERDEV_OPEN, &nxpdev->tx_state)) in ps_control()
362 mutex_lock(&psdata->ps_lock); in ps_control()
363 switch (psdata->cur_h2c_wakeupmode) { in ps_control()
366 status = serdev_device_set_tiocm(nxpdev->serdev, TIOCM_DTR, 0); in ps_control()
368 status = serdev_device_set_tiocm(nxpdev->serdev, 0, TIOCM_DTR); in ps_control()
373 status = serdev_device_break_ctl(nxpdev->serdev, 0); in ps_control()
375 status = serdev_device_break_ctl(nxpdev->serdev, -1); in ps_control()
376 msleep(20); /* Allow chip to detect UART-break and enter sleep */ in ps_control()
382 psdata->ps_state = ps_state; in ps_control()
383 mutex_unlock(&psdata->ps_lock); in ps_control()
393 if (data->ps_cmd == PS_CMD_ENTER_PS && data->cur_psmode == PS_MODE_ENABLE) in ps_work_func()
394 ps_control(data->hdev, PS_STATE_SLEEP); in ps_work_func()
395 else if (data->ps_cmd == PS_CMD_EXIT_PS) in ps_work_func()
396 ps_control(data->hdev, PS_STATE_AWAKE); in ps_work_func()
402 struct hci_dev *hdev = data->hdev; in ps_timeout_func()
405 if (test_bit(BTNXPUART_TX_STATE_ACTIVE, &nxpdev->tx_state)) { in ps_timeout_func()
408 data->ps_cmd = PS_CMD_ENTER_PS; in ps_timeout_func()
409 schedule_work(&data->work); in ps_timeout_func()
416 struct ps_data *psdata = &nxpdev->psdata; in ps_setup()
418 psdata->hdev = hdev; in ps_setup()
419 INIT_WORK(&psdata->work, ps_work_func); in ps_setup()
420 mutex_init(&psdata->ps_lock); in ps_setup()
421 timer_setup(&psdata->ps_timer, ps_timeout_func, 0); in ps_setup()
426 struct ps_data *psdata = &nxpdev->psdata; in ps_wakeup()
429 mutex_lock(&psdata->ps_lock); in ps_wakeup()
430 ps_state = psdata->ps_state; in ps_wakeup()
431 mutex_unlock(&psdata->ps_lock); in ps_wakeup()
434 psdata->ps_cmd = PS_CMD_EXIT_PS; in ps_wakeup()
435 schedule_work(&psdata->work); in ps_wakeup()
443 struct ps_data *psdata = &nxpdev->psdata; in ps_cleanup()
446 mutex_lock(&psdata->ps_lock); in ps_cleanup()
447 ps_state = psdata->ps_state; in ps_cleanup()
448 mutex_unlock(&psdata->ps_lock); in ps_cleanup()
451 ps_control(psdata->hdev, PS_STATE_AWAKE); in ps_cleanup()
454 cancel_work_sync(&psdata->work); in ps_cleanup()
455 mutex_destroy(&psdata->ps_lock); in ps_cleanup()
461 struct ps_data *psdata = &nxpdev->psdata; in send_ps_cmd()
466 if (psdata->target_ps_mode == PS_MODE_ENABLE) in send_ps_cmd()
470 pcmd.c2h_ps_interval = __cpu_to_le16(psdata->c2h_ps_interval); in send_ps_cmd()
481 psdata->cur_psmode = psdata->target_ps_mode; in send_ps_cmd()
483 psdata->target_ps_mode = psdata->cur_psmode; in send_ps_cmd()
484 if (psdata->cur_psmode == PS_MODE_ENABLE) in send_ps_cmd()
489 *status, psdata->cur_psmode); in send_ps_cmd()
499 struct ps_data *psdata = &nxpdev->psdata; in send_wakeup_method_cmd()
504 pcmd.c2h_wakeupmode = psdata->c2h_wakeupmode; in send_wakeup_method_cmd()
505 pcmd.c2h_wakeup_gpio = psdata->c2h_wakeup_gpio; in send_wakeup_method_cmd()
506 switch (psdata->h2c_wakeupmode) { in send_wakeup_method_cmd()
519 bt_dev_err(hdev, "Setting wake-up method failed (%ld)", PTR_ERR(skb)); in send_wakeup_method_cmd()
526 psdata->cur_h2c_wakeupmode = psdata->h2c_wakeupmode; in send_wakeup_method_cmd()
528 psdata->h2c_wakeupmode = psdata->cur_h2c_wakeupmode; in send_wakeup_method_cmd()
530 *status, psdata->cur_h2c_wakeupmode); in send_wakeup_method_cmd()
540 struct ps_data *psdata = &nxpdev->psdata; in ps_init()
542 serdev_device_set_tiocm(nxpdev->serdev, 0, TIOCM_RTS); in ps_init()
544 serdev_device_set_tiocm(nxpdev->serdev, TIOCM_RTS, 0); in ps_init()
547 psdata->ps_state = PS_STATE_AWAKE; in ps_init()
548 psdata->c2h_wakeupmode = BT_HOST_WAKEUP_METHOD_NONE; in ps_init()
549 psdata->c2h_wakeup_gpio = 0xff; in ps_init()
551 psdata->cur_h2c_wakeupmode = WAKEUP_METHOD_INVALID; in ps_init()
552 psdata->h2c_ps_interval = PS_DEFAULT_TIMEOUT_PERIOD_MS; in ps_init()
555 psdata->h2c_wakeupmode = WAKEUP_METHOD_DTR; in ps_init()
556 serdev_device_set_tiocm(nxpdev->serdev, 0, TIOCM_DTR); in ps_init()
557 serdev_device_set_tiocm(nxpdev->serdev, TIOCM_DTR, 0); in ps_init()
561 psdata->h2c_wakeupmode = WAKEUP_METHOD_BREAK; in ps_init()
562 serdev_device_break_ctl(nxpdev->serdev, -1); in ps_init()
564 serdev_device_break_ctl(nxpdev->serdev, 0); in ps_init()
569 psdata->cur_psmode = PS_MODE_DISABLE; in ps_init()
570 psdata->target_ps_mode = DEFAULT_PS_MODE; in ps_init()
572 if (psdata->cur_h2c_wakeupmode != psdata->h2c_wakeupmode) in ps_init()
574 if (psdata->cur_psmode != psdata->target_ps_mode) in ps_init()
584 nxpdev->fw_dnld_v1_offset = 0; in nxp_download_firmware()
585 nxpdev->fw_v1_sent_bytes = 0; in nxp_download_firmware()
586 nxpdev->fw_v1_expected_len = HDR_LEN; in nxp_download_firmware()
587 nxpdev->boot_reg_offset = 0; in nxp_download_firmware()
588 nxpdev->fw_dnld_v3_offset = 0; in nxp_download_firmware()
589 nxpdev->fw_v3_offset_correction = 0; in nxp_download_firmware()
590 nxpdev->baudrate_changed = false; in nxp_download_firmware()
591 nxpdev->timeout_changed = false; in nxp_download_firmware()
592 nxpdev->helper_downloaded = false; in nxp_download_firmware()
594 serdev_device_set_baudrate(nxpdev->serdev, HCI_NXP_PRI_BAUDRATE); in nxp_download_firmware()
595 serdev_device_set_flow_control(nxpdev->serdev, false); in nxp_download_firmware()
596 nxpdev->current_baudrate = HCI_NXP_PRI_BAUDRATE; in nxp_download_firmware()
598 /* Wait till FW is downloaded */ in nxp_download_firmware()
599 err = wait_event_interruptible_timeout(nxpdev->fw_dnld_done_wait_q, in nxp_download_firmware()
601 &nxpdev->tx_state), in nxp_download_firmware()
604 release_firmware(nxpdev->fw); in nxp_download_firmware()
605 memset(nxpdev->fw_name, 0, sizeof(nxpdev->fw_name)); in nxp_download_firmware()
608 bt_dev_err(hdev, "FW Download Timeout. offset: %d", in nxp_download_firmware()
609 nxpdev->fw_dnld_v1_offset ? in nxp_download_firmware()
610 nxpdev->fw_dnld_v1_offset : in nxp_download_firmware()
611 nxpdev->fw_dnld_v3_offset); in nxp_download_firmware()
612 return -ETIMEDOUT; in nxp_download_firmware()
614 if (test_bit(BTNXPUART_FW_DOWNLOAD_ABORT, &nxpdev->tx_state)) { in nxp_download_firmware()
615 bt_dev_err(hdev, "FW Download Aborted"); in nxp_download_firmware()
616 return -EINTR; in nxp_download_firmware()
619 serdev_device_set_flow_control(nxpdev->serdev, true); in nxp_download_firmware()
621 /* Allow the downloaded FW to initialize */ in nxp_download_firmware()
638 serdev_device_write_buf(nxpdev->serdev, ack_nak, len); in nxp_send_ack()
646 u32 clkdivaddr = CLKDIVADDR - nxpdev->boot_reg_offset; in nxp_fw_change_baudrate()
647 u32 uartdivaddr = UARTDIVADDR - nxpdev->boot_reg_offset; in nxp_fw_change_baudrate()
648 u32 uartmcraddr = UARTMCRADDR - nxpdev->boot_reg_offset; in nxp_fw_change_baudrate()
649 u32 uartreinitaddr = UARTREINITADDR - nxpdev->boot_reg_offset; in nxp_fw_change_baudrate()
650 u32 uarticraddr = UARTICRADDR - nxpdev->boot_reg_offset; in nxp_fw_change_baudrate()
651 u32 uartfcraddr = UARTFCRADDR - nxpdev->boot_reg_offset; in nxp_fw_change_baudrate()
657 /* FW expects swapped CRC bytes */ in nxp_fw_change_baudrate()
659 sizeof(nxp_cmd5) - 4)); in nxp_fw_change_baudrate()
661 serdev_device_write_buf(nxpdev->serdev, (u8 *)&nxp_cmd5, sizeof(nxp_cmd5)); in nxp_fw_change_baudrate()
662 nxpdev->fw_v3_offset_correction += req_len; in nxp_fw_change_baudrate()
671 uart_config.re_init.value = __cpu_to_le32(INIT); in nxp_fw_change_baudrate()
676 /* FW expects swapped CRC bytes */ in nxp_fw_change_baudrate()
678 sizeof(uart_config) - 4)); in nxp_fw_change_baudrate()
680 serdev_device_write_buf(nxpdev->serdev, (u8 *)&uart_config, sizeof(uart_config)); in nxp_fw_change_baudrate()
681 serdev_device_wait_until_sent(nxpdev->serdev, 0); in nxp_fw_change_baudrate()
682 nxpdev->fw_v3_offset_correction += req_len; in nxp_fw_change_baudrate()
699 /* FW expects swapped CRC bytes */ in nxp_fw_change_timeout()
701 sizeof(nxp_cmd7) - 4)); in nxp_fw_change_timeout()
702 serdev_device_write_buf(nxpdev->serdev, (u8 *)&nxp_cmd7, sizeof(nxp_cmd7)); in nxp_fw_change_timeout()
703 serdev_device_wait_until_sent(nxpdev->serdev, 0); in nxp_fw_change_timeout()
704 nxpdev->fw_v3_offset_correction += req_len; in nxp_fw_change_timeout()
712 return __le32_to_cpu(hdr->payload_len); in nxp_get_data_len()
717 return test_bit(BTNXPUART_FW_DOWNLOADING, &nxpdev->tx_state); in is_fw_downloading()
722 if (test_bit(BTNXPUART_CHECK_BOOT_SIGNATURE, &nxpdev->tx_state)) { in process_boot_signature()
723 clear_bit(BTNXPUART_CHECK_BOOT_SIGNATURE, &nxpdev->tx_state); in process_boot_signature()
724 wake_up_interruptible(&nxpdev->check_boot_sign_wait_q); in process_boot_signature()
736 return -ENOENT; in nxp_request_firmware()
738 if (!strlen(nxpdev->fw_name)) { in nxp_request_firmware()
739 snprintf(nxpdev->fw_name, MAX_FW_FILE_NAME_LEN, "%s", fw_name); in nxp_request_firmware()
741 bt_dev_dbg(hdev, "Request Firmware: %s", nxpdev->fw_name); in nxp_request_firmware()
742 err = request_firmware(&nxpdev->fw, nxpdev->fw_name, &hdev->dev); in nxp_request_firmware()
744 bt_dev_err(hdev, "Firmware file %s not found", nxpdev->fw_name); in nxp_request_firmware()
745 clear_bit(BTNXPUART_FW_DOWNLOADING, &nxpdev->tx_state); in nxp_request_firmware()
762 chip_id = le16_to_cpu(req->chip_id ^ req->chip_id_comp); in nxp_recv_chip_ver_v1()
763 if (chip_id == 0xffff && nxpdev->fw_dnld_v1_offset) { in nxp_recv_chip_ver_v1()
764 nxpdev->fw_dnld_v1_offset = 0; in nxp_recv_chip_ver_v1()
765 nxpdev->fw_v1_sent_bytes = 0; in nxp_recv_chip_ver_v1()
766 nxpdev->fw_v1_expected_len = HDR_LEN; in nxp_recv_chip_ver_v1()
767 release_firmware(nxpdev->fw); in nxp_recv_chip_ver_v1()
768 memset(nxpdev->fw_name, 0, sizeof(nxpdev->fw_name)); in nxp_recv_chip_ver_v1()
780 struct btnxpuart_data *nxp_data = nxpdev->nxp_data; in nxp_recv_fw_req_v1()
791 len = __le16_to_cpu(req->len ^ req->len_comp); in nxp_recv_fw_req_v1()
799 len = __le16_to_cpu(req->len); in nxp_recv_fw_req_v1()
801 if (!nxp_data->helper_fw_name) { in nxp_recv_fw_req_v1()
802 if (!nxpdev->timeout_changed) { in nxp_recv_fw_req_v1()
803 nxpdev->timeout_changed = nxp_fw_change_timeout(hdev, in nxp_recv_fw_req_v1()
807 if (!nxpdev->baudrate_changed) { in nxp_recv_fw_req_v1()
808 nxpdev->baudrate_changed = nxp_fw_change_baudrate(hdev, in nxp_recv_fw_req_v1()
810 if (nxpdev->baudrate_changed) { in nxp_recv_fw_req_v1()
811 serdev_device_set_baudrate(nxpdev->serdev, in nxp_recv_fw_req_v1()
813 serdev_device_set_flow_control(nxpdev->serdev, true); in nxp_recv_fw_req_v1()
814 nxpdev->current_baudrate = HCI_NXP_SEC_BAUDRATE; in nxp_recv_fw_req_v1()
820 if (!nxp_data->helper_fw_name || nxpdev->helper_downloaded) { in nxp_recv_fw_req_v1()
821 if (nxp_request_firmware(hdev, nxp_data->fw_name)) in nxp_recv_fw_req_v1()
823 } else if (nxp_data->helper_fw_name && !nxpdev->helper_downloaded) { in nxp_recv_fw_req_v1()
824 if (nxp_request_firmware(hdev, nxp_data->helper_fw_name)) in nxp_recv_fw_req_v1()
829 bt_dev_dbg(hdev, "FW Downloaded Successfully: %zu bytes", in nxp_recv_fw_req_v1()
830 nxpdev->fw->size); in nxp_recv_fw_req_v1()
831 if (nxp_data->helper_fw_name && !nxpdev->helper_downloaded) { in nxp_recv_fw_req_v1()
832 nxpdev->helper_downloaded = true; in nxp_recv_fw_req_v1()
833 serdev_device_wait_until_sent(nxpdev->serdev, 0); in nxp_recv_fw_req_v1()
834 serdev_device_set_baudrate(nxpdev->serdev, in nxp_recv_fw_req_v1()
836 serdev_device_set_flow_control(nxpdev->serdev, true); in nxp_recv_fw_req_v1()
838 clear_bit(BTNXPUART_FW_DOWNLOADING, &nxpdev->tx_state); in nxp_recv_fw_req_v1()
839 wake_up_interruptible(&nxpdev->fw_dnld_done_wait_q); in nxp_recv_fw_req_v1()
847 len = nxpdev->fw_v1_sent_bytes; in nxp_recv_fw_req_v1()
848 bt_dev_dbg(hdev, "CRC error. Resend %d bytes of FW.", len); in nxp_recv_fw_req_v1()
850 nxpdev->fw_dnld_v1_offset += nxpdev->fw_v1_sent_bytes; in nxp_recv_fw_req_v1()
852 /* The FW bin file is made up of many blocks of in nxp_recv_fw_req_v1()
854 * FW has requested a header, read the payload length in nxp_recv_fw_req_v1()
856 * In the next iteration, the FW should request the in nxp_recv_fw_req_v1()
859 * mismatch, clearly the driver and FW are out of sync, in nxp_recv_fw_req_v1()
860 * and we need to re-send the previous header again. in nxp_recv_fw_req_v1()
862 if (len == nxpdev->fw_v1_expected_len) { in nxp_recv_fw_req_v1()
864 nxpdev->fw_v1_expected_len = nxp_get_data_len(nxpdev->fw->data + in nxp_recv_fw_req_v1()
865 nxpdev->fw_dnld_v1_offset); in nxp_recv_fw_req_v1()
867 nxpdev->fw_v1_expected_len = HDR_LEN; in nxp_recv_fw_req_v1()
869 /* FW download out of sync. Send previous chunk again */ in nxp_recv_fw_req_v1()
870 nxpdev->fw_dnld_v1_offset -= nxpdev->fw_v1_sent_bytes; in nxp_recv_fw_req_v1()
871 nxpdev->fw_v1_expected_len = HDR_LEN; in nxp_recv_fw_req_v1()
875 if (nxpdev->fw_dnld_v1_offset + len <= nxpdev->fw->size) in nxp_recv_fw_req_v1()
876 serdev_device_write_buf(nxpdev->serdev, nxpdev->fw->data + in nxp_recv_fw_req_v1()
877 nxpdev->fw_dnld_v1_offset, len); in nxp_recv_fw_req_v1()
878 nxpdev->fw_v1_sent_bytes = len; in nxp_recv_fw_req_v1()
903 nxpdev->boot_reg_offset = 1; in nxp_get_fw_name_from_chipid()
936 chip_id = le16_to_cpu(req->chip_id); in nxp_recv_chip_ver_v3()
937 loader_ver = req->loader_ver; in nxp_recv_chip_ver_v3()
950 __u32 offset = __le32_to_cpu(req->offset); in nxp_handle_fw_download_error()
951 __u16 err = __le16_to_cpu(req->error); in nxp_handle_fw_download_error()
961 sizeof(nak_tx_buf) - 1, 0xff); in nxp_handle_fw_download_error()
962 serdev_device_write_buf(nxpdev->serdev, nak_tx_buf.buf, in nxp_handle_fw_download_error()
984 if (!req || !nxpdev->fw) in nxp_recv_fw_req_v3()
987 if (!req->error) { in nxp_recv_fw_req_v3()
994 len = __le16_to_cpu(req->len); in nxp_recv_fw_req_v3()
996 if (!nxpdev->timeout_changed) { in nxp_recv_fw_req_v3()
997 nxpdev->timeout_changed = nxp_fw_change_timeout(hdev, len); in nxp_recv_fw_req_v3()
1001 if (!nxpdev->baudrate_changed) { in nxp_recv_fw_req_v3()
1002 nxpdev->baudrate_changed = nxp_fw_change_baudrate(hdev, len); in nxp_recv_fw_req_v3()
1003 if (nxpdev->baudrate_changed) { in nxp_recv_fw_req_v3()
1004 serdev_device_set_baudrate(nxpdev->serdev, in nxp_recv_fw_req_v3()
1006 serdev_device_set_flow_control(nxpdev->serdev, true); in nxp_recv_fw_req_v3()
1007 nxpdev->current_baudrate = HCI_NXP_SEC_BAUDRATE; in nxp_recv_fw_req_v3()
1012 if (req->len == 0) { in nxp_recv_fw_req_v3()
1013 bt_dev_dbg(hdev, "FW Downloaded Successfully: %zu bytes", in nxp_recv_fw_req_v3()
1014 nxpdev->fw->size); in nxp_recv_fw_req_v3()
1015 clear_bit(BTNXPUART_FW_DOWNLOADING, &nxpdev->tx_state); in nxp_recv_fw_req_v3()
1016 wake_up_interruptible(&nxpdev->fw_dnld_done_wait_q); in nxp_recv_fw_req_v3()
1020 offset = __le32_to_cpu(req->offset); in nxp_recv_fw_req_v3()
1021 if (offset < nxpdev->fw_v3_offset_correction) { in nxp_recv_fw_req_v3()
1023 * FW is out of sync and needs a power cycle. in nxp_recv_fw_req_v3()
1025 bt_dev_err(hdev, "Something went wrong during FW download"); in nxp_recv_fw_req_v3()
1030 nxpdev->fw_dnld_v3_offset = offset - nxpdev->fw_v3_offset_correction; in nxp_recv_fw_req_v3()
1031 serdev_device_write_buf(nxpdev->serdev, nxpdev->fw->data + in nxp_recv_fw_req_v3()
1032 nxpdev->fw_dnld_v3_offset, len); in nxp_recv_fw_req_v3()
1042 __le32 new_baudrate = __cpu_to_le32(nxpdev->new_baudrate); in nxp_set_baudrate_cmd()
1043 struct ps_data *psdata = &nxpdev->psdata; in nxp_set_baudrate_cmd()
1052 bt_dev_err(hdev, "Setting baudrate failed (%ld)", PTR_ERR(skb)); in nxp_set_baudrate_cmd()
1059 serdev_device_set_baudrate(nxpdev->serdev, nxpdev->new_baudrate); in nxp_set_baudrate_cmd()
1060 nxpdev->current_baudrate = nxpdev->new_baudrate; in nxp_set_baudrate_cmd()
1062 bt_dev_dbg(hdev, "Set baudrate response: status=%d, baudrate=%d", in nxp_set_baudrate_cmd()
1063 *status, nxpdev->new_baudrate); in nxp_set_baudrate_cmd()
1072 serdev_device_set_baudrate(nxpdev->serdev, HCI_NXP_PRI_BAUDRATE); in nxp_check_boot_sign()
1073 if (test_bit(BTNXPUART_IR_IN_PROGRESS, &nxpdev->tx_state)) in nxp_check_boot_sign()
1074 serdev_device_set_flow_control(nxpdev->serdev, false); in nxp_check_boot_sign()
1076 serdev_device_set_flow_control(nxpdev->serdev, true); in nxp_check_boot_sign()
1077 set_bit(BTNXPUART_CHECK_BOOT_SIGNATURE, &nxpdev->tx_state); in nxp_check_boot_sign()
1079 return wait_event_interruptible_timeout(nxpdev->check_boot_sign_wait_q, in nxp_check_boot_sign()
1081 &nxpdev->tx_state), in nxp_check_boot_sign()
1093 return -ENOMEM; in nxp_set_ind_reset()
1109 bt_dev_dbg(hdev, "Need FW Download."); in nxp_setup()
1114 bt_dev_dbg(hdev, "FW already running."); in nxp_setup()
1115 clear_bit(BTNXPUART_FW_DOWNLOADING, &nxpdev->tx_state); in nxp_setup()
1118 serdev_device_set_baudrate(nxpdev->serdev, nxpdev->fw_init_baudrate); in nxp_setup()
1119 nxpdev->current_baudrate = nxpdev->fw_init_baudrate; in nxp_setup()
1121 if (nxpdev->current_baudrate != HCI_NXP_SEC_BAUDRATE) { in nxp_setup()
1122 nxpdev->new_baudrate = HCI_NXP_SEC_BAUDRATE; in nxp_setup()
1128 if (test_and_clear_bit(BTNXPUART_IR_IN_PROGRESS, &nxpdev->tx_state)) in nxp_setup()
1140 set_bit(BTNXPUART_IR_IN_PROGRESS, &nxpdev->tx_state); in nxp_hw_err()
1155 if (test_bit(BTNXPUART_IR_IN_PROGRESS, &nxpdev->tx_state)) { in nxp_shutdown()
1162 serdev_device_set_flow_control(nxpdev->serdev, false); in nxp_shutdown()
1163 set_bit(BTNXPUART_FW_DOWNLOADING, &nxpdev->tx_state); in nxp_shutdown()
1177 skb_queue_tail(&nxpdev->txq, skb); in btnxpuart_queue_skb()
1185 struct ps_data *psdata = &nxpdev->psdata; in nxp_enqueue()
1192 * driver flags accordingly and ask driver to re-send the command to FW. in nxp_enqueue()
1197 if (bt_cb(skb)->pkt_type == HCI_COMMAND_PKT && !psdata->driver_sent_cmd) { in nxp_enqueue()
1198 hdr = (struct hci_command_hdr *)skb->data; in nxp_enqueue()
1199 if (hdr->plen != (skb->len - HCI_COMMAND_HDR_SIZE)) in nxp_enqueue()
1202 switch (__le16_to_cpu(hdr->opcode)) { in nxp_enqueue()
1204 if (hdr->plen == sizeof(ps_parm)) { in nxp_enqueue()
1205 memcpy(&ps_parm, skb->data + HCI_COMMAND_HDR_SIZE, hdr->plen); in nxp_enqueue()
1207 psdata->target_ps_mode = PS_MODE_ENABLE; in nxp_enqueue()
1209 psdata->target_ps_mode = PS_MODE_DISABLE; in nxp_enqueue()
1210 psdata->c2h_ps_interval = __le16_to_cpu(ps_parm.c2h_ps_interval); in nxp_enqueue()
1216 if (hdr->plen == sizeof(wakeup_parm)) { in nxp_enqueue()
1217 memcpy(&wakeup_parm, skb->data + HCI_COMMAND_HDR_SIZE, hdr->plen); in nxp_enqueue()
1218 psdata->c2h_wakeupmode = wakeup_parm.c2h_wakeupmode; in nxp_enqueue()
1219 psdata->c2h_wakeup_gpio = wakeup_parm.c2h_wakeup_gpio; in nxp_enqueue()
1220 psdata->h2c_wakeup_gpio = wakeup_parm.h2c_wakeup_gpio; in nxp_enqueue()
1223 psdata->h2c_wakeupmode = WAKEUP_METHOD_DTR; in nxp_enqueue()
1227 psdata->h2c_wakeupmode = WAKEUP_METHOD_BREAK; in nxp_enqueue()
1235 if (hdr->plen == sizeof(baudrate_parm)) { in nxp_enqueue()
1236 memcpy(&baudrate_parm, skb->data + HCI_COMMAND_HDR_SIZE, hdr->plen); in nxp_enqueue()
1237 nxpdev->new_baudrate = __le32_to_cpu(baudrate_parm); in nxp_enqueue()
1243 if (hdr->plen == 1) { in nxp_enqueue()
1265 return skb_dequeue(&nxpdev->txq); in nxp_dequeue()
1273 struct serdev_device *serdev = nxpdev->serdev; in btnxpuart_tx_work()
1274 struct hci_dev *hdev = nxpdev->hdev; in btnxpuart_tx_work()
1282 len = serdev_device_write_buf(serdev, skb->data, skb->len); in btnxpuart_tx_work()
1283 hdev->stat.byte_tx += len; in btnxpuart_tx_work()
1286 if (skb->len > 0) { in btnxpuart_tx_work()
1287 skb_queue_head(&nxpdev->txq, skb); in btnxpuart_tx_work()
1293 hdev->stat.cmd_tx++; in btnxpuart_tx_work()
1296 hdev->stat.acl_tx++; in btnxpuart_tx_work()
1299 hdev->stat.sco_tx++; in btnxpuart_tx_work()
1305 clear_bit(BTNXPUART_TX_STATE_ACTIVE, &nxpdev->tx_state); in btnxpuart_tx_work()
1313 err = serdev_device_open(nxpdev->serdev); in btnxpuart_open()
1316 dev_name(&nxpdev->serdev->dev)); in btnxpuart_open()
1318 set_bit(BTNXPUART_SERDEV_OPEN, &nxpdev->tx_state); in btnxpuart_open()
1327 serdev_device_close(nxpdev->serdev); in btnxpuart_close()
1328 skb_queue_purge(&nxpdev->txq); in btnxpuart_close()
1329 if (!IS_ERR_OR_NULL(nxpdev->rx_skb)) { in btnxpuart_close()
1330 kfree_skb(nxpdev->rx_skb); in btnxpuart_close()
1331 nxpdev->rx_skb = NULL; in btnxpuart_close()
1333 clear_bit(BTNXPUART_SERDEV_OPEN, &nxpdev->tx_state); in btnxpuart_close()
1342 serdev_device_write_flush(nxpdev->serdev); in btnxpuart_flush()
1343 skb_queue_purge(&nxpdev->txq); in btnxpuart_flush()
1345 cancel_work_sync(&nxpdev->tx_work); in btnxpuart_flush()
1347 if (!IS_ERR_OR_NULL(nxpdev->rx_skb)) { in btnxpuart_flush()
1348 kfree_skb(nxpdev->rx_skb); in btnxpuart_flush()
1349 nxpdev->rx_skb = NULL; in btnxpuart_flush()
1372 nxpdev->rx_skb = h4_recv_buf(nxpdev->hdev, nxpdev->rx_skb, data, count, in btnxpuart_receive_buf()
1374 if (IS_ERR(nxpdev->rx_skb)) { in btnxpuart_receive_buf()
1375 int err = PTR_ERR(nxpdev->rx_skb); in btnxpuart_receive_buf()
1376 /* Safe to ignore out-of-sync bootloader signatures */ in btnxpuart_receive_buf()
1378 bt_dev_err(nxpdev->hdev, "Frame reassembly failed (%d)", err); in btnxpuart_receive_buf()
1379 nxpdev->rx_skb = NULL; in btnxpuart_receive_buf()
1383 nxpdev->hdev->stat.byte_rx += count; in btnxpuart_receive_buf()
1402 nxpdev = devm_kzalloc(&serdev->dev, sizeof(*nxpdev), GFP_KERNEL); in nxp_serdev_probe()
1404 return -ENOMEM; in nxp_serdev_probe()
1406 nxpdev->nxp_data = (struct btnxpuart_data *)device_get_match_data(&serdev->dev); in nxp_serdev_probe()
1408 nxpdev->serdev = serdev; in nxp_serdev_probe()
1413 INIT_WORK(&nxpdev->tx_work, btnxpuart_tx_work); in nxp_serdev_probe()
1414 skb_queue_head_init(&nxpdev->txq); in nxp_serdev_probe()
1416 init_waitqueue_head(&nxpdev->fw_dnld_done_wait_q); in nxp_serdev_probe()
1417 init_waitqueue_head(&nxpdev->check_boot_sign_wait_q); in nxp_serdev_probe()
1419 device_property_read_u32(&nxpdev->serdev->dev, "fw-init-baudrate", in nxp_serdev_probe()
1420 &nxpdev->fw_init_baudrate); in nxp_serdev_probe()
1421 if (!nxpdev->fw_init_baudrate) in nxp_serdev_probe()
1422 nxpdev->fw_init_baudrate = FW_INIT_BAUDRATE; in nxp_serdev_probe()
1424 set_bit(BTNXPUART_FW_DOWNLOADING, &nxpdev->tx_state); in nxp_serdev_probe()
1431 dev_err(&serdev->dev, "Can't allocate HCI device\n"); in nxp_serdev_probe()
1432 return -ENOMEM; in nxp_serdev_probe()
1435 nxpdev->hdev = hdev; in nxp_serdev_probe()
1437 hdev->bus = HCI_UART; in nxp_serdev_probe()
1440 hdev->manufacturer = MANUFACTURER_NXP; in nxp_serdev_probe()
1441 hdev->open = btnxpuart_open; in nxp_serdev_probe()
1442 hdev->close = btnxpuart_close; in nxp_serdev_probe()
1443 hdev->flush = btnxpuart_flush; in nxp_serdev_probe()
1444 hdev->setup = nxp_setup; in nxp_serdev_probe()
1445 hdev->send = nxp_enqueue; in nxp_serdev_probe()
1446 hdev->hw_error = nxp_hw_err; in nxp_serdev_probe()
1447 hdev->shutdown = nxp_shutdown; in nxp_serdev_probe()
1448 SET_HCIDEV_DEV(hdev, &serdev->dev); in nxp_serdev_probe()
1451 dev_err(&serdev->dev, "Can't register HCI device\n"); in nxp_serdev_probe()
1453 return -ENODEV; in nxp_serdev_probe()
1464 struct hci_dev *hdev = nxpdev->hdev; in nxp_serdev_remove()
1467 set_bit(BTNXPUART_FW_DOWNLOAD_ABORT, &nxpdev->tx_state); in nxp_serdev_remove()
1468 clear_bit(BTNXPUART_FW_DOWNLOADING, &nxpdev->tx_state); in nxp_serdev_remove()
1469 wake_up_interruptible(&nxpdev->check_boot_sign_wait_q); in nxp_serdev_remove()
1470 wake_up_interruptible(&nxpdev->fw_dnld_done_wait_q); in nxp_serdev_remove()
1472 /* Restore FW baudrate to fw_init_baudrate if changed. in nxp_serdev_remove()
1473 * This will ensure FW baudrate is in sync with in nxp_serdev_remove()
1474 * driver baudrate in case this driver is re-inserted. in nxp_serdev_remove()
1476 if (nxpdev->current_baudrate != nxpdev->fw_init_baudrate) { in nxp_serdev_remove()
1477 nxpdev->new_baudrate = nxpdev->fw_init_baudrate; in nxp_serdev_remove()
1497 { .compatible = "nxp,88w8987-bt", .data = &w8987_data },
1498 { .compatible = "nxp,88w8997-bt", .data = &w8997_data },