Re: [PATCH] Documentation: clarify configfs-usb-gadget-rndis

2018-01-15 Thread David Lechner

On 01/15/2018 10:36 AM, David Lechner wrote:

This removes the misleading "(hex)" from the attribute descriptions of
configfs-usb-gadget-rndis. These attributes can only accept decimal
numbers, not hexadecimal formatted numbers.

Cc: Felipe Balbi <felipe.ba...@linux.intel.com>
Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org>
Signed-off-by: David Lechner <da...@lechnology.com>
---


Please disregard this patch. This actually does use hex values.

It just does not use the "0x" prefix from C, which threw me off.


--
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] Documentation: clarify configfs-usb-gadget-rndis

2018-01-15 Thread David Lechner
This removes the misleading "(hex)" from the attribute descriptions of
configfs-usb-gadget-rndis. These attributes can only accept decimal
numbers, not hexadecimal formatted numbers.

Cc: Felipe Balbi <felipe.ba...@linux.intel.com>
Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org>
Signed-off-by: David Lechner <da...@lechnology.com>
---
 Documentation/ABI/testing/configfs-usb-gadget-rndis | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Documentation/ABI/testing/configfs-usb-gadget-rndis 
b/Documentation/ABI/testing/configfs-usb-gadget-rndis
index 1373990..453c709 100644
--- a/Documentation/ABI/testing/configfs-usb-gadget-rndis
+++ b/Documentation/ABI/testing/configfs-usb-gadget-rndis
@@ -12,6 +12,6 @@ Description:
Ethernet over USB link
dev_addr- MAC address of device's end of this
Ethernet over USB link
-   class   - USB interface class, default is 02 (hex)
-   subclass- USB interface subclass, default is 06 (hex)
-   protocol- USB interface protocol, default is 00 (hex)
+   class   - USB interface class, default is 2
+   subclass- USB interface subclass, default is 6
+   protocol- USB interface protocol, default is 0
-- 
2.7.4

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


Re: [PATCH] USB: ohci: da8xx: remove clk con_id

2018-01-07 Thread David Lechner

On 01/05/2018 07:53 PM, David Lechner wrote:

The ohci-da8xx device only has one clock, so a con_id is not needed, so
remove it. This way we don't have to add an unnecessary property to the
device tree bindings for the clock.

Signed-off-by: David Lechner <da...@lechnology.com>
---


superseded by https://marc.info/?l=linux-usb=151529526103513=2
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] USB: musb: da8xx: remove clock con_id

2018-01-07 Thread David Lechner

On 01/05/2018 07:50 PM, David Lechner wrote:

There is only one clock for the DA8xx MUSB device, so we don't need the
con_id, so remove it. This way we don't have to add an unnecessary
property to the device tree bindings for the clock.

Signed-off-by: David Lechner <da...@lechnology.com>
---


superseded by https://marc.info/?l=linux-usb=151529526103513=2
--
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/3] ARM: da8xx: remove con_id from USB clocks

2018-01-06 Thread David Lechner
This series removes unnecessary con_ids on da8xx USB clocks in preparation
of adding device tree support for clocks on this platform.

Note: this is a resend  of "USB: musb: da8xx: remove clock con_id" and
"USB: ohci: da8xx: remove clk con_id". I sent them before I realized that
things break if you don't also remove the con_id when registering the
clkdev. :-/

David Lechner (3):
  USB: musb: da8xx: remove clock con_id
  USB: ohci: da8xx: remove clk con_id
  ARM: da8xx: remove con_id from USB clocks

 arch/arm/mach-davinci/da830.c | 4 ++--
 arch/arm/mach-davinci/da850.c | 4 ++--
 drivers/usb/host/ohci-da8xx.c | 2 +-
 drivers/usb/musb/da8xx.c  | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)

-- 
2.7.4

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


[PATCH 2/3] USB: ohci: da8xx: remove clk con_id

2018-01-06 Thread David Lechner
The ohci-da8xx device only has one clock, so a con_id is not needed, so
remove it. This way we don't have to add an unnecessary property to the
device tree bindings for the clock.

Signed-off-by: David Lechner <da...@lechnology.com>
---
 drivers/usb/host/ohci-da8xx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c
index 0c507a0..a55cbba 100644
--- a/drivers/usb/host/ohci-da8xx.c
+++ b/drivers/usb/host/ohci-da8xx.c
@@ -413,7 +413,7 @@ static int ohci_da8xx_probe(struct platform_device *pdev)
da8xx_ohci = to_da8xx_ohci(hcd);
da8xx_ohci->hcd = hcd;
 
-   da8xx_ohci->usb11_clk = devm_clk_get(>dev, "usb11");
+   da8xx_ohci->usb11_clk = devm_clk_get(>dev, NULL);
if (IS_ERR(da8xx_ohci->usb11_clk)) {
error = PTR_ERR(da8xx_ohci->usb11_clk);
if (error != -EPROBE_DEFER)
-- 
2.7.4

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


[PATCH 3/3] ARM: da8xx: remove con_id from USB clocks

2018-01-06 Thread David Lechner
There is only one clock each for "musb-da8xx" and "ohci-da8xx", so we
do not the the con_id. Removing them  will also prevent needing an
unnecessary device tree property when device tree bindings are added
for clocks.

Signed-off-by: David Lechner <da...@lechnology.com>
---
 arch/arm/mach-davinci/da830.c | 4 ++--
 arch/arm/mach-davinci/da850.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-davinci/da830.c b/arch/arm/mach-davinci/da830.c
index ed0b700..57ab18c 100644
--- a/arch/arm/mach-davinci/da830.c
+++ b/arch/arm/mach-davinci/da830.c
@@ -417,7 +417,7 @@ static struct clk_lookup da830_clks[] = {
CLK("davinci-mcasp.0",  NULL,   _clk),
CLK("davinci-mcasp.1",  NULL,   _clk),
CLK("davinci-mcasp.2",  NULL,   _clk),
-   CLK("musb-da8xx",   "usb20",_clk),
+   CLK("musb-da8xx",   NULL,   _clk),
CLK("cppi41-dmaengine", NULL,   _clk),
CLK(NULL,   "aemif",_clk),
CLK(NULL,   "aintc",_clk),
@@ -426,7 +426,7 @@ static struct clk_lookup da830_clks[] = {
CLK("davinci_mdio.0",   "fck",  _clk),
CLK(NULL,   "gpio", _clk),
CLK("i2c_davinci.2",NULL,   _clk),
-   CLK("ohci-da8xx",   "usb11",_clk),
+   CLK("ohci-da8xx",   NULL,   _clk),
CLK(NULL,   "emif3",_clk),
CLK(NULL,   "arm",  _clk),
CLK(NULL,   "rmii", _clk),
diff --git a/arch/arm/mach-davinci/da850.c b/arch/arm/mach-davinci/da850.c
index 04a58a3..aa37cbd 100644
--- a/arch/arm/mach-davinci/da850.c
+++ b/arch/arm/mach-davinci/da850.c
@@ -563,8 +563,8 @@ static struct clk_lookup da850_clks[] = {
CLK("da830-mmc.1",  NULL,   _clk),
CLK("ti-aemif", NULL,   _clk),
CLK("davinci-nand.0",   "aemif",_nand_clk),
-   CLK("ohci-da8xx",   "usb11",_clk),
-   CLK("musb-da8xx",   "usb20",_clk),
+   CLK("ohci-da8xx",   NULL,   _clk),
+   CLK("musb-da8xx",   NULL,   _clk),
CLK("cppi41-dmaengine", NULL,   _clk),
CLK("spi_davinci.0",NULL,   _clk),
CLK("spi_davinci.1",NULL,   _clk),
-- 
2.7.4

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


[PATCH 1/3] USB: musb: da8xx: remove clock con_id

2018-01-06 Thread David Lechner
There is only one clock for the DA8xx MUSB device, so we don't need the
con_id, so remove it. This way we don't have to add an unnecessary
property to the device tree bindings for the clock.

Signed-off-by: David Lechner <da...@lechnology.com>
---
 drivers/usb/musb/da8xx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 6c036de..b8295ce 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -520,7 +520,7 @@ static int da8xx_probe(struct platform_device *pdev)
if (!glue)
return -ENOMEM;
 
-   clk = devm_clk_get(>dev, "usb20");
+   clk = devm_clk_get(>dev, NULL);
if (IS_ERR(clk)) {
dev_err(>dev, "failed to get clock\n");
return PTR_ERR(clk);
-- 
2.7.4

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


[PATCH] USB: ohci: da8xx: remove clk con_id

2018-01-05 Thread David Lechner
The ohci-da8xx device only has one clock, so a con_id is not needed, so
remove it. This way we don't have to add an unnecessary property to the
device tree bindings for the clock.

Signed-off-by: David Lechner <da...@lechnology.com>
---
 drivers/usb/host/ohci-da8xx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c
index 0c507a0..a55cbba 100644
--- a/drivers/usb/host/ohci-da8xx.c
+++ b/drivers/usb/host/ohci-da8xx.c
@@ -413,7 +413,7 @@ static int ohci_da8xx_probe(struct platform_device *pdev)
da8xx_ohci = to_da8xx_ohci(hcd);
da8xx_ohci->hcd = hcd;
 
-   da8xx_ohci->usb11_clk = devm_clk_get(>dev, "usb11");
+   da8xx_ohci->usb11_clk = devm_clk_get(>dev, NULL);
if (IS_ERR(da8xx_ohci->usb11_clk)) {
error = PTR_ERR(da8xx_ohci->usb11_clk);
if (error != -EPROBE_DEFER)
-- 
2.7.4

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


[PATCH] USB: musb: da8xx: remove clock con_id

2018-01-05 Thread David Lechner
There is only one clock for the DA8xx MUSB device, so we don't need the
con_id, so remove it. This way we don't have to add an unnecessary
property to the device tree bindings for the clock.

Signed-off-by: David Lechner <da...@lechnology.com>
---
 drivers/usb/musb/da8xx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 6c036de..b8295ce 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -520,7 +520,7 @@ static int da8xx_probe(struct platform_device *pdev)
if (!glue)
return -ENOMEM;
 
-   clk = devm_clk_get(>dev, "usb20");
+   clk = devm_clk_get(>dev, NULL);
if (IS_ERR(clk)) {
dev_err(>dev, "failed to get clock\n");
return PTR_ERR(clk);
-- 
2.7.4

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


[PATCH v2] usb: gadget: add RNDIS configfs options for class/subclass/protocol

2017-07-29 Thread David Lechner
This adds 3 new options to the RNDIS gadget function configs. It allows
overriding the default USB interface class/subclass/protocol.

The motivation for this is that if you set the values to "ef" (Misc),
"04" (RNDIS), "01" (Ethernet) respectively, then the device will be
recognized by the rndiscmp.inf file in Windows Vista and newer and will
cause Windows to load the correct RNDIS driver without the need for a
custom (signed) .inf file.

Signed-off-by: David Lechner <da...@lechnology.com>
---

This is a revision of "usb: gadget: add RNDIS configfs option for Windows
rndiscmp.inf compatibility"[1] using more generic options.

[1]: https://patchwork.kernel.org/patch/9597007/

 .../ABI/testing/configfs-usb-gadget-rndis  |  3 ++
 drivers/usb/gadget/function/f_rndis.c  | 20 +
 drivers/usb/gadget/function/u_ether_configfs.h | 35 ++
 drivers/usb/gadget/function/u_rndis.h  |  4 +++
 4 files changed, 62 insertions(+)

diff --git a/Documentation/ABI/testing/configfs-usb-gadget-rndis 
b/Documentation/ABI/testing/configfs-usb-gadget-rndis
index e32879b..1373990 100644
--- a/Documentation/ABI/testing/configfs-usb-gadget-rndis
+++ b/Documentation/ABI/testing/configfs-usb-gadget-rndis
@@ -12,3 +12,6 @@ Description:
Ethernet over USB link
dev_addr- MAC address of device's end of this
Ethernet over USB link
+   class   - USB interface class, default is 02 (hex)
+   subclass- USB interface subclass, default is 06 (hex)
+   protocol- USB interface protocol, default is 00 (hex)
diff --git a/drivers/usb/gadget/function/f_rndis.c 
b/drivers/usb/gadget/function/f_rndis.c
index 16562e4..e1d5853 100644
--- a/drivers/usb/gadget/function/f_rndis.c
+++ b/drivers/usb/gadget/function/f_rndis.c
@@ -691,6 +691,10 @@ rndis_bind(struct usb_configuration *c, struct 
usb_function *f)
f->os_desc_table[0].os_desc = _opts->rndis_os_desc;
}
 
+   rndis_iad_descriptor.bFunctionClass = rndis_opts->class;
+   rndis_iad_descriptor.bFunctionSubClass = rndis_opts->subclass;
+   rndis_iad_descriptor.bFunctionProtocol = rndis_opts->protocol;
+
/*
 * in drivers/usb/gadget/configfs.c:configfs_composite_bind()
 * configurations are bound in sequence with list_for_each_entry,
@@ -866,11 +870,23 @@ USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(rndis);
 /* f_rndis_opts_ifname */
 USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(rndis);
 
+/* f_rndis_opts_class */
+USB_ETHER_CONFIGFS_ITEM_ATTR_U8_RW(rndis, class);
+
+/* f_rndis_opts_subclass */
+USB_ETHER_CONFIGFS_ITEM_ATTR_U8_RW(rndis, subclass);
+
+/* f_rndis_opts_protocol */
+USB_ETHER_CONFIGFS_ITEM_ATTR_U8_RW(rndis, protocol);
+
 static struct configfs_attribute *rndis_attrs[] = {
_opts_attr_dev_addr,
_opts_attr_host_addr,
_opts_attr_qmult,
_opts_attr_ifname,
+   _opts_attr_class,
+   _opts_attr_subclass,
+   _opts_attr_protocol,
NULL,
 };
 
@@ -916,6 +932,10 @@ static struct usb_function_instance *rndis_alloc_inst(void)
}
INIT_LIST_HEAD(>rndis_os_desc.ext_prop);
 
+   opts->class = rndis_iad_descriptor.bFunctionClass;
+   opts->subclass = rndis_iad_descriptor.bFunctionSubClass;
+   opts->protocol = rndis_iad_descriptor.bFunctionProtocol;
+
descs[0] = >rndis_os_desc;
names[0] = "rndis";
config_group_init_type_name(>func_inst.group, "",
diff --git a/drivers/usb/gadget/function/u_ether_configfs.h 
b/drivers/usb/gadget/function/u_ether_configfs.h
index c71133d..e4c3f84a 100644
--- a/drivers/usb/gadget/function/u_ether_configfs.h
+++ b/drivers/usb/gadget/function/u_ether_configfs.h
@@ -153,4 +153,39 @@ out:   
\
\
CONFIGFS_ATTR_RO(_f_##_opts_, ifname)
 
+#define USB_ETHER_CONFIGFS_ITEM_ATTR_U8_RW(_f_, _n_)   \
+   static ssize_t _f_##_opts_##_n_##_show(struct config_item *item,\
+  char *page)  \
+   {   \
+   struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item);  \
+   int ret;\
+   \
+   mutex_lock(>lock);\
+   ret = sprintf(page, "%02x\n", opts->_n_);   \
+   mutex_unlock(>lock);  

[PATCH] usb: gadget: add RNDIS configfs option for Windows rndiscmp.inf compatibility

2017-02-28 Thread David Lechner
This adds a new configfs attribute named `use_ms_rndiscmp`. It is a
boolean value that is used to select the class/subclass/protocol used
by the RNDIS function interface association descriptor. By default,
this is 0x02 (Comm), 0x06 (Ethernet), 0xff (None). When the
use_ms_rndiscmp attribute is set to true, the values 0xef (Misc),
0x04 (RNDIS), 0x01 (Ethernet) will be used instead. This class/subclass/
protocol combination is recognized by the rndiscmp.inf file in Windows
Vista and newer and will cause Windows to load the correct RNDIS driver
without the need for a custom (signed) .inf file.

Signed-off-by: David Lechner <da...@lechnology.com>
---
 .../ABI/testing/configfs-usb-gadget-rndis  |  3 ++
 drivers/usb/gadget/function/f_rndis.c  | 48 ++
 drivers/usb/gadget/function/u_rndis.h  |  1 +
 include/uapi/linux/usb/misc.h  | 14 +++
 4 files changed, 66 insertions(+)
 create mode 100644 include/uapi/linux/usb/misc.h

diff --git a/Documentation/ABI/testing/configfs-usb-gadget-rndis 
b/Documentation/ABI/testing/configfs-usb-gadget-rndis
index e32879b..bb4b5a85 100644
--- a/Documentation/ABI/testing/configfs-usb-gadget-rndis
+++ b/Documentation/ABI/testing/configfs-usb-gadget-rndis
@@ -12,3 +12,6 @@ Description:
Ethernet over USB link
dev_addr- MAC address of device's end of this
Ethernet over USB link
+   use_ms_rndiscmp - Use the MS Windows rndiscmp.inf compatible
+   class 0xEF, subclass 0x04, protocol 0x01
+   instead of the default 0x02/0x06/0x00.
diff --git a/drivers/usb/gadget/function/f_rndis.c 
b/drivers/usb/gadget/function/f_rndis.c
index 16562e4..b92f4f4 100644
--- a/drivers/usb/gadget/function/f_rndis.c
+++ b/drivers/usb/gadget/function/f_rndis.c
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -692,6 +693,18 @@ rndis_bind(struct usb_configuration *c, struct 
usb_function *f)
}
 
/*
+* Starting with Vista, Windows will match this Class/SubClass/Protocol
+* with rndiscmp.inf and load the proper driver without the need for a
+* custom .inf.
+* Ref: https://msdn.microsoft.com/library/ff538820(v=vs.85).aspx
+*/
+   if (rndis_opts->use_ms_rndiscmp) {
+   rndis_iad_descriptor.bFunctionClass = USB_CLASS_MISC;
+   rndis_iad_descriptor.bFunctionSubClass = 
USB_MISC_SUBCLASS_RNDIS;
+   rndis_iad_descriptor.bFunctionProtocol = 
USB_MISC_RNDIS_PROTO_ENET;
+   }
+
+   /*
 * in drivers/usb/gadget/configfs.c:configfs_composite_bind()
 * configurations are bound in sequence with list_for_each_entry,
 * in each configuration its functions are bound in sequence
@@ -866,11 +879,46 @@ USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(rndis);
 /* f_rndis_opts_ifname */
 USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(rndis);
 
+static ssize_t
+rndis_opts_use_ms_rndiscmp_show(struct config_item *item, char *page)
+{
+   struct f_rndis_opts *opts = to_f_rndis_opts(item);
+   int ret;
+
+   mutex_lock(>lock);
+   ret = sprintf(page, "%d\n", opts->use_ms_rndiscmp);
+   mutex_unlock(>lock);
+
+   return ret;
+}
+
+static ssize_t
+rndis_opts_use_ms_rndiscmp_store(struct config_item *item, const char *page,
+size_t len)
+{
+   struct f_rndis_opts *opts = to_f_rndis_opts(item);
+   int ret;
+   bool use;
+
+   mutex_lock(>lock);
+   ret = strtobool(page, );
+   if (!ret) {
+   opts->use_ms_rndiscmp = use;
+   ret = len;
+   }
+   mutex_unlock(>lock);
+
+   return ret;
+}
+
+CONFIGFS_ATTR(rndis_opts_, use_ms_rndiscmp);
+
 static struct configfs_attribute *rndis_attrs[] = {
_opts_attr_dev_addr,
_opts_attr_host_addr,
_opts_attr_qmult,
_opts_attr_ifname,
+   _opts_attr_use_ms_rndiscmp,
NULL,
 };
 
diff --git a/drivers/usb/gadget/function/u_rndis.h 
b/drivers/usb/gadget/function/u_rndis.h
index 4eafd50..03f241f 100644
--- a/drivers/usb/gadget/function/u_rndis.h
+++ b/drivers/usb/gadget/function/u_rndis.h
@@ -25,6 +25,7 @@ struct f_rndis_opts {
struct net_device   *net;
boolbound;
boolborrowed_net;
+   booluse_ms_rndiscmp;
 
struct usb_os_desc  rndis_os_desc;
charrndis_ext_compat_id[16];
diff --git a/include/uapi/linux/usb/misc.h b/include/uapi/linux/usb/misc.h
new file mode 100644
index 000..a6661f6
--- /dev/null
+++ b/include/uapi/linux/usb/misc.h
@@ -0,0 +1,14 @@
+/*
+ * USB Miscellaneous Device Class definitions
+ *
+ * Ref: http://www.usb.org/developers/defined_class/#BaseClassEFh
+ 

Re: [PATCH 4/4] usb: gadget: f_hid: fix: Move IN request allocation to set_alt()

2017-01-20 Thread David Lechner

On 01/19/2017 11:55 AM, Krzysztof Opasiak wrote:

Since commit ba1582f22231 ("usb: gadget: f_hid: use alloc_ep_req()")
we cannot allocate any requests in bind() as we check if we should
align request buffer based on endpoint descriptor which is assigned
in set_alt().

Allocating request in bind() function causes a NULL pointer
dereference.

This commit moves allocation of IN request from bind() to set_alt()
to prevent this issue.

Fixes: ba1582f22231 ("usb: gadget: f_hid: use alloc_ep_req()")
Cc: sta...@vger.kernel.org
Signed-off-by: Krzysztof Opasiak <k.opas...@samsung.com>
---


This series fixes a crash I was experiencing in the v4.9.4 kernel caused 
by "usb: gadget: f_hid: use alloc_ep_req()"[1]. Thank you!


[1]: http://lkml.iu.edu/hypermail/linux/kernel/1701.0/00575.html

Tested-by: David Lechner <da...@lechnology.com>

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


Re: [PATCH 1/3] ARM: dts: da850: Add the cppi41 dma node

2017-01-10 Thread David Lechner

On 01/09/2017 12:26 PM, Sergei Shtylyov wrote:

Hello.

On 01/09/2017 07:24 PM, Alexandre Bailon wrote:


This adds the device tree node for the cppi41 dma
used by the usb otg controller present in the da850 family of SoC's.

Signed-off-by: Alexandre Bailon 
---
 arch/arm/boot/dts/da850.dtsi | 16 
 1 file changed, 16 insertions(+)

diff --git a/arch/arm/boot/dts/da850.dtsi b/arch/arm/boot/dts/da850.dtsi
index 104155d..d6b406a 100644
--- a/arch/arm/boot/dts/da850.dtsi
+++ b/arch/arm/boot/dts/da850.dtsi
@@ -403,6 +403,22 @@
 phy-names = "usb-phy";
 status = "disabled";
 };
+cppi41dma: dma-controller@201000 {
+compatible = "ti,da8xx-cppi41";
+reg =  <0x20 0x1000


   I don't remember any DA8xx glue regs having to do with the CPPI 4.1...


+0x201000 0x1000
+0x202000 0x1000
+0x204000 0x4000>;
+reg-names = "glue", "controller",
+"scheduler", "queuemgr";
+interrupts = <58>;
+interrupt-names = "glue";
+#dma-cells = <2>;
+#dma-channels = <4>;
+#dma-requests = <256>;
+status = "disabled";


   Why disabled? It doesn't use any external pins...


Why enable it if musb node is not also enabled?



[...]

MBR, 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 3/3] ARM: dts: da850: Enable cppi41 dma for da850-lcdk

2017-01-09 Thread David Lechner

On 01/09/2017 10:24 AM, Alexandre Bailon wrote:

This enable the cppi41 dma controller used by the usb otg for
the da850-lcdk board.

Signed-off-by: Alexandre Bailon 
---
 arch/arm/boot/dts/da850-lcdk.dts | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/arm/boot/dts/da850-lcdk.dts b/arch/arm/boot/dts/da850-lcdk.dts
index afcb482..abb9b9d 100644
--- a/arch/arm/boot/dts/da850-lcdk.dts
+++ b/arch/arm/boot/dts/da850-lcdk.dts
@@ -167,6 +167,10 @@
status = "okay";
 };

+  {


nit, there should only be one space before "{"


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



--
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: Fix copy/pasted error message

2017-01-02 Thread David Lechner
This fixes an error message that was probably copied and pasted. The same
message is used for both the in and out endpoints, so it makes it impossible
to know which one actually failed because both cases say "IN".

Make the out endpoint error message say "OUT".

Signed-off-by: David Lechner <da...@lechnology.com>
---
 drivers/usb/gadget/function/f_hid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/f_hid.c 
b/drivers/usb/gadget/function/f_hid.c
index aa1c199..b459c50 100644
--- a/drivers/usb/gadget/function/f_hid.c
+++ b/drivers/usb/gadget/function/f_hid.c
@@ -539,7 +539,7 @@ static int hidg_set_alt(struct usb_function *f, unsigned 
intf, unsigned alt)
}
status = usb_ep_enable(hidg->out_ep);
if (status < 0) {
-   ERROR(cdev, "Enable IN endpoint FAILED!\n");
+   ERROR(cdev, "Enable OUT endpoint FAILED!\n");
goto fail;
}
hidg->out_ep->driver_data = hidg;
-- 
2.7.4

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


[PATCH] Revert "usb: gadget: f_hid: use alloc_ep_req()"

2017-01-02 Thread David Lechner
This reverts commit ba1582f22231821c57534e87b077d84adbc15dbd.

I am getting a null pointer dereference when setting up an hid gadget using
configfs. Reverting this commit fixes the crash.

dmesg:

[  382.406622] Unable to handle kernel NULL pointer dereference at virtual 
address 0002
[  382.406672] pgd = c3b0c000
[  382.406695] [0002] *pgd=c2d7e831, *pte=, *ppte=
[  382.406772] Internal error: Oops: 17 [#1] PREEMPT ARM
[  382.406793] Modules linked in: usb_f_hid usb_f_ecm usb_f_rndis u_ether d_pwm 
d_analog d_uart d_iic rtl8150 suart_emu snd_legoev3 snd_pcm snd_timer snd 
soundcore lms2012_compat legoev3_bluetooth legoev3_i2c fuse uinput libcomposite 
configfs
[  382.407059] CPU: 0 PID: 485 Comm: usb-hid-gadget. Not tainted 
4.9.0-ev3dev-bpo-stretch-r2-ev3-lms2012 #1
[  382.407076] Hardware name: LEGO MINDSTORMS EV3
[  382.407099] task: c36f7660 task.stack: c2e6c000
[  382.407450] PC is at alloc_ep_req+0x28/0x8c [libcomposite]
[  382.407522] LR is at kmem_cache_alloc+0x148/0x154
[  382.407557] pc : []lr : []psr: a013
sp : c2e6dd60  ip :   fp : c2e6dd7c
[  382.407578] r10: c3bd527c  r9 : c3bd52d4  r8 : c2d132a8
[  382.407601] r7 : bf10769c  r6 : c39a4410  r5 : 0400  r4 : c3b3c2a0
[  382.407623] r3 :   r2 :   r1 : ffe0  r0 : c3b3c2a0
[  382.407648] Flags: NzCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment none
[  382.407671] Control: 0005317f  Table: c3b0c000  DAC: 0051
[  382.407694] Process usb-hid-gadget. (pid: 485, stack limit = 0xc2e6c190)
[  382.407716] Stack: (0xc2e6dd60 to 0xc2e6e000)
[  382.407769] dd60: c2ec7654 c3bd527c  c3bd5200 c2e6ddbc c2e6dd80 
bf106894 bf0138c0
[  382.407820] dd80: c2e6de34 c2e6dd90 c000e080 c0009010 c08f0f98 c2d1331c 
c3bd527c c2d132a8
[  382.407870] dda0: c2d132a8 c2d13200 c2d1331c c3bd527c c2e6dddc c2e6ddc0 
bf00f844 bf106804
[  382.407920] ddc0: c2ec7400 c3bd52d4 c2ec7654 c2d132c4 c2e6de34 c2e6dde0 
bf0133a0 bf00f7c8
[  382.407969] dde0: c2ec7400  c39a5140 c2ec768c c2e6de1c c2d1331c 
c3b16264 c2e6997c
[  382.408019] de00: c3bd52d4 c2d132c8 c35ec390 c3a91400 c2ec75e0 c2ec75e0 
 c2ec7590
[  382.408067] de20:   c2e6de54 c2e6de38 c0344e7c bf013134 
 c3a91400
[  382.408117] de40: c2ec75e0 c37c0c00 c2e6de7c c2e6de58 c0345028 c0344e58 
c37c0c00 c00a1994
[  382.408168] de60: c2ec7400 0011 c3ba9000 c37c0c00 c2e6dea4 c2e6de80 
bf01234c c0344f18
[  382.408216] de80: 0011 c08f0cc0 c3ba9000 c2e6df80 0051 c08f0cd8 
c2e6dedc c2e6dea8
[  382.408267] dea0: bf000cd0 bf0122d4 c2e6defc c1d06a00 c00109c0 c1d06a00 
c2e6df80 bf004a40
[  382.408316] dec0: 0011 c2e6df80 c2e6c000  c2e6df4c c2e6dee0 
c00d411c bf000bc0
[  382.408366] dee0: c06999f0 c2e6dfb0 000da2b8 b6e7a000 c2e6dfac c2e6df00 
c000930c c00107e0
[  382.408415] df00: c00f45b4 c00d1aa0 c3b603c0  c3b603c0 000a 
c1d06a00 c2ff60e0
[  382.408463] df20: c00f4f70 0001 c1d06a00 c1d06a00  0011 
000fc408 c2e6df80
[  382.408513] df40: c2e6df7c c2e6df50 c00d5370 c00d40fc c2e6df7c c2e6df60 
c1d06a00 c1d06a00
[  382.408562] df60: 0011 000fc408 c000a464  c2e6dfa4 c2e6df80 
c00d55cc c00d52bc
[  382.408608] df80:   0011 000fc408 b6e7ab40 0004 
 c2e6dfa8
[  382.408655] dfa0: c000a2c0 c00d5594 0011 000fc408 0001 000fc408 
0011 
[  382.408701] dfc0: 0011 000fc408 b6e7ab40 0004 0011 000fc408 
0011 
[  382.408747] dfe0:  beb53734 b6da2cc0 b6dfbefc 6010 0001 
 
[  382.408756] Backtrace: 
[  382.409175] [] (alloc_ep_req [libcomposite]) from [] 
(hidg_bind+0xa0/0x268 [usb_f_hid])
[  382.409225]  r6:c3bd5200 r5: r4:c3bd527c r3:c2ec7654
[  382.409591] [] (hidg_bind [usb_f_hid]) from [] 
(usb_add_function+0x8c/0x13c [libcomposite])
[  382.409652]  r10:c3bd527c r8:c2d1331c r7:c2d13200 r6:c2d132a8 r5:c2d132a8 
r4:c3bd527c
[  382.410191] [] (usb_add_function [libcomposite]) from [] 
(configfs_composite_bind+0x27c/0x34c [libcomposite])
[  382.410226]  r5:c2d132c4 r4:c2ec7654
[  382.410549] [] (configfs_composite_bind [libcomposite]) from 
[] (udc_bind_to_driver+0x34/0xc0)
[  382.410606]  r10: r9: r8:c2ec7590 r7: r6:c2ec75e0 
r5:c2ec75e0
[  382.410623]  r4:c3a91400
[  382.410697] [] (udc_bind_to_driver) from [] 
(usb_gadget_probe_driver+0x120/0x14c)
[  382.410736]  r6:c37c0c00 r5:c2ec75e0 r4:c3a91400 r3:
[  382.411059] [] (usb_gadget_probe_driver) from [] 
(gadget_dev_desc_UDC_store+0x88/0xc0 [libcomposite])
[  382.411105]  r7:c37c0c00 r6:c3ba9000 r5:0011 r4:c2ec7400
[  382.411584] [] (gadget_dev_desc_UDC_store [libcomposite]) from 
[] (configfs_write_file+0x120/0x154 [configfs])
[  382.411644]  r10:c08f0cd8 r8:0051 r7:c2e6df80 r6:c3ba9000 r5:c08f0cc0 
r4:0011
[  382.411865] [] (configfs_write_file [configfs]) from [] 
(__vfs_write+0x30/0x10c)
[  382.411922]  r10: r9:c2e6c000 r8:c2e6df80 r7:0011 r6:bf004a40 

Re: [PATCH v6 3/5] USB: ohci: da8xx: Allow a regulator to handle VBUS

2016-11-22 Thread David Lechner

On 11/22/2016 02:46 PM, Axel Haslam wrote:

On Tue, Nov 22, 2016 at 9:37 PM, David Lechner <da...@lechnology.com> wrote:

On 11/21/2016 10:30 AM, Axel Haslam wrote:


Using a regulator to handle VBUS will eliminate the need for
platform data and callbacks, and make the driver more generic
allowing different types of regulators to handle VBUS.

The regulator equivalents to the platform callbacks are:
set_power   ->  regulator_enable/regulator_disable
get_power   ->  regulator_is_enabled
get_oci ->  regulator_get_error_flags
ocic_notify ->  regulator event notification

Signed-off-by: Axel Haslam <ahas...@baylibre.com>
---
 drivers/usb/host/ohci-da8xx.c | 97
+--
 1 file changed, 94 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c
index 90763ad..d0eb754 100644
--- a/drivers/usb/host/ohci-da8xx.c
+++ b/drivers/usb/host/ohci-da8xx.c
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -36,8 +37,12 @@ static int (*orig_ohci_hub_control)(struct usb_hcd
*hcd, u16 typeReq,
 static int (*orig_ohci_hub_status_data)(struct usb_hcd *hcd, char *buf);

 struct da8xx_ohci_hcd {
+   struct usb_hcd *hcd;
struct clk *usb11_clk;
struct phy *usb11_phy;
+   struct regulator *vbus_reg;
+   struct notifier_block nb;
+   unsigned int reg_enabled;
 };

 #define to_da8xx_ohci(hcd) (struct da8xx_ohci_hcd
*)(hcd_to_ohci(hcd)->priv)
@@ -83,56 +88,103 @@ static void ohci_da8xx_disable(struct usb_hcd *hcd)

 static int ohci_da8xx_set_power(struct usb_hcd *hcd, int on)
 {
+   struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
struct device *dev  = hcd->self.controller;
struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
+   int ret;

if (hub && hub->set_power)
return hub->set_power(1, on);

+   if (!da8xx_ohci->vbus_reg)
+   return 0;
+
+   if (on && !da8xx_ohci->reg_enabled) {
+   ret = regulator_enable(da8xx_ohci->vbus_reg);
+   if (ret) {
+   dev_err(dev, "Failed to enable regulator: %d\n",
ret);
+   return ret;
+   }
+   da8xx_ohci->reg_enabled = 1;
+
+   } else if (!on && da8xx_ohci->reg_enabled) {
+   ret = regulator_disable(da8xx_ohci->vbus_reg);
+   if (ret) {
+   dev_err(dev, "Failed  to disable regulator: %d\n",
ret);
+   return ret;
+   }
+   da8xx_ohci->reg_enabled = 0;
+   }
+
return 0;
 }

 static int ohci_da8xx_get_power(struct usb_hcd *hcd)
 {
+   struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
struct device *dev  = hcd->self.controller;
struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);

if (hub && hub->get_power)
return hub->get_power(1);

+   if (da8xx_ohci->vbus_reg)
+   return regulator_is_enabled(da8xx_ohci->vbus_reg);
+
return 1;
 }

 static int ohci_da8xx_get_oci(struct usb_hcd *hcd)
 {
+   struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
struct device *dev  = hcd->self.controller;
struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
+   unsigned int flags;
+   int ret;

if (hub && hub->get_oci)
return hub->get_oci(1);

+   if (!da8xx_ohci->vbus_reg)
+   return 0;
+
+   ret = regulator_get_error_flags(da8xx_ohci->vbus_reg, );
+   if (ret)
+   return ret;
+
+   if (flags & REGULATOR_ERROR_OVER_CURRENT)
+   return 1;
+
return 0;
 }

 static int ohci_da8xx_has_set_power(struct usb_hcd *hcd)
 {
+   struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
struct device *dev  = hcd->self.controller;
struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);

if (hub && hub->set_power)
return 1;

+   if (da8xx_ohci->vbus_reg)
+   return 1;
+
return 0;
 }

 static int ohci_da8xx_has_oci(struct usb_hcd *hcd)
 {
+   struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
struct device *dev  = hcd->self.controller;
struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);

if (hub && hub->get_oci)
return 1;

+   if (da8xx_ohci->vbus_reg)
+   return 1;
+
return 0;
 }

@@ -160,15 +212,41 @@ static void ohci_da8xx_ocic_handler(struct
da8xx_ohci_root_hub *hub,
hub->set_power(port, 0);
 }

+static int ohci_da8xx_regulator_event(struct notifier_block *nb,
+  

Re: [PATCH v6 1/5] USB: ohci: da8xx: use ohci priv data instead of globals

2016-11-22 Thread David Lechner

On 11/21/2016 10:30 AM, Axel Haslam wrote:

Instead of global variables, use the extra_priv_size of
the ohci driver.

We cannot yet move the ocic mask because this is used on
the interrupt handler which is registerded through platform


s/registerded/registered/


data and does not have an hcd pointer. This will be moved
on a later patch.

Signed-off-by: Axel Haslam <ahas...@baylibre.com>
---


Looks good to me (other than the spelling error above).

Tested-by: David Lechner <da...@lechnology.com>

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


Re: [PATCH v6 3/5] USB: ohci: da8xx: Allow a regulator to handle VBUS

2016-11-22 Thread David Lechner

On 11/21/2016 10:30 AM, Axel Haslam wrote:

Using a regulator to handle VBUS will eliminate the need for
platform data and callbacks, and make the driver more generic
allowing different types of regulators to handle VBUS.

The regulator equivalents to the platform callbacks are:
set_power   ->  regulator_enable/regulator_disable
get_power   ->  regulator_is_enabled
get_oci ->  regulator_get_error_flags
ocic_notify ->  regulator event notification

Signed-off-by: Axel Haslam 
---
 drivers/usb/host/ohci-da8xx.c | 97 +--
 1 file changed, 94 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c
index 90763ad..d0eb754 100644
--- a/drivers/usb/host/ohci-da8xx.c
+++ b/drivers/usb/host/ohci-da8xx.c
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -36,8 +37,12 @@ static int (*orig_ohci_hub_control)(struct usb_hcd  *hcd, 
u16 typeReq,
 static int (*orig_ohci_hub_status_data)(struct usb_hcd *hcd, char *buf);

 struct da8xx_ohci_hcd {
+   struct usb_hcd *hcd;
struct clk *usb11_clk;
struct phy *usb11_phy;
+   struct regulator *vbus_reg;
+   struct notifier_block nb;
+   unsigned int reg_enabled;
 };

 #define to_da8xx_ohci(hcd) (struct da8xx_ohci_hcd *)(hcd_to_ohci(hcd)->priv)
@@ -83,56 +88,103 @@ static void ohci_da8xx_disable(struct usb_hcd *hcd)

 static int ohci_da8xx_set_power(struct usb_hcd *hcd, int on)
 {
+   struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
struct device *dev  = hcd->self.controller;
struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
+   int ret;

if (hub && hub->set_power)
return hub->set_power(1, on);

+   if (!da8xx_ohci->vbus_reg)
+   return 0;
+
+   if (on && !da8xx_ohci->reg_enabled) {
+   ret = regulator_enable(da8xx_ohci->vbus_reg);
+   if (ret) {
+   dev_err(dev, "Failed to enable regulator: %d\n", ret);
+   return ret;
+   }
+   da8xx_ohci->reg_enabled = 1;
+
+   } else if (!on && da8xx_ohci->reg_enabled) {
+   ret = regulator_disable(da8xx_ohci->vbus_reg);
+   if (ret) {
+   dev_err(dev, "Failed  to disable regulator: %d\n", ret);
+   return ret;
+   }
+   da8xx_ohci->reg_enabled = 0;
+   }
+
return 0;
 }

 static int ohci_da8xx_get_power(struct usb_hcd *hcd)
 {
+   struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
struct device *dev  = hcd->self.controller;
struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);

if (hub && hub->get_power)
return hub->get_power(1);

+   if (da8xx_ohci->vbus_reg)
+   return regulator_is_enabled(da8xx_ohci->vbus_reg);
+
return 1;
 }

 static int ohci_da8xx_get_oci(struct usb_hcd *hcd)
 {
+   struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
struct device *dev  = hcd->self.controller;
struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
+   unsigned int flags;
+   int ret;

if (hub && hub->get_oci)
return hub->get_oci(1);

+   if (!da8xx_ohci->vbus_reg)
+   return 0;
+
+   ret = regulator_get_error_flags(da8xx_ohci->vbus_reg, );
+   if (ret)
+   return ret;
+
+   if (flags & REGULATOR_ERROR_OVER_CURRENT)
+   return 1;
+
return 0;
 }

 static int ohci_da8xx_has_set_power(struct usb_hcd *hcd)
 {
+   struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
struct device *dev  = hcd->self.controller;
struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);

if (hub && hub->set_power)
return 1;

+   if (da8xx_ohci->vbus_reg)
+   return 1;
+
return 0;
 }

 static int ohci_da8xx_has_oci(struct usb_hcd *hcd)
 {
+   struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
struct device *dev  = hcd->self.controller;
struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);

if (hub && hub->get_oci)
return 1;

+   if (da8xx_ohci->vbus_reg)
+   return 1;
+
return 0;
 }

@@ -160,15 +212,41 @@ static void ohci_da8xx_ocic_handler(struct 
da8xx_ohci_root_hub *hub,
hub->set_power(port, 0);
 }

+static int ohci_da8xx_regulator_event(struct notifier_block *nb,
+   unsigned long event, void *data)
+{
+   struct da8xx_ohci_hcd *da8xx_ohci =
+   container_of(nb, struct da8xx_ohci_hcd, nb);
+   struct device *dev = da8xx_ohci->hcd->self.controller;
+
+   if (event & REGULATOR_EVENT_OVER_CURRENT) {
+   dev_warn(dev, 

Re: [v5,3/5] USB: ohci: da8xx: Allow a regulator to handle VBUS

2016-11-21 Thread David Lechner

On 11/21/2016 04:22 AM, Axel Haslam wrote:

Hi David,

Thanks for the review,



You're welcome.



@@ -160,15 +212,41 @@ static void ohci_da8xx_ocic_handler(struct
da8xx_ohci_root_hub *hub,
hub->set_power(port, 0);
 }

+static int ohci_da8xx_regulator_event(struct notifier_block *nb,
+   unsigned long event, void *data)
+{
+   struct da8xx_ohci_hcd *da8xx_ohci =
+   container_of(nb, struct da8xx_ohci_hcd,
nb);
+   struct device *dev = da8xx_ohci->hcd->self.controller;
+
+   if (event & REGULATOR_EVENT_OVER_CURRENT) {
+   dev_warn(dev, "over current event\n");



Won't this result in duplicate overcurrent warnings in the kernel log? It
seems like in previous version of this patch series, we would get an
overcurrent error from the core usb driver.


you mean in the regulator driver? i did not make changes to core usb.
but, no,  i did not add a print in the fixed regulator driver itself. Since
the regulator is  a separate driver, and could be implemented with or without
a trace, i think its better to leave this print. It shows that the usb driver
has well received the notification.



No, I mean in drivers/usb/core/hub.c. There is

if (status & USB_PORT_STAT_OVERCURRENT)
dev_err(_dev->dev, "over-current condition\n");

and

if (status & HUB_STATUS_OVERCURRENT)
dev_err(hub_dev, "over-current condition\n");

In ohci_da8xx_hub_control(), we are setting RH_PS_POCI and RH_PS_OCIC, 
so these messages will be printed via the core hub driver. We don't need 
to print another message from the same event.




--
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 v3 10/10] ARM: dts: da850: add usb device node

2016-11-20 Thread David Lechner

On 11/07/2016 02:39 PM, Axel Haslam wrote:

This adds the ohci device node for the da850 soc.
It also enables it for the omapl138 hawk board.

Signed-off-by: Axel Haslam 
---
 arch/arm/boot/dts/da850-lcdk.dts | 8 
 arch/arm/boot/dts/da850.dtsi | 8 
 2 files changed, 16 insertions(+)

diff --git a/arch/arm/boot/dts/da850-lcdk.dts b/arch/arm/boot/dts/da850-lcdk.dts
index 7b8ab21..aaf533e 100644
--- a/arch/arm/boot/dts/da850-lcdk.dts
+++ b/arch/arm/boot/dts/da850-lcdk.dts
@@ -86,6 +86,14 @@
};
 };

+_phy {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
  {
pinctrl-names = "default";
pinctrl-0 = <_rxtx_pins>;
diff --git a/arch/arm/boot/dts/da850.dtsi b/arch/arm/boot/dts/da850.dtsi
index 2534aab..50e86da 100644
--- a/arch/arm/boot/dts/da850.dtsi
+++ b/arch/arm/boot/dts/da850.dtsi
@@ -405,6 +405,14 @@
>;
status = "disabled";
};
+   ohci: usb@0225000 {


In commit 2957e36e76c836b167e5e0c1edb578d8a9bd7af6 in the linux-davinci 
tree, the alias for the musb device is usb0. So, I think we should use 
usb1 here instead of ohci - or change the usb0 alias to musb.


https://git.kernel.org/cgit/linux/kernel/git/nsekhar/linux-davinci.git/commit/?h=v4.10/dt=2957e36e76c836b167e5e0c1edb578d8a9bd7af6


+   compatible = "ti,da830-ohci";
+   reg = <0x225000 0x1000>;
+   interrupts = <59>;
+   phys = <_phy 1>;
+   phy-names = "usb-phy";
+   status = "disabled";
+   };
gpio: gpio@226000 {
compatible = "ti,dm6441-gpio";
gpio-controller;



--
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: [v5,3/5] USB: ohci: da8xx: Allow a regulator to handle VBUS

2016-11-19 Thread David Lechner

On 11/19/2016 09:31 PM, David Lechner wrote:

On 11/14/2016 08:41 AM, ahas...@baylibre.com wrote:

+ocic_mask |= 1;


I thought that a previous patch got rid of all globals. Why is ocic_mask
still a global variable?


I suppose if I read the commit message, I will know the answer ;-)

--
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: [v5,3/5] USB: ohci: da8xx: Allow a regulator to handle VBUS

2016-11-19 Thread David Lechner

On 11/14/2016 08:41 AM, ahas...@baylibre.com wrote:

Using a regulator to handle VBUS will eliminate the need for
platform data and callbacks, and make the driver more generic
allowing different types of regulators to handle VBUS.

The regulator equivalents to the platform callbacks are:
set_power   ->  regulator_enable/regulator_disable
get_power   ->  regulator_is_enabled
get_oci ->  regulator_get_error_flags
ocic_notify ->  regulator event notification

Signed-off-by: Axel Haslam 
---
 drivers/usb/host/ohci-da8xx.c | 95 ++-
 1 file changed, 93 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c
index 83e3c98..42eaeb9 100644
--- a/drivers/usb/host/ohci-da8xx.c
+++ b/drivers/usb/host/ohci-da8xx.c
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -36,8 +37,12 @@ static int (*orig_ohci_hub_control)(struct usb_hcd  *hcd, 
u16 typeReq,
 static int (*orig_ohci_hub_status_data)(struct usb_hcd *hcd, char *buf);

 struct da8xx_ohci_hcd {
+   struct usb_hcd *hcd;
struct clk *usb11_clk;
struct phy *usb11_phy;
+   struct regulator *vbus_reg;
+   struct notifier_block nb;
+   unsigned int is_powered;


Since is_powered is only used to indicate if we have called 
regulator_enable(), I think it would make more sense to name it 
reg_enabled instead.



 };

 #define to_da8xx_ohci(hcd) (struct da8xx_ohci_hcd *)(hcd_to_ohci(hcd)->priv)
@@ -83,56 +88,103 @@ static void ohci_da8xx_disable(struct usb_hcd *hcd)

 static int ohci_da8xx_set_power(struct usb_hcd *hcd, int on)
 {
+   struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
struct device *dev  = hcd->self.controller;
struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
+   int ret;

if (hub && hub->set_power)
return hub->set_power(1, on);

+   if (!da8xx_ohci->vbus_reg)
+   return 0;
+
+   if (on && !da8xx_ohci->is_powered) {
+   ret = regulator_enable(da8xx_ohci->vbus_reg);
+   if (ret) {
+   dev_err(dev, "Fail to enable regulator: %d\n", ret);


s/Fail/Failed/


+   return ret;
+   }
+   da8xx_ohci->is_powered = 1;
+
+   } else if (!on && da8xx_ohci->is_powered) {
+   ret = regulator_disable(da8xx_ohci->vbus_reg);
+   if (ret) {
+   dev_err(dev, "Fail to disable regulator: %d\n", ret);


s/Fail/Failed/


+   return ret;
+   }
+   da8xx_ohci->is_powered = 0;
+   }
+
return 0;
 }

 static int ohci_da8xx_get_power(struct usb_hcd *hcd)
 {
+   struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
struct device *dev  = hcd->self.controller;
struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);

if (hub && hub->get_power)
return hub->get_power(1);

+   if (da8xx_ohci->vbus_reg)
+   return regulator_is_enabled(da8xx_ohci->vbus_reg);
+
return 1;
 }

 static int ohci_da8xx_get_oci(struct usb_hcd *hcd)
 {
+   struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
struct device *dev  = hcd->self.controller;
struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
+   unsigned int flags;
+   int ret;

if (hub && hub->get_oci)
return hub->get_oci(1);

+   if (!da8xx_ohci->vbus_reg)
+   return 0;
+
+   ret = regulator_get_error_flags(da8xx_ohci->vbus_reg, );
+   if (ret)
+   return ret;
+
+   if (flags && REGULATOR_ERROR_OVER_CURRENT)


Is this supposed to be...

if (flags & REGULATOR_ERROR_OVER_CURRENT)



+   return 1;
+
return 0;
 }

 static int ohci_da8xx_has_set_power(struct usb_hcd *hcd)
 {
+   struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
struct device *dev  = hcd->self.controller;
struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);

if (hub && hub->set_power)
return 1;

+   if (da8xx_ohci->vbus_reg)
+   return 1;
+
return 0;
 }

 static int ohci_da8xx_has_oci(struct usb_hcd *hcd)
 {
+   struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
struct device *dev  = hcd->self.controller;
struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);

if (hub && hub->get_oci)
return 1;

+   if (da8xx_ohci->vbus_reg)
+   return 1;
+
return 0;
 }

@@ -160,15 +212,41 @@ static void ohci_da8xx_ocic_handler(struct 
da8xx_ohci_root_hub *hub,
hub->set_power(port, 0);
 }

+static int ohci_da8xx_regulator_event(struct notifier_block *nb,
+   unsigned long event, void *data)

Re: [v5,1/5] USB: ohci: da8xx: use ohci priv data instead of globals

2016-11-19 Thread David Lechner

On 11/14/2016 08:40 AM, ahas...@baylibre.com wrote:

Instead of global variables, use the extra_priv_size of
the ohci driver.

We cannot yet move the ocic mask because this is used on
the interrupt handler which is registerded through platform
data and does not have an hcd pointer. This will be moved
on a later patch.

Signed-off-by: Axel Haslam <ahas...@baylibre.com>
---
 drivers/usb/host/ohci-da8xx.c | 73 +--
 1 file changed, 43 insertions(+), 30 deletions(-)

diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c
index b3de8bc..438970b 100644
--- a/drivers/usb/host/ohci-da8xx.c
+++ b/drivers/usb/host/ohci-da8xx.c

...

@@ -238,25 +246,29 @@ static int ohci_da8xx_probe(struct platform_device *pdev)
if (hub == NULL)
return -ENODEV;

-   usb11_clk = devm_clk_get(>dev, "usb11");
-   if (IS_ERR(usb11_clk)) {
-   if (PTR_ERR(usb11_clk) != -EPROBE_DEFER)
+   hcd = usb_create_hcd(_da8xx_hc_driver, >dev,
+   dev_name(>dev));
+   if (!hcd)
+   return -ENOMEM;
+
+   da8xx_ohci = to_da8xx_ohci(hcd);
+
+   da8xx_ohci->usb11_clk = devm_clk_get(>dev, "usb11");
+   if (IS_ERR(da8xx_ohci->usb11_clk)) {
+   if (PTR_ERR(da8xx_ohci->usb11_clk) != -EPROBE_DEFER)
dev_err(>dev, "Failed to get clock.\n");
-   return PTR_ERR(usb11_clk);
+   error = PTR_ERR(da8xx_ohci->usb11_clk);
+   goto err;
}


Small thing, but this could be written slightly cleaner as:

da8xx_ohci->usb11_clk = devm_clk_get(>dev, "usb11");
if (IS_ERR(da8xx_ohci->usb11_clk)) {
error = PTR_ERR(da8xx_ohci->usb11_clk);
if (error != -EPROBE_DEFER)
dev_err(>dev, "Failed to get clock.\n");
goto err;
}



-   usb11_phy = devm_phy_get(>dev, "usb-phy");
-   if (IS_ERR(usb11_phy)) {
-   if (PTR_ERR(usb11_phy) != -EPROBE_DEFER)
+   da8xx_ohci->usb11_phy = devm_phy_get(>dev, "usb-phy");
+   if (IS_ERR(da8xx_ohci->usb11_phy)) {
+   if (PTR_ERR(da8xx_ohci->usb11_phy) != -EPROBE_DEFER)
dev_err(>dev, "Failed to get phy.\n");
-   return PTR_ERR(usb11_phy);
+   error = PTR_ERR(da8xx_ohci->usb11_phy);
+   goto err;
}


same here

...


Tested-by: David Lechner <da...@lechnology.com>

--
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 3/4] usb: musb: Add a quirk flag to skip the phy set mode

2016-11-04 Thread David Lechner

On 11/04/2016 11:43 AM, Alexandre Bailon wrote:

During the init, the driver will use the mode to configure
the controller mode and the phy mode.
The PHY of DA8xx has some issues when the phy is forced in host or device.
Add way to skip the set mode and let the da8xx glue manage the phy mode.



I think you are on the right track here. But I think a cleaner way to do 
this would be to add a bool parameter to musb_platform_set_mode() that 
is passed musb->ops->set_mode() callback. You could call this parameter 
init or first_call or something like that. This way, the set_mode() 
callback can have a different behavior depending on when it is called.


In musb_init_controller(), for example, you would have...

status = musb_platform_set_mode(musb, MUSB_HOST, true);

and in musb_mode_store(), you would have...

status = musb_platform_set_mode(musb, MUSB_HOST, false);




Signed-off-by: Alexandre Bailon 
---
 drivers/usb/musb/musb_core.c | 15 ++-
 drivers/usb/musb/musb_core.h |  1 +
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 27dadc0..6f5f039 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -2046,6 +2046,7 @@ musb_init_controller(struct device *dev, int nIrq, void 
__iomem *ctrl)
 {
int status;
struct musb *musb;
+   enum musb_mode  mode = MUSB_UNDEFINED;
struct musb_hdrc_platform_data *plat = dev_get_platdata(dev);

/* The driver might handle more features than the board; OK.
@@ -2261,13 +2262,13 @@ musb_init_controller(struct device *dev, int nIrq, void 
__iomem *ctrl)
status = musb_host_setup(musb, plat->power);
if (status < 0)
goto fail3;
-   status = musb_platform_set_mode(musb, MUSB_HOST);
+   mode = MUSB_HOST;
break;
case MUSB_PORT_MODE_GADGET:
status = musb_gadget_setup(musb);
if (status < 0)
goto fail3;
-   status = musb_platform_set_mode(musb, MUSB_PERIPHERAL);
+   mode = MUSB_PERIPHERAL;
break;
case MUSB_PORT_MODE_DUAL_ROLE:
status = musb_host_setup(musb, plat->power);
@@ -2278,15 +2279,19 @@ musb_init_controller(struct device *dev, int nIrq, void 
__iomem *ctrl)
musb_host_cleanup(musb);
goto fail3;
}
-   status = musb_platform_set_mode(musb, MUSB_OTG);
+   mode = MUSB_OTG;
break;
default:
dev_err(dev, "unsupported port mode %d\n", musb->port_mode);
break;
}

-   if (status < 0)
-   goto fail3;
+   if (mode != MUSB_UNDEFINED &&
+   !(musb->io.quirks & MUSB_SKIP_SET_MODE)) {
+   status = musb_platform_set_mode(musb, mode);
+   if (status < 0)
+   goto fail3;
+   }

status = musb_init_debugfs(musb);
if (status < 0)
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 2cb88a49..9bd8b6b 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -172,6 +172,7 @@ struct musb_io;
  */
 struct musb_platform_ops {

+#define MUSB_SKIP_SET_MODE BIT(7)


This would be better described as MUSB_SKIP_SET_MODE_IN_INIT


 #define MUSB_DMA_UX500 BIT(6)
 #define MUSB_DMA_CPPI41BIT(5)
 #define MUSB_DMA_CPPI  BIT(4)



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


Re: [PATCH v3 3/5] dt/bindings: Add a new property to DA8xx USB PHY

2016-11-03 Thread David Lechner

On 11/03/2016 12:33 PM, Alexandre Bailon wrote:

On 11/03/2016 05:53 PM, David Lechner wrote:

On 11/03/2016 10:26 AM, Alexandre Bailon wrote:

The USB PHY is able to operate in OTG, host or peripheral.
Some board may be wired to work act only as host or peripheral.
In such case, the dr_mode property of controller must be set to
host or peripheral. But doing that will also configure the PHY
in host or peripheral mode whereas OTG is able to detect which
role the USB controller should take.
The PHY's host or peripheral mode are actually only useful when
hardware doesn't allow OTG to detect it's role.

Add the usb20_force_mode property to force the PHY to operate
in host or peripheral mode.


Device tree describes the hardware, not the configuration, so this is
not acceptable.

I think that is really hardware (and board) dependent.
We will only need to set it for unusual hardware that doesn't
let the otg phy automatically find the it's role.
What do you think I should do?


I am staring to think that maybe it was a mistake for me to add the mode 
setting to the phy driver. It is not very clear to me where the division 
is between what is the responsibility of the phy and what is the 
responsibility of the musb.


Looking at the bigger picture, forcing the PHY mode and never changing 
it is not useful. It is the transition from not forced to forced or vice 
versa that is important because it is at that moment that interrupts are 
triggered.


The forcing of a PHY mode is really being used to simulate the plugging 
or unplugging of a USB device. And the only reason you would need to do 
this is that the hardware lacks the proper circuitry between the USB 
connector and the SoC in order to detect such an event.


So, what I think you should do is try to get MUSB working with the PHY 
in OTG mode without worrying about forcing other PHY modes. Then once 
that has been sorted out, we can talk about how to handle quirks for 
hardware that needs it.




Besides, this setting should not be fixed to one value anyway.

Actually, a bool is enough. If we need to force the phy in a specific
mode, we can reuse dr_mode of controller.



When usb20_force_mode is used, dr_mode should also be configured
to host or peripheral.
The controller uses dr_mode to configure itself, but the phy use
it to get the mode to use to configure the PHY mode.

Signed-off-by: Alexandre Bailon <abai...@baylibre.com>
---
 Documentation/devicetree/bindings/phy/phy-da8xx-usb.txt | 5 +
 1 file changed, 5 insertions(+)

diff --git a/Documentation/devicetree/bindings/phy/phy-da8xx-usb.txt
b/Documentation/devicetree/bindings/phy/phy-da8xx-usb.txt
index c26478b..9fc87fb 100644
--- a/Documentation/devicetree/bindings/phy/phy-da8xx-usb.txt
+++ b/Documentation/devicetree/bindings/phy/phy-da8xx-usb.txt
@@ -4,6 +4,11 @@ Required properties:
  - compatible: must be "ti,da830-usb-phy".
  - #phy-cells: must be 1.

+Optional properties:
+- usb20-force-mode: Force the phy to operate in same mode than the
USB OTG controller.
+It should only be defined if the hardware is not capable
correctly
+detect the role of USB by using VBUS and ID pin.
+
 This device controls the PHY for both the USB 1.1 OHCI and USB 2.0 OTG
 controllers on DA8xx SoCs. Consumers of this device should use index
0 for
 the USB 2.0 phy device and index 1 for the USB 1.1 phy device.







--
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 v3 5/5] usb: musb: da8xx: Remove set_mode callback

2016-11-03 Thread David Lechner

On 11/03/2016 10:26 AM, Alexandre Bailon wrote:

The USB PHY is able to operate in OTG, host or peripheral.
Some board may be wired to work act only as host or peripheral.
In such case, the dr_mode property of controller must be set to
host or peripheral. But doing that will also configure the PHY
in host or peripheral mode whereas OTG is able to detect which
role the USB controller should take.
The PHY's host or peripheral mode are actually only useful when
hardware doesn't allow OTG to detect it's role.

The set_mode callback is used by the musb driver to set mode
of the PHY. But in the case of DA8xx, the PHY have some issues.
The OTG mode work correctly but the host and peripheral don't.
In host mode, the PHY stops to work after the first disconnect.
In device mode, the PHY doesn't detect any disconnect.
As the OTG mode is working properly, let the PHY in OTG mode,
whatever is the controller mode.

Signed-off-by: Alexandre Bailon 
---
 drivers/usb/musb/da8xx.c | 23 ---
 1 file changed, 23 deletions(-)

diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 6749aa1..581f830 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -335,28 +335,6 @@ static irqreturn_t da8xx_musb_interrupt(int irq, void *hci)
return ret;
 }

-static int da8xx_musb_set_mode(struct musb *musb, u8 musb_mode)


Bin suggested using some sort of quirks flag. So instead of removing 
this callback, I think this is where to incorporate the quirks flags.


I suppose the quirks could be kernel config options. Perhaps someone 
else has a better idea?



-{
-   struct da8xx_glue *glue = dev_get_drvdata(musb->controller->parent);
-   enum phy_mode phy_mode;
-
-   switch (musb_mode) {
-   case MUSB_HOST: /* Force VBUS valid, ID = 0 */
-   phy_mode = PHY_MODE_USB_HOST;


this should be something like...

phy_mode = force_host_mode_quirk ? PHY_MODE_USB_HOST
 : PHY_MODE_USB_OTG;



-   break;
-   case MUSB_PERIPHERAL:   /* Force VBUS valid, ID = 1 */
-   phy_mode = PHY_MODE_USB_DEVICE;


and...

phy_mode = force_peripheral_mode_quirk ?
PHY_MODE_USB_DEVICE : PHY_MODE_USB_OTG;



-   break;
-   case MUSB_OTG:  /* Don't override the VBUS/ID comparators */
-   phy_mode = PHY_MODE_USB_OTG;
-   break;
-   default:
-   return -EINVAL;
-   }
-
-   return phy_set_mode(glue->phy, phy_mode);
-}
-
 static int da8xx_musb_init(struct musb *musb)
 {
struct da8xx_glue *glue = dev_get_drvdata(musb->controller->parent);
@@ -445,7 +423,6 @@ static const struct musb_platform_ops da8xx_ops = {
.enable = da8xx_musb_enable,
.disable= da8xx_musb_disable,

-   .set_mode   = da8xx_musb_set_mode,
.try_idle   = da8xx_musb_try_idle,

.set_vbus   = da8xx_musb_set_vbus,



--
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 v3 2/5] phy: da8xx-usb: Configure CFGCHIP2 to support OTG workaround

2016-11-03 Thread David Lechner

On 11/03/2016 10:26 AM, Alexandre Bailon wrote:

If we configure the da8xx OTG phy in OTG mode, neither device or host
mode will work. That is because the PHY is not able to detect and notify
the driver that value of ID pin changed.
To work despite this hardware limitation, the da8xx glue implement a
workaround.
But to work, the workaround require the VBUS sense and the session end
comparator to enabled.
Enable them if the phy is configured in OTG mode.

Signed-off-by: Alexandre Bailon 
---
 drivers/phy/phy-da8xx-usb.c | 17 -
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/phy/phy-da8xx-usb.c b/drivers/phy/phy-da8xx-usb.c
index 32ae78c..fd39292 100644
--- a/drivers/phy/phy-da8xx-usb.c
+++ b/drivers/phy/phy-da8xx-usb.c
@@ -93,24 +93,31 @@ static int da8xx_usb20_phy_power_off(struct phy *phy)
 static int da8xx_usb20_phy_set_mode(struct phy *phy, enum phy_mode mode)
 {
struct da8xx_usb_phy *d_phy = phy_get_drvdata(phy);
+   int ret;
u32 val;

+   ret = regmap_read(d_phy->regmap, CFGCHIP(2), );
+   if (ret)
+   return ret;
+
+   val &= ~CFGCHIP2_OTGMODE_MASK;
+
switch (mode) {
case PHY_MODE_USB_HOST: /* Force VBUS valid, ID = 0 */
-   val = CFGCHIP2_OTGMODE_FORCE_HOST;
+   val |= CFGCHIP2_OTGMODE_FORCE_HOST;
break;
case PHY_MODE_USB_DEVICE:   /* Force VBUS valid, ID = 1 */
-   val = CFGCHIP2_OTGMODE_FORCE_DEVICE;
+   val |= CFGCHIP2_OTGMODE_FORCE_DEVICE;
break;
case PHY_MODE_USB_OTG:  /* Don't override the VBUS/ID comparators */
-   val = CFGCHIP2_OTGMODE_NO_OVERRIDE;
+   val |= CFGCHIP2_OTGMODE_NO_OVERRIDE |
+   CFGCHIP2_SESENDEN | CFGCHIP2_VBDTCTEN;


I still think this is wrong that you set these bits but never clear 
them. For example, if you start in host mode, these bits will not bit 
set, but if you start in otg mode and switch to host mode, these bits 
will still be set.


And I still think that these bits (CFGCHIP2_SESENDEN | 
CFGCHIP2_VBDTCTEN) should just be enabled during driver probe rather 
than here since I don't know of a reason to turn them off.



break;
default:
return -EINVAL;
}

-   regmap_write_bits(d_phy->regmap, CFGCHIP(2), CFGCHIP2_OTGMODE_MASK,
- val);
+   regmap_write(d_phy->regmap, CFGCHIP(2), val);

return 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 v3 3/5] dt/bindings: Add a new property to DA8xx USB PHY

2016-11-03 Thread David Lechner

On 11/03/2016 10:26 AM, Alexandre Bailon wrote:

The USB PHY is able to operate in OTG, host or peripheral.
Some board may be wired to work act only as host or peripheral.
In such case, the dr_mode property of controller must be set to
host or peripheral. But doing that will also configure the PHY
in host or peripheral mode whereas OTG is able to detect which
role the USB controller should take.
The PHY's host or peripheral mode are actually only useful when
hardware doesn't allow OTG to detect it's role.

Add the usb20_force_mode property to force the PHY to operate
in host or peripheral mode.


Device tree describes the hardware, not the configuration, so this is 
not acceptable.


Besides, this setting should not be fixed to one value anyway.


When usb20_force_mode is used, dr_mode should also be configured
to host or peripheral.
The controller uses dr_mode to configure itself, but the phy use
it to get the mode to use to configure the PHY mode.

Signed-off-by: Alexandre Bailon 
---
 Documentation/devicetree/bindings/phy/phy-da8xx-usb.txt | 5 +
 1 file changed, 5 insertions(+)

diff --git a/Documentation/devicetree/bindings/phy/phy-da8xx-usb.txt 
b/Documentation/devicetree/bindings/phy/phy-da8xx-usb.txt
index c26478b..9fc87fb 100644
--- a/Documentation/devicetree/bindings/phy/phy-da8xx-usb.txt
+++ b/Documentation/devicetree/bindings/phy/phy-da8xx-usb.txt
@@ -4,6 +4,11 @@ Required properties:
  - compatible: must be "ti,da830-usb-phy".
  - #phy-cells: must be 1.

+Optional properties:
+- usb20-force-mode: Force the phy to operate in same mode than the USB OTG 
controller.
+   It should only be defined if the hardware is not capable 
correctly
+   detect the role of USB by using VBUS and ID pin.
+
 This device controls the PHY for both the USB 1.1 OHCI and USB 2.0 OTG
 controllers on DA8xx SoCs. Consumers of this device should use index 0 for
 the USB 2.0 phy device and index 1 for the USB 1.1 phy device.



--
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/3] davinci: ohci: fix usb ohci device name

2016-11-03 Thread David Lechner

On 11/03/2016 11:03 AM, Axel Haslam wrote:

The usb ohci clock match is not working because the usb clock
is registered as "ohci" instead of "ohci.0"

But since there is only a single ohci instance, lets pass -1 to
the platform data id parameter and avoid the extra ".0" matching.

while we are fixing this, rename the driver from "ohci" to
"ohci-da8xx" which  is less generic and consistent with other
usb drivers.

changes form v1 -> v2
*Reword commit messages (David Lechner)

Because of the recently accepted patches on the ARM-davinci side,
This patch series is based on:
branch: /v4.10/soc of the linux-davinci tree.

It Depends on two accepted usb patches missing on that branch:
6c21caa USB: OHCI: make ohci-da8xx a separate driver (in next-usb)
6110c42 usb: ohci-da8xx: Remove code that references mach (in linux-next)

A branch with both patches applied + this series can be found here:
https://github.com/axelhaslamx/linux-axel/commits/ti-davinci-ohci-rename


Axel Haslam (3):
  ARM: davinci: da8xx: Fix ohci device name
  phy: da8xx-usb: rename the ohci device to ohci-da8xx
  usb: ohci-da8xx: rename driver to ohci-da8xx

 arch/arm/mach-davinci/da830.c | 2 +-
 arch/arm/mach-davinci/da850.c | 2 +-
 arch/arm/mach-davinci/da8xx-dt.c  | 2 +-
 arch/arm/mach-davinci/usb-da8xx.c | 4 ++--
 drivers/phy/phy-da8xx-usb.c   | 5 +++--
 drivers/usb/host/ohci-da8xx.c | 2 +-
 6 files changed, 9 insertions(+), 8 deletions(-)



Thanks for making the changes. The commit messages make better sense to 
me now. :-)

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


Re: [PATCH 3/3] usb: ohci-da8xx: rename driver to ohci-da8xx

2016-11-02 Thread David Lechner

On 11/02/2016 07:44 AM, Axel Haslam wrote:

To be consistent on the usb driver for the davinci
platform follow the example of musb, and add the
"-da8xx" postfix to the driver name.



It is probably worth mentioning that the existing driver name is "ohci" 
which is a bit too generic.


--
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/3] phy: da8xx-usb: rename the ohci device to ohci-da8xx

2016-11-02 Thread David Lechner

On 11/02/2016 07:44 AM, Axel Haslam wrote:

There is only one ohci on the da8xx series of chips,
so remove the ".0" when creating the phy. Also add
the "-da8xx" postfix to be consistent across davinci
usb drivers.


It would be more accurate to say that the device name is being changed 
in the mach board configuration files, so it is being changed here in 
the lookup table to match the new name.




Signed-off-by: Axel Haslam 
---


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


Re: [PATCH 1/3] ARM: davinci: da8xx: Fix ohci driver name

2016-11-02 Thread David Lechner

On 11/02/2016 07:44 AM, Axel Haslam wrote:

There is a single instance of the ohci driver,
while the clk lookup table is making reference to "ohci"
other subsystems (such as phy) are looking for "ohci.0"



This patch changes the "device" name, not the "driver" name. You use 
"driver" above and in the subject.



Since there is a single ohci instance, change the dev id
to -1, and add the "-da8xx" for consitancy with the musb
driver name.


It would be more accurate to say that you are adding "-da8xx" because 
you are also changing the ohci _driver_ name in a separate patch.




Signed-off-by: Axel Haslam 
---



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


Re: [PATCH v2 3/3] usb: musb: da8xx: Only execute the OTG workaround when phy in OTG mode

2016-10-28 Thread David Lechner

On 10/28/2016 07:39 AM, Alexandre Bailon wrote:

On 10/28/2016 04:56 AM, David Lechner wrote:

On 10/26/2016 05:58 AM, Alexandre Bailon wrote:

When the phy is forced in host mode, only the first hot plug and
hot remove works. That is actually because the driver execute the
OTG workaround, whereas it is not applicable in host or device mode.
Indeed, to work correctly, the VBUS sense and session end comparator
must be enabled, what is only possible when the phy is in OTG mode.
Only execute the workaround if the phy is in OTG mode.

Signed-off-by: Alexandre Bailon <abai...@baylibre.com>
---
 drivers/usb/musb/da8xx.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 6749aa1..b8a6b65 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -145,6 +145,17 @@ static void otg_timer(unsigned long _musb)
 unsigned longflags;

 /*
+ * We should only execute the OTG workaround when the phy is in OTG
+ * mode. The workaround require the VBUS sense and the session end
+ * comparator to be enabled, what is only possible if the phy is in
+ * OTG mode. As the workaround is only required to detect if the
+ * controller must act as host or device, we can safely exit OTG is
+ * not in use.
+ */
+if (musb->port_mode != MUSB_PORT_MODE_DUAL_ROLE)


musb->port_mode is not valid if we have changed the mode via sysfs. It
only reflects the mode set during driver probe.

Furthermore, this breaks the host mode completely for me. The first hot
plug is not even detected.


+return;
+
+/*
  * We poll because DaVinci's won't expose several OTG-critical
  * status change events (from the transceiver) otherwise.
  */




The way this is working for me (on AM1808) is this:

The problem is not that the OTG workaround is being used. The problem is
that after disconnect, the VBUSDRV is turned off. If you look at the
handler for DA8XX_INTR_DRVVBUS in da8xx_musb_interrupt(), you will see
that if VBUSDRV is off, then drvvbus == 0, which puts the musb state
back to device mode.

I also ran into a similar problem a while back[1] that if you use a
self-powered device in host mode, it immediately becomes disconnected.
This is for the exact same reason. When a port detects a self-powered
device, it turns of VBUSDRV, which triggers the DA8XX_INTR_DRVVBUS
interrupt. As we have seen above, this takes the port out of host mode.

The workaround that I have found that seems to fix both cases is to add
and else if statement that toggles the PHY host override when we are
forcing host mode and the VBUSDRV is turned off.

I like this workaround.


Here is a partial diff of drivers/usb/musb/da8xx.c to show what I mean:

@@ -304,10 +309,14 @@ static irqreturn_t da8xx_musb_interrupt(int irq,
void *hci)
 * Also, DRVVBUS pulses for SRP (but not at 5 V)...
 */
if (status & (DA8XX_INTR_DRVVBUS << DA8XX_INTR_USB_SHIFT)) {
+   struct da8xx_glue *glue =
+   dev_get_drvdata(musb->controller->parent);
int drvvbus = musb_readl(reg_base, DA8XX_USB_STAT_REG);
void __iomem *mregs = musb->mregs;
u8 devctl = musb_readb(mregs, MUSB_DEVCTL);
-   int err;
+   int cfgchip2, err;
+
+   regmap_read(glue->cfgchip, CFGCHIP(2), );

err = musb->int_usb & MUSB_INTR_VBUSERROR;
if (err) {
@@ -332,10 +341,25 @@ static irqreturn_t da8xx_musb_interrupt(int irq,
void *hci)
musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
portstate(musb->port1_status |=
USB_PORT_STAT_POWER);
del_timer(_workaround);
+   } else if ((cfgchip2 & CFGCHIP2_OTGMODE_MASK)
+  == CFGCHIP2_OTGMODE_FORCE_HOST) {
+   /*
+* If we are forcing host mode, VBUSDRV is
turned off
+* after a device is disconnected. We need to
toggle the
+* VBUS/ID override to trigger turn it back on,
which
+* has the effect of triggering
DA8XX_INTR_DRVVBUS again.
+*/
+   regmap_write_bits(glue->cfgchip, CFGCHIP(2),
+   CFGCHIP2_OTGMODE_MASK,
+   CFGCHIP2_OTGMODE_NO_OVERRIDE);
+   regmap_write_bits(glue->cfgchip, CFGCHIP(2),
+   CFGCHIP2_OTGMODE_MASK,
+   CFGCHIP2_OTGMODE_FORCE_HOST);
} else {
musb->is_active = 0;
MUSB_DEV_MODE(musb);


I haven't thought to this workaround.
Actually, my goal with this patch was to prevent VBUSDRV to be turned
off. When I hit the issues, I captured some tr

Re: [PATCH v2 0/3] usb: musb: da8xx: Fix few issues

2016-10-28 Thread David Lechner

On 10/28/2016 04:31 AM, Alexandre Bailon wrote:

On 10/27/2016 08:44 PM, David Lechner wrote:

On 10/27/2016 12:16 PM, David Lechner wrote:

On 10/26/2016 05:58 AM, Alexandre Bailon wrote:

Currently, the USB OTG of the da8xx doesn't work.
This series intend to fix them.

Change in v2:
* Fix the error path da8xx_musb_init()

Alexandre Bailon (3):
  usb: musb: da8xx: Call earlier clk_prepare_enable()
  phy: da8xx-usb: Configure CFGCHIP2 to support OTG workaround
  usb: musb: da8xx: Only execute the OTG workaround when phy in OTG mode

 drivers/phy/phy-da8xx-usb.c | 17 -
 drivers/usb/musb/da8xx.c| 28 +++-
 2 files changed, 31 insertions(+), 14 deletions(-)



I have found another problem with peripheral mode. When we force
peripheral mode, the glue layer currently uses CFGCHIP2 to override the
VBUS and ID. This causes it to not be able to detect disconnection
because the VBUS is overridden.

How have you found it ? Does it cause any issues ?
I mean I had to enable traces to see that disconnect was not happening.


I am also using the device tree patch series. I specified dr_mode = 
"peripheral" in my device tree because the device is only wired for use 
as a peripheral port.


I have actually known about this issue for a long time. See
<https://github.com/ev3dev/ev3dev/issues/244> and 
<http://e2e.ti.com/support/embedded/linux/f/354/p/65332/237094#2370942>





Here is a patch to fix the problem. I have tested this on LEGO
MINDSTORMS EV3 (AM1808). This works because the ID pin is internally
pulled up on the SoC, so we don't need to override it.

Actually, I'm wonder if that if not related to VBUS sensing.
May be we should set CFGCHIP2_VBDTCTEN in device mode.


Yes, as we discussed in another thread, we should set CFGCHIP2_VBDTCTEN 
and CFGCHIP2_SESNDEN *always* regardless of mode. I still have the 
problem described above with these two enabled if and only if we are 
also setting CFGCHIP2_OTG_FORCE_PERIPHERAL.




---

diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 2bc12a2..33daa3b 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -374,9 +374,7 @@ static int da8xx_musb_set_mode(struct musb *musb, u8
musb_mode)
case MUSB_HOST: /* Force VBUS valid, ID = 0 */
phy_mode = PHY_MODE_USB_HOST;
break;
-   case MUSB_PERIPHERAL:   /* Force VBUS valid, ID = 1 */
-   phy_mode = PHY_MODE_USB_DEVICE;
-   break;
+   case MUSB_PERIPHERAL:
case MUSB_OTG:  /* Don't override the VBUS/ID
comparators */
phy_mode = PHY_MODE_USB_OTG;
break;

---

If this works for other SoCs/boards, I think we should make this change.
If it doesn't work, we could work around the VBUS problem by polling
VBUSSENSE in CFGCHIP2. But, I like the simple solution above better.


I have realized that due to the way my device is wired, I can actually
use OTG mode and it will behave exactly as peripheral mode because the
ID pin is not connected. So, maybe this patch is not needed after all.


Actually, I'm sure that is related to ID


The ID pin on my device is not connected, so I don't think this has to 
do with ID. It is always high (internally pulled up).



I have the same issue except the disconnect is called when I use the
OTG mode.



This is exactly the behavior I am seeing.

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


Re: [PATCH v2 3/3] usb: musb: da8xx: Only execute the OTG workaround when phy in OTG mode

2016-10-27 Thread David Lechner

On 10/26/2016 05:58 AM, Alexandre Bailon wrote:

When the phy is forced in host mode, only the first hot plug and
hot remove works. That is actually because the driver execute the
OTG workaround, whereas it is not applicable in host or device mode.
Indeed, to work correctly, the VBUS sense and session end comparator
must be enabled, what is only possible when the phy is in OTG mode.
Only execute the workaround if the phy is in OTG mode.

Signed-off-by: Alexandre Bailon 
---
 drivers/usb/musb/da8xx.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 6749aa1..b8a6b65 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -145,6 +145,17 @@ static void otg_timer(unsigned long _musb)
unsigned long   flags;

/*
+* We should only execute the OTG workaround when the phy is in OTG
+* mode. The workaround require the VBUS sense and the session end
+* comparator to be enabled, what is only possible if the phy is in
+* OTG mode. As the workaround is only required to detect if the
+* controller must act as host or device, we can safely exit OTG is
+* not in use.
+*/
+   if (musb->port_mode != MUSB_PORT_MODE_DUAL_ROLE)


musb->port_mode is not valid if we have changed the mode via sysfs. It 
only reflects the mode set during driver probe.


Furthermore, this breaks the host mode completely for me. The first hot 
plug is not even detected.



+   return;
+
+   /*
 * We poll because DaVinci's won't expose several OTG-critical
 * status change events (from the transceiver) otherwise.
 */




The way this is working for me (on AM1808) is this:

The problem is not that the OTG workaround is being used. The problem is 
that after disconnect, the VBUSDRV is turned off. If you look at the 
handler for DA8XX_INTR_DRVVBUS in da8xx_musb_interrupt(), you will see 
that if VBUSDRV is off, then drvvbus == 0, which puts the musb state 
back to device mode.


I also ran into a similar problem a while back[1] that if you use a 
self-powered device in host mode, it immediately becomes disconnected. 
This is for the exact same reason. When a port detects a self-powered 
device, it turns of VBUSDRV, which triggers the DA8XX_INTR_DRVVBUS 
interrupt. As we have seen above, this takes the port out of host mode.


The workaround that I have found that seems to fix both cases is to add 
and else if statement that toggles the PHY host override when we are 
forcing host mode and the VBUSDRV is turned off.


Here is a partial diff of drivers/usb/musb/da8xx.c to show what I mean:

@@ -304,10 +309,14 @@ static irqreturn_t da8xx_musb_interrupt(int irq, 
void *hci)

 * Also, DRVVBUS pulses for SRP (but not at 5 V)...
 */
if (status & (DA8XX_INTR_DRVVBUS << DA8XX_INTR_USB_SHIFT)) {
+   struct da8xx_glue *glue =
+   dev_get_drvdata(musb->controller->parent);
int drvvbus = musb_readl(reg_base, DA8XX_USB_STAT_REG);
void __iomem *mregs = musb->mregs;
u8 devctl = musb_readb(mregs, MUSB_DEVCTL);
-   int err;
+   int cfgchip2, err;
+
+   regmap_read(glue->cfgchip, CFGCHIP(2), );

err = musb->int_usb & MUSB_INTR_VBUSERROR;
if (err) {
@@ -332,10 +341,25 @@ static irqreturn_t da8xx_musb_interrupt(int irq, 
void *hci)

musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
portstate(musb->port1_status |= 
USB_PORT_STAT_POWER);

del_timer(_workaround);
+   } else if ((cfgchip2 & CFGCHIP2_OTGMODE_MASK)
+  == CFGCHIP2_OTGMODE_FORCE_HOST) {
+   /*
+* If we are forcing host mode, VBUSDRV is 
turned off
+* after a device is disconnected. We need to 
toggle the
+* VBUS/ID override to trigger turn it back on, 
which
+* has the effect of triggering 
DA8XX_INTR_DRVVBUS again.

+*/
+   regmap_write_bits(glue->cfgchip, CFGCHIP(2),
+   CFGCHIP2_OTGMODE_MASK,
+   CFGCHIP2_OTGMODE_NO_OVERRIDE);
+   regmap_write_bits(glue->cfgchip, CFGCHIP(2),
+   CFGCHIP2_OTGMODE_MASK,
+   CFGCHIP2_OTGMODE_FORCE_HOST);
} else {
musb->is_active = 0;
MUSB_DEV_MODE(musb);

--
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/3] usb: musb: da8xx: Fix few issues

2016-10-27 Thread David Lechner

On 10/27/2016 12:16 PM, David Lechner wrote:

On 10/26/2016 05:58 AM, Alexandre Bailon wrote:

Currently, the USB OTG of the da8xx doesn't work.
This series intend to fix them.

Change in v2:
* Fix the error path da8xx_musb_init()

Alexandre Bailon (3):
  usb: musb: da8xx: Call earlier clk_prepare_enable()
  phy: da8xx-usb: Configure CFGCHIP2 to support OTG workaround
  usb: musb: da8xx: Only execute the OTG workaround when phy in OTG mode

 drivers/phy/phy-da8xx-usb.c | 17 -
 drivers/usb/musb/da8xx.c| 28 +++-
 2 files changed, 31 insertions(+), 14 deletions(-)



I have found another problem with peripheral mode. When we force
peripheral mode, the glue layer currently uses CFGCHIP2 to override the
VBUS and ID. This causes it to not be able to detect disconnection
because the VBUS is overridden.

Here is a patch to fix the problem. I have tested this on LEGO
MINDSTORMS EV3 (AM1808). This works because the ID pin is internally
pulled up on the SoC, so we don't need to override it.

---

diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 2bc12a2..33daa3b 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -374,9 +374,7 @@ static int da8xx_musb_set_mode(struct musb *musb, u8
musb_mode)
case MUSB_HOST: /* Force VBUS valid, ID = 0 */
phy_mode = PHY_MODE_USB_HOST;
break;
-   case MUSB_PERIPHERAL:   /* Force VBUS valid, ID = 1 */
-   phy_mode = PHY_MODE_USB_DEVICE;
-   break;
+   case MUSB_PERIPHERAL:
case MUSB_OTG:  /* Don't override the VBUS/ID
comparators */
phy_mode = PHY_MODE_USB_OTG;
break;

---

If this works for other SoCs/boards, I think we should make this change.
If it doesn't work, we could work around the VBUS problem by polling
VBUSSENSE in CFGCHIP2. But, I like the simple solution above better.


I have realized that due to the way my device is wired, I can actually 
use OTG mode and it will behave exactly as peripheral mode because the 
ID pin is not connected. So, maybe this patch is not needed after all.


--
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/3] usb: musb: da8xx: Fix few issues

2016-10-27 Thread David Lechner

On 10/26/2016 05:58 AM, Alexandre Bailon wrote:

Currently, the USB OTG of the da8xx doesn't work.
This series intend to fix them.

Change in v2:
* Fix the error path da8xx_musb_init()

Alexandre Bailon (3):
  usb: musb: da8xx: Call earlier clk_prepare_enable()
  phy: da8xx-usb: Configure CFGCHIP2 to support OTG workaround
  usb: musb: da8xx: Only execute the OTG workaround when phy in OTG mode

 drivers/phy/phy-da8xx-usb.c | 17 -
 drivers/usb/musb/da8xx.c| 28 +++-
 2 files changed, 31 insertions(+), 14 deletions(-)



I have found another problem with peripheral mode. When we force 
peripheral mode, the glue layer currently uses CFGCHIP2 to override the 
VBUS and ID. This causes it to not be able to detect disconnection 
because the VBUS is overridden.


Here is a patch to fix the problem. I have tested this on LEGO 
MINDSTORMS EV3 (AM1808). This works because the ID pin is internally 
pulled up on the SoC, so we don't need to override it.


---

diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 2bc12a2..33daa3b 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -374,9 +374,7 @@ static int da8xx_musb_set_mode(struct musb *musb, u8 
musb_mode)

case MUSB_HOST: /* Force VBUS valid, ID = 0 */
phy_mode = PHY_MODE_USB_HOST;
break;
-   case MUSB_PERIPHERAL:   /* Force VBUS valid, ID = 1 */
-   phy_mode = PHY_MODE_USB_DEVICE;
-   break;
+   case MUSB_PERIPHERAL:
case MUSB_OTG:  /* Don't override the VBUS/ID 
comparators */

phy_mode = PHY_MODE_USB_OTG;
break;

---

If this works for other SoCs/boards, I think we should make this change. 
If it doesn't work, we could work around the VBUS problem by polling 
VBUSSENSE in CFGCHIP2. But, I like the simple solution above better.

--
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 2/4] usb: musb: core: added helper function for parsing DT

2016-10-26 Thread David Lechner

On 10/26/2016 10:03 AM, Alexandre Bailon wrote:

From: Petr Kulhavy <p...@barix.com>

This adds the function musb_get_mode() to get the DT property "dr_mode"

Signed-off-by: Petr Kulhavy <p...@barix.com>
Acked-by: Sergei Shtylyov <sshtyl...@ru.mvista.com>
Signed-off-by: Alexandre Bailon <abai...@baylibre.com>
---
 drivers/usb/musb/musb_core.c | 19 +++
 drivers/usb/musb/musb_core.h |  5 +
 2 files changed, 24 insertions(+)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 27dadc0..bba07e7 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -100,6 +100,7 @@
 #include 
 #include 
 #include 
+#include 

 #include "musb_core.h"
 #include "musb_trace.h"
@@ -130,6 +131,24 @@ static inline struct musb *dev_to_musb(struct device *dev)
return dev_get_drvdata(dev);
 }

+enum musb_mode musb_get_mode(struct device *dev)
+{
+   enum usb_dr_mode mode;
+
+   mode = usb_get_dr_mode(dev);
+   switch (mode) {
+   case USB_DR_MODE_HOST:
+   return MUSB_HOST;
+   case USB_DR_MODE_PERIPHERAL:
+   return MUSB_PERIPHERAL;
+   case USB_DR_MODE_OTG:
+   case USB_DR_MODE_UNKNOWN:
+   default:
+   return MUSB_OTG;
+   }
+}
+EXPORT_SYMBOL_GPL(musb_get_mode);
+
 /*-*/

 #ifndef CONFIG_BLACKFIN
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 2cb88a49..a406468 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -617,4 +617,9 @@ static inline void musb_platform_post_root_reset_end(struct 
musb *musb)
musb->ops->post_root_reset_end(musb);
 }

+/* gets the "dr_mode" property from DT and converts it into musb_mode
+ * if the property is not found or not recognized returns MUSB_OTG
+ */
+extern enum musb_mode musb_get_mode(struct device *dev);
+
 #endif /* __MUSB_CORE_H__ */



Tested working on LEGO MINDSTORMS EV3 using dr_mode = "peripheral" and 
no vbus-supply.


Tested-By: David Lechner <da...@lechnology.com>
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 3/4] usb: musb: da8xx: Add DT support for the DA8xx driver

2016-10-26 Thread David Lechner

On 10/26/2016 10:03 AM, Alexandre Bailon wrote:

From: Petr Kulhavy <p...@barix.com>

This adds DT support for TI DA8xx/OMAP-L1x/AM17xx/AM18xx MUSB driver

Signed-off-by: Petr Kulhavy <p...@barix.com>
Signed-off-by: Alexandre Bailon <abai...@baylibre.com>
---
 drivers/usb/musb/da8xx.c | 47 +++
 1 file changed, 47 insertions(+)

diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 210b7e4..bfa571d 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -6,6 +6,9 @@
  * Based on the DaVinci "glue layer" code.
  * Copyright (C) 2005-2006 by Texas Instruments
  *
+ * DT support
+ * Copyright (c) 2016 Petr Kulhavy <p...@barix.com>
+ *
  * This file is part of the Inventra Controller Driver for Linux.
  *
  * The Inventra Controller Driver for Linux is free software; you
@@ -433,6 +436,21 @@ static int da8xx_musb_exit(struct musb *musb)
return 0;
 }

+static inline u8 get_vbus_power(struct device *dev)
+{
+   struct regulator *vbus_supply;
+   int current_uA;
+
+   vbus_supply = regulator_get_optional(dev, "vbus");
+   if (IS_ERR(vbus_supply))
+   return 255;
+   current_uA = regulator_get_current_limit(vbus_supply);
+   regulator_put(vbus_supply);
+   if (current_uA <= 0 || current_uA > 51)
+   return 255;
+   return current_uA / 1000 / 2;
+}
+
 static const struct musb_platform_ops da8xx_ops = {
.quirks = MUSB_DMA_CPPI | MUSB_INDEXED_EP,
.init   = da8xx_musb_init,
@@ -458,6 +476,12 @@ static const struct platform_device_info da8xx_dev_info = {
.dma_mask   = DMA_BIT_MASK(32),
 };

+static const struct musb_hdrc_config da8xx_config = {
+   .ram_bits = 10,
+   .num_eps = 5,
+   .multipoint = 1,
+};
+
 static int da8xx_probe(struct platform_device *pdev)
 {
struct resource musb_resources[2];
@@ -465,7 +489,9 @@ static int da8xx_probe(struct platform_device *pdev)
struct da8xx_glue   *glue;
struct platform_device_info pinfo;
struct clk  *clk;
+   struct device_node  *np = pdev->dev.of_node;
int ret;
+   struct resource *res;


res is not used anywhere



glue = devm_kzalloc(>dev, sizeof(*glue), GFP_KERNEL);
if (!glue)
@@ -486,6 +512,18 @@ static int da8xx_probe(struct platform_device *pdev)
glue->dev= >dev;
glue->clk= clk;

+   if (IS_ENABLED(CONFIG_OF) && np) {
+   pdata = devm_kzalloc(>dev, sizeof(*pdata), GFP_KERNEL);
+   if (!pdata) {
+   /* FIXME */


Why FIXME? I don't see anything that needs to be fixed here.


+   return -ENOMEM;
+   }
+
+   pdata->config= _config;
+   pdata->mode  = musb_get_mode(>dev);
+   pdata->power = get_vbus_power(>dev);
+   }
+
pdata->platform_ops  = _ops;

glue->usb_phy = usb_phy_generic_register();
@@ -536,11 +574,20 @@ static int da8xx_remove(struct platform_device *pdev)
return 0;
 }



Shouldn't you have #ifdef CONFIG_OF here since you are using 
of_match_ptr() below?



+static const struct of_device_id da8xx_id_table[] = {
+   {
+   .compatible = "ti,da830-musb",
+   },
+   {},
+};
+MODULE_DEVICE_TABLE(of, da8xx_id_table);


#endif


+
 static struct platform_driver da8xx_driver = {
.probe  = da8xx_probe,
.remove = da8xx_remove,
.driver = {
.name   = "musb-da8xx",
+   .of_match_table = of_match_ptr(da8xx_id_table),
    },
 };




Tested working on LEGO MINDSTORMS EV3 using dr_mode = "peripheral" and 
no vbus-supply.


Tested-By: David Lechner <da...@lechnology.com>

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


Re: [PATCH] USB: OHCI: make ohci-da8xx a separate driver

2016-10-26 Thread David Lechner

On 10/26/2016 04:08 PM, ahas...@baylibre.com wrote:

From: Manjunath Goudar <manjunath.gou...@linaro.org>

Separate the Davinci OHCI host controller driver from ohci-hcd
host code so that it can be built as a separate driver module.
This work is part of enabling multi-platform kernels on ARM

Signed-off-by: Manjunath Goudar <manjunath.gou...@linaro.org>
[Axel: adapted and rebased, fixed minor comments]
Signed-off-by: Axel Haslam <ahas...@baylibre.com>
---


This is working for me as a module on LEGO MINDSTORMS EV3.

Tested-By: David Lechner <da...@lechnology.com>

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


Re: [PATCH] USB: OHCI: make ohci-da8xx a separate driver

2016-10-26 Thread David Lechner

On 10/26/2016 04:08 PM, ahas...@baylibre.com wrote:


+module_exit(ohci_da8xx_exit);
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL");
 MODULE_ALIAS("platform:ohci");


The "ohci" in MODULE_ALIAS() should also be replaced with hcd_name.


--
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 2/3] phy: da8xx-usb: Configure CFGCHIP2 to support OTG workaround

2016-10-26 Thread David Lechner

On 10/26/2016 05:58 AM, Alexandre Bailon wrote:

If we configure the da8xx OTG phy in OTG mode, neither device or host
mode will work. That is because the PHY is not able to detect and notify
the driver that value of ID pin changed.
To work despite this hardware limitation, the da8xx glue implement a
workaround.
But to work, the workaround require the VBUS sense and the session end
comparator to enabled.
Enable them if the phy is configured in OTG mode.

Signed-off-by: Alexandre Bailon 
---
 drivers/phy/phy-da8xx-usb.c | 17 -
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/phy/phy-da8xx-usb.c b/drivers/phy/phy-da8xx-usb.c
index 32ae78c..fd39292 100644
--- a/drivers/phy/phy-da8xx-usb.c
+++ b/drivers/phy/phy-da8xx-usb.c
@@ -93,24 +93,31 @@ static int da8xx_usb20_phy_power_off(struct phy *phy)
 static int da8xx_usb20_phy_set_mode(struct phy *phy, enum phy_mode mode)
 {
struct da8xx_usb_phy *d_phy = phy_get_drvdata(phy);
+   int ret;
u32 val;

+   ret = regmap_read(d_phy->regmap, CFGCHIP(2), );
+   if (ret)
+   return ret;
+
+   val &= ~CFGCHIP2_OTGMODE_MASK;
+
switch (mode) {
case PHY_MODE_USB_HOST: /* Force VBUS valid, ID = 0 */
-   val = CFGCHIP2_OTGMODE_FORCE_HOST;
+   val |= CFGCHIP2_OTGMODE_FORCE_HOST;
break;
case PHY_MODE_USB_DEVICE:   /* Force VBUS valid, ID = 1 */
-   val = CFGCHIP2_OTGMODE_FORCE_DEVICE;
+   val |= CFGCHIP2_OTGMODE_FORCE_DEVICE;
break;
case PHY_MODE_USB_OTG:  /* Don't override the VBUS/ID comparators */
-   val = CFGCHIP2_OTGMODE_NO_OVERRIDE;
+   val |= CFGCHIP2_OTGMODE_NO_OVERRIDE |
+   CFGCHIP2_SESENDEN | CFGCHIP2_VBDTCTEN;


The AM1808 TRM indicates that CFGCHIP2_SESENDEN and CFGCHIP2_VBDTCTEN 
(and CFGCHIP2_DATPOL) should be on for normal operation of the USB 2.0 
PHY. They do not appear to be associated with the OTG mode specifically.


It seems to me that it would be more appropriate to set these in 
da8xx_usb20_phy_power_on() instead of here in da8xx_usb20_phy_set_mode().




break;
default:
return -EINVAL;
}

-   regmap_write_bits(d_phy->regmap, CFGCHIP(2), CFGCHIP2_OTGMODE_MASK,
- val);
+   regmap_write(d_phy->regmap, CFGCHIP(2), val);

return 0;
 }



Also cc'ing phy maintainer since this is a phy driver.


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


Re: [PATCH 4/4] ARM: dts: da850: Add the usb otg device node

2016-10-25 Thread David Lechner

On 10/25/2016 09:39 AM, Alexandre Bailon wrote:

This adds the device tree node for the usb otg
controller present in the da850 family of SoC's.
This also enables the otg usb controller for the lcdk board.

Signed-off-by: Alexandre Bailon 
---
 arch/arm/boot/dts/da850-lcdk.dts |  8 
 arch/arm/boot/dts/da850.dtsi | 15 +++
 2 files changed, 23 insertions(+)

diff --git a/arch/arm/boot/dts/da850-lcdk.dts b/arch/arm/boot/dts/da850-lcdk.dts
index 7b8ab21..dca9735 100644
--- a/arch/arm/boot/dts/da850-lcdk.dts
+++ b/arch/arm/boot/dts/da850-lcdk.dts
@@ -158,6 +158,14 @@
rx-num-evt = <32>;
 };

+_phy {
+   status = "okay";
+   };
+
+ {
+   status = "okay";
+};
+
  {
pinctrl-names = "default";
pinctrl-0 = <_pins>;
diff --git a/arch/arm/boot/dts/da850.dtsi b/arch/arm/boot/dts/da850.dtsi
index f79e1b9..b11d395 100644
--- a/arch/arm/boot/dts/da850.dtsi
+++ b/arch/arm/boot/dts/da850.dtsi
@@ -372,6 +372,21 @@
>;
status = "disabled";
};
+   usb_phy: usb-phy {
+   compatible = "ti,da830-usb-phy";
+   #phy-cells = <1>;
+   status = "disabled";
+   };
+   usb20: usb20@20 {


This should be usb0: usb@20


+   compatible = "ti,da830-musb";
+   reg = <0x20 0x1>;
+   interrupts = <58>;
+   interrupt-names = "mc";
+   dr_mode = "otg";
+   phys = <_phy 0>;
+   phy-names = "usb-phy";
+   status = "disabled";
+   };
gpio: gpio@226000 {
compatible = "ti,dm6441-gpio";
gpio-controller;



--
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/3] phy: da8xx-usb: Configure CFGCHIP2 to support OTG workaround

2016-10-25 Thread David Lechner

On 10/25/2016 08:52 AM, Alexandre Bailon wrote:

If we configure the da8xx OTG phy in OTG mode, neither device or host
mode will work. That is because the PHY is not able to detect and notify
the driver that value of ID pin changed.
To work despite this hardware limitation, the da8xx glue implement a
workaround.
But to work, the workaround require the VBUS sense and the session end
comparator to enabled.
Enable them if the phy is configured in OTG mode.

Signed-off-by: Alexandre Bailon 
---
 drivers/phy/phy-da8xx-usb.c | 17 -
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/phy/phy-da8xx-usb.c b/drivers/phy/phy-da8xx-usb.c
index 32ae78c..fd39292 100644
--- a/drivers/phy/phy-da8xx-usb.c
+++ b/drivers/phy/phy-da8xx-usb.c
@@ -93,24 +93,31 @@ static int da8xx_usb20_phy_power_off(struct phy *phy)
 static int da8xx_usb20_phy_set_mode(struct phy *phy, enum phy_mode mode)
 {
struct da8xx_usb_phy *d_phy = phy_get_drvdata(phy);
+   int ret;
u32 val;

+   ret = regmap_read(d_phy->regmap, CFGCHIP(2), );
+   if (ret)
+   return ret;
+
+   val &= ~CFGCHIP2_OTGMODE_MASK;
+
switch (mode) {
case PHY_MODE_USB_HOST: /* Force VBUS valid, ID = 0 */
-   val = CFGCHIP2_OTGMODE_FORCE_HOST;
+   val |= CFGCHIP2_OTGMODE_FORCE_HOST;
break;
case PHY_MODE_USB_DEVICE:   /* Force VBUS valid, ID = 1 */
-   val = CFGCHIP2_OTGMODE_FORCE_DEVICE;
+   val |= CFGCHIP2_OTGMODE_FORCE_DEVICE;
break;
case PHY_MODE_USB_OTG:  /* Don't override the VBUS/ID comparators */
-   val = CFGCHIP2_OTGMODE_NO_OVERRIDE;
+   val |= CFGCHIP2_OTGMODE_NO_OVERRIDE |
+   CFGCHIP2_SESENDEN | CFGCHIP2_VBDTCTEN;


Do we need to clear CFGCHIP2_SESENDEN and/or CFGCHIP2_VBDTCTEN in case 
PHY_MODE_USB_HOST: or case PHY_MODE_USB_DEVICE:? Or are they ignored in 
those modes?



break;
default:
return -EINVAL;
}

-   regmap_write_bits(d_phy->regmap, CFGCHIP(2), CFGCHIP2_OTGMODE_MASK,
- val);
+   regmap_write(d_phy->regmap, CFGCHIP(2), val);

return 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 1/3] usb: musb: da8xx: Call earlier clk_prepare_enable()

2016-10-25 Thread David Lechner

On 10/25/2016 08:52 AM, Alexandre Bailon wrote:

The first attempt to read a register may fail because the clock may not
be enabled, and then the probe of musb driver will fail.
Call clk_prepare_enable() before the first register read.

Signed-off-by: Alexandre Bailon 
---
 drivers/usb/musb/da8xx.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 210b7e4..ec93602 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -366,6 +366,12 @@ static int da8xx_musb_init(struct musb *musb)

musb->mregs += DA8XX_MENTOR_CORE_OFFSET;

+   ret = clk_prepare_enable(glue->clk);
+   if (ret) {
+   dev_err(glue->dev, "failed to enable clock\n");
+   goto fail;


You can simply return ret; here instead of goto fail;


+   }
+
/* Returns zero if e.g. not clocked */
rev = musb_readl(reg_base, DA8XX_USB_REVISION_REG);
if (!rev)
@@ -377,12 +383,6 @@ static int da8xx_musb_init(struct musb *musb)
goto fail;


The unwinding on error needs to be updated so that 
clk_disable_unprepare() is called at this point and subsequently. 
Currently, all goto fail; will return without disabling the clock.



}

-   ret = clk_prepare_enable(glue->clk);
-   if (ret) {
-   dev_err(glue->dev, "failed to enable clock\n");
-   goto fail;
-   }
-
setup_timer(_workaround, otg_timer, (unsigned long)musb);

/* Reset the controller */



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


[PATCH] usb: musb: da8xx: Don't print phy error on -EPROBE_DEFER

2016-10-25 Thread David Lechner
This suppresses printing the error message "failed to get phy" in the
kernel log when the error is -EPROBE_DEFER. This prevents usless noise
in the kernel log.

Signed-off-by: David Lechner <da...@lechnology.com>
---
 drivers/usb/musb/da8xx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 481d786..f8a1591 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -516,7 +516,8 @@ static int da8xx_probe(struct platform_device *pdev)
 
glue->phy = devm_phy_get(>dev, "usb-phy");
if (IS_ERR(glue->phy)) {
-   dev_err(>dev, "failed to get phy\n");
+   if (PTR_ERR(glue->phy) != -EPROBE_DEFER)
+   dev_err(>dev, "failed to get phy\n");
return PTR_ERR(glue->phy);
}
 
-- 
2.7.4

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


Re: [PATCH/RFT v2 12/17] USB: ochi-da8xx: Use a regulator for vbus/overcurrent

2016-10-25 Thread David Lechner

On 10/25/2016 03:24 AM, Axel Haslam wrote:

On Tue, Oct 25, 2016 at 3:39 AM, David Lechner <da...@lechnology.com> wrote:

On 10/24/2016 11:46 AM, ahas...@baylibre.com wrote:


From: Axel Haslam <ahas...@baylibre.com>

Currently, the da8xx ohci driver uses a set of gpios and callbacks in
board files to handle vbus and overcurrent irqs form the power supply.
However, this does not play nice when moving to a DT based boot were
we wont have board files.

Instead of requesting and handling the gpio, use the regulator framework
to take care of enabling and disabling vbus power.
This has the benefit
that we dont need to pass any more platform data to the driver:

These will be handled by the regulator framework:
set_power   ->  regulator_enable/regulator_disable
get_power   ->  regulator_is_enabled
get_oci ->  regulator_get_mode
ocic_notify ->  regulator notification

We can keep the default potpgt and use the regulator start delay instead:
potpgt  -> regulator startup delay time

The hawk board does not have a GPIO/OVERCURRENT gpio to control vbus,
(they should not have been decleared/reserved) so, just remove those
definitions from the hwk board file.

Signed-off-by: Axel Haslam <ahas...@baylibre.com>
---




How do you recover after an overcurrent event?

I have configured a fixed-regulator using device-tree, but similar to the
configuration in the board files here. However, when I shorted out the VBUS
and caused an overcurrent event, I see nothing in the kernel log saying that
there was an overcurrent event and after I remove the short, the regulator
is never turned back on.




You should have the patch to fix gpiolib, and you should declare the
over current gpio on the regulator as such:
(if the pin is enabled high you should add oc-active-high);

   vbus_fixed: fixed-regulator-vbus {
   compatible = "regulator-fixed";
   gpio = < 109 0>;
   oc-gpio = < 36 0>;
   regulator-boot-on;
   enable-active-high;
   regulator-name = "vbus";
   regulator-min-microvolt = <500>;
   regulator-max-microvolt = <500>;
   };


Question: Do you see that the over current gpio was requested
in debugfs/gpio? and, do you see the interrupt in /proc/interrupts?

If you unplug and plug in back the usb device it should work again.
also you can unbind and bind it should also start to work:
something like:

echo usb1 >/sys/bus/usb/drivers/usb/unbind
echo usb1 >/sys/bus/usb/drivers/usb/bind




I have added oc-active-high and I get different results, but it is still 
not quite right. When I short the VBUS, I can see that my overcurrent 
gpio changes state. However, the driver does not turn of the VBUS. When 
I remove the short, I get an overcurrent error in the kernel log. I 
would expect this when I create the short, not when I remove it. I also 
tried adding  GPIO_ACTIVE_LOW to the oc-gpio, but this did not change 
the behavior. In either case, the oc_gpio shows as high under normal 
conditions, so perhaps there is a problem with the gpio-davinci driver 
not picking up GPIO_ACTIVE_LOW from the device tree.



My regulator is basically the same. My device just uses different gpios.

vbus_reg: vbus-reg {
compatible = "regulator-fixed";
pinctrl-names = "default";
pinctrl-0 = <_pins>;
gpio = < 101 GPIO_ACTIVE_LOW>;
oc-gpio = < 99 0>;
enable-active-high;
oc-active-high;
regulator-name = "vbus";
regulator-min-microvolt = <500>;
regulator-max-microvolt = <500>;
}


It seems to me though that I should not have oc-active-high since under 
normal conditions, the oc_gpio is high and during an overcurrent event, 
the oc_gpio is low. Double-checking the behavior without oc-active-high, 
I see that the vbus gpio is turned off in response to the overcurrent 
event, but I don't get the overcurrent message in the kernel log. 
Perhaps this is because as soon as there is an overcurrent event the 
vbus turns off and the oc_gpio returns to normal before the usb driver 
has a chance to poll the overcurrent state?


Also, unplugging the device and plugging it back in does nothing. 
Unbinding and binding the driver does work, but that does not seem like 
a very nice way to have to recover from an overcurrent event.




--
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/RFT v2 11/17] USB: OHCI: make ohci-da8xx a separate driver

2016-10-25 Thread David Lechner

On 10/25/2016 11:21 AM, Axel Haslam wrote:

On Tue, Oct 25, 2016 at 6:12 PM, David Lechner <da...@lechnology.com> wrote:

On 10/25/2016 02:39 AM, Axel Haslam wrote:


On Tue, Oct 25, 2016 at 2:38 AM, David Lechner <da...@lechnology.com>
wrote:


On 10/24/2016 11:46 AM, ahas...@baylibre.com wrote:



-#ifndef CONFIG_ARCH_DAVINCI_DA8XX
-#error "This file is DA8xx bus glue.  Define
CONFIG_ARCH_DAVINCI_DA8XX."
-#endif
+#include "ohci.h"
+
+#define DRIVER_DESC "OHCI DA8XX driver"
+
+static const char hcd_name[] = "ohci-da8xx";




why static const char instead of #define? This is only used one time in a
pr_info, so it seems kind of pointless anyway.



Other drivers are using static const for the same variable.
i think static const is preferred over #define because #define doet give a
type.
If you dont mind ill keep it static const.



If this string was used in this file more than one place, I would agree with
you, but currently it is only used as the argument of a pr_info(). The
string "ohci-da8xx" could just be included in the fmt string instead of
using "%s".


I think the purpose was to use it in the .name of the platform_driver
structure, too. only that not everybody is doing that, i looked at some bad
 examples :(

would you agree to keep it if we use it in .name too?

-Axel





Yes, that will make more sense. ;-)
--
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/RFT v2 11/17] USB: OHCI: make ohci-da8xx a separate driver

2016-10-25 Thread David Lechner

On 10/25/2016 02:39 AM, Axel Haslam wrote:

On Tue, Oct 25, 2016 at 2:38 AM, David Lechner <da...@lechnology.com> wrote:

On 10/24/2016 11:46 AM, ahas...@baylibre.com wrote:


-#ifndef CONFIG_ARCH_DAVINCI_DA8XX
-#error "This file is DA8xx bus glue.  Define CONFIG_ARCH_DAVINCI_DA8XX."
-#endif
+#include "ohci.h"
+
+#define DRIVER_DESC "OHCI DA8XX driver"
+
+static const char hcd_name[] = "ohci-da8xx";



why static const char instead of #define? This is only used one time in a
pr_info, so it seems kind of pointless anyway.


Other drivers are using static const for the same variable.
i think static const is preferred over #define because #define doet give a type.
If you dont mind ill keep it static const.



If this string was used in this file more than one place, I would agree 
with you, but currently it is only used as the argument of a pr_info(). 
The string "ohci-da8xx" could just be included in the fmt string instead 
of using "%s".


--
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/RFT v2 07/17] ARM: davinci: da8xx: Enable the usb20 "per" clk on phy_clk_enable

2016-10-25 Thread David Lechner

On 10/25/2016 05:12 AM, Sekhar Nori wrote:

On Monday 24 October 2016 10:16 PM, ahas...@baylibre.com wrote:

diff --git a/arch/arm/mach-davinci/usb-da8xx.c 
b/arch/arm/mach-davinci/usb-da8xx.c
index 9e41a7f..982e105 100644
--- a/arch/arm/mach-davinci/usb-da8xx.c
+++ b/arch/arm/mach-davinci/usb-da8xx.c
@@ -53,11 +53,19 @@ int __init da8xx_register_usb_refclkin(int rate)

 static void usb20_phy_clk_enable(struct clk *clk)
 {
+   struct clk *usb20_clk;
u32 val;
u32 timeout = 50; /* 500 msec */

val = readl(DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));

+   usb20_clk = clk_get(NULL, "usb20");


We should not be using a NULL device pointer here. Can you pass the musb
device pointer available in the same file? Also, da850_clks[] in da850.c
needs to be fixed to add the matching device name.


This clock can be used for usb 1.1 PHY even when musb is not being used, 
so I don't think we can depend on having a musb device here.


Also, in a previous review, it was decided that the usb clocks should 
*not* be added to da850_clks[] [1]. Instead, they are dynamically 
registered elsewhere.



[1]: http://www.gossamer-threads.com/lists/linux/kernel/2396533




+   if (IS_ERR(usb20_clk)) {
+   pr_err("could not get usb20 clk\n");
+   return;
+   }


Thanks,
Sekhar



--
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/RFT v2 02/17] ARM: davinci: da8xx: Add CFGCHIP syscon platform declaration.

2016-10-25 Thread David Lechner

Hi Sekhar,

On 10/25/2016 05:17 AM, Sekhar Nori wrote:

On Tuesday 25 October 2016 03:07 PM, Axel Haslam wrote:

Hi Sekar,

On Tue, Oct 25, 2016 at 10:10 AM, Sekhar Nori <nsek...@ti.com> wrote:

On Monday 24 October 2016 10:16 PM, ahas...@baylibre.com wrote:

From: David Lechner <da...@lechnology.com>

The CFGCHIP registers are used by a number of devices, so using a syscon
device to share them. The first consumer of this will by the phy-da8xx-usb
driver.

Signed-off-by: David Lechner <da...@lechnology.com>
[Axel: minor fix: change id to -1]


Can you please clarify this change? There could be other syscon devices
on the chip for other common registers. Why use the singular device-id?



in the case of non DT boot, the phy driver is looking for "syscon" :

d_phy->regmap = syscon_regmap_lookup_by_pdevname("syscon");

if we register the syscon driver with id = 0, the actual name of the syscon
device will be "syscon.0" and the phy driver will fail to probe, because
the strncmp match in the syscon driver (syscon_match_pdevname)
will fail.

should i change the phy driver instead?


Yes, please. Forcing only one syscon region for the whole chip will be
too restrictive, I am pretty sure.

Thanks,
Sekhar



In the previous review, you requested that this be changed to -1 [1].

If we change it back to 0, it will also require reverting a patch to the 
phy driver that has already been merged[2].


[1]: http://www.gossamer-threads.com/lists/linux/kernel/2435807?page=last
[2]: http://www.gossamer-threads.com/lists/linux/kernel/2518804


--
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/RFT v2 07/17] ARM: davinci: da8xx: Enable the usb20 "per" clk on phy_clk_enable

2016-10-24 Thread David Lechner

On 10/24/2016 11:46 AM, ahas...@baylibre.com wrote:

From: Axel Haslam 

While probing ochi phy with usb20 phy as a parent clock for usb11_phy,
the usb20_phy clock enable would time out. This is because the usb20
module clock needs to enabled while trying to lock the usb20_phy PLL.

Call clk enable and get for the usb20 peripheral before trying to
enable the phy PLL.

Signed-off-by: Axel Haslam 
---



This patch can be combined with "ARM: davinci: da8xx: add usb phy 
clocks" since that patch has not been merged yet.


If you like, I can resubmit my patches from this series along with the 
changes from this patch.


--
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/RFT v2 12/17] USB: ochi-da8xx: Use a regulator for vbus/overcurrent

2016-10-24 Thread David Lechner

On 10/24/2016 11:46 AM, ahas...@baylibre.com wrote:

From: Axel Haslam 

Currently, the da8xx ohci driver uses a set of gpios and callbacks in
board files to handle vbus and overcurrent irqs form the power supply.
However, this does not play nice when moving to a DT based boot were
we wont have board files.

Instead of requesting and handling the gpio, use the regulator framework
to take care of enabling and disabling vbus power.
This has the benefit
that we dont need to pass any more platform data to the driver:

These will be handled by the regulator framework:
set_power   ->  regulator_enable/regulator_disable
get_power   ->  regulator_is_enabled
get_oci ->  regulator_get_mode
ocic_notify ->  regulator notification

We can keep the default potpgt and use the regulator start delay instead:
potpgt  -> regulator startup delay time

The hawk board does not have a GPIO/OVERCURRENT gpio to control vbus,
(they should not have been decleared/reserved) so, just remove those
definitions from the hwk board file.

Signed-off-by: Axel Haslam 
---



How do you recover after an overcurrent event?

I have configured a fixed-regulator using device-tree, but similar to 
the configuration in the board files here. However, when I shorted out 
the VBUS and caused an overcurrent event, I see nothing in the kernel 
log saying that there was an overcurrent event and after I remove the 
short, the regulator is never turned back on.





@@ -163,7 +198,6 @@ static int ohci_da8xx_hub_control(struct usb_hcd *hcd, u16 
typeReq, u16 wValue,
  u16 wIndex, char *buf, u16 wLength)
 {
struct device *dev  = hcd->self.controller;
-   struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);


nit: unnecessary whitespace change


int temp;

switch (typeReq) {


--
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/RFT v2 13/17] USB: da8xx: use ohci priv data instead of globals

2016-10-24 Thread David Lechner

On 10/24/2016 11:46 AM, ahas...@baylibre.com wrote:

From: Axel Haslam 
>  static const struct ohci_driver_overrides da8xx_overrides __initconst = {
-   .reset  = ohci_da8xx_reset
+   .reset  = ohci_da8xx_reset,
+   .extra_priv_size = sizeof(struct da8xx_ohci_hcd),


nit: since you are changing both lines anyway, you might as well make 
the ='s line up.



 };

 /*



--
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/RFT v2 15/17] usb: host: ohci-da8xx: Add devicetree bindings documentation

2016-10-24 Thread David Lechner

On 10/24/2016 11:46 AM, ahas...@baylibre.com wrote:

From: Axel Haslam 

This patch documents the device tree bindings required for
the ohci controller found in TI da8xx family of SoC's

Signed-off-by: Axel Haslam 
---
 .../devicetree/bindings/usb/ohci-da8xx.txt | 39 ++
 1 file changed, 39 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/ohci-da8xx.txt

diff --git a/Documentation/devicetree/bindings/usb/ohci-da8xx.txt 
b/Documentation/devicetree/bindings/usb/ohci-da8xx.txt
new file mode 100644
index 000..4251c84
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/ohci-da8xx.txt
@@ -0,0 +1,39 @@
+DA8XX USB OHCI controller
+
+Required properties:
+
+ - compatible: Should be "ti,da830-ohci"
+ - reg:Should contain one register range i.e. start and length
+ - interrupts: Description of the interrupt line
+ - phys:   Phandle for the PHY device
+ - phy-names:  Should be "usb-phy"
+
+Optional properties:
+ - vbus-supply: Regulator that controls vbus power



Isn't vbus-supply property required?

If it is really supposed to be optional, the ohci driver needs to use 
devm_regulator_get_optional() and handle the case when there is no 
regulator.


I don't see a problem with making it required though since one can just 
use a dummy supply if there is not a real one.



+
+Example for omap138-lck:
+
+vbus_fixed: fixed-regulator-vbus {
+compatible = "regulator-fixed";
+gpio = < 109 0>;
+oc-gpio = < 36 0>;
+regulator-boot-on;
+enable-active-high;
+regulator-name = "vbus";
+regulator-min-microvolt = <500>;
+regulator-max-microvolt = <500>;
+};
+
+usb_phy: usb-phy {
+compatible = "ti,da830-usb-phy";
+#phy-cells = <1>;
+status = "disabled";


why disabled?


+};
+usb: usb@0225000 {
+compatible = "ti,da830-ohci";
+reg = <0x225000 0x1000>;
+interrupts = <59>;
+phys = <_phy 1>;
+phy-names = "usb-phy";


missing vbus-supply property


+status = "disabled";


why disabled?


+};



--
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/RFT v2 16/17] USB: ohci-da8xx: Allow probing from DT

2016-10-24 Thread David Lechner

On 10/24/2016 11:46 AM, ahas...@baylibre.com wrote:

From: Axel Haslam 

This adds the compatible string to the ohci driver
to be able to probe from DT

Signed-off-by: Axel Haslam 
---
 drivers/usb/host/ohci-da8xx.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c
index bebc3f0..1a8db25 100644
--- a/drivers/usb/host/ohci-da8xx.c
+++ b/drivers/usb/host/ohci-da8xx.c
@@ -273,6 +273,13 @@ static int ohci_da8xx_hub_control(struct usb_hcd *hcd, u16 
typeReq, u16 wValue,
 }

 /*-*/
+#ifdef CONFIG_OF


#ifdef CONFIG_OF is probably not needed here...


+static const struct of_device_id da8xx_ohci_ids[] = {
+   { .compatible = "ti,da830-ohci" },
+   { }
+};
+MODULE_DEVICE_TABLE(of, da8xx_ohci_ids);
+#endif

 static int ohci_da8xx_probe(struct platform_device *pdev)
 {
@@ -421,6 +428,7 @@ static int ohci_da8xx_resume(struct platform_device *dev)
 #endif
.driver = {
.name   = "ohci",
+   .of_match_table = da8xx_ohci_ids,


...otherwise, da8xx_ohci_ids will not be defined here


},
 };




--
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/RFT v2 17/17] ARM: dts: da850: add usb device node

2016-10-24 Thread David Lechner

On 10/24/2016 11:46 AM, ahas...@baylibre.com wrote:

From: Axel Haslam 

This adds the usb (ohci) device node for the da850 soc.
Also it enables it for the lcdk board

Signed-off-by: Axel Haslam 
---
 arch/arm/boot/dts/da850-lcdk.dts | 8 
 arch/arm/boot/dts/da850.dtsi | 8 
 2 files changed, 16 insertions(+)

diff --git a/arch/arm/boot/dts/da850-lcdk.dts b/arch/arm/boot/dts/da850-lcdk.dts
index 7b8ab21..fa91339 100644
--- a/arch/arm/boot/dts/da850-lcdk.dts
+++ b/arch/arm/boot/dts/da850-lcdk.dts
@@ -86,6 +86,14 @@
};
 };

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


Don't you need to specify a regulator here using the vbus-supply property?


+};
+
  {
pinctrl-names = "default";
pinctrl-0 = <_rxtx_pins>;
diff --git a/arch/arm/boot/dts/da850.dtsi b/arch/arm/boot/dts/da850.dtsi
index 33fcdce..ec2cec3 100644
--- a/arch/arm/boot/dts/da850.dtsi
+++ b/arch/arm/boot/dts/da850.dtsi
@@ -381,6 +381,14 @@
#phy-cells = <1>;
status = "disabled";
};
+   usb: usb@0225000 {


Don't need the leading 0 on usb@225000

The alias (usb:) might need to be more specific since there is a second 
usb device that will be added later for musb. (The comments in the 
previous review only referred to the "usb" in "usb@", not the alias.)



+   compatible = "ti,da830-ohci";
+   reg = <0x225000 0x1000>;
+   interrupts = <59>;
+   phys = <_phy 1>;
+   phy-names = "usb-phy";
+   status = "disabled";
+   };
gpio: gpio@226000 {
compatible = "ti,dm6441-gpio";
gpio-controller;



--
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/RFT v2 11/17] USB: OHCI: make ohci-da8xx a separate driver

2016-10-24 Thread David Lechner

On 10/24/2016 11:46 AM, ahas...@baylibre.com wrote:

From: Manjunath Goudar 

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


No need for comment about kernel 3.11.



Signed-off-by: Manjunath Goudar 
---
 drivers/usb/host/Kconfig  |   2 +-
 drivers/usb/host/Makefile |   1 +
 drivers/usb/host/ohci-da8xx.c | 185 +-
 drivers/usb/host/ohci-hcd.c   |  18 
 4 files changed, 76 insertions(+), 130 deletions(-)

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 83b6cec..642c6fe8 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -479,7 +479,7 @@ config USB_OHCI_HCD_OMAP3
  OMAP3 and later chips.

 config USB_OHCI_HCD_DAVINCI
-   bool "OHCI support for TI DaVinci DA8xx"
+   tristate "OHCI support for TI DaVinci DA8xx"
depends on ARCH_DAVINCI_DA8XX
depends on USB_OHCI_HCD=y


Need to drop the "=y" here, otherwise you still can't compile this as a 
module.



select PHY_DA8XX_USB
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index 6ef785b..2644537 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -61,6 +61,7 @@ obj-$(CONFIG_USB_OHCI_HCD_AT91)   += ohci-at91.o
 obj-$(CONFIG_USB_OHCI_HCD_S3C2410) += ohci-s3c2410.o
 obj-$(CONFIG_USB_OHCI_HCD_LPC32XX) += ohci-nxp.o
 obj-$(CONFIG_USB_OHCI_HCD_PXA27X)  += ohci-pxa27x.o
+obj-$(CONFIG_USB_OHCI_HCD_DAVINCI) += ohci-da8xx.o

 obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o
 obj-$(CONFIG_USB_FHCI_HCD) += fhci.o
diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c
index e98066d..5585d9e 100644
--- a/drivers/usb/host/ohci-da8xx.c
+++ b/drivers/usb/host/ohci-da8xx.c
@@ -11,16 +11,31 @@
  * kind, whether express or implied.
  */

+#include 
+#include 
 #include 
 #include 
+#include 
+#include 
 #include 
-#include 
 #include 
 #include 
+#include 


linux/platform_device.h is listed twice


+#include 
+#include 
+#include 

-#ifndef CONFIG_ARCH_DAVINCI_DA8XX
-#error "This file is DA8xx bus glue.  Define CONFIG_ARCH_DAVINCI_DA8XX."
-#endif
+#include "ohci.h"
+
+#define DRIVER_DESC "OHCI DA8XX driver"
+
+static const char hcd_name[] = "ohci-da8xx";


why static const char instead of #define? This is only used one time in 
a pr_info, so it seems kind of pointless anyway.



+
+static struct hc_driver __read_mostly ohci_da8xx_hc_driver;
+
+static int (*orig_ohci_hub_control)(struct usb_hcd  *hcd, u16 typeReq,
+   u16 wValue, u16 wIndex, char *buf, u16 wLength);
+static int (*orig_ohci_hub_status_data)(struct usb_hcd *hcd, char *buf);

 static struct clk *usb11_clk;
 static struct phy *usb11_phy;
@@ -73,7 +88,7 @@ static void ohci_da8xx_ocic_handler(struct 
da8xx_ohci_root_hub *hub)
hub->set_power(0);
 }

-static int ohci_da8xx_init(struct usb_hcd *hcd)
+static int ohci_da8xx_reset(struct usb_hcd *hcd)
 {
struct device *dev  = hcd->self.controller;
struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
@@ -93,7 +108,7 @@ static int ohci_da8xx_init(struct usb_hcd *hcd)
 */
ohci->num_ports = 1;

-   result = ohci_init(ohci);
+   result = ohci_setup(hcd);
if (result < 0) {
ohci_da8xx_disable();
return result;
@@ -121,30 +136,12 @@ static int ohci_da8xx_init(struct usb_hcd *hcd)
return result;
 }

-static void ohci_da8xx_stop(struct usb_hcd *hcd)
-{
-   ohci_stop(hcd);
-   ohci_da8xx_disable();
-}
-
-static int ohci_da8xx_start(struct usb_hcd *hcd)
-{
-   struct ohci_hcd *ohci   = hcd_to_ohci(hcd);
-   int result;
-
-   result = ohci_run(ohci);
-   if (result < 0)
-   ohci_da8xx_stop(hcd);
-
-   return result;
-}
-
 /*
  * Update the status data from the hub with the over-current indicator change.
  */
 static int ohci_da8xx_hub_status_data(struct usb_hcd *hcd, char *buf)
 {
-   int length  = ohci_hub_status_data(hcd, buf);
+   int length  = orig_ohci_hub_status_data(hcd, buf);

/* See if we have OCIC flag set */
if (ocic_flag) {
@@ -226,66 +223,13 @@ static int ohci_da8xx_hub_control(struct usb_hcd *hcd, 
u16 typeReq, u16 wValue,
}
}

-   return ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength);
+   return orig_ohci_hub_control(hcd, typeReq, wValue,
+   wIndex, buf, wLength);
 }

-static const struct hc_driver ohci_da8xx_hc_driver = {
-   .description= hcd_name,
-   .product_desc   = "DA8xx OHCI",
-   .hcd_priv_size  = sizeof(struct ohci_hcd),
-
-   /*
-* generic hardware linkage
-*/
-  

Re: [PATCH/RFT 07/12] USB: ohci-da8xx: Request gpios and handle interrupt in the driver

2016-10-12 Thread David Lechner

On 10/12/2016 10:01 AM, Axel Haslam wrote:

I  agree that we should use a regulator for the vbus power.
i will make that change.  However, im not so sure about using the
regulator for the overcurrent handling. There seems to be no other
driver doing this, and as you mention, we would need to change the regulator
framework, which might not be justifiable. I think there is not another way
to handle the over current notification other than powering the port off.


The regulator framework has REGULATOR_EVENT_OVER_CURRENT already. 
Perhaps this could be of some use? For example you could extend the 
existing gpio-regulator driver with an optional overcurrent gpio pin.





how about using regulator for vbus, but keeping gpio for overcurrent
notifications?


See the suggestion above about extending the gpio-regulator driver.



For the usersapce handling you describe above, maybe we should be able to
listen for an usb overcurrent uevent in userspace? it seems this
question was asked
a couple of years back[1], but im not sure what the conclusion was. In any case,
we could have DT and non-DT based ohci-da8xx working,
And could work on a uevent notification for the scenario you describe
above which
i think is not specific to the ohci-da8xx.

[1]http://linux-usb.vger.kernel.narkive.com/SjcUB5hk/how-best-to-get-over-current-notification-to-user-application


Thanks for the link. Too bad it seems nothing ever became of this. I 
guess it will be up to me to bring up the discussion again if I really 
want it.

--
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/RFT 09/12] usb: host: ohci-da8xx: Add devicetree bindings documentation

2016-10-10 Thread David Lechner

On 10/07/2016 11:42 AM, ahas...@baylibre.com wrote:

From: Axel Haslam 

This patch documents the device tree bindings required for
the ohci controller found in TI da8xx family of SoC's

Signed-off-by: Axel Haslam 
---
 .../devicetree/bindings/usb/ohci-da8xx.txt | 32 ++
 1 file changed, 32 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/ohci-da8xx.txt

diff --git a/Documentation/devicetree/bindings/usb/ohci-da8xx.txt 
b/Documentation/devicetree/bindings/usb/ohci-da8xx.txt
new file mode 100644
index 000..e954ce5
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/ohci-da8xx.txt
@@ -0,0 +1,32 @@
+DA8XX USB OHCI controller
+
+Required properties:
+
+ - compatible: Should be "ti,da830-ohci"
+ - reg:Should contain one register range i.e. start and length
+ - interrupts: Description of the interrupt line
+ - phys:   Phandle for the PHY device
+ - phy-names:  Should be "usb-phy"
+


If these are required, shouldn't they say "Must" instead of "Should"?


+Optional properties:
+ - vbus-gpio:  If present, specifies a gpio that needs to be
+   activated for the bus to be powered.
+ - oci-gpio:   If present, specifies a gpio that needs to be
+   activated for the overcurrent detection.
+ - power_on_delay: Power On to Power Good time - in ms.
+
+Example for omap138-lck:
+
+usb_phy: usb-phy {
+compatible = "ti,da830-usb-phy";
+#phy-cells = <1>;
+status = "disabled";
+};
+usb11: usb11@0225000 {
+compatible = "ti,da830-ohci";
+reg = <0x225000 0x1000>;
+interrupts = <59>;
+phys = <_phy 1>;
+phy-names = "usb-phy";
+status = "disabled";
+};



--
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/RFT 08/12] ARM: davinci: register the usb20_phy clock on the SoC file

2016-10-10 Thread David Lechner

On 10/07/2016 11:42 AM, ahas...@baylibre.com wrote:

From: Axel Haslam 

The usb20_phy clock needs to be registered for the driver to be able
to get and enable a clock. Currently the usb phy clocks are registered
form board files, which will not be called during a device tree based
boot.

To be able to probe correctly usb form a device tree boot, register
the usb phy clocks form the SoC specific init.

Unfourtunatly, davinci does not have proper clock support on device tree
yet, so by registering the clock form de SoC specific file we are
forced to hardcode the parent clock, and cannot select refclkin as
parent for any of the phy clocks of the da850 family.


FYI, I have started working on the clocks as well if you want to take it 
and run with it.


https://github.com/dlech/ev3dev-kernel/compare/9d6b50cde34b51309c74d97c26b1430c7ff6aa0f...d02084598785c369fdb23884171cbbec4fef77b0

(Ignore the ev3dev commit stuck in the middle there.)



As none of the current da850 based boards currently in mainline use
refclkin as source. I guess we can live with this limitation until clocks
are correctly represented through CCF/device tree.


--
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/RFT 07/12] USB: ohci-da8xx: Request gpios and handle interrupt in the driver

2016-10-10 Thread David Lechner

On 10/07/2016 11:42 AM, ahas...@baylibre.com wrote:

From: Axel Haslam 

Currently requesting the vbus and overcurrent gpio is handled on
the board specific file. But this does not play well moving to
device tree.

In preparation to migrate to a device tree boot, handle requesting
gpios and overcurrent interrupt on the usb driver itself, thus avoiding
callbacks to arch/mach*



Instead of using gpios, it seems like it would be better to use a 
regulator here. I don't know of any real-life cases, but who is to say 
someone will not design a board that uses a regulator controlled by I2C 
instead of gpios or something like that.


Then, boards that don't have gpios can just use a fixed regulator (or 
you can make the regulator optional). Using a regulator would also allow 
users to decide how to respond to overcurrent events (by supplying their 
own regulator driver) instead of the behavior being dictated by the ohci 
driver.


In my particular area of interest (LEGO MINDSTORMS EV3), the 5V 
(hardware) regulator for VBUS does use gpios, but the 5V is also shared 
with the LEGO input and output ports. So what I would ultimately like to 
be able to do is have userspace notified of an overcurrent event and let 
userspace decided when to turn the vbus back on. For example, someone 
might plug something into one of the LEGO input or output ports that 
causes a short circuit. I would like to display a notification to the 
user and wait for them to correct the problem and then press a button to 
turn the power back on.


This will require some modifications to the regulator subsystem though. 
I actually started work on this a while back, but haven't had the time 
to pursue it any farther.


Here are my WIP patches in case there is any interest:
* 
https://github.com/dlech/ev3dev-kernel/commit/541a42b3b8ed639e95bbc835df3292f80190c789
* 
https://github.com/dlech/ev3dev-kernel/commit/2ba99b1ad6a06c944dd33a073f54044e71b75ae6
* 
https://github.com/dlech/ev3dev-kernel/commit/cdb03caa50e64931d4f2836c648739aa4385ed3b
* 
https://github.com/dlech/ev3dev-kernel/commit/9d6b50cde34b51309c74d97c26b1430c7ff6aa0f

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


Re: [PATCH v6 1/3] usb: ohci-da8xx: Remove code that references mach

2016-10-04 Thread David Lechner

On 10/04/2016 08:38 AM, Greg Kroah-Hartman wrote:

On Tue, Oct 04, 2016 at 11:18:03AM +0200, Kevin Hilman wrote:

Hi Greg,

On Mon, Sep 5, 2016 at 10:00 PM, David Lechner <da...@lechnology.com> wrote:

Including mach/* is frowned upon in device drivers, so get rid of it.

This replaces usb20_clk and code that pokes CFGCHIP2 with a proper phy
driver.

Signed-off-by: David Lechner <da...@lechnology.com>
Acked-by: Alan Stern <st...@rowland.harvard.edu>


Can you pick up this patch?

Patches 2 & 3 from this series were picked up by Bin for musb, but
this one is still outstanding.


It's not in my todo queue from what I can tell, so it would have to be
resent and I can pick it up after 4.9-rc1 is out.

thanks,

greg k-h



Are there any magic email headers needed to make sure you don't miss it 
or will


Subject: [RESEND PATCH v6 1/3]...
To: gregkh@...

do the trick?
--
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/3] da8xx USB PHY platform devices and clocks

2016-09-05 Thread David Lechner
Just resending to get these merged into usb. The phy parts of this patch series
have already been merged into Linus' tree.

I have rebased on 4.8-rc5 but there have not been any changes to these since
the last time I submitted.

David Lechner (3):
  usb: ohci-da8xx: Remove code that references mach
  usb: musb: da8xx: Use devm in probe
  usb: musb: da8xx: Remove mach code

 drivers/usb/host/Kconfig  |   1 +
 drivers/usb/host/ohci-da8xx.c | 102 +++-
 drivers/usb/musb/Kconfig  |   2 +-
 drivers/usb/musb/da8xx.c  | 154 +++---
 4 files changed, 112 insertions(+), 147 deletions(-)

-- 
2.7.4

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


[PATCH v6 1/3] usb: ohci-da8xx: Remove code that references mach

2016-09-05 Thread David Lechner
Including mach/* is frowned upon in device drivers, so get rid of it.

This replaces usb20_clk and code that pokes CFGCHIP2 with a proper phy
driver.

Signed-off-by: David Lechner <da...@lechnology.com>
Acked-by: Alan Stern <st...@rowland.harvard.edu>
---
 drivers/usb/host/Kconfig  |   1 +
 drivers/usb/host/ohci-da8xx.c | 102 +++---
 2 files changed, 56 insertions(+), 47 deletions(-)

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 2e710a4..1f0cdab8 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -482,6 +482,7 @@ config USB_OHCI_HCD_DAVINCI
bool "OHCI support for TI DaVinci DA8xx"
depends on ARCH_DAVINCI_DA8XX
depends on USB_OHCI_HCD=y
+   select PHY_DA8XX_USB
default y
help
  Enables support for the DaVinci DA8xx integrated OHCI
diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c
index e5c33bc..3656d7c 100644
--- a/drivers/usb/host/ohci-da8xx.c
+++ b/drivers/usb/host/ohci-da8xx.c
@@ -15,58 +15,50 @@
 #include 
 #include 
 #include 
-
-#include 
+#include 
 #include 
 
 #ifndef CONFIG_ARCH_DAVINCI_DA8XX
 #error "This file is DA8xx bus glue.  Define CONFIG_ARCH_DAVINCI_DA8XX."
 #endif
 
-#define CFGCHIP2   DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG)
-
 static struct clk *usb11_clk;
-static struct clk *usb20_clk;
+static struct phy *usb11_phy;
 
 /* Over-current indicator change bitmask */
 static volatile u16 ocic_mask;
 
-static void ohci_da8xx_clock(int on)
+static int ohci_da8xx_enable(void)
 {
-   u32 cfgchip2;
-
-   cfgchip2 = __raw_readl(CFGCHIP2);
-   if (on) {
-   clk_enable(usb11_clk);
-
-   /*
-* If USB 1.1 reference clock is sourced from USB 2.0 PHY, we
-* need to enable the USB 2.0 module clocking, start its PHY,
-* and not allow it to stop the clock during USB 2.0 suspend.
-*/
-   if (!(cfgchip2 & CFGCHIP2_USB1PHYCLKMUX)) {
-   clk_enable(usb20_clk);
-
-   cfgchip2 &= ~(CFGCHIP2_RESET | CFGCHIP2_PHYPWRDN);
-   cfgchip2 |= CFGCHIP2_PHY_PLLON;
-   __raw_writel(cfgchip2, CFGCHIP2);
-
-   pr_info("Waiting for USB PHY clock good...\n");
-   while (!(__raw_readl(CFGCHIP2) & CFGCHIP2_PHYCLKGD))
-   cpu_relax();
-   }
+   int ret;
 
-   /* Enable USB 1.1 PHY */
-   cfgchip2 |= CFGCHIP2_USB1SUSPENDM;
-   } else {
-   clk_disable(usb11_clk);
-   if (!(cfgchip2 & CFGCHIP2_USB1PHYCLKMUX))
-   clk_disable(usb20_clk);
+   ret = clk_prepare_enable(usb11_clk);
+   if (ret)
+   return ret;
 
-   /* Disable USB 1.1 PHY */
-   cfgchip2 &= ~CFGCHIP2_USB1SUSPENDM;
-   }
-   __raw_writel(cfgchip2, CFGCHIP2);
+   ret = phy_init(usb11_phy);
+   if (ret)
+   goto err_phy_init;
+
+   ret = phy_power_on(usb11_phy);
+   if (ret)
+   goto err_phy_power_on;
+
+   return 0;
+
+err_phy_power_on:
+   phy_exit(usb11_phy);
+err_phy_init:
+   clk_disable_unprepare(usb11_clk);
+
+   return ret;
+}
+
+static void ohci_da8xx_disable(void)
+{
+   phy_power_off(usb11_phy);
+   phy_exit(usb11_phy);
+   clk_disable_unprepare(usb11_clk);
 }
 
 /*
@@ -92,7 +84,9 @@ static int ohci_da8xx_init(struct usb_hcd *hcd)
 
dev_dbg(dev, "starting USB controller\n");
 
-   ohci_da8xx_clock(1);
+   result = ohci_da8xx_enable();
+   if (result < 0)
+   return result;
 
/*
 * DA8xx only have 1 port connected to the pins but the HC root hub
@@ -101,8 +95,10 @@ static int ohci_da8xx_init(struct usb_hcd *hcd)
ohci->num_ports = 1;
 
result = ohci_init(ohci);
-   if (result < 0)
+   if (result < 0) {
+   ohci_da8xx_disable();
return result;
+   }
 
/*
 * Since we're providing a board-specific root hub port power control
@@ -129,7 +125,7 @@ static int ohci_da8xx_init(struct usb_hcd *hcd)
 static void ohci_da8xx_stop(struct usb_hcd *hcd)
 {
ohci_stop(hcd);
-   ohci_da8xx_clock(0);
+   ohci_da8xx_disable();
 }
 
 static int ohci_da8xx_start(struct usb_hcd *hcd)
@@ -301,12 +297,18 @@ static int usb_hcd_da8xx_probe(const struct hc_driver 
*driver,
return -ENODEV;
 
usb11_clk = devm_clk_get(>dev, "usb11");
-   if (IS_ERR(usb11_clk))
+   if (IS_ERR(usb11_clk)) {
+   if (PTR_ERR(usb11_clk) != -EPROBE_DEFER)
+   dev_err(>dev, "Failed to get clock.\n");
return PTR_ERR(usb11_clk);
+   }
 
-   usb20_clk = devm_clk_g

[PATCH v6 2/3] usb: musb: da8xx: Use devm in probe

2016-09-05 Thread David Lechner
Simplify things a bit by using devm functions where possible.

Signed-off-by: David Lechner <da...@lechnology.com>
---
 drivers/usb/musb/da8xx.c | 19 +--
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index b03d3b8..0c1997c 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -490,20 +490,18 @@ static int da8xx_probe(struct platform_device *pdev)
struct da8xx_glue   *glue;
struct platform_device_info pinfo;
struct clk  *clk;
+   int ret;
 
-   int ret = -ENOMEM;
-
-   glue = kzalloc(sizeof(*glue), GFP_KERNEL);
+   glue = devm_kzalloc(>dev, sizeof(*glue), GFP_KERNEL);
if (!glue) {
dev_err(>dev, "failed to allocate glue context\n");
-   goto err0;
+   return -ENOMEM;
}
 
-   clk = clk_get(>dev, "usb20");
+   clk = devm_clk_get(>dev, "usb20");
if (IS_ERR(clk)) {
dev_err(>dev, "failed to get clock\n");
-   ret = PTR_ERR(clk);
-   goto err3;
+   return PTR_ERR(clk);
}
 
ret = clk_enable(clk);
@@ -560,12 +558,7 @@ err5:
clk_disable(clk);
 
 err4:
-   clk_put(clk);
-
-err3:
-   kfree(glue);
 
-err0:
return ret;
 }
 
@@ -576,8 +569,6 @@ static int da8xx_remove(struct platform_device *pdev)
platform_device_unregister(glue->musb);
usb_phy_generic_unregister(glue->phy);
clk_disable(glue->clk);
-   clk_put(glue->clk);
-   kfree(glue);
 
return 0;
 }
-- 
2.7.4

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


[PATCH v6 3/3] usb: musb: da8xx: Remove mach code

2016-09-05 Thread David Lechner
Use the new phy-da8xx-usb driver to take the place of the mach code that
pokes CFGCHIP2 in the da8xx musb glue driver. This unbreaks the driver.

Signed-off-by: David Lechner <da...@lechnology.com>
---
 drivers/usb/musb/Kconfig |   2 +-
 drivers/usb/musb/da8xx.c | 135 ++-
 2 files changed, 51 insertions(+), 86 deletions(-)

diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index 886526b..c73221a 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -82,7 +82,7 @@ config USB_MUSB_DA8XX
tristate "DA8xx/OMAP-L1x"
depends on ARCH_DAVINCI_DA8XX
depends on NOP_USB_XCEIV
-   depends on BROKEN
+   select PHY_DA8XX_USB
 
 config USB_MUSB_TUSB6010
tristate "TUSB6010"
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 0c1997c..6af8c3d 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -30,13 +30,11 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 
-#include 
-#include 
-
 #include "musb_core.h"
 
 /*
@@ -80,61 +78,15 @@
 
 #define DA8XX_MENTOR_CORE_OFFSET 0x400
 
-#define CFGCHIP2   IO_ADDRESS(DA8XX_SYSCFG0_BASE + DA8XX_CFGCHIP2_REG)
-
 struct da8xx_glue {
struct device   *dev;
struct platform_device  *musb;
-   struct platform_device  *phy;
+   struct platform_device  *usb_phy;
struct clk  *clk;
+   struct phy  *phy;
 };
 
 /*
- * REVISIT (PM): we should be able to keep the PHY in low power mode most
- * of the time (24 MHz oscillator and PLL off, etc.) by setting POWER.D0
- * and, when in host mode, autosuspending idle root ports... PHY_PLLON
- * (overriding SUSPENDM?) then likely needs to stay off.
- */
-
-static inline void phy_on(void)
-{
-   u32 cfgchip2 = __raw_readl(CFGCHIP2);
-
-   /*
-* Start the on-chip PHY and its PLL.
-*/
-   cfgchip2 &= ~(CFGCHIP2_RESET | CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN);
-   cfgchip2 |= CFGCHIP2_PHY_PLLON;
-   __raw_writel(cfgchip2, CFGCHIP2);
-
-   pr_info("Waiting for USB PHY clock good...\n");
-   while (!(__raw_readl(CFGCHIP2) & CFGCHIP2_PHYCLKGD))
-   cpu_relax();
-}
-
-static inline void phy_off(void)
-{
-   u32 cfgchip2 = __raw_readl(CFGCHIP2);
-
-   /*
-* Ensure that USB 1.1 reference clock is not being sourced from
-* USB 2.0 PHY.  Otherwise do not power down the PHY.
-*/
-   if (!(cfgchip2 & CFGCHIP2_USB1PHYCLKMUX) &&
-(cfgchip2 & CFGCHIP2_USB1SUSPENDM)) {
-   pr_warning("USB 1.1 clocked from USB 2.0 PHY -- "
-  "can't power it down\n");
-   return;
-   }
-
-   /*
-* Power down the on-chip PHY.
-*/
-   cfgchip2 |= CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN;
-   __raw_writel(cfgchip2, CFGCHIP2);
-}
-
-/*
  * Because we don't set CTRL.UINT, it's "important" to:
  * - not read/write INTRUSB/INTRUSBE (except during
  *   initial setup, as a workaround);
@@ -385,29 +337,29 @@ static irqreturn_t da8xx_musb_interrupt(int irq, void 
*hci)
 
 static int da8xx_musb_set_mode(struct musb *musb, u8 musb_mode)
 {
-   u32 cfgchip2 = __raw_readl(CFGCHIP2);
+   struct da8xx_glue *glue = dev_get_drvdata(musb->controller->parent);
+   enum phy_mode phy_mode;
 
-   cfgchip2 &= ~CFGCHIP2_OTGMODE;
switch (musb_mode) {
case MUSB_HOST: /* Force VBUS valid, ID = 0 */
-   cfgchip2 |= CFGCHIP2_FORCE_HOST;
+   phy_mode = PHY_MODE_USB_HOST;
break;
case MUSB_PERIPHERAL:   /* Force VBUS valid, ID = 1 */
-   cfgchip2 |= CFGCHIP2_FORCE_DEVICE;
+   phy_mode = PHY_MODE_USB_DEVICE;
break;
case MUSB_OTG:  /* Don't override the VBUS/ID comparators */
-   cfgchip2 |= CFGCHIP2_NO_OVERRIDE;
+   phy_mode = PHY_MODE_USB_OTG;
break;
default:
-   dev_dbg(musb->controller, "Trying to set unsupported mode 
%u\n", musb_mode);
+   return -EINVAL;
}
 
-   __raw_writel(cfgchip2, CFGCHIP2);
-   return 0;
+   return phy_set_mode(glue->phy, phy_mode);
 }
 
 static int da8xx_musb_init(struct musb *musb)
 {
+   struct da8xx_glue *glue = dev_get_drvdata(musb->controller->parent);
void __iomem *reg_base = musb->ctrl_base;
u32 rev;
int ret = -ENODEV;
@@ -425,32 +377,56 @@ static int da8xx_musb_init(struct musb *musb)
goto fail;
}
 
+   ret = clk_prepare_enable(glue->clk);
+   if (ret) {
+   dev_err(glue->dev, "failed to enable clock\n");
+   goto fail;
+   }
+
setup_timer(_workaround, otg_timer, (unsigned long)m

Re: [PATCH v5 0/5] da8xx USB PHY platform devices and clocks (was "da8xx UBS clocks")

2016-08-19 Thread David Lechner

On 08/19/2016 11:40 AM, Kevin Hilman wrote:

David,

On Wed, Aug 17, 2016 at 4:35 AM, Kishon Vijay Abraham I <kis...@ti.com> wrote:


Hi Kevin,

On Saturday 13 August 2016 02:54 AM, Kevin Hilman wrote:

On Wed, May 25, 2016 at 6:18 AM, Sekhar Nori <nsek...@ti.com> wrote:

On Monday 23 May 2016 08:44 PM, David Lechner wrote:

On 05/09/2016 06:46 PM, David Lechner wrote:

v5 changes: renamed "usbphy" to "usb_phy" or "usb-phy" as appropriate



[...]



What should I be doing to keep this moving along?


We need the related driver changes to be applied first. I could then use
an immutable branch to push the platform changes against.

I did take a look at the patches and they look good to me. Except the
one comment from Sergei which I just now indicated that I agree with.


Just checking on the status of this.  I'm not seeing the driver
changes in mainline yet.

Any update?


phy driver is already merged which actually introduced a compilation error. The
fix for it is currently queued in linux-phy -fixes and it should be merged in
this -rc cycle.
I think it would be better if David Lechner re-spins the series re-based on top
of latest mainline kernel and then merged by Bin/Alan.


Does this work for you?

Kevin




Yes, I try to get this done in the next few days.
--
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 v5 2/5] ARM: davinci: da8xx: Add CFGCHIP syscon platform declaration.

2016-06-24 Thread David Lechner


Re: USB needing fixed, I'm not sure how to do this and I won't have time
for at least the next 2 or 3 months to do anything about it. The problem
is that the MUSB can't detect the ID pin. As a workaround, it is
detecting the VBUS state and using that to determine the ID pin state.
So, when you attach a self-powered device, it tells the VBUS to turn
off, which in turn triggers the workaround to say that the ID pin has
changed state.


I seem to be missing the original problem report. Can you provide a link
to the discussion?

Thanks,
Sekhar



Here is the thread: https://lkml.org/lkml/2016/5/9/942
--
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 v5 4/7] phy: da8xx-usb: new driver for DA8xx SoC USB PHY

2016-06-22 Thread David Lechner

This is a new phy driver for the SoC USB controllers on the TI DA8xx
family of microcontrollers. The USB 1.1 PHY is just a simple on/off.
The USB 2.0 PHY also allows overriding the VBUS and ID pins.

Signed-off-by: David Lechner <da...@lechnology.com>
Reviewed-by: Sekhar Nori <nsek...@ti.com>
---

Just one small change here. Changed "syscon.0" to "syscon"

(Sorry about the duplicate mail. I replied to the incorrect thread 
previously)



 drivers/phy/Kconfig |  10 ++
 drivers/phy/Makefile|   1 +
 drivers/phy/phy-da8xx-usb.c | 244 


 3 files changed, 255 insertions(+)
 create mode 100644 drivers/phy/phy-da8xx-usb.c

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 26566db..c1d315f 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -35,6 +35,16 @@ config ARMADA375_USBCLUSTER_PHY
 depends on OF && HAS_IOMEM
 select GENERIC_PHY

+config PHY_DA8XX_USB
+tristate "TI DA8xx USB PHY Driver"
+depends on ARCH_DAVINCI_DA8XX
+select GENERIC_PHY
+select MFD_SYSCON
+help
+  Enable this to support the USB PHY on DA8xx SoCs.
+
+  This driver controls both the USB 1.1 PHY and the USB 2.0 PHY.
+
 config PHY_DM816X_USB
 tristate "TI dm816x USB PHY driver"
 depends on ARCH_OMAP2PLUS
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index 24596a9..722e01c 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -5,6 +5,7 @@
 obj-$(CONFIG_GENERIC_PHY)+= phy-core.o
 obj-$(CONFIG_PHY_BERLIN_USB)+= phy-berlin-usb.o
 obj-$(CONFIG_PHY_BERLIN_SATA)+= phy-berlin-sata.o
+obj-$(CONFIG_PHY_DA8XX_USB)+= phy-da8xx-usb.o
 obj-$(CONFIG_PHY_DM816X_USB)+= phy-dm816x-usb.o
 obj-$(CONFIG_ARMADA375_USBCLUSTER_PHY)+= phy-armada375-usb2.o
 obj-$(CONFIG_BCM_KONA_USB2_PHY)+= phy-bcm-kona-usb2.o
diff --git a/drivers/phy/phy-da8xx-usb.c b/drivers/phy/phy-da8xx-usb.c
new file mode 100644
index 000..79af8d2
--- /dev/null
+++ b/drivers/phy/phy-da8xx-usb.c
@@ -0,0 +1,244 @@
+/*
+ * phy-da8xx-usb - TI DaVinci DA8xx USB PHY driver
+ *
+ * Copyright (C) 2016 David Lechner <da...@lechnology.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct da8xx_usb_phy {
+struct phy_provider*phy_provider;
+struct phy*usb11_phy;
+struct phy*usb20_phy;
+struct clk*usb11_clk;
+struct clk*usb20_clk;
+struct regmap*regmap;
+};
+
+static int da8xx_usb11_phy_power_on(struct phy *phy)
+{
+struct da8xx_usb_phy *d_phy = phy_get_drvdata(phy);
+int ret;
+
+ret = clk_prepare_enable(d_phy->usb11_clk);
+if (ret)
+return ret;
+
+regmap_write_bits(d_phy->regmap, CFGCHIP(2), CFGCHIP2_USB1SUSPENDM,
+  CFGCHIP2_USB1SUSPENDM);
+
+return 0;
+}
+
+static int da8xx_usb11_phy_power_off(struct phy *phy)
+{
+struct da8xx_usb_phy *d_phy = phy_get_drvdata(phy);
+
+regmap_write_bits(d_phy->regmap, CFGCHIP(2), CFGCHIP2_USB1SUSPENDM, 0);
+
+clk_disable_unprepare(d_phy->usb11_clk);
+
+return 0;
+}
+
+static const struct phy_ops da8xx_usb11_phy_ops = {
+.power_on= da8xx_usb11_phy_power_on,
+.power_off= da8xx_usb11_phy_power_off,
+.owner= THIS_MODULE,
+};
+
+static int da8xx_usb20_phy_power_on(struct phy *phy)
+{
+struct da8xx_usb_phy *d_phy = phy_get_drvdata(phy);
+int ret;
+
+ret = clk_prepare_enable(d_phy->usb20_clk);
+if (ret)
+return ret;
+
+regmap_write_bits(d_phy->regmap, CFGCHIP(2), CFGCHIP2_OTGPWRDN, 0);
+
+return 0;
+}
+
+static int da8xx_usb20_phy_power_off(struct phy *phy)
+{
+struct da8xx_usb_phy *d_phy = phy_get_drvdata(phy);
+
+regmap_write_bits(d_phy->regmap, CFGCHIP(2), CFGCHIP2_OTGPWRDN,
+  CFGCHIP2_OTGPWRDN);
+
+clk_disable_unprepare(d_phy->usb20_clk);
+
+return 0;
+}
+
+static int da8xx_usb20_phy_set_mode(struct phy *phy, enum phy_mode mode)
+{
+struct da8xx_usb_phy *d_phy = phy_get_drvdata(phy);
+u32 val;
+
+switch (mode) {
+case PHY_MODE_USB_HOST:/* Force VBUS valid, ID = 0 */
+val = CFGCHIP2_OTGMODE_FORCE_HOST;
+break;
+case PHY_MODE_USB_DEVICE:/* Force VBUS valid, ID = 1 */
+val = CFGCHIP2_OTGMODE_FORCE_DEVICE;
+break;
+case PHY_MODE_USB_OTG:/* Don't override the VBUS/ID comparators */
+   

Re: [PATCH v5 3/5] ARM: davinci: da8xx: Add USB PHY platform declaration

2016-06-22 Thread David Lechner

From 53c9b38e0a7860e51ce7bdfe6d4f1d83cf2394a5 Mon Sep 17 00:00:00 2001
From: David Lechner <da...@lechnology.com>
Date: Wed, 16 Mar 2016 14:25:23 -0500
Subject: [PATCH] ARM: davinci: da8xx: Add USB PHY platform declaration

There is now a proper phy driver for the DA8xx SoC USB PHY. This adds the
platform device declarations needed to use it.

Signed-off-by: David Lechner <da...@lechnology.com>
---

id = 0 is changed to id = -1


 arch/arm/mach-davinci/board-da830-evm.c | 28 
+---

 arch/arm/mach-davinci/board-omapl138-hawk.c |  5 +
 arch/arm/mach-davinci/include/mach/da8xx.h  |  1 +
 arch/arm/mach-davinci/usb-da8xx.c   | 11 +++
 4 files changed, 22 insertions(+), 23 deletions(-)

diff --git a/arch/arm/mach-davinci/board-da830-evm.c 
b/arch/arm/mach-davinci/board-da830-evm.c

index 3051cb6..c62766e 100644
--- a/arch/arm/mach-davinci/board-da830-evm.c
+++ b/arch/arm/mach-davinci/board-da830-evm.c
@@ -26,7 +26,6 @@
 #include 
 #include 
 #include 
-#include 

 #include 
 #include 
@@ -106,30 +105,8 @@ static irqreturn_t da830_evm_usb_ocic_irq(int irq, 
void *dev_id)


 static __init void da830_evm_usb_init(void)
 {
-   u32 cfgchip2;
int ret;

-   /*
-* Set up USB clock/mode in the CFGCHIP2 register.
-* FYI:  CFGCHIP2 is 0xef00 initially.
-*/
-   cfgchip2 = __raw_readl(DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
-
-   /*
-* We have to override VBUS/ID signals when MUSB is configured into the
-* host-only mode -- ID pin will float if no cable is connected, so the
-* controller won't be able to drive VBUS thinking that it's a B-device.
-* Otherwise, we want to use the OTG mode and enable VBUS comparators.
-*/
-   cfgchip2 &= ~CFGCHIP2_OTGMODE;
-#ifdef CONFIG_USB_MUSB_HOST
-   cfgchip2 |=  CFGCHIP2_FORCE_HOST;
-#else
-   cfgchip2 |=  CFGCHIP2_SESENDEN | CFGCHIP2_VBDTCTEN;
-#endif
-
-   __raw_writel(cfgchip2, DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
-
/* USB_REFCLKIN is not used. */
ret = da8xx_register_usb20_phy_clk(false);
if (ret)
@@ -141,6 +118,11 @@ static __init void da830_evm_usb_init(void)
pr_warn("%s: USB 1.1 PHY CLK registration failed: %d\n",
__func__, ret);

+   ret = da8xx_register_usb_phy();
+   if (ret)
+   pr_warn("%s: USB PHY registration failed: %d\n",
+   __func__, ret);
+
ret = davinci_cfg_reg(DA830_USB0_DRVVBUS);
if (ret)
pr_warn("%s: USB 2.0 PinMux setup failed: %d\n", __func__, ret);
diff --git a/arch/arm/mach-davinci/board-omapl138-hawk.c 
b/arch/arm/mach-davinci/board-omapl138-hawk.c

index 8691a25..c5cb8d9 100644
--- a/arch/arm/mach-davinci/board-omapl138-hawk.c
+++ b/arch/arm/mach-davinci/board-omapl138-hawk.c
@@ -260,6 +260,11 @@ static __init void omapl138_hawk_usb_init(void)
pr_warn("%s: USB 1.1 PHY CLK registration failed: %d\n",
__func__, ret);

+   ret = da8xx_register_usb_phy();
+   if (ret)
+   pr_warn("%s: USB PHY registration failed: %d\n",
+   __func__, ret);
+
ret = gpio_request_one(DA850_USB1_VBUS_PIN,
GPIOF_DIR_OUT, "USB1 VBUS");
if (ret < 0) {
diff --git a/arch/arm/mach-davinci/include/mach/da8xx.h 
b/arch/arm/mach-davinci/include/mach/da8xx.h

index c32444b..38d932e 100644
--- a/arch/arm/mach-davinci/include/mach/da8xx.h
+++ b/arch/arm/mach-davinci/include/mach/da8xx.h
@@ -92,6 +92,7 @@ int da8xx_register_watchdog(void);
 int da8xx_register_usb_refclkin(int rate);
 int da8xx_register_usb20_phy_clk(bool use_usb_refclkin);
 int da8xx_register_usb11_phy_clk(bool use_usb_refclkin);
+int da8xx_register_usb_phy(void);
 int da8xx_register_usb20(unsigned mA, unsigned potpgt);
 int da8xx_register_usb11(struct da8xx_ohci_root_hub *pdata);
 int da8xx_register_emac(void);
diff --git a/arch/arm/mach-davinci/usb-da8xx.c 
b/arch/arm/mach-davinci/usb-da8xx.c

index c524d9e..7c3175f 100644
--- a/arch/arm/mach-davinci/usb-da8xx.c
+++ b/arch/arm/mach-davinci/usb-da8xx.c
@@ -7,6 +7,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 

 #include 
@@ -230,6 +231,16 @@ int __init da8xx_register_usb11_phy_clk(bool 
use_usb_refclkin)

return ret;
 }

+static struct platform_device da8xx_usb_phy = {
+   .name   = "da8xx-usb-phy",
+   .id = -1,
+};
+
+int __init da8xx_register_usb_phy(void)
+{
+   return platform_device_register(_usb_phy);
+}
+
 #if IS_ENABLED(CONFIG_USB_MUSB_HDRC)

 static struct musb_hdrc_config musb_config = {
--
2.7.4


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


Re: [PATCH v5 2/5] ARM: davinci: da8xx: Add CFGCHIP syscon platform declaration.

2016-06-22 Thread David Lechner

On 05/25/2016 06:15 AM, Sekhar Nori wrote:

On Tuesday 10 May 2016 10:14 PM, David Lechner wrote:

On 05/10/2016 06:26 AM, Sergei Shtylyov wrote:

On 5/10/2016 2:46 AM, David Lechner wrote:


The CFGCHIP registers are used by a number of devices, so using a syscon
device to share them. The first consumer of this will by the
phy-da8xx-usb
driver.

Signed-off-by: David Lechner <da...@lechnology.com>

[...]

diff --git a/arch/arm/mach-davinci/devices-da8xx.c
b/arch/arm/mach-davinci/devices-da8xx.c
index 725e693..69d11a1 100644
--- a/arch/arm/mach-davinci/devices-da8xx.c
+++ b/arch/arm/mach-davinci/devices-da8xx.c
@@ -11,6 +11,7 @@
   * (at your option) any later version.
   */
  #include 
+#include 
  #include 
  #include 
  #include 
@@ -1109,3 +1110,30 @@ int __init da850_register_sata(unsigned long
refclkpn)
  return platform_device_register(_sata_device);
  }
  #endif
+
+static struct syscon_platform_data da8xx_cfgchip_platform_data = {
+.label= "cfgchip",
+};
+
+static struct resource da8xx_cfgchip_resources[] = {
+{
+.start= DA8XX_SYSCFG0_BASE + DA8XX_CFGCHIP0_REG,
+.end= DA8XX_SYSCFG0_BASE + DA8XX_CFGCHIP4_REG + 3,
+.flags= IORESOURCE_MEM,
+},
+};
+
+static struct platform_device da8xx_cfgchip_device = {
+.name= "syscon",
+.id= 0,


 Again, -1.

[...]

MBR, Sergei



I wish you would have noticed this when I first submitted it. I remember
going back and forth about this. But it has been too long and I can't
remember the reason why I chose to go this way.

It seems like changing it broke something with either this one or the
phy device and I opted to keep it this way on both to be consistent. For
example, the USB devices both use id = 0 as well even though there are
only one of each type.


Agree with Sergei here. Can you confirm what broke exactly? I think the
USB needs to be fixed too.

Thanks,
Sekhar



I have made the changes from id = 0 to id = -1. I'm not sure what broke 
before, but it is working now.


Re: USB needing fixed, I'm not sure how to do this and I won't have time 
for at least the next 2 or 3 months to do anything about it. The problem 
is that the MUSB can't detect the ID pin. As a workaround, it is
detecting the VBUS state and using that to determine the ID pin state. 
So, when you attach a self-powered device, it tells the VBUS to turn 
off, which in turn triggers the workaround to say that the ID pin has 
changed state.


If anyone has any ideas on what to do about this, I will be glad to have 
a look at it. It will just have to wait a bit though.



--
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 v5 2/5] ARM: davinci: da8xx: Add CFGCHIP syscon platform declaration.

2016-06-22 Thread David Lechner

From b0ae5eeba849b49f82980218a374c6d3f06487b8 Mon Sep 17 00:00:00 2001
From: David Lechner <da...@lechnology.com>
Date: Thu, 24 Mar 2016 01:38:54 -0500
Subject: [PATCH] ARM: davinci: da8xx: Add CFGCHIP syscon platform 
declaration.


The CFGCHIP registers are used by a number of devices, so using a syscon
device to share them. The first consumer of this will by the phy-da8xx-usb
driver.

Signed-off-by: David Lechner <da...@lechnology.com>
---

the id of syscon is changed from 0 to -1.

 arch/arm/mach-davinci/board-da830-evm.c |  4 
 arch/arm/mach-davinci/board-da850-evm.c |  4 
 arch/arm/mach-davinci/board-mityomapl138.c  |  4 
 arch/arm/mach-davinci/board-omapl138-hawk.c |  4 
 arch/arm/mach-davinci/devices-da8xx.c   | 28 


 arch/arm/mach-davinci/include/mach/da8xx.h  |  2 ++
 6 files changed, 46 insertions(+)

diff --git a/arch/arm/mach-davinci/board-da830-evm.c 
b/arch/arm/mach-davinci/board-da830-evm.c

index 605d444..3051cb6 100644
--- a/arch/arm/mach-davinci/board-da830-evm.c
+++ b/arch/arm/mach-davinci/board-da830-evm.c
@@ -586,6 +586,10 @@ static __init void da830_evm_init(void)
struct davinci_soc_info *soc_info = _soc_info;
int ret;

+   ret = da8xx_register_cfgchip();
+   if (ret)
+   pr_warn("%s: CFGCHIP registration failed: %d\n", __func__, ret);
+
ret = da830_register_gpio();
if (ret)
pr_warn("%s: GPIO init failed: %d\n", __func__, ret);
diff --git a/arch/arm/mach-davinci/board-da850-evm.c 
b/arch/arm/mach-davinci/board-da850-evm.c

index 8e4539f..ec5cb10 100644
--- a/arch/arm/mach-davinci/board-da850-evm.c
+++ b/arch/arm/mach-davinci/board-da850-evm.c
@@ -1345,6 +1345,10 @@ static __init void da850_evm_init(void)
 {
int ret;

+   ret = da8xx_register_cfgchip();
+   if (ret)
+   pr_warn("%s: CFGCHIP registration failed: %d\n", __func__, ret);
+
ret = da850_register_gpio();
if (ret)
pr_warn("%s: GPIO init failed: %d\n", __func__, ret);
diff --git a/arch/arm/mach-davinci/board-mityomapl138.c 
b/arch/arm/mach-davinci/board-mityomapl138.c

index bc4e63f..1a6d430 100644
--- a/arch/arm/mach-davinci/board-mityomapl138.c
+++ b/arch/arm/mach-davinci/board-mityomapl138.c
@@ -514,6 +514,10 @@ static void __init mityomapl138_init(void)
 {
int ret;

+   ret = da8xx_register_cfgchip();
+   if (ret)
+   pr_warn("%s: CFGCHIP registration failed: %d\n", __func__, ret);
+
/* for now, no special EDMA channels are reserved */
ret = da850_register_edma(NULL);
if (ret)
diff --git a/arch/arm/mach-davinci/board-omapl138-hawk.c 
b/arch/arm/mach-davinci/board-omapl138-hawk.c

index d4930b6..8691a25 100644
--- a/arch/arm/mach-davinci/board-omapl138-hawk.c
+++ b/arch/arm/mach-davinci/board-omapl138-hawk.c
@@ -294,6 +294,10 @@ static __init void omapl138_hawk_init(void)
 {
int ret;

+   ret = da8xx_register_cfgchip();
+   if (ret)
+   pr_warn("%s: CFGCHIP registration failed: %d\n", __func__, ret);
+
ret = da850_register_gpio();
if (ret)
pr_warn("%s: GPIO init failed: %d\n", __func__, ret);
diff --git a/arch/arm/mach-davinci/devices-da8xx.c 
b/arch/arm/mach-davinci/devices-da8xx.c

index 725e693..bf5f145 100644
--- a/arch/arm/mach-davinci/devices-da8xx.c
+++ b/arch/arm/mach-davinci/devices-da8xx.c
@@ -11,6 +11,7 @@
  * (at your option) any later version.
  */
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1109,3 +1110,30 @@ int __init da850_register_sata(unsigned long 
refclkpn)

return platform_device_register(_sata_device);
 }
 #endif
+
+static struct syscon_platform_data da8xx_cfgchip_platform_data = {
+   .label  = "cfgchip",
+};
+
+static struct resource da8xx_cfgchip_resources[] = {
+   {
+   .start  = DA8XX_SYSCFG0_BASE + DA8XX_CFGCHIP0_REG,
+   .end= DA8XX_SYSCFG0_BASE + DA8XX_CFGCHIP4_REG + 3,
+   .flags  = IORESOURCE_MEM,
+   },
+};
+
+static struct platform_device da8xx_cfgchip_device = {
+   .name   = "syscon",
+   .id = -1,
+   .dev= {
+   .platform_data  = _cfgchip_platform_data,
+   },
+   .num_resources  = ARRAY_SIZE(da8xx_cfgchip_resources),
+   .resource   = da8xx_cfgchip_resources,
+};
+
+int __init da8xx_register_cfgchip(void)
+{
+   return platform_device_register(_cfgchip_device);
+}
diff --git a/arch/arm/mach-davinci/include/mach/da8xx.h 
b/arch/arm/mach-davinci/include/mach/da8xx.h

index c367530..c32444b 100644
--- a/arch/arm/mach-davinci/include/mach/da8xx.h
+++ b/arch/arm/mach-davinci/include/mach/da8xx.h
@@ -61,6 +61,7 @@ extern unsigned int da850_max_speed;
 #define DA8XX_CFGCHIP1_REG 0x180
 #define DA8XX_CFGCHIP2_REG 0x184
 #define DA8XX_CFGCHIP3_REG 0x18

Re: [PATCH v5 4/7] phy: da8xx-usb: new driver for DA8xx SoC USB PHY

2016-06-22 Thread David Lechner

From 2261f0ea15690623dcefd71b8aaaea6089b16468 Mon Sep 17 00:00:00 2001
From: David Lechner <da...@lechnology.com>
Date: Wed, 16 Mar 2016 14:16:08 -0500
Subject: [PATCH] phy: da8xx-usb: new driver for DA8xx SoC USB PHY

This is a new phy driver for the SoC USB controllers on the TI DA8xx
family of microcontrollers. The USB 1.1 PHY is just a simple on/off.
The USB 2.0 PHY also allows overriding the VBUS and ID pins.

Signed-off-by: David Lechner <da...@lechnology.com>
Reviewed-by: Sekhar Nori <nsek...@ti.com>
---

Just one small change here. Changed "syscon.0" to "syscon"


 drivers/phy/Kconfig |  10 ++
 drivers/phy/Makefile|   1 +
 drivers/phy/phy-da8xx-usb.c | 244 


 3 files changed, 255 insertions(+)
 create mode 100644 drivers/phy/phy-da8xx-usb.c

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 26566db..c1d315f 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -35,6 +35,16 @@ config ARMADA375_USBCLUSTER_PHY
depends on OF && HAS_IOMEM
select GENERIC_PHY

+config PHY_DA8XX_USB
+   tristate "TI DA8xx USB PHY Driver"
+   depends on ARCH_DAVINCI_DA8XX
+   select GENERIC_PHY
+   select MFD_SYSCON
+   help
+ Enable this to support the USB PHY on DA8xx SoCs.
+
+ This driver controls both the USB 1.1 PHY and the USB 2.0 PHY.
+
 config PHY_DM816X_USB
tristate "TI dm816x USB PHY driver"
depends on ARCH_OMAP2PLUS
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index 24596a9..722e01c 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -5,6 +5,7 @@
 obj-$(CONFIG_GENERIC_PHY)  += phy-core.o
 obj-$(CONFIG_PHY_BERLIN_USB)   += phy-berlin-usb.o
 obj-$(CONFIG_PHY_BERLIN_SATA)  += phy-berlin-sata.o
+obj-$(CONFIG_PHY_DA8XX_USB)+= phy-da8xx-usb.o
 obj-$(CONFIG_PHY_DM816X_USB)   += phy-dm816x-usb.o
 obj-$(CONFIG_ARMADA375_USBCLUSTER_PHY) += phy-armada375-usb2.o
 obj-$(CONFIG_BCM_KONA_USB2_PHY)+= phy-bcm-kona-usb2.o
diff --git a/drivers/phy/phy-da8xx-usb.c b/drivers/phy/phy-da8xx-usb.c
new file mode 100644
index 000..79af8d2
--- /dev/null
+++ b/drivers/phy/phy-da8xx-usb.c
@@ -0,0 +1,244 @@
+/*
+ * phy-da8xx-usb - TI DaVinci DA8xx USB PHY driver
+ *
+ * Copyright (C) 2016 David Lechner <da...@lechnology.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct da8xx_usb_phy {
+   struct phy_provider *phy_provider;
+   struct phy  *usb11_phy;
+   struct phy  *usb20_phy;
+   struct clk  *usb11_clk;
+   struct clk  *usb20_clk;
+   struct regmap   *regmap;
+};
+
+static int da8xx_usb11_phy_power_on(struct phy *phy)
+{
+   struct da8xx_usb_phy *d_phy = phy_get_drvdata(phy);
+   int ret;
+
+   ret = clk_prepare_enable(d_phy->usb11_clk);
+   if (ret)
+   return ret;
+
+   regmap_write_bits(d_phy->regmap, CFGCHIP(2), CFGCHIP2_USB1SUSPENDM,
+ CFGCHIP2_USB1SUSPENDM);
+
+   return 0;
+}
+
+static int da8xx_usb11_phy_power_off(struct phy *phy)
+{
+   struct da8xx_usb_phy *d_phy = phy_get_drvdata(phy);
+
+   regmap_write_bits(d_phy->regmap, CFGCHIP(2), CFGCHIP2_USB1SUSPENDM, 0);
+
+   clk_disable_unprepare(d_phy->usb11_clk);
+
+   return 0;
+}
+
+static const struct phy_ops da8xx_usb11_phy_ops = {
+   .power_on   = da8xx_usb11_phy_power_on,
+   .power_off  = da8xx_usb11_phy_power_off,
+   .owner  = THIS_MODULE,
+};
+
+static int da8xx_usb20_phy_power_on(struct phy *phy)
+{
+   struct da8xx_usb_phy *d_phy = phy_get_drvdata(phy);
+   int ret;
+
+   ret = clk_prepare_enable(d_phy->usb20_clk);
+   if (ret)
+   return ret;
+
+   regmap_write_bits(d_phy->regmap, CFGCHIP(2), CFGCHIP2_OTGPWRDN, 0);
+
+   return 0;
+}
+
+static int da8xx_usb20_phy_power_off(struct phy *phy)
+{
+   struct da8xx_usb_phy *d_phy = phy_get_drvdata(phy);
+
+   regmap_write_bits(d_phy->regmap, CFGCHIP(2), CFGCHIP2_OTGPWRDN,
+ CFGCHIP2_OTGPWRDN);
+
+   clk_disable_unprepare(d_phy->usb20_clk);
+
+   return 0;
+}
+
+static int da8xx_usb20_phy_set_mode(struct phy *phy, enum phy_mode mode)
+{
+   struct da8xx_usb_phy *d_phy = phy_get_drvdata(phy);
+   u32 va

Re: [PATCH v5 3/7] phy: Add set_mode callback

2016-06-22 Thread David Lechner

On 06/22/2016 12:57 AM, Kishon Vijay Abraham I wrote:

Hi,

On Tuesday 10 May 2016 05:09 AM, David Lechner wrote:

The initial use for this is for PHYs that have a mode related to USB OTG.
There are several SoCs (e.g. TI OMAP and DA8xx) that have a mode setting
in the USB PHY to override OTG VBUS and ID signals.

Of course, the enum can be expaned in the future to include modes for
other types of PHYs as well.

Suggested-by: Kishon Vijay Abraham I <kis...@ti.com>
Signed-off-by: David Lechner <da...@lechnology.com>


This patch is required for both phy driver and the usb driver. I can create a
immutable branch with only this patch and both me and Bin Liu can merge it in
our next branch.

Thanks
Kishon



I'm new to the kernel merging process, so I am not exactly sure what 
this means, but I think it sounds like a good thing. :-)


--
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 v5 2/5] ARM: davinci: da8xx: Add CFGCHIP syscon platform declaration.

2016-05-10 Thread David Lechner

On 05/10/2016 06:26 AM, Sergei Shtylyov wrote:

On 5/10/2016 2:46 AM, David Lechner wrote:


The CFGCHIP registers are used by a number of devices, so using a syscon
device to share them. The first consumer of this will by the
phy-da8xx-usb
driver.

Signed-off-by: David Lechner <da...@lechnology.com>

[...]

diff --git a/arch/arm/mach-davinci/devices-da8xx.c
b/arch/arm/mach-davinci/devices-da8xx.c
index 725e693..69d11a1 100644
--- a/arch/arm/mach-davinci/devices-da8xx.c
+++ b/arch/arm/mach-davinci/devices-da8xx.c
@@ -11,6 +11,7 @@
  * (at your option) any later version.
  */
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1109,3 +1110,30 @@ int __init da850_register_sata(unsigned long
refclkpn)
 return platform_device_register(_sata_device);
 }
 #endif
+
+static struct syscon_platform_data da8xx_cfgchip_platform_data = {
+.label= "cfgchip",
+};
+
+static struct resource da8xx_cfgchip_resources[] = {
+{
+.start= DA8XX_SYSCFG0_BASE + DA8XX_CFGCHIP0_REG,
+.end= DA8XX_SYSCFG0_BASE + DA8XX_CFGCHIP4_REG + 3,
+.flags= IORESOURCE_MEM,
+},
+};
+
+static struct platform_device da8xx_cfgchip_device = {
+.name= "syscon",
+.id= 0,


Again, -1.

[...]

MBR, Sergei



I wish you would have noticed this when I first submitted it. I remember 
going back and forth about this. But it has been too long and I can't 
remember the reason why I chose to go this way.


It seems like changing it broke something with either this one or the 
phy device and I opted to keep it this way on both to be consistent. For 
example, the USB devices both use id = 0 as well even though there are 
only one of each type.

--
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/5] ARM: davinci: da8xx: Add USB PHY platform declaration

2016-05-09 Thread David Lechner
There is now a proper phy driver for the DA8xx SoC USB PHY. This adds the
platform device declarations needed to use it.

Signed-off-by: David Lechner <da...@lechnology.com>
---
 arch/arm/mach-davinci/board-da830-evm.c | 28 +---
 arch/arm/mach-davinci/board-omapl138-hawk.c |  5 +
 arch/arm/mach-davinci/include/mach/da8xx.h  |  1 +
 arch/arm/mach-davinci/usb-da8xx.c   | 11 +++
 4 files changed, 22 insertions(+), 23 deletions(-)

diff --git a/arch/arm/mach-davinci/board-da830-evm.c 
b/arch/arm/mach-davinci/board-da830-evm.c
index 3051cb6..c62766e 100644
--- a/arch/arm/mach-davinci/board-da830-evm.c
+++ b/arch/arm/mach-davinci/board-da830-evm.c
@@ -26,7 +26,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include 
 #include 
@@ -106,30 +105,8 @@ static irqreturn_t da830_evm_usb_ocic_irq(int irq, void 
*dev_id)
 
 static __init void da830_evm_usb_init(void)
 {
-   u32 cfgchip2;
int ret;
 
-   /*
-* Set up USB clock/mode in the CFGCHIP2 register.
-* FYI:  CFGCHIP2 is 0xef00 initially.
-*/
-   cfgchip2 = __raw_readl(DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
-
-   /*
-* We have to override VBUS/ID signals when MUSB is configured into the
-* host-only mode -- ID pin will float if no cable is connected, so the
-* controller won't be able to drive VBUS thinking that it's a B-device.
-* Otherwise, we want to use the OTG mode and enable VBUS comparators.
-*/
-   cfgchip2 &= ~CFGCHIP2_OTGMODE;
-#ifdef CONFIG_USB_MUSB_HOST
-   cfgchip2 |=  CFGCHIP2_FORCE_HOST;
-#else
-   cfgchip2 |=  CFGCHIP2_SESENDEN | CFGCHIP2_VBDTCTEN;
-#endif
-
-   __raw_writel(cfgchip2, DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
-
/* USB_REFCLKIN is not used. */
ret = da8xx_register_usb20_phy_clk(false);
if (ret)
@@ -141,6 +118,11 @@ static __init void da830_evm_usb_init(void)
pr_warn("%s: USB 1.1 PHY CLK registration failed: %d\n",
__func__, ret);
 
+   ret = da8xx_register_usb_phy();
+   if (ret)
+   pr_warn("%s: USB PHY registration failed: %d\n",
+   __func__, ret);
+
ret = davinci_cfg_reg(DA830_USB0_DRVVBUS);
if (ret)
pr_warn("%s: USB 2.0 PinMux setup failed: %d\n", __func__, ret);
diff --git a/arch/arm/mach-davinci/board-omapl138-hawk.c 
b/arch/arm/mach-davinci/board-omapl138-hawk.c
index 8691a25..c5cb8d9 100644
--- a/arch/arm/mach-davinci/board-omapl138-hawk.c
+++ b/arch/arm/mach-davinci/board-omapl138-hawk.c
@@ -260,6 +260,11 @@ static __init void omapl138_hawk_usb_init(void)
pr_warn("%s: USB 1.1 PHY CLK registration failed: %d\n",
__func__, ret);
 
+   ret = da8xx_register_usb_phy();
+   if (ret)
+   pr_warn("%s: USB PHY registration failed: %d\n",
+   __func__, ret);
+
ret = gpio_request_one(DA850_USB1_VBUS_PIN,
GPIOF_DIR_OUT, "USB1 VBUS");
if (ret < 0) {
diff --git a/arch/arm/mach-davinci/include/mach/da8xx.h 
b/arch/arm/mach-davinci/include/mach/da8xx.h
index c32444b..38d932e 100644
--- a/arch/arm/mach-davinci/include/mach/da8xx.h
+++ b/arch/arm/mach-davinci/include/mach/da8xx.h
@@ -92,6 +92,7 @@ int da8xx_register_watchdog(void);
 int da8xx_register_usb_refclkin(int rate);
 int da8xx_register_usb20_phy_clk(bool use_usb_refclkin);
 int da8xx_register_usb11_phy_clk(bool use_usb_refclkin);
+int da8xx_register_usb_phy(void);
 int da8xx_register_usb20(unsigned mA, unsigned potpgt);
 int da8xx_register_usb11(struct da8xx_ohci_root_hub *pdata);
 int da8xx_register_emac(void);
diff --git a/arch/arm/mach-davinci/usb-da8xx.c 
b/arch/arm/mach-davinci/usb-da8xx.c
index c524d9e..9e41a7f 100644
--- a/arch/arm/mach-davinci/usb-da8xx.c
+++ b/arch/arm/mach-davinci/usb-da8xx.c
@@ -7,6 +7,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -230,6 +231,16 @@ int __init da8xx_register_usb11_phy_clk(bool 
use_usb_refclkin)
return ret;
 }
 
+static struct platform_device da8xx_usb_phy = {
+   .name   = "da8xx-usb-phy",
+   .id = 0,
+};
+
+int __init da8xx_register_usb_phy(void)
+{
+   return platform_device_register(_usb_phy);
+}
+
 #if IS_ENABLED(CONFIG_USB_MUSB_HDRC)
 
 static struct musb_hdrc_config musb_config = {
-- 
2.7.4

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


[PATCH v5 1/5] ARM: davinci: da8xx: add usb phy clocks

2016-05-09 Thread David Lechner
Up to this point, the USB phy clock configuration was handled manually in
the board files and in the usb drivers. This adds proper clocks so that
the usb drivers can use clk_get and clk_enable and not have to worry about
the details. Also, the related code is removed from the board files and
replaced with the new clock registration functions.

Signed-off-by: David Lechner <da...@lechnology.com>
---
 arch/arm/mach-davinci/board-da830-evm.c |  22 ++-
 arch/arm/mach-davinci/board-omapl138-hawk.c |  16 +-
 arch/arm/mach-davinci/include/mach/da8xx.h  |   3 +
 arch/arm/mach-davinci/usb-da8xx.c   | 219 +++-
 4 files changed, 239 insertions(+), 21 deletions(-)

diff --git a/arch/arm/mach-davinci/board-da830-evm.c 
b/arch/arm/mach-davinci/board-da830-evm.c
index 3d8cf8c..605d444 100644
--- a/arch/arm/mach-davinci/board-da830-evm.c
+++ b/arch/arm/mach-davinci/board-da830-evm.c
@@ -115,18 +115,6 @@ static __init void da830_evm_usb_init(void)
 */
cfgchip2 = __raw_readl(DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
 
-   /* USB2.0 PHY reference clock is 24 MHz */
-   cfgchip2 &= ~CFGCHIP2_REFFREQ;
-   cfgchip2 |=  CFGCHIP2_REFFREQ_24MHZ;
-
-   /*
-* Select internal reference clock for USB 2.0 PHY
-* and use it as a clock source for USB 1.1 PHY
-* (this is the default setting anyway).
-*/
-   cfgchip2 &= ~CFGCHIP2_USB1PHYCLKMUX;
-   cfgchip2 |=  CFGCHIP2_USB2PHYCLKMUX;
-
/*
 * We have to override VBUS/ID signals when MUSB is configured into the
 * host-only mode -- ID pin will float if no cable is connected, so the
@@ -143,6 +131,16 @@ static __init void da830_evm_usb_init(void)
__raw_writel(cfgchip2, DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
 
/* USB_REFCLKIN is not used. */
+   ret = da8xx_register_usb20_phy_clk(false);
+   if (ret)
+   pr_warn("%s: USB 2.0 PHY CLK registration failed: %d\n",
+   __func__, ret);
+
+   ret = da8xx_register_usb11_phy_clk(false);
+   if (ret)
+   pr_warn("%s: USB 1.1 PHY CLK registration failed: %d\n",
+   __func__, ret);
+
ret = davinci_cfg_reg(DA830_USB0_DRVVBUS);
if (ret)
pr_warn("%s: USB 2.0 PinMux setup failed: %d\n", __func__, ret);
diff --git a/arch/arm/mach-davinci/board-omapl138-hawk.c 
b/arch/arm/mach-davinci/board-omapl138-hawk.c
index ee62486..d4930b6 100644
--- a/arch/arm/mach-davinci/board-omapl138-hawk.c
+++ b/arch/arm/mach-davinci/board-omapl138-hawk.c
@@ -243,7 +243,6 @@ static irqreturn_t omapl138_hawk_usb_ocic_irq(int irq, void 
*dev_id)
 static __init void omapl138_hawk_usb_init(void)
 {
int ret;
-   u32 cfgchip2;
 
ret = davinci_cfg_reg_list(da850_hawk_usb11_pins);
if (ret) {
@@ -251,12 +250,15 @@ static __init void omapl138_hawk_usb_init(void)
return;
}
 
-   /* Setup the Ref. clock frequency for the HAWK at 24 MHz. */
-
-   cfgchip2 = __raw_readl(DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
-   cfgchip2 &= ~CFGCHIP2_REFFREQ;
-   cfgchip2 |=  CFGCHIP2_REFFREQ_24MHZ;
-   __raw_writel(cfgchip2, DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
+   /* USB_REFCLKIN is not used. */
+   ret = da8xx_register_usb20_phy_clk(false);
+   if (ret)
+   pr_warn("%s: USB 2.0 PHY CLK registration failed: %d\n",
+   __func__, ret);
+   ret = da8xx_register_usb11_phy_clk(false);
+   if (ret)
+   pr_warn("%s: USB 1.1 PHY CLK registration failed: %d\n",
+   __func__, ret);
 
ret = gpio_request_one(DA850_USB1_VBUS_PIN,
GPIOF_DIR_OUT, "USB1 VBUS");
diff --git a/arch/arm/mach-davinci/include/mach/da8xx.h 
b/arch/arm/mach-davinci/include/mach/da8xx.h
index f9f9713..c367530 100644
--- a/arch/arm/mach-davinci/include/mach/da8xx.h
+++ b/arch/arm/mach-davinci/include/mach/da8xx.h
@@ -88,6 +88,9 @@ int da850_register_edma(struct edma_rsv_info *rsv[2]);
 int da8xx_register_i2c(int instance, struct davinci_i2c_platform_data *pdata);
 int da8xx_register_spi_bus(int instance, unsigned num_chipselect);
 int da8xx_register_watchdog(void);
+int da8xx_register_usb_refclkin(int rate);
+int da8xx_register_usb20_phy_clk(bool use_usb_refclkin);
+int da8xx_register_usb11_phy_clk(bool use_usb_refclkin);
 int da8xx_register_usb20(unsigned mA, unsigned potpgt);
 int da8xx_register_usb11(struct da8xx_ohci_root_hub *pdata);
 int da8xx_register_emac(void);
diff --git a/arch/arm/mach-davinci/usb-da8xx.c 
b/arch/arm/mach-davinci/usb-da8xx.c
index f141f51..c524d9e 100644
--- a/arch/arm/mach-davinci/usb-da8xx.c
+++ b/arch/arm/mach-davinci/usb-da8xx.c
@@ -1,20 +1,235 @@
 /*
  * DA8xx USB
  */
-#include 
+#include 
+#include 
 #include 
 #include 
 #include 
+#include 
 #include 
 
+#include 
 #include 
 #i

[PATCH v5 4/5] ARM: DTS: da850: Add cfgchip syscon node

2016-05-09 Thread David Lechner
Add a syscon node for the SoC CFGCHIPn registers. This is needed for
the new usb phy driver.

Signed-off-by: David Lechner <da...@lechnology.com>
---
 arch/arm/boot/dts/da850.dtsi | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/arm/boot/dts/da850.dtsi b/arch/arm/boot/dts/da850.dtsi
index cf1aad8..9546ace 100644
--- a/arch/arm/boot/dts/da850.dtsi
+++ b/arch/arm/boot/dts/da850.dtsi
@@ -168,6 +168,10 @@
};
 
};
+   cfgchip: cfgchip@1417c {
+   compatible = "ti,da830-cfgchip", "syscon";
+   reg = <0x1417c 0x14>;
+   };
edma0: edma@0 {
compatible = "ti,edma3-tpcc";
/* eDMA3 CC0: 0x01c0  - 0x01c0 7fff */
-- 
2.7.4

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


[PATCH v5 2/5] ARM: davinci: da8xx: Add CFGCHIP syscon platform declaration.

2016-05-09 Thread David Lechner
The CFGCHIP registers are used by a number of devices, so using a syscon
device to share them. The first consumer of this will by the phy-da8xx-usb
driver.

Signed-off-by: David Lechner <da...@lechnology.com>
---
 arch/arm/mach-davinci/board-da830-evm.c |  4 
 arch/arm/mach-davinci/board-da850-evm.c |  4 
 arch/arm/mach-davinci/board-mityomapl138.c  |  4 
 arch/arm/mach-davinci/board-omapl138-hawk.c |  4 
 arch/arm/mach-davinci/devices-da8xx.c   | 28 
 arch/arm/mach-davinci/include/mach/da8xx.h  |  2 ++
 6 files changed, 46 insertions(+)

diff --git a/arch/arm/mach-davinci/board-da830-evm.c 
b/arch/arm/mach-davinci/board-da830-evm.c
index 605d444..3051cb6 100644
--- a/arch/arm/mach-davinci/board-da830-evm.c
+++ b/arch/arm/mach-davinci/board-da830-evm.c
@@ -586,6 +586,10 @@ static __init void da830_evm_init(void)
struct davinci_soc_info *soc_info = _soc_info;
int ret;
 
+   ret = da8xx_register_cfgchip();
+   if (ret)
+   pr_warn("%s: CFGCHIP registration failed: %d\n", __func__, ret);
+
ret = da830_register_gpio();
if (ret)
pr_warn("%s: GPIO init failed: %d\n", __func__, ret);
diff --git a/arch/arm/mach-davinci/board-da850-evm.c 
b/arch/arm/mach-davinci/board-da850-evm.c
index 8e4539f..ec5cb10 100644
--- a/arch/arm/mach-davinci/board-da850-evm.c
+++ b/arch/arm/mach-davinci/board-da850-evm.c
@@ -1345,6 +1345,10 @@ static __init void da850_evm_init(void)
 {
int ret;
 
+   ret = da8xx_register_cfgchip();
+   if (ret)
+   pr_warn("%s: CFGCHIP registration failed: %d\n", __func__, ret);
+
ret = da850_register_gpio();
if (ret)
pr_warn("%s: GPIO init failed: %d\n", __func__, ret);
diff --git a/arch/arm/mach-davinci/board-mityomapl138.c 
b/arch/arm/mach-davinci/board-mityomapl138.c
index bc4e63f..1a6d430 100644
--- a/arch/arm/mach-davinci/board-mityomapl138.c
+++ b/arch/arm/mach-davinci/board-mityomapl138.c
@@ -514,6 +514,10 @@ static void __init mityomapl138_init(void)
 {
int ret;
 
+   ret = da8xx_register_cfgchip();
+   if (ret)
+   pr_warn("%s: CFGCHIP registration failed: %d\n", __func__, ret);
+
/* for now, no special EDMA channels are reserved */
ret = da850_register_edma(NULL);
if (ret)
diff --git a/arch/arm/mach-davinci/board-omapl138-hawk.c 
b/arch/arm/mach-davinci/board-omapl138-hawk.c
index d4930b6..8691a25 100644
--- a/arch/arm/mach-davinci/board-omapl138-hawk.c
+++ b/arch/arm/mach-davinci/board-omapl138-hawk.c
@@ -294,6 +294,10 @@ static __init void omapl138_hawk_init(void)
 {
int ret;
 
+   ret = da8xx_register_cfgchip();
+   if (ret)
+   pr_warn("%s: CFGCHIP registration failed: %d\n", __func__, ret);
+
ret = da850_register_gpio();
if (ret)
pr_warn("%s: GPIO init failed: %d\n", __func__, ret);
diff --git a/arch/arm/mach-davinci/devices-da8xx.c 
b/arch/arm/mach-davinci/devices-da8xx.c
index 725e693..69d11a1 100644
--- a/arch/arm/mach-davinci/devices-da8xx.c
+++ b/arch/arm/mach-davinci/devices-da8xx.c
@@ -11,6 +11,7 @@
  * (at your option) any later version.
  */
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1109,3 +1110,30 @@ int __init da850_register_sata(unsigned long refclkpn)
return platform_device_register(_sata_device);
 }
 #endif
+
+static struct syscon_platform_data da8xx_cfgchip_platform_data = {
+   .label  = "cfgchip",
+};
+
+static struct resource da8xx_cfgchip_resources[] = {
+   {
+   .start  = DA8XX_SYSCFG0_BASE + DA8XX_CFGCHIP0_REG,
+   .end= DA8XX_SYSCFG0_BASE + DA8XX_CFGCHIP4_REG + 3,
+   .flags  = IORESOURCE_MEM,
+   },
+};
+
+static struct platform_device da8xx_cfgchip_device = {
+   .name   = "syscon",
+   .id = 0,
+   .dev= {
+   .platform_data  = _cfgchip_platform_data,
+   },
+   .num_resources  = ARRAY_SIZE(da8xx_cfgchip_resources),
+   .resource   = da8xx_cfgchip_resources,
+};
+
+int __init da8xx_register_cfgchip(void)
+{
+   return platform_device_register(_cfgchip_device);
+}
diff --git a/arch/arm/mach-davinci/include/mach/da8xx.h 
b/arch/arm/mach-davinci/include/mach/da8xx.h
index c367530..c32444b 100644
--- a/arch/arm/mach-davinci/include/mach/da8xx.h
+++ b/arch/arm/mach-davinci/include/mach/da8xx.h
@@ -61,6 +61,7 @@ extern unsigned int da850_max_speed;
 #define DA8XX_CFGCHIP1_REG 0x180
 #define DA8XX_CFGCHIP2_REG 0x184
 #define DA8XX_CFGCHIP3_REG 0x188
+#define DA8XX_CFGCHIP4_REG 0x18c
 
 #define DA8XX_SYSCFG1_BASE (IO_PHYS + 0x22C000)
 #define DA8XX_SYSCFG1_VIRT(x)  (da8xx_syscfg1_base + (x))
@@ -116,6 +117,7 @@ void da8xx_rproc_reserve_cma(void);
 int da8xx_register_rproc(void);
 int da850_register_gpio(void);
 int da830_register_gpi

[PATCH v5 5/5] ARM: DTS: da850: Add usb phy node

2016-05-09 Thread David Lechner
Add a node for the new usb phy driver.

Signed-off-by: David Lechner <da...@lechnology.com>
---
 arch/arm/boot/dts/da850.dtsi | 5 +
 1 file changed, 5 insertions(+)

diff --git a/arch/arm/boot/dts/da850.dtsi b/arch/arm/boot/dts/da850.dtsi
index 9546ace..b2ebbe5 100644
--- a/arch/arm/boot/dts/da850.dtsi
+++ b/arch/arm/boot/dts/da850.dtsi
@@ -351,6 +351,11 @@
>;
status = "disabled";
};
+   usb_phy: usb-phy {
+   compatible = "ti,da830-usb-phy";
+   #phy-cells = <1>;
+   status = "disabled";
+   };
gpio: gpio@226000 {
compatible = "ti,dm6441-gpio";
gpio-controller;
-- 
2.7.4

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


[PATCH v5 0/5] da8xx USB PHY platform devices and clocks (was "da8xx UBS clocks")

2016-05-09 Thread David Lechner
v5 changes: renamed "usbphy" to "usb_phy" or "usb-phy" as appropriate

David Lechner (5):
  ARM: davinci: da8xx: add usb phy clocks
  ARM: davinci: da8xx: Add CFGCHIP syscon platform declaration.
  ARM: davinci: da8xx: Add USB PHY platform declaration
  ARM: DTS: da850: Add cfgchip syscon node
  ARM: DTS: da850: Add usb phy node

 arch/arm/boot/dts/da850.dtsi|   9 ++
 arch/arm/mach-davinci/board-da830-evm.c |  52 +++
 arch/arm/mach-davinci/board-da850-evm.c |   4 +
 arch/arm/mach-davinci/board-mityomapl138.c  |   4 +
 arch/arm/mach-davinci/board-omapl138-hawk.c |  23 ++-
 arch/arm/mach-davinci/devices-da8xx.c   |  28 
 arch/arm/mach-davinci/include/mach/da8xx.h  |   6 +
 arch/arm/mach-davinci/usb-da8xx.c   | 230 +++-
 8 files changed, 314 insertions(+), 42 deletions(-)

-- 
2.7.4

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


[PATCH v5 2/7] dt-bindings: Add bindings for phy-da8xx-usb

2016-05-09 Thread David Lechner
Device tree binding for new phy-da8xx-usb driver.

Signed-off-by: David Lechner <da...@lechnology.com>
Acked-by: Rob Herring <r...@kernel.org>
---
 .../devicetree/bindings/phy/phy-da8xx-usb.txt  | 40 ++
 1 file changed, 40 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/phy-da8xx-usb.txt

diff --git a/Documentation/devicetree/bindings/phy/phy-da8xx-usb.txt 
b/Documentation/devicetree/bindings/phy/phy-da8xx-usb.txt
new file mode 100644
index 000..c26478b
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/phy-da8xx-usb.txt
@@ -0,0 +1,40 @@
+TI DA8xx/OMAP-L1xx/AM18xx USB PHY
+
+Required properties:
+ - compatible: must be "ti,da830-usb-phy".
+ - #phy-cells: must be 1.
+
+This device controls the PHY for both the USB 1.1 OHCI and USB 2.0 OTG
+controllers on DA8xx SoCs. Consumers of this device should use index 0 for
+the USB 2.0 phy device and index 1 for the USB 1.1 phy device.
+
+It also requires a "syscon" node with compatible = "ti,da830-cfgchip", "syscon"
+to access the CFGCHIP2 register.
+
+Example:
+
+   cfgchip: cfgchip@1417c {
+   compatible = "ti,da830-cfgchip", "syscon";
+   reg = <0x1417c 0x14>;
+   };
+
+   usb_phy: usb-phy {
+   compatible = "ti,da830-usb-phy";
+   #phy-cells = <1>;
+   };
+
+   usb20: usb@20 {
+   compatible = "ti,da830-musb";
+   reg = <0x20 0x1000>;
+   interrupts = <58>;
+   phys = <_phy 0>;
+   phy-names = "usb-phy";
+   };
+
+   usb11: usb@225000 {
+   compatible = "ti,da830-ohci";
+   reg = <0x225000 0x1000>;
+   interrupts = <59>;
+   phys = <_phy 1>;
+   phy-names = "usb-phy";
+   };
-- 
2.7.4

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


[PATCH v5 0/7] da8xx USB PHY (was da8xx USB clocks)

2016-05-09 Thread David Lechner
v5 changes:

Functionally, nothing has really changed. Just some cleanups based on feedback.

* Renamed "usbphy" to "usb_phy" or "usb-phy" as appropriate
* License header matches MODULE_LICENSE in new phy driver

David Lechner (7):
  mfd: da8xx-cfgchip: New header file for CFGCHIP registers.
  dt-bindings: Add bindings for phy-da8xx-usb
  phy: Add set_mode callback
  phy: da8xx-usb: new driver for DA8xx SoC USB PHY
  usb: ohci-da8xx: Remove code that references mach
  usb: musb: da8xx: Use devm in probe
  usb: musb: da8xx: Remove mach code

 .../devicetree/bindings/phy/phy-da8xx-usb.txt  |  40 
 drivers/phy/Kconfig|  10 +
 drivers/phy/Makefile   |   1 +
 drivers/phy/phy-core.c |  15 ++
 drivers/phy/phy-da8xx-usb.c| 244 +
 drivers/usb/host/Kconfig   |   1 +
 drivers/usb/host/ohci-da8xx.c  | 102 +
 drivers/usb/musb/Kconfig   |   2 +-
 drivers/usb/musb/da8xx.c   | 154 +
 include/linux/mfd/da8xx-cfgchip.h  | 153 +
 include/linux/phy/phy.h|  17 ++
 include/linux/platform_data/usb-davinci.h  |  22 --
 12 files changed, 592 insertions(+), 169 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/phy/phy-da8xx-usb.txt
 create mode 100644 drivers/phy/phy-da8xx-usb.c
 create mode 100644 include/linux/mfd/da8xx-cfgchip.h

-- 
2.7.4

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


[PATCH v5 1/7] mfd: da8xx-cfgchip: New header file for CFGCHIP registers.

2016-05-09 Thread David Lechner
We will be using a generic syscon device for the TI DA8XX SoC CFGCHIPx
retisters. This will be used by a number of planned drivers including a
new USB PHY driver and common clock framework drivers.

The same defines are removed from the platform_data header file since they
are now redundant and they didn't really belong there anyway.

Signed-off-by: David Lechner <da...@lechnology.com>
Acked-by: Lee Jones <lee.jo...@linaro.org>
---
 include/linux/mfd/da8xx-cfgchip.h | 153 ++
 include/linux/platform_data/usb-davinci.h |  22 -
 2 files changed, 153 insertions(+), 22 deletions(-)
 create mode 100644 include/linux/mfd/da8xx-cfgchip.h

diff --git a/include/linux/mfd/da8xx-cfgchip.h 
b/include/linux/mfd/da8xx-cfgchip.h
new file mode 100644
index 000..304985e
--- /dev/null
+++ b/include/linux/mfd/da8xx-cfgchip.h
@@ -0,0 +1,153 @@
+/*
+ * TI DaVinci DA8xx CHIPCFGx registers for syscon consumers.
+ *
+ * Copyright (C) 2016 David Lechner <da...@lechnology.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef __LINUX_MFD_DA8XX_CFGCHIP_H
+#define __LINUX_MFD_DA8XX_CFGCHIP_H
+
+#include 
+
+/* register offset (32-bit registers) */
+#define CFGCHIP(n) ((n) * 4)
+
+/* CFGCHIP0 (PLL0/EDMA3_0) register bits */
+#define CFGCHIP0_PLL_MASTER_LOCK   BIT(4)
+#define CFGCHIP0_EDMA30TC1DBS(n)   ((n) << 2)
+#define CFGCHIP0_EDMA30TC1DBS_MASK CFGCHIP0_EDMA30TC1DBS(0x3)
+#define CFGCHIP0_EDMA30TC1DBS_16   CFGCHIP0_EDMA30TC1DBS(0x0)
+#define CFGCHIP0_EDMA30TC1DBS_32   CFGCHIP0_EDMA30TC1DBS(0x1)
+#define CFGCHIP0_EDMA30TC1DBS_64   CFGCHIP0_EDMA30TC1DBS(0x2)
+#define CFGCHIP0_EDMA30TC0DBS(n)   ((n) << 0)
+#define CFGCHIP0_EDMA30TC0DBS_MASK CFGCHIP0_EDMA30TC0DBS(0x3)
+#define CFGCHIP0_EDMA30TC0DBS_16   CFGCHIP0_EDMA30TC0DBS(0x0)
+#define CFGCHIP0_EDMA30TC0DBS_32   CFGCHIP0_EDMA30TC0DBS(0x1)
+#define CFGCHIP0_EDMA30TC0DBS_64   CFGCHIP0_EDMA30TC0DBS(0x2)
+
+/* CFGCHIP1 (eCAP/HPI/EDMA3_1/eHRPWM TBCLK/McASP0 AMUTEIN) register bits */
+#define CFGCHIP1_CAP2SRC(n)((n) << 27)
+#define CFGCHIP1_CAP2SRC_MASK  CFGCHIP1_CAP2SRC(0x1f)
+#define CFGCHIP1_CAP2SRC_ECAP_PIN  CFGCHIP1_CAP2SRC(0x0)
+#define CFGCHIP1_CAP2SRC_MCASP0_TX CFGCHIP1_CAP2SRC(0x1)
+#define CFGCHIP1_CAP2SRC_MCASP0_RX CFGCHIP1_CAP2SRC(0x2)
+#define CFGCHIP1_CAP2SRC_EMAC_C0_RX_THRESHOLD  CFGCHIP1_CAP2SRC(0x7)
+#define CFGCHIP1_CAP2SRC_EMAC_C0_RXCFGCHIP1_CAP2SRC(0x8)
+#define CFGCHIP1_CAP2SRC_EMAC_C0_TXCFGCHIP1_CAP2SRC(0x9)
+#define CFGCHIP1_CAP2SRC_EMAC_C0_MISC  CFGCHIP1_CAP2SRC(0xa)
+#define CFGCHIP1_CAP2SRC_EMAC_C1_RX_THRESHOLD  CFGCHIP1_CAP2SRC(0xb)
+#define CFGCHIP1_CAP2SRC_EMAC_C1_RXCFGCHIP1_CAP2SRC(0xc)
+#define CFGCHIP1_CAP2SRC_EMAC_C1_TXCFGCHIP1_CAP2SRC(0xd)
+#define CFGCHIP1_CAP2SRC_EMAC_C1_MISC  CFGCHIP1_CAP2SRC(0xe)
+#define CFGCHIP1_CAP2SRC_EMAC_C2_RX_THRESHOLD  CFGCHIP1_CAP2SRC(0xf)
+#define CFGCHIP1_CAP2SRC_EMAC_C2_RXCFGCHIP1_CAP2SRC(0x10)
+#define CFGCHIP1_CAP2SRC_EMAC_C2_TXCFGCHIP1_CAP2SRC(0x11)
+#define CFGCHIP1_CAP2SRC_EMAC_C2_MISC  CFGCHIP1_CAP2SRC(0x12)
+#define CFGCHIP1_CAP1SRC(n)((n) << 22)
+#define CFGCHIP1_CAP1SRC_MASK  CFGCHIP1_CAP1SRC(0x1f)
+#define CFGCHIP1_CAP1SRC_ECAP_PIN  CFGCHIP1_CAP1SRC(0x0)
+#define CFGCHIP1_CAP1SRC_MCASP0_TX CFGCHIP1_CAP1SRC(0x1)
+#define CFGCHIP1_CAP1SRC_MCASP0_RX CFGCHIP1_CAP1SRC(0x2)
+#define CFGCHIP1_CAP1SRC_EMAC_C0_RX_THRESHOLD  CFGCHIP1_CAP1SRC(0x7)
+#define CFGCHIP1_CAP1SRC_EMAC_C0_RXCFGCHIP1_CAP1SRC(0x8)
+#define CFGCHIP1_CAP1SRC_EMAC_C0_TXCFGCHIP1_CAP1SRC(0x9)
+#define CFGCHIP1_CAP1SRC_EMAC_C0_MISC  CFGCHIP1_CAP1SRC(0xa)
+#define CFGCHIP1_CAP1SRC_EMAC_C1_RX_THRESHOLD  CFGCHIP1_CAP1SRC(0xb)
+#define CFGCHIP1_CAP1SRC_EMAC_C1_RXCFGCHIP1_CAP1SRC(0xc)
+#define CFGCHIP1_CAP1SRC_EMAC_C1_TXCFGCHIP1_CAP1SRC(0xd)
+#define CFGCHIP1_CAP1SRC_EMAC_C1_MISC  CFGCHIP1_CAP1SRC(0xe)
+#define CFGCHIP1_CAP1SRC_EMAC_C2_RX_THRESHOLD  CFGCHIP1_CAP1SRC(0xf)
+#define CFGCHIP1_CAP1SRC_EMAC_C2_RXCFGCHIP1_CAP1SRC(0x10)
+#define CFGCHIP1_CAP1SRC_EMAC_C2_TXCFGCHIP1_CAP1SRC(0x11)
+#define CFGCHIP1_CAP1SRC_EMAC_C2_MIS

[PATCH v5 6/7] usb: musb: da8xx: Use devm in probe

2016-05-09 Thread David Lechner
Simplify things a bit by using devm functions where possible.

Signed-off-by: David Lechner <da...@lechnology.com>
---
 drivers/usb/musb/da8xx.c | 19 +--
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index b03d3b8..0c1997c 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -490,20 +490,18 @@ static int da8xx_probe(struct platform_device *pdev)
struct da8xx_glue   *glue;
struct platform_device_info pinfo;
struct clk  *clk;
+   int ret;
 
-   int ret = -ENOMEM;
-
-   glue = kzalloc(sizeof(*glue), GFP_KERNEL);
+   glue = devm_kzalloc(>dev, sizeof(*glue), GFP_KERNEL);
if (!glue) {
dev_err(>dev, "failed to allocate glue context\n");
-   goto err0;
+   return -ENOMEM;
}
 
-   clk = clk_get(>dev, "usb20");
+   clk = devm_clk_get(>dev, "usb20");
if (IS_ERR(clk)) {
dev_err(>dev, "failed to get clock\n");
-   ret = PTR_ERR(clk);
-   goto err3;
+   return PTR_ERR(clk);
}
 
ret = clk_enable(clk);
@@ -560,12 +558,7 @@ err5:
clk_disable(clk);
 
 err4:
-   clk_put(clk);
-
-err3:
-   kfree(glue);
 
-err0:
return ret;
 }
 
@@ -576,8 +569,6 @@ static int da8xx_remove(struct platform_device *pdev)
platform_device_unregister(glue->musb);
usb_phy_generic_unregister(glue->phy);
clk_disable(glue->clk);
-   clk_put(glue->clk);
-   kfree(glue);
 
return 0;
 }
-- 
2.7.4

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


[PATCH v5 5/7] usb: ohci-da8xx: Remove code that references mach

2016-05-09 Thread David Lechner
Including mach/* is frowned upon in device drivers, so get rid of it.

This replaces usb20_clk and code that pokes CFGCHIP2 with a proper phy
driver.

Signed-off-by: David Lechner <da...@lechnology.com>
Acked-by: Alan Stern <st...@rowland.harvard.edu>
---
 drivers/usb/host/Kconfig  |   1 +
 drivers/usb/host/ohci-da8xx.c | 102 +++---
 2 files changed, 56 insertions(+), 47 deletions(-)

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 3050b18..e4432c6 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -472,6 +472,7 @@ config USB_OHCI_HCD_DAVINCI
bool "OHCI support for TI DaVinci DA8xx"
depends on ARCH_DAVINCI_DA8XX
depends on USB_OHCI_HCD=y
+   select PHY_DA8XX_USB
default y
help
  Enables support for the DaVinci DA8xx integrated OHCI
diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c
index e5c33bc..3656d7c 100644
--- a/drivers/usb/host/ohci-da8xx.c
+++ b/drivers/usb/host/ohci-da8xx.c
@@ -15,58 +15,50 @@
 #include 
 #include 
 #include 
-
-#include 
+#include 
 #include 
 
 #ifndef CONFIG_ARCH_DAVINCI_DA8XX
 #error "This file is DA8xx bus glue.  Define CONFIG_ARCH_DAVINCI_DA8XX."
 #endif
 
-#define CFGCHIP2   DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG)
-
 static struct clk *usb11_clk;
-static struct clk *usb20_clk;
+static struct phy *usb11_phy;
 
 /* Over-current indicator change bitmask */
 static volatile u16 ocic_mask;
 
-static void ohci_da8xx_clock(int on)
+static int ohci_da8xx_enable(void)
 {
-   u32 cfgchip2;
-
-   cfgchip2 = __raw_readl(CFGCHIP2);
-   if (on) {
-   clk_enable(usb11_clk);
-
-   /*
-* If USB 1.1 reference clock is sourced from USB 2.0 PHY, we
-* need to enable the USB 2.0 module clocking, start its PHY,
-* and not allow it to stop the clock during USB 2.0 suspend.
-*/
-   if (!(cfgchip2 & CFGCHIP2_USB1PHYCLKMUX)) {
-   clk_enable(usb20_clk);
-
-   cfgchip2 &= ~(CFGCHIP2_RESET | CFGCHIP2_PHYPWRDN);
-   cfgchip2 |= CFGCHIP2_PHY_PLLON;
-   __raw_writel(cfgchip2, CFGCHIP2);
-
-   pr_info("Waiting for USB PHY clock good...\n");
-   while (!(__raw_readl(CFGCHIP2) & CFGCHIP2_PHYCLKGD))
-   cpu_relax();
-   }
+   int ret;
 
-   /* Enable USB 1.1 PHY */
-   cfgchip2 |= CFGCHIP2_USB1SUSPENDM;
-   } else {
-   clk_disable(usb11_clk);
-   if (!(cfgchip2 & CFGCHIP2_USB1PHYCLKMUX))
-   clk_disable(usb20_clk);
+   ret = clk_prepare_enable(usb11_clk);
+   if (ret)
+   return ret;
 
-   /* Disable USB 1.1 PHY */
-   cfgchip2 &= ~CFGCHIP2_USB1SUSPENDM;
-   }
-   __raw_writel(cfgchip2, CFGCHIP2);
+   ret = phy_init(usb11_phy);
+   if (ret)
+   goto err_phy_init;
+
+   ret = phy_power_on(usb11_phy);
+   if (ret)
+   goto err_phy_power_on;
+
+   return 0;
+
+err_phy_power_on:
+   phy_exit(usb11_phy);
+err_phy_init:
+   clk_disable_unprepare(usb11_clk);
+
+   return ret;
+}
+
+static void ohci_da8xx_disable(void)
+{
+   phy_power_off(usb11_phy);
+   phy_exit(usb11_phy);
+   clk_disable_unprepare(usb11_clk);
 }
 
 /*
@@ -92,7 +84,9 @@ static int ohci_da8xx_init(struct usb_hcd *hcd)
 
dev_dbg(dev, "starting USB controller\n");
 
-   ohci_da8xx_clock(1);
+   result = ohci_da8xx_enable();
+   if (result < 0)
+   return result;
 
/*
 * DA8xx only have 1 port connected to the pins but the HC root hub
@@ -101,8 +95,10 @@ static int ohci_da8xx_init(struct usb_hcd *hcd)
ohci->num_ports = 1;
 
result = ohci_init(ohci);
-   if (result < 0)
+   if (result < 0) {
+   ohci_da8xx_disable();
return result;
+   }
 
/*
 * Since we're providing a board-specific root hub port power control
@@ -129,7 +125,7 @@ static int ohci_da8xx_init(struct usb_hcd *hcd)
 static void ohci_da8xx_stop(struct usb_hcd *hcd)
 {
ohci_stop(hcd);
-   ohci_da8xx_clock(0);
+   ohci_da8xx_disable();
 }
 
 static int ohci_da8xx_start(struct usb_hcd *hcd)
@@ -301,12 +297,18 @@ static int usb_hcd_da8xx_probe(const struct hc_driver 
*driver,
return -ENODEV;
 
usb11_clk = devm_clk_get(>dev, "usb11");
-   if (IS_ERR(usb11_clk))
+   if (IS_ERR(usb11_clk)) {
+   if (PTR_ERR(usb11_clk) != -EPROBE_DEFER)
+   dev_err(>dev, "Failed to get clock.\n");
return PTR_ERR(usb11_clk);
+   }
 
-   usb20_clk = devm_clk_g

[PATCH v5 3/7] phy: Add set_mode callback

2016-05-09 Thread David Lechner
The initial use for this is for PHYs that have a mode related to USB OTG.
There are several SoCs (e.g. TI OMAP and DA8xx) that have a mode setting
in the USB PHY to override OTG VBUS and ID signals.

Of course, the enum can be expaned in the future to include modes for
other types of PHYs as well.

Suggested-by: Kishon Vijay Abraham I <kis...@ti.com>
Signed-off-by: David Lechner <da...@lechnology.com>
---
 drivers/phy/phy-core.c  | 15 +++
 include/linux/phy/phy.h | 17 +
 2 files changed, 32 insertions(+)

diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index e7e574d..fe0344c 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -342,6 +342,21 @@ int phy_power_off(struct phy *phy)
 }
 EXPORT_SYMBOL_GPL(phy_power_off);
 
+int phy_set_mode(struct phy *phy, enum phy_mode mode)
+{
+   int ret;
+
+   if (!phy || !phy->ops->set_mode)
+   return 0;
+
+   mutex_lock(>mutex);
+   ret = phy->ops->set_mode(phy, mode);
+   mutex_unlock(>mutex);
+
+   return ret;
+}
+EXPORT_SYMBOL_GPL(phy_set_mode);
+
 /**
  * _of_phy_get() - lookup and obtain a reference to a phy by phandle
  * @np: device_node for which to get the phy
diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h
index 8cf05e3..4248ade 100644
--- a/include/linux/phy/phy.h
+++ b/include/linux/phy/phy.h
@@ -22,12 +22,20 @@
 
 struct phy;
 
+enum phy_mode {
+   PHY_MODE_INVALID,
+   PHY_MODE_USB_HOST,
+   PHY_MODE_USB_DEVICE,
+   PHY_MODE_USB_OTG,
+};
+
 /**
  * struct phy_ops - set of function pointers for performing phy operations
  * @init: operation to be performed for initializing phy
  * @exit: operation to be performed while exiting
  * @power_on: powering on the phy
  * @power_off: powering off the phy
+ * @set_mode: set the mode of the phy
  * @owner: the module owner containing the ops
  */
 struct phy_ops {
@@ -35,6 +43,7 @@ struct phy_ops {
int (*exit)(struct phy *phy);
int (*power_on)(struct phy *phy);
int (*power_off)(struct phy *phy);
+   int (*set_mode)(struct phy *phy, enum phy_mode mode);
struct module *owner;
 };
 
@@ -119,6 +128,7 @@ int phy_init(struct phy *phy);
 int phy_exit(struct phy *phy);
 int phy_power_on(struct phy *phy);
 int phy_power_off(struct phy *phy);
+int phy_set_mode(struct phy *phy, enum phy_mode mode);
 static inline int phy_get_bus_width(struct phy *phy)
 {
return phy->attrs.bus_width;
@@ -224,6 +234,13 @@ static inline int phy_power_off(struct phy *phy)
return -ENOSYS;
 }
 
+static inline int phy_set_mode(struct phy *phy, enum phy_mode mode)
+{
+   if (!phy)
+   return 0;
+   return -ENOSYS;
+}
+
 static inline int phy_get_bus_width(struct phy *phy)
 {
return -ENOSYS;
-- 
2.7.4

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


[PATCH v5 7/7] usb: musb: da8xx: Remove mach code

2016-05-09 Thread David Lechner
Use the new phy-da8xx-usb driver to take the place of the mach code that
pokes CFGCHIP2 in the da8xx musb glue driver. This unbreaks the driver.

Signed-off-by: David Lechner <da...@lechnology.com>
---
 drivers/usb/musb/Kconfig |   2 +-
 drivers/usb/musb/da8xx.c | 135 ++-
 2 files changed, 51 insertions(+), 86 deletions(-)

diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index 886526b..c73221a 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -82,7 +82,7 @@ config USB_MUSB_DA8XX
tristate "DA8xx/OMAP-L1x"
depends on ARCH_DAVINCI_DA8XX
depends on NOP_USB_XCEIV
-   depends on BROKEN
+   select PHY_DA8XX_USB
 
 config USB_MUSB_TUSB6010
tristate "TUSB6010"
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 0c1997c..6af8c3d 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -30,13 +30,11 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 
-#include 
-#include 
-
 #include "musb_core.h"
 
 /*
@@ -80,61 +78,15 @@
 
 #define DA8XX_MENTOR_CORE_OFFSET 0x400
 
-#define CFGCHIP2   IO_ADDRESS(DA8XX_SYSCFG0_BASE + DA8XX_CFGCHIP2_REG)
-
 struct da8xx_glue {
struct device   *dev;
struct platform_device  *musb;
-   struct platform_device  *phy;
+   struct platform_device  *usb_phy;
struct clk  *clk;
+   struct phy  *phy;
 };
 
 /*
- * REVISIT (PM): we should be able to keep the PHY in low power mode most
- * of the time (24 MHz oscillator and PLL off, etc.) by setting POWER.D0
- * and, when in host mode, autosuspending idle root ports... PHY_PLLON
- * (overriding SUSPENDM?) then likely needs to stay off.
- */
-
-static inline void phy_on(void)
-{
-   u32 cfgchip2 = __raw_readl(CFGCHIP2);
-
-   /*
-* Start the on-chip PHY and its PLL.
-*/
-   cfgchip2 &= ~(CFGCHIP2_RESET | CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN);
-   cfgchip2 |= CFGCHIP2_PHY_PLLON;
-   __raw_writel(cfgchip2, CFGCHIP2);
-
-   pr_info("Waiting for USB PHY clock good...\n");
-   while (!(__raw_readl(CFGCHIP2) & CFGCHIP2_PHYCLKGD))
-   cpu_relax();
-}
-
-static inline void phy_off(void)
-{
-   u32 cfgchip2 = __raw_readl(CFGCHIP2);
-
-   /*
-* Ensure that USB 1.1 reference clock is not being sourced from
-* USB 2.0 PHY.  Otherwise do not power down the PHY.
-*/
-   if (!(cfgchip2 & CFGCHIP2_USB1PHYCLKMUX) &&
-(cfgchip2 & CFGCHIP2_USB1SUSPENDM)) {
-   pr_warning("USB 1.1 clocked from USB 2.0 PHY -- "
-  "can't power it down\n");
-   return;
-   }
-
-   /*
-* Power down the on-chip PHY.
-*/
-   cfgchip2 |= CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN;
-   __raw_writel(cfgchip2, CFGCHIP2);
-}
-
-/*
  * Because we don't set CTRL.UINT, it's "important" to:
  * - not read/write INTRUSB/INTRUSBE (except during
  *   initial setup, as a workaround);
@@ -385,29 +337,29 @@ static irqreturn_t da8xx_musb_interrupt(int irq, void 
*hci)
 
 static int da8xx_musb_set_mode(struct musb *musb, u8 musb_mode)
 {
-   u32 cfgchip2 = __raw_readl(CFGCHIP2);
+   struct da8xx_glue *glue = dev_get_drvdata(musb->controller->parent);
+   enum phy_mode phy_mode;
 
-   cfgchip2 &= ~CFGCHIP2_OTGMODE;
switch (musb_mode) {
case MUSB_HOST: /* Force VBUS valid, ID = 0 */
-   cfgchip2 |= CFGCHIP2_FORCE_HOST;
+   phy_mode = PHY_MODE_USB_HOST;
break;
case MUSB_PERIPHERAL:   /* Force VBUS valid, ID = 1 */
-   cfgchip2 |= CFGCHIP2_FORCE_DEVICE;
+   phy_mode = PHY_MODE_USB_DEVICE;
break;
case MUSB_OTG:  /* Don't override the VBUS/ID comparators */
-   cfgchip2 |= CFGCHIP2_NO_OVERRIDE;
+   phy_mode = PHY_MODE_USB_OTG;
break;
default:
-   dev_dbg(musb->controller, "Trying to set unsupported mode 
%u\n", musb_mode);
+   return -EINVAL;
}
 
-   __raw_writel(cfgchip2, CFGCHIP2);
-   return 0;
+   return phy_set_mode(glue->phy, phy_mode);
 }
 
 static int da8xx_musb_init(struct musb *musb)
 {
+   struct da8xx_glue *glue = dev_get_drvdata(musb->controller->parent);
void __iomem *reg_base = musb->ctrl_base;
u32 rev;
int ret = -ENODEV;
@@ -425,32 +377,56 @@ static int da8xx_musb_init(struct musb *musb)
goto fail;
}
 
+   ret = clk_prepare_enable(glue->clk);
+   if (ret) {
+   dev_err(glue->dev, "failed to enable clock\n");
+   goto fail;
+   }
+
setup_timer(_workaround, otg_timer, (unsigned long)m

[PATCH v5 4/7] phy: da8xx-usb: new driver for DA8xx SoC USB PHY

2016-05-09 Thread David Lechner
This is a new phy driver for the SoC USB controllers on the TI DA8xx
family of microcontrollers. The USB 1.1 PHY is just a simple on/off.
The USB 2.0 PHY also allows overriding the VBUS and ID pins.

Signed-off-by: David Lechner <da...@lechnology.com>
---
 drivers/phy/Kconfig |  10 ++
 drivers/phy/Makefile|   1 +
 drivers/phy/phy-da8xx-usb.c | 244 
 3 files changed, 255 insertions(+)
 create mode 100644 drivers/phy/phy-da8xx-usb.c

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 26566db..c1d315f 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -35,6 +35,16 @@ config ARMADA375_USBCLUSTER_PHY
depends on OF && HAS_IOMEM
select GENERIC_PHY
 
+config PHY_DA8XX_USB
+   tristate "TI DA8xx USB PHY Driver"
+   depends on ARCH_DAVINCI_DA8XX
+   select GENERIC_PHY
+   select MFD_SYSCON
+   help
+ Enable this to support the USB PHY on DA8xx SoCs.
+
+ This driver controls both the USB 1.1 PHY and the USB 2.0 PHY.
+
 config PHY_DM816X_USB
tristate "TI dm816x USB PHY driver"
depends on ARCH_OMAP2PLUS
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index 24596a9..722e01c 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -5,6 +5,7 @@
 obj-$(CONFIG_GENERIC_PHY)  += phy-core.o
 obj-$(CONFIG_PHY_BERLIN_USB)   += phy-berlin-usb.o
 obj-$(CONFIG_PHY_BERLIN_SATA)  += phy-berlin-sata.o
+obj-$(CONFIG_PHY_DA8XX_USB)+= phy-da8xx-usb.o
 obj-$(CONFIG_PHY_DM816X_USB)   += phy-dm816x-usb.o
 obj-$(CONFIG_ARMADA375_USBCLUSTER_PHY) += phy-armada375-usb2.o
 obj-$(CONFIG_BCM_KONA_USB2_PHY)+= phy-bcm-kona-usb2.o
diff --git a/drivers/phy/phy-da8xx-usb.c b/drivers/phy/phy-da8xx-usb.c
new file mode 100644
index 000..0c05488
--- /dev/null
+++ b/drivers/phy/phy-da8xx-usb.c
@@ -0,0 +1,244 @@
+/*
+ * phy-da8xx-usb - TI DaVinci DA8xx USB PHY driver
+ *
+ * Copyright (C) 2016 David Lechner <da...@lechnology.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct da8xx_usb_phy {
+   struct phy_provider *phy_provider;
+   struct phy  *usb11_phy;
+   struct phy  *usb20_phy;
+   struct clk  *usb11_clk;
+   struct clk  *usb20_clk;
+   struct regmap   *regmap;
+};
+
+static int da8xx_usb11_phy_power_on(struct phy *phy)
+{
+   struct da8xx_usb_phy *d_phy = phy_get_drvdata(phy);
+   int ret;
+
+   ret = clk_prepare_enable(d_phy->usb11_clk);
+   if (ret)
+   return ret;
+
+   regmap_write_bits(d_phy->regmap, CFGCHIP(2), CFGCHIP2_USB1SUSPENDM,
+ CFGCHIP2_USB1SUSPENDM);
+
+   return 0;
+}
+
+static int da8xx_usb11_phy_power_off(struct phy *phy)
+{
+   struct da8xx_usb_phy *d_phy = phy_get_drvdata(phy);
+
+   regmap_write_bits(d_phy->regmap, CFGCHIP(2), CFGCHIP2_USB1SUSPENDM, 0);
+
+   clk_disable_unprepare(d_phy->usb11_clk);
+
+   return 0;
+}
+
+static const struct phy_ops da8xx_usb11_phy_ops = {
+   .power_on   = da8xx_usb11_phy_power_on,
+   .power_off  = da8xx_usb11_phy_power_off,
+   .owner  = THIS_MODULE,
+};
+
+static int da8xx_usb20_phy_power_on(struct phy *phy)
+{
+   struct da8xx_usb_phy *d_phy = phy_get_drvdata(phy);
+   int ret;
+
+   ret = clk_prepare_enable(d_phy->usb20_clk);
+   if (ret)
+   return ret;
+
+   regmap_write_bits(d_phy->regmap, CFGCHIP(2), CFGCHIP2_OTGPWRDN, 0);
+
+   return 0;
+}
+
+static int da8xx_usb20_phy_power_off(struct phy *phy)
+{
+   struct da8xx_usb_phy *d_phy = phy_get_drvdata(phy);
+
+   regmap_write_bits(d_phy->regmap, CFGCHIP(2), CFGCHIP2_OTGPWRDN,
+ CFGCHIP2_OTGPWRDN);
+
+   clk_disable_unprepare(d_phy->usb20_clk);
+
+   return 0;
+}
+
+static int da8xx_usb20_phy_set_mode(struct phy *phy, enum phy_mode mode)
+{
+   struct da8xx_usb_phy *d_phy = phy_get_drvdata(phy);
+   u32 val;
+
+   switch (mode) {
+   case PHY_MODE_USB_HOST: /* Force VBUS valid, ID = 0 */
+   val = CFGCHIP2_OTGMODE_FORCE_HOST;
+   break;
+   case PHY_MODE_USB_DEVICE:   /* Force VBUS valid, ID = 1 */
+   val = CFGCHIP2_OTGMODE_FORCE_DEVICE;
+   break;
+   case PHY_MODE_USB_OTG:  

Re: [PATCH v4 3/7] phy: Add set_mode callback

2016-05-09 Thread David Lechner

On 05/04/2016 01:39 PM, Bin Liu wrote:

On Wed, May 04, 2016 at 01:20:36PM -0500, David Lechner wrote:

This is something I actually plan on using because the device I am
using (LEGO MINDSTORMS EV3) is not wired for OTG, so the callback is
needed to override the ID and VBUS signals when switching between
host and peripheral mode.


Have you already tested this? I never tried changing mode via sysfs, but
by quickly reviewing the code, I am wondering how it works. the core
only calls ops->set_mode() but nothing else. To really switch the mode,
the driver has to talk to the root hub, and manipulate the SESSION
bit...



I have tested this now and it works. It works because by setting the 
mode, we are overriding the VBUS and ID signals, which in turn triggers 
interrupts. I have tested switching to both peripheral mode and host 
mode via sysfs. Host mode has some issues if you are using a 
self-powered device, but that is a bug in the da8xx glue layer and 
shouldn't hold up this patch series. Aside from that, it works exactly 
as expected.

--
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 3/7] phy: Add set_mode callback

2016-05-04 Thread David Lechner

On 05/04/2016 01:39 PM, Bin Liu wrote:


Have you already tested this? I never tried changing mode via sysfs, but
by quickly reviewing the code, I am wondering how it works. the core
only calls ops->set_mode() but nothing else. To really switch the mode,
the driver has to talk to the root hub, and manipulate the SESSION
bit...

Regards,
-Bin.




I haven't actually tried this. I need to hack together a USB cable to 
test it in host mode (Mini-B to Mini-B w/ powered hub).

--
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 3/7] phy: Add set_mode callback

2016-05-04 Thread David Lechner

On 05/04/2016 01:10 PM, Bin Liu wrote:

Hi,

On Thu, Apr 14, 2016 at 01:35:14PM -0500, David Lechner wrote:

The initial use for this is for PHYs that have a mode related to USB OTG.
There are several SoCs (e.g. TI OMAP and DA8xx) that have a mode setting
in the USB PHY to override OTG VBUS and ID signals.

Of course, the enum can be expaned in the future to include modes for
other types of PHYs as well.

Suggested-by: Kishon Vijay Abraham I <kis...@ti.com>
Signed-off-by: David Lechner <da...@lechnology.com>
---

v4 changes:

* This is a new patch to avoid exporting a symbol from the phy-da8xx-usb driver.


  drivers/phy/phy-core.c  | 15 +++
  include/linux/phy/phy.h | 15 +++
  2 files changed, 30 insertions(+)

diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index e7e574d..fe0344c 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -342,6 +342,21 @@ int phy_power_off(struct phy *phy)
  }
  EXPORT_SYMBOL_GPL(phy_power_off);

+int phy_set_mode(struct phy *phy, enum phy_mode mode)
+{
+   int ret;
+
+   if (!phy || !phy->ops->set_mode)
+   return 0;
+
+   mutex_lock(>mutex);
+   ret = phy->ops->set_mode(phy, mode);
+   mutex_unlock(>mutex);
+
+   return ret;
+}
+EXPORT_SYMBOL_GPL(phy_set_mode);


Sorry for my late comments, have been busy on other things.

As I commented in v2, isn't it a better idea to not adding this callback
and let the da8xx phy driver set the mode register in _probe() based on
DT dr_mode?

musb core only calls the *optional* _set_mode() during init, so I don't
see any problem if the phy set the mode in its probe.

Regards,
-Bin.



As was already discussed, the mode can be changed via sysfs as well as 
during probe, so this callback is needed for that case.


This is something I actually plan on using because the device I am using 
(LEGO MINDSTORMS EV3) is not wired for OTG, so the callback is needed to 
override the ID and VBUS signals when switching between host and 
peripheral mode.

--
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/7] da8xx USB PHY (was da8xx USB clocks)

2016-05-04 Thread David Lechner

On 04/14/2016 01:35 PM, David Lechner wrote:

The "da8xx USB clocks" patch series was growing a bit too big, so on the advice
of Sekhar Nori, I am splitting it into two parts. This part contains everything
in drivers/ and the other part will contain everything in arch/arm/mach-davinci.

This patch series will apply and build on its own. It just won't work at runtime
without the corresponding mach-davinci changes to provide clocks, etc.

This round just contains changes from feedback. See individual patches for
details.

Tested working on LEGO MINDSTORMS EV3 using linux-davinci/master branch.

David Lechner (7):
   mfd: da8xx-cfgchip: New header file for CFGCHIP registers.
   dt-bindings: Add bindings for phy-da8xx-usb
   phy: Add set_mode callback
   phy: da8xx-usb: new driver for DA8xx SoC USB PHY
   usb: ohci-da8xx: Remove code that references mach
   usb: musb: da8xx: Use devm in probe
   usb: musb: da8xx: Remove mach code

  .../devicetree/bindings/phy/phy-da8xx-usb.txt  |  40 
  drivers/phy/Kconfig|  10 +
  drivers/phy/Makefile   |   1 +
  drivers/phy/phy-core.c |  15 ++
  drivers/phy/phy-da8xx-usb.c| 245 +
  drivers/usb/host/Kconfig   |   1 +
  drivers/usb/host/ohci-da8xx.c  | 102 +
  drivers/usb/musb/Kconfig   |   2 +-
  drivers/usb/musb/da8xx.c   | 160 +-
  include/linux/mfd/da8xx-cfgchip.h  | 153 +
  include/linux/phy/phy.h|  15 ++
  include/linux/platform_data/usb-davinci.h  |  22 --
  12 files changed, 594 insertions(+), 172 deletions(-)
  create mode 100644 Documentation/devicetree/bindings/phy/phy-da8xx-usb.txt
  create mode 100644 drivers/phy/phy-da8xx-usb.c
  create mode 100644 include/linux/mfd/da8xx-cfgchip.h



I think all of the maintainers have weighed in now. So, I think I am 
ready to submit a v5 series to address some small issues to get this to 
"good enough" status. Which maintainer will take responsibility for 
including this in his tree?

--
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 2/7] dt-bindings: Add bindings for phy-da8xx-usb

2016-04-15 Thread David Lechner

On 04/15/2016 05:48 AM, Sergei Shtylyov wrote:

On 4/14/2016 9:35 PM, David Lechner wrote:


Device tree binding for new phy-da8xx-usb driver.

Signed-off-by: David Lechner <da...@lechnology.com>
Acked-by: Rob Herring <r...@kernel.org>
---

v4 changes:

* swapped order of usb20 and usb11 to be in logical order of reg address.

  .../devicetree/bindings/phy/phy-da8xx-usb.txt  | 40
++
  1 file changed, 40 insertions(+)
  create mode 100644
Documentation/devicetree/bindings/phy/phy-da8xx-usb.txt

diff --git a/Documentation/devicetree/bindings/phy/phy-da8xx-usb.txt
b/Documentation/devicetree/bindings/phy/phy-da8xx-usb.txt
new file mode 100644
index 000..bead185
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/phy-da8xx-usb.txt
@@ -0,0 +1,40 @@
+TI DaVinci DA8xx USB PHY


DA8xx is not DaVinci, please omit this.


Just to be sure, you mean omit "DaVinci"?




+
+Required properties:
+ - compatible: must be "ti,da830-usbphy".
+ - #phy-cells: must be 1.
+
+This device controls the PHY for both the USB 1.1 OHCI and USB 2.0 OTG
+controllers on DA8xx SoCs. Consumers of this device should use index
0 for
+the USB 2.0 phy device and index 1 for the USB 1.1 phy device.


Not indices 2 and 1 already?


I changed this to reflect the TRM. USB0PHY = USB 2.0 and USB1PHY = USB 1.1




+usbphy: usbphy {


Name it "usb-phy" please, consistent to what ePAPR has mandated for
Ethernet PHYs.


Ack.

--
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 0/5] da8xx USB PHY platform devices and clocks (was "da8xx UBS clocks")

2016-04-14 Thread David Lechner
Here is the second half of v3 "da8xx UBS clocks" that just includes the
arch/arm/mach-davinci/ portion. There were no comments on these patches, so
they are mostly unchanged other than fixing on strict checkpatch complaint.

This series also requires include/linux/mfd/da8xx-cfgchip.h from the "da8xx USB
PHY" series in order to compile.

David Lechner (5):
  ARM: davinci: da8xx: add usb phy clocks
  ARM: davinci: da8xx: Add CFGCHIP syscon platform declaration.
  ARM: davinci: da8xx: Add USB PHY platform declaration
  ARM: DTS: da850: Add cfgchip syscon node
  ARM: DTS: da850: Add usb phy node

 arch/arm/boot/dts/da850.dtsi|   9 ++
 arch/arm/mach-davinci/board-da830-evm.c |  52 +++
 arch/arm/mach-davinci/board-da850-evm.c |   4 +
 arch/arm/mach-davinci/board-mityomapl138.c  |   4 +
 arch/arm/mach-davinci/board-omapl138-hawk.c |  23 ++-
 arch/arm/mach-davinci/devices-da8xx.c   |  28 
 arch/arm/mach-davinci/include/mach/da8xx.h  |   6 +
 arch/arm/mach-davinci/usb-da8xx.c   | 230 +++-
 8 files changed, 314 insertions(+), 42 deletions(-)

-- 
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 v4 3/5] ARM: davinci: da8xx: Add USB PHY platform declaration

2016-04-14 Thread David Lechner
There is now a proper phy driver for the DA8xx SoC USB PHY. This adds the
platform device declarations needed to use it.

Signed-off-by: David Lechner <da...@lechnology.com>
---

v4 changes: none

 arch/arm/mach-davinci/board-da830-evm.c | 28 +---
 arch/arm/mach-davinci/board-omapl138-hawk.c |  5 +
 arch/arm/mach-davinci/include/mach/da8xx.h  |  1 +
 arch/arm/mach-davinci/usb-da8xx.c   | 11 +++
 4 files changed, 22 insertions(+), 23 deletions(-)

diff --git a/arch/arm/mach-davinci/board-da830-evm.c 
b/arch/arm/mach-davinci/board-da830-evm.c
index 3051cb6..6421cfe 100644
--- a/arch/arm/mach-davinci/board-da830-evm.c
+++ b/arch/arm/mach-davinci/board-da830-evm.c
@@ -26,7 +26,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include 
 #include 
@@ -106,30 +105,8 @@ static irqreturn_t da830_evm_usb_ocic_irq(int irq, void 
*dev_id)
 
 static __init void da830_evm_usb_init(void)
 {
-   u32 cfgchip2;
int ret;
 
-   /*
-* Set up USB clock/mode in the CFGCHIP2 register.
-* FYI:  CFGCHIP2 is 0xef00 initially.
-*/
-   cfgchip2 = __raw_readl(DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
-
-   /*
-* We have to override VBUS/ID signals when MUSB is configured into the
-* host-only mode -- ID pin will float if no cable is connected, so the
-* controller won't be able to drive VBUS thinking that it's a B-device.
-* Otherwise, we want to use the OTG mode and enable VBUS comparators.
-*/
-   cfgchip2 &= ~CFGCHIP2_OTGMODE;
-#ifdef CONFIG_USB_MUSB_HOST
-   cfgchip2 |=  CFGCHIP2_FORCE_HOST;
-#else
-   cfgchip2 |=  CFGCHIP2_SESENDEN | CFGCHIP2_VBDTCTEN;
-#endif
-
-   __raw_writel(cfgchip2, DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
-
/* USB_REFCLKIN is not used. */
ret = da8xx_register_usb20_phy_clk(false);
if (ret)
@@ -141,6 +118,11 @@ static __init void da830_evm_usb_init(void)
pr_warn("%s: USB 1.1 PHY CLK registration failed: %d\n",
__func__, ret);
 
+   ret = da8xx_register_usbphy();
+   if (ret)
+   pr_warn("%s: USB PHY registration failed: %d\n",
+   __func__, ret);
+
ret = davinci_cfg_reg(DA830_USB0_DRVVBUS);
if (ret)
pr_warn("%s: USB 2.0 PinMux setup failed: %d\n", __func__, ret);
diff --git a/arch/arm/mach-davinci/board-omapl138-hawk.c 
b/arch/arm/mach-davinci/board-omapl138-hawk.c
index 8691a25..79aaa84 100644
--- a/arch/arm/mach-davinci/board-omapl138-hawk.c
+++ b/arch/arm/mach-davinci/board-omapl138-hawk.c
@@ -260,6 +260,11 @@ static __init void omapl138_hawk_usb_init(void)
pr_warn("%s: USB 1.1 PHY CLK registration failed: %d\n",
__func__, ret);
 
+   ret = da8xx_register_usbphy();
+   if (ret)
+   pr_warn("%s: USB PHY registration failed: %d\n",
+   __func__, ret);
+
ret = gpio_request_one(DA850_USB1_VBUS_PIN,
GPIOF_DIR_OUT, "USB1 VBUS");
if (ret < 0) {
diff --git a/arch/arm/mach-davinci/include/mach/da8xx.h 
b/arch/arm/mach-davinci/include/mach/da8xx.h
index c32444b..44ab55e 100644
--- a/arch/arm/mach-davinci/include/mach/da8xx.h
+++ b/arch/arm/mach-davinci/include/mach/da8xx.h
@@ -92,6 +92,7 @@ int da8xx_register_watchdog(void);
 int da8xx_register_usb_refclkin(int rate);
 int da8xx_register_usb20_phy_clk(bool use_usb_refclkin);
 int da8xx_register_usb11_phy_clk(bool use_usb_refclkin);
+int da8xx_register_usbphy(void);
 int da8xx_register_usb20(unsigned mA, unsigned potpgt);
 int da8xx_register_usb11(struct da8xx_ohci_root_hub *pdata);
 int da8xx_register_emac(void);
diff --git a/arch/arm/mach-davinci/usb-da8xx.c 
b/arch/arm/mach-davinci/usb-da8xx.c
index c524d9e..3b64dcf 100644
--- a/arch/arm/mach-davinci/usb-da8xx.c
+++ b/arch/arm/mach-davinci/usb-da8xx.c
@@ -7,6 +7,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -230,6 +231,16 @@ int __init da8xx_register_usb11_phy_clk(bool 
use_usb_refclkin)
return ret;
 }
 
+static struct platform_device da8xx_usbphy = {
+   .name   = "da8xx-usbphy",
+   .id = 0,
+};
+
+int __init da8xx_register_usbphy(void)
+{
+   return platform_device_register(_usbphy);
+}
+
 #if IS_ENABLED(CONFIG_USB_MUSB_HDRC)
 
 static struct musb_hdrc_config musb_config = {
-- 
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 v4 2/5] ARM: davinci: da8xx: Add CFGCHIP syscon platform declaration.

2016-04-14 Thread David Lechner
The CFGCHIP registers are used by a number of devices, so using a syscon
device to share them. The first consumer of this will by the phy-da8xx-usb
driver.

Signed-off-by: David Lechner <da...@lechnology.com>
---

v4 changes: none


 arch/arm/mach-davinci/board-da830-evm.c |  4 
 arch/arm/mach-davinci/board-da850-evm.c |  4 
 arch/arm/mach-davinci/board-mityomapl138.c  |  4 
 arch/arm/mach-davinci/board-omapl138-hawk.c |  4 
 arch/arm/mach-davinci/devices-da8xx.c   | 28 
 arch/arm/mach-davinci/include/mach/da8xx.h  |  2 ++
 6 files changed, 46 insertions(+)

diff --git a/arch/arm/mach-davinci/board-da830-evm.c 
b/arch/arm/mach-davinci/board-da830-evm.c
index 605d444..3051cb6 100644
--- a/arch/arm/mach-davinci/board-da830-evm.c
+++ b/arch/arm/mach-davinci/board-da830-evm.c
@@ -586,6 +586,10 @@ static __init void da830_evm_init(void)
struct davinci_soc_info *soc_info = _soc_info;
int ret;
 
+   ret = da8xx_register_cfgchip();
+   if (ret)
+   pr_warn("%s: CFGCHIP registration failed: %d\n", __func__, ret);
+
ret = da830_register_gpio();
if (ret)
pr_warn("%s: GPIO init failed: %d\n", __func__, ret);
diff --git a/arch/arm/mach-davinci/board-da850-evm.c 
b/arch/arm/mach-davinci/board-da850-evm.c
index 8e4539f..ec5cb10 100644
--- a/arch/arm/mach-davinci/board-da850-evm.c
+++ b/arch/arm/mach-davinci/board-da850-evm.c
@@ -1345,6 +1345,10 @@ static __init void da850_evm_init(void)
 {
int ret;
 
+   ret = da8xx_register_cfgchip();
+   if (ret)
+   pr_warn("%s: CFGCHIP registration failed: %d\n", __func__, ret);
+
ret = da850_register_gpio();
if (ret)
pr_warn("%s: GPIO init failed: %d\n", __func__, ret);
diff --git a/arch/arm/mach-davinci/board-mityomapl138.c 
b/arch/arm/mach-davinci/board-mityomapl138.c
index bc4e63f..1a6d430 100644
--- a/arch/arm/mach-davinci/board-mityomapl138.c
+++ b/arch/arm/mach-davinci/board-mityomapl138.c
@@ -514,6 +514,10 @@ static void __init mityomapl138_init(void)
 {
int ret;
 
+   ret = da8xx_register_cfgchip();
+   if (ret)
+   pr_warn("%s: CFGCHIP registration failed: %d\n", __func__, ret);
+
/* for now, no special EDMA channels are reserved */
ret = da850_register_edma(NULL);
if (ret)
diff --git a/arch/arm/mach-davinci/board-omapl138-hawk.c 
b/arch/arm/mach-davinci/board-omapl138-hawk.c
index d4930b6..8691a25 100644
--- a/arch/arm/mach-davinci/board-omapl138-hawk.c
+++ b/arch/arm/mach-davinci/board-omapl138-hawk.c
@@ -294,6 +294,10 @@ static __init void omapl138_hawk_init(void)
 {
int ret;
 
+   ret = da8xx_register_cfgchip();
+   if (ret)
+   pr_warn("%s: CFGCHIP registration failed: %d\n", __func__, ret);
+
ret = da850_register_gpio();
if (ret)
pr_warn("%s: GPIO init failed: %d\n", __func__, ret);
diff --git a/arch/arm/mach-davinci/devices-da8xx.c 
b/arch/arm/mach-davinci/devices-da8xx.c
index 725e693..69d11a1 100644
--- a/arch/arm/mach-davinci/devices-da8xx.c
+++ b/arch/arm/mach-davinci/devices-da8xx.c
@@ -11,6 +11,7 @@
  * (at your option) any later version.
  */
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1109,3 +1110,30 @@ int __init da850_register_sata(unsigned long refclkpn)
return platform_device_register(_sata_device);
 }
 #endif
+
+static struct syscon_platform_data da8xx_cfgchip_platform_data = {
+   .label  = "cfgchip",
+};
+
+static struct resource da8xx_cfgchip_resources[] = {
+   {
+   .start  = DA8XX_SYSCFG0_BASE + DA8XX_CFGCHIP0_REG,
+   .end= DA8XX_SYSCFG0_BASE + DA8XX_CFGCHIP4_REG + 3,
+   .flags  = IORESOURCE_MEM,
+   },
+};
+
+static struct platform_device da8xx_cfgchip_device = {
+   .name   = "syscon",
+   .id = 0,
+   .dev= {
+   .platform_data  = _cfgchip_platform_data,
+   },
+   .num_resources  = ARRAY_SIZE(da8xx_cfgchip_resources),
+   .resource   = da8xx_cfgchip_resources,
+};
+
+int __init da8xx_register_cfgchip(void)
+{
+   return platform_device_register(_cfgchip_device);
+}
diff --git a/arch/arm/mach-davinci/include/mach/da8xx.h 
b/arch/arm/mach-davinci/include/mach/da8xx.h
index c367530..c32444b 100644
--- a/arch/arm/mach-davinci/include/mach/da8xx.h
+++ b/arch/arm/mach-davinci/include/mach/da8xx.h
@@ -61,6 +61,7 @@ extern unsigned int da850_max_speed;
 #define DA8XX_CFGCHIP1_REG 0x180
 #define DA8XX_CFGCHIP2_REG 0x184
 #define DA8XX_CFGCHIP3_REG 0x188
+#define DA8XX_CFGCHIP4_REG 0x18c
 
 #define DA8XX_SYSCFG1_BASE (IO_PHYS + 0x22C000)
 #define DA8XX_SYSCFG1_VIRT(x)  (da8xx_syscfg1_base + (x))
@@ -116,6 +117,7 @@ void da8xx_rproc_reserve_cma(void);
 int da8xx_register_rproc(void);
 int da850_register_gpio(void);
 in

  1   2   >