Skip to contentSkip to conversation

Register at91 OHCI into DM and add SAMA7 USB PHY's

PATCH Superseded Sergiu Moga 2 participants 17 messages Dec 23, 2022 – Jan 3, 2023

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Register at91 OHCI into DM and add SAMA7 USB PHY's

This patch series originates from a bigger patch series:
https://lists.denx.de/pipermail/u-boot/2022-December/502865.html

Register ohci-at91 driver into Driver Model. 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.
In order to enable USB on SAMA7G5 the addition of the USB 2.0 PHY drivers were required.

Cristian Birsan (1):
usb: ohci-at91: Add ohci_t field in ohci_at91_priv

Sergiu Moga (3):
phy: at91: Add support for the USB 2.0 PHY's of SAMA7
usb: ohci-at91: Enable OHCI functionality and register into DM
usb: ohci-at91: Add USB PHY functionality

 drivers/phy/Kconfig              |  10 ++
 drivers/phy/Makefile             |   1 +
 drivers/phy/phy-sama7-usb.c      |  90 +++++++++++++
 drivers/phy/phy-sama7-utmi-clk.c | 202 +++++++++++++++++++++++++++++
 drivers/usb/host/ohci-at91.c     | 215 +++++++++++++++++++++++++++++++
 5 files changed, 518 insertions(+)
 create mode 100644 drivers/phy/phy-sama7-usb.c
 create mode 100644 drivers/phy/phy-sama7-utmi-clk.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/4 phy: at91: Add support for the USB 2.0 PHY's of SAMA7

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.

---
 drivers/phy/Kconfig              |  10 ++
 drivers/phy/Makefile             |   1 +
 drivers/phy/phy-sama7-usb.c      |  90 ++++++++++++++
 drivers/phy/phy-sama7-utmi-clk.c | 202 +++++++++++++++++++++++++++++++
 4 files changed, 303 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
index cf4d5908d7..9fbb956783 100644
@@ -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
index a3b9f3c5b1..9d50affd47 100644
@@ -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 +202 -0

202 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/4 usb: ohci-at91: Enable OHCI functionality and register into DM

In reply to Sergiu Moga

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.

---
 drivers/usb/host/ohci-at91.c | 183 +++++++++++++++++++++++++++++++++++
 1 file changed, 183 insertions(+)
drivers/usb/host/ohci-at91.c +183 -0
index 9b955c1bd6..9ae55c6e5d 100644
@@ -5,6 +5,9 @@
  */
 
 #include <common.h>
+
+#if !(CONFIG_IS_ENABLED(DM_USB))
+
 #include <asm/arch/clk.h>
 
 int usb_cpu_init(void)
@@ -62,3 +65,183 @@ int usb_cpu_init_fail(void)
 {
 	return usb_cpu_stop();
 }
+
+#elif CONFIG_IS_ENABLED(DM_GPIO)
+
+#include <clk.h>
+#include <dm.h>
+#include <asm/gpio.h>
+#include <usb.h>
+#include "ohci.h"
+
+#define AT91_MAX_USBH_PORTS        3
+
+#define at91_for_each_port(index)	\
+		for ((index) = 0; (index) < AT91_MAX_USBH_PORTS; (index)++)
+
+struct at91_usbh_data {
+	enum usb_init_type init_type;
+	struct gpio_desc vbus_pin[AT91_MAX_USBH_PORTS];
+	u8 ports;				/* number of ports on root hub */
+};
+
+struct ohci_at91_priv {
+	struct clk *iclk;
+	struct clk *fclk;
+	struct clk *hclk;
+	bool clocked;
+};
+
+static void at91_start_clock(struct ohci_at91_priv *ohci_at91)
+{
+	if (ohci_at91->clocked)
+		return;
+
+	clk_set_rate(ohci_at91->fclk, 48000000);
+	clk_prepare_enable(ohci_at91->hclk);
+	clk_prepare_enable(ohci_at91->iclk);
+	clk_prepare_enable(ohci_at91->fclk);
+	ohci_at91->clocked = true;
+}
+
+static void at91_stop_clock(struct ohci_at91_priv *ohci_at91)
+{
+	if (!ohci_at91->clocked)
+		return;
+
+	clk_disable_unprepare(ohci_at91->fclk);
+	clk_disable_unprepare(ohci_at91->iclk);
+	clk_disable_unprepare(ohci_at91->hclk);
+	ohci_at91->clocked = false;
+}
+
+static void ohci_at91_set_power(struct at91_usbh_data *pdata, int port,
+				bool enable)
+{
+	if (!dm_gpio_is_valid(&pdata->vbus_pin[port]))
+		return;
+
+	if (enable)
+		dm_gpio_set_dir_flags(&pdata->vbus_pin[port],
+				      GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
+	else
+		dm_gpio_set_dir_flags(&pdata->vbus_pin[port], 0);
+}
+
+static void at91_start_hc(struct udevice *dev)
+{
+	struct ohci_at91_priv *ohci_at91 = dev_get_priv(dev);
+
+	at91_start_clock(ohci_at91);
+}
+
+static void at91_stop_hc(struct udevice *dev)
+{
+	struct ohci_at91_priv *ohci_at91 = dev_get_priv(dev);
+
+	at91_stop_clock(ohci_at91);
+}
+
+static int ohci_atmel_deregister(struct udevice *dev)
+{
+	struct at91_usbh_data *pdata = dev_get_plat(dev);
+	int i;
+
+	at91_stop_hc(dev);
+
+	at91_for_each_port(i) {
+		if (i >= pdata->ports)
+			break;
+
+		ohci_at91_set_power(pdata, i, false);
+	}
+
+	return ohci_deregister(dev);
+}
+
+static int ohci_atmel_child_pre_probe(struct udevice *dev)
+{
+	struct udevice *ohci_controller = dev_get_parent(dev);
+	struct at91_usbh_data *pdata = dev_get_plat(ohci_controller);
+	int i;
+
+	at91_for_each_port(i) {
+		if (i >= pdata->ports)
+			break;
+
+		ohci_at91_set_power(pdata, i, true);
+	}
+
+	return 0;
+}
+
+static int ohci_atmel_probe(struct udevice *dev)
+{
+	struct at91_usbh_data *pdata = dev_get_plat(dev);
+	struct ohci_at91_priv *ohci_at91 = dev_get_priv(dev);
+	int		      i;
+	int		      ret;
+	u32		      ports;
+	struct ohci_regs      *regs = (struct ohci_regs *)dev_read_addr(dev);
+
+	if (!dev_read_u32(dev, "num-ports", &ports))
+		pdata->ports = ports;
+
+	at91_for_each_port(i) {
+		if (i >= pdata->ports)
+			break;
+
+		gpio_request_by_name(dev, "atmel,vbus-gpio", i,
+				     &pdata->vbus_pin[i], GPIOD_IS_OUT |
+				     GPIOD_IS_OUT_ACTIVE);
+	}
+
+	ohci_at91->iclk = devm_clk_get(dev, "ohci_clk");
+	if (IS_ERR(ohci_at91->iclk)) {
+		ret = PTR_ERR(ohci_at91->iclk);
+		goto fail;
+	}
+
+	ohci_at91->fclk = devm_clk_get(dev, "uhpck");
+	if (IS_ERR(ohci_at91->fclk)) {
+		ret = PTR_ERR(ohci_at91->fclk);
+		goto fail;
+	}
+
+	ohci_at91->hclk = devm_clk_get(dev, "hclk");
+	if (IS_ERR(ohci_at91->hclk)) {
+		ret = PTR_ERR(ohci_at91->hclk);
+		goto fail;
+	}
+
+	at91_start_hc(dev);
+
+	return ohci_register(dev, regs);
+
+fail:
+	at91_for_each_port(i)
+		if (dm_gpio_is_valid(&pdata->vbus_pin[i]))
+			gpio_free(pdata->vbus_pin[i].offset);
+
+	return ret;
+}
+
+static const struct udevice_id ohci_usb_ids[] = {
+	{ .compatible = "atmel,at91rm9200-ohci", },
+	{ }
+};
+
+U_BOOT_DRIVER(ohci_atmel) = {
+	.name		 = "ohci_atmel",
+	.id		 = UCLASS_USB,
+	.of_match	 = ohci_usb_ids,
+	.probe		 = ohci_atmel_probe,
+	.remove		 = ohci_atmel_deregister,
+	.child_pre_probe = ohci_atmel_child_pre_probe,
+	.ops		 = &ohci_usb_ops,
+	.plat_auto	 = sizeof(struct at91_usbh_data),
+	.priv_auto	 = sizeof(struct ohci_at91_priv),
+	.flags		 = DM_FLAG_ALLOC_PRIV_DMA,
+};
+
+#endif /* CONFIG_IS_ENABLED(DM_USB) && CONFIG_IS_ENABLED(DM_GPIO) */
Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH 2/4] usb: ohci-at91: Enable OHCI functionality and register into DM

On 12/23/22 13:34, Sergiu Moga wrote:

[...]

Quoted 15 lines
drivers/usb/host/ohci-at91.c +3 -0
index 9b955c1bd6..9ae55c6e5d 100644
@@ -5,6 +5,9 @@
   */
 
  #include <common.h>
+
+#if !(CONFIG_IS_ENABLED(DM_USB))
+
  #include <asm/arch/clk.h>
 
  int usb_cpu_init(void)

drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 67

Quoted 3 lines
drivers/usb/host/ohci-at91.c +0 -0
@@ -62,3 +65,183 @@ int usb_cpu_init_fail(void)
  {
  	return usb_cpu_stop();
  }

Would it be possible to just remove the non-DM functionality ?

drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 69

Quoted 1 line
drivers/usb/host/ohci-at91.c +1 -0
+#elif CONFIG_IS_ENABLED(DM_GPIO)

I think you want plain '#else' here, and then make the driver select DM_GPIO in case DM_USB is enabled in Kconfig entry.

Quoted 4 lines
drivers/usb/host/ohci-at91.c +4 -0
+#include <clk.h>
+#include <dm.h>
+#include <asm/gpio.h>
+#include <usb.h>

drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 84

Quoted 10 lines
drivers/usb/host/ohci-at91.c +9 -0
+#include "ohci.h"
+
+#define AT91_MAX_USBH_PORTS        3
 
+#define at91_for_each_port(index)	\
+		for ((index) = 0; (index) < AT91_MAX_USBH_PORTS; (index)++)
+
+struct at91_usbh_data {
+	enum usb_init_type init_type;
+	struct gpio_desc vbus_pin[AT91_MAX_USBH_PORTS];

drivers/usb/host/ehci-generic.c: ret = device_get_supply_regulator(dev, "vbus-supply",

I wonder if we can instead use regulator for vbus-supply here too ?

drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 91

Quoted 7 lines
drivers/usb/host/ohci-at91.c +7 -0
+	u8 ports;				/* number of ports on root hub */
+};
+
+struct ohci_at91_priv {
+	struct clk *iclk;
+	struct clk *fclk;
+	struct clk *hclk;

Have a look at clk.*bulk functions in U-Boot , then you can do clk_get_bulk() / clk_enable_bulk() etc. below.

drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 103

Quoted 12 lines
drivers/usb/host/ohci-at91.c +12 -0
+	bool clocked;
+};
+
+static void at91_start_clock(struct ohci_at91_priv *ohci_at91)
+{
+	if (ohci_at91->clocked)
+		return;
+
+	clk_set_rate(ohci_at91->fclk, 48000000);
+	clk_prepare_enable(ohci_at91->hclk);
+	clk_prepare_enable(ohci_at91->iclk);
+	clk_prepare_enable(ohci_at91->fclk);

E.g. here you can use clk_enable_bulk() .

drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 104

Quoted 1 line
drivers/usb/host/ohci-at91.c +1 -0
+	ohci_at91->clocked = true;

Why is this here, are you suffering from clock inbalance ? You shouldn't, so remove this and the if (ohci_at91->clocked) test above.

drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 109

Quoted 5 lines
drivers/usb/host/ohci-at91.c +5 -0
+}
+
+static void at91_stop_clock(struct ohci_at91_priv *ohci_at91)
+{
+	if (!ohci_at91->clocked)

Is this really needed ?

drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 122

Quoted 13 lines
drivers/usb/host/ohci-at91.c +13 -0
+		return;
+
+	clk_disable_unprepare(ohci_at91->fclk);
+	clk_disable_unprepare(ohci_at91->iclk);
+	clk_disable_unprepare(ohci_at91->hclk);
+	ohci_at91->clocked = false;
+}
+
+static void ohci_at91_set_power(struct at91_usbh_data *pdata, int port,
+				bool enable)
+{
+	if (!dm_gpio_is_valid(&pdata->vbus_pin[port]))
+		return;

This could be regulator instead.

Quoted 20 lines
drivers/usb/host/ohci-at91.c +20 -0
+	if (enable)
+		dm_gpio_set_dir_flags(&pdata->vbus_pin[port],
+				      GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
+	else
+		dm_gpio_set_dir_flags(&pdata->vbus_pin[port], 0);
+}
+
+static void at91_start_hc(struct udevice *dev)
+{
+	struct ohci_at91_priv *ohci_at91 = dev_get_priv(dev);
+
+	at91_start_clock(ohci_at91);
+}
+
+static void at91_stop_hc(struct udevice *dev)
+{
+	struct ohci_at91_priv *ohci_at91 = dev_get_priv(dev);
+
+	at91_stop_clock(ohci_at91);
+}

drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 153

Quoted 10 lines
drivers/usb/host/ohci-at91.c +10 -0
+
+static int ohci_atmel_deregister(struct udevice *dev)
+{
+	struct at91_usbh_data *pdata = dev_get_plat(dev);
+	int i;
+
+	at91_stop_hc(dev);
+
+	at91_for_each_port(i) {
+		if (i >= pdata->ports)

You can just wrap this test into the at91_for_each_port() macro , just use "index < min(AT91_MAX_USBH_PORTS, pdata->ports)" or so.

Quoted 25 lines
drivers/usb/host/ohci-at91.c +25 -0
+			break;
+
+		ohci_at91_set_power(pdata, i, false);
+	}
+
+	return ohci_deregister(dev);
+}
+
+static int ohci_atmel_child_pre_probe(struct udevice *dev)
+{
+	struct udevice *ohci_controller = dev_get_parent(dev);
+	struct at91_usbh_data *pdata = dev_get_plat(ohci_controller);
+	int i;
+
+	at91_for_each_port(i) {
+		if (i >= pdata->ports)
+			break;
+
+		ohci_at91_set_power(pdata, i, true);
+	}
+
+	return 0;
+}
+
+static int ohci_atmel_probe(struct udevice *dev)

drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 188

Quoted 10 lines
drivers/usb/host/ohci-at91.c +10 -0
+{
+	struct at91_usbh_data *pdata = dev_get_plat(dev);
+	struct ohci_at91_priv *ohci_at91 = dev_get_priv(dev);
+	int		      i;
+	int		      ret;
+	u32		      ports;
+	struct ohci_regs      *regs = (struct ohci_regs *)dev_read_addr(dev);
+
+	if (!dev_read_u32(dev, "num-ports", &ports))
+		pdata->ports = ports;

dev_read_u32_default() ?

Quoted 14 lines
drivers/usb/host/ohci-at91.c +14 -0
+	at91_for_each_port(i) {
+		if (i >= pdata->ports)
+			break;
+
+		gpio_request_by_name(dev, "atmel,vbus-gpio", i,
+				     &pdata->vbus_pin[i], GPIOD_IS_OUT |
+				     GPIOD_IS_OUT_ACTIVE);
+	}
+
+	ohci_at91->iclk = devm_clk_get(dev, "ohci_clk");
+	if (IS_ERR(ohci_at91->iclk)) {
+		ret = PTR_ERR(ohci_at91->iclk);
+		goto fail;
+	}

drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 213

Quoted 10 lines
drivers/usb/host/ohci-at91.c +10 -0
+
+	ohci_at91->fclk = devm_clk_get(dev, "uhpck");
+	if (IS_ERR(ohci_at91->fclk)) {
+		ret = PTR_ERR(ohci_at91->fclk);
+		goto fail;
+	}
+
+	ohci_at91->hclk = devm_clk_get(dev, "hclk");
+	if (IS_ERR(ohci_at91->hclk)) {
+		ret = PTR_ERR(ohci_at91->hclk);

clk_get_bulk() would simplify this.

[...]

#4 lore raw

Re: [PATCH 2/4] usb: ohci-at91: Enable OHCI functionality and register into DM

Quoted 17 lines · Marek Vasut

On 12/23/22 13:34, Sergiu Moga wrote:

[...]

Quoted 13 lines
drivers/usb/host/ohci-at91.c +3 -0
index 9b955c1bd6..9ae55c6e5d 100644
@@ -5,6 +5,9 @@
    */
 
   #include <common.h>
+
+#if !(CONFIG_IS_ENABLED(DM_USB))
+
   #include <asm/arch/clk.h>
 
Quoted 8 lines

drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 67

Quoted 5 lines
drivers/usb/host/ohci-at91.c +0 -0
   int usb_cpu_init(void)
@@ -62,3 +65,183 @@ int usb_cpu_init_fail(void)
   {
       return usb_cpu_stop();
   }

Would it be possible to just remove the non-DM functionality ?

Unfortunately, the other older boards would not build and work anymore if I were to remove this.

Quoted 23 lines

drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 69

Quoted 1 line
drivers/usb/host/ohci-at91.c +1 -0
+#elif CONFIG_IS_ENABLED(DM_GPIO)

I think you want plain '#else' here, and then make the driver select DM_GPIO in case DM_USB is enabled in Kconfig entry.

Quoted 4 lines
drivers/usb/host/ohci-at91.c +4 -0
+#include <clk.h>
+#include <dm.h>
+#include <asm/gpio.h>
+#include <usb.h>

drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 84

Quoted 10 lines
drivers/usb/host/ohci-at91.c +9 -0
+#include "ohci.h"
+
+#define AT91_MAX_USBH_PORTS        3
 
+#define at91_for_each_port(index)    \
+             for ((index) = 0; (index) < AT91_MAX_USBH_PORTS; (index)++)
+
+struct at91_usbh_data {
+     enum usb_init_type init_type;
+     struct gpio_desc vbus_pin[AT91_MAX_USBH_PORTS];

drivers/usb/host/ehci-generic.c:        ret =
device_get_supply_regulator(dev, "vbus-supply",

Quoted 2 lines

I wonder if we can instead use regulator for vbus-supply here too ?

I would rather keep the same DT properties as those in Linux and have them be in concordance with our USB DT binding, which specifies the atmel,vbus-gpio property and no vbus-supply.

Other than that, I am fine with the other requested changes.

Quoted 157 lines

drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 91

Quoted 8 lines

+     u8 ports;                               /* number of ports on root hub */

drivers/usb/host/ohci-at91.c +6 -0
+};
+
+struct ohci_at91_priv {
+     struct clk *iclk;
+     struct clk *fclk;
+     struct clk *hclk;

Have a look at clk.*bulk functions in U-Boot , then you can do clk_get_bulk() / clk_enable_bulk() etc. below.

drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 103

Quoted 12 lines

+     bool clocked;

drivers/usb/host/ohci-at91.c +11 -0
+};
+
+static void at91_start_clock(struct ohci_at91_priv *ohci_at91)
+{
+     if (ohci_at91->clocked)
+             return;
+
+     clk_set_rate(ohci_at91->fclk, 48000000);
+     clk_prepare_enable(ohci_at91->hclk);
+     clk_prepare_enable(ohci_at91->iclk);
+     clk_prepare_enable(ohci_at91->fclk);

E.g. here you can use clk_enable_bulk() .

Quoted 1 line

+     ohci_at91->clocked = true;

Why is this here, are you suffering from clock inbalance ? You shouldn't, so remove this and the if (ohci_at91->clocked) test above.

drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 109

Quoted 5 lines
drivers/usb/host/ohci-at91.c +5 -0
+}
+
+static void at91_stop_clock(struct ohci_at91_priv *ohci_at91)
+{
+     if (!ohci_at91->clocked)

Is this really needed ?

drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 122

Quoted 13 lines

+             return;

drivers/usb/host/ohci-at91.c +12 -0
+
+     clk_disable_unprepare(ohci_at91->fclk);
+     clk_disable_unprepare(ohci_at91->iclk);
+     clk_disable_unprepare(ohci_at91->hclk);
+     ohci_at91->clocked = false;
+}
+
+static void ohci_at91_set_power(struct at91_usbh_data *pdata, int port,
+                             bool enable)
+{
+     if (!dm_gpio_is_valid(&pdata->vbus_pin[port]))
+             return;

This could be regulator instead.

Quoted 20 lines

+     if (enable)
+             dm_gpio_set_dir_flags(&pdata->vbus_pin[port], +                                   GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); +     else
+             dm_gpio_set_dir_flags(&pdata->vbus_pin[port], 0);

drivers/usb/host/ohci-at91.c +15 -0
+}
+
+static void at91_start_hc(struct udevice *dev)
+{
+     struct ohci_at91_priv *ohci_at91 = dev_get_priv(dev);
+
+     at91_start_clock(ohci_at91);
+}
+
+static void at91_stop_hc(struct udevice *dev)
+{
+     struct ohci_at91_priv *ohci_at91 = dev_get_priv(dev);
+
+     at91_stop_clock(ohci_at91);
+}

drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 153

Quoted 10 lines
drivers/usb/host/ohci-at91.c +10 -0
+
+static int ohci_atmel_deregister(struct udevice *dev)
+{
+     struct at91_usbh_data *pdata = dev_get_plat(dev);
+     int i;
+
+     at91_stop_hc(dev);
+
+     at91_for_each_port(i) {
+             if (i >= pdata->ports)

You can just wrap this test into the at91_for_each_port() macro , just use "index < min(AT91_MAX_USBH_PORTS, pdata->ports)" or so.

Quoted 32 lines

+                     break;

drivers/usb/host/ohci-at91.c +31 -0
+
+             ohci_at91_set_power(pdata, i, false);
+     }
+
+     return ohci_deregister(dev);
+}
+
+static int ohci_atmel_child_pre_probe(struct udevice *dev)
+{
+     struct udevice *ohci_controller = dev_get_parent(dev);
+     struct at91_usbh_data *pdata = dev_get_plat(ohci_controller);
+     int i;
+
+     at91_for_each_port(i) {
+             if (i >= pdata->ports)
+                     break;
+
+             ohci_at91_set_power(pdata, i, true);
+     }
+
+     return 0;
+}
+
+static int ohci_atmel_probe(struct udevice *dev)
+{
+     struct at91_usbh_data *pdata = dev_get_plat(dev);
+     struct ohci_at91_priv *ohci_at91 = dev_get_priv(dev);
+     int                   i;
+     int                   ret;
+     u32                   ports;
+     struct ohci_regs      *regs = (struct ohci_regs 
Quoted 4 lines

*)dev_read_addr(dev);
+
+     if (!dev_read_u32(dev, "num-ports", &ports)) +             pdata->ports = ports;

dev_read_u32_default() ?

Quoted 14 lines

+     at91_for_each_port(i) {
+             if (i >= pdata->ports)
+                     break;

drivers/usb/host/ohci-at91.c +11 -0
+
+             gpio_request_by_name(dev, "atmel,vbus-gpio", i,
+                                  &pdata->vbus_pin[i], GPIOD_IS_OUT |
+                                  GPIOD_IS_OUT_ACTIVE);
+     }
+
+     ohci_at91->iclk = devm_clk_get(dev, "ohci_clk");
+     if (IS_ERR(ohci_at91->iclk)) {
+             ret = PTR_ERR(ohci_at91->iclk);
+             goto fail;
+     }

drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 213

Quoted 10 lines
drivers/usb/host/ohci-at91.c +10 -0
+
+     ohci_at91->fclk = devm_clk_get(dev, "uhpck");
+     if (IS_ERR(ohci_at91->fclk)) {
+             ret = PTR_ERR(ohci_at91->fclk);
+             goto fail;
+     }
+
+     ohci_at91->hclk = devm_clk_get(dev, "hclk");
+     if (IS_ERR(ohci_at91->hclk)) {
+             ret = PTR_ERR(ohci_at91->hclk);

clk_get_bulk() would simplify this.

[...]

#5 lore raw

Re: [PATCH 2/4] usb: ohci-at91: Enable OHCI functionality and register into DM

Quoted 27 lines · On 1/3/23 13:11, [email protected] wrote:
Quoted 17 lines · Marek Vasut

On 12/23/22 13:34, Sergiu Moga wrote:

[...]

Quoted 13 lines
drivers/usb/host/ohci-at91.c +3 -0
index 9b955c1bd6..9ae55c6e5d 100644
@@ -5,6 +5,9 @@
    */
 
   #include <common.h>
+
+#if !(CONFIG_IS_ENABLED(DM_USB))
+
   #include <asm/arch/clk.h>
 
Quoted 8 lines

drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 67

Quoted 5 lines
drivers/usb/host/ohci-at91.c +0 -0
   int usb_cpu_init(void)
@@ -62,3 +65,183 @@ int usb_cpu_init_fail(void)
   {
       return usb_cpu_stop();
   }

Would it be possible to just remove the non-DM functionality ?

Quoted 2 lines

Unfortunately, the other older boards would not build and work anymore if I were to remove this.

Any chance they can be converted to DM ?

Quoted 23 lines
Quoted 23 lines

drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 69

Quoted 1 line
drivers/usb/host/ohci-at91.c +1 -0
+#elif CONFIG_IS_ENABLED(DM_GPIO)

I think you want plain '#else' here, and then make the driver select DM_GPIO in case DM_USB is enabled in Kconfig entry.

Quoted 4 lines
drivers/usb/host/ohci-at91.c +4 -0
+#include <clk.h>
+#include <dm.h>
+#include <asm/gpio.h>
+#include <usb.h>

drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 84

Quoted 10 lines
drivers/usb/host/ohci-at91.c +9 -0
+#include "ohci.h"
+
+#define AT91_MAX_USBH_PORTS        3
 
+#define at91_for_each_port(index)    \
+             for ((index) = 0; (index) < AT91_MAX_USBH_PORTS; (index)++)
+
+struct at91_usbh_data {
+     enum usb_init_type init_type;
+     struct gpio_desc vbus_pin[AT91_MAX_USBH_PORTS];

drivers/usb/host/ehci-generic.c:        ret =
device_get_supply_regulator(dev, "vbus-supply",

Quoted 6 lines
Quoted 2 lines

I wonder if we can instead use regulator for vbus-supply here too ?

I would rather keep the same DT properties as those in Linux and have them be in concordance with our USB DT binding, which specifies the atmel,vbus-gpio property and no vbus-supply.

Oh well, so yes, we're stuck with this GPIO stuff.

[...]

#6 lore raw

Re: [PATCH 2/4] usb: ohci-at91: Enable OHCI functionality and register into DM

Quoted 29 lines · Marek Vasut
Quoted 28 lines · On 1/3/23 13:11, [email protected] wrote:
Quoted 26 lines · Marek Vasut

On 12/23/22 13:34, Sergiu Moga wrote:

[...]

Quoted 16 lines
drivers/usb/host/ohci-at91.c +3 -0
index 9b955c1bd6..9ae55c6e5d 100644
@@ -5,6 +5,9 @@
     */
 
    #include <common.h>
+
+#if !(CONFIG_IS_ENABLED(DM_USB))
+
    #include <asm/arch/clk.h>
 
    int usb_cpu_init(void)

drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 67

Quoted 3 lines
drivers/usb/host/ohci-at91.c +0 -0
@@ -62,3 +65,183 @@ int usb_cpu_init_fail(void)
    {
        return usb_cpu_stop();
    }

Would it be possible to just remove the non-DM functionality ?

Quoted 5 lines
Quoted 2 lines

Unfortunately, the other older boards would not build and work anymore if I were to remove this.

Any chance they can be converted to DM ?

Not at the moment, no.

Quoted 27 lines
Quoted 27 lines
Quoted 26 lines

drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 69

Quoted 1 line
drivers/usb/host/ohci-at91.c +1 -0
+#elif CONFIG_IS_ENABLED(DM_GPIO)

I think you want plain '#else' here, and then make the driver select DM_GPIO in case DM_USB is enabled in Kconfig entry.

Quoted 11 lines
drivers/usb/host/ohci-at91.c +9 -0
+#include <clk.h>
+#include <dm.h>
+#include <asm/gpio.h>
+#include <usb.h>
+#include "ohci.h"
+
+#define AT91_MAX_USBH_PORTS        3
 
+#define at91_for_each_port(index)    \
+             for ((index) = 0; (index) < AT91_MAX_USBH_PORTS; 

(index)++)

drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 84

Quoted 4 lines
drivers/usb/host/ohci-at91.c +4 -0
+
+struct at91_usbh_data {
+     enum usb_init_type init_type;
+     struct gpio_desc vbus_pin[AT91_MAX_USBH_PORTS];

drivers/usb/host/ehci-generic.c:        ret =
device_get_supply_regulator(dev, "vbus-supply",

I wonder if we can instead use regulator for vbus-supply here too ?

Quoted 7 lines
Quoted 3 lines

I would rather keep the same DT properties as those in Linux and have them be in concordance with our USB DT binding, which specifies the atmel,vbus-gpio property and no vbus-supply.

Oh well, so yes, we're stuck with this GPIO stuff.

[...]

Unfortunately yes...

#7 lore raw

Re: [PATCH 2/4] usb: ohci-at91: Enable OHCI functionality and register into DM

Quoted 30 lines · On 1/3/23 16:49, [email protected] wrote:
Quoted 29 lines · Marek Vasut
Quoted 28 lines · On 1/3/23 13:11, [email protected] wrote:
Quoted 26 lines · Marek Vasut

On 12/23/22 13:34, Sergiu Moga wrote:

[...]

Quoted 16 lines
drivers/usb/host/ohci-at91.c +3 -0
index 9b955c1bd6..9ae55c6e5d 100644
@@ -5,6 +5,9 @@
     */
 
    #include <common.h>
+
+#if !(CONFIG_IS_ENABLED(DM_USB))
+
    #include <asm/arch/clk.h>
 
    int usb_cpu_init(void)

drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 67

Quoted 3 lines
drivers/usb/host/ohci-at91.c +0 -0
@@ -62,3 +65,183 @@ int usb_cpu_init_fail(void)
    {
        return usb_cpu_stop();
    }

Would it be possible to just remove the non-DM functionality ?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Unfortunately, the other older boards would not build and work anymore if I were to remove this.

Any chance they can be converted to DM ?

Not at the moment, no.

Why ?

#8 lore raw

Re: [PATCH 2/4] usb: ohci-at91: Enable OHCI functionality and register into DM

Quoted 34 lines · Marek Vasut
Quoted 33 lines · On 1/3/23 16:49, [email protected] wrote:
Quoted 32 lines · Marek Vasut
Quoted 30 lines · On 1/3/23 13:11, [email protected] wrote:
Quoted 18 lines · Marek Vasut

On 12/23/22 13:34, Sergiu Moga wrote:

[...]

Quoted 14 lines
drivers/usb/host/ohci-at91.c +3 -0
index 9b955c1bd6..9ae55c6e5d 100644
@@ -5,6 +5,9 @@
      */
 
     #include <common.h>
+
+#if !(CONFIG_IS_ENABLED(DM_USB))
+
     #include <asm/arch/clk.h>
 
Quoted 8 lines

drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 67

Quoted 5 lines
drivers/usb/host/ohci-at91.c +0 -0
     int usb_cpu_init(void)
@@ -62,3 +65,183 @@ int usb_cpu_init_fail(void)
     {
         return usb_cpu_stop();
     }

Would it be possible to just remove the non-DM functionality ?

Unfortunately, the other older boards would not build and work anymore if I were to remove this.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Any chance they can be converted to DM ?

Not at the moment, no.

Why ?

My apologies, but I do not have these boards at my disposal to test them and they are not the focus of this patch series. The reason I kept the non-DM part is that so the build on the other boards does not break. Perhaps in the future there will be plans to convert these as well but at the moment I can not say for sure.

#9 lore raw

Re: [PATCH 2/4] usb: ohci-at91: Enable OHCI functionality and register into DM

Quoted 40 lines · On 1/3/23 17:01, [email protected] wrote:
Quoted 39 lines · Marek Vasut
Quoted 37 lines · On 1/3/23 16:49, [email protected] wrote:
Quoted 29 lines · Marek Vasut
Quoted 28 lines · On 1/3/23 13:11, [email protected] wrote:
Quoted 26 lines · Marek Vasut

On 12/23/22 13:34, Sergiu Moga wrote:

[...]

Quoted 16 lines
drivers/usb/host/ohci-at91.c +3 -0
index 9b955c1bd6..9ae55c6e5d 100644
@@ -5,6 +5,9 @@
      */
 
     #include <common.h>
+
+#if !(CONFIG_IS_ENABLED(DM_USB))
+
     #include <asm/arch/clk.h>
 
     int usb_cpu_init(void)

drivers/usb/host/ohci-at91.c int usb_cpu_init_fail(void) · line 67

Quoted 3 lines
drivers/usb/host/ohci-at91.c +0 -0
@@ -62,3 +65,183 @@ int usb_cpu_init_fail(void)
     {
         return usb_cpu_stop();
     }

Would it be possible to just remove the non-DM functionality ?

Quoted 5 lines
Quoted 2 lines

Unfortunately, the other older boards would not build and work anymore if I were to remove this.

Any chance they can be converted to DM ?

Not at the moment, no.

Quoted 7 lines
Quoted 1 line

Why ?

My apologies, but I do not have these boards at my disposal to test them and they are not the focus of this patch series. The reason I kept the non-DM part is that so the build on the other boards does not break. Perhaps in the future there will be plans to convert these as well but at the moment I can not say for sure.

No need to apologize. Can you add a comment into the commit message, explaining this ?

#10 lore raw

PATCH 3/4 usb: ohci-at91: Add `ohci_t` field in `ohci_at91_priv`

In reply to Sergiu Moga

From: Cristian Birsan <[email protected]>

The ohci_register function expects that the OHCI driver's priv is a struct whose first field is of type ohci_t. The original conversion to DM did not have it and this inconsistency revealed itself whenever U-Boot required multiple memory allocations resulting in a memory overwrite of where this field would supposedly be.

Thus, add this missing field and automatically increase the implicit size of the driver's priv to avoid whatever future memory allocations may take place from overwriting it.

Fixes de1cf0a9c6 ("drivers: usb: ohci-at91: Enable OHCI functionality and register into DM")
---
 drivers/usb/host/ohci-at91.c | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/host/ohci-at91.c +1 -0
index 9ae55c6e5d..5cf8f283e5 100644
@@ -86,6 +86,7 @@ struct at91_usbh_data {
 };
 
 struct ohci_at91_priv {
+	ohci_t ohci;
 	struct clk *iclk;
 	struct clk *fclk;
 	struct clk *hclk;
Signature · 1 line
2.34.1
#11 lore raw

Re: [PATCH 3/4] usb: ohci-at91: Add `ohci_t` field in `ohci_at91_priv`

Quoted 14 lines · Sergiu Moga

From: Cristian Birsan <[email protected]>

The ohci_register function expects that the OHCI driver's priv is a struct whose first field is of type ohci_t. The original conversion to DM did not have it and this inconsistency revealed itself whenever U-Boot required multiple memory allocations resulting in a memory overwrite of where this field would supposedly be.

Thus, add this missing field and automatically increase the implicit size of the driver's priv to avoid whatever future memory allocations may take place from overwriting it.

Quoted 4 lines
Fixes de1cf0a9c6 ("drivers: usb: ohci-at91: Enable OHCI functionality and register into DM")

Either squash into 2/4 or -- if this should be applied on current release -- submit as separate patch.

#12 lore raw

PATCH 4/4 usb: ohci-at91: Add USB PHY functionality

In reply to Sergiu Moga

Add the ability to enable/disable whatever USB PHY's are passed to the AT91 OHCI driver through DT.

---
 drivers/usb/host/ohci-at91.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
drivers/usb/host/ohci-at91.c +31 -0
index 5cf8f283e5..217f31b402 100644
@@ -74,6 +74,10 @@ int usb_cpu_init_fail(void)
 #include <usb.h>
 #include "ohci.h"
 
+#if CONFIG_IS_ENABLED(PHY_MICROCHIP_SAMA7_USB)
+#include <generic-phy.h>
+#endif
+
 #define AT91_MAX_USBH_PORTS        3
 
 #define at91_for_each_port(index)	\
@@ -91,6 +95,10 @@ struct ohci_at91_priv {
 	struct clk *fclk;
 	struct clk *hclk;
 	bool clocked;
+
+#if CONFIG_IS_ENABLED(PHY_MICROCHIP_SAMA7_USB)
+	struct phy phy[AT91_MAX_USBH_PORTS];
+#endif
 };
 
 static void at91_start_clock(struct ohci_at91_priv *ohci_at91)
@@ -98,6 +106,13 @@ static void at91_start_clock(struct ohci_at91_priv *ohci_at91)
 	if (ohci_at91->clocked)
 		return;
 
+#if CONFIG_IS_ENABLED(PHY_MICROCHIP_SAMA7_USB)
+	int i;
+
+	at91_for_each_port(i)
+		generic_phy_power_on(&ohci_at91->phy[i]);
+#endif
+
 	clk_set_rate(ohci_at91->fclk, 48000000);
 	clk_prepare_enable(ohci_at91->hclk);
 	clk_prepare_enable(ohci_at91->iclk);
@@ -110,6 +125,13 @@ static void at91_stop_clock(struct ohci_at91_priv *ohci_at91)
 	if (!ohci_at91->clocked)
 		return;
 
+#if CONFIG_IS_ENABLED(PHY_MICROCHIP_SAMA7_USB)
+	int i;
+
+	at91_for_each_port(i)
+		generic_phy_power_off(&ohci_at91->phy[i]);
+#endif
+
 	clk_disable_unprepare(ohci_at91->fclk);
 	clk_disable_unprepare(ohci_at91->iclk);
 	clk_disable_unprepare(ohci_at91->hclk);
@@ -215,6 +237,14 @@ static int ohci_atmel_probe(struct udevice *dev)
 		goto fail;
 	}
 
+#if CONFIG_IS_ENABLED(PHY_MICROCHIP_SAMA7_USB)
+	at91_for_each_port(i) {
+		generic_phy_get_by_index(dev, i, &ohci_at91->phy[i]);
+		generic_phy_init(&ohci_at91->phy[i]);
+		generic_phy_configure(&ohci_at91->phy[i], NULL);
+	}
+#endif
+
 	at91_start_hc(dev);
 
 	return ohci_register(dev, regs);
@@ -229,6 +259,7 @@ fail:
 
 static const struct udevice_id ohci_usb_ids[] = {
 	{ .compatible = "atmel,at91rm9200-ohci", },
+	{ .compatible = "microchip,sama7g5-ohci", },
 	{ }
 };
 
Signature · 1 line
2.34.1
#13 lore raw

Re: [PATCH 4/4] usb: ohci-at91: Add USB PHY functionality

Quoted 36 lines · Sergiu Moga

Add the ability to enable/disable whatever USB PHY's are passed to the AT91 OHCI driver through DT.

---
  drivers/usb/host/ohci-at91.c | 31 +++++++++++++++++++++++++++++++
  1 file changed, 31 insertions(+)
drivers/usb/host/ohci-at91.c +8 -0
index 5cf8f283e5..217f31b402 100644
@@ -74,6 +74,10 @@ int usb_cpu_init_fail(void)
  #include <usb.h>
  #include "ohci.h"
 
+#if CONFIG_IS_ENABLED(PHY_MICROCHIP_SAMA7_USB)
+#include <generic-phy.h>
+#endif
+
  #define AT91_MAX_USBH_PORTS        3
 
  #define at91_for_each_port(index)	\
@@ -91,6 +95,10 @@ struct ohci_at91_priv {
  	struct clk *fclk;
  	struct clk *hclk;
  	bool clocked;
+
+#if CONFIG_IS_ENABLED(PHY_MICROCHIP_SAMA7_USB)
+	struct phy phy[AT91_MAX_USBH_PORTS];
+#endif
  };
 
  static void at91_start_clock(struct ohci_at91_priv *ohci_at91)

drivers/usb/host/ohci-at91.c static void at91_start_clock(struct ohci_at91_priv *ohci_at91) · line 109

Quoted 4 lines
drivers/usb/host/ohci-at91.c +1 -0
@@ -98,6 +106,13 @@ static void at91_start_clock(struct ohci_at91_priv *ohci_at91)
  	if (ohci_at91->clocked)
  		return;
 
+#if CONFIG_IS_ENABLED(PHY_MICROCHIP_SAMA7_USB)

Use plain:

if (CONFIG_IS_ENABLED(...)) { ... }

instead of the #if ... , the compiler would optimize the code out correctly.

drivers/usb/host/ohci-at91.c static void at91_start_clock(struct ohci_at91_priv *ohci_at91) · line 113

Quoted 4 lines
drivers/usb/host/ohci-at91.c +4 -0
+	int i;
+
+	at91_for_each_port(i)
+		generic_phy_power_on(&ohci_at91->phy[i]);

Look at generic_phy_get_bulk() and generic_phy_power_on_bulk() and co. those should get rid of this loop altogether.

[...]

#14 lore raw

Re: [PATCH 4/4] usb: ohci-at91: Add USB PHY functionality

Quoted 41 lines · Marek Vasut
Quoted 40 lines · Sergiu Moga

Add the ability to enable/disable whatever USB PHY's are passed to the AT91 OHCI driver through DT.

---
  drivers/usb/host/ohci-at91.c | 31 +++++++++++++++++++++++++++++++

  1 file changed, 31 insertions(+)
drivers/usb/host/ohci-at91.c +8 -0
index 5cf8f283e5..217f31b402 100644
@@ -74,6 +74,10 @@ int usb_cpu_init_fail(void)
   #include <usb.h>
   #include "ohci.h"
 
+#if CONFIG_IS_ENABLED(PHY_MICROCHIP_SAMA7_USB)
+#include <generic-phy.h>
+#endif
+
   #define AT91_MAX_USBH_PORTS        3
 
   #define at91_for_each_port(index)   \
@@ -91,6 +95,10 @@ struct ohci_at91_priv {
       struct clk *fclk;
       struct clk *hclk;
       bool clocked;
+
+#if CONFIG_IS_ENABLED(PHY_MICROCHIP_SAMA7_USB)
+     struct phy phy[AT91_MAX_USBH_PORTS];
+#endif
   };
 
   static void at91_start_clock(struct ohci_at91_priv *ohci_at91)
@@ -98,6 +106,13 @@ static void at91_start_clock(struct ohci_at91_priv 
 *ohci_at91)
       if (ohci_at91->clocked)
               return;
 
Quoted 9 lines

drivers/usb/host/ohci-at91.c static void at91_start_clock(struct ohci_at91_priv · line 110

Quoted 1 line
drivers/usb/host/ohci-at91.c +1 -0
+#if CONFIG_IS_ENABLED(PHY_MICROCHIP_SAMA7_USB)

Use plain:

if (CONFIG_IS_ENABLED(...)) { ... }

instead of the #if ... , the compiler would optimize the code out correctly.

The build system complains that the generic_phy_* methods are not present and, if possible, I would like not to have to enable the PHY related CONFIGs on the boards that do not need it only to avoid these warnings.

Quoted 9 lines

drivers/usb/host/ohci-at91.c static void at91_start_clock(struct ohci_at91_priv *ohci_at91) · line 113

Quoted 4 lines
drivers/usb/host/ohci-at91.c +4 -0
+     int i;
+
+     at91_for_each_port(i)
+             generic_phy_power_on(&ohci_at91->phy[i]);

Look at generic_phy_get_bulk() and generic_phy_power_on_bulk() and co. those should get rid of this loop altogether.

[...]

#15 lore raw

Re: [PATCH 4/4] usb: ohci-at91: Add USB PHY functionality

Quoted 53 lines · On 1/3/23 14:02, [email protected] wrote:
Quoted 41 lines · Marek Vasut
Quoted 40 lines · Sergiu Moga

Add the ability to enable/disable whatever USB PHY's are passed to the AT91 OHCI driver through DT.

---
   drivers/usb/host/ohci-at91.c | 31 +++++++++++++++++++++++++++++++
   1 file changed, 31 insertions(+)
drivers/usb/host/ohci-at91.c +8 -0
index 5cf8f283e5..217f31b402 100644
@@ -74,6 +74,10 @@ int usb_cpu_init_fail(void)
   #include <usb.h>
   #include "ohci.h"
 
+#if CONFIG_IS_ENABLED(PHY_MICROCHIP_SAMA7_USB)
+#include <generic-phy.h>
+#endif
+
   #define AT91_MAX_USBH_PORTS        3
 
   #define at91_for_each_port(index)   \
@@ -91,6 +95,10 @@ struct ohci_at91_priv {
       struct clk *fclk;
       struct clk *hclk;
       bool clocked;
+
+#if CONFIG_IS_ENABLED(PHY_MICROCHIP_SAMA7_USB)
+     struct phy phy[AT91_MAX_USBH_PORTS];
+#endif
   };
 
   static void at91_start_clock(struct ohci_at91_priv *ohci_at91)
@@ -98,6 +106,13 @@ static void at91_start_clock(struct ohci_at91_priv
 *ohci_at91)
       if (ohci_at91->clocked)
               return;
 
Quoted 9 lines

drivers/usb/host/ohci-at91.c static void at91_start_clock(struct ohci_at91_priv · line 110

Quoted 1 line
drivers/usb/host/ohci-at91.c +1 -0
+#if CONFIG_IS_ENABLED(PHY_MICROCHIP_SAMA7_USB)

Use plain:

if (CONFIG_IS_ENABLED(...)) { ... }

instead of the #if ... , the compiler would optimize the code out correctly.

Quoted 4 lines

The build system complains that the generic_phy_* methods are not present and, if possible, I would like not to have to enable the PHY related CONFIGs on the boards that do not need it only to avoid these warnings.

Do include <generic-phy.h> . If CONFIG_PHY is not set, then those generic_phy_*() functions become empty inline functions, where are optimized out by the compiler.

#16 lore raw
In reply to Sergiu Moga
Quoted 19 lines · Sergiu Moga

This patch series originates from a bigger patch series:
https://lists.denx.de/pipermail/u-boot/2022-December/502865.html

Register ohci-at91 driver into Driver Model. 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.
In order to enable USB on SAMA7G5 the addition of the USB 2.0 PHY drivers were required.

Cristian Birsan (1):

   usb: ohci-at91: Add `ohci_t` field in `ohci_at91_priv`

Sergiu Moga (3):
phy: at91: Add support for the USB 2.0 PHY's of SAMA7
usb: ohci-at91: Enable OHCI functionality and register into DM
usb: ohci-at91: Add USB PHY functionality

Quoted 9 lines
  drivers/phy/Kconfig              |  10 ++
  drivers/phy/Makefile             |   1 +
  drivers/phy/phy-sama7-usb.c      |  90 +++++++++++++
  drivers/phy/phy-sama7-utmi-clk.c | 202 +++++++++++++++++++++++++++++
  drivers/usb/host/ohci-at91.c     | 215 +++++++++++++++++++++++++++++++
  5 files changed, 518 insertions(+)

create mode 100644 drivers/phy/phy-sama7-usb.c create mode 100644 drivers/phy/phy-sama7-utmi-clk.c

By the way, this also depends on the following patch series:
https://lists.denx.de/pipermail/u-boot/2022-December/502979.html