mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: alex.zhou@oss.nxp.com
Cc: linux-kernel@vger.kernel.org, linux-bluetooth@vger.kernel.org,
	 sherry.sun@nxp.com, marcel@holtmann.org, lgirdwood@gmail.com,
	 broonie@kernel.org, neeraj.sanjaykale@nxp.com,
	amitkumar.karwar@nxp.com,  song.xue_1@nxp.com, alex.zhou@nxp.com
Subject: Re: [PATCH v1] Bluetooth: btnxpuart: fix power sequencing and baudrate on reopen
Date: Fri, 4 Dec 2026 10:43:08 -0500	[thread overview]
Message-ID: <CABBYNZLSVNuBrDszWCkUiPWrC3nh_2F+acno03CaO2-1mraw4g@mail.gmail.com> (raw)
In-Reply-To: <20261201061237.1776685-1-alex.zhou@oss.nxp.com>

Hi Alex,

On Tue, Dec 1, 2026 at 1:12 AM <alex.zhou@oss.nxp.com> wrote:
>
> From: Alex Zhou <alex.zhou@nxp.com>
>
> Manage the optional vcc regulator on HCI open and close instead of
> keeping it enabled for the entire driver lifetime. Track the enable
> state to balance regulator references. Release any retained reference
> on removal.
>
> Separate reset control from regulator state and enable non-persistent
> setup when vcc is present so firmware setup runs again after power loss.
> Close the UART if regulator enable fails.
>
> After firmware download, initialize the UART and tracked baudrate to
> fw_init_baudrate. When firmware is already running, restore the tracked
> baudrate instead of unconditionally switching to fw_init_baudrate.
>
> Signed-off-by: Alex Zhou <alex.zhou@nxp.com>
> ---
>  drivers/bluetooth/btnxpuart.c | 78 ++++++++++++++++++++++++++++++-----
>  1 file changed, 68 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/bluetooth/btnxpuart.c b/drivers/bluetooth/btnxpuart.c
> index 5c730e336114..1d8e54229567 100644
> --- a/drivers/bluetooth/btnxpuart.c
> +++ b/drivers/bluetooth/btnxpuart.c
> @@ -210,12 +210,14 @@ struct btnxpuart_dev {
>         enum bootloader_param_change timeout_changed;
>         enum bootloader_param_change baudrate_changed;
>         bool helper_downloaded;
> +       bool supply_enabled;
>
>         struct ps_data psdata;
>         struct btnxpuart_data *nxp_data;
>         struct pwrseq_desc *pwrseq;
>         struct reset_control *pdn;
>         struct hci_uart hu;
> +       struct regulator *supply;
>  };
>
>  #define NXP_V1_FW_REQ_PKT      0xa5
> @@ -890,6 +892,40 @@ static bool fw_dump_in_progress(struct btnxpuart_dev *nxpdev)
>         return test_bit(BTNXPUART_FW_DUMP_IN_PROGRESS, &nxpdev->tx_state);
>  }
>
> +static int btnxpuart_disable_supply(struct btnxpuart_dev *nxpdev)
> +{
> +       int err;
> +
> +       if (!nxpdev->supply || !nxpdev->supply_enabled)
> +               return 0;
> +
> +       err = regulator_disable(nxpdev->supply);
> +       if (err)
> +               bt_dev_err(nxpdev->hdev,
> +                          "Failed to disable vcc regulator: %d", err);
> +       else
> +               nxpdev->supply_enabled = false;
> +
> +       return err;
> +}
> +
> +static int btnxpuart_enable_supply(struct btnxpuart_dev *nxpdev)
> +{
> +       int err;
> +
> +       if (!nxpdev->supply || nxpdev->supply_enabled)
> +               return 0;
> +
> +       err = regulator_enable(nxpdev->supply);
> +       if (err)
> +               bt_dev_err(nxpdev->hdev,
> +                          "Failed to enable vcc regulator: %d", err);
> +       else
> +               nxpdev->supply_enabled = true;
> +
> +       return err;
> +}
> +
>  static bool process_boot_signature(struct btnxpuart_dev *nxpdev)
>  {
>         if (test_bit(BTNXPUART_CHECK_BOOT_SIGNATURE, &nxpdev->tx_state)) {
> @@ -1458,9 +1494,12 @@ static int nxp_setup(struct hci_dev *hdev)
>                 err = nxp_download_firmware(hdev);
>                 if (err < 0)
>                         return err;
> +               serdev_device_set_baudrate(nxpdev->serdev, nxpdev->fw_init_baudrate);
> +               nxpdev->current_baudrate = nxpdev->fw_init_baudrate;
>         } else {
>                 bt_dev_info(hdev, "FW already running.");
>                 clear_bit(BTNXPUART_FW_DOWNLOADING, &nxpdev->tx_state);
> +               serdev_device_set_baudrate(nxpdev->serdev, nxpdev->current_baudrate);
>         }
>
>         snprintf(device_string, 30, "BTNXPUART_DEV=%s", dev_name(&serdev->dev));
> @@ -1469,9 +1508,6 @@ static int nxp_setup(struct hci_dev *hdev)
>                    event_string);
>         kobject_uevent_env(&serdev->dev.kobj, KOBJ_CHANGE, envp);
>
> -       serdev_device_set_baudrate(nxpdev->serdev, nxpdev->fw_init_baudrate);
> -       nxpdev->current_baudrate = nxpdev->fw_init_baudrate;
> -
>         ps_init(hdev);
>
>         if (test_and_clear_bit(BTNXPUART_IR_IN_PROGRESS, &nxpdev->tx_state))
> @@ -1707,9 +1743,24 @@ static int btnxpuart_open(struct hci_dev *hdev)
>         if (err) {
>                 bt_dev_err(hdev, "Unable to open UART device %s",
>                            dev_name(&nxpdev->serdev->dev));
> -       } else {
> -               set_bit(BTNXPUART_SERDEV_OPEN, &nxpdev->tx_state);
> +               return err;
>         }
> +       set_bit(BTNXPUART_SERDEV_OPEN, &nxpdev->tx_state);
> +
> +       if (hci_test_quirk(hdev, HCI_QUIRK_NON_PERSISTENT_SETUP)) {
> +               clear_bit(BTNXPUART_FW_DOWNLOAD_ABORT, &nxpdev->tx_state);
> +               set_bit(BTNXPUART_FW_DOWNLOADING, &nxpdev->tx_state);
> +       }
> +
> +       err = btnxpuart_enable_supply(nxpdev);
> +       if (err)
> +               goto close_serdev;
> +
> +       return 0;
> +
> +close_serdev:
> +       clear_bit(BTNXPUART_SERDEV_OPEN, &nxpdev->tx_state);
> +       serdev_device_close(nxpdev->serdev);
>         return err;
>  }
>
> @@ -1724,7 +1775,7 @@ static int btnxpuart_close(struct hci_dev *hdev)
>                 nxpdev->rx_skb = NULL;
>         }
>         clear_bit(BTNXPUART_SERDEV_OPEN, &nxpdev->tx_state);
> -       return 0;
> +       return btnxpuart_disable_supply(nxpdev);
>  }
>
>  static int btnxpuart_flush(struct hci_dev *hdev)
> @@ -1888,10 +1939,13 @@ static int nxp_serdev_probe(struct serdev_device *serdev)
>         if (IS_ERR(nxpdev->pdn))
>                 return PTR_ERR(nxpdev->pdn);
>
> -       err = devm_regulator_get_enable(&serdev->dev, "vcc");
> -       if (err) {
> -               dev_err(&serdev->dev, "Failed to enable vcc regulator\n");
> -               return err;
> +       nxpdev->supply = devm_regulator_get_optional(&serdev->dev, "vcc");
> +       if (IS_ERR(nxpdev->supply)) {
> +               err = PTR_ERR(nxpdev->supply);
> +               if (err != -ENODEV)
> +                       return dev_err_probe(&serdev->dev, err,
> +                                            "Failed to get vcc regulator\n");
> +               nxpdev->supply = NULL;
>         }
>
>         if (nxp_m2_connector_is_available(&serdev->ctrl->dev)) {
> @@ -1944,6 +1998,9 @@ static int nxp_serdev_probe(struct serdev_device *serdev)
>         if (bacmp(&ba, BDADDR_ANY))
>                 hci_set_quirk(hdev, HCI_QUIRK_USE_BDADDR_PROPERTY);
>
> +       if (nxpdev->supply)
> +               hci_set_quirk(hdev, HCI_QUIRK_NON_PERSISTENT_SETUP);
> +
>         err = hci_register_dev(hdev);
>         if (err < 0) {
>                 dev_err(&serdev->dev, "Can't register HCI device\n");
> @@ -1993,6 +2050,7 @@ static void nxp_serdev_remove(struct serdev_device *serdev)
>         }
>
>         ps_cleanup(nxpdev);
> +       btnxpuart_disable_supply(nxpdev);
>         hci_unregister_dev(hdev);
>         reset_control_assert(nxpdev->pdn);
>         if (nxpdev->pwrseq)
> --
> 2.34.1

Sashiko flagged a couple of problems with these changes:

https://sashiko.dev/#/patchset/20261201061237.1776685-1-alex.zhou%40oss.nxp.com

-- 
Luiz Augusto von Dentz

      reply	other threads:[~2026-12-04 15:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  6:12 alex.zhou
2026-12-04 15:43 ` Luiz Augusto von Dentz [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CABBYNZLSVNuBrDszWCkUiPWrC3nh_2F+acno03CaO2-1mraw4g@mail.gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=alex.zhou@nxp.com \
    --cc=alex.zhou@oss.nxp.com \
    --cc=amitkumar.karwar@nxp.com \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcel@holtmann.org \
    --cc=neeraj.sanjaykale@nxp.com \
    --cc=sherry.sun@nxp.com \
    --cc=song.xue_1@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®