From: Krzysztof Kozlowski <krzk@kernel.org>
To: hpchen0 <hpchen0nvt@gmail.com>,
vkoul@kernel.org, kishon@kernel.org, robh@kernel.org,
krzk+dt@kernel.org, conor+dt@kernel.org
Cc: linux-arm-kernel@lists.infradead.org,
linux-phy@lists.infradead.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] phy: nuvoton: add new driver for the Nuvoton MA35 SoC USB 2.0 PHY
Date: Mon, 29 Jul 2024 09:32:45 +0200 [thread overview]
Message-ID: <7ce7f373-c738-48c7-835e-6e7d10e8ae20@kernel.org> (raw)
In-Reply-To: <20240729061509.83828-3-hpchen0nvt@gmail.com>
On 29/07/2024 08:15, hpchen0 wrote:
> Nuvoton MA35 SoCs support DWC2 USB controller.
> Add the driver to drive the USB 2.0 PHY transceivers.
>
> Signed-off-by: hpchen0 <hpchen0nvt@gmail.com>
> +
> + ret = clk_prepare_enable(p_phy->clk);
> + if (ret < 0) {
> + dev_err(p_phy->dev, "Failed to enable PHY clock: %d\n", ret);
> + return ret;
> + }
> +
> + regmap_read(p_phy->sysreg, MA35_SYS_REG_USBPMISCR, &val);
> + if (val & PHY0SUSPEND) {
> + /*
> + * USB PHY0 is in operation mode already
> + * make sure USB PHY 60 MHz UTMI Interface Clock ready
> + */
> + timeout = jiffies + msecs_to_jiffies(200);
> + while (time_before(jiffies, timeout)) {
> + regmap_read(p_phy->sysreg, MA35_SYS_REG_USBPMISCR, &val);
> + if (val & PHY0DEVCKSTB)
> + return 0;
> + usleep_range(1000, 1500);
> + }
You want some readl_poll_timeout version here.
> + }
> +
> + /*
> + * reset USB PHY0.
> + * wait until USB PHY0 60 MHz UTMI Interface Clock ready
> + */
> + regmap_update_bits(p_phy->sysreg, MA35_SYS_REG_USBPMISCR, 0x7, (PHY0POR | PHY0SUSPEND));
> + timeout = jiffies + msecs_to_jiffies(200);
> + while (time_before(jiffies, timeout)) {
> + regmap_read(p_phy->sysreg, MA35_SYS_REG_USBPMISCR, &val);
> + if (val & PHY0DEVCKSTB)
> + break;
> + usleep_range(1000, 1500);
> + }
> +
> + /* make USB PHY0 enter operation mode */
> + regmap_update_bits(p_phy->sysreg, MA35_SYS_REG_USBPMISCR, 0x7, PHY0SUSPEND);
> +
> + /* make sure USB PHY 60 MHz UTMI Interface Clock ready */
> + timeout = jiffies + msecs_to_jiffies(200);
> + while (time_before(jiffies, timeout)) {
> + regmap_read(p_phy->sysreg, MA35_SYS_REG_USBPMISCR, &val);
> + if (val & PHY0DEVCKSTB)
> + return 0;
> + usleep_range(1000, 1500);
> + }
> +
> + dev_err(p_phy->dev, "Timed out waiting for PHY to power on\n");
> + ret = -ETIMEDOUT;
> +
> + clk_disable_unprepare(p_phy->clk);
> + return ret;
> +}
> +
> +static int ma35_usb_phy_power_off(struct phy *phy)
> +{
> + struct ma35_usb_phy *p_phy = phy_get_drvdata(phy);
> +
> + clk_disable_unprepare(p_phy->clk);
> + return 0;
> +}
> +
> +static const struct phy_ops ma35_usb_phy_ops = {
> + .power_on = ma35_usb_phy_power_on,
> + .power_off = ma35_usb_phy_power_off,
> + .owner = THIS_MODULE,
> +};
> +
> +static int ma35_usb_phy_probe(struct platform_device *pdev)
> +{
> + struct phy_provider *provider;
> + struct ma35_usb_phy *p_phy;
> + const char *clkgate;
> + struct phy *phy;
> +
> + p_phy = devm_kzalloc(&pdev->dev, sizeof(*p_phy), GFP_KERNEL);
> + if (!p_phy)
> + return -ENOMEM;
> +
> + p_phy->dev = &pdev->dev;
> + platform_set_drvdata(pdev, p_phy);
> +
> + p_phy->sysreg = syscon_regmap_lookup_by_phandle(p_phy->dev->of_node, "nuvoton,sys");
> + if (IS_ERR(p_phy->sysreg))
> + return dev_err_probe(&pdev->dev, PTR_ERR(p_phy->sysreg),
> + "Failed to get SYS registers\n");
> +
> + /* enable clock */
> + of_property_read_string(p_phy->dev->of_node, "clock-enable", &clkgate);
There is no such property.
> + p_phy->clk = devm_clk_get(p_phy->dev, clkgate);
Don't mix styles of variables: you were using pdev->dev but now entirely
different. Stick to pdev->dev.
> + if (IS_ERR(p_phy->clk))
> + return dev_err_probe(&pdev->dev, PTR_ERR(p_phy->clk),
And here again pdev->dev... Bring some consistency, not random coding style.
> + "Failed to get usb_phy clock\n");
> +
Best regards,
Krzysztof
next prev parent reply other threads:[~2024-07-29 7:32 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-29 6:15 [PATCH 0/2] Add support for nuvoton ma35 usb2 phy hpchen0
2024-07-29 6:15 ` [PATCH 1/2] dt-bindings: phy: nuvoton,ma35-usb2-phy: add new bindings hpchen0
2024-07-29 7:29 ` Krzysztof Kozlowski
2024-07-30 7:44 ` Hui-Ping Chen
2024-07-30 8:10 ` Krzysztof Kozlowski
2024-07-30 8:25 ` Hui-Ping Chen
2024-07-30 8:03 ` Hui-Ping Chen
2024-07-29 6:15 ` [PATCH 2/2] phy: nuvoton: add new driver for the Nuvoton MA35 SoC USB 2.0 PHY hpchen0
2024-07-29 7:32 ` Krzysztof Kozlowski [this message]
2024-07-30 8:05 ` Hui-Ping 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=7ce7f373-c738-48c7-835e-6e7d10e8ae20@kernel.org \
--to=krzk@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=hpchen0nvt@gmail.com \
--cc=kishon@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=robh@kernel.org \
--cc=vkoul@kernel.org \
/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®