Patches to add dr_mode for dwc2
Subsystems (3)
v3 cover Patches to add dr_mode for dwc2
These two patches enable the dr_mode for the dwc2 usb controller. These are split from the patch series adding rk3288 dwc2 support.
Changes in v3:
- fix the odd spacing in dwc2_hsotg struct
- From Jingoo's suggestion:
change the commit message
Changes in v2:
- Split out dr_mode and rk3288 bindings.
- put spaces around '+' operator
- expand the comment for dr_mode
- handle dr_mode is USB_DR_MODE_OTG
Kever Yang (2):
Documentation: dt-bindings: add dt binding info for dwc2 dr_mode
usb: dwc2: add 'mode' which based on Kconfig select or dts setting
Documentation/devicetree/bindings/usb/dwc2.txt | 2 ++ drivers/usb/dwc2/core.c | 18 ++++++++++++++++++ drivers/usb/dwc2/core.h | 5 +++++ drivers/usb/dwc2/platform.c | 12 ++++++++++++ 4 files changed, 37 insertions(+)
Signature · 1 line
1.9.1
PATCH v3 1/2 Documentation: dt-bindings: add dt binding info for dwc2 dr_mode
Indicate that the generic dr_mode binding should be used for dwc2.
---
Changes in v3: None
Changes in v2:
- Split out dr_mode and rk3288 bindings.
Documentation/devicetree/bindings/usb/dwc2.txt | 2 ++ 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/usb/dwc2.txt +2 -0
@@ -15,6 +15,8 @@ Optional properties: - phys: phy provider specifier - phy-names: shall be "usb2-phy" Refer to phy/phy-bindings.txt for generic phy consumer properties +- dr_mode: shall be one of "host", "peripheral" and "otg" + Refer to usb/generic.txt Example:
Signature · 1 line
1.9.1
Re: [PATCH v3 1/2] Documentation: dt-bindings: add dt binding info for dwc2 dr_mode
Kever,
Quoted 6 lines · Kever Yang
Indicate that the generic
dr_modebinding should be used for dwc2.Signed-off-by Kever Yang <[email protected]>---
Changes in v3: None
Since I gave my Reviewed-by tag for v2 and you made no changes from v2 to v3, you should make sure you include my Reviewed-by tag in the new version.
PATCH v3 1/2 Documentation: dt-bindings: add dt binding info for dwc2 dr_mode
In reply to Kever YangGreg,
Quoted 11 lines · Kever Yang
Indicate that the generic
dr_modebinding should be used for dwc2.Signed-off-by Kever Yang <[email protected]>---
Changes in v3: None
Changes in v2:
- Split outdr_modeand rk3288 bindings.Documentation/devicetree/bindings/usb/dwc2.txt | 2 ++ 1 file changed, 2 insertions(+)
Are there any other changes you'd like for this patch (and the next one that goes with it) before landing?
Thanks!
-Doug
Greg Kroah-Hartman
maintainerPATCH v3 1/2 Documentation: dt-bindings: add dt binding info for dwc2 dr_mode
Quoted 12 lines · Doug Anderson
Greg,
Quoted 9 lines · Kever Yang
Indicate that the generic
dr_modebinding should be used for dwc2.Signed-off-by Kever Yang <[email protected]>---
Changes in v3: None
Changes in v2:
- Split outdr_modeand rk3288 bindings.
Quoted 5 lines
Quoted 2 lines
Documentation/devicetree/bindings/usb/dwc2.txt | 2 ++ 1 file changed, 2 insertions(+)Are there any other changes you'd like for this patch (and the next one that goes with it) before landing?
No idea, please resend.
PATCH v3 2/2 usb: dwc2: add 'mode' which based on Kconfig select or dts setting
In reply to Kever YangAccording to the "dr_mode", the otg controller can work as device role during firmware period, and work as host role in the kernel, without use of usb_id pin. As the commit "usb: dwc3:
set 'mode' based on selected Kconfig choices".
---
Changes in v3:
- fix the odd spacing in dwc2_hsotg struct
- From Jingoo's suggestion:
change the commit message
Changes in v2:
- put spaces around '+' operator
- expand the comment for dr_mode
- handle dr_mode is USB_DR_MODE_OTG
drivers/usb/dwc2/core.c | 18 ++++++++++++++++++ drivers/usb/dwc2/core.h | 5 +++++ drivers/usb/dwc2/platform.c | 12 ++++++++++++ 3 files changed, 35 insertions(+)
drivers/usb/dwc2/core.c +18 -0
@@ -118,6 +118,7 @@ static int dwc2_core_reset(struct dwc2_hsotg *hsotg) {u32 greset;int count =0 ; +u32 gusbcfg;dev_vdbg (hsotg->dev,"%s()\n" , __func__);
@@ -148,6 +149,23 @@ static int dwc2_core_reset(struct dwc2_hsotg *hsotg) } }while (greset &GRSTCTL_CSFTRST ); +if (hsotg->dr_mode ==USB_DR_MODE_HOST ) { + gusbcfg =readl (hsotg->regs +GUSBCFG ); + gusbcfg &= ~GUSBCFG_FORCEDEVMODE ; + gusbcfg |=GUSBCFG_FORCEHOSTMODE ; +writel (gusbcfg, hsotg->regs +GUSBCFG ); + }else if (hsotg->dr_mode ==USB_DR_MODE_PERIPHERAL ) { + gusbcfg =readl (hsotg->regs +GUSBCFG ); + gusbcfg &= ~GUSBCFG_FORCEHOSTMODE ; + gusbcfg |=GUSBCFG_FORCEDEVMODE ; +writel (gusbcfg, hsotg->regs +GUSBCFG ); + }else if (hsotg->dr_mode ==USB_DR_MODE_OTG ) { + gusbcfg =readl (hsotg->regs +GUSBCFG ); + gusbcfg &= ~GUSBCFG_FORCEHOSTMODE ; + gusbcfg &= ~GUSBCFG_FORCEDEVMODE ; +writel (gusbcfg, hsotg->regs +GUSBCFG ); + } +/* * NOTE: This long sleep is _very_ important, otherwise the core will * not stay in host mode after a connector ID change!
drivers/usb/dwc2/core.h +5 -0
@@ -501,6 +501,10 @@ struct dwc2_hw_params {* a_peripheral and b_device=>b_host) this may not match * the core, but allows the software to determine * transitions +* @dr_mode: Requested mode of operation, one of following: +* - USB_DR_MODE_PERIPHERAL +* - USB_DR_MODE_HOST +* - USB_DR_MODE_OTG * @queuing_high_bandwidth: True if multiple packets of a high-bandwidth * transfer are in process of being queued * @srp_success: Stores status of SRP request in the case of a FS PHY
@@ -592,6 +596,7 @@ struct dwc2_hsotg {/** Params to actually use */ struct dwc2_core_params *core_params;enum usb_otg_state op_state; +enum usb_dr_mode dr_mode; unsigned int queuing_high_bandwidth:1; unsigned int srp_success:1;
drivers/usb/dwc2/platform.c +12 -0
@@ -42,6 +42,8 @@#include <linux/of_device.h> #include <linux/platform_device.h> +#include <linux/usb/of.h> +#include "core.h" #include "hcd.h"
@@ -171,6 +173,16 @@ static int dwc2_driver_probe(struct platform_device *dev)dev_dbg (&dev->dev,"mapped PA %08lx to VA %p\n" , (unsigned long )res->start, hsotg->regs); + hsotg->dr_mode =of_usb_get_dr_mode (dev->dev.of_node); + +if (IS_ENABLED (CONFIG_USB_DWC2_HOST )) + hsotg->dr_mode =USB_DR_MODE_HOST ; +else if (IS_ENABLED (CONFIG_USB_DWC2_GADGET )) + hsotg->dr_mode =USB_DR_MODE_PERIPHERAL ; + +if (hsotg->dr_mode ==USB_DR_MODE_UNKNOWN ) + hsotg->dr_mode =USB_DR_MODE_OTG ; + retval =dwc2_hcd_init (hsotg, irq, params);if (retval)return retval;
Signature · 1 line
1.9.1
Re: [PATCH v3 2/2] usb: dwc2: add 'mode' which based on Kconfig select or dts setting
Kever,
Quoted 4 lines · Kever Yang
According to the "
dr_mode", the otg controller can work as device role during firmware period, and work as host role in the kernel, without use ofusb_idpin. As the commit "usb: dwc3:
set 'mode' based on selectedKconfigchoices".
I don't think you need to mention firmware / kernel here. Just say that on some boards we always want to use host mode and on other boards we want to use gadget mode. ...and that we don't necessarily have the ID pin hooked up to make this automatic.
Quoted 1 line
Signed-off-by Kever Yang <[email protected]>
Normally I'd say that you should have added Paul's "Acked-by" since you fixed his nit and he told you to include his Acked-by when his nit was fixed, but...
Quoted 6 lines
---
Changes in v3:
- fix the odd spacing indwc2_hsotgstruct
- From Jingoo's suggestion:
change the commit message
You did more than just this. You also added some (incorrect) Kconfig things. See below.
Quoted 86 lines
Changes in v2:
- put spaces around '+' operator
- expand the comment fordr_mode
- handledr_modeisUSB_DR_MODE_OTGdrivers/usb/dwc2/core.c | 18 ++++++++++++++++++ drivers/usb/dwc2/core.h | 5 +++++ drivers/usb/dwc2/platform.c | 12 ++++++++++++ 3 files changed, 35 insertions(+)drivers/usb/dwc2/core.c +18
-0@@ -118,6 +118,7 @@ static int dwc2_core_reset(struct dwc2_hsotg *hsotg) {u32 greset;int count =0 ; +u32 gusbcfg;dev_vdbg (hsotg->dev,"%s()\n" , __func__);@@ -148,6 +149,23 @@ static int dwc2_core_reset(struct dwc2_hsotg *hsotg) } }while (greset &GRSTCTL_CSFTRST ); +if (hsotg->dr_mode ==USB_DR_MODE_HOST ) { + gusbcfg =readl (hsotg->regs +GUSBCFG ); + gusbcfg &= ~GUSBCFG_FORCEDEVMODE ; + gusbcfg |=GUSBCFG_FORCEHOSTMODE ; +writel (gusbcfg, hsotg->regs +GUSBCFG ); + }else if (hsotg->dr_mode ==USB_DR_MODE_PERIPHERAL ) { + gusbcfg =readl (hsotg->regs +GUSBCFG ); + gusbcfg &= ~GUSBCFG_FORCEHOSTMODE ; + gusbcfg |=GUSBCFG_FORCEDEVMODE ; +writel (gusbcfg, hsotg->regs +GUSBCFG ); + }else if (hsotg->dr_mode ==USB_DR_MODE_OTG ) { + gusbcfg =readl (hsotg->regs +GUSBCFG ); + gusbcfg &= ~GUSBCFG_FORCEHOSTMODE ; + gusbcfg &= ~GUSBCFG_FORCEDEVMODE ; +writel (gusbcfg, hsotg->regs +GUSBCFG ); + } +/* * NOTE: This long sleep is _very_ important, otherwise the core will * not stay in host mode after a connector ID change! drivers/usb/dwc2/core.h +5
-0@@ -501,6 +501,10 @@ struct dwc2_hw_params {* a_peripheral and b_device=>b_host) this may not match * the core, but allows the software to determine * transitions +* @dr_mode: Requested mode of operation, one of following: +* - USB_DR_MODE_PERIPHERAL +* - USB_DR_MODE_HOST +* - USB_DR_MODE_OTG * @queuing_high_bandwidth: True if multiple packets of a high-bandwidth * transfer are in process of being queued * @srp_success: Stores status of SRP request in the case of a FS PHY @@ -592,6 +596,7 @@ struct dwc2_hsotg {/** Params to actually use */ struct dwc2_core_params *core_params;enum usb_otg_state op_state; +enum usb_dr_mode dr_mode; unsigned int queuing_high_bandwidth:1; unsigned int srp_success:1;drivers/usb/dwc2/platform.c +2
-0@@ -42,6 +42,8 @@#include <linux/of_device.h> #include <linux/platform_device.h> +#include <linux/usb/of.h> +#include "core.h" #include "hcd.h" @@ -171,6 +173,16 @@ static int dwc2_driver_probe(struct platform_device *dev)dev_dbg (&dev->dev,"mapped PA %08lx to VA %p\n" , (unsigned long )res->start, hsotg->regs);
drivers/usb/dwc2/platform.c static int dwc2_driver_probe(struct platform_device *dev) · line 185
Quoted 10 lines
drivers/usb/dwc2/platform.c +10
-0+ hsotg->dr_mode =of_usb_get_dr_mode (dev->dev.of_node); + +if (IS_ENABLED (CONFIG_USB_DWC2_HOST )) + hsotg->dr_mode =USB_DR_MODE_HOST ; +else if (IS_ENABLED (CONFIG_USB_DWC2_GADGET )) + hsotg->dr_mode =USB_DR_MODE_PERIPHERAL ; + +if (hsotg->dr_mode ==USB_DR_MODE_UNKNOWN ) + hsotg->dr_mode =USB_DR_MODE_OTG ; +
Please remove this whole chunk. Specifically:
* CONFIG_USB_DWC2_GADGET is not a config option and is nowhere in any KConfig files.
* CONFIG_USB_DWC2_HOST claims in Kconfig that we'll be in "host only" mode, but I don't think that's right. The only way you'll get any host functionality is if CONFIG_USB_DWC2_HOST is defined, so we'd need that defined even for OTG mode.
Re: [PATCH v3 2/2] usb: dwc2: add 'mode' which based on Kconfig select or dts setting
Doug,
Quoted 11 lines · Doug Anderson
Kever,
Quoted 4 lines · Kever Yang
According to the "
dr_mode", the otg controller can work as device role during firmware period, and work as host role in the kernel, without use ofusb_idpin. As the commit "usb: dwc3:
set 'mode' based on selectedKconfigchoices".I don't think you need to mention firmware / kernel here. Just say that on some boards we always want to use host mode and on other boards we want to use gadget mode. ...and that we don't necessarily have the ID pin hooked up to make this automatic.
OK, I'll change this message again, I just don't know how to describe to make everyone understand what I'm doing.
Quoted 6 lines
Quoted 3 lines
Signed-off-by Kever Yang <[email protected]>Normally I'd say that you should have added Paul's "Acked-by" since you fixed his nit and he told you to include his Acked-by when his nit was fixed, but...
There are some more changes than Paul's suggestion, so I'm not sure if Paul need more review to give me the "Acked-by", I get it now.
Quoted 110 lines
Quoted 8 lines
---
Changes in v3:
- fix the odd spacing indwc2_hsotgstruct
- From Jingoo's suggestion:
change the commit messageYou did more than just this. You also added some (incorrect)
Kconfigthings. See below.Quoted 86 lines
Changes in v2:
- put spaces around '+' operator
- expand the comment fordr_mode
- handledr_modeisUSB_DR_MODE_OTGdrivers/usb/dwc2/core.c | 18 ++++++++++++++++++ drivers/usb/dwc2/core.h | 5 +++++ drivers/usb/dwc2/platform.c | 12 ++++++++++++ 3 files changed, 35 insertions(+)drivers/usb/dwc2/core.c +18
-0@@ -118,6 +118,7 @@ static int dwc2_core_reset(struct dwc2_hsotg *hsotg) {u32 greset;int count =0 ; +u32 gusbcfg;dev_vdbg (hsotg->dev,"%s()\n" , __func__);@@ -148,6 +149,23 @@ static int dwc2_core_reset(struct dwc2_hsotg *hsotg) } }while (greset &GRSTCTL_CSFTRST ); +if (hsotg->dr_mode ==USB_DR_MODE_HOST ) { + gusbcfg =readl (hsotg->regs +GUSBCFG ); + gusbcfg &= ~GUSBCFG_FORCEDEVMODE ; + gusbcfg |=GUSBCFG_FORCEHOSTMODE ; +writel (gusbcfg, hsotg->regs +GUSBCFG ); + }else if (hsotg->dr_mode ==USB_DR_MODE_PERIPHERAL ) { + gusbcfg =readl (hsotg->regs +GUSBCFG ); + gusbcfg &= ~GUSBCFG_FORCEHOSTMODE ; + gusbcfg |=GUSBCFG_FORCEDEVMODE ; +writel (gusbcfg, hsotg->regs +GUSBCFG ); + }else if (hsotg->dr_mode ==USB_DR_MODE_OTG ) { + gusbcfg =readl (hsotg->regs +GUSBCFG ); + gusbcfg &= ~GUSBCFG_FORCEHOSTMODE ; + gusbcfg &= ~GUSBCFG_FORCEDEVMODE ; +writel (gusbcfg, hsotg->regs +GUSBCFG ); + } +/* * NOTE: This long sleep is _very_ important, otherwise the core will * not stay in host mode after a connector ID change! drivers/usb/dwc2/core.h +5
-0@@ -501,6 +501,10 @@ struct dwc2_hw_params {* a_peripheral and b_device=>b_host) this may not match * the core, but allows the software to determine * transitions +* @dr_mode: Requested mode of operation, one of following: +* - USB_DR_MODE_PERIPHERAL +* - USB_DR_MODE_HOST +* - USB_DR_MODE_OTG * @queuing_high_bandwidth: True if multiple packets of a high-bandwidth * transfer are in process of being queued * @srp_success: Stores status of SRP request in the case of a FS PHY @@ -592,6 +596,7 @@ struct dwc2_hsotg {/** Params to actually use */ struct dwc2_core_params *core_params;enum usb_otg_state op_state; +enum usb_dr_mode dr_mode; unsigned int queuing_high_bandwidth:1; unsigned int srp_success:1;drivers/usb/dwc2/platform.c +2
-0@@ -42,6 +42,8 @@#include <linux/of_device.h> #include <linux/platform_device.h> +#include <linux/usb/of.h> +#include "core.h" #include "hcd.h" @@ -171,6 +173,16 @@ static int dwc2_driver_probe(struct platform_device *dev)dev_dbg (&dev->dev,"mapped PA %08lx to VA %p\n" , (unsigned long )res->start, hsotg->regs);drivers/usb/dwc2/platform.c static int dwc2_driver_probe(struct platform_device *dev) · line 185
Quoted 10 lines
drivers/usb/dwc2/platform.c +10
-0+ hsotg->dr_mode =of_usb_get_dr_mode (dev->dev.of_node); + +if (IS_ENABLED (CONFIG_USB_DWC2_HOST )) + hsotg->dr_mode =USB_DR_MODE_HOST ; +else if (IS_ENABLED (CONFIG_USB_DWC2_GADGET )) + hsotg->dr_mode =USB_DR_MODE_PERIPHERAL ; + +if (hsotg->dr_mode ==USB_DR_MODE_UNKNOWN ) + hsotg->dr_mode =USB_DR_MODE_OTG ; +Please remove this whole chunk. Specifically:
Quoted 2 lines
*
CONFIG_USB_DWC2_GADGETis not a config option and is nowhere in any KConfig files.
This should be USB_DWC2_PERIPHERAL, and I just copy it wrong from dwc3.
Quoted 5 lines
*
CONFIG_USB_DWC2_HOSTclaims inKconfigthat we'll be in "host only" mode, but I don't think that's right. The only way you'll get any host functionality is ifCONFIG_USB_DWC2_HOSTis defined, so we'd need that defined even for OTG mode.
Yeap, I add the chunk above because I'm confused by "Host only mode" for CONFIG_USB_DWC2_HOST in Kconfig. If it's the "Host only mode", I should add the dr_mode for it to make sure the controller works in host mode.
Maybe dwc2 is refer to the Kconfig in dwc3 for there is a choice from one of "Host only mode", "Gadget only mode" and "Dual Role mode", which means the role is decided by the Kconfig.
In my opinion, there maybe more than one controller in a Soc, and for different usage, the mode select should not be done in Kconfig, it's better to do that in dts file.
I agree with you that the CONFIG_USB_DWC2_HOST should defined for host functionality, not for role definition.
Paul: what do you think?
Quoted 3 lines
Re: [PATCH v3 2/2] usb: dwc2: add 'mode' which based on Kconfig select or dts setting
Kever,
Quoted 151 lines · Kever Yang
Doug,
Quoted 11 lines · Doug Anderson
Kever,
Quoted 5 lines · Kever Yang
According to the "
dr_mode", the otg controller can work as device role during firmware period, and work as host role in the kernel, without use ofusb_idpin. As the commit "usb: dwc3:
set 'mode' based on selectedKconfigchoices".Quoted 4 lines
I don't think you need to mention firmware / kernel here. Just say that on some boards we always want to use host mode and on other boards we want to use gadget mode. ...and that we don't necessarily have the ID pin hooked up to make this automatic.
OK, I'll change this message again, I just don't know how to describe to make everyone understand what I'm doing.
Quoted 7 lines
Quoted 3 lines
Signed-off-by Kever Yang <[email protected]>Normally I'd say that you should have added Paul's "Acked-by" since you fixed his nit and he told you to include his Acked-by when his nit was fixed, but...
There are some more changes than Paul's suggestion, so I'm not sure if Paul need more review to give me the "Acked-by", I get it now.
Quoted 117 lines
Quoted 8 lines
---
Changes in v3:
- fix the odd spacing indwc2_hsotgstruct
- From Jingoo's suggestion:
change the commit messageYou did more than just this. You also added some (incorrect)
Kconfigthings. See below.Quoted 91 lines
Changes in v2:
- put spaces around '+' operator
- expand the comment fordr_mode
- handledr_modeisUSB_DR_MODE_OTGdrivers/usb/dwc2/core.c | 18 ++++++++++++++++++ drivers/usb/dwc2/core.h | 5 +++++ drivers/usb/dwc2/platform.c | 12 ++++++++++++ 3 files changed, 35 insertions(+)drivers/usb/dwc2/core.c +18
-0@@ -118,6 +118,7 @@ static int dwc2_core_reset(struct dwc2_hsotg *hsotg) {u32 greset;int count =0 ; +u32 gusbcfg;dev_vdbg (hsotg->dev,"%s()\n" , __func__);@@ -148,6 +149,23 @@ static int dwc2_core_reset(struct dwc2_hsotg *hsotg) } }while (greset &GRSTCTL_CSFTRST ); +if (hsotg->dr_mode ==USB_DR_MODE_HOST ) { + gusbcfg =readl (hsotg->regs +GUSBCFG ); + gusbcfg &= ~GUSBCFG_FORCEDEVMODE ; + gusbcfg |=GUSBCFG_FORCEHOSTMODE ; +writel (gusbcfg, hsotg->regs +GUSBCFG ); + }else if (hsotg->dr_mode ==USB_DR_MODE_PERIPHERAL ) { + gusbcfg =readl (hsotg->regs +GUSBCFG ); + gusbcfg &= ~GUSBCFG_FORCEHOSTMODE ; + gusbcfg |=GUSBCFG_FORCEDEVMODE ; +writel (gusbcfg, hsotg->regs +GUSBCFG ); + }else if (hsotg->dr_mode ==USB_DR_MODE_OTG ) { + gusbcfg =readl (hsotg->regs +GUSBCFG ); + gusbcfg &= ~GUSBCFG_FORCEHOSTMODE ; + gusbcfg &= ~GUSBCFG_FORCEDEVMODE ; +writel (gusbcfg, hsotg->regs +GUSBCFG ); + } +/* * NOTE: This long sleep is _very_ important, otherwise the core will
* not stay in host mode after a connector ID change!drivers/usb/dwc2/core.h +0
-0@@ -501,6 +501,10 @@ struct dwc2_hw_params {* a_peripheral and b_device=>b_host) this may not match
* the core, but allows the software to determine
* transitions+ * @dr_mode: Requested mode of operation, one of following: + * - USB_DR_MODE_PERIPHERAL + * - USB_DR_MODE_HOST + * - USB_DR_MODE_OTG* @queuing_high_bandwidth: True if multiple packets of a
high-bandwidth
* transfer are in process of being queued
* @srp_success: Stores status of SRP request in the case of a
FS PHYdrivers/usb/dwc2/core.h +1
-0@@ -592,6 +596,7 @@ struct dwc2_hsotg {/** Params to actually use */ struct dwc2_core_params *core_params;enum usb_otg_state op_state; +enum usb_dr_mode dr_mode; unsigned int queuing_high_bandwidth:1; unsigned int srp_success:1;drivers/usb/dwc2/platform.c +2
-0@@ -42,6 +42,8 @@#include <linux/of_device.h> #include <linux/platform_device.h> +#include <linux/usb/of.h> +#include "core.h" #include "hcd.h" @@ -171,6 +173,16 @@ static int dwc2_driver_probe(struct platform_device *dev)dev_dbg (&dev->dev,"mapped PA %08lx to VA %p\n" , (unsigned long )res->start, hsotg->regs);drivers/usb/dwc2/platform.c static int dwc2_driver_probe(struct platform_device · line 186
Quoted 10 lines
drivers/usb/dwc2/platform.c +10
-0+ hsotg->dr_mode =of_usb_get_dr_mode (dev->dev.of_node); + +if (IS_ENABLED (CONFIG_USB_DWC2_HOST )) + hsotg->dr_mode =USB_DR_MODE_HOST ; +else if (IS_ENABLED (CONFIG_USB_DWC2_GADGET )) + hsotg->dr_mode =USB_DR_MODE_PERIPHERAL ; + +if (hsotg->dr_mode ==USB_DR_MODE_UNKNOWN ) + hsotg->dr_mode =USB_DR_MODE_OTG ; +Please remove this whole chunk. Specifically:
Quoted 4 lines
Quoted 2 lines
*
CONFIG_USB_DWC2_GADGETis not a config option and is nowhere in any KConfig files.This should be
USB_DWC2_PERIPHERAL, and I just copy it wrong from dwc3.
OK. ...so if both are defined then how does your code handle it? I'm pretty sure both can be defined.
Quoted 13 lines
Quoted 4 lines
*
CONFIG_USB_DWC2_HOSTclaims inKconfigthat we'll be in "host only" mode, but I don't think that's right. The only way you'll get any host functionality is ifCONFIG_USB_DWC2_HOSTis defined, so we'd need that defined even for OTG mode.Yeap, I add the chunk above because I'm confused by "Host only mode" for
CONFIG_USB_DWC2_HOSTinKconfig. If it's the "Host only mode", I should add thedr_modefor it to make sure the controller works in host mode.Maybe dwc2 is refer to the
Kconfigin dwc3 for there is a choice from one of "Host only mode", "Gadget only mode" and "Dual Role mode", which means the role is decided by theKconfig.
Quoted 6 lines
In my opinion, there maybe more than one controller in a Soc, and for different
usage, the mode select should not be done inKconfig, it's better to do that in dts file.
I agree with you that theCONFIG_USB_DWC2_HOSTshould defined for host functionality, not for role definition.
Right. In DWC3 you choose HOST, GADGET, or DUAL. ...but in DWC2 it appears that you can enable HOST and GADGET separately and if you enable both you get dual mode. That means that the wording in the dwc2 Kconfig file is just wrong. You could send up a patch to fix it. ;)
I think it would be fine to totally drop this chunk of code and add Paul's Ack back in. Then your patch can land. You could code up two separate patches if you want.
1. Add a new patch that fixes the wording in the KConfig
2. Add a new patch that says that if HOST is configured but not GADGET then it behaves like dr_mode=host. ...and if GADGET is configured but not host it behaves like dr_mode=gadget. Personally I don't think this patch is really useful (a single device might have some gadget ports and some host ports, or you might want a mutliplatform kernel), but you could put it up there and see if others want it.
-Doug
RE: [PATCH v3 2/2] usb: dwc2: add 'mode' which based on Kconfig select or dts setting
In reply to Kever YangQuoted 10 lines
From: Kever Yang [mailto:[email protected]]
Sent: Monday, August 04, 2014 6:46 PMQuoted 3 lines · Doug Anderson
Normally I'd say that you should have added Paul's "Acked-by" since you fixed his nit and he told you to include his Acked-by when his nit was fixed, but...
There are some more changes than Paul's suggestion, so I'm not sure if Paul need more review to give me the "Acked-by", I get it now.
Yes, you did the right thing by leaving off my ack (although you should have mentioned the additional changes in your email).
Quoted 104 lines
Quoted 88 lines
Quoted 76 lines
drivers/usb/dwc2/core.c +18
-0@@ -118,6 +118,7 @@ static int dwc2_core_reset(struct dwc2_hsotg *hsotg) {u32 greset;int count =0 ; +u32 gusbcfg;dev_vdbg (hsotg->dev,"%s()\n" , __func__);@@ -148,6 +149,23 @@ static int dwc2_core_reset(struct dwc2_hsotg *hsotg) } }while (greset &GRSTCTL_CSFTRST ); +if (hsotg->dr_mode ==USB_DR_MODE_HOST ) { + gusbcfg =readl (hsotg->regs +GUSBCFG ); + gusbcfg &= ~GUSBCFG_FORCEDEVMODE ; + gusbcfg |=GUSBCFG_FORCEHOSTMODE ; +writel (gusbcfg, hsotg->regs +GUSBCFG ); + }else if (hsotg->dr_mode ==USB_DR_MODE_PERIPHERAL ) { + gusbcfg =readl (hsotg->regs +GUSBCFG ); + gusbcfg &= ~GUSBCFG_FORCEHOSTMODE ; + gusbcfg |=GUSBCFG_FORCEDEVMODE ; +writel (gusbcfg, hsotg->regs +GUSBCFG ); + }else if (hsotg->dr_mode ==USB_DR_MODE_OTG ) { + gusbcfg =readl (hsotg->regs +GUSBCFG ); + gusbcfg &= ~GUSBCFG_FORCEHOSTMODE ; + gusbcfg &= ~GUSBCFG_FORCEDEVMODE ; +writel (gusbcfg, hsotg->regs +GUSBCFG ); + } +/* * NOTE: This long sleep is _very_ important, otherwise the core will * not stay in host mode after a connector ID change! drivers/usb/dwc2/core.h +5
-0@@ -501,6 +501,10 @@ struct dwc2_hw_params {* a_peripheral and b_device=>b_host) this may not match * the core, but allows the software to determine * transitions +* @dr_mode: Requested mode of operation, one of following: +* - USB_DR_MODE_PERIPHERAL +* - USB_DR_MODE_HOST +* - USB_DR_MODE_OTG * @queuing_high_bandwidth: True if multiple packets of a high-bandwidth * transfer are in process of being queued * @srp_success: Stores status of SRP request in the case of a FS PHY @@ -592,6 +596,7 @@ struct dwc2_hsotg {/** Params to actually use */ struct dwc2_core_params *core_params;enum usb_otg_state op_state; +enum usb_dr_mode dr_mode; unsigned int queuing_high_bandwidth:1; unsigned int srp_success:1;drivers/usb/dwc2/platform.c +2
-0@@ -42,6 +42,8 @@#include <linux/of_device.h> #include <linux/platform_device.h> +#include <linux/usb/of.h> +#include "core.h" #include "hcd.h" @@ -171,6 +173,16 @@ static int dwc2_driver_probe(struct platform_device *dev)dev_dbg (&dev->dev,"mapped PA %08lx to VA %p\n" , (unsigned long )res->start, hsotg->regs);drivers/usb/dwc2/platform.c static int dwc2_driver_probe(struct platform_device *dev) · line 185
Quoted 10 lines
drivers/usb/dwc2/platform.c +10
-0+ hsotg->dr_mode =of_usb_get_dr_mode (dev->dev.of_node); + +if (IS_ENABLED (CONFIG_USB_DWC2_HOST )) + hsotg->dr_mode =USB_DR_MODE_HOST ; +else if (IS_ENABLED (CONFIG_USB_DWC2_GADGET )) + hsotg->dr_mode =USB_DR_MODE_PERIPHERAL ; + +if (hsotg->dr_mode ==USB_DR_MODE_UNKNOWN ) + hsotg->dr_mode =USB_DR_MODE_OTG ; +Please remove this whole chunk. Specifically:
Quoted 2 lines
*
CONFIG_USB_DWC2_GADGETis not a config option and is nowhere in any KConfig files.This should be
USB_DWC2_PERIPHERAL, and I just copy it wrong from dwc3.Quoted 5 lines
*
CONFIG_USB_DWC2_HOSTclaims inKconfigthat we'll be in "host only" mode, but I don't think that's right. The only way you'll get any host functionality is ifCONFIG_USB_DWC2_HOSTis defined, so we'd need that defined even for OTG mode.Yeap, I add the chunk above because I'm confused by "Host only mode" for
CONFIG_USB_DWC2_HOSTinKconfig. If it's the "Host only mode", I should add thedr_modefor it to make sure the controller works in host mode.Maybe dwc2 is refer to the
Kconfigin dwc3 for there is a choice from one of "Host only mode", "Gadget only mode" and "Dual Role mode", which means the role is decided by theKconfig.
Quoted 8 lines
In my opinion, there maybe more than one controller in a Soc, and for different
usage, the mode select should not be done inKconfig, it's better to do that in dts file.
I agree with you that theCONFIG_USB_DWC2_HOSTshould defined for host functionality, not for role definition.Paul: what do you think?
I'm confused about how your dual-role mode implementation is supposed to work. Right now, the host and peripheral modes are compiled as separate drivers, and there is no dual-role mode in the Kconfig. So I don't see how your code can work. Have you tested it?
Dinh Nguyen is working on a patch series to add dual-role support, I think you have seen that, right? That adds the Kconfig options for all three modes. Maybe you should build on top of that?
Signature · 3 lines
Paul
���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m����������?�I�Re: [PATCH v3 2/2] usb: dwc2: add 'mode' which based on Kconfig select or dts setting
Paul,
Quoted 11 lines · Paul Zimmerman
Quoted 11 lines
Maybe dwc2 is refer to the
Kconfigin dwc3 for there is a choice from one of "Host only mode", "Gadget only mode" and "Dual Role mode", which means the role is decided by theKconfig.In my opinion, there maybe more than one controller in a Soc, and for different
usage, the mode select should not be done inKconfig, it's better to do that in dts file.
I agree with you that theCONFIG_USB_DWC2_HOSTshould defined for host functionality, not for role definition.
Quoted 6 lines
Quoted 1 line
Paul: what do you think?
I'm confused about how your dual-role mode implementation is supposed to work. Right now, the host and peripheral modes are compiled as separate drivers, and there is no dual-role mode in the
Kconfig. So I don't see how your code can work. Have you tested it?
Ah, interesting. I just assumed that since you could compile both in that dual mode was there, but I clearly was confused.
I don't think Kever had tested dual_role mode.
Quoted 3 lines
Dinh Nguyen is working on a patch series to add dual-role support, I think you have seen that, right? That adds the
Kconfigoptions for all three modes. Maybe you should build on top of that?
I hadn't personally seen it, but now I have! I guess this is the newest <https://www.mail-archive.com/[email protected]/msg46103.html>.
I haven't done a thorough review, but I think Kever's patch v4
<https://patchwork.kernel.org/patch/4682711/> is still relevant since I don't see anything parsing the dr_mode in Dinh's patches.
-Doug