[PATCH v2 1/1] usb: core: lpm: set lpm_capable for root hub device

2015-06-13 Thread Lu Baolu
Commit 25cd2882e2fc ("usb/xhci: Change how we indicate a host supports
Link PM.") removed the code to set lpm_capable for USB 3.0 super-speed
root hub. The intention of that change was to avoid touching usb core
internal field, a.k.a. lpm_capable, and let usb core to set it by
checking U1 and U2 exit latency values in the descriptor.

Usb core checks and sets lpm_capable in hub_port_init(). Unfortunately,
root hub is a special usb device as it has no parent. Hub_port_init()
will never be called for a root hub device. That means lpm_capable will
by no means be set for the root hub. As the result, lpm isn't functional
at all in Linux kernel.

This patch add the code to check and set lpm_capable when registering a
root hub device. It could be back-ported to kernels as old as v3.15,
that contains the Commit 25cd2882e2fc ("usb/xhci: Change how we indicate
a host supports Link PM.").

Cc: sta...@vger.kernel.org # 3.15
Reported-by: Kevin Strasser 
Signed-off-by: Lu Baolu 
---
 drivers/usb/core/hcd.c | 7 +--
 drivers/usb/core/hub.c | 2 +-
 drivers/usb/core/usb.h | 6 ++
 3 files changed, 12 insertions(+), 3 deletions(-)

 v1->v2 change log:
 1. two code blocks merged (Alan's feedback)
 2. fix build error when CONFIG_PM is not set (Alan's feedback)

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 45a915c..1c1385e 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1022,9 +1022,12 @@ static int register_root_hub(struct usb_hcd *hcd)
dev_name(&usb_dev->dev), retval);
return (retval < 0) ? retval : -EMSGSIZE;
}
-   if (usb_dev->speed == USB_SPEED_SUPER) {
+
+   if (le16_to_cpu(usb_dev->descriptor.bcdUSB) >= 0x0201) {
retval = usb_get_bos_descriptor(usb_dev);
-   if (retval < 0) {
+   if (!retval) {
+   usb_dev->lpm_capable = usb_device_supports_lpm(usb_dev);
+   } else if (usb_dev->speed == USB_SPEED_SUPER) {
mutex_unlock(&usb_bus_list_lock);
dev_dbg(parent_dev, "can't read %s bos descriptor %d\n",
dev_name(&usb_dev->dev), retval);
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 3b71516..884d702 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -122,7 +122,7 @@ struct usb_hub *usb_hub_to_struct_hub(struct usb_device 
*hdev)
return usb_get_intfdata(hdev->actconfig->interface[0]);
 }
 
-static int usb_device_supports_lpm(struct usb_device *udev)
+int usb_device_supports_lpm(struct usb_device *udev)
 {
/* USB 2.1 (and greater) devices indicate LPM support through
 * their USB 2.0 Extended Capabilities BOS descriptor.
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index 7eb1e26..d54a669 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -82,6 +82,7 @@ extern int usb_runtime_suspend(struct device *dev);
 extern int usb_runtime_resume(struct device *dev);
 extern int usb_runtime_idle(struct device *dev);
 extern int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable);
+extern int usb_device_supports_lpm(struct usb_device *udev);
 
 #else
 
@@ -106,6 +107,11 @@ static inline int usb_set_usb2_hardware_lpm(struct 
usb_device *udev, int enable)
return 0;
 }
 
+static inline int usb_device_supports_lpm(struct usb_device *udev)
+{
+   return 0;
+}
+
 #endif
 
 extern struct bus_type usb_bus_type;
-- 
2.1.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: [BUG] usb/at91: usb hub does not work

2015-06-13 Thread Boris Brezillon
Hi Jiri,

On Fri, 12 Jun 2015 11:30:20 +0200
Jiří Prchal  wrote:

> 
> 
> On 11.6.2015 15:53, Alan Stern wrote:
> > On Thu, 11 Jun 2015, Jiří Prchal wrote:
> >
> >> Hi all,
> >> I discovered some bug when I change kernel from 3.18.13 to 3.18.14. I have 
> >> board with usb hub CY7C65632 on it.
> >> In .13 it works fine but in .14 it repeats this message:
> >> [   19.17] usb 2-3: new full-speed USB device number 56 using at91_ohci
> >> and devices connected to usb through hub doesn't appear at all.
> >
> >> Any idea?
> >
> > Try using git bisect to find the commit which caused this problem to
> > start.
> 
> This is result:
> Bisecting: 0 revisions left to test after this (roughly 0 steps)
> [ae74ea64ccdb8b99ee2618b58020263d5b1d9b22] clk: at91: usb: propagate rate 
> modification to the parent clk


Actually when bisecting you found a bug that has been fixed before
3.18.14 was released (see this commit [1]).
This being said, the prototype mismatch fix does not seem to fix all
the mismatches (seems the ->determine_rate() has been changed in 3.19
too, and the prototype mismatch patch was a backport of a 3.19 fix).

Anyway, you'll find below a patch supposed to fix the remaining bug.
Can you try to apply it and let me know if it fixes your problem.

Best Regards,

Boris

[1]https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/commit/drivers/clk/at91/clk-usb.c?id=76723e7ed589998384a080e29204df4659c67cf2

-- >8 --

>From 7392429d074f43ef61d41e33db63f0f5d804bdd4 Mon Sep 17 00:00:00 2001
Subject: [PATCH] clk: at91: fix determine_rate prototype (again)

Commit ae74ea64ccdb8b99ee2618b58020263d5b1d9b22 was a backport of a bug
fix applied in 4.0, but in the meantime the ->determine_rate() prototype
has changed, thus introduction a prototype mismatch bug in pre-4.0
kernels. This prototype mismatch was supposed to be fixed by commit
76723e7ed589998384a080e29204df4659c67cf2, which fix the bug on 3.19
kernels, but the ->determine_rate() has also changed between 3.18 and
3.19. Hopefully this patch will definitely fix the prototype mismatch
for 3.18.

Signed-off-by: Boris Brezillon 
---
 drivers/clk/at91/clk-usb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/at91/clk-usb.c b/drivers/clk/at91/clk-usb.c
index 0283a57..d0d335d 100644
--- a/drivers/clk/at91/clk-usb.c
+++ b/drivers/clk/at91/clk-usb.c
@@ -59,7 +59,7 @@ static unsigned long
at91sam9x5_clk_usb_recalc_rate(struct clk_hw *hw, static long
at91sam9x5_clk_usb_determine_rate(struct clk_hw *hw, unsigned long rate,
  unsigned long
*best_parent_rate,
- struct clk_hw
**best_parent_hw)
+ struct clk
**best_parent_clk) {
struct clk *parent = NULL;
long best_rate = -EINVAL;
@@ -91,7 +91,7 @@ static long at91sam9x5_clk_usb_determine_rate(struct
clk_hw *hw, best_rate = tmp_rate;
best_diff = tmp_diff;
*best_parent_rate = tmp_parent_rate;
-   *best_parent_hw = __clk_get_hw(parent);
+   *best_parent_clk = parent;
}
 
if (!best_diff || tmp_rate < rate)
-- 
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


Re: [BUG] usb/at91: usb hub does not work

2015-06-13 Thread Boris Brezillon
On Sat, 13 Jun 2015 13:09:56 +0200
Boris Brezillon  wrote:

> Hi Jiri,
> 
> On Fri, 12 Jun 2015 11:30:20 +0200
> Jiří Prchal  wrote:
> 
> > 
> > 
> > On 11.6.2015 15:53, Alan Stern wrote:
> > > On Thu, 11 Jun 2015, Jiří Prchal wrote:
> > >
> > >> Hi all,
> > >> I discovered some bug when I change kernel from 3.18.13 to 3.18.14. I 
> > >> have board with usb hub CY7C65632 on it.
> > >> In .13 it works fine but in .14 it repeats this message:
> > >> [   19.17] usb 2-3: new full-speed USB device number 56 using 
> > >> at91_ohci
> > >> and devices connected to usb through hub doesn't appear at all.
> > >
> > >> Any idea?
> > >
> > > Try using git bisect to find the commit which caused this problem to
> > > start.
> > 
> > This is result:
> > Bisecting: 0 revisions left to test after this (roughly 0 steps)
> > [ae74ea64ccdb8b99ee2618b58020263d5b1d9b22] clk: at91: usb: propagate rate 
> > modification to the parent clk
> 
> 
> Actually when bisecting you found a bug that has been fixed before
> 3.18.14 was released (see this commit [1]).
> This being said, the prototype mismatch fix does not seem to fix all
> the mismatches (seems the ->determine_rate() has been changed in 3.19
> too, and the prototype mismatch patch was a backport of a 3.19 fix).
> 
> Anyway, you'll find below a patch supposed to fix the remaining bug.

I forgot to disable the line wrapper in my email client, here is the
same patch without the wrapped lines:

-- >8 --

>From 7392429d074f43ef61d41e33db63f0f5d804bdd4 Mon Sep 17 00:00:00 2001
Subject: [PATCH] clk: at91: fix determine_rate prototype (again)

Commit ae74ea64ccdb8b99ee2618b58020263d5b1d9b22 was a backport of a bug
fix applied in 4.0, but in the meantime the ->determine_rate() prototype
has changed, thus introduction a prototype mismatch bug in pre-4.0
kernels. This prototype mismatch was supposed to be fixed by commit
76723e7ed589998384a080e29204df4659c67cf2, which fix the bug on 3.19 kernels,
but the ->determine_rate() has also changed between 3.18 and 3.19.
Hopefully this patch will definitely fix the prototype mismatch for 3.18.

Signed-off-by: Boris Brezillon 
---
 drivers/clk/at91/clk-usb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/at91/clk-usb.c b/drivers/clk/at91/clk-usb.c
index 0283a57..d0d335d 100644
--- a/drivers/clk/at91/clk-usb.c
+++ b/drivers/clk/at91/clk-usb.c
@@ -59,7 +59,7 @@ static unsigned long at91sam9x5_clk_usb_recalc_rate(struct 
clk_hw *hw,
 static long at91sam9x5_clk_usb_determine_rate(struct clk_hw *hw,
  unsigned long rate,
  unsigned long *best_parent_rate,
- struct clk_hw **best_parent_hw)
+ struct clk **best_parent_clk)
 {
struct clk *parent = NULL;
long best_rate = -EINVAL;
@@ -91,7 +91,7 @@ static long at91sam9x5_clk_usb_determine_rate(struct clk_hw 
*hw,
best_rate = tmp_rate;
best_diff = tmp_diff;
*best_parent_rate = tmp_parent_rate;
-   *best_parent_hw = __clk_get_hw(parent);
+   *best_parent_clk = parent;
}
 
if (!best_diff || tmp_rate < rate)
-- 
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 v5 3/7] phy-sun4i-usb: Swap check for disconnect threshold

2015-06-13 Thread Hans de Goede
Before this commit the code for determining the disconnect threshold was
checking for "allwinner,sun4i-a10-usb-phy" or "allwinner,sun6i-a31-usb-phy"
assuming that those where the exception and then newer SoCs would use a
disconnect threshold of 2 like sun7i does. But it turns out that newer
SoCs use a disconnect threshold of 3 and sun5i and sun7i are the
exceptions, so check for those instead.

Here are the settings from the various Allwinner SDK sources:
 sun4i-a10: USBC_Phy_Write(usbc_no, 0x2a, 3, 2);
 sun5i-a13: USBC_Phy_Write(usbc_no, 0x2a, 2, 2);
 sun6i-a31: USBC_Phy_Write(usbc_no, 0x2a, 3, 2);
 sun7i-a20: USBC_Phy_Write(usbc_no, 0x2a, 2, 2);
 sun8i-a23: USBC_Phy_Write(usbc_no, 0x2a, 3, 2);
 sun8i-h3:  USBC_Phy_Write(usbc_no, 0x2a, 3, 2);
 sun9i-a80: USBC_Phy_Write(usbc_no, 0x2a, 3, 2);

Note this commit makes no functional changes as currently we only support
sun4i - sun7i.

Signed-off-by: Hans de Goede 
---
 drivers/phy/phy-sun4i-usb.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
index 86d9ce1..d78a071 100644
--- a/drivers/phy/phy-sun4i-usb.c
+++ b/drivers/phy/phy-sun4i-usb.c
@@ -447,11 +447,11 @@ static int sun4i_usb_phy_probe(struct platform_device 
*pdev)
else
data->num_phys = 3;
 
-   if (of_device_is_compatible(np, "allwinner,sun4i-a10-usb-phy") ||
-   of_device_is_compatible(np, "allwinner,sun6i-a31-usb-phy"))
-   data->disc_thresh = 3;
-   else
+   if (of_device_is_compatible(np, "allwinner,sun5i-a13-usb-phy") ||
+   of_device_is_compatible(np, "allwinner,sun7i-a20-usb-phy"))
data->disc_thresh = 2;
+   else
+   data->disc_thresh = 3;
 
if (of_device_is_compatible(np, "allwinner,sun6i-a31-usb-phy"))
dedicated_clocks = true;
-- 
2.4.3

--
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 v5 1/7] phy-sun4i-usb: Add id and vbus detection support for the otg phy (phy0)

2015-06-13 Thread Hans de Goede
The usb0 phy is connected to an OTG controller, and as such needs some special
handling:

1) It allows explicit control over the pullups, enable these on phy_init and
disable them on phy_exit.

2) It has bits to signal id and vbus detect to the musb-core, add support for
for monitoring id and vbus detect gpio-s for use in dual role mode, and set
these bits to the correct values for operating in host only mode when no
gpios are specified in the devicetree.

While updating the devicetree binding documentation also add documentation
for the sofar undocumented usage of regulators for vbus for all 3 phys.

Signed-off-by: Hans de Goede 
---
Changes in v2:
-Removed the sunxi specific phy functions, instead the id / vbus gpio polling
 has been moved to the phy-sun4i-usb driver and their status is exported
 through extcon for the sunxi-musb glue
Changes in v3:
-No changes
Changes in v4:
-Do not call regulator_disable in an unbalanced manner when an external vbus
 is present
Changes in v5:
-Split the addition of the extcon handler out into a separate patch
-Use sun4i_usb_phy_remove() to ensure the vbus/id detect workqueue is stopped
 if sun4i_usb_phy_probe() fails after registering an irq handler
---
 .../devicetree/bindings/phy/sun4i-usb-phy.txt  |  18 +-
 drivers/phy/phy-sun4i-usb.c| 250 -
 2 files changed, 256 insertions(+), 12 deletions(-)

diff --git a/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt 
b/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
index 16528b9..557fa99 100644
--- a/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
+++ b/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
@@ -23,6 +23,13 @@ Required properties:
   * "usb1_reset"
   * "usb2_reset" for sun4i, sun6i or sun7i
 
+Optional properties:
+- usb0_id_det-gpios : gpio phandle for reading the otg id pin value
+- usb0_vbus_det-gpios : gpio phandle for detecting the presence of usb0 vbus
+- usb0_vbus-supply : regulator phandle for controller usb0 vbus
+- usb1_vbus-supply : regulator phandle for controller usb1 vbus
+- usb2_vbus-supply : regulator phandle for controller usb2 vbus
+
 Example:
usbphy: phy@0x01c13400 {
#phy-cells = <1>;
@@ -32,6 +39,13 @@ Example:
reg-names = "phy_ctrl", "pmu1", "pmu2";
clocks = <&usb_clk 8>;
clock-names = "usb_phy";
-   resets = <&usb_clk 1>, <&usb_clk 2>;
-   reset-names = "usb1_reset", "usb2_reset";
+   resets = <&usb_clk 0>, <&usb_clk 1>, <&usb_clk 2>;
+   reset-names = "usb0_reset", "usb1_reset", "usb2_reset";
+   pinctrl-names = "default";
+   pinctrl-0 = <&usb0_id_detect_pin>, <&usb0_vbus_detect_pin>;
+   usb0_id_det-gpios = <&pio 7 19 GPIO_ACTIVE_HIGH>; /* PH19 */
+   usb0_vbus_det-gpios = <&pio 7 22 GPIO_ACTIVE_HIGH>; /* PH22 */
+   usb0_vbus-supply = <®_usb0_vbus>;
+   usb1_vbus-supply = <®_usb1_vbus>;
+   usb2_vbus-supply = <®_usb2_vbus>;
};
diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
index 91c5be4..bdf63ad 100644
--- a/drivers/phy/phy-sun4i-usb.c
+++ b/drivers/phy/phy-sun4i-usb.c
@@ -1,7 +1,7 @@
 /*
  * Allwinner sun4i USB phy driver
  *
- * Copyright (C) 2014 Hans de Goede 
+ * Copyright (C) 2014-2015 Hans de Goede 
  *
  * Based on code from
  * Allwinner Technology Co., Ltd. 
@@ -24,16 +24,19 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 
 #define REG_ISCR   0x00
 #define REG_PHYCTL 0x04
@@ -47,6 +50,17 @@
 #define SUNXI_AHB_INCRX_ALIGN_EN   BIT(8)
 #define SUNXI_ULPI_BYPASS_EN   BIT(0)
 
+/* ISCR, Interface Status and Control bits */
+#define ISCR_ID_PULLUP_EN  (1 << 17)
+#define ISCR_DPDM_PULLUP_EN(1 << 16)
+/* sunxi has the phy id/vbus pins not connected, so we use the force bits */
+#define ISCR_FORCE_ID_MASK (3 << 14)
+#define ISCR_FORCE_ID_LOW  (2 << 14)
+#define ISCR_FORCE_ID_HIGH (3 << 14)
+#define ISCR_FORCE_VBUS_MASK   (3 << 12)
+#define ISCR_FORCE_VBUS_LOW(2 << 12)
+#define ISCR_FORCE_VBUS_HIGH   (3 << 12)
+
 /* Common Control Bits for Both PHYs */
 #define PHY_PLL_BW 0x03
 #define PHY_RES45_CAL_EN   0x0c
@@ -63,6 +77,13 @@
 
 #define MAX_PHYS   3
 
+/*
+ * Note do not raise the debounce time, we must report Vusb high within 100ms
+ * otherwise we get Vbus errors
+ */
+#define DEBOUNCE_TIME  msecs_to_jiffies(50)
+#define POLL_TIME  msecs_to_jiffies(250)
+
 struct sun4i_usb_phy_data {
void __iomem *base;
struct mutex mutex;
@@ -74,13 +95,56 @@ struct sun4i_usb_phy_data {
struct regulator *vbus;
struct reset_control *reset;
 

[PATCH v5 0/7] phy-sun4i-usb: Add OTG and newer SoC support

2015-06-13 Thread Hans de Goede
Hi Kishon,

Here is a patch series with all my oustanding phy-sun4i-usb changes pending
for merging into 4.3.

This includes the 5th iteration of the OTG support addition, now with the
extcon provider support addition split-out into a new patch and ported to
the extcon API changes which are queued up for 4.2 from :

http://git.kernel.org/cgit/linux/kernel/git/chanwoo/extcon.git/log/?h=extcon-next-v4.2

which already merged in GKH's char-misc branch for 4.2, this means that
this series now depends on those changes.

Other than that this is a resend of some of the other feature addition
patches I recently send rebased on top of v5 of the OTG support.

Please merge this series for 4.3.

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 v5 5/7] phy-sun4i-usb: Add support for the usb-phys on the sun8i-a33 SoC

2015-06-13 Thread Hans de Goede
The usb-phys on the sun8i-a33 SoC are mostly the same as sun8i-a23 but for
some reason (hw bug?) the phyctl register was moved to a different address
and is not initialized to 0 on reset.

Signed-off-by: Hans de Goede 
---
 .../devicetree/bindings/phy/sun4i-usb-phy.txt  |  1 +
 drivers/phy/phy-sun4i-usb.c| 39 --
 2 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt 
b/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
index f0c640a..5f48979 100644
--- a/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
+++ b/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
@@ -8,6 +8,7 @@ Required properties:
   * allwinner,sun6i-a31-usb-phy
   * allwinner,sun7i-a20-usb-phy
   * allwinner,sun8i-a23-usb-phy
+  * allwinner,sun8i-a33-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 6850fcd..5060257 100644
--- a/drivers/phy/phy-sun4i-usb.c
+++ b/drivers/phy/phy-sun4i-usb.c
@@ -40,9 +40,10 @@
 #include 
 
 #define REG_ISCR   0x00
-#define REG_PHYCTL 0x04
+#define REG_PHYCTL_A10 0x04
 #define REG_PHYBIST0x08
 #define REG_PHYTUNE0x0c
+#define REG_PHYCTL_A33 0x10
 
 #define PHYCTL_DATABIT(7)
 
@@ -90,6 +91,7 @@ struct sun4i_usb_phy_data {
struct mutex mutex;
int num_phys;
u32 disc_thresh;
+   bool has_a33_phyctl;
struct sun4i_usb_phy {
struct phy *phy;
void __iomem *pmu;
@@ -152,37 +154,46 @@ static void sun4i_usb_phy_write(struct sun4i_usb_phy 
*phy, u32 addr, u32 data,
 {
struct sun4i_usb_phy_data *phy_data = to_sun4i_usb_phy_data(phy);
u32 temp, usbc_bit = BIT(phy->index * 2);
+   void *phyctl;
int i;
 
mutex_lock(&phy_data->mutex);
 
+   if (phy_data->has_a33_phyctl) {
+   phyctl = phy_data->base + REG_PHYCTL_A33;
+   /* A33 needs us to set phyctl to 0 explictly */
+   writel(0, phyctl);
+   } else {
+   phyctl = phy_data->base + REG_PHYCTL_A10;
+   }
+
for (i = 0; i < len; i++) {
-   temp = readl(phy_data->base + REG_PHYCTL);
+   temp = readl(phyctl);
 
/* clear the address portion */
temp &= ~(0xff << 8);
 
/* set the address */
temp |= ((addr + i) << 8);
-   writel(temp, phy_data->base + REG_PHYCTL);
+   writel(temp, phyctl);
 
/* set the data bit and clear usbc bit*/
-   temp = readb(phy_data->base + REG_PHYCTL);
+   temp = readb(phyctl);
if (data & 0x1)
temp |= PHYCTL_DATA;
else
temp &= ~PHYCTL_DATA;
temp &= ~usbc_bit;
-   writeb(temp, phy_data->base + REG_PHYCTL);
+   writeb(temp, phyctl);
 
/* pulse usbc_bit */
-   temp = readb(phy_data->base + REG_PHYCTL);
+   temp = readb(phyctl);
temp |= usbc_bit;
-   writeb(temp, phy_data->base + REG_PHYCTL);
+   writeb(temp, phyctl);
 
-   temp = readb(phy_data->base + REG_PHYCTL);
+   temp = readb(phyctl);
temp &= ~usbc_bit;
-   writeb(temp, phy_data->base + REG_PHYCTL);
+   writeb(temp, phyctl);
 
data >>= 1;
}
@@ -443,7 +454,8 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
dev_set_drvdata(dev, data);
 
if (of_device_is_compatible(np, "allwinner,sun5i-a13-usb-phy") ||
-   of_device_is_compatible(np, "allwinner,sun8i-a23-usb-phy"))
+   of_device_is_compatible(np, "allwinner,sun8i-a23-usb-phy") ||
+   of_device_is_compatible(np, "allwinner,sun8i-a33-usb-phy"))
data->num_phys = 2;
else
data->num_phys = 3;
@@ -455,11 +467,15 @@ static int sun4i_usb_phy_probe(struct platform_device 
*pdev)
data->disc_thresh = 3;
 
if (of_device_is_compatible(np, "allwinner,sun6i-a31-usb-phy") ||
-   of_device_is_compatible(np, "allwinner,sun8i-a23-usb-phy"))
+   of_device_is_compatible(np, "allwinner,sun8i-a23-usb-phy") ||
+   of_device_is_compatible(np, "allwinner,sun8i-a33-usb-phy"))
dedicated_clocks = true;
else
dedicated_clocks = false;
 
+   if (of_device_is_compatible(np, "allwinner,sun8i-a33-usb-phy"))
+   data->has_a33_phyctl = true;
+
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phy_ctrl");
data->base = devm_ioremap_resource(dev, res);
if (IS_ERR(data->base))
@@ -591,6 +607,7 @@ static const 

[PATCH v5 2/7] phy-sun4i-usb: Add extcon support for the otg phy (phy0)

2015-06-13 Thread Hans de Goede
The sunxi musb glue needs to know if a host or normal usb cable is plugged
in, add extcon support so that the musb glue can monitor the host status.

Signed-off-by: Hans de Goede 
---
Changes in v5:
-Split out of the "Add id and vbus detection support" commit
-Ported to the new extcon API queued for 4.2
---
 drivers/phy/Kconfig |  1 +
 drivers/phy/phy-sun4i-usb.c | 32 +++-
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index a53bd5b..9841780 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -173,6 +173,7 @@ config PHY_SUN4I_USB
tristate "Allwinner sunxi SoC USB PHY driver"
depends on ARCH_SUNXI && HAS_IOMEM && OF
depends on RESET_CONTROLLER
+   depends on EXTCON
select GENERIC_PHY
help
  Enable this to support the transceiver that is part of Allwinner
diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
index bdf63ad..86d9ce1 100644
--- a/drivers/phy/phy-sun4i-usb.c
+++ b/drivers/phy/phy-sun4i-usb.c
@@ -23,6 +23,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -99,6 +100,7 @@ struct sun4i_usb_phy_data {
int index;
} phys[MAX_PHYS];
/* phy0 / otg related variables */
+   struct extcon_dev *extcon;
bool phy0_init;
bool phy0_poll;
struct gpio_desc *id_det_gpio;
@@ -343,7 +345,7 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct 
work_struct *work)
struct sun4i_usb_phy_data *data =
container_of(work, struct sun4i_usb_phy_data, detect.work);
struct phy *phy0 = data->phys[0].phy;
-   int id_det, vbus_det;
+   int id_det, vbus_det, id_notify = 0, vbus_notify = 0;
 
id_det = gpiod_get_value_cansleep(data->id_det_gpio);
vbus_det = gpiod_get_value_cansleep(data->vbus_det_gpio);
@@ -358,15 +360,24 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct 
work_struct *work)
if (id_det != data->id_det) {
sun4i_usb_phy0_set_id_detect(phy0, id_det);
data->id_det = id_det;
+   id_notify = 1;
}
 
if (vbus_det != data->vbus_det) {
sun4i_usb_phy0_set_vbus_detect(phy0, vbus_det);
data->vbus_det = vbus_det;
+   vbus_notify = 1;
}
 
mutex_unlock(&phy0->mutex);
 
+   if (id_notify)
+   extcon_set_cable_state_(data->extcon, EXTCON_USB_HOST,
+   !id_det);
+
+   if (vbus_notify)
+   extcon_set_cable_state_(data->extcon, EXTCON_USB, vbus_det);
+
if (data->phy0_poll)
queue_delayed_work(system_wq, &data->detect, POLL_TIME);
 }
@@ -407,6 +418,12 @@ static int sun4i_usb_phy_remove(struct platform_device 
*pdev)
return 0;
 }
 
+static const unsigned int sun4i_usb_phy0_cable[] = {
+   EXTCON_USB,
+   EXTCON_USB_HOST,
+   EXTCON_NONE,
+};
+
 static int sun4i_usb_phy_probe(struct platform_device *pdev)
 {
struct sun4i_usb_phy_data *data;
@@ -466,6 +483,19 @@ static int sun4i_usb_phy_probe(struct platform_device 
*pdev)
return -ENODEV;
}
 
+   if (data->id_det_gpio) {
+   data->extcon = devm_extcon_dev_allocate(dev,
+   sun4i_usb_phy0_cable);
+   if (IS_ERR(data->extcon))
+   return PTR_ERR(data->extcon);
+
+   ret = devm_extcon_dev_register(dev, data->extcon);
+   if (ret) {
+   dev_err(dev, "failed to register extcon: %d\n", ret);
+   return ret;
+   }
+   }
+
for (i = 0; i < data->num_phys; i++) {
struct sun4i_usb_phy *phy = data->phys + i;
char name[16];
-- 
2.4.3

--
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 v5 6/7] phy-sun4i-usb: Add support for boards with broken Vusb-detection

2015-06-13 Thread Hans de Goede
On some boards we cannot detect the presence of an external Vusb, because
e.g. the 5V of the otg connector is directly connected to the 5V of the board,
and thus is always high.

This commit adds support for using such boards by only looking at the
id-detection pin.

Signed-off-by: Hans de Goede 
---
 drivers/phy/phy-sun4i-usb.c | 44 
 1 file changed, 36 insertions(+), 8 deletions(-)

diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
index 5060257..0681641 100644
--- a/drivers/phy/phy-sun4i-usb.c
+++ b/drivers/phy/phy-sun4i-usb.c
@@ -22,6 +22,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -309,7 +310,7 @@ static int sun4i_usb_phy_power_on(struct phy *_phy)
phy->regulator_on = true;
 
/* We must report Vbus high within OTG_TIME_A_WAIT_VRISE msec. */
-   if (phy->index == 0 && data->phy0_poll)
+   if (phy->index == 0 && data->vbus_det_gpio && data->phy0_poll)
mod_delayed_work(system_wq, &data->detect, DEBOUNCE_TIME);
 
return 0;
@@ -330,7 +331,7 @@ static int sun4i_usb_phy_power_off(struct phy *_phy)
 * phy0 vbus typically slowly discharges, sometimes this causes the
 * Vbus gpio to not trigger an edge irq on Vbus off, so force a rescan.
 */
-   if (phy->index == 0 && !data->phy0_poll)
+   if (phy->index == 0 && data->vbus_det_gpio && !data->phy0_poll)
mod_delayed_work(system_wq, &data->detect, POLL_TIME);
 
return 0;
@@ -359,7 +360,10 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct 
work_struct *work)
int id_det, vbus_det, id_notify = 0, vbus_notify = 0;
 
id_det = gpiod_get_value_cansleep(data->id_det_gpio);
-   vbus_det = gpiod_get_value_cansleep(data->vbus_det_gpio);
+   if (data->vbus_det_gpio)
+   vbus_det = gpiod_get_value_cansleep(data->vbus_det_gpio);
+   else
+   vbus_det = 1; /* Report vbus as high */
 
mutex_lock(&phy0->mutex);
 
@@ -369,6 +373,16 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct 
work_struct *work)
}
 
if (id_det != data->id_det) {
+   /*
+* When a host cable (id == 0) gets plugged in on systems
+* without vbus detection report vbus low for long enough for
+* the musb-ip to end the current device session.
+*/
+   if (!data->vbus_det_gpio && id_det == 0) {
+   sun4i_usb_phy0_set_vbus_detect(phy0, 0);
+   msleep(200);
+   sun4i_usb_phy0_set_vbus_detect(phy0, 1);
+   }
sun4i_usb_phy0_set_id_detect(phy0, id_det);
data->id_det = id_det;
id_notify = 1;
@@ -382,9 +396,22 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct 
work_struct *work)
 
mutex_unlock(&phy0->mutex);
 
-   if (id_notify)
+   if (id_notify) {
extcon_set_cable_state_(data->extcon, EXTCON_USB_HOST,
!id_det);
+   /*
+* When a host cable gets unplugged (id == 1) on systems
+* without vbus detection report vbus low for long enough to
+* the musb-ip to end the current host session.
+*/
+   if (!data->vbus_det_gpio && id_det == 1) {
+   mutex_lock(&phy0->mutex);
+   sun4i_usb_phy0_set_vbus_detect(phy0, 0);
+   msleep(1000);
+   sun4i_usb_phy0_set_vbus_detect(phy0, 1);
+   mutex_unlock(&phy0->mutex);
+   }
+   }
 
if (vbus_notify)
extcon_set_cable_state_(data->extcon, EXTCON_USB, vbus_det);
@@ -495,9 +522,9 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
data->vbus_det_gpio = NULL;
}
 
-   /* We either want both gpio pins or neither (when in host mode) */
-   if (!data->id_det_gpio != !data->vbus_det_gpio) {
-   dev_err(dev, "failed to get id or vbus detect pin\n");
+   /* vbus_det without id_det makes no sense, and is not supported */
+   if (data->vbus_det_gpio && !data->id_det_gpio) {
+   dev_err(dev, "usb0_id_det missing or invalid\n");
return -ENODEV;
}
 
@@ -565,7 +592,8 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
 
data->id_det_irq = gpiod_to_irq(data->id_det_gpio);
data->vbus_det_irq = gpiod_to_irq(data->vbus_det_gpio);
-   if (data->id_det_irq  < 0 || data->vbus_det_irq < 0)
+   if ((data->id_det_gpio && data->id_det_irq < 0) ||
+   (data->vbus_det_gpio && data->vbus_det_irq < 0))
data->phy0_poll = true;
 
if (data->id_det_irq >= 0) {
-- 
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.

[PATCH v5 4/7] phy-sun4i-usb: Add support for the usb-phys on the sun8i-a23 SoC

2015-06-13 Thread Hans de Goede
The usb-phys on the sun8i-a23 SoC have the same setup wrt clocks as on the
sun6i-a31 SoC, but there are only 2 instead of 3 like on the sun5i-a13 SoC.

Signed-off-by: Hans de Goede 
---
 Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt | 2 ++
 drivers/phy/phy-sun4i-usb.c | 7 +--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt 
b/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
index 557fa99..f0c640a 100644
--- a/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
+++ b/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
@@ -7,6 +7,7 @@ Required properties:
   * allwinner,sun5i-a13-usb-phy
   * allwinner,sun6i-a31-usb-phy
   * allwinner,sun7i-a20-usb-phy
+  * allwinner,sun8i-a23-usb-phy
 - reg : a list of offset + length pairs
 - reg-names :
   * "phy_ctrl"
@@ -17,6 +18,7 @@ Required properties:
 - clock-names :
   * "usb_phy" for sun4i, sun5i or sun7i
   * "usb0_phy", "usb1_phy" and "usb2_phy" for sun6i
+  * "usb0_phy", "usb1_phy" for sun8i
 - resets : a list of phandle + reset specifier pairs
 - reset-names :
   * "usb0_reset"
diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
index d78a071..6850fcd 100644
--- a/drivers/phy/phy-sun4i-usb.c
+++ b/drivers/phy/phy-sun4i-usb.c
@@ -442,7 +442,8 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
INIT_DELAYED_WORK(&data->detect, sun4i_usb_phy0_id_vbus_det_scan);
dev_set_drvdata(dev, data);
 
-   if (of_device_is_compatible(np, "allwinner,sun5i-a13-usb-phy"))
+   if (of_device_is_compatible(np, "allwinner,sun5i-a13-usb-phy") ||
+   of_device_is_compatible(np, "allwinner,sun8i-a23-usb-phy"))
data->num_phys = 2;
else
data->num_phys = 3;
@@ -453,7 +454,8 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
else
data->disc_thresh = 3;
 
-   if (of_device_is_compatible(np, "allwinner,sun6i-a31-usb-phy"))
+   if (of_device_is_compatible(np, "allwinner,sun6i-a31-usb-phy") ||
+   of_device_is_compatible(np, "allwinner,sun8i-a23-usb-phy"))
dedicated_clocks = true;
else
dedicated_clocks = false;
@@ -588,6 +590,7 @@ static const struct of_device_id sun4i_usb_phy_of_match[] = 
{
{ .compatible = "allwinner,sun5i-a13-usb-phy" },
{ .compatible = "allwinner,sun6i-a31-usb-phy" },
{ .compatible = "allwinner,sun7i-a20-usb-phy" },
+   { .compatible = "allwinner,sun8i-a23-usb-phy" },
{ },
 };
 MODULE_DEVICE_TABLE(of, sun4i_usb_phy_of_match);
-- 
2.4.3

--
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 v5 7/7] phy-sun4i-usb: Add support for monitoring vbus via a power-supply

2015-06-13 Thread Hans de Goede
On some boards there is no vbus_det gpio pin, instead vbus-detection for
otg can be done via the pmic.

This commit adds support for monitoring vbus_det via the power_supply
exported by the pmic, enabling support for otg on these boards.

Signed-off-by: Hans de Goede 
---
 .../devicetree/bindings/phy/sun4i-usb-phy.txt  |  1 +
 drivers/phy/Kconfig|  1 +
 drivers/phy/phy-sun4i-usb.c| 76 --
 3 files changed, 71 insertions(+), 7 deletions(-)

diff --git a/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt 
b/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
index 5f48979..0cebf74 100644
--- a/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
+++ b/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
@@ -29,6 +29,7 @@ Required properties:
 Optional properties:
 - usb0_id_det-gpios : gpio phandle for reading the otg id pin value
 - usb0_vbus_det-gpios : gpio phandle for detecting the presence of usb0 vbus
+- usb0_vbus_power-supply: power-supply phandle for usb0 vbus presence detect
 - usb0_vbus-supply : regulator phandle for controller usb0 vbus
 - usb1_vbus-supply : regulator phandle for controller usb1 vbus
 - usb2_vbus-supply : regulator phandle for controller usb2 vbus
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 9841780..4e71765 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -174,6 +174,7 @@ config PHY_SUN4I_USB
depends on ARCH_SUNXI && HAS_IOMEM && OF
depends on RESET_CONTROLLER
depends on EXTCON
+   depends on POWER_SUPPLY
select GENERIC_PHY
help
  Enable this to support the transceiver that is part of Allwinner
diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
index 0681641..1010519 100644
--- a/drivers/phy/phy-sun4i-usb.c
+++ b/drivers/phy/phy-sun4i-usb.c
@@ -36,6 +36,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -108,6 +109,9 @@ struct sun4i_usb_phy_data {
bool phy0_poll;
struct gpio_desc *id_det_gpio;
struct gpio_desc *vbus_det_gpio;
+   struct power_supply *vbus_power_supply;
+   struct notifier_block vbus_power_nb;
+   bool vbus_power_nb_registered;
int id_det_irq;
int vbus_det_irq;
int id_det;
@@ -352,6 +356,30 @@ static struct phy_ops sun4i_usb_phy_ops = {
.owner  = THIS_MODULE,
 };
 
+static int sun4i_usb_phy0_get_vbus_det(struct sun4i_usb_phy_data *data)
+{
+   if (data->vbus_det_gpio)
+   return gpiod_get_value_cansleep(data->vbus_det_gpio);
+
+   if (data->vbus_power_supply) {
+   union power_supply_propval val;
+   int r;
+
+   r = power_supply_get_property(data->vbus_power_supply,
+ POWER_SUPPLY_PROP_PRESENT, &val);
+   if (r == 0)
+   return val.intval;
+   }
+
+   /* Fallback: report vbus as high */
+   return 1;
+}
+
+static bool sun4i_usb_phy0_have_vbus_det(struct sun4i_usb_phy_data *data)
+{
+   return data->vbus_det_gpio || data->vbus_power_supply;
+}
+
 static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
 {
struct sun4i_usb_phy_data *data =
@@ -360,10 +388,7 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct 
work_struct *work)
int id_det, vbus_det, id_notify = 0, vbus_notify = 0;
 
id_det = gpiod_get_value_cansleep(data->id_det_gpio);
-   if (data->vbus_det_gpio)
-   vbus_det = gpiod_get_value_cansleep(data->vbus_det_gpio);
-   else
-   vbus_det = 1; /* Report vbus as high */
+   vbus_det = sun4i_usb_phy0_get_vbus_det(data);
 
mutex_lock(&phy0->mutex);
 
@@ -378,7 +403,7 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct 
work_struct *work)
 * without vbus detection report vbus low for long enough for
 * the musb-ip to end the current device session.
 */
-   if (!data->vbus_det_gpio && id_det == 0) {
+   if (!sun4i_usb_phy0_have_vbus_det(data) && id_det == 0) {
sun4i_usb_phy0_set_vbus_detect(phy0, 0);
msleep(200);
sun4i_usb_phy0_set_vbus_detect(phy0, 1);
@@ -404,7 +429,7 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct 
work_struct *work)
 * without vbus detection report vbus low for long enough to
 * the musb-ip to end the current host session.
 */
-   if (!data->vbus_det_gpio && id_det == 1) {
+   if (!sun4i_usb_phy0_have_vbus_det(data) && id_det == 1) {
mutex_lock(&phy0->mutex);
sun4i_usb_phy0_set_vbus_detect(phy0, 0);
msleep(1000);
@@ -430,6 +455,20 @@ static irqreturn_t sun4i_usb_phy0_id_vbus_det_irq(int irq, 
void *dev_id)
return IRQ_

[PATCH v5 0/3] musb: sunxi: Add support for the Allwinner sunxi musb

2015-06-13 Thread Hans de Goede
Hi Felipe,

Here is a patch series with all my oustanding musb-sunxi changes pending
for merging into 4.3.

This includes the 5th iteration of the patch for adding the basic sunxi-glue,
the major change in v5 is that it has been ported to the extcon API changes
which are queued up for 4.2 from :

http://git.kernel.org/cgit/linux/kernel/git/chanwoo/extcon.git/log/?h=extcon-ne

which already merged in GKH's char-misc branch for 4.2, this means that
this series now depends on those changes.

Besides that I've also squashed in a fix I send out recently which removes
the need for the special MUSB_SUN4I flag + core changes checking for that
flag which my original version has. Meaning that the changes are nowly
soley confined to the addition of drivers/usb/musb/sunxi.c + matching
Kconfig / Makefile changes.

Other than that this is a resend of some of the other feature addition
patches I recently send rebased on top of v5 of the musb sunxi glue.

Please merge this series for 4.3.

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 v5 1/3] musb: sunxi: Add support for the Allwinner sunxi musb controller

2015-06-13 Thread Hans de Goede
This is based on initial code to get the Allwinner sunxi musb controller
supported by Chen-Yu Tsai and Roman Byshko.

This adds support for the Allwinner sunxi musb controller in both host only
and otg mode. Peripheral only mode is not supported, as no boards use that.

This has been tested on a cubietruck (A20 SoC) and an UTOO P66 tablet
(A13 SoC) with a variety of devices in host mode and with the g_serial gadget
driver in peripheral mode, plugging otg / host cables in/out a lot of times
in all possible imaginable plug orders.

Signed-off-by: Hans de Goede 
---
Changes in v2:
-Move polling of id and vbus-det gpio-s to the phy driver
-Use extcon to get id (USB_HOST mode) status changes from the phy driver
-Stop using syscon, instead use Maxime Ripard's sunxi SRAM controller driver
Changes in v3:
-Check that USB_MUSB_FOO config is compatible with the dr_mode setting from dt
Changes in v4:
-Squash in "musb: sunxi: Add pre/post root reset end platform functions" patch
-Adjust for sunxi_sram controller driver changes
-Stop musb work from turning vbus off again when in host mode
Changes in v5:
-Squash in "musb: sunxi: Remove special MUSB_SUN4I flag" patch, as it was
 mostly revering changes done by this patch
-Adjust for extcon api changes landing in 4.2
---
 .../bindings/usb/allwinner,sun4i-a10-musb.txt  |  27 +
 drivers/usb/musb/Kconfig   |  13 +-
 drivers/usb/musb/Makefile  |   1 +
 drivers/usb/musb/sunxi.c   | 703 +
 4 files changed, 743 insertions(+), 1 deletion(-)
 create mode 100644 
Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt
 create mode 100644 drivers/usb/musb/sunxi.c

diff --git a/Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt 
b/Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt
new file mode 100644
index 000..9254a6c
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt
@@ -0,0 +1,27 @@
+Allwinner sun4i A10 musb DRC/OTG controller
+---
+
+Required properties:
+ - compatible  : "allwinner,sun4i-a10-musb"
+ - reg : mmio address range of the musb controller
+ - clocks  : clock specifier for the musb controller ahb gate clock
+ - interrupts  : interrupt to which the musb controller is connected
+ - interrupt-names : must be "mc"
+ - phys: phy specifier for the otg phy
+ - phy-names   : must be "usb"
+ - dr_mode : Dual-Role mode must be "host" or "otg"
+ - extcon  : extcon specifier for the otg phy
+
+Example:
+
+   usb_otg: usb@01c13000 {
+   compatible = "allwinner,sun4i-a10-musb";
+   reg = <0x01c13000 0x0400>;
+   clocks = <&ahb_gates 0>;
+   interrupts = <38>;
+   interrupt-names = "mc";
+   phys = <&usbphy 0>;
+   phy-names = "usb";
+   extcon = <&usbphy 0>;
+   status = "disabled";
+   };
diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index 39db8b6..37081ed 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -5,7 +5,7 @@
 
 # (M)HDRC = (Multipoint) Highspeed Dual-Role Controller
 config USB_MUSB_HDRC
-   tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, ...)'
+   tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, AW, ...)'
depends on (USB || USB_GADGET)
help
  Say Y here if your system has a dual role high speed USB
@@ -20,6 +20,8 @@ config USB_MUSB_HDRC
  Analog Devices parts using this IP include Blackfin BF54x,
  BF525 and BF527.
 
+ Allwinner SoCs using this IP include A10, A13, A20, ...
+
  If you do not know what this is, please say N.
 
  To compile this driver as a module, choose M here; the
@@ -60,6 +62,15 @@ endchoice
 
 comment "Platform Glue Layer"
 
+config USB_MUSB_SUNXI
+   tristate "Allwinner (sunxi)"
+   depends on ARCH_SUNXI
+   depends on NOP_USB_XCEIV
+   depends on PHY_SUN4I_USB
+   depends on EXTCON
+   depends on GENERIC_PHY
+   select SUNXI_SRAM
+
 config USB_MUSB_DAVINCI
tristate "DaVinci"
depends on ARCH_DAVINCI_DMx
diff --git a/drivers/usb/musb/Makefile b/drivers/usb/musb/Makefile
index ba49501..f95befe 100644
--- a/drivers/usb/musb/Makefile
+++ b/drivers/usb/musb/Makefile
@@ -20,6 +20,7 @@ obj-$(CONFIG_USB_MUSB_DA8XX)  += da8xx.o
 obj-$(CONFIG_USB_MUSB_BLACKFIN)+= blackfin.o
 obj-$(CONFIG_USB_MUSB_UX500)   += ux500.o
 obj-$(CONFIG_USB_MUSB_JZ4740)  += jz4740.o
+obj-$(CONFIG_USB_MUSB_SUNXI)   += sunxi.o
 
 
 obj-$(CONFIG_USB_MUSB_AM335X_CHILD)+= musb_am335x.o
diff --git a/drivers/usb/musb/sunxi.c b/drivers/usb/musb/sunxi.c
new file mode 100644
index 000..71c1cea
--- /dev/null
+++ b/drivers/usb/mus

[PATCH v5 3/3] musb: sunxi: Add support for musb controller in A33 SoC

2015-06-13 Thread Hans de Goede
The A33 SoC uses the same musb controller as found on the A31 and later,
but allwinner has removed the configdata register, this commit adds special
handling for this.

Signed-off-by: Hans de Goede 
---
 .../devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt  |  3 ++-
 drivers/usb/musb/sunxi.c  | 15 +++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt 
b/Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt
index fde180b..862cd7c 100644
--- a/Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt
+++ b/Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt
@@ -2,7 +2,8 @@ Allwinner sun4i A10 musb DRC/OTG controller
 ---
 
 Required properties:
- - compatible  : "allwinner,sun4i-a10-musb" or "allwinner,sun6i-a31-musb"
+ - compatible  : "allwinner,sun4i-a10-musb", "allwinner,sun6i-a31-musb"
+ or "allwinner,sun8i-a33-musb"
  - reg : mmio address range of the musb controller
  - clocks  : clock specifier for the musb controller ahb gate clock
  - reset   : reset specifier for the ahb reset (A31 and newer only)
diff --git a/drivers/usb/musb/sunxi.c b/drivers/usb/musb/sunxi.c
index 825bc41..0e24292 100644
--- a/drivers/usb/musb/sunxi.c
+++ b/drivers/usb/musb/sunxi.c
@@ -73,6 +73,7 @@
 #define SUNXI_MUSB_FL_PHY_ON   4
 #define SUNXI_MUSB_FL_HAS_SRAM 5
 #define SUNXI_MUSB_FL_HAS_RESET6
+#define SUNXI_MUSB_FL_NO_CONFIGDATA7
 
 /* Our read/write methods need access and do not get passed in a musb ref :| */
 struct musb *sunxi_musb;
@@ -370,6 +371,8 @@ static u32 sunxi_musb_busctl_offset(u8 epnum, u16 offset)
 
 static u8 sunxi_musb_readb(const void __iomem *addr, unsigned offset)
 {
+   struct sunxi_glue *glue;
+
if (addr == sunxi_musb->mregs) {
/* generic control or fifo control reg access */
switch (offset) {
@@ -392,6 +395,12 @@ static u8 sunxi_musb_readb(const void __iomem *addr, 
unsigned offset)
case MUSB_RXFIFOSZ:
return readb(addr + SUNXI_MUSB_RXFIFOSZ);
case MUSB_CONFIGDATA + 0x10: /* See musb_read_configdata() */
+   glue = dev_get_drvdata(sunxi_musb->controller->parent);
+   /* A33 saves a reg, and we get to hardcode this */
+   if (test_bit(SUNXI_MUSB_FL_NO_CONFIGDATA,
+&glue->flags))
+   return 0xde;
+
return readb(addr + SUNXI_MUSB_CONFIGDATA);
/* Offset for these is fixed by sunxi_musb_busctl_offset() */
case SUNXI_MUSB_TXFUNCADDR:
@@ -643,6 +652,11 @@ static int sunxi_musb_probe(struct platform_device *pdev)
if (of_device_is_compatible(np, "allwinner,sun6i-a31-musb"))
set_bit(SUNXI_MUSB_FL_HAS_RESET, &glue->flags);
 
+   if (of_device_is_compatible(np, "allwinner,sun8i-a33-musb")) {
+   set_bit(SUNXI_MUSB_FL_HAS_RESET, &glue->flags);
+   set_bit(SUNXI_MUSB_FL_NO_CONFIGDATA, &glue->flags);
+   }
+
glue->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(glue->clk)) {
dev_err(&pdev->dev, "Error getting clock: %ld\n",
@@ -723,6 +737,7 @@ static int sunxi_musb_remove(struct platform_device *pdev)
 static const struct of_device_id sunxi_musb_match[] = {
{ .compatible = "allwinner,sun4i-a10-musb", },
{ .compatible = "allwinner,sun6i-a31-musb", },
+   { .compatible = "allwinner,sun8i-a33-musb", },
{}
 };
 
-- 
2.4.3

--
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 v5 2/3] musb: sunxi: Add support for musb controller in A31 SoC

2015-06-13 Thread Hans de Goede
The A31 SoC uses the same musb controller as found in earlier SoCs, but it
is hooked up slightly different. Its SRAM is private and no longer controlled
through the SRAM controller, and its reset is controlled via a separate
reset controller. This commit adds support for this setup.

Signed-off-by: Hans de Goede 
---
 .../bindings/usb/allwinner,sun4i-a10-musb.txt  |  3 +-
 drivers/usb/musb/sunxi.c   | 50 +++---
 2 files changed, 46 insertions(+), 7 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt 
b/Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt
index 9254a6c..fde180b 100644
--- a/Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt
+++ b/Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt
@@ -2,9 +2,10 @@ Allwinner sun4i A10 musb DRC/OTG controller
 ---
 
 Required properties:
- - compatible  : "allwinner,sun4i-a10-musb"
+ - compatible  : "allwinner,sun4i-a10-musb" or "allwinner,sun6i-a31-musb"
  - reg : mmio address range of the musb controller
  - clocks  : clock specifier for the musb controller ahb gate clock
+ - reset   : reset specifier for the ahb reset (A31 and newer only)
  - interrupts  : interrupt to which the musb controller is connected
  - interrupt-names : must be "mc"
  - phys: phy specifier for the otg phy
diff --git a/drivers/usb/musb/sunxi.c b/drivers/usb/musb/sunxi.c
index 71c1cea..825bc41 100644
--- a/drivers/usb/musb/sunxi.c
+++ b/drivers/usb/musb/sunxi.c
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -70,6 +71,8 @@
 #define SUNXI_MUSB_FL_HOSTMODE_PEND2
 #define SUNXI_MUSB_FL_VBUS_ON  3
 #define SUNXI_MUSB_FL_PHY_ON   4
+#define SUNXI_MUSB_FL_HAS_SRAM 5
+#define SUNXI_MUSB_FL_HAS_RESET6
 
 /* Our read/write methods need access and do not get passed in a musb ref :| */
 struct musb *sunxi_musb;
@@ -78,6 +81,7 @@ struct sunxi_glue {
struct device   *dev;
struct platform_device  *musb;
struct clk  *clk;
+   struct reset_control*rst;
struct phy  *phy;
struct platform_device  *usb_phy;
struct usb_phy  *xceiv;
@@ -229,14 +233,22 @@ static int sunxi_musb_init(struct musb *musb)
musb->phy = glue->phy;
musb->xceiv = glue->xceiv;
 
-   ret = sunxi_sram_claim(musb->controller->parent);
-   if (ret)
-   return ret;
+   if (test_bit(SUNXI_MUSB_FL_HAS_SRAM, &glue->flags)) {
+   ret = sunxi_sram_claim(musb->controller->parent);
+   if (ret)
+   return ret;
+   }
 
ret = clk_prepare_enable(glue->clk);
if (ret)
goto error_sram_release;
 
+   if (test_bit(SUNXI_MUSB_FL_HAS_RESET, &glue->flags)) {
+   ret = reset_control_deassert(glue->rst);
+   if (ret)
+   goto error_clk_disable;
+   }
+
writeb(SUNXI_MUSB_VEND0_PIO_MODE, musb->mregs + SUNXI_MUSB_VEND0);
 
/* Register notifier before calling phy_init() */
@@ -244,7 +256,7 @@ static int sunxi_musb_init(struct musb *musb)
ret = extcon_register_notifier(glue->extcon, EXTCON_USB_HOST,
   &glue->host_nb);
if (ret)
-   goto error_clk_disable;
+   goto error_reset_assert;
}
 
ret = phy_init(glue->phy);
@@ -273,10 +285,14 @@ error_unregister_notifier:
if (musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE)
extcon_unregister_notifier(glue->extcon, EXTCON_USB_HOST,
   &glue->host_nb);
+error_reset_assert:
+   if (test_bit(SUNXI_MUSB_FL_HAS_RESET, &glue->flags))
+   reset_control_assert(glue->rst);
 error_clk_disable:
clk_disable_unprepare(glue->clk);
 error_sram_release:
-   sunxi_sram_release(musb->controller->parent);
+   if (test_bit(SUNXI_MUSB_FL_HAS_SRAM, &glue->flags))
+   sunxi_sram_release(musb->controller->parent);
return ret;
 }
 
@@ -296,8 +312,12 @@ static int sunxi_musb_exit(struct musb *musb)
extcon_unregister_notifier(glue->extcon, EXTCON_USB_HOST,
   &glue->host_nb);
 
+   if (test_bit(SUNXI_MUSB_FL_HAS_RESET, &glue->flags))
+   reset_control_assert(glue->rst);
+
clk_disable_unprepare(glue->clk);
-   sunxi_sram_release(musb->controller->parent);
+   if (test_bit(SUNXI_MUSB_FL_HAS_SRAM, &glue->flags))
+   sunxi_sram_release(musb->controller->parent);
 
return 0;
 }
@@ -617,6 +637,12 @@ static int sunxi_musb_probe(struct platform_device *pdev)
INIT_WORK(&glue->

Re: [PATCH v2 6/5] usb: Add usb interface authorization: second SysFS part for usb interface authorization attribute.

2015-06-13 Thread Sergei Shtylyov

Hello.

On 6/13/2015 12:28 AM, Stefan Koch wrote:


To allow (1) or deny (0) interfaces a mask or interface attributes could 
written.


   "Could be written", perhaps?


For interfaces that belongs together use the mask for authorization.


   Belong.


As default each bit has the initial value of the default authorization bit.
Entry: /sys/bus/usb/devices/*-*:*.*/interface_authorized



Signed-off-by: Stefan Koch 
---
  drivers/usb/core/sysfs.c | 55 
  1 file changed, 55 insertions(+)



diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index afa0799e..54e2e8e 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -995,6 +995,60 @@ static ssize_t supports_autosuspend_show(struct device 
*dev,
  }
  static DEVICE_ATTR_RO(supports_autosuspend);

+/*
+ * show authorization status of usb interface


   USB.

[...]

+/*
+ * authorize or deauthorize an usb interface


   USB.


+ * 1 is to authorize, 0 is to deauthorize
+ */
+static ssize_t interface_authorized_store(struct device *dev,
+   struct device_attribute *attr, const char *buf, size_t count)
+{
+   struct usb_interface *intf = to_usb_interface(dev);
+   struct usb_device *usb_pdev = NULL;
+   int rc = 0;
+   unsigned val = 0;
+   unsigned intf_nr = 0;


   No need for these initializers.


+   u32 mask = 0;
+
+   if (!dev->parent || !intf || !intf->cur_altsetting)
+   return -ENODEV;
+
+   usb_pdev = to_usb_device(dev->parent);
+


   No need for this empty line.


+   if (!usb_pdev)
+   return -ENODEV;
+
+   mask = usb_pdev->mask;
+   intf_nr = intf->cur_altsetting->desc.bInterfaceNumber;
+
+   if (sscanf(buf, "%u\n", &val) != 1)
+   return -EINVAL;
+
+   if (val == 0)
+   mask &= ~(1 << intf_nr);
+   else if (val == 1)
+   mask |= (1 << intf_nr);


   Parens not needed here.
   These *if* statements ask to be a *switch* statement instead.


+
+   rc = usb_device_set_mask(dev->parent, mask);
+
+   return rc < 0 ? rc : count;
+}
+static DEVICE_ATTR_RW(interface_authorized);
+

[...]

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


Re: [PATCH v2 0/5] usb: Add usb interface authorization

2015-06-13 Thread Alan Stern
On Fri, 12 Jun 2015, Stefan Koch wrote:

> Am Freitag, den 12.06.2015, 16:34 -0400 schrieb Alan Stern:
> > On Fri, 12 Jun 2015, Stefan Koch wrote:
> > 
> > > Am Freitag, den 12.06.2015, 14:09 -0400 schrieb Alan Stern:
> > > > On Fri, 12 Jun 2015, Stefan Koch wrote:
> > > > There is a lot of questionable material here.
> > > > 
> > > > First of all, I agree with Krzysztof that having an "authorized"  
> > > > attribute in each interface's sysfs directory would be simpler and 
> > > > easier to use than having a bitmask of all authorized interfaces.
> > > OK I can provide a patch for it. But note that the mask allows to enable
> > > multiple interfaces at once. And the mechanism does enable all
> > > (multiple) interfaces first and then does start the driver probing for
> > > all interfaces. This mechanism is not possible without a mask.
> > 
> > You could probe all the interfaces whenever any interface is
> > authorized.  Or there could be a separate mechanism to initiate
> > probing.
> > 
> Does this affect any running communication with the interface?

Of course it does.  If you de-authorize an interface while it is being 
used, what do you expect will happen?

Maybe you're asking what happens if an interface is probed while it is 
in use?  Nothing will happen.  Probing skips devices that already have 
a driver.

> I'll send a simple patch. So in the one case the mask could used and in
> the other case the interface attribute.

It's dumb to add two different mechanisms that do the same thing.  
Just add the interface attribute and not the mask.

And call the attribute "authorize", not "interface_authorize".  It will
be obvious that the attribute applies to the interface, because the
attribute file will be inside the interface's sysfs directory.

> > How about calling device_attach() instead?
> bus_probe_device() checks the autoprobe status... Otherwise a getter for
> the autoprobe status must implemented...

Actually, this isn't necessary at all.  After updating all the
"authorize" attributes, the user can simply write the interface names
to /sys/bus/usb/drivers_probe.  This has the advantages of using a mask 
without the disadvantages.

> > I don't understand.  If you want to make sure the mask is set 
> > correctly, you need to check the mask's _current_ value.  You don't 
> > care whether the mask has been changed from its _initial_ value.
> If you connect a device to an usb port udev runs for the device and all
> interfaces.
> 
> If you change a configuration per hand udev runs only for interfaces,
> not for the device.
> 
> So if you want to avoid to set the device's mask multiple times a status
> bit helps.

I still don't understand.  If you want to avoid setting the device's 
mask multiple times, all you have to do is check the current mask value 
before trying to change it.  If the current value is already equal to 
the new value, you don't need to change the mask.

Besides, this will be irrelevant if you implement "authorized"  
attributes rather than a mask.

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 v2 1/1] usb: core: lpm: set lpm_capable for root hub device

2015-06-13 Thread Alan Stern
On Sat, 13 Jun 2015, Lu Baolu wrote:

> Commit 25cd2882e2fc ("usb/xhci: Change how we indicate a host supports
> Link PM.") removed the code to set lpm_capable for USB 3.0 super-speed
> root hub. The intention of that change was to avoid touching usb core
> internal field, a.k.a. lpm_capable, and let usb core to set it by
> checking U1 and U2 exit latency values in the descriptor.
> 
> Usb core checks and sets lpm_capable in hub_port_init(). Unfortunately,
> root hub is a special usb device as it has no parent. Hub_port_init()
> will never be called for a root hub device. That means lpm_capable will
> by no means be set for the root hub. As the result, lpm isn't functional
> at all in Linux kernel.
> 
> This patch add the code to check and set lpm_capable when registering a
> root hub device. It could be back-ported to kernels as old as v3.15,
> that contains the Commit 25cd2882e2fc ("usb/xhci: Change how we indicate
> a host supports Link PM.").
> 
> Cc: sta...@vger.kernel.org # 3.15
> Reported-by: Kevin Strasser 
> Signed-off-by: Lu Baolu 
> ---

> --- a/drivers/usb/core/usb.h
> +++ b/drivers/usb/core/usb.h
> @@ -82,6 +82,7 @@ extern int usb_runtime_suspend(struct device *dev);
>  extern int usb_runtime_resume(struct device *dev);
>  extern int usb_runtime_idle(struct device *dev);
>  extern int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable);
> +extern int usb_device_supports_lpm(struct usb_device *udev);
>  
>  #else
>  
> @@ -106,6 +107,11 @@ static inline int usb_set_usb2_hardware_lpm(struct 
> usb_device *udev, int enable)
>   return 0;
>  }
>  
> +static inline int usb_device_supports_lpm(struct usb_device *udev)
> +{
> + return 0;
> +}
> +
>  #endif
>  
>  extern struct bus_type usb_bus_type;

In fact, usb_device_supports_lpm() is compiled even when CONFIG_PM
isn't set.  Maybe this should be changed.  But if you don't want to
change it now, you need to put the declaration outside the "#ifdef
CONFIG_PM" region.  As it is, your patch is still broken (did you try 
building it with CONFIG_PM unset?).

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: phy: phy-mxs-usb: suspend to RAM causes NULL pointer dereference

2015-06-13 Thread Stefan Wahren
Hi,

triggering suspend to RAM via sysfs on a i.MX28 causes a NULL pointer
dereference. This
regression seems to be introduced with commit efdbd3a5d6e
("usb: phy: mxs: do not set PWD.RXPWD1PT1 for low speed connection"):

root@duckbill:/sys/power# echo mem > state
[   83.677575] PM: Syncing filesystems ... done.
[   83.872011] Freezing user space processes ... (elapsed 0.006 seconds) done.
[   83.886817] Freezing remaining freezable tasks ... (elapsed 0.003 seconds)
done.
[   83.909215] Unable to handle kernel NULL pointer dereference at virtual
address 017c
[   83.917520] pgd = c6d88000
[   83.920277] [017c] *pgd=46ed9831, *pte=, *ppte=
[   83.926795] Internal error: Oops: 17 [#1] ARM
[   83.931191] Modules linked in:
[   83.934306] CPU: 0 PID: 435 Comm: bash Not tainted
4.0.0-rc4-next-20150320-gb8f4f66-dirty #163
[   83.942940] Hardware name: Freescale MXS (Device Tree)
[   83.948102] task: c4954d00 ti: c6d2 task.ti: c6d2
[   83.953544] PC is at regmap_read+0x10/0x5c
[   83.957695] LR is at mxs_phy_get_vbus_status+0x40/0x58
[   83.962865] pc : []lr : []psr: 6013
[   83.962865] sp : c6d21d20  ip : 0080  fp : 0002
[   83.974368] r10: c0340180  r9 : c07c15b0  r8 : 0002
[   83.979615] r7 : c06c6ad4  r6 :   r5 : 01c0  r4 : 
[   83.986166] r3 :   r2 : c6d21d34  r1 : 01c0  r0 : 01c0
[   83.992718] Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment user
[   83.999876] Control: 0005317f  Table: 46d88000  DAC: 0015
[   84.005644] Process bash (pid: 435, stack limit = 0xc6d20190)
[   84.011413] Stack: (0xc6d21d20 to 0xc6d22000)
[   84.015813] 1d20: c7833f10 0001  c03d8ac4 0002 c00601c8
1074 c03d8ca4
[   84.024030] 1d40: c0537268 6013 c7a6bc10 c7aea010 c7a6bc10 1074
c06c6ad4 c03d924c
[   84.032245] 1d60: c7aea010 c03d93dc c7a6bc10 c0fcf05c c07e165c c03401ac
c7a6bc10 c0348818
[   84.040459] 1d80:  c0051864 6013 c07c15d0  c7a6bc10
c0fcf05c c7a6bc10
[   84.048674] 1da0: c0fcf05c c7a6bc44 0002  c07c1564 c03494d0
c07c1590 00536bb0
[   84.056888] 1dc0: c7a6bc10 c0fcf05c  c07c1564  c0349c14
 c07e1684
[   84.065102] 1de0: 8061885f 0013 8061885f 0013  c005dec4
 0002
[   84.073316] 1e00: c0f91cc0 0003 c0f91cc0 c07e1684 c069b6d8 c069b6fc
c069b6fc c07e3d18
[   84.081529] 1e20:  c00599f8 0003   c07a275c
6013 0004
[   84.089741] 1e40: 0001     
 c07e1684
[   84.097956] 1e60: c07e1678 c069b6fc c6d2 c07e3d18  c005e178
c06e4fbc c6d21e9c
[   84.106168] 1e80: 0002 c053539c  0003  c07e1684
c069b6d8 c069b6fc
[   84.114383] 1ea0: c069b6fc c07e3d18  c005a358  0001
 c07e1468
[   84.122596] 1ec0:  c0054efc    c0165f00
 6013
[   84.130812] 1ee0: c6d8c5c0 0003 0003 c0f91cc4 0004 c6d2
c0696b14 c0058d1c
[   84.139027] 1f00: c6d15b80 0004 c6d8c5c0 c6d8c5c0 c6d15b8c c6d2
c6d21f88 c02c7b38
[   84.147240] 1f20: c6d15b80 c0166da4 c6d15b80 01f8e408 0004 c0165f74
 
[   84.155455] 1f40: 0004 c6c39120 0004 01f8e408 c6d21f88 c000f648
 c010090c
[   84.163671] 1f60: c6e17da0 c6c39120 c6c39120 c6c39120 c6c39120 0004
01f8e408 c000f648
[   84.171884] 1f80:  c0100b10   b6ef5b40 0004
01f8e408 b6ef5b40
[   84.180097] 1fa0: 0004 c000f460 0004 01f8e408 0001 01f8e408
0004 
[   84.188311] 1fc0: 0004 01f8e408 b6ef5b40 0004 0004 01f8e408
0004 
[   84.196525] 1fe0:  bec9595c b6e2143c b6e7716c 6010 0001
 
[   84.204762] [] (regmap_read) from []
(mxs_phy_get_vbus_status+0x40/0x58)
[   84.213258] [] (mxs_phy_get_vbus_status) from []
(mxs_phy_suspend+0x54/0x120)
[   84.222185] [] (mxs_phy_suspend) from []
(ci_controller_suspend+0x40/0x60)
[   84.230847] [] (ci_controller_suspend) from []
(ci_suspend+0x7c/0xbc)
[   84.239081] [] (ci_suspend) from []
(platform_pm_suspend+0x2c/0x54)
[   84.247145] [] (platform_pm_suspend) from []
(dpm_run_callback+0x48/0x12c)
[   84.255809] [] (dpm_run_callback) from []
(__device_suspend+0x12c/0x370)
[   84.264294] [] (__device_suspend) from []
(dpm_suspend+0x134/0x2fc)
[   84.272350] [] (dpm_suspend) from []
(suspend_devices_and_enter+0x8c/0x6e4)
[   84.281094] [] (suspend_devices_and_enter) from []
(pm_suspend+0x308/0x434)
[   84.289836] [] (pm_suspend) from []
(state_store+0x80/0xcc)
[   84.297192] [] (state_store) from []
(kobj_attr_store+0x18/0x1c)
[   84.304979] [] (kobj_attr_store) from []
(sysfs_kf_write+0x48/0x4c)
[   84.313046] [] (sysfs_kf_write) from []
(kernfs_fop_write+0xe0/0x188)
[   84.321282] [] (kernfs_fop_write) from []
(vfs_write+0xb8/0x1e8)
[   84.329074] [] (vfs_write) from [] (SyS_write+0x44/0x88)
[   84.336178] [] (SyS_write) from []
(ret_f

Re: [PATCH 00/21] On-demand device registration

2015-06-13 Thread Alexander Holler

Am 12.06.2015 um 13:36 schrieb Alexander Holler:

Am 12.06.2015 um 13:19 schrieb Alexander Holler:

Am 12.06.2015 um 09:25 schrieb Linus Walleij:

On Thu, Jun 11, 2015 at 6:40 PM, Alexander Holler
 wrote:

Am 11.06.2015 um 14:30 schrieb Linus Walleij:



Certainly it is possible to create deadlocks in this scenario, but the
scope is not to create an ubreakable system.


IAnd what happens if you run into a deadlock? Do you print "you've
lost, try
changing your kernel config" in some output hidden by a
splash-screen? ;)


Sorry it sounds like a blanket argument, the fact that there are
mutexes in the kernel makes it possible to deadlock, it doesn't
mean we don't use mutexes. Some programming problems are
just like such.


I'm not talking about specific deadlocks through mutexes. I'm talking
about what happens when driver A needs driver B which needs driver A.
How do you recognise and handle that with your instrumented on-demand
device initialization? Such a circular dependency might happen by just
adding a new fucntion call or by changing the kernel configuration. And
with the on-demand stuff, the possibility that the developer introducing
this new (maybe optional) call will never hit such a circular dependency
is high. So you will end up with a never ending stream of problem
reports whenever someone introduced such a circular dependecy without
having noticed it.

And to come back to specific deadlocks, if you are extending function
calls from something former simple to something which might initialize a
whole bunch of drivers, needing maybe seconds, I wouldn't say this is a
blanket argument, but a real thread.


Keep in mind, that the possibility that a function call ends up with
initializing a whole bunch of other drivers, is not determined
statically, but depends on the configuration and runtime behaviour of
the actual system the on-demand stuff actually happens.

E.g. if driver A is faster one system that driver B, the whole bunch of
drivers might become initialized by a call in driver A. But if driver B
was faster on the developers system (or the system is configured to
first init driver B), than the whole bunch of drivers might have become
initialized by driver B on the developers system. Thus he never might
have hit a possible problem when the whole bunch of drivers got
initialized in driver A.

That means it isn't always a good idea to create dynamic systems (like
on-demand device initialization), because it's very hard to foresee and
correctly handle their runtime behaviour.


And because you've said that "problem space is a bit convoluted" and I 
disagree, here's a summary from my point of view:


1. All the necessary information (dependencies between drivers) already 
exists at compile time. The set of dependencies between drivers might 
become smaller by configuration, but will not become larger. So there 
should be NO need to collect them at runtime, e.g. by instrumenting 
function calls. I've described the problems I see with that above. I've 
choosen DT as source of dependencies because it offers an easy 
accessible and almost complete set of dependencies. I just had to add 
some type information to the dtb in order to identify the dependencies 
(phandles). But other ways to collect the dependencies would work too. 
Even the most simple way to add a static list of dependencies to each 
driver (which later on might be automated by some more clever stuff than 
adding them manually) would do the trick.


2. The problem to sort a set of nodes (drivers) with dependencies is 
solved since a long time and almost any developers uses it regularly in 
form of make. And everyone who used make -jN knows that the possible 
parallel initialization of drivers I've talked about, is already solved too.


3. In order to initialize the drivers in some specific order, their 
initcalls must be identified. I've offered a possible solution to that 
without much changes, but many other, even better ways, are possible 
too. It just depends on how much you want to change and on how much of 
these changes you will be able to feed into mainline kernel (which 
depends on your connections/relations inside the core kernel crew). E.g. 
instead of still just relying on one-dimensional arrays with (anonymous) 
pointers to initcalls, a multidimensional array of initcalls and 
drivername (and maybe more information) might be thinkable.


4. x86/amd64/ACPI-people, so most longtime and core kernel maintainers 
obviously don't have much interest until you've solved 1. in a way they 
can use too. So the necessary changes for 2. or 3. will have a big 
hurdle to take if 1. isn't solved usable for them too.



Alexander Holler


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