All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mattijs Korpershoek <mkorpershoek@baylibre.com>
To: Neil Armstrong <neil.armstrong@linaro.org>,
	Christian Hewitt <christianshewitt@gmail.com>
Cc: u-boot@lists.denx.de,
	Mattijs Korpershoek <mkorpershoek@baylibre.com>,
	Marek Vasut <marex@denx.de>,
	u-boot-amlogic@groups.io
Subject: [PATCH 1/2] usb: dwc3-meson-g12a: force mode on child add/removal
Date: Wed, 23 Nov 2022 16:42:49 +0100	[thread overview]
Message-ID: <20221024-meson-dm-usb-v1-1-2ab077a503b9@baylibre.com> (raw)
In-Reply-To: <20221024-meson-dm-usb-v1-0-2ab077a503b9@baylibre.com>

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.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
---
 drivers/usb/dwc3/dwc3-meson-g12a.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/drivers/usb/dwc3/dwc3-meson-g12a.c b/drivers/usb/dwc3/dwc3-meson-g12a.c
index 90418ddc1dab..c62e42de73f7 100644
--- a/drivers/usb/dwc3/dwc3-meson-g12a.c
+++ b/drivers/usb/dwc3/dwc3-meson-g12a.c
@@ -455,6 +455,22 @@ static int dwc3_meson_g12a_remove(struct udevice *dev)
 	return dm_scan_fdt_dev(dev);
 }
 
+static int dwc3_meson_g12a_child_pre_probe(struct udevice *dev)
+{
+	if (ofnode_device_is_compatible(dev_ofnode(dev), "amlogic,meson-g12a-usb"))
+		return dwc3_meson_g12a_force_mode(dev->parent, USB_DR_MODE_PERIPHERAL);
+
+	return 0;
+}
+
+static int dwc3_meson_g12a_child_post_remove(struct udevice *dev)
+{
+	if (ofnode_device_is_compatible(dev_ofnode(dev), "amlogic,meson-g12a-usb"))
+		return dwc3_meson_g12a_force_mode(dev->parent, USB_DR_MODE_HOST);
+
+	return 0;
+}
+
 static const struct udevice_id dwc3_meson_g12a_ids[] = {
 	{ .compatible = "amlogic,meson-g12a-usb-ctrl" },
 	{ }
@@ -466,6 +482,8 @@ U_BOOT_DRIVER(dwc3_generic_wrapper) = {
 	.of_match = dwc3_meson_g12a_ids,
 	.probe = dwc3_meson_g12a_probe,
 	.remove = dwc3_meson_g12a_remove,
+	.child_pre_probe = dwc3_meson_g12a_child_pre_probe,
+	.child_post_remove = dwc3_meson_g12a_child_post_remove,
 	.plat_auto	= sizeof(struct dwc3_meson_g12a),
 
 };

-- 
b4 0.10.1

  reply	other threads:[~2022-11-23 15:43 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-23 15:42 [PATCH 0/2] mach-meson: port dwc2_otg usage to CONFIG_DM_USB_GADGET=y Mattijs Korpershoek
2022-11-23 15:42 ` Mattijs Korpershoek [this message]
2022-11-23 15:42 ` [PATCH 2/2] ARM: meson: g12a: switch dwc2 otg to DM Mattijs Korpershoek
2022-11-24  9:34 ` [PATCH 0/2] mach-meson: port dwc2_otg usage to CONFIG_DM_USB_GADGET=y Neil Armstrong
2022-12-14 14:45   ` Mattijs Korpershoek
2022-12-14 14:49     ` neil.armstrong
2022-12-14 14:49       ` Neil Armstrong
2023-01-10 11:01       ` Mattijs Korpershoek
2023-01-10 14:25         ` neil.armstrong
2023-01-10 14:25           ` Neil Armstrong
2023-01-17  8:27 ` Neil Armstrong

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=20221024-meson-dm-usb-v1-1-2ab077a503b9@baylibre.com \
    --to=mkorpershoek@baylibre.com \
    --cc=christianshewitt@gmail.com \
    --cc=marex@denx.de \
    --cc=neil.armstrong@linaro.org \
    --cc=u-boot-amlogic@groups.io \
    --cc=u-boot@lists.denx.de \
    /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 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.