Skip to contentSkip to conversation

chipidea/imx: add otg support and some bug fix

PATCH New Richard Zhao 8 participants 39 messages Aug 28, 2012 – Sep 19, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover chipidea/imx: add otg support and some bug fix

The patch set is tested on imx6q_sabrelite board.

The patch can also be found at
https://github.com/riczhao/kernel-imx/commits/topics/usb-driver

For test which merged platform patches:
https://github.com/riczhao/kernel-imx/commits/topics/usb-test

Changes since v1:
- move usbmisc as the other patch series.
- remove regulater_disable and old comments in ci13xxx_imx.

Richard Zhao (11):
USB: chipidea: imx: add pinctrl support
USB: chipidea: delay 2ms before read ID status at probe time
USB: chipidea: move OTGSC_IDIS clearing from ci_role_work to irq
handler
USB: chipidea: clear gadget struct at udc_start fail path
USB: chipidea: don't let probe fail if otg controller start one role
failed
USB: mxs-phy: add basic otg support
USB: chipidea: add vbus detect for udc
USB: chipidea: convert to use devm_request_irq
USB: chipidea: add -DDEBUG if CONFIG_USB_CHIPIDEA_DEBUG
USB: chipidea: add set_vbus_power support
USB: chipidea: re-order irq handling to avoid unhandled irq

 drivers/usb/chipidea/Makefile      |    2 ++
 drivers/usb/chipidea/ci.h          |    1 +
 drivers/usb/chipidea/ci13xxx_imx.c |   51 +++++++++++++++++++++++-------------
 drivers/usb/chipidea/core.c        |   36 +++++++++++++++----------
 drivers/usb/chipidea/host.c        |    8 ++++++
 drivers/usb/chipidea/udc.c         |   40 +++++++++++++++++++++++++++-
 drivers/usb/otg/mxs-phy.c          |   21 +++++++++++++++
 include/linux/usb/chipidea.h       |    2 ++
 8 files changed, 128 insertions(+), 33 deletions(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v2 1/11 USB: chipidea: imx: add pinctrl support

Some controllers may not need to setup pinctrl, so we don't fail the probe if pinctrl get/select failed.

---
 drivers/usb/chipidea/ci13xxx_imx.c |    7 +++++++
 1 file changed, 7 insertions(+)
drivers/usb/chipidea/ci13xxx_imx.c +7 -0
index 96ac67b..0f5ca4b 100644
@@ -20,6 +20,7 @@
 #include <linux/usb/chipidea.h>
 #include <linux/clk.h>
 #include <linux/regulator/consumer.h>
+#include <linux/pinctrl/consumer.h>
 
 #include "ci.h"
 #include "ci13xxx_imx.h"
@@ -99,6 +100,7 @@ static int __devinit ci13xxx_imx_probe(struct platform_device *pdev)
 	struct device_node *phy_np;
 	struct resource *res;
 	struct regulator *reg_vbus;
+	struct pinctrl *pinctrl;
 	int ret;
 
 	if (of_find_property(pdev->dev.of_node, "fsl,usbmisc", NULL)
@@ -117,6 +119,11 @@ static int __devinit ci13xxx_imx_probe(struct platform_device *pdev)
 		return -ENOENT;
 	}
 
+	pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
+	if (IS_ERR(pinctrl))
+		dev_warn(&pdev->dev, "pinctrl get/select failed, err=%ld\n",
+			PTR_ERR(pinctrl));
+
 	data->clk = devm_clk_get(&pdev->dev, NULL);
 	if (IS_ERR(data->clk)) {
 		dev_err(&pdev->dev,
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v2 2/11 USB: chipidea: delay 2ms before read ID status at probe time

In reply to Richard Zhao

The ID pin needs 1ms debounce time, event at probe time. We delay 2ms for safe.

---
 drivers/usb/chipidea/core.c |    2 ++
 1 file changed, 2 insertions(+)
drivers/usb/chipidea/core.c +2 -0
index 1083585..3c3ed77 100644
@@ -462,6 +462,8 @@ static int __devinit ci_hdrc_probe(struct platform_device *pdev)
 
 	if (ci->roles[CI_ROLE_HOST] && ci->roles[CI_ROLE_GADGET]) {
 		ci->is_otg = true;
+		/* ID pin needs 1ms debouce time, we delay 2ms for safe */
+		mdelay(2);
 		ci->role = ci_otg_role(ci);
 	} else {
 		ci->role = ci->roles[CI_ROLE_HOST]
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH v2 3/11 USB: chipidea: move OTGSC_IDIS clearing from ci_role_work to irq handler

In reply to Richard Zhao

OTGSC_IDIS must be cleared in irq handler to avoid re-queue the work.

---
 drivers/usb/chipidea/core.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/usb/chipidea/core.c +1 -2
index 3c3ed77..19ef324 100644
@@ -273,8 +273,6 @@ static void ci_role_work(struct work_struct *work)
 	struct ci13xxx *ci = container_of(work, struct ci13xxx, work);
 	enum ci_role role = ci_otg_role(ci);
 
-	hw_write(ci, OP_OTGSC, OTGSC_IDIS, OTGSC_IDIS);
-
 	if (role != ci->role) {
 		dev_dbg(ci->dev, "switching from %s to %s\n",
 			ci_role(ci)->name, ci->roles[role]->name);
@@ -325,6 +323,7 @@ static irqreturn_t ci_irq(int irq, void *data)
 		u32 sts = hw_read(ci, OP_OTGSC, ~0);
 
 		if (sts & OTGSC_IDIS) {
+			hw_write(ci, OP_OTGSC, OTGSC_IDIS, OTGSC_IDIS);
 			queue_work(ci->wq, &ci->work);
 			ret = IRQ_HANDLED;
 		}
Signature · 1 line
1.7.9.5
#4 lore raw

PATCH v2 4/11 USB: chipidea: clear gadget struct at udc_start fail path

In reply to Richard Zhao

States in gadget are not needed any more, set it to zero.

---
 drivers/usb/chipidea/udc.c |    1 +
 1 file changed, 1 insertion(+)
drivers/usb/chipidea/udc.c +1 -0
index c7a032a..9fb6394 100644
@@ -1746,6 +1746,7 @@ free_pools:
 	dma_pool_destroy(ci->td_pool);
 free_qh_pool:
 	dma_pool_destroy(ci->qh_pool);
+	memset(&ci->gadget, 0, sizeof(ci->gadget));
 	return retval;
 }
 
Signature · 1 line
1.7.9.5
#5 lore raw

PATCH v2 4/11 USB: chipidea: clear gadget struct at udc_start fail path

Quoted 1 line · Richard Zhao

States in gadget are not needed any more, set it to zero.

It's generally a good practice to mention in the commit message what is it that you are fixing with this patch.

Quoted 10 lines
---
 drivers/usb/chipidea/udc.c |    1 +
 1 file changed, 1 insertion(+)
drivers/usb/chipidea/udc.c +0 -0
index c7a032a..9fb6394 100644

drivers/usb/chipidea/udc.c free_pools: · line 1749

Quoted 4 lines
drivers/usb/chipidea/udc.c +1 -0
@@ -1746,6 +1746,7 @@ free_pools:
 	dma_pool_destroy(ci->td_pool);
 free_qh_pool:
 	dma_pool_destroy(ci->qh_pool);
+	memset(&ci->gadget, 0, sizeof(ci->gadget));

I understand that you're probably hitting "kobject already initialized" warning here, but I think the real problem is that this function gets called twice and fails the first time. Why does that happen?

In any case, please elaborate on the problem.

Regards,
--
Alex

#6 lore raw

PATCH v2 4/11 USB: chipidea: clear gadget struct at udc_start fail path

Quoted 6 lines · Alexander Shishkin
Quoted 1 line · Richard Zhao

States in gadget are not needed any more, set it to zero.

It's generally a good practice to mention in the commit message what is it that you are fixing with this patch.

It fixes the following dump if udc_start register gadget->dev but fail the start process:
kobject (bf8330a0): tried to init an initialized object, something is seriously wrong. [<80011d90>] (dump_backtrace+0x0/0x10c) from [<804b65ac>] (dump_stack+0x18/0x1c) [<804b6594>] (dump_stack+0x0/0x1c) from [<80247d98>] (kobject_init+0x7c/0x9c) [<80247d1c>] (kobject_init+0x0/0x9c) from [<802a3870>] (device_initialize+0x28/0x70) [<802a3848>] (device_initialize+0x0/0x70) from [<802a4798>] (device_register+0x14/0x20) [<802a4784>] (device_register+0x0/0x20) from [<80359a70>] (udc_start+0x180/0x2c8) [<803598f0>] (udc_start+0x0/0x2c8) from [<80356e9c>] (ci_role_work+0xc8/0xec) [<80356dd4>] (ci_role_work+0x0/0xec) from [<8003a8a0>] (process_one_work+0x158/0x474) [<8003a748>] (process_one_work+0x0/0x474) from [<8003af6c>] (worker_thread+0x140/0x3b4) [<8003ae2c>] (worker_thread+0x0/0x3b4) from [<8003fe60>] (kthread+0x90/0x9c) [<8003fdd0>] (kthread+0x0/0x9c) from [<8002774c>] (do_exit+0x0/0x350)

Quoted 6 lines
Quoted 6 lines
---
 drivers/usb/chipidea/udc.c |    1 +
 1 file changed, 1 insertion(+)
Quoted 13 lines

drivers/usb/chipidea/udc.c free_pools: · line 1749

Quoted 9 lines
drivers/usb/chipidea/udc.c +1 -0
index c7a032a..9fb6394 100644
@@ -1746,6 +1746,7 @@ free_pools:
 	dma_pool_destroy(ci->td_pool);
 free_qh_pool:
 	dma_pool_destroy(ci->qh_pool);
+	memset(&ci->gadget, 0, sizeof(ci->gadget));

I understand that you're probably hitting "kobject already initialized" warning here, but I think the real problem is that this function gets called twice and fails the first time. Why does that happen?

I saw the dump at early stage of adding imx otg support, when there's things not ready. I think it's less important why udc_start fail, because no one enable imx otg before. It's important when it fails, the dump shows up.

Thanks
Richard

Quoted 7 lines

In any case, please elaborate on the problem.

Regards,
--
Alex

#7 lore raw

PATCH v2 4/11 USB: chipidea: clear gadget struct at udc_start fail path

Quoted 39 lines · Richard Zhao
Quoted 6 lines · Alexander Shishkin
Quoted 1 line · Richard Zhao

States in gadget are not needed any more, set it to zero.

It's generally a good practice to mention in the commit message what is it that you are fixing with this patch.

It fixes the following dump if udc_start register gadget->dev but fail the start process:
kobject (bf8330a0): tried to init an initialized object, something is seriously wrong. [<80011d90>] (dump_backtrace+0x0/0x10c) from [<804b65ac>] (dump_stack+0x18/0x1c) [<804b6594>] (dump_stack+0x0/0x1c) from [<80247d98>] (kobject_init+0x7c/0x9c) [<80247d1c>] (kobject_init+0x0/0x9c) from [<802a3870>] (device_initialize+0x28/0x70) [<802a3848>] (device_initialize+0x0/0x70) from [<802a4798>] (device_register+0x14/0x20) [<802a4784>] (device_register+0x0/0x20) from [<80359a70>] (udc_start+0x180/0x2c8) [<803598f0>] (udc_start+0x0/0x2c8) from [<80356e9c>] (ci_role_work+0xc8/0xec) [<80356dd4>] (ci_role_work+0x0/0xec) from [<8003a8a0>] (process_one_work+0x158/0x474) [<8003a748>] (process_one_work+0x0/0x474) from [<8003af6c>] (worker_thread+0x140/0x3b4) [<8003ae2c>] (worker_thread+0x0/0x3b4) from [<8003fe60>] (kthread+0x90/0x9c) [<8003fdd0>] (kthread+0x0/0x9c) from [<8002774c>] (do_exit+0x0/0x350)

Quoted 6 lines
Quoted 6 lines
---
 drivers/usb/chipidea/udc.c |    1 +
 1 file changed, 1 insertion(+)
Quoted 13 lines

drivers/usb/chipidea/udc.c free_pools: · line 1749

Quoted 9 lines
drivers/usb/chipidea/udc.c +1 -0
index c7a032a..9fb6394 100644
@@ -1746,6 +1746,7 @@ free_pools:
 	dma_pool_destroy(ci->td_pool);
 free_qh_pool:
 	dma_pool_destroy(ci->qh_pool);
+	memset(&ci->gadget, 0, sizeof(ci->gadget));

I understand that you're probably hitting "kobject already initialized" warning here, but I think the real problem is that this function gets called twice and fails the first time. Why does that happen?

Quoted 4 lines

I saw the dump at early stage of adding imx otg support, when there's things not ready. I think it's less important why udc_start fail, because no one enable imx otg before. It's important when it fails, the dump shows up.

I'd prefer that whenever udc_start() fails it doesn't go unnoticed, except probably for the cases when it fails due to transceiver not being ready at the probe time, which needs to be handled separately.

Regards,
--
Alex

#8 lore raw

PATCH v2 4/11 USB: chipidea: clear gadget struct at udc_start fail path

Quoted 41 lines · Alexander Shishkin
Quoted 39 lines · Richard Zhao
Quoted 6 lines · Alexander Shishkin
Quoted 1 line · Richard Zhao

States in gadget are not needed any more, set it to zero.

It's generally a good practice to mention in the commit message what is it that you are fixing with this patch.

It fixes the following dump if udc_start register gadget->dev but fail the start process:
kobject (bf8330a0): tried to init an initialized object, something is seriously wrong. [<80011d90>] (dump_backtrace+0x0/0x10c) from [<804b65ac>] (dump_stack+0x18/0x1c) [<804b6594>] (dump_stack+0x0/0x1c) from [<80247d98>] (kobject_init+0x7c/0x9c) [<80247d1c>] (kobject_init+0x0/0x9c) from [<802a3870>] (device_initialize+0x28/0x70) [<802a3848>] (device_initialize+0x0/0x70) from [<802a4798>] (device_register+0x14/0x20) [<802a4784>] (device_register+0x0/0x20) from [<80359a70>] (udc_start+0x180/0x2c8) [<803598f0>] (udc_start+0x0/0x2c8) from [<80356e9c>] (ci_role_work+0xc8/0xec) [<80356dd4>] (ci_role_work+0x0/0xec) from [<8003a8a0>] (process_one_work+0x158/0x474) [<8003a748>] (process_one_work+0x0/0x474) from [<8003af6c>] (worker_thread+0x140/0x3b4) [<8003ae2c>] (worker_thread+0x0/0x3b4) from [<8003fe60>] (kthread+0x90/0x9c) [<8003fdd0>] (kthread+0x0/0x9c) from [<8002774c>] (do_exit+0x0/0x350)

Quoted 19 lines
Quoted 11 lines
---
 drivers/usb/chipidea/udc.c |    1 +
 1 file changed, 1 insertion(+)
drivers/usb/chipidea/udc.c +0 -0
index c7a032a..9fb6394 100644

drivers/usb/chipidea/udc.c free_pools: · line 1749

Quoted 4 lines
drivers/usb/chipidea/udc.c +1 -0
@@ -1746,6 +1746,7 @@ free_pools:
 	dma_pool_destroy(ci->td_pool);
 free_qh_pool:
 	dma_pool_destroy(ci->qh_pool);
+	memset(&ci->gadget, 0, sizeof(ci->gadget));

I understand that you're probably hitting "kobject already initialized" warning here, but I think the real problem is that this function gets called twice and fails the first time. Why does that happen?

Quoted 8 lines
Quoted 4 lines

I saw the dump at early stage of adding imx otg support, when there's things not ready. I think it's less important why udc_start fail, because no one enable imx otg before. It's important when it fails, the dump shows up.

I'd prefer that whenever udc_start() fails it doesn't go unnoticed, except probably for the cases when it fails due to transceiver not being ready at the probe time, which needs to be handled separately.

Is it related to the patch? The patch is logically right that reset the status, agree?

Thanks
Richard

Quoted 5 lines

Regards,
--
Alex

#9 lore raw

PATCH v2 4/11 USB: chipidea: clear gadget struct at udc_start fail path

Quoted 47 lines · Richard Zhao
Quoted 46 lines · Alexander Shishkin
Quoted 43 lines · Richard Zhao
Quoted 6 lines · Alexander Shishkin
Quoted 1 line · Richard Zhao

States in gadget are not needed any more, set it to zero.

It's generally a good practice to mention in the commit message what is it that you are fixing with this patch.

It fixes the following dump if udc_start register gadget->dev but fail the start process:
kobject (bf8330a0): tried to init an initialized object, something is seriously wrong. [<80011d90>] (dump_backtrace+0x0/0x10c) from [<804b65ac>] (dump_stack+0x18/0x1c) [<804b6594>] (dump_stack+0x0/0x1c) from [<80247d98>] (kobject_init+0x7c/0x9c) [<80247d1c>] (kobject_init+0x0/0x9c) from [<802a3870>] (device_initialize+0x28/0x70) [<802a3848>] (device_initialize+0x0/0x70) from [<802a4798>] (device_register+0x14/0x20) [<802a4784>] (device_register+0x0/0x20) from [<80359a70>] (udc_start+0x180/0x2c8) [<803598f0>] (udc_start+0x0/0x2c8) from [<80356e9c>] (ci_role_work+0xc8/0xec) [<80356dd4>] (ci_role_work+0x0/0xec) from [<8003a8a0>] (process_one_work+0x158/0x474) [<8003a748>] (process_one_work+0x0/0x474) from [<8003af6c>] (worker_thread+0x140/0x3b4) [<8003ae2c>] (worker_thread+0x0/0x3b4) from [<8003fe60>] (kthread+0x90/0x9c) [<8003fdd0>] (kthread+0x0/0x9c) from [<8002774c>] (do_exit+0x0/0x350)

Quoted 6 lines
Quoted 6 lines
---
 drivers/usb/chipidea/udc.c |    1 +
 1 file changed, 1 insertion(+)
Quoted 13 lines

drivers/usb/chipidea/udc.c free_pools: · line 1749

Quoted 9 lines
drivers/usb/chipidea/udc.c +1 -0
index c7a032a..9fb6394 100644
@@ -1746,6 +1746,7 @@ free_pools:
 	dma_pool_destroy(ci->td_pool);
 free_qh_pool:
 	dma_pool_destroy(ci->qh_pool);
+	memset(&ci->gadget, 0, sizeof(ci->gadget));

I understand that you're probably hitting "kobject already initialized" warning here, but I think the real problem is that this function gets called twice and fails the first time. Why does that happen?

I saw the dump at early stage of adding imx otg support, when there's things not ready. I think it's less important why udc_start fail, because no one enable imx otg before. It's important when it fails, the dump shows up.

Quoted 5 lines
Quoted 3 lines

I'd prefer that whenever udc_start() fails it doesn't go unnoticed, except probably for the cases when it fails due to transceiver not being ready at the probe time, which needs to be handled separately.

Is it related to the patch? The patch is logically right that reset the status, agree?

No. This warning means that we have called udc_start() once, failed (thus didn't call udc_stop()) due to some unknown reason, and called it again at a later point in time. This -- failing for unknown reason -- should not happen. If it does, we should fix the reason, not paper over the warning that is telling us that something is wrong.

If we decide that we want to allow udc_start to fail for *certain* reasons, we should do it explicitly, not by shutting up all warnings for good.

Regards,
--
Alex

#10 lore raw

PATCH v2 4/11 USB: chipidea: clear gadget struct at udc_start fail path

Quoted 52 lines · Alexander Shishkin
Quoted 50 lines · Richard Zhao
Quoted 49 lines · Alexander Shishkin
Quoted 39 lines · Richard Zhao
Quoted 6 lines · Alexander Shishkin
Quoted 1 line · Richard Zhao

States in gadget are not needed any more, set it to zero.

It's generally a good practice to mention in the commit message what is it that you are fixing with this patch.

It fixes the following dump if udc_start register gadget->dev but fail the start process:
kobject (bf8330a0): tried to init an initialized object, something is seriously wrong. [<80011d90>] (dump_backtrace+0x0/0x10c) from [<804b65ac>] (dump_stack+0x18/0x1c) [<804b6594>] (dump_stack+0x0/0x1c) from [<80247d98>] (kobject_init+0x7c/0x9c) [<80247d1c>] (kobject_init+0x0/0x9c) from [<802a3870>] (device_initialize+0x28/0x70) [<802a3848>] (device_initialize+0x0/0x70) from [<802a4798>] (device_register+0x14/0x20) [<802a4784>] (device_register+0x0/0x20) from [<80359a70>] (udc_start+0x180/0x2c8) [<803598f0>] (udc_start+0x0/0x2c8) from [<80356e9c>] (ci_role_work+0xc8/0xec) [<80356dd4>] (ci_role_work+0x0/0xec) from [<8003a8a0>] (process_one_work+0x158/0x474) [<8003a748>] (process_one_work+0x0/0x474) from [<8003af6c>] (worker_thread+0x140/0x3b4) [<8003ae2c>] (worker_thread+0x0/0x3b4) from [<8003fe60>] (kthread+0x90/0x9c) [<8003fdd0>] (kthread+0x0/0x9c) from [<8002774c>] (do_exit+0x0/0x350)

Quoted 6 lines
Quoted 6 lines
---
 drivers/usb/chipidea/udc.c |    1 +
 1 file changed, 1 insertion(+)
Quoted 13 lines

drivers/usb/chipidea/udc.c free_pools: · line 1749

Quoted 9 lines
drivers/usb/chipidea/udc.c +1 -0
index c7a032a..9fb6394 100644
@@ -1746,6 +1746,7 @@ free_pools:
 	dma_pool_destroy(ci->td_pool);
 free_qh_pool:
 	dma_pool_destroy(ci->qh_pool);
+	memset(&ci->gadget, 0, sizeof(ci->gadget));

I understand that you're probably hitting "kobject already initialized" warning here, but I think the real problem is that this function gets called twice and fails the first time. Why does that happen?

Quoted 4 lines

I saw the dump at early stage of adding imx otg support, when there's things not ready. I think it's less important why udc_start fail, because no one enable imx otg before. It's important when it fails, the dump shows up.

I'd prefer that whenever udc_start() fails it doesn't go unnoticed, except probably for the cases when it fails due to transceiver not being ready at the probe time, which needs to be handled separately.

Quoted 6 lines
Quoted 2 lines

Is it related to the patch? The patch is logically right that reset the status, agree?

No. This warning means that we have called udc_start() once, failed (thus didn't call udc_stop()) due to some unknown reason, and called it again at a later point in time.

If role start failed, it may have its own error message. Why do we use such dump message to tell something wrong? And once the role start failed, it also prevent re-trying if ID pin switch to the role again. If you think we don't need the retrying, it's ok to drop this patch.

Thanks
Richard

Quoted 12 lines

This -- failing for unknown reason --
should not happen. If it does, we should fix the reason, not paper over the warning that is telling us that something is wrong.

If we decide that we want to allow udc_start to fail for *certain* reasons, we should do it explicitly, not by shutting up all warnings for good.

Regards,
--
Alex

#11 lore raw

PATCH v2 5/11 USB: chipidea: don't let probe fail if otg controller start one role failed

In reply to Richard Zhao

One role failed, but the other role will possiblly still work. For example, when udc start failed, if plug in a host device, it works.

---
 drivers/usb/chipidea/core.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/usb/chipidea/core.c +5 -2
index 19ef324..8fd390a 100644
@@ -473,8 +473,11 @@ static int __devinit ci_hdrc_probe(struct platform_device *pdev)
 	ret = ci_role_start(ci, ci->role);
 	if (ret) {
 		dev_err(dev, "can't start %s role\n", ci_role(ci)->name);
-		ret = -ENODEV;
-		goto rm_wq;
+		ci->role = CI_ROLE_END;
+		if (!ci->is_otg) {
+			ret = -ENODEV;
+			goto rm_wq;
+		}
 	}
 
 	platform_set_drvdata(pdev, ci);
Signature · 1 line
1.7.9.5
#12 lore raw

PATCH v2 5/11 USB: chipidea: don't let probe fail if otg controller start one role failed

Quoted 3 lines · Richard Zhao

One role failed, but the other role will possiblly still work. For example, when udc start failed, if plug in a host device, it works.

If you're a host device, ci->role should be HOST at this point and ci_role_start() shouldn't fail. If ci->role is detected wrongly, the role detection must be fixed. If ci_role_start() fails for host, but it still works when it's called again after the id pin change is detected, again, the problem is elsewhere.

Quoted 11 lines
---
 drivers/usb/chipidea/core.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/usb/chipidea/core.c +0 -0
index 19ef324..8fd390a 100644

drivers/usb/chipidea/core.c static int __devinit ci_hdrc_probe(struct platform_device *pdev) · line 476

Quoted 6 lines
drivers/usb/chipidea/core.c +1 -2
@@ -473,8 +473,11 @@ static int __devinit ci_hdrc_probe(struct platform_device *pdev)
 	ret = ci_role_start(ci, ci->role);
 	if (ret) {
 		dev_err(dev, "can't start %s role\n", ci_role(ci)->name);
-		ret = -ENODEV;
-		goto rm_wq;
+		ci->role = CI_ROLE_END;

So are you relying on id pin interrupt for initializing the role after this? Can you provide more details?

Regards,
--
Alex

#13 lore raw

PATCH v2 5/11 USB: chipidea: don't let probe fail if otg controller start one role failed

Quoted 11 lines · Alexander Shishkin
Quoted 3 lines · Richard Zhao

One role failed, but the other role will possiblly still work. For example, when udc start failed, if plug in a host device, it works.

If you're a host device, ci->role should be HOST at this point and ci_role_start() shouldn't fail. If ci->role is detected wrongly, the role detection must be fixed. If ci_role_start() fails for host, but it still works when it's called again after the id pin change is detected, again, the problem is elsewhere.

The check is only for OTG device. For single role device, it just fail if it start the role failed.

Quoted 7 lines
Quoted 7 lines
---
 drivers/usb/chipidea/core.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
Quoted 14 lines

drivers/usb/chipidea/core.c static int __devinit ci_hdrc_probe(struct platform_device *pdev) · line 476

Quoted 11 lines
drivers/usb/chipidea/core.c +1 -2
index 19ef324..8fd390a 100644
@@ -473,8 +473,11 @@ static int __devinit ci_hdrc_probe(struct platform_device *pdev)
 	ret = ci_role_start(ci, ci->role);
 	if (ret) {
 		dev_err(dev, "can't start %s role\n", ci_role(ci)->name);
-		ret = -ENODEV;
-		goto rm_wq;
+		ci->role = CI_ROLE_END;

So are you relying on id pin interrupt for initializing the role after this? Can you provide more details?

Yes. The ID pin detect still works. My case is, gadget role failed, host role works. I was trying not to ruin host function.

Thanks
Richard

Quoted 9 lines

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

#14 lore raw

PATCH v2 5/11 USB: chipidea: don't let probe fail if otg controller start one role failed

Quoted 7 lines · Richard Zhao
Quoted 6 lines · Alexander Shishkin
Quoted 3 lines · Richard Zhao

One role failed, but the other role will possiblly still work. For example, when udc start failed, if plug in a host device, it works.

Quoted 7 lines
Quoted 5 lines

If you're a host device, ci->role should be HOST at this point and ci_role_start() shouldn't fail. If ci->role is detected wrongly, the role detection must be fixed. If ci_role_start() fails for host, but it still works when it's called again after the id pin change is detected, again, the problem is elsewhere.

The check is only for OTG device. For single role device, it just fail if it start the role failed.

Sorry, can you rephrase?

Quoted 21 lines
Quoted 7 lines
Quoted 7 lines
---
 drivers/usb/chipidea/core.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
Quoted 14 lines

drivers/usb/chipidea/core.c static int __devinit ci_hdrc_probe(struct platform_device *pdev) · line 476

Quoted 11 lines
drivers/usb/chipidea/core.c +1 -2
index 19ef324..8fd390a 100644
@@ -473,8 +473,11 @@ static int __devinit ci_hdrc_probe(struct platform_device *pdev)
 	ret = ci_role_start(ci, ci->role);
 	if (ret) {
 		dev_err(dev, "can't start %s role\n", ci_role(ci)->name);
-		ret = -ENODEV;
-		goto rm_wq;
+		ci->role = CI_ROLE_END;

So are you relying on id pin interrupt for initializing the role after this? Can you provide more details?

Quoted 2 lines

Yes. The ID pin detect still works. My case is, gadget role failed, host role works. I was trying not to ruin host function.

But it shouldn't even try to start the gadget, because ci_otg_role() should set ci->role to HOST before ci_role_start() happens.

Another question is, why does gadget start fail?

Regards,
--
Alex

#15 lore raw

PATCH v2 5/11 USB: chipidea: don't let probe fail if otg controller start one role failed

Quoted 40 lines · Alexander Shishkin
Quoted 7 lines · Richard Zhao
Quoted 6 lines · Alexander Shishkin
Quoted 3 lines · Richard Zhao

One role failed, but the other role will possiblly still work. For example, when udc start failed, if plug in a host device, it works.

Quoted 7 lines
Quoted 5 lines

If you're a host device, ci->role should be HOST at this point and ci_role_start() shouldn't fail. If ci->role is detected wrongly, the role detection must be fixed. If ci_role_start() fails for host, but it still works when it's called again after the id pin change is detected, again, the problem is elsewhere.

The check is only for OTG device. For single role device, it just fail if it start the role failed.

Sorry, can you rephrase?

Quoted 21 lines
Quoted 21 lines
Quoted 12 lines
---
 drivers/usb/chipidea/core.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/usb/chipidea/core.c +0 -0
index 19ef324..8fd390a 100644

drivers/usb/chipidea/core.c static int __devinit ci_hdrc_probe(struct platform_device *pdev) · line 476

Quoted 6 lines
drivers/usb/chipidea/core.c +1 -2
@@ -473,8 +473,11 @@ static int __devinit ci_hdrc_probe(struct platform_device *pdev)
 	ret = ci_role_start(ci, ci->role);
 	if (ret) {
 		dev_err(dev, "can't start %s role\n", ci_role(ci)->name);
-		ret = -ENODEV;
-		goto rm_wq;
+		ci->role = CI_ROLE_END;

So are you relying on id pin interrupt for initializing the role after this? Can you provide more details?

Quoted 5 lines
Quoted 2 lines

Yes. The ID pin detect still works. My case is, gadget role failed, host role works. I was trying not to ruin host function.

But it shouldn't even try to start the gadget, because ci_otg_role() should set ci->role to HOST before ci_role_start() happens.

It depends on ID pin. If ID pin is gadget and gadget is not support well, ci_role_start will fail. See below example.

Quoted 2 lines

Another question is, why does gadget start fail?

There's one example:
If usb phy don't support otg yet, otg_set_peripheral will fail, and then cause udc_start fail.

Thanks
Richard

Quoted 5 lines

Regards,
--
Alex

#16 lore raw

PATCH v2 5/11 USB: chipidea: don't let probe fail if otg controller start one role failed

Quoted 46 lines · Richard Zhao
Quoted 40 lines · Alexander Shishkin
Quoted 7 lines · Richard Zhao
Quoted 6 lines · Alexander Shishkin
Quoted 3 lines · Richard Zhao

One role failed, but the other role will possiblly still work. For example, when udc start failed, if plug in a host device, it works.

Quoted 7 lines
Quoted 5 lines

If you're a host device, ci->role should be HOST at this point and ci_role_start() shouldn't fail. If ci->role is detected wrongly, the role detection must be fixed. If ci_role_start() fails for host, but it still works when it's called again after the id pin change is detected, again, the problem is elsewhere.

The check is only for OTG device. For single role device, it just fail if it start the role failed.

Sorry, can you rephrase?

Quoted 21 lines
Quoted 21 lines
Quoted 12 lines
---
 drivers/usb/chipidea/core.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/usb/chipidea/core.c +0 -0
index 19ef324..8fd390a 100644

drivers/usb/chipidea/core.c static int __devinit ci_hdrc_probe(struct platform_device *pdev) · line 476

Quoted 6 lines
drivers/usb/chipidea/core.c +1 -2
@@ -473,8 +473,11 @@ static int __devinit ci_hdrc_probe(struct platform_device *pdev)
 	ret = ci_role_start(ci, ci->role);
 	if (ret) {
 		dev_err(dev, "can't start %s role\n", ci_role(ci)->name);
-		ret = -ENODEV;
-		goto rm_wq;
+		ci->role = CI_ROLE_END;

So are you relying on id pin interrupt for initializing the role after this? Can you provide more details?

Quoted 5 lines
Quoted 2 lines

Yes. The ID pin detect still works. My case is, gadget role failed, host role works. I was trying not to ruin host function.

But it shouldn't even try to start the gadget, because ci_otg_role() should set ci->role to HOST before ci_role_start() happens.

Quoted 7 lines

It depends on ID pin. If ID pin is gadget and gadget is not support well, ci_role_start will fail. See below example.

Quoted 2 lines

Another question is, why does gadget start fail?

There's one example:
If usb phy don't support otg yet, otg_set_peripheral will fail, and then cause udc_start fail.

So you should drop the CI13XXX_REQUIRE_TRANSCEIVER flag from imx platform data till the phy is fully implemented.

Regards,
--
Alex

#17 lore raw

PATCH v2 5/11 USB: chipidea: don't let probe fail if otg controller start one role failed

Quoted 51 lines · Alexander Shishkin
Quoted 49 lines · Richard Zhao
Quoted 40 lines · Alexander Shishkin
Quoted 7 lines · Richard Zhao
Quoted 6 lines · Alexander Shishkin
Quoted 3 lines · Richard Zhao

One role failed, but the other role will possiblly still work. For example, when udc start failed, if plug in a host device, it works.

Quoted 7 lines
Quoted 5 lines

If you're a host device, ci->role should be HOST at this point and ci_role_start() shouldn't fail. If ci->role is detected wrongly, the role detection must be fixed. If ci_role_start() fails for host, but it still works when it's called again after the id pin change is detected, again, the problem is elsewhere.

The check is only for OTG device. For single role device, it just fail if it start the role failed.

Sorry, can you rephrase?

Quoted 21 lines
Quoted 21 lines
Quoted 12 lines
---
 drivers/usb/chipidea/core.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/usb/chipidea/core.c +0 -0
index 19ef324..8fd390a 100644

drivers/usb/chipidea/core.c static int __devinit ci_hdrc_probe(struct platform_device *pdev) · line 476

Quoted 6 lines
drivers/usb/chipidea/core.c +1 -2
@@ -473,8 +473,11 @@ static int __devinit ci_hdrc_probe(struct platform_device *pdev)
 	ret = ci_role_start(ci, ci->role);
 	if (ret) {
 		dev_err(dev, "can't start %s role\n", ci_role(ci)->name);
-		ret = -ENODEV;
-		goto rm_wq;
+		ci->role = CI_ROLE_END;

So are you relying on id pin interrupt for initializing the role after this? Can you provide more details?

Quoted 5 lines
Quoted 2 lines

Yes. The ID pin detect still works. My case is, gadget role failed, host role works. I was trying not to ruin host function.

But it shouldn't even try to start the gadget, because ci_otg_role() should set ci->role to HOST before ci_role_start() happens.

It depends on ID pin. If ID pin is gadget and gadget is not support well, ci_role_start will fail. See below example.

Quoted 1 line
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Another question is, why does gadget start fail?

There's one example:
If usb phy don't support otg yet, otg_set_peripheral will fail, and then cause udc_start fail.

So you should drop the CI13XXX_REQUIRE_TRANSCEIVER flag from imx platform data till the phy is fully implemented.

It's just an example. We can not assume udc_start always success. If it fails, isn't it better to continue support of host than say game over?

Thanks
Richard

Quoted 5 lines

Regards,
--
Alex

#18 lore raw

PATCH v2 5/11 USB: chipidea: don't let probe fail if otg controller start one role failed

Quoted 53 lines · Richard Zhao
Quoted 52 lines · Alexander Shishkin
Quoted 50 lines · Richard Zhao
Quoted 40 lines · Alexander Shishkin
Quoted 7 lines · Richard Zhao
Quoted 6 lines · Alexander Shishkin
Quoted 3 lines · Richard Zhao

One role failed, but the other role will possiblly still work. For example, when udc start failed, if plug in a host device, it works.

Quoted 7 lines
Quoted 5 lines

If you're a host device, ci->role should be HOST at this point and ci_role_start() shouldn't fail. If ci->role is detected wrongly, the role detection must be fixed. If ci_role_start() fails for host, but it still works when it's called again after the id pin change is detected, again, the problem is elsewhere.

The check is only for OTG device. For single role device, it just fail if it start the role failed.

Sorry, can you rephrase?

Quoted 21 lines
Quoted 21 lines
Quoted 12 lines
---
 drivers/usb/chipidea/core.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/usb/chipidea/core.c +0 -0
index 19ef324..8fd390a 100644

drivers/usb/chipidea/core.c static int __devinit ci_hdrc_probe(struct platform_device *pdev) · line 476

Quoted 6 lines
drivers/usb/chipidea/core.c +1 -2
@@ -473,8 +473,11 @@ static int __devinit ci_hdrc_probe(struct platform_device *pdev)
 	ret = ci_role_start(ci, ci->role);
 	if (ret) {
 		dev_err(dev, "can't start %s role\n", ci_role(ci)->name);
-		ret = -ENODEV;
-		goto rm_wq;
+		ci->role = CI_ROLE_END;

So are you relying on id pin interrupt for initializing the role after this? Can you provide more details?

Quoted 5 lines
Quoted 2 lines

Yes. The ID pin detect still works. My case is, gadget role failed, host role works. I was trying not to ruin host function.

But it shouldn't even try to start the gadget, because ci_otg_role() should set ci->role to HOST before ci_role_start() happens.

It depends on ID pin. If ID pin is gadget and gadget is not support well, ci_role_start will fail. See below example.

Quoted 2 lines

Another question is, why does gadget start fail?

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

There's one example:
If usb phy don't support otg yet, otg_set_peripheral will fail, and then cause udc_start fail.

So you should drop the CI13XXX_REQUIRE_TRANSCEIVER flag from imx platform data till the phy is fully implemented.

It's just an example. We can not assume udc_start always success. If it fails, isn't it better to continue support of host than say game over?

Hi Alex,

Is it persuadable? Could you please give comments of other patches too?

Thanks
Richard

Quoted 9 lines

Thanks
Richard

Quoted 5 lines

Regards,
--
Alex

#19 lore raw

PATCH v2 5/11 USB: chipidea: don't let probe fail if otg controller start one role failed

In reply to Richard Zhao
Quoted 53 lines · Richard Zhao
Quoted 52 lines · Alexander Shishkin
Quoted 50 lines · Richard Zhao
Quoted 40 lines · Alexander Shishkin
Quoted 7 lines · Richard Zhao
Quoted 6 lines · Alexander Shishkin
Quoted 3 lines · Richard Zhao

One role failed, but the other role will possiblly still work. For example, when udc start failed, if plug in a host device, it works.

Quoted 7 lines
Quoted 5 lines

If you're a host device, ci->role should be HOST at this point and ci_role_start() shouldn't fail. If ci->role is detected wrongly, the role detection must be fixed. If ci_role_start() fails for host, but it still works when it's called again after the id pin change is detected, again, the problem is elsewhere.

The check is only for OTG device. For single role device, it just fail if it start the role failed.

Sorry, can you rephrase?

Quoted 21 lines
Quoted 21 lines
Quoted 12 lines
---
 drivers/usb/chipidea/core.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/usb/chipidea/core.c +0 -0
index 19ef324..8fd390a 100644

drivers/usb/chipidea/core.c static int __devinit ci_hdrc_probe(struct platform_device *pdev) · line 476

Quoted 6 lines
drivers/usb/chipidea/core.c +1 -2
@@ -473,8 +473,11 @@ static int __devinit ci_hdrc_probe(struct platform_device *pdev)
 	ret = ci_role_start(ci, ci->role);
 	if (ret) {
 		dev_err(dev, "can't start %s role\n", ci_role(ci)->name);
-		ret = -ENODEV;
-		goto rm_wq;
+		ci->role = CI_ROLE_END;

So are you relying on id pin interrupt for initializing the role after this? Can you provide more details?

Quoted 5 lines
Quoted 2 lines

Yes. The ID pin detect still works. My case is, gadget role failed, host role works. I was trying not to ruin host function.

But it shouldn't even try to start the gadget, because ci_otg_role() should set ci->role to HOST before ci_role_start() happens.

It depends on ID pin. If ID pin is gadget and gadget is not support well, ci_role_start will fail. See below example.

Quoted 2 lines

Another question is, why does gadget start fail?

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

There's one example:
If usb phy don't support otg yet, otg_set_peripheral will fail, and then cause udc_start fail.

So you should drop the CI13XXX_REQUIRE_TRANSCEIVER flag from imx platform data till the phy is fully implemented.

It's just an example. We can not assume udc_start always success. If it fails, isn't it better to continue support of host than say game over?

Ok, I think what we need here is to rework error handling around role switching, so that we can allow certain things to fail and retry at a later point (say at id pin change), while being careful about the other failures.

If this patch is not crucial for imx right now, I'd prefer to leave it out.

Regards,
--
Alex

#20 lore raw

PATCH v2 5/11 USB: chipidea: don't let probe fail if otg controller start one role failed

Quoted 64 lines · Alexander Shishkin
Quoted 53 lines · Richard Zhao
Quoted 52 lines · Alexander Shishkin
Quoted 50 lines · Richard Zhao
Quoted 40 lines · Alexander Shishkin
Quoted 7 lines · Richard Zhao
Quoted 6 lines · Alexander Shishkin
Quoted 3 lines · Richard Zhao

One role failed, but the other role will possiblly still work. For example, when udc start failed, if plug in a host device, it works.

Quoted 7 lines
Quoted 5 lines

If you're a host device, ci->role should be HOST at this point and ci_role_start() shouldn't fail. If ci->role is detected wrongly, the role detection must be fixed. If ci_role_start() fails for host, but it still works when it's called again after the id pin change is detected, again, the problem is elsewhere.

The check is only for OTG device. For single role device, it just fail if it start the role failed.

Sorry, can you rephrase?

Quoted 21 lines
Quoted 21 lines
Quoted 12 lines
---
 drivers/usb/chipidea/core.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/usb/chipidea/core.c +0 -0
index 19ef324..8fd390a 100644

drivers/usb/chipidea/core.c static int __devinit ci_hdrc_probe(struct platform_device *pdev) · line 476

Quoted 6 lines
drivers/usb/chipidea/core.c +1 -2
@@ -473,8 +473,11 @@ static int __devinit ci_hdrc_probe(struct platform_device *pdev)
 	ret = ci_role_start(ci, ci->role);
 	if (ret) {
 		dev_err(dev, "can't start %s role\n", ci_role(ci)->name);
-		ret = -ENODEV;
-		goto rm_wq;
+		ci->role = CI_ROLE_END;

So are you relying on id pin interrupt for initializing the role after this? Can you provide more details?

Quoted 5 lines
Quoted 2 lines

Yes. The ID pin detect still works. My case is, gadget role failed, host role works. I was trying not to ruin host function.

But it shouldn't even try to start the gadget, because ci_otg_role() should set ci->role to HOST before ci_role_start() happens.

It depends on ID pin. If ID pin is gadget and gadget is not support well, ci_role_start will fail. See below example.

Quoted 2 lines

Another question is, why does gadget start fail?

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

There's one example:
If usb phy don't support otg yet, otg_set_peripheral will fail, and then cause udc_start fail.

So you should drop the CI13XXX_REQUIRE_TRANSCEIVER flag from imx platform data till the phy is fully implemented.

It's just an example. We can not assume udc_start always success. If it fails, isn't it better to continue support of host than say game over?

Quoted 7 lines

Ok, I think what we need here is to rework error handling around role switching, so that we can allow certain things to fail and retry at a later point (say at id pin change), while being careful about the other failures.

If this patch is not crucial for imx right now, I'd prefer to leave it out.

That's OK. but I hope other function related patch can be merged for 3.7 :)

Thanks
Richard

Quoted 5 lines

Regards,
--
Alex

#21 lore raw

PATCH v2 5/11 USB: chipidea: don't let probe fail if otg controller start one role failed

Quoted 70 lines · Richard Zhao
Quoted 69 lines · Alexander Shishkin
Quoted 53 lines · Richard Zhao
Quoted 52 lines · Alexander Shishkin
Quoted 50 lines · Richard Zhao
Quoted 40 lines · Alexander Shishkin
Quoted 7 lines · Richard Zhao
Quoted 6 lines · Alexander Shishkin
Quoted 3 lines · Richard Zhao

One role failed, but the other role will possiblly still work. For example, when udc start failed, if plug in a host device, it works.

Quoted 7 lines
Quoted 5 lines

If you're a host device, ci->role should be HOST at this point and ci_role_start() shouldn't fail. If ci->role is detected wrongly, the role detection must be fixed. If ci_role_start() fails for host, but it still works when it's called again after the id pin change is detected, again, the problem is elsewhere.

The check is only for OTG device. For single role device, it just fail if it start the role failed.

Sorry, can you rephrase?

Quoted 21 lines
Quoted 21 lines
Quoted 12 lines
---
 drivers/usb/chipidea/core.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/usb/chipidea/core.c +0 -0
index 19ef324..8fd390a 100644

drivers/usb/chipidea/core.c static int __devinit ci_hdrc_probe(struct platform_device *pdev) · line 476

Quoted 6 lines
drivers/usb/chipidea/core.c +1 -2
@@ -473,8 +473,11 @@ static int __devinit ci_hdrc_probe(struct platform_device *pdev)
 	ret = ci_role_start(ci, ci->role);
 	if (ret) {
 		dev_err(dev, "can't start %s role\n", ci_role(ci)->name);
-		ret = -ENODEV;
-		goto rm_wq;
+		ci->role = CI_ROLE_END;

So are you relying on id pin interrupt for initializing the role after this? Can you provide more details?

Quoted 5 lines
Quoted 2 lines

Yes. The ID pin detect still works. My case is, gadget role failed, host role works. I was trying not to ruin host function.

But it shouldn't even try to start the gadget, because ci_otg_role() should set ci->role to HOST before ci_role_start() happens.

It depends on ID pin. If ID pin is gadget and gadget is not support well, ci_role_start will fail. See below example.

Quoted 2 lines

Another question is, why does gadget start fail?

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

There's one example:
If usb phy don't support otg yet, otg_set_peripheral will fail, and then cause udc_start fail.

So you should drop the CI13XXX_REQUIRE_TRANSCEIVER flag from imx platform data till the phy is fully implemented.

It's just an example. We can not assume udc_start always success. If it fails, isn't it better to continue support of host than say game over?

Ok, I think what we need here is to rework error handling around role switching, so that we can allow certain things to fail and retry at a later point (say at id pin change), while being careful about the other failures.

Quoted 4 lines
Quoted 2 lines

If this patch is not crucial for imx right now, I'd prefer to leave it out.

That's OK. but I hope other function related patch can be merged for 3.7 :)

Also 6/11 seems quite pointless to me. Otherwise, I'll send them to Greg today.

Regards,
--
Alex

#22 lore raw

PATCH v2 5/11 USB: chipidea: don't let probe fail if otg controller start one role failed

Quoted 72 lines · Alexander Shishkin
Quoted 70 lines · Richard Zhao
Quoted 69 lines · Alexander Shishkin
Quoted 53 lines · Richard Zhao
Quoted 52 lines · Alexander Shishkin
Quoted 50 lines · Richard Zhao
Quoted 40 lines · Alexander Shishkin
Quoted 7 lines · Richard Zhao
Quoted 6 lines · Alexander Shishkin
Quoted 3 lines · Richard Zhao

One role failed, but the other role will possiblly still work. For example, when udc start failed, if plug in a host device, it works.

Quoted 7 lines
Quoted 5 lines

If you're a host device, ci->role should be HOST at this point and ci_role_start() shouldn't fail. If ci->role is detected wrongly, the role detection must be fixed. If ci_role_start() fails for host, but it still works when it's called again after the id pin change is detected, again, the problem is elsewhere.

The check is only for OTG device. For single role device, it just fail if it start the role failed.

Sorry, can you rephrase?

Quoted 21 lines
Quoted 21 lines
Quoted 12 lines
---
 drivers/usb/chipidea/core.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/usb/chipidea/core.c +0 -0
index 19ef324..8fd390a 100644

drivers/usb/chipidea/core.c static int __devinit ci_hdrc_probe(struct platform_device *pdev) · line 476

Quoted 6 lines
drivers/usb/chipidea/core.c +1 -2
@@ -473,8 +473,11 @@ static int __devinit ci_hdrc_probe(struct platform_device *pdev)
 	ret = ci_role_start(ci, ci->role);
 	if (ret) {
 		dev_err(dev, "can't start %s role\n", ci_role(ci)->name);
-		ret = -ENODEV;
-		goto rm_wq;
+		ci->role = CI_ROLE_END;

So are you relying on id pin interrupt for initializing the role after this? Can you provide more details?

Quoted 5 lines
Quoted 2 lines

Yes. The ID pin detect still works. My case is, gadget role failed, host role works. I was trying not to ruin host function.

But it shouldn't even try to start the gadget, because ci_otg_role() should set ci->role to HOST before ci_role_start() happens.

It depends on ID pin. If ID pin is gadget and gadget is not support well, ci_role_start will fail. See below example.

Quoted 2 lines

Another question is, why does gadget start fail?

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

There's one example:
If usb phy don't support otg yet, otg_set_peripheral will fail, and then cause udc_start fail.

So you should drop the CI13XXX_REQUIRE_TRANSCEIVER flag from imx platform data till the phy is fully implemented.

It's just an example. We can not assume udc_start always success. If it fails, isn't it better to continue support of host than say game over?

Ok, I think what we need here is to rework error handling around role switching, so that we can allow certain things to fail and retry at a later point (say at id pin change), while being careful about the other failures.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

If this patch is not crucial for imx right now, I'd prefer to leave it out.

That's OK. but I hope other function related patch can be merged for 3.7 :)

Also 6/11 seems quite pointless to me. Otherwise, I'll send them to Greg today.

If set_peripheral is null, udc_start will fail. Or you prefer removing checking of otg_set_peripheral returned value?

Thanks
Richard

Quoted 5 lines

Regards,
--
Alex

#23 lore raw

PATCH v2 5/11 USB: chipidea: don't let probe fail if otg controller start one role failed

Quoted 75 lines · Richard Zhao
Quoted 74 lines · Alexander Shishkin
Quoted 72 lines · Richard Zhao
Quoted 71 lines · Alexander Shishkin
Quoted 53 lines · Richard Zhao
Quoted 52 lines · Alexander Shishkin
Quoted 50 lines · Richard Zhao
Quoted 40 lines · Alexander Shishkin
Quoted 7 lines · Richard Zhao
Quoted 6 lines · Alexander Shishkin
Quoted 3 lines · Richard Zhao

One role failed, but the other role will possiblly still work. For example, when udc start failed, if plug in a host device, it works.

Quoted 7 lines
Quoted 5 lines

If you're a host device, ci->role should be HOST at this point and ci_role_start() shouldn't fail. If ci->role is detected wrongly, the role detection must be fixed. If ci_role_start() fails for host, but it still works when it's called again after the id pin change is detected, again, the problem is elsewhere.

The check is only for OTG device. For single role device, it just fail if it start the role failed.

Sorry, can you rephrase?

Quoted 21 lines
Quoted 21 lines
Quoted 12 lines
---
 drivers/usb/chipidea/core.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/usb/chipidea/core.c +0 -0
index 19ef324..8fd390a 100644

drivers/usb/chipidea/core.c static int __devinit ci_hdrc_probe(struct platform_device *pdev) · line 476

Quoted 6 lines
drivers/usb/chipidea/core.c +1 -2
@@ -473,8 +473,11 @@ static int __devinit ci_hdrc_probe(struct platform_device *pdev)
 	ret = ci_role_start(ci, ci->role);
 	if (ret) {
 		dev_err(dev, "can't start %s role\n", ci_role(ci)->name);
-		ret = -ENODEV;
-		goto rm_wq;
+		ci->role = CI_ROLE_END;

So are you relying on id pin interrupt for initializing the role after this? Can you provide more details?

Quoted 5 lines
Quoted 2 lines

Yes. The ID pin detect still works. My case is, gadget role failed, host role works. I was trying not to ruin host function.

But it shouldn't even try to start the gadget, because ci_otg_role() should set ci->role to HOST before ci_role_start() happens.

It depends on ID pin. If ID pin is gadget and gadget is not support well, ci_role_start will fail. See below example.

Quoted 2 lines

Another question is, why does gadget start fail?

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

There's one example:
If usb phy don't support otg yet, otg_set_peripheral will fail, and then cause udc_start fail.

So you should drop the CI13XXX_REQUIRE_TRANSCEIVER flag from imx platform data till the phy is fully implemented.

It's just an example. We can not assume udc_start always success. If it fails, isn't it better to continue support of host than say game over?

Ok, I think what we need here is to rework error handling around role switching, so that we can allow certain things to fail and retry at a later point (say at id pin change), while being careful about the other failures.

If this patch is not crucial for imx right now, I'd prefer to leave it out.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

That's OK. but I hope other function related patch can be merged for 3.7 :)

Also 6/11 seems quite pointless to me. Otherwise, I'll send them to Greg today.

If set_peripheral is null, udc_start will fail. Or you prefer removing checking of otg_set_peripheral returned value?

I guess for now we could do something like

        if (retval &&
            !(ci->platdata->flags & CI13XXX_REQUIRE_TRANSCEIVER))
                goto remove_dbg;

... or implement an otg driver. :)

Regards,
--
Alex

#24 lore raw

PATCH v2 5/11 USB: chipidea: don't let probe fail if otg controller start one role failed

Quoted 85 lines · Alexander Shishkin
Quoted 75 lines · Richard Zhao
Quoted 74 lines · Alexander Shishkin
Quoted 72 lines · Richard Zhao
Quoted 71 lines · Alexander Shishkin
Quoted 53 lines · Richard Zhao
Quoted 52 lines · Alexander Shishkin
Quoted 50 lines · Richard Zhao
Quoted 40 lines · Alexander Shishkin
Quoted 7 lines · Richard Zhao
Quoted 6 lines · Alexander Shishkin
Quoted 3 lines · Richard Zhao

One role failed, but the other role will possiblly still work. For example, when udc start failed, if plug in a host device, it works.

Quoted 7 lines
Quoted 5 lines

If you're a host device, ci->role should be HOST at this point and ci_role_start() shouldn't fail. If ci->role is detected wrongly, the role detection must be fixed. If ci_role_start() fails for host, but it still works when it's called again after the id pin change is detected, again, the problem is elsewhere.

The check is only for OTG device. For single role device, it just fail if it start the role failed.

Sorry, can you rephrase?

Quoted 21 lines
Quoted 21 lines
Quoted 12 lines
---
 drivers/usb/chipidea/core.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/usb/chipidea/core.c +0 -0
index 19ef324..8fd390a 100644

drivers/usb/chipidea/core.c static int __devinit ci_hdrc_probe(struct platform_device *pdev) · line 476

Quoted 6 lines
drivers/usb/chipidea/core.c +1 -2
@@ -473,8 +473,11 @@ static int __devinit ci_hdrc_probe(struct platform_device *pdev)
 	ret = ci_role_start(ci, ci->role);
 	if (ret) {
 		dev_err(dev, "can't start %s role\n", ci_role(ci)->name);
-		ret = -ENODEV;
-		goto rm_wq;
+		ci->role = CI_ROLE_END;

So are you relying on id pin interrupt for initializing the role after this? Can you provide more details?

Quoted 5 lines
Quoted 2 lines

Yes. The ID pin detect still works. My case is, gadget role failed, host role works. I was trying not to ruin host function.

But it shouldn't even try to start the gadget, because ci_otg_role() should set ci->role to HOST before ci_role_start() happens.

It depends on ID pin. If ID pin is gadget and gadget is not support well, ci_role_start will fail. See below example.

Quoted 2 lines

Another question is, why does gadget start fail?

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

There's one example:
If usb phy don't support otg yet, otg_set_peripheral will fail, and then cause udc_start fail.

So you should drop the CI13XXX_REQUIRE_TRANSCEIVER flag from imx platform data till the phy is fully implemented.

It's just an example. We can not assume udc_start always success. If it fails, isn't it better to continue support of host than say game over?

Ok, I think what we need here is to rework error handling around role switching, so that we can allow certain things to fail and retry at a later point (say at id pin change), while being careful about the other failures.

If this patch is not crucial for imx right now, I'd prefer to leave it out.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

That's OK. but I hope other function related patch can be merged for 3.7 :)

Also 6/11 seems quite pointless to me. Otherwise, I'll send them to Greg today.

If set_peripheral is null, udc_start will fail. Or you prefer removing checking of otg_set_peripheral returned value?

Quoted 7 lines

I guess for now we could do something like

        if (retval &&
            !(ci->platdata->flags & CI13XXX_REQUIRE_TRANSCEIVER))
                goto remove_dbg;

... or implement an otg driver. :)

Yes, a fake otg driver sounds more simple :)

Thanks
Richard

Quoted 5 lines

Regards,
--
Alex

#25 lore raw

PATCH v2 6/11 USB: mxs-phy: add basic otg support

In reply to Richard Zhao
---
 drivers/usb/otg/mxs-phy.c |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/usb/otg/mxs-phy.c +21 -0
index c1a67cb..6a03e97 100644
@@ -97,12 +97,24 @@ static int mxs_phy_on_disconnect(struct usb_phy *phy, int port)
 	return 0;
 }
 
+static int mxs_phy_set_host(struct usb_otg *otg, struct usb_bus *host)
+{
+	return 0;
+}
+
+static int mxs_phy_set_peripheral(struct usb_otg *otg,
+					struct usb_gadget *gadget)
+{
+	return 0;
+}
+
 static int mxs_phy_probe(struct platform_device *pdev)
 {
 	struct resource *res;
 	void __iomem *base;
 	struct clk *clk;
 	struct mxs_phy *mxs_phy;
+	struct usb_otg *otg;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!res) {
@@ -139,6 +151,15 @@ static int mxs_phy_probe(struct platform_device *pdev)
 
 	mxs_phy->clk = clk;
 
+	otg = devm_kzalloc(&pdev->dev, sizeof(struct usb_otg), GFP_KERNEL);
+	if (!otg)
+		return -ENOMEM;
+	otg->phy = &mxs_phy->phy;
+	otg->set_host = mxs_phy_set_host;
+	otg->set_peripheral = mxs_phy_set_peripheral;
+
+	mxs_phy->phy.otg = otg;
+
 	platform_set_drvdata(pdev, &mxs_phy->phy);
 
 	return 0;
Signature · 1 line
1.7.9.5
#26 lore raw

PATCH v2 6/11 USB: mxs-phy: add basic otg support

Hi,

Quoted 1 line · Richard Zhao

if you add a commit log you can add my:

Quoted 53 lines
---
 drivers/usb/otg/mxs-phy.c |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/usb/otg/mxs-phy.c +21 -0
index c1a67cb..6a03e97 100644
@@ -97,12 +97,24 @@ static int mxs_phy_on_disconnect(struct usb_phy *phy, int port)
 	return 0;
 }
 
+static int mxs_phy_set_host(struct usb_otg *otg, struct usb_bus *host)
+{
+	return 0;
+}
+
+static int mxs_phy_set_peripheral(struct usb_otg *otg,
+					struct usb_gadget *gadget)
+{
+	return 0;
+}
+
 static int mxs_phy_probe(struct platform_device *pdev)
 {
 	struct resource *res;
 	void __iomem *base;
 	struct clk *clk;
 	struct mxs_phy *mxs_phy;
+	struct usb_otg *otg;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!res) {
@@ -139,6 +151,15 @@ static int mxs_phy_probe(struct platform_device *pdev)
 
 	mxs_phy->clk = clk;
 
+	otg = devm_kzalloc(&pdev->dev, sizeof(struct usb_otg), GFP_KERNEL);
+	if (!otg)
+		return -ENOMEM;
+	otg->phy = &mxs_phy->phy;
+	otg->set_host = mxs_phy_set_host;
+	otg->set_peripheral = mxs_phy_set_peripheral;
+
+	mxs_phy->phy.otg = otg;
+
 	platform_set_drvdata(pdev, &mxs_phy->phy);
 
 	return 0;
Signature · 1 line
1.7.9.5
Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20120911/5fda1de8/attachment.sig>
#27 lore raw

PATCH v2 6/11 USB: mxs-phy: add basic otg support

In reply to Richard Zhao

Hi,

Review

Quoted 2 lines · Richard Zhao
(quoted diff) +2 -0
+static int mxs_phy_set_host(struct usb_otg *otg, struct usb_bus *host)
+{

Shouldn't you at least save the host pointer?

otg->host = host;

drivers/usb/otg/mxs-phy.c static int mxs_phy_on_disconnect(struct usb_phy *phy, int port) · line 107

Quoted 6 lines
drivers/usb/otg/mxs-phy.c +6 -0
+	return 0;
+}
+
+static int mxs_phy_set_peripheral(struct usb_otg *otg,
+					struct usb_gadget *gadget)
+{

And the same with the gadget?

Quoted 2 lines
(quoted diff) +2 -0
+	return 0;
+}
Signature · 1 line
heikki
#28 lore raw

PATCH v2 6/11 USB: mxs-phy: add basic otg support

Quoted 9 lines · Heikki Krogerus

Hi,

Review

Quoted 2 lines · Richard Zhao
(quoted diff) +2 -0
+static int mxs_phy_set_host(struct usb_otg *otg, struct usb_bus *host)
+{

Shouldn't you at least save the host pointer?

otg->host = host;

It looks making sense, though it's not called by chipidea driver.

Quoted 9 lines

drivers/usb/otg/mxs-phy.c static int mxs_phy_on_disconnect(struct usb_phy *phy, int port) · line 107

Quoted 7 lines
drivers/usb/otg/mxs-phy.c +6 -0
+	return 0;
+}
+
+static int mxs_phy_set_peripheral(struct usb_otg *otg,
+					struct usb_gadget *gadget)
+{

And the same with the gadget?

Thanks
Richard

Quoted 7 lines
Quoted 3 lines
(quoted diff) +2 -0
+	return 0;
+}
Signature · 1 line
heikki
#29 lore raw

PATCH v2 6/11 USB: mxs-phy: add basic otg support

In reply to Richard Zhao
Quoted 35 lines
drivers/usb/otg/mxs-phy.c +12 -0
index c1a67cb..6a03e97 100644
@@ -97,12 +97,24 @@ static int mxs_phy_on_disconnect(struct usb_phy *phy,
 int port)
 	return 0;
 }
 
+static int mxs_phy_set_host(struct usb_otg *otg, struct usb_bus *host)
+{
+	return 0;
+}
+
+static int mxs_phy_set_peripheral(struct usb_otg *otg,
+					struct usb_gadget *gadget)
+{
+	return 0;
+}
+
 static int mxs_phy_probe(struct platform_device *pdev)
 {
 	struct resource *res;
 	void __iomem *base;
 	struct clk *clk;
 	struct mxs_phy *mxs_phy;
+	struct usb_otg *otg;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
drivers/usb/otg/mxs-phy.c +0 -0
 	if (!res) {
@@ -139,6 +151,15 @@ static int mxs_phy_probe(struct platform_device
 *pdev)
 
 	mxs_phy->clk = clk;

drivers/usb/otg/mxs-phy.c static int mxs_phy_probe(struct platform_device · line 163

Quoted 10 lines
drivers/usb/otg/mxs-phy.c +9 -0
 
+	otg = devm_kzalloc(&pdev->dev, sizeof(struct usb_otg), GFP_KERNEL);
+	if (!otg)
+		return -ENOMEM;
+	otg->phy = &mxs_phy->phy;
+	otg->set_host = mxs_phy_set_host;
+	otg->set_peripheral = mxs_phy_set_peripheral;
+
+	mxs_phy->phy.otg = otg;
+

Put otg struct at PHY driver is not a good practice.
Only OTG driver who handles ID interrupt cases about host and gadget struct. PHY is a transceiver, it not cares otg, host and device at all.

Quoted 5 lines
drivers/usb/otg/mxs-phy.c +0 -0
 	platform_set_drvdata(pdev, &mxs_phy->phy);
 

return 0;
--
1.7.9.5

#30 lore raw

PATCH v2 6/11 USB: mxs-phy: add basic otg support

Quoted 36 lines · On Fri, Sep 14, 2012 at 04:56:13PM +0800, Chen Peter-B29397 wrote:
Quoted 36 lines
drivers/usb/otg/mxs-phy.c +12 -0
index c1a67cb..6a03e97 100644
@@ -97,12 +97,24 @@ static int mxs_phy_on_disconnect(struct usb_phy *phy,
 int port)
 	return 0;
 }
 
+static int mxs_phy_set_host(struct usb_otg *otg, struct usb_bus *host)
+{
+	return 0;
+}
+
+static int mxs_phy_set_peripheral(struct usb_otg *otg,
+					struct usb_gadget *gadget)
+{
+	return 0;
+}
+
 static int mxs_phy_probe(struct platform_device *pdev)
 {
 	struct resource *res;
 	void __iomem *base;
 	struct clk *clk;
 	struct mxs_phy *mxs_phy;
+	struct usb_otg *otg;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
drivers/usb/otg/mxs-phy.c +0 -0
 	if (!res) {
@@ -139,6 +151,15 @@ static int mxs_phy_probe(struct platform_device
 *pdev)
 
 	mxs_phy->clk = clk;
 
Quoted 13 lines

drivers/usb/otg/mxs-phy.c static int mxs_phy_probe(struct platform_device *pdev) · line 162

Quoted 9 lines
drivers/usb/otg/mxs-phy.c +9 -0
+	otg = devm_kzalloc(&pdev->dev, sizeof(struct usb_otg), GFP_KERNEL);
+	if (!otg)
+		return -ENOMEM;
+	otg->phy = &mxs_phy->phy;
+	otg->set_host = mxs_phy_set_host;
+	otg->set_peripheral = mxs_phy_set_peripheral;
+
+	mxs_phy->phy.otg = otg;
+

Put otg struct at PHY driver is not a good practice.
Only OTG driver who handles ID interrupt cases about host and gadget struct. PHY is a transceiver, it not cares otg, host and device at all.

I understand your concern, but this patch don't mean to restructure common code.

Thanks
Richard

Quoted 7 lines
Quoted 6 lines
drivers/usb/otg/mxs-phy.c +0 -0
 	platform_set_drvdata(pdev, &mxs_phy->phy);
 

return 0;
--
1.7.9.5

#31 lore raw

PATCH v2 7/11 USB: chipidea: add vbus detect for udc

In reply to Richard Zhao

Using vbus valid interrupt to detect vbus.

---
 drivers/usb/chipidea/ci.h  |    1 +
 drivers/usb/chipidea/udc.c |   39 ++++++++++++++++++++++++++++++++++++++-
 2 files changed, 39 insertions(+), 1 deletion(-)
drivers/usb/chipidea/ci.h +1 -0
index d738603..e25d126 100644
@@ -139,6 +139,7 @@ struct ci13xxx {
 	enum ci_role			role;
 	bool				is_otg;
 	struct work_struct		work;
+	struct work_struct		vbus_work;
 	struct workqueue_struct		*wq;
 
 	struct dma_pool			*qh_pool;
drivers/usb/chipidea/udc.c +38 -1
index 9fb6394..2cb4498 100644
@@ -308,6 +308,18 @@ static u32 hw_test_and_clear_intr_active(struct ci13xxx *ci)
 	return reg;
 }
 
+static void hw_enable_vbus_intr(struct ci13xxx *ci)
+{
+	hw_write(ci, OP_OTGSC, OTGSC_AVVIS, OTGSC_AVVIS);
+	hw_write(ci, OP_OTGSC, OTGSC_AVVIE, OTGSC_AVVIE);
+	queue_work(ci->wq, &ci->vbus_work);
+}
+
+static void hw_disable_vbus_intr(struct ci13xxx *ci)
+{
+	hw_write(ci, OP_OTGSC, OTGSC_AVVIE, 0);
+}
+
 /**
  * hw_test_and_clear_setup_guard: test & clear setup guard (execute without
  *                                interruption)
@@ -374,6 +386,16 @@ static int hw_usb_reset(struct ci13xxx *ci)
 	return 0;
 }
 
+static void vbus_work(struct work_struct *work)
+{
+	struct ci13xxx *ci = container_of(work, struct ci13xxx, vbus_work);
+
+	if (hw_read(ci, OP_OTGSC, OTGSC_AVV))
+		usb_gadget_vbus_connect(&ci->gadget);
+	else
+		usb_gadget_vbus_disconnect(&ci->gadget);
+}
+
 /******************************************************************************
  * UTIL block
  *****************************************************************************/
@@ -1376,6 +1398,7 @@ static int ci13xxx_vbus_session(struct usb_gadget *_gadget, int is_active)
 		if (is_active) {
 			pm_runtime_get_sync(&_gadget->dev);
 			hw_device_reset(ci, USBMODE_CM_DC);
+			hw_enable_vbus_intr(ci);
 			hw_device_state(ci, ci->ep0out->qh.dma);
 		} else {
 			hw_device_state(ci, 0);
@@ -1517,8 +1540,10 @@ static int ci13xxx_start(struct usb_gadget *gadget,
 	pm_runtime_get_sync(&ci->gadget.dev);
 	if (ci->platdata->flags & CI13XXX_PULLUP_ON_VBUS) {
 		if (ci->vbus_active) {
-			if (ci->platdata->flags & CI13XXX_REGS_SHARED)
+			if (ci->platdata->flags & CI13XXX_REGS_SHARED) {
 				hw_device_reset(ci, USBMODE_CM_DC);
+				hw_enable_vbus_intr(ci);
+			}
 		} else {
 			pm_runtime_put_sync(&ci->gadget.dev);
 			goto done;
@@ -1624,6 +1649,13 @@ static irqreturn_t udc_irq(struct ci13xxx *ci)
 	} else {
 		retval = IRQ_NONE;
 	}
+
+	intr = hw_read(ci, OP_OTGSC, ~0);
+	hw_write(ci, OP_OTGSC, ~0, intr);
+
+	if (intr & (OTGSC_AVVIE & OTGSC_AVVIS))
+		queue_work(ci->wq, &ci->vbus_work);
+
 	spin_unlock(&ci->lock);
 
 	return retval;
@@ -1699,6 +1731,7 @@ static int udc_start(struct ci13xxx *ci)
 		retval = hw_device_reset(ci, USBMODE_CM_DC);
 		if (retval)
 			goto put_transceiver;
+		hw_enable_vbus_intr(ci);
 	}
 
 	retval = device_register(&ci->gadget.dev);
@@ -1762,6 +1795,9 @@ static void udc_stop(struct ci13xxx *ci)
 	if (ci == NULL)
 		return;
 
+	hw_disable_vbus_intr(ci);
+	cancel_work_sync(&ci->vbus_work);
+
 	usb_del_gadget_udc(&ci->gadget);
 
 	for (i = 0; i < ci->hw_ep_max; i++) {
@@ -1806,6 +1842,7 @@ int ci_hdrc_gadget_init(struct ci13xxx *ci)
 	rdrv->irq	= udc_irq;
 	rdrv->name	= "gadget";
 	ci->roles[CI_ROLE_GADGET] = rdrv;
+	INIT_WORK(&ci->vbus_work, vbus_work);
 
 	return 0;
 }
Signature · 1 line
1.7.9.5
#32 lore raw

PATCH v2 8/11 USB: chipidea: convert to use devm_request_irq

In reply to Richard Zhao
---
 drivers/usb/chipidea/core.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/usb/chipidea/core.c +2 -3
index 8fd390a..7485c84 100644
@@ -481,8 +481,8 @@ static int __devinit ci_hdrc_probe(struct platform_device *pdev)
 	}
 
 	platform_set_drvdata(pdev, ci);
-	ret = request_irq(ci->irq, ci_irq, IRQF_SHARED, ci->platdata->name,
-			  ci);
+	ret = devm_request_irq(dev, ci->irq, ci_irq, IRQF_SHARED,
+				ci->platdata->name, ci);
 	if (ret)
 		goto stop;
 
@@ -513,7 +513,6 @@ static int __devexit ci_hdrc_remove(struct platform_device *pdev)
 	flush_workqueue(ci->wq);
 	destroy_workqueue(ci->wq);
 	device_remove_file(ci->dev, &dev_attr_role);
-	free_irq(ci->irq, ci);
 	ci_role_stop(ci);
 
 	return 0;
Signature · 1 line
1.7.9.5
#33 lore raw

PATCH v2 9/11 USB: chipidea: add -DDEBUG if CONFIG_USB_CHIPIDEA_DEBUG

In reply to Richard Zhao
---
 drivers/usb/chipidea/Makefile |    2 ++
 1 file changed, 2 insertions(+)
drivers/usb/chipidea/Makefile +2 -0
index 57e510f..d92ca32 100644
@@ -1,3 +1,5 @@
+ccflags-$(CONFIG_USB_CHIPIDEA_DEBUG) := -DDEBUG
+
 obj-$(CONFIG_USB_CHIPIDEA)		+= ci_hdrc.o
 
 ci_hdrc-y				:= core.o
Signature · 1 line
1.7.9.5
#34 lore raw

PATCH v2 10/11 USB: chipidea: add set_vbus_power support

In reply to Richard Zhao

set_vbus_power is used to enable or disable vbus power for usb host.

[Marc Kleine-Budde <[email protected]>: fix regulator unbalance disable]

---
 drivers/usb/chipidea/ci13xxx_imx.c |   44 +++++++++++++++++++++---------------
 drivers/usb/chipidea/host.c        |    8 +++++++
 include/linux/usb/chipidea.h       |    2 ++
 3 files changed, 36 insertions(+), 18 deletions(-)
drivers/usb/chipidea/ci13xxx_imx.c +26 -18
index 0f5ca4b..5c0be08 100644
@@ -27,6 +27,8 @@
 
 #define pdev_to_phy(pdev) \
 	((struct usb_phy *)platform_get_drvdata(pdev))
+#define ci_to_imx_data(ci) \
+	((struct ci13xxx_imx_data *)dev_get_drvdata(ci->dev->parent))
 
 struct ci13xxx_imx_data {
 	struct device_node *phy_np;
@@ -85,12 +87,32 @@ EXPORT_SYMBOL_GPL(usbmisc_get_init_data);
 
 /* End of common functions shared by usbmisc drivers*/
 
+static int ci13xxx_imx_vbus(struct ci13xxx *ci, int enable)
+{
+	struct ci13xxx_imx_data *data = ci_to_imx_data(ci);
+	int ret;
+
+	if (!data->reg_vbus)
+		return 0;
+
+	if (enable)
+		ret = regulator_enable(data->reg_vbus);
+	else
+		ret = regulator_disable(data->reg_vbus);
+	if (ret)
+		dev_err(ci->dev, "ci13xxx_imx_vbus failed, enable:%d err:%d\n",
+			enable, ret);
+
+	return ret;
+}
+
 static struct ci13xxx_platform_data ci13xxx_imx_platdata __devinitdata  = {
 	.name			= "ci13xxx_imx",
 	.flags			= CI13XXX_REQUIRE_TRANSCEIVER |
 				  CI13XXX_PULLUP_ON_VBUS |
 				  CI13XXX_DISABLE_STREAMING,
 	.capoffset		= DEF_CAPOFFSET,
+	.set_vbus_power		= ci13xxx_imx_vbus,
 };
 
 static int __devinit ci13xxx_imx_probe(struct platform_device *pdev)
@@ -153,20 +175,11 @@ static int __devinit ci13xxx_imx_probe(struct platform_device *pdev)
 		}
 	}
 
-	/* we only support host now, so enable vbus here */
 	reg_vbus = devm_regulator_get(&pdev->dev, "vbus");
-	if (!IS_ERR(reg_vbus)) {
-		ret = regulator_enable(reg_vbus);
-		if (ret) {
-			dev_err(&pdev->dev,
-				"Failed to enable vbus regulator, err=%d\n",
-				ret);
-			goto put_np;
-		}
+	if (!IS_ERR(reg_vbus))
 		data->reg_vbus = reg_vbus;
-	} else {
+	else
 		reg_vbus = NULL;
-	}
 
 	ci13xxx_imx_platdata.phy = data->phy;
 
@@ -191,6 +204,8 @@ static int __devinit ci13xxx_imx_probe(struct platform_device *pdev)
 		}
 	}
 
+	platform_set_drvdata(pdev, data);
+
 	plat_ci = ci13xxx_add_device(&pdev->dev,
 				pdev->resource, pdev->num_resources,
 				&ci13xxx_imx_platdata);
@@ -203,7 +218,6 @@ static int __devinit ci13xxx_imx_probe(struct platform_device *pdev)
 	}
 
 	data->ci_pdev = plat_ci;
-	platform_set_drvdata(pdev, data);
 
 	pm_runtime_no_callbacks(&pdev->dev);
 	pm_runtime_enable(&pdev->dev);
@@ -211,9 +225,6 @@ static int __devinit ci13xxx_imx_probe(struct platform_device *pdev)
 	return 0;
 
 err:
-	if (reg_vbus)
-		regulator_disable(reg_vbus);
-put_np:
 	if (phy_np)
 		of_node_put(phy_np);
 	clk_disable_unprepare(data->clk);
@@ -227,9 +238,6 @@ static int __devexit ci13xxx_imx_remove(struct platform_device *pdev)
 	pm_runtime_disable(&pdev->dev);
 	ci13xxx_remove_device(data->ci_pdev);
 
-	if (data->reg_vbus)
-		regulator_disable(data->reg_vbus);
-
 	if (data->phy) {
 		usb_phy_shutdown(data->phy);
 		module_put(data->phy->dev->driver->owner);
drivers/usb/chipidea/host.c +8 -0
index ebff9f4..e091147 100644
@@ -106,6 +106,12 @@ static int host_start(struct ci13xxx *ci)
 	if (usb_disabled())
 		return -ENODEV;
 
+	if (ci->platdata->set_vbus_power) {
+		ret = ci->platdata->set_vbus_power(ci, 1);
+		if (ret)
+			return ret;
+	}
+
 	hcd = usb_create_hcd(&ci_ehci_hc_driver, ci->dev, dev_name(ci->dev));
 	if (!hcd)
 		return -ENOMEM;
@@ -138,6 +144,8 @@ static void host_stop(struct ci13xxx *ci)
 
 	usb_remove_hcd(hcd);
 	usb_put_hcd(hcd);
+	if (ci->platdata->set_vbus_power)
+		ci->platdata->set_vbus_power(ci, 0);
 }
 
 int ci_hdrc_host_init(struct ci13xxx *ci)
include/linux/usb/chipidea.h +2 -0
index 544825d..080f479 100644
@@ -23,6 +23,8 @@ struct ci13xxx_platform_data {
 #define CI13XXX_CONTROLLER_RESET_EVENT		0
 #define CI13XXX_CONTROLLER_STOPPED_EVENT	1
 	void	(*notify_event) (struct ci13xxx *ci, unsigned event);
+	/* set vbus power, it must be called in non-atomic context */
+	int	(*set_vbus_power) (struct ci13xxx *ci, int enable);
 };
 
 /* Default offset of capability registers */
Signature · 1 line
1.7.9.5
#35 lore raw

PATCH v2 10/11 USB: chipidea: add set_vbus_power support

Alex,

I find you dropped this too. Did you mean to add it after otg driver or any other reason?

Thanks
Richard

#36 lore raw

PATCH v2 11/11 USB: chipidea: re-order irq handling to avoid unhandled irq

In reply to Richard Zhao

- let role driver handle irq before ID change check. It give the role driver a chance to handle disconnect.
- disable irq during switch role. No role driver to handle irq in the period.

---
 drivers/usb/chipidea/core.c |   21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
drivers/usb/chipidea/core.c +13 -8
index 7485c84..0942b9b 100644
@@ -279,6 +279,7 @@ static void ci_role_work(struct work_struct *work)
 
 		ci_role_stop(ci);
 		ci_role_start(ci, role);
+		enable_irq(ci->irq);
 	}
 }
 
@@ -318,18 +319,22 @@ static irqreturn_t ci_irq(int irq, void *data)
 {
 	struct ci13xxx *ci = data;
 	irqreturn_t ret = IRQ_NONE;
+	u32 otgsc = 0;
 
-	if (ci->is_otg) {
-		u32 sts = hw_read(ci, OP_OTGSC, ~0);
+	if (ci->is_otg)
+		otgsc = hw_read(ci, OP_OTGSC, ~0);
 
-		if (sts & OTGSC_IDIS) {
-			hw_write(ci, OP_OTGSC, OTGSC_IDIS, OTGSC_IDIS);
-			queue_work(ci->wq, &ci->work);
-			ret = IRQ_HANDLED;
-		}
+	if (ci->role != CI_ROLE_END)
+		ret = ci_role(ci)->irq(ci);
+
+	if (ci->is_otg && (otgsc & OTGSC_IDIS)) {
+		hw_write(ci, OP_OTGSC, OTGSC_IDIS, OTGSC_IDIS);
+		disable_irq_nosync(ci->irq);
+		queue_work(ci->wq, &ci->work);
+		ret = IRQ_HANDLED;
 	}
 
-	return ci->role == CI_ROLE_END ? ret : ci_role(ci)->irq(ci);
+	return ret;
 }
 
 static DEFINE_IDA(ci_ida);
Signature · 1 line
1.7.9.5
#37 lore raw

v2 cover chipidea/imx: add otg support and some bug fix

In reply to Richard Zhao
Quoted 27 lines · Richard Zhao

The patch set is tested on imx6q_sabrelite board.

The patch can also be found at
https://github.com/riczhao/kernel-imx/commits/topics/usb-driver

For test which merged platform patches:
https://github.com/riczhao/kernel-imx/commits/topics/usb-test

Changes since v1:
- move usbmisc as the other patch series.
- remove regulater_disable and old comments in ci13xxx_imx.

Richard Zhao (11):
USB: chipidea: imx: add pinctrl support
USB: chipidea: delay 2ms before read ID status at probe time
USB: chipidea: move OTGSC_IDIS clearing from ci_role_work to irq
handler
USB: chipidea: clear gadget struct at udc_start fail path
USB: chipidea: don't let probe fail if otg controller start one role
failed
USB: mxs-phy: add basic otg support
USB: chipidea: add vbus detect for udc
USB: chipidea: convert to use devm_request_irq
USB: chipidea: add -DDEBUG if CONFIG_USB_CHIPIDEA_DEBUG
USB: chipidea: add set_vbus_power support
USB: chipidea: re-order irq handling to avoid unhandled irq

Quoted 9 lines
 drivers/usb/chipidea/Makefile      |    2 ++
 drivers/usb/chipidea/ci.h          |    1 +
 drivers/usb/chipidea/ci13xxx_imx.c |   51 +++++++++++++++++++++++-------------
 drivers/usb/chipidea/core.c        |   36 +++++++++++++++----------
 drivers/usb/chipidea/host.c        |    8 ++++++
 drivers/usb/chipidea/udc.c         |   40 +++++++++++++++++++++++++++-
 drivers/usb/otg/mxs-phy.c          |   21 +++++++++++++++
 include/linux/usb/chipidea.h       |    2 ++
 8 files changed, 128 insertions(+), 33 deletions(-)

Can this series be applied?

Marc

Signature · 12 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 259 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20120905/d49d5c65/attachment-0001.sig>
#38 lore raw

v2 cover chipidea/imx: add otg support and some bug fix

In reply to Richard Zhao
Quoted 27 lines · Richard Zhao

The patch set is tested on imx6q_sabrelite board.

The patch can also be found at
https://github.com/riczhao/kernel-imx/commits/topics/usb-driver

For test which merged platform patches:
https://github.com/riczhao/kernel-imx/commits/topics/usb-test

Changes since v1:
- move usbmisc as the other patch series.
- remove regulater_disable and old comments in ci13xxx_imx.

Richard Zhao (11):
USB: chipidea: imx: add pinctrl support
USB: chipidea: delay 2ms before read ID status at probe time
USB: chipidea: move OTGSC_IDIS clearing from ci_role_work to irq
handler
USB: chipidea: clear gadget struct at udc_start fail path
USB: chipidea: don't let probe fail if otg controller start one role
failed
USB: mxs-phy: add basic otg support
USB: chipidea: add vbus detect for udc
USB: chipidea: convert to use devm_request_irq
USB: chipidea: add -DDEBUG if CONFIG_USB_CHIPIDEA_DEBUG
USB: chipidea: add set_vbus_power support
USB: chipidea: re-order irq handling to avoid unhandled irq

Quoted 9 lines
 drivers/usb/chipidea/Makefile      |    2 ++
 drivers/usb/chipidea/ci.h          |    1 +
 drivers/usb/chipidea/ci13xxx_imx.c |   51 +++++++++++++++++++++++-------------
 drivers/usb/chipidea/core.c        |   36 +++++++++++++++----------
 drivers/usb/chipidea/host.c        |    8 ++++++
 drivers/usb/chipidea/udc.c         |   40 +++++++++++++++++++++++++++-
 drivers/usb/otg/mxs-phy.c          |   21 +++++++++++++++
 include/linux/usb/chipidea.h       |    2 ++
 8 files changed, 128 insertions(+), 33 deletions(-)

To get this series applied, probably patch 04/11 and 05/11 should just be dropped for now.

Michael