| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Texas Instruments AM35x "glue layer" | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (c) 2010, by Texas Instruments | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Based on the DA8xx "glue layer" code. | 
					
						
							|  |  |  |  * Copyright (c) 2008-2009, MontaVista Software, Inc. <source@mvista.com> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 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 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <linux/init.h>
 | 
					
						
							| 
									
										
										
										
											2011-11-10 09:58:04 +02:00
										 |  |  | #include <linux/module.h>
 | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | #include <linux/clk.h>
 | 
					
						
							| 
									
										
										
										
											2012-06-26 17:40:32 +05:30
										 |  |  | #include <linux/err.h>
 | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | #include <linux/io.h>
 | 
					
						
							| 
									
										
										
										
											2010-12-02 09:06:51 +02:00
										 |  |  | #include <linux/platform_device.h>
 | 
					
						
							|  |  |  | #include <linux/dma-mapping.h>
 | 
					
						
							| 
									
										
										
										
											2012-07-19 13:32:15 +03:00
										 |  |  | #include <linux/usb/nop-usb-xceiv.h>
 | 
					
						
							| 
									
										
										
										
											2012-10-24 14:26:19 -07:00
										 |  |  | #include <linux/platform_data/usb-omap.h>
 | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "musb_core.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * AM35x specific definitions | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | /* USB 2.0 OTG module registers */ | 
					
						
							|  |  |  | #define USB_REVISION_REG	0x00
 | 
					
						
							|  |  |  | #define USB_CTRL_REG		0x04
 | 
					
						
							|  |  |  | #define USB_STAT_REG		0x08
 | 
					
						
							|  |  |  | #define USB_EMULATION_REG	0x0c
 | 
					
						
							|  |  |  | /* 0x10 Reserved */ | 
					
						
							|  |  |  | #define USB_AUTOREQ_REG		0x14
 | 
					
						
							|  |  |  | #define USB_SRP_FIX_TIME_REG	0x18
 | 
					
						
							|  |  |  | #define USB_TEARDOWN_REG	0x1c
 | 
					
						
							|  |  |  | #define EP_INTR_SRC_REG		0x20
 | 
					
						
							|  |  |  | #define EP_INTR_SRC_SET_REG	0x24
 | 
					
						
							|  |  |  | #define EP_INTR_SRC_CLEAR_REG	0x28
 | 
					
						
							|  |  |  | #define EP_INTR_MASK_REG	0x2c
 | 
					
						
							|  |  |  | #define EP_INTR_MASK_SET_REG	0x30
 | 
					
						
							|  |  |  | #define EP_INTR_MASK_CLEAR_REG	0x34
 | 
					
						
							|  |  |  | #define EP_INTR_SRC_MASKED_REG	0x38
 | 
					
						
							|  |  |  | #define CORE_INTR_SRC_REG	0x40
 | 
					
						
							|  |  |  | #define CORE_INTR_SRC_SET_REG	0x44
 | 
					
						
							|  |  |  | #define CORE_INTR_SRC_CLEAR_REG	0x48
 | 
					
						
							|  |  |  | #define CORE_INTR_MASK_REG	0x4c
 | 
					
						
							|  |  |  | #define CORE_INTR_MASK_SET_REG	0x50
 | 
					
						
							|  |  |  | #define CORE_INTR_MASK_CLEAR_REG 0x54
 | 
					
						
							|  |  |  | #define CORE_INTR_SRC_MASKED_REG 0x58
 | 
					
						
							|  |  |  | /* 0x5c Reserved */ | 
					
						
							|  |  |  | #define USB_END_OF_INTR_REG	0x60
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Control register bits */ | 
					
						
							|  |  |  | #define AM35X_SOFT_RESET_MASK	1
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* USB interrupt register bits */ | 
					
						
							|  |  |  | #define AM35X_INTR_USB_SHIFT	16
 | 
					
						
							|  |  |  | #define AM35X_INTR_USB_MASK	(0x1ff << AM35X_INTR_USB_SHIFT)
 | 
					
						
							|  |  |  | #define AM35X_INTR_DRVVBUS	0x100
 | 
					
						
							|  |  |  | #define AM35X_INTR_RX_SHIFT	16
 | 
					
						
							|  |  |  | #define AM35X_INTR_TX_SHIFT	0
 | 
					
						
							|  |  |  | #define AM35X_TX_EP_MASK	0xffff		/* EP0 + 15 Tx EPs */
 | 
					
						
							|  |  |  | #define AM35X_RX_EP_MASK	0xfffe		/* 15 Rx EPs */
 | 
					
						
							|  |  |  | #define AM35X_TX_INTR_MASK	(AM35X_TX_EP_MASK << AM35X_INTR_TX_SHIFT)
 | 
					
						
							|  |  |  | #define AM35X_RX_INTR_MASK	(AM35X_RX_EP_MASK << AM35X_INTR_RX_SHIFT)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define USB_MENTOR_CORE_OFFSET	0x400
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-02 09:33:24 +02:00
										 |  |  | struct am35x_glue { | 
					
						
							|  |  |  | 	struct device		*dev; | 
					
						
							|  |  |  | 	struct platform_device	*musb; | 
					
						
							| 
									
										
										
										
											2010-12-02 09:57:08 +02:00
										 |  |  | 	struct clk		*phy_clk; | 
					
						
							|  |  |  | 	struct clk		*clk; | 
					
						
							| 
									
										
										
										
											2010-12-02 09:33:24 +02:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2010-12-02 12:53:22 +02:00
										 |  |  | #define glue_to_musb(g)		platform_get_drvdata(g->musb)
 | 
					
						
							| 
									
										
										
										
											2010-12-02 09:33:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2010-12-01 13:22:05 +02:00
										 |  |  |  * am35x_musb_enable - enable interrupts | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2010-12-01 13:22:05 +02:00
										 |  |  | static void am35x_musb_enable(struct musb *musb) | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | { | 
					
						
							|  |  |  | 	void __iomem *reg_base = musb->ctrl_base; | 
					
						
							|  |  |  | 	u32 epmask; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Workaround: setup IRQs through both register sets. */ | 
					
						
							|  |  |  | 	epmask = ((musb->epmask & AM35X_TX_EP_MASK) << AM35X_INTR_TX_SHIFT) | | 
					
						
							|  |  |  | 	       ((musb->epmask & AM35X_RX_EP_MASK) << AM35X_INTR_RX_SHIFT); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	musb_writel(reg_base, EP_INTR_MASK_SET_REG, epmask); | 
					
						
							|  |  |  | 	musb_writel(reg_base, CORE_INTR_MASK_SET_REG, AM35X_INTR_USB_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, CORE_INTR_SRC_SET_REG, | 
					
						
							|  |  |  | 			AM35X_INTR_DRVVBUS << AM35X_INTR_USB_SHIFT); | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2010-12-01 13:22:05 +02:00
										 |  |  |  * am35x_musb_disable - disable HDRC and flush interrupts | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2010-12-01 13:22:05 +02:00
										 |  |  | static void am35x_musb_disable(struct musb *musb) | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | { | 
					
						
							|  |  |  | 	void __iomem *reg_base = musb->ctrl_base; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	musb_writel(reg_base, CORE_INTR_MASK_CLEAR_REG, AM35X_INTR_USB_MASK); | 
					
						
							|  |  |  | 	musb_writel(reg_base, EP_INTR_MASK_CLEAR_REG, | 
					
						
							|  |  |  | 			 AM35X_TX_INTR_MASK | AM35X_RX_INTR_MASK); | 
					
						
							|  |  |  | 	musb_writeb(musb->mregs, MUSB_DEVCTL, 0); | 
					
						
							|  |  |  | 	musb_writel(reg_base, USB_END_OF_INTR_REG, 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define portstate(stmt)		stmt
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-01 13:22:05 +02:00
										 |  |  | static void am35x_musb_set_vbus(struct musb *musb, int is_on) | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +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 AM35x'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, | 
					
						
							| 
									
										
										
										
											2011-05-05 12:11:21 +02:00
										 |  |  | 		otg_state_string(musb->xceiv->state)); | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +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: | 
					
						
							|  |  |  | 		musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; | 
					
						
							|  |  |  | 		musb_writel(musb->ctrl_base, CORE_INTR_SRC_SET_REG, | 
					
						
							|  |  |  | 			    MUSB_INTR_VBUSERROR << AM35X_INTR_USB_SHIFT); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case OTG_STATE_B_IDLE: | 
					
						
							|  |  |  | 		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 am35x_musb_try_idle(struct musb *musb, unsigned long timeout) | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +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", | 
					
						
							| 
									
										
										
										
											2011-05-05 12:11:21 +02:00
										 |  |  | 			otg_state_string(musb->xceiv->state)); | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +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-10-19 10:08:12 +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", | 
					
						
							| 
									
										
										
										
											2011-05-05 12:11:21 +02:00
										 |  |  | 		otg_state_string(musb->xceiv->state), | 
					
						
							|  |  |  | 		jiffies_to_msecs(timeout - jiffies)); | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | 	mod_timer(&otg_workaround, timeout); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-01 13:22:05 +02:00
										 |  |  | static irqreturn_t am35x_musb_interrupt(int irq, void *hci) | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct musb  *musb = hci; | 
					
						
							|  |  |  | 	void __iomem *reg_base = musb->ctrl_base; | 
					
						
							| 
									
										
										
										
											2010-12-07 18:57:45 +05:30
										 |  |  | 	struct device *dev = musb->controller; | 
					
						
							|  |  |  | 	struct musb_hdrc_platform_data *plat = dev->platform_data; | 
					
						
							|  |  |  | 	struct omap_musb_board_data *data = plat->board_data; | 
					
						
							| 
									
										
										
										
											2012-02-13 13:24:15 +02:00
										 |  |  | 	struct usb_otg *otg = musb->xceiv->otg; | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | 	unsigned long flags; | 
					
						
							|  |  |  | 	irqreturn_t ret = IRQ_NONE; | 
					
						
							| 
									
										
										
										
											2010-12-07 18:57:45 +05:30
										 |  |  | 	u32 epintr, usbintr; | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&musb->lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Get endpoint interrupts */ | 
					
						
							|  |  |  | 	epintr = musb_readl(reg_base, EP_INTR_SRC_MASKED_REG); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (epintr) { | 
					
						
							|  |  |  | 		musb_writel(reg_base, EP_INTR_SRC_CLEAR_REG, epintr); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		musb->int_rx = | 
					
						
							|  |  |  | 			(epintr & AM35X_RX_INTR_MASK) >> AM35X_INTR_RX_SHIFT; | 
					
						
							|  |  |  | 		musb->int_tx = | 
					
						
							|  |  |  | 			(epintr & AM35X_TX_INTR_MASK) >> AM35X_INTR_TX_SHIFT; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Get usb core interrupts */ | 
					
						
							|  |  |  | 	usbintr = musb_readl(reg_base, CORE_INTR_SRC_MASKED_REG); | 
					
						
							|  |  |  | 	if (!usbintr && !epintr) | 
					
						
							|  |  |  | 		goto eoi; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (usbintr) { | 
					
						
							|  |  |  | 		musb_writel(reg_base, CORE_INTR_SRC_CLEAR_REG, usbintr); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		musb->int_usb = | 
					
						
							|  |  |  | 			(usbintr & AM35X_INTR_USB_MASK) >> AM35X_INTR_USB_SHIFT; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * DRVVBUS IRQs are the only proxy we have (a very poor one!) for | 
					
						
							|  |  |  | 	 * AM35x'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 5V) ... | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (usbintr & (AM35X_INTR_DRVVBUS << AM35X_INTR_USB_SHIFT)) { | 
					
						
							|  |  |  | 		int drvvbus = musb_readl(reg_base, USB_STAT_REG); | 
					
						
							|  |  |  | 		void __iomem *mregs = musb->mregs; | 
					
						
							|  |  |  | 		u8 devctl = musb_readb(mregs, MUSB_DEVCTL); | 
					
						
							|  |  |  | 		int err; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-24 15:46:26 +02:00
										 |  |  | 		err = musb->int_usb & MUSB_INTR_VBUSERROR; | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +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-10-19 10:08:12 +03:00
										 |  |  | 			MUSB_HST_MODE(musb); | 
					
						
							| 
									
										
										
										
											2012-02-13 13:24:15 +02:00
										 |  |  | 			otg->default_a = 1; | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +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-10-19 10:08:12 +03:00
										 |  |  | 			musb->xceiv->state = OTG_STATE_B_IDLE; | 
					
						
							|  |  |  | 			portstate(musb->port1_status &= ~USB_PORT_STAT_POWER); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* NOTE: this must complete power-on within 100 ms. */ | 
					
						
							| 
									
										
										
										
											2011-05-11 12:44:08 +03:00
										 |  |  | 		dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | 				drvvbus ? "on" : "off", | 
					
						
							| 
									
										
										
										
											2011-05-05 12:11:21 +02:00
										 |  |  | 				otg_state_string(musb->xceiv->state), | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | 				err ? " ERROR" : "", | 
					
						
							|  |  |  | 				devctl); | 
					
						
							|  |  |  | 		ret = IRQ_HANDLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-15 11:20:22 +02:00
										 |  |  | 	/* Drop spurious RX and TX if device is disconnected */ | 
					
						
							|  |  |  | 	if (musb->int_usb & MUSB_INTR_DISCONNECT) { | 
					
						
							|  |  |  | 		musb->int_tx = 0; | 
					
						
							|  |  |  | 		musb->int_rx = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | 	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 || epintr || usbintr) { | 
					
						
							|  |  |  | 		/* clear level interrupt */ | 
					
						
							| 
									
										
										
										
											2010-12-07 18:57:45 +05:30
										 |  |  | 		if (data->clear_irq) | 
					
						
							|  |  |  | 			data->clear_irq(); | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | 		/* write EOI */ | 
					
						
							|  |  |  | 		musb_writel(reg_base, 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-10-19 10:08:12 +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 am35x_musb_set_mode(struct musb *musb, u8 musb_mode) | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-12-07 18:57:45 +05:30
										 |  |  | 	struct device *dev = musb->controller; | 
					
						
							|  |  |  | 	struct musb_hdrc_platform_data *plat = dev->platform_data; | 
					
						
							|  |  |  | 	struct omap_musb_board_data *data = plat->board_data; | 
					
						
							|  |  |  | 	int     retval = 0; | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-07 18:57:45 +05:30
										 |  |  | 	if (data->set_mode) | 
					
						
							|  |  |  | 		data->set_mode(musb_mode); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		retval = -EIO; | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-07 18:57:45 +05:30
										 |  |  | 	return retval; | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-01 13:22:05 +02:00
										 |  |  | static int am35x_musb_init(struct musb *musb) | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-12-07 18:57:45 +05:30
										 |  |  | 	struct device *dev = musb->controller; | 
					
						
							|  |  |  | 	struct musb_hdrc_platform_data *plat = dev->platform_data; | 
					
						
							|  |  |  | 	struct omap_musb_board_data *data = plat->board_data; | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | 	void __iomem *reg_base = musb->ctrl_base; | 
					
						
							| 
									
										
										
										
											2010-12-07 18:57:45 +05:30
										 |  |  | 	u32 rev; | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	musb->mregs += USB_MENTOR_CORE_OFFSET; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Returns zero if e.g. not clocked */ | 
					
						
							|  |  |  | 	rev = musb_readl(reg_base, USB_REVISION_REG); | 
					
						
							| 
									
										
										
										
											2010-12-02 09:57:08 +02:00
										 |  |  | 	if (!rev) | 
					
						
							|  |  |  | 		return -ENODEV; | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	usb_nop_xceiv_register(); | 
					
						
							| 
									
										
										
										
											2012-06-22 17:02:46 +05:30
										 |  |  | 	musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); | 
					
						
							| 
									
										
										
										
											2012-06-26 17:40:32 +05:30
										 |  |  | 	if (IS_ERR_OR_NULL(musb->xceiv)) | 
					
						
							| 
									
										
										
										
											2013-01-04 23:13:58 +08:00
										 |  |  | 		return -EPROBE_DEFER; | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-24 15:46:26 +02:00
										 |  |  | 	setup_timer(&otg_workaround, otg_timer, (unsigned long) musb); | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-07 18:57:45 +05:30
										 |  |  | 	/* Reset the musb */ | 
					
						
							|  |  |  | 	if (data->reset) | 
					
						
							|  |  |  | 		data->reset(); | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Reset the controller */ | 
					
						
							|  |  |  | 	musb_writel(reg_base, USB_CTRL_REG, AM35X_SOFT_RESET_MASK); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Start the on-chip PHY and its PLL. */ | 
					
						
							| 
									
										
										
										
											2010-12-07 18:57:45 +05:30
										 |  |  | 	if (data->set_phy_power) | 
					
						
							|  |  |  | 		data->set_phy_power(1); | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	msleep(5); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-01 13:22:05 +02:00
										 |  |  | 	musb->isr = am35x_musb_interrupt; | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* clear level interrupt */ | 
					
						
							| 
									
										
										
										
											2010-12-07 18:57:45 +05:30
										 |  |  | 	if (data->clear_irq) | 
					
						
							|  |  |  | 		data->clear_irq(); | 
					
						
							| 
									
										
										
										
											2010-12-02 09:57:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-01 13:22:05 +02:00
										 |  |  | static int am35x_musb_exit(struct musb *musb) | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-12-07 18:57:45 +05:30
										 |  |  | 	struct device *dev = musb->controller; | 
					
						
							|  |  |  | 	struct musb_hdrc_platform_data *plat = dev->platform_data; | 
					
						
							|  |  |  | 	struct omap_musb_board_data *data = plat->board_data; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-24 15:46:26 +02:00
										 |  |  | 	del_timer_sync(&otg_workaround); | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-07 18:57:45 +05:30
										 |  |  | 	/* Shutdown the on-chip PHY and its PLL. */ | 
					
						
							|  |  |  | 	if (data->set_phy_power) | 
					
						
							|  |  |  | 		data->set_phy_power(0); | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-22 17:02:45 +05:30
										 |  |  | 	usb_put_phy(musb->xceiv); | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:12 +03:00
										 |  |  | 	usb_nop_xceiv_unregister(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-19 10:08:13 +03:00
										 |  |  | /* AM35x supports only 32bit read operation */ | 
					
						
							|  |  |  | void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	void __iomem *fifo = hw_ep->fifo; | 
					
						
							|  |  |  | 	u32		val; | 
					
						
							|  |  |  | 	int		i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Read for 32bit-aligned destination address */ | 
					
						
							|  |  |  | 	if (likely((0x03 & (unsigned long) dst) == 0) && len >= 4) { | 
					
						
							|  |  |  | 		readsl(fifo, dst, len >> 2); | 
					
						
							|  |  |  | 		dst += len & ~0x03; | 
					
						
							|  |  |  | 		len &= 0x03; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Now read the remaining 1 to 3 byte or complete length if | 
					
						
							|  |  |  | 	 * unaligned address. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (len > 4) { | 
					
						
							|  |  |  | 		for (i = 0; i < (len >> 2); i++) { | 
					
						
							|  |  |  | 			*(u32 *) dst = musb_readl(fifo, 0); | 
					
						
							|  |  |  | 			dst += 4; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		len &= 0x03; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (len > 0) { | 
					
						
							|  |  |  | 		val = musb_readl(fifo, 0); | 
					
						
							|  |  |  | 		memcpy(dst, &val, len); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-12-01 13:22:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-02 09:48:58 +02:00
										 |  |  | static const struct musb_platform_ops am35x_ops = { | 
					
						
							| 
									
										
										
										
											2010-12-01 13:22:05 +02:00
										 |  |  | 	.init		= am35x_musb_init, | 
					
						
							|  |  |  | 	.exit		= am35x_musb_exit, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	.enable		= am35x_musb_enable, | 
					
						
							|  |  |  | 	.disable	= am35x_musb_disable, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	.set_mode	= am35x_musb_set_mode, | 
					
						
							|  |  |  | 	.try_idle	= am35x_musb_try_idle, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	.set_vbus	= am35x_musb_set_vbus, | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2010-12-02 09:06:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | static u64 am35x_dmamask = DMA_BIT_MASK(32); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-19 13:21:48 -05:00
										 |  |  | static int am35x_probe(struct platform_device *pdev) | 
					
						
							| 
									
										
										
										
											2010-12-02 09:06:51 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct musb_hdrc_platform_data	*pdata = pdev->dev.platform_data; | 
					
						
							|  |  |  | 	struct platform_device		*musb; | 
					
						
							| 
									
										
										
										
											2010-12-02 09:33:24 +02:00
										 |  |  | 	struct am35x_glue		*glue; | 
					
						
							| 
									
										
										
										
											2010-12-02 09:06:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-02 09:57:08 +02:00
										 |  |  | 	struct clk			*phy_clk; | 
					
						
							|  |  |  | 	struct clk			*clk; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-02 09:06:51 +02:00
										 |  |  | 	int				ret = -ENOMEM; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-02 09:33:24 +02:00
										 |  |  | 	glue = kzalloc(sizeof(*glue), GFP_KERNEL); | 
					
						
							|  |  |  | 	if (!glue) { | 
					
						
							|  |  |  | 		dev_err(&pdev->dev, "failed to allocate glue context\n"); | 
					
						
							|  |  |  | 		goto err0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-31 16:12:43 +01:00
										 |  |  | 	musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); | 
					
						
							| 
									
										
										
										
											2010-12-02 09:06:51 +02:00
										 |  |  | 	if (!musb) { | 
					
						
							|  |  |  | 		dev_err(&pdev->dev, "failed to allocate musb device\n"); | 
					
						
							| 
									
										
										
										
											2012-10-31 16:12:43 +01:00
										 |  |  | 		goto err1; | 
					
						
							| 
									
										
										
										
											2010-12-02 09:06:51 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-02 09:57:08 +02:00
										 |  |  | 	phy_clk = clk_get(&pdev->dev, "fck"); | 
					
						
							|  |  |  | 	if (IS_ERR(phy_clk)) { | 
					
						
							|  |  |  | 		dev_err(&pdev->dev, "failed to get PHY clock\n"); | 
					
						
							|  |  |  | 		ret = PTR_ERR(phy_clk); | 
					
						
							| 
									
										
										
										
											2012-08-31 11:09:49 +00:00
										 |  |  | 		goto err3; | 
					
						
							| 
									
										
										
										
											2010-12-02 09:57:08 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	clk = clk_get(&pdev->dev, "ick"); | 
					
						
							|  |  |  | 	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 err4; | 
					
						
							| 
									
										
										
										
											2010-12-02 09:57:08 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ret = clk_enable(phy_clk); | 
					
						
							|  |  |  | 	if (ret) { | 
					
						
							|  |  |  | 		dev_err(&pdev->dev, "failed to enable PHY clock\n"); | 
					
						
							| 
									
										
										
										
											2012-08-31 11:09:49 +00:00
										 |  |  | 		goto err5; | 
					
						
							| 
									
										
										
										
											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 err6; | 
					
						
							| 
									
										
										
										
											2010-12-02 09:57:08 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-02 09:06:51 +02:00
										 |  |  | 	musb->dev.parent		= &pdev->dev; | 
					
						
							|  |  |  | 	musb->dev.dma_mask		= &am35x_dmamask; | 
					
						
							|  |  |  | 	musb->dev.coherent_dma_mask	= am35x_dmamask; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-02 09:33:24 +02:00
										 |  |  | 	glue->dev			= &pdev->dev; | 
					
						
							|  |  |  | 	glue->musb			= musb; | 
					
						
							| 
									
										
										
										
											2010-12-02 09:57:08 +02:00
										 |  |  | 	glue->phy_clk			= phy_clk; | 
					
						
							|  |  |  | 	glue->clk			= clk; | 
					
						
							| 
									
										
										
										
											2010-12-02 09:33:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-02 09:48:58 +02:00
										 |  |  | 	pdata->platform_ops		= &am35x_ops; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-02 09:33:24 +02:00
										 |  |  | 	platform_set_drvdata(pdev, glue); | 
					
						
							| 
									
										
										
										
											2010-12-02 09:06:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ret = platform_device_add_resources(musb, pdev->resource, | 
					
						
							|  |  |  | 			pdev->num_resources); | 
					
						
							|  |  |  | 	if (ret) { | 
					
						
							|  |  |  | 		dev_err(&pdev->dev, "failed to add resources\n"); | 
					
						
							| 
									
										
										
										
											2012-08-31 11:09:49 +00:00
										 |  |  | 		goto err7; | 
					
						
							| 
									
										
										
										
											2010-12-02 09:06:51 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); | 
					
						
							|  |  |  | 	if (ret) { | 
					
						
							|  |  |  | 		dev_err(&pdev->dev, "failed to add platform_data\n"); | 
					
						
							| 
									
										
										
										
											2012-08-31 11:09:49 +00:00
										 |  |  | 		goto err7; | 
					
						
							| 
									
										
										
										
											2010-12-02 09:06:51 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ret = platform_device_add(musb); | 
					
						
							|  |  |  | 	if (ret) { | 
					
						
							|  |  |  | 		dev_err(&pdev->dev, "failed to register musb device\n"); | 
					
						
							| 
									
										
										
										
											2012-08-31 11:09:49 +00:00
										 |  |  | 		goto err7; | 
					
						
							| 
									
										
										
										
											2010-12-02 09:06:51 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-31 11:09:49 +00:00
										 |  |  | err7: | 
					
						
							| 
									
										
										
										
											2010-12-02 09:57:08 +02:00
										 |  |  | 	clk_disable(clk); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-31 11:09:49 +00:00
										 |  |  | err6: | 
					
						
							| 
									
										
										
										
											2010-12-02 09:57:08 +02:00
										 |  |  | 	clk_disable(phy_clk); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-31 11:09:49 +00:00
										 |  |  | err5: | 
					
						
							| 
									
										
										
										
											2010-12-02 09:57:08 +02:00
										 |  |  | 	clk_put(clk); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-31 11:09:49 +00:00
										 |  |  | err4: | 
					
						
							| 
									
										
										
										
											2010-12-02 09:57:08 +02:00
										 |  |  | 	clk_put(phy_clk); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-31 11:09:49 +00:00
										 |  |  | err3: | 
					
						
							| 
									
										
										
										
											2010-12-02 09:06:51 +02:00
										 |  |  | 	platform_device_put(musb); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-02 09:33:24 +02:00
										 |  |  | err1: | 
					
						
							|  |  |  | 	kfree(glue); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-02 09:06:51 +02:00
										 |  |  | err0: | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-19 13:26:20 -05:00
										 |  |  | static int am35x_remove(struct platform_device *pdev) | 
					
						
							| 
									
										
										
										
											2010-12-02 09:06:51 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-12-02 09:33:24 +02:00
										 |  |  | 	struct am35x_glue	*glue = platform_get_drvdata(pdev); | 
					
						
							| 
									
										
										
										
											2010-12-02 09:06:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-23 13:24:51 +08:00
										 |  |  | 	platform_device_unregister(glue->musb); | 
					
						
							| 
									
										
										
										
											2010-12-02 09:57:08 +02:00
										 |  |  | 	clk_disable(glue->clk); | 
					
						
							|  |  |  | 	clk_disable(glue->phy_clk); | 
					
						
							|  |  |  | 	clk_put(glue->clk); | 
					
						
							|  |  |  | 	clk_put(glue->phy_clk); | 
					
						
							| 
									
										
										
										
											2010-12-02 09:33:24 +02:00
										 |  |  | 	kfree(glue); | 
					
						
							| 
									
										
										
										
											2010-12-02 09:06:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-02 12:53:22 +02:00
										 |  |  | #ifdef CONFIG_PM
 | 
					
						
							|  |  |  | static int am35x_suspend(struct device *dev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct am35x_glue	*glue = dev_get_drvdata(dev); | 
					
						
							| 
									
										
										
										
											2010-12-07 18:57:45 +05:30
										 |  |  | 	struct musb_hdrc_platform_data *plat = dev->platform_data; | 
					
						
							|  |  |  | 	struct omap_musb_board_data *data = plat->board_data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Shutdown the on-chip PHY and its PLL. */ | 
					
						
							|  |  |  | 	if (data->set_phy_power) | 
					
						
							|  |  |  | 		data->set_phy_power(0); | 
					
						
							| 
									
										
										
										
											2010-12-02 12:53:22 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	clk_disable(glue->phy_clk); | 
					
						
							|  |  |  | 	clk_disable(glue->clk); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int am35x_resume(struct device *dev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct am35x_glue	*glue = dev_get_drvdata(dev); | 
					
						
							| 
									
										
										
										
											2010-12-07 18:57:45 +05:30
										 |  |  | 	struct musb_hdrc_platform_data *plat = dev->platform_data; | 
					
						
							|  |  |  | 	struct omap_musb_board_data *data = plat->board_data; | 
					
						
							| 
									
										
										
										
											2010-12-02 12:53:22 +02:00
										 |  |  | 	int			ret; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-07 18:57:45 +05:30
										 |  |  | 	/* Start the on-chip PHY and its PLL. */ | 
					
						
							|  |  |  | 	if (data->set_phy_power) | 
					
						
							|  |  |  | 		data->set_phy_power(1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-02 12:53:22 +02:00
										 |  |  | 	ret = clk_enable(glue->phy_clk); | 
					
						
							|  |  |  | 	if (ret) { | 
					
						
							|  |  |  | 		dev_err(dev, "failed to enable PHY clock\n"); | 
					
						
							|  |  |  | 		return ret; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ret = clk_enable(glue->clk); | 
					
						
							|  |  |  | 	if (ret) { | 
					
						
							|  |  |  | 		dev_err(dev, "failed to enable clock\n"); | 
					
						
							|  |  |  | 		return ret; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct dev_pm_ops am35x_pm_ops = { | 
					
						
							|  |  |  | 	.suspend	= am35x_suspend, | 
					
						
							|  |  |  | 	.resume		= am35x_resume, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define DEV_PM_OPS	&am35x_pm_ops
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | #define DEV_PM_OPS	NULL
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-02 09:06:51 +02:00
										 |  |  | static struct platform_driver am35x_driver = { | 
					
						
							| 
									
										
										
										
											2012-01-26 12:40:23 +02:00
										 |  |  | 	.probe		= am35x_probe, | 
					
						
							| 
									
										
										
										
											2012-11-19 13:21:08 -05:00
										 |  |  | 	.remove		= am35x_remove, | 
					
						
							| 
									
										
										
										
											2010-12-02 09:06:51 +02:00
										 |  |  | 	.driver		= { | 
					
						
							|  |  |  | 		.name	= "musb-am35x", | 
					
						
							| 
									
										
										
										
											2010-12-02 12:53:22 +02:00
										 |  |  | 		.pm	= DEV_PM_OPS, | 
					
						
							| 
									
										
										
										
											2010-12-02 09:06:51 +02:00
										 |  |  | 	}, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MODULE_DESCRIPTION("AM35x MUSB Glue Layer"); | 
					
						
							|  |  |  | MODULE_AUTHOR("Ajay Kumar Gupta <ajay.gupta@ti.com>"); | 
					
						
							|  |  |  | MODULE_LICENSE("GPL v2"); | 
					
						
							| 
									
										
										
										
											2012-10-10 19:36:46 +01:00
										 |  |  | module_platform_driver(am35x_driver); |