mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 5/5] usb: musb: use usb_register_otg_device()
Date: Thu, 21 Nov 2019 12:12:26 +0100	[thread overview]
Message-ID: <20191121111226.5036-5-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20191121111226.5036-1-s.hauer@pengutronix.de>

We now have usb_register_otg_device() to register an "otg" device. Use
it and drop the custom code.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/usb/musb/Kconfig     |  1 +
 drivers/usb/musb/musb_dsps.c | 44 ++++++------------------------------
 2 files changed, 8 insertions(+), 37 deletions(-)

diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index b795f30275..127d6d1955 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -6,6 +6,7 @@ if USB_MUSB
 config USB_MUSB_DSPS
 	tristate
 	select OFDEVICE
+	select USB_OTGDEV
 
 config USB_MUSB_AM335X
 	tristate "AM335x USB support"
diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c
index 5fe3bcb7cd..3b76b6cc61 100644
--- a/drivers/usb/musb/musb_dsps.c
+++ b/drivers/usb/musb/musb_dsps.c
@@ -303,50 +303,20 @@ static int get_musb_port_mode(struct device_d *dev)
 	}
 }
 
-static int dsps_set_mode(struct param_d *param, void *priv)
+static int dsps_set_mode(void *ctx, enum usb_dr_mode mode)
 {
-	struct dsps_glue *glue = priv;
+	struct dsps_glue *glue = ctx;
 
-	if (glue->pdata.mode != MUSB_PORT_MODE_DUAL_ROLE)
-		return -EBUSY;
-
-	switch (glue->otgmode) {
-	case 0:
-	default:
-		return -EINVAL;
-	case 1:
+	if (mode == USB_DR_MODE_HOST)
 		glue->pdata.mode = MUSB_PORT_MODE_HOST;
-		break;
-	case 2:
+	else if (mode == USB_DR_MODE_PERIPHERAL)
 		glue->pdata.mode = MUSB_PORT_MODE_GADGET;
-		break;
-	}
+	else
+		return -EINVAL;
 
 	return musb_init_controller(&glue->musb, &glue->pdata);
 }
 
-static const char *dsps_mode_names[] = {
-	"otg", "host", "peripheral"
-};
-
-static int dsps_register_otg_device(struct dsps_glue *glue)
-{
-	int ret;
-
-	dev_set_name(&glue->otg_dev, "otg");
-	glue->otg_dev.id = DEVICE_ID_DYNAMIC,
-	glue->otg_dev.parent = glue->dev;
-
-	ret = register_device(&glue->otg_dev);
-	if (ret)
-		return ret;
-
-	dev_add_param_enum(&glue->otg_dev, "mode",
-			dsps_set_mode, NULL, &glue->otgmode,
-			dsps_mode_names, ARRAY_SIZE(dsps_mode_names), glue);
-	return 0;
-}
-
 static int dsps_probe(struct device_d *dev)
 {
 	struct resource *iores;
@@ -405,7 +375,7 @@ static int dsps_probe(struct device_d *dev)
 	config->multipoint = of_property_read_bool(dn, "mentor,multipoint");
 
 	if (pdata->mode == MUSB_PORT_MODE_DUAL_ROLE) {
-		ret = dsps_register_otg_device(glue);
+		ret = usb_register_otg_device(dev, dsps_set_mode, glue);
 		if (ret)
 			return ret;
 		return 0;
-- 
2.24.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

      parent reply	other threads:[~2019-11-21 11:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-21 11:12 [PATCH 1/5] usb: dwc3: remove unnecessary warning Sascha Hauer
2019-11-21 11:12 ` [PATCH 2/5] usb: Add function to register otg dev Sascha Hauer
2019-11-21 11:12 ` [PATCH 3/5] usb: dwc3: register otg device Sascha Hauer
2019-11-21 11:12 ` [PATCH 4/5] usb: i.MX: Use usb_register_otg_device() Sascha Hauer
2019-11-21 11:12 ` Sascha Hauer [this message]

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=20191121111226.5036-5-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox