| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Texas Instruments DA8xx/OMAP-L1x "glue layer" | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (c) 2008-2009 MontaVista Software, Inc. <source@mvista.com> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Based on the DaVinci "glue layer" code. | 
					
						
							|  |  |  |  * Copyright (C) 2005-2006 by Texas Instruments | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This file is part of the Inventra Controller Driver for Linux. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Inventra Controller Driver for Linux is free software; you | 
					
						
							|  |  |  |  * can redistribute it and/or modify it under the terms of the GNU | 
					
						
							|  |  |  |  * General Public License version 2 as published by the Free Software | 
					
						
							|  |  |  |  * Foundation. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Inventra Controller Driver for Linux is distributed in | 
					
						
							|  |  |  |  * the hope that it will be useful, but WITHOUT ANY WARRANTY; | 
					
						
							|  |  |  |  * without even the implied warranty of MERCHANTABILITY or | 
					
						
							|  |  |  |  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public | 
					
						
							|  |  |  |  * License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with The Inventra Controller Driver for Linux ; if not, | 
					
						
							|  |  |  |  * write to the Free Software Foundation, Inc., 59 Temple Place, | 
					
						
							|  |  |  |  * Suite 330, Boston, MA  02111-1307  USA | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-10 09:58:04 +02:00
										 |  |  | #include <linux/module.h>
 | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | #include <linux/clk.h>
 | 
					
						
							| 
									
										
										
										
											2012-06-26 17:40:32 +05:30
										 |  |  | #include <linux/err.h>
 | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | #include <linux/io.h>
 | 
					
						
							| 
									
										
										
										
											2010-12-02 09:19:35 +02:00
										 |  |  | #include <linux/platform_device.h>
 | 
					
						
							|  |  |  | #include <linux/dma-mapping.h>
 | 
					
						
							| 
									
										
										
										
											2013-07-26 12:16:42 +02:00
										 |  |  | #include <linux/usb/usb_phy_gen_xceiv.h>
 | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <mach/da8xx.h>
 | 
					
						
							| 
									
										
										
										
											2012-08-24 15:11:34 +02:00
										 |  |  | #include <linux/platform_data/usb-davinci.h>
 | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "musb_core.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * DA8XX specific definitions | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* USB 2.0 OTG module registers */ | 
					
						
							|  |  |  | #define DA8XX_USB_REVISION_REG	0x00
 | 
					
						
							|  |  |  | #define DA8XX_USB_CTRL_REG	0x04
 | 
					
						
							|  |  |  | #define DA8XX_USB_STAT_REG	0x08
 | 
					
						
							|  |  |  | #define DA8XX_USB_EMULATION_REG 0x0c
 | 
					
						
							|  |  |  | #define DA8XX_USB_MODE_REG	0x10	/* Transparent, CDC, [Generic] RNDIS */
 | 
					
						
							|  |  |  | #define DA8XX_USB_AUTOREQ_REG	0x14
 | 
					
						
							|  |  |  | #define DA8XX_USB_SRP_FIX_TIME_REG 0x18
 | 
					
						
							|  |  |  | #define DA8XX_USB_TEARDOWN_REG	0x1c
 | 
					
						
							|  |  |  | #define DA8XX_USB_INTR_SRC_REG	0x20
 | 
					
						
							|  |  |  | #define DA8XX_USB_INTR_SRC_SET_REG 0x24
 | 
					
						
							|  |  |  | #define DA8XX_USB_INTR_SRC_CLEAR_REG 0x28
 | 
					
						
							|  |  |  | #define DA8XX_USB_INTR_MASK_REG 0x2c
 | 
					
						
							|  |  |  | #define DA8XX_USB_INTR_MASK_SET_REG 0x30
 | 
					
						
							|  |  |  | #define DA8XX_USB_INTR_MASK_CLEAR_REG 0x34
 | 
					
						
							|  |  |  | #define DA8XX_USB_INTR_SRC_MASKED_REG 0x38
 | 
					
						
							|  |  |  | #define DA8XX_USB_END_OF_INTR_REG 0x3c
 | 
					
						
							|  |  |  | #define DA8XX_USB_GENERIC_RNDIS_EP_SIZE_REG(n) (0x50 + (((n) - 1) << 2))
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Control register bits */ | 
					
						
							|  |  |  | #define DA8XX_SOFT_RESET_MASK	1
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define DA8XX_USB_TX_EP_MASK	0x1f		/* EP0 + 4 Tx EPs */
 | 
					
						
							|  |  |  | #define DA8XX_USB_RX_EP_MASK	0x1e		/* 4 Rx EPs */
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* USB interrupt register bits */ | 
					
						
							|  |  |  | #define DA8XX_INTR_USB_SHIFT	16
 | 
					
						
							|  |  |  | #define DA8XX_INTR_USB_MASK	(0x1ff << DA8XX_INTR_USB_SHIFT) /* 8 Mentor */
 | 
					
						
							|  |  |  | 					/* interrupts and DRVVBUS interrupt */ | 
					
						
							|  |  |  | #define DA8XX_INTR_DRVVBUS	0x100
 | 
					
						
							|  |  |  | #define DA8XX_INTR_RX_SHIFT	8
 | 
					
						
							|  |  |  | #define DA8XX_INTR_RX_MASK	(DA8XX_USB_RX_EP_MASK << DA8XX_INTR_RX_SHIFT)
 | 
					
						
							|  |  |  | #define DA8XX_INTR_TX_SHIFT	0
 | 
					
						
							|  |  |  | #define DA8XX_INTR_TX_MASK	(DA8XX_USB_TX_EP_MASK << DA8XX_INTR_TX_SHIFT)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define DA8XX_MENTOR_CORE_OFFSET 0x400
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define CFGCHIP2	IO_ADDRESS(DA8XX_SYSCFG0_BASE + DA8XX_CFGCHIP2_REG)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-02 09:40:34 +02:00
										 |  |  | struct da8xx_glue { | 
					
						
							|  |  |  | 	struct device		*dev; | 
					
						
							|  |  |  | 	struct platform_device	*musb; | 
					
						
							| 
									
										
										
										
											2010-12-02 09:57:08 +02:00
										 |  |  | 	struct clk		*clk; | 
					
						
							| 
									
										
										
										
											2010-12-02 09:40:34 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * REVISIT (PM): we should be able to keep the PHY in low power mode most | 
					
						
							|  |  |  |  * of the time (24 MHz oscillator and PLL off, etc.) by setting POWER.D0 | 
					
						
							|  |  |  |  * and, when in host mode, autosuspending idle root ports... PHY_PLLON | 
					
						
							|  |  |  |  * (overriding SUSPENDM?) then likely needs to stay off. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void phy_on(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u32 cfgchip2 = __raw_readl(CFGCHIP2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Start the on-chip PHY and its PLL. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	cfgchip2 &= ~(CFGCHIP2_RESET | CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN); | 
					
						
							|  |  |  | 	cfgchip2 |= CFGCHIP2_PHY_PLLON; | 
					
						
							|  |  |  | 	__raw_writel(cfgchip2, CFGCHIP2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	pr_info("Waiting for USB PHY clock good...\n"); | 
					
						
							|  |  |  | 	while (!(__raw_readl(CFGCHIP2) & CFGCHIP2_PHYCLKGD)) | 
					
						
							|  |  |  | 		cpu_relax(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void phy_off(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u32 cfgchip2 = __raw_readl(CFGCHIP2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Ensure that USB 1.1 reference clock is not being sourced from | 
					
						
							|  |  |  | 	 * USB 2.0 PHY.  Otherwise do not power down the PHY. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (!(cfgchip2 & CFGCHIP2_USB1PHYCLKMUX) && | 
					
						
							|  |  |  | 	     (cfgchip2 & CFGCHIP2_USB1SUSPENDM)) { | 
					
						
							|  |  |  | 		pr_warning("USB 1.1 clocked from USB 2.0 PHY -- " | 
					
						
							|  |  |  | 			   "can't power it down\n"); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Power down the on-chip PHY. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	cfgchip2 |= CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN; | 
					
						
							|  |  |  | 	__raw_writel(cfgchip2, CFGCHIP2); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Because we don't set CTRL.UINT, it's "important" to: | 
					
						
							|  |  |  |  *	- not read/write INTRUSB/INTRUSBE (except during | 
					
						
							|  |  |  |  *	  initial setup, as a workaround); | 
					
						
							|  |  |  |  *	- use INTSET/INTCLR instead. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2010-12-01 13:22:05 +02:00
										 |  |  |  * da8xx_musb_enable - enable interrupts | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2010-12-01 13:22:05 +02:00
										 |  |  | static void da8xx_musb_enable(struct musb *musb) | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | { | 
					
						
							|  |  |  | 	void __iomem *reg_base = musb->ctrl_base; | 
					
						
							|  |  |  | 	u32 mask; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Workaround: setup IRQs through both register sets. */ | 
					
						
							|  |  |  | 	mask = ((musb->epmask & DA8XX_USB_TX_EP_MASK) << DA8XX_INTR_TX_SHIFT) | | 
					
						
							|  |  |  | 	       ((musb->epmask & DA8XX_USB_RX_EP_MASK) << DA8XX_INTR_RX_SHIFT) | | 
					
						
							|  |  |  | 	       DA8XX_INTR_USB_MASK; | 
					
						
							|  |  |  | 	musb_writel(reg_base, DA8XX_USB_INTR_MASK_SET_REG, mask); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Force the DRVVBUS IRQ so we can start polling for ID change. */ | 
					
						
							| 
									
										
										
										
											2011-11-24 15:46:26 +02:00
										 |  |  | 	musb_writel(reg_base, DA8XX_USB_INTR_SRC_SET_REG, | 
					
						
							|  |  |  | 			DA8XX_INTR_DRVVBUS << DA8XX_INTR_USB_SHIFT); | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2010-12-01 13:22:05 +02:00
										 |  |  |  * da8xx_musb_disable - disable HDRC and flush interrupts | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2010-12-01 13:22:05 +02:00
										 |  |  | static void da8xx_musb_disable(struct musb *musb) | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | { | 
					
						
							|  |  |  | 	void __iomem *reg_base = musb->ctrl_base; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	musb_writel(reg_base, DA8XX_USB_INTR_MASK_CLEAR_REG, | 
					
						
							|  |  |  | 		    DA8XX_INTR_USB_MASK | | 
					
						
							|  |  |  | 		    DA8XX_INTR_TX_MASK | DA8XX_INTR_RX_MASK); | 
					
						
							|  |  |  | 	musb_writeb(musb->mregs, MUSB_DEVCTL, 0); | 
					
						
							|  |  |  | 	musb_writel(reg_base, DA8XX_USB_END_OF_INTR_REG, 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-22 17:28:09 +03:00
										 |  |  | #define portstate(stmt)		stmt
 | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-01 13:22:05 +02:00
										 |  |  | static void da8xx_musb_set_vbus(struct musb *musb, int is_on) | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | { | 
					
						
							|  |  |  | 	WARN_ON(is_on && is_peripheral_active(musb)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define	POLL_SECONDS	2
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct timer_list otg_workaround; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void otg_timer(unsigned long _musb) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct musb		*musb = (void *)_musb; | 
					
						
							|  |  |  | 	void __iomem		*mregs = musb->mregs; | 
					
						
							|  |  |  | 	u8			devctl; | 
					
						
							|  |  |  | 	unsigned long		flags; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * We poll because DaVinci's won't expose several OTG-critical | 
					
						
							|  |  |  | 	 * status change events (from the transceiver) otherwise. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	devctl = musb_readb(mregs, MUSB_DEVCTL); | 
					
						
							| 
									
										
										
										
											2011-05-11 12:44:08 +03:00
										 |  |  | 	dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl, | 
					
						
							| 
									
										
										
										
											2013-03-07 10:39:57 +02:00
										 |  |  | 		usb_otg_state_string(musb->xceiv->state)); | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&musb->lock, flags); | 
					
						
							|  |  |  | 	switch (musb->xceiv->state) { | 
					
						
							|  |  |  | 	case OTG_STATE_A_WAIT_BCON: | 
					
						
							|  |  |  | 		devctl &= ~MUSB_DEVCTL_SESSION; | 
					
						
							|  |  |  | 		musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		devctl = musb_readb(musb->mregs, MUSB_DEVCTL); | 
					
						
							|  |  |  | 		if (devctl & MUSB_DEVCTL_BDEVICE) { | 
					
						
							|  |  |  | 			musb->xceiv->state = OTG_STATE_B_IDLE; | 
					
						
							|  |  |  | 			MUSB_DEV_MODE(musb); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			musb->xceiv->state = OTG_STATE_A_IDLE; | 
					
						
							|  |  |  | 			MUSB_HST_MODE(musb); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case OTG_STATE_A_WAIT_VFALL: | 
					
						
							|  |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * Wait till VBUS falls below SessionEnd (~0.2 V); the 1.3 | 
					
						
							|  |  |  | 		 * RTL seems to mis-handle session "start" otherwise (or in | 
					
						
							|  |  |  | 		 * our case "recover"), in routine "VBUS was valid by the time | 
					
						
							|  |  |  | 		 * VBUSERR got reported during enumeration" cases. | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		if (devctl & MUSB_DEVCTL_VBUS) { | 
					
						
							|  |  |  | 			mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; | 
					
						
							|  |  |  | 		musb_writel(musb->ctrl_base, DA8XX_USB_INTR_SRC_SET_REG, | 
					
						
							|  |  |  | 			    MUSB_INTR_VBUSERROR << DA8XX_INTR_USB_SHIFT); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case OTG_STATE_B_IDLE: | 
					
						
							|  |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * There's no ID-changed IRQ, so we have no good way to tell | 
					
						
							|  |  |  | 		 * when to switch to the A-Default state machine (by setting | 
					
						
							|  |  |  | 		 * the DEVCTL.Session bit). | 
					
						
							|  |  |  | 		 * | 
					
						
							|  |  |  | 		 * Workaround:  whenever we're in B_IDLE, try setting the | 
					
						
							|  |  |  | 		 * session flag every few seconds.  If it works, ID was | 
					
						
							|  |  |  | 		 * grounded and we're now in the A-Default state machine. | 
					
						
							|  |  |  | 		 * | 
					
						
							|  |  |  | 		 * NOTE: setting the session flag is _supposed_ to trigger | 
					
						
							|  |  |  | 		 * SRP but clearly it doesn't. | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		musb_writeb(mregs, MUSB_DEVCTL, devctl | MUSB_DEVCTL_SESSION); | 
					
						
							|  |  |  | 		devctl = musb_readb(mregs, MUSB_DEVCTL); | 
					
						
							|  |  |  | 		if (devctl & MUSB_DEVCTL_BDEVICE) | 
					
						
							|  |  |  | 			mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			musb->xceiv->state = OTG_STATE_A_IDLE; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&musb->lock, flags); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-01 13:22:05 +02:00
										 |  |  | static void da8xx_musb_try_idle(struct musb *musb, unsigned long timeout) | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | { | 
					
						
							|  |  |  | 	static unsigned long last_timer; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (timeout == 0) | 
					
						
							|  |  |  | 		timeout = jiffies + msecs_to_jiffies(3); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Never idle if active, or when VBUS timeout is not set as host */ | 
					
						
							|  |  |  | 	if (musb->is_active || (musb->a_wait_bcon == 0 && | 
					
						
							|  |  |  | 				musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) { | 
					
						
							| 
									
										
										
										
											2011-05-11 12:44:08 +03:00
										 |  |  | 		dev_dbg(musb->controller, "%s active, deleting timer\n", | 
					
						
							| 
									
										
										
										
											2013-03-07 10:39:57 +02:00
										 |  |  | 			usb_otg_state_string(musb->xceiv->state)); | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | 		del_timer(&otg_workaround); | 
					
						
							|  |  |  | 		last_timer = jiffies; | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (time_after(last_timer, timeout) && timer_pending(&otg_workaround)) { | 
					
						
							| 
									
										
										
										
											2011-05-11 12:44:08 +03:00
										 |  |  | 		dev_dbg(musb->controller, "Longer idle timer already pending, ignoring...\n"); | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	last_timer = timeout; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-11 12:44:08 +03:00
										 |  |  | 	dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", | 
					
						
							| 
									
										
										
										
											2013-03-07 10:39:57 +02:00
										 |  |  | 		usb_otg_state_string(musb->xceiv->state), | 
					
						
							| 
									
										
										
										
											2011-05-05 12:11:21 +02:00
										 |  |  | 		jiffies_to_msecs(timeout - jiffies)); | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | 	mod_timer(&otg_workaround, timeout); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-01 13:22:05 +02:00
										 |  |  | static irqreturn_t da8xx_musb_interrupt(int irq, void *hci) | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct musb		*musb = hci; | 
					
						
							|  |  |  | 	void __iomem		*reg_base = musb->ctrl_base; | 
					
						
							| 
									
										
										
										
											2012-02-13 13:24:15 +02:00
										 |  |  | 	struct usb_otg		*otg = musb->xceiv->otg; | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | 	unsigned long		flags; | 
					
						
							|  |  |  | 	irqreturn_t		ret = IRQ_NONE; | 
					
						
							|  |  |  | 	u32			status; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&musb->lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * NOTE: DA8XX shadows the Mentor IRQs.  Don't manage them through | 
					
						
							|  |  |  | 	 * the Mentor registers (except for setup), use the TI ones and EOI. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Acknowledge and handle non-CPPI interrupts */ | 
					
						
							|  |  |  | 	status = musb_readl(reg_base, DA8XX_USB_INTR_SRC_MASKED_REG); | 
					
						
							|  |  |  | 	if (!status) | 
					
						
							|  |  |  | 		goto eoi; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	musb_writel(reg_base, DA8XX_USB_INTR_SRC_CLEAR_REG, status); | 
					
						
							| 
									
										
										
										
											2011-05-11 12:44:08 +03:00
										 |  |  | 	dev_dbg(musb->controller, "USB IRQ %08x\n", status); | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	musb->int_rx = (status & DA8XX_INTR_RX_MASK) >> DA8XX_INTR_RX_SHIFT; | 
					
						
							|  |  |  | 	musb->int_tx = (status & DA8XX_INTR_TX_MASK) >> DA8XX_INTR_TX_SHIFT; | 
					
						
							|  |  |  | 	musb->int_usb = (status & DA8XX_INTR_USB_MASK) >> DA8XX_INTR_USB_SHIFT; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * DRVVBUS IRQs are the only proxy we have (a very poor one!) for | 
					
						
							|  |  |  | 	 * DA8xx's missing ID change IRQ.  We need an ID change IRQ to | 
					
						
							|  |  |  | 	 * switch appropriately between halves of the OTG state machine. | 
					
						
							|  |  |  | 	 * Managing DEVCTL.Session per Mentor docs requires that we know its | 
					
						
							|  |  |  | 	 * value but DEVCTL.BDevice is invalid without DEVCTL.Session set. | 
					
						
							|  |  |  | 	 * Also, DRVVBUS pulses for SRP (but not at 5 V)... | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (status & (DA8XX_INTR_DRVVBUS << DA8XX_INTR_USB_SHIFT)) { | 
					
						
							|  |  |  | 		int drvvbus = musb_readl(reg_base, DA8XX_USB_STAT_REG); | 
					
						
							|  |  |  | 		void __iomem *mregs = musb->mregs; | 
					
						
							|  |  |  | 		u8 devctl = musb_readb(mregs, MUSB_DEVCTL); | 
					
						
							|  |  |  | 		int err; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-14 10:18:29 +01:00
										 |  |  | 		err = musb->int_usb & MUSB_INTR_VBUSERROR; | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | 		if (err) { | 
					
						
							|  |  |  | 			/*
 | 
					
						
							|  |  |  | 			 * The Mentor core doesn't debounce VBUS as needed | 
					
						
							|  |  |  | 			 * to cope with device connect current spikes. This | 
					
						
							|  |  |  | 			 * means it's not uncommon for bus-powered devices | 
					
						
							|  |  |  | 			 * to get VBUS errors during enumeration. | 
					
						
							|  |  |  | 			 * | 
					
						
							|  |  |  | 			 * This is a workaround, but newer RTL from Mentor | 
					
						
							|  |  |  | 			 * seems to allow a better one: "re"-starting sessions | 
					
						
							|  |  |  | 			 * without waiting for VBUS to stop registering in | 
					
						
							|  |  |  | 			 * devctl. | 
					
						
							|  |  |  | 			 */ | 
					
						
							|  |  |  | 			musb->int_usb &= ~MUSB_INTR_VBUSERROR; | 
					
						
							|  |  |  | 			musb->xceiv->state = OTG_STATE_A_WAIT_VFALL; | 
					
						
							|  |  |  | 			mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); | 
					
						
							|  |  |  | 			WARNING("VBUS error workaround (delay coming)\n"); | 
					
						
							| 
									
										
										
										
											2011-11-24 15:46:26 +02:00
										 |  |  | 		} else if (drvvbus) { | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | 			MUSB_HST_MODE(musb); | 
					
						
							| 
									
										
										
										
											2012-02-13 13:24:15 +02:00
										 |  |  | 			otg->default_a = 1; | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | 			musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; | 
					
						
							|  |  |  | 			portstate(musb->port1_status |= USB_PORT_STAT_POWER); | 
					
						
							|  |  |  | 			del_timer(&otg_workaround); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			musb->is_active = 0; | 
					
						
							|  |  |  | 			MUSB_DEV_MODE(musb); | 
					
						
							| 
									
										
										
										
											2012-02-13 13:24:15 +02:00
										 |  |  | 			otg->default_a = 0; | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | 			musb->xceiv->state = OTG_STATE_B_IDLE; | 
					
						
							|  |  |  | 			portstate(musb->port1_status &= ~USB_PORT_STAT_POWER); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-11 12:44:08 +03:00
										 |  |  | 		dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | 				drvvbus ? "on" : "off", | 
					
						
							| 
									
										
										
										
											2013-03-07 10:39:57 +02:00
										 |  |  | 				usb_otg_state_string(musb->xceiv->state), | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | 				err ? " ERROR" : "", | 
					
						
							|  |  |  | 				devctl); | 
					
						
							|  |  |  | 		ret = IRQ_HANDLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (musb->int_tx || musb->int_rx || musb->int_usb) | 
					
						
							|  |  |  | 		ret |= musb_interrupt(musb); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  eoi: | 
					
						
							|  |  |  | 	/* EOI needs to be written for the IRQ to be re-asserted. */ | 
					
						
							|  |  |  | 	if (ret == IRQ_HANDLED || status) | 
					
						
							|  |  |  | 		musb_writel(reg_base, DA8XX_USB_END_OF_INTR_REG, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Poll for ID change */ | 
					
						
							| 
									
										
										
										
											2011-11-24 15:46:26 +02:00
										 |  |  | 	if (musb->xceiv->state == OTG_STATE_B_IDLE) | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | 		mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&musb->lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-01 13:22:05 +02:00
										 |  |  | static int da8xx_musb_set_mode(struct musb *musb, u8 musb_mode) | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | { | 
					
						
							|  |  |  | 	u32 cfgchip2 = __raw_readl(CFGCHIP2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cfgchip2 &= ~CFGCHIP2_OTGMODE; | 
					
						
							|  |  |  | 	switch (musb_mode) { | 
					
						
							|  |  |  | 	case MUSB_HOST:		/* Force VBUS valid, ID = 0 */ | 
					
						
							|  |  |  | 		cfgchip2 |= CFGCHIP2_FORCE_HOST; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case MUSB_PERIPHERAL:	/* Force VBUS valid, ID = 1 */ | 
					
						
							|  |  |  | 		cfgchip2 |= CFGCHIP2_FORCE_DEVICE; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case MUSB_OTG:		/* Don't override the VBUS/ID comparators */ | 
					
						
							|  |  |  | 		cfgchip2 |= CFGCHIP2_NO_OVERRIDE; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2011-05-11 12:44:08 +03:00
										 |  |  | 		dev_dbg(musb->controller, "Trying to set unsupported mode %u\n", musb_mode); | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	__raw_writel(cfgchip2, CFGCHIP2); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-01 13:22:05 +02:00
										 |  |  | static int da8xx_musb_init(struct musb *musb) | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | { | 
					
						
							|  |  |  | 	void __iomem *reg_base = musb->ctrl_base; | 
					
						
							|  |  |  | 	u32 rev; | 
					
						
							| 
									
										
										
										
											2013-01-04 23:13:58 +08:00
										 |  |  | 	int ret = -ENODEV; | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	musb->mregs += DA8XX_MENTOR_CORE_OFFSET; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Returns zero if e.g. not clocked */ | 
					
						
							|  |  |  | 	rev = musb_readl(reg_base, DA8XX_USB_REVISION_REG); | 
					
						
							|  |  |  | 	if (!rev) | 
					
						
							|  |  |  | 		goto fail; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	usb_nop_xceiv_register(); | 
					
						
							| 
									
										
										
										
											2012-06-22 17:02:46 +05:30
										 |  |  | 	musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); | 
					
						
							| 
									
										
										
										
											2013-01-04 23:13:58 +08:00
										 |  |  | 	if (IS_ERR_OR_NULL(musb->xceiv)) { | 
					
						
							|  |  |  | 		ret = -EPROBE_DEFER; | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | 		goto fail; | 
					
						
							| 
									
										
										
										
											2013-01-04 23:13:58 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-24 15:46:26 +02:00
										 |  |  | 	setup_timer(&otg_workaround, otg_timer, (unsigned long)musb); | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Reset the controller */ | 
					
						
							|  |  |  | 	musb_writel(reg_base, DA8XX_USB_CTRL_REG, DA8XX_SOFT_RESET_MASK); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Start the on-chip PHY and its PLL. */ | 
					
						
							|  |  |  | 	phy_on(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	msleep(5); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* NOTE: IRQs are in mixed mode, not bypass to pure MUSB */ | 
					
						
							|  |  |  | 	pr_debug("DA8xx OTG revision %08x, PHY %03x, control %02x\n", | 
					
						
							|  |  |  | 		 rev, __raw_readl(CFGCHIP2), | 
					
						
							|  |  |  | 		 musb_readb(reg_base, DA8XX_USB_CTRL_REG)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-01 13:22:05 +02:00
										 |  |  | 	musb->isr = da8xx_musb_interrupt; | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | fail: | 
					
						
							| 
									
										
										
										
											2013-01-04 23:13:58 +08:00
										 |  |  | 	return ret; | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-01 13:22:05 +02:00
										 |  |  | static int da8xx_musb_exit(struct musb *musb) | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-11-24 15:46:26 +02:00
										 |  |  | 	del_timer_sync(&otg_workaround); | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	phy_off(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-22 17:02:45 +05:30
										 |  |  | 	usb_put_phy(musb->xceiv); | 
					
						
							| 
									
										
										
										
											2010-09-24 13:44:03 +03:00
										 |  |  | 	usb_nop_xceiv_unregister(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-12-01 13:22:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-02 09:48:58 +02:00
										 |  |  | static const struct musb_platform_ops da8xx_ops = { | 
					
						
							| 
									
										
										
										
											2010-12-01 13:22:05 +02:00
										 |  |  | 	.init		= da8xx_musb_init, | 
					
						
							|  |  |  | 	.exit		= da8xx_musb_exit, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	.enable		= da8xx_musb_enable, | 
					
						
							|  |  |  | 	.disable	= da8xx_musb_disable, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	.set_mode	= da8xx_musb_set_mode, | 
					
						
							|  |  |  | 	.try_idle	= da8xx_musb_try_idle, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	.set_vbus	= da8xx_musb_set_vbus, | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2010-12-02 09:19:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-20 00:14:38 +01:00
										 |  |  | static const struct platform_device_info da8xx_dev_info = { | 
					
						
							|  |  |  | 	.name		= "musb-hdrc", | 
					
						
							|  |  |  | 	.id		= PLATFORM_DEVID_AUTO, | 
					
						
							|  |  |  | 	.dma_mask	= DMA_BIT_MASK(32), | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2010-12-02 09:19:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-19 13:21:48 -05:00
										 |  |  | static int da8xx_probe(struct platform_device *pdev) | 
					
						
							| 
									
										
										
										
											2010-12-02 09:19:35 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-04-24 17:21:42 +03:00
										 |  |  | 	struct resource musb_resources[2]; | 
					
						
							| 
									
										
										
										
											2013-07-30 17:03:12 +09:00
										 |  |  | 	struct musb_hdrc_platform_data	*pdata = dev_get_platdata(&pdev->dev); | 
					
						
							| 
									
										
										
										
											2010-12-02 09:19:35 +02:00
										 |  |  | 	struct platform_device		*musb; | 
					
						
							| 
									
										
										
										
											2010-12-02 09:40:34 +02:00
										 |  |  | 	struct da8xx_glue		*glue; | 
					
						
							| 
									
										
										
										
											2013-09-20 00:14:38 +01:00
										 |  |  | 	struct platform_device_info	pinfo; | 
					
						
							| 
									
										
										
										
											2010-12-02 09:57:08 +02:00
										 |  |  | 	struct clk			*clk; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-02 09:19:35 +02:00
										 |  |  | 	int				ret = -ENOMEM; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-02 09:40:34 +02:00
										 |  |  | 	glue = kzalloc(sizeof(*glue), GFP_KERNEL); | 
					
						
							|  |  |  | 	if (!glue) { | 
					
						
							|  |  |  | 		dev_err(&pdev->dev, "failed to allocate glue context\n"); | 
					
						
							|  |  |  | 		goto err0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-02 09:57:08 +02:00
										 |  |  | 	clk = clk_get(&pdev->dev, "usb20"); | 
					
						
							|  |  |  | 	if (IS_ERR(clk)) { | 
					
						
							|  |  |  | 		dev_err(&pdev->dev, "failed to get clock\n"); | 
					
						
							|  |  |  | 		ret = PTR_ERR(clk); | 
					
						
							| 
									
										
										
										
											2012-08-31 11:09:49 +00:00
										 |  |  | 		goto err3; | 
					
						
							| 
									
										
										
										
											2010-12-02 09:57:08 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ret = clk_enable(clk); | 
					
						
							|  |  |  | 	if (ret) { | 
					
						
							|  |  |  | 		dev_err(&pdev->dev, "failed to enable clock\n"); | 
					
						
							| 
									
										
										
										
											2012-08-31 11:09:49 +00:00
										 |  |  | 		goto err4; | 
					
						
							| 
									
										
										
										
											2010-12-02 09:57:08 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-02 09:40:34 +02:00
										 |  |  | 	glue->dev			= &pdev->dev; | 
					
						
							| 
									
										
										
										
											2010-12-02 09:57:08 +02:00
										 |  |  | 	glue->clk			= clk; | 
					
						
							| 
									
										
										
										
											2010-12-02 09:40:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-02 09:48:58 +02:00
										 |  |  | 	pdata->platform_ops		= &da8xx_ops; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-02 09:40:34 +02:00
										 |  |  | 	platform_set_drvdata(pdev, glue); | 
					
						
							| 
									
										
										
										
											2010-12-02 09:19:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-24 17:21:42 +03:00
										 |  |  | 	memset(musb_resources, 0x00, sizeof(*musb_resources) * | 
					
						
							|  |  |  | 			ARRAY_SIZE(musb_resources)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	musb_resources[0].name = pdev->resource[0].name; | 
					
						
							|  |  |  | 	musb_resources[0].start = pdev->resource[0].start; | 
					
						
							|  |  |  | 	musb_resources[0].end = pdev->resource[0].end; | 
					
						
							|  |  |  | 	musb_resources[0].flags = pdev->resource[0].flags; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	musb_resources[1].name = pdev->resource[1].name; | 
					
						
							|  |  |  | 	musb_resources[1].start = pdev->resource[1].start; | 
					
						
							|  |  |  | 	musb_resources[1].end = pdev->resource[1].end; | 
					
						
							|  |  |  | 	musb_resources[1].flags = pdev->resource[1].flags; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-20 00:14:38 +01:00
										 |  |  | 	pinfo = da8xx_dev_info; | 
					
						
							|  |  |  | 	pinfo.parent = &pdev->dev; | 
					
						
							|  |  |  | 	pinfo.res = musb_resources; | 
					
						
							|  |  |  | 	pinfo.num_res = ARRAY_SIZE(musb_resources); | 
					
						
							|  |  |  | 	pinfo.data = pdata; | 
					
						
							|  |  |  | 	pinfo.size_data = sizeof(*pdata); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	glue->musb = musb = platform_device_register_full(&pinfo); | 
					
						
							|  |  |  | 	if (IS_ERR(musb)) { | 
					
						
							|  |  |  | 		ret = PTR_ERR(musb); | 
					
						
							|  |  |  | 		dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); | 
					
						
							| 
									
										
										
										
											2012-08-31 11:09:49 +00:00
										 |  |  | 		goto err5; | 
					
						
							| 
									
										
										
										
											2010-12-02 09:19:35 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-31 11:09:49 +00:00
										 |  |  | err5: | 
					
						
							| 
									
										
										
										
											2010-12-02 09:57:08 +02:00
										 |  |  | 	clk_disable(clk); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-31 11:09:49 +00:00
										 |  |  | err4: | 
					
						
							| 
									
										
										
										
											2010-12-02 09:57:08 +02:00
										 |  |  | 	clk_put(clk); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-31 11:09:49 +00:00
										 |  |  | err3: | 
					
						
							| 
									
										
										
										
											2010-12-02 09:40:34 +02:00
										 |  |  | 	kfree(glue); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-02 09:19:35 +02:00
										 |  |  | err0: | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-19 13:26:20 -05:00
										 |  |  | static int da8xx_remove(struct platform_device *pdev) | 
					
						
							| 
									
										
										
										
											2010-12-02 09:19:35 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-12-02 09:40:34 +02:00
										 |  |  | 	struct da8xx_glue		*glue = platform_get_drvdata(pdev); | 
					
						
							| 
									
										
										
										
											2010-12-02 09:19:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-23 13:26:15 +08:00
										 |  |  | 	platform_device_unregister(glue->musb); | 
					
						
							| 
									
										
										
										
											2010-12-02 09:57:08 +02:00
										 |  |  | 	clk_disable(glue->clk); | 
					
						
							|  |  |  | 	clk_put(glue->clk); | 
					
						
							| 
									
										
										
										
											2010-12-02 09:40:34 +02:00
										 |  |  | 	kfree(glue); | 
					
						
							| 
									
										
										
										
											2010-12-02 09:19:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct platform_driver da8xx_driver = { | 
					
						
							| 
									
										
										
										
											2012-01-26 12:40:23 +02:00
										 |  |  | 	.probe		= da8xx_probe, | 
					
						
							| 
									
										
										
										
											2012-11-19 13:21:08 -05:00
										 |  |  | 	.remove		= da8xx_remove, | 
					
						
							| 
									
										
										
										
											2010-12-02 09:19:35 +02:00
										 |  |  | 	.driver		= { | 
					
						
							|  |  |  | 		.name	= "musb-da8xx", | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MODULE_DESCRIPTION("DA8xx/OMAP-L1x MUSB Glue Layer"); | 
					
						
							|  |  |  | MODULE_AUTHOR("Sergei Shtylyov <sshtylyov@ru.mvista.com>"); | 
					
						
							|  |  |  | MODULE_LICENSE("GPL v2"); | 
					
						
							| 
									
										
										
										
											2012-10-10 19:36:59 +01:00
										 |  |  | module_platform_driver(da8xx_driver); |