usb: dwc2: add 'mode' which based on Kconfig select or dts setting
According to the "dr_mode", the otg controller can work as device role and host role. Some boards always want to use host mode and some other boards want to use gadget mode. We use the dts setting to set dwc2's mode, rather than fixing it to whatever hardware says. Signed-off-by: Kever Yang <kever.yang@rock-chips.com> Acked-by: Paul Zimmerman <paulz@synopsys.com> Tested-by: Doug Anderson <dianders@chromium.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
fc1b0e2aa3
commit
c0155b9d5e
|
@ -118,6 +118,7 @@ static int dwc2_core_reset(struct dwc2_hsotg *hsotg)
|
||||||
{
|
{
|
||||||
u32 greset;
|
u32 greset;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
u32 gusbcfg;
|
||||||
|
|
||||||
dev_vdbg(hsotg->dev, "%s()\n", __func__);
|
dev_vdbg(hsotg->dev, "%s()\n", __func__);
|
||||||
|
|
||||||
|
@ -148,6 +149,23 @@ static int dwc2_core_reset(struct dwc2_hsotg *hsotg)
|
||||||
}
|
}
|
||||||
} while (greset & GRSTCTL_CSFTRST);
|
} 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
|
* NOTE: This long sleep is _very_ important, otherwise the core will
|
||||||
* not stay in host mode after a connector ID change!
|
* not stay in host mode after a connector ID change!
|
||||||
|
|
|
@ -501,6 +501,10 @@ struct dwc2_hw_params {
|
||||||
* a_peripheral and b_device=>b_host) this may not match
|
* a_peripheral and b_device=>b_host) this may not match
|
||||||
* the core, but allows the software to determine
|
* the core, but allows the software to determine
|
||||||
* transitions
|
* 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
|
* @queuing_high_bandwidth: True if multiple packets of a high-bandwidth
|
||||||
* transfer are in process of being queued
|
* transfer are in process of being queued
|
||||||
* @srp_success: Stores status of SRP request in the case of a FS PHY
|
* @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 */
|
/** Params to actually use */
|
||||||
struct dwc2_core_params *core_params;
|
struct dwc2_core_params *core_params;
|
||||||
enum usb_otg_state op_state;
|
enum usb_otg_state op_state;
|
||||||
|
enum usb_dr_mode dr_mode;
|
||||||
|
|
||||||
unsigned int queuing_high_bandwidth:1;
|
unsigned int queuing_high_bandwidth:1;
|
||||||
unsigned int srp_success:1;
|
unsigned int srp_success:1;
|
||||||
|
|
|
@ -42,6 +42,8 @@
|
||||||
#include <linux/of_device.h>
|
#include <linux/of_device.h>
|
||||||
#include <linux/platform_device.h>
|
#include <linux/platform_device.h>
|
||||||
|
|
||||||
|
#include <linux/usb/of.h>
|
||||||
|
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
#include "hcd.h"
|
#include "hcd.h"
|
||||||
|
|
||||||
|
@ -200,6 +202,8 @@ static int dwc2_driver_probe(struct platform_device *dev)
|
||||||
dev_dbg(&dev->dev, "mapped PA %08lx to VA %p\n",
|
dev_dbg(&dev->dev, "mapped PA %08lx to VA %p\n",
|
||||||
(unsigned long)res->start, hsotg->regs);
|
(unsigned long)res->start, hsotg->regs);
|
||||||
|
|
||||||
|
hsotg->dr_mode = of_usb_get_dr_mode(dev->dev.of_node);
|
||||||
|
|
||||||
retval = dwc2_hcd_init(hsotg, irq, params);
|
retval = dwc2_hcd_init(hsotg, irq, params);
|
||||||
if (retval)
|
if (retval)
|
||||||
return retval;
|
return retval;
|
||||||
|
|
Loading…
Reference in New Issue