Skip to contentSkip to conversation

Support qcom's HSIC USB and rewrite USB2 HS support

PATCH Superseded Stephen Boyd 6 participants 54 messages Oct 18, 2016 – Nov 14, 2016

Subsystems (7)

v5 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v5 cover Support qcom's HSIC USB and rewrite USB2 HS support

The state of USB ChipIdea support on Qualcomm's platforms is not great. The DT description of these devices requires up to three different nodes for what amounts to be the same hardware block, when there should really only be one. Furthermore, the "phy" driver that is in mainline (phy-msm-usb.c) duplicates the OTG state machine and touches the ci controller wrapper registers when it should really be focused on the phy and the ULPI accesses needed to get the phy working. There's also a slimmed down phy driver for the msm8916 platform, but really the phy hardware is the same as other MSMs, so we have two drivers doing pretty much the same thing. This leads to a situtaion where we have the chipidea core driver, the "phy" driver, and sometimes the ehci-msm.c driver operating the same device all at the same time with very little coordination. This just isn't very safe and is confusing from a driver perspective when trying to figure out who does what. Finally, there isn't any HSIC support on platforms like apq8074 so we should add that.

This patch series updates the ChipIdea driver and the MSM wrapper (ci_hdrc_msm.c) to properly handle the PHY and wrapper bits at the right times in the right places. To get there, we update the ChipIdea core to have support for the ULPI phy bus introduced by Heikki. Along the way we fix bugs with the extcon handling for peripheral and OTG mode controllers and move the parts of phy-usb-msm.c that are touching the CI controller wrapper into the wrapper driver (ci_hdrc_msm.c). Finally we add support for the HSIC phy based on the ULPI bus and rewrite the HS phy driver (phy-usb-msm.c) as a standard ULPI phy driver.

Once this series is accepted, we should be able to delete the phy-usb-msm.c, phy-qcom-8x16-usb.c, and ehci-msm.c drivers from the tree and use the ULPI based phy driver (which also lives in drivers/phy/ instead of drivers/usb/phy/) and the chipidea host core instead.

I've also sent separate patches for other minor pieces to make this all work. The full tree can be found here[2], hacks and all to get things working. I've tested this on the db410c, apq8074 dragonboard, and ifc6410 with configfs gadgets and otg cables.

Patches based on v4.8-rc1

Changes from v4:
* Picked up Acks from Rob
* Updated HS phy init sequence DT property to restrict it to offsets

Changes from v3:
* Picked up Acks from Peter
* Updated extcon consolidation patch per Peter's comments
* Folded in simplification from Heikki for ULPI DT matching

Changes from v2:
* Added SoC specific compatibles in phy bindings
* Dropped AVVIS patch for OTG statemachine
* New patch to consolidate extcon handlers
* Picked up Acks from Peter
* Rebased onto v4.8-rc1
* Reworked ULPI OF code to look at vid == 0 instead of pid == 0
* Dropped ULPI bindings for vid and pid overrides

Changes from v1:
* Reworked ULPI device probing to keep using vendor/product ids that come from DT if needed and falls back to OF style match when product id is 0
* PHY init later patch was rejected so that moved to a quirk flag and the msm wrapper started managing the phy on/off
* Updated clk requirements for HSIC phy in binding doc
* Added optional clk in wrapper for "housekeeping" found on older qcom platforms
* Bug fix to OTGSC polling function
* Changed runtime PM patch to set as active instead of get/put

TODO:
* DMA fails on arm64 so we need something like [1] or [3] to make it work.
* The db410c needs a driver to toggle the onboard switch to connect the usb hub instead of micro port when the usb cable is disconnected. I've sent a patch set for this[4], which needs some further discussion/development.
* apq8064 platforms need a vbus regulator to really use otg and I haven't tried out the RPM based regulators yet
* The HSIC phy on the apq8074 dragonboard is connected to a usb4604 device which requires the i2c driver to probe and send an i2c sequence before the HSIC controller enumerates or HSIC doesn't work. Right now I have a hack to force the controller to probe defer once so that usb4604 probes first. This needs a more proper solution like having the DT describe a linkage between the controller and the usb device so we can enforce probe ordering.
* There are problems around the OTG switch still, due to how we handle extcon events that I'm working through

[1] https://lkml.org/lkml/2016/2/22/7
[2] https://git.linaro.org/people/stephen.boyd/linux.git/shortlog/refs/heads/usb-hsic-8074
[3] https://patchwork.kernel.org/patch/9319527/
[4] https://lkml.kernel.org/r/20160914014246.31847-1-stephen.boyd at linaro.org

Stephen Boyd (23):
of: device: Support loading a module with OF based modalias
of: device: Export of_device_{get_modalias,uvent_modalias} to modules
usb: ulpi: Support device discovery via DT
usb: chipidea: Only read/write OTGSC from one place
usb: chipidea: Handle extcon events properly
usb: chipidea: Add platform flag for wrapper phy management
usb: chipidea: Notify events when switching host mode
usb: chipidea: Remove locking in ci_udc_start()
usb: chipidea: Add support for ULPI PHY bus
usb: chipidea: Consolidate extcon notifiers
usb: chipidea: Emulate OTGSC interrupt enable path
usb: chipidea: msm: Mark device as runtime pm active
usb: chipidea: msm: Rely on core to override AHBBURST
usb: chipidea: msm: Use hw_write_id_reg() instead of writel
usb: chipidea: msm: Add proper clk and reset support
usb: chipidea: msm: Mux over secondary phy at the right time
usb: chipidea: msm: Restore wrapper settings after reset
usb: chipidea: msm: Make platform data driver local instead of global
usb: chipidea: msm: Add reset controller for PHY POR bit
usb: chipidea: msm: Handle phy power states
usb: chipidea: msm: Be silent on probe defer errors
phy: Add support for Qualcomm's USB HSIC phy
phy: Add support for Qualcomm's USB HS phy

 .../devicetree/bindings/phy/qcom,usb-hs-phy.txt    |  86 +++++++
 .../devicetree/bindings/phy/qcom,usb-hsic-phy.txt  |  65 +++++
 Documentation/devicetree/bindings/usb/ulpi.txt     |  20 ++
 drivers/of/device.c                                |  25 ++
 drivers/phy/Kconfig                                |  15 ++
 drivers/phy/Makefile                               |   2 +
 drivers/phy/phy-qcom-usb-hs.c                      | 286 +++++++++++++++++++++
 drivers/phy/phy-qcom-usb-hsic.c                    | 160 ++++++++++++
 drivers/usb/chipidea/Kconfig                       |   8 +
 drivers/usb/chipidea/Makefile                      |   1 +
 drivers/usb/chipidea/ci.h                          |  24 +-
 drivers/usb/chipidea/ci_hdrc_msm.c                 | 280 +++++++++++++++++---
 drivers/usb/chipidea/core.c                        | 135 +++++-----
 drivers/usb/chipidea/host.c                        |  10 +
 drivers/usb/chipidea/otg.c                         | 105 +++++++-
 drivers/usb/chipidea/udc.c                         |   3 -
 drivers/usb/chipidea/ulpi.c                        | 113 ++++++++
 drivers/usb/common/ulpi.c                          |  79 +++++-
 include/linux/of_device.h                          |   6 +
 include/linux/usb/chipidea.h                       |   9 +-
 20 files changed, 1292 insertions(+), 140 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/phy/qcom,usb-hs-phy.txt
 create mode 100644 Documentation/devicetree/bindings/phy/qcom,usb-hsic-phy.txt
 create mode 100644 Documentation/devicetree/bindings/usb/ulpi.txt
 create mode 100644 drivers/phy/phy-qcom-usb-hs.c
 create mode 100644 drivers/phy/phy-qcom-usb-hsic.c
 create mode 100644 drivers/usb/chipidea/ulpi.c
Signature · 1 line
2.10.0.297.gf6727b0
#1 lore raw

PATCH v5 1/23 of: device: Support loading a module with OF based modalias

In the case of ULPI devices, we want to be able to load the driver before registering the device so that we don't get stuck in a loop waiting for the phy module to appear and failing usb controller probe. Currently we request the ulpi module via the ulpi ids, but in the DT case we might need to request it with the OF based modalias instead. Add a common function that allows anyone to request a module with the OF based modalias.

---
 drivers/of/device.c       | 23 +++++++++++++++++++++++
 include/linux/of_device.h |  6 ++++++
 2 files changed, 29 insertions(+)
drivers/of/device.c +23 -0
index fd5cfad7c403..8a22a253a830 100644
@@ -226,6 +226,29 @@ ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len)
 	return tsize;
 }
 
+int of_device_request_module(struct device *dev)
+{
+	char *str;
+	ssize_t size;
+	int ret;
+
+	size = of_device_get_modalias(dev, NULL, 0);
+	if (size < 0)
+		return size;
+
+	str = kmalloc(size + 1, GFP_KERNEL);
+	if (!str)
+		return -ENOMEM;
+
+	of_device_get_modalias(dev, str, size);
+	str[size] = '\0';
+	ret = request_module(str);
+	kfree(str);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(of_device_request_module);
+
 /**
  * of_device_uevent - Display OF related uevent information
  */
include/linux/of_device.h +6 -0
index cc7dd687a89d..e9afbcc8de12 100644
@@ -37,6 +37,7 @@ extern const void *of_device_get_match_data(const struct device *dev);
 
 extern ssize_t of_device_get_modalias(struct device *dev,
 					char *str, ssize_t len);
+extern int of_device_request_module(struct device *dev);
 
 extern void of_device_uevent(struct device *dev, struct kobj_uevent_env *env);
 extern int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env);
@@ -78,6 +79,11 @@ static inline int of_device_get_modalias(struct device *dev,
 	return -ENODEV;
 }
 
+static inline int of_device_request_module(struct device *dev)
+{
+	return -ENODEV;
+}
+
 static inline int of_device_uevent_modalias(struct device *dev,
 				   struct kobj_uevent_env *env)
 {
Signature · 1 line
2.10.0.297.gf6727b0
#2 lore raw

PATCH v5 2/23 of: device: Export of_device_{get_modalias,uvent_modalias} to modules

In reply to Stephen Boyd

The ULPI bus can be built as a module, and it will soon be calling these functions when it supports probing devices from DT. Export them so they can be used by the ULPI module.

---
 drivers/of/device.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/of/device.c +2 -0
index 8a22a253a830..6719ab35b62e 100644
@@ -225,6 +225,7 @@ ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len)
 
 	return tsize;
 }
+EXPORT_SYMBOL_GPL(of_device_get_modalias);
 
 int of_device_request_module(struct device *dev)
 {
@@ -290,6 +291,7 @@ void of_device_uevent(struct device *dev, struct kobj_uevent_env *env)
 	}
 	mutex_unlock(&of_mutex);
 }
+EXPORT_SYMBOL_GPL(of_device_uevent_modalias);
 
 int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env)
 {
Signature · 1 line
2.10.0.297.gf6727b0
#3 lore raw

Re: [PATCH v5 02/23] of: device: Export of_device_{get_modalias, uvent_modalias} to modules

Quoted 7 lines · Stephen Boyd

The ULPI bus can be built as a module, and it will soon be calling these functions when it supports probing devices from DT. Export them so they can be used by the ULPI module.

I'm interested in this as well. The sunxi-rsb bus is non-enumerable and DT only, and existing slave device drivers can be built as modules. We'd need this to support modalias loading of drivers.

ChenYu

#4 lore raw

Re: [PATCH v5 02/23] of: device: Export of_device_{get_modalias, uvent_modalias} to modules

In reply to Stephen Boyd

Hi,

Quoted 24 lines · Stephen Boyd

The ULPI bus can be built as a module, and it will soon be calling these functions when it supports probing devices from DT. Export them so they can be used by the ULPI module.

---
 drivers/of/device.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/of/device.c +1 -0
index 8a22a253a830..6719ab35b62e 100644
@@ -225,6 +225,7 @@ ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len)
 
        return tsize;
 }
+EXPORT_SYMBOL_GPL(of_device_get_modalias);
 
 int of_device_request_module(struct device *dev)
 {

drivers/of/device.c void of_device_uevent(struct device *dev, struct kobj_uevent_env *env) · line 294

Quoted 4 lines
drivers/of/device.c +1 -0
@@ -290,6 +291,7 @@ void of_device_uevent(struct device *dev, struct kobj_uevent_env *env)
        }
        mutex_unlock(&of_mutex);
 }
+EXPORT_SYMBOL_GPL(of_device_uevent_modalias);

This is trailing the wrong function.

ChenYu

Quoted 11 lines
drivers/of/device.c +0 -1
 int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env)
 {
--

2.10.0.297.gf6727b0

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#5 lore raw

PATCH v5 2/23 of: device: Export of_device_{get_modalias, uvent_modalias} to modules

Quoting Chen-Yu Tsai (2016-10-24 05:19:05)

Quoted 24 lines

Hi,

Quoted 21 lines · Stephen Boyd

The ULPI bus can be built as a module, and it will soon be calling these functions when it supports probing devices from DT. Export them so they can be used by the ULPI module.

---
 drivers/of/device.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/of/device.c +1 -0
index 8a22a253a830..6719ab35b62e 100644
@@ -225,6 +225,7 @@ ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len)
 
        return tsize;
 }
+EXPORT_SYMBOL_GPL(of_device_get_modalias);
 
Quoted 10 lines

drivers/of/device.c void of_device_uevent(struct device *dev, struct kobj_uevent_env *env) · line 294

Quoted 7 lines
drivers/of/device.c +1 -0
 int of_device_request_module(struct device *dev)
 {
@@ -290,6 +291,7 @@ void of_device_uevent(struct device *dev, struct kobj_uevent_env *env)
        }
        mutex_unlock(&of_mutex);
 }
+EXPORT_SYMBOL_GPL(of_device_uevent_modalias);

This is trailing the wrong function.

Good catch. Must have been some bad rebase.

Peter, can you fix it while applying or should I resend this patch?

#6 lore raw

Re: [PATCH v5 02/23] of: device: Export of_device_{get_modalias, uvent_modalias} to modules

Quoted 36 lines · Stephen Boyd

Quoting Chen-Yu Tsai (2016-10-24 05:19:05)

Quoted 24 lines

Hi,

Quoted 21 lines · Stephen Boyd

The ULPI bus can be built as a module, and it will soon be calling these functions when it supports probing devices from DT. Export them so they can be used by the ULPI module.

---
 drivers/of/device.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/of/device.c +1 -0
index 8a22a253a830..6719ab35b62e 100644
@@ -225,6 +225,7 @@ ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len)
 
        return tsize;
 }
+EXPORT_SYMBOL_GPL(of_device_get_modalias);
 
Quoted 10 lines

drivers/of/device.c void of_device_uevent(struct device *dev, struct kobj_uevent_env *env) · line 294

Quoted 7 lines
drivers/of/device.c +1 -0
 int of_device_request_module(struct device *dev)
 {
@@ -290,6 +291,7 @@ void of_device_uevent(struct device *dev, struct kobj_uevent_env *env)
        }
        mutex_unlock(&of_mutex);
 }
+EXPORT_SYMBOL_GPL(of_device_uevent_modalias);

This is trailing the wrong function.

Quoted 4 lines

Good catch. Must have been some bad rebase.

Peter, can you fix it while applying or should I resend this patch?

But, this is device tree patch. I can only get chipidea part and other USB patches if Greg agrees.

Signature · 2 lines
Best Regards,
Peter Chen
#7 lore raw

Re: [PATCH v5 02/23] of: device: Export of_device_{get_modalias, uvent_modalias} to modules

Quoting Peter Chen (2016-10-24 18:16:32)

Quoted 37 lines · Stephen Boyd
Quoted 36 lines

Quoting Chen-Yu Tsai (2016-10-24 05:19:05)

Quoted 34 lines

Hi,

Quoted 24 lines · Stephen Boyd

The ULPI bus can be built as a module, and it will soon be calling these functions when it supports probing devices from DT. Export them so they can be used by the ULPI module.

---
 drivers/of/device.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/of/device.c +1 -0
index 8a22a253a830..6719ab35b62e 100644
@@ -225,6 +225,7 @@ ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len)
 
        return tsize;
 }
+EXPORT_SYMBOL_GPL(of_device_get_modalias);
 
 int of_device_request_module(struct device *dev)
 {

drivers/of/device.c void of_device_uevent(struct device *dev, struct kobj_uevent_env *env) · line 294

Quoted 4 lines
drivers/of/device.c +1 -0
@@ -290,6 +291,7 @@ void of_device_uevent(struct device *dev, struct kobj_uevent_env *env)
        }
        mutex_unlock(&of_mutex);
 }
+EXPORT_SYMBOL_GPL(of_device_uevent_modalias);

This is trailing the wrong function.

Quoted 8 lines
Quoted 4 lines

Good catch. Must have been some bad rebase.

Peter, can you fix it while applying or should I resend this patch?

But, this is device tree patch. I can only get chipidea part and other USB patches if Greg agrees.

Were you expecting Rob to take the drivers/of/* patches? Sorry I thought Rob acked them so they could go through usb with the other changes.

#8 lore raw

Re: [PATCH v5 02/23] of: device: Export of_device_{get_modalias, uvent_modalias} to modules

Quoted 43 lines · Stephen Boyd

Quoting Peter Chen (2016-10-24 18:16:32)

Quoted 42 lines · Stephen Boyd
Quoted 40 lines

Quoting Chen-Yu Tsai (2016-10-24 05:19:05)

Quoted 24 lines

Hi,

Quoted 21 lines · Stephen Boyd

The ULPI bus can be built as a module, and it will soon be calling these functions when it supports probing devices from DT. Export them so they can be used by the ULPI module.

---
 drivers/of/device.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/of/device.c +1 -0
index 8a22a253a830..6719ab35b62e 100644
@@ -225,6 +225,7 @@ ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len)
 
        return tsize;
 }
+EXPORT_SYMBOL_GPL(of_device_get_modalias);
 
Quoted 10 lines

drivers/of/device.c void of_device_uevent(struct device *dev, struct kobj_uevent_env *env) · line 294

Quoted 7 lines
drivers/of/device.c +1 -0
 int of_device_request_module(struct device *dev)
 {
@@ -290,6 +291,7 @@ void of_device_uevent(struct device *dev, struct kobj_uevent_env *env)
        }
        mutex_unlock(&of_mutex);
 }
+EXPORT_SYMBOL_GPL(of_device_uevent_modalias);

This is trailing the wrong function.

Good catch. Must have been some bad rebase.

Peter, can you fix it while applying or should I resend this patch?

Quoted 6 lines
Quoted 3 lines

But, this is device tree patch. I can only get chipidea part and other USB patches if Greg agrees.

Were you expecting Rob to take the drivers/of/* patches? Sorry I thought Rob acked them so they could go through usb with the other changes.

I am just worried about possible merge error when linus pulls both OF and USB tree. Greg, is it ok the OF patches through USB tree with OF maintainer's ack?

Signature · 2 lines
Best Regards,
Peter Chen
#9 lore raw

Re: [PATCH v5 02/23] of: device: Export of_device_{get_modalias, uvent_modalias} to modules

Quoted 48 lines · Peter Chen
Quoted 47 lines · Stephen Boyd

Quoting Peter Chen (2016-10-24 18:16:32)

Quoted 45 lines · Stephen Boyd
Quoted 36 lines

Quoting Chen-Yu Tsai (2016-10-24 05:19:05)

Quoted 24 lines

Hi,

Quoted 21 lines · Stephen Boyd

The ULPI bus can be built as a module, and it will soon be calling these functions when it supports probing devices from DT. Export them so they can be used by the ULPI module.

---
 drivers/of/device.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/of/device.c +1 -0
index 8a22a253a830..6719ab35b62e 100644
@@ -225,6 +225,7 @@ ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len)
 
        return tsize;
 }
+EXPORT_SYMBOL_GPL(of_device_get_modalias);
 
Quoted 10 lines

drivers/of/device.c void of_device_uevent(struct device *dev, struct kobj_uevent_env *env) · line 294

Quoted 7 lines
drivers/of/device.c +1 -0
 int of_device_request_module(struct device *dev)
 {
@@ -290,6 +291,7 @@ void of_device_uevent(struct device *dev, struct kobj_uevent_env *env)
        }
        mutex_unlock(&of_mutex);
 }
+EXPORT_SYMBOL_GPL(of_device_uevent_modalias);

This is trailing the wrong function.

Quoted 4 lines

Good catch. Must have been some bad rebase.

Peter, can you fix it while applying or should I resend this patch?

But, this is device tree patch. I can only get chipidea part and other USB patches if Greg agrees.

Quoted 6 lines
Quoted 2 lines

Were you expecting Rob to take the drivers/of/* patches? Sorry I thought Rob acked them so they could go through usb with the other changes.

I am just worried about possible merge error when linus pulls both OF and USB tree. Greg, is it ok the OF patches through USB tree with OF maintainer's ack?

May I suggest putting the OF patches on an immutable branch so other subsystems can pull them in without pulling in the USB patches? At least I want to use them in the I2C subsystem, and in the sunxi-rsb driver.

Regards
ChenYu

maintainer
#10 lore raw

Re: [PATCH v5 02/23] of: device: Export of_device_{get_modalias, uvent_modalias} to modules

Quoted 52 lines · Chen-Yu Tsai
Quoted 51 lines · Peter Chen
Quoted 49 lines · Stephen Boyd

Quoting Peter Chen (2016-10-24 18:16:32)

Quoted 37 lines · Stephen Boyd
Quoted 36 lines

Quoting Chen-Yu Tsai (2016-10-24 05:19:05)

Quoted 34 lines

Hi,

Quoted 24 lines · Stephen Boyd

The ULPI bus can be built as a module, and it will soon be calling these functions when it supports probing devices from DT. Export them so they can be used by the ULPI module.

---
 drivers/of/device.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/of/device.c +1 -0
index 8a22a253a830..6719ab35b62e 100644
@@ -225,6 +225,7 @@ ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len)
 
        return tsize;
 }
+EXPORT_SYMBOL_GPL(of_device_get_modalias);
 
 int of_device_request_module(struct device *dev)
 {

drivers/of/device.c void of_device_uevent(struct device *dev, struct kobj_uevent_env *env) · line 294

Quoted 4 lines
drivers/of/device.c +1 -0
@@ -290,6 +291,7 @@ void of_device_uevent(struct device *dev, struct kobj_uevent_env *env)
        }
        mutex_unlock(&of_mutex);
 }
+EXPORT_SYMBOL_GPL(of_device_uevent_modalias);

This is trailing the wrong function.

Quoted 8 lines
Quoted 4 lines

Good catch. Must have been some bad rebase.

Peter, can you fix it while applying or should I resend this patch?

But, this is device tree patch. I can only get chipidea part and other USB patches if Greg agrees.

Were you expecting Rob to take the drivers/of/* patches? Sorry I thought Rob acked them so they could go through usb with the other changes.

Quoted 8 lines
Quoted 3 lines

I am just worried about possible merge error when linus pulls both OF and USB tree. Greg, is it ok the OF patches through USB tree with OF maintainer's ack?

May I suggest putting the OF patches on an immutable branch so other subsystems can pull them in without pulling in the USB patches? At least I want to use them in the I2C subsystem, and in the sunxi-rsb driver.

Do you have patches using this already. If not, it is starting to get a bit late for v4.10.

I can apply this, but then you'll just be pulling in other DT patches.

Rob

#11 lore raw

Re: [PATCH v5 02/23] of: device: Export of_device_{get_modalias, uvent_modalias} to modules

Quoted 62 lines · Rob Herring
Quoted 52 lines · Chen-Yu Tsai
Quoted 51 lines · Peter Chen
Quoted 49 lines · Stephen Boyd

Quoting Peter Chen (2016-10-24 18:16:32)

Quoted 37 lines · Stephen Boyd
Quoted 36 lines

Quoting Chen-Yu Tsai (2016-10-24 05:19:05)

Quoted 34 lines

Hi,

Quoted 24 lines · Stephen Boyd

The ULPI bus can be built as a module, and it will soon be calling these functions when it supports probing devices from DT. Export them so they can be used by the ULPI module.

---
 drivers/of/device.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/of/device.c +1 -0
index 8a22a253a830..6719ab35b62e 100644
@@ -225,6 +225,7 @@ ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len)
 
        return tsize;
 }
+EXPORT_SYMBOL_GPL(of_device_get_modalias);
 
 int of_device_request_module(struct device *dev)
 {

drivers/of/device.c void of_device_uevent(struct device *dev, struct kobj_uevent_env *env) · line 294

Quoted 4 lines
drivers/of/device.c +1 -0
@@ -290,6 +291,7 @@ void of_device_uevent(struct device *dev, struct kobj_uevent_env *env)
        }
        mutex_unlock(&of_mutex);
 }
+EXPORT_SYMBOL_GPL(of_device_uevent_modalias);

This is trailing the wrong function.

Quoted 8 lines
Quoted 4 lines

Good catch. Must have been some bad rebase.

Peter, can you fix it while applying or should I resend this patch?

But, this is device tree patch. I can only get chipidea part and other USB patches if Greg agrees.

Were you expecting Rob to take the drivers/of/* patches? Sorry I thought Rob acked them so they could go through usb with the other changes.

Quoted 8 lines
Quoted 3 lines

I am just worried about possible merge error when linus pulls both OF and USB tree. Greg, is it ok the OF patches through USB tree with OF maintainer's ack?

May I suggest putting the OF patches on an immutable branch so other subsystems can pull them in without pulling in the USB patches? At least I want to use them in the I2C subsystem, and in the sunxi-rsb driver.

Quoted 4 lines

Do you have patches using this already. If not, it is starting to get a bit late for v4.10.

I can apply this, but then you'll just be pulling in other DT patches.

Not sure what you mean by "using" this...

I have patches which use this to add DT-based modalias entries for module auto-loading to i2c and sunxi-rsb that I haven't sent.

As far as DT usage goes, we already need this for the axp20x mfd driver. There are 2 variants, i2c and sunxi-rsb. For the I2C variant a fix was sent to fix module auto-loading by using the I2C client ID table:

    mfd: axp20x-i2c: Add i2c-ids to fix module auto-loading
    https://git.kernel.org/cgit/linux/kernel/git/lee/mfd.git/commit/?h=for-mfd-next&id=b7142a19321484bd7681aa547c1d50148c8e2825

But for the sunxi-rsb variant such a fix does not exist, as the bus does not have a separate ID table. It uses DT exclusively.

Regards
ChenYu

#12 lore raw

Re: [PATCH v5 02/23] of: device: Export of_device_{get_modalias, uvent_modalias} to modules

Hello ChenYu

Quoted 1 line · Chen-Yu Tsai

On Fri, Nov 11, 2016 at 5:42 AM, Rob Herring <[email protected]> wrote:

[snip]

Quoted 11 lines
Quoted 5 lines

Do you have patches using this already. If not, it is starting to get a bit late for v4.10.

I can apply this, but then you'll just be pulling in other DT patches.

Not sure what you mean by "using" this...

I have patches which use this to add DT-based modalias entries for module auto-loading to i2c and sunxi-rsb that I haven't sent.

Unfortunately the I2C core can't be changed without breaking a lot of I2C drivers that are relying on the current behavior. I've already posted a RFC patch [0] for I2C that does this about a year ago and enumerated the issues that have to be addressed before the change can be made (and fixed some of the issues mentioned) on this series [1].

Another issue is that an I2C device ID table is a requirement anyways since I2C drivers expect an i2c_device_id as an argument of their probe function. Kieran already have patches [2] to change that which should land soon.

I plan to fix the remaining I2C drivers once his patches are merged and re-post the RFC patch as a proper one.

Quoted 7 lines

As far as DT usage goes, we already need this for the axp20x mfd driver. There are 2 variants, i2c and sunxi-rsb. For the I2C variant a fix was sent to fix module auto-loading by using the I2C client ID table:

    mfd: axp20x-i2c: Add i2c-ids to fix module auto-loading
    https://git.kernel.org/cgit/linux/kernel/git/lee/mfd.git/commit/?h=for-mfd-next&id=b7142a19321484bd7681aa547c1d50148c8e2825

Yes, this is the workaround used by most DT-only I2C drivers. The only reason that these drivers have an I2C device ID is due the restrictions imposed by the I2C core.

Best regards,
Javier

#13 lore raw

PATCH v5 3/23 usb: ulpi: Support device discovery via DT

In reply to Stephen Boyd

The qcom HSIC ULPI phy doesn't have any bits set in the vendor or product ID registers. This makes it impossible to make a ULPI driver match against the ID registers. Add support to discover the ULPI phys via DT help alleviate this problem. In the DT case, we'll look for a ULPI bus node underneath the device registering the ULPI viewport (or the parent of that device to support chipidea's device layout) and then match up the phy node underneath that with the ULPI device that's created.

The side benefit of this is that we can use standard properties in the phy node like clks, regulators, gpios, etc. because we don't have firmware like ACPI to turn these things on for us. And we can use the DT phy binding to point our phy consumer to the phy provider.

The ULPI bus code supports native enumeration by reading the vendor ID and product ID registers at device creation time, but we can't be certain that those register reads will succeed if the phy is not powered up. To avoid any problems with reading the ID registers before the phy is powered we fallback to DT matching when the ID reads fail.

If the ULPI spec had some generic power sequencing for these registers we could put that into the ULPI bus layer and power up the device before reading the ID registers. Unfortunately this doesn't exist and the power sequence is usually device specific. By having the device matched up with DT we can avoid this problem.

Cc Greg Kroah-Hartman <[email protected]>
Cc Heikki Krogerus <[email protected]>
Cc Rob Herring <[email protected]>
---
 Documentation/devicetree/bindings/usb/ulpi.txt | 20 +++++++
 drivers/usb/common/ulpi.c                      | 79 ++++++++++++++++++++++++--
 2 files changed, 93 insertions(+), 6 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/usb/ulpi.txt
Documentation/devicetree/bindings/usb/ulpi.txt new file +20 -0
new file mode 100644
index 000000000000..ca179dc4bd50
@@ -0,0 +1,20 @@
+ULPI bus binding
+----------------
+
+Phys that are behind a ULPI connection can be described with the following
+binding. The host controller shall have a "ulpi" named node as a child, and
+that node shall have one enabled node underneath it representing the ulpi
+device on the bus.
+
+EXAMPLE
+-------
+
+usb {
+	compatible = "vendor,usb-controller";
+
+	ulpi {
+		phy {
+			compatible = "vendor,phy";
+		};
+	};
+};
drivers/usb/common/ulpi.c +73 -6

147 lines not on this page · raw message

Signature · 1 line
2.10.0.297.gf6727b0
maintainer Acked-by on v5 3/23
#14 lore raw

Re: [PATCH v5 03/23] usb: ulpi: Support device discovery via DT

Quoted 34 lines · Stephen Boyd

The qcom HSIC ULPI phy doesn't have any bits set in the vendor or product ID registers. This makes it impossible to make a ULPI driver match against the ID registers. Add support to discover the ULPI phys via DT help alleviate this problem. In the DT case, we'll look for a ULPI bus node underneath the device registering the ULPI viewport (or the parent of that device to support chipidea's device layout) and then match up the phy node underneath that with the ULPI device that's created.

The side benefit of this is that we can use standard properties in the phy node like clks, regulators, gpios, etc. because we don't have firmware like ACPI to turn these things on for us. And we can use the DT phy binding to point our phy consumer to the phy provider.

The ULPI bus code supports native enumeration by reading the vendor ID and product ID registers at device creation time, but we can't be certain that those register reads will succeed if the phy is not powered up. To avoid any problems with reading the ID registers before the phy is powered we fallback to DT matching when the ID reads fail.

If the ULPI spec had some generic power sequencing for these registers we could put that into the ULPI bus layer and power up the device before reading the ID registers. Unfortunately this doesn't exist and the power sequence is usually device specific. By having the device matched up with DT we can avoid this problem.

Cc Greg Kroah-Hartman <[email protected]>
Cc Heikki Krogerus <[email protected]>
Cc Rob Herring <[email protected]>
Quoted 5 lines
---
 Documentation/devicetree/bindings/usb/ulpi.txt | 20 +++++++
 drivers/usb/common/ulpi.c                      | 79 ++++++++++++++++++++++++--
 2 files changed, 93 insertions(+), 6 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/usb/ulpi.txt
maintainer Acked-by on v5 3/23
#15 lore raw

Re: [PATCH v5 03/23] usb: ulpi: Support device discovery via DT

In reply to Stephen Boyd
Quoted 29 lines · Stephen Boyd

The qcom HSIC ULPI phy doesn't have any bits set in the vendor or product ID registers. This makes it impossible to make a ULPI driver match against the ID registers. Add support to discover the ULPI phys via DT help alleviate this problem. In the DT case, we'll look for a ULPI bus node underneath the device registering the ULPI viewport (or the parent of that device to support chipidea's device layout) and then match up the phy node underneath that with the ULPI device that's created.

The side benefit of this is that we can use standard properties in the phy node like clks, regulators, gpios, etc. because we don't have firmware like ACPI to turn these things on for us. And we can use the DT phy binding to point our phy consumer to the phy provider.

The ULPI bus code supports native enumeration by reading the vendor ID and product ID registers at device creation time, but we can't be certain that those register reads will succeed if the phy is not powered up. To avoid any problems with reading the ID registers before the phy is powered we fallback to DT matching when the ID reads fail.

If the ULPI spec had some generic power sequencing for these registers we could put that into the ULPI bus layer and power up the device before reading the ID registers. Unfortunately this doesn't exist and the power sequence is usually device specific. By having the device matched up with DT we can avoid this problem.

Quoted 5 lines
Cc Greg Kroah-Hartman <[email protected]>
Cc Heikki Krogerus <[email protected]>
Cc Rob Herring <[email protected]>
Signature · 1 line
heikki
#16 lore raw

PATCH v5 4/23 usb: chipidea: Only read/write OTGSC from one place

In reply to Stephen Boyd

With the id and vbus detection done via extcon we need to make sure we poll the status of OTGSC properly by considering what the extcon is saying, and not just what the register is saying. Let's move this hw_wait_reg() function to the only place it's used and simplify it for polling the OTGSC register. Then we can make certain we only use the hw_read_otgsc() API to read OTGSC, which will make sure we properly handle extcon events.

Cc Greg Kroah-Hartman <[email protected]>
Cc "Ivan T. Ivanov" <[email protected]>
Fixes 3ecb3e09b042 ("usb: chipidea: Use extcon framework for VBUS and ID detect")
---
 drivers/usb/chipidea/ci.h   |  3 ---
 drivers/usb/chipidea/core.c | 32 --------------------------------
 drivers/usb/chipidea/otg.c  | 34 ++++++++++++++++++++++++++++++----
 3 files changed, 30 insertions(+), 39 deletions(-)
drivers/usb/chipidea/ci.h +0 -3
index cd414559040f..05bc4d631cb9 100644
@@ -428,9 +428,6 @@ int hw_port_test_set(struct ci_hdrc *ci, u8 mode);
 
 u8 hw_port_test_get(struct ci_hdrc *ci);
 
-int hw_wait_reg(struct ci_hdrc *ci, enum ci_hw_regs reg, u32 mask,
-				u32 value, unsigned int timeout_ms);
-
 void ci_platform_configure(struct ci_hdrc *ci);
 
 int dbg_create_files(struct ci_hdrc *ci);
drivers/usb/chipidea/core.c +0 -32
index 69426e644d17..01390e02ee53 100644
@@ -516,38 +516,6 @@ int hw_device_reset(struct ci_hdrc *ci)
 	return 0;
 }
 
-/**
- * hw_wait_reg: wait the register value
- *
- * Sometimes, it needs to wait register value before going on.
- * Eg, when switch to device mode, the vbus value should be lower
- * than OTGSC_BSV before connects to host.
- *
- * @ci: the controller
- * @reg: register index
- * @mask: mast bit
- * @value: the bit value to wait
- * @timeout_ms: timeout in millisecond
- *
- * This function returns an error code if timeout
- */
-int hw_wait_reg(struct ci_hdrc *ci, enum ci_hw_regs reg, u32 mask,
-				u32 value, unsigned int timeout_ms)
-{
-	unsigned long elapse = jiffies + msecs_to_jiffies(timeout_ms);
-
-	while (hw_read(ci, reg, mask) != value) {
-		if (time_after(jiffies, elapse)) {
-			dev_err(ci->dev, "timeout waiting for %08x in %d\n",
-					mask, reg);
-			return -ETIMEDOUT;
-		}
-		msleep(20);
-	}
-
-	return 0;
-}
-
 static irqreturn_t ci_irq(int irq, void *data)
 {
 	struct ci_hdrc *ci = data;
drivers/usb/chipidea/otg.c +30 -4
index 03b6743461d1..a829607c3e4d 100644
@@ -104,7 +104,31 @@ void ci_handle_vbus_change(struct ci_hdrc *ci)
 		usb_gadget_vbus_disconnect(&ci->gadget);
 }
 
-#define CI_VBUS_STABLE_TIMEOUT_MS 5000
+/**
+ * When we switch to device mode, the vbus value should be lower
+ * than OTGSC_BSV before connecting to host.
+ *
+ * @ci: the controller
+ *
+ * This function returns an error code if timeout
+ */
+static int hw_wait_vbus_lower_bsv(struct ci_hdrc *ci)
+{
+	unsigned long elapse = jiffies + msecs_to_jiffies(5000);
+	u32 mask = OTGSC_BSV;
+
+	while (hw_read_otgsc(ci, mask)) {
+		if (time_after(jiffies, elapse)) {
+			dev_err(ci->dev, "timeout waiting for %08x in OTGSC\n",
+					mask);
+			return -ETIMEDOUT;
+		}
+		msleep(20);
+	}
+
+	return 0;
+}
+
 static void ci_handle_id_switch(struct ci_hdrc *ci)
 {
 	enum ci_role role = ci_otg_role(ci);
@@ -116,9 +140,11 @@ static void ci_handle_id_switch(struct ci_hdrc *ci)
 		ci_role_stop(ci);
 
 		if (role == CI_ROLE_GADGET)
-			/* wait vbus lower than OTGSC_BSV */
-			hw_wait_reg(ci, OP_OTGSC, OTGSC_BSV, 0,
-					CI_VBUS_STABLE_TIMEOUT_MS);
+			/*
+			 * wait vbus lower than OTGSC_BSV before connecting
+			 * to host
+			 */
+			hw_wait_vbus_lower_bsv(ci);
 
 		ci_role_start(ci, role);
 	}
Signature · 1 line
2.10.0.297.gf6727b0
#17 lore raw

PATCH v5 5/23 usb: chipidea: Handle extcon events properly

In reply to Stephen Boyd

We're currently emulating the vbus and id interrupts in the OTGSC read API, but we also need to make sure that if we're handling the events with extcon that we don't enable the interrupts for those events in the hardware. Therefore, properly emulate this register if we're using extcon, but don't enable the interrupts. This allows me to get my cable connect/disconnect working properly without getting spurious interrupts on my device that uses an extcon for these two events.

Cc Greg Kroah-Hartman <[email protected]>
Cc "Ivan T. Ivanov" <[email protected]>
Fixes 3ecb3e09b042 ("usb: chipidea: Use extcon framework for VBUS and ID detect")
---
 drivers/usb/chipidea/otg.c   | 46 +++++++++++++++++++++++++++++++++++++++-----
 include/linux/usb/chipidea.h |  2 ++
 2 files changed, 43 insertions(+), 5 deletions(-)
drivers/usb/chipidea/otg.c +41 -5
index a829607c3e4d..0cf149edddd8 100644
@@ -44,12 +44,15 @@ u32 hw_read_otgsc(struct ci_hdrc *ci, u32 mask)
 		else
 			val &= ~OTGSC_BSVIS;
 
-		cable->changed = false;
-
 		if (cable->state)
 			val |= OTGSC_BSV;
 		else
 			val &= ~OTGSC_BSV;
+
+		if (cable->enabled)
+			val |= OTGSC_BSVIE;
+		else
+			val &= ~OTGSC_BSVIE;
 	}
 
 	cable = &ci->platdata->id_extcon;
@@ -59,15 +62,18 @@ u32 hw_read_otgsc(struct ci_hdrc *ci, u32 mask)
 		else
 			val &= ~OTGSC_IDIS;
 
-		cable->changed = false;
-
 		if (cable->state)
 			val |= OTGSC_ID;
 		else
 			val &= ~OTGSC_ID;
+
+		if (cable->enabled)
+			val |= OTGSC_IDIE;
+		else
+			val &= ~OTGSC_IDIE;
 	}
 
-	return val;
+	return val & mask;
 }
 
 /**
@@ -77,6 +83,36 @@ u32 hw_read_otgsc(struct ci_hdrc *ci, u32 mask)
  */
 void hw_write_otgsc(struct ci_hdrc *ci, u32 mask, u32 data)
 {
+	struct ci_hdrc_cable *cable;
+
+	cable = &ci->platdata->vbus_extcon;
+	if (!IS_ERR(cable->edev)) {
+		if (data & mask & OTGSC_BSVIS)
+			cable->changed = false;
+
+		/* Don't enable vbus interrupt if using external notifier */
+		if (data & mask & OTGSC_BSVIE) {
+			cable->enabled = true;
+			data &= ~OTGSC_BSVIE;
+		} else if (mask & OTGSC_BSVIE) {
+			cable->enabled = false;
+		}
+	}
+
+	cable = &ci->platdata->id_extcon;
+	if (!IS_ERR(cable->edev)) {
+		if (data & mask & OTGSC_IDIS)
+			cable->changed = false;
+
+		/* Don't enable id interrupt if using external notifier */
+		if (data & mask & OTGSC_IDIE) {
+			cable->enabled = true;
+			data &= ~OTGSC_IDIE;
+		} else if (mask & OTGSC_IDIE) {
+			cable->enabled = false;
+		}
+	}
+
 	hw_write(ci, OP_OTGSC, mask | OTGSC_INT_STATUS_BITS, data);
 }
 
include/linux/usb/chipidea.h +2 -0
index 5dd75fa47dd8..f9be467d6695 100644
@@ -14,6 +14,7 @@ struct ci_hdrc;
  * struct ci_hdrc_cable - structure for external connector cable state tracking
  * @state: current state of the line
  * @changed: set to true when extcon event happen
+ * @enabled: set to true if we've enabled the vbus or id interrupt
  * @edev: device which generate events
  * @ci: driver state of the chipidea device
  * @nb: hold event notification callback
@@ -22,6 +23,7 @@ struct ci_hdrc;
 struct ci_hdrc_cable {
 	bool				state;
 	bool				changed;
+	bool				enabled;
 	struct extcon_dev		*edev;
 	struct ci_hdrc			*ci;
 	struct notifier_block		nb;
Signature · 1 line
2.10.0.297.gf6727b0
#18 lore raw

PATCH v5 6/23 usb: chipidea: Add platform flag for wrapper phy management

In reply to Stephen Boyd

The ULPI phy on qcom platforms needs to be initialized and powered on after a USB reset and before we toggle the run/stop bit. Otherwise, the phy locks up and doesn't work properly. Therefore, add a flag to skip any phy power management in the core layer, leaving it up to the glue driver to manage.

---
 drivers/usb/chipidea/core.c  | 6 ++++++
 include/linux/usb/chipidea.h | 1 +
 2 files changed, 7 insertions(+)
drivers/usb/chipidea/core.c +6 -0
index 01390e02ee53..532085a096d9 100644
@@ -361,6 +361,9 @@ static int _ci_usb_phy_init(struct ci_hdrc *ci)
  */
 static void ci_usb_phy_exit(struct ci_hdrc *ci)
 {
+	if (ci->platdata->flags & CI_HDRC_OVERRIDE_PHY_CONTROL)
+		return;
+
 	if (ci->phy) {
 		phy_power_off(ci->phy);
 		phy_exit(ci->phy);
@@ -379,6 +382,9 @@ static int ci_usb_phy_init(struct ci_hdrc *ci)
 {
 	int ret;
 
+	if (ci->platdata->flags & CI_HDRC_OVERRIDE_PHY_CONTROL)
+		return 0;
+
 	switch (ci->platdata->phy_mode) {
 	case USBPHY_INTERFACE_MODE_UTMI:
 	case USBPHY_INTERFACE_MODE_UTMIW:
include/linux/usb/chipidea.h +1 -0
index f9be467d6695..d07b162073f7 100644
@@ -57,6 +57,7 @@ struct ci_hdrc_platform_data {
 #define CI_HDRC_OVERRIDE_AHB_BURST	BIT(9)
 #define CI_HDRC_OVERRIDE_TX_BURST	BIT(10)
 #define CI_HDRC_OVERRIDE_RX_BURST	BIT(11)
+#define CI_HDRC_OVERRIDE_PHY_CONTROL	BIT(12) /* Glue layer manages phy */
 	enum usb_dr_mode	dr_mode;
 #define CI_HDRC_CONTROLLER_RESET_EVENT		0
 #define CI_HDRC_CONTROLLER_STOPPED_EVENT	1
Signature · 1 line
2.10.0.297.gf6727b0
#19 lore raw

PATCH v5 7/23 usb: chipidea: Notify events when switching host mode

In reply to Stephen Boyd

The chipidea/udc.c file sends a CI_HDRC_CONTROLLER_RESET_EVENT to the wrapper drivers when it calls hw_device_reset(), but that function is not called from chipidea/host.c. And the udc.c file sends the CI_HDRC_CONTROLLER_STOPPED_EVENT but the host.c file doesn't do anything.

The intent of the reset event is to allow the wrapper driver to do any wrapper specific things after the reset bit has been set in the usb command register. Therefore, add this event hook in the host role after we toggle that bit.

Similarly, the intent of the stopped event is to allow the wrapper driver to do any wrapper specific things after the device is stopped. So when we stop the host role, send the stopped event.

---
 drivers/usb/chipidea/host.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/usb/chipidea/host.c +6 -0
index 96ae69502c86..f036a9e39ced 100644
@@ -90,6 +90,9 @@ static int ehci_ci_reset(struct usb_hcd *hcd)
 
 	ehci->need_io_watchdog = 0;
 
+	if (ci->platdata->notify_event)
+		ci->platdata->notify_event(ci, CI_HDRC_CONTROLLER_RESET_EVENT);
+
 	ci_platform_configure(ci);
 
 	return ret;
@@ -187,6 +190,9 @@ static void host_stop(struct ci_hdrc *ci)
 	struct usb_hcd *hcd = ci->hcd;
 
 	if (hcd) {
+		if (ci->platdata->notify_event)
+			ci->platdata->notify_event(ci,
+				CI_HDRC_CONTROLLER_STOPPED_EVENT);
 		usb_remove_hcd(hcd);
 		usb_put_hcd(hcd);
 		if (ci->platdata->reg_vbus && !ci_otg_is_fsm_mode(ci) &&
Signature · 1 line
2.10.0.297.gf6727b0
#20 lore raw

PATCH v5 8/23 usb: chipidea: Remove locking in ci_udc_start()

In reply to Stephen Boyd

We don't call hw_device_reset() with the ci->lock held, so it doesn't seem like this lock here is protecting anything. Let's just remove it. This allows us to call sleeping functions like phy_init() from within the CI_HDRC_CONTROLLER_RESET_EVENT hook.

---
 drivers/usb/chipidea/udc.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/usb/chipidea/udc.c +0 -3
index 661f43fe0f9e..145b1fd86f58 100644
@@ -1725,7 +1725,6 @@ static int ci_udc_start(struct usb_gadget *gadget,
 			 struct usb_gadget_driver *driver)
 {
 	struct ci_hdrc *ci = container_of(gadget, struct ci_hdrc, gadget);
-	unsigned long flags;
 	int retval = -ENOMEM;
 
 	if (driver->disconnect == NULL)
@@ -1752,7 +1751,6 @@ static int ci_udc_start(struct usb_gadget *gadget,
 
 	pm_runtime_get_sync(&ci->gadget.dev);
 	if (ci->vbus_active) {
-		spin_lock_irqsave(&ci->lock, flags);
 		hw_device_reset(ci);
 	} else {
 		usb_udc_vbus_handler(&ci->gadget, false);
@@ -1761,7 +1759,6 @@ static int ci_udc_start(struct usb_gadget *gadget,
 	}
 
 	retval = hw_device_state(ci, ci->ep0out->qh.dma);
-	spin_unlock_irqrestore(&ci->lock, flags);
 	if (retval)
 		pm_runtime_put_sync(&ci->gadget.dev);
 
Signature · 1 line
2.10.0.297.gf6727b0
#21 lore raw

PATCH v5 9/23 usb: chipidea: Add support for ULPI PHY bus

In reply to Stephen Boyd

Some phys for the chipidea controller are controlled via the ULPI viewport. Add support for the ULPI bus so that these sorts of phys can be probed and read/written automatically without having to duplicate the viewport logic in each phy driver.

Cc Greg Kroah-Hartman <[email protected]>
Cc Heikki Krogerus <[email protected]>
---
 drivers/usb/chipidea/Kconfig  |   7 +++
 drivers/usb/chipidea/Makefile |   1 +
 drivers/usb/chipidea/ci.h     |  21 ++++++++
 drivers/usb/chipidea/core.c   |  31 +++++++++---
 drivers/usb/chipidea/ulpi.c   | 113 ++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 167 insertions(+), 6 deletions(-)
 create mode 100644 drivers/usb/chipidea/ulpi.c
drivers/usb/chipidea/Kconfig +7 -0
index 5e5b9eb7ebf6..19c20eaa23f2 100644
@@ -38,4 +38,11 @@ config USB_CHIPIDEA_HOST
 	  Say Y here to enable host controller functionality of the
 	  ChipIdea driver.
 
+config USB_CHIPIDEA_ULPI
+	bool "ChipIdea ULPI PHY support"
+	depends on USB_ULPI_BUS=y || USB_ULPI_BUS=USB_CHIPIDEA
+	help
+	  Say Y here if you have a ULPI PHY attached to your ChipIdea
+	  controller.
+
 endif
drivers/usb/chipidea/Makefile +1 -0
index 518e445476c3..39fca5715ed3 100644
@@ -4,6 +4,7 @@ ci_hdrc-y				:= core.o otg.o debug.o
 ci_hdrc-$(CONFIG_USB_CHIPIDEA_UDC)	+= udc.o
 ci_hdrc-$(CONFIG_USB_CHIPIDEA_HOST)	+= host.o
 ci_hdrc-$(CONFIG_USB_OTG_FSM)		+= otg_fsm.o
+ci_hdrc-$(CONFIG_USB_CHIPIDEA_ULPI)	+= ulpi.o
 
 # Glue/Bridge layers go here
 
drivers/usb/chipidea/ci.h +21 -0
index 05bc4d631cb9..59e22389c10b 100644
@@ -18,6 +18,8 @@
 #include <linux/usb.h>
 #include <linux/usb/gadget.h>
 #include <linux/usb/otg-fsm.h>
+#include <linux/usb/otg.h>
+#include <linux/ulpi/interface.h>
 
 /******************************************************************************
  * DEFINE
@@ -52,6 +54,7 @@ enum ci_hw_regs {
 	OP_ENDPTLISTADDR,
 	OP_TTCTRL,
 	OP_BURSTSIZE,
+	OP_ULPI_VIEWPORT,
 	OP_PORTSC,
 	OP_DEVLC,
 	OP_OTGSC,
@@ -187,6 +190,8 @@ struct hw_bank {
  * @test_mode: the selected test mode
  * @platdata: platform specific information supplied by parent device
  * @vbus_active: is VBUS active
+ * @ulpi: pointer to ULPI device, if any
+ * @ulpi_ops: ULPI read/write ops for this device
  * @phy: pointer to PHY, if any
  * @usb_phy: pointer to USB PHY, if any and if using the USB PHY framework
  * @hcd: pointer to usb_hcd for ehci host driver
@@ -236,6 +241,10 @@ struct ci_hdrc {
 
 	struct ci_hdrc_platform_data	*platdata;
 	int				vbus_active;
+#ifdef CONFIG_USB_CHIPIDEA_ULPI
+	struct ulpi			*ulpi;
+	struct ulpi_ops 		ulpi_ops;
+#endif
 	struct phy			*phy;
 	/* old usb_phy interface */
 	struct usb_phy			*usb_phy;
@@ -418,6 +427,16 @@ static inline bool ci_otg_is_fsm_mode(struct ci_hdrc *ci)
 #endif
 }
 
+#if IS_ENABLED(CONFIG_USB_CHIPIDEA_ULPI)
+int ci_ulpi_init(struct ci_hdrc *ci);
+void ci_ulpi_exit(struct ci_hdrc *ci);
+int ci_ulpi_resume(struct ci_hdrc *ci);
+#else
+static inline int ci_ulpi_init(struct ci_hdrc *ci) { return 0; }
+static inline void ci_ulpi_exit(struct ci_hdrc *ci) { }
+static inline int ci_ulpi_resume(struct ci_hdrc *ci) { return 0; }
+#endif
+
 u32 hw_read_intr_enable(struct ci_hdrc *ci);
 
 u32 hw_read_intr_status(struct ci_hdrc *ci);
@@ -428,6 +447,8 @@ int hw_port_test_set(struct ci_hdrc *ci, u8 mode);
 
 u8 hw_port_test_get(struct ci_hdrc *ci);
 
+void hw_phymode_configure(struct ci_hdrc *ci);
+
 void ci_platform_configure(struct ci_hdrc *ci);
 
 int dbg_create_files(struct ci_hdrc *ci);
drivers/usb/chipidea/core.c +25 -6
index 532085a096d9..f144e1bbcc82 100644
@@ -86,6 +86,7 @@ static const u8 ci_regs_nolpm[] = {
 	[OP_ENDPTLISTADDR]	= 0x18U,
 	[OP_TTCTRL]		= 0x1CU,
 	[OP_BURSTSIZE]		= 0x20U,
+	[OP_ULPI_VIEWPORT]	= 0x30U,
 	[OP_PORTSC]		= 0x44U,
 	[OP_DEVLC]		= 0x84U,
 	[OP_OTGSC]		= 0x64U,
@@ -110,6 +111,7 @@ static const u8 ci_regs_lpm[] = {
 	[OP_ENDPTLISTADDR]	= 0x18U,
 	[OP_TTCTRL]		= 0x1CU,
 	[OP_BURSTSIZE]		= 0x20U,
+	[OP_ULPI_VIEWPORT]	= 0x30U,
 	[OP_PORTSC]		= 0x44U,
 	[OP_DEVLC]		= 0x84U,
 	[OP_OTGSC]		= 0xC4U,
@@ -285,7 +287,7 @@ static int hw_device_init(struct ci_hdrc *ci, void __iomem *base)
 	return 0;
 }
 
-static void hw_phymode_configure(struct ci_hdrc *ci)
+void hw_phymode_configure(struct ci_hdrc *ci)
 {
 	u32 portsc, lpm, sts = 0;
 
@@ -894,6 +896,7 @@ static int ci_hdrc_probe(struct platform_device *pdev)
 		CI_HDRC_IMX28_WRITE_FIX);
 	ci->supports_runtime_pm = !!(ci->platdata->flags &
 		CI_HDRC_SUPPORTS_RUNTIME_PM);
+	platform_set_drvdata(pdev, ci);
 
 	ret = hw_device_init(ci, base);
 	if (ret < 0) {
@@ -901,6 +904,10 @@ static int ci_hdrc_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 
+	ret = ci_ulpi_init(ci);
+	if (ret)
+		return ret;
+
 	if (ci->platdata->phy) {
 		ci->phy = ci->platdata->phy;
 	} else if (ci->platdata->usb_phy) {
@@ -911,11 +918,15 @@ static int ci_hdrc_probe(struct platform_device *pdev)
 
 		/* if both generic PHY and USB PHY layers aren't enabled */
 		if (PTR_ERR(ci->phy) == -ENOSYS &&
-				PTR_ERR(ci->usb_phy) == -ENXIO)
-			return -ENXIO;
+				PTR_ERR(ci->usb_phy) == -ENXIO) {
+			ret = -ENXIO;
+			goto ulpi_exit;
+		}
 
-		if (IS_ERR(ci->phy) && IS_ERR(ci->usb_phy))
-			return -EPROBE_DEFER;
+		if (IS_ERR(ci->phy) && IS_ERR(ci->usb_phy)) {
+			ret = -EPROBE_DEFER;
+			goto ulpi_exit;
+		}
 
 		if (IS_ERR(ci->phy))
 			ci->phy = NULL;
@@ -1000,7 +1011,6 @@ static int ci_hdrc_probe(struct platform_device *pdev)
 		}
 	}
 
-	platform_set_drvdata(pdev, ci);
 	ret = devm_request_irq(dev, ci->irq, ci_irq, IRQF_SHARED,
 			ci->platdata->name, ci);
 	if (ret)
@@ -1032,6 +1042,8 @@ static int ci_hdrc_probe(struct platform_device *pdev)
 	ci_role_destroy(ci);
 deinit_phy:
 	ci_usb_phy_exit(ci);
+ulpi_exit:
+	ci_ulpi_exit(ci);
 
 	return ret;
 }
@@ -1051,6 +1063,7 @@ static int ci_hdrc_remove(struct platform_device *pdev)
 	ci_role_destroy(ci);
 	ci_hdrc_enter_lpm(ci, true);
 	ci_usb_phy_exit(ci);
+	ci_ulpi_exit(ci);
 
 	return 0;
 }
@@ -1098,6 +1111,7 @@ static void ci_controller_suspend(struct ci_hdrc *ci)
 static int ci_controller_resume(struct device *dev)
 {
 	struct ci_hdrc *ci = dev_get_drvdata(dev);
+	int ret;
 
 	dev_dbg(dev, "at %s\n", __func__);
 
@@ -1107,6 +1121,11 @@ static int ci_controller_resume(struct device *dev)
 	}
 
 	ci_hdrc_enter_lpm(ci, false);
+
+	ret = ci_ulpi_resume(ci);
+	if (ret)
+		return ret;
+
 	if (ci->usb_phy) {
 		usb_phy_set_suspend(ci->usb_phy, 0);
 		usb_phy_set_wakeup(ci->usb_phy, false);
drivers/usb/chipidea/ulpi.c new file +113 -0

113 lines not on this page · raw message

Signature · 1 line
2.10.0.297.gf6727b0
#22 lore raw

PATCH v5 10/23 usb: chipidea: Consolidate extcon notifiers

In reply to Stephen Boyd

The two extcon notifiers are almost the same except for the variable name for the cable structure and the id notifier inverts the cable->state logic. Make it the same and replace two functions with one to save some lines. This also makes it so that the id cable state is true when the id pin is pulled low, so we change the name of ->state to ->connected to properly reflect that we're interested in the cable being connected.

Cc Greg Kroah-Hartman <[email protected]>
Cc "Ivan T. Ivanov" <[email protected]>
---
 drivers/usb/chipidea/core.c  | 45 ++++++++++++--------------------------------
 drivers/usb/chipidea/otg.c   |  8 ++++----
 include/linux/usb/chipidea.h |  4 ++--
 3 files changed, 18 insertions(+), 39 deletions(-)
drivers/usb/chipidea/core.c +12 -33
index f144e1bbcc82..83bc2f2dd6a8 100644
@@ -577,35 +577,14 @@ static irqreturn_t ci_irq(int irq, void *data)
 	return ret;
 }
 
-static int ci_vbus_notifier(struct notifier_block *nb, unsigned long event,
-			    void *ptr)
+static int ci_cable_notifier(struct notifier_block *nb, unsigned long event,
+			     void *ptr)
 {
-	struct ci_hdrc_cable *vbus = container_of(nb, struct ci_hdrc_cable, nb);
-	struct ci_hdrc *ci = vbus->ci;
+	struct ci_hdrc_cable *cbl = container_of(nb, struct ci_hdrc_cable, nb);
+	struct ci_hdrc *ci = cbl->ci;
 
-	if (event)
-		vbus->state = true;
-	else
-		vbus->state = false;
-
-	vbus->changed = true;
-
-	ci_irq(ci->irq, ci);
-	return NOTIFY_DONE;
-}
-
-static int ci_id_notifier(struct notifier_block *nb, unsigned long event,
-			  void *ptr)
-{
-	struct ci_hdrc_cable *id = container_of(nb, struct ci_hdrc_cable, nb);
-	struct ci_hdrc *ci = id->ci;
-
-	if (event)
-		id->state = false;
-	else
-		id->state = true;
-
-	id->changed = true;
+	cbl->connected = event;
+	cbl->changed = true;
 
 	ci_irq(ci->irq, ci);
 	return NOTIFY_DONE;
@@ -714,27 +693,27 @@ static int ci_get_platdata(struct device *dev,
 	}
 
 	cable = &platdata->vbus_extcon;
-	cable->nb.notifier_call = ci_vbus_notifier;
+	cable->nb.notifier_call = ci_cable_notifier;
 	cable->edev = ext_vbus;
 
 	if (!IS_ERR(ext_vbus)) {
 		ret = extcon_get_cable_state_(cable->edev, EXTCON_USB);
 		if (ret)
-			cable->state = true;
+			cable->connected = true;
 		else
-			cable->state = false;
+			cable->connected = false;
 	}
 
 	cable = &platdata->id_extcon;
-	cable->nb.notifier_call = ci_id_notifier;
+	cable->nb.notifier_call = ci_cable_notifier;
 	cable->edev = ext_id;
 
 	if (!IS_ERR(ext_id)) {
 		ret = extcon_get_cable_state_(cable->edev, EXTCON_USB_HOST);
 		if (ret)
-			cable->state = false;
+			cable->connected = true;
 		else
-			cable->state = true;
+			cable->connected = false;
 	}
 	return 0;
 }
drivers/usb/chipidea/otg.c +4 -4
index 0cf149edddd8..695f3fe3ae21 100644
@@ -44,7 +44,7 @@ u32 hw_read_otgsc(struct ci_hdrc *ci, u32 mask)
 		else
 			val &= ~OTGSC_BSVIS;
 
-		if (cable->state)
+		if (cable->connected)
 			val |= OTGSC_BSV;
 		else
 			val &= ~OTGSC_BSV;
@@ -62,10 +62,10 @@ u32 hw_read_otgsc(struct ci_hdrc *ci, u32 mask)
 		else
 			val &= ~OTGSC_IDIS;
 
-		if (cable->state)
-			val |= OTGSC_ID;
+		if (cable->connected)
+			val &= ~OTGSC_ID; /* host */
 		else
-			val &= ~OTGSC_ID;
+			val |= OTGSC_ID; /* device */
 
 		if (cable->enabled)
 			val |= OTGSC_IDIE;
include/linux/usb/chipidea.h +2 -2
index d07b162073f7..7e3daa37cf60 100644
@@ -12,7 +12,7 @@ struct ci_hdrc;
 
 /**
  * struct ci_hdrc_cable - structure for external connector cable state tracking
- * @state: current state of the line
+ * @connected: true if cable is connected, false otherwise
  * @changed: set to true when extcon event happen
  * @enabled: set to true if we've enabled the vbus or id interrupt
  * @edev: device which generate events
@@ -21,7 +21,7 @@ struct ci_hdrc;
  * @conn: used for notification registration
  */
 struct ci_hdrc_cable {
-	bool				state;
+	bool				connected;
 	bool				changed;
 	bool				enabled;
 	struct extcon_dev		*edev;
Signature · 1 line
2.10.0.297.gf6727b0
#23 lore raw

PATCH v5 11/23 usb: chipidea: Emulate OTGSC interrupt enable path

In reply to Stephen Boyd

In the case of an extcon-usb-gpio device being used with the chipidea driver we'll sometimes miss the BSVIS event in the OTGSC register. Consider the case where we don't have a cable attached and the id pin is indicating "host" mode. When we plug in the usb cable for "device" mode a gpio goes high and indicates that we should do the role switch and that vbus is high. When we're in "host" mode the OTGSC register doesn't have BSVIE set.

The following scenario can happen:

CPU0
----
<extcon notifier chain>
ci_cable_notifier()
update id cable state
ci_irq()
if (ci->is_otg && (otgsc & OTGSC_IDIE) && (otgsc & OTGSC_IDIS)) { // true

    ci->id_event = true;
    ci_otg_queue_work()
     schedule()

<extcon notifier event> // same task as before
ci_cable_notifier()
update vbus cable state
ci_irq()

    if (ci->is_otg && (otgsc & OTGSC_BSVIE) && (otgsc & OTGSC_BSVIS)) // false

return IRQ_NONE

ci_otg_work() // switch task to the workqueue now
if (ci->id_event)
ci_handle_id_switch()
ci_role_stop()

    host_stop()
   hw_wait_vbus_lower_bsv(ci); // this times out because vbus is already set
   ci_role_start()
    udc_id_switch_for_device()
     hw_write_otgsc(ci, OTGSC_BSVIS | OTGSC_BSVIE, OTGSC_BSVIS | OTGSC_BSVIE);

At this point, we don't replay the vbus connect event because the vbus event has already happened. This causes things like gadget instances to never see vbus appear, and thus the gadget is never started. Furthermore, we see timeout messages like:

timeout waiting for 0000800 in OTGSC

Let's workaround this by skiping the wait for BSV when we're using an extcon for the vbus notification and let's properly emulate the BSVIS event that would happen when we enable the vbus interrupt while enabling "device" mode.

Cc Peter Chen <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 drivers/usb/chipidea/ci.h   |  2 ++
 drivers/usb/chipidea/core.c | 23 +++++++++++++++++------
 drivers/usb/chipidea/otg.c  | 31 ++++++++++++++++++++++++-------
 3 files changed, 43 insertions(+), 13 deletions(-)
drivers/usb/chipidea/ci.h +2 -0
index 59e22389c10b..e099b8bc79e2 100644
@@ -437,6 +437,8 @@ static inline void ci_ulpi_exit(struct ci_hdrc *ci) { }
 static inline int ci_ulpi_resume(struct ci_hdrc *ci) { return 0; }
 #endif
 
+irqreturn_t __ci_irq(int irq, struct ci_hdrc *ci);
+
 u32 hw_read_intr_enable(struct ci_hdrc *ci);
 
 u32 hw_read_intr_status(struct ci_hdrc *ci);
drivers/usb/chipidea/core.c +17 -6
index 83bc2f2dd6a8..d1ae9a03e0fa 100644
@@ -524,9 +524,8 @@ int hw_device_reset(struct ci_hdrc *ci)
 	return 0;
 }
 
-static irqreturn_t ci_irq(int irq, void *data)
+irqreturn_t __ci_irq(int irq, struct ci_hdrc *ci)
 {
-	struct ci_hdrc *ci = data;
 	irqreturn_t ret = IRQ_NONE;
 	u32 otgsc = 0;
 
@@ -570,9 +569,20 @@ static irqreturn_t ci_irq(int irq, void *data)
 		return IRQ_HANDLED;
 	}
 
-	/* Handle device/host interrupt */
-	if (ci->role != CI_ROLE_END)
-		ret = ci_role(ci)->irq(ci);
+	return ret;
+}
+
+static irqreturn_t ci_irq(int irq, void *data)
+{
+	irqreturn_t ret;
+	struct ci_hdrc *ci = data;
+
+	ret = __ci_irq(irq, ci);
+	if (ret == IRQ_NONE) {
+		/* Handle device/host interrupt */
+		if (ci->role != CI_ROLE_END)
+			ret = ci_role(ci)->irq(ci);
+	}
 
 	return ret;
 }
@@ -586,7 +596,8 @@ static int ci_cable_notifier(struct notifier_block *nb, unsigned long event,
 	cbl->connected = event;
 	cbl->changed = true;
 
-	ci_irq(ci->irq, ci);
+	__ci_irq(ci->irq, ci);
+
 	return NOTIFY_DONE;
 }
 
drivers/usb/chipidea/otg.c +24 -7
index 695f3fe3ae21..f4a21ade1901 100644
@@ -84,36 +84,44 @@ u32 hw_read_otgsc(struct ci_hdrc *ci, u32 mask)
 void hw_write_otgsc(struct ci_hdrc *ci, u32 mask, u32 data)
 {
 	struct ci_hdrc_cable *cable;
+	bool raise_irq = false;
 
 	cable = &ci->platdata->vbus_extcon;
 	if (!IS_ERR(cable->edev)) {
-		if (data & mask & OTGSC_BSVIS)
-			cable->changed = false;
-
 		/* Don't enable vbus interrupt if using external notifier */
 		if (data & mask & OTGSC_BSVIE) {
+			if (cable->enabled == false && cable->changed == true)
+				raise_irq = true;
 			cable->enabled = true;
 			data &= ~OTGSC_BSVIE;
 		} else if (mask & OTGSC_BSVIE) {
 			cable->enabled = false;
 		}
+
+		if (data & mask & OTGSC_BSVIS && !raise_irq)
+			cable->changed = false;
 	}
 
 	cable = &ci->platdata->id_extcon;
 	if (!IS_ERR(cable->edev)) {
-		if (data & mask & OTGSC_IDIS)
-			cable->changed = false;
-
 		/* Don't enable id interrupt if using external notifier */
 		if (data & mask & OTGSC_IDIE) {
+			if (cable->enabled == false && cable->changed == true)
+				raise_irq = true;
 			cable->enabled = true;
 			data &= ~OTGSC_IDIE;
 		} else if (mask & OTGSC_IDIE) {
 			cable->enabled = false;
 		}
+
+		if (data & mask & OTGSC_IDIS && !raise_irq)
+			cable->changed = false;
 	}
 
 	hw_write(ci, OP_OTGSC, mask | OTGSC_INT_STATUS_BITS, data);
+
+	if (raise_irq)
+		__ci_irq(ci->irq, ci);
 }
 
 /**
@@ -175,7 +183,16 @@ static void ci_handle_id_switch(struct ci_hdrc *ci)
 
 		ci_role_stop(ci);
 
-		if (role == CI_ROLE_GADGET)
+		/*
+		 * BSV could be set "immediately" if we're using extcon for
+		 * VBUS because sometimes it's a single GPIO for ID and VBUS
+		 * like in the case of extcon-usb-gpio. In that case we ignore
+		 * waiting for a BSV transition. Really we can't tell when BSV
+		 * is low and the cable is connected, all we know is that the
+		 * BSV is high when we update BSV state.
+		 */
+		if (role == CI_ROLE_GADGET &&
+		    IS_ERR(ci->platdata->vbus_extcon.edev))
 			/*
 			 * wait vbus lower than OTGSC_BSV before connecting
 			 * to host
Signature · 1 line
2.10.0.297.gf6727b0
#24 lore raw

Re: [PATCH v5 11/23] usb: chipidea: Emulate OTGSC interrupt enable path

Quoted 7 lines · Stephen Boyd

In the case of an extcon-usb-gpio device being used with the chipidea driver we'll sometimes miss the BSVIS event in the OTGSC register. Consider the case where we don't have a cable attached and the id pin is indicating "host" mode. When we plug in the usb cable for "device" mode a gpio goes high and indicates that we should do the role switch and that vbus is high. When we're in "host" mode the OTGSC register doesn't have BSVIE set.

I have some questions for your description:

- Do you have any pending or related patches what this patch set is based on? Afaik, the extcon-usb-gpio has no vbus event supported.
- When the ID from 0->1, the chipidea driver will do role switch, and set BSVIE, why it does not occur for your case?

Peter

Quoted 195 lines

The following scenario can happen:

CPU0
----
<extcon notifier chain>
ci_cable_notifier()
update id cable state
ci_irq()
if (ci->is_otg && (otgsc & OTGSC_IDIE) && (otgsc & OTGSC_IDIS)) { // true

    ci->id_event = true;
    ci_otg_queue_work()
     schedule()

<extcon notifier event> // same task as before
ci_cable_notifier()
update vbus cable state
ci_irq()

    if (ci->is_otg && (otgsc & OTGSC_BSVIE) && (otgsc & OTGSC_BSVIS)) // false

return IRQ_NONE

ci_otg_work() // switch task to the workqueue now
if (ci->id_event)
ci_handle_id_switch()
ci_role_stop()

    host_stop()
   hw_wait_vbus_lower_bsv(ci); // this times out because vbus is already set
   ci_role_start()
    udc_id_switch_for_device()
     hw_write_otgsc(ci, OTGSC_BSVIS | OTGSC_BSVIE, OTGSC_BSVIS | OTGSC_BSVIE);

At this point, we don't replay the vbus connect event because the vbus event has already happened. This causes things like gadget instances to never see vbus appear, and thus the gadget is never started. Furthermore, we see timeout messages like:

timeout waiting for 0000800 in OTGSC

Let's workaround this by skiping the wait for BSV when we're using an extcon for the vbus notification and let's properly emulate the BSVIS event that would happen when we enable the vbus interrupt while enabling "device" mode.

Cc Peter Chen <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 drivers/usb/chipidea/ci.h   |  2 ++
 drivers/usb/chipidea/core.c | 23 +++++++++++++++++------
 drivers/usb/chipidea/otg.c  | 31 ++++++++++++++++++++++++-------
 3 files changed, 43 insertions(+), 13 deletions(-)
drivers/usb/chipidea/ci.h +2 -0
index 59e22389c10b..e099b8bc79e2 100644
@@ -437,6 +437,8 @@ static inline void ci_ulpi_exit(struct ci_hdrc *ci) { }
 static inline int ci_ulpi_resume(struct ci_hdrc *ci) { return 0; }
 #endif
 
+irqreturn_t __ci_irq(int irq, struct ci_hdrc *ci);
+
 u32 hw_read_intr_enable(struct ci_hdrc *ci);
 
 u32 hw_read_intr_status(struct ci_hdrc *ci);
drivers/usb/chipidea/core.c +17 -6
index 83bc2f2dd6a8..d1ae9a03e0fa 100644
@@ -524,9 +524,8 @@ int hw_device_reset(struct ci_hdrc *ci)
 	return 0;
 }
 
-static irqreturn_t ci_irq(int irq, void *data)
+irqreturn_t __ci_irq(int irq, struct ci_hdrc *ci)
 {
-	struct ci_hdrc *ci = data;
 	irqreturn_t ret = IRQ_NONE;
 	u32 otgsc = 0;
 
@@ -570,9 +569,20 @@ static irqreturn_t ci_irq(int irq, void *data)
 		return IRQ_HANDLED;
 	}
 
-	/* Handle device/host interrupt */
-	if (ci->role != CI_ROLE_END)
-		ret = ci_role(ci)->irq(ci);
+	return ret;
+}
+
+static irqreturn_t ci_irq(int irq, void *data)
+{
+	irqreturn_t ret;
+	struct ci_hdrc *ci = data;
+
+	ret = __ci_irq(irq, ci);
+	if (ret == IRQ_NONE) {
+		/* Handle device/host interrupt */
+		if (ci->role != CI_ROLE_END)
+			ret = ci_role(ci)->irq(ci);
+	}
 
 	return ret;
 }
@@ -586,7 +596,8 @@ static int ci_cable_notifier(struct notifier_block *nb, unsigned long event,
 	cbl->connected = event;
 	cbl->changed = true;
 
-	ci_irq(ci->irq, ci);
+	__ci_irq(ci->irq, ci);
+
 	return NOTIFY_DONE;
 }
 
drivers/usb/chipidea/otg.c +24 -7
index 695f3fe3ae21..f4a21ade1901 100644
@@ -84,36 +84,44 @@ u32 hw_read_otgsc(struct ci_hdrc *ci, u32 mask)
 void hw_write_otgsc(struct ci_hdrc *ci, u32 mask, u32 data)
 {
 	struct ci_hdrc_cable *cable;
+	bool raise_irq = false;
 
 	cable = &ci->platdata->vbus_extcon;
 	if (!IS_ERR(cable->edev)) {
-		if (data & mask & OTGSC_BSVIS)
-			cable->changed = false;
-
 		/* Don't enable vbus interrupt if using external notifier */
 		if (data & mask & OTGSC_BSVIE) {
+			if (cable->enabled == false && cable->changed == true)
+				raise_irq = true;
 			cable->enabled = true;
 			data &= ~OTGSC_BSVIE;
 		} else if (mask & OTGSC_BSVIE) {
 			cable->enabled = false;
 		}
+
+		if (data & mask & OTGSC_BSVIS && !raise_irq)
+			cable->changed = false;
 	}
 
 	cable = &ci->platdata->id_extcon;
 	if (!IS_ERR(cable->edev)) {
-		if (data & mask & OTGSC_IDIS)
-			cable->changed = false;
-
 		/* Don't enable id interrupt if using external notifier */
 		if (data & mask & OTGSC_IDIE) {
+			if (cable->enabled == false && cable->changed == true)
+				raise_irq = true;
 			cable->enabled = true;
 			data &= ~OTGSC_IDIE;
 		} else if (mask & OTGSC_IDIE) {
 			cable->enabled = false;
 		}
+
+		if (data & mask & OTGSC_IDIS && !raise_irq)
+			cable->changed = false;
 	}
 
 	hw_write(ci, OP_OTGSC, mask | OTGSC_INT_STATUS_BITS, data);
+
+	if (raise_irq)
+		__ci_irq(ci->irq, ci);
 }
 
 /**
@@ -175,7 +183,16 @@ static void ci_handle_id_switch(struct ci_hdrc *ci)
 
 		ci_role_stop(ci);
 
-		if (role == CI_ROLE_GADGET)
+		/*
+		 * BSV could be set "immediately" if we're using extcon for
+		 * VBUS because sometimes it's a single GPIO for ID and VBUS
+		 * like in the case of extcon-usb-gpio. In that case we ignore
+		 * waiting for a BSV transition. Really we can't tell when BSV
+		 * is low and the cable is connected, all we know is that the
+		 * BSV is high when we update BSV state.
+		 */
+		if (role == CI_ROLE_GADGET &&
+		    IS_ERR(ci->platdata->vbus_extcon.edev))
 			/*
 			 * wait vbus lower than OTGSC_BSV before connecting
 			 * to host
Signature · 7 lines
2.10.0.297.gf6727b0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Signature · 2 lines
Best Regards,
Peter Chen
#25 lore raw

PATCH v5 11/23 usb: chipidea: Emulate OTGSC interrupt enable path

Quoting Peter Chen (2016-10-18 18:15:35)

Quoted 9 lines · Stephen Boyd
Quoted 7 lines

In the case of an extcon-usb-gpio device being used with the chipidea driver we'll sometimes miss the BSVIS event in the OTGSC register. Consider the case where we don't have a cable attached and the id pin is indicating "host" mode. When we plug in the usb cable for "device" mode a gpio goes high and indicates that we should do the role switch and that vbus is high. When we're in "host" mode the OTGSC register doesn't have BSVIE set.

Quoted 4 lines

I have some questions for your description:

- Do you have any pending or related patches what this patch set is based on? Afaik, the extcon-usb-gpio has no vbus event supported.

If you're asking if I've made modifications to extcon-usb-gpio, then the answer is no. The branch on linaro.org git server from the cover-letter is the branch I've used to test this with. This patch is specifically to fix issues with that design on the db410c board that has only one pin for ID and vbus detection. It's the schematic that we've discussed in another thread.

extcon-usb-gpio sends two extcon events, EXTCON_USB_HOST (for the id pin) and EXTCON_USB (for the vbus). So afaik it does support vbus events.

Quoted 2 lines

- When the ID from 0->1, the chipidea driver will do role switch, and set BSVIE, why it does not occur for your case?

Right, that happens with this line in the sequence I describe below:

  hw_write_otgsc(ci, OTGSC_BSVIS | OTGSC_BSVIE, OTGSC_BSVIS | OTGSC_BSVIE);

but that happens much later than when the extcon event happens so we miss the interrupt. Technically, the driver isn't expecting the BSVIS interrupt to happen until BSVIE is set, but the extcon can come whenever it wants regardless of how the registers are configured in the controller. So we have to do some sort of 'caching' here to remember that the vbus event happened and replay it when BSVIE is set. At least I imagine this is how the hardware would work? Or if vbus goes high before we enable the interrupt would it just be missed? It seems like polling the BSV bit and then enabling BSVIE is sort of racy there.

Plus, we poll the BSV bit when we role switch, but in my case id bit toggles and vbus goes high at exactly the same time because that is all happening from a single cable being connected, so it's not possible for BSV to go low and see it after the id pin from 0 to 1.

Quoted 44 lines

Peter

Quoted 42 lines

The following scenario can happen:

CPU0
----
<extcon notifier chain>
ci_cable_notifier()
update id cable state
ci_irq()
if (ci->is_otg && (otgsc & OTGSC_IDIE) && (otgsc & OTGSC_IDIS)) { // true

    ci->id_event = true;
    ci_otg_queue_work()
     schedule()

<extcon notifier event> // same task as before
ci_cable_notifier()
update vbus cable state
ci_irq()

    if (ci->is_otg && (otgsc & OTGSC_BSVIE) && (otgsc & OTGSC_BSVIS)) // false

return IRQ_NONE

ci_otg_work() // switch task to the workqueue now
if (ci->id_event)
ci_handle_id_switch()
ci_role_stop()

    host_stop()
   hw_wait_vbus_lower_bsv(ci); // this times out because vbus is already set
   ci_role_start()
    udc_id_switch_for_device()
     hw_write_otgsc(ci, OTGSC_BSVIS | OTGSC_BSVIE, OTGSC_BSVIS | OTGSC_BSVIE);

At this point, we don't replay the vbus connect event because the vbus event has already happened. This causes things like gadget instances to never see vbus appear, and thus the gadget is never started. Furthermore, we see timeout messages like:

timeout waiting for 0000800 in OTGSC

Let's workaround this by skiping the wait for BSV when we're using an extcon for the vbus notification and let's properly emulate the BSVIS event that would happen when we enable the vbus interrupt while enabling "device" mode.

#26 lore raw

Re: [PATCH v5 11/23] usb: chipidea: Emulate OTGSC interrupt enable path

Quoted 22 lines · Stephen Boyd

Quoting Peter Chen (2016-10-18 18:15:35)

Quoted 9 lines · Stephen Boyd
Quoted 7 lines

In the case of an extcon-usb-gpio device being used with the chipidea driver we'll sometimes miss the BSVIS event in the OTGSC register. Consider the case where we don't have a cable attached and the id pin is indicating "host" mode. When we plug in the usb cable for "device" mode a gpio goes high and indicates that we should do the role switch and that vbus is high. When we're in "host" mode the OTGSC register doesn't have BSVIE set.

Quoted 4 lines

I have some questions for your description:

- Do you have any pending or related patches what this patch set is based on? Afaik, the extcon-usb-gpio has no vbus event supported.

If you're asking if I've made modifications to extcon-usb-gpio, then the answer is no. The branch on linaro.org git server from the cover-letter is the branch I've used to test this with. This patch is specifically to fix issues with that design on the db410c board that has only one pin for ID and vbus detection. It's the schematic that we've discussed in another thread.

Quoted 4 lines

extcon-usb-gpio sends two extcon events, EXTCON_USB_HOST (for the id pin) and EXTCON_USB (for the vbus). So afaik it does support vbus events.

Hmm, in fact, your ID event is the same with vbus event, you take external vbus event as ID event for extcon-usb-gpio handling. Yes, it can work due to it sends EXTCON_USB_HOST event first.

Where you change the USB_SW_SEL_PM pin?

Quoted 17 lines
Quoted 2 lines

- When the ID from 0->1, the chipidea driver will do role switch, and set BSVIE, why it does not occur for your case?

Right, that happens with this line in the sequence I describe below:

  hw_write_otgsc(ci, OTGSC_BSVIS | OTGSC_BSVIE, OTGSC_BSVIS | OTGSC_BSVIE);

but that happens much later than when the extcon event happens so we miss the interrupt. Technically, the driver isn't expecting the BSVIS interrupt to happen until BSVIE is set, but the extcon can come whenever it wants regardless of how the registers are configured in the controller. So we have to do some sort of 'caching' here to remember that the vbus event happened and replay it when BSVIE is set. At least I imagine this is how the hardware would work? Or if vbus goes high before we enable the interrupt would it just be missed? It seems like polling the BSV bit and then enabling BSVIE is sort of racy there.

Quoted 4 lines

Plus, we poll the BSV bit when we role switch, but in my case id bit toggles and vbus goes high at exactly the same time because that is all happening from a single cable being connected, so it's not possible for BSV to go low and see it after the id pin from 0 to 1.

Now, I understand your case, but your changes are a little complicated. Would you try if below patch can fix your issue?

Quoted 1 line

From 8b8baf31dcaca53612d0fd91068c84fe09d66f6c Mon Sep 17 00:00:00 2001

From: Peter Chen <[email protected]>
Date: Wed, 19 Oct 2016 15:32:58 +0800
Subject: [PATCH 1/1] usb: chipidea: vbus event may exist before starting
gadget

At some situations, the vbus may already be there before starting gadget. So we need to check vbus event after switch to gadget in order to handle missing vbus event. The typical use cases are plugging vbus cable before driver load or the vbus has already been there after stopping host but before starting gadget.

---
 drivers/usb/chipidea/core.c |  4 ----
 drivers/usb/chipidea/otg.c  | 10 ++++++----
 drivers/usb/chipidea/udc.c  |  2 ++
 3 files changed, 8 insertions(+), 8 deletions(-)
drivers/usb/chipidea/core.c +0 -4
index b814d91..a7d2c68 100644
@@ -992,10 +992,6 @@ static int ci_hdrc_probe(struct platform_device *pdev)
 	}
 
 	if (!ci_otg_is_fsm_mode(ci)) {
-		/* only update vbus status for peripheral */
-		if (ci->role == CI_ROLE_GADGET)
-			ci_handle_vbus_change(ci);
-
 		ret = ci_role_start(ci, ci->role);
 		if (ret) {
 			dev_err(dev, "can't start %s role\n",
drivers/usb/chipidea/otg.c +6 -4
index 695f3fe..99c0709 100644
@@ -134,9 +134,9 @@ void ci_handle_vbus_change(struct ci_hdrc *ci)
 	if (!ci->is_otg)
 		return;
 
-	if (hw_read_otgsc(ci, OTGSC_BSV))
+	if (hw_read_otgsc(ci, OTGSC_BSV) && !ci->vbus_active)
 		usb_gadget_vbus_connect(&ci->gadget);
-	else
+	else if (!hw_read_otgsc(ci, OTGSC_BSV) && ci->vbus_active)
 		usb_gadget_vbus_disconnect(&ci->gadget);
 }
 
@@ -175,10 +175,12 @@ static void ci_handle_id_switch(struct ci_hdrc *ci)
 
 		ci_role_stop(ci);
 
-		if (role == CI_ROLE_GADGET)
+		if (role == CI_ROLE_GADGET &&
+				IS_ERR(ci->platdata->vbus_extcon.edev))
 			/*
 			 * wait vbus lower than OTGSC_BSV before connecting
-			 * to host
+			 * to host. And if vbus's status is an external
+			 * connector, it doesn't need to wait here.
 			 */
 			hw_wait_vbus_lower_bsv(ci);
 
drivers/usb/chipidea/udc.c +2 -0
index 001c2fa..184ffba 100644
@@ -1963,6 +1963,8 @@ static int udc_id_switch_for_device(struct ci_hdrc *ci)
 		/* Clear and enable BSV irq */
 		hw_write_otgsc(ci, OTGSC_BSVIS | OTGSC_BSVIE,
 					OTGSC_BSVIS | OTGSC_BSVIE);
+	/* vbus change may has already been occurred */
+	ci_handle_vbus_change(ci);
 
 	return 0;
 }
Signature · 7 lines
2.7.4


-- 

Best Regards,
Peter Chen
#27 lore raw

PATCH v5 11/23 usb: chipidea: Emulate OTGSC interrupt enable path

Quoting Peter Chen (2016-10-19 01:02:11)

Quoted 13 lines · Stephen Boyd
Quoted 11 lines

If you're asking if I've made modifications to extcon-usb-gpio, then the answer is no. The branch on linaro.org git server from the cover-letter is the branch I've used to test this with. This patch is specifically to fix issues with that design on the db410c board that has only one pin for ID and vbus detection. It's the schematic that we've discussed in another thread.

extcon-usb-gpio sends two extcon events, EXTCON_USB_HOST (for the id pin) and EXTCON_USB (for the vbus). So afaik it does support vbus events.

Quoted 5 lines

Hmm, in fact, your ID event is the same with vbus event, you take external vbus event as ID event for extcon-usb-gpio handling. Yes, it can work due to it sends EXTCON_USB_HOST event first.

Where you change the USB_SW_SEL_PM pin?

Currently that is done with the mux driver I sent based on the extcon event. We don't know if that's before or after the controller handles the extcon event though, so the pin should probably be changed from the chipidea driver instead to be more explicit. Why do you ask though?

Quoted 32 lines
Quoted 18 lines
Quoted 3 lines

- When the ID from 0->1, the chipidea driver will do role switch, and set BSVIE, why it does not occur for your case?

Right, that happens with this line in the sequence I describe below:

  hw_write_otgsc(ci, OTGSC_BSVIS | OTGSC_BSVIE, OTGSC_BSVIS | OTGSC_BSVIE);

but that happens much later than when the extcon event happens so we miss the interrupt. Technically, the driver isn't expecting the BSVIS interrupt to happen until BSVIE is set, but the extcon can come whenever it wants regardless of how the registers are configured in the controller. So we have to do some sort of 'caching' here to remember that the vbus event happened and replay it when BSVIE is set. At least I imagine this is how the hardware would work? Or if vbus goes high before we enable the interrupt would it just be missed? It seems like polling the BSV bit and then enabling BSVIE is sort of racy there.

Quoted 4 lines

Plus, we poll the BSV bit when we role switch, but in my case id bit toggles and vbus goes high at exactly the same time because that is all happening from a single cable being connected, so it's not possible for BSV to go low and see it after the id pin from 0 to 1.

Now, I understand your case, but your changes are a little complicated. Would you try if below patch can fix your issue?

From 8b8baf31dcaca53612d0fd91068c84fe09d66f6c Mon Sep 17 00:00:00 2001
From: Peter Chen <[email protected]>
Date: Wed, 19 Oct 2016 15:32:58 +0800
Subject: [PATCH 1/1] usb: chipidea: vbus event may exist before starting
gadget

Quoted 7 lines

At some situations, the vbus may already be there before starting gadget. So we need to check vbus event after switch to gadget in order to handle missing vbus event. The typical use cases are plugging vbus cable before driver load or the vbus has already been there after stopping host but before starting gadget.

Yes this should work. Light testing doesn't show any problems so far.

Quoted 39 lines
---
 drivers/usb/chipidea/core.c |  4 ----
 drivers/usb/chipidea/otg.c  | 10 ++++++----
 drivers/usb/chipidea/udc.c  |  2 ++
 3 files changed, 8 insertions(+), 8 deletions(-)
drivers/usb/chipidea/core.c +0 -4
index b814d91..a7d2c68 100644
@@ -992,10 +992,6 @@ static int ci_hdrc_probe(struct platform_device *pdev)
        }
 
        if (!ci_otg_is_fsm_mode(ci)) {
-               /* only update vbus status for peripheral */
-               if (ci->role == CI_ROLE_GADGET)
-                       ci_handle_vbus_change(ci);
-
                ret = ci_role_start(ci, ci->role);
                if (ret) {
                        dev_err(dev, "can't start %s role\n",
drivers/usb/chipidea/otg.c +2 -2
index 695f3fe..99c0709 100644
@@ -134,9 +134,9 @@ void ci_handle_vbus_change(struct ci_hdrc *ci)
        if (!ci->is_otg)
                return;
 
-       if (hw_read_otgsc(ci, OTGSC_BSV))
+       if (hw_read_otgsc(ci, OTGSC_BSV) && !ci->vbus_active)
                usb_gadget_vbus_connect(&ci->gadget);
-       else
+       else if (!hw_read_otgsc(ci, OTGSC_BSV) && ci->vbus_active)
                usb_gadget_vbus_disconnect(&ci->gadget);
 }
 
@@ -175,10 +175,12 @@ static void ci_handle_id_switch(struct ci_hdrc *ci)
 

drivers/usb/chipidea/otg.c static void ci_handle_id_switch(struct ci_hdrc *ci) · line 183

Quoted 10 lines
drivers/usb/chipidea/otg.c +4 -2
                ci_role_stop(ci);
 
-               if (role == CI_ROLE_GADGET)
+               if (role == CI_ROLE_GADGET &&
+                               IS_ERR(ci->platdata->vbus_extcon.edev))
                        /*
                         * wait vbus lower than OTGSC_BSV before connecting
-                        * to host
+                        * to host. And if vbus's status is an external
+                        * connector, it doesn't need to wait here.

because OTGSC_BSV will toggle based on the extcon state and not when the phy connects to the host? It would be good to explain why it's not needed instead of just repeating what the code is doing.

drivers/usb/chipidea/udc.c static int udc_id_switch_for_device(struct ci_hdrc *ci) · line 1966

Quoted 12 lines
drivers/usb/chipidea/otg.c +0 -0
                         */
                        hw_wait_vbus_lower_bsv(ci);
 
drivers/usb/chipidea/udc.c +1 -0
index 001c2fa..184ffba 100644
@@ -1963,6 +1963,8 @@ static int udc_id_switch_for_device(struct ci_hdrc *ci)
                /* Clear and enable BSV irq */
                hw_write_otgsc(ci, OTGSC_BSVIS | OTGSC_BSVIE,
                                        OTGSC_BSVIS | OTGSC_BSVIE);
+       /* vbus change may has already been occurred */

"vbus change may have already occurred"?

Quoted 4 lines
drivers/usb/chipidea/udc.c +1 -0
+       ci_handle_vbus_change(ci);
 
        return 0;
 }
#28 lore raw

Re: [PATCH v5 11/23] usb: chipidea: Emulate OTGSC interrupt enable path

Quoted 18 lines · Stephen Boyd

Quoting Peter Chen (2016-10-19 01:02:11)

Quoted 17 lines · Stephen Boyd
Quoted 11 lines

If you're asking if I've made modifications to extcon-usb-gpio, then the answer is no. The branch on linaro.org git server from the cover-letter is the branch I've used to test this with. This patch is specifically to fix issues with that design on the db410c board that has only one pin for ID and vbus detection. It's the schematic that we've discussed in another thread.

extcon-usb-gpio sends two extcon events, EXTCON_USB_HOST (for the id pin) and EXTCON_USB (for the vbus). So afaik it does support vbus events.

Hmm, in fact, your ID event is the same with vbus event, you take external vbus event as ID event for extcon-usb-gpio handling. Yes, it can work due to it sends EXTCON_USB_HOST event first.

Quoted 6 lines
Quoted 1 line

Where you change the USB_SW_SEL_PM pin?

Currently that is done with the mux driver I sent based on the extcon event. We don't know if that's before or after the controller handles the extcon event though, so the pin should probably be changed from the chipidea driver instead to be more explicit. Why do you ask though?

I was just curious how you handle it, now I am clear. From my point, the suitable way may be: mux driver + user app (echo role through debugfs). The extcon-usb-gpio is not necessary, since you have already known role at mux driver.

The current kernel has no framework to handle dual-role switch at kernel space.

Quoted 51 lines
Quoted 7 lines

At some situations, the vbus may already be there before starting gadget. So we need to check vbus event after switch to gadget in order to handle missing vbus event. The typical use cases are plugging vbus cable before driver load or the vbus has already been there after stopping host but before starting gadget.

Yes this should work. Light testing doesn't show any problems so far.

Quoted 41 lines
---
 drivers/usb/chipidea/core.c |  4 ----
 drivers/usb/chipidea/otg.c  | 10 ++++++----
 drivers/usb/chipidea/udc.c  |  2 ++
 3 files changed, 8 insertions(+), 8 deletions(-)
drivers/usb/chipidea/core.c +0 -4
index b814d91..a7d2c68 100644
@@ -992,10 +992,6 @@ static int ci_hdrc_probe(struct platform_device *pdev)
        }
 
        if (!ci_otg_is_fsm_mode(ci)) {
-               /* only update vbus status for peripheral */
-               if (ci->role == CI_ROLE_GADGET)
-                       ci_handle_vbus_change(ci);
-
                ret = ci_role_start(ci, ci->role);
                if (ret) {
                        dev_err(dev, "can't start %s role\n",
drivers/usb/chipidea/otg.c +2 -2
index 695f3fe..99c0709 100644
@@ -134,9 +134,9 @@ void ci_handle_vbus_change(struct ci_hdrc *ci)
        if (!ci->is_otg)
                return;
 
-       if (hw_read_otgsc(ci, OTGSC_BSV))
+       if (hw_read_otgsc(ci, OTGSC_BSV) && !ci->vbus_active)
                usb_gadget_vbus_connect(&ci->gadget);
-       else
+       else if (!hw_read_otgsc(ci, OTGSC_BSV) && ci->vbus_active)
                usb_gadget_vbus_disconnect(&ci->gadget);
 }
 
@@ -175,10 +175,12 @@ static void ci_handle_id_switch(struct ci_hdrc *ci)
 
                ci_role_stop(ci);
 
Quoted 13 lines

drivers/usb/chipidea/otg.c static void ci_handle_id_switch(struct ci_hdrc *ci) · line 183

Quoted 8 lines
drivers/usb/chipidea/otg.c +4 -2
-               if (role == CI_ROLE_GADGET)
+               if (role == CI_ROLE_GADGET &&
+                               IS_ERR(ci->platdata->vbus_extcon.edev))
                        /*
                         * wait vbus lower than OTGSC_BSV before connecting
-                        * to host
+                        * to host. And if vbus's status is an external
+                        * connector, it doesn't need to wait here.

because OTGSC_BSV will toggle based on the extcon state and not when the phy connects to the host? It would be good to explain why it's not needed instead of just repeating what the code is doing.

Thanks, will change like below

"
If connecting status is from an external connector instead of register, we don't need to care vbus on the board, since it will not affect external connector status.
"

Quoted 14 lines

drivers/usb/chipidea/udc.c static int udc_id_switch_for_device(struct ci_hdrc *ci) · line 1966

Quoted 12 lines
drivers/usb/chipidea/otg.c +0 -0
                         */
                        hw_wait_vbus_lower_bsv(ci);
 
drivers/usb/chipidea/udc.c +1 -0
index 001c2fa..184ffba 100644
@@ -1963,6 +1963,8 @@ static int udc_id_switch_for_device(struct ci_hdrc *ci)
                /* Clear and enable BSV irq */
                hw_write_otgsc(ci, OTGSC_BSVIS | OTGSC_BSVIE,
                                        OTGSC_BSVIS | OTGSC_BSVIE);
+       /* vbus change may has already been occurred */

"vbus change may have already occurred"?

Yes, will change.

Signature · 2 lines
Best Regards,
Peter Chen
#29 lore raw

PATCH v5 11/23 usb: chipidea: Emulate OTGSC interrupt enable path

Quoting Peter Chen (2016-10-20 03:10:18)

Quoted 26 lines · Stephen Boyd
Quoted 18 lines

Quoting Peter Chen (2016-10-19 01:02:11)

Quoted 17 lines · Stephen Boyd
Quoted 11 lines

If you're asking if I've made modifications to extcon-usb-gpio, then the answer is no. The branch on linaro.org git server from the cover-letter is the branch I've used to test this with. This patch is specifically to fix issues with that design on the db410c board that has only one pin for ID and vbus detection. It's the schematic that we've discussed in another thread.

extcon-usb-gpio sends two extcon events, EXTCON_USB_HOST (for the id pin) and EXTCON_USB (for the vbus). So afaik it does support vbus events.

Hmm, in fact, your ID event is the same with vbus event, you take external vbus event as ID event for extcon-usb-gpio handling. Yes, it can work due to it sends EXTCON_USB_HOST event first.

Quoted 6 lines
Quoted 1 line

Where you change the USB_SW_SEL_PM pin?

Currently that is done with the mux driver I sent based on the extcon event. We don't know if that's before or after the controller handles the extcon event though, so the pin should probably be changed from the chipidea driver instead to be more explicit. Why do you ask though?

Quoted 7 lines

I was just curious how you handle it, now I am clear. From my point, the suitable way may be: mux driver + user app (echo role through debugfs). The extcon-usb-gpio is not necessary, since you have already known role at mux driver.

The current kernel has no framework to handle dual-role switch at kernel space.

Ok. I'm planning that as future work after this set of patches is merged.

Quoted 10 lines
Quoted 7 lines

drivers/usb/chipidea/udc.c static int udc_id_switch_for_device(struct ci_hdrc *ci) · line 1966

Quoted 5 lines
drivers/usb/chipidea/udc.c +1 -0
@@ -1963,6 +1963,8 @@ static int udc_id_switch_for_device(struct ci_hdrc *ci)
                /* Clear and enable BSV irq */
                hw_write_otgsc(ci, OTGSC_BSVIS | OTGSC_BSVIE,
                                        OTGSC_BSVIS | OTGSC_BSVIE);
+       /* vbus change may has already been occurred */

"vbus change may have already occurred"?

Yes, will change.

Great. Should I wait to incorporate your change into my series, or will you apply the usb patches and Kishon can apply the phy patches? This patch #11 should be dropped, but otherwise I don't think there's anything left to do for this series.

#30 lore raw

Re: [PATCH v5 11/23] usb: chipidea: Emulate OTGSC interrupt enable path

Quoted 46 lines · Stephen Boyd

Quoting Peter Chen (2016-10-20 03:10:18)

Quoted 26 lines · Stephen Boyd
Quoted 18 lines

Quoting Peter Chen (2016-10-19 01:02:11)

Quoted 17 lines · Stephen Boyd
Quoted 11 lines

If you're asking if I've made modifications to extcon-usb-gpio, then the answer is no. The branch on linaro.org git server from the cover-letter is the branch I've used to test this with. This patch is specifically to fix issues with that design on the db410c board that has only one pin for ID and vbus detection. It's the schematic that we've discussed in another thread.

extcon-usb-gpio sends two extcon events, EXTCON_USB_HOST (for the id pin) and EXTCON_USB (for the vbus). So afaik it does support vbus events.

Hmm, in fact, your ID event is the same with vbus event, you take external vbus event as ID event for extcon-usb-gpio handling. Yes, it can work due to it sends EXTCON_USB_HOST event first.

Quoted 6 lines
Quoted 1 line

Where you change the USB_SW_SEL_PM pin?

Currently that is done with the mux driver I sent based on the extcon event. We don't know if that's before or after the controller handles the extcon event though, so the pin should probably be changed from the chipidea driver instead to be more explicit. Why do you ask though?

Quoted 7 lines

I was just curious how you handle it, now I am clear. From my point, the suitable way may be: mux driver + user app (echo role through debugfs). The extcon-usb-gpio is not necessary, since you have already known role at mux driver.

The current kernel has no framework to handle dual-role switch at kernel space.

Ok. I'm planning that as future work after this set of patches is merged.

Quoted 8 lines
Quoted 7 lines

drivers/usb/chipidea/udc.c static int udc_id_switch_for_device(struct ci_hdrc *ci) · line 1966

Quoted 5 lines
drivers/usb/chipidea/udc.c +1 -0
@@ -1963,6 +1963,8 @@ static int udc_id_switch_for_device(struct ci_hdrc *ci)
                /* Clear and enable BSV irq */
                hw_write_otgsc(ci, OTGSC_BSVIS | OTGSC_BSVIE,
                                        OTGSC_BSVIS | OTGSC_BSVIE);
+       /* vbus change may has already been occurred */

"vbus change may have already occurred"?

Quoted 7 lines
Quoted 2 lines

Yes, will change.

Great. Should I wait to incorporate your change into my series, or will you apply the usb patches and Kishon can apply the phy patches? This patch #11 should be dropped, but otherwise I don't think there's anything left to do for this series.

I tested my patch, it works well at my side, if it is ok for you, please ack it, I will apply it as well as your chipidea series after your gpu fix patch at greg's usb-next tree.

Is it ok for you?

Signature · 2 lines
Best Regards,
Peter Chen
#31 lore raw

PATCH v5 11/23 usb: chipidea: Emulate OTGSC interrupt enable path

Quoting Peter Chen (2016-10-20 19:14:50)

Quoted 4 lines

I tested my patch, it works well at my side, if it is ok for you, please ack it, I will apply it as well as your chipidea series after your gpu fix patch at greg's usb-next tree.

Feel free to add my:

tags to the patch.

Quoted 3 lines

Is it ok for you?

Ok sounds good. The GPU patch has been picked up into drm-misc now, but I'm not sure if it's going to be merged into -rc2 or not but it sounds like you'll figure that part out.

I'll resend the phy drivers to Kishon now. Thanks.

#32 lore raw

PATCH v5 12/23 usb: chipidea: msm: Mark device as runtime pm active

In reply to Stephen Boyd

We're not properly marking the glue layer/wrapper device as runtime active, so runtime PM believes that the hardware state is inactive when we call pm_runtime_enable() in this driver. This causes a problem when the glue layer has a power domain associated with it, because runtime PM will go and disable the power domain to match the 'inactive' state of the device. Let's mark the device as active so that runtime PM doesn't improperly power down this device when it's actually active.

---
 drivers/usb/chipidea/ci_hdrc_msm.c | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/chipidea/ci_hdrc_msm.c +1 -0
index 3889809fd0c4..89c1a02d69b5 100644
@@ -80,6 +80,7 @@ static int ci_hdrc_msm_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, plat_ci);
 
+	pm_runtime_set_active(&pdev->dev);
 	pm_runtime_no_callbacks(&pdev->dev);
 	pm_runtime_enable(&pdev->dev);
 
Signature · 1 line
2.10.0.297.gf6727b0
#33 lore raw

PATCH v5 13/23 usb: chipidea: msm: Rely on core to override AHBBURST

In reply to Stephen Boyd

The core framework already handles setting this parameter with a platform quirk. Add the appropriate flag so that we always set AHBBURST to 0. Technically DT should be doing this, but we always do it for msm chipidea devices so setting the flag in the driver works just as well. If the burst needs to be anything besides 0, we expect the 'ahb-burst-config' dts property to be present.

---
 drivers/usb/chipidea/ci_hdrc_msm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/chipidea/ci_hdrc_msm.c +2 -2
index 89c1a02d69b5..719b20caf88e 100644
@@ -24,7 +24,6 @@ static void ci_hdrc_msm_notify_event(struct ci_hdrc *ci, unsigned event)
 	switch (event) {
 	case CI_HDRC_CONTROLLER_RESET_EVENT:
 		dev_dbg(dev, "CI_HDRC_CONTROLLER_RESET_EVENT received\n");
-		writel(0, USB_AHBBURST);
 		/* use AHB transactor, allow posted data writes */
 		writel(0x8, USB_AHBMODE);
 		usb_phy_init(ci->usb_phy);
@@ -47,7 +46,8 @@ static struct ci_hdrc_platform_data ci_hdrc_msm_platdata = {
 	.name			= "ci_hdrc_msm",
 	.capoffset		= DEF_CAPOFFSET,
 	.flags			= CI_HDRC_REGS_SHARED |
-				  CI_HDRC_DISABLE_STREAMING,
+				  CI_HDRC_DISABLE_STREAMING |
+				  CI_HDRC_OVERRIDE_AHB_BURST,
 
 	.notify_event		= ci_hdrc_msm_notify_event,
 };
Signature · 1 line
2.10.0.297.gf6727b0
#34 lore raw

PATCH v5 14/23 usb: chipidea: msm: Use hw_write_id_reg() instead of writel

In reply to Stephen Boyd

The MSM_USB_BASE macro trick is not very clear, and we're using it for only one register write so let's just move to using hw_write_id_reg() and passing the ci pointer instead. That clearly shows what offset we're using and avoids needing to include the msm_hsusb_hw.h file when we're going to delete that file soon.

---
 drivers/usb/chipidea/ci_hdrc_msm.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/usb/chipidea/ci_hdrc_msm.c +2 -4
index 719b20caf88e..b282a717bf8c 100644
@@ -8,14 +8,12 @@
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
-#include <linux/usb/msm_hsusb_hw.h>
-#include <linux/usb/ulpi.h>
 #include <linux/usb/gadget.h>
 #include <linux/usb/chipidea.h>
 
 #include "ci.h"
 
-#define MSM_USB_BASE	(ci->hw_bank.abs)
+#define HS_PHY_AHB_MODE			0x0098
 
 static void ci_hdrc_msm_notify_event(struct ci_hdrc *ci, unsigned event)
 {
@@ -25,7 +23,7 @@ static void ci_hdrc_msm_notify_event(struct ci_hdrc *ci, unsigned event)
 	case CI_HDRC_CONTROLLER_RESET_EVENT:
 		dev_dbg(dev, "CI_HDRC_CONTROLLER_RESET_EVENT received\n");
 		/* use AHB transactor, allow posted data writes */
-		writel(0x8, USB_AHBMODE);
+		hw_write_id_reg(ci, HS_PHY_AHB_MODE, 0xffffffff, 0x8);
 		usb_phy_init(ci->usb_phy);
 		break;
 	case CI_HDRC_CONTROLLER_STOPPED_EVENT:
Signature · 1 line
2.10.0.297.gf6727b0
#35 lore raw

PATCH v5 15/23 usb: chipidea: msm: Add proper clk and reset support

In reply to Stephen Boyd

The msm chipidea controller uses two main clks, an AHB clk to read/write the MMIO registers and a core clk called the system clk that drives the controller itself. Add support for these clks as they're required in all designs.

Also add support for an optional third clk that we need to turn on to reset the controller and wrapper logic and other "housekeeping" things. This clk was removed in later revisions of the hardware because the reset methodology no longer required clks to be enabled to propagate resets.

---
 drivers/usb/chipidea/ci_hdrc_msm.c | 72 +++++++++++++++++++++++++++++++++++---
 1 file changed, 68 insertions(+), 4 deletions(-)
drivers/usb/chipidea/ci_hdrc_msm.c +68 -4
index b282a717bf8c..7e870a253f55 100644
@@ -10,11 +10,20 @@
 #include <linux/pm_runtime.h>
 #include <linux/usb/gadget.h>
 #include <linux/usb/chipidea.h>
+#include <linux/clk.h>
+#include <linux/reset.h>
 
 #include "ci.h"
 
 #define HS_PHY_AHB_MODE			0x0098
 
+struct ci_hdrc_msm {
+	struct platform_device *ci;
+	struct clk *core_clk;
+	struct clk *iface_clk;
+	struct clk *fs_clk;
+};
+
 static void ci_hdrc_msm_notify_event(struct ci_hdrc *ci, unsigned event)
 {
 	struct device *dev = ci->gadget.dev.parent;
@@ -52,11 +61,20 @@ static struct ci_hdrc_platform_data ci_hdrc_msm_platdata = {
 
 static int ci_hdrc_msm_probe(struct platform_device *pdev)
 {
+	struct ci_hdrc_msm *ci;
 	struct platform_device *plat_ci;
 	struct usb_phy *phy;
+	struct clk *clk;
+	struct reset_control *reset;
+	int ret;
 
 	dev_dbg(&pdev->dev, "ci_hdrc_msm_probe\n");
 
+	ci = devm_kzalloc(&pdev->dev, sizeof(*ci), GFP_KERNEL);
+	if (!ci)
+		return -ENOMEM;
+	platform_set_drvdata(pdev, ci);
+
 	/*
 	 * OTG(PHY) driver takes care of PHY initialization, clock management,
 	 * powering up VBUS, mapping of registers address space and power
@@ -68,29 +86,75 @@ static int ci_hdrc_msm_probe(struct platform_device *pdev)
 
 	ci_hdrc_msm_platdata.usb_phy = phy;
 
+	reset = devm_reset_control_get(&pdev->dev, "core");
+	if (IS_ERR(reset))
+		return PTR_ERR(reset);
+
+	ci->core_clk = clk = devm_clk_get(&pdev->dev, "core");
+	if (IS_ERR(clk))
+		return PTR_ERR(clk);
+
+	ci->iface_clk = clk = devm_clk_get(&pdev->dev, "iface");
+	if (IS_ERR(clk))
+		return PTR_ERR(clk);
+
+	ci->fs_clk = clk = devm_clk_get(&pdev->dev, "fs");
+	if (IS_ERR(clk)) {
+		if (PTR_ERR(clk) == -EPROBE_DEFER)
+			return -EPROBE_DEFER;
+		ci->fs_clk = NULL;
+	}
+
+	ret = clk_prepare_enable(ci->fs_clk);
+	if (ret)
+		return ret;
+
+	reset_control_assert(reset);
+	usleep_range(10000, 12000);
+	reset_control_deassert(reset);
+
+	clk_disable_unprepare(ci->fs_clk);
+
+	ret = clk_prepare_enable(ci->core_clk);
+	if (ret)
+		return ret;
+
+	ret = clk_prepare_enable(ci->iface_clk);
+	if (ret)
+		goto err_iface;
+
 	plat_ci = ci_hdrc_add_device(&pdev->dev,
 				pdev->resource, pdev->num_resources,
 				&ci_hdrc_msm_platdata);
 	if (IS_ERR(plat_ci)) {
 		dev_err(&pdev->dev, "ci_hdrc_add_device failed!\n");
-		return PTR_ERR(plat_ci);
+		ret = PTR_ERR(plat_ci);
+		goto err_mux;
 	}
 
-	platform_set_drvdata(pdev, plat_ci);
+	ci->ci = plat_ci;
 
 	pm_runtime_set_active(&pdev->dev);
 	pm_runtime_no_callbacks(&pdev->dev);
 	pm_runtime_enable(&pdev->dev);
 
 	return 0;
+
+err_mux:
+	clk_disable_unprepare(ci->iface_clk);
+err_iface:
+	clk_disable_unprepare(ci->core_clk);
+	return ret;
 }
 
 static int ci_hdrc_msm_remove(struct platform_device *pdev)
 {
-	struct platform_device *plat_ci = platform_get_drvdata(pdev);
+	struct ci_hdrc_msm *ci = platform_get_drvdata(pdev);
 
 	pm_runtime_disable(&pdev->dev);
-	ci_hdrc_remove_device(plat_ci);
+	ci_hdrc_remove_device(ci->ci);
+	clk_disable_unprepare(ci->iface_clk);
+	clk_disable_unprepare(ci->core_clk);
 
 	return 0;
 }
Signature · 1 line
2.10.0.297.gf6727b0
#36 lore raw

PATCH v5 16/23 usb: chipidea: msm: Mux over secondary phy at the right time

In reply to Stephen Boyd

We need to pick the correct phy at runtime based on how the SoC has been wired onto the board. If the secondary phy is used, take it out of reset and mux over to it by writing into the TCSR register. Make sure to do this on reset too, because this register is reset to the default value (primary phy) after the RESET bit is set in USBCMD.

---
 drivers/usb/chipidea/ci_hdrc_msm.c | 62 ++++++++++++++++++++++++++++++++++++--
 1 file changed, 60 insertions(+), 2 deletions(-)
drivers/usb/chipidea/ci_hdrc_msm.c +60 -2
index 7e870a253f55..4b0aadc2be2f 100644
@@ -8,29 +8,44 @@
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
-#include <linux/usb/gadget.h>
 #include <linux/usb/chipidea.h>
 #include <linux/clk.h>
 #include <linux/reset.h>
+#include <linux/mfd/syscon.h>
+#include <linux/regmap.h>
+#include <linux/io.h>
 
 #include "ci.h"
 
 #define HS_PHY_AHB_MODE			0x0098
 
+/* Vendor base starts at 0x200 beyond CI base */
+#define HS_PHY_SEC_CTRL			0x0078
+#define HS_PHY_DIG_CLAMP_N		BIT(16)
+
 struct ci_hdrc_msm {
 	struct platform_device *ci;
 	struct clk *core_clk;
 	struct clk *iface_clk;
 	struct clk *fs_clk;
+	bool secondary_phy;
+	void __iomem *base;
 };
 
 static void ci_hdrc_msm_notify_event(struct ci_hdrc *ci, unsigned event)
 {
-	struct device *dev = ci->gadget.dev.parent;
+	struct device *dev = ci->dev->parent;
+	struct ci_hdrc_msm *msm_ci = dev_get_drvdata(dev);
 
 	switch (event) {
 	case CI_HDRC_CONTROLLER_RESET_EVENT:
 		dev_dbg(dev, "CI_HDRC_CONTROLLER_RESET_EVENT received\n");
+		if (msm_ci->secondary_phy) {
+			u32 val = readl_relaxed(msm_ci->base + HS_PHY_SEC_CTRL);
+			val |= HS_PHY_DIG_CLAMP_N;
+			writel_relaxed(val, msm_ci->base + HS_PHY_SEC_CTRL);
+		}
+
 		/* use AHB transactor, allow posted data writes */
 		hw_write_id_reg(ci, HS_PHY_AHB_MODE, 0xffffffff, 0x8);
 		usb_phy_init(ci->usb_phy);
@@ -59,6 +74,39 @@ static struct ci_hdrc_platform_data ci_hdrc_msm_platdata = {
 	.notify_event		= ci_hdrc_msm_notify_event,
 };
 
+static int ci_hdrc_msm_mux_phy(struct ci_hdrc_msm *ci,
+			       struct platform_device *pdev)
+{
+	struct regmap *regmap;
+	struct device *dev = &pdev->dev;
+	struct of_phandle_args args;
+	u32 val;
+	int ret;
+
+	ret = of_parse_phandle_with_fixed_args(dev->of_node, "phy-select", 2, 0,
+					       &args);
+	if (ret)
+		return 0;
+
+	regmap = syscon_node_to_regmap(args.np);
+	of_node_put(args.np);
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);
+
+	ret = regmap_write(regmap, args.args[0], args.args[1]);
+	if (ret)
+		return ret;
+
+	ci->secondary_phy = !!args.args[1];
+	if (ci->secondary_phy) {
+		val = readl_relaxed(ci->base + HS_PHY_SEC_CTRL);
+		val |= HS_PHY_DIG_CLAMP_N;
+		writel_relaxed(val, ci->base + HS_PHY_SEC_CTRL);
+	}
+
+	return 0;
+}
+
 static int ci_hdrc_msm_probe(struct platform_device *pdev)
 {
 	struct ci_hdrc_msm *ci;
@@ -66,6 +114,7 @@ static int ci_hdrc_msm_probe(struct platform_device *pdev)
 	struct usb_phy *phy;
 	struct clk *clk;
 	struct reset_control *reset;
+	struct resource *res;
 	int ret;
 
 	dev_dbg(&pdev->dev, "ci_hdrc_msm_probe\n");
@@ -105,6 +154,11 @@ static int ci_hdrc_msm_probe(struct platform_device *pdev)
 		ci->fs_clk = NULL;
 	}
 
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+	ci->base = devm_ioremap_resource(&pdev->dev, res);
+	if (!ci->base)
+		return -ENOMEM;
+
 	ret = clk_prepare_enable(ci->fs_clk);
 	if (ret)
 		return ret;
@@ -123,6 +177,10 @@ static int ci_hdrc_msm_probe(struct platform_device *pdev)
 	if (ret)
 		goto err_iface;
 
+	ret = ci_hdrc_msm_mux_phy(ci, pdev);
+	if (ret)
+		goto err_mux;
+
 	plat_ci = ci_hdrc_add_device(&pdev->dev,
 				pdev->resource, pdev->num_resources,
 				&ci_hdrc_msm_platdata);
Signature · 1 line
2.10.0.297.gf6727b0
#37 lore raw

PATCH v5 17/23 usb: chipidea: msm: Restore wrapper settings after reset

In reply to Stephen Boyd

When the RESET bit is set in the USBCMD register it resets quite a few of the wrapper's registers to their reset state. This includes the GENCONFIG and GENCONFIG2 registers. Currently this is done by the usb phy and ehci-msm drivers writing into the controller wrapper's MMIO address space. Let's consolidate the register writes into the wrapper driver instead so that we clearly split the wrapper from the phys.

---
 drivers/usb/chipidea/ci_hdrc_msm.c | 39 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
drivers/usb/chipidea/ci_hdrc_msm.c +39 -0
index 4b0aadc2be2f..333817291798 100644
@@ -14,11 +14,22 @@
 #include <linux/mfd/syscon.h>
 #include <linux/regmap.h>
 #include <linux/io.h>
+#include <linux/extcon.h>
+#include <linux/of.h>
 
 #include "ci.h"
 
 #define HS_PHY_AHB_MODE			0x0098
 
+#define HS_PHY_GENCONFIG		0x009c
+#define HS_PHY_TXFIFO_IDLE_FORCE_DIS	BIT(4)
+
+#define HS_PHY_GENCONFIG_2		0x00a0
+#define HS_PHY_SESS_VLD_CTRL_EN		BIT(7)
+#define HS_PHY_ULPI_TX_PKT_EN_CLR_FIX	BIT(19)
+
+#define HSPHY_SESS_VLD_CTRL		BIT(25)
+
 /* Vendor base starts at 0x200 beyond CI base */
 #define HS_PHY_SEC_CTRL			0x0078
 #define HS_PHY_DIG_CLAMP_N		BIT(16)
@@ -29,6 +40,7 @@ struct ci_hdrc_msm {
 	struct clk *iface_clk;
 	struct clk *fs_clk;
 	bool secondary_phy;
+	bool hsic;
 	void __iomem *base;
 };
 
@@ -48,6 +60,24 @@ static void ci_hdrc_msm_notify_event(struct ci_hdrc *ci, unsigned event)
 
 		/* use AHB transactor, allow posted data writes */
 		hw_write_id_reg(ci, HS_PHY_AHB_MODE, 0xffffffff, 0x8);
+
+		/* workaround for rx buffer collision issue */
+		hw_write_id_reg(ci, HS_PHY_GENCONFIG,
+				HS_PHY_TXFIFO_IDLE_FORCE_DIS, 0);
+
+		if (!msm_ci->hsic)
+			hw_write_id_reg(ci, HS_PHY_GENCONFIG_2,
+					HS_PHY_ULPI_TX_PKT_EN_CLR_FIX, 0);
+
+		if (!IS_ERR(ci->platdata->vbus_extcon.edev)) {
+			hw_write_id_reg(ci, HS_PHY_GENCONFIG_2,
+					HS_PHY_SESS_VLD_CTRL_EN,
+					HS_PHY_SESS_VLD_CTRL_EN);
+			hw_write(ci, OP_USBCMD, HSPHY_SESS_VLD_CTRL,
+				 HSPHY_SESS_VLD_CTRL);
+
+		}
+
 		usb_phy_init(ci->usb_phy);
 		break;
 	case CI_HDRC_CONTROLLER_STOPPED_EVENT:
@@ -116,6 +146,7 @@ static int ci_hdrc_msm_probe(struct platform_device *pdev)
 	struct reset_control *reset;
 	struct resource *res;
 	int ret;
+	struct device_node *ulpi_node, *phy_node;
 
 	dev_dbg(&pdev->dev, "ci_hdrc_msm_probe\n");
 
@@ -181,6 +212,14 @@ static int ci_hdrc_msm_probe(struct platform_device *pdev)
 	if (ret)
 		goto err_mux;
 
+	ulpi_node = of_find_node_by_name(pdev->dev.of_node, "ulpi");
+	if (ulpi_node) {
+		phy_node = of_get_next_available_child(ulpi_node, NULL);
+		ci->hsic = of_device_is_compatible(phy_node, "qcom,usb-hsic-phy");
+		of_node_put(phy_node);
+	}
+	of_node_put(ulpi_node);
+
 	plat_ci = ci_hdrc_add_device(&pdev->dev,
 				pdev->resource, pdev->num_resources,
 				&ci_hdrc_msm_platdata);
Signature · 1 line
2.10.0.297.gf6727b0
#38 lore raw

PATCH v5 18/23 usb: chipidea: msm: Make platform data driver local instead of global

In reply to Stephen Boyd

If two devices are probed with this same driver, they'll share the same platform data structure, while the chipidea core layer writes and modifies it. This can lead to interesting results especially if one device is an OTG type chipidea controller and another is a host. Let's create a copy of this structure per each device instance so that odd things don't happen.

---
 drivers/usb/chipidea/ci_hdrc_msm.c | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)
drivers/usb/chipidea/ci_hdrc_msm.c +9 -14
index 333817291798..2489a63d3e75 100644
@@ -39,6 +39,7 @@ struct ci_hdrc_msm {
 	struct clk *core_clk;
 	struct clk *iface_clk;
 	struct clk *fs_clk;
+	struct ci_hdrc_platform_data pdata;
 	bool secondary_phy;
 	bool hsic;
 	void __iomem *base;
@@ -94,16 +95,6 @@ static void ci_hdrc_msm_notify_event(struct ci_hdrc *ci, unsigned event)
 	}
 }
 
-static struct ci_hdrc_platform_data ci_hdrc_msm_platdata = {
-	.name			= "ci_hdrc_msm",
-	.capoffset		= DEF_CAPOFFSET,
-	.flags			= CI_HDRC_REGS_SHARED |
-				  CI_HDRC_DISABLE_STREAMING |
-				  CI_HDRC_OVERRIDE_AHB_BURST,
-
-	.notify_event		= ci_hdrc_msm_notify_event,
-};
-
 static int ci_hdrc_msm_mux_phy(struct ci_hdrc_msm *ci,
 			       struct platform_device *pdev)
 {
@@ -164,7 +155,12 @@ static int ci_hdrc_msm_probe(struct platform_device *pdev)
 	if (IS_ERR(phy))
 		return PTR_ERR(phy);
 
-	ci_hdrc_msm_platdata.usb_phy = phy;
+	ci->pdata.name = "ci_hdrc_msm";
+	ci->pdata.capoffset = DEF_CAPOFFSET;
+	ci->pdata.flags	= CI_HDRC_REGS_SHARED | CI_HDRC_DISABLE_STREAMING |
+			  CI_HDRC_OVERRIDE_AHB_BURST;
+	ci->pdata.notify_event = ci_hdrc_msm_notify_event;
+	ci->pdata.usb_phy = phy;
 
 	reset = devm_reset_control_get(&pdev->dev, "core");
 	if (IS_ERR(reset))
@@ -220,9 +216,8 @@ static int ci_hdrc_msm_probe(struct platform_device *pdev)
 	}
 	of_node_put(ulpi_node);
 
-	plat_ci = ci_hdrc_add_device(&pdev->dev,
-				pdev->resource, pdev->num_resources,
-				&ci_hdrc_msm_platdata);
+	plat_ci = ci_hdrc_add_device(&pdev->dev, pdev->resource,
+				     pdev->num_resources, &ci->pdata);
 	if (IS_ERR(plat_ci)) {
 		dev_err(&pdev->dev, "ci_hdrc_add_device failed!\n");
 		ret = PTR_ERR(plat_ci);
Signature · 1 line
2.10.0.297.gf6727b0
#39 lore raw

PATCH v5 19/23 usb: chipidea: msm: Add reset controller for PHY POR bit

In reply to Stephen Boyd

The MSM chipidea wrapper has two bits that are used to reset the first or second phy. Add support for these bits via the reset controller framework, so that phy drivers can reset their hardware at the right time during initialization.

---
 drivers/usb/chipidea/Kconfig       |  1 +
 drivers/usb/chipidea/ci_hdrc_msm.c | 50 ++++++++++++++++++++++++++++++++++++--
 2 files changed, 49 insertions(+), 2 deletions(-)
drivers/usb/chipidea/Kconfig +1 -0
index 19c20eaa23f2..fc96f5cdcb5c 100644
@@ -2,6 +2,7 @@ config USB_CHIPIDEA
 	tristate "ChipIdea Highspeed Dual Role Controller"
 	depends on ((USB_EHCI_HCD && USB_GADGET) || (USB_EHCI_HCD && !USB_GADGET) || (!USB_EHCI_HCD && USB_GADGET)) && HAS_DMA
 	select EXTCON
+	select RESET_CONTROLLER
 	help
 	  Say Y here if your system has a dual role high speed USB
 	  controller based on ChipIdea silicon IP. It supports:
drivers/usb/chipidea/ci_hdrc_msm.c +48 -2

102 lines not on this page · raw message

Signature · 1 line
2.10.0.297.gf6727b0
#40 lore raw

PATCH v5 20/23 usb: chipidea: msm: Handle phy power states

In reply to Stephen Boyd

The ULPI phy on qcom platforms needs to be initialized and powered on after a USB reset and before we toggle the run/stop bit. Otherwise, the phy locks up and doesn't work properly. Hook the phy initialization into the RESET event and the phy power off into the STOPPED event.

---
 drivers/usb/chipidea/ci_hdrc_msm.c | 40 +++++++++++++++++++-------------------
 drivers/usb/chipidea/core.c        |  8 ++++++--
 drivers/usb/chipidea/host.c        |  8 ++++++--
 include/linux/usb/chipidea.h       |  2 +-
 4 files changed, 33 insertions(+), 25 deletions(-)
drivers/usb/chipidea/ci_hdrc_msm.c +20 -20
index fe96df7b530c..316044dba0ac 100644
@@ -80,20 +80,33 @@ static const struct reset_control_ops ci_hdrc_msm_reset_ops = {
 	.reset = ci_hdrc_msm_por_reset,
 };
 
-static void ci_hdrc_msm_notify_event(struct ci_hdrc *ci, unsigned event)
+static int ci_hdrc_msm_notify_event(struct ci_hdrc *ci, unsigned event)
 {
 	struct device *dev = ci->dev->parent;
 	struct ci_hdrc_msm *msm_ci = dev_get_drvdata(dev);
+	int ret;
 
 	switch (event) {
 	case CI_HDRC_CONTROLLER_RESET_EVENT:
 		dev_dbg(dev, "CI_HDRC_CONTROLLER_RESET_EVENT received\n");
+
+		hw_phymode_configure(ci);
 		if (msm_ci->secondary_phy) {
 			u32 val = readl_relaxed(msm_ci->base + HS_PHY_SEC_CTRL);
 			val |= HS_PHY_DIG_CLAMP_N;
 			writel_relaxed(val, msm_ci->base + HS_PHY_SEC_CTRL);
 		}
 
+		ret = phy_init(ci->phy);
+		if (ret)
+			return ret;
+
+		ret = phy_power_on(ci->phy);
+		if (ret) {
+			phy_exit(ci->phy);
+			return ret;
+		}
+
 		/* use AHB transactor, allow posted data writes */
 		hw_write_id_reg(ci, HS_PHY_AHB_MODE, 0xffffffff, 0x8);
 
@@ -113,21 +126,18 @@ static void ci_hdrc_msm_notify_event(struct ci_hdrc *ci, unsigned event)
 				 HSPHY_SESS_VLD_CTRL);
 
 		}
-
-		usb_phy_init(ci->usb_phy);
 		break;
 	case CI_HDRC_CONTROLLER_STOPPED_EVENT:
 		dev_dbg(dev, "CI_HDRC_CONTROLLER_STOPPED_EVENT received\n");
-		/*
-		 * Put the phy in non-driving mode. Otherwise host
-		 * may not detect soft-disconnection.
-		 */
-		usb_phy_notify_disconnect(ci->usb_phy, USB_SPEED_UNKNOWN);
+		phy_power_off(ci->phy);
+		phy_exit(ci->phy);
 		break;
 	default:
 		dev_dbg(dev, "unknown ci_hdrc event\n");
 		break;
 	}
+
+	return 0;
 }
 
 static int ci_hdrc_msm_mux_phy(struct ci_hdrc_msm *ci,
@@ -167,7 +177,6 @@ static int ci_hdrc_msm_probe(struct platform_device *pdev)
 {
 	struct ci_hdrc_msm *ci;
 	struct platform_device *plat_ci;
-	struct usb_phy *phy;
 	struct clk *clk;
 	struct reset_control *reset;
 	struct resource *res;
@@ -181,21 +190,12 @@ static int ci_hdrc_msm_probe(struct platform_device *pdev)
 		return -ENOMEM;
 	platform_set_drvdata(pdev, ci);
 
-	/*
-	 * OTG(PHY) driver takes care of PHY initialization, clock management,
-	 * powering up VBUS, mapping of registers address space and power
-	 * management.
-	 */
-	phy = devm_usb_get_phy_by_phandle(&pdev->dev, "usb-phy", 0);
-	if (IS_ERR(phy))
-		return PTR_ERR(phy);
-
 	ci->pdata.name = "ci_hdrc_msm";
 	ci->pdata.capoffset = DEF_CAPOFFSET;
 	ci->pdata.flags	= CI_HDRC_REGS_SHARED | CI_HDRC_DISABLE_STREAMING |
-			  CI_HDRC_OVERRIDE_AHB_BURST;
+			  CI_HDRC_OVERRIDE_AHB_BURST |
+			  CI_HDRC_OVERRIDE_PHY_CONTROL;
 	ci->pdata.notify_event = ci_hdrc_msm_notify_event;
-	ci->pdata.usb_phy = phy;
 
 	reset = devm_reset_control_get(&pdev->dev, "core");
 	if (IS_ERR(reset))
drivers/usb/chipidea/core.c +6 -2
index d1ae9a03e0fa..fbef1c961572 100644
@@ -327,6 +327,7 @@ void hw_phymode_configure(struct ci_hdrc *ci)
 			hw_write(ci, OP_PORTSC, PORTSC_STS, PORTSC_STS);
 	}
 }
+EXPORT_SYMBOL_GPL(hw_phymode_configure);
 
 /**
  * _ci_usb_phy_init: initialize phy taking in account both phy and usb_phy
@@ -503,9 +504,12 @@ int hw_device_reset(struct ci_hdrc *ci)
 		return ret;
 	}
 
-	if (ci->platdata->notify_event)
-		ci->platdata->notify_event(ci,
+	if (ci->platdata->notify_event) {
+		ret = ci->platdata->notify_event(ci,
 			CI_HDRC_CONTROLLER_RESET_EVENT);
+		if (ret)
+			return ret;
+	}
 
 	/* USBMODE should be configured step by step */
 	hw_write(ci, OP_USBMODE, USBMODE_CM, USBMODE_CM_IDLE);
drivers/usb/chipidea/host.c +6 -2
index f036a9e39ced..bbfb9e62d49d 100644
@@ -90,8 +90,12 @@ static int ehci_ci_reset(struct usb_hcd *hcd)
 
 	ehci->need_io_watchdog = 0;
 
-	if (ci->platdata->notify_event)
-		ci->platdata->notify_event(ci, CI_HDRC_CONTROLLER_RESET_EVENT);
+	if (ci->platdata->notify_event) {
+		ret = ci->platdata->notify_event(ci,
+				CI_HDRC_CONTROLLER_RESET_EVENT);
+		if (ret)
+			return ret;
+	}
 
 	ci_platform_configure(ci);
 
include/linux/usb/chipidea.h +1 -1
index 7e3daa37cf60..c5fdfcf99828 100644
@@ -61,7 +61,7 @@ struct ci_hdrc_platform_data {
 	enum usb_dr_mode	dr_mode;
 #define CI_HDRC_CONTROLLER_RESET_EVENT		0
 #define CI_HDRC_CONTROLLER_STOPPED_EVENT	1
-	void	(*notify_event) (struct ci_hdrc *ci, unsigned event);
+	int	(*notify_event) (struct ci_hdrc *ci, unsigned event);
 	struct regulator	*reg_vbus;
 	struct usb_otg_caps	ci_otg_caps;
 	bool			tpl_support;
Signature · 1 line
2.10.0.297.gf6727b0
#41 lore raw

PATCH v5 21/23 usb: chipidea: msm: Be silent on probe defer errors

In reply to Stephen Boyd

If something fails in ci_hdrc_add_device() due to probe defer, we shouldn't print an error message. Be silent in this case as we'll try probe again later.

---
 drivers/usb/chipidea/ci_hdrc_msm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/chipidea/ci_hdrc_msm.c +2 -1
index 316044dba0ac..f1ede7909f54 100644
@@ -262,8 +262,9 @@ static int ci_hdrc_msm_probe(struct platform_device *pdev)
 	plat_ci = ci_hdrc_add_device(&pdev->dev, pdev->resource,
 				     pdev->num_resources, &ci->pdata);
 	if (IS_ERR(plat_ci)) {
-		dev_err(&pdev->dev, "ci_hdrc_add_device failed!\n");
 		ret = PTR_ERR(plat_ci);
+		if (ret != -EPROBE_DEFER)
+			dev_err(&pdev->dev, "ci_hdrc_add_device failed!\n");
 		goto err_mux;
 	}
 
Signature · 1 line
2.10.0.297.gf6727b0
#42 lore raw

PATCH v5 22/23 phy: Add support for Qualcomm's USB HSIC phy

In reply to Stephen Boyd

The HSIC USB controller on qcom SoCs has an integrated all digital phy controlled via the ULPI viewport.

---
 .../devicetree/bindings/phy/qcom,usb-hsic-phy.txt  |  65 +++++++++
 drivers/phy/Kconfig                                |   7 +
 drivers/phy/Makefile                               |   1 +
 drivers/phy/phy-qcom-usb-hsic.c                    | 160 +++++++++++++++++++++
 4 files changed, 233 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/qcom,usb-hsic-phy.txt
 create mode 100644 drivers/phy/phy-qcom-usb-hsic.c
Documentation/devicetree/bindings/phy/qcom,usb-hsic-phy.txt new file +65 -0
new file mode 100644
index 000000000000..3c7cb2be4b12
@@ -0,0 +1,65 @@
+Qualcomm's USB HSIC PHY
+
+PROPERTIES
+
+- compatible:
+    Usage: required
+    Value type: <string>
+    Definition: Should contain "qcom,usb-hsic-phy" and more specifically one of the
+		following:
+
+			"qcom,usb-hsic-phy-mdm9615"
+			"qcom,usb-hsic-phy-msm8974"
+
+- #phy-cells:
+    Usage: required
+    Value type: <u32>
+    Definition: Should contain 0
+
+- clocks:
+    Usage: required
+    Value type: <prop-encoded-array>
+    Definition: Should contain clock specifier for phy, calibration and
+                a calibration sleep clock
+
+- clock-names:
+    Usage: required
+    Value type: <stringlist>
+    Definition: Should contain "phy, "cal" and "cal_sleep"
+
+- pinctrl-names:
+    Usage: required
+    Value type: <stringlist>
+    Definition: Should contain "init" and "default" in that order
+
+- pinctrl-0:
+    Usage: required
+    Value type: <prop-encoded-array>
+    Definition: List of pinctrl settings to apply to keep HSIC pins in a glitch
+                free state
+
+- pinctrl-1:
+    Usage: required
+    Value type: <prop-encoded-array>
+    Definition: List of pinctrl settings to apply to mux out the HSIC pins
+
+EXAMPLE
+
+usb-controller {
+	ulpi {
+		phy {
+			compatible = "qcom,usb-hsic-phy-msm8974",
+				     "qcom,usb-hsic-phy";
+			#phy-cells = <0>;
+			pinctrl-names = "init", "default";
+			pinctrl-0 = <&hsic_sleep>;
+			pinctrl-1 = <&hsic_default>;
+			clocks = <&gcc GCC_USB_HSIC_CLK>,
+				 <&gcc GCC_USB_HSIC_IO_CAL_CLK>,
+				 <&gcc GCC_USB_HSIC_IO_CAL_SLEEP_CLK>;
+			clock-names = "phy", "cal", "cal_sleep";
+			assigned-clocks = <&gcc GCC_USB_HSIC_IO_CAL_CLK>;
+			assigned-clock-rates = <960000>;
+		};
+	};
+};
drivers/phy/Kconfig +7 -0
index fe00f9134d51..6bfc91a8ea3e 100644
@@ -453,6 +453,13 @@ config PHY_QCOM_UFS
 	help
 	  Support for UFS PHY on QCOM chipsets.
 
+config PHY_QCOM_USB_HSIC
+	tristate "Qualcomm USB HSIC ULPI PHY module"
+	depends on USB_ULPI_BUS
+	select GENERIC_PHY
+	help
+	  Support for the USB HSIC ULPI compliant PHY on QCOM chipsets.
+
 config PHY_TUSB1210
 	tristate "TI TUSB1210 ULPI PHY module"
 	depends on USB_ULPI_BUS
drivers/phy/Makefile +1 -0
index a534cf5be07d..914b843eac13 100644
@@ -54,6 +54,7 @@ obj-$(CONFIG_PHY_STIH41X_USB)		+= phy-stih41x-usb.o
 obj-$(CONFIG_PHY_QCOM_UFS) 	+= phy-qcom-ufs.o
 obj-$(CONFIG_PHY_QCOM_UFS) 	+= phy-qcom-ufs-qmp-20nm.o
 obj-$(CONFIG_PHY_QCOM_UFS) 	+= phy-qcom-ufs-qmp-14nm.o
+obj-$(CONFIG_PHY_QCOM_USB_HSIC) 	+= phy-qcom-usb-hsic.o
 obj-$(CONFIG_PHY_TUSB1210)		+= phy-tusb1210.o
 obj-$(CONFIG_PHY_BRCM_SATA)		+= phy-brcm-sata.o
 obj-$(CONFIG_PHY_PISTACHIO_USB)		+= phy-pistachio-usb.o
drivers/phy/phy-qcom-usb-hsic.c new file +160 -0

160 lines not on this page · raw message

Signature · 1 line
2.10.0.297.gf6727b0
#43 lore raw

PATCH v5 23/23 phy: Add support for Qualcomm's USB HS phy

In reply to Stephen Boyd

The high-speed phy on qcom SoCs is controlled via the ULPI viewport.

Cc Kishon Vijay Abraham I <[email protected]>
Cc Rob Herring <[email protected]>
---
 .../devicetree/bindings/phy/qcom,usb-hs-phy.txt    |  86 +++++++
 drivers/phy/Kconfig                                |   8 +
 drivers/phy/Makefile                               |   1 +
 drivers/phy/phy-qcom-usb-hs.c                      | 286 +++++++++++++++++++++
 4 files changed, 381 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/qcom,usb-hs-phy.txt
 create mode 100644 drivers/phy/phy-qcom-usb-hs.c
Documentation/devicetree/bindings/phy/qcom,usb-hs-phy.txt new file +86 -0
new file mode 100644
index 000000000000..ed994dbc9248
@@ -0,0 +1,86 @@
+Qualcomm's USB HS PHY
+
+PROPERTIES
+
+- compatible:
+    Usage: required
+    Value type: <string>
+    Definition: Should contain "qcom,usb-hs-phy" and more specifically one of the
+                following:
+
+                        "qcom,usb-hs-phy-apq8064"
+                        "qcom,usb-hs-phy-msm8916"
+                        "qcom,usb-hs-phy-msm8974"
+
+- #phy-cells:
+    Usage: required
+    Value type: <u32>
+    Definition: Should contain 0
+
+- clocks:
+    Usage: required
+    Value type: <prop-encoded-array>
+    Definition: Should contain clock specifier for the reference and sleep
+                clocks
+
+- clock-names:
+    Usage: required
+    Value type: <stringlist>
+    Definition: Should contain "ref" and "sleep" for the reference and sleep
+                clocks respectively
+
+- resets:
+    Usage: required
+    Value type: <prop-encoded-array>
+    Definition: Should contain the phy and POR resets
+
+- reset-names:
+    Usage: required
+    Value type: <stringlist>
+    Definition: Should contain "phy" and "por" for the phy and POR resets
+                respectively
+
+- v3p3-supply:
+    Usage: required
+    Value type: <phandle>
+    Definition: Should contain a reference to the 3.3V supply
+
+- v1p8-supply:
+    Usage: required
+    Value type: <phandle>
+    Definition: Should contain a reference to the 1.8V supply
+
+- extcon:
+    Usage: optional
+    Value type: <prop-encoded-array>
+    Definition: Should contain the vbus and ID extcons in the first and second
+                cells respectively
+
+- qcom,init-seq:
+    Usage: optional
+    Value type: <u8 array>
+    Definition: Should contain a sequence of ULPI address and value pairs to
+                program into the ULPI_EXT_VENDOR_SPECIFIC area. This is related
+                to Device Mode Eye Diagram test. The addresses are offsets
+		from the ULPI_EXT_VENDOR_SPECIFIC address, for example,
+		<0x1 0x53> would mean we should write the value 0x53 to address
+		0x81.
+
+EXAMPLE
+
+otg: usb-controller {
+	ulpi {
+		phy {
+			compatible = "qcom,usb-hs-phy-msm8974", "qcom,usb-hs-phy";
+			#phy-cells = <0>;
+			clocks = <&xo_board>, <&gcc GCC_USB2A_PHY_SLEEP_CLK>;
+			clock-names = "ref", "sleep";
+			resets = <&gcc GCC_USB2A_PHY_BCR>, <&otg 0>;
+			reset-names = "phy", "por";
+			v3p3-supply = <&pm8941_l24>;
+			v1p8-supply = <&pm8941_l6>;
+			extcon = <&smbb>, <&usb_id>;
+			qcom,init-seq = /bits/ 8 <0x1 0x63>;
+		};
+	};
+};
drivers/phy/Kconfig +8 -0
index 6bfc91a8ea3e..3fcfc5899b6d 100644
@@ -453,6 +453,14 @@ config PHY_QCOM_UFS
 	help
 	  Support for UFS PHY on QCOM chipsets.
 
+config PHY_QCOM_USB_HS
+	tristate "Qualcomm USB HS PHY module"
+	depends on USB_ULPI_BUS
+	select GENERIC_PHY
+	help
+	  Support for the USB high-speed ULPI compliant phy on Qualcomm
+	  chipsets.
+
 config PHY_QCOM_USB_HSIC
 	tristate "Qualcomm USB HSIC ULPI PHY module"
 	depends on USB_ULPI_BUS
drivers/phy/Makefile +1 -0
index 914b843eac13..df62074ded2f 100644
@@ -54,6 +54,7 @@ obj-$(CONFIG_PHY_STIH41X_USB)		+= phy-stih41x-usb.o
 obj-$(CONFIG_PHY_QCOM_UFS) 	+= phy-qcom-ufs.o
 obj-$(CONFIG_PHY_QCOM_UFS) 	+= phy-qcom-ufs-qmp-20nm.o
 obj-$(CONFIG_PHY_QCOM_UFS) 	+= phy-qcom-ufs-qmp-14nm.o
+obj-$(CONFIG_PHY_QCOM_USB_HS) 		+= phy-qcom-usb-hs.o
 obj-$(CONFIG_PHY_QCOM_USB_HSIC) 	+= phy-qcom-usb-hsic.o
 obj-$(CONFIG_PHY_TUSB1210)		+= phy-tusb1210.o
 obj-$(CONFIG_PHY_BRCM_SATA)		+= phy-brcm-sata.o
drivers/phy/phy-qcom-usb-hs.c new file +286 -0

286 lines not on this page · raw message

Signature · 1 line
2.10.0.297.gf6727b0
maintainer Acked-by on v5 23/23
#44 lore raw

Re: [PATCH v5 23/23] phy: Add support for Qualcomm's USB HS phy

Quoted 9 lines · Stephen Boyd

The high-speed phy on qcom SoCs is controlled via the ULPI viewport.

Cc Kishon Vijay Abraham I <[email protected]>
Cc Rob Herring <[email protected]>
---
 .../devicetree/bindings/phy/qcom,usb-hs-phy.txt    |  86 +++++++
Quoted 6 lines
 drivers/phy/Kconfig                                |   8 +
 drivers/phy/Makefile                               |   1 +
 drivers/phy/phy-qcom-usb-hs.c                      | 286 +++++++++++++++++++++
 4 files changed, 381 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/qcom,usb-hs-phy.txt
 create mode 100644 drivers/phy/phy-qcom-usb-hs.c
maintainer Acked-by on v5 23/23
#45 lore raw

Re: [PATCH v5 23/23] phy: Add support for Qualcomm's USB HS phy

In reply to Stephen Boyd
Quoted 9 lines · Stephen Boyd

The high-speed phy on qcom SoCs is controlled via the ULPI viewport.

Cc Kishon Vijay Abraham I <[email protected]>
Cc Rob Herring <[email protected]>
---
 .../devicetree/bindings/phy/qcom,usb-hs-phy.txt    |  86 +++++++
Quoted 6 lines
 drivers/phy/Kconfig                                |   8 +
 drivers/phy/Makefile                               |   1 +
 drivers/phy/phy-qcom-usb-hs.c                      | 286 +++++++++++++++++++++
 4 files changed, 381 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/qcom,usb-hs-phy.txt
 create mode 100644 drivers/phy/phy-qcom-usb-hs.c
#46 lore raw

Re: [PATCH v5 23/23] phy: Add support for Qualcomm's USB HS phy

In reply to Stephen Boyd

Quoting Stephen Boyd (2016-10-17 18:56:36)

drivers/phy/phy-qcom-usb-hs.c line 58

Quoted 11 lines
drivers/phy/phy-qcom-usb-hs.c new file +11 -0
+
+static int
+qcom_usb_hs_phy_vbus_notifier(struct notifier_block *nb, unsigned long event,
+                             void *ptr)
+{
+       struct qcom_usb_hs_phy *uphy;
+       int is_host;
+       u8 addr;
+
+       uphy = container_of(nb, struct qcom_usb_hs_phy, vbus_notify);
+       is_host = extcon_get_cable_state_(uphy->id_edev, EXTCON_USB_HOST);

Please don't apply this patch. This call now deadlocks on v4.9-rc1 because of how extcon_get_cable_state_() now grabs a lock that is already held here when we're inside the notifier. It's not really required that we grab the lock in extcon there, but this has exposed a flaw in the logic anyway. We don't know if the id pin is going to toggle before or after this function is called, so we should really keep track of both vbus and id state in this driver and then do the same ulpi writes from two different notifiers for both vbus and id pin. We would be duplicating work sometimes, but that's pretty much the best solution I can come up with. Otherwise it's racy.

#47 lore raw

Re: [PATCH v5 23/23] phy: Add support for Qualcomm's USB HS phy

Quoted 15 lines · Stephen Boyd

Quoting Stephen Boyd (2016-10-17 18:56:36)

drivers/phy/phy-qcom-usb-hs.c line 58

Quoted 11 lines
drivers/phy/phy-qcom-usb-hs.c new file +11 -0
+
+static int
+qcom_usb_hs_phy_vbus_notifier(struct notifier_block *nb, unsigned long event,
+                             void *ptr)
+{
+       struct qcom_usb_hs_phy *uphy;
+       int is_host;
+       u8 addr;
+
+       uphy = container_of(nb, struct qcom_usb_hs_phy, vbus_notify);
+       is_host = extcon_get_cable_state_(uphy->id_edev, EXTCON_USB_HOST);

Please don't apply this patch. This call now deadlocks on v4.9-rc1 because of how extcon_get_cable_state_() now grabs a lock that is

Quoted 9 lines

already held here when we're inside the notifier. It's not really required that we grab the lock in extcon there, but this has exposed a flaw in the logic anyway. We don't know if the id pin is going to toggle before or after this function is called, so we should really keep track of both vbus and id state in this driver and then do the same ulpi writes from two different notifiers for both vbus and id pin. We would be duplicating work sometimes, but that's pretty much the best solution I can come up with. Otherwise it's racy.

Why you need to care id status? If EXTCON_USB event has happened, and event is true, you can set, otherwise, it is clear operation, that's to say you may not need have id extcon phandle, do you think so?

Signature · 2 lines
Best Regards,
Peter Chen
#48 lore raw

PATCH v5 23/23 phy: Add support for Qualcomm's USB HS phy

Quoting Peter Chen (2016-10-20 19:20:30)

Quoted 26 lines · Stephen Boyd
Quoted 15 lines

Quoting Stephen Boyd (2016-10-17 18:56:36)

drivers/phy/phy-qcom-usb-hs.c line 58

Quoted 11 lines
drivers/phy/phy-qcom-usb-hs.c new file +11 -0
+
+static int
+qcom_usb_hs_phy_vbus_notifier(struct notifier_block *nb, unsigned long event,
+                             void *ptr)
+{
+       struct qcom_usb_hs_phy *uphy;
+       int is_host;
+       u8 addr;
+
+       uphy = container_of(nb, struct qcom_usb_hs_phy, vbus_notify);
+       is_host = extcon_get_cable_state_(uphy->id_edev, EXTCON_USB_HOST);

Please don't apply this patch. This call now deadlocks on v4.9-rc1 because of how extcon_get_cable_state_() now grabs a lock that is

Quoted 9 lines

already held here when we're inside the notifier. It's not really required that we grab the lock in extcon there, but this has exposed a flaw in the logic anyway. We don't know if the id pin is going to toggle before or after this function is called, so we should really keep track of both vbus and id state in this driver and then do the same ulpi writes from two different notifiers for both vbus and id pin. We would be duplicating work sometimes, but that's pretty much the best solution I can come up with. Otherwise it's racy.

Quoted 4 lines

Why you need to care id status? If EXTCON_USB event has happened, and event is true, you can set, otherwise, it is clear operation, that's to say you may not need have id extcon phandle, do you think so?

I need to add a comment to the code here because I forgot what was going on.

Either way, this code is pulling D+ up when we're in device mode. We don't want to do the pullup if we're a host, and vbus extcon only tells us if the cable is attached so we can't just rely on that one bit of information.

I suppose that's not really appropriate to do via extcon though in the phy driver though, so I'm thinking that it should be rewritten to use the phy_set_mode() feature of the phy framework. Basically, ci_udc_pullup() will call phy_set_mode() with PHY_MODE_USB_DEVICE or PHY_MODE_USB_HOST and then we can set or clear these bits in the ulpi register space. I think that will make things simpler here and things like soft-connect will work better. Sound good?

#49 lore raw

Re: [PATCH v5 23/23] phy: Add support for Qualcomm's USB HS phy

Quoted 40 lines · Stephen Boyd

Quoting Peter Chen (2016-10-20 19:20:30)

Quoted 26 lines · Stephen Boyd
Quoted 15 lines

Quoting Stephen Boyd (2016-10-17 18:56:36)

drivers/phy/phy-qcom-usb-hs.c line 58

Quoted 11 lines
drivers/phy/phy-qcom-usb-hs.c new file +11 -0
+
+static int
+qcom_usb_hs_phy_vbus_notifier(struct notifier_block *nb, unsigned long event,
+                             void *ptr)
+{
+       struct qcom_usb_hs_phy *uphy;
+       int is_host;
+       u8 addr;
+
+       uphy = container_of(nb, struct qcom_usb_hs_phy, vbus_notify);
+       is_host = extcon_get_cable_state_(uphy->id_edev, EXTCON_USB_HOST);

Please don't apply this patch. This call now deadlocks on v4.9-rc1 because of how extcon_get_cable_state_() now grabs a lock that is

Quoted 9 lines

already held here when we're inside the notifier. It's not really required that we grab the lock in extcon there, but this has exposed a flaw in the logic anyway. We don't know if the id pin is going to toggle before or after this function is called, so we should really keep track of both vbus and id state in this driver and then do the same ulpi writes from two different notifiers for both vbus and id pin. We would be duplicating work sometimes, but that's pretty much the best solution I can come up with. Otherwise it's racy.

Quoted 4 lines

Why you need to care id status? If EXTCON_USB event has happened, and event is true, you can set, otherwise, it is clear operation, that's to say you may not need have id extcon phandle, do you think so?

I need to add a comment to the code here because I forgot what was going on.

Either way, this code is pulling D+ up when we're in device mode. We don't want to do the pullup if we're a host, and vbus extcon only tells us if the cable is attached so we can't just rely on that one bit of information.

Quoted 7 lines

I suppose that's not really appropriate to do via extcon though in the phy driver though, so I'm thinking that it should be rewritten to use the phy_set_mode() feature of the phy framework. Basically, ci_udc_pullup() will call phy_set_mode() with PHY_MODE_USB_DEVICE or PHY_MODE_USB_HOST and then we can set or clear these bits in the ulpi register space. I think that will make things simpler here and things like soft-connect will work better. Sound good?

I agree with you, and you may notify controller role through phy_set_mode at the controller probe and role switch routine.

Signature · 2 lines
Best Regards,
Peter Chen
#50 lore raw
In reply to Stephen Boyd
Quoted 36 lines · Stephen Boyd

The state of USB ChipIdea support on Qualcomm's platforms is not great. The DT description of these devices requires up to three different nodes for what amounts to be the same hardware block, when there should really only be one. Furthermore, the "phy" driver that is in mainline (phy-msm-usb.c) duplicates the OTG state machine and touches the ci controller wrapper registers when it should really be focused on the phy and the ULPI accesses needed to get the phy working. There's also a slimmed down phy driver for the msm8916 platform, but really the phy hardware is the same as other MSMs, so we have two drivers doing pretty much the same thing. This leads to a situtaion where we have the chipidea core driver, the "phy" driver, and sometimes the ehci-msm.c driver operating the same device all at the same time with very little coordination. This just isn't very safe and is confusing from a driver perspective when trying to figure out who does what. Finally, there isn't any HSIC support on platforms like apq8074 so we should add that.

This patch series updates the ChipIdea driver and the MSM wrapper (ci_hdrc_msm.c) to properly handle the PHY and wrapper bits at the right times in the right places. To get there, we update the ChipIdea core to have support for the ULPI phy bus introduced by Heikki. Along the way we fix bugs with the extcon handling for peripheral and OTG mode controllers and move the parts of phy-usb-msm.c that are touching the CI controller wrapper into the wrapper driver (ci_hdrc_msm.c). Finally we add support for the HSIC phy based on the ULPI bus and rewrite the HS phy driver (phy-usb-msm.c) as a standard ULPI phy driver.

Once this series is accepted, we should be able to delete the phy-usb-msm.c, phy-qcom-8x16-usb.c, and ehci-msm.c drivers from the tree and use the ULPI based phy driver (which also lives in drivers/phy/ instead of drivers/usb/phy/) and the chipidea host core instead.

I've also sent separate patches for other minor pieces to make this all work. The full tree can be found here[2], hacks and all to get things working. I've tested this on the db410c, apq8074 dragonboard, and ifc6410 with configfs gadgets and otg cables.

Quoted 5 lines

Patches based on v4.8-rc1

Changes from v4:
* Picked up Acks from Rob
* Updated HS phy init sequence DT property to restrict it to offsets

I remembered that you got all my acks for chipidea patches, right? I did not check for this series.

Besides, the patch "gpu: Remove depends on RESET_CONTROLLER when not a provider" [1] still not be accepted, I need this patch to be merged first, then apply your chipidea part, otherwise, there is a building warning.

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

Peter

Quoted 111 lines

Changes from v3:
* Picked up Acks from Peter
* Updated extcon consolidation patch per Peter's comments
* Folded in simplification from Heikki for ULPI DT matching

Changes from v2:
* Added SoC specific compatibles in phy bindings
* Dropped AVVIS patch for OTG statemachine
* New patch to consolidate extcon handlers
* Picked up Acks from Peter
* Rebased onto v4.8-rc1
* Reworked ULPI OF code to look at vid == 0 instead of pid == 0
* Dropped ULPI bindings for vid and pid overrides

Changes from v1:
* Reworked ULPI device probing to keep using vendor/product ids that come from DT if needed and falls back to OF style match when product id is 0
* PHY init later patch was rejected so that moved to a quirk flag and the msm wrapper started managing the phy on/off
* Updated clk requirements for HSIC phy in binding doc
* Added optional clk in wrapper for "housekeeping" found on older qcom platforms
* Bug fix to OTGSC polling function
* Changed runtime PM patch to set as active instead of get/put

TODO:
* DMA fails on arm64 so we need something like [1] or [3] to make it work.
* The db410c needs a driver to toggle the onboard switch to connect the usb hub instead of micro port when the usb cable is disconnected. I've sent a patch set for this[4], which needs some further discussion/development.
* apq8064 platforms need a vbus regulator to really use otg and I haven't tried out the RPM based regulators yet
* The HSIC phy on the apq8074 dragonboard is connected to a usb4604 device which requires the i2c driver to probe and send an i2c sequence before the HSIC controller enumerates or HSIC doesn't work. Right now I have a hack to force the controller to probe defer once so that usb4604 probes first. This needs a more proper solution like having the DT describe a linkage between the controller and the usb device so we can enforce probe ordering.
* There are problems around the OTG switch still, due to how we handle extcon events that I'm working through

[1] https://lkml.org/lkml/2016/2/22/7
[2] https://git.linaro.org/people/stephen.boyd/linux.git/shortlog/refs/heads/usb-hsic-8074
[3] https://patchwork.kernel.org/patch/9319527/
[4] https://lkml.kernel.org/r/20160914014246.31847-1-stephen.boyd at linaro.org

Stephen Boyd (23):
of: device: Support loading a module with OF based modalias
of: device: Export of_device_{get_modalias,uvent_modalias} to modules
usb: ulpi: Support device discovery via DT
usb: chipidea: Only read/write OTGSC from one place
usb: chipidea: Handle extcon events properly
usb: chipidea: Add platform flag for wrapper phy management
usb: chipidea: Notify events when switching host mode
usb: chipidea: Remove locking in ci_udc_start()
usb: chipidea: Add support for ULPI PHY bus
usb: chipidea: Consolidate extcon notifiers
usb: chipidea: Emulate OTGSC interrupt enable path
usb: chipidea: msm: Mark device as runtime pm active
usb: chipidea: msm: Rely on core to override AHBBURST
usb: chipidea: msm: Use hw_write_id_reg() instead of writel
usb: chipidea: msm: Add proper clk and reset support
usb: chipidea: msm: Mux over secondary phy at the right time
usb: chipidea: msm: Restore wrapper settings after reset
usb: chipidea: msm: Make platform data driver local instead of global
usb: chipidea: msm: Add reset controller for PHY POR bit
usb: chipidea: msm: Handle phy power states
usb: chipidea: msm: Be silent on probe defer errors
phy: Add support for Qualcomm's USB HSIC phy
phy: Add support for Qualcomm's USB HS phy

 .../devicetree/bindings/phy/qcom,usb-hs-phy.txt    |  86 +++++++
 .../devicetree/bindings/phy/qcom,usb-hsic-phy.txt  |  65 +++++
 Documentation/devicetree/bindings/usb/ulpi.txt     |  20 ++
 drivers/of/device.c                                |  25 ++
 drivers/phy/Kconfig                                |  15 ++
 drivers/phy/Makefile                               |   2 +
 drivers/phy/phy-qcom-usb-hs.c                      | 286 +++++++++++++++++++++
 drivers/phy/phy-qcom-usb-hsic.c                    | 160 ++++++++++++
 drivers/usb/chipidea/Kconfig                       |   8 +
 drivers/usb/chipidea/Makefile                      |   1 +
 drivers/usb/chipidea/ci.h                          |  24 +-
 drivers/usb/chipidea/ci_hdrc_msm.c                 | 280 +++++++++++++++++---
 drivers/usb/chipidea/core.c                        | 135 +++++-----
 drivers/usb/chipidea/host.c                        |  10 +
 drivers/usb/chipidea/otg.c                         | 105 +++++++-
 drivers/usb/chipidea/udc.c                         |   3 -
 drivers/usb/chipidea/ulpi.c                        | 113 ++++++++
 drivers/usb/common/ulpi.c                          |  79 +++++-
 include/linux/of_device.h                          |   6 +
 include/linux/usb/chipidea.h                       |   9 +-
 20 files changed, 1292 insertions(+), 140 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/phy/qcom,usb-hs-phy.txt
 create mode 100644 Documentation/devicetree/bindings/phy/qcom,usb-hsic-phy.txt
 create mode 100644 Documentation/devicetree/bindings/usb/ulpi.txt
 create mode 100644 drivers/phy/phy-qcom-usb-hs.c
 create mode 100644 drivers/phy/phy-qcom-usb-hsic.c
 create mode 100644 drivers/usb/chipidea/ulpi.c
Signature · 7 lines
2.10.0.297.gf6727b0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Signature · 2 lines
Best Regards,
Peter Chen
#51 lore raw

v5 cover Support qcom's HSIC USB and rewrite USB2 HS support

Quoting Peter Chen (2016-10-18 02:31:40)

Quoted 7 lines · Stephen Boyd
Quoted 6 lines

I've also sent separate patches for other minor pieces to make this all work. The full tree can be found here[2], hacks and all to get things working. I've tested this on the db410c, apq8074 dragonboard, and ifc6410 with configfs gadgets and otg cables.

Patches based on v4.8-rc1

Oops should be v4.9-rc1 here.

Quoted 7 lines
Quoted 4 lines

Changes from v4:
* Picked up Acks from Rob
* Updated HS phy init sequence DT property to restrict it to offsets

I remembered that you got all my acks for chipidea patches, right? I did not check for this series.

Sorry I've added in one more patch

usb: chipidea: Emulate OTGSC interrupt enable path

to fix extcon interrupt emulation even further.

Quoted 7 lines

Besides, the patch "gpu: Remove depends on RESET_CONTROLLER when not a provider" [1] still not be accepted, I need this patch to be merged first, then apply your chipidea part, otherwise, there is a building warning.

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

Yes, I'm going to resend that patch now. I hope that David will apply it for -rc2.

#52 lore raw
Quoted 31 lines · Stephen Boyd

Quoting Peter Chen (2016-10-18 02:31:40)

Quoted 7 lines · Stephen Boyd
Quoted 6 lines

I've also sent separate patches for other minor pieces to make this all work. The full tree can be found here[2], hacks and all to get things working. I've tested this on the db410c, apq8074 dragonboard, and ifc6410 with configfs gadgets and otg cables.

Patches based on v4.8-rc1

Oops should be v4.9-rc1 here.

Quoted 7 lines
Quoted 4 lines

Changes from v4:
* Picked up Acks from Rob
* Updated HS phy init sequence DT property to restrict it to offsets

I remembered that you got all my acks for chipidea patches, right? I did not check for this series.

Sorry I've added in one more patch

usb: chipidea: Emulate OTGSC interrupt enable path

to fix extcon interrupt emulation even further.

Quoted 6 lines

Besides, the patch "gpu: Remove depends on RESET_CONTROLLER when not a provider" [1] still not be accepted, I need this patch to be merged first, then apply your chipidea part, otherwise, there is a building warning.

Quoted 4 lines
Quoted 1 line

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

Yes, I'm going to resend that patch now. I hope that David will apply it for -rc2.

Stephen, just a mind. I have rebased Greg's usb-next tree (v4.9-rc3 on it), your GPU fix is still not there.

Signature · 2 lines
Best Regards,
Peter Chen
#53 lore raw

v5 cover Support qcom's HSIC USB and rewrite USB2 HS support

Quoting Peter Chen (2016-11-10 23:40:17)

Quoted 32 lines · Stephen Boyd
Quoted 31 lines

Quoting Peter Chen (2016-10-18 02:31:40)

Quoted 7 lines · Stephen Boyd
Quoted 6 lines

I've also sent separate patches for other minor pieces to make this all work. The full tree can be found here[2], hacks and all to get things working. I've tested this on the db410c, apq8074 dragonboard, and ifc6410 with configfs gadgets and otg cables.

Patches based on v4.8-rc1

Oops should be v4.9-rc1 here.

Quoted 7 lines
Quoted 4 lines

Changes from v4:
* Picked up Acks from Rob
* Updated HS phy init sequence DT property to restrict it to offsets

I remembered that you got all my acks for chipidea patches, right? I did not check for this series.

Sorry I've added in one more patch

usb: chipidea: Emulate OTGSC interrupt enable path

to fix extcon interrupt emulation even further.

Quoted 6 lines

Besides, the patch "gpu: Remove depends on RESET_CONTROLLER when not a provider" [1] still not be accepted, I need this patch to be merged first, then apply your chipidea part, otherwise, there is a building warning.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

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

Yes, I'm going to resend that patch now. I hope that David will apply it for -rc2.

Stephen, just a mind. I have rebased Greg's usb-next tree (v4.9-rc3 on it), your GPU fix is still not there.

It looks like the patch is in drm-misc. I think they're going to hold off on merging it until the next merge window though. fb80016af071 is the commit in drm-misc tree and in linux-next. I'm not sure anything can be done here besides a cross tree merge or ignore the warning?