[PATCH,RFC] usb: add devicetree helpers for determining dr_mode and phy_type

2013-01-29 Thread Sascha Hauer
From: Michael Grzeschik 

This adds two little devicetree helper functions for determining the
dr_mode (host, peripheral, otg) and phy_type (utmi, ulpi,...) from
the devicetree.

Signed-off-by: Michael Grzeschik 
Signed-off-by: Marc Kleine-Budde 
---

The properties and their values have been taken from the fsl-mph-dr driver.
This binding is also documented (though currently not used) for the tegra
ehci driver (Documentation/devicetree/bindings/usb/nvidia,tegra20-ehci.txt).
This is a first attempt to parse these bindings at a common place so that
others can make use of it.

Basically I want to know whether this binding is recommended for new drivers
since normally the devicetree uses '-' instead of '_', and maybe there are
other problems with it.

I need this binding for the chipidea driver. I suspect that the fsl-mph-dr
driver also really handles a chipidea core.

Should we agree on this I would convert the fsl-mph-dr driver to use these
helpers.

Sascha

 drivers/usb/core/Makefile |1 +
 drivers/usb/core/of.c |   76 +
 include/linux/usb/of.h|   22 +
 include/linux/usb/phy.h   |9 ++
 4 files changed, 108 insertions(+)
 create mode 100644 drivers/usb/core/of.c
 create mode 100644 include/linux/usb/of.h

diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile
index 26059b9..5378add 100644
--- a/drivers/usb/core/Makefile
+++ b/drivers/usb/core/Makefile
@@ -10,5 +10,6 @@ usbcore-y += devio.o notify.o generic.o quirks.o devices.o
 
 usbcore-$(CONFIG_PCI)  += hcd-pci.o
 usbcore-$(CONFIG_ACPI) += usb-acpi.o
+usbcore-$(CONFIG_OF)   += of.o
 
 obj-$(CONFIG_USB)  += usbcore.o
diff --git a/drivers/usb/core/of.c b/drivers/usb/core/of.c
new file mode 100644
index 000..d000d9f
--- /dev/null
+++ b/drivers/usb/core/of.c
@@ -0,0 +1,76 @@
+/*
+ * OF helpers for usb devices.
+ *
+ * This file is released under the GPLv2
+ *
+ * Initially copied out of drivers/of/of_net.c
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static const char *usbphy_modes[] = {
+   [USBPHY_INTERFACE_MODE_NA]  = "",
+   [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_get_usbphy_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_NA;
+
+   for (i = 0; i < ARRAY_SIZE(usbphy_modes); i++)
+   if (!strcasecmp(phy_type, usbphy_modes[i]))
+   return i;
+
+   return USBPHY_INTERFACE_MODE_NA;
+}
+EXPORT_SYMBOL_GPL(of_usb_get_phy_mode);
+
+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_phy_dr_mode
+ */
+enum usb_phy_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 (!strcasecmp(dr_mode, usb_dr_modes[i]))
+   return i;
+
+   return USB_DR_MODE_UNKNOWN;
+}
+EXPORT_SYMBOL_GPL(of_usb_get_dr_mode);
diff --git a/include/linux/usb/of.h b/include/linux/usb/of.h
new file mode 100644
index 000..582ba96
--- /dev/null
+++ b/include/linux/usb/of.h
@@ -0,0 +1,22 @@
+/*
+ * OF helpers for usb devices.
+ *
+ * This file is released under the GPLv2
+ */
+
+#ifndef __LINUX_USB_OF_H
+#define __LINUX_USB_OF_H
+
+#include 
+
+enum usb_phy_dr_mode {
+   USB_DR_MODE_UNKNOWN,
+   USB_DR_MODE_HOST,
+   USB_DR_MODE_PERIPHERAL,
+   USB_DR_MODE_OTG,
+};
+
+enum usb_phy_interface of_usb_get_phy_mode(struct device_node *np);
+enum usb_phy_dr_mode of_usb_get_dr_mode(struct device_node *np);
+
+#endif /* __LINUX_USB_OF_H */
diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h
index a29ae1e..c5154cf 100644
--- a/include/linux/usb/phy.h
+++ b/include/linux/usb/phy.h
@@ -12,6 +12,15 @@
 #include 
 #include 
 
+enum usb_phy_interface {
+

Re: [PATCH,RFC] usb: add devicetree helpers for determining dr_mode and phy_type

2013-01-29 Thread Sascha Hauer
On Tue, Jan 29, 2013 at 07:14:51PM +0530, kishon wrote:
> Hi,
> 
> On Tuesday 29 January 2013 04:52 PM, Sascha Hauer wrote:
> >From: Michael Grzeschik 
> >
> >This adds two little devicetree helper functions for determining the
> >dr_mode (host, peripheral, otg) and phy_type (utmi, ulpi,...) from
> >the devicetree.
> >
> >Signed-off-by: Michael Grzeschik 
> >Signed-off-by: Marc Kleine-Budde 
> >---
> >
> >The properties and their values have been taken from the fsl-mph-dr driver.
> >This binding is also documented (though currently not used) for the tegra
> >ehci driver (Documentation/devicetree/bindings/usb/nvidia,tegra20-ehci.txt).
> >This is a first attempt to parse these bindings at a common place so that
> >others can make use of it.
> >
> >Basically I want to know whether this binding is recommended for new drivers
> >since normally the devicetree uses '-' instead of '_', and maybe there are
> >other problems with it.
> >
> >I need this binding for the chipidea driver. I suspect that the fsl-mph-dr
> >driver also really handles a chipidea core.
> >
> >Should we agree on this I would convert the fsl-mph-dr driver to use these
> >helpers.
> >
> >Sascha
> >
> >  drivers/usb/core/Makefile |1 +
> >  drivers/usb/core/of.c |   76 
> > +
> 
> This file should ideally go into drivers/usb/phy/.

I originally wanted to do that, but the host/peripheral/otg property is
not phy specific. DO you still want to move it there?

> >  include/linux/usb/of.h|   22 +
> >  include/linux/usb/phy.h   |9 ++
> >  4 files changed, 108 insertions(+)
> >  create mode 100644 drivers/usb/core/of.c
> >  create mode 100644 include/linux/usb/of.h
> >
> >diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile
> >index 26059b9..5378add 100644
> >--- a/drivers/usb/core/Makefile
> >+++ b/drivers/usb/core/Makefile
> >@@ -10,5 +10,6 @@ usbcore-y += devio.o notify.o generic.o quirks.o devices.o
> >
> >  usbcore-$(CONFIG_PCI)  += hcd-pci.o
> >  usbcore-$(CONFIG_ACPI) += usb-acpi.o
> >+usbcore-$(CONFIG_OF)+= of.o
> 
> No Kconfig? Shouldn't this file be compiled only when some one is
> going to use the PHY?

Yes. Just skipped that for the first shot.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH,RFC] usb: add devicetree helpers for determining dr_mode and phy_type

2013-01-30 Thread Sascha Hauer
On Wed, Jan 30, 2013 at 11:21:35AM +0530, kishon wrote:
> On Wednesday 30 January 2013 02:00 AM, Sascha Hauer wrote:
> >On Tue, Jan 29, 2013 at 07:14:51PM +0530, kishon wrote:
> >>Hi,
> >>
> >>On Tuesday 29 January 2013 04:52 PM, Sascha Hauer wrote:
> >>>From: Michael Grzeschik 
> >>>
> >>>This adds two little devicetree helper functions for determining the
> >>>dr_mode (host, peripheral, otg) and phy_type (utmi, ulpi,...) from
> >>>the devicetree.
> >>>
> >>>Signed-off-by: Michael Grzeschik 
> >>>Signed-off-by: Marc Kleine-Budde 
> >>>---
> >>>
> >>>The properties and their values have been taken from the fsl-mph-dr driver.
> >>>This binding is also documented (though currently not used) for the tegra
> >>>ehci driver 
> >>>(Documentation/devicetree/bindings/usb/nvidia,tegra20-ehci.txt).
> >>>This is a first attempt to parse these bindings at a common place so that
> >>>others can make use of it.
> >>>
> >>>Basically I want to know whether this binding is recommended for new 
> >>>drivers
> >>>since normally the devicetree uses '-' instead of '_', and maybe there are
> >>>other problems with it.
> >>>
> >>>I need this binding for the chipidea driver. I suspect that the fsl-mph-dr
> >>>driver also really handles a chipidea core.
> >>>
> >>>Should we agree on this I would convert the fsl-mph-dr driver to use these
> >>>helpers.
> >>>
> >>>Sascha
> >>>
> >>>  drivers/usb/core/Makefile |1 +
> >>>  drivers/usb/core/of.c |   76 
> >>> +
> >>
> >>This file should ideally go into drivers/usb/phy/.
> >
> >I originally wanted to do that, but the host/peripheral/otg property is
> >not phy specific. DO you still want to move it there?
> 
> I think then you can just move of_usb_get_phy_mode() to phy/of.c.
> Then we can also move some functions defined in otg.c (specific to
> PHY and dt) to phy/of.c.

The phy specific stuff in otg.c can't easily be moved as all functions
operate on a static list and spinlock. Also nothing in otg/otg.c is
currently of specific.

What about the dr_mode helper? Moving it to otg/ would mean that all
users which want to use it would have to select USB_OTG_UTILS. At least
the fsl mph driver currently does not need USB_OTG_UTILS.

ATM I'm feeling like killing USB_OTG_UTILS completely, that would make
things easier.

Sascha


-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH,RFC] usb: add devicetree helpers for determining dr_mode and phy_type

2013-01-30 Thread Sascha Hauer
On Wed, Jan 30, 2013 at 10:06:28AM +0800, Peter Chen wrote:
> On Tue, Jan 29, 2013 at 01:55:04PM +0200, Alexander Shishkin wrote:
> > Sascha Hauer  writes:
> > 
> > > From: Michael Grzeschik 
> > >
> > > This adds two little devicetree helper functions for determining the
> > > dr_mode (host, peripheral, otg) and phy_type (utmi, ulpi,...) from
> > > the devicetree.
> > >
> > > Signed-off-by: Michael Grzeschik 
> > > Signed-off-by: Marc Kleine-Budde 
> > > ---
> > >
> > > The properties and their values have been taken from the fsl-mph-dr 
> > > driver.
> > > This binding is also documented (though currently not used) for the tegra
> > > ehci driver 
> > > (Documentation/devicetree/bindings/usb/nvidia,tegra20-ehci.txt).
> > > This is a first attempt to parse these bindings at a common place so that
> > > others can make use of it.
> > >
> > > Basically I want to know whether this binding is recommended for new 
> > > drivers
> > > since normally the devicetree uses '-' instead of '_', and maybe there are
> > > other problems with it.
> > >
> > > I need this binding for the chipidea driver. I suspect that the fsl-mph-dr
> > > driver also really handles a chipidea core.
> > 
> > As far as I know, it is a chipidea core. Adding Peter to Cc list, he can
> > probably confirm.
> 
> The fsl-mph-dr can't be used for chipdiea as it handles three platform
> drivers for three roles (peripheral , host, otg). But chipidea only has
> two platform drivers, one is the chipidea core, the other is related
> controller wrapper.

What do you mean by 'three platform drivers'? That's only how the driver
is built, no? I was talking about the hardware the fsl-mph-dr driver
handles which definitely smells like chipidea.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 4/6] usb: chipidea: add PTW and PTS handling

2013-01-30 Thread Sascha Hauer
From: Michael Grzeschik 

This patch makes it possible to configure the PTW and PTS bits inside
the portsc register for host and device mode before the driver starts
and the phy can be addressed as hardware implementation is designed.

Signed-off-by: Michael Grzeschik 
Signed-off-by: Marc Kleine-Budde 
Signed-off-by: Sascha Hauer 
---
 .../devicetree/bindings/usb/ci13xxx-imx.txt|5 +++
 drivers/usb/chipidea/bits.h|7 
 drivers/usb/chipidea/ci13xxx_imx.c |3 ++
 drivers/usb/chipidea/core.c|   40 
 include/linux/usb/chipidea.h   |1 +
 5 files changed, 56 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt 
b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
index 5778b9c..dd42ccd 100644
--- a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
+++ b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
@@ -5,6 +5,11 @@ Required properties:
 - reg: Should contain registers location and length
 - interrupts: Should contain controller interrupt
 
+Recommended properies:
+- phy_type: the type of the phy connected to the core. Should be one
+  of "utmi", "utmi_wide", "ulpi", "serial" or "hsic". Without this
+  property the PORTSC register won't be touched
+
 Optional properties:
 - fsl,usbphy: phandler of usb phy that connects to the only one port
 - fsl,usbmisc: phandler of non-core register device, with one argument
diff --git a/drivers/usb/chipidea/bits.h b/drivers/usb/chipidea/bits.h
index 050de85..4817fd8 100644
--- a/drivers/usb/chipidea/bits.h
+++ b/drivers/usb/chipidea/bits.h
@@ -48,6 +48,13 @@
 #define PORTSC_SUSP   BIT(7)
 #define PORTSC_HSPBIT(9)
 #define PORTSC_PTC(0x0FUL << 16)
+/* PTS and PTW for non lpm version only */
+#define PORTSC_PTS_PTW(BIT(31) | BIT(30) | BIT(28) | BIT(25))
+#define PORTSC_PTS_PTW_UTMI   0
+#define PORTSC_PTS_PTW_HSIC   BIT(25)
+#define PORTSC_PTS_PTW_UTMIW  BIT(28)
+#define PORTSC_PTS_PTW_ULPI   BIT(31)
+#define PORTSC_PTS_PTW_SERIAL (BIT(30) | BIT(31))
 
 /* DEVLC */
 #define DEVLC_PSPD(0x03UL << 25)
diff --git a/drivers/usb/chipidea/ci13xxx_imx.c 
b/drivers/usb/chipidea/ci13xxx_imx.c
index 69024e0..ebc1148 100644
--- a/drivers/usb/chipidea/ci13xxx_imx.c
+++ b/drivers/usb/chipidea/ci13xxx_imx.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "ci.h"
 #include "ci13xxx_imx.h"
@@ -112,6 +113,8 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
   CI13XXX_PULLUP_ON_VBUS |
   CI13XXX_DISABLE_STREAMING;
 
+   pdata->phy_mode = of_usb_get_phy_mode(pdev->dev.of_node);
+
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
if (!data) {
dev_err(&pdev->dev, "Failed to allocate CI13xxx-IMX data!\n");
diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
index 57cae1f..dcb650f 100644
--- a/drivers/usb/chipidea/core.c
+++ b/drivers/usb/chipidea/core.c
@@ -67,6 +67,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include "ci.h"
 #include "udc.h"
@@ -211,6 +213,42 @@ static int hw_device_init(struct ci13xxx *ci, void __iomem 
*base)
return 0;
 }
 
+static void hw_phymode_configure(struct ci13xxx *ci)
+{
+   u32 portsc;
+
+   /*
+* The lpm version has the corresponding bits in the devlc register.
+* Currently not implemented.
+*/
+   if (ci->hw_bank.lpm)
+   return;
+
+   switch (ci->platdata->phy_mode) {
+   case USBPHY_INTERFACE_MODE_UTMI:
+   portsc = PORTSC_PTS_PTW_UTMI;
+   break;
+   case USBPHY_INTERFACE_MODE_UTMIW:
+   portsc = PORTSC_PTS_PTW_UTMIW;
+   break;
+   case USBPHY_INTERFACE_MODE_ULPI:
+   portsc = PORTSC_PTS_PTW_ULPI;
+   break;
+   case USBPHY_INTERFACE_MODE_SERIAL:
+   portsc = PORTSC_PTS_PTW_SERIAL;
+   break;
+   case USBPHY_INTERFACE_MODE_HSIC:
+   portsc = PORTSC_PTS_PTW_HSIC;
+   break;
+   default:
+   return;
+   }
+
+   hw_write(ci, OP_PORTSC, PORTSC_PTS_PTW, portsc);
+
+   mdelay(10);
+}
+
 /**
  * hw_device_reset: resets chip (execute without interruption)
  * @ci: the controller
@@ -476,6 +514,8 @@ static int ci_hdrc_probe(struct platform_device *pdev)
: CI_ROLE_GADGET;
}
 
+   hw_phymode_configure(ci);
+
ret = ci_role_start(ci, ci->role);
if (ret) {
dev_err(dev, "can't start %s role\n", ci_role(ci)->name);
diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h
index 544825d..1a2aa18 100644
--- a/include/linux/usb/c

[PATCH 1/6] USB: move bulk of otg/otg.c to phy/phy.c

2013-01-30 Thread Sascha Hauer
Most of otg/otg.c is not otg specific, but phy specific, so move it
to the phy directory.

Signed-off-by: Sascha Hauer 
---
 drivers/usb/otg/otg.c|  423 -
 drivers/usb/phy/Makefile |1 +
 drivers/usb/phy/phy.c|  424 ++
 3 files changed, 425 insertions(+), 423 deletions(-)
 create mode 100644 drivers/usb/phy/phy.c

diff --git a/drivers/usb/otg/otg.c b/drivers/usb/otg/otg.c
index e181439..358cfd9 100644
--- a/drivers/usb/otg/otg.c
+++ b/drivers/usb/otg/otg.c
@@ -8,432 +8,9 @@
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
  */
-
-#include 
 #include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
 #include 
 
-static LIST_HEAD(phy_list);
-static LIST_HEAD(phy_bind_list);
-static DEFINE_SPINLOCK(phy_lock);
-
-static struct usb_phy *__usb_find_phy(struct list_head *list,
-   enum usb_phy_type type)
-{
-   struct usb_phy  *phy = NULL;
-
-   list_for_each_entry(phy, list, head) {
-   if (phy->type != type)
-   continue;
-
-   return phy;
-   }
-
-   return ERR_PTR(-ENODEV);
-}
-
-static struct usb_phy *__usb_find_phy_dev(struct device *dev,
-   struct list_head *list, u8 index)
-{
-   struct usb_phy_bind *phy_bind = NULL;
-
-   list_for_each_entry(phy_bind, list, list) {
-   if (!(strcmp(phy_bind->dev_name, dev_name(dev))) &&
-   phy_bind->index == index) {
-   if (phy_bind->phy)
-   return phy_bind->phy;
-   else
-   return ERR_PTR(-EPROBE_DEFER);
-   }
-   }
-
-   return ERR_PTR(-ENODEV);
-}
-
-static struct usb_phy *__of_usb_find_phy(struct device_node *node)
-{
-   struct usb_phy  *phy;
-
-   list_for_each_entry(phy, &phy_list, head) {
-   if (node != phy->dev->of_node)
-   continue;
-
-   return phy;
-   }
-
-   return ERR_PTR(-ENODEV);
-}
-
-static void devm_usb_phy_release(struct device *dev, void *res)
-{
-   struct usb_phy *phy = *(struct usb_phy **)res;
-
-   usb_put_phy(phy);
-}
-
-static int devm_usb_phy_match(struct device *dev, void *res, void *match_data)
-{
-   return res == match_data;
-}
-
-/**
- * devm_usb_get_phy - find the USB PHY
- * @dev - device that requests this phy
- * @type - the type of the phy the controller requires
- *
- * Gets the phy using usb_get_phy(), and associates a device with it using
- * devres. On driver detach, release function is invoked on the devres data,
- * then, devres data is freed.
- *
- * For use by USB host and peripheral drivers.
- */
-struct usb_phy *devm_usb_get_phy(struct device *dev, enum usb_phy_type type)
-{
-   struct usb_phy **ptr, *phy;
-
-   ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL);
-   if (!ptr)
-   return NULL;
-
-   phy = usb_get_phy(type);
-   if (!IS_ERR(phy)) {
-   *ptr = phy;
-   devres_add(dev, ptr);
-   } else
-   devres_free(ptr);
-
-   return phy;
-}
-EXPORT_SYMBOL(devm_usb_get_phy);
-
-/**
- * usb_get_phy - find the USB PHY
- * @type - the type of the phy the controller requires
- *
- * Returns the phy driver, after getting a refcount to it; or
- * -ENODEV if there is no such phy.  The caller is responsible for
- * calling usb_put_phy() to release that count.
- *
- * For use by USB host and peripheral drivers.
- */
-struct usb_phy *usb_get_phy(enum usb_phy_type type)
-{
-   struct usb_phy  *phy = NULL;
-   unsigned long   flags;
-
-   spin_lock_irqsave(&phy_lock, flags);
-
-   phy = __usb_find_phy(&phy_list, type);
-   if (IS_ERR(phy)) {
-   pr_err("unable to find transceiver of type %s\n",
-   usb_phy_type_string(type));
-   goto err0;
-   }
-
-   get_device(phy->dev);
-
-err0:
-   spin_unlock_irqrestore(&phy_lock, flags);
-
-   return phy;
-}
-EXPORT_SYMBOL(usb_get_phy);
-
- /**
- * devm_usb_get_phy_by_phandle - find the USB PHY by phandle
- * @dev - device that requests this phy
- * @phandle - name of the property holding the phy phandle value
- * @index - the index of the phy
- *
- * Returns the phy driver associated with the given phandle value,
- * after getting a refcount to it, -ENODEV if there is no such phy or
- * -EPROBE_DEFER if there is a phandle to the phy, but the device is
- * not yet loaded. While at that, it also associates the device with
- * the phy using devres. On driver detach, release function is invoked
- * on the devres data, then, devres data is freed.
- *
- * For use by USB host and peripheral drivers.
- */
-struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
-   const char *phandle, u

[PATCH 6/6] USB chipidea i.MX: introduce dr_mode property

2013-01-30 Thread Sascha Hauer
The dr_mode devicetree property allows to explicitly specify the
host/peripheral/otg mode. This is necessary for boards without proper
ID pin handling.

Signed-off-by: Sascha Hauer 
---
 Documentation/devicetree/bindings/usb/ci13xxx-imx.txt |1 +
 drivers/usb/chipidea/ci13xxx_imx.c|1 +
 2 files changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt 
b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
index dd42ccd..493a414 100644
--- a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
+++ b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
@@ -9,6 +9,7 @@ Recommended properies:
 - phy_type: the type of the phy connected to the core. Should be one
   of "utmi", "utmi_wide", "ulpi", "serial" or "hsic". Without this
   property the PORTSC register won't be touched
+- dr_mode: One of "host", "peripheral" or "otg". Defaults to "otg"
 
 Optional properties:
 - fsl,usbphy: phandler of usb phy that connects to the only one port
diff --git a/drivers/usb/chipidea/ci13xxx_imx.c 
b/drivers/usb/chipidea/ci13xxx_imx.c
index ebc1148..b598bb8f 100644
--- a/drivers/usb/chipidea/ci13xxx_imx.c
+++ b/drivers/usb/chipidea/ci13xxx_imx.c
@@ -114,6 +114,7 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
   CI13XXX_DISABLE_STREAMING;
 
pdata->phy_mode = of_usb_get_phy_mode(pdev->dev.of_node);
+   pdata->dr_mode = of_usb_get_dr_mode(pdev->dev.of_node);
 
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
if (!data) {
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/6] usb: add devicetree helpers for determining dr_mode and phy_type

2013-01-30 Thread Sascha Hauer
From: Michael Grzeschik 

This adds two little devicetree helper functions for determining the
dr_mode (host, peripheral, otg) and phy_type (utmi, ulpi,...) from
the devicetree.

Signed-off-by: Michael Grzeschik 
Signed-off-by: Marc Kleine-Budde 
Signed-off-by: Sascha Hauer 
---
 drivers/usb/usb-common.c |   69 ++
 include/linux/usb/of.h   |   27 ++
 include/linux/usb/otg.h  |7 +
 include/linux/usb/phy.h  |9 ++
 4 files changed, 112 insertions(+)
 create mode 100644 include/linux/usb/of.h

diff --git a/drivers/usb/usb-common.c b/drivers/usb/usb-common.c
index d29503e..1c0292c 100644
--- a/drivers/usb/usb-common.c
+++ b/drivers/usb/usb-common.c
@@ -14,6 +14,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 const char *usb_speed_string(enum usb_device_speed speed)
 {
@@ -32,4 +35,70 @@ const char *usb_speed_string(enum usb_device_speed speed)
 }
 EXPORT_SYMBOL_GPL(usb_speed_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_phy_dr_mode
+ */
+enum usb_phy_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 (!strcasecmp(dr_mode, usb_dr_modes[i]))
+   return i;
+
+   return USB_DR_MODE_UNKNOWN;
+}
+EXPORT_SYMBOL_GPL(of_usb_get_dr_mode);
+
+static const char *usbphy_modes[] = {
+   [USBPHY_INTERFACE_MODE_NA]  = "",
+   [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_get_usbphy_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_NA;
+
+   for (i = 0; i < ARRAY_SIZE(usbphy_modes); i++)
+   if (!strcasecmp(phy_type, usbphy_modes[i]))
+   return i;
+
+   return USBPHY_INTERFACE_MODE_NA;
+}
+EXPORT_SYMBOL_GPL(of_usb_get_phy_mode);
+#endif
+
 MODULE_LICENSE("GPL");
diff --git a/include/linux/usb/of.h b/include/linux/usb/of.h
new file mode 100644
index 000..53d69da
--- /dev/null
+++ b/include/linux/usb/of.h
@@ -0,0 +1,27 @@
+/*
+ * OF helpers for usb devices.
+ *
+ * This file is released under the GPLv2
+ */
+
+#ifndef __LINUX_USB_OF_H
+#define __LINUX_USB_OF_H
+
+#include 
+
+#ifdef CONFIG_OF
+enum usb_phy_interface of_usb_get_phy_mode(struct device_node *np);
+enum usb_phy_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_NA;
+}
+
+static inline enum usb_phy_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 e8a5fe8..9c012f0 100644
--- a/include/linux/usb/otg.h
+++ b/include/linux/usb/otg.h
@@ -99,4 +99,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_phy_dr_mode {
+   USB_DR_MODE_UNKNOWN,
+   USB_DR_MODE_HOST,
+   USB_DR_MODE_PERIPHERAL,
+   USB_DR_MODE_OTG,
+};
+
 #endif /* __LINUX_USB_OTG_H */
diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h
index 15847cb..a5170d8 100644
--- a/include/linux/usb/phy.h
+++ b/include/linux/usb/phy.h
@@ -12,6 +12,15 @@
 #include 
 #include 
 
+enum usb_phy_interface {
+   USBPHY_INTERFACE_MODE_NA,
+   USBPHY_INTERFACE_MODE_UTMI,
+   USBPHY_INTERFACE_MODE_UTMIW,
+   USBPHY_INTERFACE_MODE_ULPI,
+   USBPHY_INTERFACE_MODE_SERIAL,
+   USBPHY_I

[PATCH 5/6] USB chipidea: introduce dual role mode pdata flags

2013-01-30 Thread Sascha Hauer
Even if a chipidea core is otg capable the board may not. This allows
to explicitly set the core to host/peripheral mode. Without these
flags the driver falls back to the old behaviour.

Signed-off-by: Sascha Hauer 
---
 drivers/usb/chipidea/core.c  |   21 +++--
 include/linux/usb/chipidea.h |2 +-
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
index dcb650f..f313927 100644
--- a/drivers/usb/chipidea/core.c
+++ b/drivers/usb/chipidea/core.c
@@ -436,6 +436,7 @@ static int ci_hdrc_probe(struct platform_device *pdev)
struct resource *res;
void __iomem*base;
int ret;
+   int dr_mode;
 
if (!dev->platform_data) {
dev_err(dev, "platform data missing\n");
@@ -488,14 +489,22 @@ static int ci_hdrc_probe(struct platform_device *pdev)
return -ENODEV;
}
 
+   dr_mode = ci->platdata->dr_mode;
+   if (dr_mode == USB_DR_MODE_UNKNOWN)
+   dr_mode = USB_DR_MODE_OTG;
+
/* initialize role(s) before the interrupt is requested */
-   ret = ci_hdrc_host_init(ci);
-   if (ret)
-   dev_info(dev, "doesn't support host\n");
+   if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) {
+   ret = ci_hdrc_host_init(ci);
+   if (ret)
+   dev_info(dev, "doesn't support host\n");
+   }
 
-   ret = ci_hdrc_gadget_init(ci);
-   if (ret)
-   dev_info(dev, "doesn't support gadget\n");
+   if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_PERIPHERAL) {
+   ret = ci_hdrc_gadget_init(ci);
+   if (ret)
+   dev_info(dev, "doesn't support gadget\n");
+   }
 
if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) {
dev_err(dev, "no supported roles\n");
diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h
index 1a2aa18..d2d4101 100644
--- a/include/linux/usb/chipidea.h
+++ b/include/linux/usb/chipidea.h
@@ -20,7 +20,7 @@ struct ci13xxx_platform_data {
 #define CI13XXX_REQUIRE_TRANSCEIVERBIT(1)
 #define CI13XXX_PULLUP_ON_VBUS BIT(2)
 #define CI13XXX_DISABLE_STREAMING  BIT(3)
-
+   enum usb_phy_dr_modedr_mode;
 #define CI13XXX_CONTROLLER_RESET_EVENT 0
 #define CI13XXX_CONTROLLER_STOPPED_EVENT   1
void(*notify_event) (struct ci13xxx *ci, unsigned event);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/6] usb: chipidea: ci13xxx-imx: create dynamic platformdata

2013-01-30 Thread Sascha Hauer
From: Michael Grzeschik 

This patch removes the limitation of having only one instance of the
ci13xxx-imx platformdata and makes different configurations possible.

Signed-off-by: Michael Grzeschik 
Signed-off-by: Marc Kleine-Budde 
Signed-off-by: Sascha Hauer 
---
 drivers/usb/chipidea/ci13xxx_imx.c |   25 +++--
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/chipidea/ci13xxx_imx.c 
b/drivers/usb/chipidea/ci13xxx_imx.c
index 8c29122..69024e0 100644
--- a/drivers/usb/chipidea/ci13xxx_imx.c
+++ b/drivers/usb/chipidea/ci13xxx_imx.c
@@ -85,17 +85,10 @@ EXPORT_SYMBOL_GPL(usbmisc_get_init_data);
 
 /* End of common functions shared by usbmisc drivers*/
 
-static struct ci13xxx_platform_data ci13xxx_imx_platdata  = {
-   .name   = "ci13xxx_imx",
-   .flags  = CI13XXX_REQUIRE_TRANSCEIVER |
- CI13XXX_PULLUP_ON_VBUS |
- CI13XXX_DISABLE_STREAMING,
-   .capoffset  = DEF_CAPOFFSET,
-};
-
 static int ci13xxx_imx_probe(struct platform_device *pdev)
 {
struct ci13xxx_imx_data *data;
+   struct ci13xxx_platform_data *pdata;
struct platform_device *plat_ci, *phy_pdev;
struct device_node *phy_np;
struct resource *res;
@@ -107,6 +100,18 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
&& !usbmisc_ops)
return -EPROBE_DEFER;
 
+   pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
+   if (!pdata) {
+   dev_err(&pdev->dev, "Failed to allocate CI13xxx-IMX pdata!\n");
+   return -ENOMEM;
+   }
+
+   pdata->name = "ci13xxx_imx";
+   pdata->capoffset = DEF_CAPOFFSET;
+   pdata->flags = CI13XXX_REQUIRE_TRANSCEIVER |
+  CI13XXX_PULLUP_ON_VBUS |
+  CI13XXX_DISABLE_STREAMING;
+
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
if (!data) {
dev_err(&pdev->dev, "Failed to allocate CI13xxx-IMX data!\n");
@@ -168,7 +173,7 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
reg_vbus = NULL;
}
 
-   ci13xxx_imx_platdata.phy = data->phy;
+   pdata->phy = data->phy;
 
if (!pdev->dev.dma_mask) {
pdev->dev.dma_mask = devm_kzalloc(&pdev->dev,
@@ -193,7 +198,7 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
 
plat_ci = ci13xxx_add_device(&pdev->dev,
pdev->resource, pdev->num_resources,
-   &ci13xxx_imx_platdata);
+   pdata);
if (IS_ERR(plat_ci)) {
ret = PTR_ERR(plat_ci);
dev_err(&pdev->dev,
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] Add USB of helpers and use them in the chipidea driver

2013-01-30 Thread Sascha Hauer
This is the 2nd version of the USB of helper patch, this time with
adding support for the chipidea driver for the new properties.

Kishon, I decided against adding an extra Kconfig option for the
OF helpers since I found out the USB stuff already has enough options ;)

The helpers are now in usb-common.c which seems an appropriate place
for them. For the phy_type helpers I had a look again and saw that
it is not really phy specific, the PORTSC registers in the chipidea
driver have to be configured even without phy support compiled in.

Sascha


Michael Grzeschik (3):
  usb: add devicetree helpers for determining dr_mode and phy_type
  usb: chipidea: ci13xxx-imx: create dynamic platformdata
  usb: chipidea: add PTW and PTS handling

Sascha Hauer (2):
  USB chipidea: introduce dual role mode pdata flags
  USB chipidea i.MX: introduce dr_mode property

 .../devicetree/bindings/usb/ci13xxx-imx.txt|6 ++
 drivers/usb/chipidea/bits.h|7 ++
 drivers/usb/chipidea/ci13xxx_imx.c |   29 +---
 drivers/usb/chipidea/core.c|   61 +++--
 drivers/usb/usb-common.c   |   69 
 include/linux/usb/chipidea.h   |3 +-
 include/linux/usb/of.h |   27 
 include/linux/usb/otg.h|7 ++
 include/linux/usb/phy.h|9 +++
 9 files changed, 201 insertions(+), 17 deletions(-)
 create mode 100644 include/linux/usb/of.h
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 4/6] usb: chipidea: add PTW and PTS handling

2013-01-30 Thread Sascha Hauer
On Wed, Jan 30, 2013 at 05:54:54PM +0100, Matthieu CASTET wrote:
> > diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
> > index 57cae1f..dcb650f 100644
> > --- a/drivers/usb/chipidea/core.c
> > +++ b/drivers/usb/chipidea/core.c
> > @@ -67,6 +67,8 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> > +#include 
> >  
> >  #include "ci.h"
> >  #include "udc.h"
> > @@ -211,6 +213,42 @@ static int hw_device_init(struct ci13xxx *ci, void 
> > __iomem *base)
> > return 0;
> >  }
> >  
> > +static void hw_phymode_configure(struct ci13xxx *ci)
> > +{
> > +   u32 portsc;
> > +
> > +   /*
> > +* The lpm version has the corresponding bits in the devlc register.
> > +* Currently not implemented.
> > +*/
> > +   if (ci->hw_bank.lpm)
> > +   return;
> Why you don't implement it ?
> 
> If you don't implement it, I believe you should add a warning in order to 
> catch
> it when used with lpm devices.

I'm against adding a warning because current users seem to go well
without this setting. Adding a warning would lead to more confusion than
it would help.

I could try and implement it, though I'm unsure about the register
layout.

What I know from an earlier post from you is this:

#define LPM_PTS(d)  (((d)>>29)&7)
#define LPM_STS BIT(28) /* serial transceiver select */
#define LPM_PTW BIT(27) /* parallel transceiver width */

Do you also know how LPM_PTS is decoded?

Sascha


-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/6] usb: add devicetree helpers for determining dr_mode and phy_type

2013-01-30 Thread Sascha Hauer
On Thu, Jan 31, 2013 at 11:44:21AM +0530, kishon wrote:
> Hi,
> 
> On Wednesday 30 January 2013 08:59 PM, Sascha Hauer wrote:
> >From: Michael Grzeschik 
> >
> >This adds two little devicetree helper functions for determining the
> >dr_mode (host, peripheral, otg) and phy_type (utmi, ulpi,...) from
> >the devicetree.
> >
> >Signed-off-by: Michael Grzeschik 
> >Signed-off-by: Marc Kleine-Budde 
> >Signed-off-by: Sascha Hauer 
> >---
> >  drivers/usb/usb-common.c |   69 
> > ++
> >  include/linux/usb/of.h   |   27 ++
> >  include/linux/usb/otg.h  |7 +
> >  include/linux/usb/phy.h  |9 ++
> >  4 files changed, 112 insertions(+)
> >  create mode 100644 include/linux/usb/of.h
> >
> >diff --git a/drivers/usb/usb-common.c b/drivers/usb/usb-common.c
> >index d29503e..1c0292c 100644
> >--- a/drivers/usb/usb-common.c
> >+++ b/drivers/usb/usb-common.c
> >@@ -14,6 +14,9 @@
> >  #include 
> >  #include 
> >  #include 
> >+#include 
> >+#include 
> >+#include 
> >
> >  const char *usb_speed_string(enum usb_device_speed speed)
> >  {
> >@@ -32,4 +35,70 @@ const char *usb_speed_string(enum usb_device_speed speed)
> >  }
> >  EXPORT_SYMBOL_GPL(usb_speed_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_phy_dr_mode
> >+ */
> >+enum usb_phy_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 (!strcasecmp(dr_mode, usb_dr_modes[i]))
> >+return i;
> >+
> >+return USB_DR_MODE_UNKNOWN;
> >+}
> >+EXPORT_SYMBOL_GPL(of_usb_get_dr_mode);
> >+
> >+static const char *usbphy_modes[] = {
> >+[USBPHY_INTERFACE_MODE_NA]  = "",
> >+[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_get_usbphy_mode - Get phy mode for given device_node
> 
> %s/of_get_usbphy_mode/of_usb_get_phy_mode
> >+ * @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)
> >+{
> 
> You agreed to move this function inside usb/phy.. no?

Yes, I did, but as mentioned in the introduction mail, the chipidea
driver has to determine the phy type even when phy support (aka
CONFIG_USB_OTG_UTILS) is disabled, so I can't put it in phy/phy.c.

I could add a phy/of.c though. Would that be better?

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 4/6] usb: chipidea: add PTW and PTS handling

2013-01-30 Thread Sascha Hauer
On Thu, Jan 31, 2013 at 11:08:54AM +0800, Peter Chen wrote:
> On Wed, Jan 30, 2013 at 04:29:40PM +0100, Sascha Hauer wrote:
> > From: Michael Grzeschik 
> > 
> > +static void hw_phymode_configure(struct ci13xxx *ci)
> > +{
> > +   u32 portsc;
> > +
> > +   /*
> > +* The lpm version has the corresponding bits in the devlc register.
> > +* Currently not implemented.
> > +*/
> > +   if (ci->hw_bank.lpm)
> > +   return;
> > +
> > +   switch (ci->platdata->phy_mode) {
> > +   case USBPHY_INTERFACE_MODE_UTMI:
> > +   portsc = PORTSC_PTS_PTW_UTMI;
> > +   break;
> > +   case USBPHY_INTERFACE_MODE_UTMIW:
> > +   portsc = PORTSC_PTS_PTW_UTMIW;
> > +   break;
> > +   case USBPHY_INTERFACE_MODE_ULPI:
> > +   portsc = PORTSC_PTS_PTW_ULPI;
> > +   break;
> > +   case USBPHY_INTERFACE_MODE_SERIAL:
> > +   portsc = PORTSC_PTS_PTW_SERIAL;
> > +   break;
> > +   case USBPHY_INTERFACE_MODE_HSIC:
> > +   portsc = PORTSC_PTS_PTW_HSIC;
> > +   break;
> > +   default:
> > +   return;
> > +   }
> > +
> > +   hw_write(ci, OP_PORTSC, PORTSC_PTS_PTW, portsc);
> > +
> > +   mdelay(10);
> Please use usleep_range, can we recall which platform needs it?
> As we as I know, there is no such delay at FSL internal release
> code.

Then let's drop it. People will complain when they find the platform
that needs it and then we can decide whether we add this unconditionally
or do something better.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/6] usb: add devicetree helpers for determining dr_mode and phy_type

2013-01-31 Thread Sascha Hauer
On Thu, Jan 31, 2013 at 10:30:36AM +0800, Peter Chen wrote:
> On Wed, Jan 30, 2013 at 04:29:38PM +0100, Sascha Hauer wrote:
> > From: Michael Grzeschik 
> > 
> > This adds two little devicetree helper functions for determining the
> > dr_mode (host, peripheral, otg) and phy_type (utmi, ulpi,...) from
> > the devicetree.
> > 
> > Signed-off-by: Michael Grzeschik 
> > Signed-off-by: Marc Kleine-Budde 
> > Signed-off-by: Sascha Hauer 
> > ---
> >  drivers/usb/usb-common.c |   69 
> > ++
> >  include/linux/usb/of.h   |   27 ++
> >  include/linux/usb/otg.h  |7 +
> >  include/linux/usb/phy.h  |9 ++
> >  4 files changed, 112 insertions(+)
> >  create mode 100644 include/linux/usb/of.h
> > 
> > diff --git a/drivers/usb/usb-common.c b/drivers/usb/usb-common.c
> > index d29503e..1c0292c 100644
> > --- a/drivers/usb/usb-common.c
> > +++ b/drivers/usb/usb-common.c
> > @@ -14,6 +14,9 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> > +#include 
> > +#include 
> >  
> >  const char *usb_speed_string(enum usb_device_speed speed)
> >  {
> > @@ -32,4 +35,70 @@ const char *usb_speed_string(enum usb_device_speed speed)
> >  }
> >  EXPORT_SYMBOL_GPL(usb_speed_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_phy_dr_mode
> > + */
> > +enum usb_phy_dr_mode of_usb_get_dr_mode(struct device_node *np)
> The word "phy" at usb_phy_dr_mode may cause misunderstand, just usb_dr_mode
> is ok

ok, changed.

> > +{
> > +   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 (!strcasecmp(dr_mode, usb_dr_modes[i]))
> > +   return i;
> Just curious, why not using strcmp?

Probably because this is based on drivers/of/of_net.c which uses
strcasecmp. I never heard that devicetrees are case insensitive, so
I'll change this to strcmp.

> > +
> > +   return USB_DR_MODE_UNKNOWN;
> > +}
> > +
> > +#ifdef CONFIG_OF
> > +enum usb_phy_interface of_usb_get_phy_mode(struct device_node *np);
> > +enum usb_phy_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_NA;
> > +}
> > +
> > +static inline enum usb_phy_dr_mode of_usb_get_dr_mode(struct device_node 
> > *np)
> > +{
> > +   return USB_DR_MODE_UNKNOWN;
> > +}
> For, dr_mode, if value has not existed, you use *_UNKNOWN, why
> for usbphy,  you use *_NA. It is better uniform.

yup, fixed.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2] Add USB of helpers and use them in the chipidea driver

2013-01-31 Thread Sascha Hauer

changes since v1:

- move phy specific of helper to drivers/usb/phy/of.c
- use strcmp instead of strcasecmp for matching property values
- change usb_phy_dr_mode to usb_dr_mode
- change USBPHY_INTERFACE_MODE_NA to USBPHY_INTERFACE_MODE_UNKNOWN
- add copyright header to new files
- chipidea: drop mdelay at end of PTS/PTW setup
- chipidea: implement lpm core type handling for PTS/PTW

Sascha


Michael Grzeschik (3):
  USB: add devicetree helpers for determining dr_mode and phy_type
  USB: chipidea: ci13xxx-imx: create dynamic platformdata
  USB: chipidea: add PTW and PTS handling

Sascha Hauer (3):
  USB: move bulk of otg/otg.c to phy/phy.c
  USB chipidea: introduce dual role mode pdata flags
  USB chipidea i.MX: introduce dr_mode property

 .../devicetree/bindings/usb/ci13xxx-imx.txt|6 +
 drivers/usb/chipidea/bits.h|   14 +-
 drivers/usb/chipidea/ci13xxx_imx.c |   29 +-
 drivers/usb/chipidea/core.c|   60 ++-
 drivers/usb/otg/otg.c  |  423 ---
 drivers/usb/phy/Makefile   |2 +
 drivers/usb/phy/phy.c  |  434 
 drivers/usb/usb-common.c   |   36 ++
 include/linux/usb/chipidea.h   |3 +-
 include/linux/usb/of.h |   27 ++
 include/linux/usb/otg.h|7 +
 include/linux/usb/phy.h|9 +
 12 files changed, 609 insertions(+), 441 deletions(-)
 create mode 100644 drivers/usb/phy/phy.c
 create mode 100644 include/linux/usb/of.h
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 4/6] USB: chipidea: add PTW and PTS handling

2013-01-31 Thread Sascha Hauer
From: Michael Grzeschik 

This patch makes it possible to configure the PTW and PTS bits inside
the portsc register for host and device mode before the driver starts
and the phy can be addressed as hardware implementation is designed.

Signed-off-by: Michael Grzeschik 
Signed-off-by: Marc Kleine-Budde 
Signed-off-by: Sascha Hauer 
---
 .../devicetree/bindings/usb/ci13xxx-imx.txt|5 +++
 drivers/usb/chipidea/bits.h|   14 ++-
 drivers/usb/chipidea/ci13xxx_imx.c |3 ++
 drivers/usb/chipidea/core.c|   39 
 include/linux/usb/chipidea.h   |1 +
 5 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt 
b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
index 5778b9c..dd42ccd 100644
--- a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
+++ b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
@@ -5,6 +5,11 @@ Required properties:
 - reg: Should contain registers location and length
 - interrupts: Should contain controller interrupt
 
+Recommended properies:
+- phy_type: the type of the phy connected to the core. Should be one
+  of "utmi", "utmi_wide", "ulpi", "serial" or "hsic". Without this
+  property the PORTSC register won't be touched
+
 Optional properties:
 - fsl,usbphy: phandler of usb phy that connects to the only one port
 - fsl,usbmisc: phandler of non-core register device, with one argument
diff --git a/drivers/usb/chipidea/bits.h b/drivers/usb/chipidea/bits.h
index 050de85..d8ffc2f 100644
--- a/drivers/usb/chipidea/bits.h
+++ b/drivers/usb/chipidea/bits.h
@@ -48,10 +48,22 @@
 #define PORTSC_SUSP   BIT(7)
 #define PORTSC_HSPBIT(9)
 #define PORTSC_PTC(0x0FUL << 16)
+/* PTS and PTW for non lpm version only */
+#define PORTSC_PTS(d) d) & 0x3) << 30) | (((d) & 0x4) ? BIT(25) : 
0))
+#define PORTSC_PTWBIT(28)
 
 /* DEVLC */
 #define DEVLC_PSPD(0x03UL << 25)
-#defineDEVLC_PSPD_HS  (0x02UL << 25)
+#define DEVLC_PSPD_HS (0x02UL << 25)
+#define DEVLC_PTW BIT(27)
+#define DEVLC_STS BIT(28)
+#define DEVLC_PTS(d)  (((d) & 0x7) << 29)
+
+/* Encoding for DEVLC_PTS and PORTSC_PTS */
+#define PTS_UTMI  0
+#define PTS_ULPI  2
+#define PTS_SERIAL3
+#define PTS_HSIC  4
 
 /* OTGSC */
 #define OTGSC_IDPU   BIT(5)
diff --git a/drivers/usb/chipidea/ci13xxx_imx.c 
b/drivers/usb/chipidea/ci13xxx_imx.c
index 69024e0..ebc1148 100644
--- a/drivers/usb/chipidea/ci13xxx_imx.c
+++ b/drivers/usb/chipidea/ci13xxx_imx.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "ci.h"
 #include "ci13xxx_imx.h"
@@ -112,6 +113,8 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
   CI13XXX_PULLUP_ON_VBUS |
   CI13XXX_DISABLE_STREAMING;
 
+   pdata->phy_mode = of_usb_get_phy_mode(pdev->dev.of_node);
+
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
if (!data) {
dev_err(&pdev->dev, "Failed to allocate CI13xxx-IMX data!\n");
diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
index 57cae1f..a3ec29d 100644
--- a/drivers/usb/chipidea/core.c
+++ b/drivers/usb/chipidea/core.c
@@ -67,6 +67,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include "ci.h"
 #include "udc.h"
@@ -211,6 +213,41 @@ static int hw_device_init(struct ci13xxx *ci, void __iomem 
*base)
return 0;
 }
 
+static void hw_phymode_configure(struct ci13xxx *ci)
+{
+   u32 portsc, lpm;
+
+   switch (ci->platdata->phy_mode) {
+   case USBPHY_INTERFACE_MODE_UTMI:
+   portsc = PORTSC_PTS(PTS_UTMI);
+   lpm = DEVLC_PTS(PTS_UTMI);
+   break;
+   case USBPHY_INTERFACE_MODE_UTMIW:
+   portsc = PORTSC_PTS(PTS_UTMI) | PORTSC_PTW;
+   lpm = DEVLC_PTS(PTS_UTMI) | DEVLC_PTW;
+   break;
+   case USBPHY_INTERFACE_MODE_ULPI:
+   portsc = PORTSC_PTS(PTS_ULPI);
+   lpm = DEVLC_PTS(PTS_ULPI);
+   break;
+   case USBPHY_INTERFACE_MODE_SERIAL:
+   portsc = PORTSC_PTS(PTS_SERIAL);
+   lpm = DEVLC_PTS(PTS_SERIAL);
+   break;
+   case USBPHY_INTERFACE_MODE_HSIC:
+   portsc = PORTSC_PTS(PTS_HSIC);
+   lpm = DEVLC_PTS(PTS_HSIC);
+   break;
+   default:
+   return;
+   }
+
+   if (ci->hw_bank.lpm)
+   hw_write(ci, OP_PORTSC, DEVLC_PTS(7) | DEVLC_PTW, lpm);
+   else
+   hw_write(ci, OP_PORTSC, PORTSC_PTS(7) | PORTSC_PTW

[PATCH 1/6] USB: move bulk of otg/otg.c to phy/phy.c

2013-01-31 Thread Sascha Hauer
Most of otg/otg.c is not otg specific, but phy specific, so move it
to the phy directory.

Signed-off-by: Sascha Hauer 
Reported-by: kishon 
Cc: Felipe Balbi 
---
 drivers/usb/otg/otg.c|  423 -
 drivers/usb/phy/Makefile |1 +
 drivers/usb/phy/phy.c|  424 ++
 3 files changed, 425 insertions(+), 423 deletions(-)
 create mode 100644 drivers/usb/phy/phy.c

diff --git a/drivers/usb/otg/otg.c b/drivers/usb/otg/otg.c
index e181439..358cfd9 100644
--- a/drivers/usb/otg/otg.c
+++ b/drivers/usb/otg/otg.c
@@ -8,432 +8,9 @@
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
  */
-
-#include 
 #include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
 #include 
 
-static LIST_HEAD(phy_list);
-static LIST_HEAD(phy_bind_list);
-static DEFINE_SPINLOCK(phy_lock);
-
-static struct usb_phy *__usb_find_phy(struct list_head *list,
-   enum usb_phy_type type)
-{
-   struct usb_phy  *phy = NULL;
-
-   list_for_each_entry(phy, list, head) {
-   if (phy->type != type)
-   continue;
-
-   return phy;
-   }
-
-   return ERR_PTR(-ENODEV);
-}
-
-static struct usb_phy *__usb_find_phy_dev(struct device *dev,
-   struct list_head *list, u8 index)
-{
-   struct usb_phy_bind *phy_bind = NULL;
-
-   list_for_each_entry(phy_bind, list, list) {
-   if (!(strcmp(phy_bind->dev_name, dev_name(dev))) &&
-   phy_bind->index == index) {
-   if (phy_bind->phy)
-   return phy_bind->phy;
-   else
-   return ERR_PTR(-EPROBE_DEFER);
-   }
-   }
-
-   return ERR_PTR(-ENODEV);
-}
-
-static struct usb_phy *__of_usb_find_phy(struct device_node *node)
-{
-   struct usb_phy  *phy;
-
-   list_for_each_entry(phy, &phy_list, head) {
-   if (node != phy->dev->of_node)
-   continue;
-
-   return phy;
-   }
-
-   return ERR_PTR(-ENODEV);
-}
-
-static void devm_usb_phy_release(struct device *dev, void *res)
-{
-   struct usb_phy *phy = *(struct usb_phy **)res;
-
-   usb_put_phy(phy);
-}
-
-static int devm_usb_phy_match(struct device *dev, void *res, void *match_data)
-{
-   return res == match_data;
-}
-
-/**
- * devm_usb_get_phy - find the USB PHY
- * @dev - device that requests this phy
- * @type - the type of the phy the controller requires
- *
- * Gets the phy using usb_get_phy(), and associates a device with it using
- * devres. On driver detach, release function is invoked on the devres data,
- * then, devres data is freed.
- *
- * For use by USB host and peripheral drivers.
- */
-struct usb_phy *devm_usb_get_phy(struct device *dev, enum usb_phy_type type)
-{
-   struct usb_phy **ptr, *phy;
-
-   ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL);
-   if (!ptr)
-   return NULL;
-
-   phy = usb_get_phy(type);
-   if (!IS_ERR(phy)) {
-   *ptr = phy;
-   devres_add(dev, ptr);
-   } else
-   devres_free(ptr);
-
-   return phy;
-}
-EXPORT_SYMBOL(devm_usb_get_phy);
-
-/**
- * usb_get_phy - find the USB PHY
- * @type - the type of the phy the controller requires
- *
- * Returns the phy driver, after getting a refcount to it; or
- * -ENODEV if there is no such phy.  The caller is responsible for
- * calling usb_put_phy() to release that count.
- *
- * For use by USB host and peripheral drivers.
- */
-struct usb_phy *usb_get_phy(enum usb_phy_type type)
-{
-   struct usb_phy  *phy = NULL;
-   unsigned long   flags;
-
-   spin_lock_irqsave(&phy_lock, flags);
-
-   phy = __usb_find_phy(&phy_list, type);
-   if (IS_ERR(phy)) {
-   pr_err("unable to find transceiver of type %s\n",
-   usb_phy_type_string(type));
-   goto err0;
-   }
-
-   get_device(phy->dev);
-
-err0:
-   spin_unlock_irqrestore(&phy_lock, flags);
-
-   return phy;
-}
-EXPORT_SYMBOL(usb_get_phy);
-
- /**
- * devm_usb_get_phy_by_phandle - find the USB PHY by phandle
- * @dev - device that requests this phy
- * @phandle - name of the property holding the phy phandle value
- * @index - the index of the phy
- *
- * Returns the phy driver associated with the given phandle value,
- * after getting a refcount to it, -ENODEV if there is no such phy or
- * -EPROBE_DEFER if there is a phandle to the phy, but the device is
- * not yet loaded. While at that, it also associates the device with
- * the phy using devres. On driver detach, release function is invoked
- * on the devres data, then, devres data is freed.
- *
- * For use by USB host and peripheral drivers.
- */
-struct usb_phy *devm_usb_get_phy_by_phandle

[PATCH 2/6] USB: add devicetree helpers for determining dr_mode and phy_type

2013-01-31 Thread Sascha Hauer
From: Michael Grzeschik 

This adds two little devicetree helper functions for determining the
dr_mode (host, peripheral, otg) and phy_type (utmi, ulpi,...) from
the devicetree.

Signed-off-by: Michael Grzeschik 
Signed-off-by: Marc Kleine-Budde 
Signed-off-by: Sascha Hauer 
---
 drivers/usb/phy/Makefile |1 +
 drivers/usb/phy/phy.c|   10 ++
 drivers/usb/usb-common.c |   36 
 include/linux/usb/of.h   |   27 +++
 include/linux/usb/otg.h  |7 +++
 include/linux/usb/phy.h  |9 +
 6 files changed, 90 insertions(+)
 create mode 100644 include/linux/usb/of.h

diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile
index 9fa6327..e1be1e8 100644
--- a/drivers/usb/phy/Makefile
+++ b/drivers/usb/phy/Makefile
@@ -5,6 +5,7 @@
 ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
 
 obj-$(CONFIG_USB_OTG_UTILS)+= phy.o
+obj-$(CONFIG_OF)   += of.o
 obj-$(CONFIG_OMAP_USB2)+= omap-usb2.o
 obj-$(CONFIG_OMAP_USB3)+= omap-usb3.o
 obj-$(CONFIG_OMAP_CONTROL_USB) += omap-control-usb.o
diff --git a/drivers/usb/phy/phy.c b/drivers/usb/phy/phy.c
index ef35eb0..3ad4b5c 100644
--- a/drivers/usb/phy/phy.c
+++ b/drivers/usb/phy/phy.c
@@ -1,3 +1,13 @@
+/*
+ * phy.c -- USB phy handling
+ *
+ * Copyright (C) 2004 Texas Instruments
+ *
+ * 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 
 #include 
 #include 
diff --git a/drivers/usb/usb-common.c b/drivers/usb/usb-common.c
index d29503e..ad4d87d 100644
--- a/drivers/usb/usb-common.c
+++ b/drivers/usb/usb-common.c
@@ -14,6 +14,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 const char *usb_speed_string(enum usb_device_speed speed)
 {
@@ -32,4 +35,37 @@ const char *usb_speed_string(enum usb_device_speed speed)
 }
 EXPORT_SYMBOL_GPL(usb_speed_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 000..4681a20
--- /dev/null
+++ b/include/linux/usb/of.h
@@ -0,0 +1,27 @@
+/*
+ * OF helpers for usb devices.
+ *
+ * This file is released under the GPLv2
+ */
+
+#ifndef __LINUX_USB_OF_H
+#define __LINUX_USB_OF_H
+
+#include 
+
+#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 e8a5fe8..4e8bfbb 100644
--- a/include/linux/usb/otg.h
+++ b/include/linux/usb/otg.h
@@ -99,4 +99,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,
+};
+
 #endif /* __LINUX_USB_OTG_H */
diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h
index 15847cb..5edddb1 100644
--- a/include/linux/usb/phy.h
+++ b/include/linux/usb/phy.h
@@ -12,6 +12,15 @@
 #include 
 #include 
 
+enum usb_phy_interface {
+   USBPHY_INTERFACE_MODE_UNKNOWN,
+   USBPHY_INTERFACE_MODE_UTMI,
+   USBPHY_INTERFACE_MODE_UTMIW,
+   USBPHY_INTERFACE_MODE_ULPI,
+   USBPHY_INTERFACE_MODE_SERIAL,
+   USBPHY_INTERFACE_MODE_HSIC,
+};
+
 enum usb_phy_events {
USB_EVENT_NONE,  

[PATCH 6/6] USB chipidea i.MX: introduce dr_mode property

2013-01-31 Thread Sascha Hauer
The dr_mode devicetree property allows to explicitly specify the
host/peripheral/otg mode. This is necessary for boards without proper
ID pin handling.

Signed-off-by: Sascha Hauer 
---
 Documentation/devicetree/bindings/usb/ci13xxx-imx.txt |1 +
 drivers/usb/chipidea/ci13xxx_imx.c|1 +
 2 files changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt 
b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
index dd42ccd..493a414 100644
--- a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
+++ b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
@@ -9,6 +9,7 @@ Recommended properies:
 - phy_type: the type of the phy connected to the core. Should be one
   of "utmi", "utmi_wide", "ulpi", "serial" or "hsic". Without this
   property the PORTSC register won't be touched
+- dr_mode: One of "host", "peripheral" or "otg". Defaults to "otg"
 
 Optional properties:
 - fsl,usbphy: phandler of usb phy that connects to the only one port
diff --git a/drivers/usb/chipidea/ci13xxx_imx.c 
b/drivers/usb/chipidea/ci13xxx_imx.c
index ebc1148..b598bb8f 100644
--- a/drivers/usb/chipidea/ci13xxx_imx.c
+++ b/drivers/usb/chipidea/ci13xxx_imx.c
@@ -114,6 +114,7 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
   CI13XXX_DISABLE_STREAMING;
 
pdata->phy_mode = of_usb_get_phy_mode(pdev->dev.of_node);
+   pdata->dr_mode = of_usb_get_dr_mode(pdev->dev.of_node);
 
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
if (!data) {
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 5/6] USB chipidea: introduce dual role mode pdata flags

2013-01-31 Thread Sascha Hauer
Even if a chipidea core is otg capable the board may not. This allows
to explicitly set the core to host/peripheral mode. Without these
flags the driver falls back to the old behaviour.

Signed-off-by: Sascha Hauer 
---
 drivers/usb/chipidea/core.c  |   21 +++--
 include/linux/usb/chipidea.h |2 +-
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
index a3ec29d..b2dbf55 100644
--- a/drivers/usb/chipidea/core.c
+++ b/drivers/usb/chipidea/core.c
@@ -435,6 +435,7 @@ static int ci_hdrc_probe(struct platform_device *pdev)
struct resource *res;
void __iomem*base;
int ret;
+   int dr_mode;
 
if (!dev->platform_data) {
dev_err(dev, "platform data missing\n");
@@ -487,14 +488,22 @@ static int ci_hdrc_probe(struct platform_device *pdev)
return -ENODEV;
}
 
+   dr_mode = ci->platdata->dr_mode;
+   if (dr_mode == USB_DR_MODE_UNKNOWN)
+   dr_mode = USB_DR_MODE_OTG;
+
/* initialize role(s) before the interrupt is requested */
-   ret = ci_hdrc_host_init(ci);
-   if (ret)
-   dev_info(dev, "doesn't support host\n");
+   if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) {
+   ret = ci_hdrc_host_init(ci);
+   if (ret)
+   dev_info(dev, "doesn't support host\n");
+   }
 
-   ret = ci_hdrc_gadget_init(ci);
-   if (ret)
-   dev_info(dev, "doesn't support gadget\n");
+   if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_PERIPHERAL) {
+   ret = ci_hdrc_gadget_init(ci);
+   if (ret)
+   dev_info(dev, "doesn't support gadget\n");
+   }
 
if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) {
dev_err(dev, "no supported roles\n");
diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h
index 1a2aa18..b314647 100644
--- a/include/linux/usb/chipidea.h
+++ b/include/linux/usb/chipidea.h
@@ -20,7 +20,7 @@ struct ci13xxx_platform_data {
 #define CI13XXX_REQUIRE_TRANSCEIVERBIT(1)
 #define CI13XXX_PULLUP_ON_VBUS BIT(2)
 #define CI13XXX_DISABLE_STREAMING  BIT(3)
-
+   enum usb_dr_modedr_mode;
 #define CI13XXX_CONTROLLER_RESET_EVENT 0
 #define CI13XXX_CONTROLLER_STOPPED_EVENT   1
void(*notify_event) (struct ci13xxx *ci, unsigned event);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/6] USB: chipidea: ci13xxx-imx: create dynamic platformdata

2013-01-31 Thread Sascha Hauer
From: Michael Grzeschik 

This patch removes the limitation of having only one instance of the
ci13xxx-imx platformdata and makes different configurations possible.

Signed-off-by: Michael Grzeschik 
Signed-off-by: Marc Kleine-Budde 
Signed-off-by: Sascha Hauer 
---
 drivers/usb/chipidea/ci13xxx_imx.c |   25 +++--
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/chipidea/ci13xxx_imx.c 
b/drivers/usb/chipidea/ci13xxx_imx.c
index 8c29122..69024e0 100644
--- a/drivers/usb/chipidea/ci13xxx_imx.c
+++ b/drivers/usb/chipidea/ci13xxx_imx.c
@@ -85,17 +85,10 @@ EXPORT_SYMBOL_GPL(usbmisc_get_init_data);
 
 /* End of common functions shared by usbmisc drivers*/
 
-static struct ci13xxx_platform_data ci13xxx_imx_platdata  = {
-   .name   = "ci13xxx_imx",
-   .flags  = CI13XXX_REQUIRE_TRANSCEIVER |
- CI13XXX_PULLUP_ON_VBUS |
- CI13XXX_DISABLE_STREAMING,
-   .capoffset  = DEF_CAPOFFSET,
-};
-
 static int ci13xxx_imx_probe(struct platform_device *pdev)
 {
struct ci13xxx_imx_data *data;
+   struct ci13xxx_platform_data *pdata;
struct platform_device *plat_ci, *phy_pdev;
struct device_node *phy_np;
struct resource *res;
@@ -107,6 +100,18 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
&& !usbmisc_ops)
return -EPROBE_DEFER;
 
+   pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
+   if (!pdata) {
+   dev_err(&pdev->dev, "Failed to allocate CI13xxx-IMX pdata!\n");
+   return -ENOMEM;
+   }
+
+   pdata->name = "ci13xxx_imx";
+   pdata->capoffset = DEF_CAPOFFSET;
+   pdata->flags = CI13XXX_REQUIRE_TRANSCEIVER |
+  CI13XXX_PULLUP_ON_VBUS |
+  CI13XXX_DISABLE_STREAMING;
+
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
if (!data) {
dev_err(&pdev->dev, "Failed to allocate CI13xxx-IMX data!\n");
@@ -168,7 +173,7 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
reg_vbus = NULL;
}
 
-   ci13xxx_imx_platdata.phy = data->phy;
+   pdata->phy = data->phy;
 
if (!pdev->dev.dma_mask) {
pdev->dev.dma_mask = devm_kzalloc(&pdev->dev,
@@ -193,7 +198,7 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
 
plat_ci = ci13xxx_add_device(&pdev->dev,
pdev->resource, pdev->num_resources,
-   &ci13xxx_imx_platdata);
+   pdata);
if (IS_ERR(plat_ci)) {
ret = PTR_ERR(plat_ci);
dev_err(&pdev->dev,
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/6] USB: add devicetree helpers for determining dr_mode and phy_type

2013-01-31 Thread Sascha Hauer
On Thu, Jan 31, 2013 at 10:20:59AM +0100, Greg KH wrote:
> On Thu, Jan 31, 2013 at 10:01:09AM +0100, Sascha Hauer wrote:
> > From: Michael Grzeschik 
> > 
> > This adds two little devicetree helper functions for determining the
> > dr_mode (host, peripheral, otg) and phy_type (utmi, ulpi,...) from
> > the devicetree.
> > 
> > Signed-off-by: Michael Grzeschik 
> > Signed-off-by: Marc Kleine-Budde 
> > Signed-off-by: Sascha Hauer 
> > ---
> >  drivers/usb/phy/Makefile |1 +
> >  drivers/usb/phy/phy.c|   10 ++
> >  drivers/usb/usb-common.c |   36 
> >  include/linux/usb/of.h   |   27 +++
> >  include/linux/usb/otg.h  |7 +++
> >  include/linux/usb/phy.h  |9 +
> >  6 files changed, 90 insertions(+)
> >  create mode 100644 include/linux/usb/of.h
> > 
> > diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile
> > index 9fa6327..e1be1e8 100644
> > --- a/drivers/usb/phy/Makefile
> > +++ b/drivers/usb/phy/Makefile
> > @@ -5,6 +5,7 @@
> >  ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
> >  
> >  obj-$(CONFIG_USB_OTG_UTILS)+= phy.o
> > +obj-$(CONFIG_OF)   += of.o
> >  obj-$(CONFIG_OMAP_USB2)+= omap-usb2.o
> >  obj-$(CONFIG_OMAP_USB3)+= omap-usb3.o
> >  obj-$(CONFIG_OMAP_CONTROL_USB) += omap-control-usb.o
> > diff --git a/drivers/usb/phy/phy.c b/drivers/usb/phy/phy.c
> > index ef35eb0..3ad4b5c 100644
> > --- a/drivers/usb/phy/phy.c
> > +++ b/drivers/usb/phy/phy.c
> > @@ -1,3 +1,13 @@
> > +/*
> > + * phy.c -- USB phy handling
> > + *
> > + * Copyright (C) 2004 Texas Instruments
> > + *
> > + * 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.
> > + */
> 
> Do you really mean to change the license of the file from GPLv2 to
> GPLv2+?  Did TI agree to that licening change?  I need some
> documentation from some TI people before I can ever accept something
> like this.

Sorry, the hunk above belongs to patch 1/6. I did not change the
license, the header is a copy from drivers/usb/otg/otg.c which was
GPLv2+ already.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/6] USB: add devicetree helpers for determining dr_mode and phy_type

2013-01-31 Thread Sascha Hauer
On Thu, Jan 31, 2013 at 02:42:48PM +0530, kishon wrote:
> Hi,
> 
> On Thursday 31 January 2013 02:31 PM, Sascha Hauer wrote:
> >From: Michael Grzeschik 
> >
> >This adds two little devicetree helper functions for determining the
> >dr_mode (host, peripheral, otg) and phy_type (utmi, ulpi,...) from
> >the devicetree.
> >
> >Signed-off-by: Michael Grzeschik 
> >Signed-off-by: Marc Kleine-Budde 
> >Signed-off-by: Sascha Hauer 
> >---
> >  drivers/usb/phy/Makefile |1 +
> >  drivers/usb/phy/phy.c|   10 ++
> >  drivers/usb/usb-common.c |   36 
> >  include/linux/usb/of.h   |   27 +++
> >  include/linux/usb/otg.h  |7 +++
> >  include/linux/usb/phy.h  |9 +
> >  6 files changed, 90 insertions(+)
> >  create mode 100644 include/linux/usb/of.h
> >
> >diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile
> >index 9fa6327..e1be1e8 100644
> >--- a/drivers/usb/phy/Makefile
> >+++ b/drivers/usb/phy/Makefile
> >@@ -5,6 +5,7 @@
> >  ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
> >
> >  obj-$(CONFIG_USB_OTG_UTILS)+= phy.o
> >+obj-$(CONFIG_OF)+= of.o
> 
> You've missed doing "git add ..usb/phy/of.c".
> 
> >  obj-$(CONFIG_OMAP_USB2)+= omap-usb2.o
> >  obj-$(CONFIG_OMAP_USB3)+= omap-usb3.o
> >  obj-$(CONFIG_OMAP_CONTROL_USB) += omap-control-usb.o
> >diff --git a/drivers/usb/phy/phy.c b/drivers/usb/phy/phy.c
> >index ef35eb0..3ad4b5c 100644
> >--- a/drivers/usb/phy/phy.c
> >+++ b/drivers/usb/phy/phy.c
> >@@ -1,3 +1,13 @@
> >+/*
> >+ * phy.c -- USB phy handling
> >+ *
> >+ * Copyright (C) 2004 Texas Instruments
> 
> it's 2013 already :-P
> >+ *
> >+ * 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.
> 
> But your *MODULE_LICENSE("GPL")* below tells it's only GPL.

The MODULE_LICENSE("GPL") is in usb-common.c, not in the file I added.

Sascha

> .
> 
> .
> .
> 
> >  MODULE_LICENSE("GPL");
> 

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 4/6] usb: chipidea: add PTW and PTS handling

2013-01-31 Thread Sascha Hauer
On Thu, Jan 31, 2013 at 10:15:54AM +0100, Matthieu CASTET wrote:
> >> Why you don't implement it ?
> >>
> >> If you don't implement it, I believe you should add a warning in order to 
> >> catch
> >> it when used with lpm devices.
> > 
> > I'm against adding a warning because current users seem to go well
> > without this setting. Adding a warning would lead to more confusion than
> > it would help.
> > 
> > I could try and implement it, though I'm unsure about the register
> > layout.
> > 
> > What I know from an earlier post from you is this:
> > 
> > #define LPM_PTS(d)  (((d)>>29)&7)
> > #define LPM_STS BIT(28) /* serial transceiver select */
> > #define LPM_PTW BIT(27) /* parallel transceiver width */
> > 
> > Do you also know how LPM_PTS is decoded?
> 
> I will say the same as not lpm device :
> 
> PTS is  made up from PORTSCx bits 25, 30 and 31.

Here it is

PTS0 -> bit 30
PTS1 -> bit 31
PTS2 -> bit 25

> 
> PTS is  made up from devlc bits 31, 30 and 29.

In my new series I now assumed:

PTS0 -> bit 29
PTS1 -> bit 30
PTS2 -> bit 31

> 
> 
> Also in my datasheet, they give a way to check if the bits are read only or 
> read
> write [1]. I don't know if it is worth the trouble to check it.
> 
> 
> Matthieu
> 
> 
> [1]
> PTS
> This register bit pair is used in conjunction with the configuration constant
> VUSB_HS_PHY_TYPE to control which parallel transceiver interface is selected. 
> If
> VUSB_HS_PHY_TYPE is set for 0, 1, 2, 3, 8 or 10 then this bit is read only. If
> VUSB_HS_PHY_TYPE is 4, 5, 6, 7, 9 or 11 then this bit is read/write.
> 
> This field is reset to:
> '000b' if VUSB_HS_PHY_TYPE = 0, 4 ­ UTMI/UTMI+
> '001b' if VUSB_HS_PHY_TYPE = 1, 5 ­ ULPI DDR
> '010b' if VUSB_HS_PHY_TYPE = 2, 6 ­ ULPI
> '011b' if VUSB_HS_PHY_TYPE = 3, 7, 8, 9 ­ Serial/1.1 PHY/IC_USB (FS Only)
> '100b' if VUSB_HS_PHY_TYPE = 10, 11 ­ UTMI for HSIC PHY

Ok, this seems to match my assumption, except that our controller marks
the 'ULPI DDR' setting as reserved.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/6] USB: add devicetree helpers for determining dr_mode and phy_type

2013-01-31 Thread Sascha Hauer
On Thu, Jan 31, 2013 at 06:01:08PM +0800, Peter Chen wrote:
> On Thu, Jan 31, 2013 at 10:01:09AM +0100, Sascha Hauer wrote:
> > From: Michael Grzeschik 
> > 
> > 
> > +   for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++)
> > +   if (!strcmp(dr_mode, usb_dr_modes[i]))
> > +   return i;
> 
> if (strcmp(dr_mode, usb_dr_modes[i]) == 0) may be more friendly.
> 
> > +
> > +#ifndef __LINUX_USB_OF_H
> > +#define __LINUX_USB_OF_H
> > +
> > +#include 
> > +
> > +#ifdef CONFIG_OF
> > +enum usb_phy_interface of_usb_get_phy_mode(struct device_node *np);
> 
> Will you put definition to phy.c, I can't find it at this version

This goes to drivers/usb/phy/of.c Sorry, as Kishon noted I missed to git
add the file. See the attached updated patch.

> 
> > index e8a5fe8..4e8bfbb 100644
> > --- a/include/linux/usb/otg.h
> > +++ b/include/linux/usb/otg.h
> > @@ -99,4 +99,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 am not sure if otg.h is a good place to put this, in fact, we need
> a common header file for it.

Well linux/usb/otg.h is at least a header which can be included safely
by everyone interested in usb_dr_mode. Anyway, I'm open for better
suggestions, I just hesitated to add a new file just for this enum.

Sascha


>From 19c1a6552d6aa93f5ff354a224de0679d55a8126 Mon Sep 17 00:00:00 2001
From: Michael Grzeschik 
Date: Tue, 6 Nov 2012 16:10:10 +0100
Subject: [PATCH] USB: add devicetree helpers for determining dr_mode and
 phy_type

This adds two little devicetree helper functions for determining the
dr_mode (host, peripheral, otg) and phy_type (utmi, ulpi,...) from
the devicetree.

Signed-off-by: Michael Grzeschik 
Signed-off-by: Marc Kleine-Budde 
Signed-off-by: Sascha Hauer 
---
 drivers/usb/phy/Makefile |1 +
 drivers/usb/phy/of.c |   47 ++
 drivers/usb/usb-common.c |   36 +++
 include/linux/usb/of.h   |   27 ++
 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 9fa6327..e1be1e8 100644
--- a/drivers/usb/phy/Makefile
+++ b/drivers/usb/phy/Makefile
@@ -5,6 +5,7 @@
 ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
 
 obj-$(CONFIG_USB_OTG_UTILS)+= phy.o
+obj-$(CONFIG_OF)   += of.o
 obj-$(CONFIG_OMAP_USB2)+= omap-usb2.o
 obj-$(CONFIG_OMAP_USB3)+= omap-usb3.o
 obj-$(CONFIG_OMAP_CONTROL_USB) += omap-control-usb.o
diff --git a/drivers/usb/phy/of.c b/drivers/usb/phy/of.c
new file mode 100644
index 000..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 
+#include 
+#include 
+#include 
+#include 
+
+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 d29503e..ad4d87d 100644
--- a/drivers/usb/usb

Re: [PATCH,RFC] usb: add devicetree helpers for determining dr_mode and phy_type

2013-01-31 Thread Sascha Hauer
On Thu, Jan 31, 2013 at 10:05:44AM +0800, Peter Chen wrote:
> On Wed, Jan 30, 2013 at 03:00:15PM +0100, Sascha Hauer wrote:
> > On Wed, Jan 30, 2013 at 10:06:28AM +0800, Peter Chen wrote:
> > > On Tue, Jan 29, 2013 at 01:55:04PM +0200, Alexander Shishkin wrote:
> > > > Sascha Hauer  writes:
> > > > 
> > > > > From: Michael Grzeschik 
> > > > >
> > > > > This adds two little devicetree helper functions for determining the
> > > > > dr_mode (host, peripheral, otg) and phy_type (utmi, ulpi,...) from
> > > > > the devicetree.
> > > > >
> > > > > Signed-off-by: Michael Grzeschik 
> > > > > Signed-off-by: Marc Kleine-Budde 
> > > > > ---
> > > > >
> > > > > The properties and their values have been taken from the fsl-mph-dr 
> > > > > driver.
> > > > > This binding is also documented (though currently not used) for the 
> > > > > tegra
> > > > > ehci driver 
> > > > > (Documentation/devicetree/bindings/usb/nvidia,tegra20-ehci.txt).
> > > > > This is a first attempt to parse these bindings at a common place so 
> > > > > that
> > > > > others can make use of it.
> > > > >
> > > > > Basically I want to know whether this binding is recommended for new 
> > > > > drivers
> > > > > since normally the devicetree uses '-' instead of '_', and maybe 
> > > > > there are
> > > > > other problems with it.
> > > > >
> > > > > I need this binding for the chipidea driver. I suspect that the 
> > > > > fsl-mph-dr
> > > > > driver also really handles a chipidea core.
> > > > 
> > > > As far as I know, it is a chipidea core. Adding Peter to Cc list, he can
> > > > probably confirm.
> > > 
> > > The fsl-mph-dr can't be used for chipdiea as it handles three platform
> > > drivers for three roles (peripheral , host, otg). But chipidea only has
> > > two platform drivers, one is the chipidea core, the other is related
> > > controller wrapper.
> > 
> > What do you mean by 'three platform drivers'? That's only how the driver
> > is built, no? I was talking about the hardware the fsl-mph-dr driver
> > handles which definitely smells like chipidea.
> 
> It creates host/device/otg platform device according to dr_mode from
> the device tree.

Again, that's software specific. What I'd like to know is whether the
*hardware* could be handled by the chipidea driver.

Sascha


-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] USB chipidea i.MX: use framework phy handling

2013-01-31 Thread Sascha Hauer
This series switches the mxs phy and the i.MX chipidea support
from homegrew phy support to use usb_add_phy_dev/devm_usb_get_phy_by_phandle.

Based on

[PATCH v2] Add USB of helpers and use them in the chipidea driver

But I think this could also be applied separately if necessary.

Sascha


Sascha Hauer (2):
  USB mxs-phy: Register phy with framework
  USB chipidea i.MX: use devm_usb_get_phy_by_phandle to get phy

 drivers/usb/chipidea/ci13xxx_imx.c |   31 ++-
 drivers/usb/otg/mxs-phy.c  |9 +
 2 files changed, 19 insertions(+), 21 deletions(-)

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/2] USB mxs-phy: Register phy with framework

2013-01-31 Thread Sascha Hauer
We now have usb_add_phy_dev(), so use it to register with the framework
to be able to find the phy from the USB driver.

Signed-off-by: Sascha Hauer 
---
 drivers/usb/otg/mxs-phy.c |9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/usb/otg/mxs-phy.c b/drivers/usb/otg/mxs-phy.c
index 5158332..5b39885 100644
--- a/drivers/usb/otg/mxs-phy.c
+++ b/drivers/usb/otg/mxs-phy.c
@@ -127,6 +127,7 @@ static int mxs_phy_probe(struct platform_device *pdev)
void __iomem *base;
struct clk *clk;
struct mxs_phy *mxs_phy;
+   int ret;
 
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) {
@@ -166,11 +167,19 @@ static int mxs_phy_probe(struct platform_device *pdev)
 
platform_set_drvdata(pdev, &mxs_phy->phy);
 
+   ret = usb_add_phy_dev(&mxs_phy->phy);
+   if (ret)
+   return ret;
+
return 0;
 }
 
 static int mxs_phy_remove(struct platform_device *pdev)
 {
+   struct mxs_phy *mxs_phy = platform_get_drvdata(pdev);
+
+   usb_remove_phy(&mxs_phy->phy);
+
platform_set_drvdata(pdev, NULL);
 
return 0;
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/2] USB chipidea i.MX: use devm_usb_get_phy_by_phandle to get phy

2013-01-31 Thread Sascha Hauer
Signed-off-by: Sascha Hauer 
---
 drivers/usb/chipidea/ci13xxx_imx.c |   31 ++-
 1 file changed, 10 insertions(+), 21 deletions(-)

diff --git a/drivers/usb/chipidea/ci13xxx_imx.c 
b/drivers/usb/chipidea/ci13xxx_imx.c
index b598bb8f..1df4b41 100644
--- a/drivers/usb/chipidea/ci13xxx_imx.c
+++ b/drivers/usb/chipidea/ci13xxx_imx.c
@@ -30,7 +30,6 @@
((struct usb_phy *)platform_get_drvdata(pdev))
 
 struct ci13xxx_imx_data {
-   struct device_node *phy_np;
struct usb_phy *phy;
struct platform_device *ci_pdev;
struct clk *clk;
@@ -90,12 +89,12 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
 {
struct ci13xxx_imx_data *data;
struct ci13xxx_platform_data *pdata;
-   struct platform_device *plat_ci, *phy_pdev;
-   struct device_node *phy_np;
+   struct platform_device *plat_ci;
struct resource *res;
struct regulator *reg_vbus;
struct pinctrl *pinctrl;
int ret;
+   struct usb_phy *phy;
 
if (of_find_property(pdev->dev.of_node, "fsl,usbmisc", NULL)
&& !usbmisc_ops)
@@ -147,18 +146,12 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
return ret;
}
 
-   phy_np = of_parse_phandle(pdev->dev.of_node, "fsl,usbphy", 0);
-   if (phy_np) {
-   data->phy_np = phy_np;
-   phy_pdev = of_find_device_by_node(phy_np);
-   if (phy_pdev) {
-   struct usb_phy *phy;
-   phy = pdev_to_phy(phy_pdev);
-   if (phy &&
-   try_module_get(phy_pdev->dev.driver->owner)) {
-   usb_phy_init(phy);
-   data->phy = phy;
-   }
+   phy = devm_usb_get_phy_by_phandle(&pdev->dev, "fsl,usbphy", 0);
+   if (!IS_ERR(phy)) {
+   ret = usb_phy_init(phy);
+   if (ret) {
+   dev_err(&pdev->dev, "unable to init phy: %d\n", ret);
+   goto err_clk;
}
}
 
@@ -170,7 +163,7 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
dev_err(&pdev->dev,
"Failed to enable vbus regulator, err=%d\n",
ret);
-   goto put_np;
+   goto err_clk;
}
data->reg_vbus = reg_vbus;
} else {
@@ -222,9 +215,7 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
 err:
if (reg_vbus)
regulator_disable(reg_vbus);
-put_np:
-   if (phy_np)
-   of_node_put(phy_np);
+err_clk:
clk_disable_unprepare(data->clk);
return ret;
 }
@@ -244,8 +235,6 @@ static int ci13xxx_imx_remove(struct platform_device *pdev)
module_put(data->phy->dev->driver->owner);
}
 
-   of_node_put(data->phy_np);
-
clk_disable_unprepare(data->clk);
 
platform_set_drvdata(pdev, NULL);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH,RFC] usb: add devicetree helpers for determining dr_mode and phy_type

2013-01-31 Thread Sascha Hauer
On Fri, Feb 01, 2013 at 09:11:54AM +0800, Peter Chen wrote:
> On Thu, Jan 31, 2013 at 11:29:13AM +0100, Sascha Hauer wrote:
> > On Thu, Jan 31, 2013 at 10:05:44AM +0800, Peter Chen wrote:
> > > On Wed, Jan 30, 2013 at 03:00:15PM +0100, Sascha Hauer wrote:
> > > > On Wed, Jan 30, 2013 at 10:06:28AM +0800, Peter Chen wrote:
> > > > > On Tue, Jan 29, 2013 at 01:55:04PM +0200, Alexander Shishkin wrote:
> > > > > > Sascha Hauer  writes:
> > > > > > 
> > > > > > > From: Michael Grzeschik 
> > > > > > >
> > > > > > > This adds two little devicetree helper functions for determining 
> > > > > > > the
> > > > > > > dr_mode (host, peripheral, otg) and phy_type (utmi, ulpi,...) from
> > > > > > > the devicetree.
> > > > > > >
> > > > > > > Signed-off-by: Michael Grzeschik 
> > > > > > > Signed-off-by: Marc Kleine-Budde 
> > > > > > > ---
> > > > > > >
> > > > > > > The properties and their values have been taken from the 
> > > > > > > fsl-mph-dr driver.
> > > > > > > This binding is also documented (though currently not used) for 
> > > > > > > the tegra
> > > > > > > ehci driver 
> > > > > > > (Documentation/devicetree/bindings/usb/nvidia,tegra20-ehci.txt).
> > > > > > > This is a first attempt to parse these bindings at a common place 
> > > > > > > so that
> > > > > > > others can make use of it.
> > > > > > >
> > > > > > > Basically I want to know whether this binding is recommended for 
> > > > > > > new drivers
> > > > > > > since normally the devicetree uses '-' instead of '_', and maybe 
> > > > > > > there are
> > > > > > > other problems with it.
> > > > > > >
> > > > > > > I need this binding for the chipidea driver. I suspect that the 
> > > > > > > fsl-mph-dr
> > > > > > > driver also really handles a chipidea core.
> > > > > > 
> > > > > > As far as I know, it is a chipidea core. Adding Peter to Cc list, 
> > > > > > he can
> > > > > > probably confirm.
> > > > > 
> > > > > The fsl-mph-dr can't be used for chipdiea as it handles three platform
> > > > > drivers for three roles (peripheral , host, otg). But chipidea only 
> > > > > has
> > > > > two platform drivers, one is the chipidea core, the other is related
> > > > > controller wrapper.
> > > > 
> > > > What do you mean by 'three platform drivers'? That's only how the driver
> > > > is built, no? I was talking about the hardware the fsl-mph-dr driver
> > > > handles which definitely smells like chipidea.
> > > 
> > > It creates host/device/otg platform device according to dr_mode from
> > > the device tree.
> > 
> > Again, that's software specific. What I'd like to know is whether the
> > *hardware* could be handled by the chipidea driver.
> not understand u, you mean the DT information at there? Those DT information
> may not be used for i.mx hardware.

The original question was:

There is a driver in the tree called fsl-mph-dr-of.c. Does this driver
handle a hardware which is compatible to the hardware the chipidea
driver handles?

I think the answer is yes, because said driver registers a ehci device,
or fsl-usb2-udc device (the same we used on i.MX). This hardware also
has a PORTSC register. All this seems to suggest that

drivers/usb/host/fsl-mph-dr-of.c
drivers/usb/host/ehci-fsl.c
drivers/usb/otg/fsl_otg.c
drivers/usb/gadget/fsl_usb2_udc.h
drivers/usb/gadget/fsl_udc_core.c

Could be replaced by the chipidea driver.

Sascha


-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] USB chipidea i.MX: use framework phy handling

2013-01-31 Thread Sascha Hauer
On Thu, Jan 31, 2013 at 12:32:15PM +0100, Sascha Hauer wrote:
> This series switches the mxs phy and the i.MX chipidea support
> from homegrew phy support to use usb_add_phy_dev/devm_usb_get_phy_by_phandle.
> 
> Based on
> 
> [PATCH v2] Add USB of helpers and use them in the chipidea driver
> 
> But I think this could also be applied separately if necessary.

Kishon, Peter,

Thanks for reviewing these, but I'm afraid I must send another iteration
for these. These patches do not handle -EPROBE_DEFER correctly.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 7/9] como fec wip

2013-01-31 Thread Sascha Hauer
Signed-off-by: Sascha Hauer 
---
 Documentation/devicetree/bindings/net/fsl-fec.txt |   20 ++
 drivers/net/ethernet/freescale/fec.c  |   77 -
 drivers/net/ethernet/freescale/fec.h  |1 +
 3 files changed, 67 insertions(+), 31 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/fsl-fec.txt 
b/Documentation/devicetree/bindings/net/fsl-fec.txt
index d536392..ec7060b 100644
--- a/Documentation/devicetree/bindings/net/fsl-fec.txt
+++ b/Documentation/devicetree/bindings/net/fsl-fec.txt
@@ -15,6 +15,9 @@ Optional properties:
   only if property "phy-reset-gpios" is available.  Missing the property
   will have the duration be 1 millisecond.  Numbers greater than 1000 are
   invalid and 1 millisecond will be used instead.
+- phy : a phandle for the PHY device used for the fec. Used to specify an
+  external phy or to specify a particular address if the mdio bus has multiple
+  phys on it.
 
 Example:
 
@@ -26,3 +29,20 @@ ethernet@83fec000 {
phy-reset-gpios = <&gpio2 14 0>; /* GPIO2_14 */
local-mac-address = [00 04 9F 01 1B B9];
 };
+
+Example with specific phy address:
+
+ethernet@83fec000 {
+   compatible = "fsl,imx51-fec", "fsl,imx27-fec";
+   reg = <0x83fec000 0x4000>;
+   interrupts = <87>;
+   phy-mode = "mii";
+   phy-reset-gpios = <&gpio2 14 0>; /* GPIO2_14 */
+   local-mac-address = [00 04 9F 01 1B B9];
+   phy = &phy3;
+
+   phy3: ethernet-phy@3 {
+   reg = <3>;
+   device_type = "ethernet-phy";
+   };
+};
diff --git a/drivers/net/ethernet/freescale/fec.c 
b/drivers/net/ethernet/freescale/fec.c
index 0704bca..54a8506 100644
--- a/drivers/net/ethernet/freescale/fec.c
+++ b/drivers/net/ethernet/freescale/fec.c
@@ -48,6 +48,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -950,31 +951,38 @@ static int fec_enet_mii_probe(struct net_device *ndev)
 
fep->phy_dev = NULL;
 
-   /* check for attached phy */
-   for (phy_id = 0; (phy_id < PHY_MAX_ADDR); phy_id++) {
-   if ((fep->mii_bus->phy_mask & (1 << phy_id)))
-   continue;
-   if (fep->mii_bus->phy_map[phy_id] == NULL)
-   continue;
-   if (fep->mii_bus->phy_map[phy_id]->phy_id == 0)
-   continue;
-   if (dev_id--)
-   continue;
-   strncpy(mdio_bus_id, fep->mii_bus->id, MII_BUS_ID_SIZE);
-   break;
-   }
+   if (fep->phy_node) {
+   phy_dev = of_phy_connect(ndev, fep->phy_node, 
&fec_enet_adjust_link, 0,
+ fep->phy_interface);
+   } else {
+   /* check for attached phy */
+   for (phy_id = 0; (phy_id < PHY_MAX_ADDR); phy_id++) {
+   if ((fep->mii_bus->phy_mask & (1 << phy_id)))
+   continue;
+   if (fep->mii_bus->phy_map[phy_id] == NULL)
+   continue;
+   if (fep->mii_bus->phy_map[phy_id]->phy_id == 0)
+   continue;
+   if (dev_id--)
+   continue;
+   strncpy(mdio_bus_id, fep->mii_bus->id, MII_BUS_ID_SIZE);
+   break;
+   }
 
-   if (phy_id >= PHY_MAX_ADDR) {
-   printk(KERN_INFO
-   "%s: no PHY, assuming direct connection to switch\n",
-   ndev->name);
-   strncpy(mdio_bus_id, "fixed-0", MII_BUS_ID_SIZE);
-   phy_id = 0;
+   if (phy_id >= PHY_MAX_ADDR) {
+   printk(KERN_INFO
+   "%s: no PHY, assuming direct connection to 
switch\n",
+   ndev->name);
+   strncpy(mdio_bus_id, "fixed-0", MII_BUS_ID_SIZE);
+   phy_id = 0;
+   }
+
+   snprintf(phy_name, sizeof(phy_name), PHY_ID_FMT, mdio_bus_id, 
phy_id);
+
+   phy_dev = phy_connect(ndev, phy_name, &fec_enet_adjust_link, 0,
+ fep->phy_interface);
}
 
-   snprintf(phy_name, sizeof(phy_name), PHY_ID_FMT, mdio_bus_id, phy_id);
-   phy_dev = phy_connect(ndev, phy_name, &fec_enet_adjust_link, 0,
- fep->phy_interface);
if (IS_ERR(phy_dev)) {
printk(KERN_ERR "%s: could not attach to PHY\n", ndev->name);
return PTR_ERR(phy_dev);
@@ -1076,7 +1084,12 @@ static int fec_enet_mii_init(struct platform_device 
*pdev)
for (i = 0; i < PHY_MAX_ADD

[PATCH 5/9] USB chipidea: introduce dual role mode pdata flags

2013-01-31 Thread Sascha Hauer
Even if a chipidea core is otg capable the board may not. This allows
to explicitly set the core to host/peripheral mode. Without these
flags the driver falls back to the old behaviour.

Signed-off-by: Sascha Hauer 
---
 drivers/usb/chipidea/core.c  |   21 +++--
 include/linux/usb/chipidea.h |2 +-
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
index a3ec29d..b2dbf55 100644
--- a/drivers/usb/chipidea/core.c
+++ b/drivers/usb/chipidea/core.c
@@ -435,6 +435,7 @@ static int ci_hdrc_probe(struct platform_device *pdev)
struct resource *res;
void __iomem*base;
int ret;
+   int dr_mode;
 
if (!dev->platform_data) {
dev_err(dev, "platform data missing\n");
@@ -487,14 +488,22 @@ static int ci_hdrc_probe(struct platform_device *pdev)
return -ENODEV;
}
 
+   dr_mode = ci->platdata->dr_mode;
+   if (dr_mode == USB_DR_MODE_UNKNOWN)
+   dr_mode = USB_DR_MODE_OTG;
+
/* initialize role(s) before the interrupt is requested */
-   ret = ci_hdrc_host_init(ci);
-   if (ret)
-   dev_info(dev, "doesn't support host\n");
+   if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) {
+   ret = ci_hdrc_host_init(ci);
+   if (ret)
+   dev_info(dev, "doesn't support host\n");
+   }
 
-   ret = ci_hdrc_gadget_init(ci);
-   if (ret)
-   dev_info(dev, "doesn't support gadget\n");
+   if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_PERIPHERAL) {
+   ret = ci_hdrc_gadget_init(ci);
+   if (ret)
+   dev_info(dev, "doesn't support gadget\n");
+   }
 
if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) {
dev_err(dev, "no supported roles\n");
diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h
index 1a2aa18..b314647 100644
--- a/include/linux/usb/chipidea.h
+++ b/include/linux/usb/chipidea.h
@@ -20,7 +20,7 @@ struct ci13xxx_platform_data {
 #define CI13XXX_REQUIRE_TRANSCEIVERBIT(1)
 #define CI13XXX_PULLUP_ON_VBUS BIT(2)
 #define CI13XXX_DISABLE_STREAMING  BIT(3)
-
+   enum usb_dr_modedr_mode;
 #define CI13XXX_CONTROLLER_RESET_EVENT 0
 #define CI13XXX_CONTROLLER_STOPPED_EVENT   1
void(*notify_event) (struct ci13xxx *ci, unsigned event);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/9] USB: chipidea: ci13xxx-imx: create dynamic platformdata

2013-01-31 Thread Sascha Hauer
From: Michael Grzeschik 

This patch removes the limitation of having only one instance of the
ci13xxx-imx platformdata and makes different configurations possible.

Signed-off-by: Michael Grzeschik 
Signed-off-by: Marc Kleine-Budde 
Signed-off-by: Sascha Hauer 
Reviewed-by: Peter Chen 
---
 drivers/usb/chipidea/ci13xxx_imx.c |   25 +++--
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/chipidea/ci13xxx_imx.c 
b/drivers/usb/chipidea/ci13xxx_imx.c
index 8c29122..69024e0 100644
--- a/drivers/usb/chipidea/ci13xxx_imx.c
+++ b/drivers/usb/chipidea/ci13xxx_imx.c
@@ -85,17 +85,10 @@ EXPORT_SYMBOL_GPL(usbmisc_get_init_data);
 
 /* End of common functions shared by usbmisc drivers*/
 
-static struct ci13xxx_platform_data ci13xxx_imx_platdata  = {
-   .name   = "ci13xxx_imx",
-   .flags  = CI13XXX_REQUIRE_TRANSCEIVER |
- CI13XXX_PULLUP_ON_VBUS |
- CI13XXX_DISABLE_STREAMING,
-   .capoffset  = DEF_CAPOFFSET,
-};
-
 static int ci13xxx_imx_probe(struct platform_device *pdev)
 {
struct ci13xxx_imx_data *data;
+   struct ci13xxx_platform_data *pdata;
struct platform_device *plat_ci, *phy_pdev;
struct device_node *phy_np;
struct resource *res;
@@ -107,6 +100,18 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
&& !usbmisc_ops)
return -EPROBE_DEFER;
 
+   pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
+   if (!pdata) {
+   dev_err(&pdev->dev, "Failed to allocate CI13xxx-IMX pdata!\n");
+   return -ENOMEM;
+   }
+
+   pdata->name = "ci13xxx_imx";
+   pdata->capoffset = DEF_CAPOFFSET;
+   pdata->flags = CI13XXX_REQUIRE_TRANSCEIVER |
+  CI13XXX_PULLUP_ON_VBUS |
+  CI13XXX_DISABLE_STREAMING;
+
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
if (!data) {
dev_err(&pdev->dev, "Failed to allocate CI13xxx-IMX data!\n");
@@ -168,7 +173,7 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
reg_vbus = NULL;
}
 
-   ci13xxx_imx_platdata.phy = data->phy;
+   pdata->phy = data->phy;
 
if (!pdev->dev.dma_mask) {
pdev->dev.dma_mask = devm_kzalloc(&pdev->dev,
@@ -193,7 +198,7 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
 
plat_ci = ci13xxx_add_device(&pdev->dev,
pdev->resource, pdev->num_resources,
-   &ci13xxx_imx_platdata);
+   pdata);
if (IS_ERR(plat_ci)) {
ret = PTR_ERR(plat_ci);
dev_err(&pdev->dev,
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/9] USB: add devicetree helpers for determining dr_mode and phy_type

2013-01-31 Thread Sascha Hauer
From: Michael Grzeschik 

This adds two little devicetree helper functions for determining the
dr_mode (host, peripheral, otg) and phy_type (utmi, ulpi,...) from
the devicetree.

Signed-off-by: Michael Grzeschik 
Signed-off-by: Marc Kleine-Budde 
Signed-off-by: Sascha Hauer 
---
 drivers/usb/phy/Makefile |1 +
 drivers/usb/phy/of.c |   47 ++
 drivers/usb/usb-common.c |   36 +++
 include/linux/usb/of.h   |   27 ++
 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 9fa6327..e1be1e8 100644
--- a/drivers/usb/phy/Makefile
+++ b/drivers/usb/phy/Makefile
@@ -5,6 +5,7 @@
 ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
 
 obj-$(CONFIG_USB_OTG_UTILS)+= phy.o
+obj-$(CONFIG_OF)   += of.o
 obj-$(CONFIG_OMAP_USB2)+= omap-usb2.o
 obj-$(CONFIG_OMAP_USB3)+= omap-usb3.o
 obj-$(CONFIG_OMAP_CONTROL_USB) += omap-control-usb.o
diff --git a/drivers/usb/phy/of.c b/drivers/usb/phy/of.c
new file mode 100644
index 000..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 
+#include 
+#include 
+#include 
+#include 
+
+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 d29503e..ad4d87d 100644
--- a/drivers/usb/usb-common.c
+++ b/drivers/usb/usb-common.c
@@ -14,6 +14,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 const char *usb_speed_string(enum usb_device_speed speed)
 {
@@ -32,4 +35,37 @@ const char *usb_speed_string(enum usb_device_speed speed)
 }
 EXPORT_SYMBOL_GPL(usb_speed_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 000..4681a20
--- /dev/null
+++ b/include/linux/usb/of.h
@@ -0,0 +1,27 @@
+/*
+ * OF helpers for usb devices.
+ *
+ * This file is released under the GPLv2
+ */
+
+#ifndef __LINUX_USB_OF_H
+#define __LINUX_USB_OF_H
+
+#include 
+
+#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(s

[PATCH 8/9] USB mxs-phy: Register phy with framework

2013-01-31 Thread Sascha Hauer
We now have usb_add_phy_dev(), so use it to register with the framework
to be able to find the phy from the USB driver.

Signed-off-by: Sascha Hauer 
---
 drivers/usb/otg/mxs-phy.c |9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/usb/otg/mxs-phy.c b/drivers/usb/otg/mxs-phy.c
index 5158332..5b39885 100644
--- a/drivers/usb/otg/mxs-phy.c
+++ b/drivers/usb/otg/mxs-phy.c
@@ -127,6 +127,7 @@ static int mxs_phy_probe(struct platform_device *pdev)
void __iomem *base;
struct clk *clk;
struct mxs_phy *mxs_phy;
+   int ret;
 
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) {
@@ -166,11 +167,19 @@ static int mxs_phy_probe(struct platform_device *pdev)
 
platform_set_drvdata(pdev, &mxs_phy->phy);
 
+   ret = usb_add_phy_dev(&mxs_phy->phy);
+   if (ret)
+   return ret;
+
return 0;
 }
 
 static int mxs_phy_remove(struct platform_device *pdev)
 {
+   struct mxs_phy *mxs_phy = platform_get_drvdata(pdev);
+
+   usb_remove_phy(&mxs_phy->phy);
+
platform_set_drvdata(pdev, NULL);
 
return 0;
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3] USB: add devicetree helpers for determining dr_mode and phy_type

2013-01-31 Thread Sascha Hauer
(resend because I got the linux-usb address wrong)

Here's another round of the dr_mode/phy_type patches. I think they should
be ready for merging now. Greg, will you apply them should there be no
problems anymore?

Sascha

changes since v2:

- fix adding of GPL Header was in wrong patch
- add missing hunk for new file of.c

changes since v1:
- move phy specific of helper to drivers/usb/phy/of.c
- use strcmp instead of strcasecmp for matching property values
- change usb_phy_dr_mode to usb_dr_mode
- change USBPHY_INTERFACE_MODE_NA to USBPHY_INTERFACE_MODE_UNKNOWN
- add copyright header to new files
- chipidea: drop mdelay at end of PTS/PTW setup
- chipidea: implement lpm core type handling for PTS/PTW

The following changes since commit 7b8bc3aad0deabf3bc50cd2fe29bce29be5681fe:

  USB: chipidea: ci13xxx_imx: Remove sparse warning (2013-01-30 00:17:39 -0500)

are available in the git repository at:

  git://git.pengutronix.de/git/imx/linux-2.6.git tags/usb-chipidea-for-next

for you to fetch changes up to b82b92ba281add3e4d67bf6704052c0fd8c5c7f0:

  USB chipidea i.MX: use devm_usb_get_phy_by_phandle to get phy (2013-01-31 
12:27:36 +0100)


USB Chipidea patches for v3.9

These add OF helpers for handling the dr_mode and phy_type property
and makes use of them in the chipidea driver.


Michael Grzeschik (3):
  USB: add devicetree helpers for determining dr_mode and phy_type
  USB: chipidea: ci13xxx-imx: create dynamic platformdata
  USB: chipidea: add PTW and PTS handling

Sascha Hauer (6):
  USB: move bulk of otg/otg.c to phy/phy.c
  USB chipidea: introduce dual role mode pdata flags
  USB chipidea i.MX: introduce dr_mode property
  como fec wip
  USB mxs-phy: Register phy with framework
  USB chipidea i.MX: use devm_usb_get_phy_by_phandle to get phy

 Documentation/devicetree/bindings/net/fsl-fec.txt  |   20 +
 .../devicetree/bindings/usb/ci13xxx-imx.txt|6 +
 drivers/net/ethernet/freescale/fec.c   |   77 ++--
 drivers/net/ethernet/freescale/fec.h   |1 +
 drivers/usb/chipidea/bits.h|   14 +-
 drivers/usb/chipidea/ci13xxx_imx.c |   60 ++-
 drivers/usb/chipidea/core.c|   60 ++-
 drivers/usb/otg/mxs-phy.c  |9 +
 drivers/usb/otg/otg.c  |  423 ---
 drivers/usb/phy/Makefile   |2 +
 drivers/usb/phy/of.c   |   47 +++
 drivers/usb/phy/phy.c  |  434 
 drivers/usb/usb-common.c   |   36 ++
 include/linux/usb/chipidea.h   |3 +-
 include/linux/usb/of.h |   27 ++
 include/linux/usb/otg.h|7 +
 include/linux/usb/phy.h|9 +
 17 files changed, 742 insertions(+), 493 deletions(-)
 create mode 100644 drivers/usb/phy/of.c
 create mode 100644 drivers/usb/phy/phy.c
 create mode 100644 include/linux/usb/of.h
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 4/9] USB: chipidea: add PTW and PTS handling

2013-01-31 Thread Sascha Hauer
From: Michael Grzeschik 

This patch makes it possible to configure the PTW and PTS bits inside
the portsc register for host and device mode before the driver starts
and the phy can be addressed as hardware implementation is designed.

Signed-off-by: Michael Grzeschik 
Signed-off-by: Marc Kleine-Budde 
Signed-off-by: Sascha Hauer 
---
 .../devicetree/bindings/usb/ci13xxx-imx.txt|5 +++
 drivers/usb/chipidea/bits.h|   14 ++-
 drivers/usb/chipidea/ci13xxx_imx.c |3 ++
 drivers/usb/chipidea/core.c|   39 
 include/linux/usb/chipidea.h   |1 +
 5 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt 
b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
index 5778b9c..dd42ccd 100644
--- a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
+++ b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
@@ -5,6 +5,11 @@ Required properties:
 - reg: Should contain registers location and length
 - interrupts: Should contain controller interrupt
 
+Recommended properies:
+- phy_type: the type of the phy connected to the core. Should be one
+  of "utmi", "utmi_wide", "ulpi", "serial" or "hsic". Without this
+  property the PORTSC register won't be touched
+
 Optional properties:
 - fsl,usbphy: phandler of usb phy that connects to the only one port
 - fsl,usbmisc: phandler of non-core register device, with one argument
diff --git a/drivers/usb/chipidea/bits.h b/drivers/usb/chipidea/bits.h
index 050de85..d8ffc2f 100644
--- a/drivers/usb/chipidea/bits.h
+++ b/drivers/usb/chipidea/bits.h
@@ -48,10 +48,22 @@
 #define PORTSC_SUSP   BIT(7)
 #define PORTSC_HSPBIT(9)
 #define PORTSC_PTC(0x0FUL << 16)
+/* PTS and PTW for non lpm version only */
+#define PORTSC_PTS(d) d) & 0x3) << 30) | (((d) & 0x4) ? BIT(25) : 
0))
+#define PORTSC_PTWBIT(28)
 
 /* DEVLC */
 #define DEVLC_PSPD(0x03UL << 25)
-#defineDEVLC_PSPD_HS  (0x02UL << 25)
+#define DEVLC_PSPD_HS (0x02UL << 25)
+#define DEVLC_PTW BIT(27)
+#define DEVLC_STS BIT(28)
+#define DEVLC_PTS(d)  (((d) & 0x7) << 29)
+
+/* Encoding for DEVLC_PTS and PORTSC_PTS */
+#define PTS_UTMI  0
+#define PTS_ULPI  2
+#define PTS_SERIAL3
+#define PTS_HSIC  4
 
 /* OTGSC */
 #define OTGSC_IDPU   BIT(5)
diff --git a/drivers/usb/chipidea/ci13xxx_imx.c 
b/drivers/usb/chipidea/ci13xxx_imx.c
index 69024e0..ebc1148 100644
--- a/drivers/usb/chipidea/ci13xxx_imx.c
+++ b/drivers/usb/chipidea/ci13xxx_imx.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "ci.h"
 #include "ci13xxx_imx.h"
@@ -112,6 +113,8 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
   CI13XXX_PULLUP_ON_VBUS |
   CI13XXX_DISABLE_STREAMING;
 
+   pdata->phy_mode = of_usb_get_phy_mode(pdev->dev.of_node);
+
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
if (!data) {
dev_err(&pdev->dev, "Failed to allocate CI13xxx-IMX data!\n");
diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
index 57cae1f..a3ec29d 100644
--- a/drivers/usb/chipidea/core.c
+++ b/drivers/usb/chipidea/core.c
@@ -67,6 +67,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include "ci.h"
 #include "udc.h"
@@ -211,6 +213,41 @@ static int hw_device_init(struct ci13xxx *ci, void __iomem 
*base)
return 0;
 }
 
+static void hw_phymode_configure(struct ci13xxx *ci)
+{
+   u32 portsc, lpm;
+
+   switch (ci->platdata->phy_mode) {
+   case USBPHY_INTERFACE_MODE_UTMI:
+   portsc = PORTSC_PTS(PTS_UTMI);
+   lpm = DEVLC_PTS(PTS_UTMI);
+   break;
+   case USBPHY_INTERFACE_MODE_UTMIW:
+   portsc = PORTSC_PTS(PTS_UTMI) | PORTSC_PTW;
+   lpm = DEVLC_PTS(PTS_UTMI) | DEVLC_PTW;
+   break;
+   case USBPHY_INTERFACE_MODE_ULPI:
+   portsc = PORTSC_PTS(PTS_ULPI);
+   lpm = DEVLC_PTS(PTS_ULPI);
+   break;
+   case USBPHY_INTERFACE_MODE_SERIAL:
+   portsc = PORTSC_PTS(PTS_SERIAL);
+   lpm = DEVLC_PTS(PTS_SERIAL);
+   break;
+   case USBPHY_INTERFACE_MODE_HSIC:
+   portsc = PORTSC_PTS(PTS_HSIC);
+   lpm = DEVLC_PTS(PTS_HSIC);
+   break;
+   default:
+   return;
+   }
+
+   if (ci->hw_bank.lpm)
+   hw_write(ci, OP_PORTSC, DEVLC_PTS(7) | DEVLC_PTW, lpm);
+   else
+   hw_write(ci, OP_PORTSC, PORTSC_PTS(7) | PORTSC_PTW

[PATCH 6/9] USB chipidea i.MX: introduce dr_mode property

2013-01-31 Thread Sascha Hauer
The dr_mode devicetree property allows to explicitly specify the
host/peripheral/otg mode. This is necessary for boards without proper
ID pin handling.

Signed-off-by: Sascha Hauer 
Reviewed-by: Peter Chen 
---
 Documentation/devicetree/bindings/usb/ci13xxx-imx.txt |1 +
 drivers/usb/chipidea/ci13xxx_imx.c|1 +
 2 files changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt 
b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
index dd42ccd..493a414 100644
--- a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
+++ b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
@@ -9,6 +9,7 @@ Recommended properies:
 - phy_type: the type of the phy connected to the core. Should be one
   of "utmi", "utmi_wide", "ulpi", "serial" or "hsic". Without this
   property the PORTSC register won't be touched
+- dr_mode: One of "host", "peripheral" or "otg". Defaults to "otg"
 
 Optional properties:
 - fsl,usbphy: phandler of usb phy that connects to the only one port
diff --git a/drivers/usb/chipidea/ci13xxx_imx.c 
b/drivers/usb/chipidea/ci13xxx_imx.c
index ebc1148..b598bb8f 100644
--- a/drivers/usb/chipidea/ci13xxx_imx.c
+++ b/drivers/usb/chipidea/ci13xxx_imx.c
@@ -114,6 +114,7 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
   CI13XXX_DISABLE_STREAMING;
 
pdata->phy_mode = of_usb_get_phy_mode(pdev->dev.of_node);
+   pdata->dr_mode = of_usb_get_dr_mode(pdev->dev.of_node);
 
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
if (!data) {
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 9/9] USB chipidea i.MX: use devm_usb_get_phy_by_phandle to get phy

2013-01-31 Thread Sascha Hauer
Signed-off-by: Sascha Hauer 
---
 drivers/usb/chipidea/ci13xxx_imx.c |   31 ++-
 1 file changed, 10 insertions(+), 21 deletions(-)

diff --git a/drivers/usb/chipidea/ci13xxx_imx.c 
b/drivers/usb/chipidea/ci13xxx_imx.c
index b598bb8f..1df4b41 100644
--- a/drivers/usb/chipidea/ci13xxx_imx.c
+++ b/drivers/usb/chipidea/ci13xxx_imx.c
@@ -30,7 +30,6 @@
((struct usb_phy *)platform_get_drvdata(pdev))
 
 struct ci13xxx_imx_data {
-   struct device_node *phy_np;
struct usb_phy *phy;
struct platform_device *ci_pdev;
struct clk *clk;
@@ -90,12 +89,12 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
 {
struct ci13xxx_imx_data *data;
struct ci13xxx_platform_data *pdata;
-   struct platform_device *plat_ci, *phy_pdev;
-   struct device_node *phy_np;
+   struct platform_device *plat_ci;
struct resource *res;
struct regulator *reg_vbus;
struct pinctrl *pinctrl;
int ret;
+   struct usb_phy *phy;
 
if (of_find_property(pdev->dev.of_node, "fsl,usbmisc", NULL)
&& !usbmisc_ops)
@@ -147,18 +146,12 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
return ret;
}
 
-   phy_np = of_parse_phandle(pdev->dev.of_node, "fsl,usbphy", 0);
-   if (phy_np) {
-   data->phy_np = phy_np;
-   phy_pdev = of_find_device_by_node(phy_np);
-   if (phy_pdev) {
-   struct usb_phy *phy;
-   phy = pdev_to_phy(phy_pdev);
-   if (phy &&
-   try_module_get(phy_pdev->dev.driver->owner)) {
-   usb_phy_init(phy);
-   data->phy = phy;
-   }
+   phy = devm_usb_get_phy_by_phandle(&pdev->dev, "fsl,usbphy", 0);
+   if (!IS_ERR(phy)) {
+   ret = usb_phy_init(phy);
+   if (ret) {
+   dev_err(&pdev->dev, "unable to init phy: %d\n", ret);
+   goto err_clk;
}
}
 
@@ -170,7 +163,7 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
dev_err(&pdev->dev,
"Failed to enable vbus regulator, err=%d\n",
ret);
-   goto put_np;
+   goto err_clk;
}
data->reg_vbus = reg_vbus;
} else {
@@ -222,9 +215,7 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
 err:
if (reg_vbus)
regulator_disable(reg_vbus);
-put_np:
-   if (phy_np)
-   of_node_put(phy_np);
+err_clk:
clk_disable_unprepare(data->clk);
return ret;
 }
@@ -244,8 +235,6 @@ static int ci13xxx_imx_remove(struct platform_device *pdev)
module_put(data->phy->dev->driver->owner);
}
 
-   of_node_put(data->phy_np);
-
clk_disable_unprepare(data->clk);
 
platform_set_drvdata(pdev, NULL);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/9] USB: move bulk of otg/otg.c to phy/phy.c

2013-01-31 Thread Sascha Hauer
Most of otg/otg.c is not otg specific, but phy specific, so move it
to the phy directory.

Signed-off-by: Sascha Hauer 
Reported-by: Kishon Vijay Abraham I 
Cc: Felipe Balbi 
---
 drivers/usb/otg/otg.c|  423 
 drivers/usb/phy/Makefile |1 +
 drivers/usb/phy/phy.c|  434 ++
 3 files changed, 435 insertions(+), 423 deletions(-)
 create mode 100644 drivers/usb/phy/phy.c

diff --git a/drivers/usb/otg/otg.c b/drivers/usb/otg/otg.c
index e181439..358cfd9 100644
--- a/drivers/usb/otg/otg.c
+++ b/drivers/usb/otg/otg.c
@@ -8,432 +8,9 @@
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
  */
-
-#include 
 #include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
 #include 
 
-static LIST_HEAD(phy_list);
-static LIST_HEAD(phy_bind_list);
-static DEFINE_SPINLOCK(phy_lock);
-
-static struct usb_phy *__usb_find_phy(struct list_head *list,
-   enum usb_phy_type type)
-{
-   struct usb_phy  *phy = NULL;
-
-   list_for_each_entry(phy, list, head) {
-   if (phy->type != type)
-   continue;
-
-   return phy;
-   }
-
-   return ERR_PTR(-ENODEV);
-}
-
-static struct usb_phy *__usb_find_phy_dev(struct device *dev,
-   struct list_head *list, u8 index)
-{
-   struct usb_phy_bind *phy_bind = NULL;
-
-   list_for_each_entry(phy_bind, list, list) {
-   if (!(strcmp(phy_bind->dev_name, dev_name(dev))) &&
-   phy_bind->index == index) {
-   if (phy_bind->phy)
-   return phy_bind->phy;
-   else
-   return ERR_PTR(-EPROBE_DEFER);
-   }
-   }
-
-   return ERR_PTR(-ENODEV);
-}
-
-static struct usb_phy *__of_usb_find_phy(struct device_node *node)
-{
-   struct usb_phy  *phy;
-
-   list_for_each_entry(phy, &phy_list, head) {
-   if (node != phy->dev->of_node)
-   continue;
-
-   return phy;
-   }
-
-   return ERR_PTR(-ENODEV);
-}
-
-static void devm_usb_phy_release(struct device *dev, void *res)
-{
-   struct usb_phy *phy = *(struct usb_phy **)res;
-
-   usb_put_phy(phy);
-}
-
-static int devm_usb_phy_match(struct device *dev, void *res, void *match_data)
-{
-   return res == match_data;
-}
-
-/**
- * devm_usb_get_phy - find the USB PHY
- * @dev - device that requests this phy
- * @type - the type of the phy the controller requires
- *
- * Gets the phy using usb_get_phy(), and associates a device with it using
- * devres. On driver detach, release function is invoked on the devres data,
- * then, devres data is freed.
- *
- * For use by USB host and peripheral drivers.
- */
-struct usb_phy *devm_usb_get_phy(struct device *dev, enum usb_phy_type type)
-{
-   struct usb_phy **ptr, *phy;
-
-   ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL);
-   if (!ptr)
-   return NULL;
-
-   phy = usb_get_phy(type);
-   if (!IS_ERR(phy)) {
-   *ptr = phy;
-   devres_add(dev, ptr);
-   } else
-   devres_free(ptr);
-
-   return phy;
-}
-EXPORT_SYMBOL(devm_usb_get_phy);
-
-/**
- * usb_get_phy - find the USB PHY
- * @type - the type of the phy the controller requires
- *
- * Returns the phy driver, after getting a refcount to it; or
- * -ENODEV if there is no such phy.  The caller is responsible for
- * calling usb_put_phy() to release that count.
- *
- * For use by USB host and peripheral drivers.
- */
-struct usb_phy *usb_get_phy(enum usb_phy_type type)
-{
-   struct usb_phy  *phy = NULL;
-   unsigned long   flags;
-
-   spin_lock_irqsave(&phy_lock, flags);
-
-   phy = __usb_find_phy(&phy_list, type);
-   if (IS_ERR(phy)) {
-   pr_err("unable to find transceiver of type %s\n",
-   usb_phy_type_string(type));
-   goto err0;
-   }
-
-   get_device(phy->dev);
-
-err0:
-   spin_unlock_irqrestore(&phy_lock, flags);
-
-   return phy;
-}
-EXPORT_SYMBOL(usb_get_phy);
-
- /**
- * devm_usb_get_phy_by_phandle - find the USB PHY by phandle
- * @dev - device that requests this phy
- * @phandle - name of the property holding the phy phandle value
- * @index - the index of the phy
- *
- * Returns the phy driver associated with the given phandle value,
- * after getting a refcount to it, -ENODEV if there is no such phy or
- * -EPROBE_DEFER if there is a phandle to the phy, but the device is
- * not yet loaded. While at that, it also associates the device with
- * the phy using devres. On driver detach, release function is invoked
- * on the devres data, then, devres data is freed.
- *
- * For use by USB host and peripheral drivers.
- */
-struct usb_phy *devm_usb_get_phy_by_phandle

Re: [PATCH v3] USB: add devicetree helpers for determining dr_mode and phy_type

2013-02-01 Thread Sascha Hauer
Apparantly I was not fully awake while sending this series :(

On Fri, Feb 01, 2013 at 08:52:03AM +0100, Sascha Hauer wrote:
> (resend because I got the linux-usb address wrong)
> 
> Here's another round of the dr_mode/phy_type patches. I think they should
> be ready for merging now. Greg, will you apply them should there be no
> problems anymore?
> 
> Sascha
> 
> changes since v2:
> 
> - fix adding of GPL Header was in wrong patch
> - add missing hunk for new file of.c
> 
> changes since v1:
> - move phy specific of helper to drivers/usb/phy/of.c
> - use strcmp instead of strcasecmp for matching property values
> - change usb_phy_dr_mode to usb_dr_mode
> - change USBPHY_INTERFACE_MODE_NA to USBPHY_INTERFACE_MODE_UNKNOWN
> - add copyright header to new files
> - chipidea: drop mdelay at end of PTS/PTW setup
> - chipidea: implement lpm core type handling for PTS/PTW
> 
> The following changes since commit 7b8bc3aad0deabf3bc50cd2fe29bce29be5681fe:
> 
>   USB: chipidea: ci13xxx_imx: Remove sparse warning (2013-01-30 00:17:39 
> -0500)
> 
> are available in the git repository at:
> 
>   git://git.pengutronix.de/git/imx/linux-2.6.git tags/usb-chipidea-for-next
> 
> for you to fetch changes up to b82b92ba281add3e4d67bf6704052c0fd8c5c7f0:
> 
>   USB chipidea i.MX: use devm_usb_get_phy_by_phandle to get phy (2013-01-31 
> 12:27:36 +0100)
> 
> 
> USB Chipidea patches for v3.9
> 
> These add OF helpers for handling the dr_mode and phy_type property
> and makes use of them in the chipidea driver.
> 
> 
> Michael Grzeschik (3):
>   USB: add devicetree helpers for determining dr_mode and phy_type
>   USB: chipidea: ci13xxx-imx: create dynamic platformdata
>   USB: chipidea: add PTW and PTS handling
> 
> Sascha Hauer (6):
>   USB: move bulk of otg/otg.c to phy/phy.c
>   USB chipidea: introduce dual role mode pdata flags
>   USB chipidea i.MX: introduce dr_mode property
>   como fec wip
>   USB mxs-phy: Register phy with framework
>   USB chipidea i.MX: use devm_usb_get_phy_by_phandle to get phy
> 
>  Documentation/devicetree/bindings/net/fsl-fec.txt  |   20 +
>  .../devicetree/bindings/usb/ci13xxx-imx.txt|6 +
>  drivers/net/ethernet/freescale/fec.c   |   77 ++--
>  drivers/net/ethernet/freescale/fec.h   |1 +
>  drivers/usb/chipidea/bits.h|   14 +-
>  drivers/usb/chipidea/ci13xxx_imx.c |   60 ++-
>  drivers/usb/chipidea/core.c|   60 ++-
>  drivers/usb/otg/mxs-phy.c  |9 +
>  drivers/usb/otg/otg.c  |  423 ---
>  drivers/usb/phy/Makefile   |2 +
>  drivers/usb/phy/of.c   |   47 +++
>  drivers/usb/phy/phy.c  |  434 
> 
>  drivers/usb/usb-common.c   |   36 ++
>  include/linux/usb/chipidea.h   |3 +-
>  include/linux/usb/of.h |   27 ++
>  include/linux/usb/otg.h|7 +
>  include/linux/usb/phy.h|9 +
>  17 files changed, 742 insertions(+), 493 deletions(-)
>  create mode 100644 drivers/usb/phy/of.c
>  create mode 100644 drivers/usb/phy/phy.c
>  create mode 100644 include/linux/usb/of.h
> 

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 6/9] USB chipidea: introduce dual role mode pdata flags

2013-02-04 Thread Sascha Hauer
Even if a chipidea core is otg capable the board may not. This allows
to explicitly set the core to host/peripheral mode. Without these
flags the driver falls back to the old behaviour.

Signed-off-by: Sascha Hauer 
---
 drivers/usb/chipidea/core.c  |   21 +++--
 include/linux/usb/chipidea.h |2 +-
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
index 04d68cb..c89f2aa 100644
--- a/drivers/usb/chipidea/core.c
+++ b/drivers/usb/chipidea/core.c
@@ -435,6 +435,7 @@ static int ci_hdrc_probe(struct platform_device *pdev)
struct resource *res;
void __iomem*base;
int ret;
+   enum usb_dr_mode dr_mode;
 
if (!dev->platform_data) {
dev_err(dev, "platform data missing\n");
@@ -487,14 +488,22 @@ static int ci_hdrc_probe(struct platform_device *pdev)
return -ENODEV;
}
 
+   dr_mode = ci->platdata->dr_mode;
+   if (dr_mode == USB_DR_MODE_UNKNOWN)
+   dr_mode = USB_DR_MODE_OTG;
+
/* initialize role(s) before the interrupt is requested */
-   ret = ci_hdrc_host_init(ci);
-   if (ret)
-   dev_info(dev, "doesn't support host\n");
+   if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) {
+   ret = ci_hdrc_host_init(ci);
+   if (ret)
+   dev_info(dev, "doesn't support host\n");
+   }
 
-   ret = ci_hdrc_gadget_init(ci);
-   if (ret)
-   dev_info(dev, "doesn't support gadget\n");
+   if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_PERIPHERAL) {
+   ret = ci_hdrc_gadget_init(ci);
+   if (ret)
+   dev_info(dev, "doesn't support gadget\n");
+   }
 
if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) {
dev_err(dev, "no supported roles\n");
diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h
index 1a2aa18..b314647 100644
--- a/include/linux/usb/chipidea.h
+++ b/include/linux/usb/chipidea.h
@@ -20,7 +20,7 @@ struct ci13xxx_platform_data {
 #define CI13XXX_REQUIRE_TRANSCEIVERBIT(1)
 #define CI13XXX_PULLUP_ON_VBUS BIT(2)
 #define CI13XXX_DISABLE_STREAMING  BIT(3)
-
+   enum usb_dr_modedr_mode;
 #define CI13XXX_CONTROLLER_RESET_EVENT 0
 #define CI13XXX_CONTROLLER_STOPPED_EVENT   1
void(*notify_event) (struct ci13xxx *ci, unsigned event);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4] USB: add devicetree helpers for determining dr_mode and phy_type

2013-02-04 Thread Sascha Hauer
4th round of patches.

Peter, I would be glad if you could test them before your holiday. I rebased
your last round of Chipidea OTG patches onto this series which you can pull
here:

git://git.pengutronix.de/git/imx/linux-2.6.git tags/usb-chipidea-otg-for-next

I couldn't really test the otg patches since my current hardware does not have
the ID pin connected, but I can verify that my usecase still works with your
patches applied.

Alex, should the patches work for you and are fine otherwise, could you apply
them for v3.9?

Sascha



changes since v3:

- add phy patches (which were accidently already part of v2)
- Use OP_DEVLC instead of OP_PORTSC for lpm case
- Use enum usb_dr_mode ub ci_hdrc_probe()

changes since v2:

- fix adding of GPL Header was in wrong patch
- add missing hunk for new file of.c

changes since v1:
- move phy specific of helper to drivers/usb/phy/of.c
- use strcmp instead of strcasecmp for matching property values
- change usb_phy_dr_mode to usb_dr_mode
- change USBPHY_INTERFACE_MODE_NA to USBPHY_INTERFACE_MODE_UNKNOWN
- add copyright header to new files
- chipidea: drop mdelay at end of PTS/PTW setup
- chipidea: implement lpm core type handling for PTS/PTW


The following changes since commit 2f0760774711c957c395b31131b848043af98edf:

  USB: GADGET: optionally force full-speed for net2280 UDC (2013-01-31 10:09:19 
+0100)

are available in the git repository at:

  git://git.pengutronix.de/git/imx/linux-2.6.git tags/usb-chipidea-for-next

for you to fetch changes up to 25682afd7be85f1462647d8530dca1bf848074fc:

  USB chipidea i.MX: use devm_usb_get_phy_by_phandle to get phy (2013-02-04 
12:28:53 +0100)


USB: chipidea patches for v3.9

These add OF helpers for handling the dr_mode and phy_type property
and makes use of them in the chipidea driver.


Marc Kleine-Budde (1):
  usb: otg: use try_module_get in all usb_get_phy functions and add missing 
module_put

Michael Grzeschik (3):
  USB: add devicetree helpers for determining dr_mode and phy_type
  USB: chipidea: ci13xxx-imx: create dynamic platformdata
  USB: chipidea: add PTW and PTS handling

Sascha Hauer (5):
  USB: move bulk of otg/otg.c to phy/phy.c
  USB chipidea: introduce dual role mode pdata flags
  USB chipidea i.MX: introduce dr_mode property
  USB mxs-phy: Register phy with framework
  USB chipidea i.MX: use devm_usb_get_phy_by_phandle to get phy

 .../devicetree/bindings/usb/ci13xxx-imx.txt|6 +
 drivers/usb/chipidea/bits.h|   14 +-
 drivers/usb/chipidea/ci13xxx_imx.c |   68 +--
 drivers/usb/chipidea/core.c|   60 ++-
 drivers/usb/otg/mxs-phy.c  |9 +
 drivers/usb/otg/otg.c  |  423 ---
 drivers/usb/phy/Makefile   |2 +
 drivers/usb/phy/of.c   |   47 +++
 drivers/usb/phy/phy.c  |  438 
 drivers/usb/usb-common.c   |   36 ++
 include/linux/usb/chipidea.h   |3 +-
 include/linux/usb/of.h |   27 ++
 include/linux/usb/otg.h|7 +
 include/linux/usb/phy.h|9 +
 14 files changed, 687 insertions(+), 462 deletions(-)
 create mode 100644 drivers/usb/phy/of.c
 create mode 100644 drivers/usb/phy/phy.c
 create mode 100644 include/linux/usb/of.h
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 4/9] USB: chipidea: ci13xxx-imx: create dynamic platformdata

2013-02-04 Thread Sascha Hauer
From: Michael Grzeschik 

This patch removes the limitation of having only one instance of the
ci13xxx-imx platformdata and makes different configurations possible.

Signed-off-by: Michael Grzeschik 
Signed-off-by: Marc Kleine-Budde 
Signed-off-by: Sascha Hauer 
Reviewed-by: Peter Chen 
---
 drivers/usb/chipidea/ci13xxx_imx.c |   25 +++--
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/chipidea/ci13xxx_imx.c 
b/drivers/usb/chipidea/ci13xxx_imx.c
index 8c29122..69024e0 100644
--- a/drivers/usb/chipidea/ci13xxx_imx.c
+++ b/drivers/usb/chipidea/ci13xxx_imx.c
@@ -85,17 +85,10 @@ EXPORT_SYMBOL_GPL(usbmisc_get_init_data);
 
 /* End of common functions shared by usbmisc drivers*/
 
-static struct ci13xxx_platform_data ci13xxx_imx_platdata  = {
-   .name   = "ci13xxx_imx",
-   .flags  = CI13XXX_REQUIRE_TRANSCEIVER |
- CI13XXX_PULLUP_ON_VBUS |
- CI13XXX_DISABLE_STREAMING,
-   .capoffset  = DEF_CAPOFFSET,
-};
-
 static int ci13xxx_imx_probe(struct platform_device *pdev)
 {
struct ci13xxx_imx_data *data;
+   struct ci13xxx_platform_data *pdata;
struct platform_device *plat_ci, *phy_pdev;
struct device_node *phy_np;
struct resource *res;
@@ -107,6 +100,18 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
&& !usbmisc_ops)
return -EPROBE_DEFER;
 
+   pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
+   if (!pdata) {
+   dev_err(&pdev->dev, "Failed to allocate CI13xxx-IMX pdata!\n");
+   return -ENOMEM;
+   }
+
+   pdata->name = "ci13xxx_imx";
+   pdata->capoffset = DEF_CAPOFFSET;
+   pdata->flags = CI13XXX_REQUIRE_TRANSCEIVER |
+  CI13XXX_PULLUP_ON_VBUS |
+  CI13XXX_DISABLE_STREAMING;
+
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
if (!data) {
dev_err(&pdev->dev, "Failed to allocate CI13xxx-IMX data!\n");
@@ -168,7 +173,7 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
reg_vbus = NULL;
}
 
-   ci13xxx_imx_platdata.phy = data->phy;
+   pdata->phy = data->phy;
 
if (!pdev->dev.dma_mask) {
pdev->dev.dma_mask = devm_kzalloc(&pdev->dev,
@@ -193,7 +198,7 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
 
plat_ci = ci13xxx_add_device(&pdev->dev,
pdev->resource, pdev->num_resources,
-   &ci13xxx_imx_platdata);
+   pdata);
if (IS_ERR(plat_ci)) {
ret = PTR_ERR(plat_ci);
dev_err(&pdev->dev,
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 7/9] USB chipidea i.MX: introduce dr_mode property

2013-02-04 Thread Sascha Hauer
The dr_mode devicetree property allows to explicitly specify the
host/peripheral/otg mode. This is necessary for boards without proper
ID pin handling.

Signed-off-by: Sascha Hauer 
Reviewed-by: Peter Chen 
---
 Documentation/devicetree/bindings/usb/ci13xxx-imx.txt |1 +
 drivers/usb/chipidea/ci13xxx_imx.c|1 +
 2 files changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt 
b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
index dd42ccd..493a414 100644
--- a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
+++ b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
@@ -9,6 +9,7 @@ Recommended properies:
 - phy_type: the type of the phy connected to the core. Should be one
   of "utmi", "utmi_wide", "ulpi", "serial" or "hsic". Without this
   property the PORTSC register won't be touched
+- dr_mode: One of "host", "peripheral" or "otg". Defaults to "otg"
 
 Optional properties:
 - fsl,usbphy: phandler of usb phy that connects to the only one port
diff --git a/drivers/usb/chipidea/ci13xxx_imx.c 
b/drivers/usb/chipidea/ci13xxx_imx.c
index ebc1148..b598bb8f 100644
--- a/drivers/usb/chipidea/ci13xxx_imx.c
+++ b/drivers/usb/chipidea/ci13xxx_imx.c
@@ -114,6 +114,7 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
   CI13XXX_DISABLE_STREAMING;
 
pdata->phy_mode = of_usb_get_phy_mode(pdev->dev.of_node);
+   pdata->dr_mode = of_usb_get_dr_mode(pdev->dev.of_node);
 
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
if (!data) {
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/9] usb: otg: use try_module_get in all usb_get_phy functions and add missing module_put

2013-02-04 Thread Sascha Hauer
From: Marc Kleine-Budde 

In patch "5d3c28b usb: otg: add device tree support to otg library"
devm_usb_get_phy_by_phandle() was added. It uses try_module_get() to lock the
phy driver in memory. The corresponding module_put() is missing in that patch.

This patch adds try_module_get() to usb_get_phy() and usb_get_phy_dev().
Further the missing module_put() is added to usb_put_phy().

Signed-off-by: Marc Kleine-Budde 
Signed-off-by: Sascha Hauer 
---
 drivers/usb/otg/otg.c |   10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/otg/otg.c b/drivers/usb/otg/otg.c
index e181439..2bd03d2 100644
--- a/drivers/usb/otg/otg.c
+++ b/drivers/usb/otg/otg.c
@@ -130,7 +130,7 @@ struct usb_phy *usb_get_phy(enum usb_phy_type type)
spin_lock_irqsave(&phy_lock, flags);
 
phy = __usb_find_phy(&phy_list, type);
-   if (IS_ERR(phy)) {
+   if (IS_ERR(phy) || !try_module_get(phy->dev->driver->owner)) {
pr_err("unable to find transceiver of type %s\n",
usb_phy_type_string(type));
goto err0;
@@ -228,7 +228,7 @@ struct usb_phy *usb_get_phy_dev(struct device *dev, u8 
index)
spin_lock_irqsave(&phy_lock, flags);
 
phy = __usb_find_phy_dev(dev, &phy_bind_list, index);
-   if (IS_ERR(phy)) {
+   if (IS_ERR(phy) || !try_module_get(phy->dev->driver->owner)) {
pr_err("unable to find transceiver\n");
goto err0;
}
@@ -301,8 +301,12 @@ EXPORT_SYMBOL(devm_usb_put_phy);
  */
 void usb_put_phy(struct usb_phy *x)
 {
-   if (x)
+   if (x) {
+   struct module *owner = x->dev->driver->owner;
+
put_device(x->dev);
+   module_put(owner);
+   }
 }
 EXPORT_SYMBOL(usb_put_phy);
 
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 5/9] USB: chipidea: add PTW and PTS handling

2013-02-04 Thread Sascha Hauer
From: Michael Grzeschik 

This patch makes it possible to configure the PTW and PTS bits inside
the portsc register for host and device mode before the driver starts
and the phy can be addressed as hardware implementation is designed.

Signed-off-by: Michael Grzeschik 
Signed-off-by: Marc Kleine-Budde 
Signed-off-by: Sascha Hauer 
---
 .../devicetree/bindings/usb/ci13xxx-imx.txt|5 +++
 drivers/usb/chipidea/bits.h|   14 ++-
 drivers/usb/chipidea/ci13xxx_imx.c |3 ++
 drivers/usb/chipidea/core.c|   39 
 include/linux/usb/chipidea.h   |1 +
 5 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt 
b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
index 5778b9c..dd42ccd 100644
--- a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
+++ b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
@@ -5,6 +5,11 @@ Required properties:
 - reg: Should contain registers location and length
 - interrupts: Should contain controller interrupt
 
+Recommended properies:
+- phy_type: the type of the phy connected to the core. Should be one
+  of "utmi", "utmi_wide", "ulpi", "serial" or "hsic". Without this
+  property the PORTSC register won't be touched
+
 Optional properties:
 - fsl,usbphy: phandler of usb phy that connects to the only one port
 - fsl,usbmisc: phandler of non-core register device, with one argument
diff --git a/drivers/usb/chipidea/bits.h b/drivers/usb/chipidea/bits.h
index 050de85..d8ffc2f 100644
--- a/drivers/usb/chipidea/bits.h
+++ b/drivers/usb/chipidea/bits.h
@@ -48,10 +48,22 @@
 #define PORTSC_SUSP   BIT(7)
 #define PORTSC_HSPBIT(9)
 #define PORTSC_PTC(0x0FUL << 16)
+/* PTS and PTW for non lpm version only */
+#define PORTSC_PTS(d) d) & 0x3) << 30) | (((d) & 0x4) ? BIT(25) : 
0))
+#define PORTSC_PTWBIT(28)
 
 /* DEVLC */
 #define DEVLC_PSPD(0x03UL << 25)
-#defineDEVLC_PSPD_HS  (0x02UL << 25)
+#define DEVLC_PSPD_HS (0x02UL << 25)
+#define DEVLC_PTW BIT(27)
+#define DEVLC_STS BIT(28)
+#define DEVLC_PTS(d)  (((d) & 0x7) << 29)
+
+/* Encoding for DEVLC_PTS and PORTSC_PTS */
+#define PTS_UTMI  0
+#define PTS_ULPI  2
+#define PTS_SERIAL3
+#define PTS_HSIC  4
 
 /* OTGSC */
 #define OTGSC_IDPU   BIT(5)
diff --git a/drivers/usb/chipidea/ci13xxx_imx.c 
b/drivers/usb/chipidea/ci13xxx_imx.c
index 69024e0..ebc1148 100644
--- a/drivers/usb/chipidea/ci13xxx_imx.c
+++ b/drivers/usb/chipidea/ci13xxx_imx.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "ci.h"
 #include "ci13xxx_imx.h"
@@ -112,6 +113,8 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
   CI13XXX_PULLUP_ON_VBUS |
   CI13XXX_DISABLE_STREAMING;
 
+   pdata->phy_mode = of_usb_get_phy_mode(pdev->dev.of_node);
+
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
if (!data) {
dev_err(&pdev->dev, "Failed to allocate CI13xxx-IMX data!\n");
diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
index 57cae1f..04d68cb 100644
--- a/drivers/usb/chipidea/core.c
+++ b/drivers/usb/chipidea/core.c
@@ -67,6 +67,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include "ci.h"
 #include "udc.h"
@@ -211,6 +213,41 @@ static int hw_device_init(struct ci13xxx *ci, void __iomem 
*base)
return 0;
 }
 
+static void hw_phymode_configure(struct ci13xxx *ci)
+{
+   u32 portsc, lpm;
+
+   switch (ci->platdata->phy_mode) {
+   case USBPHY_INTERFACE_MODE_UTMI:
+   portsc = PORTSC_PTS(PTS_UTMI);
+   lpm = DEVLC_PTS(PTS_UTMI);
+   break;
+   case USBPHY_INTERFACE_MODE_UTMIW:
+   portsc = PORTSC_PTS(PTS_UTMI) | PORTSC_PTW;
+   lpm = DEVLC_PTS(PTS_UTMI) | DEVLC_PTW;
+   break;
+   case USBPHY_INTERFACE_MODE_ULPI:
+   portsc = PORTSC_PTS(PTS_ULPI);
+   lpm = DEVLC_PTS(PTS_ULPI);
+   break;
+   case USBPHY_INTERFACE_MODE_SERIAL:
+   portsc = PORTSC_PTS(PTS_SERIAL);
+   lpm = DEVLC_PTS(PTS_SERIAL);
+   break;
+   case USBPHY_INTERFACE_MODE_HSIC:
+   portsc = PORTSC_PTS(PTS_HSIC);
+   lpm = DEVLC_PTS(PTS_HSIC);
+   break;
+   default:
+   return;
+   }
+
+   if (ci->hw_bank.lpm)
+   hw_write(ci, OP_DEVLC, DEVLC_PTS(7) | DEVLC_PTW, lpm);
+   else
+   hw_write(ci, OP_PORTSC, PORTSC_PTS(7) | PORTSC_PTW

[PATCH 9/9] USB chipidea i.MX: use devm_usb_get_phy_by_phandle to get phy

2013-02-04 Thread Sascha Hauer
Signed-off-by: Sascha Hauer 
---
 drivers/usb/chipidea/ci13xxx_imx.c |   39 +---
 1 file changed, 18 insertions(+), 21 deletions(-)

diff --git a/drivers/usb/chipidea/ci13xxx_imx.c 
b/drivers/usb/chipidea/ci13xxx_imx.c
index b598bb8f..136869b 100644
--- a/drivers/usb/chipidea/ci13xxx_imx.c
+++ b/drivers/usb/chipidea/ci13xxx_imx.c
@@ -30,7 +30,6 @@
((struct usb_phy *)platform_get_drvdata(pdev))
 
 struct ci13xxx_imx_data {
-   struct device_node *phy_np;
struct usb_phy *phy;
struct platform_device *ci_pdev;
struct clk *clk;
@@ -90,12 +89,12 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
 {
struct ci13xxx_imx_data *data;
struct ci13xxx_platform_data *pdata;
-   struct platform_device *plat_ci, *phy_pdev;
-   struct device_node *phy_np;
+   struct platform_device *plat_ci;
struct resource *res;
struct regulator *reg_vbus;
struct pinctrl *pinctrl;
int ret;
+   struct usb_phy *phy;
 
if (of_find_property(pdev->dev.of_node, "fsl,usbmisc", NULL)
&& !usbmisc_ops)
@@ -147,19 +146,21 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
return ret;
}
 
-   phy_np = of_parse_phandle(pdev->dev.of_node, "fsl,usbphy", 0);
-   if (phy_np) {
-   data->phy_np = phy_np;
-   phy_pdev = of_find_device_by_node(phy_np);
-   if (phy_pdev) {
-   struct usb_phy *phy;
-   phy = pdev_to_phy(phy_pdev);
-   if (phy &&
-   try_module_get(phy_pdev->dev.driver->owner)) {
-   usb_phy_init(phy);
-   data->phy = phy;
-   }
+   phy = devm_usb_get_phy_by_phandle(&pdev->dev, "fsl,usbphy", 0);
+
+   if (PTR_ERR(phy) == -EPROBE_DEFER) {
+   ret = -EPROBE_DEFER;
+   goto err_clk;
+   }
+
+   if (!IS_ERR(phy)) {
+   ret = usb_phy_init(phy);
+   if (ret) {
+   dev_err(&pdev->dev, "unable to init phy: %d\n", ret);
+   goto err_clk;
}
+
+   data->phy = phy;
}
 
/* we only support host now, so enable vbus here */
@@ -170,7 +171,7 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
dev_err(&pdev->dev,
"Failed to enable vbus regulator, err=%d\n",
ret);
-   goto put_np;
+   goto err_clk;
}
data->reg_vbus = reg_vbus;
} else {
@@ -222,9 +223,7 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
 err:
if (reg_vbus)
regulator_disable(reg_vbus);
-put_np:
-   if (phy_np)
-   of_node_put(phy_np);
+err_clk:
clk_disable_unprepare(data->clk);
return ret;
 }
@@ -244,8 +243,6 @@ static int ci13xxx_imx_remove(struct platform_device *pdev)
module_put(data->phy->dev->driver->owner);
}
 
-   of_node_put(data->phy_np);
-
clk_disable_unprepare(data->clk);
 
platform_set_drvdata(pdev, NULL);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/9] USB: add devicetree helpers for determining dr_mode and phy_type

2013-02-04 Thread Sascha Hauer
From: Michael Grzeschik 

This adds two little devicetree helper functions for determining the
dr_mode (host, peripheral, otg) and phy_type (utmi, ulpi,...) from
the devicetree.

Signed-off-by: Michael Grzeschik 
Signed-off-by: Marc Kleine-Budde 
Signed-off-by: Sascha Hauer 
---
 drivers/usb/phy/Makefile |1 +
 drivers/usb/phy/of.c |   47 ++
 drivers/usb/usb-common.c |   36 +++
 include/linux/usb/of.h   |   27 ++
 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 9fa6327..e1be1e8 100644
--- a/drivers/usb/phy/Makefile
+++ b/drivers/usb/phy/Makefile
@@ -5,6 +5,7 @@
 ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
 
 obj-$(CONFIG_USB_OTG_UTILS)+= phy.o
+obj-$(CONFIG_OF)   += of.o
 obj-$(CONFIG_OMAP_USB2)+= omap-usb2.o
 obj-$(CONFIG_OMAP_USB3)+= omap-usb3.o
 obj-$(CONFIG_OMAP_CONTROL_USB) += omap-control-usb.o
diff --git a/drivers/usb/phy/of.c b/drivers/usb/phy/of.c
new file mode 100644
index 000..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 
+#include 
+#include 
+#include 
+#include 
+
+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 d29503e..ad4d87d 100644
--- a/drivers/usb/usb-common.c
+++ b/drivers/usb/usb-common.c
@@ -14,6 +14,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 const char *usb_speed_string(enum usb_device_speed speed)
 {
@@ -32,4 +35,37 @@ const char *usb_speed_string(enum usb_device_speed speed)
 }
 EXPORT_SYMBOL_GPL(usb_speed_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 000..4681a20
--- /dev/null
+++ b/include/linux/usb/of.h
@@ -0,0 +1,27 @@
+/*
+ * OF helpers for usb devices.
+ *
+ * This file is released under the GPLv2
+ */
+
+#ifndef __LINUX_USB_OF_H
+#define __LINUX_USB_OF_H
+
+#include 
+
+#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(s

[PATCH 8/9] USB mxs-phy: Register phy with framework

2013-02-04 Thread Sascha Hauer
We now have usb_add_phy_dev(), so use it to register with the framework
to be able to find the phy from the USB driver.

Signed-off-by: Sascha Hauer 
---
 drivers/usb/otg/mxs-phy.c |9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/usb/otg/mxs-phy.c b/drivers/usb/otg/mxs-phy.c
index 5158332..5b39885 100644
--- a/drivers/usb/otg/mxs-phy.c
+++ b/drivers/usb/otg/mxs-phy.c
@@ -127,6 +127,7 @@ static int mxs_phy_probe(struct platform_device *pdev)
void __iomem *base;
struct clk *clk;
struct mxs_phy *mxs_phy;
+   int ret;
 
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) {
@@ -166,11 +167,19 @@ static int mxs_phy_probe(struct platform_device *pdev)
 
platform_set_drvdata(pdev, &mxs_phy->phy);
 
+   ret = usb_add_phy_dev(&mxs_phy->phy);
+   if (ret)
+   return ret;
+
return 0;
 }
 
 static int mxs_phy_remove(struct platform_device *pdev)
 {
+   struct mxs_phy *mxs_phy = platform_get_drvdata(pdev);
+
+   usb_remove_phy(&mxs_phy->phy);
+
platform_set_drvdata(pdev, NULL);
 
return 0;
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/9] USB: move bulk of otg/otg.c to phy/phy.c

2013-02-04 Thread Sascha Hauer
Most of otg/otg.c is not otg specific, but phy specific, so move it
to the phy directory.

Signed-off-by: Sascha Hauer 
Reported-by: Kishon Vijay Abraham I 
Cc: Felipe Balbi 
---
 drivers/usb/otg/otg.c|  427 
 drivers/usb/phy/Makefile |1 +
 drivers/usb/phy/phy.c|  438 ++
 3 files changed, 439 insertions(+), 427 deletions(-)
 create mode 100644 drivers/usb/phy/phy.c

diff --git a/drivers/usb/otg/otg.c b/drivers/usb/otg/otg.c
index 2bd03d2..358cfd9 100644
--- a/drivers/usb/otg/otg.c
+++ b/drivers/usb/otg/otg.c
@@ -8,436 +8,9 @@
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
  */
-
-#include 
 #include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
 #include 
 
-static LIST_HEAD(phy_list);
-static LIST_HEAD(phy_bind_list);
-static DEFINE_SPINLOCK(phy_lock);
-
-static struct usb_phy *__usb_find_phy(struct list_head *list,
-   enum usb_phy_type type)
-{
-   struct usb_phy  *phy = NULL;
-
-   list_for_each_entry(phy, list, head) {
-   if (phy->type != type)
-   continue;
-
-   return phy;
-   }
-
-   return ERR_PTR(-ENODEV);
-}
-
-static struct usb_phy *__usb_find_phy_dev(struct device *dev,
-   struct list_head *list, u8 index)
-{
-   struct usb_phy_bind *phy_bind = NULL;
-
-   list_for_each_entry(phy_bind, list, list) {
-   if (!(strcmp(phy_bind->dev_name, dev_name(dev))) &&
-   phy_bind->index == index) {
-   if (phy_bind->phy)
-   return phy_bind->phy;
-   else
-   return ERR_PTR(-EPROBE_DEFER);
-   }
-   }
-
-   return ERR_PTR(-ENODEV);
-}
-
-static struct usb_phy *__of_usb_find_phy(struct device_node *node)
-{
-   struct usb_phy  *phy;
-
-   list_for_each_entry(phy, &phy_list, head) {
-   if (node != phy->dev->of_node)
-   continue;
-
-   return phy;
-   }
-
-   return ERR_PTR(-ENODEV);
-}
-
-static void devm_usb_phy_release(struct device *dev, void *res)
-{
-   struct usb_phy *phy = *(struct usb_phy **)res;
-
-   usb_put_phy(phy);
-}
-
-static int devm_usb_phy_match(struct device *dev, void *res, void *match_data)
-{
-   return res == match_data;
-}
-
-/**
- * devm_usb_get_phy - find the USB PHY
- * @dev - device that requests this phy
- * @type - the type of the phy the controller requires
- *
- * Gets the phy using usb_get_phy(), and associates a device with it using
- * devres. On driver detach, release function is invoked on the devres data,
- * then, devres data is freed.
- *
- * For use by USB host and peripheral drivers.
- */
-struct usb_phy *devm_usb_get_phy(struct device *dev, enum usb_phy_type type)
-{
-   struct usb_phy **ptr, *phy;
-
-   ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL);
-   if (!ptr)
-   return NULL;
-
-   phy = usb_get_phy(type);
-   if (!IS_ERR(phy)) {
-   *ptr = phy;
-   devres_add(dev, ptr);
-   } else
-   devres_free(ptr);
-
-   return phy;
-}
-EXPORT_SYMBOL(devm_usb_get_phy);
-
-/**
- * usb_get_phy - find the USB PHY
- * @type - the type of the phy the controller requires
- *
- * Returns the phy driver, after getting a refcount to it; or
- * -ENODEV if there is no such phy.  The caller is responsible for
- * calling usb_put_phy() to release that count.
- *
- * For use by USB host and peripheral drivers.
- */
-struct usb_phy *usb_get_phy(enum usb_phy_type type)
-{
-   struct usb_phy  *phy = NULL;
-   unsigned long   flags;
-
-   spin_lock_irqsave(&phy_lock, flags);
-
-   phy = __usb_find_phy(&phy_list, type);
-   if (IS_ERR(phy) || !try_module_get(phy->dev->driver->owner)) {
-   pr_err("unable to find transceiver of type %s\n",
-   usb_phy_type_string(type));
-   goto err0;
-   }
-
-   get_device(phy->dev);
-
-err0:
-   spin_unlock_irqrestore(&phy_lock, flags);
-
-   return phy;
-}
-EXPORT_SYMBOL(usb_get_phy);
-
- /**
- * devm_usb_get_phy_by_phandle - find the USB PHY by phandle
- * @dev - device that requests this phy
- * @phandle - name of the property holding the phy phandle value
- * @index - the index of the phy
- *
- * Returns the phy driver associated with the given phandle value,
- * after getting a refcount to it, -ENODEV if there is no such phy or
- * -EPROBE_DEFER if there is a phandle to the phy, but the device is
- * not yet loaded. While at that, it also associates the device with
- * the phy using devres. On driver detach, release function is invoked
- * on the devres data, then, devres data is freed.
- *
- * For use by USB host and peripheral drive

Re: [PATCH 9/9] USB chipidea i.MX: use devm_usb_get_phy_by_phandle to get phy

2013-02-05 Thread Sascha Hauer
On Tue, Feb 05, 2013 at 03:45:12PM +0400, Sergei Shtylyov wrote:
> Hello.
> 
> On 04-02-2013 17:24, Sascha Hauer wrote:
> 
> >Signed-off-by: Sascha Hauer 
> >---
> >  drivers/usb/chipidea/ci13xxx_imx.c |   39 
> > +---
> >  1 file changed, 18 insertions(+), 21 deletions(-)
> 
> >diff --git a/drivers/usb/chipidea/ci13xxx_imx.c 
> >b/drivers/usb/chipidea/ci13xxx_imx.c
> >index b598bb8f..136869b 100644
> >--- a/drivers/usb/chipidea/ci13xxx_imx.c
> >+++ b/drivers/usb/chipidea/ci13xxx_imx.c
> [...]
> >@@ -147,19 +146,21 @@ static int ci13xxx_imx_probe(struct platform_device 
> >*pdev)
> > return ret;
> > }
> >
> >+phy = devm_usb_get_phy_by_phandle(&pdev->dev, "fsl,usbphy", 0);
> >+
> 
>No need for emoty line here. Keep the style as it was please.
> 
> >+if (PTR_ERR(phy) == -EPROBE_DEFER) {
> 
>Is it valid to call PTR_ERR() on non-error pointer?

Why shouldn't it?

> Isn't it
> better to do this check under *else* clause below the next *if*.

For better readability, yes.

Sascha

> 
> >+ret = -EPROBE_DEFER;
> >+goto err_clk;
> >+}
> >+
> 
>This empty line is also not needed, I think.
> 
> >+if (!IS_ERR(phy)) {
> >+ret = usb_phy_init(phy);
> >+if (ret) {
> >+dev_err(&pdev->dev, "unable to init phy: %d\n", ret);
> >+goto err_clk;
> > }
> >+
> >+data->phy = phy;
> > }
> >
> > /* we only support host now, so enable vbus here */
> 
> WBR, Sergei
> 
> 

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4] USB: add devicetree helpers for determining dr_mode and phy_type

2013-02-07 Thread Sascha Hauer
Alexander,

Did you have a chance to look at this series? Development of this driver
has stalled for too long now, I don't want to miss the next merge
window.

Thanks
 Sascha

On Mon, Feb 04, 2013 at 02:24:26PM +0100, Sascha Hauer wrote:
> 4th round of patches.
> 
> Peter, I would be glad if you could test them before your holiday. I rebased
> your last round of Chipidea OTG patches onto this series which you can pull
> here:
> 
> git://git.pengutronix.de/git/imx/linux-2.6.git tags/usb-chipidea-otg-for-next
> 
> I couldn't really test the otg patches since my current hardware does not have
> the ID pin connected, but I can verify that my usecase still works with your
> patches applied.
> 
> Alex, should the patches work for you and are fine otherwise, could you apply
> them for v3.9?
> 
> Sascha
> 
> 
> 
> changes since v3:
> 
> - add phy patches (which were accidently already part of v2)
> - Use OP_DEVLC instead of OP_PORTSC for lpm case
> - Use enum usb_dr_mode ub ci_hdrc_probe()
> 
> changes since v2:
> 
> - fix adding of GPL Header was in wrong patch
> - add missing hunk for new file of.c
> 
> changes since v1:
> - move phy specific of helper to drivers/usb/phy/of.c
> - use strcmp instead of strcasecmp for matching property values
> - change usb_phy_dr_mode to usb_dr_mode
> - change USBPHY_INTERFACE_MODE_NA to USBPHY_INTERFACE_MODE_UNKNOWN
> - add copyright header to new files
> - chipidea: drop mdelay at end of PTS/PTW setup
> - chipidea: implement lpm core type handling for PTS/PTW
> 
> 
> The following changes since commit 2f0760774711c957c395b31131b848043af98edf:
> 
>   USB: GADGET: optionally force full-speed for net2280 UDC (2013-01-31 
> 10:09:19 +0100)
> 
> are available in the git repository at:
> 
>   git://git.pengutronix.de/git/imx/linux-2.6.git tags/usb-chipidea-for-next
> 
> for you to fetch changes up to 25682afd7be85f1462647d8530dca1bf848074fc:
> 
>   USB chipidea i.MX: use devm_usb_get_phy_by_phandle to get phy (2013-02-04 
> 12:28:53 +0100)
> 
> 
> USB: chipidea patches for v3.9
> 
> These add OF helpers for handling the dr_mode and phy_type property
> and makes use of them in the chipidea driver.
> 
> 
> Marc Kleine-Budde (1):
>   usb: otg: use try_module_get in all usb_get_phy functions and add 
> missing module_put
> 
> Michael Grzeschik (3):
>   USB: add devicetree helpers for determining dr_mode and phy_type
>   USB: chipidea: ci13xxx-imx: create dynamic platformdata
>   USB: chipidea: add PTW and PTS handling
> 
> Sascha Hauer (5):
>   USB: move bulk of otg/otg.c to phy/phy.c
>   USB chipidea: introduce dual role mode pdata flags
>   USB chipidea i.MX: introduce dr_mode property
>   USB mxs-phy: Register phy with framework
>   USB chipidea i.MX: use devm_usb_get_phy_by_phandle to get phy
> 
>  .../devicetree/bindings/usb/ci13xxx-imx.txt|6 +
>  drivers/usb/chipidea/bits.h|   14 +-
>  drivers/usb/chipidea/ci13xxx_imx.c |   68 +--
>  drivers/usb/chipidea/core.c|   60 ++-
>  drivers/usb/otg/mxs-phy.c  |9 +
>  drivers/usb/otg/otg.c  |  423 ---
>  drivers/usb/phy/Makefile   |2 +
>  drivers/usb/phy/of.c   |   47 +++
>  drivers/usb/phy/phy.c  |  438 
> 
>  drivers/usb/usb-common.c   |   36 ++
>  include/linux/usb/chipidea.h   |3 +-
>  include/linux/usb/of.h |   27 ++
>  include/linux/usb/otg.h|7 +
>  include/linux/usb/phy.h|9 +
>  14 files changed, 687 insertions(+), 462 deletions(-)
>  create mode 100644 drivers/usb/phy/of.c
>  create mode 100644 drivers/usb/phy/phy.c
>  create mode 100644 include/linux/usb/of.h
> 

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4] USB: add devicetree helpers for determining dr_mode and phy_type

2013-02-12 Thread Sascha Hauer
On Thu, Feb 07, 2013 at 11:56:32AM +0100, Sascha Hauer wrote:
> Alexander,
> 
> Did you have a chance to look at this series? Development of this driver
> has stalled for too long now, I don't want to miss the next merge
> window.

Alexander,

Any comments?

Thanks
 Sascha

> 
> Thanks
>  Sascha
> 
> On Mon, Feb 04, 2013 at 02:24:26PM +0100, Sascha Hauer wrote:
> > 4th round of patches.
> > 
> > Peter, I would be glad if you could test them before your holiday. I rebased
> > your last round of Chipidea OTG patches onto this series which you can pull
> > here:
> > 
> > git://git.pengutronix.de/git/imx/linux-2.6.git 
> > tags/usb-chipidea-otg-for-next
> > 
> > I couldn't really test the otg patches since my current hardware does not 
> > have
> > the ID pin connected, but I can verify that my usecase still works with your
> > patches applied.
> > 
> > Alex, should the patches work for you and are fine otherwise, could you 
> > apply
> > them for v3.9?
> > 
> > Sascha
> > 
> > 
> > 
> > changes since v3:
> > 
> > - add phy patches (which were accidently already part of v2)
> > - Use OP_DEVLC instead of OP_PORTSC for lpm case
> > - Use enum usb_dr_mode ub ci_hdrc_probe()
> > 
> > changes since v2:
> > 
> > - fix adding of GPL Header was in wrong patch
> > - add missing hunk for new file of.c
> > 
> > changes since v1:
> > - move phy specific of helper to drivers/usb/phy/of.c
> > - use strcmp instead of strcasecmp for matching property values
> > - change usb_phy_dr_mode to usb_dr_mode
> > - change USBPHY_INTERFACE_MODE_NA to USBPHY_INTERFACE_MODE_UNKNOWN
> > - add copyright header to new files
> > - chipidea: drop mdelay at end of PTS/PTW setup
> > - chipidea: implement lpm core type handling for PTS/PTW
> > 
> > 
> > The following changes since commit 2f0760774711c957c395b31131b848043af98edf:
> > 
> >   USB: GADGET: optionally force full-speed for net2280 UDC (2013-01-31 
> > 10:09:19 +0100)
> > 
> > are available in the git repository at:
> > 
> >   git://git.pengutronix.de/git/imx/linux-2.6.git tags/usb-chipidea-for-next
> > 
> > for you to fetch changes up to 25682afd7be85f1462647d8530dca1bf848074fc:
> > 
> >   USB chipidea i.MX: use devm_usb_get_phy_by_phandle to get phy (2013-02-04 
> > 12:28:53 +0100)
> > 
> > 
> > USB: chipidea patches for v3.9
> > 
> > These add OF helpers for handling the dr_mode and phy_type property
> > and makes use of them in the chipidea driver.
> > 
> > ----
> > Marc Kleine-Budde (1):
> >   usb: otg: use try_module_get in all usb_get_phy functions and add 
> > missing module_put
> > 
> > Michael Grzeschik (3):
> >   USB: add devicetree helpers for determining dr_mode and phy_type
> >   USB: chipidea: ci13xxx-imx: create dynamic platformdata
> >   USB: chipidea: add PTW and PTS handling
> > 
> > Sascha Hauer (5):
> >   USB: move bulk of otg/otg.c to phy/phy.c
> >   USB chipidea: introduce dual role mode pdata flags
> >   USB chipidea i.MX: introduce dr_mode property
> >   USB mxs-phy: Register phy with framework
> >   USB chipidea i.MX: use devm_usb_get_phy_by_phandle to get phy
> > 
> >  .../devicetree/bindings/usb/ci13xxx-imx.txt|6 +
> >  drivers/usb/chipidea/bits.h|   14 +-
> >  drivers/usb/chipidea/ci13xxx_imx.c |   68 +--
> >  drivers/usb/chipidea/core.c|   60 ++-
> >  drivers/usb/otg/mxs-phy.c  |9 +
> >  drivers/usb/otg/otg.c  |  423 
> > ---
> >  drivers/usb/phy/Makefile   |2 +
> >  drivers/usb/phy/of.c   |   47 +++
> >  drivers/usb/phy/phy.c  |  438 
> > 
> >  drivers/usb/usb-common.c   |   36 ++
> >  include/linux/usb/chipidea.h   |3 +-
> >  include/linux/usb/of.h |   27 ++
> >  include/linux/usb/otg.h|7 +
> >  include/linux/usb/phy.h|9 +
> >  14 files changed, 687 insertions(+), 462 deletions(-)
> >  create mode 100644 drivers/usb/phy/of.c
> >  create mode 100644 drivers/usb/phy/phy.c
> >  crea

Re: [PATCH 3/9] USB: add devicetree helpers for determining dr_mode and phy_type

2013-02-14 Thread Sascha Hauer
On Thu, Feb 14, 2013 at 11:58:22AM +0200, Felipe Balbi wrote:
> Hi,
> 
> On Thu, Feb 14, 2013 at 10:49:44AM +0100, Marc Kleine-Budde wrote:
> > >> diff --git a/drivers/usb/usb-common.c b/drivers/usb/usb-common.c
> > >> index d29503e..ad4d87d 100644
> > >> --- a/drivers/usb/usb-common.c
> > >> +++ b/drivers/usb/usb-common.c
> > >> @@ -14,6 +14,9 @@
> > >>  #include 
> > >>  #include 
> > >>  #include 
> > >> +#include 
> > >> +#include 
> > >> +#include 
> > >>  
> > >>  const char *usb_speed_string(enum usb_device_speed speed)
> > >>  {
> > >> @@ -32,4 +35,37 @@ const char *usb_speed_string(enum usb_device_speed 
> > >> speed)
> > >>  }
> > >>  EXPORT_SYMBOL_GPL(usb_speed_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",
> > >> +};
> > > 
> > > It turns out this is a problem, especially since this is generic usb
> > > code: we have a chipidea controller (a patchset just arrived) that does
> > > both host and peripheral, but not otg. And I'm told now that dwc3
> > > controller can be synthesized like that too.
> 
> I wonder if this part is really necessary. Usually you would read it
> from HW's registers. For dwc3, it's quite recently that we allowed the
> driver to be built with host-only, device-only or DRD functionality.

We have quite some boards on which the ID pin is not wired up, so if a
core is both host and device capable there is no way to detect the
wanted mode if not given from the devicetree.

> 
> Also, this is likely to create troubles if not done correctly. Imagine
> user compiles a host-only driver and board passes dr_mode = peripheral ?

Either nothing will happen or some "you messed it up" printk should show
the user what's going on.

> 
> Maybe we can ignore dr_mode in host-only and device-only builds and only
> look at it for DRD builds ?

If something is or is not compiled in the kernel this doesn't mean the kernel
is not started on boards with a different situation.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/9] USB: add devicetree helpers for determining dr_mode and phy_type

2013-02-14 Thread Sascha Hauer
On Thu, Feb 14, 2013 at 12:15:10PM +0200, Felipe Balbi wrote:
> Hi,
> 
> On Thu, Feb 14, 2013 at 11:07:22AM +0100, Sascha Hauer wrote:
> > > > >> @@ -32,4 +35,37 @@ const char *usb_speed_string(enum 
> > > > >> usb_device_speed speed)
> > > > >>  }
> > > > >>  EXPORT_SYMBOL_GPL(usb_speed_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",
> > > > >> +};
> > > > > 
> > > > > It turns out this is a problem, especially since this is generic usb
> > > > > code: we have a chipidea controller (a patchset just arrived) that 
> > > > > does
> > > > > both host and peripheral, but not otg. And I'm told now that dwc3
> > > > > controller can be synthesized like that too.
> > > 
> > > I wonder if this part is really necessary. Usually you would read it
> > > from HW's registers. For dwc3, it's quite recently that we allowed the
> > > driver to be built with host-only, device-only or DRD functionality.
> > 
> > We have quite some boards on which the ID pin is not wired up, so if a
> > core is both host and device capable there is no way to detect the
> > wanted mode if not given from the devicetree.
> 
> right, that's fair. But that doesn't mean board can't work as both,
> right. The IP is still the same, just the board is wired differently ;-)

Yes, it is. Usually I run kernels with both host and device support enabled.
Consider the IP is OTG capable, the chipidea driver will initialize
both roles. Now if a board only supports one role and does not have an
ID pin, how do I make sure the driver is in the correct mode? I need to
specify it somehow. Otherwise I may end up on a host-only board with the
driver sitting in device mode, or with a device-only board with the
driver sitting in host mode.

> 
> > > Maybe we can ignore dr_mode in host-only and device-only builds and only
> > > look at it for DRD builds ?
> > 
> > If something is or is not compiled in the kernel this doesn't mean the 
> > kernel
> > is not started on boards with a different situation.
> 
> who said kernel wouldn't start ? If you request a host-only build, you
> need to force your IP into working as host, since that's all you have,
> either that or you bail out on probe().

Let me clarify, I don't want to use Kconfig to specify my boards
capabilities. If a kernel is compiled for host mode only and the
devicetree specifies a port is device-only, then yes, the driver
should bail out on probe, maybe leaving a message that it found
a device for which the suitable role is not compiled in.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/9] USB: add devicetree helpers for determining dr_mode and phy_type

2013-02-14 Thread Sascha Hauer
On Thu, Feb 14, 2013 at 03:10:15PM +0200, Felipe Balbi wrote:
> On Thu, Feb 14, 2013 at 12:24:49PM +0100, Sascha Hauer wrote:
> > On Thu, Feb 14, 2013 at 12:15:10PM +0200, Felipe Balbi wrote:
> > > Hi,
> > > 
> > > On Thu, Feb 14, 2013 at 11:07:22AM +0100, Sascha Hauer wrote:
> > > > > > >> @@ -32,4 +35,37 @@ const char *usb_speed_string(enum 
> > > > > > >> usb_device_speed speed)
> > > > > > >>  }
> > > > > > >>  EXPORT_SYMBOL_GPL(usb_speed_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",
> > > > > > >> +};
> > > > > > > 
> > > > > > > It turns out this is a problem, especially since this is generic 
> > > > > > > usb
> > > > > > > code: we have a chipidea controller (a patchset just arrived) 
> > > > > > > that does
> > > > > > > both host and peripheral, but not otg. And I'm told now that dwc3
> > > > > > > controller can be synthesized like that too.
> > > > > 
> > > > > I wonder if this part is really necessary. Usually you would read it
> > > > > from HW's registers. For dwc3, it's quite recently that we allowed the
> > > > > driver to be built with host-only, device-only or DRD functionality.
> > > > 
> > > > We have quite some boards on which the ID pin is not wired up, so if a
> > > > core is both host and device capable there is no way to detect the
> > > > wanted mode if not given from the devicetree.
> > > 
> > > right, that's fair. But that doesn't mean board can't work as both,
> > > right. The IP is still the same, just the board is wired differently ;-)
> > 
> > Yes, it is. Usually I run kernels with both host and device support enabled.
> > Consider the IP is OTG capable, the chipidea driver will initialize
> > both roles. Now if a board only supports one role and does not have an
> > ID pin, how do I make sure the driver is in the correct mode? I need to
> > specify it somehow. Otherwise I may end up on a host-only board with the
> > driver sitting in device mode, or with a device-only board with the
> > driver sitting in host mode.
> 
> right.
> 
> > > > > Maybe we can ignore dr_mode in host-only and device-only builds and 
> > > > > only
> > > > > look at it for DRD builds ?
> > > > 
> > > > If something is or is not compiled in the kernel this doesn't mean the 
> > > > kernel
> > > > is not started on boards with a different situation.
> > > 
> > > who said kernel wouldn't start ? If you request a host-only build, you
> > > need to force your IP into working as host, since that's all you have,
> > > either that or you bail out on probe().
> > 
> > Let me clarify, I don't want to use Kconfig to specify my boards
> > capabilities. If a kernel is compiled for host mode only and the
> > devicetree specifies a port is device-only, then yes, the driver
> > should bail out on probe, maybe leaving a message that it found
> > a device for which the suitable role is not compiled in.
> 
> yeah, this is why I said we should ignore dr_mode (or bail out) when
> !OTG.

Ok, that's what the patch effectively does. We have this in chipidea/core.c:

|   dr_mode = ci->platdata->dr_mode;
|   if (dr_mode == USB_DR_MODE_UNKNOWN)
|   dr_mode = USB_DR_MODE_OTG;

default to otg if nothing specified.

| 
|   /* initialize role(s) before the interrupt is requested */
|   if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) {
|   ret = ci_hdrc_host_init(ci);
|   if (ret)
|   dev_info(dev, "doesn't support host\n");
|   }

If we can do OTG or host, try to initialize host role,

| 
|   if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_PERIPHERAL) {
|   ret = ci_hdrc_gadget_init(ci);
|   if (ret)
|   dev_info(dev, "doesn't support gadget\n");
|   }

if we can do otg or peripheral, try to initialize device role,

| 
|   if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) {
|   dev_err(dev, "no supported roles\n");
|   ret = -ENODEV;
|   goto rm_wq;
|   }

If we have no roles, complain and bail out.

ci_hdrc_host_init / ci_hdrc_gadget_init are static inline noops when
gadget or host are disabled.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/2] USB mxs-phy: Register phy with framework

2013-02-14 Thread Sascha Hauer
On Thu, Feb 14, 2013 at 12:37:29PM +0200, Felipe Balbi wrote:
> Hi,
> 
> On Thu, Jan 31, 2013 at 12:32:16PM +0100, Sascha Hauer wrote:
> > We now have usb_add_phy_dev(), so use it to register with the framework
> > to be able to find the phy from the USB driver.
> > 
> > Signed-off-by: Sascha Hauer 
> 
> Sascha, are you taking this through your tree or you want me to queue it
> up ?

I would prefer if either you could take it or Alexander Shishkin along
with the other patches in:

[PATCH v4] USB: add devicetree helpers for determining dr_mode and phy_type

Could you have a look at them? Alexander is asking for an ack for 1/9,
2/9, 3/9, 8/9. I just realized you are not on Cc for these. I could
bounce you the patches in case you don't have them in your mailbox.

Thanks
 Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/9] USB: add devicetree helpers for determining dr_mode and phy_type

2013-02-14 Thread Sascha Hauer
On Thu, Feb 14, 2013 at 08:04:44PM +0200, Felipe Balbi wrote:
> Hi,
> 
> On Thu, Feb 14, 2013 at 05:06:55PM +0100, Sascha Hauer wrote:
> > > > > > > Maybe we can ignore dr_mode in host-only and device-only builds 
> > > > > > > and only
> > > > > > > look at it for DRD builds ?
> > > > > > 
> > > > > > If something is or is not compiled in the kernel this doesn't mean 
> > > > > > the kernel
> > > > > > is not started on boards with a different situation.
> > > > > 
> > > > > who said kernel wouldn't start ? If you request a host-only build, you
> > > > > need to force your IP into working as host, since that's all you have,
> > > > > either that or you bail out on probe().
> > > > 
> > > > Let me clarify, I don't want to use Kconfig to specify my boards
> > > > capabilities. If a kernel is compiled for host mode only and the
> > > > devicetree specifies a port is device-only, then yes, the driver
> > > > should bail out on probe, maybe leaving a message that it found
> > > > a device for which the suitable role is not compiled in.
> > > 
> > > yeah, this is why I said we should ignore dr_mode (or bail out) when
> > > !OTG.
> > 
> > Ok, that's what the patch effectively does. We have this in chipidea/core.c:
> > 
> > |   dr_mode = ci->platdata->dr_mode;
> > |   if (dr_mode == USB_DR_MODE_UNKNOWN)
> > |   dr_mode = USB_DR_MODE_OTG;
> > 
> > default to otg if nothing specified.
> 
> you missed my point. I wanted something like:
> 
> dr_mode = ci->platdata->dr_mode;
> if ((dr_mode == USB_DR_MODE_UNKNOWN) || !IS_ENABLED(CONFIG_USB_CHIPIDEA_OTG)
>   dr_mode = USB_DR_MODE_OTG;

So everytime the chipidea driver cannot do OTG the driver falls back to
exactly this mode?

> 
> this copes with the situation where dr_mode == USB_DR_MODE_HOST but
> kernel is gadget-only.

When I specify dr_mode = USB_DR_MODE_HOST in the devicetree indicating
that my board is only host capable I exactly want the driver to be in
host mode for this device, or to bail out if the kernel does not have
host support compiled in.

Sorry, I still don't get it.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/2] USB mxs-phy: Register phy with framework

2013-02-14 Thread Sascha Hauer
On Thu, Feb 14, 2013 at 08:00:11PM +0200, Felipe Balbi wrote:
> Hi,
> 
> On Thu, Feb 14, 2013 at 05:23:37PM +0100, Sascha Hauer wrote:
> > On Thu, Feb 14, 2013 at 12:37:29PM +0200, Felipe Balbi wrote:
> > > Hi,
> > > 
> > > On Thu, Jan 31, 2013 at 12:32:16PM +0100, Sascha Hauer wrote:
> > > > We now have usb_add_phy_dev(), so use it to register with the framework
> > > > to be able to find the phy from the USB driver.
> > > > 
> > > > Signed-off-by: Sascha Hauer 
> > > 
> > > Sascha, are you taking this through your tree or you want me to queue it
> > > up ?
> > 
> > I would prefer if either you could take it or Alexander Shishkin along
> > with the other patches in:
> > 
> > [PATCH v4] USB: add devicetree helpers for determining dr_mode and phy_type
> > 
> > Could you have a look at them? Alexander is asking for an ack for 1/9,
> > 2/9, 3/9, 8/9. I just realized you are not on Cc for these. I could
> > bounce you the patches in case you don't have them in your mailbox.
> 
> Ok, I'll look at them, no need to bounce. You _do_ realize, however,
> that Greg has already closed all his trees for v3.9, right ? So anything
> from now on will be queued for v3.10.

I'm fine with that. I'm just a bit insistent because the chipidea patches are
floating around for half a year now. Once I have the warm feeling that
the patches are handled I have time ;)

Thanks
 Sascha


-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/9] USB: add devicetree helpers for determining dr_mode and phy_type

2013-02-15 Thread Sascha Hauer
On Thu, Feb 14, 2013 at 09:36:26PM +0200, Felipe Balbi wrote:
> Hi,
> 
> On Thu, Feb 14, 2013 at 07:30:26PM +0100, Sascha Hauer wrote:
> > > > > yeah, this is why I said we should ignore dr_mode (or bail out) when
> > > > > !OTG.
> > > > 
> > > > Ok, that's what the patch effectively does. We have this in 
> > > > chipidea/core.c:
> > > > 
> > > > |   dr_mode = ci->platdata->dr_mode;
> > > > |   if (dr_mode == USB_DR_MODE_UNKNOWN)
> > > > |   dr_mode = USB_DR_MODE_OTG;
> > > > 
> > > > default to otg if nothing specified.
> > > 
> > > you missed my point. I wanted something like:
> > > 
> > > dr_mode = ci->platdata->dr_mode;
> > > if ((dr_mode == USB_DR_MODE_UNKNOWN) || 
> > > !IS_ENABLED(CONFIG_USB_CHIPIDEA_OTG)
> > >   dr_mode = USB_DR_MODE_OTG;
> > 
> > So everytime the chipidea driver cannot do OTG the driver falls back to
> > exactly this mode?
> 
> hehe, that was me being stupid I meant something like:
> 
> if (!IS_ENABLED(HOST) && dr_mode == HOST)
> 
> or
> 
> if (!IS_ENABLED(GADGET) && dr_mode == GADGET)
> 
> in those cases, it's best to either force OTG (then driver will work
> with whatever it has) or bail out.
> 
> Thinking a bit harder, it's best to bail as you can't be sure udc.c or
> host.c have been compiled in.

Look again, that's what the current code does. Maybe it's not coded as
explicit as you describe above.

|   /* initialize role(s) before the interrupt is requested */
|   if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) {
|   ret = ci_hdrc_host_init(ci);
|   if (ret)
|   dev_info(dev, "doesn't support host\n");
|   }

if IS_ENABLED(HOST), then ci_hdrc_host_init() will set
ci->roles[CI_ROLE_HOST] in case it manages to initialize the host driver.

if !IS_ENABLED(HOST), then ci_hdrc_host_init() will be a static inline
noop function, so ci->roles[CI_ROLE_HOST] ends up being NULL.

| 
|   if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_PERIPHERAL) {
|   ret = ci_hdrc_gadget_init(ci);
|   if (ret)
|   dev_info(dev, "doesn't support gadget\n");
|   }

Same applies for gadget.

| 
|   if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) {
|   dev_err(dev, "no supported roles\n");
|   ret = -ENODEV;
|   goto rm_wq;
|   }

At this point (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET])
means that the intersection of what is requested and what we are able to
do is empty. The reasons could be That the requested mode is not compiled
into the kernel, or the requested role failed to initialize.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/9] USB: move bulk of otg/otg.c to phy/phy.c

2013-02-19 Thread Sascha Hauer
On Tue, Feb 19, 2013 at 11:30:19AM +0200, Felipe Balbi wrote:
> On Mon, Feb 04, 2013 at 02:24:28PM +0100, Sascha Hauer wrote:
> > Most of otg/otg.c is not otg specific, but phy specific, so move it
> > to the phy directory.
> > 
> > Signed-off-by: Sascha Hauer 
> > Reported-by: Kishon Vijay Abraham I 
> > Cc: Felipe Balbi 
> 
> this is pretty ok, I'll start queueing patches for v3.10 in about a week
> or two.

Ok, thanks. I'll resend this after the merge window.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v10 6/8] usb: chipidea: imx: add internal vbus regulator control

2013-02-27 Thread Sascha Hauer
On Wed, Feb 27, 2013 at 09:55:10AM +0200, Felipe Balbi wrote:
> Hi,
> 
> On Wed, Feb 27, 2013 at 02:33:17PM +0800, Peter Chen wrote:
> > - For host, the vbus should always be on.
> > - For otg, the vbus is off defaultly, the vbus needs to be
> > turned on/off when usb role switches.
> > 
> > Signed-off-by: Peter Chen 
> 
> one quick question, if chipidea already has an imx glue layer, can I
> delete the broken imx_udc ? It doesn't even compile and it's including
> headers which don't exist.

This driver handles i.MX1. This one has a gadget only core which is not
chipidea compatible. You should ping Darius Augulis 
if he is willing to put some love into the driver.

Sascha


-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] USB: chipidea: fix error path

2013-12-19 Thread Sascha Hauer
devm_usb_get_phy_by_phandle() returns a PTR_ERR on failure, so we have
to check for IS_ERR before calling usb_phy_shutdown(), not for NULL.

Signed-off-by: Sascha Hauer 
Cc: Peter Chen 
Cc: linux-usb@vger.kernel.org
---
 drivers/usb/chipidea/ci_hdrc_imx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c 
b/drivers/usb/chipidea/ci_hdrc_imx.c
index be822a2..1b7ffc9 100644
--- a/drivers/usb/chipidea/ci_hdrc_imx.c
+++ b/drivers/usb/chipidea/ci_hdrc_imx.c
@@ -165,7 +165,7 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
 disable_device:
ci_hdrc_remove_device(data->ci_pdev);
 err_phy:
-   if (data->phy)
+   if (!IS_ERR(data->phy))
usb_phy_shutdown(data->phy);
 err_clk:
clk_disable_unprepare(data->clk);
@@ -179,7 +179,7 @@ static int ci_hdrc_imx_remove(struct platform_device *pdev)
pm_runtime_disable(&pdev->dev);
ci_hdrc_remove_device(data->ci_pdev);
 
-   if (data->phy)
+   if (!IS_ERR(data->phy))
usb_phy_shutdown(data->phy);
 
clk_disable_unprepare(data->clk);
-- 
1.8.5.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] USB: chipidea: fix error path

2013-12-20 Thread Sascha Hauer
On Thu, Dec 19, 2013 at 04:28:54PM +0800, Peter Chen wrote:
> On Thu, Dec 19, 2013 at 09:35:44AM +0100, Sascha Hauer wrote:
> > devm_usb_get_phy_by_phandle() returns a PTR_ERR on failure, so we have
> > to check for IS_ERR before calling usb_phy_shutdown(), not for NULL.
> > 
> > Signed-off-by: Sascha Hauer 
> > Cc: Peter Chen 
> > Cc: linux-usb@vger.kernel.org
> > ---
> >  drivers/usb/chipidea/ci_hdrc_imx.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c 
> > b/drivers/usb/chipidea/ci_hdrc_imx.c
> > index be822a2..1b7ffc9 100644
> > --- a/drivers/usb/chipidea/ci_hdrc_imx.c
> > +++ b/drivers/usb/chipidea/ci_hdrc_imx.c
> > @@ -165,7 +165,7 @@ static int ci_hdrc_imx_probe(struct platform_device 
> > *pdev)
> >  disable_device:
> > ci_hdrc_remove_device(data->ci_pdev);
> >  err_phy:
> > -   if (data->phy)
> > +   if (!IS_ERR(data->phy))
> > usb_phy_shutdown(data->phy);
> >  err_clk:
> > clk_disable_unprepare(data->clk);
> > @@ -179,7 +179,7 @@ static int ci_hdrc_imx_remove(struct platform_device 
> > *pdev)
> > pm_runtime_disable(&pdev->dev);
> > ci_hdrc_remove_device(data->ci_pdev);
> >  
> > -   if (data->phy)
> > +   if (!IS_ERR(data->phy))
> > usb_phy_shutdown(data->phy);
> >  
> > clk_disable_unprepare(data->clk);
> > -- 
> > 1.8.5.1
> > 
> 
> Sascha, thanks for your patch.
> 
> We have already moved PHY operation from glue layer to core, this
> patch may not be needed.

Ok, right. I missed these.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 5/5] arm: dts: imx: Delete usbmisc_imx

2013-08-08 Thread Sascha Hauer
On Thu, Aug 08, 2013 at 06:19:43PM +0800, Peter Chen wrote:
> > > - compatible = "fsl,imx25-usbmisc";
> > > - clocks = <&clks 9>, <&clks 70>, <&clks 8>;
> > > - clock-names = "ipg", "ahb", "per";
> > > - reg = <0x53ff4600 0x00f>;
> > > - status = "disabled";
> > > + noncore: usb-non-core@53ff4600 {
> > > +  compatible = "fsl,imx-usb-non-core", "syscon";
> > > +  reg = <0x53ff4600 0xf>;
> > >   };
> > 
> > This is bullshit for multiple reasons.
> > 
> > It's the usbmisc unit that changes between different SoCs, not the
> > chipidea core. So pretending the usbmisc unit is generic by removing the
> > SoC specific compatible and instead leaking in the SoC type from the
> > chipidea device nodes is just crazy.
> > 
> 
> Please do not call usbmisc as "unit", it should not be a driver, it is
> a "lib", it is "usbmisc-lib" to implement functions for controller
> driver.
> 
> At current design, there are two drivers (ci_hdrc_imx & usbmisc_imx) to
> control one hardware (one imx usb controller). You will need to control
> the same clocks at two drivers, it is not a good idea.

It's more meaningful to talk about devices instead of drivers. The USB
core consists of three (on most i.MX) devices, namely three identical
chipidea cores. The clocks are shared between all these devices and the
clock framework handles this just fine due to reference counting.

> Besides, there
> are dependencies between two drivers, the usbmisc will be unloaded
> first, how usbmisc can supply the functions after it is unloaded?
> Remember, it is one hardware, why one driver can forbid another to use
> controller's function?
> 
> > What you are doing here is to model the DT after how the Linux driver is
> > programmed. This really is a bad idea. Remember that the bindings have
> > to be OS agnostic. They can't be changed just because you want to
> > resolve your module probe dependencies.
> 
> I am a beginner for DT, how DT binding can't be changed if the driver
> has re-designed? If I understand correctly, you say "bindings have to
> be OS agnostic", you mean the same DT can be used at all late Linux 
> versions after the binding has finished, is it correct?

And not only Linux, but also *BSD and others. Currently I use the same
bindings for barebox which means I would have to change the bindings
there aswell once you change them in the Kernel.

> 
> > 
> > Also the existing binding with referencing the usbmisc instance with
> > <&usbmisc number> is good and convenient. Instead depending on the alias
> > number of the chipidea node is quite non-obvious.
> > 
> 
> Again, binding is for driver, if it is not suitable as a driver, what 
> the meaningful for the existent of binding? 

Maybe I would believe you if you removed the need for a driver, but what
you do is to replace a 'usbmisc driver' handling a 'usbmisc device' with
a 'syscon driver' handling a 'syscon device'. The real change here is
that the implementation of the driver logic is moved from the usbmisc
driver to the chipidea driver.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/2] USB: chipidea: i.MX: remove unused define

2013-08-08 Thread Sascha Hauer
Signed-off-by: Sascha Hauer 
---
 drivers/usb/chipidea/ci_hdrc_imx.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c 
b/drivers/usb/chipidea/ci_hdrc_imx.c
index 14362c0..11ed423 100644
--- a/drivers/usb/chipidea/ci_hdrc_imx.c
+++ b/drivers/usb/chipidea/ci_hdrc_imx.c
@@ -24,9 +24,6 @@
 #include "ci.h"
 #include "ci_hdrc_imx.h"
 
-#define pdev_to_phy(pdev) \
-   ((struct usb_phy *)platform_get_drvdata(pdev))
-
 struct ci_hdrc_imx_data {
struct usb_phy *phy;
struct platform_device *ci_pdev;
-- 
1.8.4.rc1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/2] USB: chipidea: i.MX: simplify usbmisc

2013-08-08 Thread Sascha Hauer
The chipidea i.MX driver is split into two drivers. The ci_hdrc_imx driver
handles the chipidea cores and the usbmisc_imx driver handles the noncore
registers common to all chipidea cores (but SoC specific). Current flow is:

- usbmisc sets an ops pointer in the ci_hdrc_imx driver during probe
- ci_hdrc_imx checks if the pointer is valid during probe, if yes calls
  the functions in the ops pointer.
- usbmisc_imx calls back into the ci_hdrc_imx driver to get additional
  data

This is overly complicated and has problems if the drivers are compiled
as modules. In this case the usbmisc_imx driver can be unloaded even if
the ci_hdrc_imx driver still needs usbmisc functionality.

This patch changes this by letting the ci_hdrc_imx driver calling functions
from the usbmisc_imx driver. This way the symbol resolving during module
load makes sure the ci_hdrc_imx driver depends on the usbmisc_imx driver.

Also instead of letting the usbmisc_imx driver call back into the ci_hdrc_imx
driver, pass the needed data in the first place.

Signed-off-by: Sascha Hauer 
---
 drivers/usb/chipidea/ci_hdrc_imx.c | 74 +++--
 drivers/usb/chipidea/ci_hdrc_imx.h | 17 ++-
 drivers/usb/chipidea/usbmisc_imx.c | 95 +-
 3 files changed, 72 insertions(+), 114 deletions(-)

diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c 
b/drivers/usb/chipidea/ci_hdrc_imx.c
index 11ed423..7e722fe 100644
--- a/drivers/usb/chipidea/ci_hdrc_imx.c
+++ b/drivers/usb/chipidea/ci_hdrc_imx.c
@@ -29,57 +29,43 @@ struct ci_hdrc_imx_data {
struct platform_device *ci_pdev;
struct clk *clk;
struct regulator *reg_vbus;
+   struct imx_usbmisc_data *usbmisc_data;
 };
 
-static const struct usbmisc_ops *usbmisc_ops;
-
 /* Common functions shared by usbmisc drivers */
 
-int usbmisc_set_ops(const struct usbmisc_ops *ops)
-{
-   if (usbmisc_ops)
-   return -EBUSY;
-
-   usbmisc_ops = ops;
-
-   return 0;
-}
-EXPORT_SYMBOL_GPL(usbmisc_set_ops);
-
-void usbmisc_unset_ops(const struct usbmisc_ops *ops)
-{
-   usbmisc_ops = NULL;
-}
-EXPORT_SYMBOL_GPL(usbmisc_unset_ops);
-
-int usbmisc_get_init_data(struct device *dev, struct usbmisc_usb_device 
*usbdev)
+static struct imx_usbmisc_data *usbmisc_get_init_data(struct device *dev)
 {
struct device_node *np = dev->of_node;
struct of_phandle_args args;
+   struct imx_usbmisc_data *data;
int ret;
 
-   usbdev->dev = dev;
+   if (!of_get_property(np, "fsl,usbmisc", NULL))
+   return NULL;
 
ret = of_parse_phandle_with_args(np, "fsl,usbmisc", "#index-cells",
0, &args);
if (ret) {
dev_err(dev, "Failed to parse property fsl,usbmisc, errno %d\n",
ret);
-   memset(usbdev, 0, sizeof(*usbdev));
-   return ret;
+   return ERR_PTR(ret);
}
-   usbdev->index = args.args[0];
-   of_node_put(args.np);
+
+   data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
+   if (!data)
+   return ERR_PTR(-ENOMEM);
+
+   data->index = args.args[0];
 
if (of_find_property(np, "disable-over-current", NULL))
-   usbdev->disable_oc = 1;
+   data->disable_oc = 1;
 
if (of_find_property(np, "external-vbus-divider", NULL))
-   usbdev->evdo = 1;
+   data->evdo = 1;
 
-   return 0;
+   return data;
 }
-EXPORT_SYMBOL_GPL(usbmisc_get_init_data);
 
 /* End of common functions shared by usbmisc drivers*/
 
@@ -96,10 +82,6 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
struct resource *res;
int ret;
 
-   if (of_find_property(pdev->dev.of_node, "fsl,usbmisc", NULL)
-   && !usbmisc_ops)
-   return -EPROBE_DEFER;
-
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
if (!data) {
dev_err(&pdev->dev, "Failed to allocate ci_hdrc-imx data!\n");
@@ -112,6 +94,10 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
return -ENOENT;
}
 
+   data->usbmisc_data = usbmisc_get_init_data(&pdev->dev);
+   if (IS_ERR(data->usbmisc_data))
+   return PTR_ERR(data->usbmisc_data);
+
data->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(data->clk)) {
dev_err(&pdev->dev,
@@ -159,13 +145,10 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
if (!pdev->dev.coherent_dma_mask)
pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
 
-   if (usbmisc_ops && usbmisc_ops->init) {
-   ret = usbmisc_ops->init(&pdev->dev);
-   if (ret) {
-   dev_err(&

[PATCH] USB chipidea i.MX: Fix module loading

2013-08-08 Thread Sascha Hauer
The Chipidea i.MX driver has some issues with module loading dependencies.
This fixes this. It is an alternative approach to the one Peter Chen
suggested that does without changing the dt binding.

Sascha


Sascha Hauer (2):
  USB: chipidea: i.MX: remove unused define
  USB: chipidea: i.MX: simplify usbmisc

 drivers/usb/chipidea/ci_hdrc_imx.c | 77 +++---
 drivers/usb/chipidea/ci_hdrc_imx.h | 17 ++-
 drivers/usb/chipidea/usbmisc_imx.c | 95 +-
 3 files changed, 72 insertions(+), 117 deletions(-)
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] chipidea: core: Move hw_phymode_configure() into probe

2013-08-09 Thread Sascha Hauer
On Thu, Jul 25, 2013 at 06:20:34PM -0300, Fabio Estevam wrote:
> Currently hw_phymode_configure() is located inside hw_device_reset(), which is
> only called by chipidea udc driver.
> 
> When operating in host mode, we also need to call hw_phymode_configure() in 
> order to properly configure the PHY mode, so move this function into probe.
> 
> After this change, USB Host1 port on mx53qsb board is functional.
> 
> Signed-off-by: Fabio Estevam 

Also fixes my i.MX53 USB host mode problems.

Acked-by: Sascha Hauer 

Sascha

> ---
>  drivers/usb/chipidea/core.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
> index a5df24c..a5b3774 100644
> --- a/drivers/usb/chipidea/core.c
> +++ b/drivers/usb/chipidea/core.c
> @@ -264,8 +264,6 @@ int hw_device_reset(struct ci_hdrc *ci, u32 mode)
>   while (hw_read(ci, OP_USBCMD, USBCMD_RST))
>   udelay(10); /* not RTOS friendly */
>  
> - hw_phymode_configure(ci);
> -
>   if (ci->platdata->notify_event)
>   ci->platdata->notify_event(ci,
>   CI_HDRC_CONTROLLER_RESET_EVENT);
> @@ -457,6 +455,8 @@ static int ci_hdrc_probe(struct platform_device *pdev)
>   if (!ci->platdata->phy_mode)
>   ci->platdata->phy_mode = of_usb_get_phy_mode(dev->of_node);
>  
> + hw_phymode_configure(ci);
> +
>   if (!ci->platdata->dr_mode)
>   ci->platdata->dr_mode = of_usb_get_dr_mode(dev->of_node);
>  
> -- 
> 1.8.1.2
> 
> 
> 

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] USB: chipidea: i.MX: simplify usbmisc

2013-08-09 Thread Sascha Hauer
On Fri, Aug 09, 2013 at 06:25:29PM +0800, Peter Chen wrote:
> > -void usbmisc_unset_ops(const struct usbmisc_ops *ops)
> > -{
> > -   usbmisc_ops = NULL;
> > -}
> > -EXPORT_SYMBOL_GPL(usbmisc_unset_ops);
> > -
> > -int usbmisc_get_init_data(struct device *dev, struct usbmisc_usb_device 
> > *usbdev)
> > +static struct imx_usbmisc_data *usbmisc_get_init_data(struct device *dev)
> >  {
> > struct device_node *np = dev->of_node;
> > struct of_phandle_args args;
> > +   struct imx_usbmisc_data *data;
> > int ret;
> >  
> > -   usbdev->dev = dev;
> > +   if (!of_get_property(np, "fsl,usbmisc", NULL))
> > +   return NULL;
> >  
> > ret = of_parse_phandle_with_args(np, "fsl,usbmisc", "#index-cells",
> > 0, &args);
> > if (ret) {
> > dev_err(dev, "Failed to parse property fsl,usbmisc, errno %d\n",
> > ret);
> > -   memset(usbdev, 0, sizeof(*usbdev));
> > -   return ret;
> > +   return ERR_PTR(ret);
> > }
> > -   usbdev->index = args.args[0];
> > -   of_node_put(args.np);
> 
> Is it a bug fix?

Nope, it introduces one. The of_node_put should stay there. Will fix.

> > +   data->usbmisc_data = usbmisc_get_init_data(&pdev->dev);
> > +   if (IS_ERR(data->usbmisc_data))
> > +   return PTR_ERR(data->usbmisc_data);
> > +
> 
> You need to consider mx23/mx28 case which doesn't have usbmisc.

The idea was that if fsl,usbmisc is not present the device doesn't need
usbmisc handling, but I haven't implemented this correctly.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/2] USB: chipidea: i.MX: simplify usbmisc

2013-08-12 Thread Sascha Hauer
The chipidea i.MX driver is split into two drivers. The ci_hdrc_imx driver
handles the chipidea cores and the usbmisc_imx driver handles the noncore
registers common to all chipidea cores (but SoC specific). Current flow is:

- usbmisc sets an ops pointer in the ci_hdrc_imx driver during probe
- ci_hdrc_imx checks if the pointer is valid during probe, if yes calls
  the functions in the ops pointer.
- usbmisc_imx calls back into the ci_hdrc_imx driver to get additional
  data

This is overly complicated and has problems if the drivers are compiled
as modules. In this case the usbmisc_imx driver can be unloaded even if
the ci_hdrc_imx driver still needs usbmisc functionality.

This patch changes this by letting the ci_hdrc_imx driver calling functions
from the usbmisc_imx driver. This way the symbol resolving during module
load makes sure the ci_hdrc_imx driver depends on the usbmisc_imx driver.

Also instead of letting the usbmisc_imx driver call back into the ci_hdrc_imx
driver, pass the needed data in the first place.

Signed-off-by: Sascha Hauer 
---
 drivers/usb/chipidea/ci_hdrc_imx.c | 71 +---
 drivers/usb/chipidea/ci_hdrc_imx.h | 17 ++-
 drivers/usb/chipidea/usbmisc_imx.c | 95 +-
 3 files changed, 76 insertions(+), 107 deletions(-)

diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c 
b/drivers/usb/chipidea/ci_hdrc_imx.c
index 11ed423..b9464ff 100644
--- a/drivers/usb/chipidea/ci_hdrc_imx.c
+++ b/drivers/usb/chipidea/ci_hdrc_imx.c
@@ -29,57 +29,48 @@ struct ci_hdrc_imx_data {
struct platform_device *ci_pdev;
struct clk *clk;
struct regulator *reg_vbus;
+   struct imx_usbmisc_data *usbmisc_data;
 };
 
-static const struct usbmisc_ops *usbmisc_ops;
-
 /* Common functions shared by usbmisc drivers */
 
-int usbmisc_set_ops(const struct usbmisc_ops *ops)
-{
-   if (usbmisc_ops)
-   return -EBUSY;
-
-   usbmisc_ops = ops;
-
-   return 0;
-}
-EXPORT_SYMBOL_GPL(usbmisc_set_ops);
-
-void usbmisc_unset_ops(const struct usbmisc_ops *ops)
-{
-   usbmisc_ops = NULL;
-}
-EXPORT_SYMBOL_GPL(usbmisc_unset_ops);
-
-int usbmisc_get_init_data(struct device *dev, struct usbmisc_usb_device 
*usbdev)
+static struct imx_usbmisc_data *usbmisc_get_init_data(struct device *dev)
 {
struct device_node *np = dev->of_node;
struct of_phandle_args args;
+   struct imx_usbmisc_data *data;
int ret;
 
-   usbdev->dev = dev;
+   /*
+* In case the fsl,usbmisc property is not present this device doesn't
+* need usbmisc. Return NULL (which is no error here)
+*/
+   if (!of_get_property(np, "fsl,usbmisc", NULL))
+   return NULL;
+
+   data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
+   if (!data)
+   return ERR_PTR(-ENOMEM);
 
ret = of_parse_phandle_with_args(np, "fsl,usbmisc", "#index-cells",
0, &args);
if (ret) {
dev_err(dev, "Failed to parse property fsl,usbmisc, errno %d\n",
ret);
-   memset(usbdev, 0, sizeof(*usbdev));
-   return ret;
+   return ERR_PTR(ret);
}
-   usbdev->index = args.args[0];
+
+   data->index = args.args[0];
of_node_put(args.np);
 
if (of_find_property(np, "disable-over-current", NULL))
-   usbdev->disable_oc = 1;
+   data->disable_oc = 1;
 
if (of_find_property(np, "external-vbus-divider", NULL))
-   usbdev->evdo = 1;
+   data->evdo = 1;
 
-   return 0;
+   return data;
 }
-EXPORT_SYMBOL_GPL(usbmisc_get_init_data);
 
 /* End of common functions shared by usbmisc drivers*/
 
@@ -96,10 +87,6 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
struct resource *res;
int ret;
 
-   if (of_find_property(pdev->dev.of_node, "fsl,usbmisc", NULL)
-   && !usbmisc_ops)
-   return -EPROBE_DEFER;
-
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
if (!data) {
dev_err(&pdev->dev, "Failed to allocate ci_hdrc-imx data!\n");
@@ -112,6 +99,10 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
return -ENOENT;
}
 
+   data->usbmisc_data = usbmisc_get_init_data(&pdev->dev);
+   if (IS_ERR(data->usbmisc_data))
+   return PTR_ERR(data->usbmisc_data);
+
data->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(data->clk)) {
dev_err(&pdev->dev,
@@ -159,11 +150,11 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
if (!pdev->dev.coherent_dma_mask)
pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
 
-   if (

[PATCH v2] USB chipidea i.MX: Fix module loading

2013-08-12 Thread Sascha Hauer
The Chipidea i.MX driver has some issues with module loading dependencies.
This fixes this. It is an alternative approach to the one Peter Chen
suggested that does without changing the dt binding.

Sascha

changes since v1:
- make usbmisc optional when fsl,usbmisc property is not present.
  Needed for i.MX23/28 as suggested by Peter Chen


Sascha Hauer (2):
  USB: chipidea: i.MX: remove unused define
  USB: chipidea: i.MX: simplify usbmisc

 drivers/usb/chipidea/ci_hdrc_imx.c | 74 +
 drivers/usb/chipidea/ci_hdrc_imx.h | 17 ++-
 drivers/usb/chipidea/usbmisc_imx.c | 95 +-
 3 files changed, 76 insertions(+), 110 deletions(-)
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/2] USB: chipidea: i.MX: remove unused define

2013-08-12 Thread Sascha Hauer
Signed-off-by: Sascha Hauer 
---
 drivers/usb/chipidea/ci_hdrc_imx.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c 
b/drivers/usb/chipidea/ci_hdrc_imx.c
index 14362c0..11ed423 100644
--- a/drivers/usb/chipidea/ci_hdrc_imx.c
+++ b/drivers/usb/chipidea/ci_hdrc_imx.c
@@ -24,9 +24,6 @@
 #include "ci.h"
 #include "ci_hdrc_imx.h"
 
-#define pdev_to_phy(pdev) \
-   ((struct usb_phy *)platform_get_drvdata(pdev))
-
 struct ci_hdrc_imx_data {
struct usb_phy *phy;
struct platform_device *ci_pdev;
-- 
1.8.4.rc1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 0/7] driver core: prevent deferred probe with platform_driver_probe

2013-09-23 Thread Sascha Hauer
On Mon, Sep 23, 2013 at 04:27:25PM +0200, Johan Hovold wrote:
> Deferred probing cannot be used with platform_driver_probe as by the
> time probing is retried either the driver has been unregistered or its
> probe function has been set to platform_drv_probe_fail.
> 
> With commit e9354576 ("gpiolib: Defer failed gpio requests by default")
> the gpio subsystem started returning -EPROBE_DEFER, which in turn
> several platform drivers using platform_driver_probe return to driver
> core. Other subsystems (e.g. regulator) has since started doing the
> same.
> 
> The first patch in this series prevents platform drivers using
> platform_driver_probe from requesting probe deferral while warning that
> it is not supported.
> 
> The remaining patches move six platform-driver probe functions that rely
> on gpio_request out of __init. There are likely other probe functions
> that might return -EPROBE_DEFER and should be moved out of __init as
> well.

As usually when I read this I wonder why platform_driver_probe exists
anyway. The only advantage I can think off is that the probe functions
are in __init and thus can be disposed of later. Now you remove the
__init annotations from these probe functions. Wouldn't it be better to
convert the drivers to regular platform_driver_register instead?

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 0/7] driver core: prevent deferred probe with platform_driver_probe

2013-09-23 Thread Sascha Hauer
On Mon, Sep 23, 2013 at 05:20:18PM +0200, Johan Hovold wrote:
> On Mon, Sep 23, 2013 at 04:50:29PM +0200, Sascha Hauer wrote:
> > On Mon, Sep 23, 2013 at 04:27:25PM +0200, Johan Hovold wrote:
> > > Deferred probing cannot be used with platform_driver_probe as by the
> > > time probing is retried either the driver has been unregistered or its
> > > probe function has been set to platform_drv_probe_fail.
> > > 
> > > With commit e9354576 ("gpiolib: Defer failed gpio requests by default")
> > > the gpio subsystem started returning -EPROBE_DEFER, which in turn
> > > several platform drivers using platform_driver_probe return to driver
> > > core. Other subsystems (e.g. regulator) has since started doing the
> > > same.
> > > 
> > > The first patch in this series prevents platform drivers using
> > > platform_driver_probe from requesting probe deferral while warning that
> > > it is not supported.
> > > 
> > > The remaining patches move six platform-driver probe functions that rely
> > > on gpio_request out of __init. There are likely other probe functions
> > > that might return -EPROBE_DEFER and should be moved out of __init as
> > > well.
> > 
> > As usually when I read this I wonder why platform_driver_probe exists
> > anyway. The only advantage I can think off is that the probe functions
> > are in __init and thus can be disposed of later. Now you remove the
> > __init annotations from these probe functions. Wouldn't it be better to
> > convert the drivers to regular platform_driver_register instead?
> 
> Perhaps that paragraph was a bit unclear: I move them out of __init
> _and_ use platform_driver_register instead of platform_driver_probe as
> well.

Oh yes, I should have looked closer. Sorry for the noise.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 01/11] usb: chipidea: Add power management support

2013-10-14 Thread Sascha Hauer
On Mon, Oct 14, 2013 at 03:55:48PM +0800, Peter Chen wrote:
> On Mon, Oct 14, 2013 at 10:04:58AM +0200, Lothar Waßmann wrote:
> > Hi,
> > 
> > Peter Chen wrote:
> > > This commit adds runtime and system power management support for
> > > chipidea core. The runtime pm support is controlled by glue
> > > layer, it can be enabled by flag CI_HDRC_SUPPORTS_RUNTIME_PM.
> > > 
> > [...]
> > > +#ifdef CONFIG_PM
> > > +static int ci_controller_suspend(struct device *dev)
> > > +{
> > > + struct ci_hdrc *ci = dev_get_drvdata(dev);
> > > +
> > > + dev_dbg(dev, "at %s\n", __func__);
> > > +
> > > + if (atomic_read(&ci->in_lpm))
> > > + return 0;
> > > +
> > What does this 'atomic_read()' buy you over just testing/assinging a
> > simple integer. Note that just because the function has 'atomic' in
> > its name the sequence:
> > atomic_read();
> > ...
> > atomic_set();
> > does not magically become an atomic operation.
> 
> I just want the read and set are atomic, not the operations
> between atomic_read and atomic_set.

It makes no sense to use atomic operations here. atomic types are to
atomically read/modify/write variables. If all you ever do is
atomic_read and atomic_set then you can use a simple bool variable.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 01/11] usb: chipidea: Add power management support

2013-10-14 Thread Sascha Hauer
On Mon, Oct 14, 2013 at 05:04:21PM +0800, Peter Chen wrote:
> On Mon, Oct 14, 2013 at 10:42:16AM +0200, Sascha Hauer wrote:
> > On Mon, Oct 14, 2013 at 03:55:48PM +0800, Peter Chen wrote:
> > > On Mon, Oct 14, 2013 at 10:04:58AM +0200, Lothar Waßmann wrote:
> > > > Hi,
> > > > 
> > > > Peter Chen wrote:
> > > > > This commit adds runtime and system power management support for
> > > > > chipidea core. The runtime pm support is controlled by glue
> > > > > layer, it can be enabled by flag CI_HDRC_SUPPORTS_RUNTIME_PM.
> > > > > 
> > > > [...]
> > > > > +#ifdef CONFIG_PM
> > > > > +static int ci_controller_suspend(struct device *dev)
> > > > > +{
> > > > > + struct ci_hdrc *ci = dev_get_drvdata(dev);
> > > > > +
> > > > > + dev_dbg(dev, "at %s\n", __func__);
> > > > > +
> > > > > + if (atomic_read(&ci->in_lpm))
> > > > > + return 0;
> > > > > +
> > > > What does this 'atomic_read()' buy you over just testing/assinging a
> > > > simple integer. Note that just because the function has 'atomic' in
> > > > its name the sequence:
> > > > atomic_read();
> > > > ...
> > > > atomic_set();
> > > > does not magically become an atomic operation.
> > > 
> > > I just want the read and set are atomic, not the operations
> > > between atomic_read and atomic_set.
> > 
> > It makes no sense to use atomic operations here. atomic types are to
> > atomically read/modify/write variables. If all you ever do is
> > atomic_read and atomic_set then you can use a simple bool variable.
> > 
> 
> It is for ARM, but for other platforms, it may not.

It is for other platforms aswell. Otherwise the kernel would break into
pieces.

You only need atomic ops when you want to atomically read/modify/write a
variable.

Sascha


-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v6 1/3] USB: chipidea: add imx usbmisc support

2012-08-29 Thread Sascha Hauer
On Wed, Aug 29, 2012 at 10:50:08AM +0300, Alexander Shishkin wrote:
> Richard Zhao  writes:
> 
> > i.MX usb controllers shares non-core registers, which may include
> > SoC specific controls. We take it as a usbmisc device and usbmisc
> > driver set operations needed by ci13xxx_imx driver.
> >
> > For example, Sabrelite board has bad over-current design, we can
> > usbmisc to disable over-current detect.
> 
> Why does this have to be part of the usb driver instead of SoC specific
> code? It looks like you've created a whole new device/driver
> infrastructure just to disable overcurrent for a specific board.

Richards code indeed only handles overcurrent for a specific board, but
there are more bits to configure in the longer run: power pin
polarities, ULPI/serial mode select and some more.

> 
> And the infrastructure boils down to a complex way of passing a callback
> from imx driver to another imx driver, that only works if they are
> probed in the right order. I don't see any point in doing it like this
> other than inflating the device tree tables even further.
> 
> Why can't this be part of the SoC code like it is done, for example in
> arch/arm/mach-omap2/control.c?

The settings are board specific, so there must be some way to configure
them in the devicetree.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v6 1/3] USB: chipidea: add imx usbmisc support

2012-08-29 Thread Sascha Hauer
On Wed, Aug 29, 2012 at 01:18:10PM +0300, Alexander Shishkin wrote:
> Sascha Hauer  writes:
> 
> > On Wed, Aug 29, 2012 at 10:50:08AM +0300, Alexander Shishkin wrote:
> >> Richard Zhao  writes:
> >> 
> >> > i.MX usb controllers shares non-core registers, which may include
> >> > SoC specific controls. We take it as a usbmisc device and usbmisc
> >> > driver set operations needed by ci13xxx_imx driver.
> >> >
> >> > For example, Sabrelite board has bad over-current design, we can
> >> > usbmisc to disable over-current detect.
> >> 
> >> Why does this have to be part of the usb driver instead of SoC specific
> >> code? It looks like you've created a whole new device/driver
> >> infrastructure just to disable overcurrent for a specific board.
> >
> > Richards code indeed only handles overcurrent for a specific board, but
> > there are more bits to configure in the longer run: power pin
> > polarities, ULPI/serial mode select and some more.
> 
> Sounds to me like these things that should be taken care of by the phy
> driver, which will likely be simpler from both driver's and devicetree's
> perspective.

Most i.MX SoCs have three instances of the chipidea core. These cores
share a single register space for controlling the mentioned bits (the
usbmisc register space). The usbmisc looks different on the different
SoCs.
Indeed they control some phy specific aspects, but the phy itself may
also be an external ULPI or UTMI phy with a separate driver. So if we
integrate the usbmisc into the phy wouldn't that mean that it has to
be integrated into all possible phy drivers?

>From a devicetrees perspective it makes sense to integrate the flags
into the chipidea nodes, because there is one node per chipidea core,
but only one usbmisc unit for all ports on the SoC. So we can do a:

chipidea@ofs {
disable-overcurrent = <1>;
};

instead of

usbmisc@ofs {
disable-overcurrent-port0 = <1>;
disable-overcurrent-port1 = <0>;
...
};

> 
> >
> >> 
> >> And the infrastructure boils down to a complex way of passing a callback
> >> from imx driver to another imx driver, that only works if they are
> >> probed in the right order. I don't see any point in doing it like this
> >> other than inflating the device tree tables even further.
> >> 
> >> Why can't this be part of the SoC code like it is done, for example in
> >> arch/arm/mach-omap2/control.c?
> >
> > The settings are board specific, so there must be some way to configure
> > them in the devicetree.
> 
> But I'm sure there's a way to control board-specific settings/kludges
> from devicetree?

Hm, yes. That's what Richard does, right? I may be misunderstanding you
here.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH RFC] USB: EHCI on imx53

2012-09-03 Thread Sascha Hauer
Hi Roland,

On Mon, Sep 03, 2012 at 04:27:57PM +0200, Roland Stigge wrote:
> Hi,
> 
> this is my first try on activating EHCI on imx53 (primarily via dt). However,
> probe() still hangs on the first ehci_writel() l.189. I guess some
> clock/enabling is still missing?
> 
> Sascha, do you already have EHCI running on imx53?

I'm sorry to say that you are sitting on a dead end. Please google for
chipidea, Richard Zhao, Marc Kleine-Budde. They are regularly dropping
large patch bombs on linux-usb. I have no idea how to merge the patches
together to some working state. Maybe Marc can give you a pointer.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 00/34] i.MX multi-platform support

2012-09-17 Thread Sascha Hauer
Hi Shawn,

On Mon, Sep 17, 2012 at 01:34:29PM +0800, Shawn Guo wrote:
> The series enables multi-platform support for imx.  Since the required
> frameworks (clk, pwm) and spare_irq have already been adopted on imx,
> the series is all about cleaning up mach/* headers.  Along with the
> changes, arch/arm/plat-mxc gets merged into arch/arm/mach-imx.
> 
> It's based on a bunch of branches (works from others), Rob's initial
> multi-platform series, Arnd's platform-data and smp_ops (Marc's) and
> imx 3.7 material (Sascha and myself).
> 
> It's available on branch below.
> 
>   git://git.linaro.org/people/shawnguo/linux-2.6.git imx/multi-platform
> 
> It's been tested on imx5 and imx6, and only compile-tested on imx2 and
> imx3, so testing on imx2/3 are appreciated.

Great work! This really pushes the i.MX architecture one step closer to
a clean code base.

I gave it a test on i.MX1, i.MX27, i.MX31 and i.MX35. All run fine, but
the last patch breaks the imx_v4_v5_defconfig: Somehow it now defaults
to ARMv7 based machines. I haven't looked into it, just reenabled
ARMv4/ARMv5 and the boards again -> works. The config should be updated
with the last patch.

I'm fine with the changes to mx2-camera, but Javier should give his ok
to it, he has worked on it quite a lot recently.

One other issue related to imx-dma, see comment to that patch.

Otherwise:

Acked-by: Sascha Hauer 
Tested-by: Sascha Hauer 

Thanks
 Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 00/34] i.MX multi-platform support

2012-09-18 Thread Sascha Hauer
Hi Shawn,

On Mon, Sep 17, 2012 at 01:34:29PM +0800, Shawn Guo wrote:
> The series enables multi-platform support for imx.  Since the required
> frameworks (clk, pwm) and spare_irq have already been adopted on imx,
> the series is all about cleaning up mach/* headers.  Along with the
> changes, arch/arm/plat-mxc gets merged into arch/arm/mach-imx.
> 
> It's based on a bunch of branches (works from others), Rob's initial
> multi-platform series, Arnd's platform-data and smp_ops (Marc's) and
> imx 3.7 material (Sascha and myself).
> 
> It's available on branch below.
> 
>   git://git.linaro.org/people/shawnguo/linux-2.6.git imx/multi-platform
> 
> It's been tested on imx5 and imx6, and only compile-tested on imx2 and
> imx3, so testing on imx2/3 are appreciated.
> 
> Subsystem maintainers,
> 
> I plan to send the whole series via arm-soc tree at the end of 3.7
> merge window when all dependant bits hit mainline.  Please have a
> look at the patches you get copied and provide ACKs if the changes
> are good.  Thanks.

I just had a look at the remaining initcalls in arch-imx. Most of them
are protected with a cpu_is_*, but this one should be fixed before i.MX
is enabled for multi platform:

arch/arm/mach-imx/devices/devices.c:48:core_initcall(mxc_device_init);

I think this won't harm others directly, but it will register i.MX
related devices on foreign platforms.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 0/7] update USB gadget driver fsl-usb2-udc

2012-10-19 Thread Sascha Hauer
Hi Christoph,

What system are you working on? If it's i.MX you should use/work on the
chipidea driver instead.

Sascha

On Fri, Oct 19, 2012 at 12:22:36PM +0200, Christoph Fritz wrote:
> This series updates USB gadget driver fsl-usb2-udc.
> 
> Christoph Fritz (7):
>   usb: gadget: fsl_udc: simplify driver init
>   usb: gadget: fsl_udc: protect fsl_pullup() with spin_lock
>   usb: gadget: fsl_udc: convert to new ulc style
>   usb: gadget: fsl_udc: drop ARCH dependency
>   usb: gadget: fsl_udc: postpone freeing current dTD
>   usb: gadget: fsl_udc: purge global pointer usb_sys_regs
>   usb: gadget: fsl_udc: purge global pointer dr_regs
> 
>  drivers/usb/gadget/fsl_udc_core.c |  755 
> -
>  drivers/usb/gadget/fsl_usb2_udc.h |4 +
>  2 files changed, 322 insertions(+), 437 deletions(-)
> 
> -- 
> 1.7.2.5
> 
> 

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v12 02/13] usb: chipidea: imx: remove vbus regulator operation

2013-07-10 Thread Sascha Hauer
On Thu, Jul 11, 2013 at 02:27:10PM +0800, Peter Chen wrote:
> Since we have added vbus reguatlor operation at common
> host file (chipidea/host.c), the glue layer vbus operation
> isn't needed any more.
> 
> Signed-off-by: Peter Chen 
> ---
>  drivers/usb/chipidea/ci_hdrc_imx.c |   30 +++---
>  1 files changed, 7 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c 
> b/drivers/usb/chipidea/ci_hdrc_imx.c
> index 14362c0..d06355e 100644
> --- a/drivers/usb/chipidea/ci_hdrc_imx.c
> +++ b/drivers/usb/chipidea/ci_hdrc_imx.c
> @@ -31,7 +31,6 @@ struct ci_hdrc_imx_data {
>   struct usb_phy *phy;
>   struct platform_device *ci_pdev;
>   struct clk *clk;
> - struct regulator *reg_vbus;
>  };
>  
>  static const struct usbmisc_ops *usbmisc_ops;
> @@ -141,22 +140,13 @@ static int ci_hdrc_imx_probe(struct platform_device 
> *pdev)
>   goto err_clk;
>   }
>  
> - /* we only support host now, so enable vbus here */
> - data->reg_vbus = devm_regulator_get(&pdev->dev, "vbus");
> - if (!IS_ERR(data->reg_vbus)) {
> - ret = regulator_enable(data->reg_vbus);
> - if (ret) {
> - dev_err(&pdev->dev,
> - "Failed to enable vbus regulator, err=%d\n",
> - ret);
> - goto err_clk;
> - }
> - } else {
> - data->reg_vbus = NULL;
> - }
> -
>   pdata.phy = data->phy;
>  
> + /* Get the vbus regulator */
> + pdata.reg_vbus = devm_regulator_get(&pdev->dev, "vbus");
> + if (IS_ERR(pdata.reg_vbus))
> + pdata.reg_vbus = NULL;

I think you should bail out at least in the -EPROBE_DEFER case.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 01/15] drivers: phy: add generic PHY framework

2013-07-21 Thread Sascha Hauer
On Sat, Jul 20, 2013 at 07:59:10PM -0700, Greg KH wrote:
> On Sat, Jul 20, 2013 at 10:32:26PM -0400, Alan Stern wrote:
> > On Sat, 20 Jul 2013, Greg KH wrote:
> > 
> > > > >>That should be passed using platform data.
> > > > >
> > > > >Ick, don't pass strings around, pass pointers.  If you have platform
> > > > >data you can get to, then put the pointer there, don't use a "name".
> > > > 
> > > > I don't think I understood you here :-s We wont have phy pointer
> > > > when we create the device for the controller no?(it'll be done in
> > > > board file). Probably I'm missing something.
> > > 
> > > Why will you not have that pointer?  You can't rely on the "name" as the
> > > device id will not match up, so you should be able to rely on the
> > > pointer being in the structure that the board sets up, right?
> > > 
> > > Don't use names, especially as ids can, and will, change, that is going
> > > to cause big problems.  Use pointers, this is C, we are supposed to be
> > > doing that :)
> > 
> > Kishon, I think what Greg means is this:  The name you are using must
> > be stored somewhere in a data structure constructed by the board file,
> > right?  Or at least, associated with some data structure somehow.  
> > Otherwise the platform code wouldn't know which PHY hardware
> > corresponded to a particular name.
> > 
> > Greg's suggestion is that you store the address of that data structure 
> > in the platform data instead of storing the name string.  Have the 
> > consumer pass the data structure's address when it calls phy_create, 
> > instead of passing the name.  Then you don't have to worry about two 
> > PHYs accidentally ending up with the same name or any other similar 
> > problems.
> 
> Close, but the issue is that whatever returns from phy_create() should
> then be used, no need to call any "find" functions, as you can just use
> the pointer that phy_create() returns.  Much like all other class api
> functions in the kernel work.

I think the problem here is to connect two from the bus structure
completely independent devices. Several frameworks (ASoC, soc-camera)
had this problem and this wasn't solved until the advent of devicetrees
and their phandles.
phy_create might be called from the probe function of some i2c device
(the phy device) and the resulting pointer is then needed in some other
platform devices (the user of the phy) probe function.
The best solution we have right now is implemented in the clk framework
which uses a string matching of the device names in clk_get() (at least
in the non-dt case).

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/1] usb: chipidea: imx: include usbmisc_imx.c in ci_hdrc_imx.c

2013-08-07 Thread Sascha Hauer
On Wed, Aug 07, 2013 at 01:34:37PM +0800, Peter Chen wrote:
> At former design, both ci_hdrc_imx and usbmisc_imx are individual
> module, ci_hdrc_imx is glue layer for imx usb driver. usbmisc_imx
> handles non-core registers which has different register layout
> for imx SoC serials, it usually supplies interface for wakeup
> setting, PHY setting, etc.
> 
> usbmisc_imx uses symbols from ci_hdrc_imx, So, when we combile both
> of drivers as loadable module, usbmisc is needed to be unload first.
> However at ci_hdrc_imx, it needs to call usbmisc_imx's interface
> at its removal function once we enable wakeup/runtime pm function, so
> keeping two drivers can't work well at loadable module use case.
> 
> To fix loadable module use case, we need to build usbmisc_imx into
> ci_hdrc_imx. The usbmisc_imx still handles misc setting for controllers,
> and will be included at ci_hdrc_imx.
> 
> There is a short discussion for it:
> http://marc.info/?l=linux-usb&m=136861599423172&w=2
> 
> Besides, we update dts and binding doc for at this commit

This patch does far too many things at once.

- Convert imx-usb-misc from a driver into something which is called
  directly
- add aliases
- change devicetree bindings (which causes pain and it's not explained why
  this is necessary at all)
- converts the misc stuff to regmap

Please split this up so that it can be reviewed.

>  
>  #include "ci.h"
>  #include "ci_hdrc_imx.h"
> +#include "usbmisc_imx.c"

Don't include C files.

> - ret);
> - memset(usbdev, 0, sizeof(*usbdev));
> + ret = of_alias_get_id(np, "usb");
> + if (ret < 0) {
> + dev_err(dev, "failed to get alias id, errno %d\n", ret);
>   return ret;
>   }
> - usbdev->index = args.args[0];
> - of_node_put(args.np);
>  
>   if (of_find_property(np, "disable-over-current", NULL))
> - usbdev->disable_oc = 1;
> + data->disable_oc = 1;
>  
>   if (of_find_property(np, "external-vbus-divider", NULL))
> - usbdev->evdo = 1;
> + data->evdo = 1;
> +
> + /* mx23 and mx28 doesn't have non core registers */
> + if (data->misc_data && (!strcmp(data->misc_data->name, "imx23-usb") ||
> + !strcmp(data->misc_data->name, "imx28-usb")))
> + return 0;

If a USB node does not have a usbmisc (or noncore) property then don't
initialize it. No need for string compares.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/1] usb: chipidea: imx: include usbmisc_imx.c in ci_hdrc_imx.c

2013-08-07 Thread Sascha Hauer
On Wed, Aug 07, 2013 at 03:00:05PM +0800, Peter Chen wrote:
> On Wed, Aug 07, 2013 at 10:15:22AM +0200, Sascha Hauer wrote:
> > On Wed, Aug 07, 2013 at 01:34:37PM +0800, Peter Chen wrote:
> > > At former design, both ci_hdrc_imx and usbmisc_imx are individual
> > > module, ci_hdrc_imx is glue layer for imx usb driver. usbmisc_imx
> > > handles non-core registers which has different register layout
> > > for imx SoC serials, it usually supplies interface for wakeup
> > > setting, PHY setting, etc.
> > > 
> > > usbmisc_imx uses symbols from ci_hdrc_imx, So, when we combile both
> > > of drivers as loadable module, usbmisc is needed to be unload first.
> > > However at ci_hdrc_imx, it needs to call usbmisc_imx's interface
> > > at its removal function once we enable wakeup/runtime pm function, so
> > > keeping two drivers can't work well at loadable module use case.
> > > 
> > > To fix loadable module use case, we need to build usbmisc_imx into
> > > ci_hdrc_imx. The usbmisc_imx still handles misc setting for controllers,
> > > and will be included at ci_hdrc_imx.
> > > 
> > > There is a short discussion for it:
> > > http://marc.info/?l=linux-usb&m=136861599423172&w=2
> > > 
> > > Besides, we update dts and binding doc for at this commit
> > 
> > This patch does far too many things at once.
> > 
> > - Convert imx-usb-misc from a driver into something which is called
> >   directly
> > - add aliases
> > - change devicetree bindings (which causes pain and it's not explained why
> >   this is necessary at all)
> 
> Yes, I need to split doc from implementation.

No, you don't. You just have to explain *why* the bindings need to be
chaged.

> 
> > - converts the misc stuff to regmap
> > 
> > Please split this up so that it can be reviewed.
> 
> The changes are all related to convert usbmisc_imx from a driver to something
> which can be called directly.
> 
> - usbmisc has #index-cells to indicate controller number, now, it is not
> a driver, we use aliases at controller driver to instead of it.

Why?

> - When usbmisc_imx is a device, the register maps only one time.
> But ci_hdrc_imx will be several devices, the non-core register
> will be mapped several times, we have to use syscon to visit one register
> region among several devices.

Converting the imx-usb misc driver to regmap is fine, but I see no
reason to not make this a separate patch. This would make this much
easier to read.

> 
> 
> > 
> > >  
> > >  #include "ci.h"
> > >  #include "ci_hdrc_imx.h"
> > > +#include "usbmisc_imx.c"
> > 
> > Don't include C files.
> > 
> 
> Yes, it is not a good practice, but I want to keep ci_hdrc_imx.c
> as clean as possible. The SoC related implementation will be more
> and more in the future after we add more USB functions.

Just because you want to have the binary code in a single module doesn't
mean the source code has to be in a single C file.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/1] usb: chipidea: imx: include usbmisc_imx.c in ci_hdrc_imx.c

2013-08-07 Thread Sascha Hauer
On Wed, Aug 07, 2013 at 01:34:37PM +0800, Peter Chen wrote:
> -
> - reg = usbmisc->base + MX25_USB_PHY_CTRL_OFFSET;
> -
> - if (usbdev->evdo) {
> - spin_lock_irqsave(&usbmisc->lock, flags);
> - val = readl(reg);
> - writel(val | MX25_BM_EXTERNAL_VBUS_DIVIDER, reg);
> - spin_unlock_irqrestore(&usbmisc->lock, flags);
> + if (data->evdo) {
> + spin_lock_irqsave(&data->lock, flags);
> + regmap_read(data->non_core_base_addr,
> + MX25_USB_PHY_CTRL_OFFSET, &val);
> + regmap_write(data->non_core_base_addr,
> + MX25_USB_PHY_CTRL_OFFSET,
> + val | MX25_BM_EXTERNAL_VBUS_DIVIDER);
> + spin_unlock_irqrestore(&data->lock, flags);

Have a look at regmap_update_bits. You won't need this spinlock anymore.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/1] usb: chipidea: imx: include usbmisc_imx.c in ci_hdrc_imx.c

2013-08-07 Thread Sascha Hauer
On Wed, Aug 07, 2013 at 03:54:06PM +0800, Peter Chen wrote:
> On Wed, Aug 07, 2013 at 11:08:45AM +0200, Sascha Hauer wrote:
> > > > 
> > > > - Convert imx-usb-misc from a driver into something which is called
> > > >   directly
> > > > - add aliases
> > > > - change devicetree bindings (which causes pain and it's not explained 
> > > > why
> > > >   this is necessary at all)
> > > 
> > > Yes, I need to split doc from implementation.
> > 
> > No, you don't. You just have to explain *why* the bindings need to be
> > chaged.
> > 
> 
> OK, I will
> 
> > > 
> > > > - converts the misc stuff to regmap
> > > > 
> > > > Please split this up so that it can be reviewed.
> > > 
> > > The changes are all related to convert usbmisc_imx from a driver to 
> > > something
> > > which can be called directly.
> > > 
> > > - usbmisc has #index-cells to indicate controller number, now, it is not
> > > a driver, we use aliases at controller driver to instead of it.
> > 
> > Why?
> > 
> 
> We need to know controller number, like pdev->id in the past.
> The registers at non core register is messy, the specific bit
> is for specific controller.

The controller number is present in the old binding:

fsl,usbmisc = <&usbmisc 1>;
   ^^^

Merging the usbmisc stuff into the imx driver shouldn't be a reason to
change this binding.

Please get used to the fact that dt bindings cannot be changed easily
just because the newer binding looks nicer. They define an ABI and
breaking this ABI causes pain.

> 
> > > - When usbmisc_imx is a device, the register maps only one time.
> > > But ci_hdrc_imx will be several devices, the non-core register
> > > will be mapped several times, we have to use syscon to visit one register
> > > region among several devices.
> > 
> > Converting the imx-usb misc driver to regmap is fine, but I see no
> > reason to not make this a separate patch. This would make this much
> > easier to read.
> 
> You mean delete "reg" entry at usbmisc dts, and using noncore phandle
> at usbmisc_imx.c as the first patch, then, convert driver as separate
> file.

I mean: create a patch which converts the usbmisc driver to regmap and
base your other stuff on this patch.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/1] usb: chipidea: imx: include usbmisc_imx.c in ci_hdrc_imx.c

2013-08-07 Thread Sascha Hauer
On Wed, Aug 07, 2013 at 01:34:37PM +0800, Peter Chen wrote:
> diff --git a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt 
> b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
> index b4b5b79..13720a2 100644
> --- a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
> +++ b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
> @@ -13,8 +13,8 @@ Recommended properies:
>  
>  Optional properties:
>  - fsl,usbphy: phandler of usb phy that connects to the only one port
> -- fsl,usbmisc: phandler of non-core register device, with one argument
> -  that indicate usb controller index
> +- ci,noncore: phandler of non-core register device, the user must enable
> +syscon driver to use it

Don't add Linux specifics to the binding documentation. The bindings are
supposed to be OS agnostic.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/1] usb: chipidea: imx: include usbmisc_imx.c in ci_hdrc_imx.c

2013-08-07 Thread Sascha Hauer
On Wed, Aug 07, 2013 at 05:24:45PM +0800, Peter Chen wrote:
> On Wed, Aug 07, 2013 at 12:05:07PM +0200, Sascha Hauer wrote:
> > > 
> > > We need to know controller number, like pdev->id in the past.
> > > The registers at non core register is messy, the specific bit
> > > is for specific controller.
> > 
> > The controller number is present in the old binding:
> > 
> > fsl,usbmisc = <&usbmisc 1>;
> >^^^
> > 
> > Merging the usbmisc stuff into the imx driver shouldn't be a reason to
> > change this binding.
> > 
> > Please get used to the fact that dt bindings cannot be changed easily
> > just because the newer binding looks nicer. They define an ABI and
> > breaking this ABI causes pain.
> > 
> 
> But current situation is the device node of "usbmisc" will not be needed.

If it's really not needed then you could remove it.

> The usbmisc will not be a driver.

Not true. It's still a driver, just one that happens to be not
compilable as module: syscon

> We only need usbmisc to supply kinds
> of SoC specific implementations, as well as filling the content of the data
> at struct of_device_id (imx-usb's).

Yes, that's the purpose of usbmisc and ever has been.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 5/5] arm: dts: imx: Delete usbmisc_imx

2013-08-08 Thread Sascha Hauer
On Thu, Aug 08, 2013 at 03:33:01PM +0800, Peter Chen wrote:
> Since ci_hdrc_imx and usbmisc_imx has relationship between each other,
> they can't be existed as two modules. We change the code, and make
> the usbmisc_imx has no longer a driver.
> 
> Due to above reason, we introduce non core register phandle to know
> the non core register, and delete the binding doc from usbmisc_imx as well.
> 
> Signed-off-by: Peter Chen 
> ---
>  .../devicetree/bindings/usb/ci_hdrc_imx.txt|   12 
>  .../devicetree/bindings/usb/usbmisc-imx.txt|   14 --
>  arch/arm/boot/dts/imx25.dtsi   |   14 +-
>  arch/arm/boot/dts/imx51.dtsi   |   16 +++-
>  arch/arm/boot/dts/imx53.dtsi   |   16 +++-
>  arch/arm/boot/dts/imx6qdl.dtsi |   16 +++-
>  6 files changed, 34 insertions(+), 54 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/usb/ci_hdrc_imx.txt 
> b/Documentation/devicetree/bindings/usb/ci_hdrc_imx.txt
> index b4b5b79..56d94cb 100644
> --- a/Documentation/devicetree/bindings/usb/ci_hdrc_imx.txt
> +++ b/Documentation/devicetree/bindings/usb/ci_hdrc_imx.txt
> @@ -1,4 +1,4 @@
> -* Freescale i.MX ci13xxx usb controllers
> +* Freescale i.MX chipidea usb controllers
>  
>  Required properties:
>  - compatible: Should be "fsl,imx27-usb"
> @@ -13,8 +13,7 @@ Recommended properies:
>  
>  Optional properties:
>  - fsl,usbphy: phandler of usb phy that connects to the only one port
> -- fsl,usbmisc: phandler of non-core register device, with one argument
> -  that indicate usb controller index
> +- ci,noncore: phandler of non-core register node
>  - vbus-supply: regulator for vbus
>  - disable-over-current: disable over current detect
>  - external-vbus-divider: enables off-chip resistor divider for Vbus
> @@ -25,7 +24,12 @@ usb@02184000 { /* USB OTG */
>   reg = <0x02184000 0x200>;
>   interrupts = <0 43 0x04>;
>   fsl,usbphy = <&usbphy1>;
> - fsl,usbmisc = <&usbmisc 0>;
> + ci,noncore = <&noncore>;
>   disable-over-current;
>   external-vbus-divider;
>  };
> +
> +noncore: usb-non-core@02184800 {
> +  compatible = "fsl,imx-usb-non-core", "syscon";
> +  reg = <0x02184800 0x200>;
> +};
> diff --git a/Documentation/devicetree/bindings/usb/usbmisc-imx.txt 
> b/Documentation/devicetree/bindings/usb/usbmisc-imx.txt
> deleted file mode 100644
> index 97ce94e..000
> --- a/Documentation/devicetree/bindings/usb/usbmisc-imx.txt
> +++ /dev/null
> @@ -1,14 +0,0 @@
> -* Freescale i.MX non-core registers
> -
> -Required properties:
> -- #index-cells: Cells used to descibe usb controller index. Should be <1>
> -- compatible: Should be one of below:
> - "fsl,imx6q-usbmisc" for imx6q
> -- reg: Should contain registers location and length
> -
> -Examples:
> -usbmisc@02184800 {
> - #index-cells = <1>;
> - compatible = "fsl,imx6q-usbmisc";
> - reg = <0x02184800 0x200>;
> -};
> diff --git a/arch/arm/boot/dts/imx25.dtsi b/arch/arm/boot/dts/imx25.dtsi
> index 7011539..a09251b 100644
> --- a/arch/arm/boot/dts/imx25.dtsi
> +++ b/arch/arm/boot/dts/imx25.dtsi
> @@ -460,7 +460,7 @@
>   interrupts = <37>;
>   clocks = <&clks 9>, <&clks 70>, <&clks 8>;
>   clock-names = "ipg", "ahb", "per";
> - fsl,usbmisc = <&usbmisc 0>;
> + ci,noncore = <&noncore>;
>   status = "disabled";
>   };
>  
> @@ -470,17 +470,13 @@
>   interrupts = <35>;
>   clocks = <&clks 9>, <&clks 70>, <&clks 8>;
>   clock-names = "ipg", "ahb", "per";
> - fsl,usbmisc = <&usbmisc 1>;
> + ci,noncore = <&noncore>;
>   status = "disabled";
>   };
>  
> - usbmisc: usbmisc@53ff4600 {
> - #index-cells = <1>;
> - compatible = "fsl,imx25-usbmisc";
> - clocks = <&clks 9>, <&clks 70>, <&clks 8>;
> - clock-names = "ipg", "ahb", "per";
> - reg = <0x53ff4600 0x00f>;
> - status = "disabled";
> + noncore: usb-non-core@53ff4600 {
> +  compatible = "fsl,imx-usb-non-core", "syscon";
> +  reg = <0x53ff4600 0xf>;
>   };

This is bullshit for multiple reasons.

It's the usbmisc unit that changes between different SoCs, not the
chipidea core. So pretending the usbmisc unit is generic by removing the
SoC specific compatible and instead leaking in the SoC type from the
chipidea device nodes is just crazy.

What you are doing here is to model the 

Re: [PATCH 12/12] USB: chipidea: add imx usbmisc support

2012-07-16 Thread Sascha Hauer
On Thu, Jul 12, 2012 at 03:01:52PM +0800, Richard Zhao wrote:
> i.MX usb controllers shares non-core registers, which may include
> SoC specific controls. We take it as a usbmisc device and usbmisc
> driver export functions needed by ci13xxx_imx driver.
> 
> For example, Sabrelite board has bad over-current design, we can
> usbmisc to disable over-current detect.
> 
> Signed-off-by: Richard Zhao 
> ---
>  .../devicetree/bindings/usb/imx-usbmisc.txt|   15 ++
>  drivers/usb/chipidea/Makefile  |2 +-
>  drivers/usb/chipidea/ci13xxx_imx.c |4 +
>  drivers/usb/chipidea/imx_usbmisc.c |  144 
> 
>  4 files changed, 164 insertions(+), 1 deletion(-)
>  create mode 100644 Documentation/devicetree/bindings/usb/imx-usbmisc.txt
>  create mode 100644 drivers/usb/chipidea/imx_usbmisc.c
> 
> diff --git a/Documentation/devicetree/bindings/usb/imx-usbmisc.txt 
> b/Documentation/devicetree/bindings/usb/imx-usbmisc.txt
> new file mode 100644
> index 000..09f01ca
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/usb/imx-usbmisc.txt
> @@ -0,0 +1,15 @@
> +* Freescale i.MX non-core registers
> +
> +Required properties:
> +- compatible: Should be "fsl,imx6q-usbmisc"
> +- reg: Should contain registers location and length
> +
> +Optional properties:
> +- fsl,disable-over-current: disable over current detect
> +
> +Examples:
> +usbmisc@02184800 {
> + compatible = "fsl,imx6q-usbmisc";
> + reg = <0x02184800 0x200>;
> + fsl,disable-over-current;
> +};
> diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile
> index 3f56b76..46fc31c 100644
> --- a/drivers/usb/chipidea/Makefile
> +++ b/drivers/usb/chipidea/Makefile
> @@ -17,5 +17,5 @@ ifneq ($(CONFIG_PCI),)
>  endif
>  
>  ifneq ($(CONFIG_OF_DEVICE),)
> - obj-$(CONFIG_USB_CHIPIDEA)  += ci13xxx_imx.o
> + obj-$(CONFIG_USB_CHIPIDEA)  += ci13xxx_imx.o imx_usbmisc.o
>  endif
> diff --git a/drivers/usb/chipidea/ci13xxx_imx.c 
> b/drivers/usb/chipidea/ci13xxx_imx.c
> index b3173d8..dd7f3a3 100644
> --- a/drivers/usb/chipidea/ci13xxx_imx.c
> +++ b/drivers/usb/chipidea/ci13xxx_imx.c
> @@ -24,6 +24,8 @@
>  
>  #include "ci.h"
>  
> +int imx_usbmisc_init(struct device *usbdev);
> +
>  #define pdev_to_phy(pdev) \
>   ((struct usb_phy *)platform_get_drvdata(pdev))
>  #define ci_to_imx_data(ci) \
> @@ -142,6 +144,8 @@ static int __devinit ci13xxx_imx_probe(struct 
> platform_device *pdev)
>   dma_set_coherent_mask(&pdev->dev, *pdev->dev.dma_mask);
>   }
>  
> + imx_usbmisc_init(&pdev->dev);
> +
>   platform_set_drvdata(pdev, data);
>  
>   plat_ci = ci13xxx_add_device(&pdev->dev,
> diff --git a/drivers/usb/chipidea/imx_usbmisc.c 
> b/drivers/usb/chipidea/imx_usbmisc.c
> new file mode 100644
> index 000..33a8ec0
> --- /dev/null
> +++ b/drivers/usb/chipidea/imx_usbmisc.c
> @@ -0,0 +1,144 @@
> +/*
> + * Copyright 2012 Freescale Semiconductor, Inc.
> + *
> + * The code contained herein is licensed under the GNU General Public
> + * License. You may obtain a copy of the GNU General Public License
> + * Version 2 or later at the following locations:
> + *
> + * http://www.opensource.org/licenses/gpl-license.html
> + * http://www.gnu.org/copyleft/gpl.html
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 

linux/io.h

> +
> +struct usbmisc;
> +
> +struct soc_data {
> + int (*init) (struct usbmisc *usbmisc, int id);
> + void (*exit) (struct usbmisc *usbmisc, int id);
> +};
> +
> +struct usbmisc {
> + struct soc_data *soc_data;
> + void __iomem *base;
> + struct clk *clk;
> +
> + int dis_oc:1;
> +};
> +
> +/* Since we only have one usbmisc device at runtime, we global variables */
> +static struct usbmisc *usbmisc;

NACK

What you've done here exactly matches your current usecase but is not
enough for any of the other usecases I can think of. Even the i.MX6 has
three USB ports, each of them has a overcurrent disable bit. Also, there
are more flags, like:

- use internal phy
- power pin polarity
- ttl enabled

I think the best you can do here is to add the flags to the
fsl,imx6q-usb device nodes:

usb@02184000 { /* USB OTG */
compatible = "fsl,imx6q-usb", "fsl,imx27-usb";
reg = <0x02184000 0x200>;
interrupts = <0 43 0x04>;
fsl,usbphy = <&usbphy1>;
status = "disabled";
fsl,disable-over-current;
;
};

Then add a usbmisc device which does not contain any flags. During
initialization of the fsl,imx6q-usb device you can then pass a pointer
to its device node to imx_usbmisc_init.

Sascha

-- 
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:   +

Re: [PATCH 12/12] USB: chipidea: add imx usbmisc support

2012-07-16 Thread Sascha Hauer
On Mon, Jul 16, 2012 at 04:38:38PM +0800, Richard Zhao wrote:
> > 
> > NACK
> Right, it's a bad design. I'm considering change it too. Maybe I will
> move it out this patch series. As I asked you in another mail in this
> thread, do you think it's good to put it here or in mach-imx/ ?

I prefer it to be in drivers/usb/chipidea.

> > 
> > What you've done here exactly matches your current usecase but is not
> > enough for any of the other usecases I can think of. Even the i.MX6 has
> > three USB ports, each of them has a overcurrent disable bit. Also, there
> > are more flags, like:
> Yes, I'll change it to support different usb with different properties.
> > 
> > - use internal phy
> > - power pin polarity
> > - ttl enabled
> I focus on imx6 now. So I think the property can be added when it's
> needed. Now I only use disable oc.

That's fine, but you should give the impression that you thought about
other usecases and other SoCs than your current one, it'll make it easier
for us to believe that your patch does the right thing ;)

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 1/2] USB: chipidea: add imx usbmisc support

2012-07-18 Thread Sascha Hauer
On Wed, Jul 18, 2012 at 06:29:06PM +0800, Richard Zhao wrote:
> i.MX usb controllers shares non-core registers, which may include
> SoC specific controls. We take it as a usbmisc device and usbmisc
> driver set operations needed by ci13xxx_imx driver.
> 
> For example, Sabrelite board has bad over-current design, we can
> usbmisc to disable over-current detect.
> 
> Signed-off-by: Richard Zhao 
> ---
>  .../devicetree/bindings/usb/ci13xxx-imx.txt|2 +
>  .../devicetree/bindings/usb/usbmisc-imx.txt|   12 ++
>  drivers/usb/chipidea/Makefile  |2 +-
>  drivers/usb/chipidea/ci13xxx_imx.c |   23 +++
>  drivers/usb/chipidea/usbmisc_imx6q.c   |  161 
> 
>  5 files changed, 199 insertions(+), 1 deletion(-)
>  create mode 100644 Documentation/devicetree/bindings/usb/usbmisc-imx.txt
>  create mode 100644 drivers/usb/chipidea/usbmisc_imx6q.c
> 
> diff --git a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt 
> b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
> index 2c29041..06105ce 100644
> --- a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
> +++ b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
> @@ -8,6 +8,7 @@ Required properties:
>  Optional properties:
>  - fsl,usbphy: phandler of usb phy that connects to the only one port
>  - vbus-supply: regulator for vbus
> +- disable-over-current: disable over current detect
>  
>  Examples:
>  usb@02184000 { /* USB OTG */
> @@ -15,4 +16,5 @@ usb@02184000 { /* USB OTG */
>   reg = <0x02184000 0x200>;
>   interrupts = <0 43 0x04>;
>   fsl,usbphy = <&usbphy1>;
> + disable-over-current;
>  };
> diff --git a/Documentation/devicetree/bindings/usb/usbmisc-imx.txt 
> b/Documentation/devicetree/bindings/usb/usbmisc-imx.txt
> new file mode 100644
> index 000..4fa500d
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/usb/usbmisc-imx.txt
> @@ -0,0 +1,12 @@
> +* Freescale i.MX non-core registers
> +
> +Required properties:
> +- compatible: Should be one of below:
> + "fsl,imx6q-usbmisc" for imx6q
> +- reg: Should contain registers location and length
> +
> +Examples:
> +usbmisc@02184800 {
> + compatible = "fsl,imx6q-usbmisc";
> + reg = <0x02184800 0x200>;
> +};
> diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile
> index 5c66d9c..57e510f 100644
> --- a/drivers/usb/chipidea/Makefile
> +++ b/drivers/usb/chipidea/Makefile
> @@ -15,5 +15,5 @@ ifneq ($(CONFIG_PCI),)
>  endif
>  
>  ifneq ($(CONFIG_OF_DEVICE),)
> - obj-$(CONFIG_USB_CHIPIDEA)  += ci13xxx_imx.o
> + obj-$(CONFIG_USB_CHIPIDEA)  += ci13xxx_imx.o usbmisc_imx6q.o
>  endif
> diff --git a/drivers/usb/chipidea/ci13xxx_imx.c 
> b/drivers/usb/chipidea/ci13xxx_imx.c
> index ef60d06..e790c0e 100644
> --- a/drivers/usb/chipidea/ci13xxx_imx.c
> +++ b/drivers/usb/chipidea/ci13xxx_imx.c
> @@ -22,6 +22,7 @@
>  #include 
>  
>  #include "ci.h"
> +#include "ci13xxx_imx.h"
>  
>  #define pdev_to_phy(pdev) \
>   ((struct usb_phy *)platform_get_drvdata(pdev))
> @@ -34,6 +35,25 @@ struct ci13xxx_imx_data {
>   struct regulator *reg_vbus;
>  };
>  
> +static const struct usbmisc_ops *usbmisc_ops;
> +
> +int usbmisc_set_ops(const struct usbmisc_ops *ops)
> +{
> + if (usbmisc_ops)
> + return -EBUSY;
> +
> + usbmisc_ops = ops;
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(usbmisc_set_ops);
> +
> +void usbmisc_unset_ops(const struct usbmisc_ops *ops)
> +{
> + usbmisc_ops = NULL;
> +}
> +EXPORT_SYMBOL_GPL(usbmisc_unset_ops);
> +
>  static struct ci13xxx_platform_data ci13xxx_imx_platdata __devinitdata  = {
>   .name   = "ci13xxx_imx",
>   .flags  = CI13XXX_REQUIRE_TRANSCEIVER |
> @@ -120,6 +140,9 @@ static int __devinit ci13xxx_imx_probe(struct 
> platform_device *pdev)
>   *pdev->dev.dma_mask = DMA_BIT_MASK(32);
>   dma_set_coherent_mask(&pdev->dev, *pdev->dev.dma_mask);
>   }
> +
> + usbmisc_ops->init(&pdev->dev);

usbmisc_ops can be NULL and also can return an error.

> +
>   plat_ci = ci13xxx_add_device(&pdev->dev,
>   pdev->resource, pdev->num_resources,
>   &ci13xxx_imx_platdata);
> diff --git a/drivers/usb/chipidea/usbmisc_imx6q.c 
> b/drivers/usb/chipidea/usbmisc_imx6q.c
> new file mode 100644
> index 000..9f69a8c
> --- /dev/null
> +++ b/drivers/usb/chipidea/usbmisc_imx6q.c
> @@ -0,0 +1,161 @@
> +/*
> + * Copyright 2012 Freescale Semiconductor, Inc.
> + *
> + * The code contained herein is licensed under the GNU General Public
> + * License. You may obtain a copy of the GNU General Public License
> + * Version 2 or later at the following locations:
> + *
> + * http://www.opensource.org/licenses/gpl-license.html
> + * http://www.gnu.org/copyleft/gpl.html
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "ci13xxx_imx.h"
> +
> +#define USB_DEV_MAX 

Re: [PATCH v2 2/2] ARM: dts: imx6q-sabrelite: add usbmisc device

2012-07-18 Thread Sascha Hauer
On Wed, Jul 18, 2012 at 06:29:07PM +0800, Richard Zhao wrote:
> Signed-off-by: Richard Zhao 
> ---
>  arch/arm/boot/dts/imx6q-sabrelite.dts |4 
>  arch/arm/boot/dts/imx6q.dtsi  |   19 +++
>  arch/arm/mach-imx/clk-imx6q.c |1 +
>  3 files changed, 20 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/arm/boot/dts/imx6q-sabrelite.dts 
> b/arch/arm/boot/dts/imx6q-sabrelite.dts
> index d42e851..c66ff9d 100644
> --- a/arch/arm/boot/dts/imx6q-sabrelite.dts
> +++ b/arch/arm/boot/dts/imx6q-sabrelite.dts
> @@ -62,12 +62,16 @@
>   aips-bus@0210 { /* AIPS2 */
>   usb@02184000 { /* USB OTG */
>   vbus-supply = <®_usb_otg_vbus>;
> + disable-over-current;
>   status = "okay";
>   };
>  
>   usb@02184200 { /* USB1 */
>   status = "okay";
>   };
> + usbmisc@02184800 {
> + status = "okay";
> + };

Do we need to have this disabled initially in the SoC dtsi?

Also, common style in this file is to add a blank line between nodes.
Please keep it.

Sascha


-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 1/2] USB: chipidea: add imx usbmisc support

2012-07-18 Thread Sascha Hauer
On Wed, Jul 18, 2012 at 07:19:17PM +0800, Richard Zhao wrote:
> > > +
> > > +struct imx6q_usbmisc {
> > > + void __iomem *base;
> > > + struct clk *clk;
> > > + struct device *usb_dev[USB_DEV_MAX];
> > > + spinlock_t lock;
> > > +
> > > + int disable_oc:USB_DEV_MAX;
> > > +};
> > 
> > Please add a per-port struct instead of adding multiple arrays into
> > struct imx6q_usbmisc.
> ok
> 
> > 
> > Also, I think this per port struct shouldn't be imx6q specific. Then
> > we could add generic code parsing the oftree flags into the port
> > specific struct and have SoC specific code which translates this struct
> > into the acual register settings.
> hmm... I thought only ops is generic. The code is SoC specific, I doubt
> do we really need to take the properties as generic?

I think it would be good. They mostly match across the different i.MX
SoCs.

Sascha

-- 
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- |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


  1   2   >