From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
BAREBOX <barebox@lists.infradead.org>
Subject: Re: [PATCH 1/4] usb: otg: Add function to set dr_mode
Date: Mon, 20 Apr 2026 12:42:35 +0200 [thread overview]
Message-ID: <1165e329-6af8-4763-bf32-9ef49db33b5a@pengutronix.de> (raw)
In-Reply-To: <20260420-usb-typec-stusb160x-v1-1-5875bbae80ab@pengutronix.de>
Hi,
On 4/20/26 11:02 AM, Sascha Hauer wrote:
> So far we can only set the dr_mode on the command line. Add a function
> for it.
>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
> drivers/usb/otg/otgdev.c | 20 ++++++++++++++++++++
> include/linux/usb/usb.h | 1 +
> 2 files changed, 21 insertions(+)
>
> diff --git a/drivers/usb/otg/otgdev.c b/drivers/usb/otg/otgdev.c
> index 5a86263430..50d8105be3 100644
> --- a/drivers/usb/otg/otgdev.c
> +++ b/drivers/usb/otg/otgdev.c
> @@ -74,6 +74,26 @@ int otg_device_get_mode(struct device *dev)
> return otg->cur_mode;
> }
>
> +int otg_device_set_dr_mode(struct device *dev, enum usb_dr_mode mode)
> +{
> + struct otg_mode *otg;
> + int ret;
> +
> + if (dev->bus != &otg_bus_type)
> + return -ENODEV;
> +
> + otg = dev->priv;
> +
> + ret = otg->set_mode_callback(otg->ctx, mode);
> + if (ret)
> + return ret;
This doesn't guard against switching from peripheral to host and back
unlike the param version, which only allows switching away from otg.
I think the existing logic should be moved into this function and
otg_set_mode changed to a wrapper around it.
> +
> + otg->cur_mode = mode;
> + otg->var_mode = mode;
> +
> + return 0;
> +}
> +
> int usb_register_otg_device(struct device *parent,
> int (*set_mode)(void *ctx, enum usb_dr_mode mode), void *ctx)
> {
> diff --git a/include/linux/usb/usb.h b/include/linux/usb/usb.h
> index c25f3d73c3..6aa9e55cc9 100644
> --- a/include/linux/usb/usb.h
> +++ b/include/linux/usb/usb.h
> @@ -477,6 +477,7 @@ int usb_register_otg_device(struct device *parent,
> int (*set_mode)(void *ctx, enum usb_dr_mode mode), void *ctx);
>
> int otg_device_get_mode(struct device *dev);
> +int otg_device_set_dr_mode(struct device *dev, enum usb_dr_mode mode);
>
> extern struct bus_type otg_bus_type;
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
next prev parent reply other threads:[~2026-04-20 10:43 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-20 9:02 [PATCH 0/4] usb: typec: STUSB160x support Sascha Hauer
2026-04-20 9:02 ` [PATCH 1/4] usb: otg: Add function to set dr_mode Sascha Hauer
2026-04-20 10:42 ` Ahmad Fatoum [this message]
2026-04-20 9:02 ` [PATCH 2/4] usb: typec: wire USB role changes to OTG device Sascha Hauer
2026-04-20 11:08 ` Ahmad Fatoum
2026-04-20 12:02 ` Sascha Hauer
2026-04-20 9:02 ` [PATCH 3/4] usb: typec: add typec_find_port_power_role() and typec_find_pwr_opmode() Sascha Hauer
2026-04-20 9:02 ` [PATCH 4/4] USB: typec: Add STUSB160x driver Sascha Hauer
2026-04-20 11:14 ` Ahmad Fatoum
2026-04-20 11:30 ` Sascha Hauer
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=1165e329-6af8-4763-bf32-9ef49db33b5a@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox