[PATCH] usb: host: ohci-pxa27x: use of_property_read_bool()

2015-11-15 Thread Saurabh Sengar
for checking if a property is present or not,
of_property_read_bool is more appropriate then of_get_property()

Signed-off-by: Saurabh Sengar 
---
 drivers/usb/host/ohci-pxa27x.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/host/ohci-pxa27x.c b/drivers/usb/host/ohci-pxa27x.c
index ba1bec7..e8c006e 100644
--- a/drivers/usb/host/ohci-pxa27x.c
+++ b/drivers/usb/host/ohci-pxa27x.c
@@ -365,19 +365,19 @@ static int ohci_pxa_of_init(struct platform_device *pdev)
if (!pdata)
return -ENOMEM;
 
-   if (of_get_property(np, "marvell,enable-port1", NULL))
+   if (of_property_read_bool(np, "marvell,enable-port1"))
pdata->flags |= ENABLE_PORT1;
-   if (of_get_property(np, "marvell,enable-port2", NULL))
+   if (of_property_read_bool(np, "marvell,enable-port2"))
pdata->flags |= ENABLE_PORT2;
-   if (of_get_property(np, "marvell,enable-port3", NULL))
+   if (of_property_read_bool(np, "marvell,enable-port3"))
pdata->flags |= ENABLE_PORT3;
-   if (of_get_property(np, "marvell,port-sense-low", NULL))
+   if (of_property_read_bool(np, "marvell,port-sense-low"))
pdata->flags |= POWER_SENSE_LOW;
-   if (of_get_property(np, "marvell,power-control-low", NULL))
+   if (of_property_read_bool(np, "marvell,power-control-low"))
pdata->flags |= POWER_CONTROL_LOW;
-   if (of_get_property(np, "marvell,no-oc-protection", NULL))
+   if (of_property_read_bool(np, "marvell,no-oc-protection"))
pdata->flags |= NO_OC_PROTECTION;
-   if (of_get_property(np, "marvell,oc-mode-perport", NULL))
+   if (of_property_read_bool(np, "marvell,oc-mode-perport"))
pdata->flags |= OC_MODE_PERPORT;
if (!of_property_read_u32(np, "marvell,power-on-delay", ))
pdata->power_on_delay = tmp;
-- 
1.9.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 2/2] ehci-platform: Add support for controllers with multiple reset lines

2015-11-15 Thread Hans de Goede
From: Reinder de Haan 

At least the EHCI found on the Allwinnner H3 SoC needs multiple reset
lines, the controller will not initialize while the reset for its
companion OHCI is still asserted, which means we need to de-assert
2 reset-controllers for this EHCI controller to work.

Signed-off-by: Reinder de Haan 
Signed-off-by: Hans de Goede 
---
 drivers/usb/host/ehci-platform.c | 47 +---
 1 file changed, 29 insertions(+), 18 deletions(-)

diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c
index 5c3c085..2720f27 100644
--- a/drivers/usb/host/ehci-platform.c
+++ b/drivers/usb/host/ehci-platform.c
@@ -38,11 +38,12 @@
 
 #define DRIVER_DESC "EHCI generic platform driver"
 #define EHCI_MAX_CLKS 3
+#define EHCI_MAX_RESETS 2
 #define hcd_to_ehci_priv(h) ((struct ehci_platform_priv *)hcd_to_ehci(h)->priv)
 
 struct ehci_platform_priv {
struct clk *clks[EHCI_MAX_CLKS];
-   struct reset_control *rst;
+   struct reset_control *resets[EHCI_MAX_RESETS];
struct phy **phys;
int num_phys;
bool reset_on_resume;
@@ -148,7 +149,7 @@ static int ehci_platform_probe(struct platform_device *dev)
struct usb_ehci_pdata *pdata = dev_get_platdata(>dev);
struct ehci_platform_priv *priv;
struct ehci_hcd *ehci;
-   int err, irq, phy_num, clk = 0;
+   int err, irq, phy_num, clk = 0, rst = 0;
 
if (usb_disabled())
return -ENODEV;
@@ -229,18 +230,24 @@ static int ehci_platform_probe(struct platform_device 
*dev)
break;
}
}
-   }
 
-   priv->rst = devm_reset_control_get_optional(>dev, NULL);
-   if (IS_ERR(priv->rst)) {
-   err = PTR_ERR(priv->rst);
-   if (err == -EPROBE_DEFER)
-   goto err_put_clks;
-   priv->rst = NULL;
-   } else {
-   err = reset_control_deassert(priv->rst);
-   if (err)
-   goto err_put_clks;
+   for (rst = 0; rst < EHCI_MAX_RESETS; rst++) {
+   priv->resets[rst] =
+   of_reset_control_get_by_index(dev->dev.of_node,
+ rst);
+   if (IS_ERR(priv->resets[rst])) {
+   err = PTR_ERR(priv->resets[rst]);
+   if (err == -EPROBE_DEFER)
+   goto err_reset;
+   priv->resets[rst] = NULL;
+   break;
+   }
+   err = reset_control_deassert(priv->resets[rst]);
+   if (err) {
+   reset_control_put(priv->resets[rst]);
+   goto err_reset;
+   }
+   }
}
 
if (pdata->big_endian_desc)
@@ -297,8 +304,10 @@ err_power:
if (pdata->power_off)
pdata->power_off(dev);
 err_reset:
-   if (priv->rst)
-   reset_control_assert(priv->rst);
+   while (--rst >= 0) {
+   reset_control_assert(priv->resets[rst]);
+   reset_control_put(priv->resets[rst]);
+   }
 err_put_clks:
while (--clk >= 0)
clk_put(priv->clks[clk]);
@@ -316,15 +325,17 @@ static int ehci_platform_remove(struct platform_device 
*dev)
struct usb_hcd *hcd = platform_get_drvdata(dev);
struct usb_ehci_pdata *pdata = dev_get_platdata(>dev);
struct ehci_platform_priv *priv = hcd_to_ehci_priv(hcd);
-   int clk;
+   int clk, rst;
 
usb_remove_hcd(hcd);
 
if (pdata->power_off)
pdata->power_off(dev);
 
-   if (priv->rst)
-   reset_control_assert(priv->rst);
+   for (rst = 0; rst < EHCI_MAX_RESETS && priv->resets[rst]; rst++) {
+   reset_control_assert(priv->resets[rst]);
+   reset_control_put(priv->resets[rst]);
+   }
 
for (clk = 0; clk < EHCI_MAX_CLKS && priv->clks[clk]; clk++)
clk_put(priv->clks[clk]);
-- 
2.5.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


[PATCH 0/2] ehci-platform: Add support for controllers with multiple reset lines

2015-11-15 Thread Hans de Goede
Hi All,

Note the second patch in this set obviously depends on the first patch.
Perhaps it is best to merge both through Greg's tree with Philipp's ack ?

Regards,

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


[PATCH 1/2] reset: Add of_reset_control_get_by_index

2015-11-15 Thread Hans de Goede
From: Reinder de Haan 

In some cases it is useful to be able to get a reset-controller by
index rather then by name. E.g. for a generic ip-block driver such
as the ehci-platform drivers which needs to support more then one reset,
without knowing the names of the reset lines (as that would make it
non generic).

Signed-off-by: Reinder de Haan 
Signed-off-by: Hans de Goede 
---
 drivers/reset/core.c  | 23 +++
 include/linux/reset.h |  8 
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/drivers/reset/core.c b/drivers/reset/core.c
index 7955e00..b2405d8 100644
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -152,16 +152,31 @@ EXPORT_SYMBOL_GPL(reset_control_status);
 struct reset_control *of_reset_control_get(struct device_node *node,
   const char *id)
 {
+   int index = 0;
+
+   if (id)
+   index = of_property_match_string(node, "reset-names", id);
+
+   return of_reset_control_get_by_index(node, index);
+}
+
+/**
+ * of_reset_control_get_by_index - Lookup and obtain a reference to a
+ * reset controller.
+ * @node: device to be reset by the controller
+ * @index: reset line index
+ *
+ * Returns a struct reset_control or IS_ERR() condition containing errno.
+ */
+struct reset_control *of_reset_control_get_by_index(struct device_node *node,
+   int index)
+{
struct reset_control *rstc = ERR_PTR(-EPROBE_DEFER);
struct reset_controller_dev *r, *rcdev;
struct of_phandle_args args;
-   int index = 0;
int rstc_id;
int ret;
 
-   if (id)
-   index = of_property_match_string(node,
-"reset-names", id);
ret = of_parse_phandle_with_args(node, "resets", "#reset-cells",
 index, );
if (ret)
diff --git a/include/linux/reset.h b/include/linux/reset.h
index 7f65f9c..8f56b66 100644
--- a/include/linux/reset.h
+++ b/include/linux/reset.h
@@ -38,6 +38,9 @@ static inline struct reset_control 
*devm_reset_control_get_optional(
 struct reset_control *of_reset_control_get(struct device_node *node,
   const char *id);
 
+struct reset_control *of_reset_control_get_by_index(struct device_node *node,
+  int index);
+
 #else
 
 static inline int reset_control_reset(struct reset_control *rstc)
@@ -106,6 +109,11 @@ static inline struct reset_control *of_reset_control_get(
return ERR_PTR(-ENOSYS);
 }
 
+static inline struct reset_control *of_reset_control_get_by_index(
+   struct device_node *node, int index)
+{
+   return ERR_PTR(-EINVAL);
+}
 #endif /* CONFIG_RESET_CONTROLLER */
 
 #endif
-- 
2.5.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


[PATCH 2/5] phy-sun4i-usb: Add support for the host usb-phys found on the H3 SoC

2015-11-15 Thread Hans de Goede
From: Reinder de Haan 

Note this commit only adds support for phys 1-3, phy 0, the otg phy, is
not yet (fully) supported after this commit.

Signed-off-by: Reinder de Haan 
Signed-off-by: Hans de Goede 
---
 .../devicetree/bindings/phy/sun4i-usb-phy.txt  |  1 +
 drivers/phy/phy-sun4i-usb.c| 67 +-
 2 files changed, 53 insertions(+), 15 deletions(-)

diff --git a/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt 
b/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
index 0cebf74..95736d7 100644
--- a/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
+++ b/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
@@ -9,6 +9,7 @@ Required properties:
   * allwinner,sun7i-a20-usb-phy
   * allwinner,sun8i-a23-usb-phy
   * allwinner,sun8i-a33-usb-phy
+  * allwinner,sun8i-h3-usb-phy
 - reg : a list of offset + length pairs
 - reg-names :
   * "phy_ctrl"
diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
index b12964b..17f97ab 100644
--- a/drivers/phy/phy-sun4i-usb.c
+++ b/drivers/phy/phy-sun4i-usb.c
@@ -46,6 +46,9 @@
 #define REG_PHYBIST0x08
 #define REG_PHYTUNE0x0c
 #define REG_PHYCTL_A33 0x10
+#define REG_PHY_UNK_H3 0x20
+
+#define REG_PMU_UNK_H3 0x10
 
 #define PHYCTL_DATABIT(7)
 
@@ -79,7 +82,7 @@
 #define PHY_DISCON_TH_SEL  0x2a
 #define PHY_SQUELCH_DETECT 0x3c
 
-#define MAX_PHYS   3
+#define MAX_PHYS   4
 
 /*
  * Note do not raise the debounce time, we must report Vusb high within 100ms
@@ -88,12 +91,19 @@
 #define DEBOUNCE_TIME  msecs_to_jiffies(50)
 #define POLL_TIME  msecs_to_jiffies(250)
 
+enum sun4i_usb_phy_type {
+   sun4i_a10_phy,
+   sun8i_a33_phy,
+   sun8i_h3_phy
+};
+
 struct sun4i_usb_phy_data {
+   struct device *dev;
void __iomem *base;
struct mutex mutex;
int num_phys;
u32 disc_thresh;
-   bool has_a33_phyctl;
+   enum sun4i_usb_phy_type type;
struct sun4i_usb_phy {
struct phy *phy;
void __iomem *pmu;
@@ -164,12 +174,18 @@ static void sun4i_usb_phy_write(struct sun4i_usb_phy 
*phy, u32 addr, u32 data,
 
mutex_lock(_data->mutex);
 
-   if (phy_data->has_a33_phyctl) {
+   switch (phy_data->type) {
+   case sun4i_a10_phy:
+   phyctl = phy_data->base + REG_PHYCTL_A10;
+   break;
+   case sun8i_a33_phy:
phyctl = phy_data->base + REG_PHYCTL_A33;
/* A33 needs us to set phyctl to 0 explicitly */
writel(0, phyctl);
-   } else {
-   phyctl = phy_data->base + REG_PHYCTL_A10;
+   break;
+   case sun8i_h3_phy:
+   dev_err(phy_data->dev, "H3 usb_phy_write is not supported\n");
+   break;
}
 
for (i = 0; i < len; i++) {
@@ -230,6 +246,7 @@ static int sun4i_usb_phy_init(struct phy *_phy)
struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
int ret;
+   u32 val;
 
ret = clk_prepare_enable(phy->clk);
if (ret)
@@ -241,15 +258,26 @@ static int sun4i_usb_phy_init(struct phy *_phy)
return ret;
}
 
-   /* Enable USB 45 Ohm resistor calibration */
-   if (phy->index == 0)
-   sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1);
+   if (data->type == sun8i_h3_phy) {
+   if (phy->index == 0) {
+   val = readl(data->base + REG_PHY_UNK_H3);
+   writel(val & ~1, data->base + REG_PHY_UNK_H3);
+   }
+
+   val = readl(phy->pmu + REG_PMU_UNK_H3);
+   writel(val & ~2, phy->pmu + REG_PMU_UNK_H3);
+   } else {
+   /* Enable USB 45 Ohm resistor calibration */
+   if (phy->index == 0)
+   sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1);
 
-   /* Adjust PHY's magnitude and rate */
-   sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
+   /* Adjust PHY's magnitude and rate */
+   sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
 
-   /* Disconnect threshold adjustment */
-   sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL, data->disc_thresh, 2);
+   /* Disconnect threshold adjustment */
+   sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
+   data->disc_thresh, 2);
+   }
 
sun4i_usb_phy_passby(phy, 1);
 
@@ -522,11 +550,14 @@ static int sun4i_usb_phy_probe(struct platform_device 
*pdev)
mutex_init(>mutex);
INIT_DELAYED_WORK(>detect, sun4i_usb_phy0_id_vbus_det_scan);
dev_set_drvdata(dev, data);
+   

[PATCH 4/5] ARM: dts: sun8i: Add usbphy and usb host controller nodes

2015-11-15 Thread Hans de Goede
From: Reinder de Haan 

Add nodes describing the H3's usbphy and usb host controller nodes.

Signed-off-by: Reinder de Haan 
Signed-off-by: Hans de Goede 
---
 arch/arm/boot/dts/sun8i-h3.dtsi | 101 
 1 file changed, 101 insertions(+)

diff --git a/arch/arm/boot/dts/sun8i-h3.dtsi b/arch/arm/boot/dts/sun8i-h3.dtsi
index 22ff593..0faa38a 100644
--- a/arch/arm/boot/dts/sun8i-h3.dtsi
+++ b/arch/arm/boot/dts/sun8i-h3.dtsi
@@ -359,6 +359,107 @@
#size-cells = <0>;
};
 
+   usbphy: phy@01c19400 {
+   compatible = "allwinner,sun8i-h3-usb-phy";
+   reg = <0x01c19400 0x2c>,
+ <0x01c1a800 0x4>,
+ <0x01c1b800 0x4>,
+ <0x01c1c800 0x4>,
+ <0x01c1d800 0x4>;
+   reg-names = "phy_ctrl",
+   "pmu0",
+   "pmu1",
+   "pmu2",
+   "pmu3";
+   clocks = <_clk 8>,
+<_clk 9>,
+<_clk 10>,
+<_clk 11>;
+   clock-names = "usb0_phy",
+ "usb1_phy",
+ "usb2_phy",
+ "usb3_phy";
+   resets = <_clk 0>,
+<_clk 1>,
+<_clk 2>,
+<_clk 3>;
+   reset-names = "usb0_reset",
+ "usb1_reset",
+ "usb2_reset",
+ "usb3_reset";
+   status = "disabled";
+   #phy-cells = <1>;
+   };
+
+   ehci1: usb@01c1b000 {
+   compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
+   reg = <0x01c1b000 0x100>;
+   interrupts = ;
+   clocks = <_gates 25>, <_gates 29>;
+   resets = <_rst 25>, <_rst 29>;
+   phys = < 1>;
+   phy-names = "usb";
+   status = "disabled";
+   };
+
+   ohci1: usb@01c1b400 {
+   compatible = "allwinner,sun8i-h3-ohci", "generic-ohci";
+   reg = <0x01c1b400 0x100>;
+   interrupts = ;
+   clocks = <_gates 29>, <_gates 25>,
+<_clk 17>;
+   resets = <_rst 29>, <_rst 25>;
+   phys = < 1>;
+   phy-names = "usb";
+   status = "disabled";
+   };
+
+   ehci2: usb@01c1c000 {
+   compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
+   reg = <0x01c1c000 0x100>;
+   interrupts = ;
+   clocks = <_gates 26>, <_gates 30>;
+   resets = <_rst 26>, <_rst 30>;
+   phys = < 2>;
+   phy-names = "usb";
+   status = "disabled";
+   };
+
+   ohci2: usb@01c1c400 {
+   compatible = "allwinner,sun8i-h3-ohci", "generic-ohci";
+   reg = <0x01c1c400 0x100>;
+   interrupts = ;
+   clocks = <_gates 30>, <_gates 26>,
+<_clk 18>;
+   resets = <_rst 30>, <_rst 26>;
+   phys = < 2>;
+   phy-names = "usb";
+   status = "disabled";
+   };
+
+   ehci3: usb@01c1d000 {
+   compatible = "allwinner,sun8i-h3-ehci", "generic-ehci";
+   reg = <0x01c1d000 0x100>;
+   interrupts = ;
+   clocks = <_gates 27>, <_gates 31>;
+   resets = <_rst 27>, <_rst 31>;
+   phys = < 3>;
+   phy-names = "usb";
+   status = "disabled";
+   };
+
+   ohci3: usb@01c1d400 {
+   compatible = "allwinner,sun8i-h3-ohci", "generic-ohci";
+   reg = <0x01c1d400 0x100>;
+   interrupts = ;
+   clocks = <_gates 31>, <_gates 27>,
+<_clk 19>;
+   resets = <_rst 31>, <_rst 27>;
+   phys = < 3>;
+   phy-names = "usb";
+   status = "disabled";
+   };
+
pio: 

[PATCH 5/5] ARM: dts: sun8i-h3-orangepi-plus: Enable USB host controllers

2015-11-15 Thread Hans de Goede
From: Reinder de Haan 

Enable the 3 pairs of USB host controllers used on the Orange Pi Plus.

Signed-off-by: Reinder de Haan 
Signed-off-by: Hans de Goede 
---
 arch/arm/boot/dts/sun8i-h3-orangepi-plus.dts | 28 
 1 file changed, 28 insertions(+)

diff --git a/arch/arm/boot/dts/sun8i-h3-orangepi-plus.dts 
b/arch/arm/boot/dts/sun8i-h3-orangepi-plus.dts
index e67df59..e05a409 100644
--- a/arch/arm/boot/dts/sun8i-h3-orangepi-plus.dts
+++ b/arch/arm/boot/dts/sun8i-h3-orangepi-plus.dts
@@ -60,6 +60,18 @@
};
 };
 
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
  {
pinctrl-names = "default";
pinctrl-0 = <_pins_a>, <_cd_pin>;
@@ -70,8 +82,24 @@
status = "okay";
 };
 
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
  {
pinctrl-names = "default";
pinctrl-0 = <_pins_a>;
status = "okay";
 };
+
+ {
+   status = "okay";
+};
-- 
2.5.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


[PATCH 3/5] ARM: dts: sun8i: Add support for H3 usb clocks

2015-11-15 Thread Hans de Goede
From: Reinder de Haan 

Add a node describing the usb-clks found on the H3.

Signed-off-by: Reinder de Haan 
Signed-off-by: Hans de Goede 
---
 arch/arm/boot/dts/sun8i-h3.dtsi | 12 
 1 file changed, 12 insertions(+)

diff --git a/arch/arm/boot/dts/sun8i-h3.dtsi b/arch/arm/boot/dts/sun8i-h3.dtsi
index c18b5f7..22ff593 100644
--- a/arch/arm/boot/dts/sun8i-h3.dtsi
+++ b/arch/arm/boot/dts/sun8i-h3.dtsi
@@ -266,6 +266,18 @@
 "mmc2_sample";
};
 
+   usb_clk: clk@01c200cc {
+   #clock-cells = <1>;
+   #reset-cells = <1>;
+   compatible = "allwinner,sun8i-h3-usb-clk";
+   reg = <0x01c200cc 0x4>;
+   clocks = <>;
+   clock-output-names = "usb_phy0", "usb_phy1",
+"usb_phy2", "usb_phy3",
+"usb_ohci0", "usb_ohci1",
+"usb_ohci2", "usb_ohci3";
+   };
+
mbus_clk: clk@01c2015c {
#clock-cells = <0>;
compatible = "allwinner,sun8i-a23-mbus-clk";
-- 
2.5.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


[PATCH 1/5] clk: sunxi: Add support for the H3 usb phy clocks

2015-11-15 Thread Hans de Goede
From: Reinder de Haan 

The H3 has a usb-phy clk register which is similar to that of earlier
SoCs, but with support for a larger number of phys. So we can simply add
a new set of clk-data and a new compatible and be done with it.

Signed-off-by: Reinder de Haan 
Signed-off-by: Hans de Goede 
---
 Documentation/devicetree/bindings/clock/sunxi.txt |  1 +
 drivers/clk/sunxi/clk-usb.c   | 12 
 2 files changed, 13 insertions(+)

diff --git a/Documentation/devicetree/bindings/clock/sunxi.txt 
b/Documentation/devicetree/bindings/clock/sunxi.txt
index d303dec..23e7bce 100644
--- a/Documentation/devicetree/bindings/clock/sunxi.txt
+++ b/Documentation/devicetree/bindings/clock/sunxi.txt
@@ -70,6 +70,7 @@ Required properties:
"allwinner,sun5i-a13-usb-clk" - for usb gates + resets on A13
"allwinner,sun6i-a31-usb-clk" - for usb gates + resets on A31
"allwinner,sun8i-a23-usb-clk" - for usb gates + resets on A23
+   "allwinner,sun8i-h3-usb-clk" - for usb gates + resets on H3
"allwinner,sun9i-a80-usb-mod-clk" - for usb gates + resets on A80
"allwinner,sun9i-a80-usb-phy-clk" - for usb phy gates + resets on A80
 
diff --git a/drivers/clk/sunxi/clk-usb.c b/drivers/clk/sunxi/clk-usb.c
index 1a72cd6..67b8e38 100644
--- a/drivers/clk/sunxi/clk-usb.c
+++ b/drivers/clk/sunxi/clk-usb.c
@@ -243,3 +243,15 @@ static void __init sun9i_a80_usb_phy_setup(struct 
device_node *node)
sunxi_usb_clk_setup(node, _a80_usb_phy_data, _usb_phy_lock);
 }
 CLK_OF_DECLARE(sun9i_a80_usb_phy, "allwinner,sun9i-a80-usb-phy-clk", 
sun9i_a80_usb_phy_setup);
+
+static const struct usb_clk_data sun8i_h3_usb_clk_data __initconst = {
+   .clk_mask =  BIT(19) | BIT(18) | BIT(17) | BIT(16) |
+BIT(11) | BIT(10) | BIT(9) | BIT(8),
+   .reset_mask = BIT(3) | BIT(2) | BIT(1) | BIT(0),
+};
+
+static void __init sun8i_h3_usb_setup(struct device_node *node)
+{
+   sunxi_usb_clk_setup(node, _h3_usb_clk_data, _a10_usb_lock);
+}
+CLK_OF_DECLARE(sun8i_h3_usb, "allwinner,sun8i-h3-usb-clk", sun8i_h3_usb_setup);
-- 
2.5.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


Re: [PATCH v4 0/5] usb: usbtmc: Add support for missing functions in USBTMC-USB488 spec

2015-11-15 Thread Andy Shevchenko
On Sun, Nov 15, 2015 at 8:34 PM, Dave Penkler  wrote:
> Implement support for the USB488 defined READ_STATUS_BYTE ioctl (1/5)
> and SRQ notifications with fasync (2/5) and poll/select (3/5) in order
> to be able to synchronize with variable duration instrument
> operations.
>
> Add ioctls for other USB488 requests: REN_CONTROL, GOTO_LOCAL and
> LOCAL_LOCKOUT. (4/5)
>
> Add convenience ioctl to return all device capabilities (5/5)
>
>  PATCH Changelog:
> v4 - Remove excess newlines and parens

Seems you missed few extra empty lines at least. Please, recheck again.

>- Simplify some expressions
>- Remove redundant initialisation

-- 
With Best Regards,
Andy Shevchenko
--
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: XHCI, "brain-dead scanner", and microframe rounding

2015-11-15 Thread Stéphane Lavergne
On Sat, Sep 12, 2015 at 4:08 AM, Hans-Peter Jansen  wrote:
> With some changes in the 4.0 time frame, AND an update of the epson iscan
> stuff, I'm happily scanning with my Epson 4490 Photo scanner plugged to a USB
> 3.0 port using xsane.
>
> Other USB 3.0 issues are currently investigated.

Thank you for the update.  I updated my Debian amd64 box to kernel
4.2.0-0 (Jessie backport) today, re-enabled "Auto" XHCI in my Gigabyte
BIOS and I can confirm that xhci_usb is handling my Fujitsu ScanSnap
S1500 correctly now.

FYI I do get 2 warnings in dmesg and my console every single time Sane
talks to the device:

[ 2036.780271] usb 3-12: ep 0x81 - rounding interval to 128
microframes, ep desc says 255 microframes

[ 2036.780835] usb 3-12: ep 0x2 - rounding interval to 128
microframes, ep desc says 255 microframes

No big deal, just thought I'd let _someone_ out there know. :)

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


Re: [PATCH v4 1/5] Implement an ioctl to support the USMTMC-USB488 READ_STATUS_BYTE operation.

2015-11-15 Thread Andy Shevchenko
On Sun, Nov 15, 2015 at 8:39 PM, Dave Penkler  wrote:
> Background:
> When performing a read on an instrument that is executing a function
> that runs longer than the USB timeout the instrument may hang and
> require a device reset to recover. The READ_STATUS_BYTE operation
> always returns even when the instrument is busy permitting to poll
> for the appropriate condition. This capability is referred to in
> instrument application notes on synchronizing acquisitions for other
> platforms.
>

Few nitpicks below.

> Signed-off-by: Dave Penkler 
> ---
>  drivers/usb/class/usbtmc.c   | 219 
> +++
>  include/uapi/linux/usb/tmc.h |   2 +
>  2 files changed, 221 insertions(+)
>
> diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c
> index 7a11a82..72ef7f0 100644
> --- a/drivers/usb/class/usbtmc.c
> +++ b/drivers/usb/class/usbtmc.c
> @@ -87,6 +87,19 @@ struct usbtmc_device_data {
> u8 bTag_last_write; /* needed for abort */
> u8 bTag_last_read;  /* needed for abort */
>
> +   /* data for interrupt in endpoint handling */
> +   u8 bNotify1;
> +   u8 bNotify2;
> +   u16ifnum;
> +   u8 iin_bTag;
> +   u8*iin_buffer;
> +   atomic_t   iin_data_valid;
> +   unsigned int   iin_ep;
> +   intiin_ep_present;
> +   intiin_interval;
> +   struct urb*iin_urb;
> +   u16iin_wMaxPacketSize;
> +
> u8 rigol_quirk;
>
> /* attributes from the USB TMC spec for this device */
> @@ -99,6 +112,7 @@ struct usbtmc_device_data {
> struct usbtmc_dev_capabilities  capabilities;
> struct kref kref;
> struct mutex io_mutex;  /* only one i/o function running at a time */
> +   wait_queue_head_t waitq;
>  };
>  #define to_usbtmc_data(d) container_of(d, struct usbtmc_device_data, kref)
>
> @@ -373,6 +387,88 @@ exit:
> return rv;
>  }
>
> +static int usbtmc488_ioctl_read_stb(struct usbtmc_device_data *data,
> +   unsigned long arg)
> +{
> +   u8 *buffer;
> +   struct device *dev;
> +   int rv;
> +   u8 tag, stb;
> +
> +   dev = >intf->dev;

it could be struct device *dev = …;

> +
> +   dev_dbg(dev, "Enter ioctl_read_stb iin_ep_present: %d\n",
> +   data->iin_ep_present);
> +
> +   buffer = kmalloc(8, GFP_KERNEL);
> +   if (!buffer)
> +   return -ENOMEM;
> +
> +   atomic_set(>iin_data_valid, 0);
> +
> +   rv = usb_control_msg(data->usb_dev,
> +   usb_rcvctrlpipe(data->usb_dev, 0),
> +   USBTMC488_REQUEST_READ_STATUS_BYTE,
> +   USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
> +   data->iin_bTag,
> +   data->ifnum,
> +   buffer, 0x03, USBTMC_TIMEOUT);
> +
> +   if (rv < 0) {
> +   dev_err(dev, "stb usb_control_msg returned %d\n", rv);
> +   goto exit;
> +   }
> +
> +   if (buffer[0] != USBTMC_STATUS_SUCCESS) {
> +   dev_err(dev, "control status returned %x\n", buffer[0]);
> +   rv = -EIO;
> +   goto exit;
> +   }
> +
> +   if (data->iin_ep_present) {
> +

Redundant empty line.

> +   rv = wait_event_interruptible_timeout(
> +   data->waitq,
> +   atomic_read(>iin_data_valid) != 0,
> +   USBTMC_TIMEOUT);
> +
> +   if (rv < 0) {
> +   dev_dbg(dev, "wait interrupted %d\n", rv);
> +   goto exit;
> +   }
> +
> +   if (rv == 0) {
> +   dev_dbg(dev, "wait timed out\n");
> +   rv = -ETIME;
> +   goto exit;
> +   }
> +
> +   tag = data->bNotify1 & 0x7f;
> +
> +   if (tag != data->iin_bTag) {
> +   dev_err(dev, "expected bTag %x got %x\n",
> +   data->iin_bTag, tag);
> +   }
> +
> +   stb = data->bNotify2;
> +   } else {
> +   stb = buffer[2];
> +   }
> +
> +   rv = copy_to_user((void __user *)arg, , sizeof(stb));
> +   if (rv)
> +   rv = -EFAULT;
> +
> + exit:
> +   /* bump interrupt bTag */
> +   data->iin_bTag += 1;
> +   if (data->iin_bTag > 127)

> +   data->iin_bTag = 2;

Hmm… Why 2?
A-ha, below I found a comment. Something might be good to have here as well.

> +
> +   kfree(buffer);
> +   return rv;
> +}
> +
>  /*
>   * Sends a REQUEST_DEV_DEP_MSG_IN message on the Bulk-IN endpoint.
>   * @transfer_size: number of bytes to request from the device.
> @@ -1069,6 +1165,11 @@ static long usbtmc_ioctl(struct file *file, unsigned 
> int cmd, unsigned long arg)
> 

Re: [PATCH v4 5/5] Add ioctls to enable and disable local controls on an instrument

2015-11-15 Thread Andy Shevchenko
On Sun, Nov 15, 2015 at 8:40 PM, Dave Penkler  wrote:
> These ioctls provide support for the USBTMC-USB488 control requests
> for REN_CONTROL, GO_TO_LOCAL and LOCAL_LOCKOUT
>

Nitpicks below.

> Signed-off-by: Dave Penkler 
> ---
>  drivers/usb/class/usbtmc.c   | 76 
> 
>  include/uapi/linux/usb/tmc.h |  6 
>  2 files changed, 82 insertions(+)
>
> diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c
> index add0ce2..79caa78 100644
> --- a/drivers/usb/class/usbtmc.c
> +++ b/drivers/usb/class/usbtmc.c
> @@ -478,6 +478,68 @@ static int usbtmc488_ioctl_read_stb(struct 
> usbtmc_device_data *data,
> return rv;
>  }
>
> +static int usbtmc488_ioctl_simple(struct usbtmc_device_data *data,
> +   unsigned long arg,
> +   unsigned int cmd)
> +{
> +   u8 *buffer;
> +   struct device *dev;
> +   int rv;
> +   unsigned int val;
> +   u16 wValue;
> +
> +   dev = >intf->dev;

Could be assigned above.

> +
> +   if (!(data->usb488_caps & USBTMC488_CAPABILITY_SIMPLE))
> +   return -EINVAL;
> +
> +   buffer = kmalloc(8, GFP_KERNEL);
> +   if (!buffer)
> +   return -ENOMEM;
> +
> +   if (cmd == USBTMC488_REQUEST_REN_CONTROL) {
> +   rv = copy_from_user(, (void __user *)arg, sizeof(val));
> +   if (rv) {
> +   rv = -EFAULT;
> +   goto exit;
> +   }
> +   wValue = (val) ? 1 : 0;

Redundant parens.

> +   } else {
> +   wValue = 0;
> +   }
> +
> +   dev_warn(dev, "wValue is %d\n", wValue);
> +
> +   rv = usb_control_msg(data->usb_dev,
> +   usb_rcvctrlpipe(data->usb_dev, 0),
> +   cmd,
> +   USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
> +   wValue,
> +   data->ifnum,
> +   buffer, 0x01, USBTMC_TIMEOUT);
> +
> +   if (rv < 0) {
> +   dev_err(dev, "simple usb_control_msg failed %d\n", rv);
> +   goto exit;
> +   } else if (rv != 1) {
> +   dev_warn(dev, "simple usb_control_msg returned %d\n", rv);
> +   rv = -EIO;

Hmm… Does usb_control_msg() return a proper error code? If it does,
perhaps better to propagate it.

> +   goto exit;
> +   }
> +
> +   if (buffer[0] != USBTMC_STATUS_SUCCESS) {
> +   dev_err(dev, "simple control status returned %x\n", 
> buffer[0]);
> +   rv = -EIO;
> +   goto exit;

> +   } else {

Redundant else.

> +   rv = 0;
> +   }


> +
> + exit:
> +   kfree(buffer);
> +   return rv;
> +}
> +
>  /*
>   * Sends a REQUEST_DEV_DEP_MSG_IN message on the Bulk-IN endpoint.
>   * @transfer_size: number of bytes to request from the device.
> @@ -1188,6 +1250,20 @@ static long usbtmc_ioctl(struct file *file, unsigned 
> int cmd, unsigned long arg)
> retval = usbtmc488_ioctl_read_stb(data, arg);
> break;
>
> +   case USBTMC488_IOCTL_REN_CONTROL:
> +   retval = usbtmc488_ioctl_simple(data, arg,
> +   
> USBTMC488_REQUEST_REN_CONTROL);
> +   break;
> +
> +   case USBTMC488_IOCTL_GOTO_LOCAL:
> +   retval = usbtmc488_ioctl_simple(data, arg,
> +   USBTMC488_REQUEST_GOTO_LOCAL);
> +   break;
> +
> +   case USBTMC488_IOCTL_LOCAL_LOCKOUT:
> +   retval = usbtmc488_ioctl_simple(data, arg,
> +   
> USBTMC488_REQUEST_LOCAL_LOCKOUT);
> +   break;
> }
>
>  skip_io_on_zombie:
> diff --git a/include/uapi/linux/usb/tmc.h b/include/uapi/linux/usb/tmc.h
> index 1dc3af1..0d852c9 100644
> --- a/include/uapi/linux/usb/tmc.h
> +++ b/include/uapi/linux/usb/tmc.h
> @@ -33,6 +33,9 @@
>  #define USBTMC_REQUEST_GET_CAPABILITIES7
>  #define USBTMC_REQUEST_INDICATOR_PULSE 64
>  #define USBTMC488_REQUEST_READ_STATUS_BYTE 128
> +#define USBTMC488_REQUEST_REN_CONTROL  160
> +#define USBTMC488_REQUEST_GOTO_LOCAL   161
> +#define USBTMC488_REQUEST_LOCAL_LOCKOUT162
>
>  /* Request values for USBTMC driver's ioctl entry point */
>  #define USBTMC_IOC_NR  91
> @@ -44,6 +47,9 @@
>  #define USBTMC_IOCTL_CLEAR_IN_HALT _IO(USBTMC_IOC_NR, 7)
>  #define USBTMC488_IOCTL_GET_CAPS   _IO(USBTMC_IOC_NR, 17)
>  #define USBTMC488_IOCTL_READ_STB   _IOR(USBTMC_IOC_NR, 18, unsigned char)
> +#define USBTMC488_IOCTL_REN_CONTROL_IOW(USBTMC_IOC_NR, 19, unsigned char)
> +#define USBTMC488_IOCTL_GOTO_LOCAL _IO(USBTMC_IOC_NR, 20)
> +#define USBTMC488_IOCTL_LOCAL_LOCKOUT  

[PATCH v4 1/5] Implement an ioctl to support the USMTMC-USB488 READ_STATUS_BYTE operation.

2015-11-15 Thread Dave Penkler
Background:
When performing a read on an instrument that is executing a function
that runs longer than the USB timeout the instrument may hang and
require a device reset to recover. The READ_STATUS_BYTE operation
always returns even when the instrument is busy permitting to poll
for the appropriate condition. This capability is referred to in
instrument application notes on synchronizing acquisitions for other
platforms.

Signed-off-by: Dave Penkler 
---
 drivers/usb/class/usbtmc.c   | 219 +++
 include/uapi/linux/usb/tmc.h |   2 +
 2 files changed, 221 insertions(+)

diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c
index 7a11a82..72ef7f0 100644
--- a/drivers/usb/class/usbtmc.c
+++ b/drivers/usb/class/usbtmc.c
@@ -87,6 +87,19 @@ struct usbtmc_device_data {
u8 bTag_last_write; /* needed for abort */
u8 bTag_last_read;  /* needed for abort */
 
+   /* data for interrupt in endpoint handling */
+   u8 bNotify1;
+   u8 bNotify2;
+   u16ifnum;
+   u8 iin_bTag;
+   u8*iin_buffer;
+   atomic_t   iin_data_valid;
+   unsigned int   iin_ep;
+   intiin_ep_present;
+   intiin_interval;
+   struct urb*iin_urb;
+   u16iin_wMaxPacketSize;
+
u8 rigol_quirk;
 
/* attributes from the USB TMC spec for this device */
@@ -99,6 +112,7 @@ struct usbtmc_device_data {
struct usbtmc_dev_capabilities  capabilities;
struct kref kref;
struct mutex io_mutex;  /* only one i/o function running at a time */
+   wait_queue_head_t waitq;
 };
 #define to_usbtmc_data(d) container_of(d, struct usbtmc_device_data, kref)
 
@@ -373,6 +387,88 @@ exit:
return rv;
 }
 
+static int usbtmc488_ioctl_read_stb(struct usbtmc_device_data *data,
+   unsigned long arg)
+{
+   u8 *buffer;
+   struct device *dev;
+   int rv;
+   u8 tag, stb;
+
+   dev = >intf->dev;
+
+   dev_dbg(dev, "Enter ioctl_read_stb iin_ep_present: %d\n",
+   data->iin_ep_present);
+
+   buffer = kmalloc(8, GFP_KERNEL);
+   if (!buffer)
+   return -ENOMEM;
+
+   atomic_set(>iin_data_valid, 0);
+
+   rv = usb_control_msg(data->usb_dev,
+   usb_rcvctrlpipe(data->usb_dev, 0),
+   USBTMC488_REQUEST_READ_STATUS_BYTE,
+   USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
+   data->iin_bTag,
+   data->ifnum,
+   buffer, 0x03, USBTMC_TIMEOUT);
+
+   if (rv < 0) {
+   dev_err(dev, "stb usb_control_msg returned %d\n", rv);
+   goto exit;
+   }
+
+   if (buffer[0] != USBTMC_STATUS_SUCCESS) {
+   dev_err(dev, "control status returned %x\n", buffer[0]);
+   rv = -EIO;
+   goto exit;
+   }
+
+   if (data->iin_ep_present) {
+
+   rv = wait_event_interruptible_timeout(
+   data->waitq,
+   atomic_read(>iin_data_valid) != 0,
+   USBTMC_TIMEOUT);
+
+   if (rv < 0) {
+   dev_dbg(dev, "wait interrupted %d\n", rv);
+   goto exit;
+   }
+
+   if (rv == 0) {
+   dev_dbg(dev, "wait timed out\n");
+   rv = -ETIME;
+   goto exit;
+   }
+
+   tag = data->bNotify1 & 0x7f;
+
+   if (tag != data->iin_bTag) {
+   dev_err(dev, "expected bTag %x got %x\n",
+   data->iin_bTag, tag);
+   }
+
+   stb = data->bNotify2;
+   } else {
+   stb = buffer[2];
+   }
+
+   rv = copy_to_user((void __user *)arg, , sizeof(stb));
+   if (rv)
+   rv = -EFAULT;
+
+ exit:
+   /* bump interrupt bTag */
+   data->iin_bTag += 1;
+   if (data->iin_bTag > 127)
+   data->iin_bTag = 2;
+
+   kfree(buffer);
+   return rv;
+}
+
 /*
  * Sends a REQUEST_DEV_DEP_MSG_IN message on the Bulk-IN endpoint.
  * @transfer_size: number of bytes to request from the device.
@@ -1069,6 +1165,11 @@ static long usbtmc_ioctl(struct file *file, unsigned int 
cmd, unsigned long arg)
case USBTMC_IOCTL_ABORT_BULK_IN:
retval = usbtmc_ioctl_abort_bulk_in(data);
break;
+
+   case USBTMC488_IOCTL_READ_STB:
+   retval = usbtmc488_ioctl_read_stb(data, arg);
+   break;
+
}
 
 skip_io_on_zombie:
@@ -1092,6 +1193,69 @@ static struct usb_class_driver usbtmc_class = {
.minor_base =   USBTMC_MINOR_BASE,
 };
 
+static void usbtmc_interrupt(struct urb *urb)
+{
+   struct usbtmc_device_data *data = urb->context;
+   int 

Re: [PATCH 2/2] ehci-platform: Add support for controllers with multiple reset lines

2015-11-15 Thread kbuild test robot
Hi Reinder,

[auto build test ERROR on: v4.3-rc7]
[also build test ERROR on: next-20151115]

url:
https://github.com/0day-ci/linux/commits/Hans-de-Goede/reset-Add-of_reset_control_get_by_index/20151116-034643
config: i386-allmodconfig (attached as .config)
reproduce:
# save the attached .config to linux build tree
make ARCH=i386 

All errors (new ones prefixed by >>):

>> ERROR: "of_reset_control_get_by_index" undefined!

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: Binary data


Re: Page allocation failure

2015-11-15 Thread Steinar H. Gunderson
On Sat, Nov 14, 2015 at 12:36:48PM -0500, Alan Stern wrote:
> Hmmm.  If the shared memory can be accessed by the CPU using ordinary
> load and store instructions and it can be kmalloc'ed, then it should be
> usable for zerocopy I/O.  But again, only if it satisfies the
> restrictions imposed by the USB controller's DMA hardware.

I don't honestly know how DRM allocates its memory, and the proprietary
drivers from NVIDIA/AMD probably is a different story entirely. I guess the
only real way would be to have the kernel see if the memory given in is
acceptable, and that's probably a different approach from what this one does.

Just so we're on the same page, I cleaned up the patch I'm now using, and I'm
attaching it here. You said the next step would be changing the memory
allocation interface; I guess I could give it a shot, but I doubt I would
understand the subtleties involved.

/* Steinar */
-- 
Homepage: https://www.sesse.net/
>From 4cf27fbf8000eb6a5ea75c87cd6315ed82d0 Mon Sep 17 00:00:00 2001
From: "Steinar H. Gunderson" 
Date: Mon, 16 Nov 2015 01:36:38 +0100
Subject: [PATCH] Add support for usbfs zerocopy.

This is essentially a patch by Markus Rechberger with some updates.
The original can be found at

  http://sundtek.de/support/devio_mmap_v0.4.diff

This version has the following changes:

  - Rebased against a newer kernel (with some conflicts fixed).
  - Fixed most checkpatch violations (some remain).
  - Fixes an issue where isochronous transfers would not really be
zero-copy, but go through a pointless memcpy from one area to
itself.
  - Ask for cached memory instead of uncached.
---
 drivers/usb/core/devio.c  | 229 +++---
 include/uapi/linux/usbdevice_fs.h |   8 ++
 2 files changed, 224 insertions(+), 13 deletions(-)

diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 986abde..39e8c2b 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -69,6 +69,7 @@ struct usb_dev_state {
 	spinlock_t lock;/* protects the async urb lists */
 	struct list_head async_pending;
 	struct list_head async_completed;
+	struct list_head memory_list;
 	wait_queue_head_t wait; /* wake up if a request completed */
 	unsigned int discsignr;
 	struct pid *disc_pid;
@@ -96,6 +97,16 @@ struct async {
 	u8 bulk_status;
 };
 
+struct usb_memory {
+	struct list_head memlist;
+	int vma_use_count;
+	int usb_use_count;
+	u32 offset;
+	u32 size;
+	void *mem;
+	unsigned long vm_start;
+};
+
 static bool usbfs_snoop;
 module_param(usbfs_snoop, bool, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(usbfs_snoop, "true to log all usbfs traffic");
@@ -288,6 +299,9 @@ static struct async *alloc_async(unsigned int numisoframes)
 
 static void free_async(struct async *as)
 {
+	struct usb_memory *usbm = NULL, *usbm_iter;
+	unsigned long flags;
+	struct usb_dev_state *ps = as->ps;
 	int i;
 
 	put_pid(as->pid);
@@ -297,8 +311,22 @@ static void free_async(struct async *as)
 		if (sg_page(>urb->sg[i]))
 			kfree(sg_virt(>urb->sg[i]));
 	}
+
+	spin_lock_irqsave(>lock, flags);
+	list_for_each_entry(usbm_iter, >memory_list, memlist) {
+		if (usbm_iter->mem == as->urb->transfer_buffer) {
+			usbm = usbm_iter;
+			break;
+		}
+	}
+	spin_unlock_irqrestore(>lock, flags);
+
 	kfree(as->urb->sg);
-	kfree(as->urb->transfer_buffer);
+	if (usbm == NULL)
+		kfree(as->urb->transfer_buffer);
+	else
+		usbm->usb_use_count--;
+
 	kfree(as->urb->setup_packet);
 	usb_free_urb(as->urb);
 	usbfs_decrease_memory_usage(as->mem_usage);
@@ -910,6 +938,7 @@ static int usbdev_open(struct inode *inode, struct file *file)
 	INIT_LIST_HEAD(>list);
 	INIT_LIST_HEAD(>async_pending);
 	INIT_LIST_HEAD(>async_completed);
+	INIT_LIST_HEAD(>memory_list);
 	init_waitqueue_head(>wait);
 	ps->discsignr = 0;
 	ps->disc_pid = get_pid(task_pid(current));
@@ -938,6 +967,8 @@ static int usbdev_release(struct inode *inode, struct file *file)
 	struct usb_dev_state *ps = file->private_data;
 	struct usb_device *dev = ps->dev;
 	unsigned int ifnum;
+	struct list_head *p, *q;
+	struct usb_memory *tmp;
 	struct async *as;
 
 	usb_lock_device(dev);
@@ -962,6 +993,14 @@ static int usbdev_release(struct inode *inode, struct file *file)
 		free_async(as);
 		as = async_getcompleted(ps);
 	}
+
+	list_for_each_safe(p, q, >memory_list) {
+		tmp = list_entry(p, struct usb_memory, memlist);
+		list_del(p);
+		if (tmp->mem)
+			free_pages_exact(tmp->mem, tmp->size);
+		kfree(tmp);
+	}
 	kfree(ps);
 	return 0;
 }
@@ -1289,6 +1328,7 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
 	struct usb_host_endpoint *ep;
 	struct async *as = NULL;
 	struct usb_ctrlrequest *dr = NULL;
+	struct usb_memory *usbm = NULL, *iter = NULL;
 	unsigned int u, totlen, isofrmlen;
 	int i, ret, is_in, num_sgs = 0, ifnum = -1;
 	int number_of_packets = 0;
@@ -1370,9 +1410,16 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
 			uurb->type = 

Re: [PATCH v3 04/12] usb: xhci: dbc: add support for Intel xHCI dbc quirk

2015-11-15 Thread Lu Baolu

Hi,

On 11/13/2015 11:34 PM, Dmitry Malkin wrote:

On Mon, 9 Nov 2015 15:38:33 +0800, Lu Baolu wrote:

On Intel platform, if the debug target is connected with debug
host, enabling DCE bit in command register leads to a hung bus
state. In the hung state, the host system will not see a port
connected status bit set. Hence debug target fails to be probed.

The state could be resolved by performing a port reset to the
debug port from the host xHCI. This patch introduces this work
around.

Is it correct to call this a "hung bus state"?  Wouldn't calling it
"hung port state" more appropriate?


Yes, "hung port state" is more appropriate.



I have observed this DCE-enable-related hung port state,
but the reason seemed to be different in my case:

Citing a note (sic!) from The Holy XHCI Spec, section 7.6.4.1:

If a Debug Host attempts to attach to a Debug Target before the DCE flag is set,
both ends of the link shall transition to the Inactive state.
So a Debug Host should periodically issue a Warm Reset
to ports that are Inactive to enable a connection to the DbC of the Debug 
Target.


Exactly. A formal workaround is to periodically issue Warm Resets to ports
from debug host.


Indeed, the inactive state is what I have observed (PLS field of port register 
PORTSC)
when the DCE bit is set to 1 with the cable already plugged in.

Now, according to my interpretation of The Hole USB 3.1 spec, section 7.5.2,
which says:

eSS.Inactive is a state where a link has failed Enhanced SuperSpeed operation.
A downstream port can only exit from this state when directed, or upon 
detection of
an absence of a far-end receiver termination (R RX-DC ) specified in Table 6-21,
or upon a Warm Reset.

It follows, that since hosts without DBC cannot listen to upstream requests,
the debug target-originated port reset requests (both hot and warm) will be 
ignored
by the debug host.


As above, a formal workaround is to issue Warm Reset periodically from debug
host, but that could cause much complexity. My quirk is to issue port 
reset just

*before* setting DCE bit. This quirk seems to work on several platforms.
(My debug host doesn't have DBC.)



This is the essence of the "hung port state" that I was able to observe.

Note, that this roadblock doesn't appear if you attach the cable /after/ 
enabling the DCE bit,


Yes.


or, alternatively, if the host has DBC.


Really? I haven't tried it yet.



And indeed, your quirk will work in the latter case, since the debug host hub
will be able to see the upstream reset request.


This quirk works as well if debug host doesn't have DBC. I didn't try a 
DBC-capable

debug host yet.



--
with best regards,
Dmitry Malkin


Thank you.
-Baolu


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



--
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: [linux-sunxi] [PATCH 3/5] ARM: dts: sun8i: Add support for H3 usb clocks

2015-11-15 Thread Chen-Yu Tsai
On Mon, Nov 16, 2015 at 3:46 AM, Hans de Goede  wrote:
> From: Reinder de Haan 
>
> Add a node describing the usb-clks found on the H3.
>
> Signed-off-by: Reinder de Haan 
> Signed-off-by: Hans de Goede 

Acked-by: Chen-Yu Tsai 

(Also updated Mike's email in my reply.)

> ---
>  arch/arm/boot/dts/sun8i-h3.dtsi | 12 
>  1 file changed, 12 insertions(+)
>
> diff --git a/arch/arm/boot/dts/sun8i-h3.dtsi b/arch/arm/boot/dts/sun8i-h3.dtsi
> index c18b5f7..22ff593 100644
> --- a/arch/arm/boot/dts/sun8i-h3.dtsi
> +++ b/arch/arm/boot/dts/sun8i-h3.dtsi
> @@ -266,6 +266,18 @@
>  "mmc2_sample";
> };
>
> +   usb_clk: clk@01c200cc {
> +   #clock-cells = <1>;
> +   #reset-cells = <1>;
> +   compatible = "allwinner,sun8i-h3-usb-clk";
> +   reg = <0x01c200cc 0x4>;
> +   clocks = <>;
> +   clock-output-names = "usb_phy0", "usb_phy1",
> +"usb_phy2", "usb_phy3",
> +"usb_ohci0", "usb_ohci1",
> +"usb_ohci2", "usb_ohci3";
> +   };
> +
> mbus_clk: clk@01c2015c {
> #clock-cells = <0>;
> compatible = "allwinner,sun8i-a23-mbus-clk";
> --
> 2.5.0
>
> --
> You received this message because you are subscribed to the Google Groups 
> "linux-sunxi" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to linux-sunxi+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
--
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: [linux-sunxi] [PATCH 1/5] clk: sunxi: Add support for the H3 usb phy clocks

2015-11-15 Thread Chen-Yu Tsai
On Mon, Nov 16, 2015 at 3:46 AM, Hans de Goede  wrote:
> From: Reinder de Haan 
>
> The H3 has a usb-phy clk register which is similar to that of earlier
> SoCs, but with support for a larger number of phys. So we can simply add
> a new set of clk-data and a new compatible and be done with it.
>
> Signed-off-by: Reinder de Haan 
> Signed-off-by: Hans de Goede 

Acked-by: Chen-Yu Tsai 

> ---
>  Documentation/devicetree/bindings/clock/sunxi.txt |  1 +
>  drivers/clk/sunxi/clk-usb.c   | 12 
>  2 files changed, 13 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/clock/sunxi.txt 
> b/Documentation/devicetree/bindings/clock/sunxi.txt
> index d303dec..23e7bce 100644
> --- a/Documentation/devicetree/bindings/clock/sunxi.txt
> +++ b/Documentation/devicetree/bindings/clock/sunxi.txt
> @@ -70,6 +70,7 @@ Required properties:
> "allwinner,sun5i-a13-usb-clk" - for usb gates + resets on A13
> "allwinner,sun6i-a31-usb-clk" - for usb gates + resets on A31
> "allwinner,sun8i-a23-usb-clk" - for usb gates + resets on A23
> +   "allwinner,sun8i-h3-usb-clk" - for usb gates + resets on H3
> "allwinner,sun9i-a80-usb-mod-clk" - for usb gates + resets on A80
> "allwinner,sun9i-a80-usb-phy-clk" - for usb phy gates + resets on A80
>
> diff --git a/drivers/clk/sunxi/clk-usb.c b/drivers/clk/sunxi/clk-usb.c
> index 1a72cd6..67b8e38 100644
> --- a/drivers/clk/sunxi/clk-usb.c
> +++ b/drivers/clk/sunxi/clk-usb.c
> @@ -243,3 +243,15 @@ static void __init sun9i_a80_usb_phy_setup(struct 
> device_node *node)
> sunxi_usb_clk_setup(node, _a80_usb_phy_data, _usb_phy_lock);
>  }
>  CLK_OF_DECLARE(sun9i_a80_usb_phy, "allwinner,sun9i-a80-usb-phy-clk", 
> sun9i_a80_usb_phy_setup);
> +
> +static const struct usb_clk_data sun8i_h3_usb_clk_data __initconst = {
> +   .clk_mask =  BIT(19) | BIT(18) | BIT(17) | BIT(16) |
> +BIT(11) | BIT(10) | BIT(9) | BIT(8),
> +   .reset_mask = BIT(3) | BIT(2) | BIT(1) | BIT(0),
> +};
> +
> +static void __init sun8i_h3_usb_setup(struct device_node *node)
> +{
> +   sunxi_usb_clk_setup(node, _h3_usb_clk_data, 
> _a10_usb_lock);
> +}
> +CLK_OF_DECLARE(sun8i_h3_usb, "allwinner,sun8i-h3-usb-clk", 
> sun8i_h3_usb_setup);
> --
> 2.5.0
>
> --
> You received this message because you are subscribed to the Google Groups 
> "linux-sunxi" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to linux-sunxi+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
--
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: [linux-sunxi] [PATCH 5/5] ARM: dts: sun8i-h3-orangepi-plus: Enable USB host controllers

2015-11-15 Thread Chen-Yu Tsai
Hi,

On Mon, Nov 16, 2015 at 3:46 AM, Hans de Goede  wrote:
> From: Reinder de Haan 
>
> Enable the 3 pairs of USB host controllers used on the Orange Pi Plus.
>
> Signed-off-by: Reinder de Haan 
> Signed-off-by: Hans de Goede 
> ---
>  arch/arm/boot/dts/sun8i-h3-orangepi-plus.dts | 28 
> 
>  1 file changed, 28 insertions(+)
>
> diff --git a/arch/arm/boot/dts/sun8i-h3-orangepi-plus.dts 
> b/arch/arm/boot/dts/sun8i-h3-orangepi-plus.dts
> index e67df59..e05a409 100644
> --- a/arch/arm/boot/dts/sun8i-h3-orangepi-plus.dts
> +++ b/arch/arm/boot/dts/sun8i-h3-orangepi-plus.dts
> @@ -60,6 +60,18 @@
> };
>  };
>
> + {
> +   status = "okay";
> +};
> +
> + {
> +   status = "okay";
> +};
> +
> + {
> +   status = "okay";
> +};
> +
>   {
> pinctrl-names = "default";
> pinctrl-0 = <_pins_a>, <_cd_pin>;
> @@ -70,8 +82,24 @@
> status = "okay";
>  };
>
> + {
> +   status = "okay";
> +};

This controller is connected to a FE1.1s USB 2.0 hub, giving us the
four usable external USB ports. We shouldn't need to enable OHCI.

> +
> + {
> +   status = "okay";
> +};

According to the schematics, this port is never used. Please remove.

> + {
> +   status = "okay";
> +};

This is connected to the GL830 USB-SATA bridge. Again, OHCI isn't
needed.

> +
>   {
> pinctrl-names = "default";
> pinctrl-0 = <_pins_a>;
> status = "okay";
>  };
> +
> + {
> +   status = "okay";

And what about power supplies / regulators?


Regards
ChenYu

> +};
> --
> 2.5.0
>
> --
> You received this message because you are subscribed to the Google Groups 
> "linux-sunxi" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to linux-sunxi+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] ehci-platform: Add support for controllers with multiple reset lines

2015-11-15 Thread kbuild test robot
Hi Reinder,

[auto build test ERROR on v4.3-rc7]
[also build test ERROR on next-20151115]

url:
https://github.com/0day-ci/linux/commits/Hans-de-Goede/reset-Add-of_reset_control_get_by_index/20151116-034643
config: x86_64-allmodconfig (attached as .config)
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

All errors (new ones prefixed by >>):

>> ERROR: "of_reset_control_get_by_index" [drivers/usb/host/ehci-platform.ko] 
>> undefined!

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: Binary data


[PATCH v6 1/4] gadget: Introduce the usb charger framework

2015-11-15 Thread Baolin Wang
This patch introduces the usb charger driver based on usb gadget that
makes an enhancement to a power driver. It works well in practice but
that requires a system with suitable hardware.

The basic conception of the usb charger is that, when one usb charger
is added or removed by reporting from the usb gadget state change or
the extcon device state change, the usb charger will report to power
user to set the current limitation.

The usb charger will register notifiees on the usb gadget or the extcon
device to get notified the usb charger state. It also supplies the
notification mechanism to userspace When the usb charger state is changed.

Power user will register a notifiee on the usb charger to get notified
by status changes from the usb charger. It will report to power user
to set the current limitation when detecting the usb charger is added
or removed from extcon device state or usb gadget state.

This patch doesn't yet integrate with the gadget code, so some functions
which rely on the 'gadget' are not completed, that will be implemented
in the following patches.

Signed-off-by: Baolin Wang 
---
 drivers/usb/gadget/Kconfig  |7 +
 drivers/usb/gadget/Makefile |1 +
 drivers/usb/gadget/charger.c|  574 +++
 include/linux/usb/usb_charger.h |  162 +++
 4 files changed, 744 insertions(+)
 create mode 100644 drivers/usb/gadget/charger.c
 create mode 100644 include/linux/usb/usb_charger.h

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 33834aa..8d69dca 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -127,6 +127,13 @@ config USB_GADGET_STORAGE_NUM_BUFFERS
   a module parameter as well.
   If unsure, say 2.
 
+config USB_CHARGER
+   bool "USB charger support"
+   help
+ The usb charger driver based on the usb gadget that makes an
+ enhancement to a power driver which can set the current limitation
+ when the usb charger is added or removed.
+
 source "drivers/usb/gadget/udc/Kconfig"
 
 #
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 598a67d..1e421c1 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -10,3 +10,4 @@ libcomposite-y:= usbstring.o config.o 
epautoconf.o
 libcomposite-y += composite.o functions.o configfs.o u_f.o
 
 obj-$(CONFIG_USB_GADGET)   += udc/ function/ legacy/
+obj-$(CONFIG_USB_CHARGER)  += charger.o
diff --git a/drivers/usb/gadget/charger.c b/drivers/usb/gadget/charger.c
new file mode 100644
index 000..921f8e2
--- /dev/null
+++ b/drivers/usb/gadget/charger.c
@@ -0,0 +1,574 @@
+/*
+ * charger.c -- USB charger driver
+ *
+ * Copyright (C) 2015 Linaro Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DEFAULT_CUR_PROTECT(50)
+#define DEFAULT_SDP_CUR_LIMIT  (500 - DEFAULT_CUR_PROTECT)
+#define DEFAULT_DCP_CUR_LIMIT  (1500 - DEFAULT_CUR_PROTECT)
+#define DEFAULT_CDP_CUR_LIMIT  (1500 - DEFAULT_CUR_PROTECT)
+#define DEFAULT_ACA_CUR_LIMIT  (1500 - DEFAULT_CUR_PROTECT)
+#define UCHGER_STATE_LENGTH(50)
+
+static DEFINE_IDA(usb_charger_ida);
+static struct bus_type usb_charger_subsys = {
+   .name   = "usb-charger",
+   .dev_name   = "usb-charger",
+};
+
+static struct usb_charger *dev_to_uchger(struct device *udev)
+{
+   return container_of(udev, struct usb_charger, dev);
+}
+
+static ssize_t cur_limit_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+   struct usb_charger *uchger = dev_to_uchger(dev);
+
+   return scnprintf(buf, PAGE_SIZE, "%d %d %d %d\n",
+uchger->cur_limit.sdp_cur_limit,
+uchger->cur_limit.dcp_cur_limit,
+uchger->cur_limit.cdp_cur_limit,
+uchger->cur_limit.aca_cur_limit);
+}
+
+static ssize_t cur_limit_store(struct device *dev,
+  struct device_attribute *attr,
+  const char *buf, size_t count)
+{
+   struct usb_charger *uchger = dev_to_uchger(dev);
+   struct usb_charger_cur_limit cur;
+   int ret;
+
+   ret = sscanf(buf, "%d %d %d %d",
+_cur_limit, _cur_limit,
+_cur_limit, _cur_limit);
+   if (ret == 0)
+   return -EINVAL;
+
+   ret = usb_charger_set_cur_limit(uchger, );
+   if (ret < 0)
+   return ret;
+
+   return count;
+}
+static DEVICE_ATTR_RW(cur_limit);
+
+static struct 

[PATCH v6 4/4] power: wm831x_power: Support USB charger current limit management

2015-11-15 Thread Baolin Wang
Integrate with the newly added USB charger interface to limit the current
we draw from the USB input based on the input device configuration
identified by the USB stack, allowing us to charge more quickly from high
current inputs without drawing more current than specified from others.

Signed-off-by: Mark Brown 
Signed-off-by: Baolin Wang 
Acked-by: Lee Jones 
Acked-by: Charles Keepax 
Acked-by: Peter Chen 
Acked-by: Sebastian Reichel 
---
 drivers/power/wm831x_power.c |   69 ++
 include/linux/mfd/wm831x/pdata.h |3 ++
 2 files changed, 72 insertions(+)

diff --git a/drivers/power/wm831x_power.c b/drivers/power/wm831x_power.c
index 7082301..043f1f4 100644
--- a/drivers/power/wm831x_power.c
+++ b/drivers/power/wm831x_power.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -31,6 +32,8 @@ struct wm831x_power {
char usb_name[20];
char battery_name[20];
bool have_battery;
+   struct usb_charger *usb_charger;
+   struct notifier_block usb_notify;
 };
 
 static int wm831x_power_check_online(struct wm831x *wm831x, int supply,
@@ -125,6 +128,43 @@ static enum power_supply_property wm831x_usb_props[] = {
POWER_SUPPLY_PROP_VOLTAGE_NOW,
 };
 
+/* In milliamps */
+static unsigned int wm831x_usb_limits[] = {
+   0,
+   2,
+   100,
+   500,
+   900,
+   1500,
+   1800,
+   550,
+};
+
+static int wm831x_usb_limit_change(struct notifier_block *nb,
+  unsigned long limit, void *data)
+{
+   struct wm831x_power *wm831x_power = container_of(nb,
+struct wm831x_power,
+usb_notify);
+   int i, best;
+
+   /* Find the highest supported limit */
+   best = 0;
+   for (i = 0; i < ARRAY_SIZE(wm831x_usb_limits); i++) {
+   if (limit >= wm831x_usb_limits[i] &&
+   wm831x_usb_limits[best] < wm831x_usb_limits[i])
+   best = i;
+   }
+
+   dev_dbg(wm831x_power->wm831x->dev,
+   "Limiting USB current to %dmA", wm831x_usb_limits[best]);
+
+   wm831x_set_bits(wm831x_power->wm831x, WM831X_POWER_STATE,
+   WM831X_USB_ILIM_MASK, best);
+
+   return 0;
+}
+
 /*
  * Battery properties
  */
@@ -607,8 +647,31 @@ static int wm831x_power_probe(struct platform_device *pdev)
}
}
 
+   if (wm831x_pdata && wm831x_pdata->usb_gadget) {
+   power->usb_charger =
+   usb_charger_find_by_name(wm831x_pdata->usb_gadget);
+   if (IS_ERR(power->usb_charger)) {
+   ret = PTR_ERR(power->usb_charger);
+   dev_err(>dev,
+   "Failed to find USB gadget: %d\n", ret);
+   goto err_bat_irq;
+   }
+
+   power->usb_notify.notifier_call = wm831x_usb_limit_change;
+
+   ret = usb_charger_register_notify(power->usb_charger,
+ >usb_notify);
+   if (ret != 0) {
+   dev_err(>dev,
+   "Failed to register notifier: %d\n", ret);
+   goto err_usb_charger;
+   }
+   }
+
return ret;
 
+err_usb_charger:
+   /* put_device on charger */
 err_bat_irq:
--i;
for (; i >= 0; i--) {
@@ -637,6 +700,12 @@ static int wm831x_power_remove(struct platform_device 
*pdev)
struct wm831x *wm831x = wm831x_power->wm831x;
int irq, i;
 
+   if (wm831x_power->usb_charger) {
+   usb_charger_unregister_notify(wm831x_power->usb_charger,
+ _power->usb_notify);
+   /* Free charger */
+   }
+
for (i = 0; i < ARRAY_SIZE(wm831x_bat_irqs); i++) {
irq = wm831x_irq(wm831x, 
 platform_get_irq_byname(pdev,
diff --git a/include/linux/mfd/wm831x/pdata.h b/include/linux/mfd/wm831x/pdata.h
index dcc9631..5af8399 100644
--- a/include/linux/mfd/wm831x/pdata.h
+++ b/include/linux/mfd/wm831x/pdata.h
@@ -126,6 +126,9 @@ struct wm831x_pdata {
/** The driver should initiate a power off sequence during shutdown */
bool soft_shutdown;
 
+   /** dev_name of USB charger gadget to integrate with */
+   const char *usb_gadget;
+
int irq_base;
int gpio_base;
int gpio_defaults[WM831X_GPIO_NUM];
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body 

[PATCH v6 3/4] gadget: Integrate with the usb gadget supporting for usb charger

2015-11-15 Thread Baolin Wang
When the usb gadget supporting for usb charger is ready, the usb charger
should get the type by the 'get_charger_type' callback which is implemented
by the usb gadget operations, and get the usb charger pointer from struct
'usb_gadget'.

Signed-off-by: Baolin Wang 
---
 drivers/usb/gadget/charger.c |   43 --
 1 file changed, 41 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/charger.c b/drivers/usb/gadget/charger.c
index 921f8e2..5d3cda6 100644
--- a/drivers/usb/gadget/charger.c
+++ b/drivers/usb/gadget/charger.c
@@ -183,7 +183,11 @@ int usb_charger_unregister_notify(struct usb_charger 
*uchger,
 enum usb_charger_type
 usb_charger_detect_type(struct usb_charger *uchger)
 {
-   if (uchger->psy) {
+   if (uchger->gadget && uchger->gadget->ops
+   && uchger->gadget->ops->get_charger_type) {
+   uchger->type =
+   uchger->gadget->ops->get_charger_type(uchger->gadget);
+   } else if (uchger->psy) {
union power_supply_propval val;
 
power_supply_get_property(uchger->psy,
@@ -385,6 +389,29 @@ usb_charger_plug_by_extcon(struct notifier_block *nb,
 int usb_charger_plug_by_gadget(struct usb_gadget *gadget,
   unsigned long state)
 {
+   struct usb_charger *uchger = gadget->charger;
+   enum usb_charger_state uchger_state;
+
+   if (!uchger)
+   return -EINVAL;
+
+   /* Report event to power to setting the current limitation
+* for this usb charger when one usb charger state is changed
+* with detecting by usb gadget state.
+*/
+   if (uchger->old_gadget_state != state) {
+   uchger->old_gadget_state = state;
+
+   if (state >= USB_STATE_ATTACHED)
+   uchger_state = USB_CHARGER_PRESENT;
+   else if (state == USB_STATE_NOTATTACHED)
+   uchger_state = USB_CHARGER_REMOVE;
+   else
+   uchger_state = USB_CHARGER_DEFAULT;
+
+   usb_charger_notify_others(uchger, uchger_state);
+   }
+
return 0;
 }
 
@@ -540,6 +567,7 @@ int usb_charger_init(struct usb_gadget *ugadget)
 
/* register a notifier on a usb gadget device */
uchger->gadget = ugadget;
+   ugadget->charger = uchger;
uchger->old_gadget_state = ugadget->state;
 
/* register a new usb charger */
@@ -560,7 +588,18 @@ fail:
 
 int usb_charger_exit(struct usb_gadget *ugadget)
 {
-   return 0;
+   struct usb_charger *uchger = ugadget->charger;
+
+   if (!uchger)
+   return -EINVAL;
+
+   if (uchger->extcon_dev)
+   extcon_unregister_notifier(uchger->extcon_dev,
+  EXTCON_USB, >extcon_nb.nb);
+
+   ida_simple_remove(_charger_ida, uchger->id);
+
+   return usb_charger_unregister(uchger);
 }
 
 static int __init usb_charger_sysfs_init(void)
-- 
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 v6 0/4] Introduce usb charger framework to deal with the usb gadget power negotation

2015-11-15 Thread Baolin Wang
Currently the Linux kernel does not provide any standard integration of this
feature that integrates the USB subsystem with the system power regulation
provided by PMICs meaning that either vendors must add this in their kernels
or USB gadget devices based on Linux (such as mobile phones) may not behave
as they should. Thus provide a standard framework for doing this in kernel.

Now introduce one user with wm831x_power to support and test the usb charger,
which is pending testing. Moreover there may be other potential users will use
it in future.

Changes since v5:
 - Remove the notifier chain things from the gadget and introduce one callback
 function to report to the usb charger when the gadget state is changed.
 - Flesh out the port type detection which combines the USB negotiation and
 PMICs detection.
 - Supply the notification mechanism to userspace when charger state is changed.
 - Integrate with the vbus staff in the gadget API.

Baolin Wang (4):
  gadget: Introduce the usb charger framework
  gadget: Support for the usb charger framework
  gadget: Integrate with the usb gadget supporting for usb charger
  power: wm831x_power: Support USB charger current limit management

 drivers/power/wm831x_power.c  |   69 +
 drivers/usb/gadget/Kconfig|7 +
 drivers/usb/gadget/Makefile   |1 +
 drivers/usb/gadget/charger.c  |  613 +
 drivers/usb/gadget/udc/udc-core.c |   11 +
 include/linux/mfd/wm831x/pdata.h  |3 +
 include/linux/usb/gadget.h|   10 +
 include/linux/usb/usb_charger.h   |  162 ++
 8 files changed, 876 insertions(+)
 create mode 100644 drivers/usb/gadget/charger.c
 create mode 100644 include/linux/usb/usb_charger.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


[PATCH v6 2/4] gadget: Support for the usb charger framework

2015-11-15 Thread Baolin Wang
For supporting the usb charger, it adds the usb_charger_init() and
usb_charger_exit() functions for usb charger initialization and exit.

It will report to the usb charger when the gadget state is changed,
then the usb charger can do the power things.

Introduce a callback 'get_charger_type' which will implemented by
user for usb gadget operations to get the usb charger type.

Signed-off-by: Baolin Wang 
---
 drivers/usb/gadget/udc/udc-core.c |   11 +++
 include/linux/usb/gadget.h|   10 ++
 2 files changed, 21 insertions(+)

diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index f660afb..2727f01 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /**
  * struct usb_udc - describes one usb device controller
@@ -226,6 +227,9 @@ static void usb_gadget_state_work(struct work_struct *work)
struct usb_gadget *gadget = work_to_gadget(work);
struct usb_udc *udc = gadget->udc;
 
+   /* when the gadget state is changed, then report to USB charger */
+   usb_charger_plug_by_gadget(gadget, gadget->state);
+
if (udc)
sysfs_notify(>dev.kobj, NULL, "state");
 }
@@ -405,8 +409,14 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
mutex_unlock(_lock);
 
+   ret = usb_charger_init(gadget);
+   if (ret)
+   goto err5;
+
return 0;
 
+err5:
+   device_del(>dev);
 err4:
list_del(>list);
mutex_unlock(_lock);
@@ -481,6 +491,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
kobject_uevent(>dev.kobj, KOBJ_REMOVE);
flush_work(>work);
device_unregister(>dev);
+   usb_charger_exit(gadget);
device_unregister(>dev);
 }
 EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 3d583a1..b8a6d38 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 struct usb_ep;
 
@@ -560,6 +561,7 @@ struct usb_gadget_ops {
struct usb_ep *(*match_ep)(struct usb_gadget *,
struct usb_endpoint_descriptor *,
struct usb_ss_ep_comp_descriptor *);
+   enum usb_charger_type (*get_charger_type)(struct usb_gadget *);
 };
 
 /**
@@ -632,6 +634,8 @@ struct usb_gadget {
unsignedout_epnum;
unsignedin_epnum;
struct usb_otg_caps *otg_caps;
+   /* negotiate the power with the usb charger */
+   struct usb_charger  *charger;
 
unsignedsg_supported:1;
unsignedis_otg:1;
@@ -836,10 +840,16 @@ static inline int usb_gadget_vbus_connect(struct 
usb_gadget *gadget)
  * reporting how much power the device may consume.  For example, this
  * could affect how quickly batteries are recharged.
  *
+ * It will also notify the USB charger how much power the device may
+ * consume if there is a USB charger linking with the gadget.
+ *
  * Returns zero on success, else negative errno.
  */
 static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
 {
+   if (gadget->charger)
+   usb_charger_set_cur_limit_by_type(gadget->charger, mA);
+
if (!gadget->ops->vbus_draw)
return -EOPNOTSUPP;
return gadget->ops->vbus_draw(gadget, mA);
-- 
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


Darlehen anbieten

2015-11-15 Thread OCEAN FINANCE


Guten Tag,
 
 Wir sind OCEAN FINANCE Darlehen Unternehmen geben Kredite per Post 
Anzeige. Wir bieten verschiedene Arten von Krediten (kurz- und langfristige 
Darlehen, persönliche Darlehen, Kredite an Unternehmen etc.) um 3% Zins. Wir 
geben Kredite an Menschen in Not nicht unabhängig von ihrem Standort, 
Geschlecht, Familienstand, Bildung, Job-Status, sondern muss eine rechtliche 
Mittel der Rückzahlung haben. Unsere Darlehen bewegen sich zwischen 5.000,00 zu 
10.000.000,00 US-Dollar oder Euro oder Pfund mit einer Laufzeit von maximal 20 
Jahren. Wenn Sie an weiteren Informationen interessiert sind, füllen Sie bitte 
das folgende Formular aus und schicken Sie es an unsere E-Mail-Adresse: 
oceanfina...@hotmail.com

Bitte füllen Sie:

Name:

Adresse:

Alter:

Geschlecht:

Kontakt-Telefon:

Beruf:

Monatliches Einkommen:

Die erforderliche Höhe des Darlehens:

Laufzeit des Darlehens:

Der Zweck des Darlehens:

Land:

ZIP Code:


"Wir zeigen Ihnen, einen besseren Weg, um Ihre finanzielle Freiheit"

Mit freundlichen Grüßen,

Alexander Balanoff
--
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: gadget: Add the console support for usb-to-serial port

2015-11-15 Thread Baolin Wang
It dose not work when we want to use the usb-to-serial port based
on one usb gadget as a console. Thus this patch adds the console
initialization to support this request.

Signed-off-by: Baolin Wang 
---
 drivers/usb/gadget/Kconfig |6 +
 drivers/usb/gadget/function/u_serial.c |  238 
 2 files changed, 244 insertions(+)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 33834aa..be5aab9 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -127,6 +127,12 @@ config USB_GADGET_STORAGE_NUM_BUFFERS
   a module parameter as well.
   If unsure, say 2.
 
+config U_SERIAL_CONSOLE
+   bool "Serial gadget console support"
+   depends on USB_G_SERIAL
+   help
+  It supports the serial gadget can be used as a console.
+
 source "drivers/usb/gadget/udc/Kconfig"
 
 #
diff --git a/drivers/usb/gadget/function/u_serial.c 
b/drivers/usb/gadget/function/u_serial.c
index f7771d8..4ade527 100644
--- a/drivers/usb/gadget/function/u_serial.c
+++ b/drivers/usb/gadget/function/u_serial.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "u_serial.h"
 
@@ -79,6 +80,16 @@
  */
 #define QUEUE_SIZE 16
 #define WRITE_BUF_SIZE 8192/* TX only */
+#define GS_BUFFER_SIZE (4096)
+#define GS_CONSOLE_BUF_SIZE(2 * GS_BUFFER_SIZE)
+
+struct gscons_info {
+   struct gs_port  *port;
+   struct tty_driver   *tty_driver;
+   struct work_struct  work;
+   int buf_tail;
+   charbuf[GS_CONSOLE_BUF_SIZE];
+};
 
 /* circular buffer */
 struct gs_buf {
@@ -118,6 +129,7 @@ struct gs_port {
 
/* REVISIT this state ... */
struct usb_cdc_line_coding port_line_coding;/* 8-N-1 etc */
+   struct usb_request  *console_req;
 };
 
 static struct portmaster {
@@ -1054,6 +1066,7 @@ gs_port_alloc(unsigned port_num, struct 
usb_cdc_line_coding *coding)
 
port->port_num = port_num;
port->port_line_coding = *coding;
+   port->console_req = NULL;
 
ports[port_num].port = port;
 out:
@@ -1143,6 +1156,227 @@ err:
 }
 EXPORT_SYMBOL_GPL(gserial_alloc_line);
 
+#ifdef CONFIG_U_SERIAL_CONSOLE
+
+static struct usb_request *gs_request_new(struct usb_ep *ep, int buffer_size)
+{
+   struct usb_request *req = usb_ep_alloc_request(ep, GFP_ATOMIC);
+
+   if (!req)
+   return NULL;
+
+   /* now allocate buffers for the requests */
+   req->buf = kmalloc(buffer_size, GFP_ATOMIC);
+   if (!req->buf) {
+   usb_ep_free_request(ep, req);
+   return NULL;
+   }
+
+   return req;
+}
+
+static void gs_request_free(struct usb_request *req, struct usb_ep *ep)
+{
+   if (req) {
+   kfree(req->buf);
+   usb_ep_free_request(ep, req);
+   }
+}
+
+static void gs_complete_out(struct usb_ep *ep, struct usb_request *req)
+{
+   if (req->status != 0 && req->status != -ECONNRESET)
+   return;
+}
+
+static struct console gserial_cons;
+static int gs_console_connect(void)
+{
+   struct gscons_info *info = gserial_cons.data;
+   int port_num = gserial_cons.index;
+   struct usb_request *req;
+   struct gs_port *port;
+   struct usb_ep *ep;
+
+   if (port_num >= MAX_U_SERIAL_PORTS || port_num < 0) {
+   pr_err("%s: port num [%d] exceeds the range.\n",
+  __func__, port_num);
+   return -ENXIO;
+   }
+
+   port = ports[port_num].port;
+   if (!port) {
+   pr_err("%s: serial line [%d] not allocated.\n",
+  __func__, port_num);
+   return -ENODEV;
+   }
+
+   if (!port->port_usb) {
+   pr_err("%s: no port usb.\n", __func__);
+   return -ENODEV;
+   }
+
+   ep = port->port_usb->in;
+   if (!ep) {
+   pr_err("%s: no usb endpoint.\n", __func__);
+   return -ENXIO;
+   }
+
+   req = port->console_req;
+   if (!req) {
+   req = gs_request_new(ep, GS_BUFFER_SIZE);
+   if (!req) {
+   pr_err("%s: request fail.\n", __func__);
+   return -ENOMEM;
+   }
+   req->complete = gs_complete_out;
+   }
+
+   info->port = port;
+
+   pr_debug("%s: port[%d] console connect!\n", __func__, port_num);
+   return 0;
+}
+
+static void gs_console_work(struct work_struct *work)
+{
+   struct gscons_info *info = container_of(work, struct gscons_info, work);
+   struct gs_port *port = info->port;
+   struct usb_request *req;
+   struct usb_ep *ep;
+   int xfer, ret, count;
+   char *p;
+
+   if (!port || !port->port_usb)
+   return;
+
+   req = port->console_req;
+   ep = port->port_usb->in;
+   if (!req || !ep)
+   

[PATCH v4 0/5] usb: usbtmc: Add support for missing functions in USBTMC-USB488 spec

2015-11-15 Thread Dave Penkler
Implement support for the USB488 defined READ_STATUS_BYTE ioctl (1/5)
and SRQ notifications with fasync (2/5) and poll/select (3/5) in order
to be able to synchronize with variable duration instrument
operations.

Add ioctls for other USB488 requests: REN_CONTROL, GOTO_LOCAL and
LOCAL_LOCKOUT. (4/5)

Add convenience ioctl to return all device capabilities (5/5)

 PATCH Changelog:
v4 - Remove excess newlines and parens
   - Simplify some expressions
   - Remove redundant initialisation

v3 - Split into multiple patches as per gregkh request

V2 - Fix V1 bug: not waking sleepers on disconnect.
   - Correct sparse warnings.

V1 - Original patch

 Testing:
All functions tested ok on an USBTMC-USB488 compliant oscilloscope

Dave Penkler (5):
  Implement an ioctl to support the USMTMC-USB488 READ_STATUS_BYTE
operation.
  Add support for USBTMC USB488 SRQ notification with fasync
  Add support for receiving USBTMC USB488 SRQ notifications via
poll/select
  Add ioctl to retrieve USBTMC-USB488 capabilities
  Add ioctls to enable and disable local controls on an instrument

 drivers/usb/class/usbtmc.c   | 354 +++
 include/uapi/linux/usb/tmc.h |  29 +++-
 2 files changed, 380 insertions(+), 3 deletions(-)

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


[PATCH v4 5/5] Add ioctls to enable and disable local controls on an instrument

2015-11-15 Thread Dave Penkler
These ioctls provide support for the USBTMC-USB488 control requests
for REN_CONTROL, GO_TO_LOCAL and LOCAL_LOCKOUT

Signed-off-by: Dave Penkler 
---
 drivers/usb/class/usbtmc.c   | 76 
 include/uapi/linux/usb/tmc.h |  6 
 2 files changed, 82 insertions(+)

diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c
index add0ce2..79caa78 100644
--- a/drivers/usb/class/usbtmc.c
+++ b/drivers/usb/class/usbtmc.c
@@ -478,6 +478,68 @@ static int usbtmc488_ioctl_read_stb(struct 
usbtmc_device_data *data,
return rv;
 }
 
+static int usbtmc488_ioctl_simple(struct usbtmc_device_data *data,
+   unsigned long arg,
+   unsigned int cmd)
+{
+   u8 *buffer;
+   struct device *dev;
+   int rv;
+   unsigned int val;
+   u16 wValue;
+
+   dev = >intf->dev;
+
+   if (!(data->usb488_caps & USBTMC488_CAPABILITY_SIMPLE))
+   return -EINVAL;
+
+   buffer = kmalloc(8, GFP_KERNEL);
+   if (!buffer)
+   return -ENOMEM;
+
+   if (cmd == USBTMC488_REQUEST_REN_CONTROL) {
+   rv = copy_from_user(, (void __user *)arg, sizeof(val));
+   if (rv) {
+   rv = -EFAULT;
+   goto exit;
+   }
+   wValue = (val) ? 1 : 0;
+   } else {
+   wValue = 0;
+   }
+
+   dev_warn(dev, "wValue is %d\n", wValue);
+
+   rv = usb_control_msg(data->usb_dev,
+   usb_rcvctrlpipe(data->usb_dev, 0),
+   cmd,
+   USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
+   wValue,
+   data->ifnum,
+   buffer, 0x01, USBTMC_TIMEOUT);
+
+   if (rv < 0) {
+   dev_err(dev, "simple usb_control_msg failed %d\n", rv);
+   goto exit;
+   } else if (rv != 1) {
+   dev_warn(dev, "simple usb_control_msg returned %d\n", rv);
+   rv = -EIO;
+   goto exit;
+   }
+
+   if (buffer[0] != USBTMC_STATUS_SUCCESS) {
+   dev_err(dev, "simple control status returned %x\n", buffer[0]);
+   rv = -EIO;
+   goto exit;
+   } else {
+   rv = 0;
+   }
+
+ exit:
+   kfree(buffer);
+   return rv;
+}
+
 /*
  * Sends a REQUEST_DEV_DEP_MSG_IN message on the Bulk-IN endpoint.
  * @transfer_size: number of bytes to request from the device.
@@ -1188,6 +1250,20 @@ static long usbtmc_ioctl(struct file *file, unsigned int 
cmd, unsigned long arg)
retval = usbtmc488_ioctl_read_stb(data, arg);
break;
 
+   case USBTMC488_IOCTL_REN_CONTROL:
+   retval = usbtmc488_ioctl_simple(data, arg,
+   USBTMC488_REQUEST_REN_CONTROL);
+   break;
+
+   case USBTMC488_IOCTL_GOTO_LOCAL:
+   retval = usbtmc488_ioctl_simple(data, arg,
+   USBTMC488_REQUEST_GOTO_LOCAL);
+   break;
+
+   case USBTMC488_IOCTL_LOCAL_LOCKOUT:
+   retval = usbtmc488_ioctl_simple(data, arg,
+   
USBTMC488_REQUEST_LOCAL_LOCKOUT);
+   break;
}
 
 skip_io_on_zombie:
diff --git a/include/uapi/linux/usb/tmc.h b/include/uapi/linux/usb/tmc.h
index 1dc3af1..0d852c9 100644
--- a/include/uapi/linux/usb/tmc.h
+++ b/include/uapi/linux/usb/tmc.h
@@ -33,6 +33,9 @@
 #define USBTMC_REQUEST_GET_CAPABILITIES7
 #define USBTMC_REQUEST_INDICATOR_PULSE 64
 #define USBTMC488_REQUEST_READ_STATUS_BYTE 128
+#define USBTMC488_REQUEST_REN_CONTROL  160
+#define USBTMC488_REQUEST_GOTO_LOCAL   161
+#define USBTMC488_REQUEST_LOCAL_LOCKOUT162
 
 /* Request values for USBTMC driver's ioctl entry point */
 #define USBTMC_IOC_NR  91
@@ -44,6 +47,9 @@
 #define USBTMC_IOCTL_CLEAR_IN_HALT _IO(USBTMC_IOC_NR, 7)
 #define USBTMC488_IOCTL_GET_CAPS   _IO(USBTMC_IOC_NR, 17)
 #define USBTMC488_IOCTL_READ_STB   _IOR(USBTMC_IOC_NR, 18, unsigned char)
+#define USBTMC488_IOCTL_REN_CONTROL_IOW(USBTMC_IOC_NR, 19, unsigned char)
+#define USBTMC488_IOCTL_GOTO_LOCAL _IO(USBTMC_IOC_NR, 20)
+#define USBTMC488_IOCTL_LOCAL_LOCKOUT  _IO(USBTMC_IOC_NR, 21)
 
 /* Driver encoded usb488 capabilities */
 #define USBTMC488_CAPABILITY_TRIGGER 1
-- 
2.5.1
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 2/5] Add support for USBTMC USB488 SRQ notification with fasync

2015-11-15 Thread Dave Penkler
Background:
By configuring an instrument's event status register various
conditions can be reported via an SRQ notification. This complements
the synchronous polling approach using the READ_STATUS_BYTE ioctl
with an asynchronous notification.

Signed-off-by: Dave Penkler 
---
 drivers/usb/class/usbtmc.c | 24 
 1 file changed, 24 insertions(+)

diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c
index 72ef7f0..7430a52 100644
--- a/drivers/usb/class/usbtmc.c
+++ b/drivers/usb/class/usbtmc.c
@@ -99,6 +99,7 @@ struct usbtmc_device_data {
intiin_interval;
struct urb*iin_urb;
u16iin_wMaxPacketSize;
+   atomic_t   srq_asserted;
 
u8 rigol_quirk;
 
@@ -113,6 +114,7 @@ struct usbtmc_device_data {
struct kref kref;
struct mutex io_mutex;  /* only one i/o function running at a time */
wait_queue_head_t waitq;
+   struct fasync_struct *fasync;
 };
 #define to_usbtmc_data(d) container_of(d, struct usbtmc_device_data, kref)
 
@@ -406,6 +408,9 @@ static int usbtmc488_ioctl_read_stb(struct 
usbtmc_device_data *data,
 
atomic_set(>iin_data_valid, 0);
 
+   /* must issue read_stb before using poll or select */
+   atomic_set(>srq_asserted, 0);
+
rv = usb_control_msg(data->usb_dev,
usb_rcvctrlpipe(data->usb_dev, 0),
USBTMC488_REQUEST_READ_STATUS_BYTE,
@@ -1177,6 +1182,13 @@ skip_io_on_zombie:
return retval;
 }
 
+static int usbtmc_fasync(int fd, struct file *file, int on)
+{
+   struct usbtmc_device_data *data = file->private_data;
+
+   return fasync_helper(fd, file, on, >fasync);
+}
+
 static const struct file_operations fops = {
.owner  = THIS_MODULE,
.read   = usbtmc_read,
@@ -1184,6 +1196,7 @@ static const struct file_operations fops = {
.open   = usbtmc_open,
.release= usbtmc_release,
.unlocked_ioctl = usbtmc_ioctl,
+   .fasync = usbtmc_fasync,
.llseek = default_llseek,
 };
 
@@ -1214,6 +1227,16 @@ static void usbtmc_interrupt(struct urb *urb)
wake_up_interruptible(>waitq);
goto exit;
}
+   /* check for SRQ notification */
+   if ((data->iin_buffer[0] & 0x7f) == 1) {
+   if (data->fasync)
+   kill_fasync(>fasync,
+   SIGIO, POLL_IN);
+
+   atomic_set(>srq_asserted, 1);
+   wake_up_interruptible(>waitq);
+   goto exit;
+   }
}
dev_warn(>intf->dev, "invalid notification: %x\n",
data->iin_buffer[0]);
@@ -1280,6 +1303,7 @@ static int usbtmc_probe(struct usb_interface *intf,
mutex_init(>io_mutex);
init_waitqueue_head(>waitq);
atomic_set(>iin_data_valid, 0);
+   atomic_set(>srq_asserted, 0);
data->zombie = 0;
 
/* Determine if it is a Rigol or not */
-- 
2.5.1
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 3/5] Add support for receiving USBTMC USB488 SRQ notifications via poll/select

2015-11-15 Thread Dave Penkler
Background:
In many situations operations on multiple instruments need to be
synchronized. poll/select provide a convenient way of waiting on a
number of different instruments and other peripherals
simultaneously.

Signed-off-by: Dave Penkler 
---
 drivers/usb/class/usbtmc.c | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c
index 7430a52..6c0e1dc 100644
--- a/drivers/usb/class/usbtmc.c
+++ b/drivers/usb/class/usbtmc.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1189,6 +1190,27 @@ static int usbtmc_fasync(int fd, struct file *file, int 
on)
return fasync_helper(fd, file, on, >fasync);
 }
 
+static unsigned int usbtmc_poll(struct file *file, poll_table *wait)
+{
+   struct usbtmc_device_data *data = file->private_data;
+   unsigned int mask;
+
+   mutex_lock(>io_mutex);
+
+   if (data->zombie) {
+   mask = POLLHUP | POLLERR;
+   goto no_poll;
+   }
+
+   poll_wait(file, >waitq, wait);
+
+   mask = (atomic_read(>srq_asserted)) ? POLLIN | POLLRDNORM : 0;
+
+no_poll:
+   mutex_unlock(>io_mutex);
+   return mask;
+}
+
 static const struct file_operations fops = {
.owner  = THIS_MODULE,
.read   = usbtmc_read,
@@ -1197,6 +1219,7 @@ static const struct file_operations fops = {
.release= usbtmc_release,
.unlocked_ioctl = usbtmc_ioctl,
.fasync = usbtmc_fasync,
+   .poll   = usbtmc_poll,
.llseek = default_llseek,
 };
 
-- 
2.5.1
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 4/5] Add ioctl to retrieve USBTMC-USB488 capabilities

2015-11-15 Thread Dave Penkler
This is a convenience function to obtain an instrument's
capabilities from its file descriptor without having to access sysfs
from the user program.

Signed-off-by: Dave Penkler 
---
 drivers/usb/class/usbtmc.c   | 12 
 include/uapi/linux/usb/tmc.h | 21 ++---
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c
index 6c0e1dc..add0ce2 100644
--- a/drivers/usb/class/usbtmc.c
+++ b/drivers/usb/class/usbtmc.c
@@ -102,6 +102,9 @@ struct usbtmc_device_data {
u16iin_wMaxPacketSize;
atomic_t   srq_asserted;
 
+   /* coalesced usb488_caps from usbtmc_dev_capabilities */
+   u8 usb488_caps;
+
u8 rigol_quirk;
 
/* attributes from the USB TMC spec for this device */
@@ -997,6 +1000,7 @@ static int get_capabilities(struct usbtmc_device_data 
*data)
data->capabilities.device_capabilities = buffer[5];
data->capabilities.usb488_interface_capabilities = buffer[14];
data->capabilities.usb488_device_capabilities = buffer[15];
+   data->usb488_caps = (buffer[14] & 0x07) | ((buffer[15] & 0x0f) << 4);
rv = 0;
 
 err_out:
@@ -1172,6 +1176,14 @@ static long usbtmc_ioctl(struct file *file, unsigned int 
cmd, unsigned long arg)
retval = usbtmc_ioctl_abort_bulk_in(data);
break;
 
+   case USBTMC488_IOCTL_GET_CAPS:
+   retval = copy_to_user((void __user *)arg,
+   >usb488_caps,
+   sizeof(data->usb488_caps));
+   if (retval)
+   retval = -EFAULT;
+   break;
+
case USBTMC488_IOCTL_READ_STB:
retval = usbtmc488_ioctl_read_stb(data, arg);
break;
diff --git a/include/uapi/linux/usb/tmc.h b/include/uapi/linux/usb/tmc.h
index 7e5ced8..1dc3af1 100644
--- a/include/uapi/linux/usb/tmc.h
+++ b/include/uapi/linux/usb/tmc.h
@@ -2,12 +2,14 @@
  * Copyright (C) 2007 Stefan Kopp, Gechingen, Germany
  * Copyright (C) 2008 Novell, Inc.
  * Copyright (C) 2008 Greg Kroah-Hartman 
+ * Copyright (C) 2015 Dave Penkler 
  *
  * This file holds USB constants defined by the USB Device Class
- * Definition for Test and Measurement devices published by the USB-IF.
+ * and USB488 Subclass Definitions for Test and Measurement devices
+ * published by the USB-IF.
  *
- * It also has the ioctl definitions for the usbtmc kernel driver that
- * userspace needs to know about.
+ * It also has the ioctl and capability definitions for the
+ * usbtmc kernel driver that userspace needs to know about.
  */
 
 #ifndef __LINUX_USB_TMC_H
@@ -40,6 +42,19 @@
 #define USBTMC_IOCTL_ABORT_BULK_IN _IO(USBTMC_IOC_NR, 4)
 #define USBTMC_IOCTL_CLEAR_OUT_HALT_IO(USBTMC_IOC_NR, 6)
 #define USBTMC_IOCTL_CLEAR_IN_HALT _IO(USBTMC_IOC_NR, 7)
+#define USBTMC488_IOCTL_GET_CAPS   _IO(USBTMC_IOC_NR, 17)
 #define USBTMC488_IOCTL_READ_STB   _IOR(USBTMC_IOC_NR, 18, unsigned char)
 
+/* Driver encoded usb488 capabilities */
+#define USBTMC488_CAPABILITY_TRIGGER 1
+#define USBTMC488_CAPABILITY_SIMPLE  2
+#define USBTMC488_CAPABILITY_REN_CONTROL 2
+#define USBTMC488_CAPABILITY_GOTO_LOCAL  2
+#define USBTMC488_CAPABILITY_LOCAL_LOCKOUT   2
+#define USBTMC488_CAPABILITY_488_DOT_2   4
+#define USBTMC488_CAPABILITY_DT1 16
+#define USBTMC488_CAPABILITY_RL1 32
+#define USBTMC488_CAPABILITY_SR1 64
+#define USBTMC488_CAPABILITY_FULL_SCPI   128
+
 #endif
-- 
2.5.1
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html