[PATCH v8 8/8] usb: phy: twl4030-usb: remove *set_suspend* and *phy_init* ops

2013-06-25 Thread Kishon Vijay Abraham I
Now that twl4030-usb is adapted to the new generic PHY framework,
*set_suspend* and *phy_init* ops can be removed from twl4030-usb driver.

Signed-off-by: Kishon Vijay Abraham I kis...@ti.com
Reviewed-by: Felipe Balbi ba...@ti.com
Reviewed-by: Sylwester Nawrocki s.nawro...@samsung.com
---
 drivers/usb/phy/phy-twl4030-usb.c |   57 +
 1 file changed, 13 insertions(+), 44 deletions(-)

diff --git a/drivers/usb/phy/phy-twl4030-usb.c 
b/drivers/usb/phy/phy-twl4030-usb.c
index 3f09b7b..f32e503 100644
--- a/drivers/usb/phy/phy-twl4030-usb.c
+++ b/drivers/usb/phy/phy-twl4030-usb.c
@@ -422,25 +422,20 @@ static void twl4030_phy_power(struct twl4030_usb *twl, 
int on)
}
 }
 
-static void twl4030_phy_suspend(struct twl4030_usb *twl, int controller_off)
+static int twl4030_phy_power_off(struct phy *phy)
 {
+   struct twl4030_usb *twl = dev_get_drvdata(phy-dev);
+
if (twl-asleep)
-   return;
+   return 0;
 
twl4030_phy_power(twl, 0);
twl-asleep = 1;
dev_dbg(twl-dev, %s\n, __func__);
-}
-
-static int twl4030_phy_power_off(struct phy *phy)
-{
-   struct twl4030_usb *twl = dev_get_drvdata(phy-dev);
-
-   twl4030_phy_suspend(twl, 0);
return 0;
 }
 
-static void __twl4030_phy_resume(struct twl4030_usb *twl)
+static void __twl4030_phy_power_on(struct twl4030_usb *twl)
 {
twl4030_phy_power(twl, 1);
twl4030_i2c_access(twl, 1);
@@ -449,11 +444,13 @@ static void __twl4030_phy_resume(struct twl4030_usb *twl)
twl4030_i2c_access(twl, 0);
 }
 
-static void twl4030_phy_resume(struct twl4030_usb *twl)
+static int twl4030_phy_power_on(struct phy *phy)
 {
+   struct twl4030_usb *twl = dev_get_drvdata(phy-dev);
+
if (!twl-asleep)
-   return;
-   __twl4030_phy_resume(twl);
+   return 0;
+   __twl4030_phy_power_on(twl);
twl-asleep = 0;
dev_dbg(twl-dev, %s\n, __func__);
 
@@ -466,13 +463,6 @@ static void twl4030_phy_resume(struct twl4030_usb *twl)
cancel_delayed_work(twl-id_workaround_work);
schedule_delayed_work(twl-id_workaround_work, HZ);
}
-}
-
-static int twl4030_phy_power_on(struct phy *phy)
-{
-   struct twl4030_usb *twl = dev_get_drvdata(phy-dev);
-
-   twl4030_phy_resume(twl);
return 0;
 }
 
@@ -604,9 +594,9 @@ static void twl4030_id_workaround_work(struct work_struct 
*work)
}
 }
 
-static int twl4030_usb_phy_init(struct usb_phy *phy)
+static int twl4030_phy_init(struct phy *phy)
 {
-   struct twl4030_usb *twl = phy_to_twl(phy);
+   struct twl4030_usb *twl = dev_get_drvdata(phy-dev);
enum omap_musb_vbus_id_status status;
 
/*
@@ -621,32 +611,13 @@ static int twl4030_usb_phy_init(struct usb_phy *phy)
 
if (status == OMAP_MUSB_ID_GROUND || status == OMAP_MUSB_VBUS_VALID) {
omap_musb_mailbox(twl-linkstat);
-   twl4030_phy_resume(twl);
+   twl4030_phy_power_on(phy);
}
 
sysfs_notify(twl-dev-kobj, NULL, vbus);
return 0;
 }
 
-static int twl4030_phy_init(struct phy *phy)
-{
-   struct twl4030_usb *twl = dev_get_drvdata(phy-dev);
-
-   return twl4030_usb_phy_init(twl-phy);
-}
-
-static int twl4030_set_suspend(struct usb_phy *x, int suspend)
-{
-   struct twl4030_usb *twl = phy_to_twl(x);
-
-   if (suspend)
-   twl4030_phy_suspend(twl, 1);
-   else
-   twl4030_phy_resume(twl);
-
-   return 0;
-}
-
 static int twl4030_set_peripheral(struct usb_otg *otg,
struct usb_gadget *gadget)
 {
@@ -717,8 +688,6 @@ static int twl4030_usb_probe(struct platform_device *pdev)
twl-phy.label  = twl4030;
twl-phy.otg= otg;
twl-phy.type   = USB_PHY_TYPE_USB2;
-   twl-phy.set_suspend= twl4030_set_suspend;
-   twl-phy.init   = twl4030_usb_phy_init;
 
otg-phy= twl-phy;
otg-set_host   = twl4030_set_host;
-- 
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 v8 6/8] usb: musb: omap2430: use the new generic PHY framework

2013-06-25 Thread Kishon Vijay Abraham I
Use the generic PHY framework API to get the PHY. The usb_phy_set_resume
and usb_phy_set_suspend is replaced with power_on and
power_off to align with the new PHY framework.

musb-xceiv can't be removed as of now because musb core uses xceiv.state and
xceiv.otg. Once there is a separate state machine to handle otg, these can be
moved out of xceiv and then we can start using the generic PHY framework.

Signed-off-by: Kishon Vijay Abraham I kis...@ti.com
Reviewed-by: Sylwester Nawrocki s.nawro...@samsung.com
---
 drivers/usb/musb/Kconfig |1 +
 drivers/usb/musb/musb_core.c |1 +
 drivers/usb/musb/musb_core.h |3 +++
 drivers/usb/musb/omap2430.c  |   26 --
 4 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index 06f8d29..6ef595a 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -47,6 +47,7 @@ config USB_MUSB_TUSB6010
 config USB_MUSB_OMAP2PLUS
tristate OMAP2430 and onwards
depends on ARCH_OMAP2PLUS
+   depends on GENERIC_PHY
 
 config USB_MUSB_AM35X
tristate AM35x
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 37a261a..f732bcc 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -1864,6 +1864,7 @@ musb_init_controller(struct device *dev, int nIrq, void 
__iomem *ctrl)
musb-board_set_power = plat-set_power;
musb-min_power = plat-min_power;
musb-ops = plat-platform_ops;
+   musb-phy_label = plat-phy_label;
 
/* The musb_platform_init() call:
 *   - adjusts musb-mregs
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 7fb4819..498ae21 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -46,6 +46,7 @@
 #include linux/usb.h
 #include linux/usb/otg.h
 #include linux/usb/musb.h
+#include linux/phy/phy.h
 
 struct musb;
 struct musb_hw_ep;
@@ -357,6 +358,7 @@ struct musb {
u16 int_tx;
 
struct usb_phy  *xceiv;
+   struct phy  *phy;
 
int nIrq;
unsignedirq_wake:1;
@@ -434,6 +436,7 @@ struct musb {
unsigneddouble_buffer_not_ok:1;
 
struct musb_hdrc_config *config;
+   const char  *phy_label;
 
 #ifdef MUSB_CONFIG_PROC_FS
struct proc_dir_entry *proc_entry;
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index 628b93f..12b94da 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -348,11 +348,21 @@ static int omap2430_musb_init(struct musb *musb)
 * up through ULPI.  TWL4030-family PMICs include one,
 * which needs a driver, drivers aren't always needed.
 */
-   if (dev-parent-of_node)
+   if (dev-parent-of_node) {
+   musb-phy = devm_phy_get(dev-parent, usb2-phy);
+
+   /* We can't totally remove musb-xceiv as of now because
+* musb core uses xceiv.state and xceiv.otg. Once we have
+* a separate state machine to handle otg, these can be moved
+* out of xceiv and then we can start using the generic PHY
+* framework
+*/
musb-xceiv = devm_usb_get_phy_by_phandle(dev-parent,
usb-phy, 0);
-   else
+   } else {
musb-xceiv = devm_usb_get_phy_dev(dev, 0);
+   musb-phy = devm_phy_get(dev, musb-phy_label);
+   }
 
if (IS_ERR(musb-xceiv)) {
status = PTR_ERR(musb-xceiv);
@@ -364,6 +374,10 @@ static int omap2430_musb_init(struct musb *musb)
return -EPROBE_DEFER;
}
 
+   if (IS_ERR(musb-phy)) {
+   pr_err(HS USB OTG: no PHY configured\n);
+   return PTR_ERR(musb-phy);
+   }
musb-isr = omap2430_musb_interrupt;
 
status = pm_runtime_get_sync(dev);
@@ -397,7 +411,7 @@ static int omap2430_musb_init(struct musb *musb)
if (glue-status != OMAP_MUSB_UNKNOWN)
omap_musb_set_mailbox(glue);
 
-   usb_phy_init(musb-xceiv);
+   phy_init(musb-phy);
 
pm_runtime_put_noidle(musb-controller);
return 0;
@@ -460,6 +474,7 @@ static int omap2430_musb_exit(struct musb *musb)
del_timer_sync(musb_idle_timer);
 
omap2430_low_level_exit(musb);
+   phy_exit(musb-phy);
 
return 0;
 }
@@ -619,7 +634,7 @@ static int omap2430_runtime_suspend(struct device *dev)
OTG_INTERFSEL);
 
omap2430_low_level_exit(musb);
-   usb_phy_set_suspend(musb-xceiv, 1);
+   phy_power_off(musb-phy);
}
 
return 0;
@@ -634,8 +649,7 @@ static int omap2430_runtime_resume(struct device *dev)
omap2430_low_level_init(musb);
musb_writel(musb-mregs, OTG_INTERFSEL,

[PATCH v8 7/8] usb: phy: omap-usb2: remove *set_suspend* callback from omap-usb2

2013-06-25 Thread Kishon Vijay Abraham I
Now that omap-usb2 is adapted to the new generic PHY framework,
*set_suspend* ops can be removed from omap-usb2 driver.

Signed-off-by: Kishon Vijay Abraham I kis...@ti.com
Reviewed-by: Felipe Balbi ba...@ti.com
Reviewed-by: Sylwester Nawrocki s.nawro...@samsung.com
---
 drivers/usb/phy/phy-omap-usb2.c |   25 -
 1 file changed, 25 deletions(-)

diff --git a/drivers/usb/phy/phy-omap-usb2.c b/drivers/usb/phy/phy-omap-usb2.c
index ecdf1ac..7171426 100644
--- a/drivers/usb/phy/phy-omap-usb2.c
+++ b/drivers/usb/phy/phy-omap-usb2.c
@@ -97,29 +97,6 @@ static int omap_usb_set_peripheral(struct usb_otg *otg,
return 0;
 }
 
-static int omap_usb2_suspend(struct usb_phy *x, int suspend)
-{
-   u32 ret;
-   struct omap_usb *phy = phy_to_omapusb(x);
-
-   if (suspend  !phy-is_suspended) {
-   omap_control_usb_phy_power(phy-control_dev, 0);
-   pm_runtime_put_sync(phy-dev);
-   phy-is_suspended = 1;
-   } else if (!suspend  phy-is_suspended) {
-   ret = pm_runtime_get_sync(phy-dev);
-   if (ret  0) {
-   dev_err(phy-dev, get_sync failed with err %d\n,
-   ret);
-   return ret;
-   }
-   omap_control_usb_phy_power(phy-control_dev, 1);
-   phy-is_suspended = 0;
-   }
-
-   return 0;
-}
-
 static int omap_usb_power_off(struct phy *x)
 {
struct omap_usb *phy = dev_get_drvdata(x-dev);
@@ -167,7 +144,6 @@ static int omap_usb2_probe(struct platform_device *pdev)
 
phy-phy.dev= phy-dev;
phy-phy.label  = omap-usb2;
-   phy-phy.set_suspend= omap_usb2_suspend;
phy-phy.otg= otg;
phy-phy.type   = USB_PHY_TYPE_USB2;
 
@@ -182,7 +158,6 @@ static int omap_usb2_probe(struct platform_device *pdev)
return -ENODEV;
}
 
-   phy-is_suspended   = 1;
omap_control_usb_phy_power(phy-control_dev, 0);
 
otg-set_host   = omap_usb_set_host;
-- 
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 v8 2/8] usb: phy: omap-usb2: use the new generic PHY framework

2013-06-25 Thread Kishon Vijay Abraham I
Used the generic PHY framework API to create the PHY. Now the power off and
power on are done in omap_usb_power_off and omap_usb_power_on respectively.

However using the old USB PHY library cannot be completely removed
because OTG is intertwined with PHY and moving to the new framework
will break OTG. Once we have a separate OTG state machine, we
can get rid of the USB PHY library.

Signed-off-by: Kishon Vijay Abraham I kis...@ti.com
Reviewed-by: Sylwester Nawrocki s.nawro...@samsung.com
---
 drivers/usb/phy/Kconfig |1 +
 drivers/usb/phy/phy-omap-usb2.c |   43 +++
 2 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
index 7ef3eb8..5caeafd 100644
--- a/drivers/usb/phy/Kconfig
+++ b/drivers/usb/phy/Kconfig
@@ -69,6 +69,7 @@ config OMAP_CONTROL_USB
 config OMAP_USB2
tristate OMAP USB2 PHY Driver
depends on ARCH_OMAP2PLUS
+   depends on GENERIC_PHY
select OMAP_CONTROL_USB
help
  Enable this to support the transceiver that is part of SOC. This
diff --git a/drivers/usb/phy/phy-omap-usb2.c b/drivers/usb/phy/phy-omap-usb2.c
index 844ab68..ecdf1ac 100644
--- a/drivers/usb/phy/phy-omap-usb2.c
+++ b/drivers/usb/phy/phy-omap-usb2.c
@@ -28,6 +28,7 @@
 #include linux/pm_runtime.h
 #include linux/delay.h
 #include linux/usb/omap_control_usb.h
+#include linux/phy/phy.h
 
 /**
  * omap_usb2_set_comparator - links the comparator present in the sytem with
@@ -119,10 +120,36 @@ static int omap_usb2_suspend(struct usb_phy *x, int 
suspend)
return 0;
 }
 
+static int omap_usb_power_off(struct phy *x)
+{
+   struct omap_usb *phy = dev_get_drvdata(x-dev);
+
+   omap_control_usb_phy_power(phy-control_dev, 0);
+
+   return 0;
+}
+
+static int omap_usb_power_on(struct phy *x)
+{
+   struct omap_usb *phy = dev_get_drvdata(x-dev);
+
+   omap_control_usb_phy_power(phy-control_dev, 1);
+
+   return 0;
+}
+
+static struct phy_ops ops = {
+   .power_on   = omap_usb_power_on,
+   .power_off  = omap_usb_power_off,
+   .owner  = THIS_MODULE,
+};
+
 static int omap_usb2_probe(struct platform_device *pdev)
 {
struct omap_usb *phy;
+   struct phy  *generic_phy;
struct usb_otg  *otg;
+   struct phy_provider *phy_provider;
 
phy = devm_kzalloc(pdev-dev, sizeof(*phy), GFP_KERNEL);
if (!phy) {
@@ -144,6 +171,11 @@ static int omap_usb2_probe(struct platform_device *pdev)
phy-phy.otg= otg;
phy-phy.type   = USB_PHY_TYPE_USB2;
 
+   phy_provider = devm_of_phy_provider_register(phy-dev,
+   of_phy_simple_xlate);
+   if (IS_ERR(phy_provider))
+   return PTR_ERR(phy_provider);
+
phy-control_dev = omap_get_control_dev();
if (IS_ERR(phy-control_dev)) {
dev_dbg(pdev-dev, Failed to get control device\n);
@@ -159,6 +191,13 @@ static int omap_usb2_probe(struct platform_device *pdev)
otg-start_srp  = omap_usb_start_srp;
otg-phy= phy-phy;
 
+   platform_set_drvdata(pdev, phy);
+   pm_runtime_enable(phy-dev);
+
+   generic_phy = devm_phy_create(phy-dev, 0, ops, omap-usb2, phy);
+   if (IS_ERR(generic_phy))
+   return PTR_ERR(generic_phy);
+
phy-wkupclk = devm_clk_get(phy-dev, usb_phy_cm_clk32k);
if (IS_ERR(phy-wkupclk)) {
dev_err(pdev-dev, unable to get usb_phy_cm_clk32k\n);
@@ -174,10 +213,6 @@ static int omap_usb2_probe(struct platform_device *pdev)
 
usb_add_phy_dev(phy-phy);
 
-   platform_set_drvdata(pdev, phy);
-
-   pm_runtime_enable(phy-dev);
-
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 v8 3/8] usb: phy: twl4030: use the new generic PHY framework

2013-06-25 Thread Kishon Vijay Abraham I
Used the generic PHY framework API to create the PHY. For powering on
and powering off the PHY, power_on and power_off ops are used. Once the
MUSB OMAP glue is adapted to the new framework, the suspend and resume
ops of usb phy library will be removed.

However using the old usb phy library cannot be completely removed
because otg is intertwined with phy and moving to the new
framework completely will break otg. Once we have a separate otg state machine,
we can get rid of the usb phy library.

Signed-off-by: Kishon Vijay Abraham I kis...@ti.com
Reviewed-by: Felipe Balbi ba...@ti.com
Reviewed-by: Sylwester Nawrocki s.nawro...@samsung.com
---
 drivers/usb/phy/phy-twl4030-usb.c |   48 -
 1 file changed, 47 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/phy/phy-twl4030-usb.c 
b/drivers/usb/phy/phy-twl4030-usb.c
index 8fbe2d9..3f09b7b 100644
--- a/drivers/usb/phy/phy-twl4030-usb.c
+++ b/drivers/usb/phy/phy-twl4030-usb.c
@@ -33,6 +33,7 @@
 #include linux/io.h
 #include linux/delay.h
 #include linux/usb/otg.h
+#include linux/phy/phy.h
 #include linux/usb/musb-omap.h
 #include linux/usb/ulpi.h
 #include linux/i2c/twl.h
@@ -431,6 +432,14 @@ static void twl4030_phy_suspend(struct twl4030_usb *twl, 
int controller_off)
dev_dbg(twl-dev, %s\n, __func__);
 }
 
+static int twl4030_phy_power_off(struct phy *phy)
+{
+   struct twl4030_usb *twl = dev_get_drvdata(phy-dev);
+
+   twl4030_phy_suspend(twl, 0);
+   return 0;
+}
+
 static void __twl4030_phy_resume(struct twl4030_usb *twl)
 {
twl4030_phy_power(twl, 1);
@@ -459,6 +468,14 @@ static void twl4030_phy_resume(struct twl4030_usb *twl)
}
 }
 
+static int twl4030_phy_power_on(struct phy *phy)
+{
+   struct twl4030_usb *twl = dev_get_drvdata(phy-dev);
+
+   twl4030_phy_resume(twl);
+   return 0;
+}
+
 static int twl4030_usb_ldo_init(struct twl4030_usb *twl)
 {
/* Enable writing to power configuration registers */
@@ -602,13 +619,22 @@ static int twl4030_usb_phy_init(struct usb_phy *phy)
status = twl4030_usb_linkstat(twl);
twl-linkstat = status;
 
-   if (status == OMAP_MUSB_ID_GROUND || status == OMAP_MUSB_VBUS_VALID)
+   if (status == OMAP_MUSB_ID_GROUND || status == OMAP_MUSB_VBUS_VALID) {
omap_musb_mailbox(twl-linkstat);
+   twl4030_phy_resume(twl);
+   }
 
sysfs_notify(twl-dev-kobj, NULL, vbus);
return 0;
 }
 
+static int twl4030_phy_init(struct phy *phy)
+{
+   struct twl4030_usb *twl = dev_get_drvdata(phy-dev);
+
+   return twl4030_usb_phy_init(twl-phy);
+}
+
 static int twl4030_set_suspend(struct usb_phy *x, int suspend)
 {
struct twl4030_usb *twl = phy_to_twl(x);
@@ -646,13 +672,22 @@ static int twl4030_set_host(struct usb_otg *otg, struct 
usb_bus *host)
return 0;
 }
 
+static const struct phy_ops ops = {
+   .init   = twl4030_phy_init,
+   .power_on   = twl4030_phy_power_on,
+   .power_off  = twl4030_phy_power_off,
+   .owner  = THIS_MODULE,
+};
+
 static int twl4030_usb_probe(struct platform_device *pdev)
 {
struct twl4030_usb_data *pdata = pdev-dev.platform_data;
struct twl4030_usb  *twl;
+   struct phy  *phy;
int status, err;
struct usb_otg  *otg;
struct device_node  *np = pdev-dev.of_node;
+   struct phy_provider *phy_provider;
 
twl = devm_kzalloc(pdev-dev, sizeof *twl, GFP_KERNEL);
if (!twl)
@@ -689,6 +724,17 @@ static int twl4030_usb_probe(struct platform_device *pdev)
otg-set_host   = twl4030_set_host;
otg-set_peripheral = twl4030_set_peripheral;
 
+   phy_provider = devm_of_phy_provider_register(twl-dev,
+   of_phy_simple_xlate);
+   if (IS_ERR(phy_provider))
+   return PTR_ERR(phy_provider);
+
+   phy = devm_phy_create(twl-dev, 0, ops, twl4030, twl);
+   if (IS_ERR(phy)) {
+   dev_dbg(pdev-dev, Failed to create PHY\n);
+   return PTR_ERR(phy);
+   }
+
/* init spinlock for workqueue */
spin_lock_init(twl-lock);
 
-- 
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 v8 5/8] ARM: dts: omap: update usb_otg_hs data

2013-06-25 Thread Kishon Vijay Abraham I
Updated the usb_otg_hs dt data to include the *phy* and *phy-names*
binding in order for the driver to use the new generic PHY framework.
Also updated the Documentation to include the binding information.
The PHY binding information can be found at
Documentation/devicetree/bindings/phy/phy-bindings.txt

Signed-off-by: Kishon Vijay Abraham I kis...@ti.com
Reviewed-by: Felipe Balbi ba...@ti.com
Reviewed-by: Sylwester Nawrocki s.nawro...@samsung.com
---
 Documentation/devicetree/bindings/usb/omap-usb.txt |5 +
 Documentation/devicetree/bindings/usb/usb-phy.txt  |6 ++
 arch/arm/boot/dts/omap3-beagle-xm.dts  |2 ++
 arch/arm/boot/dts/omap3-evm.dts|2 ++
 arch/arm/boot/dts/omap3-overo.dtsi |2 ++
 arch/arm/boot/dts/omap4.dtsi   |3 +++
 arch/arm/boot/dts/twl4030.dtsi |1 +
 7 files changed, 21 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/omap-usb.txt 
b/Documentation/devicetree/bindings/usb/omap-usb.txt
index d4769f3..c0871a7 100644
--- a/Documentation/devicetree/bindings/usb/omap-usb.txt
+++ b/Documentation/devicetree/bindings/usb/omap-usb.txt
@@ -19,6 +19,9 @@ OMAP MUSB GLUE
  - power : Should be 50. This signifies the controller can supply upto
100mA when operating in host mode.
  - usb-phy : the phandle for the PHY device
+ - phys : the phandle for the PHY device (used by generic PHY framework)
+ - phy-names : the names of the PHY corresponding to the PHYs present in the
+   *phy* phandle.
 
 Optional properties:
  - ctrl-module : phandle of the control module this glue uses to write to
@@ -33,6 +36,8 @@ usb_otg_hs: usb_otg_hs@4a0ab000 {
num-eps = 16;
ram-bits = 12;
ctrl-module = omap_control_usb;
+   phys = usb2_phy;
+   phy-names = usb2-phy;
 };
 
 Board specific device node entry
diff --git a/Documentation/devicetree/bindings/usb/usb-phy.txt 
b/Documentation/devicetree/bindings/usb/usb-phy.txt
index 61496f5..c0245c8 100644
--- a/Documentation/devicetree/bindings/usb/usb-phy.txt
+++ b/Documentation/devicetree/bindings/usb/usb-phy.txt
@@ -5,6 +5,8 @@ OMAP USB2 PHY
 Required properties:
  - compatible: Should be ti,omap-usb2
  - reg : Address and length of the register set for the device.
+ - #phy-cells: determine the number of cells that should be given in the
+   phandle while referencing this phy.
 
 Optional properties:
  - ctrl-module : phandle of the control module used by PHY driver to power on
@@ -16,6 +18,7 @@ usb2phy@4a0ad080 {
compatible = ti,omap-usb2;
reg = 0x4a0ad080 0x58;
ctrl-module = omap_control_usb;
+   #phy-cells = 0;
 };
 
 OMAP USB3 PHY
@@ -25,6 +28,8 @@ Required properties:
  - reg : Address and length of the register set for the device.
  - reg-names: The names of the register addresses corresponding to the 
registers
filled in reg.
+ - #phy-cells: determine the number of cells that should be given in the
+   phandle while referencing this phy.
 
 Optional properties:
  - ctrl-module : phandle of the control module used by PHY driver to power on
@@ -39,4 +44,5 @@ usb3phy@4a084400 {
  0x4a084c00 0x40;
reg-names = phy_rx, phy_tx, pll_ctrl;
ctrl-module = omap_control_usb;
+   #phy-cells = 0;
 };
diff --git a/arch/arm/boot/dts/omap3-beagle-xm.dts 
b/arch/arm/boot/dts/omap3-beagle-xm.dts
index 3046d1f..023596e 100644
--- a/arch/arm/boot/dts/omap3-beagle-xm.dts
+++ b/arch/arm/boot/dts/omap3-beagle-xm.dts
@@ -123,6 +123,8 @@
 usb_otg_hs {
interface-type = 0;
usb-phy = usb2_phy;
+   phys = usb2_phy;
+   phy-names = usb2-phy;
mode = 3;
power = 50;
 };
diff --git a/arch/arm/boot/dts/omap3-evm.dts b/arch/arm/boot/dts/omap3-evm.dts
index 96d1c20..f2b8314 100644
--- a/arch/arm/boot/dts/omap3-evm.dts
+++ b/arch/arm/boot/dts/omap3-evm.dts
@@ -69,6 +69,8 @@
 usb_otg_hs {
interface-type = 0;
usb-phy = usb2_phy;
+   phys = usb2_phy;
+   phy-names = usb2-phy;
mode = 3;
power = 50;
 };
diff --git a/arch/arm/boot/dts/omap3-overo.dtsi 
b/arch/arm/boot/dts/omap3-overo.dtsi
index a626c50..b65916e 100644
--- a/arch/arm/boot/dts/omap3-overo.dtsi
+++ b/arch/arm/boot/dts/omap3-overo.dtsi
@@ -74,6 +74,8 @@
 usb_otg_hs {
interface-type = 0;
usb-phy = usb2_phy;
+   phys = usb2_phy;
+   phy-names = usb2-phy;
mode = 3;
power = 50;
 };
diff --git a/arch/arm/boot/dts/omap4.dtsi b/arch/arm/boot/dts/omap4.dtsi
index 2a56428..dae620b 100644
--- a/arch/arm/boot/dts/omap4.dtsi
+++ b/arch/arm/boot/dts/omap4.dtsi
@@ -517,6 +517,7 @@
compatible = ti,omap-usb2;
reg = 0x4a0ad080 0x58;
ctrl-module = omap_control_usb;
+   #phy-cells = 0;
};
};
 
@@ -655,6 +656,8 @@
interrupt-names = mc, dma;
  

[PATCH v8 4/8] ARM: OMAP: USB: Add phy binding information

2013-06-25 Thread Kishon Vijay Abraham I
In order for controllers to get PHY in case of non dt boot, the phy
binding information (phy device name) should be added in the platform
data of the controller.

Signed-off-by: Kishon Vijay Abraham I kis...@ti.com
Reviewed-by: Sylwester Nawrocki s.nawro...@samsung.com
---
 arch/arm/mach-omap2/usb-musb.c |6 +-
 include/linux/usb/musb.h   |3 +++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-omap2/usb-musb.c b/arch/arm/mach-omap2/usb-musb.c
index 3242a55..284ba51 100644
--- a/arch/arm/mach-omap2/usb-musb.c
+++ b/arch/arm/mach-omap2/usb-musb.c
@@ -85,8 +85,12 @@ void __init usb_musb_init(struct omap_musb_board_data 
*musb_board_data)
musb_plat.mode = board_data-mode;
musb_plat.extvbus = board_data-extvbus;
 
-   if (cpu_is_omap44xx())
+   if (cpu_is_omap44xx()) {
musb_plat.has_mailbox = true;
+   musb_plat.phy_label = omap-usb2;
+   } else if (cpu_is_omap34xx()) {
+   musb_plat.phy_label = twl4030;
+   }
 
if (soc_is_am35xx()) {
oh_name = am35x_otg_hs;
diff --git a/include/linux/usb/musb.h b/include/linux/usb/musb.h
index 053c268..596f8c8 100644
--- a/include/linux/usb/musb.h
+++ b/include/linux/usb/musb.h
@@ -104,6 +104,9 @@ struct musb_hdrc_platform_data {
/* for clk_get() */
const char  *clock;
 
+   /* phy label */
+   const char  *phy_label;
+
/* (HOST or OTG) switch VBUS on/off */
int (*set_vbus)(struct device *dev, int is_on);
 
-- 
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 v8 1/8] drivers: phy: add generic PHY framework

2013-06-25 Thread Kishon Vijay Abraham I
The PHY framework provides a set of APIs for the PHY drivers to
create/destroy a PHY and APIs for the PHY users to obtain a reference to the
PHY with or without using phandle. For dt-boot, the PHY drivers should
also register *PHY provider* with the framework.

PHY drivers should create the PHY by passing id and ops like init, exit,
power_on and power_off. This framework is also pm runtime enabled.

The documentation for the generic PHY framework is added in
Documentation/phy.txt and the documentation for dt binding can be found at
Documentation/devicetree/bindings/phy/phy-bindings.txt

Signed-off-by: Kishon Vijay Abraham I kis...@ti.com
Tested-by: Sylwester Nawrocki s.nawro...@samsung.com
---
 .../devicetree/bindings/phy/phy-bindings.txt   |   66 +++
 Documentation/phy.txt  |  125 +
 MAINTAINERS|7 +
 drivers/Kconfig|2 +
 drivers/Makefile   |2 +
 drivers/phy/Kconfig|   13 +
 drivers/phy/Makefile   |5 +
 drivers/phy/phy-core.c |  548 
 include/linux/phy/phy.h|  334 
 9 files changed, 1102 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/phy-bindings.txt
 create mode 100644 Documentation/phy.txt
 create mode 100644 drivers/phy/Kconfig
 create mode 100644 drivers/phy/Makefile
 create mode 100644 drivers/phy/phy-core.c
 create mode 100644 include/linux/phy/phy.h

diff --git a/Documentation/devicetree/bindings/phy/phy-bindings.txt 
b/Documentation/devicetree/bindings/phy/phy-bindings.txt
new file mode 100644
index 000..8ae844f
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/phy-bindings.txt
@@ -0,0 +1,66 @@
+This document explains only the device tree data binding. For general
+information about PHY subsystem refer to Documentation/phy.txt
+
+PHY device node
+===
+
+Required Properties:
+#phy-cells:Number of cells in a PHY specifier;  The meaning of all those
+   cells is defined by the binding for the phy node. The PHY
+   provider can use the values in cells to find the appropriate
+   PHY.
+
+For example:
+
+phys: phy {
+compatible = xxx;
+reg = ...;
+.
+.
+#phy-cells = 1;
+.
+.
+};
+
+That node describes an IP block (PHY provider) that implements 2 different 
PHYs.
+In order to differentiate between these 2 PHYs, an additonal specifier should 
be
+given while trying to get a reference to it.
+
+PHY user node
+=
+
+Required Properties:
+phys : the phandle for the PHY device (used by the PHY subsystem)
+phy-names : the names of the PHY corresponding to the PHYs present in the
+   *phys* phandle
+
+Example 1:
+usb1: usb_otg_ss@xxx {
+compatible = xxx;
+reg = xxx;
+.
+.
+phys = usb2_phy, usb3_phy;
+phy-names = usb2phy, usb3phy;
+.
+.
+};
+
+This node represents a controller that uses two PHYs, one for usb2 and one for
+usb3.
+
+Example 2:
+usb2: usb_otg_ss@xxx {
+compatible = xxx;
+reg = xxx;
+.
+.
+phys = phys 1;
+phy-names = usbphy;
+.
+.
+};
+
+This node represents a controller that uses one of the PHYs of the PHY provider
+device defined previously. Note that the phy handle has an additional specifier
+1 to differentiate between the two PHYs.
diff --git a/Documentation/phy.txt b/Documentation/phy.txt
new file mode 100644
index 000..d66ddcc
--- /dev/null
+++ b/Documentation/phy.txt
@@ -0,0 +1,125 @@
+   PHY SUBSYSTEM
+ Kishon Vijay Abraham I kis...@ti.com
+
+This document explains the Generic PHY Framework along with the APIs provided,
+and how-to-use.
+
+1. Introduction
+
+*PHY* is the abbreviation for physical layer. It is used to connect a device
+to the physical medium e.g., the USB controller has a PHY to provide functions
+such as serialization, de-serialization, encoding, decoding and is responsible
+for obtaining the required data transmission rate. Note that some USB
+controllers have PHY functionality embedded into it and others use an external
+PHY. Other peripherals that use PHY include Wireless LAN, Ethernet,
+SATA etc.
+
+The intention of creating this framework is to bring the PHY drivers spread
+all over the Linux kernel to drivers/phy to increase code re-use and for
+better code maintainability.
+
+This framework will be of use only to devices that use external PHY (PHY
+functionality is not embedded within the controller).
+
+2. Registering/Unregistering the PHY provider
+
+PHY provider refers to an entity that implements one or more PHY instances.
+For the simple case where the PHY provider implements only a single instance of
+the PHY, the framework provides its own implementation of of_xlate in
+of_phy_simple_xlate. If the PHY provider 

[PATCH V3 4/6] USB: OHCI: make ohci-spear a separate driver

2013-06-25 Thread Manjunath Goudar
Separate the ST OHCI SPEAr host controller driver from ohci-hcd
host code so that it can be built as a separate driver module.
This work is part of enabling multi-platform kernels on ARM;
it would be nice to have in 3.11.

Signed-off-by: Manjunath Goudar manjunath.gou...@linaro.org
Acked-by: Alan Stern st...@rowland.harvard.edu
Cc: Viresh Kumar viresh.li...@gmail.com
Cc: Arnd Bergmann a...@arndb.de
Cc: Greg KH g...@kroah.com
Cc: linux-usb@vger.kernel.org

V2:
 -ohci_setup() removed because it is called in .reset member
  of the ohci_hc_driver structure.
 -debugging stuff isn't needed any more that's what removed.

V3:
 No change.
---
 drivers/usb/host/Kconfig  |8 +++
 drivers/usb/host/Makefile |1 +
 drivers/usb/host/ohci-hcd.c   |   18 --
 drivers/usb/host/ohci-spear.c |  140 +
 4 files changed, 65 insertions(+), 102 deletions(-)

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index db20e43..46c2f42 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -382,6 +382,14 @@ config USB_OHCI_HCD_OMAP1
---help---
  Enables support for the OHCI controller on OMAP1/2 chips.
 
+config USB_OHCI_HCD_SPEAR
+tristate Support for ST SPEAr on-chip OHCI USB controller
+depends on USB_OHCI_HCD  PLAT_SPEAR
+default y
+---help---
+  Enables support for the on-chip OHCI controller on
+  ST SPEAr chips.
+
 config USB_OHCI_HCD_OMAP3
tristate OHCI support for OMAP3 and later chips
depends on (ARCH_OMAP3 || ARCH_OMAP4)
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index 9f2f5f3..26cb6b3 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -48,6 +48,7 @@ obj-$(CONFIG_USB_OHCI_HCD_PLATFORM)   += ohci-platform.o
 obj-$(CONFIG_USB_OHCI_EXYNOS)  += ohci-exynos.o
 obj-$(CONFIG_USB_OHCI_HCD_OMAP1)   += ohci-omap.o
 obj-$(CONFIG_USB_OHCI_HCD_OMAP3)   += ohci-omap3.o
+obj-$(CONFIG_USB_OHCI_HCD_SPEAR)   += ohci-spear.o
 
 obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o
 obj-$(CONFIG_USB_FHCI_HCD) += fhci.o
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index cad51d2..34ec156 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -1212,11 +1212,6 @@ MODULE_LICENSE (GPL);
 #define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver
 #endif
 
-#ifdef CONFIG_PLAT_SPEAR
-#include ohci-spear.c
-#define SPEAR_PLATFORM_DRIVER  spear_ohci_hcd_driver
-#endif
-
 #ifdef CONFIG_PPC_PS3
 #include ohci-ps3.c
 #define PS3_SYSTEM_BUS_DRIVER  ps3_ohci_driver
@@ -1333,19 +1328,9 @@ static int __init ohci_hcd_mod_init(void)
goto error_davinci;
 #endif
 
-#ifdef SPEAR_PLATFORM_DRIVER
-   retval = platform_driver_register(SPEAR_PLATFORM_DRIVER);
-   if (retval  0)
-   goto error_spear;
-#endif
-
return retval;
 
/* Error path */
-#ifdef SPEAR_PLATFORM_DRIVER
-   platform_driver_unregister(SPEAR_PLATFORM_DRIVER);
- error_spear:
-#endif
 #ifdef DAVINCI_PLATFORM_DRIVER
platform_driver_unregister(DAVINCI_PLATFORM_DRIVER);
  error_davinci:
@@ -1403,9 +1388,6 @@ module_init(ohci_hcd_mod_init);
 
 static void __exit ohci_hcd_mod_exit(void)
 {
-#ifdef SPEAR_PLATFORM_DRIVER
-   platform_driver_unregister(SPEAR_PLATFORM_DRIVER);
-#endif
 #ifdef DAVINCI_PLATFORM_DRIVER
platform_driver_unregister(DAVINCI_PLATFORM_DRIVER);
 #endif
diff --git a/drivers/usb/host/ohci-spear.c b/drivers/usb/host/ohci-spear.c
index cc9dd9e..31ff3fc 100644
--- a/drivers/usb/host/ohci-spear.c
+++ b/drivers/usb/host/ohci-spear.c
@@ -11,92 +11,37 @@
 * warranty of any kind, whether express or implied.
 */
 
-#include linux/signal.h
-#include linux/platform_device.h
 #include linux/clk.h
+#include linux/dma-mapping.h
+#include linux/io.h
+#include linux/kernel.h
+#include linux/module.h
 #include linux/of.h
+#include linux/platform_device.h
+#include linux/signal.h
+#include linux/usb.h
+#include linux/usb/hcd.h
+
+#include ohci.h
 
+#define DRIVER_DESC OHCI SPEAr driver
+
+static const char hcd_name[] = SPEAr-ohci;
 struct spear_ohci {
-   struct ohci_hcd ohci;
struct clk *clk;
 };
 
-#define to_spear_ohci(hcd) (struct spear_ohci *)hcd_to_ohci(hcd)
-
-static void spear_start_ohci(struct spear_ohci *ohci)
-{
-   clk_prepare_enable(ohci-clk);
-}
-
-static void spear_stop_ohci(struct spear_ohci *ohci)
-{
-   clk_disable_unprepare(ohci-clk);
-}
-
-static int ohci_spear_start(struct usb_hcd *hcd)
-{
-   struct ohci_hcd *ohci = hcd_to_ohci(hcd);
-   int ret;
-
-   ret = ohci_init(ohci);
-   if (ret  0)
-   return ret;
-   ohci-regs = hcd-regs;
-
-   ret = ohci_run(ohci);
-   if (ret  0) {
-   dev_err(hcd-self.controller, can't start\n);
-   ohci_stop(hcd);
-   return ret;
-   }
-
-   create_debug_files(ohci);
-
-#ifdef DEBUG
-   ohci_dump(ohci, 1);

[PATCH V3 2/6] USB: OHCI: make ohci-omap a separate driver

2013-06-25 Thread Manjunath Goudar
Separate the  TI OHCI OMAP1/2 host controller driver from ohci-hcd
host code so that it can be built as a separate driver module.
This work is part of enabling multi-platform kernels on ARM;
it would be nice to have in 3.11.

Signed-off-by: Manjunath Goudar manjunath.gou...@linaro.org
Cc: Felipe Balbi ba...@ti.com
Cc: Arnd Bergmann a...@arndb.de
Cc: Greg KH g...@kroah.com
Cc: Alan Stern st...@rowland.harvard.edu
Cc: linux-usb@vger.kernel.org

V2:
 -omap_ohci_clock_power(0) called in usb_hcd_omap_remove().
 -Removed ohci_setup() call from usb_hcd_omap_probe().
 -host_enabled and host_initialized variables aren't used for anything
  thats what removed.

V3:
 -rewritten if (config-otg || config-rwc) block statements into
  two separate 'if blocks' to handle below scenarios
  1. config-otg set scenario.
  2. if any of these (config-otg, config-rwc) are set, this
 scenario should be handled only after ohci_setup()
---
 drivers/usb/host/Kconfig |2 +-
 drivers/usb/host/Makefile|1 +
 drivers/usb/host/ohci-hcd.c  |   18 -
 drivers/usb/host/ohci-omap.c |  157 +++---
 4 files changed, 56 insertions(+), 122 deletions(-)

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 75456f2..7a87c72 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -376,7 +376,7 @@ config USB_OHCI_HCD
 if USB_OHCI_HCD
 
 config USB_OHCI_HCD_OMAP1
-   bool OHCI support for OMAP1/2 chips
+   tristate OHCI support for OMAP1/2 chips
depends on ARCH_OMAP1
default y
---help---
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index bf4a4b2..52f2c44 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -46,6 +46,7 @@ obj-$(CONFIG_USB_OHCI_HCD)+= ohci-hcd.o
 obj-$(CONFIG_USB_OHCI_HCD_PCI) += ohci-pci.o
 obj-$(CONFIG_USB_OHCI_HCD_PLATFORM)+= ohci-platform.o
 obj-$(CONFIG_USB_OHCI_EXYNOS)  += ohci-exynos.o
+obj-$(CONFIG_USB_OHCI_HCD_OMAP1)   += ohci-omap.o
 
 obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o
 obj-$(CONFIG_USB_FHCI_HCD) += fhci.o
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 2980bb6..1abc1e7 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -1182,11 +1182,6 @@ MODULE_LICENSE (GPL);
 #define S3C2410_PLATFORM_DRIVERohci_hcd_s3c2410_driver
 #endif
 
-#ifdef CONFIG_USB_OHCI_HCD_OMAP1
-#include ohci-omap.c
-#define OMAP1_PLATFORM_DRIVER  ohci_hcd_omap_driver
-#endif
-
 #ifdef CONFIG_USB_OHCI_HCD_OMAP3
 #include ohci-omap3.c
 #define OMAP3_PLATFORM_DRIVER  ohci_hcd_omap3_driver
@@ -1289,12 +1284,6 @@ static int __init ohci_hcd_mod_init(void)
goto error_platform;
 #endif
 
-#ifdef OMAP1_PLATFORM_DRIVER
-   retval = platform_driver_register(OMAP1_PLATFORM_DRIVER);
-   if (retval  0)
-   goto error_omap1_platform;
-#endif
-
 #ifdef OMAP3_PLATFORM_DRIVER
retval = platform_driver_register(OMAP3_PLATFORM_DRIVER);
if (retval  0)
@@ -1408,10 +1397,6 @@ static int __init ohci_hcd_mod_init(void)
platform_driver_unregister(OMAP3_PLATFORM_DRIVER);
  error_omap3_platform:
 #endif
-#ifdef OMAP1_PLATFORM_DRIVER
-   platform_driver_unregister(OMAP1_PLATFORM_DRIVER);
- error_omap1_platform:
-#endif
 #ifdef PLATFORM_DRIVER
platform_driver_unregister(PLATFORM_DRIVER);
  error_platform:
@@ -1466,9 +1451,6 @@ static void __exit ohci_hcd_mod_exit(void)
 #ifdef OMAP3_PLATFORM_DRIVER
platform_driver_unregister(OMAP3_PLATFORM_DRIVER);
 #endif
-#ifdef OMAP1_PLATFORM_DRIVER
-   platform_driver_unregister(OMAP1_PLATFORM_DRIVER);
-#endif
 #ifdef PLATFORM_DRIVER
platform_driver_unregister(PLATFORM_DRIVER);
 #endif
diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c
index 8747fa6..10ba58d 100644
--- a/drivers/usb/host/ohci-omap.c
+++ b/drivers/usb/host/ohci-omap.c
@@ -14,12 +14,21 @@
  * This file is licenced under the GPL.
  */
 
-#include linux/signal.h
-#include linux/jiffies.h
-#include linux/platform_device.h
 #include linux/clk.h
+#include linux/dma-mapping.h
 #include linux/err.h
 #include linux/gpio.h
+#include linux/io.h
+#include linux/jiffies.h
+#include linux/kernel.h
+#include linux/module.h
+#include linux/usb/otg.h
+#include linux/platform_device.h
+#include linux/signal.h
+#include linux/usb.h
+#include linux/usb/hcd.h
+
+#include ohci.h
 
 #include asm/io.h
 #include asm/mach-types.h
@@ -42,10 +51,7 @@
 #define OMAP1510_LB_MMU_RAM_H  0xfffec234
 #define OMAP1510_LB_MMU_RAM_L  0xfffec238
 
-
-#ifndef CONFIG_ARCH_OMAP
-#error This file is OMAP bus glue.  CONFIG_OMAP must be defined.
-#endif
+#define DRIVER_DESC OHCI OMAP driver
 
 #ifdef CONFIG_TPS65010
 #include linux/i2c/tps65010.h
@@ -68,8 +74,9 @@ extern int ocpi_enable(void);
 
 static struct clk *usb_host_ck;
 static struct clk *usb_dc_ck;
-static int host_enabled;
-static int host_initialized;
+
+static const char hcd_name[] = ohci-omap;
+static 

[PATCH V3 5/6] USB: OHCI: make ohci-at91 a separate driver

2013-06-25 Thread Manjunath Goudar
Separate the  TI OHCI Atmel host controller driver from ohci-hcd
host code so that it can be built as a separate driver module.
This work is part of enabling multi-platform kernels on ARM;
it would be nice to have in 3.11.

Signed-off-by: Manjunath Goudar manjunath.gou...@linaro.org
Cc: Arnd Bergmann a...@arndb.de
Cc: Alan Stern st...@rowland.harvard.edu
Cc: Greg KH g...@kroah.com
Cc: linux-usb@vger.kernel.org

V2:
 -Set non-standard fields in ohci_at91_hc_driver manually, rather than
  relying on an expanded struct ohci_driver_overrides.
 -Save orig_ohci_hub_control and orig_ohci_hub_status_data rather than
  relying on ohci_hub_control and hub_status_data being exported.
 -ohci_setup() has been removed because it is called in .reset member
  of the ohci_hc_driver structure.

V3:
 -The ohci_restart() function is not required in  current scenario,
  only discarding connection state of integrated transceivers is sufficient,
  for this directly handling ohci-hc_control.
---
 drivers/usb/host/Kconfig |8 +++
 drivers/usb/host/Makefile|1 +
 drivers/usb/host/ohci-at91.c |  151 +++---
 drivers/usb/host/ohci-hcd.c  |   18 -
 4 files changed, 77 insertions(+), 101 deletions(-)

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 46c2f42..e4dc9ab 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -390,6 +390,14 @@ config USB_OHCI_HCD_SPEAR
   Enables support for the on-chip OHCI controller on
   ST SPEAr chips.
 
+config USB_OHCI_HCD_AT91
+tristate  Support for Atmel on-chip OHCI USB controller
+depends on USB_OHCI_HCD  ARCH_AT91
+default y
+---help---
+  Enables support for the on-chip OHCI controller on
+  Atmel chips.
+
 config USB_OHCI_HCD_OMAP3
tristate OHCI support for OMAP3 and later chips
depends on (ARCH_OMAP3 || ARCH_OMAP4)
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index 26cb6b3..f3e02c0 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -49,6 +49,7 @@ obj-$(CONFIG_USB_OHCI_EXYNOS) += ohci-exynos.o
 obj-$(CONFIG_USB_OHCI_HCD_OMAP1)   += ohci-omap.o
 obj-$(CONFIG_USB_OHCI_HCD_OMAP3)   += ohci-omap3.o
 obj-$(CONFIG_USB_OHCI_HCD_SPEAR)   += ohci-spear.o
+obj-$(CONFIG_USB_OHCI_HCD_AT91)+= ohci-at91.o
 
 obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o
 obj-$(CONFIG_USB_FHCI_HCD) += fhci.o
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 2ee1496..4c01759 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -13,27 +13,41 @@
  */
 
 #include linux/clk.h
-#include linux/platform_device.h
+#include linux/dma-mapping.h
 #include linux/of_platform.h
 #include linux/of_gpio.h
+#include linux/platform_device.h
 #include linux/platform_data/atmel.h
+#include linux/io.h
+#include linux/kernel.h
+#include linux/module.h
+#include linux/usb.h
+#include linux/usb/hcd.h
 
 #include mach/hardware.h
 #include asm/gpio.h
 
 #include mach/cpu.h
 
-#ifndef CONFIG_ARCH_AT91
-#error CONFIG_ARCH_AT91 must be defined.
-#endif
+
+#include ohci.h
 
 #define valid_port(index)  ((index) = 0  (index)  AT91_MAX_USBH_PORTS)
 #define at91_for_each_port(index)  \
for ((index) = 0; (index)  AT91_MAX_USBH_PORTS; (index)++)
 
 /* interface and function clocks; sometimes also an AHB clock */
+
+#define DRIVER_DESC OHCI Atmel driver
+
+static const char hcd_name[] = ohci-atmel;
+
+static struct hc_driver __read_mostly ohci_at91_hc_driver;
 static struct clk *iclk, *fclk, *hclk;
 static int clocked;
+static int (*orig_ohci_hub_control)(struct usb_hcd  *hcd, u16 typeReq, u16 
wValue,
+   u16 wIndex, char *buf, u16 wLength);
+static int (*orig_ohci_hub_status_data)(struct usb_hcd *hcd, char *buf);
 
 extern int usb_disabled(void);
 
@@ -111,6 +125,8 @@ static void usb_hcd_at91_remove (struct usb_hcd *, struct 
platform_device *);
 static int usb_hcd_at91_probe(const struct hc_driver *driver,
struct platform_device *pdev)
 {
+   struct at91_usbh_data *board;
+   struct ohci_hcd *ohci;
int retval;
struct usb_hcd *hcd = NULL;
 
@@ -163,8 +179,10 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
goto err5;
}
 
+   board = hcd-self.controller-platform_data;
+   ohci = hcd_to_ohci(hcd);
+   ohci-num_ports = board-ports;
at91_start_hc(pdev);
-   ohci_hcd_init(hcd_to_ohci(hcd));
 
retval = usb_add_hcd(hcd, pdev-resource[1].start, IRQF_SHARED);
if (retval == 0)
@@ -221,36 +239,6 @@ static void usb_hcd_at91_remove(struct usb_hcd *hcd,
 }
 
 /*-*/
-
-static int
-ohci_at91_reset (struct usb_hcd *hcd)
-{
-   struct at91_usbh_data   *board = hcd-self.controller-platform_data;
-   struct ohci_hcd *ohci = 

[PATCH V3 6/6] USB: OHCI: make ohci-s3c2410 a separate driver

2013-06-25 Thread Manjunath Goudar
Separate the Samsung OHCI S3C host controller driver from ohci-hcd
host code so that it can be built as a separate driver module.
This work is part of enabling multi-platform kernels on ARM;
it would be nice to have in 3.11.

Signed-off-by: Manjunath Goudar manjunath.gou...@linaro.org
Cc: Arnd Bergmann a...@arndb.de
Cc: Alan Stern st...@rowland.harvard.edu
Cc: Greg KH g...@kroah.com
Cc: linux-usb@vger.kernel.org

V2:
 -Set non-standard fields in ohci_s3c2410_hc_driver manually, rather than
  relying on an expanded struct ohci_driver_overrides.
 -Save orig_ohci_hub_control and orig_ohci_hub_status_data rather than
  relying on ohci_hub_control and hub_status_data being exported.

V3:
 -Kconfig wrong parentheses discription fixed.
 -ohci_setup() has been removed because it is called in .reset member
  of the ohci_hc_driver structure.
---
 drivers/usb/host/Kconfig|8 +++
 drivers/usb/host/Makefile   |1 +
 drivers/usb/host/ohci-hcd.c |   18 --
 drivers/usb/host/ohci-s3c2410.c |  128 +--
 4 files changed, 66 insertions(+), 89 deletions(-)

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index e4dc9ab..f19524f 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -390,6 +390,14 @@ config USB_OHCI_HCD_SPEAR
   Enables support for the on-chip OHCI controller on
   ST SPEAr chips.
 
+config USB_OHCI_HCD_S3C
+tristate Support for S3C on-chip OHCI USB controller
+depends on USB_OHCI_HCD  (ARCH_S3C24XX || ARCH_S3C64XX)
+default y
+---help---
+  Enables support for the on-chip OHCI controller on
+  S3C chips.
+
 config USB_OHCI_HCD_AT91
 tristate  Support for Atmel on-chip OHCI USB controller
 depends on USB_OHCI_HCD  ARCH_AT91
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index f3e02c0..9fa4b3e 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -50,6 +50,7 @@ obj-$(CONFIG_USB_OHCI_HCD_OMAP1)  += ohci-omap.o
 obj-$(CONFIG_USB_OHCI_HCD_OMAP3)   += ohci-omap3.o
 obj-$(CONFIG_USB_OHCI_HCD_SPEAR)   += ohci-spear.o
 obj-$(CONFIG_USB_OHCI_HCD_AT91)+= ohci-at91.o
+obj-$(CONFIG_USB_OHCI_HCD_S3C) += ohci-s3c2410.o
 
 obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o
 obj-$(CONFIG_USB_FHCI_HCD) += fhci.o
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index b48c892..b69a49e 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -1177,11 +1177,6 @@ MODULE_LICENSE (GPL);
 #define SA_DRIVER  ohci_hcd_sa_driver
 #endif
 
-#if defined(CONFIG_ARCH_S3C24XX) || defined(CONFIG_ARCH_S3C64XX)
-#include ohci-s3c2410.c
-#define S3C2410_PLATFORM_DRIVERohci_hcd_s3c2410_driver
-#endif
-
 #if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx)
 #include ohci-pxa27x.c
 #define PLATFORM_DRIVERohci_hcd_pxa27x_driver
@@ -1293,12 +1288,6 @@ static int __init ohci_hcd_mod_init(void)
goto error_tmio;
 #endif
 
-#ifdef S3C2410_PLATFORM_DRIVER
-   retval = platform_driver_register(S3C2410_PLATFORM_DRIVER);
-   if (retval  0)
-   goto error_s3c2410;
-#endif
-
 #ifdef EP93XX_PLATFORM_DRIVER
retval = platform_driver_register(EP93XX_PLATFORM_DRIVER);
if (retval  0)
@@ -1332,10 +1321,6 @@ static int __init ohci_hcd_mod_init(void)
platform_driver_unregister(EP93XX_PLATFORM_DRIVER);
  error_ep93xx:
 #endif
-#ifdef S3C2410_PLATFORM_DRIVER
-   platform_driver_unregister(S3C2410_PLATFORM_DRIVER);
- error_s3c2410:
-#endif
 #ifdef TMIO_OHCI_DRIVER
platform_driver_unregister(TMIO_OHCI_DRIVER);
  error_tmio:
@@ -1382,9 +1367,6 @@ static void __exit ohci_hcd_mod_exit(void)
 #ifdef EP93XX_PLATFORM_DRIVER
platform_driver_unregister(EP93XX_PLATFORM_DRIVER);
 #endif
-#ifdef S3C2410_PLATFORM_DRIVER
-   platform_driver_unregister(S3C2410_PLATFORM_DRIVER);
-#endif
 #ifdef TMIO_OHCI_DRIVER
platform_driver_unregister(TMIO_OHCI_DRIVER);
 #endif
diff --git a/drivers/usb/host/ohci-s3c2410.c b/drivers/usb/host/ohci-s3c2410.c
index e125770..b0f6644 100644
--- a/drivers/usb/host/ohci-s3c2410.c
+++ b/drivers/usb/host/ohci-s3c2410.c
@@ -19,17 +19,34 @@
  * This file is licenced under the GPL.
 */
 
-#include linux/platform_device.h
 #include linux/clk.h
+#include linux/io.h
+#include linux/kernel.h
+#include linux/module.h
+#include linux/platform_device.h
 #include linux/platform_data/usb-ohci-s3c2410.h
+#include linux/usb.h
+#include linux/usb/hcd.h
+
+#include ohci.h
+
 
 #define valid_port(idx) ((idx) == 1 || (idx) == 2)
 
 /* clock device associated with the hcd */
 
+
+#define DRIVER_DESC OHCI S3C driver
+
+static const char hcd_name[] = ohci-s3c;
+
 static struct clk *clk;
 static struct clk *usb_clk;
 
+static int (*orig_ohci_hub_control)(struct usb_hcd  *hcd, u16 typeReq,
+   u16 wValue, u16 wIndex, char *buf, u16 

[PATCH V3 3/6] USB: OHCI: make ohci-omap3 a separate driver

2013-06-25 Thread Manjunath Goudar
Separate the  TI OHCI OMAP3 host controller driver from ohci-hcd
host code so that it can be built as a separate driver module.
This work is part of enabling multi-platform kernels on ARM;
it would be nice to have in 3.11.

Signed-off-by: Manjunath Goudar manjunath.gou...@linaro.org
Cc: Anand Gadiyar gadi...@ti.com
Cc: Felipe Balbi ba...@ti.com
Cc: Arnd Bergmann a...@arndb.de
Cc: Greg KH g...@kroah.com
Cc: Alan Stern st...@rowland.harvard.edu
Cc: linux-usb@vger.kernel.org

V2:
 -ohci_setup() removed because it is called in .reset member
  of the ohci_hc_driver structure.
 -The improper multi-line commenting style written in proper way.
  ('*' characters aligned in vertically).

V3:
 -RemoteWakeupConnected setting has been removed.
---
 drivers/usb/host/Kconfig  |2 +-
 drivers/usb/host/Makefile |1 +
 drivers/usb/host/ohci-hcd.c   |   18 ---
 drivers/usb/host/ohci-omap3.c |  113 -
 4 files changed, 34 insertions(+), 100 deletions(-)

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 7a87c72..db20e43 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -383,7 +383,7 @@ config USB_OHCI_HCD_OMAP1
  Enables support for the OHCI controller on OMAP1/2 chips.
 
 config USB_OHCI_HCD_OMAP3
-   bool OHCI support for OMAP3 and later chips
+   tristate OHCI support for OMAP3 and later chips
depends on (ARCH_OMAP3 || ARCH_OMAP4)
default y
---help---
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index 52f2c44..9f2f5f3 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -47,6 +47,7 @@ obj-$(CONFIG_USB_OHCI_HCD_PCI)+= ohci-pci.o
 obj-$(CONFIG_USB_OHCI_HCD_PLATFORM)+= ohci-platform.o
 obj-$(CONFIG_USB_OHCI_EXYNOS)  += ohci-exynos.o
 obj-$(CONFIG_USB_OHCI_HCD_OMAP1)   += ohci-omap.o
+obj-$(CONFIG_USB_OHCI_HCD_OMAP3)   += ohci-omap3.o
 
 obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o
 obj-$(CONFIG_USB_FHCI_HCD) += fhci.o
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 1abc1e7..cad51d2 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -1182,11 +1182,6 @@ MODULE_LICENSE (GPL);
 #define S3C2410_PLATFORM_DRIVERohci_hcd_s3c2410_driver
 #endif
 
-#ifdef CONFIG_USB_OHCI_HCD_OMAP3
-#include ohci-omap3.c
-#define OMAP3_PLATFORM_DRIVER  ohci_hcd_omap3_driver
-#endif
-
 #if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx)
 #include ohci-pxa27x.c
 #define PLATFORM_DRIVERohci_hcd_pxa27x_driver
@@ -1284,12 +1279,6 @@ static int __init ohci_hcd_mod_init(void)
goto error_platform;
 #endif
 
-#ifdef OMAP3_PLATFORM_DRIVER
-   retval = platform_driver_register(OMAP3_PLATFORM_DRIVER);
-   if (retval  0)
-   goto error_omap3_platform;
-#endif
-
 #ifdef OF_PLATFORM_DRIVER
retval = platform_driver_register(OF_PLATFORM_DRIVER);
if (retval  0)
@@ -1393,10 +1382,6 @@ static int __init ohci_hcd_mod_init(void)
platform_driver_unregister(OF_PLATFORM_DRIVER);
  error_of_platform:
 #endif
-#ifdef OMAP3_PLATFORM_DRIVER
-   platform_driver_unregister(OMAP3_PLATFORM_DRIVER);
- error_omap3_platform:
-#endif
 #ifdef PLATFORM_DRIVER
platform_driver_unregister(PLATFORM_DRIVER);
  error_platform:
@@ -1448,9 +1433,6 @@ static void __exit ohci_hcd_mod_exit(void)
 #ifdef OF_PLATFORM_DRIVER
platform_driver_unregister(OF_PLATFORM_DRIVER);
 #endif
-#ifdef OMAP3_PLATFORM_DRIVER
-   platform_driver_unregister(OMAP3_PLATFORM_DRIVER);
-#endif
 #ifdef PLATFORM_DRIVER
platform_driver_unregister(PLATFORM_DRIVER);
 #endif
diff --git a/drivers/usb/host/ohci-omap3.c b/drivers/usb/host/ohci-omap3.c
index 8f71357..f2de21b 100644
--- a/drivers/usb/host/ohci-omap3.c
+++ b/drivers/usb/host/ohci-omap3.c
@@ -29,90 +29,22 @@
  * - add kernel-doc
  */
 
+#include linux/dma-mapping.h
+#include linux/kernel.h
+#include linux/module.h
+#include linux/of.h
+#include linux/usb/otg.h
 #include linux/platform_device.h
 #include linux/pm_runtime.h
-#include linux/of.h
-#include linux/dma-mapping.h
-
-/*-*/
-
-static int ohci_omap3_init(struct usb_hcd *hcd)
-{
-   dev_dbg(hcd-self.controller, starting OHCI controller\n);
-
-   return ohci_init(hcd_to_ohci(hcd));
-}
-
-/*-*/
-
-static int ohci_omap3_start(struct usb_hcd *hcd)
-{
-   struct ohci_hcd *ohci = hcd_to_ohci(hcd);
-   int ret;
-
-   /*
-* RemoteWakeupConnected has to be set explicitly before
-* calling ohci_run. The reset value of RWC is 0.
-*/
-   ohci-hc_control = OHCI_CTRL_RWC;
-   writel(OHCI_CTRL_RWC, ohci-regs-control);
-
-   ret = ohci_run(ohci);
-
-   if (ret  0) {
-   dev_err(hcd-self.controller, can't start\n);
-   ohci_stop(hcd);

[PATCH V3 0/6] USB: OHCI: more bus glues as separate modules

2013-06-25 Thread Manjunath Goudar
These patches are for separating the SOC On-Chip ohci host controller
from ohci-hcd host code into its own driver module.
This work is part of enabling multi-platform kernels on ARM;
it would be nice to have in 3.11.

V2:
  In patch 5/6 and 6/6:
  -Set non-standard fields in hc_driver manually, rather than
   relying on an expanded struct ohci_driver_overrides.
  -Save orig_ohci_hub_control and orig_ohci_hub_status_data rather than
   relying on ohci_hub_control and hub_status_data being exported.

  In patch 1/6 to 4/6
  -ohci_setup() has been removed because it is called in .reset member
   of the ohci_hc_driver structure.

V3:
 In patch 5/6 and 6/6:
 -ohci_setup() has been removed because it is called in .reset member
  of the ohci_hc_driver structure.
 
 In patch 5/6:
 -The ohci_restart() function is not required in  current scenario,
  only discarding connection state of integrated transceivers is sufficient,
  for this directly handling ohci-hc_control.
 
 In patch 2/6 :
 -rewritten if (config-otg || config-rwc) block statements into
  two separate 'if blocks' to handle below scenarios
  1. config-otg set scenario.
  2. if any of these (config-otg, config-rwc) are set, this
 scenario should be handled only after ohci_setup()

 In patch 1/6 and 4/6:
  No change. 

Manjunath Goudar (6):
  USB: OHCI: make ohci-exynos a separate driver
  USB: OHCI: make ohci-omap a separate driver
  USB: OHCI: make ohci-omap3 a separate driver
  USB: OHCI: make ohci-spear a separate driver
  USB: OHCI: make ohci-at91 a separate driver
  USB: OHCI: make ohci-s3c2410 a separate driver

 drivers/usb/host/Kconfig|   30 ++-
 drivers/usb/host/Makefile   |6 ++
 drivers/usb/host/ohci-at91.c|  151 ---
 drivers/usb/host/ohci-exynos.c  |  167 ---
 drivers/usb/host/ohci-hcd.c |  108 -
 drivers/usb/host/ohci-omap.c|  157 +---
 drivers/usb/host/ohci-omap3.c   |  113 --
 drivers/usb/host/ohci-s3c2410.c |  128 +-
 drivers/usb/host/ohci-spear.c   |  140 +---
 9 files changed, 369 insertions(+), 631 deletions(-)

-- 
1.7.9.5

--
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 1/6] USB: OHCI: make ohci-exynos a separate driver

2013-06-25 Thread Manjunath Goudar
Separate the  Samsung OHCI EXYNOS host controller driver from ohci-hcd
host code so that it can be built as a separate driver module.
This work is part of enabling multi-platform kernels on ARM;
it would be nice to have in 3.11.

Signed-off-by: Manjunath Goudar manjunath.gou...@linaro.org
Acked-by: Alan Stern st...@rowland.harvard.edu
Acked-by: Jingoo Han jg1@samsung.com
Cc: Vivek Gautam gautam.vi...@samsung.com
Cc: Arnd Bergmann a...@arndb.de
Cc: Kukjin Kim kgene@samsung.com
Cc: Greg KH g...@kroah.com
Cc: linux-usb@vger.kernel.org

V2:
 -exynos_ohci_hcd structure assignment error fixed.
 -Removed multiple usb_create_hcd() from prob funtion.
 -platform_set_drvdata() called before exynos_ohci_phy_enable().
 -ohci_setup() removed because it is called in .reset member
  of the ohci_hc_driver structure

V3:
 -No major changes only exynos written in capital letters
  in OHCI exynos driver.
---
 drivers/usb/host/Kconfig   |2 +-
 drivers/usb/host/Makefile  |1 +
 drivers/usb/host/ohci-exynos.c |  167 +---
 drivers/usb/host/ohci-hcd.c|   18 -
 4 files changed, 71 insertions(+), 117 deletions(-)

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index f35f71e..75456f2 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -463,7 +463,7 @@ config USB_OHCI_SH
  If you use the PCI OHCI controller, this option is not necessary.
 
 config USB_OHCI_EXYNOS
-   boolean OHCI support for Samsung EXYNOS SoC Series
+   tristate OHCI support for Samsung EXYNOS SoC Series
depends on ARCH_EXYNOS
help
 Enable support for the Samsung Exynos SOC's on-chip OHCI controller.
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index d1a34e0..bf4a4b2 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -45,6 +45,7 @@ obj-$(CONFIG_USB_ISP1362_HCD) += isp1362-hcd.o
 obj-$(CONFIG_USB_OHCI_HCD) += ohci-hcd.o
 obj-$(CONFIG_USB_OHCI_HCD_PCI) += ohci-pci.o
 obj-$(CONFIG_USB_OHCI_HCD_PLATFORM)+= ohci-platform.o
+obj-$(CONFIG_USB_OHCI_EXYNOS)  += ohci-exynos.o
 
 obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o
 obj-$(CONFIG_USB_FHCI_HCD) += fhci.o
diff --git a/drivers/usb/host/ohci-exynos.c b/drivers/usb/host/ohci-exynos.c
index b0b542c..ae6068d 100644
--- a/drivers/usb/host/ohci-exynos.c
+++ b/drivers/usb/host/ohci-exynos.c
@@ -12,24 +12,39 @@
  */
 
 #include linux/clk.h
+#include linux/dma-mapping.h
+#include linux/io.h
+#include linux/kernel.h
+#include linux/module.h
 #include linux/of.h
 #include linux/platform_device.h
 #include linux/platform_data/usb-ohci-exynos.h
 #include linux/usb/phy.h
 #include linux/usb/samsung_usb_phy.h
+#include linux/usb.h
+#include linux/usb/hcd.h
+#include linux/usb/otg.h
+
+#include ohci.h
+
+#define DRIVER_DESC OHCI EXYNOS driver
+
+static const char hcd_name[] = ohci-exynos;
+static struct hc_driver __read_mostly exynos_ohci_hc_driver;
+
+#define to_exynos_ohci(hcd) (struct exynos_ohci_hcd *)(hcd_to_ohci(hcd)-priv)
 
 struct exynos_ohci_hcd {
-   struct device *dev;
-   struct usb_hcd *hcd;
struct clk *clk;
struct usb_phy *phy;
struct usb_otg *otg;
struct exynos4_ohci_platdata *pdata;
 };
 
-static void exynos_ohci_phy_enable(struct exynos_ohci_hcd *exynos_ohci)
+static void exynos_ohci_phy_enable(struct platform_device *pdev)
 {
-   struct platform_device *pdev = to_platform_device(exynos_ohci-dev);
+   struct usb_hcd *hcd = platform_get_drvdata(pdev);
+   struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd);
 
if (exynos_ohci-phy)
usb_phy_init(exynos_ohci-phy);
@@ -37,9 +52,10 @@ static void exynos_ohci_phy_enable(struct exynos_ohci_hcd 
*exynos_ohci)
exynos_ohci-pdata-phy_init(pdev, USB_PHY_TYPE_HOST);
 }
 
-static void exynos_ohci_phy_disable(struct exynos_ohci_hcd *exynos_ohci)
+static void exynos_ohci_phy_disable(struct platform_device *pdev)
 {
-   struct platform_device *pdev = to_platform_device(exynos_ohci-dev);
+   struct usb_hcd *hcd = platform_get_drvdata(pdev);
+   struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd);
 
if (exynos_ohci-phy)
usb_phy_shutdown(exynos_ohci-phy);
@@ -47,63 +63,11 @@ static void exynos_ohci_phy_disable(struct exynos_ohci_hcd 
*exynos_ohci)
exynos_ohci-pdata-phy_exit(pdev, USB_PHY_TYPE_HOST);
 }
 
-static int ohci_exynos_reset(struct usb_hcd *hcd)
-{
-   return ohci_init(hcd_to_ohci(hcd));
-}
-
-static int ohci_exynos_start(struct usb_hcd *hcd)
-{
-   struct ohci_hcd *ohci = hcd_to_ohci(hcd);
-   int ret;
-
-   ohci_dbg(ohci, ohci_exynos_start, ohci:%p, ohci);
-
-   ret = ohci_run(ohci);
-   if (ret  0) {
-   dev_err(hcd-self.controller, can't start %s\n,
-   hcd-self.bus_name);
-   ohci_stop(hcd);
-   return ret;
-   }
-
-   return 0;
-}
-
-static 

[PATCH V4 05/11] USB: OHCI: Properly handle ohci-ep93xx suspend

2013-06-25 Thread Manjunath Goudar
Suspend scenario in case of ohci-ep93xx glue was not
properly handled as it was not suspending generic part
of ohci controller. Calling explicitly the ohci_suspend()
routine in ohci_hcd_ep93xx_drv_suspend() will ensure proper
handling of suspend scenario.

Signed-off-by: Manjunath Goudar manjunath.gou...@linaro.org
Acked-by: Alan Stern st...@rowland.harvard.edu
Cc: Arnd Bergmann a...@arndb.de
Cc: Greg KH g...@kroah.com
Cc: linux-usb@vger.kernel.org

V2:
 -Incase ohci_suspend() fails, return right away without
  executing further.
V3:
 -Aligned variable do_wakeup and ret.
V4:
 -The do_wakeup and ret variable alignment is removed.
---
 drivers/usb/host/ohci-ep93xx.c |9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/ohci-ep93xx.c b/drivers/usb/host/ohci-ep93xx.c
index 8704e9f..f0aaa48 100644
--- a/drivers/usb/host/ohci-ep93xx.c
+++ b/drivers/usb/host/ohci-ep93xx.c
@@ -174,13 +174,20 @@ static int ohci_hcd_ep93xx_drv_suspend(struct 
platform_device *pdev, pm_message_
 {
struct usb_hcd *hcd = platform_get_drvdata(pdev);
struct ohci_hcd *ohci = hcd_to_ohci(hcd);
+   bool do_wakeup = device_may_wakeup(pdev-dev);
+   int ret;
 
if (time_before(jiffies, ohci-next_statechange))
msleep(5);
ohci-next_statechange = jiffies;
 
+   ret = ohci_suspend(hcd, do_wakeup);
+   if (ret)
+   return ret;
+
ep93xx_stop_hc(pdev-dev);
-   return 0;
+
+   return ret;
 }
 
 static int ohci_hcd_ep93xx_drv_resume(struct platform_device *pdev)
-- 
1.7.9.5

--
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 02/11] USB: OHCI: Properly handle ohci-at91 suspend

2013-06-25 Thread Manjunath Goudar
Suspend scenario in case of ohci-at91 glue was not properly
handled as it was not suspending generic part of ohci controller.
Calling explicitly the ohci_suspend() routine in ohci_hcd_at91_drv_suspend()
will ensure proper handling of suspend scenario.

Signed-off-by: Manjunath Goudar manjunath.gou...@linaro.org
Acked-by: Alan Stern st...@rowland.harvard.edu
Cc: Arnd Bergmann a...@arndb.de
Cc: Greg KH g...@kroah.com
Cc: linux-usb@vger.kernel.org

V2:
  -Incase ohci_suspend() fails, return right away without executing further.

V3:
  -Aligned variable do_wakeup and ret.

V4:
  - No change.
---
 drivers/usb/host/ohci-at91.c |   10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 4c01759..09f17d1 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -618,8 +618,14 @@ ohci_hcd_at91_drv_suspend(struct platform_device *pdev, 
pm_message_t mesg)
 {
struct usb_hcd  *hcd = platform_get_drvdata(pdev);
struct ohci_hcd *ohci = hcd_to_ohci(hcd);
+   booldo_wakeup = device_may_wakeup(pdev-dev);
+   int ret;
 
-   if (device_may_wakeup(pdev-dev))
+   ret = ohci_suspend(hcd, do_wakeup);
+   if (ret)
+   return ret;
+
+   if (do_wakeup)
enable_irq_wake(hcd-irq);
 
/*
@@ -640,7 +646,7 @@ ohci_hcd_at91_drv_suspend(struct platform_device *pdev, 
pm_message_t mesg)
at91_stop_clock();
}
 
-   return 0;
+   return ret;
 }
 
 static int ohci_hcd_at91_drv_resume(struct platform_device *pdev)
-- 
1.7.9.5

--
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 01/11] USB: OHCI: Properly handle OHCI controller suspend

2013-06-25 Thread Manjunath Goudar
Suspend scenario in case of OHCI was not properly
handled in ochi_suspend()routine. This does proper
handling of suspend scenario.

Signed-off-by: Manjunath Goudar manjunath.gou...@linaro.org
Acked-by: Alan Stern st...@rowland.harvard.edu
Cc: Arnd Bergmann a...@arndb.de
Cc: Greg KH g...@kroah.com
Cc: linux-usb@vger.kernel.org

V3: New patch.

V4: No change.
---
 drivers/usb/host/ohci-hcd.c |9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index b69a49e..f3dcaa2 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -1034,6 +1034,7 @@ int ohci_suspend(struct usb_hcd *hcd, bool do_wakeup)
 {
struct ohci_hcd *ohci = hcd_to_ohci (hcd);
unsigned long   flags;
+   int rc = 0;
 
/* Disable irq emission and mark HW unaccessible. Use
 * the spinlock to properly synchronize with possible pending
@@ -1046,7 +1047,13 @@ int ohci_suspend(struct usb_hcd *hcd, bool do_wakeup)
clear_bit(HCD_FLAG_HW_ACCESSIBLE, hcd-flags);
spin_unlock_irqrestore (ohci-lock, flags);
 
-   return 0;
+   synchronize_irq(hcd-irq);
+
+   if (do_wakeup  HCD_WAKEUP_PENDING(hcd)) {
+   ohci_resume(hcd, false);
+   rc = -EBUSY;
+   }
+   return rc;
 }
 EXPORT_SYMBOL_GPL(ohci_suspend);
 
-- 
1.7.9.5

--
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 04/11] USB: OHCI: Properly handle ohci-da8xx suspend

2013-06-25 Thread Manjunath Goudar
Suspend scenario in case of ohci-da8xx glue was not
properly handled as it was not suspending generic part
of ohci controller. Calling explicitly the ohci_suspend()
routine in ohci_da8xx_suspend() will ensure proper
handling of suspend scenario.

Signed-off-by: Manjunath Goudar manjunath.gou...@linaro.org
Acked-by: Alan Stern st...@rowland.harvard.edu
Cc: Arnd Bergmann a...@arndb.de
Cc: Greg KH g...@kroah.com
Cc: linux-usb@vger.kernel.org

V2:
 -Incase ohci_suspend() fails, return right away without
  executing further.

V3:
 -Aligned variable do_wakeup and ret.
 -pdev-dev.power.power_state stuff has been removed.

V4:
 -Properly aligned do_wakeup and ret variable.
---
 drivers/usb/host/ohci-da8xx.c |   15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c
index 6aaa9c9..c649a35 100644
--- a/drivers/usb/host/ohci-da8xx.c
+++ b/drivers/usb/host/ohci-da8xx.c
@@ -406,19 +406,26 @@ static int ohci_hcd_da8xx_drv_remove(struct 
platform_device *dev)
 }
 
 #ifdef CONFIG_PM
-static int ohci_da8xx_suspend(struct platform_device *dev, pm_message_t 
message)
+static int ohci_da8xx_suspend(struct platform_device *pdev,
+   pm_message_t message)
 {
-   struct usb_hcd  *hcd= platform_get_drvdata(dev);
+   struct usb_hcd  *hcd= platform_get_drvdata(pdev);
struct ohci_hcd *ohci   = hcd_to_ohci(hcd);
+   booldo_wakeup   = device_may_wakeup(pdev-dev);
+   int ret;
 
if (time_before(jiffies, ohci-next_statechange))
msleep(5);
ohci-next_statechange = jiffies;
 
+   ret = ohci_suspend(hcd, do_wakeup);
+   if (ret)
+   return ret;
+
ohci_da8xx_clock(0);
hcd-state = HC_STATE_SUSPENDED;
-   dev-dev.power.power_state = PMSG_SUSPEND;
-   return 0;
+
+   return ret;
 }
 
 static int ohci_da8xx_resume(struct platform_device *dev)
-- 
1.7.9.5

--
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 00/11] USB: OHCI:Properly handle ohci_suspend()routine in bus glue

2013-06-25 Thread Manjunath Goudar
Suspend scenario in case of ohci bus glue was not properly handled as
it was not suspending generic part of ohci controller. Calling
explicitly the ohci_suspend()routine will ensure proper handling
of suspend scenario.

V2:
 -Incase ohci_suspend() fails, return right away without executing further.

V3:
 -New patch 1/11 added, for generic ohci-hcd suspend code.

V4:
 -Properly aligned do_wakeup and ret variables.

Manjunath Goudar (11):
  USB: OHCI: Properly handle OHCI controller suspend
  USB: OHCI: Properly handle ohci-at91 suspend
  USB: OHCI: Properly handle ohci-s3c2410 suspend
  USB: OHCI: Properly handle ohci-da8xx suspend
  USB: OHCI: Properly handle ohci-ep93xx suspend
  USB: OHCI: Properly handle ohci-exynos suspend
  USB: OHCI: Properly handle ohci-omap suspend
  USB: OHCI: Properly handle ohci-platform suspend
  USB: OHCI: Properly handle ohci-pxa27x suspend
  USB: OHCI: Properly handle ohci-sm501 suspend
  USB: OHCI: Properly handle ohci-spear suspend

 drivers/usb/host/ohci-at91.c |   10 --
 drivers/usb/host/ohci-da8xx.c|   15 +++
 drivers/usb/host/ohci-ep93xx.c   |9 -
 drivers/usb/host/ohci-exynos.c   |   20 +---
 drivers/usb/host/ohci-hcd.c  |9 -
 drivers/usb/host/ohci-omap.c |   13 ++---
 drivers/usb/host/ohci-platform.c |9 -
 drivers/usb/host/ohci-pxa27x.c   |8 +++-
 drivers/usb/host/ohci-s3c2410.c  |   19 ---
 drivers/usb/host/ohci-sm501.c|   11 +--
 drivers/usb/host/ohci-spear.c|   12 +---
 11 files changed, 87 insertions(+), 48 deletions(-)

-- 
1.7.9.5

--
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 03/11] USB: OHCI: Properly handle ohci-s3c2410 suspend

2013-06-25 Thread Manjunath Goudar
Suspend scenario in case of ohci-s3c2410 glue was not
properly handled as it was not suspending generic part
of ohci controller. Calling explicitly the ohci_suspend()
routine in ohci_hcd_s3c2410_drv_suspend() will ensure
proper handling of suspend scenario.

Signed-off-by: Manjunath Goudar manjunath.gou...@linaro.org
Acked-by: Alan Stern st...@rowland.harvard.edu
Cc: Arnd Bergmann a...@arndb.de
Cc: Greg KH g...@kroah.com
Cc: linux-usb@vger.kernel.org

V2:
 -Incase ohci_suspend() fails, return right away without
  executing further.
V3:
 -rid of unwanted code from ohci_hcd_s3c2410_drv_suspend()
  which already ohci_suspend() does it.

V4:
 -The do_wakeup variable alignment is removed.
---
 drivers/usb/host/ohci-s3c2410.c |   19 ---
 1 file changed, 4 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/host/ohci-s3c2410.c b/drivers/usb/host/ohci-s3c2410.c
index b0f6644..4189aaa 100644
--- a/drivers/usb/host/ohci-s3c2410.c
+++ b/drivers/usb/host/ohci-s3c2410.c
@@ -427,26 +427,15 @@ static int ohci_hcd_s3c2410_drv_suspend(struct device 
*dev)
struct usb_hcd *hcd = dev_get_drvdata(dev);
struct ohci_hcd *ohci = hcd_to_ohci(hcd);
struct platform_device *pdev = to_platform_device(dev);
+   bool do_wakeup = device_may_wakeup(dev);
unsigned long flags;
int rc = 0;
 
-   /*
-* Root hub was already suspended. Disable irq emission and
-* mark HW unaccessible, bail out if RH has been resumed. Use
-* the spinlock to properly synchronize with possible pending
-* RH suspend or resume activity.
-*/
-   spin_lock_irqsave(ohci-lock, flags);
-   if (ohci-rh_state != OHCI_RH_SUSPENDED) {
-   rc = -EINVAL;
-   goto bail;
-   }
-
-   clear_bit(HCD_FLAG_HW_ACCESSIBLE, hcd-flags);
+   rc = ohci_suspend(hcd, do_wakeup);
+   if (rc)
+   return rc;
 
s3c2410_stop_hc(pdev);
-bail:
-   spin_unlock_irqrestore(ohci-lock, flags);
 
return rc;
 }
-- 
1.7.9.5

--
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 07/11] USB: OHCI: Properly handle ohci-omap suspend

2013-06-25 Thread Manjunath Goudar
Suspend scenario in case of ohci-omap glue was not
properly handled as it was not suspending generic part
of ohci controller. Calling explicitly the ohci_suspend()
routine in ohci_omap_suspend() will ensure proper
handling of suspend scenario.

Signed-off-by: Manjunath Goudar manjunath.gou...@linaro.org
Acked-by: Alan Stern st...@rowland.harvard.edu
Cc: Arnd Bergmann a...@arndb.de
Cc: Greg KH g...@kroah.com
Cc: linux-usb@vger.kernel.org

V2:
 -Incase ohci_suspend() fails, return right away without
  executing further.

V3:
 -Aligned variable do_wakeup and ret.

V4:
 -The do_wakeup and ret variable alignment is removed.
---
 drivers/usb/host/ohci-omap.c |   13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c
index 10ba58d..baefc46 100644
--- a/drivers/usb/host/ohci-omap.c
+++ b/drivers/usb/host/ohci-omap.c
@@ -432,16 +432,23 @@ static int ohci_hcd_omap_drv_remove(struct 
platform_device *dev)
 
 #ifdef CONFIG_PM
 
-static int ohci_omap_suspend(struct platform_device *dev, pm_message_t message)
+static int ohci_omap_suspend(struct platform_device *pdev, pm_message_t 
message)
 {
-   struct ohci_hcd *ohci = hcd_to_ohci(platform_get_drvdata(dev));
+   struct usb_hcd *hcd = platform_get_drvdata(pdev);
+   struct ohci_hcd *ohci = hcd_to_ohci(hcd);
+   bool do_wakeup = device_may_wakeup(pdev-dev);
+   int ret;
 
if (time_before(jiffies, ohci-next_statechange))
msleep(5);
ohci-next_statechange = jiffies;
 
+   ret = ohci_suspend(hcd, do_wakeup);
+   if (ret)
+   return ret;
+
omap_ohci_clock_power(0);
-   return 0;
+   return ret;
 }
 
 static int ohci_omap_resume(struct platform_device *dev)
-- 
1.7.9.5

--
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 06/11] USB: OHCI: Properly handle ohci-exynos suspend

2013-06-25 Thread Manjunath Goudar
Suspend scenario in case of ohci-exynos glue was not
properly handled as it was not suspending generic part
of ohci controller. Calling explicitly the ohci_suspend()
routine in exynos_ohci_suspend() will ensure proper
handling of suspend scenario.

Signed-off-by: Manjunath Goudar manjunath.gou...@linaro.org
Acked-by: Alan Stern st...@rowland.harvard.edu
Cc: Arnd Bergmann a...@arndb.de
Cc: Greg KH g...@kroah.com
Cc: linux-usb@vger.kernel.org

V2:
 -Incase ohci_suspend() fails, return right away without
  executing further.

V3:
 -rid of unwanted code from ohci_hcd_s3c2410_drv_suspend() which already
  ohci_suspend() does it.
 -Aligned variable do_wakeup and ret.

V4:
 -The do_wakeup and rc variable alignment is removed.
---
 drivers/usb/host/ohci-exynos.c |   20 +---
 1 file changed, 5 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/host/ohci-exynos.c b/drivers/usb/host/ohci-exynos.c
index ae6068d..17de3dd 100644
--- a/drivers/usb/host/ohci-exynos.c
+++ b/drivers/usb/host/ohci-exynos.c
@@ -203,24 +203,15 @@ static int exynos_ohci_suspend(struct device *dev)
struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd);
struct ohci_hcd *ohci = hcd_to_ohci(hcd);
struct platform_device *pdev = to_platform_device(dev);
+   bool do_wakeup = device_may_wakeup(dev);
unsigned long flags;
int rc = 0;
 
-   /*
-* Root hub was already suspended. Disable irq emission and
-* mark HW unaccessible, bail out if RH has been resumed. Use
-* the spinlock to properly synchronize with possible pending
-* RH suspend or resume activity.
-*/
-   spin_lock_irqsave(ohci-lock, flags);
-   if (ohci-rh_state != OHCI_RH_SUSPENDED 
-   ohci-rh_state != OHCI_RH_HALTED) {
-   rc = -EINVAL;
-   goto fail;
-   }
-
-   clear_bit(HCD_FLAG_HW_ACCESSIBLE, hcd-flags);
+   rc = ohci_suspend(hcd, do_wakeup);
+   if (rc)
+   return rc;
 
+   spin_lock_irqsave(ohci-lock, flags);
if (exynos_ohci-otg)
exynos_ohci-otg-set_host(exynos_ohci-otg, hcd-self);
 
@@ -228,7 +219,6 @@ static int exynos_ohci_suspend(struct device *dev)
 
clk_disable_unprepare(exynos_ohci-clk);
 
-fail:
spin_unlock_irqrestore(ohci-lock, flags);
 
return rc;
-- 
1.7.9.5

--
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 09/11] USB: OHCI: Properly handle ohci-pxa27x suspend

2013-06-25 Thread Manjunath Goudar
Suspend scenario in case of ohci-pxa27x glue was not
properly handled as it was not suspending generic part
of ohci controller. Calling explicitly the ohci_suspend()
routine in ohci_hcd_pxa27x_drv_suspend() will ensure proper
handling of suspend scenario.

Signed-off-by: Manjunath Goudar manjunath.gou...@linaro.org
Acked-by: Alan Stern st...@rowland.harvard.edu
Cc: Arnd Bergmann a...@arndb.de
Cc: Greg KH g...@kroah.com
Cc: linux-usb@vger.kernel.org

V2:
 -Incase ohci_suspend() fails, return right away without
  executing further.
V3:
 -Aligned variable do_wakeup and ret.

V4:
 -The do_wakeup and ret variable alignment is removed.
---
 drivers/usb/host/ohci-pxa27x.c |8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/ohci-pxa27x.c b/drivers/usb/host/ohci-pxa27x.c
index 3a9c01d..5fb91f1 100644
--- a/drivers/usb/host/ohci-pxa27x.c
+++ b/drivers/usb/host/ohci-pxa27x.c
@@ -564,13 +564,19 @@ static int ohci_hcd_pxa27x_drv_suspend(struct device *dev)
 {
struct usb_hcd *hcd = dev_get_drvdata(dev);
struct pxa27x_ohci *ohci = to_pxa27x_ohci(hcd);
+   bool do_wakeup = device_may_wakeup(dev);
+   int ret;
 
if (time_before(jiffies, ohci-ohci.next_statechange))
msleep(5);
ohci-ohci.next_statechange = jiffies;
 
+   ret = ohci_suspend(hcd, do_wakeup);
+   if (ret)
+   return ret;
+
pxa27x_stop_hc(ohci, dev);
-   return 0;
+   return ret;
 }
 
 static int ohci_hcd_pxa27x_drv_resume(struct device *dev)
-- 
1.7.9.5

--
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 11/11] USB: OHCI: Properly handle ohci-spear suspend

2013-06-25 Thread Manjunath Goudar
Suspend scenario in case of ohci-spear glue was not
properly handled as it was not suspending generic part
of ohci controller. Calling explicitly the ohci_suspend()
routine in spear_ohci_hcd_drv_suspend() will ensure proper
handling of suspend scenario.

Signed-off-by: Manjunath Goudar manjunath.gou...@linaro.org
Acked-by: Alan Stern st...@rowland.harvard.edu
Cc: Arnd Bergmann a...@arndb.de
Cc: Greg KH g...@kroah.com
Cc: linux-usb@vger.kernel.org

V2:
 -Incase ohci_suspend() fails, return right away without
  executing further.
V3:
 -Aligned variable do_wakeup and ret.

V4:
 -The do_wakeup and ret variable alignment is removed.
---
 drivers/usb/host/ohci-spear.c |   12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/ohci-spear.c b/drivers/usb/host/ohci-spear.c
index 31ff3fc..41148f8 100644
--- a/drivers/usb/host/ohci-spear.c
+++ b/drivers/usb/host/ohci-spear.c
@@ -130,20 +130,26 @@ static int spear_ohci_hcd_drv_remove(struct 
platform_device *pdev)
 }
 
 #if defined(CONFIG_PM)
-static int spear_ohci_hcd_drv_suspend(struct platform_device *dev,
+static int spear_ohci_hcd_drv_suspend(struct platform_device *pdev,
pm_message_t message)
 {
-   struct usb_hcd *hcd = platform_get_drvdata(dev);
+   struct usb_hcd *hcd = platform_get_drvdata(pdev);
struct ohci_hcd *ohci = hcd_to_ohci(hcd);
struct spear_ohci *sohci_p = to_spear_ohci(hcd);
+   bool do_wakeup = device_may_wakeup(pdev-dev);
+   int ret;
 
if (time_before(jiffies, ohci-next_statechange))
msleep(5);
ohci-next_statechange = jiffies;
 
+   ret = ohci_suspend(hcd, do_wakeup);
+   if (ret)
+   return ret;
+
clk_disable_unprepare(sohci_p-clk);
 
-   return 0;
+   return ret;
 }
 
 static int spear_ohci_hcd_drv_resume(struct platform_device *dev)
-- 
1.7.9.5

--
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 10/11] USB: OHCI: Properly handle ohci-sm501 suspend

2013-06-25 Thread Manjunath Goudar
Suspend scenario in case of ohci-sm501 glue was not
properly handled as it was not suspending generic part
of ohci controller. Calling explicitly the ohci_suspend()
routine in ohci_sm501_suspend() will ensure proper
handling of suspend scenario.

Signed-off-by: Manjunath Goudar manjunath.gou...@linaro.org
Acked-by: Alan Stern st...@rowland.harvard.edu
Cc: Arnd Bergmann a...@arndb.de
Cc: Greg KH g...@kroah.com
Cc: linux-usb@vger.kernel.org

V2:
 -Incase ohci_suspend() fails, return right away without
  executing further.
V3:
 -Aligned variable do_wakeup and ret.

-V4:
 -The do_wakeup and ret variable alignment is removed.
---
 drivers/usb/host/ohci-sm501.c |   11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/ohci-sm501.c b/drivers/usb/host/ohci-sm501.c
index d479d5d..2a5de5f 100644
--- a/drivers/usb/host/ohci-sm501.c
+++ b/drivers/usb/host/ohci-sm501.c
@@ -216,14 +216,21 @@ static int ohci_hcd_sm501_drv_remove(struct 
platform_device *pdev)
 static int ohci_sm501_suspend(struct platform_device *pdev, pm_message_t msg)
 {
struct device *dev = pdev-dev;
-   struct ohci_hcd *ohci = hcd_to_ohci(platform_get_drvdata(pdev));
+   struct usb_hcd  *hcd = platform_get_drvdata(pdev);
+   struct ohci_hcd *ohci = hcd_to_ohci(hcd);
+   bool do_wakeup = device_may_wakeup(dev);
+   int ret;
 
if (time_before(jiffies, ohci-next_statechange))
msleep(5);
ohci-next_statechange = jiffies;
 
+   ret = ohci_suspend(hcd, do_wakeup);
+   if (ret)
+   return ret;
+
sm501_unit_power(dev-parent, SM501_GATE_USB_HOST, 0);
-   return 0;
+   return ret;
 }
 
 static int ohci_sm501_resume(struct platform_device *pdev)
-- 
1.7.9.5

--
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 08/11] USB: OHCI: Properly handle ohci-platform suspend

2013-06-25 Thread Manjunath Goudar
Suspend scenario in case of ohci-platform glue was not
properly handled as it was not suspending generic part
of ohci controller. Calling explicitly the ohci_suspend()
routine in ohci_platform_suspend() will ensure proper
handling of suspend scenario.

Signed-off-by: Manjunath Goudar manjunath.gou...@linaro.org
Acked-by: Alan Stern st...@rowland.harvard.edu
Cc: Arnd Bergmann a...@arndb.de
Cc: Greg KH g...@kroah.com
Cc: linux-usb@vger.kernel.org

V2:
 -Incase ohci_suspend() fails, return right away without
  executing further.

V3:
 -Aligned variable do_wakeup and ret.

V4:
 -The do_wakeup and ret variable alignment is removed.
---
 drivers/usb/host/ohci-platform.c |9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/ohci-platform.c b/drivers/usb/host/ohci-platform.c
index bc30475..b4a8784 100644
--- a/drivers/usb/host/ohci-platform.c
+++ b/drivers/usb/host/ohci-platform.c
@@ -139,14 +139,21 @@ static int ohci_platform_remove(struct platform_device 
*dev)
 
 static int ohci_platform_suspend(struct device *dev)
 {
+   struct usb_hcd *hcd = dev_get_drvdata(dev);
struct usb_ohci_pdata *pdata = dev-platform_data;
struct platform_device *pdev =
container_of(dev, struct platform_device, dev);
+   bool do_wakeup = device_may_wakeup(dev);
+   int ret;
+
+   ret = ohci_suspend(hcd, do_wakeup);
+   if (ret)
+   return ret;
 
if (pdata-power_suspend)
pdata-power_suspend(pdev);
 
-   return 0;
+   return ret;
 }
 
 static int ohci_platform_resume(struct device *dev)
-- 
1.7.9.5

--
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: musb: omap2430: make it compile again

2013-06-25 Thread Sebastian Andrzej Siewior
it does not compile since 09fc7d (usb: musb: fix incorrect usage of
resource pointer). What makes me wonder most is if source of the
Tested-by tag :)

Acked-by: Felipe Balbi ba...@ti.com
Signed-off-by: Sebastian Andrzej Siewior bige...@linutronix.de
---
Greg, this is against your usb-next tree.

 drivers/usb/musb/omap2430.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index c7c1d7a..4315d35 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -481,7 +481,7 @@ static u64 omap2430_dmamask = DMA_BIT_MASK(32);
 
 static int omap2430_probe(struct platform_device *pdev)
 {
-   struct resource musb_resouces[2];
+   struct resource musb_resources[2];
struct musb_hdrc_platform_data  *pdata = pdev-dev.platform_data;
struct omap_musb_board_data *data;
struct platform_device  *musb;
@@ -568,7 +568,7 @@ static int omap2430_probe(struct platform_device *pdev)
 
INIT_WORK(glue-omap_musb_mailbox_work, omap_musb_mailbox_work);
 
-   memset(musb_resouces, 0x00, sizeof(*musb_resources) *
+   memset(musb_resources, 0x00, sizeof(*musb_resources) *
ARRAY_SIZE(musb_resources));
 
musb_resources[0].name = pdev-resource[0].name;
-- 
1.8.3.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


[RFC 02/19] usb/gadget: create a utility module for mass_storage

2013-06-25 Thread Marek Szyprowski
From: Andrzej Pietrasiewicz andrze...@samsung.com

Converting to configfs requires making the f_mass_storage.c a module.
But first we need to get rid of #include storage_common.c.
This patch makes storage_common.c a separately compiled file, which is
built as a utility module named u_ms.ko. After all mass storage users are
converted to the new function interface this module can be eliminated
by merging it with the mass storage function's module.

USB descriptors are exported so that they can be accessed from
f_mass_storage.

FSG_VENDOR_ID and FSG_PRODUCT_ID are moved to their only user.

Handling of CONFIG_USB_GADGET_DEBUG_FILES is moved to f_mass_storage.c.
The fsg_num_buffers static is moved to FSG_MODULE_PARAMETER users, so
instead of using a global variable the f_mass_storage introduces
fsg_num_buffers member in fsg_common (and fsg_config).

fsg_strings and fsg_stringtab are moved to f_mass_storage.c.

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/usb/gadget/Kconfig  |6 +
 drivers/usb/gadget/Makefile |2 +
 drivers/usb/gadget/acm_ms.c |   17 +-
 drivers/usb/gadget/f_mass_storage.c |   71 ++--
 drivers/usb/gadget/mass_storage.c   |   25 ++-
 drivers/usb/gadget/multi.c  |   17 +-
 drivers/usb/gadget/storage_common.c |  319 ++-
 drivers/usb/gadget/storage_common.h |  208 +++
 8 files changed, 380 insertions(+), 285 deletions(-)
 create mode 100644 drivers/usb/gadget/storage_common.h

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 01b8229..71d284f 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -539,6 +539,9 @@ config USB_F_SUBSET
 config USB_F_RNDIS
tristate
 
+config USB_U_MS
+   tristate
+
 choice
tristate USB Gadget Drivers
default USB_ETH
@@ -891,6 +894,7 @@ config USB_MASS_STORAGE
tristate Mass Storage Gadget
depends on BLOCK
select USB_LIBCOMPOSITE
+   select USB_U_MS
help
  The Mass Storage Gadget acts as a USB Mass Storage disk drive.
  As its storage repository it can use a regular file or a block
@@ -1014,6 +1018,7 @@ config USB_G_ACM_MS
select USB_LIBCOMPOSITE
select USB_U_SERIAL
select USB_F_ACM
+   select USB_U_MS
help
  This driver provides two functions in one configuration:
  a mass storage, and a CDC ACM (serial port) link.
@@ -1030,6 +1035,7 @@ config USB_G_MULTI
select USB_U_ETHER
select USB_U_RNDIS
select USB_F_ACM
+   select USB_U_MS
help
  The Multifunction Composite Gadget provides Ethernet (RNDIS
  and/or CDC Ethernet), mass storage and ACM serial link
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index bad08e6..b9c779a 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -61,6 +61,8 @@ usb_f_ecm_subset-y:= f_subset.o
 obj-$(CONFIG_USB_F_SUBSET) += usb_f_ecm_subset.o
 usb_f_rndis-y  := f_rndis.o
 obj-$(CONFIG_USB_F_RNDIS)  += usb_f_rndis.o
+u_ms-y := storage_common.o
+obj-$(CONFIG_USB_U_MS) += u_ms.o
 
 #
 # USB gadget drivers
diff --git a/drivers/usb/gadget/acm_ms.c b/drivers/usb/gadget/acm_ms.c
index 4b947bb..992ffb0 100644
--- a/drivers/usb/gadget/acm_ms.c
+++ b/drivers/usb/gadget/acm_ms.c
@@ -104,6 +104,20 @@ static struct usb_gadget_strings *dev_strings[] = {
 /** Configurations **/
 
 static struct fsg_module_parameters fsg_mod_data = { .stall = 1 };
+#ifdef CONFIG_USB_GADGET_DEBUG_FILES
+
+static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS;
+
+#else
+
+/*
+ * Number of buffers we will use.
+ * 2 is usually enough for good buffering pipeline
+ */
+#define fsg_num_buffersCONFIG_USB_GADGET_STORAGE_NUM_BUFFERS
+
+#endif /* CONFIG_USB_DEBUG */
+
 FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data);
 
 static struct fsg_common fsg_common;
@@ -167,7 +181,8 @@ static int __init acm_ms_bind(struct usb_composite_dev 
*cdev)
void*retp;
 
/* set up mass storage function */
-   retp = fsg_common_from_params(fsg_common, cdev, fsg_mod_data);
+   retp = fsg_common_from_params(fsg_common, cdev, fsg_mod_data,
+ fsg_num_buffers);
if (IS_ERR(retp)) {
status = PTR_ERR(retp);
return PTR_ERR(retp);
diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index 56f1fd1..163d911 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -228,8 +228,18 @@
 
 static const char fsg_string_interface[] = Mass Storage;
 
-#include storage_common.c
+#include storage_common.h
 
+/* Static strings, in UTF-8 (for 

[RFC 01/19] usb/gadget: configfs: add a method to unregister the gadget

2013-06-25 Thread Marek Szyprowski
From: Andrzej Pietrasiewicz andrze...@samsung.com

Add a method to unregister the gadget using its config_item.
Add a method to query the registered status using config_item.

There can be functions (e.g. mass storage), which in some circumstances
need the gadget stopped. Add a method of stopping the gadget.

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/usb/gadget/configfs.c |8 
 drivers/usb/gadget/configfs.h |6 ++
 2 files changed, 14 insertions(+)
 create mode 100644 drivers/usb/gadget/configfs.h

diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
index 80e7f75..cda3ead 100644
--- a/drivers/usb/gadget/configfs.c
+++ b/drivers/usb/gadget/configfs.c
@@ -989,6 +989,14 @@ static struct configfs_subsystem gadget_subsys = {
.su_mutex = __MUTEX_INITIALIZER(gadget_subsys.su_mutex),
 };
 
+void unregister_gadget_item(struct config_item *item)
+{
+   struct gadget_info *gi = to_gadget_info(item);
+
+   unregister_gadget(gi);
+}
+EXPORT_SYMBOL(unregister_gadget_item);
+
 static int __init gadget_cfs_init(void)
 {
int ret;
diff --git a/drivers/usb/gadget/configfs.h b/drivers/usb/gadget/configfs.h
new file mode 100644
index 000..a7b564a
--- /dev/null
+++ b/drivers/usb/gadget/configfs.h
@@ -0,0 +1,6 @@
+#ifndef USB__GADGET__CONFIGFS__H
+#define USB__GADGET__CONFIGFS__H
+
+void unregister_gadget_item(struct config_item *item);
+
+#endif /*  USB__GADGET__CONFIGFS__H */
-- 
1.7.9.5

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


[RFC 15/19] usb/gadget: f_mass_storage: convert to new function interface with backward compatibility

2013-06-25 Thread Marek Szyprowski
From: Andrzej Pietrasiewicz andrze...@samsung.com

Converting mass storage to the new function interface requires converting
the USB mass storage's function code and its users.
This patch converts the f_mass_storage.c to the new function interface.
The file is now compiled into a separate usb_f_mass_storage.ko module.
The old function interface is provided by means of a preprocessor conditional
directives. After all users are converted, the old interface can be removed.

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/usb/gadget/Kconfig  |3 +
 drivers/usb/gadget/Makefile |2 +
 drivers/usb/gadget/acm_ms.c |1 +
 drivers/usb/gadget/f_mass_storage.c |  217 +++
 drivers/usb/gadget/f_mass_storage.h |7 ++
 drivers/usb/gadget/mass_storage.c   |1 +
 drivers/usb/gadget/multi.c  |1 +
 7 files changed, 212 insertions(+), 20 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 71d284f..ffc1791 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -542,6 +542,9 @@ config USB_F_RNDIS
 config USB_U_MS
tristate
 
+config USB_F_MASS_STORAGE
+   tristate
+
 choice
tristate USB Gadget Drivers
default USB_ETH
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index b9c779a..dccab69 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -63,6 +63,8 @@ usb_f_rndis-y := f_rndis.o
 obj-$(CONFIG_USB_F_RNDIS)  += usb_f_rndis.o
 u_ms-y := storage_common.o
 obj-$(CONFIG_USB_U_MS) += u_ms.o
+usb_f_mass_storage-y   := f_mass_storage.o
+obj-$(CONFIG_USB_F_MASS_STORAGE)+= usb_f_mass_storage.o
 
 #
 # USB gadget drivers
diff --git a/drivers/usb/gadget/acm_ms.c b/drivers/usb/gadget/acm_ms.c
index 992ffb0..31aae8f 100644
--- a/drivers/usb/gadget/acm_ms.c
+++ b/drivers/usb/gadget/acm_ms.c
@@ -40,6 +40,7 @@
  * the runtime footprint, and giving us at least some parts of what
  * a gcc --combine ... part1.c part2.c part3.c ...  build would.
  */
+#define USB_FMS_INCLUDED
 #include f_mass_storage.c
 
 /*-*/
diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index 6f578f4..22a68f7 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -213,6 +213,7 @@
 #include linux/spinlock.h
 #include linux/string.h
 #include linux/freezer.h
+#include linux/module.h
 
 #include linux/usb/ch9.h
 #include linux/usb/gadget.h
@@ -2589,11 +2590,17 @@ void fsg_common_get(struct fsg_common *common)
 {
kref_get(common-ref);
 }
+#ifndef USB_FMS_INCLUDED
+EXPORT_SYMBOL(fsg_common_get);
+#endif
 
 void fsg_common_put(struct fsg_common *common)
 {
kref_put(common-ref, fsg_common_release);
 }
+#ifndef USB_FMS_INCLUDED
+EXPORT_SYMBOL(fsg_common_put);
+#endif
 
 /* check if fsg_num_buffers is within a valid range */
 static inline int fsg_num_buffers_validate(unsigned int fsg_num_buffers)
@@ -2631,6 +2638,9 @@ void fsg_common_set_sysfs(struct fsg_common *common, bool 
sysfs)
 {
common-sysfs = sysfs;
 }
+#ifndef USB_FMS_INCLUDED
+EXPORT_SYMBOL(fsg_common_set_sysfs);
+#endif
 
 int fsg_common_set_num_buffers(struct fsg_common *common, unsigned int n)
 {
@@ -2677,6 +2687,9 @@ error_release:
 
return -ENOMEM;
 }
+#ifndef USB_FMS_INCLUDED
+EXPORT_SYMBOL(fsg_common_set_num_buffers);
+#endif
 
 void fsg_common_free_buffers(struct fsg_common *common)
 {
@@ -2693,6 +2706,9 @@ void fsg_common_free_buffers(struct fsg_common *common)
kfree(common-buffhds);
common-buffhds = NULL;
 }
+#ifndef USB_FMS_INCLUDED
+EXPORT_SYMBOL(fsg_common_free_buffers);
+#endif
 
 int fsg_common_set_nluns(struct fsg_common *common, int nluns)
 {
@@ -2715,22 +2731,34 @@ int fsg_common_set_nluns(struct fsg_common *common, int 
nluns)
 
return 0;
 }
+#ifndef USB_FMS_INCLUDED
+EXPORT_SYMBOL(fsg_common_set_nluns);
+#endif
 
 void fsg_common_free_luns(struct fsg_common *common)
 {
kfree(common-luns);
common-luns = NULL;
 }
+#ifndef USB_FMS_INCLUDED
+EXPORT_SYMBOL(fsg_common_free_luns);
+#endif
 
 void fsg_common_set_ops(struct fsg_common *common, const struct fsg_operations 
*ops)
 {
common-ops = ops;
 }
+#ifndef USB_FMS_INCLUDED
+EXPORT_SYMBOL(fsg_common_set_ops);
+#endif
 
 void fsg_common_set_private_data(struct fsg_common *common, void *priv)
 {
common-private_data = priv;
 }
+#ifndef USB_FMS_INCLUDED
+EXPORT_SYMBOL(fsg_common_set_private_data);
+#endif
 
 int fsg_common_set_cdev(struct fsg_common *common,
 struct usb_composite_dev *cdev, bool can_stall)
@@ -2760,6 +2788,9 @@ int fsg_common_set_cdev(struct fsg_common *common,
 
return 0;
 }
+#ifndef USB_FMS_INCLUDED

[RFC 07/19] usb/gadget: f_mass_storage: use fsg_common_setup in fsg_common_init

2013-06-25 Thread Marek Szyprowski
From: Andrzej Pietrasiewicz andrze...@samsung.com

fsg_common_init is a lengthy function. Now there are helper functions
which cover all parts of it. Use them.

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/usb/gadget/f_mass_storage.c |   19 +++
 1 file changed, 3 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index fc3b5ff..24c407a 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -2996,16 +2996,9 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
return ERR_PTR(-EINVAL);
}
 
-   /* Allocate? */
-   if (!common) {
-   common = kzalloc(sizeof *common, GFP_KERNEL);
-   if (!common)
-   return ERR_PTR(-ENOMEM);
-   common-free_storage_on_release = 1;
-   } else {
-   memset(common, 0, sizeof *common);
-   common-free_storage_on_release = 0;
-   }
+   common = fsg_common_setup(common, !!common);
+   if (IS_ERR(common))
+   return common;
common-sysfs = true;
common-state = FSG_STATE_IDLE;
 
@@ -3045,8 +3038,6 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
}
common-luns = curlun;
 
-   init_rwsem(common-filesem);
-
for (i = 0, lcfg = cfg-luns; i  nluns; ++i, ++curlun, ++lcfg) {
*curlun = kzalloc(sizeof(**curlun), GFP_KERNEL);
if (!*curlun) {
@@ -3135,8 +3126,6 @@ buffhds_first_it:
common-can_stall = cfg-can_stall 
!(gadget_is_at91(common-gadget));
 
-   spin_lock_init(common-lock);
-   kref_init(common-ref);
 
/* Tell the thread to start working */
common-thread_task =
@@ -3145,8 +3134,6 @@ buffhds_first_it:
rc = PTR_ERR(common-thread_task);
goto error_release;
}
-   init_completion(common-thread_notifier);
-   init_waitqueue_head(common-fsg_wait);
 
/* Information */
INFO(common, FSG_DRIVER_DESC , version:  FSG_DRIVER_VERSION \n);
-- 
1.7.9.5

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


[RFC 00/19] Equivalent of g_mass_storage.ko with configfs

2013-06-25 Thread Marek Szyprowski
Hello All,

Andrzej Pietrasiewicz, who has been working on configfs support for usb
gadgets for a last few months, went for holidays this week. He asked me
to post his initial patches adding configs support to mass storage usb
function.

The patches are based on latest usb-next kernel free from
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git

Best regards, Marek Szyprowski


Here is the cover letter prepared by Andrzej:



Dear All,

This series aims at integrating configfs into mass storage, the way
it has been done for acm, ncm, ecm, eem, ecm subset, rndis, obex and phonet.
It contains everything that is required to provide the equivalent of
g_mass_storage.ko with configfs.

Mass storage itself is quite large, so the resulting patch series is a bit
lengthy. However, it is supposed to be done in steps like this:

1) preliminary work, e.g. factoring out a header file, creating a utility
u_ms.ko module, use usb_gstrings_attach
2) prepare for initializing the fsg_common structure in smaller steps instead
of in one big step
3) usual stuff, similar to functions previously converted to configfs

I kindly ask for comments; I will be out of office until June 30th,
so when I'm back I will be happy to get my hands dirty with implementing
changes resulting from lots of good comments ;)


BACKWARD COMPATIBILITY
==

Please note that the old g_mass_storage.ko is still available and works.


USING THE NEW GADGET
==

Please refer to this post:

http://www.spinics.net/lists/linux-usb/msg76388.html

for general information from Sebastian on how to use configfs-based
gadgets (*).

With configfs the procedure is as follows, compared to the information
mentioned above (*):

instead of mkdir functions/acm.ttyS1 do

mkdir functions/mass_storage.instance name

e.g. mkdir functions/mass_storage.0

In functions/function.instance name there will be the following attribute
files:

stall   - Set to permit function to halt bulk endpoints.
Disabled on some USB devices known not to work
correctly. You should set it to true.
num_buffers - Number of pipeline buffers. Valid numbers
are 2..4. Available only if
CONFIG_USB_GADGET_DEBUG_FILES is set.

and a default lun.0 directory corresponding to SCSI LUN #0.

A new lun can be added with mkdir:

$ mkdir functions/mass_storage.0/partition.5

Lun numbering does not have to be continuous, except for lun #0 which is
created by default. A maximum of 8 luns can be specified and they all must be
named following the name.number scheme. The numbers can be 0..8.
Probably a good convention is to name the luns lun.number,
although it is not mandatory.

In each lun directory there are the following attribute files:

file- The path to the backing file for the LUN.
Required if LUN is not marked as removable.
ro  - Flag specifying access to the LUN shall be
read-only. This is implied if CD-ROM emulation
is enabled as well as when it was impossible
to open filename in R/W mode.
removable   - Flag specifying that LUN shall be indicated as
being removable.
cdrom   - Flag specifying that LUN shall be reported as
being a CD-ROM.
nofua   - Flag specifying that FUA flag
in SCSI WRITE(10,12)

The rest of the procedure (*) remains the same.

An example gadget with two luns:

$ modprobe libcomposite
 
$ mount none cfg -t configfs
 
$ mkdir cfg/usb_gadget/g1
$ cd cfg/usb_gadget/g1
 
$ mkdir configs/c.1
$ mkdir functions/mass_storage.0
$ echo /root/lun0.img  functions/mass_storage.0/lun.0/file
$ mkdir functions/mass_storage.0/lun.1
$ echo /root/lun1.img  functions/mass_storage.0/lun.1/file
$ mkdir strings/0x409
$ mkdir configs/c.1/strings/0x409
 
$ echo 0xa4a2  idProduct
$ echo 0x0525  idVendor
$ echo samsung123  strings/0x409/serialnumber
$ echo Samsung  strings/0x409/manufacturer
$ echo Mass Storage Gadget  strings/0x409/product
 
$ echo Conf 1  configs/c.1/strings/0x409/configuration
$ echo 120  configs/c.1/MaxPower
$ ln -s functions/mass_storage.0 configs/c.1
 
$ echo s3c-hsotg  UDC

After unbinding the gadget with echo   UDC
the symbolic links in the configuration directory can be removed,
the strings/* subdirectories in the configuration directory can
be removed, the strings/* subdirectories at the gadget level can
be removed and the configs/* subdirectories can be removed.
The functions/* subdirectories can be removed.
After that the gadget directory can be removed.
After that the respective modules can be unloaded.


TESTING THE FUNCTIONS (actually there is only one)
=

mass_storage)

device: connect 

[RFC 09/19] usb/gadget: f_mass_storage: use fsg_common_set_nluns in fsg_common_init

2013-06-25 Thread Marek Szyprowski
From: Andrzej Pietrasiewicz andrze...@samsung.com

fsg_common_init is a lengthy function. Now there are helper functions
which cover all parts of it. Use them.

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/usb/gadget/f_mass_storage.c |   22 +-
 1 file changed, 5 insertions(+), 17 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index f833c35..6869134 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -2984,12 +2984,6 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
int nluns, i, rc;
char *pathbuf;
 
-   /* Find out how many LUNs there should be */
-   nluns = cfg-nluns;
-   if (nluns  1 || nluns  FSG_MAX_LUNS) {
-   dev_err(gadget-dev, invalid number of LUNs: %u\n, nluns);
-   return ERR_PTR(-EINVAL);
-   }
 
common = fsg_common_setup(common, !!common);
if (IS_ERR(common))
@@ -3019,17 +3013,12 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
}
fsg_intf_desc.iInterface = us[FSG_STRING_INTERFACE].id;
 
-   /*
-* Create the LUNs, open their backing files, and register the
-* LUN devices in sysfs.
-*/
-   curlun = kcalloc(nluns, sizeof(*curlun), GFP_KERNEL);
-   if (unlikely(!curlun)) {
-   rc = -ENOMEM;
-   goto error_release;
-   }
-   common-luns = curlun;
 
+   rc = fsg_common_set_nluns(common, cfg-nluns);
+   if (rc)
+   goto error_release;
+   curlun = common-luns;
+   nluns = cfg-nluns;
for (i = 0, lcfg = cfg-luns; i  nluns; ++i, ++curlun, ++lcfg) {
*curlun = kzalloc(sizeof(**curlun), GFP_KERNEL);
if (!*curlun) {
@@ -3082,7 +3071,6 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
goto error_luns;
}
}
-   common-nluns = nluns;
 
 
/* Prepare inquiryString */
-- 
1.7.9.5

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


[RFC 04/19] usb/gadget: f_mass_storage: add a level of indirection for luns storage

2013-06-25 Thread Marek Szyprowski
From: Andrzej Pietrasiewicz andrze...@samsung.com

This is needed to prepare for configfs integration.

So far the luns have been allocated during gadget's initialization, based
on the nluns module parameter's value; the exact number is known when the
gadget is initialized and that number of luns is allocated in one go; they
all will be used.

When configfs is in place, the luns will be created one-by-one by the user.
Once the user is satisfied with the number of luns, they activate the
gadget. The number of luns must be = FSG_MAX_LUN (currently 8), but other
than that it is not known up front and the user need not use contiguous
numbering (apart from the default lun #0). On the other hand, the function
code uses lun numbers to identify them and the number needs to be used
as an index into an array.

Given the above, an array needs to be allocated, but it might happen that
7 out of its 8 elements will not be used. On my machine
sizeof(struct fsg_lun) == 462, so  3k of memory is allocated but not used
in the worst case.

By adding another level of indirection (allocating an array of pointers
to struct fsg_lun and then allocating individual luns instead of an array
of struct fsg_luns) at most 7 pointers are wasted, which is much less.

This patch also changes some for/while loops to cope with the fact
that in the luns array some entries are potentially empty.

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/usb/gadget/f_mass_storage.c |  417 ++-
 1 file changed, 215 insertions(+), 202 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index c36e208..c386f76 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -274,8 +274,8 @@ struct fsg_common {
 
unsigned intnluns;
unsigned intlun;
-   struct fsg_lun  *luns;
-   struct fsg_lun  *curlun;
+   struct fsg_lun  **luns;
+   struct fsg_lun  **curlun;
 
unsigned intbulk_out_maxpacket;
enum fsg_state  state;  /* For exception handling */
@@ -621,7 +621,7 @@ static int sleep_thread(struct fsg_common *common)
 
 static int do_read(struct fsg_common *common)
 {
-   struct fsg_lun  *curlun = common-curlun;
+   struct fsg_lun  **curlun = common-curlun;
u32 lba;
struct fsg_buffhd   *bh;
int rc;
@@ -645,15 +645,15 @@ static int do_read(struct fsg_common *common)
 * cache), but we don't implement them.
 */
if ((common-cmnd[1]  ~0x18) != 0) {
-   curlun-sense_data = SS_INVALID_FIELD_IN_CDB;
+   (*curlun)-sense_data = SS_INVALID_FIELD_IN_CDB;
return -EINVAL;
}
}
-   if (lba = curlun-num_sectors) {
-   curlun-sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
+   if (lba = (*curlun)-num_sectors) {
+   (*curlun)-sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
return -EINVAL;
}
-   file_offset = ((loff_t) lba)  curlun-blkbits;
+   file_offset = ((loff_t) lba)  (*curlun)-blkbits;
 
/* Carry out the file reads */
amount_left = common-data_size_from_cmnd;
@@ -669,7 +669,7 @@ static int do_read(struct fsg_common *common)
 */
amount = min(amount_left, FSG_BUFLEN);
amount = min((loff_t)amount,
-curlun-file_length - file_offset);
+(*curlun)-file_length - file_offset);
 
/* Wait for the next buffer to become available */
bh = common-next_buffhd_to_fill;
@@ -684,11 +684,11 @@ static int do_read(struct fsg_common *common)
 * end with an empty buffer.
 */
if (amount == 0) {
-   curlun-sense_data =
+   (*curlun)-sense_data =
SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
-   curlun-sense_data_info =
-   file_offset  curlun-blkbits;
-   curlun-info_valid = 1;
+   (*curlun)-sense_data_info =
+   file_offset  (*curlun)-blkbits;
+   (*curlun)-info_valid = 1;
bh-inreq-length = 0;
bh-state = BUF_STATE_FULL;
break;
@@ -696,21 +696,21 @@ static int do_read(struct fsg_common *common)
 
/* Perform the read */
file_offset_tmp = file_offset;
-   nread = vfs_read(curlun-filp,
+   nread = vfs_read((*curlun)-filp,
  

[RFC 12/19] usb/gadget: f_mass_storage: use fsg_common_create_luns in fsg_common_init

2013-06-25 Thread Marek Szyprowski
From: Andrzej Pietrasiewicz andrze...@samsung.com

fsg_common_init is a lengthy function. Now there are helper functions
which cover all parts of it. Use them.

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/usb/gadget/f_mass_storage.c |   89 ++-
 1 file changed, 4 insertions(+), 85 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index a0ddd2c..b38db6a 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -2977,12 +2977,7 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
   struct usb_composite_dev *cdev,
   struct fsg_config *cfg)
 {
-   struct usb_gadget *gadget = cdev-gadget;
-   struct fsg_lun **curlun;
-   struct fsg_lun_config *lcfg;
-   int nluns, i, rc;
-   char *pathbuf;
-
+   int i, rc;
 
common = fsg_common_setup(common, !!common);
if (IS_ERR(common))
@@ -3007,61 +3002,10 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
rc = fsg_common_set_nluns(common, cfg-nluns);
if (rc)
goto error_release;
-   curlun = common-luns;
-   nluns = cfg-nluns;
-   for (i = 0, lcfg = cfg-luns; i  nluns; ++i, ++curlun, ++lcfg) {
-   *curlun = kzalloc(sizeof(**curlun), GFP_KERNEL);
-   if (!*curlun) {
-   rc = -ENOMEM;
-   common-nluns = i;
-   goto error_release;
-   }
-   (*curlun)-cdrom = !!lcfg-cdrom;
-   (*curlun)-ro = lcfg-cdrom || lcfg-ro;
-   (*curlun)-initially_ro = (*curlun)-ro;
-   (*curlun)-removable = lcfg-removable;
-   (*curlun)-dev.release = fsg_lun_release;
-   (*curlun)-dev.parent = gadget-dev;
-   /* (curlun*)-dev.driver = fsg_driver.driver; XXX */
-   dev_set_drvdata((*curlun)-dev, common-filesem);
-   dev_set_name((*curlun)-dev, lun%d, i);
-
-   rc = device_register((*curlun)-dev);
-   if (rc) {
-   INFO(common, failed to register LUN%d: %d\n, i, rc);
-   common-nluns = i;
-   put_device((*curlun)-dev);
-   kfree(*curlun);
-   goto error_release;
-   }
-
-   rc = device_create_file((*curlun)-dev,
-   (*curlun)-cdrom
- ? dev_attr_ro_cdrom
- : dev_attr_ro);
-   if (rc)
-   goto error_luns;
-   rc = device_create_file((*curlun)-dev,
-   (*curlun)-removable
- ? dev_attr_file
- : dev_attr_file_nonremovable);
-   if (rc)
-   goto error_luns;
-   rc = device_create_file((*curlun)-dev, dev_attr_nofua);
-   if (rc)
-   goto error_luns;
-
-   if (lcfg-filename) {
-   rc = fsg_lun_open(*curlun, lcfg-filename);
-   if (rc)
-   goto error_luns;
-   } else if (!(*curlun)-removable) {
-   ERROR(common, no file given for LUN%d\n, i);
-   rc = -EINVAL;
-   goto error_luns;
-   }
-   }
 
+   rc = fsg_common_create_luns(common, cfg);
+   if (rc)
+   goto error_release;
 
/* Prepare inquiryString */
i = get_default_bcdDevice();
@@ -3073,7 +3017,6 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
 : File-Stor Gadget),
 i);
 
-
/* Tell the thread to start working */
common-thread_task =
kthread_create(fsg_main_thread, common, file-storage);
@@ -3086,36 +3029,12 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
INFO(common, FSG_DRIVER_DESC , version:  FSG_DRIVER_VERSION \n);
INFO(common, Number of LUNs=%d\n, common-nluns);
 
-   pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
-   for (i = 0, nluns = common-nluns, curlun = common-luns;
-i  nluns;
-++curlun, ++i) {
-   char *p = (no medium);
-   if (fsg_lun_is_open(*curlun)) {
-   p = (error);
-   if (pathbuf) {
-   p = d_path((*curlun)-filp-f_path,
-  pathbuf, PATH_MAX);
-   if (IS_ERR(p))
-   p = (error);
-   }
-   }
-   

[RFC 18/19] usb/gadget: storage_common: add methods to show/store 'cdrom' and 'removable'

2013-06-25 Thread Marek Szyprowski
From: Andrzej Pietrasiewicz andrze...@samsung.com

This will be required by configfs integration.

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
Signed-off-by: Kyungin Park kyungmin.p...@samsung.com
---
 drivers/usb/gadget/storage_common.c |   41 +++
 drivers/usb/gadget/storage_common.h |5 +
 2 files changed, 46 insertions(+)

diff --git a/drivers/usb/gadget/storage_common.c 
b/drivers/usb/gadget/storage_common.c
index 5e4d476..5dec046 100644
--- a/drivers/usb/gadget/storage_common.c
+++ b/drivers/usb/gadget/storage_common.c
@@ -359,6 +359,17 @@ ssize_t fsg_show_file(struct fsg_lun *curlun, struct 
rw_semaphore *filesem,
 }
 EXPORT_SYMBOL(fsg_show_file);
 
+ssize_t fsg_show_cdrom(struct fsg_lun *curlun, char *buf)
+{
+   return sprintf(buf, %u\n, curlun-cdrom);
+}
+EXPORT_SYMBOL(fsg_show_cdrom);
+
+ssize_t fsg_show_removable(struct fsg_lun *curlun, char *buf)
+{
+   return sprintf(buf, %u\n, curlun-removable);
+}
+EXPORT_SYMBOL(fsg_show_removable);
 
 ssize_t fsg_store_ro(struct fsg_lun *curlun, struct rw_semaphore *filesem,
const char *buf, size_t count)
@@ -439,4 +450,34 @@ ssize_t fsg_store_file(struct fsg_lun *curlun, struct 
rw_semaphore *filesem,
 }
 EXPORT_SYMBOL(fsg_store_file);
 
+ssize_t fsg_store_cdrom(struct fsg_lun *curlun, const char *buf, size_t count)
+{
+   unsignedcdrom;
+   int ret;
+
+   ret = kstrtouint(buf, 2, cdrom);
+   if (ret)
+   return ret;
+
+   curlun-cdrom = cdrom;
+
+   return count;
+}
+EXPORT_SYMBOL(fsg_store_cdrom);
+
+ssize_t fsg_store_removable(struct fsg_lun *curlun, const char *buf, size_t 
count)
+{
+   unsignedremovable;
+   int ret;
+
+   ret = kstrtouint(buf, 2, removable);
+   if (ret)
+   return ret;
+
+   curlun-removable = removable;
+
+   return count;
+}
+EXPORT_SYMBOL(fsg_store_removable);
+
 MODULE_LICENSE(GPL);
diff --git a/drivers/usb/gadget/storage_common.h 
b/drivers/usb/gadget/storage_common.h
index 0cc244d..f3f7c96 100644
--- a/drivers/usb/gadget/storage_common.h
+++ b/drivers/usb/gadget/storage_common.h
@@ -200,10 +200,15 @@ ssize_t fsg_show_ro(struct fsg_lun *curlun, char *buf);
 ssize_t fsg_show_nofua(struct fsg_lun *curlun, char *buf);
 ssize_t fsg_show_file(struct fsg_lun *curlun, struct rw_semaphore *filesem,
  char *buf);
+ssize_t fsg_show_cdrom(struct fsg_lun *curlun, char *buf);
+ssize_t fsg_show_removable(struct fsg_lun *curlun, char *buf);
 ssize_t fsg_store_ro(struct fsg_lun *curlun, struct rw_semaphore *filesem,
 const char *buf, size_t count);
 ssize_t fsg_store_nofua(struct fsg_lun *curlun, const char *buf, size_t count);
 ssize_t fsg_store_file(struct fsg_lun *curlun, struct rw_semaphore *filesem,
   const char *buf, size_t count);
+ssize_t fsg_store_cdrom(struct fsg_lun *curlun, const char *buf, size_t count);
+ssize_t fsg_store_removable(struct fsg_lun *curlun, const char *buf,
+   size_t count);
 
 #endif /* USB_STORAGE_COMMON_H */
-- 
1.7.9.5

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


[RFC 13/19] usb/gadget: f_mass_storage: use fsg_common_set_inquiry_string in fsg_common_init

2013-06-25 Thread Marek Szyprowski
From: Andrzej Pietrasiewicz andrze...@samsung.com

fsg_common_init is a lengthy function. Now there are helper functions
which cover all parts of it. Use them.

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/usb/gadget/f_mass_storage.c |   12 ++--
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index b38db6a..883078c 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -2977,7 +2977,7 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
   struct usb_composite_dev *cdev,
   struct fsg_config *cfg)
 {
-   int i, rc;
+   int rc;
 
common = fsg_common_setup(common, !!common);
if (IS_ERR(common))
@@ -3007,16 +3007,8 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
if (rc)
goto error_release;
 
-   /* Prepare inquiryString */
-   i = get_default_bcdDevice();
-   snprintf(common-inquiry_string, sizeof common-inquiry_string,
-%-8s%-16s%04x, cfg-vendor_name ?: Linux,
-/* Assume product name dependent on the first LUN */
-cfg-product_name ?: ((*common-luns)-cdrom
-? File-CD Gadget
-: File-Stor Gadget),
-i);
 
+   fsg_common_set_inquiry_string(common, cfg-vendor_name, 
cfg-product_name);
/* Tell the thread to start working */
common-thread_task =
kthread_create(fsg_main_thread, common, file-storage);
-- 
1.7.9.5

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


[RFC 10/19] usb/gadget: f_mass_storage: use fsg_common_set_ops/_private_data in fsg_common_init

2013-06-25 Thread Marek Szyprowski
From: Andrzej Pietrasiewicz andrze...@samsung.com

fsg_common_init is a lengthy function. Now there are helper functions
which cover all parts of it. Use them.

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/usb/gadget/f_mass_storage.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index 6869134..e828b89 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -2997,8 +2997,9 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
kfree(common);
return ERR_PTR(rc);
}
-   common-ops = cfg-ops;
-   common-private_data = cfg-private_data;
+
+   fsg_common_set_ops(common, cfg-ops);
+   fsg_common_set_private_data(common, cfg-private_data);
 
common-gadget = gadget;
common-ep0 = gadget-ep0;
-- 
1.7.9.5

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


[RFC 14/19] usb/gadget: f_mass_storage: use fsg_common_run_thread in fsg_common_init

2013-06-25 Thread Marek Szyprowski
From: Andrzej Pietrasiewicz andrze...@samsung.com

fsg_common_init is a lengthy function. Now there are helper functions
which cover all parts of it. Use them.

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/usb/gadget/f_mass_storage.c |   14 +++---
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index 883078c..6f578f4 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -3009,21 +3009,13 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
 
 
fsg_common_set_inquiry_string(common, cfg-vendor_name, 
cfg-product_name);
-   /* Tell the thread to start working */
-   common-thread_task =
-   kthread_create(fsg_main_thread, common, file-storage);
-   if (IS_ERR(common-thread_task)) {
-   rc = PTR_ERR(common-thread_task);
-   goto error_release;
-   }
 
/* Information */
INFO(common, FSG_DRIVER_DESC , version:  FSG_DRIVER_VERSION \n);
-   INFO(common, Number of LUNs=%d\n, common-nluns);
 
-   DBG(common, I/O thread pid: %d\n, task_pid_nr(common-thread_task));
-
-   wake_up_process(common-thread_task);
+   rc = fsg_common_run_thread(common);
+   if (rc)
+   goto error_release;
 
return common;
 
-- 
1.7.9.5

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


[RFC 11/19] usb/gadget: f_mass_storage: use fsg_common_set_cdev in fsg_common_init

2013-06-25 Thread Marek Szyprowski
From: Andrzej Pietrasiewicz andrze...@samsung.com

fsg_common_init is a lengthy function. Now there are helper functions
which cover all parts of it. Use them.

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/usb/gadget/f_mass_storage.c |   23 ++-
 1 file changed, 2 insertions(+), 21 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index e828b89..a0ddd2c 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -2980,7 +2980,6 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
struct usb_gadget *gadget = cdev-gadget;
struct fsg_lun **curlun;
struct fsg_lun_config *lcfg;
-   struct usb_string *us;
int nluns, i, rc;
char *pathbuf;
 
@@ -3001,19 +3000,9 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
fsg_common_set_ops(common, cfg-ops);
fsg_common_set_private_data(common, cfg-private_data);
 
-   common-gadget = gadget;
-   common-ep0 = gadget-ep0;
-   common-ep0req = cdev-req;
-   common-cdev = cdev;
-
-   us = usb_gstrings_attach(cdev, fsg_strings_array,
-ARRAY_SIZE(fsg_strings));
-   if (IS_ERR(us)) {
-   rc = PTR_ERR(us);
+   rc = fsg_common_set_cdev(common, cdev, cfg-can_stall);
+   if (rc)
goto error_release;
-   }
-   fsg_intf_desc.iInterface = us[FSG_STRING_INTERFACE].id;
-
 
rc = fsg_common_set_nluns(common, cfg-nluns);
if (rc)
@@ -3084,14 +3073,6 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
 : File-Stor Gadget),
 i);
 
-   /*
-* Some peripheral controllers are known not to be able to
-* halt bulk endpoints correctly.  If one of them is present,
-* disable stalls.
-*/
-   common-can_stall = cfg-can_stall 
-   !(gadget_is_at91(common-gadget));
-
 
/* Tell the thread to start working */
common-thread_task =
-- 
1.7.9.5

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


[RFC 08/19] usb/gadget: f_mass_storage: use fsg_common_set_num_buffers in fsg_common_init

2013-06-25 Thread Marek Szyprowski
From: Andrzej Pietrasiewicz andrze...@samsung.com

fsg_common_init is a lengthy function. Now there are helper functions
which cover all parts of it. Use them.

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/usb/gadget/f_mass_storage.c |   29 +++--
 1 file changed, 3 insertions(+), 26 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index 24c407a..f833c35 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -2978,17 +2978,12 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
   struct fsg_config *cfg)
 {
struct usb_gadget *gadget = cdev-gadget;
-   struct fsg_buffhd *bh;
struct fsg_lun **curlun;
struct fsg_lun_config *lcfg;
struct usb_string *us;
int nluns, i, rc;
char *pathbuf;
 
-   rc = fsg_num_buffers_validate(cfg-fsg_num_buffers);
-   if (rc != 0)
-   return ERR_PTR(rc);
-
/* Find out how many LUNs there should be */
nluns = cfg-nluns;
if (nluns  1 || nluns  FSG_MAX_LUNS) {
@@ -3002,15 +2997,12 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
common-sysfs = true;
common-state = FSG_STATE_IDLE;
 
-   common-fsg_num_buffers = cfg-fsg_num_buffers;
-   common-buffhds = kcalloc(common-fsg_num_buffers,
- sizeof *(common-buffhds), GFP_KERNEL);
-   if (!common-buffhds) {
+   rc = fsg_common_set_num_buffers(common, cfg-fsg_num_buffers);
+   if (rc) {
if (common-free_storage_on_release)
kfree(common);
-   return ERR_PTR(-ENOMEM);
+   return ERR_PTR(rc);
}
-
common-ops = cfg-ops;
common-private_data = cfg-private_data;
 
@@ -3092,21 +3084,6 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
}
common-nluns = nluns;
 
-   /* Data buffers cyclic list */
-   bh = common-buffhds;
-   i = common-fsg_num_buffers;
-   goto buffhds_first_it;
-   do {
-   bh-next = bh + 1;
-   ++bh;
-buffhds_first_it:
-   bh-buf = kmalloc(FSG_BUFLEN, GFP_KERNEL);
-   if (unlikely(!bh-buf)) {
-   rc = -ENOMEM;
-   goto error_release;
-   }
-   } while (--i);
-   bh-next = common-buffhds;
 
/* Prepare inquiryString */
i = get_default_bcdDevice();
-- 
1.7.9.5

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


[RFC 05/19] usb/gadget: f_mass_storage: use usb_gstrings_attach

2013-06-25 Thread Marek Szyprowski
From: Andrzej Pietrasiewicz andrze...@samsung.com

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/usb/gadget/f_mass_storage.c |   25 -
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index c386f76..8d0b451 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -242,6 +242,11 @@ static struct usb_gadget_strings   fsg_stringtab = {
.strings= fsg_strings,
 };
 
+static struct usb_gadget_strings *fsg_strings_array[] = {
+   fsg_stringtab,
+   NULL,
+};
+
 /*-*/
 
 struct fsg_dev;
@@ -2607,6 +2612,7 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
struct fsg_buffhd *bh;
struct fsg_lun **curlun;
struct fsg_lun_config *lcfg;
+   struct usb_string *us;
int nluns, i, rc;
char *pathbuf;
 
@@ -2649,14 +2655,13 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
common-ep0req = cdev-req;
common-cdev = cdev;
 
-   /* Maybe allocate device-global string IDs, and patch descriptors */
-   if (fsg_strings[FSG_STRING_INTERFACE].id == 0) {
-   rc = usb_string_id(cdev);
-   if (unlikely(rc  0))
-   goto error_release;
-   fsg_strings[FSG_STRING_INTERFACE].id = rc;
-   fsg_intf_desc.iInterface = rc;
+   us = usb_gstrings_attach(cdev, fsg_strings_array,
+ARRAY_SIZE(fsg_strings));
+   if (IS_ERR(us)) {
+   rc = PTR_ERR(us);
+   goto error_release;
}
+   fsg_intf_desc.iInterface = us[FSG_STRING_INTERFACE].id;
 
/*
 * Create the LUNs, open their backing files, and register the
@@ -2944,11 +2949,6 @@ autoconf_fail:
 
 /** ADD FUNCTION **/
 
-static struct usb_gadget_strings *fsg_strings_array[] = {
-   fsg_stringtab,
-   NULL,
-};
-
 static int fsg_bind_config(struct usb_composite_dev *cdev,
   struct usb_configuration *c,
   struct fsg_common *common)
@@ -2961,7 +2961,6 @@ static int fsg_bind_config(struct usb_composite_dev *cdev,
return -ENOMEM;
 
fsg-function.name= FSG_DRIVER_DESC;
-   fsg-function.strings = fsg_strings_array;
fsg-function.bind= fsg_bind;
fsg-function.unbind  = fsg_unbind;
fsg-function.setup   = fsg_setup;
-- 
1.7.9.5

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


[RFC 19/19] usb/gadget: f_mass_storage: add configfs support

2013-06-25 Thread Marek Szyprowski
From: Andrzej Pietrasiewicz andrze...@samsung.com

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 .../ABI/testing/configfs-usb-gadget-mass-storage   |   31 ++
 drivers/usb/gadget/Kconfig |   11 +
 drivers/usb/gadget/f_mass_storage.c|  362 
 drivers/usb/gadget/f_mass_storage.h|   17 +
 4 files changed, 421 insertions(+)
 create mode 100644 Documentation/ABI/testing/configfs-usb-gadget-mass-storage

diff --git a/Documentation/ABI/testing/configfs-usb-gadget-mass-storage 
b/Documentation/ABI/testing/configfs-usb-gadget-mass-storage
new file mode 100644
index 000..e1e918e
--- /dev/null
+++ b/Documentation/ABI/testing/configfs-usb-gadget-mass-storage
@@ -0,0 +1,31 @@
+What:  /config/usb-gadget/gadget/functions/mass_storage.name
+Date:  Jul 2013
+KenelVersion:  3.12
+Description:
+   The attributes:
+
+   stall   - Set to permit function to halt bulk endpoints.
+   Disabled on some USB devices known not to work
+   correctly. You should set it to true.
+   num_buffers - Number of pipeline buffers. Valid numbers
+   are 2..4. Available only if
+   CONFIG_USB_GADGET_DEBUG_FILES is set.
+
+What:  /config/usb-gadget/gadget/functions/mass_storage.name/lun.name
+Date:  Jul 2013
+KenelVersion:  3.12
+Description:
+   The attributes:
+
+   file- The path to the backing file for the LUN.
+   Required if LUN is not marked as removable.
+   ro  - Flag specifying access to the LUN shall be
+   read-only. This is implied if CD-ROM emulation
+   is enabled as well as when it was impossible
+   to open filename in R/W mode.
+   removable   - Flag specifying that LUN shall be indicated as
+   being removable.
+   cdrom   - Flag specifying that LUN shall be reported as
+   being a CD-ROM.
+   nofua   - Flag specifying that FUA flag
+   in SCSI WRITE(10,12)
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 0035732..757fe47 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -681,6 +681,17 @@ config USB_CONFIGFS_PHONET
help
  The Phonet protocol implementation for USB device.
 
+config USB_CONFIGFS_MASS_STORAGE
+   boolean Mass storage
+   depends on USB_CONFIGFS
+   select USB_U_MS
+   select USB_F_MASS_STORAGE
+   help
+ The Mass Storage Gadget acts as a USB Mass Storage disk drive.
+ As its storage repository it can use a regular file or a block
+ device (in much the same way as the loop device driver),
+ specified as a module parameter or sysfs option.
+
 config USB_ZERO
tristate Gadget Zero (DEVELOPMENT)
select USB_LIBCOMPOSITE
diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index a1a18a4..8920c66 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -220,6 +220,7 @@
 #include linux/usb/composite.h
 
 #include gadget_chips.h
+#include configfs.h
 
 
 /**/
@@ -3322,6 +3323,345 @@ static int fsg_bind_config(struct usb_composite_dev 
*cdev,
 
 #else
 
+static inline struct fsg_lun_opts *to_fsg_lun_opts(struct config_item *item)
+{
+   return container_of(to_config_group(item), struct fsg_lun_opts, group);
+}
+
+static inline struct fsg_opts *to_fsg_opts(struct config_item *item)
+{
+   return container_of(to_config_group(item), struct fsg_opts,
+   func_inst.group);
+}
+
+CONFIGFS_ATTR_STRUCT(fsg_lun_opts);
+CONFIGFS_ATTR_OPS(fsg_lun_opts);
+
+static void fsg_lun_attr_release(struct config_item *item)
+{
+   struct fsg_lun_opts *lun_opts;
+
+   lun_opts = to_fsg_lun_opts(item);
+   kfree(lun_opts);
+}
+
+static struct configfs_item_operations fsg_lun_item_ops = {
+   .release= fsg_lun_attr_release,
+   .show_attribute = fsg_lun_opts_attr_show,
+   .store_attribute = fsg_lun_opts_attr_store,
+};
+
+static ssize_t fsg_lun_opts_file_show(struct fsg_lun_opts *opts, char *page)
+{
+   struct fsg_opts *fsg_opts;
+
+   fsg_opts = to_fsg_opts(opts-group.cg_item.ci_parent);
+
+   return fsg_show_file(opts-lun, fsg_opts-common-filesem, page);
+}
+
+static ssize_t fsg_lun_opts_file_store(struct fsg_lun_opts *opts,
+  const char *page, size_t len)
+{
+   struct fsg_opts *fsg_opts;
+
+   fsg_opts = 

[RFC 06/19] usb/gadget: f_mass_storage: split fsg_common initialization into a number of functions

2013-06-25 Thread Marek Szyprowski
From: Andrzej Pietrasiewicz andrze...@samsung.com

When configfs is in place, the things related to intialization
of struct fsg_common will be split over a number of places.
This patch adds several functions which together cover the former
intialization routine fsg_common_init. As a consequence, issuing of
some debug messages needs to be adjusted.

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/usb/gadget/f_mass_storage.c |  400 +--
 drivers/usb/gadget/f_mass_storage.h |   31 +++
 drivers/usb/gadget/storage_common.c |   24 +--
 3 files changed, 430 insertions(+), 25 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index 8d0b451..fc3b5ff 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -299,6 +299,7 @@ struct fsg_common {
unsigned intshort_packet_received:1;
unsigned intbad_lun_okay:1;
unsigned intrunning:1;
+   unsigned intsysfs:1;
 
int thread_wakeup_needed;
struct completion   thread_notifier;
@@ -2604,6 +2605,374 @@ static inline int fsg_num_buffers_validate(unsigned int 
fsg_num_buffers)
return -EINVAL;
 }
 
+static struct fsg_common *fsg_common_setup(struct fsg_common *common, bool 
zero)
+{
+   if (!common) {
+   common = kzalloc(sizeof *common, GFP_KERNEL);
+   if (!common)
+   return ERR_PTR(-ENOMEM);
+   common-free_storage_on_release = 1;
+   } else {
+   if (zero)
+   memset(common, 0, sizeof *common);
+   common-free_storage_on_release = 0;
+   }
+   init_rwsem(common-filesem);
+   spin_lock_init(common-lock);
+   kref_init(common-ref);
+   init_completion(common-thread_notifier);
+   init_waitqueue_head(common-fsg_wait);
+   common-state = FSG_STATE_TERMINATED;
+
+   return common;
+}
+
+void fsg_common_set_sysfs(struct fsg_common *common, bool sysfs)
+{
+   common-sysfs = sysfs;
+}
+
+int fsg_common_set_num_buffers(struct fsg_common *common, unsigned int n)
+{
+   struct fsg_buffhd *bh, *new_buffhds;
+   int i, rc;
+
+   rc = fsg_num_buffers_validate(n);
+   if (rc != 0)
+   return rc;
+
+   new_buffhds = kcalloc(n, sizeof *(new_buffhds), GFP_KERNEL);
+   if (!new_buffhds)
+   return -ENOMEM;
+
+   /* Data buffers cyclic list */
+   bh = new_buffhds;
+   i = n;
+   goto buffhds_first_it;
+   do {
+   bh-next = bh + 1;
+   ++bh;
+buffhds_first_it:
+   bh-buf = kmalloc(FSG_BUFLEN, GFP_KERNEL);
+   if (unlikely(!bh-buf))
+   goto error_release;
+   } while (--i);
+   bh-next = new_buffhds;
+
+   common-fsg_num_buffers = n;
+   kfree(common-buffhds);
+   common-buffhds = new_buffhds;
+
+   return 0;
+
+error_release:
+   bh = new_buffhds;
+   i = n - i;
+   while (i--) {
+   kfree(bh-buf);
+   bh++;
+   };
+
+   kfree(new_buffhds);
+
+   return -ENOMEM;
+}
+
+void fsg_common_free_buffers(struct fsg_common *common)
+{
+   struct fsg_buffhd *bh;
+   int i;
+
+   bh = common-buffhds;
+   i = common-fsg_num_buffers;
+   while (i--) {
+   kfree(bh-buf);
+   bh++;
+   };
+
+   kfree(common-buffhds);
+   common-buffhds = NULL;
+}
+
+int fsg_common_set_nluns(struct fsg_common *common, int nluns)
+{
+   struct fsg_lun **curlun;
+
+   /* Find out how many LUNs there should be */
+   if (nluns  1 || nluns  FSG_MAX_LUNS) {
+   ERROR(common, invalid number of LUNs: %u\n, nluns);
+   return -EINVAL;
+   }
+
+   curlun = kcalloc(nluns, sizeof(*curlun), GFP_KERNEL);
+   if (unlikely(!curlun))
+   return -ENOMEM;
+
+   common-luns = curlun;
+   common-nluns = nluns;
+
+   pr_info(Number of LUNs=%d\n, common-nluns);
+
+   return 0;
+}
+
+void fsg_common_free_luns(struct fsg_common *common)
+{
+   kfree(common-luns);
+   common-luns = NULL;
+}
+
+void fsg_common_set_ops(struct fsg_common *common, const struct fsg_operations 
*ops)
+{
+   common-ops = ops;
+}
+
+void fsg_common_set_private_data(struct fsg_common *common, void *priv)
+{
+   common-private_data = priv;
+}
+
+int fsg_common_set_cdev(struct fsg_common *common,
+struct usb_composite_dev *cdev, bool can_stall)
+{
+   struct usb_string *us;
+   int rc;
+
+   common-gadget = cdev-gadget;
+   common-ep0 = cdev-gadget-ep0;
+   common-ep0req = cdev-req;
+   common-cdev = cdev;
+
+   us = usb_gstrings_attach(cdev, fsg_strings_array,
+ARRAY_SIZE(fsg_strings));

[RFC 16/19] usb/gadget: mass_storage: convert to new interface of f_mass_storage

2013-06-25 Thread Marek Szyprowski
From: Andrzej Pietrasiewicz andrze...@samsung.com

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/usb/gadget/Kconfig|1 +
 drivers/usb/gadget/mass_storage.c |  107 +++--
 2 files changed, 81 insertions(+), 27 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index ffc1791..0035732 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -898,6 +898,7 @@ config USB_MASS_STORAGE
depends on BLOCK
select USB_LIBCOMPOSITE
select USB_U_MS
+   select USB_F_MASS_STORAGE
help
  The Mass Storage Gadget acts as a USB Mass Storage disk drive.
  As its storage repository it can use a regular file or a block
diff --git a/drivers/usb/gadget/mass_storage.c 
b/drivers/usb/gadget/mass_storage.c
index 6b79814..a9b5c95 100644
--- a/drivers/usb/gadget/mass_storage.c
+++ b/drivers/usb/gadget/mass_storage.c
@@ -46,17 +46,7 @@
 #define FSG_VENDOR_ID  0x0525  /* NetChip */
 #define FSG_PRODUCT_ID 0xa4a5  /* Linux-USB File-backed Storage Gadget */
 
-/*-*/
-
-/*
- * kbuild is not very cooperative with respect to linking separately
- * compiled library objects into one module.  So for now we won't use
- * separate compilation ... ensuring init/exit sections work to shrink
- * the runtime footprint, and giving us at least some parts of what
- * a gcc --combine ... part1.c part2.c part3.c ...  build would.
- */
-#define USB_FMS_INCLUDED
-#include f_mass_storage.c
+#include f_mass_storage.h
 
 /*-*/
 USB_GADGET_COMPOSITE_OPTIONS();
@@ -107,6 +97,9 @@ static struct usb_gadget_strings *dev_strings[] = {
NULL,
 };
 
+static struct usb_function_instance *fi_msg;
+static struct usb_function *f_msg;
+
 /** Configurations **/
 
 static struct fsg_module_parameters mod_data = {
@@ -139,13 +132,7 @@ static int msg_thread_exits(struct fsg_common *common)
 
 static int __init msg_do_config(struct usb_configuration *c)
 {
-   static const struct fsg_operations ops = {
-   .thread_exits = msg_thread_exits,
-   };
-   static struct fsg_common common;
-
-   struct fsg_common *retp;
-   struct fsg_config config;
+   struct fsg_opts *opts;
int ret;
 
if (gadget_is_otg(c-cdev-gadget)) {
@@ -153,15 +140,24 @@ static int __init msg_do_config(struct usb_configuration 
*c)
c-bmAttributes |= USB_CONFIG_ATT_WAKEUP;
}
 
-   fsg_config_from_params(config, mod_data, fsg_num_buffers);
-   config.ops = ops;
+   opts = container_of(fi_msg, struct fsg_opts, func_inst);
+
+   f_msg = usb_get_function(fi_msg);
+   if (IS_ERR(f_msg))
+   return PTR_ERR(f_msg);
 
-   retp = fsg_common_init(common, c-cdev, config);
-   if (IS_ERR(retp))
-   return PTR_ERR(retp);
+   ret = fsg_common_run_thread(opts-common);
+   if (ret)
+   goto put_func;
 
-   ret = fsg_bind_config(c-cdev, c, common);
-   fsg_common_put(common);
+   ret = usb_add_function(c, f_msg);
+   if (ret)
+   goto put_func;
+
+   return 0;
+
+put_func:
+   usb_put_function(f_msg);
return ret;
 }
 
@@ -176,23 +172,79 @@ static struct usb_configuration msg_config_driver = {
 
 static int __init msg_bind(struct usb_composite_dev *cdev)
 {
+   static const struct fsg_operations ops = {
+   .thread_exits = msg_thread_exits,
+   };
+   struct fsg_opts *opts;
+   struct fsg_config config;
int status;
 
+   fi_msg = usb_get_function_instance(mass_storage);
+   if (IS_ERR(fi_msg))
+   return PTR_ERR(fi_msg);
+
+   fsg_config_from_params(config, mod_data, fsg_num_buffers);
+   opts = container_of(fi_msg, struct fsg_opts, func_inst);
+
+   opts-no_configfs = true;
+   fsg_common_set_sysfs(opts-common, true);
+   status = fsg_common_set_num_buffers(opts-common, fsg_num_buffers);
+   if (status)
+   goto fail;
+
+   status = fsg_common_set_nluns(opts-common, config.nluns);
+   if (status)
+   goto fail_set_nluns;
+
+   fsg_common_set_ops(opts-common, ops);
+
+   status = fsg_common_set_cdev(opts-common, cdev, config.can_stall);
+   if (status)
+   goto fail_set_cdev;
+
+   status = fsg_common_create_luns(opts-common, config);
+   if (status)
+   goto fail_set_cdev;
+
+   fsg_common_set_inquiry_string(opts-common, config.vendor_name,
+ config.product_name);
+
status = usb_string_ids_tab(cdev, strings_dev);
if (status  0)
-   return status;
+   goto fail_string_ids;

[RFC 17/19] usb/gadget: storage_common: make attribute operations more generic

2013-06-25 Thread Marek Szyprowski
From: Andrzej Pietrasiewicz andrze...@samsung.com

Show/store methods for sysfs attributes contain code which can be used
also by configfs. Make them abstract the source the lun and rw_semaphore
are taken from.

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/usb/gadget/f_mass_storage.c |   67 ---
 drivers/usb/gadget/storage_common.c |   36 +--
 drivers/usb/gadget/storage_common.h |   21 +--
 3 files changed, 81 insertions(+), 43 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index 22a68f7..a1a18a4 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -2567,14 +2567,71 @@ static int fsg_main_thread(void *common_)
 
 /*** DEVICE ATTRIBUTES ***/
 
-static DEVICE_ATTR(ro, 0644, fsg_show_ro, fsg_store_ro);
-static DEVICE_ATTR(nofua, 0644, fsg_show_nofua, fsg_store_nofua);
-static DEVICE_ATTR(file, 0644, fsg_show_file, fsg_store_file);
+static ssize_t sysfs_fsg_show_ro(struct device *dev,
+struct device_attribute *attr,
+char *buf)
+{
+   struct fsg_lun  *curlun = fsg_lun_from_dev(dev);
+
+   return fsg_show_ro(curlun, buf);
+}
+
+static ssize_t sysfs_fsg_show_nofua(struct device *dev,
+   struct device_attribute *attr,
+   char *buf)
+{
+   struct fsg_lun  *curlun = fsg_lun_from_dev(dev);
+
+   return fsg_show_nofua(curlun, buf);
+}
+
+static ssize_t sysfs_fsg_show_file(struct device *dev,
+  struct device_attribute *attr,
+  char *buf)
+{
+   struct fsg_lun  *curlun = fsg_lun_from_dev(dev);
+   struct rw_semaphore *filesem = dev_get_drvdata(dev);
+
+   return fsg_show_file(curlun, filesem, buf);
+}
+
+static ssize_t sysfs_fsg_store_ro(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+   struct fsg_lun  *curlun = fsg_lun_from_dev(dev);
+   struct rw_semaphore *filesem = dev_get_drvdata(dev);
+
+   return fsg_store_ro(curlun, filesem, buf, count);
+}
+
+static ssize_t sysfs_fsg_store_nofua(struct device *dev,
+struct device_attribute *attr,
+const char *buf, size_t count)
+{
+   struct fsg_lun  *curlun = fsg_lun_from_dev(dev);
+
+   return fsg_store_nofua(curlun, buf, count);
+}
+
+static ssize_t sysfs_fsg_store_file(struct device *dev,
+   struct device_attribute *attr,
+   const char *buf, size_t count)
+{
+   struct fsg_lun  *curlun = fsg_lun_from_dev(dev);
+   struct rw_semaphore *filesem = dev_get_drvdata(dev);
+
+   return fsg_store_file(curlun, filesem, buf, count);
+}
+
+static DEVICE_ATTR(ro, 0644, sysfs_fsg_show_ro, sysfs_fsg_store_ro);
+static DEVICE_ATTR(nofua, 0644, sysfs_fsg_show_nofua, sysfs_fsg_store_nofua);
+static DEVICE_ATTR(file, 0644, sysfs_fsg_show_file, sysfs_fsg_store_file);
 
 static struct device_attribute dev_attr_ro_cdrom =
-   __ATTR(ro, 0444, fsg_show_ro, NULL);
+   __ATTR(ro, 0444, sysfs_fsg_show_ro, NULL);
 static struct device_attribute dev_attr_file_nonremovable =
-   __ATTR(file, 0444, fsg_show_file, NULL);
+   __ATTR(file, 0444, sysfs_fsg_show_file, NULL);
 
 
 /** FSG COMMON **/
diff --git a/drivers/usb/gadget/storage_common.c 
b/drivers/usb/gadget/storage_common.c
index a70a5d3..5e4d476 100644
--- a/drivers/usb/gadget/storage_common.c
+++ b/drivers/usb/gadget/storage_common.c
@@ -31,11 +31,6 @@
 
 #include storage_common.h
 
-static inline struct fsg_lun *fsg_lun_from_dev(struct device *dev)
-{
-   return container_of(dev, struct fsg_lun, dev);
-}
-
 /* There is only one interface. */
 
 struct usb_interface_descriptor fsg_intf_desc = {
@@ -324,31 +319,23 @@ EXPORT_SYMBOL(store_cdrom_address);
 /*-*/
 
 
-ssize_t fsg_show_ro(struct device *dev, struct device_attribute *attr,
-  char *buf)
+ssize_t fsg_show_ro(struct fsg_lun *curlun, char *buf)
 {
-   struct fsg_lun  *curlun = fsg_lun_from_dev(dev);
-
return sprintf(buf, %d\n, fsg_lun_is_open(curlun)
  ? curlun-ro
  : curlun-initially_ro);
 }
 EXPORT_SYMBOL(fsg_show_ro);
 
-ssize_t fsg_show_nofua(struct device *dev, struct device_attribute *attr,
- char *buf)
+ssize_t fsg_show_nofua(struct fsg_lun *curlun, char *buf)
 {
-   struct 

[RFC 03/19] usb/gadget: f_mass_storage: factor out a header file

2013-06-25 Thread Marek Szyprowski
From: Andrzej Pietrasiewicz andrze...@samsung.com

In order to prepare for the new function interface the f_mass_storage.c
needs to be compiled as a module, and so a header file will be required.
This patch factors out some code to a new f_mass_storage.h.

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/usb/gadget/f_mass_storage.c |  117 ++--
 drivers/usb/gadget/f_mass_storage.h |  126 +++
 2 files changed, 133 insertions(+), 110 deletions(-)
 create mode 100644 drivers/usb/gadget/f_mass_storage.h

diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index 163d911..c36e208 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -229,6 +229,7 @@
 static const char fsg_string_interface[] = Mass Storage;
 
 #include storage_common.h
+#include f_mass_storage.h
 
 /* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */
 static struct usb_string   fsg_strings[] = {
@@ -246,18 +247,6 @@ static struct usb_gadget_strings   fsg_stringtab = {
 struct fsg_dev;
 struct fsg_common;
 
-/* FSF callback functions */
-struct fsg_operations {
-   /*
-* Callback function to call when thread exits.  If no
-* callback is set or it returns value lower then zero MSF
-* will force eject all LUNs it operates on (including those
-* marked as non-removable or with prevent_medium_removal flag
-* set).
-*/
-   int (*thread_exits)(struct fsg_common *common);
-};
-
 /* Data shared by all the FSG instances. */
 struct fsg_common {
struct usb_gadget   *gadget;
@@ -324,28 +313,6 @@ struct fsg_common {
struct kref ref;
 };
 
-struct fsg_config {
-   unsigned nluns;
-   struct fsg_lun_config {
-   const char *filename;
-   char ro;
-   char removable;
-   char cdrom;
-   char nofua;
-   } luns[FSG_MAX_LUNS];
-
-   /* Callback functions. */
-   const struct fsg_operations *ops;
-   /* Gadget's private data. */
-   void*private_data;
-
-   const char *vendor_name;/*  8 characters or less */
-   const char *product_name;   /* 16 characters or less */
-
-   charcan_stall;
-   unsigned intfsg_num_buffers;
-};
-
 struct fsg_dev {
struct usb_function function;
struct usb_gadget   *gadget;/* Copy of cdev-gadget */
@@ -2609,12 +2576,12 @@ static void fsg_lun_release(struct device *dev)
/* Nothing needs to be done */
 }
 
-static inline void fsg_common_get(struct fsg_common *common)
+void fsg_common_get(struct fsg_common *common)
 {
kref_get(common-ref);
 }
 
-static inline void fsg_common_put(struct fsg_common *common)
+void fsg_common_put(struct fsg_common *common)
 {
kref_put(common-ref, fsg_common_release);
 }
@@ -2629,9 +2596,9 @@ static inline int fsg_num_buffers_validate(unsigned int 
fsg_num_buffers)
return -EINVAL;
 }
 
-static struct fsg_common *fsg_common_init(struct fsg_common *common,
- struct usb_composite_dev *cdev,
- struct fsg_config *cfg)
+struct fsg_common *fsg_common_init(struct fsg_common *common,
+  struct usb_composite_dev *cdev,
+  struct fsg_config *cfg)
 {
struct usb_gadget *gadget = cdev-gadget;
struct fsg_buffhd *bh;
@@ -3008,62 +2975,8 @@ static int fsg_bind_config(struct usb_composite_dev 
*cdev,
 
 /* Module parameters */
 
-struct fsg_module_parameters {
-   char*file[FSG_MAX_LUNS];
-   boolro[FSG_MAX_LUNS];
-   boolremovable[FSG_MAX_LUNS];
-   boolcdrom[FSG_MAX_LUNS];
-   boolnofua[FSG_MAX_LUNS];
-
-   unsigned intfile_count, ro_count, removable_count, cdrom_count;
-   unsigned intnofua_count;
-   unsigned intluns;   /* nluns */
-   boolstall;  /* can_stall */
-};
-
-#define _FSG_MODULE_PARAM_ARRAY(prefix, params, name, type, desc)  \
-   module_param_array_named(prefix ## name, params.name, type, \
-prefix ## params.name ## _count,  \
-S_IRUGO);  \
-   MODULE_PARM_DESC(prefix ## name, desc)
-
-#define _FSG_MODULE_PARAM(prefix, params, name, type, desc)\
-   module_param_named(prefix ## name, params.name, type,   \
-  S_IRUGO);\
-   MODULE_PARM_DESC(prefix ## name, desc)
-
-#define __FSG_MODULE_PARAMETERS(prefix, params)

Re: Fwd: Re: Bug#704242: Driver for PL-2303 HX not working

2013-06-25 Thread Karsten Malcher

Hello Greg,

Am 24.06.2013 20:56, schrieb Greg KH:

But wiring that up to a real 9pin serial port would be a pain (doable,
but a pain).  Is there any devices out there with a DB-9 output
connector?

You mean if you want to test full handshake with all signals - that's true.

Which is what the driver needs to test, right?  And of course, everone
with this problem is properly hooking up these signals, right?


I can't speak for all applications but i never use the hardware handshake for 
data transfer.
As i have written i don't know applications that will do it. Like most of the 
older mobile adapters.
That's the reason why this PL-2303 HX adapter has no handshake signals outside.

Maybe some people abuse this input and output lines for IO purposes like for 
programmers.
One time is tried such an adapter like this but it does not work. ;-)
http://www.lancos.com/siprogsch.html
(I tried not to use it with an usb serial interface - i used a good and old PC 
UART.)


Otherwise, there will be problems as the pins could float and cause
transmissions / receive data to stop happening.


This should not happen if handshake is disabled.
In the case of this PL-2303 HX adapter it worked with windows and the older 
kernel without handshake.

But of course it is better when everything is tested.



At the least, loop-back testing is important.


This test is sufficient to see if the problem occurs.




The advantage of the adapter is to get directly 5V and 3,3V.

What do you mean by this?


Normally you use this adapters to transfer data from a microcontroller.
It is very useful when you have direct the necessary power supply for the 
microcontroller.
The PL-2303 can work with 5V and 3.3V logic and this adapter has also a 3.3V 
output for some mA.




I don't know some other adapter with exactly this chip, because i don't need 
them.
Only this Adapter which use the other chip ch341-uart which works without 
problems
http://www.ebay.com/itm/USB-to-RS232-Serial-9-Pin-DB9-Adapter-PC-PDA-RS-232-/180399132966

When i think about it i never seen that someone uses the handshake for this 
simple serial communication.
Not in communication with mobiles, ARM-boards or AVR microcontroller.
The built-in UART's in the ARM and AVR don't suffer handshake
signals, so that you must do it by software with additional IO
ports.

What's wrong with software flow control?


Nothing is wrong with it!
I just want to say that in most applications nobody use it.
You communicate from a quick PC to a slower microcontroller with at least slow 
data rates.
The microcontroller has an IRQ on the UART you can use for incoming data.
So this works normally without any problems and additional handshake.


   Why reinvent something that
has been successfully used for 30+ years?


Before 30 years computers where slow and without a multitasking OS.
So you need handshake when you don't want to loose data.

i think you misunderstand me.



thanks,

greg k-h


Regards
Karsten

--
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 3/4] usb: gadget: at91_udc: prepare clk before calling enable

2013-06-25 Thread Boris BREZILLON
Replace clk_enable/disable with clk_prepare_enable/disable_unprepare to
avoid common clk framework warnings.

Signed-off-by: Boris BREZILLON b.brezil...@overkiz.com
---
 drivers/usb/gadget/at91_udc.c |   14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index 073b938..fce8e4e 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -870,8 +870,8 @@ static void clk_on(struct at91_udc *udc)
if (udc-clocked)
return;
udc-clocked = 1;
-   clk_enable(udc-iclk);
-   clk_enable(udc-fclk);
+   clk_prepare_enable(udc-iclk);
+   clk_prepare_enable(udc-fclk);
 }
 
 static void clk_off(struct at91_udc *udc)
@@ -880,8 +880,8 @@ static void clk_off(struct at91_udc *udc)
return;
udc-clocked = 0;
udc-gadget.speed = USB_SPEED_UNKNOWN;
-   clk_disable(udc-fclk);
-   clk_disable(udc-iclk);
+   clk_disable_unprepare(udc-fclk);
+   clk_disable_unprepare(udc-iclk);
 }
 
 /*
@@ -1782,12 +1782,14 @@ static int at91udc_probe(struct platform_device *pdev)
}
 
/* don't do anything until we have both gadget driver and VBUS */
-   clk_enable(udc-iclk);
+   retval = clk_prepare_enable(udc-iclk);
+   if (retval)
+   goto fail1;
at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS);
at91_udp_write(udc, AT91_UDP_IDR, 0x);
/* Clear all pending interrupts - UDP may be used by bootloader. */
at91_udp_write(udc, AT91_UDP_ICR, 0x);
-   clk_disable(udc-iclk);
+   clk_disable_unprepare(udc-iclk);
 
/* request UDC and maybe VBUS irqs */
udc-udp_irq = platform_get_irq(pdev, 0);
-- 
1.7.9.5

--
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: Bug#704242: Driver for PL-2303 HX not working

2013-06-25 Thread Karsten Malcher

Am 24.06.2013 21:00, schrieb Greg KH:

Personally, I have resolved to abandon the PL2303 chip, and move to
FTDI instead. But for the sake of other Linux users who might buy that
adapter by mistake, I am willing to donate the hardware to an able
kernel hacker :-)
Yes, I recommend the ftdi devices as well, the specs are availble, and
the driver seems to work better because of it.


Yes - i agree.
But you have no influence which chip is used when you buy an adapter or 
interface cable.
There are millions out there for mobiles, GPS, PDA, etc.
It's a pity when you can't connect your device because the usb serial chip is 
not supported in Linux.
(When you have a newer device you will find out that bluetooth is not working 
correct also.)



thanks,

greg k-h


Regards
Karsten
--
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] build some drivers only when compile-testing

2013-06-25 Thread Jiri Slaby
On 06/25/2013 01:42 AM, Greg Kroah-Hartman wrote:
 On Wed, Jun 19, 2013 at 08:50:08AM +0200, Jiri Slaby wrote:
 On 06/18/2013 06:04 PM, Greg Kroah-Hartman wrote:
 So currently I have what is attached... Comments?

 Looks good to me, want me to queue it up through my char/misc driver
 tree for 3.11?

 If there are no objections... Whoever picks that up, I would be happy 8-).
 
 I've taken it, without the chipidea portion, through my driver-core
 tree.

Ok thanks. (FWIW I sent v3 without the chipidea change too...)

-- 
js
suse labs
--
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: ci13xxx_imx: Access phy via private data

2013-06-25 Thread Alexander Shishkin
Fabio Estevam fabio.este...@freescale.com writes:

 commit ea1418b5f1a (usb: chipidea: i.MX: use devm_usb_get_phy_by_phandle to 
 get
 phy) causes the USB host to miss the disconnect/connect events.

 In order to reproduce this problem:

 - Insert a USB thumb into the USB host port (connection is detected)
 - Remove it (no disconnect event will be reported)
 - Insert the USB thumb again (connection is not detected)

 Fix this problem by accessing the usb_phy structure using the private data 
 instead of accessing a local structure.

 Tested on a mx28evk board.

 Signed-off-by: Fabio Estevam fabio.este...@freescale.com

Looks good, thanks. I'll send it to Greg in a bit, there's a conflict
with the mass renaming patch.

Regards,
--
Alex
--
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 0/1] usb: chipidea: imx fix

2013-06-25 Thread Alexander Shishkin
Hi,

Here is one more fix for the usb-next.

Fabio Estevam (1):
  usb: chipidea: ci_hdrc_imx: access phy via private data

 drivers/usb/chipidea/ci_hdrc_imx.c |9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

-- 
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/1] usb: chipidea: ci_hdrc_imx: access phy via private data

2013-06-25 Thread Alexander Shishkin
From: Fabio Estevam fabio.este...@freescale.com

commit ea1418b5f1a (usb: chipidea: i.MX: use devm_usb_get_phy_by_phandle to get
phy) causes the USB host to miss the disconnect/connect events.

In order to reproduce this problem:

- Insert a USB thumb into the USB host port (connection is detected)
- Remove it (no disconnect event will be reported)
- Insert the USB thumb again (connection is not detected)

Fix this problem by accessing the usb_phy structure using the private data
instead of accessing a local structure.

Tested on a mx28evk board.

Signed-off-by: Fabio Estevam fabio.este...@freescale.com
Acked-by: Peter Chen peter.c...@freescale.com
Signed-off-by: Alexander Shishkin alexander.shish...@linux.intel.com
---
 drivers/usb/chipidea/ci_hdrc_imx.c |9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c 
b/drivers/usb/chipidea/ci_hdrc_imx.c
index 37fdae5..14362c0 100644
--- a/drivers/usb/chipidea/ci_hdrc_imx.c
+++ b/drivers/usb/chipidea/ci_hdrc_imx.c
@@ -98,7 +98,6 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
};
struct resource *res;
int ret;
-   struct usb_phy *phy;
 
if (of_find_property(pdev-dev.of_node, fsl,usbmisc, NULL)
 !usbmisc_ops)
@@ -130,14 +129,14 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
return ret;
}
 
-   phy = devm_usb_get_phy_by_phandle(pdev-dev, fsl,usbphy, 0);
-   if (!IS_ERR(phy)) {
-   ret = usb_phy_init(phy);
+   data-phy = devm_usb_get_phy_by_phandle(pdev-dev, fsl,usbphy, 0);
+   if (!IS_ERR(data-phy)) {
+   ret = usb_phy_init(data-phy);
if (ret) {
dev_err(pdev-dev, unable to init phy: %d\n, ret);
goto err_clk;
}
-   } else if (PTR_ERR(phy) == -EPROBE_DEFER) {
+   } else if (PTR_ERR(data-phy) == -EPROBE_DEFER) {
ret = -EPROBE_DEFER;
goto err_clk;
}
-- 
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: Proposed modification to PL2303 driver

2013-06-25 Thread Reinhard Max

Hi Greg,

coincidentally, I also tested non-standard baudrates on a PL2303 these 
days and was about to start a similar thread when I found this one...


On Fri, 14 Jun 2013 at 18:58, Greg KH wrote:


On Fri, Jun 14, 2013 at 11:20:01AM +0200, Mastro Gippo wrote:

PS: this device (at least mine) WILL support 250K baudrate, as in 
windows I can set it in any software I use, and the output is spot 
on, measured with a digital oscilloscope.


That's good to know, which model is it?  Remember, the pl2303 driver 
supports at least 3 generations of this chipset (maybe 4).  All of 
them seem to work just a little bit differently.


I've tested[1] 250kBaud and even some strange baud rates such as 
345678 and 77 on a PL2303HX based device and got plausible numbers 
(same percentage off as nearby standard rates) when measuring the time 
it takes to send and receive 1000 bytes after through a RX/TX loop.


This looks to me like at least the HX variant does support arbitrary 
baud rates and it definitely doesn't fall back to 9600 as stated in 
the comment above the rounding loop.


So, how about starting to get rid of the baud rate list by skipping it 
for HX chips only until someone with a type_0 or type_1 devices can 
confirm that it works there as well?


BTW, newer revisions of the things that Prolific calls datasheets have 
a note next to the baud rate list that says, For special baud rate 
requirements, please contact Prolific FAE for driver customization 
support., which I take as a confirmation that the limit to standard 
rates is only imposed by the driver.


BTW2, the open source OSX driver[2] to which Prolific links from their 
support page, detects the chip revision, based on the USB device 
release number instead of guessing it from other properties of the 
device.


cu
Reinhard

[1] As a quick way for testing the capability of the hardware without 
having to worry about getting a non-standard baud rate through glibc 
and the kernel down to the driver, I hacked the driver to turn a 
request for 75 baud into the rate I wanted to test.


[2] http://sourceforge.net/p/osx-pl2303/code/HEAD/tree/trunk

--
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] staging: usbip: replace pr_warning() with pr_warn()

2013-06-25 Thread navin patidar
On Tue, Jun 25, 2013, Greg KH gre...@linuxfoundation.org said:

 On Fri, Jun 21, 2013 at 03:01:04PM +0530, navin patidar wrote:
 pr_warn() is preferred over pr_warning().

 And dev_warn() is preferred over both of them, can you convert the code
 to use that instead?


struct device is not available in usbip_start_eh()  which is required
for dev_warn().

usbip_device's containers struct stub_device and struct  vhci_device
both have member structure usb_device but inside usbip_start_eh(), it
is difficult to determine  to which container struct usbip_device
belongs, thus container_of() can not be used here to get struct
usb_device.


regards,
--navin-patidar
--
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


xhci_hcd: Signal/Timeout while waiting for evaluate context command then Assuming host is dying, halting host

2013-06-25 Thread Jérôme Carretero
Hi,

I am seeing that with an acquisition board:

[27044.406737] usb 4-4.4: usb_probe_device
[27044.406739] usb 4-4.4: configuration #1 chosen from 1 choice
[27044.406803] usb 4-4.4: Successful Endpoint Configure command
[27044.418946] usb 4-4.4: Successful evaluate context command
[27044.421725] usb 4-4.4: Successful evaluate context command
[27044.425133] usb 4-4.4: adding 4-4.4:1.0 (config #1, interface 0)
[27098.096802] usb 4-4.4: Successful evaluate context command
[27098.096993] usb 4-4.4: Successful evaluate context command
[27098.100436] usb 4-4.4: Successful evaluate context command
[27307.822372] xhci_hcd :00:14.0: Signal while waiting for evaluate context 
command
[27307.822381] usb 4-4.4: Could not disable xHCI U2 timeout, bus schedule 
bandwidth may be impacted.
[27307.822493] xhci_hcd :00:14.0: Signal while waiting for evaluate context 
command
[27307.822500] usb 4-4.4: Could not enable U1 link state, xHCI error -62.
[27878.845220] xhci_hcd :00:14.0: Timeout while waiting for evaluate 
context command
[27878.845230] usb 4-4.4: Could not disable xHCI U2 timeout, bus schedule 
bandwidth may be impacted.
[27883.840337] xhci_hcd :00:14.0: Timeout while waiting for evaluate 
context command
[27883.840348] usb 4-4.4: Could not enable U1 link state, xHCI error -62.
[27888.955329] xhci_hcd :00:14.0: xHCI host not responding to stop endpoint 
command.
[27888.955336] xhci_hcd :00:14.0: Assuming host is dying, halting host.
[27888.955396] xhci_hcd :00:14.0: HC died; cleaning up
[27888.955419] hub 3-0:1.0: state 0 ports 4 chg  evt 
[27888.955426] usb 3-4: USB disconnect, device number 2
[27888.955428] usb 3-4: unregistering device
[27888.955430] usb 3-4: unregistering interface 3-4:1.0
[27888.99] usb 3-4: usb_disable_device nuking all URBs
[27888.955701] xhci_hcd :00:14.0: Slot 2 endpoint 2 not removed from BW 
list!
[27888.955715] hub 4-0:1.0: state 0 ports 4 chg  evt 
[27888.955719] usb 4-4: USB disconnect, device number 8
[27888.955722] usb 4-4.4: USB disconnect, device number 15
[27888.955723] usb 4-4.4: unregistering device
[27888.955726] usb 4-4.4: unregistering interface 4-4.4:1.0
[27888.955763] usb 4-4.4: Failed to set U1 timeout to 0x0,error code -19
[27888.955767] usb 4-4.4: Set SEL for device-initiated U1 failed.
[27888.955769] usb 4-4.4: Set SEL for device-initiated U2 failed.
[27888.955785] usb 4-4.4: Failed to set U1 timeout to 0x0,error code -19
[27888.955788] usb 4-4.4: Set SEL for device-initiated U1 failed.
[27888.955790] usb 4-4.4: Set SEL for device-initiated U2 failed.
[27888.955794] usb 4-4.4: usb_disable_device nuking all URBs
[27888.955891] usb 4-4: unregistering device
[27888.955893] usb 4-4: unregistering interface 4-4:1.0
[27888.955925] usb 4-4: Failed to set U1 timeout to 0x0,error code -19
[27888.955929] usb 4-4: Set SEL for device-initiated U1 failed.
[27888.955931] usb 4-4: Set SEL for device-initiated U2 failed.
[27888.955996] usb 4-4: Failed to set U1 timeout to 0x0,error code -19
[27888.956000] usb 4-4: Set SEL for device-initiated U1 failed.
[27888.956004] usb 4-4: Set SEL for device-initiated U2 failed.
[27888.956007] usb 4-4: usb_disable_device nuking all URBs

Today this was running linux 3.10-rc6 but I've seen that before.

This is very similar to a report I found here:
http://ubuntuforums.org/showthread.php?t=2149484

Has anybody seen that?

In my case I'm using libusb to talk with a board.

Note: this is running on an Intel Sandy Bridge USB3.0 port...
So far I have seen many issues with non-Intel USB3.0 controllers
and that same board.

Thanks,

-- 
cJ
--
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/4] USB: HCD: support giveback of URB in tasklet context

2013-06-25 Thread Ming Lei
On Mon, Jun 24, 2013 at 11:17 PM, Alan Stern st...@rowland.harvard.edu wrote:
 On Mon, 24 Jun 2013, Ming Lei wrote:

 This patch implements the mechanism of giveback of URB in
 tasklet context, so that hardware interrupt handling time for
 usb host controller can be saved much, and HCD interrupt handling
 can be simplified.

 Changes from v1 to v2?

The change log is put in 0/4.



 +static void usb_giveback_urb_bh(unsigned long param)
 +{
 + struct giveback_urb_bh *bh = (struct giveback_urb_bh *)param;
 + unsigned long flags;
 + struct list_head local_list;
 +
 + spin_lock_irqsave(bh-lock, flags);
 + bh-running = 1;
 + restart:
 + list_replace_init(bh-head, local_list);
 + spin_unlock_irqrestore(bh-lock, flags);

 Tasklet routines are always called with interrupts enabled, right?
 Therefore you don't need to use the flags argument here or below.

Good catch.


 @@ -1667,25 +1721,40 @@ int usb_hcd_unlink_urb (struct urb *urb, int status)
   */
  void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb, int status)
  {
 - urb-hcpriv = NULL;
 - if (unlikely(urb-unlinked))
 - status = urb-unlinked;
 - else if (unlikely((urb-transfer_flags  URB_SHORT_NOT_OK) 
 - urb-actual_length  urb-transfer_buffer_length 
 - !status))
 - status = -EREMOTEIO;
 + struct giveback_urb_bh *bh;
 + bool sched, high_prio_bh;

 - unmap_urb_for_dma(hcd, urb);
 - usbmon_urb_complete(hcd-self, urb, status);
 - usb_unanchor_urb(urb);
 + /* pass status to tasklet via unlinked */
 + if (likely(!urb-unlinked))
 + urb-unlinked = status;

 - /* pass ownership to the completion handler */
 - urb-status = status;
 - urb-complete (urb);
 - atomic_dec (urb-use_count);
 - if (unlikely(atomic_read(urb-reject)))
 - wake_up (usb_kill_urb_queue);
 - usb_put_urb (urb);
 + if (!hcd_giveback_urb_in_bh(hcd)  !is_root_hub(urb-dev)) {
 + __usb_hcd_giveback_urb(urb);
 + return;
 + }
 +
 + if (usb_pipeisoc(urb-pipe) || usb_pipeint(urb-pipe)) {
 + bh = hcd-high_prio_bh;
 + high_prio_bh = 1;
 + } else {
 + bh = hcd-low_prio_bh;
 + high_prio_bh = 0;
 + }

 Bool values should be assigned true or false, not 1 or 0.

Right.


 +
 + spin_lock(bh-lock);
 + list_add_tail(urb-urb_list, bh-head);
 + if (bh-running)
 + sched = 0;
 + else
 + sched = 1;
 + spin_unlock(bh-lock);

 How about calling this variable running instead of sched?  Then you
 could just say:

 running = bh-running;

 with no if statement.

OK, even we can do this below without name change:

   sched = !bh-running;


 +
 + if (!sched)
 + ;
 + else if (high_prio_bh)
 + tasklet_hi_schedule(bh-bh);
 + else
 + tasklet_schedule(bh-bh);
  }
  EXPORT_SYMBOL_GPL(usb_hcd_giveback_urb);

 @@ -2307,6 +2376,42 @@ EXPORT_SYMBOL_GPL (usb_hc_died);

  
 /*-*/

 +static void __init_giveback_urb_bh(struct giveback_urb_bh *bh)
 +{
 +
 + spin_lock_init(bh-lock);
 + INIT_LIST_HEAD(bh-head);
 + tasklet_init(bh-bh, usb_giveback_urb_bh, (unsigned long)bh);
 +}
 +
 +static void init_giveback_urb_bh(struct usb_hcd *hcd)
 +{
 + if (!hcd_giveback_urb_in_bh(hcd))
 + return;

 As you mentioned, there's not much point in skipping this code when
 it's not needed.  In fact, you could just put the two lines below
 directly into usb_create_shared_hcd(), and get rid of the __ from the
 beginning of the name.

OK.


 +
 + __init_giveback_urb_bh(hcd-high_prio_bh);
 + __init_giveback_urb_bh(hcd-low_prio_bh);
 +}
 +
 +static void exit_giveback_urb_bh(struct usb_hcd *hcd)
 +{
 + if (!hcd_giveback_urb_in_bh(hcd))
 + return;
 +
 + /*
 +  * tasklet_kill() isn't needed here because:
 +  * - driver's disconnec() called from usb_disconnect() should

 Misspelled disconnect.

 +  *   make sure its URBs are completed during the disconnect()
 +  *   callback
 +  *
 +  * - it is too late to run complete() here since driver may have
 +  *   been removed already now
 +  *
 +  * Using tasklet to run URB's complete() doesn't change this
 +  * behavior of usbcore.
 +  */
 +}

 Why have a separate subroutine for doing nothing?  Simply put this
 comment directly into usb_remove_hcd().  (And you can remove the last
 two lines of the comment; they don't make sense in this context.)

Looks it is a bit clean to put the comment in the function, but it is
OK to add them in usb_remove_hcd() too.

Thanks again for your review.

Thanks,
--
Ming Lei
--
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  

Re: [PATCH v2 3/4] USB: EHCI: improve interrupt qh unlink

2013-06-25 Thread Ming Lei
On Tue, Jun 25, 2013 at 2:53 AM, Alan Stern st...@rowland.harvard.edu wrote:
 On Mon, 24 Jun 2013, Ming Lei wrote:

 Given interrupt URB will be resubmitted from tasklet context which
 is scheduled by ehci hardware interrupt handler, and commonly only
 one interrupt URB is scheduled on qh, so the qh may be unlinked
 immediately once qh_completions() returns from ehci_irq(), then
 the intr URB to be resubmitted in complete() can only be scheduled
 and linked to hardware until the qh unlink is completed.

 This patch improves this above situation, and the qh will wait for 5
 milliseconds before being unlinked from hardware, if one URB is submitted
 during the period, the qh is move out of unlink wait list and the
 interrupt transfer can be scheduled immediately, not like before: the
 transfer is only linked to hardware until previous unlink is completed.

 This description is very hard to understand.  I suggest rewriting it,
 something like this:

 ehci-hcd currently unlinks an interrupt QH when it becomes empty, that
 is, after its last URB completes.  This works well because in almost
 all cases, the completion handler for an interrupt URB resubmits the
 URB; therefore the QH doesn't become empty and doesn't get unlinked.

 When we start using tasklets for URB completion, this scheme won't work
 as well.  The resubmission won't occur until the tasklet runs, which
 will be some time after the completion is queued with the tasklet.
 During that delay, the QH will be empty and so will be unlinked
 unnecessarily.

 To prevent this problem, this patch adds a 5-ms time delay before empty
 interrupt QHs are unlinked.  Most often, during that time the interrupt
 URB will be resubmitted and thus we can avoid unlinking the QH.

Excellent description about the change, and I will add it in V3,
also care to add your signed-off in the patch for the change log part?


 diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
 index f80d033..5bf67e2 100644
 --- a/drivers/usb/host/ehci-sched.c
 +++ b/drivers/usb/host/ehci-sched.c
 @@ -601,12 +601,24 @@ static void qh_unlink_periodic(struct ehci_hcd *ehci, 
 struct ehci_qh *qh)
   list_del(qh-intr_node);
  }

 -static void start_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh)
 +/* must be called with holding ehci-lock */

 The comment should be:

 /* caller must hold ehci-lock */

 But in fact you can leave it out.  Almost all the code in this file
 runs with the lock held.

OK.


 +static void cancel_unlink_wait_intr(struct ehci_hcd *ehci, struct ehci_qh 
 *qh)
  {
 - /* If the QH isn't linked then there's nothing we can do. */
 - if (qh-qh_state != QH_STATE_LINKED)
 + if (qh-qh_state != QH_STATE_LINKED || list_empty(qh-unlink_node))
   return;

 + list_del_init(qh-unlink_node);
 +
 + /* avoid unnecessary CPU wakeup */
 + if (list_empty(ehci-intr_unlink_wait))
 + ehci_disable_event(ehci, EHCI_HRTIMER_START_UNLINK_INTR);

 If you don't mind, can we leave out ehci_disable_event() for now and
 add it after the rest of this series is merged?  It will keeps things a
 little simpler, and then we'll be able to use ehci_disable_event() for
 the IAA watchdog timer event as well as using it here.

I am fine, so this patch will become simpler and has less change.


 +}
 +
 +static void start_do_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh)
 +{
 + /* if the qh is waitting for unlink, cancel it now */

 s/waitt/wait/

 + cancel_unlink_wait_intr(ehci, qh);
 +
   qh_unlink_periodic (ehci, qh);

   /* Make sure the unlinks are visible before starting the timer */
 @@ -632,6 +644,45 @@ static void start_unlink_intr(struct ehci_hcd *ehci, 
 struct ehci_qh *qh)
   }
  }

 +/*
 + * It is common only one intr URB is scheduled on one qh, and
 + * given complete() is run in tasklet context, introduce a bit
 + * delay to avoid unlink qh too early.
 + */
 +static void __start_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh,
 + bool wait)
 +{
 + /* If the QH isn't linked then there's nothing we can do. */
 + if (qh-qh_state != QH_STATE_LINKED)
 + return;
 +
 + if (!wait)
 + return start_do_unlink_intr(ehci, qh);
 +
 + qh-unlink_cycle = ehci-intr_unlink_wait_cycle;
 +
 + /* New entries go at the end of the intr_unlink_wait list */
 + list_add_tail(qh-unlink_node, ehci-intr_unlink_wait);
 +
 + if (ehci-rh_state  EHCI_RH_RUNNING)
 + ehci_handle_start_intr_unlinks(ehci);
 + else if (ehci-intr_unlink_wait.next == qh-unlink_node) {
 + ehci_enable_event(ehci, EHCI_HRTIMER_START_UNLINK_INTR, true);
 + ++ehci-intr_unlink_wait_cycle;
 + }
 +}
 +
 +static void start_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh)
 +{
 + __start_unlink_intr(ehci, qh, false);
 +}
 +
 +static void start_unlink_intr_wait(struct ehci_hcd *ehci,
 +struct 

Re: [v4] usb: UHCI: fix pkt size in TD for a sg element

2013-06-25 Thread Ming Lei
On Tue, Jun 25, 2013 at 12:26 AM, Alan Stern st...@rowland.harvard.edu wrote:

 Other than usbtest, the only driver using SG that I know of is
 usb-storage, and it does make that assumption.  It works because the

Another example is usbfs driver, which sets the SG size as 16KB and also
makes the assumption.

 block layer packages the I/O up into groups of pages and the bulk
 maxpacket values always divide 4096 (or whatever the page size happens
 to be) -- except for wireless USB.



Thanks,
-- 
Ming Lei
--
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: musb: omap2430: make it compile again

2013-06-25 Thread Sergei Shtylyov

Hello.

On 25-06-2013 11:41, Sebastian Andrzej Siewior wrote:


it does not compile since 09fc7d (usb: musb: fix incorrect usage of
resource pointer). What makes me wonder most is if source of the
Tested-by tag :)



Acked-by: Felipe Balbi ba...@ti.com
Signed-off-by: Sebastian Andrzej Siewior bige...@linutronix.de
---
Greg, this is against your usb-next tree.



  drivers/usb/musb/omap2430.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)



diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index c7c1d7a..4315d35 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -481,7 +481,7 @@ static u64 omap2430_dmamask = DMA_BIT_MASK(32);

  static int omap2430_probe(struct platform_device *pdev)
  {
-   struct resource musb_resouces[2];
+   struct resource musb_resources[2];
struct musb_hdrc_platform_data  *pdata = pdev-dev.platform_data;
struct omap_musb_board_data *data;
struct platform_device  *musb;
@@ -568,7 +568,7 @@ static int omap2430_probe(struct platform_device *pdev)

INIT_WORK(glue-omap_musb_mailbox_work, omap_musb_mailbox_work);

-   memset(musb_resouces, 0x00, sizeof(*musb_resources) *
+   memset(musb_resources, 0x00, sizeof(*musb_resources) *
ARRAY_SIZE(musb_resources));


   Why not just sizeof(musb_resources)?

WBR, Sergei

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


[RFC PATCH] USB: check sg buffer size in usb_submit_urb

2013-06-25 Thread Ming Lei
USB spec stats that short packet can only appear at the end
of transfer. Because lost of HC(EHCI/UHCI/OHCI/...) can't
build a full packet from discontinuous buffers, we introduce
the limit in usb_submit_urb() to avoid such kind of bad sg
coming from driver.

The limit might be a bit strict:
- platform has iommu to do sg list mapping
- some host controllers may support to build full packet from
discontinuous buffers.

But considered that most of HCs don't support that, and driver
need work well or keep consistent on different HCs or ARCHs, we
have to introduce the limit.

Currently, only usbtest is reported to pass such sg buffers to HC,
and other users(mass storage, usbfs) don't have the problem.

Reported-by: Konstantin Filatov kfila...@parallels.com
Reported-by: Denis V. Lunev d...@openvz.org
Cc: Alan Stern st...@rowland.harvard.edu
Cc: Felipe Balbi ba...@ti.com
Signed-off-by: Ming Lei ming@canonical.com
---
 drivers/usb/core/urb.c |   11 +++
 include/linux/usb.h|3 ++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c
index 16927fa..ad6717a 100644
--- a/drivers/usb/core/urb.c
+++ b/drivers/usb/core/urb.c
@@ -7,6 +7,7 @@
 #include linux/usb.h
 #include linux/wait.h
 #include linux/usb/hcd.h
+#include linux/scatterlist.h
 
 #define to_urb(d) container_of(d, struct urb, kref)
 
@@ -413,6 +414,16 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
urb-iso_frame_desc[n].status = -EXDEV;
urb-iso_frame_desc[n].actual_length = 0;
}
+   } else {
+   /* check sg buffer size */
+   if (urb-num_sgs) {
+   struct scatterlist *sg;
+   int i;
+
+   for_each_sg(urb-sg, sg, urb-num_sgs, i)
+   if (i  urb-num_sgs - 1  (sg-length % max))
+   return -EINVAL;
+   }
}
 
/* the I/O buffer must be mapped/unmapped, except when length=0 */
diff --git a/include/linux/usb.h b/include/linux/usb.h
index a232b7e..d21a025 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -1258,7 +1258,8 @@ typedef void (*usb_complete_t)(struct urb *);
  * the device driver is saying that it provided this DMA address,
  * which the host controller driver should use in preference to the
  * transfer_buffer.
- * @sg: scatter gather buffer list
+ * @sg: scatter gather buffer list, except for the last sg, buffer size
+ * of all sg must be divided by the endpoint's max packet size
  * @num_mapped_sgs: (internal) number of mapped sg entries
  * @num_sgs: number of entries in the sg list
  * @transfer_buffer_length: How big is transfer_buffer.  The transfer may
-- 
1.7.9.5

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


usb reset issue ...

2013-06-25 Thread raespi
Hi ... I'm using an ARM Samsung S3C24XX processor with a 3.1.10 kernel.  
I'm interested in creating medical equipment using Linux and came onto 
an issue today.  I've created an application that connects to two FTDI 
devices and reads continuous data from a medical sensor.  I have a 
custom based board ( no external ports ), and my FTDI devices go 
directly to the S3C24xx USB pins and my app is configured to read from a 
specific product, vendor and device address location.  I've been testing 
it without problems and today it stopped working. Apparently, when 
checking the *dmesg* messages, the kernel disconnected those two USB 
devices and assigned them two new addresses ( 5 and 6 ) different from 
the original 3 and 4.  I always noticed on PC's that this issue was 
somehow related to hardware problems and/or disconnection from the USB 
port.  Also both the /dev/ttyUSB0 and /dev/ttyUSB1 devices on the /dev 
directory dissapeared ( for now not a problem since I don't access the 
FTDI device this way ).  These are the kernel messages:


usb 1-1.3: USB disconnect, device number 3
usb 1-1.4: USB disconnect, device number 4
usb 1-1: reset full speed USB device number 2 using s3c2410-ohci
usb 1-1.3: new full speed USB device number 5 using s3c2410-ohci
usb 1-1.4: new full speed USB device number 6 using s3c2410-ohci

On my board I can't hook up my application again to the new address 
since it's the only parameter identifiable by it.  Both FTDI Devices 
have the same product and vendor numbers:


Bus 001 Device 003: ID 0403:6001
Bus 001 Device 004: ID 0403:6001

The address on which they are on is the only ID I've got.   Is there 
some way to disable the kernel usb reset policy or assign them a 
specific address ?? I'm using *mdev* from userspace but the type of 
address assignment with mdev is the one concerning the device's name 
under the /dev directory AFAIK ...


Thanks ...

--
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] USB: initialize or shutdown PHY when add or remove host controller

2013-06-25 Thread Roger Quadros
On 06/24/2013 10:36 PM, Felipe Balbi wrote:
 On Thu, Jun 20, 2013 at 01:25:31PM -0400, Alan Stern wrote:
 On Thu, 20 Jun 2013, Felipe Balbi wrote:

 In fact, the PHY setting and handling is related to platform or SOC,
 and for different SOC they can
 have same EHCI HCD but they PHY handling can be different.
 Omap'a case is the example, and i think some other vendors may have
 silimar cases.
 From above point, It is better to leave the PHY initialization and
 shutdown to be done by each echi-xxx driver.

 So Alan and Felipe
 What are your ideas about it?

 If we have so many exceptions, then sure. But eventually, the common
 case should be added generically with a flag so that non-generic cases
 (like OMAP) can request to handle the PHY by themselves.

 Alan ?

 I don't have very strong feelings about this; Felipe has much more
 experience with these things.

 However, when the common case is added into the core, the simplest way
 to indicate that the HCD wants to handle the PHY(s) by itself will be
 to leave hcd-phy set to NULL or an ERR_PTR value.

 One important thing that hasn't been pointed out yet: When we move
 these calls into the core, the same patch must also remove those calls
 from the glue drivers that currently do set hcd-phy.  And it must make
 sure that the glue drivers which handle the PHY by themselves do not
 set hcd-phy.
 
 perfect summary. Perhaps Roger could already work on private PHY handle
 for ehci-omap.c and later we can start moving generic case to usbcore
 without having to touch ehci-omap.c at all. Roger, any commetns ?
 

This looks fine to me. I don't have anything to add.

cheers,
-roger
--
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] USB: initialize or shutdown PHY when add or remove host controller

2013-06-25 Thread Felipe Balbi
On Tue, Jun 25, 2013 at 04:37:11PM +0300, Roger Quadros wrote:
 On 06/24/2013 10:36 PM, Felipe Balbi wrote:
  On Thu, Jun 20, 2013 at 01:25:31PM -0400, Alan Stern wrote:
  On Thu, 20 Jun 2013, Felipe Balbi wrote:
 
  In fact, the PHY setting and handling is related to platform or SOC,
  and for different SOC they can
  have same EHCI HCD but they PHY handling can be different.
  Omap'a case is the example, and i think some other vendors may have
  silimar cases.
  From above point, It is better to leave the PHY initialization and
  shutdown to be done by each echi-xxx driver.
 
  So Alan and Felipe
  What are your ideas about it?
 
  If we have so many exceptions, then sure. But eventually, the common
  case should be added generically with a flag so that non-generic cases
  (like OMAP) can request to handle the PHY by themselves.
 
  Alan ?
 
  I don't have very strong feelings about this; Felipe has much more
  experience with these things.
 
  However, when the common case is added into the core, the simplest way
  to indicate that the HCD wants to handle the PHY(s) by itself will be
  to leave hcd-phy set to NULL or an ERR_PTR value.
 
  One important thing that hasn't been pointed out yet: When we move
  these calls into the core, the same patch must also remove those calls
  from the glue drivers that currently do set hcd-phy.  And it must make
  sure that the glue drivers which handle the PHY by themselves do not
  set hcd-phy.
  
  perfect summary. Perhaps Roger could already work on private PHY handle
  for ehci-omap.c and later we can start moving generic case to usbcore
  without having to touch ehci-omap.c at all. Roger, any commetns ?
  
 
 This looks fine to me. I don't have anything to add.

thanks :-)

-- 
balbi


signature.asc
Description: Digital signature


Re: [RFC PATCH 4/6] USB: ehci-omap: Suspend the controller during bus suspend

2013-06-25 Thread Roger Quadros
On 06/24/2013 10:34 PM, Alan Stern wrote:
 On Mon, 24 Jun 2013, Roger Quadros wrote:
 
 OK I've tried to handle all this in an alternate way. Now the controller 
 suspend/resume
 and runtime suspend/resume is independent of bus suspend.

 The controller now runtime suspends when all devices on the bus have 
 suspended and
 the hub auto suspends. NOTE: HW_ACCESSIBLE is still set on runtime_suspend.
 The challenge here is to process the interrupt in this state.
 
 The situation is a little peculiar.  Does the hardware really use the
 same IRQ for reporting wakeup events when the controller is suspended
 and for reporting normal I/O events?

No and yes :). Actually the Pad wakeup comes as a separate IRQ from hardware.
The omap pinctrl driver captures that, determines which pad caused the wakeup 
and
routes it to the appropriate interrupt based on the mapping provided in the 
device tree.
In the ehci-omap case we provide the EHCI IRQ number in the mapping for the USB 
host pads.

 
 In principle, HW_ACCESSIBLE should not be set when the controller is
 suspended, because you can't access the hardware then (since the clocks
 are off, right?).  But I can see how this would cause a problem if it
 leads to wakeup interrupts being ignored.
 
 Also, note that one of the things ehci_suspend() does is turn off the 
 Interrupt-Enable register, which means the wakeup interrupt would never 
 be issued in the first place.  I guess ehci_hcd_omap_suspend() will 
 have to turn on the proper enable bit before stopping the clocks.

For us, in runtime_suspend, we do not call ehci_suspend(), we just cut the 
clocks.
So HW_ACCESSIBLE is still set, which is kind of wrong, I agree. I'll update 
this in
the next patch.

 
 I've tried to handle this state. (i.e. interrupt while controller is runtime 
 suspended),
 by disabling the interrupt till we are ready and calling 
 usb_hcd_resume_root_hub().
 We mark a flag (HW_IRQ_DISABLED) stating that the interrupt was disabled and 
 based on
 that enable the IRQ and clear the flag in hcd_resume_work().

 Do let me know what you think of this approach.
 
 This is a very tricky problem.  Right now, usbcore assumes that when 
 HW_ACCESSIBLE is clear, the hardware can't generate interrupt requests 
 and therefore any interrupt must come from some other device sharing 
 the same IRQ line.  For the systems you're working on, this is wrong in 
 both respects (the hardware _can_ generate interrupt requests and IRQ 
 lines aren't shared).

Right.
 
 I think we will have to add a new flag to describe your situation.  
 Let's call it hcd-has_wakeup_interrupts.  Presumably there will never
 be a system that uses interrupts for wakeup signals _and_ has shared
 IRQ lines?  That would be a bad combination...

Sounds good.

 
 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
 index d53547d..8879cd2 100644
 --- a/drivers/usb/core/hcd.c
 +++ b/drivers/usb/core/hcd.c
 @@ -2136,6 +2136,11 @@ static void hcd_resume_work(struct work_struct *work)
  usb_lock_device(udev);
  usb_remote_wakeup(udev);
  usb_unlock_device(udev);
 +if (HCD_IRQ_DISABLED(hcd)) {
 +/* Interrupt was disabled */
 +clear_bit(HCD_FLAG_IRQ_DISABLED, hcd-flags);
 +enable_irq(hcd-irq);
 +}
  }
 
 This part is okay.
 
 @@ -2225,6 +2230,16 @@ irqreturn_t usb_hcd_irq (int irq, void *__hcd)
  
  if (unlikely(HCD_DEAD(hcd) || !HCD_HW_ACCESSIBLE(hcd)))
  rc = IRQ_NONE;
 +else if (pm_runtime_status_suspended(hcd-self.controller)) {
 +/*
 + * We can't handle it yet so disable IRQ, make note of it
 + * and resume root hub (i.e. controller as well)
 + */
 +disable_irq_nosync(hcd-irq);
 +set_bit(HCD_FLAG_IRQ_DISABLED, hcd-flags);
 +usb_hcd_resume_root_hub(hcd);
 +rc = IRQ_HANDLED;
 +}
 
 This part will have to be different.
 
 Certainly if HCD_DEAD(hcd) then we want to return IRQ_NONE.  Likewise
 if (!HCD_HW_ACCESSIBLE(hcd)  !hcd-has_wakeup_interrupts).  In all
 other cases we have to call the HCD's interrupt handler.
 
 The rest of the work will have to be done in the HCD, while holding the 
 private lock.  In ehci_irq(), after the spin_lock() call, you'll have 
 to add something like this:
 
   if (unlikely(!HCD_HW_ACCESSIBLE(hcd))) {
   /*
* We got a wakeup interrupt while the controller was
* suspending or suspended.  We can't handle it now, so
* disable the IRQ and resume the root hub (and hence
* the controller too).
*/
   disable_irq_nosync(hcd-irq);
   set_bit(HCD_FLAG_IRQ_DISABLED, hcd-flags);
   spin_unlock(ehci-lock);
 
   usb_hcd_resume_root_hub(hcd);
   return IRQ_HANDLED;
   }
 
 I think this will work.  How does it look to you?
 

Looks good to me. Below is the implementation on these lines.
I've 

Re: Chipidea usb otg support for IMX/MXS (device functionality)

2013-06-25 Thread Fabio Estevam
On Mon, Jun 24, 2013 at 10:51 AM, Marek Vasut ma...@denx.de wrote:

 Fabio, can you possibly test on MX23EVK please?

I never used USB gadget with chipidea driver.

Could you please explain what are the changes I need to do in the dts
file (I want to try on mx28evk first) and defconfig in order to be
able to test gadget? I am running today's linux-next.
--
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


webcams that work on ehci but don't work on xhci

2013-06-25 Thread Oliver Neukum
Hi Sarah,

I am seeing a few webcams that work only on EHCI. The XHCI is in principle
functional. Other webcams do work. Do you have any idea what to do in such
a case? The cameras are high-speed devices. The camera is detected, but yields 
no pictures.
I do have traces but they are rather large.

Regards
Oliver

(trace of device detection - the open won't go over the list)880149426e40 2195218371 S Co:1:004:0 s 01 0b  0001  0
880149426e40 2195220983 C Co:1:004:0 0 0
880149426e40 2195221003 S Ci:1:004:0 s a1 87 0100 0001 001a 26 
880149426e40 2195222371 C Ci:1:004:0 0 26 = 0101 15160500  
 2060 0928 
880149426e40 2195222384 S Co:1:004:0 s 21 01 0100 0001 001a 26 = 0101 
15160500   2060 0928 
880149426e40 2200220151 C Co:1:004:0 -2 0
880149426e40 2200220214 S Ci:1:004:0 s a1 81 0100 0001 001a 26 
880149426e40 2200223444 C Ci:1:004:0 0 26 = 0101 15160500  
 2060 0928 
880149789b00 2200226418 S Ii:1:004:3 -115:32 16 
880149789b00 2200226550 C Ii:1:004:3 -2:32 0
880149789b00 2200235172 S Ii:1:004:3 -115:32 16 
880149789b00 2200236814 C Ii:1:004:3 -2:32 0


Re: usb reset issue ...

2013-06-25 Thread Alan Stern
On Tue, 25 Jun 2013, raespi wrote:

 Hi ... I'm using an ARM Samsung S3C24XX processor with a 3.1.10 kernel.  
 I'm interested in creating medical equipment using Linux and came onto 
 an issue today.  I've created an application that connects to two FTDI 
 devices and reads continuous data from a medical sensor.  I have a 
 custom based board ( no external ports ), and my FTDI devices go 
 directly to the S3C24xx USB pins and my app is configured to read from a 
 specific product, vendor and device address location.  I've been testing 
 it without problems and today it stopped working. Apparently, when 
 checking the *dmesg* messages, the kernel disconnected those two USB 
 devices and assigned them two new addresses ( 5 and 6 ) different from 
 the original 3 and 4.  I always noticed on PC's that this issue was 
 somehow related to hardware problems and/or disconnection from the USB 
 port.  Also both the /dev/ttyUSB0 and /dev/ttyUSB1 devices on the /dev 
 directory dissapeared ( for now not a problem since I don't access the 
 FTDI device this way ).  These are the kernel messages:
 
 usb 1-1.3: USB disconnect, device number 3
 usb 1-1.4: USB disconnect, device number 4
 usb 1-1: reset full speed USB device number 2 using s3c2410-ohci
 usb 1-1.3: new full speed USB device number 5 using s3c2410-ohci
 usb 1-1.4: new full speed USB device number 6 using s3c2410-ohci

The disconnects happened because the hub that the two devices were 
plugged into needed to be reset.  So there's a problem related to that 
hub.

 On my board I can't hook up my application again to the new address 
 since it's the only parameter identifiable by it.  Both FTDI Devices 
 have the same product and vendor numbers:
 
 Bus 001 Device 003: ID 0403:6001
 Bus 001 Device 004: ID 0403:6001
 
 The address on which they are on is the only ID I've got.

That's not true; there's also the port number.  In this case, the log
messages above show one device plugged into port 3 of the hub and the
other device plugged into port 4.  Therefore the addresses are
available in the files

/sys/bus/usb/devices/1-1.3/devnum
/sys/bus/usb/devices/1-1.4/devnum

If you plug the devices into different ports, the file paths will 
change accordingly.

   Is there 
 some way to disable the kernel usb reset policy or assign them a 
 specific address ??

If you disable the reset, the kernel will no longer be able to tell
when devices are plugged in or unplugged.  The devices may even stop 
working entirely.

You could force the address to be a particular value by hacking the 
kernel.  But why bother?  It's likely to be easier to change your 
program to get the addresses based on the port numbers.

 I'm using *mdev* from userspace but the type of 
 address assignment with mdev is the one concerning the device's name 
 under the /dev directory AFAIK ...

Alan Stern

--
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: webcams that work on ehci but don't work on xhci

2013-06-25 Thread Alan Stern
On Tue, 25 Jun 2013, Oliver Neukum wrote:

 Hi Sarah,
 
 I am seeing a few webcams that work only on EHCI. The XHCI is in principle
 functional. Other webcams do work. Do you have any idea what to do in such
 a case? The cameras are high-speed devices. The camera is detected, but 
 yields no pictures.
 I do have traces but they are rather large.
 
   Regards
   Oliver
 
 (trace of device detection - the open won't go over the list)

Did you compare an EHCI usbmon trace with the xHCI trace?

Alan Stern

--
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: webcams that work on ehci but don't work on xhci

2013-06-25 Thread Oliver Neukum
On Tuesday 25 June 2013 10:29:06 Alan Stern wrote:
 On Tue, 25 Jun 2013, Oliver Neukum wrote:
 
  Hi Sarah,
  
  I am seeing a few webcams that work only on EHCI. The XHCI is in principle
  functional. Other webcams do work. Do you have any idea what to do in such
  a case? The cameras are high-speed devices. The camera is detected, but 
  yields no pictures.
  I do have traces but they are rather large.
  
  Regards
  Oliver
  
  (trace of device detection - the open won't go over the list)
 
 Did you compare an EHCI usbmon trace with the xHCI trace?

Yes, there are no errors on the USB level.

Regards
Oliver

--
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: usb reset issue ...

2013-06-25 Thread raespi

On 06/25/2013 10:26 AM, Alan Stern wrote:

On Tue, 25 Jun 2013, raespi wrote:


On my board I can't hook up my application again to the new address
since it's the only parameter identifiable by it.  Both FTDI Devices
have the same product and vendor numbers:

Bus 001 Device 003: ID 0403:6001
Bus 001 Device 004: ID 0403:6001

The address on which they are on is the only ID I've got.

That's not true; there's also the port number.  In this case, the log
messages above show one device plugged into port 3 of the hub and the
other device plugged into port 4.  Therefore the addresses are
available in the files

/sys/bus/usb/devices/1-1.3/devnum
/sys/bus/usb/devices/1-1.4/devnum

If you plug the devices into different ports, the file paths will
change accordingly.
Yes I'm aware of that.  The problem is that which device gets to which 
port ??.  Maybe I can tweak my app so that it tries to discover which 
are the new ports but how can I identify them ?? Say the sensor A gets 
to port 3 and sensor B gets to port 4 the first time,  but when a reset 
happens they get switched in order and sensor A gets to port 5 and 
sensor B gets to port 4??.  In a medical device this is catastrophic.  
Does the kernel always assign them in order ?? 3 and 4 or 4 and 5 ??

   Is there
some way to disable the kernel usb reset policy or assign them a
specific address ??

If you disable the reset, the kernel will no longer be able to tell
when devices are plugged in or unplugged.  The devices may even stop
working entirely.

You could force the address to be a particular value by hacking the
kernel.  But why bother?  It's likely to be easier to change your
program to get the addresses based on the port numbers.


I'm using *mdev* from userspace but the type of
address assignment with mdev is the one concerning the device's name
under the /dev directory AFAIK ...

Alan Stern
My device has no ports, it's a custom made industrial PCB if the reset 
happens you're saying it's only because of a hardware fault ??



--
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: URB completion order, normal behavior or bug?

2013-06-25 Thread Alan Stern
On Mon, 24 Jun 2013, Daniel Santos wrote:

  I submit an out URB (to rx my response)
  No, an OUT URB transfers data _out_ from the computer to the device.
  The response goes from the device _in_ to the computer.
 
 I sure do appreciate this because I was initially confused about this 
 and am now re-confused.  I presumed that out meant out of the 
 computer and into the USB device.

That is exactly what it means.

  However, I indeed have the variable 
 labeled out that I am using to receive responses and visa versa. I 
 have this little struct I use for both the IN and OUT URBs in my device 
 struct:
 
 struct mcp2210_endpoint_proxy {
  const struct usb_host_endpoint *ep;
  struct urb *urb;
  struct mcp2210_msg *buffer;
  /* FIXME: inefficient */
  u8 submitted:1;
  u8 completed:1;
  u8 kill:1;
  u8 retry_count:4;
  u8 is_dir_in:1;
 };
 
 /* then in my device struct: */
 struct mcp2210_device {
  struct usb_device *udev;
  struct usb_interface *intf;
  struct spi_master *spi_master;
  struct gpio_chip *gpio_chip;
 
 ...
  struct mcp2210_endpoint_proxy in;
  struct mcp2210_endpoint_proxy out;
 ...
 };
 
 I initialize them both with a single function and it works!  This is 
 what caused me to believe that the URB directions were described from 
 the USB device standpoint. (please pardon my mailer's mangling of 
 whitespace)
 
 
 static __always_inline int init_endpoint(struct mcp2210_device *dev,
   const struct usb_host_endpoint *ep)
 {
  int is_dir_in = !!usb_endpoint_dir_in(ep-desc);
  struct mcp2210_endpoint_proxy *dest;
  unsigned int pipe;
  usb_complete_t complete_fn;
  struct urb *urb;
 
  if (is_dir_in) {
  dest = dev-in;
  pipe = usb_sndintpipe(dev-udev, ep-desc.bEndpointAddress);
  complete_fn = urb_complete_in;
  } else {
  dest = dev-out;
  pipe = usb_rcvintpipe(dev-udev, ep-desc.bEndpointAddress);
  complete_fn = urb_complete_out;
  }
  dest-is_dir_in = is_dir_in;

So you're assigning an OUT pipe value to the in proxy and vice versa.  
But the OUT pipe uses the endpoint number of the IN endpoint, and vice
versa.

This might work if the two endpoints have the same number (for example,
if the OUT endpoint's address is 0x02 and the IN endpoint's address is
0x82).  However, it certainly isn't what you should be doing!

I guess we should add a check to the debugging code, to make sure the 
pipe's direction matches the endpoint's direction.

  if (unlikely(dest-ep)) {
  mcp2210_warn(Unexpected: more than one interrupt %s endpoint 
   discovered, ingoring them\n,
   urb_dir_str[is_dir_in]);
  return 0;
  }
 
  urb = usb_alloc_urb(0, GFP_KERNEL);
  if (unlikely(!urb)) {
  mcp2210_err(Failed to alloc %s URB\n, urb_dir_str[is_dir_in]);
  return -ENOMEM;
  }
 
  dest-buffer = usb_alloc_coherent(dev-udev, 64, GFP_KERNEL,
urb-transfer_dma);

Most likely you don't need to use a coherent buffer.

  if (unlikely(!dest-buffer)) {
  usb_free_urb(urb);
  mcp2210_err(Failed to alloc %s URB DMA buffer\n,
  urb_dir_str[is_dir_in]);
  return -ENOMEM;
  }
 
  dest-ep = ep;
  dest-urb = urb;
 
  usb_fill_int_urb(urb,
  dev-udev,
  pipe,
  dest-buffer,
  64,
  complete_fn,
  dev,
  ep-desc.bInterval);
  urb-transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
 
  return 0;
 }
 
 This is how I use it in my probe function:
 
 int mcp2210_probe(struct usb_interface *intf, const struct usb_device_id 
 *id)
 {
  struct usb_device *udev = interface_to_usbdev(intf);
  struct usb_host_interface *intf_desc = intf-cur_altsetting;
  struct mcp2210_device *dev;
  struct usb_host_endpoint *ep, *ep_end;
  int ret = -ENODEV;
  int i;
 
  printk(mcp2210_probe\n);
 
 ...
 
  /* Set up interrupt endpoint information. */
  ep_end = intf_desc-endpoint[intf_desc-desc.bNumEndpoints];
  for (ep = intf_desc-endpoint; ep != ep_end; ++ep) {
 
  if (!usb_endpoint_xfer_int(ep-desc))
  continue;
 
  if (init_endpoint(dev, ep))
  goto error0;
  }
 
  if (unlikely(!dev-in.ep || !dev-out.ep)) {
  mcp2210_err(could not find in and/or out interrupt endpoints);
  goto error0;
  }
 
 ...
 }
 
 I don't understand why this works and the previous didn't in light of 
 your comment (as well as my original assumptions).  Can you see any 
 flaws in this?  I've used !!usb_endpoint_dir_in(ep-desc) to get a one 
 or zero for rather or not I have the IN endpoint since I store this in a 
 u8:1 bitfield.

usb_endpoint_dir_in() always returns a 0 or 1 value, so the !! isn't 
needed.

 Gotcha here!  My thought on submitting them both at the same time 

Re: [PATCH v2 1/4] USB: HCD: support giveback of URB in tasklet context

2013-06-25 Thread Alan Stern
On Tue, 25 Jun 2013, Ming Lei wrote:

  +
  + spin_lock(bh-lock);
  + list_add_tail(urb-urb_list, bh-head);
  + if (bh-running)
  + sched = 0;
  + else
  + sched = 1;
  + spin_unlock(bh-lock);
 
  How about calling this variable running instead of sched?  Then you
  could just say:
 
  running = bh-running;
 
  with no if statement.
 
 OK, even we can do this below without name change:
 
sched = !bh-running;
 
 
  +
  + if (!sched)
  + ;
  + else if (high_prio_bh)
  + tasklet_hi_schedule(bh-bh);
  + else
  + tasklet_schedule(bh-bh);

The advantage of running instead of sched is that it avoids a 
double negative:

sched = !bh-running;
...
if (!sched) ...

as opposed to

running = bh-running;
...
if (running) ...

Alan Stern

--
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] staging: usbip: replace pr_warning() with pr_warn()

2013-06-25 Thread Greg KH
On Tue, Jun 25, 2013 at 04:27:18PM +0530, navin patidar wrote:
 On Tue, Jun 25, 2013, Greg KH gre...@linuxfoundation.org said:
 
  On Fri, Jun 21, 2013 at 03:01:04PM +0530, navin patidar wrote:
  pr_warn() is preferred over pr_warning().
 
  And dev_warn() is preferred over both of them, can you convert the code
  to use that instead?
 
 
 struct device is not available in usbip_start_eh()  which is required
 for dev_warn().
 
 usbip_device's containers struct stub_device and struct  vhci_device
 both have member structure usb_device but inside usbip_start_eh(), it
 is difficult to determine  to which container struct usbip_device
 belongs, thus container_of() can not be used here to get struct
 usb_device.

Then the code should be reworked in order to be able to properly
determine that.

greg k-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 v2 3/4] USB: EHCI: improve interrupt qh unlink

2013-06-25 Thread Alan Stern
On Tue, 25 Jun 2013, Ming Lei wrote:

 On Tue, Jun 25, 2013 at 2:53 AM, Alan Stern st...@rowland.harvard.edu wrote:
  On Mon, 24 Jun 2013, Ming Lei wrote:
 
  Given interrupt URB will be resubmitted from tasklet context which
  is scheduled by ehci hardware interrupt handler, and commonly only
  one interrupt URB is scheduled on qh, so the qh may be unlinked
  immediately once qh_completions() returns from ehci_irq(), then
  the intr URB to be resubmitted in complete() can only be scheduled
  and linked to hardware until the qh unlink is completed.
 
  This patch improves this above situation, and the qh will wait for 5
  milliseconds before being unlinked from hardware, if one URB is submitted
  during the period, the qh is move out of unlink wait list and the
  interrupt transfer can be scheduled immediately, not like before: the
  transfer is only linked to hardware until previous unlink is completed.
 
  This description is very hard to understand.  I suggest rewriting it,
  something like this:
 
  ehci-hcd currently unlinks an interrupt QH when it becomes empty, that
  is, after its last URB completes.  This works well because in almost
  all cases, the completion handler for an interrupt URB resubmits the
  URB; therefore the QH doesn't become empty and doesn't get unlinked.
 
  When we start using tasklets for URB completion, this scheme won't work
  as well.  The resubmission won't occur until the tasklet runs, which
  will be some time after the completion is queued with the tasklet.
  During that delay, the QH will be empty and so will be unlinked
  unnecessarily.
 
  To prevent this problem, this patch adds a 5-ms time delay before empty
  interrupt QHs are unlinked.  Most often, during that time the interrupt
  URB will be resubmitted and thus we can avoid unlinking the QH.
 
 Excellent description about the change, and I will add it in V3,
 also care to add your signed-off in the patch for the change log part?

You have my permission to add it.

  +static void start_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh)
  +{
  + __start_unlink_intr(ehci, qh, false);
  +}
  +
  +static void start_unlink_intr_wait(struct ehci_hcd *ehci,
  +struct ehci_qh *qh)
  +{
  + __start_unlink_intr(ehci, qh, true);
  +}
 
  This is not what I had in mind.
 
  Instead, copy the qh-qh_state test into the beginning of
  start_unlink_intr() and move the rest of start_do_unlink_intr() there.
  Then you can rename __start_unlink_intr() to start_unlink_intr_wait()
  and get rid of the wait parameter.
 
 The current code can do the check centrally, but it isn't big deal, and I
 will follow your suggestion.

Copying the check adds two lines of code (plus a comment and a blank 
line).  Your two extra function headers, extra parameter, and extra 
test add more than that.

 OK.
 
 BTW, indenting two tab might cause more lines, and looks many subsystems
 don't do that. But, anyway, I am fine with two tab, :-)

I admit, it isn't a perfect system and sometimes I don't use it.  But
it does have the advantage that changes to the first line don't require
the continuation line to be changed as well, just to keep the desired
alignment.  Furthermore, aligning the continuation with the first
parameter of a function call can often require _more_ than two extra
tab stops of indentation.

Alan Stern

--
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: [RFC PATCH] USB: check sg buffer size in usb_submit_urb

2013-06-25 Thread Alan Stern
On Tue, 25 Jun 2013, Ming Lei wrote:

 USB spec stats that short packet can only appear at the end
 of transfer. Because lost of HC(EHCI/UHCI/OHCI/...) can't
 build a full packet from discontinuous buffers, we introduce
 the limit in usb_submit_urb() to avoid such kind of bad sg
 coming from driver.
 
 The limit might be a bit strict:
   - platform has iommu to do sg list mapping
   - some host controllers may support to build full packet from
   discontinuous buffers.
 
 But considered that most of HCs don't support that, and driver
 need work well or keep consistent on different HCs or ARCHs, we
 have to introduce the limit.
 
 Currently, only usbtest is reported to pass such sg buffers to HC,
 and other users(mass storage, usbfs) don't have the problem.
 
 Reported-by: Konstantin Filatov kfila...@parallels.com
 Reported-by: Denis V. Lunev d...@openvz.org
 Cc: Alan Stern st...@rowland.harvard.edu
 Cc: Felipe Balbi ba...@ti.com
 Signed-off-by: Ming Lei ming@canonical.com
 ---
  drivers/usb/core/urb.c |   11 +++
  include/linux/usb.h|3 ++-
  2 files changed, 13 insertions(+), 1 deletion(-)
 
 diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c
 index 16927fa..ad6717a 100644
 --- a/drivers/usb/core/urb.c
 +++ b/drivers/usb/core/urb.c
 @@ -7,6 +7,7 @@
  #include linux/usb.h
  #include linux/wait.h
  #include linux/usb/hcd.h
 +#include linux/scatterlist.h
  
  #define to_urb(d) container_of(d, struct urb, kref)
  
 @@ -413,6 +414,16 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
   urb-iso_frame_desc[n].status = -EXDEV;
   urb-iso_frame_desc[n].actual_length = 0;
   }
 + } else {
 + /* check sg buffer size */
 + if (urb-num_sgs) {
 + struct scatterlist *sg;
 + int i;
 +
 + for_each_sg(urb-sg, sg, urb-num_sgs, i)
 + if (i  urb-num_sgs - 1  (sg-length % max))

Make this:  for_each_sg(urb-sg, sg, urb-num_sgs - 1, i)
Then you won't have to check the value of i.

 + return -EINVAL;
 + }
   }
  
   /* the I/O buffer must be mapped/unmapped, except when length=0 */
 diff --git a/include/linux/usb.h b/include/linux/usb.h
 index a232b7e..d21a025 100644
 --- a/include/linux/usb.h
 +++ b/include/linux/usb.h
 @@ -1258,7 +1258,8 @@ typedef void (*usb_complete_t)(struct urb *);
   *   the device driver is saying that it provided this DMA address,
   *   which the host controller driver should use in preference to the
   *   transfer_buffer.
 - * @sg: scatter gather buffer list
 + * @sg: scatter gather buffer list, except for the last sg, buffer size
 + *   of all sg must be divided by the endpoint's max packet size

It doesn't make sense to talk about the last sg or all sg here, 
because @sg is simply a pointer.  You should say:

 * @sg: scatter gather buffer list: the buffer size of each element in the
 *  list (except the last) must be divisible by the endpoint's max packet
 *  size

Alan Stern

--
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: webcams that work on ehci but don't work on xhci

2013-06-25 Thread Alan Stern
On Tue, 25 Jun 2013, Oliver Neukum wrote:

 On Tuesday 25 June 2013 10:29:06 Alan Stern wrote:
  On Tue, 25 Jun 2013, Oliver Neukum wrote:
  
   Hi Sarah,
   
   I am seeing a few webcams that work only on EHCI. The XHCI is in principle
   functional. Other webcams do work. Do you have any idea what to do in such
   a case? The cameras are high-speed devices. The camera is detected, but 
   yields no pictures.
   I do have traces but they are rather large.
   
 Regards
 Oliver
   
   (trace of device detection - the open won't go over the list)
  
  Did you compare an EHCI usbmon trace with the xHCI trace?
 
 Yes, there are no errors on the USB level.

Don't look for errors; look for differences.  If everything was working 
properly, the two traces would be the same except for small changes in 
timing, device addresses, and so on.

Alan Stern

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


USB tree now closed for 3.11

2013-06-25 Thread Greg KH
Hi all,

With the release of the 3.10-rc7 kernel, I think it's time to close the
USB tree for new features / cleanups for 3.11.  So I'm closing my
tree, and will only be applying obvious bugfixes or regressions to it
until 3.11-rc1 comes out.

You can keep sending me patches for the tree that don't fit the bugfix
category, but note that I'll be storing them away to wait for 3.11-rc1
comes out, which might be a few weeks, so please be patient.

The USB tree right now contains 382 patches, and the diffstat
summary is:
 410 files changed, 18183 insertions(+), 4956 deletions(-)

thanks,

greg k-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 v8 1/8] drivers: phy: add generic PHY framework

2013-06-25 Thread Felipe Balbi
Hi,

On Tue, Jun 25, 2013 at 11:28:39AM +0530, Kishon Vijay Abraham I wrote:
 diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h
 new file mode 100644
 index 000..7abf573
 --- /dev/null
 +++ b/include/linux/phy/phy.h

on this header, how about adding phy_set_drvdata() and phy_get_drvdata()
helpers ?

cheers

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH v8 5/8] ARM: dts: omap: update usb_otg_hs data

2013-06-25 Thread Felipe Balbi
On Tue, Jun 25, 2013 at 11:28:43AM +0530, Kishon Vijay Abraham I wrote:
 Updated the usb_otg_hs dt data to include the *phy* and *phy-names*
 binding in order for the driver to use the new generic PHY framework.
 Also updated the Documentation to include the binding information.
 The PHY binding information can be found at
 Documentation/devicetree/bindings/phy/phy-bindings.txt
 
 Signed-off-by: Kishon Vijay Abraham I kis...@ti.com
 Reviewed-by: Felipe Balbi ba...@ti.com

Acked-by: Felipe Balbi ba...@ti.com

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH v8 2/8] usb: phy: omap-usb2: use the new generic PHY framework

2013-06-25 Thread Felipe Balbi
On Tue, Jun 25, 2013 at 11:28:40AM +0530, Kishon Vijay Abraham I wrote:
 Used the generic PHY framework API to create the PHY. Now the power off and
 power on are done in omap_usb_power_off and omap_usb_power_on respectively.
 
 However using the old USB PHY library cannot be completely removed
 because OTG is intertwined with PHY and moving to the new framework
 will break OTG. Once we have a separate OTG state machine, we
 can get rid of the USB PHY library.
 
 Signed-off-by: Kishon Vijay Abraham I kis...@ti.com
 Reviewed-by: Sylwester Nawrocki s.nawro...@samsung.com

Acked-by: Felipe Balbi ba...@ti.com

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH v8 3/8] usb: phy: twl4030: use the new generic PHY framework

2013-06-25 Thread Felipe Balbi
On Tue, Jun 25, 2013 at 11:28:41AM +0530, Kishon Vijay Abraham I wrote:
 Used the generic PHY framework API to create the PHY. For powering on
 and powering off the PHY, power_on and power_off ops are used. Once the
 MUSB OMAP glue is adapted to the new framework, the suspend and resume
 ops of usb phy library will be removed.
 
 However using the old usb phy library cannot be completely removed
 because otg is intertwined with phy and moving to the new
 framework completely will break otg. Once we have a separate otg state 
 machine,
 we can get rid of the usb phy library.
 
 Signed-off-by: Kishon Vijay Abraham I kis...@ti.com
 Reviewed-by: Felipe Balbi ba...@ti.com

I'll add an Acked-by here:

Acked-by: Felipe Balbi ba...@ti.com

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH v8 4/8] ARM: OMAP: USB: Add phy binding information

2013-06-25 Thread Felipe Balbi
On Tue, Jun 25, 2013 at 11:28:42AM +0530, Kishon Vijay Abraham I wrote:
 In order for controllers to get PHY in case of non dt boot, the phy
 binding information (phy device name) should be added in the platform
 data of the controller.
 
 Signed-off-by: Kishon Vijay Abraham I kis...@ti.com
 Reviewed-by: Sylwester Nawrocki s.nawro...@samsung.com

Acked-by: Felipe Balbi ba...@ti.com

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH v8 7/8] usb: phy: omap-usb2: remove *set_suspend* callback from omap-usb2

2013-06-25 Thread Felipe Balbi
On Tue, Jun 25, 2013 at 11:28:45AM +0530, Kishon Vijay Abraham I wrote:
 Now that omap-usb2 is adapted to the new generic PHY framework,
 *set_suspend* ops can be removed from omap-usb2 driver.
 
 Signed-off-by: Kishon Vijay Abraham I kis...@ti.com
 Reviewed-by: Felipe Balbi ba...@ti.com

Acked-by: Felipe Balbi ba...@ti.com

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH v8 6/8] usb: musb: omap2430: use the new generic PHY framework

2013-06-25 Thread Felipe Balbi
On Tue, Jun 25, 2013 at 11:28:44AM +0530, Kishon Vijay Abraham I wrote:
 Use the generic PHY framework API to get the PHY. The usb_phy_set_resume
 and usb_phy_set_suspend is replaced with power_on and
 power_off to align with the new PHY framework.
 
 musb-xceiv can't be removed as of now because musb core uses xceiv.state and
 xceiv.otg. Once there is a separate state machine to handle otg, these can be
 moved out of xceiv and then we can start using the generic PHY framework.
 
 Signed-off-by: Kishon Vijay Abraham I kis...@ti.com
 Reviewed-by: Sylwester Nawrocki s.nawro...@samsung.com

Acked-by: Felipe Balbi ba...@ti.com

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH v8 8/8] usb: phy: twl4030-usb: remove *set_suspend* and *phy_init* ops

2013-06-25 Thread Felipe Balbi
On Tue, Jun 25, 2013 at 11:28:46AM +0530, Kishon Vijay Abraham I wrote:
 Now that twl4030-usb is adapted to the new generic PHY framework,
 *set_suspend* and *phy_init* ops can be removed from twl4030-usb driver.
 
 Signed-off-by: Kishon Vijay Abraham I kis...@ti.com
 Reviewed-by: Felipe Balbi ba...@ti.com

Acked-by: Felipe Balbi ba...@ti.com

-- 
balbi


signature.asc
Description: Digital signature


Re: USB tree now closed for 3.11

2013-06-25 Thread Greg KH
On Tue, Jun 25, 2013 at 11:21:43AM -0400, Alan Stern wrote:
 On Tue, 25 Jun 2013, Greg KH wrote:
 
  Hi all,
  
  With the release of the 3.10-rc7 kernel, I think it's time to close the
  USB tree for new features / cleanups for 3.11.  So I'm closing my
  tree, and will only be applying obvious bugfixes or regressions to it
  until 3.11-rc1 comes out.
  
  You can keep sending me patches for the tree that don't fit the bugfix
  category, but note that I'll be storing them away to wait for 3.11-rc1
  comes out, which might be a few weeks, so please be patient.
  
  The USB tree right now contains 382 patches, and the diffstat
  summary is:
   410 files changed, 18183 insertions(+), 4956 deletions(-)
 
 Instead of storing away new patches where people can't easily get at
 them, you could create a temporary branch to hold them until 3.11-rc1
 is released.  Would that involve a significant amount of extra work?

Yes that would, because I'm busy doing other merge-related things for
these next 3 weeks, I don't have the time to be building a new tree.  I
supposed you could always use patchwork to see the pending patches, but
I need this time away from applying patches to catch up on my other
tasks.

sorry,

greg k-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: usb reset issue ...

2013-06-25 Thread Alan Stern
On Tue, 25 Jun 2013, raespi wrote:

 On 06/25/2013 10:26 AM, Alan Stern wrote:
  On Tue, 25 Jun 2013, raespi wrote:
 
  On my board I can't hook up my application again to the new address
  since it's the only parameter identifiable by it.  Both FTDI Devices
  have the same product and vendor numbers:
 
  Bus 001 Device 003: ID 0403:6001
  Bus 001 Device 004: ID 0403:6001
 
  The address on which they are on is the only ID I've got.
  That's not true; there's also the port number.  In this case, the log
  messages above show one device plugged into port 3 of the hub and the
  other device plugged into port 4.  Therefore the addresses are
  available in the files
 
  /sys/bus/usb/devices/1-1.3/devnum
  /sys/bus/usb/devices/1-1.4/devnum
 
  If you plug the devices into different ports, the file paths will
  change accordingly.
 Yes I'm aware of that.  The problem is that which device gets to which 
 port ??.

Whoever assembled the system should know that.  Besides, you already 
face this problem in a different form: Which FTDI device gets which 
address?

  Maybe I can tweak my app so that it tries to discover which 
 are the new ports but how can I identify them ??

I don't know what you mean by new ports.  Ports are pieces of 
hardware; they don't flash into and out of existence.

 Say the sensor A gets 
 to port 3 and sensor B gets to port 4 the first time,  but when a reset 
 happens they get switched in order and sensor A gets to port 5 and 
 sensor B gets to port 4??.

That won't happen unless you remove the wires connecting the sensors to
the board, swap the wires, and then reconnect them to the board. 

  In a medical device this is catastrophic.  
 Does the kernel always assign them in order ?? 3 and 4 or 4 and 5 ??

The port numbers are fixed.  They are built into the hub's hardware.

 My device has no ports, it's a custom made industrial PCB if the reset 
 happens you're saying it's only because of a hardware fault ??

By port, I mean the particular connector on the PCB that the sensor 
is wired to.  Under this meaning, your device very definitely _does_ 
have ports.

When the reset happens, it is certainly because of some fault.  I can't 
tell from your description whether the fault is in hardware or 
software.

Alan Stern

--
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: USB tree now closed for 3.11

2013-06-25 Thread Alan Stern
On Tue, 25 Jun 2013, Greg KH wrote:

 Hi all,
 
 With the release of the 3.10-rc7 kernel, I think it's time to close the
 USB tree for new features / cleanups for 3.11.  So I'm closing my
 tree, and will only be applying obvious bugfixes or regressions to it
 until 3.11-rc1 comes out.
 
 You can keep sending me patches for the tree that don't fit the bugfix
 category, but note that I'll be storing them away to wait for 3.11-rc1
 comes out, which might be a few weeks, so please be patient.
 
 The USB tree right now contains 382 patches, and the diffstat
 summary is:
410 files changed, 18183 insertions(+), 4956 deletions(-)

Instead of storing away new patches where people can't easily get at
them, you could create a temporary branch to hold them until 3.11-rc1
is released.  Would that involve a significant amount of extra work?

Alan Stern

--
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/4] usb: gadget: s3c-hsotg: Allow driver instantiation using device tree

2013-06-25 Thread Tomasz Figa
This patch adds OF match table to the driver to allow instantiating it
using device tree.

Signed-off-by: Tomasz Figa t.f...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 .../devicetree/bindings/usb/samsung-hsotg.txt  | 40 ++
 drivers/usb/gadget/s3c-hsotg.c | 10 ++
 2 files changed, 50 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/samsung-hsotg.txt

diff --git a/Documentation/devicetree/bindings/usb/samsung-hsotg.txt 
b/Documentation/devicetree/bindings/usb/samsung-hsotg.txt
new file mode 100644
index 000..b83d428
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/samsung-hsotg.txt
@@ -0,0 +1,40 @@
+Samsung High Speed USB OTG controller
+-
+
+The Samsung HSOTG IP can be found on Samsung SoCs, from S3C6400 onwards.
+It gives functionality of OTG-compliant USB 2.0 host and device with
+support for USB 2.0 high-speed (480Mbps) and full-speed (12 Mbps)
+operation.
+
+Currently only device mode is supported.
+
+Binding details
+-
+
+Required properties:
+- compatible: samsung,s3c6400-hsotg should be used for all currently
+supported SoC,
+- interrupt-parent: phandle for the interrupt controller to which the
+interrupt signal of the HSOTG block is routed,
+- interrupts: specifier of interrupt signal of interrupt controller,
+according to bindings of interrupt controller,
+- clocks: contains an array of clock specifiers:
+- first entry: OTG clock
+- clock-names: contains array of clock names:
+- first entry: must be otg
+- vusb_d-supply: phandle to voltage regulator of digital section,
+- vusb_a-supply: phandle to voltage regulator of analog section.
+
+Example
+-
+
+   hsotg@1248 {
+   compatible = samsung,s3c6400-hsotg;
+   reg = 0x1248 0x2;
+   interrupts = 0 71 0;
+   clocks = clock 305;
+   clock-names = otg;
+   vusb_d-supply = vusb_reg;
+   vusb_a-supply = vusbdac_reg;
+   };
+
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c
index af22f24..616ed51 100644
--- a/drivers/usb/gadget/s3c-hsotg.c
+++ b/drivers/usb/gadget/s3c-hsotg.c
@@ -29,6 +29,7 @@
 #include linux/slab.h
 #include linux/clk.h
 #include linux/regulator/consumer.h
+#include linux/of_platform.h
 
 #include linux/usb/ch9.h
 #include linux/usb/gadget.h
@@ -3648,10 +3649,19 @@ static int s3c_hsotg_remove(struct platform_device 
*pdev)
 #define s3c_hsotg_resume NULL
 #endif
 
+#ifdef CONFIG_OF
+static const struct of_device_id s3c_hsotg_of_ids[] = {
+   { .compatible = samsung,s3c6400-hsotg, },
+   { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, s3c_hsotg_of_ids);
+#endif
+
 static struct platform_driver s3c_hsotg_driver = {
.driver = {
.name   = s3c-hsotg,
.owner  = THIS_MODULE,
+   .of_match_table = of_match_ptr(s3c_hsotg_of_ids),
},
.probe  = s3c_hsotg_probe,
.remove = s3c_hsotg_remove,
-- 
1.8.2.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


[PATCH 3/4] ARM: dts: exynos4: Add nodes for USB PHY block

2013-06-25 Thread Tomasz Figa
This patch adds device tree nodes for USB OTG PHYs of Exynos4210 and
Exynos4x12 SoCs.

Signed-off-by: Tomasz Figa t.f...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 arch/arm/boot/dts/exynos4210.dtsi | 15 +++
 arch/arm/boot/dts/exynos4x12.dtsi | 15 +++
 2 files changed, 30 insertions(+)

diff --git a/arch/arm/boot/dts/exynos4210.dtsi 
b/arch/arm/boot/dts/exynos4210.dtsi
index 54710de..3c71ea5 100644
--- a/arch/arm/boot/dts/exynos4210.dtsi
+++ b/arch/arm/boot/dts/exynos4210.dtsi
@@ -114,6 +114,21 @@
interrupts = 2 4;
};
 
+   usbphy@125B {
+   compatible = samsung,exynos4210-usb2phy;
+   reg = 0x125B 0x100;
+   clocks = clock 305;
+   clock-names = otg;
+   status = disabled;
+   ranges;
+   #address-cells = 1;
+   #size-cells = 1;
+
+   usbphy-sys {
+   reg = 0x10020704 0x8;
+   };
+   };
+
g2d@1280 {
compatible = samsung,s5pv210-g2d;
reg = 0x1280 0x1000;
diff --git a/arch/arm/boot/dts/exynos4x12.dtsi 
b/arch/arm/boot/dts/exynos4x12.dtsi
index e3380a7..267ed95 100644
--- a/arch/arm/boot/dts/exynos4x12.dtsi
+++ b/arch/arm/boot/dts/exynos4x12.dtsi
@@ -79,4 +79,19 @@
interrupts = 0 89 0;
status = disabled;
};
+
+   usbphy@125B {
+   compatible = samsung,exynos4x12-usb2phy;
+   reg = 0x125B 0x100;
+   clocks = clock 305;
+   clock-names = otg;
+   status = disabled;
+   ranges;
+   #address-cells = 1;
+   #size-cells = 1;
+
+   usbphy-sys {
+   reg = 0x10020704 0x8;
+   };
+   };
 };
-- 
1.8.2.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


[PATCH 0/4] Add support for Samsung HSOTG on DT-enabled platforms

2013-06-25 Thread Tomasz Figa
This series enables platforms booting with Device Tree to use the Samsung
HSOTG IP. Since USB PHY support has been already added, it's just a matter
of adding an OF match table to the driver and respective device tree nodes
to dts files.

[On Samsung Trats board based on Exynos 4210]
Tested-by: Tomasz Figa t.f...@samsung.com

Tomasz Figa (4):
  usb: gadget: s3c-hsotg: Allow driver instantiation using device tree
  ARM: dts: exynos4: Add node for hsotg
  ARM: dts: exynos4: Add nodes for USB PHY block
  ARM: dts: exynos4210-trats: Enable USB gadget functionality

 .../devicetree/bindings/usb/samsung-hsotg.txt  | 40 ++
 arch/arm/boot/dts/exynos4.dtsi |  9 +
 arch/arm/boot/dts/exynos4210-trats.dts | 10 ++
 arch/arm/boot/dts/exynos4210.dtsi  | 15 
 arch/arm/boot/dts/exynos4x12.dtsi  | 15 
 drivers/usb/gadget/s3c-hsotg.c | 10 ++
 6 files changed, 99 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/samsung-hsotg.txt

-- 
1.8.2.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


[PATCH 4/4] ARM: dts: exynos4210-trats: Enable USB gadget functionality

2013-06-25 Thread Tomasz Figa
This patch adds device tree nodes necessary to enable USB gadget
functionality on Exynos4210-based Trats board.

Signed-off-by: Tomasz Figa t.f...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 arch/arm/boot/dts/exynos4210-trats.dts | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm/boot/dts/exynos4210-trats.dts 
b/arch/arm/boot/dts/exynos4210-trats.dts
index 9a14484..d2ce1cf 100644
--- a/arch/arm/boot/dts/exynos4210-trats.dts
+++ b/arch/arm/boot/dts/exynos4210-trats.dts
@@ -39,6 +39,12 @@
enable-active-high;
};
 
+   hsotg@1248 {
+   vusb_d-supply = vusb_reg;
+   vusb_a-supply = vusbdac_reg;
+   status = okay;
+   };
+
sdhci_emmc: sdhci@1251 {
bus-width = 8;
non-removable;
@@ -48,6 +54,10 @@
status = okay;
};
 
+   usbphy@125B {
+   status = okay;
+   };
+
serial@1380 {
status = okay;
};
-- 
1.8.2.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: Chipidea usb otg support for IMX/MXS (device functionality)

2013-06-25 Thread Fabio Estevam
On Tue, Jun 25, 2013 at 11:23 AM, Fabio Estevam feste...@gmail.com wrote:
 On Mon, Jun 24, 2013 at 10:51 AM, Marek Vasut ma...@denx.de wrote:

 Fabio, can you possibly test on MX23EVK please?

 I never used USB gadget with chipidea driver.

 Could you please explain what are the changes I need to do in the dts
 file (I want to try on mx28evk first) and defconfig in order to be
 able to test gadget? I am running today's linux-next.

I tried the following:

--- a/arch/arm/boot/dts/imx28-evk.dts
+++ b/arch/arm/boot/dts/imx28-evk.dts
@@ -239,7 +239,7 @@

ahb@8008 {
usb0: usb@8008 {
-   vbus-supply = reg_usb0_vbus;
+   dr_mode = peripheral;
status = okay;
};

,but I get:

[1.495725] usbcore: registered new interface driver asix
[1.501516] usbcore: registered new interface driver ax88179_178a
[1.508139] usbcore: registered new interface driver cdc_ether
[1.514463] usbcore: registered new interface driver smsc95xx
[1.520743] usbcore: registered new interface driver net1080
[1.526920] usbcore: registered new interface driver cdc_subset
[1.533254] usbcore: registered new interface driver zaurus
[1.539587] usbcore: registered new interface driver cdc_ncm
[1.545432] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[1.552494] usbcore: registered new interface driver usb-storage
[1.565640] ci_hdrc ci_hdrc.0: can't start gadget role
[1.577682] ci_hdrc ci_hdrc.1: can't start gadget role
[1.588304] ci_hdrc ci_hdrc.2: can't start gadget role
[1.59] ci_hdrc ci_hdrc.3: can't start gadget role
[1.609508] ci_hdrc ci_hdrc.4: can't start gadget role
[1.620144] ci_hdrc ci_hdrc.5: can't start gadget role
[1.631028] ci_hdrc ci_hdrc.6: can't start gadget role
[1.642563] ci_hdrc ci_hdrc.7: can't start gadget role
[1.653530] ci_hdrc ci_hdrc.8: can't start gadget role
[1.664744] ci_hdrc ci_hdrc.9: can't start gadget role
[1.676085] ci_hdrc ci_hdrc.10: can't start gadget role
[1.687121] ci_hdrc ci_hdrc.11: can't start gadget role
[1.698309] ci_hdrc ci_hdrc.12: can't start gadget role
[1.709442] ci_hdrc ci_hdrc.13: can't start gadget role
[1.720879] ci_hdrc ci_hdrc.14: can't start gadget role
[1.732216] ci_hdrc ci_hdrc.15: can't start gadget role
[1.743660] ci_hdrc ci_hdrc.16: can't start gadget role
[1.755289] ci_hdrc ci_hdrc.17: can't start gadget role
[1.766821] ci_hdrc ci_hdrc.18: can't start gadget role
[1.778642] ci_hdrc ci_hdrc.19: can't start gadget role
[1.790227] ci_hdrc ci_hdrc.20: can't start gadget role
[1.802036] ci_hdrc ci_hdrc.21: can't start gadget role
[1.813879] ci_hdrc ci_hdrc.22: can't start gadget role
[1.825921] ci_hdrc ci_hdrc.23: can't start gadget role

... and system hangs here.

Any suggestions as to how to get gadget working?
--
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/4] ARM: dts: exynos4: Add node for hsotg

2013-06-25 Thread Tomasz Figa
This patch adds device tree node for USB HSOTG controller present on
Exynos4 SoCs.

Signed-off-by: Tomasz Figa t.f...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 arch/arm/boot/dts/exynos4.dtsi | 9 +
 1 file changed, 9 insertions(+)

diff --git a/arch/arm/boot/dts/exynos4.dtsi b/arch/arm/boot/dts/exynos4.dtsi
index 359694c..d53b9da 100644
--- a/arch/arm/boot/dts/exynos4.dtsi
+++ b/arch/arm/boot/dts/exynos4.dtsi
@@ -119,6 +119,15 @@
status = disabled;
};
 
+   hsotg@1248 {
+   compatible = samsung,s3c6400-hsotg;
+   reg = 0x1248 0x2;
+   interrupts = 0 71 0;
+   clocks = clock 305;
+   clock-names = otg;
+   status = disabled;
+   };
+
sdhci@1251 {
compatible = samsung,exynos4210-sdhci;
reg = 0x1251 0x100;
-- 
1.8.2.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: usb reset issue ...

2013-06-25 Thread Greg KH
On Tue, Jun 25, 2013 at 09:25:50AM -0400, raespi wrote:
 Hi ... I'm using an ARM Samsung S3C24XX processor with a 3.1.10
 kernel.

Note, this is a very old and unsupported kernel version, you really
should consider upgrading, or getting support for these types of issues
from the vendor that is forcing you to use this kernel version.

 I'm interested in creating medical equipment using Linux
 and came onto an issue today.  I've created an application that
 connects to two FTDI devices and reads continuous data from a
 medical sensor.  I have a custom based board ( no external ports ),
 and my FTDI devices go directly to the S3C24xx USB pins and my app
 is configured to read from a specific product, vendor and device
 address location.  I've been testing it without problems and today
 it stopped working. Apparently, when checking the *dmesg* messages,
 the kernel disconnected those two USB devices and assigned them two
 new addresses ( 5 and 6 ) different from the original 3 and 4.  I
 always noticed on PC's that this issue was somehow related to
 hardware problems and/or disconnection from the USB port.  Also both
 the /dev/ttyUSB0 and /dev/ttyUSB1 devices on the /dev directory
 dissapeared ( for now not a problem since I don't access the FTDI
 device this way ).

How are you accessing the FTDI devices, if not through their ttyUSB
ports?  Your system should also have some persistant device names for
these ports in the /dev/serial/ directory if you are using udev.  I'd
recommend using them and making sure each of these devices has a unique
serial number, in order to always know you are talking to the correct
device.

good luck,

greg k-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] staging: ozwpan: Convert printk to dev_dbg()

2013-06-25 Thread Rupesh Gujare
convert all debug messages from printk to dev_dbg()  add kernel config to
enable/disable these messages during compilation.

Signed-off-by: Rupesh Gujare rupesh.guj...@atmel.com
---
 drivers/staging/ozwpan/Kbuild|2 +-
 drivers/staging/ozwpan/Kconfig   |9 +
 drivers/staging/ozwpan/ozcdev.c  |9 +
 drivers/staging/ozwpan/oztrace.h |9 +
 4 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/ozwpan/Kbuild b/drivers/staging/ozwpan/Kbuild
index 1766a26..35a4278 100644
--- a/drivers/staging/ozwpan/Kbuild
+++ b/drivers/staging/ozwpan/Kbuild
@@ -15,4 +15,4 @@ ozwpan-y := \
ozurbparanoia.o \
oztrace.o
 
-
+ccflags-$(CONFIG_USB_WPAN_HCD_DEBUG) := -DDEBUG -DWANT_TRACE
diff --git a/drivers/staging/ozwpan/Kconfig b/drivers/staging/ozwpan/Kconfig
index 7904cae..ccee97c 100644
--- a/drivers/staging/ozwpan/Kconfig
+++ b/drivers/staging/ozwpan/Kconfig
@@ -7,3 +7,12 @@ config USB_WPAN_HCD
 
  To compile this driver a module, choose M here: the module
  will be called ozwpan.
+
+if USB_WPAN_HCD
+
+config USB_WPAN_HCD_DEBUG
+   boolean Debug support for USB over WiFi Host Controller
+   help
+ Say yes to enable debug messages.
+
+endif # USB_WPAN_HCD
diff --git a/drivers/staging/ozwpan/ozcdev.c b/drivers/staging/ozwpan/ozcdev.c
index 374fdc3..2fc944b 100644
--- a/drivers/staging/ozwpan/ozcdev.c
+++ b/drivers/staging/ozwpan/ozcdev.c
@@ -44,6 +44,7 @@ struct oz_serial_ctx {
  */
 static struct oz_cdev g_cdev;
 static struct class *g_oz_class;
+struct device *g_oz_wpan_dev;
 
/*--
  * Context: process and softirq
  */
@@ -334,7 +335,6 @@ static const struct file_operations oz_fops = {
 int oz_cdev_register(void)
 {
int err;
-   struct device *dev;
memset(g_cdev, 0, sizeof(g_cdev));
err = alloc_chrdev_region(g_cdev.devnum, 0, 1, ozwpan);
if (err  0)
@@ -357,10 +357,11 @@ int oz_cdev_register(void)
err = PTR_ERR(g_oz_class);
goto out1;
}
-   dev = device_create(g_oz_class, NULL, g_cdev.devnum, NULL, ozwpan);
-   if (IS_ERR(dev)) {
+   g_oz_wpan_dev = device_create(g_oz_class, NULL, g_cdev.devnum, NULL,
+   ozwpan);
+   if (IS_ERR(g_oz_wpan_dev)) {
oz_trace(Failed to create sysfs entry for cdev\n);
-   err = PTR_ERR(dev);
+   err = PTR_ERR(g_oz_wpan_dev);
goto out1;
}
return 0;
diff --git a/drivers/staging/ozwpan/oztrace.h b/drivers/staging/ozwpan/oztrace.h
index 8293b24..8764f37 100644
--- a/drivers/staging/ozwpan/oztrace.h
+++ b/drivers/staging/ozwpan/oztrace.h
@@ -7,14 +7,15 @@
 #define _OZTRACE_H_
 #include ozconfig.h
 
-#define TRACE_PREFIX   KERN_ALERT OZWPAN: 
+extern struct device *g_oz_wpan_dev;
 
 #ifdef WANT_TRACE
-#define oz_trace(...) printk(TRACE_PREFIX __VA_ARGS__)
+#define oz_trace(fmt, ...) dev_dbg(g_oz_wpan_dev, fmt, ##__VA_ARGS__);
 #ifdef WANT_VERBOSE_TRACE
 extern unsigned long trace_flags;
-#define oz_trace2(_flag, ...) \
-   do { if (trace_flags  _flag) printk(TRACE_PREFIX __VA_ARGS__); \
+#define oz_trace2(_flag, fmt, ...) \
+   do { if (trace_flags  _flag) \
+   dev_dbg(g_oz_wpan_dev, fmt, ##__VA_ARGS__); \
} while (0)
 #else
 #define oz_trace2(...)
-- 
1.7.9.5

--
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] staging: ozwpan: Convert printk to dev_dbg()

2013-06-25 Thread Joe Perches
On Tue, 2013-06-25 at 17:30 +0100, Rupesh Gujare wrote:
 convert all debug messages from printk to dev_dbg()  add kernel config to
 enable/disable these messages during compilation.
[]
 -#define oz_trace(...) printk(TRACE_PREFIX __VA_ARGS__)
 +#define oz_trace(fmt, ...) dev_dbg(g_oz_wpan_dev, fmt, ##__VA_ARGS__);
  #ifdef WANT_VERBOSE_TRACE
  extern unsigned long trace_flags;
 -#define oz_trace2(_flag, ...) \
 - do { if (trace_flags  _flag) printk(TRACE_PREFIX __VA_ARGS__); \
 +#define oz_trace2(_flag, fmt, ...) \
 + do { if (trace_flags  _flag) \
 + dev_dbg(g_oz_wpan_dev, fmt, ##__VA_ARGS__); \
   } while (0)

I think oz_trace is a poor name.
It implies you're using the trace subsystem
trace_flags as a global name is also poor
g_oz_wpan_dev is too as it limits the module to
a single dev instance.

I suggest:

#define oz_dbg(level, fmt, ...) \
do {\
if (level  oz_dbg_mask)\
dev_dbg(g_oz_wpan_dev, fmt, ##__VA_ARGS__); \
} while (0)

or better avoiding the single dev:

#define oz_dbg(level, dev, fmt, ...)\
do {\
if (level  oz_dbg_mask)\
dev_dbg(dev, fmt, ##__VA_ARGS__);   \
} while (0)

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