* [PATCH v3 0/2] Add support for nuvoton ma35 usb2 phy
@ 2024-08-01 5:37 ` Hui-Ping Chen
0 siblings, 0 replies; 16+ messages in thread
From: Hui-Ping Chen @ 2024-08-01 5:37 UTC (permalink / raw)
To: vkoul, kishon, robh, krzk+dt, conor+dt
Cc: linux-arm-kernel, linux-phy, devicetree, linux-kernel,
Hui-Ping Chen
This patch series adds the usb2 phy driver for the nuvoton ma35 ARMv8 SoC.
It includes DT binding documentation and the ma35 usb2 phy driver.
v3:
- Update nuvoton,ma35d1-usb2-phy.yaml
- Update the syscon usage description.
v2:
- Update nuvoton,ma35d1-usb2-phy.yaml
- Update the 'nuvoton,ma35-usb2-phy' to 'nuvoton,ma35d1-usb2-phy'.
- Remove unnecessary descriptions.
- Add explanations related to SYS.
- Update ma35d1 usb2 phy driver
- Update the 'nuvoton,ma35-usb2-phy' to 'nuvoton,ma35d1-usb2-phy'.
- Use readl_poll_timeout() to make the system more efficient and the
code more streamlined.
- Use the same variable name. Update the 'p_phy->dev' to 'pdev->dev'.
Hui-Ping Chen (2):
dt-bindings: phy: nuvoton,ma35-usb2-phy: add new bindings
phy: nuvoton: add new driver for the Nuvoton MA35 SoC USB 2.0 PHY
.../bindings/phy/nuvoton,ma35d1-usb2-phy.yaml | 45 ++++++
drivers/phy/Kconfig | 1 +
drivers/phy/Makefile | 1 +
drivers/phy/nuvoton/Kconfig | 13 ++
drivers/phy/nuvoton/Makefile | 3 +
drivers/phy/nuvoton/phy-ma35d1-usb2.c | 146 ++++++++++++++++++
6 files changed, 209 insertions(+)
create mode 100644 Documentation/devicetree/bindings/phy/nuvoton,ma35d1-usb2-phy.yaml
create mode 100644 drivers/phy/nuvoton/Kconfig
create mode 100644 drivers/phy/nuvoton/Makefile
create mode 100644 drivers/phy/nuvoton/phy-ma35d1-usb2.c
--
2.25.1
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
^ permalink raw reply [flat|nested] 16+ messages in thread* [PATCH v3 0/2] Add support for nuvoton ma35 usb2 phy @ 2024-08-01 5:37 ` Hui-Ping Chen 0 siblings, 0 replies; 16+ messages in thread From: Hui-Ping Chen @ 2024-08-01 5:37 UTC (permalink / raw) To: vkoul, kishon, robh, krzk+dt, conor+dt Cc: linux-arm-kernel, linux-phy, devicetree, linux-kernel, Hui-Ping Chen This patch series adds the usb2 phy driver for the nuvoton ma35 ARMv8 SoC. It includes DT binding documentation and the ma35 usb2 phy driver. v3: - Update nuvoton,ma35d1-usb2-phy.yaml - Update the syscon usage description. v2: - Update nuvoton,ma35d1-usb2-phy.yaml - Update the 'nuvoton,ma35-usb2-phy' to 'nuvoton,ma35d1-usb2-phy'. - Remove unnecessary descriptions. - Add explanations related to SYS. - Update ma35d1 usb2 phy driver - Update the 'nuvoton,ma35-usb2-phy' to 'nuvoton,ma35d1-usb2-phy'. - Use readl_poll_timeout() to make the system more efficient and the code more streamlined. - Use the same variable name. Update the 'p_phy->dev' to 'pdev->dev'. Hui-Ping Chen (2): dt-bindings: phy: nuvoton,ma35-usb2-phy: add new bindings phy: nuvoton: add new driver for the Nuvoton MA35 SoC USB 2.0 PHY .../bindings/phy/nuvoton,ma35d1-usb2-phy.yaml | 45 ++++++ drivers/phy/Kconfig | 1 + drivers/phy/Makefile | 1 + drivers/phy/nuvoton/Kconfig | 13 ++ drivers/phy/nuvoton/Makefile | 3 + drivers/phy/nuvoton/phy-ma35d1-usb2.c | 146 ++++++++++++++++++ 6 files changed, 209 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/nuvoton,ma35d1-usb2-phy.yaml create mode 100644 drivers/phy/nuvoton/Kconfig create mode 100644 drivers/phy/nuvoton/Makefile create mode 100644 drivers/phy/nuvoton/phy-ma35d1-usb2.c -- 2.25.1 ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v3 1/2] dt-bindings: phy: nuvoton,ma35-usb2-phy: add new bindings 2024-08-01 5:37 ` Hui-Ping Chen @ 2024-08-01 5:37 ` Hui-Ping Chen -1 siblings, 0 replies; 16+ messages in thread From: Hui-Ping Chen @ 2024-08-01 5:37 UTC (permalink / raw) To: vkoul, kishon, robh, krzk+dt, conor+dt Cc: linux-arm-kernel, linux-phy, devicetree, linux-kernel, Hui-Ping Chen Add dt-bindings for USB2 PHY found on the Nuvoton MA35 SoC. Signed-off-by: Hui-Ping Chen <hpchen0nvt@gmail.com> --- .../bindings/phy/nuvoton,ma35d1-usb2-phy.yaml | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/nuvoton,ma35d1-usb2-phy.yaml diff --git a/Documentation/devicetree/bindings/phy/nuvoton,ma35d1-usb2-phy.yaml b/Documentation/devicetree/bindings/phy/nuvoton,ma35d1-usb2-phy.yaml new file mode 100644 index 000000000000..fff858c909a0 --- /dev/null +++ b/Documentation/devicetree/bindings/phy/nuvoton,ma35d1-usb2-phy.yaml @@ -0,0 +1,45 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/phy/nuvoton,ma35d1-usb2-phy.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Nuvoton MA35D1 USB2 phy + +maintainers: + - Hui-Ping Chen <hpchen0nvt@gmail.com> + +properties: + compatible: + enum: + - nuvoton,ma35d1-usb2-phy + + "#phy-cells": + const: 0 + + clocks: + maxItems: 1 + + nuvoton,sys: + $ref: /schemas/types.yaml#/definitions/phandle + description: + phandle to syscon for checking the PHY clock status. + +required: + - compatible + - "#phy-cells" + - clocks + - nuvoton,sys + +additionalProperties: false + +examples: + - | + #include <dt-bindings/clock/nuvoton,ma35d1-clk.h> + + usb_phy: usb-phy { + compatible = "nuvoton,ma35d1-usb2-phy"; + clocks = <&clk USBD_GATE>; + nuvoton,sys = <&sys>; + #phy-cells = <0>; + }; -- 2.25.1 -- linux-phy mailing list linux-phy@lists.infradead.org https://lists.infradead.org/mailman/listinfo/linux-phy ^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v3 1/2] dt-bindings: phy: nuvoton,ma35-usb2-phy: add new bindings @ 2024-08-01 5:37 ` Hui-Ping Chen 0 siblings, 0 replies; 16+ messages in thread From: Hui-Ping Chen @ 2024-08-01 5:37 UTC (permalink / raw) To: vkoul, kishon, robh, krzk+dt, conor+dt Cc: linux-arm-kernel, linux-phy, devicetree, linux-kernel, Hui-Ping Chen Add dt-bindings for USB2 PHY found on the Nuvoton MA35 SoC. Signed-off-by: Hui-Ping Chen <hpchen0nvt@gmail.com> --- .../bindings/phy/nuvoton,ma35d1-usb2-phy.yaml | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/nuvoton,ma35d1-usb2-phy.yaml diff --git a/Documentation/devicetree/bindings/phy/nuvoton,ma35d1-usb2-phy.yaml b/Documentation/devicetree/bindings/phy/nuvoton,ma35d1-usb2-phy.yaml new file mode 100644 index 000000000000..fff858c909a0 --- /dev/null +++ b/Documentation/devicetree/bindings/phy/nuvoton,ma35d1-usb2-phy.yaml @@ -0,0 +1,45 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/phy/nuvoton,ma35d1-usb2-phy.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Nuvoton MA35D1 USB2 phy + +maintainers: + - Hui-Ping Chen <hpchen0nvt@gmail.com> + +properties: + compatible: + enum: + - nuvoton,ma35d1-usb2-phy + + "#phy-cells": + const: 0 + + clocks: + maxItems: 1 + + nuvoton,sys: + $ref: /schemas/types.yaml#/definitions/phandle + description: + phandle to syscon for checking the PHY clock status. + +required: + - compatible + - "#phy-cells" + - clocks + - nuvoton,sys + +additionalProperties: false + +examples: + - | + #include <dt-bindings/clock/nuvoton,ma35d1-clk.h> + + usb_phy: usb-phy { + compatible = "nuvoton,ma35d1-usb2-phy"; + clocks = <&clk USBD_GATE>; + nuvoton,sys = <&sys>; + #phy-cells = <0>; + }; -- 2.25.1 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH v3 1/2] dt-bindings: phy: nuvoton,ma35-usb2-phy: add new bindings 2024-08-01 5:37 ` Hui-Ping Chen @ 2024-08-01 14:40 ` Krzysztof Kozlowski -1 siblings, 0 replies; 16+ messages in thread From: Krzysztof Kozlowski @ 2024-08-01 14:40 UTC (permalink / raw) To: Hui-Ping Chen, vkoul, kishon, robh, krzk+dt, conor+dt Cc: linux-arm-kernel, linux-phy, devicetree, linux-kernel On 01/08/2024 07:37, Hui-Ping Chen wrote: > Add dt-bindings for USB2 PHY found on the Nuvoton MA35 SoC. > > Signed-off-by: Hui-Ping Chen <hpchen0nvt@gmail.com> > --- Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Best regards, Krzysztof -- linux-phy mailing list linux-phy@lists.infradead.org https://lists.infradead.org/mailman/listinfo/linux-phy ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v3 1/2] dt-bindings: phy: nuvoton,ma35-usb2-phy: add new bindings @ 2024-08-01 14:40 ` Krzysztof Kozlowski 0 siblings, 0 replies; 16+ messages in thread From: Krzysztof Kozlowski @ 2024-08-01 14:40 UTC (permalink / raw) To: Hui-Ping Chen, vkoul, kishon, robh, krzk+dt, conor+dt Cc: linux-arm-kernel, linux-phy, devicetree, linux-kernel On 01/08/2024 07:37, Hui-Ping Chen wrote: > Add dt-bindings for USB2 PHY found on the Nuvoton MA35 SoC. > > Signed-off-by: Hui-Ping Chen <hpchen0nvt@gmail.com> > --- Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Best regards, Krzysztof ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v3 2/2] phy: nuvoton: add new driver for the Nuvoton MA35 SoC USB 2.0 PHY 2024-08-01 5:37 ` Hui-Ping Chen @ 2024-08-01 5:37 ` Hui-Ping Chen -1 siblings, 0 replies; 16+ messages in thread From: Hui-Ping Chen @ 2024-08-01 5:37 UTC (permalink / raw) To: vkoul, kishon, robh, krzk+dt, conor+dt Cc: linux-arm-kernel, linux-phy, devicetree, linux-kernel, Hui-Ping Chen Nuvoton MA35 SoCs support DWC2 USB controller. Add the driver to drive the USB 2.0 PHY transceivers. Signed-off-by: Hui-Ping Chen <hpchen0nvt@gmail.com> --- drivers/phy/Kconfig | 1 + drivers/phy/Makefile | 1 + drivers/phy/nuvoton/Kconfig | 13 +++ drivers/phy/nuvoton/Makefile | 3 + drivers/phy/nuvoton/phy-ma35d1-usb2.c | 146 ++++++++++++++++++++++++++ 5 files changed, 164 insertions(+) create mode 100644 drivers/phy/nuvoton/Kconfig create mode 100644 drivers/phy/nuvoton/Makefile create mode 100644 drivers/phy/nuvoton/phy-ma35d1-usb2.c diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig index dfab1c66b3e5..f73abff416be 100644 --- a/drivers/phy/Kconfig +++ b/drivers/phy/Kconfig @@ -95,6 +95,7 @@ source "drivers/phy/mediatek/Kconfig" source "drivers/phy/microchip/Kconfig" source "drivers/phy/motorola/Kconfig" source "drivers/phy/mscc/Kconfig" +source "drivers/phy/nuvoton/Kconfig" source "drivers/phy/qualcomm/Kconfig" source "drivers/phy/ralink/Kconfig" source "drivers/phy/realtek/Kconfig" diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile index 5fcbce5f9ab1..ebc399560da4 100644 --- a/drivers/phy/Makefile +++ b/drivers/phy/Makefile @@ -25,6 +25,7 @@ obj-y += allwinner/ \ microchip/ \ motorola/ \ mscc/ \ + nuvoton/ \ qualcomm/ \ ralink/ \ realtek/ \ diff --git a/drivers/phy/nuvoton/Kconfig b/drivers/phy/nuvoton/Kconfig new file mode 100644 index 000000000000..270ee2943287 --- /dev/null +++ b/drivers/phy/nuvoton/Kconfig @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# PHY drivers for Nuvoton MA35 platforms +# +config PHY_MA35_USB + tristate "Nuvoton MA35 USB2.0 PHY driver" + depends on ARCH_MA35 || COMPILE_TEST + depends on OF + select GENERIC_PHY + help + Enable this to support the USB2.0 PHY on the Nuvoton MA35 + series SoCs. + diff --git a/drivers/phy/nuvoton/Makefile b/drivers/phy/nuvoton/Makefile new file mode 100644 index 000000000000..2937e3921898 --- /dev/null +++ b/drivers/phy/nuvoton/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_PHY_MA35_USB) += phy-ma35d1-usb2.o diff --git a/drivers/phy/nuvoton/phy-ma35d1-usb2.c b/drivers/phy/nuvoton/phy-ma35d1-usb2.c new file mode 100644 index 000000000000..8922e5da8e3b --- /dev/null +++ b/drivers/phy/nuvoton/phy-ma35d1-usb2.c @@ -0,0 +1,146 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2024 Nuvoton Technology Corp. + */ +#include <linux/bitfield.h> +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/mfd/syscon.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/phy/phy.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> + +/* USB PHY Miscellaneous Control Register */ +#define MA35_SYS_REG_USBPMISCR 0x60 +#define PHY0POR BIT(0) /* PHY Power-On Reset Control Bit */ +#define PHY0SUSPEND BIT(1) /* PHY Suspend; 0: suspend, 1: operaion */ +#define PHY0COMN BIT(2) /* PHY Common Block Power-Down Control */ +#define PHY0DEVCKSTB BIT(10) /* PHY 60 MHz UTMI clock stable bit */ + +struct ma35_usb_phy { + struct clk *clk; + struct device *dev; + struct regmap *sysreg; +}; + +static int ma35_usb_phy_power_on(struct phy *phy) +{ + struct ma35_usb_phy *p_phy = phy_get_drvdata(phy); + unsigned int val; + int ret; + + 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 + */ + ret = readl_poll_timeout((void __iomem *)p_phy->sysreg + MA35_SYS_REG_USBPMISCR, + val, val & PHY0DEVCKSTB, 1, 100); + if (ret == -ETIMEDOUT) { + dev_err(p_phy->dev, "1.Check PHY clock, Timeout: %d\n", val); + return ret; + } + return 0; + } + + /* + * 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)); + udelay(10); + + /* 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 */ + ret = readl_poll_timeout((void __iomem *)p_phy->sysreg + MA35_SYS_REG_USBPMISCR, + val, val & PHY0DEVCKSTB, 1, 100); + if (ret == -ETIMEDOUT) { + dev_err(p_phy->dev, "2.Check PHY clock, Timeout: %d\n", ret); + return ret; + } + + clk_disable_unprepare(p_phy->clk); + return 0; +} + +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; + 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(pdev->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"); + + p_phy->clk = of_clk_get(pdev->dev.of_node, 0); + if (IS_ERR(p_phy->clk)) + return dev_err_probe(&pdev->dev, PTR_ERR(p_phy->clk), + "failed to find usb_phy clock\n"); + + phy = devm_phy_create(&pdev->dev, NULL, &ma35_usb_phy_ops); + if (IS_ERR(phy)) + return dev_err_probe(&pdev->dev, PTR_ERR(phy), "Failed to create PHY\n"); + + phy_set_drvdata(phy, p_phy); + + provider = devm_of_phy_provider_register(&pdev->dev, of_phy_simple_xlate); + if (IS_ERR(provider)) + return dev_err_probe(&pdev->dev, PTR_ERR(provider), + "Failed to register PHY provider\n"); + return 0; +} + +static const struct of_device_id ma35_usb_phy_of_match[] = { + { .compatible = "nuvoton,ma35d1-usb2-phy", }, + { }, +}; +MODULE_DEVICE_TABLE(of, ma35_usb_phy_of_match); + +static struct platform_driver ma35_usb_phy_driver = { + .probe = ma35_usb_phy_probe, + .driver = { + .name = "ma35d1-usb2-phy", + .of_match_table = ma35_usb_phy_of_match, + }, +}; +module_platform_driver(ma35_usb_phy_driver); + +MODULE_DESCRIPTION("Nuvoton ma35d1 USB2.0 PHY driver"); +MODULE_AUTHOR("hpchen0nvt@gmail.com"); +MODULE_LICENSE("GPL"); -- 2.25.1 -- linux-phy mailing list linux-phy@lists.infradead.org https://lists.infradead.org/mailman/listinfo/linux-phy ^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v3 2/2] phy: nuvoton: add new driver for the Nuvoton MA35 SoC USB 2.0 PHY @ 2024-08-01 5:37 ` Hui-Ping Chen 0 siblings, 0 replies; 16+ messages in thread From: Hui-Ping Chen @ 2024-08-01 5:37 UTC (permalink / raw) To: vkoul, kishon, robh, krzk+dt, conor+dt Cc: linux-arm-kernel, linux-phy, devicetree, linux-kernel, Hui-Ping Chen Nuvoton MA35 SoCs support DWC2 USB controller. Add the driver to drive the USB 2.0 PHY transceivers. Signed-off-by: Hui-Ping Chen <hpchen0nvt@gmail.com> --- drivers/phy/Kconfig | 1 + drivers/phy/Makefile | 1 + drivers/phy/nuvoton/Kconfig | 13 +++ drivers/phy/nuvoton/Makefile | 3 + drivers/phy/nuvoton/phy-ma35d1-usb2.c | 146 ++++++++++++++++++++++++++ 5 files changed, 164 insertions(+) create mode 100644 drivers/phy/nuvoton/Kconfig create mode 100644 drivers/phy/nuvoton/Makefile create mode 100644 drivers/phy/nuvoton/phy-ma35d1-usb2.c diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig index dfab1c66b3e5..f73abff416be 100644 --- a/drivers/phy/Kconfig +++ b/drivers/phy/Kconfig @@ -95,6 +95,7 @@ source "drivers/phy/mediatek/Kconfig" source "drivers/phy/microchip/Kconfig" source "drivers/phy/motorola/Kconfig" source "drivers/phy/mscc/Kconfig" +source "drivers/phy/nuvoton/Kconfig" source "drivers/phy/qualcomm/Kconfig" source "drivers/phy/ralink/Kconfig" source "drivers/phy/realtek/Kconfig" diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile index 5fcbce5f9ab1..ebc399560da4 100644 --- a/drivers/phy/Makefile +++ b/drivers/phy/Makefile @@ -25,6 +25,7 @@ obj-y += allwinner/ \ microchip/ \ motorola/ \ mscc/ \ + nuvoton/ \ qualcomm/ \ ralink/ \ realtek/ \ diff --git a/drivers/phy/nuvoton/Kconfig b/drivers/phy/nuvoton/Kconfig new file mode 100644 index 000000000000..270ee2943287 --- /dev/null +++ b/drivers/phy/nuvoton/Kconfig @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# PHY drivers for Nuvoton MA35 platforms +# +config PHY_MA35_USB + tristate "Nuvoton MA35 USB2.0 PHY driver" + depends on ARCH_MA35 || COMPILE_TEST + depends on OF + select GENERIC_PHY + help + Enable this to support the USB2.0 PHY on the Nuvoton MA35 + series SoCs. + diff --git a/drivers/phy/nuvoton/Makefile b/drivers/phy/nuvoton/Makefile new file mode 100644 index 000000000000..2937e3921898 --- /dev/null +++ b/drivers/phy/nuvoton/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_PHY_MA35_USB) += phy-ma35d1-usb2.o diff --git a/drivers/phy/nuvoton/phy-ma35d1-usb2.c b/drivers/phy/nuvoton/phy-ma35d1-usb2.c new file mode 100644 index 000000000000..8922e5da8e3b --- /dev/null +++ b/drivers/phy/nuvoton/phy-ma35d1-usb2.c @@ -0,0 +1,146 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2024 Nuvoton Technology Corp. + */ +#include <linux/bitfield.h> +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/mfd/syscon.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/phy/phy.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> + +/* USB PHY Miscellaneous Control Register */ +#define MA35_SYS_REG_USBPMISCR 0x60 +#define PHY0POR BIT(0) /* PHY Power-On Reset Control Bit */ +#define PHY0SUSPEND BIT(1) /* PHY Suspend; 0: suspend, 1: operaion */ +#define PHY0COMN BIT(2) /* PHY Common Block Power-Down Control */ +#define PHY0DEVCKSTB BIT(10) /* PHY 60 MHz UTMI clock stable bit */ + +struct ma35_usb_phy { + struct clk *clk; + struct device *dev; + struct regmap *sysreg; +}; + +static int ma35_usb_phy_power_on(struct phy *phy) +{ + struct ma35_usb_phy *p_phy = phy_get_drvdata(phy); + unsigned int val; + int ret; + + 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 + */ + ret = readl_poll_timeout((void __iomem *)p_phy->sysreg + MA35_SYS_REG_USBPMISCR, + val, val & PHY0DEVCKSTB, 1, 100); + if (ret == -ETIMEDOUT) { + dev_err(p_phy->dev, "1.Check PHY clock, Timeout: %d\n", val); + return ret; + } + return 0; + } + + /* + * 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)); + udelay(10); + + /* 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 */ + ret = readl_poll_timeout((void __iomem *)p_phy->sysreg + MA35_SYS_REG_USBPMISCR, + val, val & PHY0DEVCKSTB, 1, 100); + if (ret == -ETIMEDOUT) { + dev_err(p_phy->dev, "2.Check PHY clock, Timeout: %d\n", ret); + return ret; + } + + clk_disable_unprepare(p_phy->clk); + return 0; +} + +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; + 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(pdev->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"); + + p_phy->clk = of_clk_get(pdev->dev.of_node, 0); + if (IS_ERR(p_phy->clk)) + return dev_err_probe(&pdev->dev, PTR_ERR(p_phy->clk), + "failed to find usb_phy clock\n"); + + phy = devm_phy_create(&pdev->dev, NULL, &ma35_usb_phy_ops); + if (IS_ERR(phy)) + return dev_err_probe(&pdev->dev, PTR_ERR(phy), "Failed to create PHY\n"); + + phy_set_drvdata(phy, p_phy); + + provider = devm_of_phy_provider_register(&pdev->dev, of_phy_simple_xlate); + if (IS_ERR(provider)) + return dev_err_probe(&pdev->dev, PTR_ERR(provider), + "Failed to register PHY provider\n"); + return 0; +} + +static const struct of_device_id ma35_usb_phy_of_match[] = { + { .compatible = "nuvoton,ma35d1-usb2-phy", }, + { }, +}; +MODULE_DEVICE_TABLE(of, ma35_usb_phy_of_match); + +static struct platform_driver ma35_usb_phy_driver = { + .probe = ma35_usb_phy_probe, + .driver = { + .name = "ma35d1-usb2-phy", + .of_match_table = ma35_usb_phy_of_match, + }, +}; +module_platform_driver(ma35_usb_phy_driver); + +MODULE_DESCRIPTION("Nuvoton ma35d1 USB2.0 PHY driver"); +MODULE_AUTHOR("hpchen0nvt@gmail.com"); +MODULE_LICENSE("GPL"); -- 2.25.1 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH v3 2/2] phy: nuvoton: add new driver for the Nuvoton MA35 SoC USB 2.0 PHY 2024-08-01 5:37 ` Hui-Ping Chen @ 2024-08-01 9:50 ` Markus Elfring -1 siblings, 0 replies; 16+ messages in thread From: Markus Elfring @ 2024-08-01 9:50 UTC (permalink / raw) To: Hui-Ping Chen, linux-phy, linux-arm-kernel, devicetree, Conor Dooley, Kishon Vijay Abraham I, Krzysztof Kozlowski, Rob Herring, Vinod Koul Cc: LKML … > +++ b/drivers/phy/nuvoton/phy-ma35d1-usb2.c > @@ -0,0 +1,146 @@ … > +MODULE_DESCRIPTION("Nuvoton ma35d1 USB2.0 PHY driver"); > +MODULE_AUTHOR("hpchen0nvt@gmail.com"); … How do you think about to add a personal name to such an email address? Regards, Markus -- linux-phy mailing list linux-phy@lists.infradead.org https://lists.infradead.org/mailman/listinfo/linux-phy ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v3 2/2] phy: nuvoton: add new driver for the Nuvoton MA35 SoC USB 2.0 PHY @ 2024-08-01 9:50 ` Markus Elfring 0 siblings, 0 replies; 16+ messages in thread From: Markus Elfring @ 2024-08-01 9:50 UTC (permalink / raw) To: Hui-Ping Chen, linux-phy, linux-arm-kernel, devicetree, Conor Dooley, Kishon Vijay Abraham I, Krzysztof Kozlowski, Rob Herring, Vinod Koul Cc: LKML … > +++ b/drivers/phy/nuvoton/phy-ma35d1-usb2.c > @@ -0,0 +1,146 @@ … > +MODULE_DESCRIPTION("Nuvoton ma35d1 USB2.0 PHY driver"); > +MODULE_AUTHOR("hpchen0nvt@gmail.com"); … How do you think about to add a personal name to such an email address? Regards, Markus ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v3 2/2] phy: nuvoton: add new driver for the Nuvoton MA35 SoC USB 2.0 PHY 2024-08-01 9:50 ` Markus Elfring @ 2024-08-02 4:57 ` Hui-Ping Chen -1 siblings, 0 replies; 16+ messages in thread From: Hui-Ping Chen @ 2024-08-02 4:57 UTC (permalink / raw) To: Markus Elfring, linux-phy, linux-arm-kernel, devicetree, Conor Dooley, Kishon Vijay Abraham I, Krzysztof Kozlowski, Rob Herring, Vinod Koul Cc: LKML Dear Markus, Thank you for your reply. On 2024/8/1 下午 05:50, Markus Elfring wrote: > … >> +++ b/drivers/phy/nuvoton/phy-ma35d1-usb2.c >> @@ -0,0 +1,146 @@ > … >> +MODULE_DESCRIPTION("Nuvoton ma35d1 USB2.0 PHY driver"); >> +MODULE_AUTHOR("hpchen0nvt@gmail.com"); > … > > How do you think about to add a personal name to such an email address? I'm sorry. I forgot to put my name here. I'll make it up. > Regards, > Markus Best regards, Hui-Ping Chen -- linux-phy mailing list linux-phy@lists.infradead.org https://lists.infradead.org/mailman/listinfo/linux-phy ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v3 2/2] phy: nuvoton: add new driver for the Nuvoton MA35 SoC USB 2.0 PHY @ 2024-08-02 4:57 ` Hui-Ping Chen 0 siblings, 0 replies; 16+ messages in thread From: Hui-Ping Chen @ 2024-08-02 4:57 UTC (permalink / raw) To: Markus Elfring, linux-phy, linux-arm-kernel, devicetree, Conor Dooley, Kishon Vijay Abraham I, Krzysztof Kozlowski, Rob Herring, Vinod Koul Cc: LKML Dear Markus, Thank you for your reply. On 2024/8/1 下午 05:50, Markus Elfring wrote: > … >> +++ b/drivers/phy/nuvoton/phy-ma35d1-usb2.c >> @@ -0,0 +1,146 @@ > … >> +MODULE_DESCRIPTION("Nuvoton ma35d1 USB2.0 PHY driver"); >> +MODULE_AUTHOR("hpchen0nvt@gmail.com"); > … > > How do you think about to add a personal name to such an email address? I'm sorry. I forgot to put my name here. I'll make it up. > Regards, > Markus Best regards, Hui-Ping Chen ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v3 2/2] phy: nuvoton: add new driver for the Nuvoton MA35 SoC USB 2.0 PHY 2024-08-01 5:37 ` Hui-Ping Chen @ 2024-08-01 14:43 ` Krzysztof Kozlowski -1 siblings, 0 replies; 16+ messages in thread From: Krzysztof Kozlowski @ 2024-08-01 14:43 UTC (permalink / raw) To: Hui-Ping Chen, vkoul, kishon, robh, krzk+dt, conor+dt Cc: linux-arm-kernel, linux-phy, devicetree, linux-kernel On 01/08/2024 07:37, Hui-Ping Chen wrote: > + struct regmap *sysreg; Look here - iomem? No. > +}; > + > +static int ma35_usb_phy_power_on(struct phy *phy) > +{ > + struct ma35_usb_phy *p_phy = phy_get_drvdata(phy); > + unsigned int val; > + int ret; > + > + 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 > + */ > + ret = readl_poll_timeout((void __iomem *)p_phy->sysreg + MA35_SYS_REG_USBPMISCR, Eh, I responded to v2, not here, so repeating: sysreg is a regmap, not io address. How could it possibly work and be tested?!? This cannot work. Test your code *before* sending it. Best regards, Krzysztof -- linux-phy mailing list linux-phy@lists.infradead.org https://lists.infradead.org/mailman/listinfo/linux-phy ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v3 2/2] phy: nuvoton: add new driver for the Nuvoton MA35 SoC USB 2.0 PHY @ 2024-08-01 14:43 ` Krzysztof Kozlowski 0 siblings, 0 replies; 16+ messages in thread From: Krzysztof Kozlowski @ 2024-08-01 14:43 UTC (permalink / raw) To: Hui-Ping Chen, vkoul, kishon, robh, krzk+dt, conor+dt Cc: linux-arm-kernel, linux-phy, devicetree, linux-kernel On 01/08/2024 07:37, Hui-Ping Chen wrote: > + struct regmap *sysreg; Look here - iomem? No. > +}; > + > +static int ma35_usb_phy_power_on(struct phy *phy) > +{ > + struct ma35_usb_phy *p_phy = phy_get_drvdata(phy); > + unsigned int val; > + int ret; > + > + 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 > + */ > + ret = readl_poll_timeout((void __iomem *)p_phy->sysreg + MA35_SYS_REG_USBPMISCR, Eh, I responded to v2, not here, so repeating: sysreg is a regmap, not io address. How could it possibly work and be tested?!? This cannot work. Test your code *before* sending it. Best regards, Krzysztof ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v3 2/2] phy: nuvoton: add new driver for the Nuvoton MA35 SoC USB 2.0 PHY 2024-08-01 14:43 ` Krzysztof Kozlowski @ 2024-08-02 5:01 ` Hui-Ping Chen -1 siblings, 0 replies; 16+ messages in thread From: Hui-Ping Chen @ 2024-08-02 5:01 UTC (permalink / raw) To: Krzysztof Kozlowski, vkoul, kishon, robh, krzk+dt, conor+dt Cc: linux-arm-kernel, linux-phy, devicetree, linux-kernel Dear Krzysztof, Thank you for your reply. On 2024/8/1 下午 10:43, Krzysztof Kozlowski wrote: > On 01/08/2024 07:37, Hui-Ping Chen wrote: >> + struct regmap *sysreg; > Look here - iomem? No. Yes, this is my mistake. >> +}; >> + >> +static int ma35_usb_phy_power_on(struct phy *phy) >> +{ >> + struct ma35_usb_phy *p_phy = phy_get_drvdata(phy); >> + unsigned int val; >> + int ret; >> + >> + 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 >> + */ >> + ret = readl_poll_timeout((void __iomem *)p_phy->sysreg + MA35_SYS_REG_USBPMISCR, > Eh, I responded to v2, not here, so repeating: > > sysreg is a regmap, not io address. How could it possibly work and be > tested?!? This cannot work. Test your code *before* sending it. > Yes, this is my mistake. I won't reply to v2. I will reply here. I would change 'readl_poll_timeout' to 'regmap_read_poll_timeout'. And it has been tested OK on our platform. > Best regards, > Krzysztof Best regards, Hui-Ping Chen -- linux-phy mailing list linux-phy@lists.infradead.org https://lists.infradead.org/mailman/listinfo/linux-phy ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v3 2/2] phy: nuvoton: add new driver for the Nuvoton MA35 SoC USB 2.0 PHY @ 2024-08-02 5:01 ` Hui-Ping Chen 0 siblings, 0 replies; 16+ messages in thread From: Hui-Ping Chen @ 2024-08-02 5:01 UTC (permalink / raw) To: Krzysztof Kozlowski, vkoul, kishon, robh, krzk+dt, conor+dt Cc: linux-arm-kernel, linux-phy, devicetree, linux-kernel Dear Krzysztof, Thank you for your reply. On 2024/8/1 下午 10:43, Krzysztof Kozlowski wrote: > On 01/08/2024 07:37, Hui-Ping Chen wrote: >> + struct regmap *sysreg; > Look here - iomem? No. Yes, this is my mistake. >> +}; >> + >> +static int ma35_usb_phy_power_on(struct phy *phy) >> +{ >> + struct ma35_usb_phy *p_phy = phy_get_drvdata(phy); >> + unsigned int val; >> + int ret; >> + >> + 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 >> + */ >> + ret = readl_poll_timeout((void __iomem *)p_phy->sysreg + MA35_SYS_REG_USBPMISCR, > Eh, I responded to v2, not here, so repeating: > > sysreg is a regmap, not io address. How could it possibly work and be > tested?!? This cannot work. Test your code *before* sending it. > Yes, this is my mistake. I won't reply to v2. I will reply here. I would change 'readl_poll_timeout' to 'regmap_read_poll_timeout'. And it has been tested OK on our platform. > Best regards, > Krzysztof Best regards, Hui-Ping Chen ^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2024-08-02 5:01 UTC | newest] Thread overview: 16+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-08-01 5:37 [PATCH v3 0/2] Add support for nuvoton ma35 usb2 phy Hui-Ping Chen 2024-08-01 5:37 ` Hui-Ping Chen 2024-08-01 5:37 ` [PATCH v3 1/2] dt-bindings: phy: nuvoton,ma35-usb2-phy: add new bindings Hui-Ping Chen 2024-08-01 5:37 ` Hui-Ping Chen 2024-08-01 14:40 ` Krzysztof Kozlowski 2024-08-01 14:40 ` Krzysztof Kozlowski 2024-08-01 5:37 ` [PATCH v3 2/2] phy: nuvoton: add new driver for the Nuvoton MA35 SoC USB 2.0 PHY Hui-Ping Chen 2024-08-01 5:37 ` Hui-Ping Chen 2024-08-01 9:50 ` Markus Elfring 2024-08-01 9:50 ` Markus Elfring 2024-08-02 4:57 ` Hui-Ping Chen 2024-08-02 4:57 ` Hui-Ping Chen 2024-08-01 14:43 ` Krzysztof Kozlowski 2024-08-01 14:43 ` Krzysztof Kozlowski 2024-08-02 5:01 ` Hui-Ping Chen 2024-08-02 5:01 ` Hui-Ping Chen
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.