usb: dwc3: adapt to use dr_mode device tree helper
This patch adapts the dwc3 to use the device tree helper "of_usb_get_dr_mode" for the mode of operation of the dwc3 instance being probed. [ balbi@ti.com : make of_usb_get_dr_mode() conditional on dev->of_node and let pdata pass dr_mode too ] Reviewed-by: Roger Quadros <rogerq@ti.com> Signed-off-by: Ruchika Kharwar <ruchika@ti.com> Signed-off-by: Felipe Balbi <balbi@ti.com>
This commit is contained in:
Родитель
51e563e3c1
Коммит
a45c82b84c
|
@ -37,6 +37,7 @@
|
||||||
#include <linux/usb/ch9.h>
|
#include <linux/usb/ch9.h>
|
||||||
#include <linux/usb/gadget.h>
|
#include <linux/usb/gadget.h>
|
||||||
#include <linux/usb/of.h>
|
#include <linux/usb/of.h>
|
||||||
|
#include <linux/usb/otg.h>
|
||||||
|
|
||||||
#include "platform_data.h"
|
#include "platform_data.h"
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
|
@ -359,8 +360,6 @@ static int dwc3_probe(struct platform_device *pdev)
|
||||||
void __iomem *regs;
|
void __iomem *regs;
|
||||||
void *mem;
|
void *mem;
|
||||||
|
|
||||||
u8 mode;
|
|
||||||
|
|
||||||
mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL);
|
mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL);
|
||||||
if (!mem) {
|
if (!mem) {
|
||||||
dev_err(dev, "not enough memory\n");
|
dev_err(dev, "not enough memory\n");
|
||||||
|
@ -415,6 +414,7 @@ static int dwc3_probe(struct platform_device *pdev)
|
||||||
dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1);
|
dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1);
|
||||||
|
|
||||||
dwc->needs_fifo_resize = of_property_read_bool(node, "tx-fifo-resize");
|
dwc->needs_fifo_resize = of_property_read_bool(node, "tx-fifo-resize");
|
||||||
|
dwc->dr_mode = of_usb_get_dr_mode(node);
|
||||||
} else {
|
} else {
|
||||||
dwc->maximum_speed = pdata->maximum_speed;
|
dwc->maximum_speed = pdata->maximum_speed;
|
||||||
|
|
||||||
|
@ -422,6 +422,7 @@ static int dwc3_probe(struct platform_device *pdev)
|
||||||
dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3);
|
dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3);
|
||||||
|
|
||||||
dwc->needs_fifo_resize = pdata->tx_fifo_resize;
|
dwc->needs_fifo_resize = pdata->tx_fifo_resize;
|
||||||
|
dwc->dr_mode = pdata->dr_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* default to superspeed if no maximum_speed passed */
|
/* default to superspeed if no maximum_speed passed */
|
||||||
|
@ -498,14 +499,15 @@ static int dwc3_probe(struct platform_device *pdev)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_ENABLED(CONFIG_USB_DWC3_HOST))
|
if (IS_ENABLED(CONFIG_USB_DWC3_HOST))
|
||||||
mode = DWC3_MODE_HOST;
|
dwc->dr_mode = USB_DR_MODE_HOST;
|
||||||
else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET))
|
else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET))
|
||||||
mode = DWC3_MODE_DEVICE;
|
dwc->dr_mode = USB_DR_MODE_PERIPHERAL;
|
||||||
else
|
|
||||||
mode = DWC3_MODE_DRD;
|
|
||||||
|
|
||||||
switch (mode) {
|
if (dwc->dr_mode == USB_DR_MODE_UNKNOWN)
|
||||||
case DWC3_MODE_DEVICE:
|
dwc->dr_mode = USB_DR_MODE_OTG;
|
||||||
|
|
||||||
|
switch (dwc->dr_mode) {
|
||||||
|
case USB_DR_MODE_PERIPHERAL:
|
||||||
dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
|
dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
|
||||||
ret = dwc3_gadget_init(dwc);
|
ret = dwc3_gadget_init(dwc);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
@ -513,7 +515,7 @@ static int dwc3_probe(struct platform_device *pdev)
|
||||||
goto err2;
|
goto err2;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DWC3_MODE_HOST:
|
case USB_DR_MODE_HOST:
|
||||||
dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST);
|
dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST);
|
||||||
ret = dwc3_host_init(dwc);
|
ret = dwc3_host_init(dwc);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
@ -521,7 +523,7 @@ static int dwc3_probe(struct platform_device *pdev)
|
||||||
goto err2;
|
goto err2;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DWC3_MODE_DRD:
|
case USB_DR_MODE_OTG:
|
||||||
dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG);
|
dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG);
|
||||||
ret = dwc3_host_init(dwc);
|
ret = dwc3_host_init(dwc);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
@ -536,10 +538,9 @@ static int dwc3_probe(struct platform_device *pdev)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dev_err(dev, "Unsupported mode of operation %d\n", mode);
|
dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode);
|
||||||
goto err2;
|
goto err2;
|
||||||
}
|
}
|
||||||
dwc->mode = mode;
|
|
||||||
|
|
||||||
ret = dwc3_debugfs_init(dwc);
|
ret = dwc3_debugfs_init(dwc);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
@ -552,14 +553,14 @@ static int dwc3_probe(struct platform_device *pdev)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err3:
|
err3:
|
||||||
switch (mode) {
|
switch (dwc->dr_mode) {
|
||||||
case DWC3_MODE_DEVICE:
|
case USB_DR_MODE_PERIPHERAL:
|
||||||
dwc3_gadget_exit(dwc);
|
dwc3_gadget_exit(dwc);
|
||||||
break;
|
break;
|
||||||
case DWC3_MODE_HOST:
|
case USB_DR_MODE_HOST:
|
||||||
dwc3_host_exit(dwc);
|
dwc3_host_exit(dwc);
|
||||||
break;
|
break;
|
||||||
case DWC3_MODE_DRD:
|
case USB_DR_MODE_OTG:
|
||||||
dwc3_host_exit(dwc);
|
dwc3_host_exit(dwc);
|
||||||
dwc3_gadget_exit(dwc);
|
dwc3_gadget_exit(dwc);
|
||||||
break;
|
break;
|
||||||
|
@ -592,14 +593,14 @@ static int dwc3_remove(struct platform_device *pdev)
|
||||||
|
|
||||||
dwc3_debugfs_exit(dwc);
|
dwc3_debugfs_exit(dwc);
|
||||||
|
|
||||||
switch (dwc->mode) {
|
switch (dwc->dr_mode) {
|
||||||
case DWC3_MODE_DEVICE:
|
case USB_DR_MODE_PERIPHERAL:
|
||||||
dwc3_gadget_exit(dwc);
|
dwc3_gadget_exit(dwc);
|
||||||
break;
|
break;
|
||||||
case DWC3_MODE_HOST:
|
case USB_DR_MODE_HOST:
|
||||||
dwc3_host_exit(dwc);
|
dwc3_host_exit(dwc);
|
||||||
break;
|
break;
|
||||||
case DWC3_MODE_DRD:
|
case USB_DR_MODE_OTG:
|
||||||
dwc3_host_exit(dwc);
|
dwc3_host_exit(dwc);
|
||||||
dwc3_gadget_exit(dwc);
|
dwc3_gadget_exit(dwc);
|
||||||
break;
|
break;
|
||||||
|
@ -623,12 +624,12 @@ static int dwc3_prepare(struct device *dev)
|
||||||
|
|
||||||
spin_lock_irqsave(&dwc->lock, flags);
|
spin_lock_irqsave(&dwc->lock, flags);
|
||||||
|
|
||||||
switch (dwc->mode) {
|
switch (dwc->dr_mode) {
|
||||||
case DWC3_MODE_DEVICE:
|
case USB_DR_MODE_PERIPHERAL:
|
||||||
case DWC3_MODE_DRD:
|
case USB_DR_MODE_OTG:
|
||||||
dwc3_gadget_prepare(dwc);
|
dwc3_gadget_prepare(dwc);
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
case DWC3_MODE_HOST:
|
case USB_DR_MODE_HOST:
|
||||||
default:
|
default:
|
||||||
dwc3_event_buffers_cleanup(dwc);
|
dwc3_event_buffers_cleanup(dwc);
|
||||||
break;
|
break;
|
||||||
|
@ -646,12 +647,12 @@ static void dwc3_complete(struct device *dev)
|
||||||
|
|
||||||
spin_lock_irqsave(&dwc->lock, flags);
|
spin_lock_irqsave(&dwc->lock, flags);
|
||||||
|
|
||||||
switch (dwc->mode) {
|
switch (dwc->dr_mode) {
|
||||||
case DWC3_MODE_DEVICE:
|
case USB_DR_MODE_PERIPHERAL:
|
||||||
case DWC3_MODE_DRD:
|
case USB_DR_MODE_OTG:
|
||||||
dwc3_gadget_complete(dwc);
|
dwc3_gadget_complete(dwc);
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
case DWC3_MODE_HOST:
|
case USB_DR_MODE_HOST:
|
||||||
default:
|
default:
|
||||||
dwc3_event_buffers_setup(dwc);
|
dwc3_event_buffers_setup(dwc);
|
||||||
break;
|
break;
|
||||||
|
@ -667,12 +668,12 @@ static int dwc3_suspend(struct device *dev)
|
||||||
|
|
||||||
spin_lock_irqsave(&dwc->lock, flags);
|
spin_lock_irqsave(&dwc->lock, flags);
|
||||||
|
|
||||||
switch (dwc->mode) {
|
switch (dwc->dr_mode) {
|
||||||
case DWC3_MODE_DEVICE:
|
case USB_DR_MODE_PERIPHERAL:
|
||||||
case DWC3_MODE_DRD:
|
case USB_DR_MODE_OTG:
|
||||||
dwc3_gadget_suspend(dwc);
|
dwc3_gadget_suspend(dwc);
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
case DWC3_MODE_HOST:
|
case USB_DR_MODE_HOST:
|
||||||
default:
|
default:
|
||||||
/* do nothing */
|
/* do nothing */
|
||||||
break;
|
break;
|
||||||
|
@ -700,12 +701,12 @@ static int dwc3_resume(struct device *dev)
|
||||||
|
|
||||||
dwc3_writel(dwc->regs, DWC3_GCTL, dwc->gctl);
|
dwc3_writel(dwc->regs, DWC3_GCTL, dwc->gctl);
|
||||||
|
|
||||||
switch (dwc->mode) {
|
switch (dwc->dr_mode) {
|
||||||
case DWC3_MODE_DEVICE:
|
case USB_DR_MODE_PERIPHERAL:
|
||||||
case DWC3_MODE_DRD:
|
case USB_DR_MODE_OTG:
|
||||||
dwc3_gadget_resume(dwc);
|
dwc3_gadget_resume(dwc);
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
case DWC3_MODE_HOST:
|
case USB_DR_MODE_HOST:
|
||||||
default:
|
default:
|
||||||
/* do nothing */
|
/* do nothing */
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
#include <linux/usb/ch9.h>
|
#include <linux/usb/ch9.h>
|
||||||
#include <linux/usb/gadget.h>
|
#include <linux/usb/gadget.h>
|
||||||
|
#include <linux/usb/otg.h>
|
||||||
|
|
||||||
/* Global constants */
|
/* Global constants */
|
||||||
#define DWC3_EP0_BOUNCE_SIZE 512
|
#define DWC3_EP0_BOUNCE_SIZE 512
|
||||||
|
@ -545,11 +546,6 @@ struct dwc3_hwparams {
|
||||||
/* HWPARAMS0 */
|
/* HWPARAMS0 */
|
||||||
#define DWC3_MODE(n) ((n) & 0x7)
|
#define DWC3_MODE(n) ((n) & 0x7)
|
||||||
|
|
||||||
#define DWC3_MODE_DEVICE 0
|
|
||||||
#define DWC3_MODE_HOST 1
|
|
||||||
#define DWC3_MODE_DRD 2
|
|
||||||
#define DWC3_MODE_HUB 3
|
|
||||||
|
|
||||||
#define DWC3_MDWIDTH(n) (((n) & 0xff00) >> 8)
|
#define DWC3_MDWIDTH(n) (((n) & 0xff00) >> 8)
|
||||||
|
|
||||||
/* HWPARAMS1 */
|
/* HWPARAMS1 */
|
||||||
|
@ -611,7 +607,7 @@ struct dwc3_scratchpad_array {
|
||||||
* @u1u2: only used on revisions <1.83a for workaround
|
* @u1u2: only used on revisions <1.83a for workaround
|
||||||
* @maximum_speed: maximum speed requested (mainly for testing purposes)
|
* @maximum_speed: maximum speed requested (mainly for testing purposes)
|
||||||
* @revision: revision register contents
|
* @revision: revision register contents
|
||||||
* @mode: mode of operation
|
* @dr_mode: requested mode of operation
|
||||||
* @usb2_phy: pointer to USB2 PHY
|
* @usb2_phy: pointer to USB2 PHY
|
||||||
* @usb3_phy: pointer to USB3 PHY
|
* @usb3_phy: pointer to USB3 PHY
|
||||||
* @dcfg: saved contents of DCFG register
|
* @dcfg: saved contents of DCFG register
|
||||||
|
@ -669,6 +665,8 @@ struct dwc3 {
|
||||||
void __iomem *regs;
|
void __iomem *regs;
|
||||||
size_t regs_size;
|
size_t regs_size;
|
||||||
|
|
||||||
|
enum usb_dr_mode dr_mode;
|
||||||
|
|
||||||
/* used for suspend/resume */
|
/* used for suspend/resume */
|
||||||
u32 dcfg;
|
u32 dcfg;
|
||||||
u32 gctl;
|
u32 gctl;
|
||||||
|
@ -677,7 +675,6 @@ struct dwc3 {
|
||||||
u32 u1u2;
|
u32 u1u2;
|
||||||
u32 maximum_speed;
|
u32 maximum_speed;
|
||||||
u32 revision;
|
u32 revision;
|
||||||
u32 mode;
|
|
||||||
|
|
||||||
#define DWC3_REVISION_173A 0x5533173a
|
#define DWC3_REVISION_173A 0x5533173a
|
||||||
#define DWC3_REVISION_175A 0x5533175a
|
#define DWC3_REVISION_175A 0x5533175a
|
||||||
|
|
|
@ -18,8 +18,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <linux/usb/ch9.h>
|
#include <linux/usb/ch9.h>
|
||||||
|
#include <linux/usb/otg.h>
|
||||||
|
|
||||||
struct dwc3_platform_data {
|
struct dwc3_platform_data {
|
||||||
enum usb_device_speed maximum_speed;
|
enum usb_device_speed maximum_speed;
|
||||||
|
enum usb_dr_mode dr_mode;
|
||||||
bool tx_fifo_resize;
|
bool tx_fifo_resize;
|
||||||
};
|
};
|
||||||
|
|
Загрузка…
Ссылка в новой задаче