xref: /linux/drivers/usb/musb/musb_dsps.c (revision 3e594b18f1871a758812aa5e705873012cabf0e8)
19ecb8875SAjay Kumar Gupta /*
29ecb8875SAjay Kumar Gupta  * Texas Instruments DSPS platforms "glue layer"
39ecb8875SAjay Kumar Gupta  *
49ecb8875SAjay Kumar Gupta  * Copyright (C) 2012, by Texas Instruments
59ecb8875SAjay Kumar Gupta  *
69ecb8875SAjay Kumar Gupta  * Based on the am35x "glue layer" code.
79ecb8875SAjay Kumar Gupta  *
89ecb8875SAjay Kumar Gupta  * This file is part of the Inventra Controller Driver for Linux.
99ecb8875SAjay Kumar Gupta  *
109ecb8875SAjay Kumar Gupta  * The Inventra Controller Driver for Linux is free software; you
119ecb8875SAjay Kumar Gupta  * can redistribute it and/or modify it under the terms of the GNU
129ecb8875SAjay Kumar Gupta  * General Public License version 2 as published by the Free Software
139ecb8875SAjay Kumar Gupta  * Foundation.
149ecb8875SAjay Kumar Gupta  *
159ecb8875SAjay Kumar Gupta  * The Inventra Controller Driver for Linux is distributed in
169ecb8875SAjay Kumar Gupta  * the hope that it will be useful, but WITHOUT ANY WARRANTY;
179ecb8875SAjay Kumar Gupta  * without even the implied warranty of MERCHANTABILITY or
189ecb8875SAjay Kumar Gupta  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
199ecb8875SAjay Kumar Gupta  * License for more details.
209ecb8875SAjay Kumar Gupta  *
219ecb8875SAjay Kumar Gupta  * You should have received a copy of the GNU General Public License
229ecb8875SAjay Kumar Gupta  * along with The Inventra Controller Driver for Linux ; if not,
239ecb8875SAjay Kumar Gupta  * write to the Free Software Foundation, Inc., 59 Temple Place,
249ecb8875SAjay Kumar Gupta  * Suite 330, Boston, MA  02111-1307  USA
259ecb8875SAjay Kumar Gupta  *
269ecb8875SAjay Kumar Gupta  * musb_dsps.c will be a common file for all the TI DSPS platforms
279ecb8875SAjay Kumar Gupta  * such as dm64x, dm36x, dm35x, da8x, am35x and ti81x.
289ecb8875SAjay Kumar Gupta  * For now only ti81x is using this and in future davinci.c, am35x.c
299ecb8875SAjay Kumar Gupta  * da8xx.c would be merged to this file after testing.
309ecb8875SAjay Kumar Gupta  */
319ecb8875SAjay Kumar Gupta 
329ecb8875SAjay Kumar Gupta #include <linux/init.h>
339ecb8875SAjay Kumar Gupta #include <linux/io.h>
3465145677SAjay Kumar Gupta #include <linux/of.h>
35ded017eeSKishon Vijay Abraham I #include <linux/err.h>
369ecb8875SAjay Kumar Gupta #include <linux/platform_device.h>
379ecb8875SAjay Kumar Gupta #include <linux/dma-mapping.h>
389ecb8875SAjay Kumar Gupta #include <linux/pm_runtime.h>
399ecb8875SAjay Kumar Gupta #include <linux/module.h>
4078c289f8SFelipe Balbi #include <linux/usb/nop-usb-xceiv.h>
419ecb8875SAjay Kumar Gupta 
429ecb8875SAjay Kumar Gupta #include <linux/of.h>
439ecb8875SAjay Kumar Gupta #include <linux/of_device.h>
449ecb8875SAjay Kumar Gupta #include <linux/of_address.h>
459ecb8875SAjay Kumar Gupta 
469ecb8875SAjay Kumar Gupta #include <plat/usb.h>
479ecb8875SAjay Kumar Gupta 
489ecb8875SAjay Kumar Gupta #include "musb_core.h"
499ecb8875SAjay Kumar Gupta 
5065145677SAjay Kumar Gupta #ifdef CONFIG_OF
5165145677SAjay Kumar Gupta static const struct of_device_id musb_dsps_of_match[];
5265145677SAjay Kumar Gupta #endif
5365145677SAjay Kumar Gupta 
549ecb8875SAjay Kumar Gupta /**
559ecb8875SAjay Kumar Gupta  * avoid using musb_readx()/musb_writex() as glue layer should not be
569ecb8875SAjay Kumar Gupta  * dependent on musb core layer symbols.
579ecb8875SAjay Kumar Gupta  */
589ecb8875SAjay Kumar Gupta static inline u8 dsps_readb(const void __iomem *addr, unsigned offset)
599ecb8875SAjay Kumar Gupta 	{ return __raw_readb(addr + offset); }
609ecb8875SAjay Kumar Gupta 
619ecb8875SAjay Kumar Gupta static inline u32 dsps_readl(const void __iomem *addr, unsigned offset)
629ecb8875SAjay Kumar Gupta 	{ return __raw_readl(addr + offset); }
639ecb8875SAjay Kumar Gupta 
649ecb8875SAjay Kumar Gupta static inline void dsps_writeb(void __iomem *addr, unsigned offset, u8 data)
659ecb8875SAjay Kumar Gupta 	{ __raw_writeb(data, addr + offset); }
669ecb8875SAjay Kumar Gupta 
679ecb8875SAjay Kumar Gupta static inline void dsps_writel(void __iomem *addr, unsigned offset, u32 data)
689ecb8875SAjay Kumar Gupta 	{ __raw_writel(data, addr + offset); }
699ecb8875SAjay Kumar Gupta 
709ecb8875SAjay Kumar Gupta /**
719ecb8875SAjay Kumar Gupta  * DSPS musb wrapper register offset.
729ecb8875SAjay Kumar Gupta  * FIXME: This should be expanded to have all the wrapper registers from TI DSPS
739ecb8875SAjay Kumar Gupta  * musb ips.
749ecb8875SAjay Kumar Gupta  */
759ecb8875SAjay Kumar Gupta struct dsps_musb_wrapper {
769ecb8875SAjay Kumar Gupta 	u16	revision;
779ecb8875SAjay Kumar Gupta 	u16	control;
789ecb8875SAjay Kumar Gupta 	u16	status;
799ecb8875SAjay Kumar Gupta 	u16	eoi;
809ecb8875SAjay Kumar Gupta 	u16	epintr_set;
819ecb8875SAjay Kumar Gupta 	u16	epintr_clear;
829ecb8875SAjay Kumar Gupta 	u16	epintr_status;
839ecb8875SAjay Kumar Gupta 	u16	coreintr_set;
849ecb8875SAjay Kumar Gupta 	u16	coreintr_clear;
859ecb8875SAjay Kumar Gupta 	u16	coreintr_status;
869ecb8875SAjay Kumar Gupta 	u16	phy_utmi;
879ecb8875SAjay Kumar Gupta 	u16	mode;
889ecb8875SAjay Kumar Gupta 
899ecb8875SAjay Kumar Gupta 	/* bit positions for control */
909ecb8875SAjay Kumar Gupta 	unsigned	reset:5;
919ecb8875SAjay Kumar Gupta 
929ecb8875SAjay Kumar Gupta 	/* bit positions for interrupt */
939ecb8875SAjay Kumar Gupta 	unsigned	usb_shift:5;
949ecb8875SAjay Kumar Gupta 	u32		usb_mask;
959ecb8875SAjay Kumar Gupta 	u32		usb_bitmap;
969ecb8875SAjay Kumar Gupta 	unsigned	drvvbus:5;
979ecb8875SAjay Kumar Gupta 
989ecb8875SAjay Kumar Gupta 	unsigned	txep_shift:5;
999ecb8875SAjay Kumar Gupta 	u32		txep_mask;
1009ecb8875SAjay Kumar Gupta 	u32		txep_bitmap;
1019ecb8875SAjay Kumar Gupta 
1029ecb8875SAjay Kumar Gupta 	unsigned	rxep_shift:5;
1039ecb8875SAjay Kumar Gupta 	u32		rxep_mask;
1049ecb8875SAjay Kumar Gupta 	u32		rxep_bitmap;
1059ecb8875SAjay Kumar Gupta 
1069ecb8875SAjay Kumar Gupta 	/* bit positions for phy_utmi */
1079ecb8875SAjay Kumar Gupta 	unsigned	otg_disable:5;
1089ecb8875SAjay Kumar Gupta 
1099ecb8875SAjay Kumar Gupta 	/* bit positions for mode */
1109ecb8875SAjay Kumar Gupta 	unsigned	iddig:5;
1119ecb8875SAjay Kumar Gupta 	/* miscellaneous stuff */
1129ecb8875SAjay Kumar Gupta 	u32		musb_core_offset;
1139ecb8875SAjay Kumar Gupta 	u8		poll_seconds;
114db4a9320SB, Ravi 	/* number of musb instances */
115db4a9320SB, Ravi 	u8		instances;
1169ecb8875SAjay Kumar Gupta };
1179ecb8875SAjay Kumar Gupta 
1189ecb8875SAjay Kumar Gupta /**
1199ecb8875SAjay Kumar Gupta  * DSPS glue structure.
1209ecb8875SAjay Kumar Gupta  */
1219ecb8875SAjay Kumar Gupta struct dsps_glue {
1229ecb8875SAjay Kumar Gupta 	struct device *dev;
123db4a9320SB, Ravi 	struct platform_device *musb[2];	/* child musb pdev */
1249ecb8875SAjay Kumar Gupta 	const struct dsps_musb_wrapper *wrp; /* wrapper register offsets */
125db4a9320SB, Ravi 	struct timer_list timer[2];	/* otg_workaround timer */
126db4a9320SB, Ravi 	unsigned long last_timer[2];    /* last timer data for each instance */
1279ecb8875SAjay Kumar Gupta };
1289ecb8875SAjay Kumar Gupta 
1299ecb8875SAjay Kumar Gupta /**
1309ecb8875SAjay Kumar Gupta  * dsps_musb_enable - enable interrupts
1319ecb8875SAjay Kumar Gupta  */
1329ecb8875SAjay Kumar Gupta static void dsps_musb_enable(struct musb *musb)
1339ecb8875SAjay Kumar Gupta {
1349ecb8875SAjay Kumar Gupta 	struct device *dev = musb->controller;
1359ecb8875SAjay Kumar Gupta 	struct platform_device *pdev = to_platform_device(dev->parent);
1369ecb8875SAjay Kumar Gupta 	struct dsps_glue *glue = platform_get_drvdata(pdev);
1379ecb8875SAjay Kumar Gupta 	const struct dsps_musb_wrapper *wrp = glue->wrp;
1389ecb8875SAjay Kumar Gupta 	void __iomem *reg_base = musb->ctrl_base;
1399ecb8875SAjay Kumar Gupta 	u32 epmask, coremask;
1409ecb8875SAjay Kumar Gupta 
1419ecb8875SAjay Kumar Gupta 	/* Workaround: setup IRQs through both register sets. */
1429ecb8875SAjay Kumar Gupta 	epmask = ((musb->epmask & wrp->txep_mask) << wrp->txep_shift) |
1439ecb8875SAjay Kumar Gupta 	       ((musb->epmask & wrp->rxep_mask) << wrp->rxep_shift);
1449ecb8875SAjay Kumar Gupta 	coremask = (wrp->usb_bitmap & ~MUSB_INTR_SOF);
1459ecb8875SAjay Kumar Gupta 
1469ecb8875SAjay Kumar Gupta 	dsps_writel(reg_base, wrp->epintr_set, epmask);
1479ecb8875SAjay Kumar Gupta 	dsps_writel(reg_base, wrp->coreintr_set, coremask);
1489ecb8875SAjay Kumar Gupta 	/* Force the DRVVBUS IRQ so we can start polling for ID change. */
1499ecb8875SAjay Kumar Gupta 	dsps_writel(reg_base, wrp->coreintr_set,
1509ecb8875SAjay Kumar Gupta 		    (1 << wrp->drvvbus) << wrp->usb_shift);
1519ecb8875SAjay Kumar Gupta }
1529ecb8875SAjay Kumar Gupta 
1539ecb8875SAjay Kumar Gupta /**
1549ecb8875SAjay Kumar Gupta  * dsps_musb_disable - disable HDRC and flush interrupts
1559ecb8875SAjay Kumar Gupta  */
1569ecb8875SAjay Kumar Gupta static void dsps_musb_disable(struct musb *musb)
1579ecb8875SAjay Kumar Gupta {
1589ecb8875SAjay Kumar Gupta 	struct device *dev = musb->controller;
1599ecb8875SAjay Kumar Gupta 	struct platform_device *pdev = to_platform_device(dev->parent);
1609ecb8875SAjay Kumar Gupta 	struct dsps_glue *glue = platform_get_drvdata(pdev);
1619ecb8875SAjay Kumar Gupta 	const struct dsps_musb_wrapper *wrp = glue->wrp;
1629ecb8875SAjay Kumar Gupta 	void __iomem *reg_base = musb->ctrl_base;
1639ecb8875SAjay Kumar Gupta 
1649ecb8875SAjay Kumar Gupta 	dsps_writel(reg_base, wrp->coreintr_clear, wrp->usb_bitmap);
1659ecb8875SAjay Kumar Gupta 	dsps_writel(reg_base, wrp->epintr_clear,
1669ecb8875SAjay Kumar Gupta 			 wrp->txep_bitmap | wrp->rxep_bitmap);
1679ecb8875SAjay Kumar Gupta 	dsps_writeb(musb->mregs, MUSB_DEVCTL, 0);
1689ecb8875SAjay Kumar Gupta 	dsps_writel(reg_base, wrp->eoi, 0);
1699ecb8875SAjay Kumar Gupta }
1709ecb8875SAjay Kumar Gupta 
1719ecb8875SAjay Kumar Gupta static void otg_timer(unsigned long _musb)
1729ecb8875SAjay Kumar Gupta {
1739ecb8875SAjay Kumar Gupta 	struct musb *musb = (void *)_musb;
1749ecb8875SAjay Kumar Gupta 	void __iomem *mregs = musb->mregs;
1759ecb8875SAjay Kumar Gupta 	struct device *dev = musb->controller;
176db4a9320SB, Ravi 	struct platform_device *pdev = to_platform_device(dev);
177db4a9320SB, Ravi 	struct dsps_glue *glue = dev_get_drvdata(dev->parent);
1789ecb8875SAjay Kumar Gupta 	const struct dsps_musb_wrapper *wrp = glue->wrp;
1799ecb8875SAjay Kumar Gupta 	u8 devctl;
1809ecb8875SAjay Kumar Gupta 	unsigned long flags;
1819ecb8875SAjay Kumar Gupta 
1829ecb8875SAjay Kumar Gupta 	/*
1839ecb8875SAjay Kumar Gupta 	 * We poll because DSPS IP's won't expose several OTG-critical
1849ecb8875SAjay Kumar Gupta 	 * status change events (from the transceiver) otherwise.
1859ecb8875SAjay Kumar Gupta 	 */
1869ecb8875SAjay Kumar Gupta 	devctl = dsps_readb(mregs, MUSB_DEVCTL);
1879ecb8875SAjay Kumar Gupta 	dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl,
1889ecb8875SAjay Kumar Gupta 				otg_state_string(musb->xceiv->state));
1899ecb8875SAjay Kumar Gupta 
1909ecb8875SAjay Kumar Gupta 	spin_lock_irqsave(&musb->lock, flags);
1919ecb8875SAjay Kumar Gupta 	switch (musb->xceiv->state) {
1929ecb8875SAjay Kumar Gupta 	case OTG_STATE_A_WAIT_BCON:
1939ecb8875SAjay Kumar Gupta 		devctl &= ~MUSB_DEVCTL_SESSION;
1949ecb8875SAjay Kumar Gupta 		dsps_writeb(musb->mregs, MUSB_DEVCTL, devctl);
1959ecb8875SAjay Kumar Gupta 
1969ecb8875SAjay Kumar Gupta 		devctl = dsps_readb(musb->mregs, MUSB_DEVCTL);
1979ecb8875SAjay Kumar Gupta 		if (devctl & MUSB_DEVCTL_BDEVICE) {
1989ecb8875SAjay Kumar Gupta 			musb->xceiv->state = OTG_STATE_B_IDLE;
1999ecb8875SAjay Kumar Gupta 			MUSB_DEV_MODE(musb);
2009ecb8875SAjay Kumar Gupta 		} else {
2019ecb8875SAjay Kumar Gupta 			musb->xceiv->state = OTG_STATE_A_IDLE;
2029ecb8875SAjay Kumar Gupta 			MUSB_HST_MODE(musb);
2039ecb8875SAjay Kumar Gupta 		}
2049ecb8875SAjay Kumar Gupta 		break;
2059ecb8875SAjay Kumar Gupta 	case OTG_STATE_A_WAIT_VFALL:
2069ecb8875SAjay Kumar Gupta 		musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
2079ecb8875SAjay Kumar Gupta 		dsps_writel(musb->ctrl_base, wrp->coreintr_set,
2089ecb8875SAjay Kumar Gupta 			    MUSB_INTR_VBUSERROR << wrp->usb_shift);
2099ecb8875SAjay Kumar Gupta 		break;
2109ecb8875SAjay Kumar Gupta 	case OTG_STATE_B_IDLE:
2119ecb8875SAjay Kumar Gupta 		devctl = dsps_readb(mregs, MUSB_DEVCTL);
2129ecb8875SAjay Kumar Gupta 		if (devctl & MUSB_DEVCTL_BDEVICE)
213db4a9320SB, Ravi 			mod_timer(&glue->timer[pdev->id],
2149ecb8875SAjay Kumar Gupta 					jiffies + wrp->poll_seconds * HZ);
2159ecb8875SAjay Kumar Gupta 		else
2169ecb8875SAjay Kumar Gupta 			musb->xceiv->state = OTG_STATE_A_IDLE;
2179ecb8875SAjay Kumar Gupta 		break;
2189ecb8875SAjay Kumar Gupta 	default:
2199ecb8875SAjay Kumar Gupta 		break;
2209ecb8875SAjay Kumar Gupta 	}
2219ecb8875SAjay Kumar Gupta 	spin_unlock_irqrestore(&musb->lock, flags);
2229ecb8875SAjay Kumar Gupta }
2239ecb8875SAjay Kumar Gupta 
2249ecb8875SAjay Kumar Gupta static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout)
2259ecb8875SAjay Kumar Gupta {
2269ecb8875SAjay Kumar Gupta 	struct device *dev = musb->controller;
227db4a9320SB, Ravi 	struct platform_device *pdev = to_platform_device(dev);
228db4a9320SB, Ravi 	struct dsps_glue *glue = dev_get_drvdata(dev->parent);
2299ecb8875SAjay Kumar Gupta 
2309ecb8875SAjay Kumar Gupta 	if (timeout == 0)
2319ecb8875SAjay Kumar Gupta 		timeout = jiffies + msecs_to_jiffies(3);
2329ecb8875SAjay Kumar Gupta 
2339ecb8875SAjay Kumar Gupta 	/* Never idle if active, or when VBUS timeout is not set as host */
2349ecb8875SAjay Kumar Gupta 	if (musb->is_active || (musb->a_wait_bcon == 0 &&
2359ecb8875SAjay Kumar Gupta 				musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) {
2369ecb8875SAjay Kumar Gupta 		dev_dbg(musb->controller, "%s active, deleting timer\n",
2379ecb8875SAjay Kumar Gupta 				otg_state_string(musb->xceiv->state));
238db4a9320SB, Ravi 		del_timer(&glue->timer[pdev->id]);
239db4a9320SB, Ravi 		glue->last_timer[pdev->id] = jiffies;
2409ecb8875SAjay Kumar Gupta 		return;
2419ecb8875SAjay Kumar Gupta 	}
2429ecb8875SAjay Kumar Gupta 
243db4a9320SB, Ravi 	if (time_after(glue->last_timer[pdev->id], timeout) &&
244db4a9320SB, Ravi 				timer_pending(&glue->timer[pdev->id])) {
2459ecb8875SAjay Kumar Gupta 		dev_dbg(musb->controller,
2469ecb8875SAjay Kumar Gupta 			"Longer idle timer already pending, ignoring...\n");
2479ecb8875SAjay Kumar Gupta 		return;
2489ecb8875SAjay Kumar Gupta 	}
249db4a9320SB, Ravi 	glue->last_timer[pdev->id] = timeout;
2509ecb8875SAjay Kumar Gupta 
2519ecb8875SAjay Kumar Gupta 	dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n",
2529ecb8875SAjay Kumar Gupta 		otg_state_string(musb->xceiv->state),
2539ecb8875SAjay Kumar Gupta 			jiffies_to_msecs(timeout - jiffies));
254db4a9320SB, Ravi 	mod_timer(&glue->timer[pdev->id], timeout);
2559ecb8875SAjay Kumar Gupta }
2569ecb8875SAjay Kumar Gupta 
2579ecb8875SAjay Kumar Gupta static irqreturn_t dsps_interrupt(int irq, void *hci)
2589ecb8875SAjay Kumar Gupta {
2599ecb8875SAjay Kumar Gupta 	struct musb  *musb = hci;
2609ecb8875SAjay Kumar Gupta 	void __iomem *reg_base = musb->ctrl_base;
2619ecb8875SAjay Kumar Gupta 	struct device *dev = musb->controller;
262db4a9320SB, Ravi 	struct platform_device *pdev = to_platform_device(dev);
263db4a9320SB, Ravi 	struct dsps_glue *glue = dev_get_drvdata(dev->parent);
2649ecb8875SAjay Kumar Gupta 	const struct dsps_musb_wrapper *wrp = glue->wrp;
2659ecb8875SAjay Kumar Gupta 	unsigned long flags;
2669ecb8875SAjay Kumar Gupta 	irqreturn_t ret = IRQ_NONE;
2679ecb8875SAjay Kumar Gupta 	u32 epintr, usbintr;
2689ecb8875SAjay Kumar Gupta 
2699ecb8875SAjay Kumar Gupta 	spin_lock_irqsave(&musb->lock, flags);
2709ecb8875SAjay Kumar Gupta 
2719ecb8875SAjay Kumar Gupta 	/* Get endpoint interrupts */
2729ecb8875SAjay Kumar Gupta 	epintr = dsps_readl(reg_base, wrp->epintr_status);
2739ecb8875SAjay Kumar Gupta 	musb->int_rx = (epintr & wrp->rxep_bitmap) >> wrp->rxep_shift;
2749ecb8875SAjay Kumar Gupta 	musb->int_tx = (epintr & wrp->txep_bitmap) >> wrp->txep_shift;
2759ecb8875SAjay Kumar Gupta 
2769ecb8875SAjay Kumar Gupta 	if (epintr)
2779ecb8875SAjay Kumar Gupta 		dsps_writel(reg_base, wrp->epintr_status, epintr);
2789ecb8875SAjay Kumar Gupta 
2799ecb8875SAjay Kumar Gupta 	/* Get usb core interrupts */
2809ecb8875SAjay Kumar Gupta 	usbintr = dsps_readl(reg_base, wrp->coreintr_status);
2819ecb8875SAjay Kumar Gupta 	if (!usbintr && !epintr)
2829ecb8875SAjay Kumar Gupta 		goto eoi;
2839ecb8875SAjay Kumar Gupta 
2849ecb8875SAjay Kumar Gupta 	musb->int_usb =	(usbintr & wrp->usb_bitmap) >> wrp->usb_shift;
2859ecb8875SAjay Kumar Gupta 	if (usbintr)
2869ecb8875SAjay Kumar Gupta 		dsps_writel(reg_base, wrp->coreintr_status, usbintr);
2879ecb8875SAjay Kumar Gupta 
2889ecb8875SAjay Kumar Gupta 	dev_dbg(musb->controller, "usbintr (%x) epintr(%x)\n",
2899ecb8875SAjay Kumar Gupta 			usbintr, epintr);
2909ecb8875SAjay Kumar Gupta 	/*
2919ecb8875SAjay Kumar Gupta 	 * DRVVBUS IRQs are the only proxy we have (a very poor one!) for
2929ecb8875SAjay Kumar Gupta 	 * DSPS IP's missing ID change IRQ.  We need an ID change IRQ to
2939ecb8875SAjay Kumar Gupta 	 * switch appropriately between halves of the OTG state machine.
2949ecb8875SAjay Kumar Gupta 	 * Managing DEVCTL.SESSION per Mentor docs requires that we know its
2959ecb8875SAjay Kumar Gupta 	 * value but DEVCTL.BDEVICE is invalid without DEVCTL.SESSION set.
2969ecb8875SAjay Kumar Gupta 	 * Also, DRVVBUS pulses for SRP (but not at 5V) ...
2979ecb8875SAjay Kumar Gupta 	 */
298032ec49fSFelipe Balbi 	if (usbintr & MUSB_INTR_BABBLE)
2999ecb8875SAjay Kumar Gupta 		pr_info("CAUTION: musb: Babble Interrupt Occured\n");
3009ecb8875SAjay Kumar Gupta 
3019ecb8875SAjay Kumar Gupta 	if (usbintr & ((1 << wrp->drvvbus) << wrp->usb_shift)) {
3029ecb8875SAjay Kumar Gupta 		int drvvbus = dsps_readl(reg_base, wrp->status);
3039ecb8875SAjay Kumar Gupta 		void __iomem *mregs = musb->mregs;
3049ecb8875SAjay Kumar Gupta 		u8 devctl = dsps_readb(mregs, MUSB_DEVCTL);
3059ecb8875SAjay Kumar Gupta 		int err;
3069ecb8875SAjay Kumar Gupta 
307032ec49fSFelipe Balbi 		err = musb->int_usb & MUSB_INTR_VBUSERROR;
3089ecb8875SAjay Kumar Gupta 		if (err) {
3099ecb8875SAjay Kumar Gupta 			/*
3109ecb8875SAjay Kumar Gupta 			 * The Mentor core doesn't debounce VBUS as needed
3119ecb8875SAjay Kumar Gupta 			 * to cope with device connect current spikes. This
3129ecb8875SAjay Kumar Gupta 			 * means it's not uncommon for bus-powered devices
3139ecb8875SAjay Kumar Gupta 			 * to get VBUS errors during enumeration.
3149ecb8875SAjay Kumar Gupta 			 *
3159ecb8875SAjay Kumar Gupta 			 * This is a workaround, but newer RTL from Mentor
3169ecb8875SAjay Kumar Gupta 			 * seems to allow a better one: "re"-starting sessions
3179ecb8875SAjay Kumar Gupta 			 * without waiting for VBUS to stop registering in
3189ecb8875SAjay Kumar Gupta 			 * devctl.
3199ecb8875SAjay Kumar Gupta 			 */
3209ecb8875SAjay Kumar Gupta 			musb->int_usb &= ~MUSB_INTR_VBUSERROR;
3219ecb8875SAjay Kumar Gupta 			musb->xceiv->state = OTG_STATE_A_WAIT_VFALL;
322db4a9320SB, Ravi 			mod_timer(&glue->timer[pdev->id],
3239ecb8875SAjay Kumar Gupta 					jiffies + wrp->poll_seconds * HZ);
3249ecb8875SAjay Kumar Gupta 			WARNING("VBUS error workaround (delay coming)\n");
325032ec49fSFelipe Balbi 		} else if (drvvbus) {
3269ecb8875SAjay Kumar Gupta 			musb->is_active = 1;
3279ecb8875SAjay Kumar Gupta 			MUSB_HST_MODE(musb);
3289ecb8875SAjay Kumar Gupta 			musb->xceiv->otg->default_a = 1;
3299ecb8875SAjay Kumar Gupta 			musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
330db4a9320SB, Ravi 			del_timer(&glue->timer[pdev->id]);
3319ecb8875SAjay Kumar Gupta 		} else {
3329ecb8875SAjay Kumar Gupta 			musb->is_active = 0;
3339ecb8875SAjay Kumar Gupta 			MUSB_DEV_MODE(musb);
3349ecb8875SAjay Kumar Gupta 			musb->xceiv->otg->default_a = 0;
3359ecb8875SAjay Kumar Gupta 			musb->xceiv->state = OTG_STATE_B_IDLE;
3369ecb8875SAjay Kumar Gupta 		}
3379ecb8875SAjay Kumar Gupta 
3389ecb8875SAjay Kumar Gupta 		/* NOTE: this must complete power-on within 100 ms. */
3399ecb8875SAjay Kumar Gupta 		dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n",
3409ecb8875SAjay Kumar Gupta 				drvvbus ? "on" : "off",
3419ecb8875SAjay Kumar Gupta 				otg_state_string(musb->xceiv->state),
3429ecb8875SAjay Kumar Gupta 				err ? " ERROR" : "",
3439ecb8875SAjay Kumar Gupta 				devctl);
3449ecb8875SAjay Kumar Gupta 		ret = IRQ_HANDLED;
3459ecb8875SAjay Kumar Gupta 	}
3469ecb8875SAjay Kumar Gupta 
3479ecb8875SAjay Kumar Gupta 	if (musb->int_tx || musb->int_rx || musb->int_usb)
3489ecb8875SAjay Kumar Gupta 		ret |= musb_interrupt(musb);
3499ecb8875SAjay Kumar Gupta 
3509ecb8875SAjay Kumar Gupta  eoi:
3519ecb8875SAjay Kumar Gupta 	/* EOI needs to be written for the IRQ to be re-asserted. */
3529ecb8875SAjay Kumar Gupta 	if (ret == IRQ_HANDLED || epintr || usbintr)
3539ecb8875SAjay Kumar Gupta 		dsps_writel(reg_base, wrp->eoi, 1);
3549ecb8875SAjay Kumar Gupta 
3559ecb8875SAjay Kumar Gupta 	/* Poll for ID change */
356032ec49fSFelipe Balbi 	if (musb->xceiv->state == OTG_STATE_B_IDLE)
357db4a9320SB, Ravi 		mod_timer(&glue->timer[pdev->id],
358db4a9320SB, Ravi 			 jiffies + wrp->poll_seconds * HZ);
3599ecb8875SAjay Kumar Gupta 
3609ecb8875SAjay Kumar Gupta 	spin_unlock_irqrestore(&musb->lock, flags);
3619ecb8875SAjay Kumar Gupta 
3629ecb8875SAjay Kumar Gupta 	return ret;
3639ecb8875SAjay Kumar Gupta }
3649ecb8875SAjay Kumar Gupta 
3659ecb8875SAjay Kumar Gupta static int dsps_musb_init(struct musb *musb)
3669ecb8875SAjay Kumar Gupta {
3679ecb8875SAjay Kumar Gupta 	struct device *dev = musb->controller;
368db4a9320SB, Ravi 	struct platform_device *pdev = to_platform_device(dev);
369db4a9320SB, Ravi 	struct dsps_glue *glue = dev_get_drvdata(dev->parent);
3709ecb8875SAjay Kumar Gupta 	const struct dsps_musb_wrapper *wrp = glue->wrp;
3719ecb8875SAjay Kumar Gupta 	void __iomem *reg_base = musb->ctrl_base;
3729ecb8875SAjay Kumar Gupta 	u32 rev, val;
3739ecb8875SAjay Kumar Gupta 	int status;
3749ecb8875SAjay Kumar Gupta 
3759ecb8875SAjay Kumar Gupta 	/* mentor core register starts at offset of 0x400 from musb base */
3769ecb8875SAjay Kumar Gupta 	musb->mregs += wrp->musb_core_offset;
3779ecb8875SAjay Kumar Gupta 
378d8c3ef25SAjay Kumar Gupta 	/* Get the NOP PHY */
379662dca54SKishon Vijay Abraham I 	musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
380ded017eeSKishon Vijay Abraham I 	if (IS_ERR_OR_NULL(musb->xceiv))
3819ecb8875SAjay Kumar Gupta 		return -ENODEV;
3829ecb8875SAjay Kumar Gupta 
3839ecb8875SAjay Kumar Gupta 	/* Returns zero if e.g. not clocked */
3849ecb8875SAjay Kumar Gupta 	rev = dsps_readl(reg_base, wrp->revision);
3859ecb8875SAjay Kumar Gupta 	if (!rev) {
3869ecb8875SAjay Kumar Gupta 		status = -ENODEV;
3879ecb8875SAjay Kumar Gupta 		goto err0;
3889ecb8875SAjay Kumar Gupta 	}
3899ecb8875SAjay Kumar Gupta 
390db4a9320SB, Ravi 	setup_timer(&glue->timer[pdev->id], otg_timer, (unsigned long) musb);
3919ecb8875SAjay Kumar Gupta 
3929ecb8875SAjay Kumar Gupta 	/* Reset the musb */
3939ecb8875SAjay Kumar Gupta 	dsps_writel(reg_base, wrp->control, (1 << wrp->reset));
3949ecb8875SAjay Kumar Gupta 
3959ecb8875SAjay Kumar Gupta 	musb->isr = dsps_interrupt;
3969ecb8875SAjay Kumar Gupta 
3979ecb8875SAjay Kumar Gupta 	/* reset the otgdisable bit, needed for host mode to work */
3989ecb8875SAjay Kumar Gupta 	val = dsps_readl(reg_base, wrp->phy_utmi);
3999ecb8875SAjay Kumar Gupta 	val &= ~(1 << wrp->otg_disable);
4009ecb8875SAjay Kumar Gupta 	dsps_writel(musb->ctrl_base, wrp->phy_utmi, val);
4019ecb8875SAjay Kumar Gupta 
4029ecb8875SAjay Kumar Gupta 	/* clear level interrupt */
4039ecb8875SAjay Kumar Gupta 	dsps_writel(reg_base, wrp->eoi, 0);
4049ecb8875SAjay Kumar Gupta 
4059ecb8875SAjay Kumar Gupta 	return 0;
4069ecb8875SAjay Kumar Gupta err0:
407721002ecSKishon Vijay Abraham I 	usb_put_phy(musb->xceiv);
4089ecb8875SAjay Kumar Gupta 	usb_nop_xceiv_unregister();
4099ecb8875SAjay Kumar Gupta 	return status;
4109ecb8875SAjay Kumar Gupta }
4119ecb8875SAjay Kumar Gupta 
4129ecb8875SAjay Kumar Gupta static int dsps_musb_exit(struct musb *musb)
4139ecb8875SAjay Kumar Gupta {
4149ecb8875SAjay Kumar Gupta 	struct device *dev = musb->controller;
415db4a9320SB, Ravi 	struct platform_device *pdev = to_platform_device(dev);
416db4a9320SB, Ravi 	struct dsps_glue *glue = dev_get_drvdata(dev->parent);
4179ecb8875SAjay Kumar Gupta 
418db4a9320SB, Ravi 	del_timer_sync(&glue->timer[pdev->id]);
4199ecb8875SAjay Kumar Gupta 
4209ecb8875SAjay Kumar Gupta 	/* NOP driver needs change if supporting dual instance */
421721002ecSKishon Vijay Abraham I 	usb_put_phy(musb->xceiv);
4229ecb8875SAjay Kumar Gupta 	usb_nop_xceiv_unregister();
4239ecb8875SAjay Kumar Gupta 
4249ecb8875SAjay Kumar Gupta 	return 0;
4259ecb8875SAjay Kumar Gupta }
4269ecb8875SAjay Kumar Gupta 
4279ecb8875SAjay Kumar Gupta static struct musb_platform_ops dsps_ops = {
4289ecb8875SAjay Kumar Gupta 	.init		= dsps_musb_init,
4299ecb8875SAjay Kumar Gupta 	.exit		= dsps_musb_exit,
4309ecb8875SAjay Kumar Gupta 
4319ecb8875SAjay Kumar Gupta 	.enable		= dsps_musb_enable,
4329ecb8875SAjay Kumar Gupta 	.disable	= dsps_musb_disable,
4339ecb8875SAjay Kumar Gupta 
4349ecb8875SAjay Kumar Gupta 	.try_idle	= dsps_musb_try_idle,
4359ecb8875SAjay Kumar Gupta };
4369ecb8875SAjay Kumar Gupta 
4379ecb8875SAjay Kumar Gupta static u64 musb_dmamask = DMA_BIT_MASK(32);
4389ecb8875SAjay Kumar Gupta 
4399ecb8875SAjay Kumar Gupta static int __devinit dsps_create_musb_pdev(struct dsps_glue *glue, u8 id)
4409ecb8875SAjay Kumar Gupta {
4419ecb8875SAjay Kumar Gupta 	struct device *dev = glue->dev;
4429ecb8875SAjay Kumar Gupta 	struct platform_device *pdev = to_platform_device(dev);
4439ecb8875SAjay Kumar Gupta 	struct musb_hdrc_platform_data  *pdata = dev->platform_data;
44465145677SAjay Kumar Gupta 	struct device_node *np = pdev->dev.of_node;
44565145677SAjay Kumar Gupta 	struct musb_hdrc_config	*config;
4469ecb8875SAjay Kumar Gupta 	struct platform_device	*musb;
4479ecb8875SAjay Kumar Gupta 	struct resource *res;
4489ecb8875SAjay Kumar Gupta 	struct resource	resources[2];
4499ecb8875SAjay Kumar Gupta 	char res_name[10];
4502f771164SSebastian Andrzej Siewior 	int ret;
4519ecb8875SAjay Kumar Gupta 
452*3e594b18SAfzal Mohammed 	/* first resource is for usbss, so start index from 1 */
453*3e594b18SAfzal Mohammed 	res = platform_get_resource(pdev, IORESOURCE_MEM, id + 1);
4549ecb8875SAjay Kumar Gupta 	if (!res) {
455*3e594b18SAfzal Mohammed 		dev_err(dev, "failed to get memory for instance %d\n", id);
4569ecb8875SAjay Kumar Gupta 		ret = -ENODEV;
4579ecb8875SAjay Kumar Gupta 		goto err0;
4589ecb8875SAjay Kumar Gupta 	}
4599ecb8875SAjay Kumar Gupta 	res->parent = NULL;
4609ecb8875SAjay Kumar Gupta 	resources[0] = *res;
4619ecb8875SAjay Kumar Gupta 
462*3e594b18SAfzal Mohammed 	/* first resource is for usbss, so start index from 1 */
463*3e594b18SAfzal Mohammed 	res = platform_get_resource(pdev, IORESOURCE_IRQ, id + 1);
4649ecb8875SAjay Kumar Gupta 	if (!res) {
465*3e594b18SAfzal Mohammed 		dev_err(dev, "failed to get irq for instance %d\n", id);
4669ecb8875SAjay Kumar Gupta 		ret = -ENODEV;
4679ecb8875SAjay Kumar Gupta 		goto err0;
4689ecb8875SAjay Kumar Gupta 	}
4699ecb8875SAjay Kumar Gupta 	res->parent = NULL;
4709ecb8875SAjay Kumar Gupta 	resources[1] = *res;
4713bb55348SAjay Kumar Gupta 	resources[1].name = "mc";
4729ecb8875SAjay Kumar Gupta 
47365b3d52dSB, Ravi 	/* allocate the child platform device */
4742f771164SSebastian Andrzej Siewior 	musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
47565b3d52dSB, Ravi 	if (!musb) {
47665b3d52dSB, Ravi 		dev_err(dev, "failed to allocate musb device\n");
47765b3d52dSB, Ravi 		ret = -ENOMEM;
4782f771164SSebastian Andrzej Siewior 		goto err0;
47965b3d52dSB, Ravi 	}
4809ecb8875SAjay Kumar Gupta 
4819ecb8875SAjay Kumar Gupta 	musb->dev.parent		= dev;
4829ecb8875SAjay Kumar Gupta 	musb->dev.dma_mask		= &musb_dmamask;
4839ecb8875SAjay Kumar Gupta 	musb->dev.coherent_dma_mask	= musb_dmamask;
4849ecb8875SAjay Kumar Gupta 
485db4a9320SB, Ravi 	glue->musb[id]			= musb;
4869ecb8875SAjay Kumar Gupta 
4879ecb8875SAjay Kumar Gupta 	ret = platform_device_add_resources(musb, resources, 2);
4889ecb8875SAjay Kumar Gupta 	if (ret) {
4899ecb8875SAjay Kumar Gupta 		dev_err(dev, "failed to add resources\n");
49065b3d52dSB, Ravi 		goto err2;
4919ecb8875SAjay Kumar Gupta 	}
4929ecb8875SAjay Kumar Gupta 
49365145677SAjay Kumar Gupta 	if (np) {
49465145677SAjay Kumar Gupta 		pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
49565145677SAjay Kumar Gupta 		if (!pdata) {
49665145677SAjay Kumar Gupta 			dev_err(&pdev->dev,
49765145677SAjay Kumar Gupta 				"failed to allocate musb platfrom data\n");
49865145677SAjay Kumar Gupta 			ret = -ENOMEM;
49965145677SAjay Kumar Gupta 			goto err2;
50065145677SAjay Kumar Gupta 		}
50165145677SAjay Kumar Gupta 
50265145677SAjay Kumar Gupta 		config = devm_kzalloc(&pdev->dev, sizeof(*config), GFP_KERNEL);
50365145677SAjay Kumar Gupta 		if (!config) {
50465145677SAjay Kumar Gupta 			dev_err(&pdev->dev,
50565145677SAjay Kumar Gupta 				"failed to allocate musb hdrc config\n");
50665145677SAjay Kumar Gupta 			goto err2;
50765145677SAjay Kumar Gupta 		}
50865145677SAjay Kumar Gupta 
50965145677SAjay Kumar Gupta 		of_property_read_u32(np, "num-eps", (u32 *)&config->num_eps);
51065145677SAjay Kumar Gupta 		of_property_read_u32(np, "ram-bits", (u32 *)&config->ram_bits);
51165145677SAjay Kumar Gupta 		sprintf(res_name, "port%d-mode", id);
51265145677SAjay Kumar Gupta 		of_property_read_u32(np, res_name, (u32 *)&pdata->mode);
51365145677SAjay Kumar Gupta 		of_property_read_u32(np, "power", (u32 *)&pdata->power);
51465145677SAjay Kumar Gupta 		config->multipoint = of_property_read_bool(np, "multipoint");
51565145677SAjay Kumar Gupta 
51665145677SAjay Kumar Gupta 		pdata->config		= config;
51765145677SAjay Kumar Gupta 	}
51865145677SAjay Kumar Gupta 
51965145677SAjay Kumar Gupta 	pdata->platform_ops		= &dsps_ops;
52065145677SAjay Kumar Gupta 
5219ecb8875SAjay Kumar Gupta 	ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
5229ecb8875SAjay Kumar Gupta 	if (ret) {
5239ecb8875SAjay Kumar Gupta 		dev_err(dev, "failed to add platform_data\n");
52465b3d52dSB, Ravi 		goto err2;
5259ecb8875SAjay Kumar Gupta 	}
5269ecb8875SAjay Kumar Gupta 
5279ecb8875SAjay Kumar Gupta 	ret = platform_device_add(musb);
5289ecb8875SAjay Kumar Gupta 	if (ret) {
5299ecb8875SAjay Kumar Gupta 		dev_err(dev, "failed to register musb device\n");
53065b3d52dSB, Ravi 		goto err2;
5319ecb8875SAjay Kumar Gupta 	}
5329ecb8875SAjay Kumar Gupta 
5339ecb8875SAjay Kumar Gupta 	return 0;
5349ecb8875SAjay Kumar Gupta 
53565b3d52dSB, Ravi err2:
5369ecb8875SAjay Kumar Gupta 	platform_device_put(musb);
5379ecb8875SAjay Kumar Gupta err0:
5389ecb8875SAjay Kumar Gupta 	return ret;
5399ecb8875SAjay Kumar Gupta }
5409ecb8875SAjay Kumar Gupta 
5419ecb8875SAjay Kumar Gupta static int __devinit dsps_probe(struct platform_device *pdev)
5429ecb8875SAjay Kumar Gupta {
54365145677SAjay Kumar Gupta 	struct device_node *np = pdev->dev.of_node;
54465145677SAjay Kumar Gupta 	const struct of_device_id *match;
54565145677SAjay Kumar Gupta 	const struct dsps_musb_wrapper *wrp;
5469ecb8875SAjay Kumar Gupta 	struct dsps_glue *glue;
5479ecb8875SAjay Kumar Gupta 	struct resource *iomem;
548db4a9320SB, Ravi 	int ret, i;
5499ecb8875SAjay Kumar Gupta 
55065145677SAjay Kumar Gupta 	match = of_match_node(musb_dsps_of_match, np);
55165145677SAjay Kumar Gupta 	if (!match) {
55265145677SAjay Kumar Gupta 		dev_err(&pdev->dev, "fail to get matching of_match struct\n");
55365145677SAjay Kumar Gupta 		ret = -EINVAL;
55465145677SAjay Kumar Gupta 		goto err0;
55565145677SAjay Kumar Gupta 	}
55665145677SAjay Kumar Gupta 	wrp = match->data;
5579ecb8875SAjay Kumar Gupta 
5589ecb8875SAjay Kumar Gupta 	/* allocate glue */
5599ecb8875SAjay Kumar Gupta 	glue = kzalloc(sizeof(*glue), GFP_KERNEL);
5609ecb8875SAjay Kumar Gupta 	if (!glue) {
5619ecb8875SAjay Kumar Gupta 		dev_err(&pdev->dev, "unable to allocate glue memory\n");
5629ecb8875SAjay Kumar Gupta 		ret = -ENOMEM;
5639ecb8875SAjay Kumar Gupta 		goto err0;
5649ecb8875SAjay Kumar Gupta 	}
5659ecb8875SAjay Kumar Gupta 
5669ecb8875SAjay Kumar Gupta 	/* get memory resource */
5679ecb8875SAjay Kumar Gupta 	iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
5689ecb8875SAjay Kumar Gupta 	if (!iomem) {
5699ecb8875SAjay Kumar Gupta 		dev_err(&pdev->dev, "failed to get usbss mem resourse\n");
5709ecb8875SAjay Kumar Gupta 		ret = -ENODEV;
5719ecb8875SAjay Kumar Gupta 		goto err1;
5729ecb8875SAjay Kumar Gupta 	}
5739ecb8875SAjay Kumar Gupta 
5749ecb8875SAjay Kumar Gupta 	glue->dev = &pdev->dev;
5759ecb8875SAjay Kumar Gupta 
5769ecb8875SAjay Kumar Gupta 	glue->wrp = kmemdup(wrp, sizeof(*wrp), GFP_KERNEL);
5779ecb8875SAjay Kumar Gupta 	if (!glue->wrp) {
5789ecb8875SAjay Kumar Gupta 		dev_err(&pdev->dev, "failed to duplicate wrapper struct memory\n");
5799ecb8875SAjay Kumar Gupta 		ret = -ENOMEM;
5809ecb8875SAjay Kumar Gupta 		goto err1;
5819ecb8875SAjay Kumar Gupta 	}
5829ecb8875SAjay Kumar Gupta 	platform_set_drvdata(pdev, glue);
5839ecb8875SAjay Kumar Gupta 
5849ecb8875SAjay Kumar Gupta 	/* enable the usbss clocks */
5859ecb8875SAjay Kumar Gupta 	pm_runtime_enable(&pdev->dev);
5869ecb8875SAjay Kumar Gupta 
5879ecb8875SAjay Kumar Gupta 	ret = pm_runtime_get_sync(&pdev->dev);
5889ecb8875SAjay Kumar Gupta 	if (ret < 0) {
5899ecb8875SAjay Kumar Gupta 		dev_err(&pdev->dev, "pm_runtime_get_sync FAILED");
5900e38c4edSAjay Kumar Gupta 		goto err2;
5910e38c4edSAjay Kumar Gupta 	}
5920e38c4edSAjay Kumar Gupta 
593db4a9320SB, Ravi 	/* create the child platform device for all instances of musb */
594db4a9320SB, Ravi 	for (i = 0; i < wrp->instances ; i++) {
595db4a9320SB, Ravi 		ret = dsps_create_musb_pdev(glue, i);
5960e38c4edSAjay Kumar Gupta 		if (ret != 0) {
5970e38c4edSAjay Kumar Gupta 			dev_err(&pdev->dev, "failed to create child pdev\n");
598db4a9320SB, Ravi 			/* release resources of previously created instances */
599db4a9320SB, Ravi 			for (i--; i >= 0 ; i--)
6002f771164SSebastian Andrzej Siewior 				platform_device_unregister(glue->musb[i]);
6019ecb8875SAjay Kumar Gupta 			goto err3;
6029ecb8875SAjay Kumar Gupta 		}
603db4a9320SB, Ravi 	}
6049ecb8875SAjay Kumar Gupta 
6059ecb8875SAjay Kumar Gupta 	return 0;
6069ecb8875SAjay Kumar Gupta 
6079ecb8875SAjay Kumar Gupta err3:
6080e38c4edSAjay Kumar Gupta 	pm_runtime_put(&pdev->dev);
6099ecb8875SAjay Kumar Gupta err2:
6100e38c4edSAjay Kumar Gupta 	pm_runtime_disable(&pdev->dev);
6119ecb8875SAjay Kumar Gupta 	kfree(glue->wrp);
6129ecb8875SAjay Kumar Gupta err1:
6139ecb8875SAjay Kumar Gupta 	kfree(glue);
6149ecb8875SAjay Kumar Gupta err0:
6159ecb8875SAjay Kumar Gupta 	return ret;
6169ecb8875SAjay Kumar Gupta }
6179ecb8875SAjay Kumar Gupta static int __devexit dsps_remove(struct platform_device *pdev)
6189ecb8875SAjay Kumar Gupta {
6199ecb8875SAjay Kumar Gupta 	struct dsps_glue *glue = platform_get_drvdata(pdev);
620db4a9320SB, Ravi 	const struct dsps_musb_wrapper *wrp = glue->wrp;
621db4a9320SB, Ravi 	int i;
6229ecb8875SAjay Kumar Gupta 
6239ecb8875SAjay Kumar Gupta 	/* delete the child platform device */
624db4a9320SB, Ravi 	for (i = 0; i < wrp->instances ; i++)
6252f771164SSebastian Andrzej Siewior 		platform_device_unregister(glue->musb[i]);
6269ecb8875SAjay Kumar Gupta 
6279ecb8875SAjay Kumar Gupta 	/* disable usbss clocks */
6289ecb8875SAjay Kumar Gupta 	pm_runtime_put(&pdev->dev);
6299ecb8875SAjay Kumar Gupta 	pm_runtime_disable(&pdev->dev);
6309ecb8875SAjay Kumar Gupta 	kfree(glue->wrp);
6319ecb8875SAjay Kumar Gupta 	kfree(glue);
6329ecb8875SAjay Kumar Gupta 	return 0;
6339ecb8875SAjay Kumar Gupta }
6349ecb8875SAjay Kumar Gupta 
6359ecb8875SAjay Kumar Gupta #ifdef CONFIG_PM_SLEEP
6369ecb8875SAjay Kumar Gupta static int dsps_suspend(struct device *dev)
6379ecb8875SAjay Kumar Gupta {
6389ecb8875SAjay Kumar Gupta 	return 0;
6399ecb8875SAjay Kumar Gupta }
6409ecb8875SAjay Kumar Gupta 
6419ecb8875SAjay Kumar Gupta static int dsps_resume(struct device *dev)
6429ecb8875SAjay Kumar Gupta {
6439ecb8875SAjay Kumar Gupta 	return 0;
6449ecb8875SAjay Kumar Gupta }
6459ecb8875SAjay Kumar Gupta #endif
6469ecb8875SAjay Kumar Gupta 
6479ecb8875SAjay Kumar Gupta static SIMPLE_DEV_PM_OPS(dsps_pm_ops, dsps_suspend, dsps_resume);
6489ecb8875SAjay Kumar Gupta 
6499ecb8875SAjay Kumar Gupta static const struct dsps_musb_wrapper ti81xx_driver_data __devinitconst = {
6509ecb8875SAjay Kumar Gupta 	.revision		= 0x00,
6519ecb8875SAjay Kumar Gupta 	.control		= 0x14,
6529ecb8875SAjay Kumar Gupta 	.status			= 0x18,
6539ecb8875SAjay Kumar Gupta 	.eoi			= 0x24,
6549ecb8875SAjay Kumar Gupta 	.epintr_set		= 0x38,
6559ecb8875SAjay Kumar Gupta 	.epintr_clear		= 0x40,
6569ecb8875SAjay Kumar Gupta 	.epintr_status		= 0x30,
6579ecb8875SAjay Kumar Gupta 	.coreintr_set		= 0x3c,
6589ecb8875SAjay Kumar Gupta 	.coreintr_clear		= 0x44,
6599ecb8875SAjay Kumar Gupta 	.coreintr_status	= 0x34,
6609ecb8875SAjay Kumar Gupta 	.phy_utmi		= 0xe0,
6619ecb8875SAjay Kumar Gupta 	.mode			= 0xe8,
6629ecb8875SAjay Kumar Gupta 	.reset			= 0,
6639ecb8875SAjay Kumar Gupta 	.otg_disable		= 21,
6649ecb8875SAjay Kumar Gupta 	.iddig			= 8,
6659ecb8875SAjay Kumar Gupta 	.usb_shift		= 0,
6669ecb8875SAjay Kumar Gupta 	.usb_mask		= 0x1ff,
6679ecb8875SAjay Kumar Gupta 	.usb_bitmap		= (0x1ff << 0),
6689ecb8875SAjay Kumar Gupta 	.drvvbus		= 8,
6699ecb8875SAjay Kumar Gupta 	.txep_shift		= 0,
6709ecb8875SAjay Kumar Gupta 	.txep_mask		= 0xffff,
6719ecb8875SAjay Kumar Gupta 	.txep_bitmap		= (0xffff << 0),
6729ecb8875SAjay Kumar Gupta 	.rxep_shift		= 16,
6739ecb8875SAjay Kumar Gupta 	.rxep_mask		= 0xfffe,
6749ecb8875SAjay Kumar Gupta 	.rxep_bitmap		= (0xfffe << 16),
6759ecb8875SAjay Kumar Gupta 	.musb_core_offset	= 0x400,
6769ecb8875SAjay Kumar Gupta 	.poll_seconds		= 2,
6773b46dd76SAfzal Mohammed 	.instances		= 1,
6789ecb8875SAjay Kumar Gupta };
6799ecb8875SAjay Kumar Gupta 
6809ecb8875SAjay Kumar Gupta static const struct platform_device_id musb_dsps_id_table[] __devinitconst = {
6819ecb8875SAjay Kumar Gupta 	{
6829ecb8875SAjay Kumar Gupta 		.name	= "musb-ti81xx",
6839ecb8875SAjay Kumar Gupta 		.driver_data	= (kernel_ulong_t) &ti81xx_driver_data,
6849ecb8875SAjay Kumar Gupta 	},
6859ecb8875SAjay Kumar Gupta 	{  },	/* Terminating Entry */
6869ecb8875SAjay Kumar Gupta };
6879ecb8875SAjay Kumar Gupta MODULE_DEVICE_TABLE(platform, musb_dsps_id_table);
6889ecb8875SAjay Kumar Gupta 
68965145677SAjay Kumar Gupta #ifdef CONFIG_OF
6909ecb8875SAjay Kumar Gupta static const struct of_device_id musb_dsps_of_match[] __devinitconst = {
69165145677SAjay Kumar Gupta 	{ .compatible = "ti,musb-am33xx",
69265145677SAjay Kumar Gupta 		.data = (void *) &ti81xx_driver_data, },
6939ecb8875SAjay Kumar Gupta 	{  },
6949ecb8875SAjay Kumar Gupta };
6959ecb8875SAjay Kumar Gupta MODULE_DEVICE_TABLE(of, musb_dsps_of_match);
69665145677SAjay Kumar Gupta #endif
6979ecb8875SAjay Kumar Gupta 
6989ecb8875SAjay Kumar Gupta static struct platform_driver dsps_usbss_driver = {
6999ecb8875SAjay Kumar Gupta 	.probe		= dsps_probe,
7009ecb8875SAjay Kumar Gupta 	.remove         = __devexit_p(dsps_remove),
7019ecb8875SAjay Kumar Gupta 	.driver         = {
7029ecb8875SAjay Kumar Gupta 		.name   = "musb-dsps",
7039ecb8875SAjay Kumar Gupta 		.pm	= &dsps_pm_ops,
70465145677SAjay Kumar Gupta 		.of_match_table	= of_match_ptr(musb_dsps_of_match),
7059ecb8875SAjay Kumar Gupta 	},
7069ecb8875SAjay Kumar Gupta 	.id_table	= musb_dsps_id_table,
7079ecb8875SAjay Kumar Gupta };
7089ecb8875SAjay Kumar Gupta 
7099ecb8875SAjay Kumar Gupta MODULE_DESCRIPTION("TI DSPS MUSB Glue Layer");
7109ecb8875SAjay Kumar Gupta MODULE_AUTHOR("Ravi B <ravibabu@ti.com>");
7119ecb8875SAjay Kumar Gupta MODULE_AUTHOR("Ajay Kumar Gupta <ajay.gupta@ti.com>");
7129ecb8875SAjay Kumar Gupta MODULE_LICENSE("GPL v2");
7139ecb8875SAjay Kumar Gupta 
7149ecb8875SAjay Kumar Gupta static int __init dsps_init(void)
7159ecb8875SAjay Kumar Gupta {
7169ecb8875SAjay Kumar Gupta 	return platform_driver_register(&dsps_usbss_driver);
7179ecb8875SAjay Kumar Gupta }
7189ecb8875SAjay Kumar Gupta subsys_initcall(dsps_init);
7199ecb8875SAjay Kumar Gupta 
7209ecb8875SAjay Kumar Gupta static void __exit dsps_exit(void)
7219ecb8875SAjay Kumar Gupta {
7229ecb8875SAjay Kumar Gupta 	platform_driver_unregister(&dsps_usbss_driver);
7239ecb8875SAjay Kumar Gupta }
7249ecb8875SAjay Kumar Gupta module_exit(dsps_exit);
725