Add support for specifying USB controller mode via FDT.

Add FDT support to the DWC OTG kernel module.

Submitted by:	John Wehle <john@feith.com>
PR:		usb/188683
MFC after:	1 week
This commit is contained in:
Hans Petter Selasky 2014-04-18 08:31:55 +00:00
parent 8a00edea58
commit 491d5d0577
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=264642
3 changed files with 27 additions and 4 deletions

View File

@ -2149,7 +2149,12 @@ dwc_otg_vbus_interrupt(struct dwc_otg_softc *sc, uint8_t is_on)
{
DPRINTFN(5, "vbus = %u\n", is_on);
if (is_on) {
/*
* If the USB host mode is forced, then assume VBUS is always
* present else rely on the input to this function:
*/
if ((is_on != 0) || (sc->sc_mode == DWC_MODE_HOST)) {
if (!sc->sc_flags.status_vbus) {
sc->sc_flags.status_vbus = 1;
@ -3182,7 +3187,7 @@ dwc_otg_init(struct dwc_otg_softc *sc)
sc->sc_host_ch_max);
/* setup FIFO */
if (dwc_otg_init_fifo(sc, DWC_MODE_OTG))
if (dwc_otg_init_fifo(sc, sc->sc_mode))
return (EINVAL);
/* enable interrupts */

View File

@ -91,6 +91,7 @@ static int
dwc_otg_attach(device_t dev)
{
struct dwc_otg_super_softc *sc = device_get_softc(dev);
char usb_mode[24];
int err;
int rid;
@ -99,6 +100,23 @@ dwc_otg_attach(device_t dev)
sc->sc_otg.sc_bus.devices = sc->sc_otg.sc_devices;
sc->sc_otg.sc_bus.devices_max = DWC_OTG_MAX_DEVICES;
/* get USB mode, if any */
if (OF_getprop(ofw_bus_get_node(dev), "dr_mode",
&usb_mode, sizeof(usb_mode)) > 0) {
/* ensure proper zero termination */
usb_mode[sizeof(usb_mode) - 1] = 0;
if (strcasecmp(usb_mode, "host") == 0)
sc->sc_otg.sc_mode = DWC_MODE_HOST;
else if (strcasecmp(usb_mode, "peripheral") == 0)
sc->sc_otg.sc_mode = DWC_MODE_DEVICE;
else if (strcasecmp(usb_mode, "otg") != 0) {
device_printf(dev, "Invalid FDT dr_mode: %s\n",
usb_mode);
}
}
/* get all DMA memory */
if (usb_bus_mem_alloc_all(&sc->sc_otg.sc_bus,
USB_GET_DMA_TAG(dev), NULL)) {

View File

@ -31,8 +31,8 @@ S= ${.CURDIR}/../../..
KMOD= dwc_otg
SRCS= bus_if.h device_if.h usb_if.h \
opt_bus.h opt_usb.h \
dwc_otg.c \
opt_bus.h opt_usb.h ofw_bus_if.h \
dwc_otg.c dwc_otg_fdt.c \
pci_if.h
.if defined(HAS_ATMELARM)