phy: at91: Add support for the USB 2.0 PHY's of SAMA7
PATCH v5 1/3 phy: at91: Add support for the USB 2.0 PHY's of SAMA7
From: Sergiu Moga <[email protected]>
In order to have USB functionality, drivers for SAMA7's USB 2.0 PHY's have been added. There is one driver for UTMI clock's SFR and RESET required functionalities and one for its three possible subclocks of the phy's themselves. In order for this layout to properly work in conjunction with CCF and DT, the former driver will also act as a clock provider for the three phy's with the help of a custom hook into the driver's of_xlate method.
---
v1 -> v2:
- use *_bulk API's
v2 -> v3:
- use if (CONFIG_IS_ENABLED(...))
v3->v4:
- none
v4->v5
- add Rb Marek
drivers/phy/Kconfig | 10 ++ drivers/phy/Makefile | 1 + drivers/phy/phy-sama7-usb.c | 90 +++++++++++++ drivers/phy/phy-sama7-utmi-clk.c | 216 +++++++++++++++++++++++++++++++ 4 files changed, 317 insertions(+) create mode 100644 drivers/phy/phy-sama7-usb.c create mode 100644 drivers/phy/phy-sama7-utmi-clk.c
drivers/phy/Kconfig +10 -0
@@ -281,6 +281,16 @@ config PHY_XILINX_ZYNQMP Enable this to support ZynqMP High Speed Gigabit Transceiver that is part of ZynqMP SoC. +config PHY_MICROCHIP_SAMA7_USB + tristate "Microchip SAMA7 USB 2.0 PHY" + depends on PHY && ARCH_AT91 + help + Enable this to support SAMA7 USB 2.0 PHY. + + The USB 2.0 PHY integrates high-speed, full-speed and low-speed + termination and signal switching. With a single resistor, it + requires minimal external components. + source "drivers/phy/rockchip/Kconfig" source "drivers/phy/cadence/Kconfig" source "drivers/phy/ti/Kconfig"
drivers/phy/Makefile +1 -0
@@ -38,6 +38,7 @@ obj-$(CONFIG_PHY_MTK_TPHY) += phy-mtk-tphy.o obj-$(CONFIG_PHY_NPCM_USB) += phy-npcm-usb.o obj-$(CONFIG_PHY_IMX8MQ_USB) += phy-imx8mq-usb.o obj-$(CONFIG_PHY_XILINX_ZYNQMP) += phy-zynqmp.o +obj-$(CONFIG_PHY_MICROCHIP_SAMA7_USB) += phy-sama7-utmi-clk.o phy-sama7-usb.o obj-y += cadence/ obj-y += ti/ obj-y += qcom/
drivers/phy/phy-sama7-usb.c new file +90 -0
90 lines not on this page · raw message
drivers/phy/phy-sama7-utmi-clk.c new file +216 -0
216 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v5 2/3 usb: ohci-at91: Enable OHCI functionality and register into DM
From: Sergiu Moga <[email protected]>
Register the OHCI driver into DM by properly initializing the required clocks and pins required by the DT node of OHCI. In order for the VBUS to stay enabled, a child_pre_probe method has been added to overcome the DM core disabling it in usb_scan_device: when the generic device_probe method is called, the pinctrl is processed once again, undoing whatever changes have been made in our driver's probe method.
Furthermore, enable CONFIG_DM_GPIO whenever this driver and CONFIG_DM_USB are selected.
---
v1 -> v2:
- squashed 3/4 into this patch
- removed bool clocked
- use *_blk API's
- select DM_GPIO in Kconfig if DM_USB enabled
- use dev_read_u32_default
v2 -> v3:
- check value of dev_read_addr
- clk_disable in case of failure after at91_start_hc
v3->v4:
none
v4->v5:
add Rb Marek
drivers/usb/host/Kconfig | 1 + drivers/usb/host/ohci-at91.c | 159 +++++++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+)
drivers/usb/host/Kconfig +1 -0
@@ -437,6 +437,7 @@ config USB_ATMEL depends on ARCH_AT91 select SYS_USB_OHCI_CPU_INIT select USB_OHCI_NEW + select DM_GPIO if DM_USB choice prompt "Clock for OHCI"
drivers/usb/host/ohci-at91.c +159 -0
168 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v5 2/3] usb: ohci-at91: Enable OHCI functionality and register into DM
On 7/25/23 17:43, Eugen Hristev wrote:
[...]
Quoted 12 lines
drivers/usb/host/ohci-at91.c +12
-0+static int ohci_atmel_probe (struct udevice *dev) +{ +struct ohci_at91_priv *ohci_at91 =dev_get_priv (dev); +struct at91_usbh_data *pdata =dev_get_plat (dev); +struct ohci_regs *regs; +int ret; +u32 i; + + regs = (struct ohci_regs *)dev_read_addr (dev); +if (IS_ERR (regs)) { + ret =PTR_ERR (regs); + goto fail;
drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 180
Quoted 10 lines
drivers/usb/host/ohci-at91.c +10
-0+ } + + pdata->ports =dev_read_u32_default (dev,"num-ports" ,3 ); + +at91_for_each_port (i, pdata->ports) +gpio_request_by_name (dev,"atmel,vbus-gpio" , i, + &pdata->vbus_pin[i],GPIOD_IS_OUT | +GPIOD_IS_OUT_ACTIVE ); + + ret =clk_get_bulk (dev, &ohci_at91->clks);
If this fails, and ohci_at91->clks is not populated ...
Quoted 9 lines
drivers/usb/host/ohci-at91.c +9
-0+if (ret) + goto fail; + + ret =clk_enable_bulk (&ohci_at91->clks); +if (ret) + goto fail; + + ret =at91_start_hc (dev); +if (ret)
drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 199
Quoted 10 lines
drivers/usb/host/ohci-at91.c +10
-0+ goto fail; + +return ohci_register (dev, regs); + +fail: +at91_for_each_port (i, pdata->ports) +if (dm_gpio_is_valid (&pdata->vbus_pin[i])) +gpio_free (pdata->vbus_pin[i].offset); + +clk_disable_bulk (&ohci_at91->clks);
... then this clk_disable_bulk() would likely misbehave, right ?
PATCH v5 3/3 usb: ohci-at91: Add USB PHY functionality
In reply to Eugen HristevFrom: Sergiu Moga <[email protected]>
Add the ability to enable/disable whatever USB PHY's are passed to the AT91 OHCI driver through DT.
---
v1 -> v2:
- use *_bulk API's
v2 -> v3:
- use if (CONFIG_IS_ENABLED(...))
v3 -> v4
[[email protected]: disable PHYs in at91_start_clock if clk_enable_bulk fails]
v4->v5:
[[email protected]: rewrite error paths according to Marek's review]
drivers/usb/host/ohci-at91.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-)
drivers/usb/host/ohci-at91.c +33 -1
@@ -73,6 +73,7 @@ int usb_cpu_init_fail(void)#include <asm/gpio.h> #include <usb.h> #include "ohci.h" +#include <generic-phy.h> #define AT91_MAX_USBH_PORTS 3
@@ -90,15 +91,36 @@ struct at91_usbh_data {struct ohci_at91_priv {ohci_t ohci;struct clk_bulk clks; +struct phy_bulk phys; };static int at91_start_clock (struct ohci_at91_priv *ohci_at91) { -return clk_enable_bulk (&ohci_at91->clks); +int ret; + +if (CONFIG_IS_ENABLED (PHY_MICROCHIP_SAMA7_USB )) { + ret =generic_phy_power_on_bulk (&ohci_at91->phys); +if (ret) +return ret; + } + + ret =clk_enable_bulk (&ohci_at91->clks); +if (ret) + goto at91_start_clock_err; + +return 0 ; + +at91_start_clock_err: +generic_phy_power_off_bulk (&ohci_at91->phys); + +return ret; }static int at91_stop_clock (struct ohci_at91_priv *ohci_at91) { +if (CONFIG_IS_ENABLED (PHY_MICROCHIP_SAMA7_USB )) +generic_phy_power_off_bulk (&ohci_at91->phys); +return clk_disable_bulk (&ohci_at91->clks); }
@@ -185,6 +207,16 @@ static int ohci_atmel_probe(struct udevice *dev)if (ret) goto fail; +if (CONFIG_IS_ENABLED (PHY_MICROCHIP_SAMA7_USB )) { + ret =generic_phy_get_bulk (dev, &ohci_at91->phys); +if (ret) + goto fail; + + ret =generic_phy_init_bulk (&ohci_at91->phys); +if (ret) + goto fail; + } + ret =at91_start_hc (dev);if (ret) goto fail;
Signature · 1 line
2.34.1
Re: [PATCH v5 3/3] usb: ohci-at91: Add USB PHY functionality
Quoted 54 lines · Eugen Hristev
From: Sergiu Moga <[email protected]>
Add the ability to enable/disable whatever USB PHY's are passed to the AT91 OHCI driver through DT.
Signed-off-by Sergiu Moga <[email protected]>[[email protected]: rewrite error paths according to Marek's review]Signed-off-by Eugen Hristev <[email protected]>---
v1 -> v2:
- use*_bulkAPI'sv2 -> v3:
- use if (CONFIG_IS_ENABLED(...))v3 -> v4
[[email protected]: disable PHYs inat91_start_clockifclk_enable_bulkfails]
v4->v5:
[[email protected]: rewrite error paths according to Marek's review]drivers/usb/host/ohci-at91.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-)drivers/usb/host/ohci-at91.c +7
-1@@ -73,6 +73,7 @@ int usb_cpu_init_fail(void)#include <asm/gpio.h> #include <usb.h> #include "ohci.h" +#include <generic-phy.h> #define AT91_MAX_USBH_PORTS 3@@ -90,15 +91,36 @@ struct at91_usbh_data {struct ohci_at91_priv {ohci_t ohci;struct clk_bulk clks; +struct phy_bulk phys; };static int at91_start_clock (struct ohci_at91_priv *ohci_at91) { -return clk_enable_bulk (&ohci_at91->clks); +int ret; + +if (CONFIG_IS_ENABLED (PHY_MICROCHIP_SAMA7_USB )) { + ret =generic_phy_power_on_bulk (&ohci_at91->phys); +if (ret)
drivers/usb/host/ohci-at91.c struct at91_usbh_data { · line 113
Quoted 10 lines
drivers/usb/host/ohci-at91.c +10
-0+return ret; + } + + ret =clk_enable_bulk (&ohci_at91->clks); +if (ret) + goto at91_start_clock_err; + +return 0 ; + +at91_start_clock_err:
This likely also needs:
if (CONFIG_IS_ENABLED(PHY_MICROCHIP_SAMA7_USB))
Quoted 30 lines
drivers/usb/host/ohci-at91.c +16
-0+generic_phy_power_off_bulk (&ohci_at91->phys); + +return ret; }static int at91_stop_clock (struct ohci_at91_priv *ohci_at91) { +if (CONFIG_IS_ENABLED (PHY_MICROCHIP_SAMA7_USB )) +generic_phy_power_off_bulk (&ohci_at91->phys); +return clk_disable_bulk (&ohci_at91->clks); }@@ -185,6 +207,16 @@ static int ohci_atmel_probe(struct udevice *dev)if (ret) goto fail; +if (CONFIG_IS_ENABLED (PHY_MICROCHIP_SAMA7_USB )) { + ret =generic_phy_get_bulk (dev, &ohci_at91->phys); +if (ret) + goto fail; + + ret =generic_phy_init_bulk (&ohci_at91->phys); +if (ret) + goto fail; + } + ret =at91_start_hc (dev);if (ret) goto fail;
[...]