[U-Boot] [PATCH 1/3] usb: host: ehci-vf: Remove hardcoded USB host client configuration

The current ehci-vf USB driver for Vybrid hardcodes the USB host and client functionality. Remove this.
Reported-by: Santhosh Kumar Janardhanam santhosh.kj@hcl.com Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com --- drivers/usb/host/ehci-vf.c | 5 ----- 1 file changed, 5 deletions(-)
diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c index 98e0fc6..351e0fb 100644 --- a/drivers/usb/host/ehci-vf.c +++ b/drivers/usb/host/ehci-vf.c @@ -134,11 +134,6 @@ int ehci_hcd_init(int index, enum usb_init_type init, if (index >= ARRAY_SIZE(nc_reg_bases)) return -EINVAL;
- if (init == USB_INIT_DEVICE && index == 1) - return -ENODEV; - if (init == USB_INIT_HOST && index == 0) - return -ENODEV; - ehci = (struct usb_ehci *)nc_reg_bases[index];
/* Do board specific initialisation */

Add board_usb_phy_mode weak function on similar lines to ehci-mx6. However since Vybrid USB does not have a true OTG, make this weak functon just return 0. The function is supposed to be implemented by the individual boards using a GPIO for providing the OTG pin functionality.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com --- There seems to be a problem here. As per DFU's help note, the first argument to dfu is the USB controller.
So if dfu 1 nand 2 is run, I would expect the ehci_hcd_init function's first index argument to recieve 1. However this does not seem to be the case. Not sure if I am understanding something wrongly here. Is this expected?
Currently because of this even though I did like dfu 1 nand 2 to bail out, it does not. I tried tracing the code from do_dfu but I have yet to get from where ehci_hcd_init is getting called in the call chain.
All seems to be well when using usb start.
--- drivers/usb/host/ehci-vf.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c index 351e0fb..335e303 100644 --- a/drivers/usb/host/ehci-vf.c +++ b/drivers/usb/host/ehci-vf.c @@ -121,6 +121,11 @@ static void usb_oc_config(int index) setbits_le32(ctrl, UCTRL_OVER_CUR_DIS); }
+int __weak board_usb_phy_mode(int port) +{ + return 0; +} + int __weak board_ehci_hcd_init(int port) { return 0; @@ -130,6 +135,7 @@ int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr, struct ehci_hcor **hcor) { struct usb_ehci *ehci; + enum usb_init_type type;
if (index >= ARRAY_SIZE(nc_reg_bases)) return -EINVAL; @@ -148,6 +154,10 @@ int ehci_hcd_init(int index, enum usb_init_type init, *hcor = (struct ehci_hcor *)((uint32_t)*hccr + HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
+ type = board_usb_phy_mode(index); + if (type != init) + return -ENODEV; + if (init == USB_INIT_DEVICE) { setbits_le32(&ehci->usbmode, CM_DEVICE); writel((PORT_PTS_UTMI | PORT_PTS_PTW), &ehci->portsc);

Hello Stefano / Marek,
Can you pick this up?
- Sanchayan.
On 15-10-26 18:28:50, Sanchayan Maity wrote:
Add board_usb_phy_mode weak function on similar lines to ehci-mx6. However since Vybrid USB does not have a true OTG, make this weak functon just return 0. The function is supposed to be implemented by the individual boards using a GPIO for providing the OTG pin functionality.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com
There seems to be a problem here. As per DFU's help note, the first argument to dfu is the USB controller.
So if dfu 1 nand 2 is run, I would expect the ehci_hcd_init function's first index argument to recieve 1. However this does not seem to be the case. Not sure if I am understanding something wrongly here. Is this expected?
Currently because of this even though I did like dfu 1 nand 2 to bail out, it does not. I tried tracing the code from do_dfu but I have yet to get from where ehci_hcd_init is getting called in the call chain.
All seems to be well when using usb start.
drivers/usb/host/ehci-vf.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c index 351e0fb..335e303 100644 --- a/drivers/usb/host/ehci-vf.c +++ b/drivers/usb/host/ehci-vf.c @@ -121,6 +121,11 @@ static void usb_oc_config(int index) setbits_le32(ctrl, UCTRL_OVER_CUR_DIS); }
+int __weak board_usb_phy_mode(int port) +{
- return 0;
+}
int __weak board_ehci_hcd_init(int port) { return 0; @@ -130,6 +135,7 @@ int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr, struct ehci_hcor **hcor) { struct usb_ehci *ehci;
enum usb_init_type type;
if (index >= ARRAY_SIZE(nc_reg_bases)) return -EINVAL;
@@ -148,6 +154,10 @@ int ehci_hcd_init(int index, enum usb_init_type init, *hcor = (struct ehci_hcor *)((uint32_t)*hccr + HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
- type = board_usb_phy_mode(index);
- if (type != init)
return -ENODEV;
- if (init == USB_INIT_DEVICE) { setbits_le32(&ehci->usbmode, CM_DEVICE); writel((PORT_PTS_UTMI | PORT_PTS_PTW), &ehci->portsc);
-- 2.6.2

Add board_usb_phy_mode function for detecting whether a port is being used as host or client using a GPIO. On Colibri Vybrid we provide the GPIO 102 for the very same purpose.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com --- board/toradex/colibri_vf/colibri_vf.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/board/toradex/colibri_vf/colibri_vf.c b/board/toradex/colibri_vf/colibri_vf.c index a6d1c5b..fd90ef2 100644 --- a/board/toradex/colibri_vf/colibri_vf.c +++ b/board/toradex/colibri_vf/colibri_vf.c @@ -34,6 +34,7 @@ DECLARE_GLOBAL_DATA_PTR; PAD_CTL_DSE_50ohm | PAD_CTL_OBE_IBE_ENABLE)
#define USB_PEN_GPIO 83 +#define USB_CDET_GPIO 102
static struct ddrmc_cr_setting colibri_vf_cr_settings[] = { /* levelling */ @@ -92,6 +93,7 @@ static struct ddrmc_cr_setting colibri_vf_cr_settings[] = {
static const iomux_v3_cfg_t usb_pads[] = { VF610_PAD_PTD4__GPIO_83, + VF610_PAD_PTC29__GPIO_102, };
int dram_init(void) @@ -280,7 +282,6 @@ static void setup_iomux_gpio(void) VF610_PAD_PTB23__GPIO_93, VF610_PAD_PTB26__GPIO_96, VF610_PAD_PTB28__GPIO_98, - VF610_PAD_PTC29__GPIO_102, VF610_PAD_PTC30__GPIO_103, VF610_PAD_PTA7__GPIO_134, }; @@ -554,4 +555,20 @@ int board_ehci_hcd_init(int port) } return 0; } + +int board_usb_phy_mode(int port) +{ + switch (port) { + case 0: + gpio_request(USB_CDET_GPIO, "usb-cdet-gpio"); + return gpio_get_value(USB_CDET_GPIO); + break; + case 1: + return 0; + break; + default: + return 0; + break; + } +} #endif

On Monday, October 26, 2015 at 01:58:51 PM, Sanchayan Maity wrote:
Add board_usb_phy_mode function for detecting whether a port is being used as host or client using a GPIO. On Colibri Vybrid we provide the GPIO 102 for the very same purpose.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com
board/toradex/colibri_vf/colibri_vf.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/board/toradex/colibri_vf/colibri_vf.c b/board/toradex/colibri_vf/colibri_vf.c index a6d1c5b..fd90ef2 100644 --- a/board/toradex/colibri_vf/colibri_vf.c +++ b/board/toradex/colibri_vf/colibri_vf.c @@ -34,6 +34,7 @@ DECLARE_GLOBAL_DATA_PTR; PAD_CTL_DSE_50ohm | PAD_CTL_OBE_IBE_ENABLE)
#define USB_PEN_GPIO 83 +#define USB_CDET_GPIO 102
static struct ddrmc_cr_setting colibri_vf_cr_settings[] = { /* levelling */ @@ -92,6 +93,7 @@ static struct ddrmc_cr_setting colibri_vf_cr_settings[] = {
static const iomux_v3_cfg_t usb_pads[] = { VF610_PAD_PTD4__GPIO_83,
- VF610_PAD_PTC29__GPIO_102,
};
int dram_init(void) @@ -280,7 +282,6 @@ static void setup_iomux_gpio(void) VF610_PAD_PTB23__GPIO_93, VF610_PAD_PTB26__GPIO_96, VF610_PAD_PTB28__GPIO_98,
VF610_PAD_PTC30__GPIO_103, VF610_PAD_PTA7__GPIO_134, };VF610_PAD_PTC29__GPIO_102,
@@ -554,4 +555,20 @@ int board_ehci_hcd_init(int port) } return 0; }
+int board_usb_phy_mode(int port) +{
- switch (port) {
- case 0:
gpio_request(USB_CDET_GPIO, "usb-cdet-gpio");
The gpio_request() here will fail the second time you do "usb reset" on the command line I think. You might want to request this elsewhere.
return gpio_get_value(USB_CDET_GPIO);
break;
- case 1:
return 0;
break;
- default:
return 0;
break;
- }
+} #endif
Best regards, Marek Vasut

On 15-10-27 10:18:47, Marek Vasut wrote:
On Monday, October 26, 2015 at 01:58:51 PM, Sanchayan Maity wrote:
Add board_usb_phy_mode function for detecting whether a port is being used as host or client using a GPIO. On Colibri Vybrid we provide the GPIO 102 for the very same purpose.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com
board/toradex/colibri_vf/colibri_vf.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/board/toradex/colibri_vf/colibri_vf.c b/board/toradex/colibri_vf/colibri_vf.c index a6d1c5b..fd90ef2 100644 --- a/board/toradex/colibri_vf/colibri_vf.c +++ b/board/toradex/colibri_vf/colibri_vf.c @@ -34,6 +34,7 @@ DECLARE_GLOBAL_DATA_PTR; PAD_CTL_DSE_50ohm | PAD_CTL_OBE_IBE_ENABLE)
#define USB_PEN_GPIO 83 +#define USB_CDET_GPIO 102
static struct ddrmc_cr_setting colibri_vf_cr_settings[] = { /* levelling */ @@ -92,6 +93,7 @@ static struct ddrmc_cr_setting colibri_vf_cr_settings[] = {
static const iomux_v3_cfg_t usb_pads[] = { VF610_PAD_PTD4__GPIO_83,
- VF610_PAD_PTC29__GPIO_102,
};
int dram_init(void) @@ -280,7 +282,6 @@ static void setup_iomux_gpio(void) VF610_PAD_PTB23__GPIO_93, VF610_PAD_PTB26__GPIO_96, VF610_PAD_PTB28__GPIO_98,
VF610_PAD_PTC30__GPIO_103, VF610_PAD_PTA7__GPIO_134, };VF610_PAD_PTC29__GPIO_102,
@@ -554,4 +555,20 @@ int board_ehci_hcd_init(int port) } return 0; }
+int board_usb_phy_mode(int port) +{
- switch (port) {
- case 0:
gpio_request(USB_CDET_GPIO, "usb-cdet-gpio");
The gpio_request() here will fail the second time you do "usb reset" on the command line I think. You might want to request this elsewhere.
Hmmm makes sense. I did not try usb reset. Only usb start stop and dfu cmds. Will check and revert back accordingly.
Thanks.
- Sanchayan.
return gpio_get_value(USB_CDET_GPIO);
break;
- case 1:
return 0;
break;
- default:
return 0;
break;
- }
+} #endif
Best regards, Marek Vasut

Add board_usb_phy_mode function for detecting whether a port is being used as host or client using a GPIO. On Colibri Vybrid we provide the GPIO 102 for this very same purpose.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com --- Changes since v1:
Move the GPIO request call to the board_init function as all further calls to board_usb_phy_mode will actually result in the gpio_request failing.
--- board/toradex/colibri_vf/colibri_vf.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/board/toradex/colibri_vf/colibri_vf.c b/board/toradex/colibri_vf/colibri_vf.c index a6d1c5b..69274e5 100644 --- a/board/toradex/colibri_vf/colibri_vf.c +++ b/board/toradex/colibri_vf/colibri_vf.c @@ -34,6 +34,7 @@ DECLARE_GLOBAL_DATA_PTR; PAD_CTL_DSE_50ohm | PAD_CTL_OBE_IBE_ENABLE)
#define USB_PEN_GPIO 83 +#define USB_CDET_GPIO 102
static struct ddrmc_cr_setting colibri_vf_cr_settings[] = { /* levelling */ @@ -92,6 +93,7 @@ static struct ddrmc_cr_setting colibri_vf_cr_settings[] = {
static const iomux_v3_cfg_t usb_pads[] = { VF610_PAD_PTD4__GPIO_83, + VF610_PAD_PTC29__GPIO_102, };
int dram_init(void) @@ -280,7 +282,6 @@ static void setup_iomux_gpio(void) VF610_PAD_PTB23__GPIO_93, VF610_PAD_PTB26__GPIO_96, VF610_PAD_PTB28__GPIO_98, - VF610_PAD_PTC29__GPIO_102, VF610_PAD_PTC30__GPIO_103, VF610_PAD_PTA7__GPIO_134, }; @@ -509,6 +510,10 @@ int board_init(void)
setbits_le32(&scsc->sosc_ctr, SCSC_SOSC_CTR_SOSC_EN);
+#ifdef CONFIG_USB_EHCI_VF + gpio_request(USB_CDET_GPIO, "usb-cdet-gpio"); +#endif + return 0; }
@@ -554,4 +559,19 @@ int board_ehci_hcd_init(int port) } return 0; } + +int board_usb_phy_mode(int port) +{ + switch (port) { + case 0: + return gpio_get_value(USB_CDET_GPIO); + break; + case 1: + return 0; + break; + default: + return 0; + break; + } +} #endif

On Thursday, October 29, 2015 at 11:15:24 AM, Sanchayan Maity wrote:
Add board_usb_phy_mode function for detecting whether a port is being used as host or client using a GPIO. On Colibri Vybrid we provide the GPIO 102 for this very same purpose.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com
Hi!
[...]
@@ -554,4 +559,19 @@ int board_ehci_hcd_init(int port) } return 0; }
+int board_usb_phy_mode(int port) +{
- switch (port) {
- case 0:
return gpio_get_value(USB_CDET_GPIO);
break;
- case 1:
return 0;
This should return USB_INIT_DEVICE or USB_INIT_HOST .
break;
- default:
return 0;
break;
- }
+} #endif
Best regards, Marek Vasut

Add board_usb_phy_mode function for detecting whether a port is being used as host or client using a GPIO. On Colibri Vybrid we provide the GPIO 102 for this very same purpose.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com --- Changes since v1:
Move the GPIO request call to the board_init function as all further calls to board_usb_phy_mode will actually result in the gpio_request failing.
Changes since v2:
Instead of returning 0 from board_usb_phy_mode return it as USB_INIT_HOST. --- board/toradex/colibri_vf/colibri_vf.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/board/toradex/colibri_vf/colibri_vf.c b/board/toradex/colibri_vf/colibri_vf.c index a6d1c5b..9878671 100644 --- a/board/toradex/colibri_vf/colibri_vf.c +++ b/board/toradex/colibri_vf/colibri_vf.c @@ -21,6 +21,7 @@ #include <i2c.h> #include <g_dnl.h> #include <asm/gpio.h> +#include <usb.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -34,6 +35,7 @@ DECLARE_GLOBAL_DATA_PTR; PAD_CTL_DSE_50ohm | PAD_CTL_OBE_IBE_ENABLE)
#define USB_PEN_GPIO 83 +#define USB_CDET_GPIO 102
static struct ddrmc_cr_setting colibri_vf_cr_settings[] = { /* levelling */ @@ -92,6 +94,7 @@ static struct ddrmc_cr_setting colibri_vf_cr_settings[] = {
static const iomux_v3_cfg_t usb_pads[] = { VF610_PAD_PTD4__GPIO_83, + VF610_PAD_PTC29__GPIO_102, };
int dram_init(void) @@ -280,7 +283,6 @@ static void setup_iomux_gpio(void) VF610_PAD_PTB23__GPIO_93, VF610_PAD_PTB26__GPIO_96, VF610_PAD_PTB28__GPIO_98, - VF610_PAD_PTC29__GPIO_102, VF610_PAD_PTC30__GPIO_103, VF610_PAD_PTA7__GPIO_134, }; @@ -509,6 +511,10 @@ int board_init(void)
setbits_le32(&scsc->sosc_ctr, SCSC_SOSC_CTR_SOSC_EN);
+#ifdef CONFIG_USB_EHCI_VF + gpio_request(USB_CDET_GPIO, "usb-cdet-gpio"); +#endif + return 0; }
@@ -554,4 +560,19 @@ int board_ehci_hcd_init(int port) } return 0; } + +int board_usb_phy_mode(int port) +{ + switch (port) { + case 0: + return gpio_get_value(USB_CDET_GPIO); + break; + case 1: + return USB_INIT_HOST; + break; + default: + return USB_INIT_HOST; + break; + } +} #endif

On Friday, October 30, 2015 at 01:26:59 PM, Sanchayan Maity wrote:
Add board_usb_phy_mode function for detecting whether a port is being used as host or client using a GPIO. On Colibri Vybrid we provide the GPIO 102 for this very same purpose.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com
Changes since v1:
Move the GPIO request call to the board_init function as all further calls to board_usb_phy_mode will actually result in the gpio_request failing.
Changes since v2:
Instead of returning 0 from board_usb_phy_mode return it as USB_INIT_HOST.
board/toradex/colibri_vf/colibri_vf.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/board/toradex/colibri_vf/colibri_vf.c b/board/toradex/colibri_vf/colibri_vf.c index a6d1c5b..9878671 100644 --- a/board/toradex/colibri_vf/colibri_vf.c +++ b/board/toradex/colibri_vf/colibri_vf.c @@ -21,6 +21,7 @@ #include <i2c.h> #include <g_dnl.h> #include <asm/gpio.h> +#include <usb.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -34,6 +35,7 @@ DECLARE_GLOBAL_DATA_PTR; PAD_CTL_DSE_50ohm | PAD_CTL_OBE_IBE_ENABLE)
#define USB_PEN_GPIO 83 +#define USB_CDET_GPIO 102
static struct ddrmc_cr_setting colibri_vf_cr_settings[] = { /* levelling */ @@ -92,6 +94,7 @@ static struct ddrmc_cr_setting colibri_vf_cr_settings[] = {
static const iomux_v3_cfg_t usb_pads[] = { VF610_PAD_PTD4__GPIO_83,
- VF610_PAD_PTC29__GPIO_102,
};
int dram_init(void) @@ -280,7 +283,6 @@ static void setup_iomux_gpio(void) VF610_PAD_PTB23__GPIO_93, VF610_PAD_PTB26__GPIO_96, VF610_PAD_PTB28__GPIO_98,
VF610_PAD_PTC30__GPIO_103, VF610_PAD_PTA7__GPIO_134, };VF610_PAD_PTC29__GPIO_102,
@@ -509,6 +511,10 @@ int board_init(void)
setbits_le32(&scsc->sosc_ctr, SCSC_SOSC_CTR_SOSC_EN);
+#ifdef CONFIG_USB_EHCI_VF
- gpio_request(USB_CDET_GPIO, "usb-cdet-gpio");
+#endif
- return 0;
}
@@ -554,4 +560,19 @@ int board_ehci_hcd_init(int port) } return 0; }
+int board_usb_phy_mode(int port) +{
- switch (port) {
- case 0:
return gpio_get_value(USB_CDET_GPIO);
So what would happen to this code in case we re-number the USB_INIT_HOST and USB_INIT_DEVICE or in case the GPIO API starts returning something else but 0 or 1 here ?
break;
- case 1:
return USB_INIT_HOST;
break;
- default:
return USB_INIT_HOST;
break;
- }
+} #endif

On 15-10-30 14:20:29, Marek Vasut wrote:
On Friday, October 30, 2015 at 01:26:59 PM, Sanchayan Maity wrote:
Add board_usb_phy_mode function for detecting whether a port is being used as host or client using a GPIO. On Colibri Vybrid we provide the GPIO 102 for this very same purpose.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com
Changes since v1:
Move the GPIO request call to the board_init function as all further calls to board_usb_phy_mode will actually result in the gpio_request failing.
Changes since v2:
Instead of returning 0 from board_usb_phy_mode return it as USB_INIT_HOST.
board/toradex/colibri_vf/colibri_vf.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/board/toradex/colibri_vf/colibri_vf.c b/board/toradex/colibri_vf/colibri_vf.c index a6d1c5b..9878671 100644 --- a/board/toradex/colibri_vf/colibri_vf.c +++ b/board/toradex/colibri_vf/colibri_vf.c @@ -21,6 +21,7 @@ #include <i2c.h> #include <g_dnl.h> #include <asm/gpio.h> +#include <usb.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -34,6 +35,7 @@ DECLARE_GLOBAL_DATA_PTR; PAD_CTL_DSE_50ohm | PAD_CTL_OBE_IBE_ENABLE)
#define USB_PEN_GPIO 83 +#define USB_CDET_GPIO 102
static struct ddrmc_cr_setting colibri_vf_cr_settings[] = { /* levelling */ @@ -92,6 +94,7 @@ static struct ddrmc_cr_setting colibri_vf_cr_settings[] = {
static const iomux_v3_cfg_t usb_pads[] = { VF610_PAD_PTD4__GPIO_83,
- VF610_PAD_PTC29__GPIO_102,
};
int dram_init(void) @@ -280,7 +283,6 @@ static void setup_iomux_gpio(void) VF610_PAD_PTB23__GPIO_93, VF610_PAD_PTB26__GPIO_96, VF610_PAD_PTB28__GPIO_98,
VF610_PAD_PTC30__GPIO_103, VF610_PAD_PTA7__GPIO_134, };VF610_PAD_PTC29__GPIO_102,
@@ -509,6 +511,10 @@ int board_init(void)
setbits_le32(&scsc->sosc_ctr, SCSC_SOSC_CTR_SOSC_EN);
+#ifdef CONFIG_USB_EHCI_VF
- gpio_request(USB_CDET_GPIO, "usb-cdet-gpio");
+#endif
- return 0;
}
@@ -554,4 +560,19 @@ int board_ehci_hcd_init(int port) } return 0; }
+int board_usb_phy_mode(int port) +{
- switch (port) {
- case 0:
return gpio_get_value(USB_CDET_GPIO);
So what would happen to this code in case we re-number the USB_INIT_HOST and USB_INIT_DEVICE or in case the GPIO API starts returning something else but 0 or 1 here ?
Sorry for the delay in reply. Had got tied up elsewhere.
Currently USB_INIT_HOST and USB_INIT_DEVICE are defined with an enum. If we were to switch this would not work as I intended. I guess this would be more appropriate then
if (gpio_get_value(USB_CDET_GPIO)) return USB_INIT_DEVICE; else return USB_INIT_HOST;
For the GPIO, isn't gpio_get_value always suppose to return the actual state of GPIO? Would we ever change the GPIO API to report otherwise?
Concerning the other thread from Stefan's query I will add the comments.
Thanks.
- Sanchayan.
break;
- case 1:
return USB_INIT_HOST;
break;
- default:
return USB_INIT_HOST;
break;
- }
+} #endif

On Friday, November 06, 2015 at 08:00:01 AM, maitysanchayan@gmail.com wrote:
On 15-10-30 14:20:29, Marek Vasut wrote:
On Friday, October 30, 2015 at 01:26:59 PM, Sanchayan Maity wrote:
Add board_usb_phy_mode function for detecting whether a port is being used as host or client using a GPIO. On Colibri Vybrid we provide the GPIO 102 for this very same purpose.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com
Changes since v1:
Move the GPIO request call to the board_init function as all further calls to board_usb_phy_mode will actually result in the gpio_request failing.
Changes since v2:
Instead of returning 0 from board_usb_phy_mode return it as USB_INIT_HOST.
board/toradex/colibri_vf/colibri_vf.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/board/toradex/colibri_vf/colibri_vf.c b/board/toradex/colibri_vf/colibri_vf.c index a6d1c5b..9878671 100644 --- a/board/toradex/colibri_vf/colibri_vf.c +++ b/board/toradex/colibri_vf/colibri_vf.c @@ -21,6 +21,7 @@
#include <i2c.h> #include <g_dnl.h> #include <asm/gpio.h>
+#include <usb.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -34,6 +35,7 @@ DECLARE_GLOBAL_DATA_PTR;
PAD_CTL_DSE_50ohm | PAD_CTL_OBE_IBE_ENABLE)
#define USB_PEN_GPIO 83
+#define USB_CDET_GPIO 102
static struct ddrmc_cr_setting colibri_vf_cr_settings[] = {
/* levelling */
@@ -92,6 +94,7 @@ static struct ddrmc_cr_setting colibri_vf_cr_settings[] = {
static const iomux_v3_cfg_t usb_pads[] = {
VF610_PAD_PTD4__GPIO_83,
- VF610_PAD_PTC29__GPIO_102,
};
int dram_init(void)
@@ -280,7 +283,6 @@ static void setup_iomux_gpio(void)
VF610_PAD_PTB23__GPIO_93, VF610_PAD_PTB26__GPIO_96, VF610_PAD_PTB28__GPIO_98,
VF610_PAD_PTC29__GPIO_102,
VF610_PAD_PTC30__GPIO_103, VF610_PAD_PTA7__GPIO_134,
};
@@ -509,6 +511,10 @@ int board_init(void)
setbits_le32(&scsc->sosc_ctr, SCSC_SOSC_CTR_SOSC_EN);
+#ifdef CONFIG_USB_EHCI_VF
- gpio_request(USB_CDET_GPIO, "usb-cdet-gpio");
+#endif
return 0;
}
@@ -554,4 +560,19 @@ int board_ehci_hcd_init(int port)
} return 0;
}
+int board_usb_phy_mode(int port) +{
- switch (port) {
- case 0:
return gpio_get_value(USB_CDET_GPIO);
So what would happen to this code in case we re-number the USB_INIT_HOST and USB_INIT_DEVICE or in case the GPIO API starts returning something else but 0 or 1 here ?
Sorry for the delay in reply. Had got tied up elsewhere.
Yeah, no problem, I can relate to that.
Currently USB_INIT_HOST and USB_INIT_DEVICE are defined with an enum. If we were to switch this would not work as I intended. I guess this would be more appropriate then
if (gpio_get_value(USB_CDET_GPIO)) return USB_INIT_DEVICE; else return USB_INIT_HOST;
Yeah.
For the GPIO, isn't gpio_get_value always suppose to return the actual state of GPIO? Would we ever change the GPIO API to report otherwise?
It will report 0 for GPIO inactive and non-zero for GPIO active, that's the behavior of it.
Concerning the other thread from Stefan's query I will add the comments.
Thanks!

Hi All,
On 2015-10-30 05:26, Sanchayan Maity wrote:
+int board_usb_phy_mode(int port) +{
- switch (port) {
- case 0:
return gpio_get_value(USB_CDET_GPIO);
break;
- case 1:
return USB_INIT_HOST;
break;
- default:
return USB_INIT_HOST;
break;
One thing I would like to note in this whole discussion is that the old setup is kind of the "default" role of each dual-role controller: The boot ROM uses USB1 as client, the tower board uses this configuration too... So maybe we could/should keep that default role at least in here?
-- Stefan

On Friday, October 30, 2015 at 05:12:54 PM, Stefan Agner wrote:
Hi All,
Hi!
On 2015-10-30 05:26, Sanchayan Maity wrote:
+int board_usb_phy_mode(int port) +{
- switch (port) {
- case 0:
return gpio_get_value(USB_CDET_GPIO);
break;
- case 1:
return USB_INIT_HOST;
break;
- default:
return USB_INIT_HOST;
break;
One thing I would like to note in this whole discussion is that the old setup is kind of the "default" role of each dual-role controller: The boot ROM uses USB1 as client, the tower board uses this configuration too... So maybe we could/should keep that default role at least in here?
Well we cannot, since this is a custom board, right ?
Best regards, Marek Vasut

On 2015-10-30 09:24, Marek Vasut wrote:
On Friday, October 30, 2015 at 05:12:54 PM, Stefan Agner wrote:
Hi All,
Hi!
On 2015-10-30 05:26, Sanchayan Maity wrote:
+int board_usb_phy_mode(int port) +{
- switch (port) {
- case 0:
return gpio_get_value(USB_CDET_GPIO);
break;
- case 1:
return USB_INIT_HOST;
break;
- default:
return USB_INIT_HOST;
break;
One thing I would like to note in this whole discussion is that the old setup is kind of the "default" role of each dual-role controller: The boot ROM uses USB1 as client, the tower board uses this configuration too... So maybe we could/should keep that default role at least in here?
Well we cannot, since this is a custom board, right ?
Ah sorry, the switch statement is enumerating the port numbers, hence this default refers to ports > 2. Somehow read that the wrong way around.
Sorry for the noise.
-- Stefan

On Friday, October 30, 2015 at 05:26:25 PM, Stefan Agner wrote:
On 2015-10-30 09:24, Marek Vasut wrote:
On Friday, October 30, 2015 at 05:12:54 PM, Stefan Agner wrote:
Hi All,
Hi!
On 2015-10-30 05:26, Sanchayan Maity wrote:
+int board_usb_phy_mode(int port) +{
- switch (port) {
- case 0:
return gpio_get_value(USB_CDET_GPIO);
break;
- case 1:
return USB_INIT_HOST;
break;
- default:
return USB_INIT_HOST;
break;
One thing I would like to note in this whole discussion is that the old setup is kind of the "default" role of each dual-role controller: The boot ROM uses USB1 as client, the tower board uses this configuration too... So maybe we could/should keep that default role at least in here?
Well we cannot, since this is a custom board, right ?
Ah sorry, the switch statement is enumerating the port numbers, hence this default refers to ports > 2. Somehow read that the wrong way around.
Well, if it is not obvious to you, comment in the code is a good idea. Sanchayan, please add one.
Best regards, Marek Vasut

Add board_usb_phy_mode function for detecting whether a port is being used as host or client using a GPIO. On Colibri Vybrid we provide GPIO 102 for this very same purpose.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com --- Changes since v3: Return USB_INIT_DEVICE or USB_INIT_HOST after checking for the GPIO state to account for the fact that the previous logic breaks in case if the enum for USB mode were to ever be changed.
Add comments based on Stefan's feedback.
Changes since v2:
Instead of returning 0 from board_usb_phy_mode return it as USB_INIT_HOST.
Changes since v1:
Move the GPIO request call to the board_init function as all further calls to board_usb_phy_mode will actually result in the gpio_request failing. --- board/toradex/colibri_vf/colibri_vf.c | 36 ++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-)
diff --git a/board/toradex/colibri_vf/colibri_vf.c b/board/toradex/colibri_vf/colibri_vf.c index a6d1c5b..b1a3375 100644 --- a/board/toradex/colibri_vf/colibri_vf.c +++ b/board/toradex/colibri_vf/colibri_vf.c @@ -21,6 +21,7 @@ #include <i2c.h> #include <g_dnl.h> #include <asm/gpio.h> +#include <usb.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -34,6 +35,7 @@ DECLARE_GLOBAL_DATA_PTR; PAD_CTL_DSE_50ohm | PAD_CTL_OBE_IBE_ENABLE)
#define USB_PEN_GPIO 83 +#define USB_CDET_GPIO 102
static struct ddrmc_cr_setting colibri_vf_cr_settings[] = { /* levelling */ @@ -92,6 +94,7 @@ static struct ddrmc_cr_setting colibri_vf_cr_settings[] = {
static const iomux_v3_cfg_t usb_pads[] = { VF610_PAD_PTD4__GPIO_83, + VF610_PAD_PTC29__GPIO_102, };
int dram_init(void) @@ -280,7 +283,6 @@ static void setup_iomux_gpio(void) VF610_PAD_PTB23__GPIO_93, VF610_PAD_PTB26__GPIO_96, VF610_PAD_PTB28__GPIO_98, - VF610_PAD_PTC29__GPIO_102, VF610_PAD_PTC30__GPIO_103, VF610_PAD_PTA7__GPIO_134, }; @@ -509,6 +511,10 @@ int board_init(void)
setbits_le32(&scsc->sosc_ctr, SCSC_SOSC_CTR_SOSC_EN);
+#ifdef CONFIG_USB_EHCI_VF + gpio_request(USB_CDET_GPIO, "usb-cdet-gpio"); +#endif + return 0; }
@@ -554,4 +560,32 @@ int board_ehci_hcd_init(int port) } return 0; } + +int board_usb_phy_mode(int port) +{ + switch (port) { + case 0: + /* + * Port 0 is used only in client mode on Colibri Vybrid modules + * Check for state of USB client gpio pin and accordingly return + * USB_INIT_DEVICE or USB_INIT_HOST. + */ + if (gpio_get_value(USB_CDET_GPIO)) + return USB_INIT_DEVICE; + else + return USB_INIT_HOST; + break; + case 1: + /* Port 1 is used only in host mode on Colibri Vybrid modules */ + return USB_INIT_HOST; + break; + default: + /* + * There are only two USB controllers on Vybrid. Ideally we will + * not reach here. However return USB_INIT_HOST if we do. + */ + return USB_INIT_HOST; + break; + } +} #endif

On Monday, November 09, 2015 at 03:59:56 PM, Sanchayan Maity wrote:
Add board_usb_phy_mode function for detecting whether a port is being used as host or client using a GPIO. On Colibri Vybrid we provide GPIO 102 for this very same purpose.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com
Changes since v3: Return USB_INIT_DEVICE or USB_INIT_HOST after checking for the GPIO state to account for the fact that the previous logic breaks in case if the enum for USB mode were to ever be changed.
Add comments based on Stefan's feedback.
Changes since v2:
Instead of returning 0 from board_usb_phy_mode return it as USB_INIT_HOST.
Changes since v1:
Move the GPIO request call to the board_init function as all further calls to board_usb_phy_mode will actually result in the gpio_request failing.
board/toradex/colibri_vf/colibri_vf.c | 36 ++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-)
diff --git a/board/toradex/colibri_vf/colibri_vf.c b/board/toradex/colibri_vf/colibri_vf.c index a6d1c5b..b1a3375 100644 --- a/board/toradex/colibri_vf/colibri_vf.c +++ b/board/toradex/colibri_vf/colibri_vf.c @@ -21,6 +21,7 @@ #include <i2c.h> #include <g_dnl.h> #include <asm/gpio.h> +#include <usb.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -34,6 +35,7 @@ DECLARE_GLOBAL_DATA_PTR; PAD_CTL_DSE_50ohm | PAD_CTL_OBE_IBE_ENABLE)
#define USB_PEN_GPIO 83 +#define USB_CDET_GPIO 102
static struct ddrmc_cr_setting colibri_vf_cr_settings[] = { /* levelling */ @@ -92,6 +94,7 @@ static struct ddrmc_cr_setting colibri_vf_cr_settings[] = {
static const iomux_v3_cfg_t usb_pads[] = { VF610_PAD_PTD4__GPIO_83,
- VF610_PAD_PTC29__GPIO_102,
};
int dram_init(void) @@ -280,7 +283,6 @@ static void setup_iomux_gpio(void) VF610_PAD_PTB23__GPIO_93, VF610_PAD_PTB26__GPIO_96, VF610_PAD_PTB28__GPIO_98,
VF610_PAD_PTC30__GPIO_103, VF610_PAD_PTA7__GPIO_134, };VF610_PAD_PTC29__GPIO_102,
@@ -509,6 +511,10 @@ int board_init(void)
setbits_le32(&scsc->sosc_ctr, SCSC_SOSC_CTR_SOSC_EN);
+#ifdef CONFIG_USB_EHCI_VF
- gpio_request(USB_CDET_GPIO, "usb-cdet-gpio");
+#endif
- return 0;
}
@@ -554,4 +560,32 @@ int board_ehci_hcd_init(int port) } return 0; }
+int board_usb_phy_mode(int port) +{
- switch (port) {
- case 0:
/*
* Port 0 is used only in client mode on Colibri Vybrid modules
* Check for state of USB client gpio pin and accordingly return
* USB_INIT_DEVICE or USB_INIT_HOST.
*/
if (gpio_get_value(USB_CDET_GPIO))
return USB_INIT_DEVICE;
else
return USB_INIT_HOST;
break;
You don't have to break after return.
- case 1:
/* Port 1 is used only in host mode on Colibri Vybrid modules */
return USB_INIT_HOST;
break;
DTTO
- default:
/*
* There are only two USB controllers on Vybrid. Ideally we will
* not reach here. However return USB_INIT_HOST if we do.
*/
return USB_INIT_HOST;
break;
DTTO.
- }
+} #endif

Add board_usb_phy_mode function for detecting whether a port is being used as host or client using a GPIO. On Colibri Vybrid we provide GPIO 102 for this very same purpose.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com --- Changes since v4: No need to break after return.
Changes since v3: Return USB_INIT_DEVICE or USB_INIT_HOST after checking for the GPIO state to account for the fact that the previous logic breaks in case if the enum for USB mode were to ever be changed.
Add comments based on Stefan's feedback.
Changes since v2:
Instead of returning 0 from board_usb_phy_mode return it as USB_INIT_HOST.
Changes since v1:
Move the GPIO request call to the board_init function as all further calls to board_usb_phy_mode will actually result in the gpio_request failing. --- board/toradex/colibri_vf/colibri_vf.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-)
diff --git a/board/toradex/colibri_vf/colibri_vf.c b/board/toradex/colibri_vf/colibri_vf.c index a6d1c5b..c65ccb3 100644 --- a/board/toradex/colibri_vf/colibri_vf.c +++ b/board/toradex/colibri_vf/colibri_vf.c @@ -21,6 +21,7 @@ #include <i2c.h> #include <g_dnl.h> #include <asm/gpio.h> +#include <usb.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -34,6 +35,7 @@ DECLARE_GLOBAL_DATA_PTR; PAD_CTL_DSE_50ohm | PAD_CTL_OBE_IBE_ENABLE)
#define USB_PEN_GPIO 83 +#define USB_CDET_GPIO 102
static struct ddrmc_cr_setting colibri_vf_cr_settings[] = { /* levelling */ @@ -92,6 +94,7 @@ static struct ddrmc_cr_setting colibri_vf_cr_settings[] = {
static const iomux_v3_cfg_t usb_pads[] = { VF610_PAD_PTD4__GPIO_83, + VF610_PAD_PTC29__GPIO_102, };
int dram_init(void) @@ -280,7 +283,6 @@ static void setup_iomux_gpio(void) VF610_PAD_PTB23__GPIO_93, VF610_PAD_PTB26__GPIO_96, VF610_PAD_PTB28__GPIO_98, - VF610_PAD_PTC29__GPIO_102, VF610_PAD_PTC30__GPIO_103, VF610_PAD_PTA7__GPIO_134, }; @@ -509,6 +511,10 @@ int board_init(void)
setbits_le32(&scsc->sosc_ctr, SCSC_SOSC_CTR_SOSC_EN);
+#ifdef CONFIG_USB_EHCI_VF + gpio_request(USB_CDET_GPIO, "usb-cdet-gpio"); +#endif + return 0; }
@@ -554,4 +560,29 @@ int board_ehci_hcd_init(int port) } return 0; } + +int board_usb_phy_mode(int port) +{ + switch (port) { + case 0: + /* + * Port 0 is used only in client mode on Colibri Vybrid modules + * Check for state of USB client gpio pin and accordingly return + * USB_INIT_DEVICE or USB_INIT_HOST. + */ + if (gpio_get_value(USB_CDET_GPIO)) + return USB_INIT_DEVICE; + else + return USB_INIT_HOST; + case 1: + /* Port 1 is used only in host mode on Colibri Vybrid modules */ + return USB_INIT_HOST; + default: + /* + * There are only two USB controllers on Vybrid. Ideally we will + * not reach here. However return USB_INIT_HOST if we do. + */ + return USB_INIT_HOST; + } +} #endif

Hello,
Ping?
Any further feedback? Is the patchset good to get accepted?
Thanks.
Regards, Sanchayan.
On 15-11-12 11:47:35, Sanchayan Maity wrote:
Add board_usb_phy_mode function for detecting whether a port is being used as host or client using a GPIO. On Colibri Vybrid we provide GPIO 102 for this very same purpose.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com
Changes since v4: No need to break after return.
Changes since v3: Return USB_INIT_DEVICE or USB_INIT_HOST after checking for the GPIO state to account for the fact that the previous logic breaks in case if the enum for USB mode were to ever be changed.
Add comments based on Stefan's feedback.
Changes since v2:
Instead of returning 0 from board_usb_phy_mode return it as USB_INIT_HOST.
Changes since v1:
Move the GPIO request call to the board_init function as all further calls to board_usb_phy_mode will actually result in the gpio_request failing.
board/toradex/colibri_vf/colibri_vf.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-)
diff --git a/board/toradex/colibri_vf/colibri_vf.c b/board/toradex/colibri_vf/colibri_vf.c index a6d1c5b..c65ccb3 100644 --- a/board/toradex/colibri_vf/colibri_vf.c +++ b/board/toradex/colibri_vf/colibri_vf.c @@ -21,6 +21,7 @@ #include <i2c.h> #include <g_dnl.h> #include <asm/gpio.h> +#include <usb.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -34,6 +35,7 @@ DECLARE_GLOBAL_DATA_PTR; PAD_CTL_DSE_50ohm | PAD_CTL_OBE_IBE_ENABLE)
#define USB_PEN_GPIO 83 +#define USB_CDET_GPIO 102
static struct ddrmc_cr_setting colibri_vf_cr_settings[] = { /* levelling */ @@ -92,6 +94,7 @@ static struct ddrmc_cr_setting colibri_vf_cr_settings[] = {
static const iomux_v3_cfg_t usb_pads[] = { VF610_PAD_PTD4__GPIO_83,
- VF610_PAD_PTC29__GPIO_102,
};
int dram_init(void) @@ -280,7 +283,6 @@ static void setup_iomux_gpio(void) VF610_PAD_PTB23__GPIO_93, VF610_PAD_PTB26__GPIO_96, VF610_PAD_PTB28__GPIO_98,
VF610_PAD_PTC30__GPIO_103, VF610_PAD_PTA7__GPIO_134, };VF610_PAD_PTC29__GPIO_102,
@@ -509,6 +511,10 @@ int board_init(void)
setbits_le32(&scsc->sosc_ctr, SCSC_SOSC_CTR_SOSC_EN);
+#ifdef CONFIG_USB_EHCI_VF
- gpio_request(USB_CDET_GPIO, "usb-cdet-gpio");
+#endif
- return 0;
}
@@ -554,4 +560,29 @@ int board_ehci_hcd_init(int port) } return 0; }
+int board_usb_phy_mode(int port) +{
- switch (port) {
- case 0:
/*
* Port 0 is used only in client mode on Colibri Vybrid modules
* Check for state of USB client gpio pin and accordingly return
* USB_INIT_DEVICE or USB_INIT_HOST.
*/
if (gpio_get_value(USB_CDET_GPIO))
return USB_INIT_DEVICE;
else
return USB_INIT_HOST;
- case 1:
/* Port 1 is used only in host mode on Colibri Vybrid modules */
return USB_INIT_HOST;
- default:
/*
* There are only two USB controllers on Vybrid. Ideally we will
* not reach here. However return USB_INIT_HOST if we do.
*/
return USB_INIT_HOST;
- }
+}
#endif
2.6.2

On Tuesday, November 24, 2015 at 11:23:04 AM, maitysanchayan@gmail.com wrote:
Hello,
Ping?
Any further feedback? Is the patchset good to get accepted?
Not from me. Stefano, this is borad-level stuff, so pick it up please.
Best regards, Marek Vasut

On 24/11/2015 11:23, maitysanchayan@gmail.com wrote:
Hello,
Ping?
Any further feedback? Is the patchset good to get accepted?
I'll pick it up
Best regards, Stefano Babic
Thanks.
Regards, Sanchayan.
On 15-11-12 11:47:35, Sanchayan Maity wrote:
Add board_usb_phy_mode function for detecting whether a port is being used as host or client using a GPIO. On Colibri Vybrid we provide GPIO 102 for this very same purpose.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com
Changes since v4: No need to break after return.
Changes since v3: Return USB_INIT_DEVICE or USB_INIT_HOST after checking for the GPIO state to account for the fact that the previous logic breaks in case if the enum for USB mode were to ever be changed.
Add comments based on Stefan's feedback.
Changes since v2:
Instead of returning 0 from board_usb_phy_mode return it as USB_INIT_HOST.
Changes since v1:
Move the GPIO request call to the board_init function as all further calls to board_usb_phy_mode will actually result in the gpio_request failing.
board/toradex/colibri_vf/colibri_vf.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-)
diff --git a/board/toradex/colibri_vf/colibri_vf.c b/board/toradex/colibri_vf/colibri_vf.c index a6d1c5b..c65ccb3 100644 --- a/board/toradex/colibri_vf/colibri_vf.c +++ b/board/toradex/colibri_vf/colibri_vf.c @@ -21,6 +21,7 @@ #include <i2c.h> #include <g_dnl.h> #include <asm/gpio.h> +#include <usb.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -34,6 +35,7 @@ DECLARE_GLOBAL_DATA_PTR; PAD_CTL_DSE_50ohm | PAD_CTL_OBE_IBE_ENABLE)
#define USB_PEN_GPIO 83 +#define USB_CDET_GPIO 102
static struct ddrmc_cr_setting colibri_vf_cr_settings[] = { /* levelling */ @@ -92,6 +94,7 @@ static struct ddrmc_cr_setting colibri_vf_cr_settings[] = {
static const iomux_v3_cfg_t usb_pads[] = { VF610_PAD_PTD4__GPIO_83,
- VF610_PAD_PTC29__GPIO_102,
};
int dram_init(void) @@ -280,7 +283,6 @@ static void setup_iomux_gpio(void) VF610_PAD_PTB23__GPIO_93, VF610_PAD_PTB26__GPIO_96, VF610_PAD_PTB28__GPIO_98,
VF610_PAD_PTC30__GPIO_103, VF610_PAD_PTA7__GPIO_134, };VF610_PAD_PTC29__GPIO_102,
@@ -509,6 +511,10 @@ int board_init(void)
setbits_le32(&scsc->sosc_ctr, SCSC_SOSC_CTR_SOSC_EN);
+#ifdef CONFIG_USB_EHCI_VF
- gpio_request(USB_CDET_GPIO, "usb-cdet-gpio");
+#endif
- return 0;
}
@@ -554,4 +560,29 @@ int board_ehci_hcd_init(int port) } return 0; }
+int board_usb_phy_mode(int port) +{
- switch (port) {
- case 0:
/*
* Port 0 is used only in client mode on Colibri Vybrid modules
* Check for state of USB client gpio pin and accordingly return
* USB_INIT_DEVICE or USB_INIT_HOST.
*/
if (gpio_get_value(USB_CDET_GPIO))
return USB_INIT_DEVICE;
else
return USB_INIT_HOST;
- case 1:
/* Port 1 is used only in host mode on Colibri Vybrid modules */
return USB_INIT_HOST;
- default:
/*
* There are only two USB controllers on Vybrid. Ideally we will
* not reach here. However return USB_INIT_HOST if we do.
*/
return USB_INIT_HOST;
- }
+}
#endif
2.6.2

On 15-11-24 11:37:59, Stefano Babic wrote:
On 24/11/2015 11:23, maitysanchayan@gmail.com wrote:
Hello,
Ping?
Any further feedback? Is the patchset good to get accepted?
I'll pick it up
Thanks.
- Sanchayan.

Hello Stefano,
Ping?
I just checked the master branch and this has not been picked up yet.
- Sanchayan.
On 15-11-24 11:37:59, Stefano Babic wrote:
On 24/11/2015 11:23, maitysanchayan@gmail.com wrote:
Hello,
Ping?
Any further feedback? Is the patchset good to get accepted?
I'll pick it up
Best regards, Stefano Babic
Thanks.
Regards, Sanchayan.
On 15-11-12 11:47:35, Sanchayan Maity wrote:
Add board_usb_phy_mode function for detecting whether a port is being used as host or client using a GPIO. On Colibri Vybrid we provide GPIO 102 for this very same purpose.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com
Changes since v4: No need to break after return.
Changes since v3: Return USB_INIT_DEVICE or USB_INIT_HOST after checking for the GPIO state to account for the fact that the previous logic breaks in case if the enum for USB mode were to ever be changed.
Add comments based on Stefan's feedback.
Changes since v2:
Instead of returning 0 from board_usb_phy_mode return it as USB_INIT_HOST.
Changes since v1:
Move the GPIO request call to the board_init function as all further calls to board_usb_phy_mode will actually result in the gpio_request failing.
board/toradex/colibri_vf/colibri_vf.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-)
diff --git a/board/toradex/colibri_vf/colibri_vf.c b/board/toradex/colibri_vf/colibri_vf.c index a6d1c5b..c65ccb3 100644 --- a/board/toradex/colibri_vf/colibri_vf.c +++ b/board/toradex/colibri_vf/colibri_vf.c @@ -21,6 +21,7 @@ #include <i2c.h> #include <g_dnl.h> #include <asm/gpio.h> +#include <usb.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -34,6 +35,7 @@ DECLARE_GLOBAL_DATA_PTR; PAD_CTL_DSE_50ohm | PAD_CTL_OBE_IBE_ENABLE)
#define USB_PEN_GPIO 83 +#define USB_CDET_GPIO 102
static struct ddrmc_cr_setting colibri_vf_cr_settings[] = { /* levelling */ @@ -92,6 +94,7 @@ static struct ddrmc_cr_setting colibri_vf_cr_settings[] = {
static const iomux_v3_cfg_t usb_pads[] = { VF610_PAD_PTD4__GPIO_83,
- VF610_PAD_PTC29__GPIO_102,
};
int dram_init(void) @@ -280,7 +283,6 @@ static void setup_iomux_gpio(void) VF610_PAD_PTB23__GPIO_93, VF610_PAD_PTB26__GPIO_96, VF610_PAD_PTB28__GPIO_98,
VF610_PAD_PTC30__GPIO_103, VF610_PAD_PTA7__GPIO_134, };VF610_PAD_PTC29__GPIO_102,
@@ -509,6 +511,10 @@ int board_init(void)
setbits_le32(&scsc->sosc_ctr, SCSC_SOSC_CTR_SOSC_EN);
+#ifdef CONFIG_USB_EHCI_VF
- gpio_request(USB_CDET_GPIO, "usb-cdet-gpio");
+#endif
- return 0;
}
@@ -554,4 +560,29 @@ int board_ehci_hcd_init(int port) } return 0; }
+int board_usb_phy_mode(int port) +{
- switch (port) {
- case 0:
/*
* Port 0 is used only in client mode on Colibri Vybrid modules
* Check for state of USB client gpio pin and accordingly return
* USB_INIT_DEVICE or USB_INIT_HOST.
*/
if (gpio_get_value(USB_CDET_GPIO))
return USB_INIT_DEVICE;
else
return USB_INIT_HOST;
- case 1:
/* Port 1 is used only in host mode on Colibri Vybrid modules */
return USB_INIT_HOST;
- default:
/*
* There are only two USB controllers on Vybrid. Ideally we will
* not reach here. However return USB_INIT_HOST if we do.
*/
return USB_INIT_HOST;
- }
+}
#endif
2.6.2
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic@denx.de =====================================================================

Hi,
On 07/01/2016 21:02, maitysanchayan@gmail.com wrote:
Hello Stefano,
Ping?
I just checked the master branch and this has not been picked up yet.
Can you check ? I see:
commit 01a8cf91513981d05bf89840d768e9c060ee998b Author: Sanchayan Maity maitysanchayan@gmail.com Date: Thu Nov 12 11:47:35 2015 +0530
colibri_vf: Add board_usb_phy_mode function
Regards, Stefano
- Sanchayan.
On 15-11-24 11:37:59, Stefano Babic wrote:
On 24/11/2015 11:23, maitysanchayan@gmail.com wrote:
Hello,
Ping?
Any further feedback? Is the patchset good to get accepted?
I'll pick it up
Best regards, Stefano Babic
Thanks.
Regards, Sanchayan.
On 15-11-12 11:47:35, Sanchayan Maity wrote:
Add board_usb_phy_mode function for detecting whether a port is being used as host or client using a GPIO. On Colibri Vybrid we provide GPIO 102 for this very same purpose.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com
Changes since v4: No need to break after return.
Changes since v3: Return USB_INIT_DEVICE or USB_INIT_HOST after checking for the GPIO state to account for the fact that the previous logic breaks in case if the enum for USB mode were to ever be changed.
Add comments based on Stefan's feedback.
Changes since v2:
Instead of returning 0 from board_usb_phy_mode return it as USB_INIT_HOST.
Changes since v1:
Move the GPIO request call to the board_init function as all further calls to board_usb_phy_mode will actually result in the gpio_request failing.
board/toradex/colibri_vf/colibri_vf.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-)
diff --git a/board/toradex/colibri_vf/colibri_vf.c b/board/toradex/colibri_vf/colibri_vf.c index a6d1c5b..c65ccb3 100644 --- a/board/toradex/colibri_vf/colibri_vf.c +++ b/board/toradex/colibri_vf/colibri_vf.c @@ -21,6 +21,7 @@ #include <i2c.h> #include <g_dnl.h> #include <asm/gpio.h> +#include <usb.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -34,6 +35,7 @@ DECLARE_GLOBAL_DATA_PTR; PAD_CTL_DSE_50ohm | PAD_CTL_OBE_IBE_ENABLE)
#define USB_PEN_GPIO 83 +#define USB_CDET_GPIO 102
static struct ddrmc_cr_setting colibri_vf_cr_settings[] = { /* levelling */ @@ -92,6 +94,7 @@ static struct ddrmc_cr_setting colibri_vf_cr_settings[] = {
static const iomux_v3_cfg_t usb_pads[] = { VF610_PAD_PTD4__GPIO_83,
- VF610_PAD_PTC29__GPIO_102,
};
int dram_init(void) @@ -280,7 +283,6 @@ static void setup_iomux_gpio(void) VF610_PAD_PTB23__GPIO_93, VF610_PAD_PTB26__GPIO_96, VF610_PAD_PTB28__GPIO_98,
VF610_PAD_PTC30__GPIO_103, VF610_PAD_PTA7__GPIO_134, };VF610_PAD_PTC29__GPIO_102,
@@ -509,6 +511,10 @@ int board_init(void)
setbits_le32(&scsc->sosc_ctr, SCSC_SOSC_CTR_SOSC_EN);
+#ifdef CONFIG_USB_EHCI_VF
- gpio_request(USB_CDET_GPIO, "usb-cdet-gpio");
+#endif
- return 0;
}
@@ -554,4 +560,29 @@ int board_ehci_hcd_init(int port) } return 0; }
+int board_usb_phy_mode(int port) +{
- switch (port) {
- case 0:
/*
* Port 0 is used only in client mode on Colibri Vybrid modules
* Check for state of USB client gpio pin and accordingly return
* USB_INIT_DEVICE or USB_INIT_HOST.
*/
if (gpio_get_value(USB_CDET_GPIO))
return USB_INIT_DEVICE;
else
return USB_INIT_HOST;
- case 1:
/* Port 1 is used only in host mode on Colibri Vybrid modules */
return USB_INIT_HOST;
- default:
/*
* There are only two USB controllers on Vybrid. Ideally we will
* not reach here. However return USB_INIT_HOST if we do.
*/
return USB_INIT_HOST;
- }
+}
#endif
2.6.2
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic@denx.de =====================================================================

Hello,
On 16-01-07 22:12:29, Stefano Babic wrote:
Hi,
On 07/01/2016 21:02, maitysanchayan@gmail.com wrote:
Hello Stefano,
Ping?
I just checked the master branch and this has not been picked up yet.
Can you check ? I see:
commit 01a8cf91513981d05bf89840d768e9c060ee998b Author: Sanchayan Maity maitysanchayan@gmail.com Date: Thu Nov 12 11:47:35 2015 +0530
colibri_vf: Add board_usb_phy_mode function
Yes, this seems to be present but the first and second patch in the series which make changes to the ehci-vf driver are not present.
- Sanchayan.
Regards, Stefano
- Sanchayan.
On 15-11-24 11:37:59, Stefano Babic wrote:
On 24/11/2015 11:23, maitysanchayan@gmail.com wrote:
Hello,
Ping?
Any further feedback? Is the patchset good to get accepted?
I'll pick it up
Best regards, Stefano Babic
Thanks.
Regards, Sanchayan.
On 15-11-12 11:47:35, Sanchayan Maity wrote:
Add board_usb_phy_mode function for detecting whether a port is being used as host or client using a GPIO. On Colibri Vybrid we provide GPIO 102 for this very same purpose.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com
Changes since v4: No need to break after return.
Changes since v3: Return USB_INIT_DEVICE or USB_INIT_HOST after checking for the GPIO state to account for the fact that the previous logic breaks in case if the enum for USB mode were to ever be changed.
Add comments based on Stefan's feedback.
Changes since v2:
Instead of returning 0 from board_usb_phy_mode return it as USB_INIT_HOST.
Changes since v1:
Move the GPIO request call to the board_init function as all further calls to board_usb_phy_mode will actually result in the gpio_request failing.
board/toradex/colibri_vf/colibri_vf.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-)
diff --git a/board/toradex/colibri_vf/colibri_vf.c b/board/toradex/colibri_vf/colibri_vf.c index a6d1c5b..c65ccb3 100644 --- a/board/toradex/colibri_vf/colibri_vf.c +++ b/board/toradex/colibri_vf/colibri_vf.c @@ -21,6 +21,7 @@ #include <i2c.h> #include <g_dnl.h> #include <asm/gpio.h> +#include <usb.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -34,6 +35,7 @@ DECLARE_GLOBAL_DATA_PTR; PAD_CTL_DSE_50ohm | PAD_CTL_OBE_IBE_ENABLE)
#define USB_PEN_GPIO 83 +#define USB_CDET_GPIO 102
static struct ddrmc_cr_setting colibri_vf_cr_settings[] = { /* levelling */ @@ -92,6 +94,7 @@ static struct ddrmc_cr_setting colibri_vf_cr_settings[] = {
static const iomux_v3_cfg_t usb_pads[] = { VF610_PAD_PTD4__GPIO_83,
- VF610_PAD_PTC29__GPIO_102,
};
int dram_init(void) @@ -280,7 +283,6 @@ static void setup_iomux_gpio(void) VF610_PAD_PTB23__GPIO_93, VF610_PAD_PTB26__GPIO_96, VF610_PAD_PTB28__GPIO_98,
VF610_PAD_PTC30__GPIO_103, VF610_PAD_PTA7__GPIO_134, };VF610_PAD_PTC29__GPIO_102,
@@ -509,6 +511,10 @@ int board_init(void)
setbits_le32(&scsc->sosc_ctr, SCSC_SOSC_CTR_SOSC_EN);
+#ifdef CONFIG_USB_EHCI_VF
- gpio_request(USB_CDET_GPIO, "usb-cdet-gpio");
+#endif
- return 0;
}
@@ -554,4 +560,29 @@ int board_ehci_hcd_init(int port) } return 0; }
+int board_usb_phy_mode(int port) +{
- switch (port) {
- case 0:
/*
* Port 0 is used only in client mode on Colibri Vybrid modules
* Check for state of USB client gpio pin and accordingly return
* USB_INIT_DEVICE or USB_INIT_HOST.
*/
if (gpio_get_value(USB_CDET_GPIO))
return USB_INIT_DEVICE;
else
return USB_INIT_HOST;
- case 1:
/* Port 1 is used only in host mode on Colibri Vybrid modules */
return USB_INIT_HOST;
- default:
/*
* There are only two USB controllers on Vybrid. Ideally we will
* not reach here. However return USB_INIT_HOST if we do.
*/
return USB_INIT_HOST;
- }
+}
#endif
2.6.2
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic@denx.de =====================================================================
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic@denx.de =====================================================================

On Friday, January 08, 2016 at 06:50:41 AM, maitysanchayan@gmail.com wrote:
Hello,
On 16-01-07 22:12:29, Stefano Babic wrote:
Hi,
On 07/01/2016 21:02, maitysanchayan@gmail.com wrote:
Hello Stefano,
Ping?
I just checked the master branch and this has not been picked up yet.
Can you check ? I see:
commit 01a8cf91513981d05bf89840d768e9c060ee998b Author: Sanchayan Maity maitysanchayan@gmail.com Date: Thu Nov 12 11:47:35 2015 +0530
colibri_vf: Add board_usb_phy_mode function
Yes, this seems to be present but the first and second patch in the series which make changes to the ehci-vf driver are not present.
But this is only a single patch here , even the subject indicates so ... ?
Best regards, Marek Vasut

On 16-01-08 13:11:27, Marek Vasut wrote:
On Friday, January 08, 2016 at 06:50:41 AM, maitysanchayan@gmail.com wrote:
Hello,
On 16-01-07 22:12:29, Stefano Babic wrote:
Hi,
On 07/01/2016 21:02, maitysanchayan@gmail.com wrote:
Hello Stefano,
Ping?
I just checked the master branch and this has not been picked up yet.
Can you check ? I see:
commit 01a8cf91513981d05bf89840d768e9c060ee998b Author: Sanchayan Maity maitysanchayan@gmail.com Date: Thu Nov 12 11:47:35 2015 +0530
colibri_vf: Add board_usb_phy_mode function
Yes, this seems to be present but the first and second patch in the series which make changes to the ehci-vf driver are not present.
But this is only a single patch here , even the subject indicates so ... ?
Hmm I guess I get it. This patch I had send as a reply to the 3rd patch in a thread of a 3 patch series
http://thread.gmane.org/gmane.comp.boot-loaders.u-boot/238549
My bad. Sorry about the confusion. I will ping on the respective individual 1st and 2nd patch.
- Sanchayan.

On Friday, January 08, 2016 at 01:18:46 PM, maitysanchayan@gmail.com wrote:
On 16-01-08 13:11:27, Marek Vasut wrote:
On Friday, January 08, 2016 at 06:50:41 AM, maitysanchayan@gmail.com wrote:
Hello,
On 16-01-07 22:12:29, Stefano Babic wrote:
Hi,
On 07/01/2016 21:02, maitysanchayan@gmail.com wrote:
Hello Stefano,
Ping?
I just checked the master branch and this has not been picked up yet.
Can you check ? I see:
commit 01a8cf91513981d05bf89840d768e9c060ee998b Author: Sanchayan Maity maitysanchayan@gmail.com Date: Thu Nov 12 11:47:35 2015 +0530
colibri_vf: Add board_usb_phy_mode function
Yes, this seems to be present but the first and second patch in the series which make changes to the ehci-vf driver are not present.
But this is only a single patch here , even the subject indicates so ... ?
Hmm I guess I get it. This patch I had send as a reply to the 3rd patch in a thread of a 3 patch series
http://thread.gmane.org/gmane.comp.boot-loaders.u-boot/238549
My bad. Sorry about the confusion. I will ping on the respective individual 1st and 2nd patch.
Thanks :) I suppose it's clear now to everyone involved.
Best regards, Marek Vasut

On Monday, October 26, 2015 at 01:58:49 PM, Sanchayan Maity wrote:
The current ehci-vf USB driver for Vybrid hardcodes the USB host and client functionality. Remove this.
Reported-by: Santhosh Kumar Janardhanam santhosh.kj@hcl.com Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com
Is this a V2 or why did I receive this patchset twice ?
Looks OK though.
Best regards, Marek Vasut

Hello,
On 15-10-26 20:19:42, Marek Vasut wrote:
On Monday, October 26, 2015 at 01:58:49 PM, Sanchayan Maity wrote:
The current ehci-vf USB driver for Vybrid hardcodes the USB host and client functionality. Remove this.
Reported-by: Santhosh Kumar Janardhanam santhosh.kj@hcl.com Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com
Is this a V2 or why did I receive this patchset twice ?
Yes sorry about that. I specified the uboot mailing list address wrong in my first patchset mail. Had to resend but then missed adding RESEND.
- Sanchayan.
Looks OK though.
Best regards, Marek Vasut

Hello Stefano / Marek,
Can you pick this up?
- Sanchayan.
On 15-10-26 18:28:49, Sanchayan Maity wrote:
The current ehci-vf USB driver for Vybrid hardcodes the USB host and client functionality. Remove this.
Reported-by: Santhosh Kumar Janardhanam santhosh.kj@hcl.com Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com
drivers/usb/host/ehci-vf.c | 5 ----- 1 file changed, 5 deletions(-)
diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c index 98e0fc6..351e0fb 100644 --- a/drivers/usb/host/ehci-vf.c +++ b/drivers/usb/host/ehci-vf.c @@ -134,11 +134,6 @@ int ehci_hcd_init(int index, enum usb_init_type init, if (index >= ARRAY_SIZE(nc_reg_bases)) return -EINVAL;
if (init == USB_INIT_DEVICE && index == 1)
return -ENODEV;
if (init == USB_INIT_HOST && index == 0)
return -ENODEV;
ehci = (struct usb_ehci *)nc_reg_bases[index];
/* Do board specific initialisation */
-- 2.6.2

On Friday, January 08, 2016 at 01:20:23 PM, maitysanchayan@gmail.com wrote:
Hello Stefano / Marek,
Can you pick this up?
I can, but only for next. Is that fine ?
- Sanchayan.
On 15-10-26 18:28:49, Sanchayan Maity wrote:
The current ehci-vf USB driver for Vybrid hardcodes the USB host and client functionality. Remove this.
Reported-by: Santhosh Kumar Janardhanam santhosh.kj@hcl.com Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com
drivers/usb/host/ehci-vf.c | 5 ----- 1 file changed, 5 deletions(-)
diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c index 98e0fc6..351e0fb 100644 --- a/drivers/usb/host/ehci-vf.c +++ b/drivers/usb/host/ehci-vf.c @@ -134,11 +134,6 @@ int ehci_hcd_init(int index, enum usb_init_type init,
if (index >= ARRAY_SIZE(nc_reg_bases))
return -EINVAL;
if (init == USB_INIT_DEVICE && index == 1)
return -ENODEV;
if (init == USB_INIT_HOST && index == 0)
return -ENODEV;
ehci = (struct usb_ehci *)nc_reg_bases[index];
/* Do board specific initialisation */
Best regards, Marek Vasut

Hello Marek,
On 16-01-08 13:26:32, Marek Vasut wrote:
On Friday, January 08, 2016 at 01:20:23 PM, maitysanchayan@gmail.com wrote:
Hello Stefano / Marek,
Can you pick this up?
I can, but only for next. Is that fine ?
Yes it's fine. Thank you.
- Sanchayan.
On 15-10-26 18:28:49, Sanchayan Maity wrote:
The current ehci-vf USB driver for Vybrid hardcodes the USB host and client functionality. Remove this.
Reported-by: Santhosh Kumar Janardhanam santhosh.kj@hcl.com Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com
drivers/usb/host/ehci-vf.c | 5 ----- 1 file changed, 5 deletions(-)
diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c index 98e0fc6..351e0fb 100644 --- a/drivers/usb/host/ehci-vf.c +++ b/drivers/usb/host/ehci-vf.c @@ -134,11 +134,6 @@ int ehci_hcd_init(int index, enum usb_init_type init,
if (index >= ARRAY_SIZE(nc_reg_bases))
return -EINVAL;
if (init == USB_INIT_DEVICE && index == 1)
return -ENODEV;
if (init == USB_INIT_HOST && index == 0)
return -ENODEV;
ehci = (struct usb_ehci *)nc_reg_bases[index];
/* Do board specific initialisation */
Best regards, Marek Vasut
participants (5)
-
maitysanchayan@gmail.com
-
Marek Vasut
-
Sanchayan Maity
-
Stefan Agner
-
Stefano Babic