From: Michael Grzeschik <mgr-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
To: Alexander Shishkin
<alexander.shishkin-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
balbi-l0cyMroinI0@public.gmane.org,
devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org,
kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org,
Michael Grzeschik
<m.grzeschik-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
Subject: Re: [PATCH 1/7] USB: add devicetree helpers for determining dr_mode and phy_type
Date: Tue, 4 Jun 2013 15:01:40 +0200 [thread overview]
Message-ID: <20130604130140.GF28181@pengutronix.de> (raw)
In-Reply-To: <8761xvjrwt.fsf-qxRn5AmX6ZD9BXuAQUXR0fooFf0ArEBIu+b9c/7xato@public.gmane.org>
On Mon, Jun 03, 2013 at 03:32:50PM +0300, Alexander Shishkin wrote:
> Michael Grzeschik <mgr-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> writes:
>
> > From: Michael Grzeschik <m.grzeschik-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> >
> > This adds two little devicetree helper functions for determining the
> > dr_mode (host, peripheral, otg) and phy_type (utmi, ulpi,...) from
> > the devicetree.
>
> This one needs an ack from Felipe.
Right, we currently also wait for his answer in another thread.
http://www.spinics.net/lists/linux-usb/msg86906.html
> > Signed-off-by: Michael Grzeschik <m.grzeschik-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> > Signed-off-by: Marc Kleine-Budde <mkl-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> > Signed-off-by: Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> > ---
> > drivers/usb/phy/Makefile | 1 +
> > drivers/usb/phy/of.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
> > drivers/usb/usb-common.c | 35 +++++++++++++++++++++++++++++++++++
> > include/linux/usb/of.h | 28 ++++++++++++++++++++++++++++
> > include/linux/usb/otg.h | 7 +++++++
> > include/linux/usb/phy.h | 9 +++++++++
> > 6 files changed, 127 insertions(+)
> > create mode 100644 drivers/usb/phy/of.c
> > create mode 100644 include/linux/usb/of.h
> >
> > diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile
> > index a9169cb..070eca3 100644
> > --- a/drivers/usb/phy/Makefile
> > +++ b/drivers/usb/phy/Makefile
> > @@ -5,6 +5,7 @@
> > ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
> >
> > obj-$(CONFIG_USB_PHY) += phy.o
> > +obj-$(CONFIG_OF) += of.o
> >
> > # transceiver drivers, keep the list sorted
> >
> > diff --git a/drivers/usb/phy/of.c b/drivers/usb/phy/of.c
> > new file mode 100644
> > index 0000000..e6f3b74
> > --- /dev/null
> > +++ b/drivers/usb/phy/of.c
> > @@ -0,0 +1,47 @@
> > +/*
> > + * USB of helper code
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License as published by
> > + * the Free Software Foundation; either version 2 of the License, or
> > + * (at your option) any later version.
> > + */
> > +
> > +#include <linux/kernel.h>
> > +#include <linux/module.h>
> > +#include <linux/of.h>
> > +#include <linux/usb/of.h>
> > +#include <linux/usb/otg.h>
> > +
> > +static const char *usbphy_modes[] = {
> > + [USBPHY_INTERFACE_MODE_UNKNOWN] = "",
> > + [USBPHY_INTERFACE_MODE_UTMI] = "utmi",
> > + [USBPHY_INTERFACE_MODE_UTMIW] = "utmi_wide",
> > + [USBPHY_INTERFACE_MODE_ULPI] = "ulpi",
> > + [USBPHY_INTERFACE_MODE_SERIAL] = "serial",
> > + [USBPHY_INTERFACE_MODE_HSIC] = "hsic",
> > +};
> > +
> > +/**
> > + * of_usb_get_phy_mode - Get phy mode for given device_node
> > + * @np: Pointer to the given device_node
> > + *
> > + * The function gets phy interface string from property 'phy_type',
> > + * and returns the correspondig enum usb_phy_interface
> > + */
> > +enum usb_phy_interface of_usb_get_phy_mode(struct device_node *np)
> > +{
> > + const char *phy_type;
> > + int err, i;
> > +
> > + err = of_property_read_string(np, "phy_type", &phy_type);
> > + if (err < 0)
> > + return USBPHY_INTERFACE_MODE_UNKNOWN;
> > +
> > + for (i = 0; i < ARRAY_SIZE(usbphy_modes); i++)
> > + if (!strcmp(phy_type, usbphy_modes[i]))
> > + return i;
> > +
> > + return USBPHY_INTERFACE_MODE_UNKNOWN;
> > +}
> > +EXPORT_SYMBOL_GPL(of_usb_get_phy_mode);
> > diff --git a/drivers/usb/usb-common.c b/drivers/usb/usb-common.c
> > index 0db0a91..027582d 100644
> > --- a/drivers/usb/usb-common.c
> > +++ b/drivers/usb/usb-common.c
> > @@ -13,7 +13,9 @@
> >
> > #include <linux/kernel.h>
> > #include <linux/module.h>
> > +#include <linux/of.h>
> > #include <linux/usb/ch9.h>
> > +#include <linux/usb/of.h>
> > #include <linux/usb/otg.h>
> >
> > const char *usb_otg_state_string(enum usb_otg_state state)
> > @@ -79,4 +81,37 @@ const char *usb_state_string(enum usb_device_state state)
> > }
> > EXPORT_SYMBOL_GPL(usb_state_string);
> >
> > +#ifdef CONFIG_OF
> > +static const char *usb_dr_modes[] = {
> > + [USB_DR_MODE_UNKNOWN] = "",
> > + [USB_DR_MODE_HOST] = "host",
> > + [USB_DR_MODE_PERIPHERAL] = "peripheral",
> > + [USB_DR_MODE_OTG] = "otg",
> > +};
> > +
> > +/**
> > + * of_usb_get_dr_mode - Get dual role mode for given device_node
> > + * @np: Pointer to the given device_node
> > + *
> > + * The function gets phy interface string from property 'dr_mode',
> > + * and returns the correspondig enum usb_dr_mode
> > + */
> > +enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np)
> > +{
> > + const char *dr_mode;
> > + int err, i;
> > +
> > + err = of_property_read_string(np, "dr_mode", &dr_mode);
> > + if (err < 0)
> > + return USB_DR_MODE_UNKNOWN;
> > +
> > + for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++)
> > + if (!strcmp(dr_mode, usb_dr_modes[i]))
> > + return i;
> > +
> > + return USB_DR_MODE_UNKNOWN;
> > +}
> > +EXPORT_SYMBOL_GPL(of_usb_get_dr_mode);
> > +#endif
> > +
> > MODULE_LICENSE("GPL");
> > diff --git a/include/linux/usb/of.h b/include/linux/usb/of.h
> > new file mode 100644
> > index 0000000..e460a24
> > --- /dev/null
> > +++ b/include/linux/usb/of.h
> > @@ -0,0 +1,28 @@
> > +/*
> > + * OF helpers for usb devices.
> > + *
> > + * This file is released under the GPLv2
> > + */
> > +
> > +#ifndef __LINUX_USB_OF_H
> > +#define __LINUX_USB_OF_H
> > +
> > +#include <linux/usb/otg.h>
> > +#include <linux/usb/phy.h>
> > +
> > +#ifdef CONFIG_OF
> > +enum usb_phy_interface of_usb_get_phy_mode(struct device_node *np);
> > +enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np);
> > +#else
> > +static inline enum usb_phy_interface of_usb_get_phy_mode(struct device_node *np)
> > +{
> > + return USBPHY_INTERFACE_MODE_UNKNOWN;
> > +}
> > +
> > +static inline enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np)
> > +{
> > + return USB_DR_MODE_UNKNOWN;
> > +}
> > +#endif
> > +
> > +#endif /* __LINUX_USB_OF_H */
> > diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h
> > index 291e01b..154332b 100644
> > --- a/include/linux/usb/otg.h
> > +++ b/include/linux/usb/otg.h
> > @@ -92,4 +92,11 @@ otg_start_srp(struct usb_otg *otg)
> > /* for OTG controller drivers (and maybe other stuff) */
> > extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num);
> >
> > +enum usb_dr_mode {
> > + USB_DR_MODE_UNKNOWN,
> > + USB_DR_MODE_HOST,
> > + USB_DR_MODE_PERIPHERAL,
> > + USB_DR_MODE_OTG,
> > +};
> > +
>
> I would suggest turning this into a bitmask, so that further tests look
> like
>
> if (dr_mode & USB_DR_MODE_HOST) {...}
>
> instead of how they currently look like in the other patch.
You mean 32 modes will be enough? :)
These helpers are derived from drivers/of/of_net.c. Its enums are
commonly used all over the kernel. We should align to already used
coding patterns. I also prefer to switch over an enum than compare bits.
Thanks,
Michael
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2013-06-04 13:01 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-31 18:38 [PATCH v6 0/7] USB: add devicetree helpers for determining dr_mode and phy_type Michael Grzeschik
[not found] ` <1370025529-7414-1-git-send-email-mgr-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2013-05-31 18:38 ` [PATCH 1/7] " Michael Grzeschik
[not found] ` <1370025529-7414-2-git-send-email-mgr-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2013-06-03 12:32 ` Alexander Shishkin
[not found] ` <8761xvjrwt.fsf-qxRn5AmX6ZD9BXuAQUXR0fooFf0ArEBIu+b9c/7xato@public.gmane.org>
2013-06-04 13:01 ` Michael Grzeschik [this message]
[not found] ` <20130604130140.GF28181-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2013-06-04 20:25 ` Felipe Balbi
2013-05-31 18:38 ` [PATCH 2/7] USB: chipidea: ci13xxx-imx: move static pdata into probe function Michael Grzeschik
[not found] ` <1370025529-7414-3-git-send-email-mgr-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2013-06-05 12:29 ` Michael Grzeschik
[not found] ` <20130605122906.GB20095-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2013-06-05 13:04 ` Alexander Shishkin
2013-05-31 18:38 ` [PATCH 3/7] USB: chipidea: add PTW, PTS and STS handling Michael Grzeschik
[not found] ` <1370025529-7414-4-git-send-email-mgr-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2013-06-03 12:35 ` Alexander Shishkin
[not found] ` <8738szjrs6.fsf-qxRn5AmX6ZD9BXuAQUXR0fooFf0ArEBIu+b9c/7xato@public.gmane.org>
2013-06-03 16:11 ` Michael Grzeschik
[not found] ` <20130603161136.GB28181-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2013-06-04 9:22 ` Alexander Shishkin
2013-06-06 10:54 ` Michael Grzeschik
2013-05-31 18:38 ` [PATCH 4/7] USB chipidea: introduce dual role mode pdata flags Michael Grzeschik
[not found] ` <1370025529-7414-5-git-send-email-mgr-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2013-06-03 12:37 ` Alexander Shishkin
[not found] ` <87zjv7id52.fsf-qxRn5AmX6ZD9BXuAQUXR0fooFf0ArEBIu+b9c/7xato@public.gmane.org>
2013-06-04 1:42 ` Peter Chen
[not found] ` <CAL411-pMnJC55M3n5bAuffH3pwRZTzhBfDiEfT+egtGN29c7uw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-06-04 9:31 ` Alexander Shishkin
[not found] ` <87ehcii5n0.fsf-qxRn5AmX6ZD9BXuAQUXR0fooFf0ArEBIu+b9c/7xato@public.gmane.org>
2013-06-04 10:09 ` Peter Chen
[not found] ` <CAL411-pyrFXxyEX_GAFRS5ubh_Pf2yWLZXYC3PJevu1WSJS78g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-06-04 11:09 ` Alexander Shishkin
2013-05-31 18:38 ` [PATCH 5/7] USB chipidea i.MX: use devm_usb_get_phy_by_phandle to get phy Michael Grzeschik
[not found] ` <1370025529-7414-6-git-send-email-mgr-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2013-05-31 19:23 ` Sergei Shtylyov
2013-06-03 12:39 ` Alexander Shishkin
2013-05-31 18:38 ` [PATCH 6/7] usb: chipidea: udc: add force-full-speed option Michael Grzeschik
[not found] ` <1370025529-7414-7-git-send-email-mgr-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2013-06-01 7:39 ` Sascha Hauer
[not found] ` <20130601073933.GK32299-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2013-06-01 8:19 ` Michael Grzeschik
[not found] ` <20130601081932.GA28181-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2013-06-01 9:21 ` Sascha Hauer
[not found] ` <20130601092151.GP32299-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2013-06-03 12:40 ` Alexander Shishkin
2013-05-31 18:38 ` [PATCH 7/7] usb: chipidea: usbmisc: use module_platform_driver Michael Grzeschik
[not found] ` <1370025529-7414-8-git-send-email-mgr-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2013-06-03 12:41 ` Alexander Shishkin
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=20130604130140.GF28181@pengutronix.de \
--to=mgr-bicnvbalz9megne8c9+irq@public.gmane.org \
--cc=alexander.shishkin-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
--cc=balbi-l0cyMroinI0@public.gmane.org \
--cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org \
--cc=kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org \
--cc=linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=m.grzeschik-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.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 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.