Initialize the host and gagdet subsystems of the musb driver only when the appropriate mode is selected from platform data, or device-tree information, respectively. Refuse to start the gadget part if the port is in host-only mode. Signed-off-by: Daniel Mack <zonque@xxxxxxxxx> --- drivers/usb/musb/musb_core.c | 25 +++++++++++++++++-------- drivers/usb/musb/musb_core.h | 7 +++++++ drivers/usb/musb/musb_gadget.c | 5 +++++ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index cb1631e..c021058 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -943,10 +943,12 @@ void musb_start(struct musb *musb) * (b) vbus present/connect IRQ, peripheral mode; * (c) peripheral initiates, using SRP */ - if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) + if (musb->port_mode != MUSB_PORT_MODE_HOST && + (devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) { musb->is_active = 1; - else + } else { devctl |= MUSB_DEVCTL_SESSION; + } musb_platform_enable(musb); musb_writeb(regs, MUSB_DEVCTL, devctl); @@ -1868,6 +1870,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl) musb->board_set_power = plat->set_power; musb->min_power = plat->min_power; musb->ops = plat->platform_ops; + musb->port_mode = plat->mode; /* The musb_platform_init() call: * - adjusts musb->mregs @@ -1958,13 +1961,19 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl) musb->xceiv->state = OTG_STATE_B_IDLE; } - status = musb_host_setup(musb, plat->power); - if (status < 0) - goto fail3; + if (musb->port_mode == MUSB_PORT_MODE_HOST || + musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE) { + status = musb_host_setup(musb, plat->power); + if (status < 0) + goto fail3; + } - status = musb_gadget_setup(musb); - if (status < 0) - goto fail3; + if (musb->port_mode == MUSB_PORT_MODE_GADGET || + musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE) { + status = musb_gadget_setup(musb); + if (status < 0) + goto fail3; + } status = musb_init_debugfs(musb); if (status < 0) diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h index ef5b4e6..ed1644f 100644 --- a/drivers/usb/musb/musb_core.h +++ b/drivers/usb/musb/musb_core.h @@ -77,6 +77,12 @@ struct musb_ep; #define is_peripheral_active(m) (!(m)->is_host) #define is_host_active(m) ((m)->is_host) +enum { + MUSB_PORT_MODE_HOST = 1, + MUSB_PORT_MODE_GADGET = 2, + MUSB_PORT_MODE_DUAL_ROLE = 3, +}; + #ifdef CONFIG_PROC_FS #include <linux/fs.h> #define MUSB_CONFIG_PROC_FS @@ -356,6 +362,7 @@ struct musb { u8 min_power; /* vbus for periph, in mA/2 */ + int port_mode; /* MUSB_PORT_MODE_* */ bool is_host; int a_wait_bcon; /* VBUS timeout in msecs */ diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c index 0414bc1..c606088 100644 --- a/drivers/usb/musb/musb_gadget.c +++ b/drivers/usb/musb/musb_gadget.c @@ -1823,6 +1823,11 @@ static int musb_gadget_start(struct usb_gadget *g, unsigned long flags; int retval = 0; + if (musb->port_mode == MUSB_PORT_MODE_HOST) { + retval = -EINVAL; + goto err; + } + if (driver->max_speed < USB_SPEED_HIGH) { retval = -EINVAL; goto err; -- 1.8.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html