[PATCH] sunxi:usb: Fix otg usb mode selection

377 views
Skip to first unread message

Alexsey Shestacov

unread,
Sep 2, 2013, 6:04:29 PM9/2/13
to d...@linux-sunxi.org, Alexsey Shestacov
OTG+Host mode was not workable due lack defines for code
this patch fixes it
OTG only mode was not buildable , this patch only fixes building

Signed-off-by: Alexsey Shestacov <wing...@linux-sunxi.org>
---
drivers/usb/gadget/Kconfig | 1 +
drivers/usb/sunxi_usb/Kconfig | 25 ++++++++++++++++-------
drivers/usb/sunxi_usb/hcd/core/sw_hcd_core.c | 4 ++++
drivers/usb/sunxi_usb/manager/usb_hcd_servers.c | 4 ++--
drivers/usb/sunxi_usb/manager/usb_msg_center.c | 18 ++++++++++------
5 files changed, 37 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 8bd50b6..7c5bdee 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -547,6 +547,7 @@ endchoice
config USB_SW_SUNXI_UDC0
bool
depends on USB_SW_SUNXI_USB_MANAGER
+ select USB_SW_SUNXI_USB0_OTG


# Selected by UDC drivers that support high-speed operation.
diff --git a/drivers/usb/sunxi_usb/Kconfig b/drivers/usb/sunxi_usb/Kconfig
index 013441e..a881653 100644
--- a/drivers/usb/sunxi_usb/Kconfig
+++ b/drivers/usb/sunxi_usb/Kconfig
@@ -18,6 +18,15 @@ config USB_SW_SUNXI_USB_MANAGER
depends on USB_SW_SUNXI_USB
help
manager all usb controller.
+#
+# Workaround, fix request massive define remake
+#
+
+config USB_SW_SUNXI_USB0_OTG
+ boolean "SoftWinner SUNXI USB HCD0 OTG Support"
+ depends on USB_SW_SUNXI_UDC0
+ help
+ SoftWinner SUNXI USB2.0 Host Controller0, OTG port

#---------------------------------------------
#-
@@ -28,6 +37,7 @@ choice

prompt "USB0 Controller support"
depends on (USB_SW_SUNXI_USB && USB_SW_SUNXI_USB_MANAGER)
+ default USB_SW_SUNXI_USB0_OTG
help
usb0 Controller mode select. choice "device only", then usb0 can only use for device.
choice "host only", then usb0 can only use for host. choice "OTG", then usb0 can only
@@ -37,21 +47,22 @@ choice
SUNXI USB Peripheral Controller", enabled under USB gadget config.

config USB_SW_SUNXI_USB0_HOST_ONLY
- boolean "host only support"
+ boolean "Host only mode"
select USB_SW_SUNXI_HCD0
help
usb0 can only use for host.

-config USB_SW_SUNXI_USB0_OTG
- boolean "otg support"
- depends on USB_SW_SUNXI_UDC0
+config USB_SW_SUNXI_USB0_OTG_AND_HOST
+ boolean "OTG and Host mode"
+ select USB_SW_SUNXI_UDC0
select USB_SW_SUNXI_HCD0
help
- usb0 can only use for device and host.
+ usb0 can use for device and host.

config USB_SW_SUNXI_USB0_DEVICE_ONLY
- boolean "device only support"
- depends on USB_SW_SUNXI_UDC0
+ boolean "OTG only mode"
+ select USB_SW_SUNXI_UDC0
+ select USB_SW_SUNXI_USB0_OTG
help
usb0 can only use for device.

diff --git a/drivers/usb/sunxi_usb/hcd/core/sw_hcd_core.c b/drivers/usb/sunxi_usb/hcd/core/sw_hcd_core.c
index f8a8366..aaf8910 100644
--- a/drivers/usb/sunxi_usb/hcd/core/sw_hcd_core.c
+++ b/drivers/usb/sunxi_usb/hcd/core/sw_hcd_core.c
@@ -811,7 +811,9 @@ static irqreturn_t sw_hcd_stage0_irq(struct sw_hcd *sw_hcd, u8 int_usb, u8 devct
struct usb_hcd *hcd = sw_hcd_to_hcd(sw_hcd);

DMSG_INFO("\n------------IRQ CONNECT-------------\n\n");
+#ifdef CONFIG_USB_SW_SUNXI_HCD0
set_hcd0_connect_status(1);
+#endif
USBC_INT_ClearMiscPending(sw_hcd->sw_hcd_io->usb_bsp_hdle, (1 << USBC_BP_INTUSB_CONNECT));

handled = IRQ_HANDLED;
@@ -928,7 +930,9 @@ static irqreturn_t sw_hcd_stage2_irq(struct sw_hcd *sw_hcd,

if ((int_usb & (1 << USBC_BP_INTUSB_DISCONNECT)) && !sw_hcd->ignore_disconnect) {
DMSG_INFO("\n------------IRQ DISCONNECT-------------\n\n");
+#ifdef CONFIG_USB_SW_SUNXI_HDD0
set_hcd0_connect_status(0);
+#endif
USBC_INT_ClearMiscPending(sw_hcd->sw_hcd_io->usb_bsp_hdle, (1 << USBC_BP_INTUSB_DISCONNECT));

handled = IRQ_HANDLED;
diff --git a/drivers/usb/sunxi_usb/manager/usb_hcd_servers.c b/drivers/usb/sunxi_usb/manager/usb_hcd_servers.c
index 7034e2d..64f6a69 100644
--- a/drivers/usb/sunxi_usb/manager/usb_hcd_servers.c
+++ b/drivers/usb/sunxi_usb/manager/usb_hcd_servers.c
@@ -54,7 +54,7 @@ static enum sw_usbc_type controller_type = SW_USB_EHCI;
int sw_usb_disable_hcd(__u32 usbc_no)
{
if (usbc_no == 0) {
-#if defined(CONFIG_USB_SW_SUNXI_USB0_OTG) || defined(USB_SW_SUNXI_USB0_HOST_ONLY)
+#ifdef CONFIG_USB_SW_SUNXI_HCD0
sw_usb_disable_hcd0();
#endif
} else if (usbc_no == 1 || usbc_no == 2) {
@@ -113,7 +113,7 @@ int sw_usb_enable_hcd(__u32 usbc_no)
"usb_controller_type failed\n");

if (usbc_no == 0) {
-#if defined(CONFIG_USB_SW_SUNXI_USB0_OTG) || defined(USB_SW_SUNXI_USB0_HOST_ONLY)
+#ifdef CONFIG_USB_SW_SUNXI_HDC0
sw_usb_enable_hcd0();
#endif
} else if (usbc_no == 1 || usbc_no == 2) {
diff --git a/drivers/usb/sunxi_usb/manager/usb_msg_center.c b/drivers/usb/sunxi_usb/manager/usb_msg_center.c
index 9451beb..b06fdd3 100644
--- a/drivers/usb/sunxi_usb/manager/usb_msg_center.c
+++ b/drivers/usb/sunxi_usb/manager/usb_msg_center.c
@@ -171,11 +171,14 @@ static void modify_msg(struct usb_msg *msg)
*/
static void insmod_host_driver(struct usb_msg_center_info *center_info)
{
- DMSG_INFO("\n\ninsmod_host_driver\n\n");

+#ifdef CONFIG_USB_SW_SUNXI_HCD0
+ DMSG_INFO("insmod_host_driver\n");
set_usb_role(center_info, USB_ROLE_HOST);
sw_usb_host0_enable();
-
+#else
+ DMSG_INFO("IGNORE -host driver not builded within currect kernel.\n");
+#endif
return;
}

@@ -199,18 +202,21 @@ static void insmod_host_driver(struct usb_msg_center_info *center_info)
*/
static void rmmod_host_driver(struct usb_msg_center_info *center_info)
{
- int ret = 0;
-
- DMSG_INFO("\n\nrmmod_host_driver\n\n");
+#ifdef CONFIG_USB_SW_SUNXI_HCD0
+ int ret = 0;
+ DMSG_INFO("rmmod_host_driver\n");

ret = sw_usb_host0_disable();
if(ret != 0){
DMSG_PANIC("err: disable hcd0 failed\n");
return;
}
-
set_usb_role(center_info, USB_ROLE_NULL);

+#else
+ DMSG_INFO("IGNORE - Host driver not builed in\n");
+#endif
+
return;
}
/*
--
1.7.10.4

Hans de Goede

unread,
Sep 3, 2013, 3:45:45 AM9/3/13
to linux...@googlegroups.com, Alexsey Shestacov, d...@linux-sunxi.org, Alexsey Shestacov
Hi Alexsey,

I believe this patch is against 3.0, correct ?

Thanks & Regards,

Hans

Jari Helaakoski

unread,
Sep 4, 2013, 4:13:15 PM9/4/13
to linux...@googlegroups.com, d...@linux-sunxi.org, Alexsey Shestacov



2013/9/3 Alexsey Shestacov <wing...@gmail.com>

OTG+Host mode was not workable due lack defines for code
this patch fixes it
OTG only mode was not buildable , this patch only fixes building

I think this patch is not needed. I verified OTG with a13 with following diff: I'll send patch later.

@@ -2416,14 +2416,12 @@ static struct platform_driver sw_hcd_driver = {
 *******************************************************************************
 */
 static int __init sw_hcd_init(void)
 {
  DMSG_INFO_HCD0("usb host driver initialize........\n");
-#ifdef CONFIG_USB_PORT_POWER_MANAGEMENT
  hcd0_set_vbus_cnt--;
  hcd0_enable--;
-#endif
     if (usb_disabled()){
         DMSG_PANIC("ERR: usb disabled\n");
  return 0;
  }
 
-Jari

 

Jari Helaakoski

unread,
Sep 4, 2013, 4:24:57 PM9/4/13
to linux...@googlegroups.com, d...@linux-sunxi.org, Alexsey Shestacov



2013/9/4 Jari Helaakoski <tek...@gmail.com>
Hmm.. sorry. This diff fixes host mode only. OTG seems to be having other problems. 

-Jari

Jari Helaakoski

unread,
Sep 6, 2013, 6:45:25 PM9/6/13
to linux...@googlegroups.com
Hi,

This is my quick review. Wouldn't it be easier to just post config change, since it looks like we are not supporting "make oldconfig".

2013/9/3 Alexsey Shestacov <wing...@gmail.com>

OTG+Host mode was not workable due lack defines for code
this patch fixes it
OTG only mode was not buildable , this patch only fixes building

Signed-off-by: Alexsey Shestacov <wing...@linux-sunxi.org>
---
 drivers/usb/gadget/Kconfig                      |    1 +
 drivers/usb/sunxi_usb/Kconfig                   |   25 ++++++++++++++++-------
 drivers/usb/sunxi_usb/hcd/core/sw_hcd_core.c    |    4 ++++
 drivers/usb/sunxi_usb/manager/usb_hcd_servers.c |    4 ++--
 drivers/usb/sunxi_usb/manager/usb_msg_center.c  |   18 ++++++++++------
 5 files changed, 37 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 8bd50b6..7c5bdee 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -547,6 +547,7 @@ endchoice
 config USB_SW_SUNXI_UDC0
        bool
        depends on USB_SW_SUNXI_USB_MANAGER
+       select USB_SW_SUNXI_USB0_OTG

OTG == UDC + HCD , so this line is wrong when user wants to select UDC only.
OTG == UDC(device mode) + HCD(host mode) , so mentioning host separetly is senseless

+    boolean "OTG and Host mode"
+    select USB_SW_SUNXI_UDC0
     select USB_SW_SUNXI_HCD0
     help
-        usb0 can only use for device and host.
+        usb0 can use for device and host.

 config USB_SW_SUNXI_USB0_DEVICE_ONLY
-    boolean "device only support"
-    depends on USB_SW_SUNXI_UDC0
+    boolean "OTG only mode"
There is already selection for OTG.
 
+    select USB_SW_SUNXI_UDC0
+    select USB_SW_SUNXI_USB0_OTG
     help
         usb0 can only use for device.

diff --git a/drivers/usb/sunxi_usb/hcd/core/sw_hcd_core.c b/drivers/usb/sunxi_usb/hcd/core/sw_hcd_core.c
index f8a8366..aaf8910 100644
--- a/drivers/usb/sunxi_usb/hcd/core/sw_hcd_core.c
+++ b/drivers/usb/sunxi_usb/hcd/core/sw_hcd_core.c
@@ -811,7 +811,9 @@ static irqreturn_t sw_hcd_stage0_irq(struct sw_hcd *sw_hcd, u8 int_usb, u8 devct
                struct usb_hcd *hcd = sw_hcd_to_hcd(sw_hcd);

                DMSG_INFO("\n------------IRQ CONNECT-------------\n\n");
+#ifdef CONFIG_USB_SW_SUNXI_HCD0
                set_hcd0_connect_status(1);
+#endif
                USBC_INT_ClearMiscPending(sw_hcd->sw_hcd_io->usb_bsp_hdle, (1 << USBC_BP_INTUSB_CONNECT));

                handled = IRQ_HANDLED;
@@ -928,7 +930,9 @@ static irqreturn_t sw_hcd_stage2_irq(struct sw_hcd *sw_hcd,

        if ((int_usb & (1 << USBC_BP_INTUSB_DISCONNECT)) && !sw_hcd->ignore_disconnect) {
                DMSG_INFO("\n------------IRQ DISCONNECT-------------\n\n");
+#ifdef CONFIG_USB_SW_SUNXI_HDD0
HDD0 Typo.
 
--
1.7.10.4

--
You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages