diff mbox series

[1/2] usb: dwc3-meson-gxl: force mode on child add/removal

Message ID 20230117-u-boot-usb-gxl-otg-dm-v1-1-2853f6d75b06@linaro.org
State Accepted
Commit 043a9674b64741e02b99e9c5ad2e4ee5a1c841d5
Headers show
Series mach-meson: port GXL & AXG dwc2_otg usage to CONFIG_DM_USB_GADGET=y | expand

Commit Message

Neil Armstrong Jan. 17, 2023, 9:11 a.m. UTC
arch/mach-meson has some custom usb logic, in particular:
* on board_usb_init(), we force USB_DR_MODE_PERIPHERAL
* on board_usb_cleanup(), we force USB_DR_MODE_HOST

With DM_USB_GADGET=y, board_usb_init/cleanup() are no
longer used when we call usb_gadget_initialize().
Instead, the generic (from udc-uclass) initialization/release is
called, which itself calls the controller driver's probe()/remove().

Therefore, enabling DM_USB_GADGET=y will mean that this mode
switching will break.

To prepare for enabling DM_USB_GADGET, perform the mode switching
when the "amlogic,meson-g12a-usb" (dwc2) driver is
probed()/removed() instead.

This is achieved via the glue driver, which gets notified each time one
of its children is probed()/removed.

Note: this change should be harmless without DM_USB_GADGET=y
because the amlogic-g12a-usb driver is not probed via driver model.

Thanks for Mattijs for the original work at [1].

[1] https://lore.kernel.org/all/20221024-meson-dm-usb-v1-1-2ab077a503b9@baylibre.com/

Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
---
 drivers/usb/dwc3/dwc3-meson-gxl.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Comments

Mattijs Korpershoek Jan. 17, 2023, 9:43 a.m. UTC | #1
On Tue, Jan 17, 2023 at 10:11, Neil Armstrong <neil.armstrong@linaro.org> wrote:

> arch/mach-meson has some custom usb logic, in particular:
> * on board_usb_init(), we force USB_DR_MODE_PERIPHERAL
> * on board_usb_cleanup(), we force USB_DR_MODE_HOST
>
> With DM_USB_GADGET=y, board_usb_init/cleanup() are no
> longer used when we call usb_gadget_initialize().
> Instead, the generic (from udc-uclass) initialization/release is
> called, which itself calls the controller driver's probe()/remove().
>
> Therefore, enabling DM_USB_GADGET=y will mean that this mode
> switching will break.
>
> To prepare for enabling DM_USB_GADGET, perform the mode switching
> when the "amlogic,meson-g12a-usb" (dwc2) driver is
> probed()/removed() instead.
>
> This is achieved via the glue driver, which gets notified each time one
> of its children is probed()/removed.
>
> Note: this change should be harmless without DM_USB_GADGET=y
> because the amlogic-g12a-usb driver is not probed via driver model.
>
> Thanks for Mattijs for the original work at [1].
>
> [1] https://lore.kernel.org/all/20221024-meson-dm-usb-v1-1-2ab077a503b9@baylibre.com/
>
> Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>

Thank you for mentioning me, I appreciate it.

Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

> ---
>  drivers/usb/dwc3/dwc3-meson-gxl.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
>
> diff --git a/drivers/usb/dwc3/dwc3-meson-gxl.c b/drivers/usb/dwc3/dwc3-meson-gxl.c
> index 6c6d463203..d56f2747b6 100644
> --- a/drivers/usb/dwc3/dwc3-meson-gxl.c
> +++ b/drivers/usb/dwc3/dwc3-meson-gxl.c
> @@ -408,6 +408,22 @@ static int dwc3_meson_gxl_remove(struct udevice *dev)
>  	return dm_scan_fdt_dev(dev);
>  }
>  
> +static int dwc3_meson_gxl_child_pre_probe(struct udevice *dev)
> +{
> +	if (ofnode_device_is_compatible(dev_ofnode(dev), "amlogic,meson-g12a-usb"))
> +		return dwc3_meson_gxl_force_mode(dev->parent, USB_DR_MODE_PERIPHERAL);
> +
> +	return 0;
> +}
> +
> +static int dwc3_meson_gxl_child_post_remove(struct udevice *dev)
> +{
> +	if (ofnode_device_is_compatible(dev_ofnode(dev), "amlogic,meson-g12a-usb"))
> +		return dwc3_meson_gxl_force_mode(dev->parent, USB_DR_MODE_HOST);
> +
> +	return 0;
> +}
> +
>  static const struct udevice_id dwc3_meson_gxl_ids[] = {
>  	{ .compatible = "amlogic,meson-axg-usb-ctrl" },
>  	{ .compatible = "amlogic,meson-gxl-usb-ctrl" },
> @@ -421,6 +437,8 @@ U_BOOT_DRIVER(dwc3_generic_wrapper) = {
>  	.of_match = dwc3_meson_gxl_ids,
>  	.probe = dwc3_meson_gxl_probe,
>  	.remove = dwc3_meson_gxl_remove,
> +	.child_pre_probe = dwc3_meson_gxl_child_pre_probe,
> +	.child_post_remove = dwc3_meson_gxl_child_post_remove,
>  	.plat_auto	= sizeof(struct dwc3_meson_gxl),
>  
>  };
>
> -- 
> 2.34.1
Marek Vasut Jan. 17, 2023, 10:06 a.m. UTC | #2
On 1/17/23 10:43, Mattijs Korpershoek wrote:
> On Tue, Jan 17, 2023 at 10:11, Neil Armstrong <neil.armstrong@linaro.org> wrote:
> 
>> arch/mach-meson has some custom usb logic, in particular:
>> * on board_usb_init(), we force USB_DR_MODE_PERIPHERAL
>> * on board_usb_cleanup(), we force USB_DR_MODE_HOST
>>
>> With DM_USB_GADGET=y, board_usb_init/cleanup() are no
>> longer used when we call usb_gadget_initialize().
>> Instead, the generic (from udc-uclass) initialization/release is
>> called, which itself calls the controller driver's probe()/remove().
>>
>> Therefore, enabling DM_USB_GADGET=y will mean that this mode
>> switching will break.
>>
>> To prepare for enabling DM_USB_GADGET, perform the mode switching
>> when the "amlogic,meson-g12a-usb" (dwc2) driver is
>> probed()/removed() instead.
>>
>> This is achieved via the glue driver, which gets notified each time one
>> of its children is probed()/removed.
>>
>> Note: this change should be harmless without DM_USB_GADGET=y
>> because the amlogic-g12a-usb driver is not probed via driver model.
>>
>> Thanks for Mattijs for the original work at [1].
>>
>> [1] https://lore.kernel.org/all/20221024-meson-dm-usb-v1-1-2ab077a503b9@baylibre.com/
>>
>> Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
> 
> Thank you for mentioning me, I appreciate it.
> 
> Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

Reviewed-by: Marek Vasut <marex@denx.de>

Feel free to pull via amlogic tree, so it goes together with the config 
change.
diff mbox series

Patch

diff --git a/drivers/usb/dwc3/dwc3-meson-gxl.c b/drivers/usb/dwc3/dwc3-meson-gxl.c
index 6c6d463203..d56f2747b6 100644
--- a/drivers/usb/dwc3/dwc3-meson-gxl.c
+++ b/drivers/usb/dwc3/dwc3-meson-gxl.c
@@ -408,6 +408,22 @@  static int dwc3_meson_gxl_remove(struct udevice *dev)
 	return dm_scan_fdt_dev(dev);
 }
 
+static int dwc3_meson_gxl_child_pre_probe(struct udevice *dev)
+{
+	if (ofnode_device_is_compatible(dev_ofnode(dev), "amlogic,meson-g12a-usb"))
+		return dwc3_meson_gxl_force_mode(dev->parent, USB_DR_MODE_PERIPHERAL);
+
+	return 0;
+}
+
+static int dwc3_meson_gxl_child_post_remove(struct udevice *dev)
+{
+	if (ofnode_device_is_compatible(dev_ofnode(dev), "amlogic,meson-g12a-usb"))
+		return dwc3_meson_gxl_force_mode(dev->parent, USB_DR_MODE_HOST);
+
+	return 0;
+}
+
 static const struct udevice_id dwc3_meson_gxl_ids[] = {
 	{ .compatible = "amlogic,meson-axg-usb-ctrl" },
 	{ .compatible = "amlogic,meson-gxl-usb-ctrl" },
@@ -421,6 +437,8 @@  U_BOOT_DRIVER(dwc3_generic_wrapper) = {
 	.of_match = dwc3_meson_gxl_ids,
 	.probe = dwc3_meson_gxl_probe,
 	.remove = dwc3_meson_gxl_remove,
+	.child_pre_probe = dwc3_meson_gxl_child_pre_probe,
+	.child_post_remove = dwc3_meson_gxl_child_post_remove,
 	.plat_auto	= sizeof(struct dwc3_meson_gxl),
 
 };