Skip to content

Commit 6fca678

Browse files
NeerajSanjayKaleVudentz
authored andcommitted
Bluetooth: btnxpuart: Move vendor specific initialization to .post_init
This moves change baudrate and power save vendor commands from nxp_setup() to nxp_post_init(). This also moves the baudrate restore logic from nxp_serdev_remove() to nxp_shutdown() which ensure baudrate is restored even when HCI dev is down, preventing baudrate mismatch between host and controller when device is probed again next time. In case of removal when the hdev is up and running, we have to call the shutdown procedure explicitly before unregistering the hdev. Signed-off-by: Neeraj Sanjay Kale <neeraj.sanjaykale@nxp.com> Co-developed-by: Loic Poulain <loic.poulain@linaro.org> Signed-off-by: Loic Poulain <loic.poulain@linaro.org> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
1 parent 07e6bdd commit 6fca678

1 file changed

Lines changed: 27 additions & 18 deletions

File tree

drivers/bluetooth/btnxpuart.c

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -630,11 +630,6 @@ static void ps_init(struct hci_dev *hdev)
630630

631631
psdata->cur_psmode = PS_MODE_DISABLE;
632632
psdata->target_ps_mode = DEFAULT_PS_MODE;
633-
634-
if (psdata->cur_h2c_wakeupmode != psdata->h2c_wakeupmode)
635-
hci_cmd_sync_queue(hdev, send_wakeup_method_cmd, NULL, NULL);
636-
if (psdata->cur_psmode != psdata->target_ps_mode)
637-
hci_cmd_sync_queue(hdev, send_ps_cmd, NULL, NULL);
638633
}
639634

640635
/* NXP Firmware Download Feature */
@@ -1228,11 +1223,6 @@ static int nxp_setup(struct hci_dev *hdev)
12281223
serdev_device_set_baudrate(nxpdev->serdev, nxpdev->fw_init_baudrate);
12291224
nxpdev->current_baudrate = nxpdev->fw_init_baudrate;
12301225

1231-
if (nxpdev->current_baudrate != HCI_NXP_SEC_BAUDRATE) {
1232-
nxpdev->new_baudrate = HCI_NXP_SEC_BAUDRATE;
1233-
hci_cmd_sync_queue(hdev, nxp_set_baudrate_cmd, NULL, NULL);
1234-
}
1235-
12361226
ps_init(hdev);
12371227

12381228
if (test_and_clear_bit(BTNXPUART_IR_IN_PROGRESS, &nxpdev->tx_state))
@@ -1241,6 +1231,22 @@ static int nxp_setup(struct hci_dev *hdev)
12411231
return 0;
12421232
}
12431233

1234+
static int nxp_post_init(struct hci_dev *hdev)
1235+
{
1236+
struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev);
1237+
struct ps_data *psdata = &nxpdev->psdata;
1238+
1239+
if (nxpdev->current_baudrate != HCI_NXP_SEC_BAUDRATE) {
1240+
nxpdev->new_baudrate = HCI_NXP_SEC_BAUDRATE;
1241+
nxp_set_baudrate_cmd(hdev, NULL);
1242+
}
1243+
if (psdata->cur_h2c_wakeupmode != psdata->h2c_wakeupmode)
1244+
send_wakeup_method_cmd(hdev, NULL);
1245+
if (psdata->cur_psmode != psdata->target_ps_mode)
1246+
send_ps_cmd(hdev, NULL);
1247+
return 0;
1248+
}
1249+
12441250
static void nxp_hw_err(struct hci_dev *hdev, u8 code)
12451251
{
12461252
struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev);
@@ -1273,6 +1279,9 @@ static int nxp_shutdown(struct hci_dev *hdev)
12731279
set_bit(BTNXPUART_FW_DOWNLOADING, &nxpdev->tx_state);
12741280
}
12751281
kfree_skb(skb);
1282+
} else if (nxpdev->current_baudrate != nxpdev->fw_init_baudrate) {
1283+
nxpdev->new_baudrate = nxpdev->fw_init_baudrate;
1284+
nxp_set_baudrate_cmd(hdev, NULL);
12761285
}
12771286

12781287
return 0;
@@ -1566,6 +1575,7 @@ static int nxp_serdev_probe(struct serdev_device *serdev)
15661575
hdev->close = btnxpuart_close;
15671576
hdev->flush = btnxpuart_flush;
15681577
hdev->setup = nxp_setup;
1578+
hdev->post_init = nxp_post_init;
15691579
hdev->send = nxp_enqueue;
15701580
hdev->hw_error = nxp_hw_err;
15711581
hdev->shutdown = nxp_shutdown;
@@ -1597,16 +1607,15 @@ static void nxp_serdev_remove(struct serdev_device *serdev)
15971607
clear_bit(BTNXPUART_FW_DOWNLOADING, &nxpdev->tx_state);
15981608
wake_up_interruptible(&nxpdev->check_boot_sign_wait_q);
15991609
wake_up_interruptible(&nxpdev->fw_dnld_done_wait_q);
1600-
} else {
1601-
/* Restore FW baudrate to fw_init_baudrate if changed.
1602-
* This will ensure FW baudrate is in sync with
1603-
* driver baudrate in case this driver is re-inserted.
1610+
}
1611+
1612+
if (test_bit(HCI_RUNNING, &hdev->flags)) {
1613+
/* Ensure shutdown callback is executed before unregistering, so
1614+
* that baudrate is reset to initial value.
16041615
*/
1605-
if (nxpdev->current_baudrate != nxpdev->fw_init_baudrate) {
1606-
nxpdev->new_baudrate = nxpdev->fw_init_baudrate;
1607-
nxp_set_baudrate_cmd(hdev, NULL);
1608-
}
1616+
nxp_shutdown(hdev);
16091617
}
1618+
16101619
ps_cleanup(nxpdev);
16111620
hci_unregister_dev(hdev);
16121621
hci_free_dev(hdev);

0 commit comments

Comments
 (0)