From: Roger Quadros <rogerq@kernel.org>
To: "Théo Lebrun" <theo.lebrun@bootlin.com>,
"Peter Chen" <peter.chen@kernel.org>,
"Pawel Laszczak" <pawell@cadence.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Mathias Nyman" <mathias.nyman@intel.com>
Cc: "Grégory Clement" <gregory.clement@bootlin.com>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 1/5] usb: cdns3-ti: move reg writes to separate function
Date: Thu, 12 Dec 2024 14:12:03 +0200 [thread overview]
Message-ID: <24a2c881-a322-4985-adb8-c424f08b3cd8@kernel.org> (raw)
In-Reply-To: <20241210-s2r-cdns-v6-1-28a17f9715a2@bootlin.com>
On 10/12/2024 19:13, Théo Lebrun wrote:
> The device probe function mixes management code and hardware
> initialisation code. Extract the latter into an explicitly named
> cdns_ti_reset_and_init_hw() function to clarify intent. It also will
> allow easier transition to using runtime PM for triggering HW init.
>
> Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
> ---
> drivers/usb/cdns3/cdns3-ti.c | 84 ++++++++++++++++++++++++--------------------
> 1 file changed, 46 insertions(+), 38 deletions(-)
>
> diff --git a/drivers/usb/cdns3/cdns3-ti.c b/drivers/usb/cdns3/cdns3-ti.c
> index 040bb91e9c017d8298a7e251fd0e192a336e8a52..d704eb39820ad08a8774be7f00aa473c3ff267c0 100644
> --- a/drivers/usb/cdns3/cdns3-ti.c
> +++ b/drivers/usb/cdns3/cdns3-ti.c
> @@ -58,6 +58,7 @@ struct cdns_ti {
> unsigned vbus_divider:1;
> struct clk *usb2_refclk;
> struct clk *lpm_clk;
> + int usb2_refclk_rate_code;
> };
>
> static const int cdns_ti_rate_table[] = { /* in KHZ */
> @@ -98,15 +99,52 @@ static const struct of_dev_auxdata cdns_ti_auxdata[] = {
> {},
> };
>
> +static void cdns_ti_reset_and_init_hw(struct cdns_ti *data)
> +{
> + u32 reg;
> +
> + /* assert RESET */
> + reg = cdns_ti_readl(data, USBSS_W1);
> + reg &= ~USBSS_W1_PWRUP_RST;
> + cdns_ti_writel(data, USBSS_W1, reg);
> +
> + /* set static config */
> + reg = cdns_ti_readl(data, USBSS_STATIC_CONFIG);
> + reg &= ~USBSS1_STATIC_PLL_REF_SEL_MASK;
> + reg |= data->usb2_refclk_rate_code << USBSS1_STATIC_PLL_REF_SEL_SHIFT;
> +
> + reg &= ~USBSS1_STATIC_VBUS_SEL_MASK;
> +
new line not required?
> + if (data->vbus_divider)
> + reg |= 1 << USBSS1_STATIC_VBUS_SEL_SHIFT;
> +
> + cdns_ti_writel(data, USBSS_STATIC_CONFIG, reg);
> + reg = cdns_ti_readl(data, USBSS_STATIC_CONFIG);
> +
> + /* set USB2_ONLY mode if requested */
> + reg = cdns_ti_readl(data, USBSS_W1);
> +
here too?
> + if (data->usb2_only)
> + reg |= USBSS_W1_USB2_ONLY;
> +
> + /* set default modestrap */
> + reg |= USBSS_W1_MODESTRAP_SEL;
> + reg &= ~USBSS_W1_MODESTRAP_MASK;
> + reg |= USBSS_MODESTRAP_MODE_NONE << USBSS_W1_MODESTRAP_SHIFT;
> + cdns_ti_writel(data, USBSS_W1, reg);
> +
> + /* de-assert RESET */
> + reg |= USBSS_W1_PWRUP_RST;
> + cdns_ti_writel(data, USBSS_W1, reg);
> +}
> +
> static int cdns_ti_probe(struct platform_device *pdev)
> {
> struct device *dev = &pdev->dev;
> struct device_node *node = pdev->dev.of_node;
> struct cdns_ti *data;
> - int error;
> - u32 reg;
> - int rate_code, i;
> unsigned long rate;
> + int error, i;
>
> data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
> if (!data)
> @@ -146,7 +184,11 @@ static int cdns_ti_probe(struct platform_device *pdev)
> return -EINVAL;
> }
>
> - rate_code = i;
> + data->usb2_refclk_rate_code = i;
> + data->vbus_divider = device_property_read_bool(dev, "ti,vbus-divider");
> + data->usb2_only = device_property_read_bool(dev, "ti,usb2-only");
> +
> + cdns_ti_reset_and_init_hw(data);
>
> pm_runtime_enable(dev);
> error = pm_runtime_get_sync(dev);
> @@ -155,40 +197,6 @@ static int cdns_ti_probe(struct platform_device *pdev)
> goto err;
> }
>
> - /* assert RESET */
> - reg = cdns_ti_readl(data, USBSS_W1);
> - reg &= ~USBSS_W1_PWRUP_RST;
> - cdns_ti_writel(data, USBSS_W1, reg);
> -
> - /* set static config */
> - reg = cdns_ti_readl(data, USBSS_STATIC_CONFIG);
> - reg &= ~USBSS1_STATIC_PLL_REF_SEL_MASK;
> - reg |= rate_code << USBSS1_STATIC_PLL_REF_SEL_SHIFT;
> -
> - reg &= ~USBSS1_STATIC_VBUS_SEL_MASK;
> - data->vbus_divider = device_property_read_bool(dev, "ti,vbus-divider");
> - if (data->vbus_divider)
> - reg |= 1 << USBSS1_STATIC_VBUS_SEL_SHIFT;
> -
> - cdns_ti_writel(data, USBSS_STATIC_CONFIG, reg);
> - reg = cdns_ti_readl(data, USBSS_STATIC_CONFIG);
> -
> - /* set USB2_ONLY mode if requested */
> - reg = cdns_ti_readl(data, USBSS_W1);
> - data->usb2_only = device_property_read_bool(dev, "ti,usb2-only");
> - if (data->usb2_only)
> - reg |= USBSS_W1_USB2_ONLY;
> -
> - /* set default modestrap */
> - reg |= USBSS_W1_MODESTRAP_SEL;
> - reg &= ~USBSS_W1_MODESTRAP_MASK;
> - reg |= USBSS_MODESTRAP_MODE_NONE << USBSS_W1_MODESTRAP_SHIFT;
> - cdns_ti_writel(data, USBSS_W1, reg);
> -
> - /* de-assert RESET */
> - reg |= USBSS_W1_PWRUP_RST;
> - cdns_ti_writel(data, USBSS_W1, reg);
> -
> error = of_platform_populate(node, NULL, cdns_ti_auxdata, dev);
> if (error) {
> dev_err(dev, "failed to create children: %d\n", error);
>
Reviewed-by: Roger Quadros <rogerq@kernel.org>
--
cheers,
-roger
next prev parent reply other threads:[~2024-12-12 12:12 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-10 17:13 [PATCH v6 0/5] Fix USB suspend on TI J7200 (cdns3-ti, cdns3, xhci) Théo Lebrun
2024-12-10 17:13 ` [PATCH v6 1/5] usb: cdns3-ti: move reg writes to separate function Théo Lebrun
2024-12-12 12:12 ` Roger Quadros [this message]
2024-12-10 17:13 ` [PATCH v6 2/5] usb: cdns3-ti: run HW init at resume() if HW was reset Théo Lebrun
2024-12-12 12:18 ` Roger Quadros
2024-12-13 15:28 ` Théo Lebrun
2024-12-17 21:13 ` Roger Quadros
2024-12-14 8:49 ` Peter Chen
2024-12-16 14:02 ` Théo Lebrun
2024-12-17 6:12 ` Peter Chen
2024-12-10 17:13 ` [PATCH v6 3/5] usb: cdns3: rename hibernated argument of role->resume() to lost_power Théo Lebrun
2024-12-14 8:51 ` Peter Chen
2024-12-10 17:13 ` [PATCH v6 4/5] xhci: introduce xhci->lost_power flag Théo Lebrun
2024-12-12 12:37 ` Roger Quadros
2024-12-13 16:03 ` Théo Lebrun
2024-12-17 21:00 ` Roger Quadros
2024-12-18 17:49 ` Théo Lebrun
2025-01-08 10:59 ` Théo Lebrun
2025-01-08 18:43 ` Mathias Nyman
2025-01-29 10:45 ` Théo Lebrun
2025-01-29 10:56 ` [PATCH 1/9] usb: host: xhci-plat: mvebu: use ->quirks instead of ->init_quirk() func Théo Lebrun
2025-01-29 10:56 ` [PATCH 2/9] usb: xhci: tegra: rename `runtime` boolean to `is_auto_runtime` Théo Lebrun
2025-01-29 10:56 ` [PATCH 3/9] usb: cdns3-ti: move reg writes to separate function Théo Lebrun
2025-01-29 10:56 ` [PATCH 4/9] usb: cdns3-ti: run HW init at resume() if HW was reset Théo Lebrun
2025-01-29 10:56 ` [PATCH 5/9] usb: cdns3: rename hibernated argument of role->resume() to lost_power Théo Lebrun
2025-01-29 10:56 ` [PATCH 6/9] usb: cdns3: call cdns_power_is_lost() only once in cdns_resume() Théo Lebrun
2025-01-29 10:56 ` [PATCH 7/9] usb: xhci: change xhci_resume() parameters to explicit the desired info Théo Lebrun
2025-01-29 10:56 ` [PATCH 8/9] usb: host: xhci-plat: allow upper layers to signal power loss Théo Lebrun
2025-01-29 10:56 ` [PATCH 9/9] usb: host: cdns3: forward lost power information to xhci Théo Lebrun
2024-12-10 17:13 ` [PATCH v6 5/5] usb: cdns3: host: transmit lost_power signal from wrapper to XHCI Théo Lebrun
2024-12-14 9:06 ` [PATCH v6 0/5] Fix USB suspend on TI J7200 (cdns3-ti, cdns3, xhci) Peter Chen
2024-12-16 14:09 ` Théo Lebrun
2024-12-17 6:17 ` Peter Chen
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=24a2c881-a322-4985-adb8-c424f08b3cd8@kernel.org \
--to=rogerq@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=gregory.clement@bootlin.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@intel.com \
--cc=pawell@cadence.com \
--cc=peter.chen@kernel.org \
--cc=theo.lebrun@bootlin.com \
--cc=thomas.petazzoni@bootlin.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