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> 34*65145677SAjay 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> 409ecb8875SAjay Kumar Gupta 419ecb8875SAjay Kumar Gupta #include <linux/of.h> 429ecb8875SAjay Kumar Gupta #include <linux/of_device.h> 439ecb8875SAjay Kumar Gupta #include <linux/of_address.h> 449ecb8875SAjay Kumar Gupta 459ecb8875SAjay Kumar Gupta #include <plat/usb.h> 469ecb8875SAjay Kumar Gupta 479ecb8875SAjay Kumar Gupta #include "musb_core.h" 489ecb8875SAjay Kumar Gupta 49*65145677SAjay Kumar Gupta #ifdef CONFIG_OF 50*65145677SAjay Kumar Gupta static const struct of_device_id musb_dsps_of_match[]; 51*65145677SAjay Kumar Gupta #endif 52*65145677SAjay Kumar Gupta 539ecb8875SAjay Kumar Gupta /** 549ecb8875SAjay Kumar Gupta * avoid using musb_readx()/musb_writex() as glue layer should not be 559ecb8875SAjay Kumar Gupta * dependent on musb core layer symbols. 569ecb8875SAjay Kumar Gupta */ 579ecb8875SAjay Kumar Gupta static inline u8 dsps_readb(const void __iomem *addr, unsigned offset) 589ecb8875SAjay Kumar Gupta { return __raw_readb(addr + offset); } 599ecb8875SAjay Kumar Gupta 609ecb8875SAjay Kumar Gupta static inline u32 dsps_readl(const void __iomem *addr, unsigned offset) 619ecb8875SAjay Kumar Gupta { return __raw_readl(addr + offset); } 629ecb8875SAjay Kumar Gupta 639ecb8875SAjay Kumar Gupta static inline void dsps_writeb(void __iomem *addr, unsigned offset, u8 data) 649ecb8875SAjay Kumar Gupta { __raw_writeb(data, addr + offset); } 659ecb8875SAjay Kumar Gupta 669ecb8875SAjay Kumar Gupta static inline void dsps_writel(void __iomem *addr, unsigned offset, u32 data) 679ecb8875SAjay Kumar Gupta { __raw_writel(data, addr + offset); } 689ecb8875SAjay Kumar Gupta 699ecb8875SAjay Kumar Gupta /** 709ecb8875SAjay Kumar Gupta * DSPS musb wrapper register offset. 719ecb8875SAjay Kumar Gupta * FIXME: This should be expanded to have all the wrapper registers from TI DSPS 729ecb8875SAjay Kumar Gupta * musb ips. 739ecb8875SAjay Kumar Gupta */ 749ecb8875SAjay Kumar Gupta struct dsps_musb_wrapper { 759ecb8875SAjay Kumar Gupta u16 revision; 769ecb8875SAjay Kumar Gupta u16 control; 779ecb8875SAjay Kumar Gupta u16 status; 789ecb8875SAjay Kumar Gupta u16 eoi; 799ecb8875SAjay Kumar Gupta u16 epintr_set; 809ecb8875SAjay Kumar Gupta u16 epintr_clear; 819ecb8875SAjay Kumar Gupta u16 epintr_status; 829ecb8875SAjay Kumar Gupta u16 coreintr_set; 839ecb8875SAjay Kumar Gupta u16 coreintr_clear; 849ecb8875SAjay Kumar Gupta u16 coreintr_status; 859ecb8875SAjay Kumar Gupta u16 phy_utmi; 869ecb8875SAjay Kumar Gupta u16 mode; 879ecb8875SAjay Kumar Gupta 889ecb8875SAjay Kumar Gupta /* bit positions for control */ 899ecb8875SAjay Kumar Gupta unsigned reset:5; 909ecb8875SAjay Kumar Gupta 919ecb8875SAjay Kumar Gupta /* bit positions for interrupt */ 929ecb8875SAjay Kumar Gupta unsigned usb_shift:5; 939ecb8875SAjay Kumar Gupta u32 usb_mask; 949ecb8875SAjay Kumar Gupta u32 usb_bitmap; 959ecb8875SAjay Kumar Gupta unsigned drvvbus:5; 969ecb8875SAjay Kumar Gupta 979ecb8875SAjay Kumar Gupta unsigned txep_shift:5; 989ecb8875SAjay Kumar Gupta u32 txep_mask; 999ecb8875SAjay Kumar Gupta u32 txep_bitmap; 1009ecb8875SAjay Kumar Gupta 1019ecb8875SAjay Kumar Gupta unsigned rxep_shift:5; 1029ecb8875SAjay Kumar Gupta u32 rxep_mask; 1039ecb8875SAjay Kumar Gupta u32 rxep_bitmap; 1049ecb8875SAjay Kumar Gupta 1059ecb8875SAjay Kumar Gupta /* bit positions for phy_utmi */ 1069ecb8875SAjay Kumar Gupta unsigned otg_disable:5; 1079ecb8875SAjay Kumar Gupta 1089ecb8875SAjay Kumar Gupta /* bit positions for mode */ 1099ecb8875SAjay Kumar Gupta unsigned iddig:5; 1109ecb8875SAjay Kumar Gupta /* miscellaneous stuff */ 1119ecb8875SAjay Kumar Gupta u32 musb_core_offset; 1129ecb8875SAjay Kumar Gupta u8 poll_seconds; 113db4a9320SB, Ravi /* number of musb instances */ 114db4a9320SB, Ravi u8 instances; 1159ecb8875SAjay Kumar Gupta }; 1169ecb8875SAjay Kumar Gupta 1179ecb8875SAjay Kumar Gupta /** 1189ecb8875SAjay Kumar Gupta * DSPS glue structure. 1199ecb8875SAjay Kumar Gupta */ 1209ecb8875SAjay Kumar Gupta struct dsps_glue { 1219ecb8875SAjay Kumar Gupta struct device *dev; 122db4a9320SB, Ravi struct platform_device *musb[2]; /* child musb pdev */ 1239ecb8875SAjay Kumar Gupta const struct dsps_musb_wrapper *wrp; /* wrapper register offsets */ 124db4a9320SB, Ravi struct timer_list timer[2]; /* otg_workaround timer */ 125db4a9320SB, Ravi unsigned long last_timer[2]; /* last timer data for each instance */ 1269ecb8875SAjay Kumar Gupta }; 1279ecb8875SAjay Kumar Gupta 1289ecb8875SAjay Kumar Gupta /** 1299ecb8875SAjay Kumar Gupta * dsps_musb_enable - enable interrupts 1309ecb8875SAjay Kumar Gupta */ 1319ecb8875SAjay Kumar Gupta static void dsps_musb_enable(struct musb *musb) 1329ecb8875SAjay Kumar Gupta { 1339ecb8875SAjay Kumar Gupta struct device *dev = musb->controller; 1349ecb8875SAjay Kumar Gupta struct platform_device *pdev = to_platform_device(dev->parent); 1359ecb8875SAjay Kumar Gupta struct dsps_glue *glue = platform_get_drvdata(pdev); 1369ecb8875SAjay Kumar Gupta const struct dsps_musb_wrapper *wrp = glue->wrp; 1379ecb8875SAjay Kumar Gupta void __iomem *reg_base = musb->ctrl_base; 1389ecb8875SAjay Kumar Gupta u32 epmask, coremask; 1399ecb8875SAjay Kumar Gupta 1409ecb8875SAjay Kumar Gupta /* Workaround: setup IRQs through both register sets. */ 1419ecb8875SAjay Kumar Gupta epmask = ((musb->epmask & wrp->txep_mask) << wrp->txep_shift) | 1429ecb8875SAjay Kumar Gupta ((musb->epmask & wrp->rxep_mask) << wrp->rxep_shift); 1439ecb8875SAjay Kumar Gupta coremask = (wrp->usb_bitmap & ~MUSB_INTR_SOF); 1449ecb8875SAjay Kumar Gupta 1459ecb8875SAjay Kumar Gupta dsps_writel(reg_base, wrp->epintr_set, epmask); 1469ecb8875SAjay Kumar Gupta dsps_writel(reg_base, wrp->coreintr_set, coremask); 1479ecb8875SAjay Kumar Gupta /* Force the DRVVBUS IRQ so we can start polling for ID change. */ 1489ecb8875SAjay Kumar Gupta dsps_writel(reg_base, wrp->coreintr_set, 1499ecb8875SAjay Kumar Gupta (1 << wrp->drvvbus) << wrp->usb_shift); 1509ecb8875SAjay Kumar Gupta } 1519ecb8875SAjay Kumar Gupta 1529ecb8875SAjay Kumar Gupta /** 1539ecb8875SAjay Kumar Gupta * dsps_musb_disable - disable HDRC and flush interrupts 1549ecb8875SAjay Kumar Gupta */ 1559ecb8875SAjay Kumar Gupta static void dsps_musb_disable(struct musb *musb) 1569ecb8875SAjay Kumar Gupta { 1579ecb8875SAjay Kumar Gupta struct device *dev = musb->controller; 1589ecb8875SAjay Kumar Gupta struct platform_device *pdev = to_platform_device(dev->parent); 1599ecb8875SAjay Kumar Gupta struct dsps_glue *glue = platform_get_drvdata(pdev); 1609ecb8875SAjay Kumar Gupta const struct dsps_musb_wrapper *wrp = glue->wrp; 1619ecb8875SAjay Kumar Gupta void __iomem *reg_base = musb->ctrl_base; 1629ecb8875SAjay Kumar Gupta 1639ecb8875SAjay Kumar Gupta dsps_writel(reg_base, wrp->coreintr_clear, wrp->usb_bitmap); 1649ecb8875SAjay Kumar Gupta dsps_writel(reg_base, wrp->epintr_clear, 1659ecb8875SAjay Kumar Gupta wrp->txep_bitmap | wrp->rxep_bitmap); 1669ecb8875SAjay Kumar Gupta dsps_writeb(musb->mregs, MUSB_DEVCTL, 0); 1679ecb8875SAjay Kumar Gupta dsps_writel(reg_base, wrp->eoi, 0); 1689ecb8875SAjay Kumar Gupta } 1699ecb8875SAjay Kumar Gupta 1709ecb8875SAjay Kumar Gupta static void otg_timer(unsigned long _musb) 1719ecb8875SAjay Kumar Gupta { 1729ecb8875SAjay Kumar Gupta struct musb *musb = (void *)_musb; 1739ecb8875SAjay Kumar Gupta void __iomem *mregs = musb->mregs; 1749ecb8875SAjay Kumar Gupta struct device *dev = musb->controller; 175db4a9320SB, Ravi struct platform_device *pdev = to_platform_device(dev); 176db4a9320SB, Ravi struct dsps_glue *glue = dev_get_drvdata(dev->parent); 1779ecb8875SAjay Kumar Gupta const struct dsps_musb_wrapper *wrp = glue->wrp; 1789ecb8875SAjay Kumar Gupta u8 devctl; 1799ecb8875SAjay Kumar Gupta unsigned long flags; 1809ecb8875SAjay Kumar Gupta 1819ecb8875SAjay Kumar Gupta /* 1829ecb8875SAjay Kumar Gupta * We poll because DSPS IP's won't expose several OTG-critical 1839ecb8875SAjay Kumar Gupta * status change events (from the transceiver) otherwise. 1849ecb8875SAjay Kumar Gupta */ 1859ecb8875SAjay Kumar Gupta devctl = dsps_readb(mregs, MUSB_DEVCTL); 1869ecb8875SAjay Kumar Gupta dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl, 1879ecb8875SAjay Kumar Gupta otg_state_string(musb->xceiv->state)); 1889ecb8875SAjay Kumar Gupta 1899ecb8875SAjay Kumar Gupta spin_lock_irqsave(&musb->lock, flags); 1909ecb8875SAjay Kumar Gupta switch (musb->xceiv->state) { 1919ecb8875SAjay Kumar Gupta case OTG_STATE_A_WAIT_BCON: 1929ecb8875SAjay Kumar Gupta devctl &= ~MUSB_DEVCTL_SESSION; 1939ecb8875SAjay Kumar Gupta dsps_writeb(musb->mregs, MUSB_DEVCTL, devctl); 1949ecb8875SAjay Kumar Gupta 1959ecb8875SAjay Kumar Gupta devctl = dsps_readb(musb->mregs, MUSB_DEVCTL); 1969ecb8875SAjay Kumar Gupta if (devctl & MUSB_DEVCTL_BDEVICE) { 1979ecb8875SAjay Kumar Gupta musb->xceiv->state = OTG_STATE_B_IDLE; 1989ecb8875SAjay Kumar Gupta MUSB_DEV_MODE(musb); 1999ecb8875SAjay Kumar Gupta } else { 2009ecb8875SAjay Kumar Gupta musb->xceiv->state = OTG_STATE_A_IDLE; 2019ecb8875SAjay Kumar Gupta MUSB_HST_MODE(musb); 2029ecb8875SAjay Kumar Gupta } 2039ecb8875SAjay Kumar Gupta break; 2049ecb8875SAjay Kumar Gupta case OTG_STATE_A_WAIT_VFALL: 2059ecb8875SAjay Kumar Gupta musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; 2069ecb8875SAjay Kumar Gupta dsps_writel(musb->ctrl_base, wrp->coreintr_set, 2079ecb8875SAjay Kumar Gupta MUSB_INTR_VBUSERROR << wrp->usb_shift); 2089ecb8875SAjay Kumar Gupta break; 2099ecb8875SAjay Kumar Gupta case OTG_STATE_B_IDLE: 2109ecb8875SAjay Kumar Gupta devctl = dsps_readb(mregs, MUSB_DEVCTL); 2119ecb8875SAjay Kumar Gupta if (devctl & MUSB_DEVCTL_BDEVICE) 212db4a9320SB, Ravi mod_timer(&glue->timer[pdev->id], 2139ecb8875SAjay Kumar Gupta jiffies + wrp->poll_seconds * HZ); 2149ecb8875SAjay Kumar Gupta else 2159ecb8875SAjay Kumar Gupta musb->xceiv->state = OTG_STATE_A_IDLE; 2169ecb8875SAjay Kumar Gupta break; 2179ecb8875SAjay Kumar Gupta default: 2189ecb8875SAjay Kumar Gupta break; 2199ecb8875SAjay Kumar Gupta } 2209ecb8875SAjay Kumar Gupta spin_unlock_irqrestore(&musb->lock, flags); 2219ecb8875SAjay Kumar Gupta } 2229ecb8875SAjay Kumar Gupta 2239ecb8875SAjay Kumar Gupta static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout) 2249ecb8875SAjay Kumar Gupta { 2259ecb8875SAjay Kumar Gupta struct device *dev = musb->controller; 226db4a9320SB, Ravi struct platform_device *pdev = to_platform_device(dev); 227db4a9320SB, Ravi struct dsps_glue *glue = dev_get_drvdata(dev->parent); 2289ecb8875SAjay Kumar Gupta 2299ecb8875SAjay Kumar Gupta if (timeout == 0) 2309ecb8875SAjay Kumar Gupta timeout = jiffies + msecs_to_jiffies(3); 2319ecb8875SAjay Kumar Gupta 2329ecb8875SAjay Kumar Gupta /* Never idle if active, or when VBUS timeout is not set as host */ 2339ecb8875SAjay Kumar Gupta if (musb->is_active || (musb->a_wait_bcon == 0 && 2349ecb8875SAjay Kumar Gupta musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) { 2359ecb8875SAjay Kumar Gupta dev_dbg(musb->controller, "%s active, deleting timer\n", 2369ecb8875SAjay Kumar Gupta otg_state_string(musb->xceiv->state)); 237db4a9320SB, Ravi del_timer(&glue->timer[pdev->id]); 238db4a9320SB, Ravi glue->last_timer[pdev->id] = jiffies; 2399ecb8875SAjay Kumar Gupta return; 2409ecb8875SAjay Kumar Gupta } 2419ecb8875SAjay Kumar Gupta 242db4a9320SB, Ravi if (time_after(glue->last_timer[pdev->id], timeout) && 243db4a9320SB, Ravi timer_pending(&glue->timer[pdev->id])) { 2449ecb8875SAjay Kumar Gupta dev_dbg(musb->controller, 2459ecb8875SAjay Kumar Gupta "Longer idle timer already pending, ignoring...\n"); 2469ecb8875SAjay Kumar Gupta return; 2479ecb8875SAjay Kumar Gupta } 248db4a9320SB, Ravi glue->last_timer[pdev->id] = timeout; 2499ecb8875SAjay Kumar Gupta 2509ecb8875SAjay Kumar Gupta dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", 2519ecb8875SAjay Kumar Gupta otg_state_string(musb->xceiv->state), 2529ecb8875SAjay Kumar Gupta jiffies_to_msecs(timeout - jiffies)); 253db4a9320SB, Ravi mod_timer(&glue->timer[pdev->id], timeout); 2549ecb8875SAjay Kumar Gupta } 2559ecb8875SAjay Kumar Gupta 2569ecb8875SAjay Kumar Gupta static irqreturn_t dsps_interrupt(int irq, void *hci) 2579ecb8875SAjay Kumar Gupta { 2589ecb8875SAjay Kumar Gupta struct musb *musb = hci; 2599ecb8875SAjay Kumar Gupta void __iomem *reg_base = musb->ctrl_base; 2609ecb8875SAjay Kumar Gupta struct device *dev = musb->controller; 261db4a9320SB, Ravi struct platform_device *pdev = to_platform_device(dev); 262db4a9320SB, Ravi struct dsps_glue *glue = dev_get_drvdata(dev->parent); 2639ecb8875SAjay Kumar Gupta const struct dsps_musb_wrapper *wrp = glue->wrp; 2649ecb8875SAjay Kumar Gupta unsigned long flags; 2659ecb8875SAjay Kumar Gupta irqreturn_t ret = IRQ_NONE; 2669ecb8875SAjay Kumar Gupta u32 epintr, usbintr; 2679ecb8875SAjay Kumar Gupta 2689ecb8875SAjay Kumar Gupta spin_lock_irqsave(&musb->lock, flags); 2699ecb8875SAjay Kumar Gupta 2709ecb8875SAjay Kumar Gupta /* Get endpoint interrupts */ 2719ecb8875SAjay Kumar Gupta epintr = dsps_readl(reg_base, wrp->epintr_status); 2729ecb8875SAjay Kumar Gupta musb->int_rx = (epintr & wrp->rxep_bitmap) >> wrp->rxep_shift; 2739ecb8875SAjay Kumar Gupta musb->int_tx = (epintr & wrp->txep_bitmap) >> wrp->txep_shift; 2749ecb8875SAjay Kumar Gupta 2759ecb8875SAjay Kumar Gupta if (epintr) 2769ecb8875SAjay Kumar Gupta dsps_writel(reg_base, wrp->epintr_status, epintr); 2779ecb8875SAjay Kumar Gupta 2789ecb8875SAjay Kumar Gupta /* Get usb core interrupts */ 2799ecb8875SAjay Kumar Gupta usbintr = dsps_readl(reg_base, wrp->coreintr_status); 2809ecb8875SAjay Kumar Gupta if (!usbintr && !epintr) 2819ecb8875SAjay Kumar Gupta goto eoi; 2829ecb8875SAjay Kumar Gupta 2839ecb8875SAjay Kumar Gupta musb->int_usb = (usbintr & wrp->usb_bitmap) >> wrp->usb_shift; 2849ecb8875SAjay Kumar Gupta if (usbintr) 2859ecb8875SAjay Kumar Gupta dsps_writel(reg_base, wrp->coreintr_status, usbintr); 2869ecb8875SAjay Kumar Gupta 2879ecb8875SAjay Kumar Gupta dev_dbg(musb->controller, "usbintr (%x) epintr(%x)\n", 2889ecb8875SAjay Kumar Gupta usbintr, epintr); 2899ecb8875SAjay Kumar Gupta /* 2909ecb8875SAjay Kumar Gupta * DRVVBUS IRQs are the only proxy we have (a very poor one!) for 2919ecb8875SAjay Kumar Gupta * DSPS IP's missing ID change IRQ. We need an ID change IRQ to 2929ecb8875SAjay Kumar Gupta * switch appropriately between halves of the OTG state machine. 2939ecb8875SAjay Kumar Gupta * Managing DEVCTL.SESSION per Mentor docs requires that we know its 2949ecb8875SAjay Kumar Gupta * value but DEVCTL.BDEVICE is invalid without DEVCTL.SESSION set. 2959ecb8875SAjay Kumar Gupta * Also, DRVVBUS pulses for SRP (but not at 5V) ... 2969ecb8875SAjay Kumar Gupta */ 297032ec49fSFelipe Balbi if (usbintr & MUSB_INTR_BABBLE) 2989ecb8875SAjay Kumar Gupta pr_info("CAUTION: musb: Babble Interrupt Occured\n"); 2999ecb8875SAjay Kumar Gupta 3009ecb8875SAjay Kumar Gupta if (usbintr & ((1 << wrp->drvvbus) << wrp->usb_shift)) { 3019ecb8875SAjay Kumar Gupta int drvvbus = dsps_readl(reg_base, wrp->status); 3029ecb8875SAjay Kumar Gupta void __iomem *mregs = musb->mregs; 3039ecb8875SAjay Kumar Gupta u8 devctl = dsps_readb(mregs, MUSB_DEVCTL); 3049ecb8875SAjay Kumar Gupta int err; 3059ecb8875SAjay Kumar Gupta 306032ec49fSFelipe Balbi err = musb->int_usb & MUSB_INTR_VBUSERROR; 3079ecb8875SAjay Kumar Gupta if (err) { 3089ecb8875SAjay Kumar Gupta /* 3099ecb8875SAjay Kumar Gupta * The Mentor core doesn't debounce VBUS as needed 3109ecb8875SAjay Kumar Gupta * to cope with device connect current spikes. This 3119ecb8875SAjay Kumar Gupta * means it's not uncommon for bus-powered devices 3129ecb8875SAjay Kumar Gupta * to get VBUS errors during enumeration. 3139ecb8875SAjay Kumar Gupta * 3149ecb8875SAjay Kumar Gupta * This is a workaround, but newer RTL from Mentor 3159ecb8875SAjay Kumar Gupta * seems to allow a better one: "re"-starting sessions 3169ecb8875SAjay Kumar Gupta * without waiting for VBUS to stop registering in 3179ecb8875SAjay Kumar Gupta * devctl. 3189ecb8875SAjay Kumar Gupta */ 3199ecb8875SAjay Kumar Gupta musb->int_usb &= ~MUSB_INTR_VBUSERROR; 3209ecb8875SAjay Kumar Gupta musb->xceiv->state = OTG_STATE_A_WAIT_VFALL; 321db4a9320SB, Ravi mod_timer(&glue->timer[pdev->id], 3229ecb8875SAjay Kumar Gupta jiffies + wrp->poll_seconds * HZ); 3239ecb8875SAjay Kumar Gupta WARNING("VBUS error workaround (delay coming)\n"); 324032ec49fSFelipe Balbi } else if (drvvbus) { 3259ecb8875SAjay Kumar Gupta musb->is_active = 1; 3269ecb8875SAjay Kumar Gupta MUSB_HST_MODE(musb); 3279ecb8875SAjay Kumar Gupta musb->xceiv->otg->default_a = 1; 3289ecb8875SAjay Kumar Gupta musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; 329db4a9320SB, Ravi del_timer(&glue->timer[pdev->id]); 3309ecb8875SAjay Kumar Gupta } else { 3319ecb8875SAjay Kumar Gupta musb->is_active = 0; 3329ecb8875SAjay Kumar Gupta MUSB_DEV_MODE(musb); 3339ecb8875SAjay Kumar Gupta musb->xceiv->otg->default_a = 0; 3349ecb8875SAjay Kumar Gupta musb->xceiv->state = OTG_STATE_B_IDLE; 3359ecb8875SAjay Kumar Gupta } 3369ecb8875SAjay Kumar Gupta 3379ecb8875SAjay Kumar Gupta /* NOTE: this must complete power-on within 100 ms. */ 3389ecb8875SAjay Kumar Gupta dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", 3399ecb8875SAjay Kumar Gupta drvvbus ? "on" : "off", 3409ecb8875SAjay Kumar Gupta otg_state_string(musb->xceiv->state), 3419ecb8875SAjay Kumar Gupta err ? " ERROR" : "", 3429ecb8875SAjay Kumar Gupta devctl); 3439ecb8875SAjay Kumar Gupta ret = IRQ_HANDLED; 3449ecb8875SAjay Kumar Gupta } 3459ecb8875SAjay Kumar Gupta 3469ecb8875SAjay Kumar Gupta if (musb->int_tx || musb->int_rx || musb->int_usb) 3479ecb8875SAjay Kumar Gupta ret |= musb_interrupt(musb); 3489ecb8875SAjay Kumar Gupta 3499ecb8875SAjay Kumar Gupta eoi: 3509ecb8875SAjay Kumar Gupta /* EOI needs to be written for the IRQ to be re-asserted. */ 3519ecb8875SAjay Kumar Gupta if (ret == IRQ_HANDLED || epintr || usbintr) 3529ecb8875SAjay Kumar Gupta dsps_writel(reg_base, wrp->eoi, 1); 3539ecb8875SAjay Kumar Gupta 3549ecb8875SAjay Kumar Gupta /* Poll for ID change */ 355032ec49fSFelipe Balbi if (musb->xceiv->state == OTG_STATE_B_IDLE) 356db4a9320SB, Ravi mod_timer(&glue->timer[pdev->id], 357db4a9320SB, Ravi jiffies + wrp->poll_seconds * HZ); 3589ecb8875SAjay Kumar Gupta 3599ecb8875SAjay Kumar Gupta spin_unlock_irqrestore(&musb->lock, flags); 3609ecb8875SAjay Kumar Gupta 3619ecb8875SAjay Kumar Gupta return ret; 3629ecb8875SAjay Kumar Gupta } 3639ecb8875SAjay Kumar Gupta 3649ecb8875SAjay Kumar Gupta static int dsps_musb_init(struct musb *musb) 3659ecb8875SAjay Kumar Gupta { 3669ecb8875SAjay Kumar Gupta struct device *dev = musb->controller; 3679ecb8875SAjay Kumar Gupta struct musb_hdrc_platform_data *plat = dev->platform_data; 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 struct omap_musb_board_data *data = plat->board_data; 3729ecb8875SAjay Kumar Gupta void __iomem *reg_base = musb->ctrl_base; 3739ecb8875SAjay Kumar Gupta u32 rev, val; 3749ecb8875SAjay Kumar Gupta int status; 3759ecb8875SAjay Kumar Gupta 3769ecb8875SAjay Kumar Gupta /* mentor core register starts at offset of 0x400 from musb base */ 3779ecb8875SAjay Kumar Gupta musb->mregs += wrp->musb_core_offset; 3789ecb8875SAjay Kumar Gupta 3799ecb8875SAjay Kumar Gupta /* NOP driver needs change if supporting dual instance */ 3809ecb8875SAjay Kumar Gupta usb_nop_xceiv_register(); 381662dca54SKishon Vijay Abraham I musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); 382ded017eeSKishon Vijay Abraham I if (IS_ERR_OR_NULL(musb->xceiv)) 3839ecb8875SAjay Kumar Gupta return -ENODEV; 3849ecb8875SAjay Kumar Gupta 3859ecb8875SAjay Kumar Gupta /* Returns zero if e.g. not clocked */ 3869ecb8875SAjay Kumar Gupta rev = dsps_readl(reg_base, wrp->revision); 3879ecb8875SAjay Kumar Gupta if (!rev) { 3889ecb8875SAjay Kumar Gupta status = -ENODEV; 3899ecb8875SAjay Kumar Gupta goto err0; 3909ecb8875SAjay Kumar Gupta } 3919ecb8875SAjay Kumar Gupta 392db4a9320SB, Ravi setup_timer(&glue->timer[pdev->id], otg_timer, (unsigned long) musb); 3939ecb8875SAjay Kumar Gupta 3949ecb8875SAjay Kumar Gupta /* Reset the musb */ 3959ecb8875SAjay Kumar Gupta dsps_writel(reg_base, wrp->control, (1 << wrp->reset)); 3969ecb8875SAjay Kumar Gupta 3979ecb8875SAjay Kumar Gupta /* Start the on-chip PHY and its PLL. */ 3989ecb8875SAjay Kumar Gupta if (data->set_phy_power) 3999ecb8875SAjay Kumar Gupta data->set_phy_power(1); 4009ecb8875SAjay Kumar Gupta 4019ecb8875SAjay Kumar Gupta musb->isr = dsps_interrupt; 4029ecb8875SAjay Kumar Gupta 4039ecb8875SAjay Kumar Gupta /* reset the otgdisable bit, needed for host mode to work */ 4049ecb8875SAjay Kumar Gupta val = dsps_readl(reg_base, wrp->phy_utmi); 4059ecb8875SAjay Kumar Gupta val &= ~(1 << wrp->otg_disable); 4069ecb8875SAjay Kumar Gupta dsps_writel(musb->ctrl_base, wrp->phy_utmi, val); 4079ecb8875SAjay Kumar Gupta 4089ecb8875SAjay Kumar Gupta /* clear level interrupt */ 4099ecb8875SAjay Kumar Gupta dsps_writel(reg_base, wrp->eoi, 0); 4109ecb8875SAjay Kumar Gupta 4119ecb8875SAjay Kumar Gupta return 0; 4129ecb8875SAjay Kumar Gupta err0: 413721002ecSKishon Vijay Abraham I usb_put_phy(musb->xceiv); 4149ecb8875SAjay Kumar Gupta usb_nop_xceiv_unregister(); 4159ecb8875SAjay Kumar Gupta return status; 4169ecb8875SAjay Kumar Gupta } 4179ecb8875SAjay Kumar Gupta 4189ecb8875SAjay Kumar Gupta static int dsps_musb_exit(struct musb *musb) 4199ecb8875SAjay Kumar Gupta { 4209ecb8875SAjay Kumar Gupta struct device *dev = musb->controller; 4219ecb8875SAjay Kumar Gupta struct musb_hdrc_platform_data *plat = dev->platform_data; 4229ecb8875SAjay Kumar Gupta struct omap_musb_board_data *data = plat->board_data; 423db4a9320SB, Ravi struct platform_device *pdev = to_platform_device(dev); 424db4a9320SB, Ravi struct dsps_glue *glue = dev_get_drvdata(dev->parent); 4259ecb8875SAjay Kumar Gupta 426db4a9320SB, Ravi del_timer_sync(&glue->timer[pdev->id]); 4279ecb8875SAjay Kumar Gupta 4289ecb8875SAjay Kumar Gupta /* Shutdown the on-chip PHY and its PLL. */ 4299ecb8875SAjay Kumar Gupta if (data->set_phy_power) 4309ecb8875SAjay Kumar Gupta data->set_phy_power(0); 4319ecb8875SAjay Kumar Gupta 4329ecb8875SAjay Kumar Gupta /* NOP driver needs change if supporting dual instance */ 433721002ecSKishon Vijay Abraham I usb_put_phy(musb->xceiv); 4349ecb8875SAjay Kumar Gupta usb_nop_xceiv_unregister(); 4359ecb8875SAjay Kumar Gupta 4369ecb8875SAjay Kumar Gupta return 0; 4379ecb8875SAjay Kumar Gupta } 4389ecb8875SAjay Kumar Gupta 4399ecb8875SAjay Kumar Gupta static struct musb_platform_ops dsps_ops = { 4409ecb8875SAjay Kumar Gupta .init = dsps_musb_init, 4419ecb8875SAjay Kumar Gupta .exit = dsps_musb_exit, 4429ecb8875SAjay Kumar Gupta 4439ecb8875SAjay Kumar Gupta .enable = dsps_musb_enable, 4449ecb8875SAjay Kumar Gupta .disable = dsps_musb_disable, 4459ecb8875SAjay Kumar Gupta 4469ecb8875SAjay Kumar Gupta .try_idle = dsps_musb_try_idle, 4479ecb8875SAjay Kumar Gupta }; 4489ecb8875SAjay Kumar Gupta 4499ecb8875SAjay Kumar Gupta static u64 musb_dmamask = DMA_BIT_MASK(32); 4509ecb8875SAjay Kumar Gupta 4519ecb8875SAjay Kumar Gupta static int __devinit dsps_create_musb_pdev(struct dsps_glue *glue, u8 id) 4529ecb8875SAjay Kumar Gupta { 4539ecb8875SAjay Kumar Gupta struct device *dev = glue->dev; 4549ecb8875SAjay Kumar Gupta struct platform_device *pdev = to_platform_device(dev); 4559ecb8875SAjay Kumar Gupta struct musb_hdrc_platform_data *pdata = dev->platform_data; 456*65145677SAjay Kumar Gupta struct device_node *np = pdev->dev.of_node; 457*65145677SAjay Kumar Gupta struct musb_hdrc_config *config; 4589ecb8875SAjay Kumar Gupta struct platform_device *musb; 4599ecb8875SAjay Kumar Gupta struct resource *res; 4609ecb8875SAjay Kumar Gupta struct resource resources[2]; 4619ecb8875SAjay Kumar Gupta char res_name[10]; 46265b3d52dSB, Ravi int ret, musbid; 4639ecb8875SAjay Kumar Gupta 4649ecb8875SAjay Kumar Gupta /* get memory resource */ 4659ecb8875SAjay Kumar Gupta sprintf(res_name, "musb%d", id); 4669ecb8875SAjay Kumar Gupta res = platform_get_resource_byname(pdev, IORESOURCE_MEM, res_name); 4679ecb8875SAjay Kumar Gupta if (!res) { 4689ecb8875SAjay Kumar Gupta dev_err(dev, "%s get mem resource failed\n", res_name); 4699ecb8875SAjay Kumar Gupta ret = -ENODEV; 4709ecb8875SAjay Kumar Gupta goto err0; 4719ecb8875SAjay Kumar Gupta } 4729ecb8875SAjay Kumar Gupta res->parent = NULL; 4739ecb8875SAjay Kumar Gupta resources[0] = *res; 4749ecb8875SAjay Kumar Gupta 4759ecb8875SAjay Kumar Gupta /* get irq resource */ 4769ecb8875SAjay Kumar Gupta sprintf(res_name, "musb%d-irq", id); 4779ecb8875SAjay Kumar Gupta res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, res_name); 4789ecb8875SAjay Kumar Gupta if (!res) { 4799ecb8875SAjay Kumar Gupta dev_err(dev, "%s get irq resource failed\n", res_name); 4809ecb8875SAjay Kumar Gupta ret = -ENODEV; 4819ecb8875SAjay Kumar Gupta goto err0; 4829ecb8875SAjay Kumar Gupta } 4839ecb8875SAjay Kumar Gupta strcpy((u8 *)res->name, "mc"); 4849ecb8875SAjay Kumar Gupta res->parent = NULL; 4859ecb8875SAjay Kumar Gupta resources[1] = *res; 4869ecb8875SAjay Kumar Gupta 48765b3d52dSB, Ravi /* get the musb id */ 48865b3d52dSB, Ravi musbid = musb_get_id(dev, GFP_KERNEL); 48965b3d52dSB, Ravi if (musbid < 0) { 49065b3d52dSB, Ravi dev_err(dev, "failed to allocate musb id\n"); 4919ecb8875SAjay Kumar Gupta ret = -ENOMEM; 4929ecb8875SAjay Kumar Gupta goto err0; 4939ecb8875SAjay Kumar Gupta } 49465b3d52dSB, Ravi /* allocate the child platform device */ 49565b3d52dSB, Ravi musb = platform_device_alloc("musb-hdrc", musbid); 49665b3d52dSB, Ravi if (!musb) { 49765b3d52dSB, Ravi dev_err(dev, "failed to allocate musb device\n"); 49865b3d52dSB, Ravi ret = -ENOMEM; 49965b3d52dSB, Ravi goto err1; 50065b3d52dSB, Ravi } 5019ecb8875SAjay Kumar Gupta 50265b3d52dSB, Ravi musb->id = musbid; 5039ecb8875SAjay Kumar Gupta musb->dev.parent = dev; 5049ecb8875SAjay Kumar Gupta musb->dev.dma_mask = &musb_dmamask; 5059ecb8875SAjay Kumar Gupta musb->dev.coherent_dma_mask = musb_dmamask; 5069ecb8875SAjay Kumar Gupta 507db4a9320SB, Ravi glue->musb[id] = musb; 5089ecb8875SAjay Kumar Gupta 5099ecb8875SAjay Kumar Gupta ret = platform_device_add_resources(musb, resources, 2); 5109ecb8875SAjay Kumar Gupta if (ret) { 5119ecb8875SAjay Kumar Gupta dev_err(dev, "failed to add resources\n"); 51265b3d52dSB, Ravi goto err2; 5139ecb8875SAjay Kumar Gupta } 5149ecb8875SAjay Kumar Gupta 515*65145677SAjay Kumar Gupta if (np) { 516*65145677SAjay Kumar Gupta pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 517*65145677SAjay Kumar Gupta if (!pdata) { 518*65145677SAjay Kumar Gupta dev_err(&pdev->dev, 519*65145677SAjay Kumar Gupta "failed to allocate musb platfrom data\n"); 520*65145677SAjay Kumar Gupta ret = -ENOMEM; 521*65145677SAjay Kumar Gupta goto err2; 522*65145677SAjay Kumar Gupta } 523*65145677SAjay Kumar Gupta 524*65145677SAjay Kumar Gupta config = devm_kzalloc(&pdev->dev, sizeof(*config), GFP_KERNEL); 525*65145677SAjay Kumar Gupta if (!config) { 526*65145677SAjay Kumar Gupta dev_err(&pdev->dev, 527*65145677SAjay Kumar Gupta "failed to allocate musb hdrc config\n"); 528*65145677SAjay Kumar Gupta goto err2; 529*65145677SAjay Kumar Gupta } 530*65145677SAjay Kumar Gupta 531*65145677SAjay Kumar Gupta of_property_read_u32(np, "num-eps", (u32 *)&config->num_eps); 532*65145677SAjay Kumar Gupta of_property_read_u32(np, "ram-bits", (u32 *)&config->ram_bits); 533*65145677SAjay Kumar Gupta sprintf(res_name, "port%d-mode", id); 534*65145677SAjay Kumar Gupta of_property_read_u32(np, res_name, (u32 *)&pdata->mode); 535*65145677SAjay Kumar Gupta of_property_read_u32(np, "power", (u32 *)&pdata->power); 536*65145677SAjay Kumar Gupta config->multipoint = of_property_read_bool(np, "multipoint"); 537*65145677SAjay Kumar Gupta 538*65145677SAjay Kumar Gupta pdata->config = config; 539*65145677SAjay Kumar Gupta } 540*65145677SAjay Kumar Gupta 541*65145677SAjay Kumar Gupta pdata->platform_ops = &dsps_ops; 542*65145677SAjay Kumar Gupta 5439ecb8875SAjay Kumar Gupta ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 5449ecb8875SAjay Kumar Gupta if (ret) { 5459ecb8875SAjay Kumar Gupta dev_err(dev, "failed to add platform_data\n"); 54665b3d52dSB, Ravi goto err2; 5479ecb8875SAjay Kumar Gupta } 5489ecb8875SAjay Kumar Gupta 5499ecb8875SAjay Kumar Gupta ret = platform_device_add(musb); 5509ecb8875SAjay Kumar Gupta if (ret) { 5519ecb8875SAjay Kumar Gupta dev_err(dev, "failed to register musb device\n"); 55265b3d52dSB, Ravi goto err2; 5539ecb8875SAjay Kumar Gupta } 5549ecb8875SAjay Kumar Gupta 5559ecb8875SAjay Kumar Gupta return 0; 5569ecb8875SAjay Kumar Gupta 55765b3d52dSB, Ravi err2: 5589ecb8875SAjay Kumar Gupta platform_device_put(musb); 55965b3d52dSB, Ravi err1: 56065b3d52dSB, Ravi musb_put_id(dev, musbid); 5619ecb8875SAjay Kumar Gupta err0: 5629ecb8875SAjay Kumar Gupta return ret; 5639ecb8875SAjay Kumar Gupta } 5649ecb8875SAjay Kumar Gupta 565db4a9320SB, Ravi static void dsps_delete_musb_pdev(struct dsps_glue *glue, u8 id) 5669ecb8875SAjay Kumar Gupta { 567db4a9320SB, Ravi musb_put_id(glue->dev, glue->musb[id]->id); 568db4a9320SB, Ravi platform_device_del(glue->musb[id]); 569db4a9320SB, Ravi platform_device_put(glue->musb[id]); 5709ecb8875SAjay Kumar Gupta } 5719ecb8875SAjay Kumar Gupta 5729ecb8875SAjay Kumar Gupta static int __devinit dsps_probe(struct platform_device *pdev) 5739ecb8875SAjay Kumar Gupta { 574*65145677SAjay Kumar Gupta struct device_node *np = pdev->dev.of_node; 575*65145677SAjay Kumar Gupta const struct of_device_id *match; 576*65145677SAjay Kumar Gupta const struct dsps_musb_wrapper *wrp; 5779ecb8875SAjay Kumar Gupta struct dsps_glue *glue; 5789ecb8875SAjay Kumar Gupta struct resource *iomem; 579db4a9320SB, Ravi int ret, i; 5809ecb8875SAjay Kumar Gupta 581*65145677SAjay Kumar Gupta match = of_match_node(musb_dsps_of_match, np); 582*65145677SAjay Kumar Gupta if (!match) { 583*65145677SAjay Kumar Gupta dev_err(&pdev->dev, "fail to get matching of_match struct\n"); 584*65145677SAjay Kumar Gupta ret = -EINVAL; 585*65145677SAjay Kumar Gupta goto err0; 586*65145677SAjay Kumar Gupta } 587*65145677SAjay Kumar Gupta wrp = match->data; 588*65145677SAjay Kumar Gupta 5899ecb8875SAjay Kumar Gupta /* allocate glue */ 5909ecb8875SAjay Kumar Gupta glue = kzalloc(sizeof(*glue), GFP_KERNEL); 5919ecb8875SAjay Kumar Gupta if (!glue) { 5929ecb8875SAjay Kumar Gupta dev_err(&pdev->dev, "unable to allocate glue memory\n"); 5939ecb8875SAjay Kumar Gupta ret = -ENOMEM; 5949ecb8875SAjay Kumar Gupta goto err0; 5959ecb8875SAjay Kumar Gupta } 5969ecb8875SAjay Kumar Gupta 5979ecb8875SAjay Kumar Gupta /* get memory resource */ 5989ecb8875SAjay Kumar Gupta iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 5999ecb8875SAjay Kumar Gupta if (!iomem) { 6009ecb8875SAjay Kumar Gupta dev_err(&pdev->dev, "failed to get usbss mem resourse\n"); 6019ecb8875SAjay Kumar Gupta ret = -ENODEV; 6029ecb8875SAjay Kumar Gupta goto err1; 6039ecb8875SAjay Kumar Gupta } 6049ecb8875SAjay Kumar Gupta 6059ecb8875SAjay Kumar Gupta glue->dev = &pdev->dev; 6069ecb8875SAjay Kumar Gupta 6079ecb8875SAjay Kumar Gupta glue->wrp = kmemdup(wrp, sizeof(*wrp), GFP_KERNEL); 6089ecb8875SAjay Kumar Gupta if (!glue->wrp) { 6099ecb8875SAjay Kumar Gupta dev_err(&pdev->dev, "failed to duplicate wrapper struct memory\n"); 6109ecb8875SAjay Kumar Gupta ret = -ENOMEM; 6119ecb8875SAjay Kumar Gupta goto err1; 6129ecb8875SAjay Kumar Gupta } 6139ecb8875SAjay Kumar Gupta platform_set_drvdata(pdev, glue); 6149ecb8875SAjay Kumar Gupta 6159ecb8875SAjay Kumar Gupta /* create the child platform device for first instances of musb */ 6169ecb8875SAjay Kumar Gupta ret = dsps_create_musb_pdev(glue, 0); 6179ecb8875SAjay Kumar Gupta if (ret != 0) { 6189ecb8875SAjay Kumar Gupta dev_err(&pdev->dev, "failed to create child pdev\n"); 6199ecb8875SAjay Kumar Gupta goto err2; 6209ecb8875SAjay Kumar Gupta } 6219ecb8875SAjay Kumar Gupta 6229ecb8875SAjay Kumar Gupta /* enable the usbss clocks */ 6239ecb8875SAjay Kumar Gupta pm_runtime_enable(&pdev->dev); 6249ecb8875SAjay Kumar Gupta 6259ecb8875SAjay Kumar Gupta ret = pm_runtime_get_sync(&pdev->dev); 6269ecb8875SAjay Kumar Gupta if (ret < 0) { 6279ecb8875SAjay Kumar Gupta dev_err(&pdev->dev, "pm_runtime_get_sync FAILED"); 628db4a9320SB, Ravi /* create the child platform device for all instances of musb */ 629db4a9320SB, Ravi for (i = 0; i < wrp->instances ; i++) { 630db4a9320SB, Ravi ret = dsps_create_musb_pdev(glue, i); 631db4a9320SB, Ravi if (ret != 0) { 632db4a9320SB, Ravi dev_err(&pdev->dev, "failed to create child pdev\n"); 633db4a9320SB, Ravi /* release resources of previously created instances */ 634db4a9320SB, Ravi for (i--; i >= 0 ; i--) 635db4a9320SB, Ravi dsps_delete_musb_pdev(glue, i); 6369ecb8875SAjay Kumar Gupta goto err3; 6379ecb8875SAjay Kumar Gupta } 638db4a9320SB, Ravi } 6399ecb8875SAjay Kumar Gupta 6409ecb8875SAjay Kumar Gupta return 0; 6419ecb8875SAjay Kumar Gupta 6429ecb8875SAjay Kumar Gupta err3: 6439ecb8875SAjay Kumar Gupta pm_runtime_disable(&pdev->dev); 6449ecb8875SAjay Kumar Gupta err2: 6459ecb8875SAjay Kumar Gupta kfree(glue->wrp); 6469ecb8875SAjay Kumar Gupta err1: 6479ecb8875SAjay Kumar Gupta kfree(glue); 6489ecb8875SAjay Kumar Gupta err0: 6499ecb8875SAjay Kumar Gupta return ret; 6509ecb8875SAjay Kumar Gupta } 6519ecb8875SAjay Kumar Gupta static int __devexit dsps_remove(struct platform_device *pdev) 6529ecb8875SAjay Kumar Gupta { 6539ecb8875SAjay Kumar Gupta struct dsps_glue *glue = platform_get_drvdata(pdev); 654db4a9320SB, Ravi const struct dsps_musb_wrapper *wrp = glue->wrp; 655db4a9320SB, Ravi int i; 6569ecb8875SAjay Kumar Gupta 6579ecb8875SAjay Kumar Gupta /* delete the child platform device */ 658db4a9320SB, Ravi for (i = 0; i < wrp->instances ; i++) 659db4a9320SB, Ravi dsps_delete_musb_pdev(glue, i); 6609ecb8875SAjay Kumar Gupta 6619ecb8875SAjay Kumar Gupta /* disable usbss clocks */ 6629ecb8875SAjay Kumar Gupta pm_runtime_put(&pdev->dev); 6639ecb8875SAjay Kumar Gupta pm_runtime_disable(&pdev->dev); 6649ecb8875SAjay Kumar Gupta kfree(glue->wrp); 6659ecb8875SAjay Kumar Gupta kfree(glue); 6669ecb8875SAjay Kumar Gupta return 0; 6679ecb8875SAjay Kumar Gupta } 6689ecb8875SAjay Kumar Gupta 6699ecb8875SAjay Kumar Gupta #ifdef CONFIG_PM_SLEEP 6709ecb8875SAjay Kumar Gupta static int dsps_suspend(struct device *dev) 6719ecb8875SAjay Kumar Gupta { 6729ecb8875SAjay Kumar Gupta struct musb_hdrc_platform_data *plat = dev->platform_data; 6739ecb8875SAjay Kumar Gupta struct omap_musb_board_data *data = plat->board_data; 6749ecb8875SAjay Kumar Gupta 6759ecb8875SAjay Kumar Gupta /* Shutdown the on-chip PHY and its PLL. */ 6769ecb8875SAjay Kumar Gupta if (data->set_phy_power) 6779ecb8875SAjay Kumar Gupta data->set_phy_power(0); 6789ecb8875SAjay Kumar Gupta 6799ecb8875SAjay Kumar Gupta return 0; 6809ecb8875SAjay Kumar Gupta } 6819ecb8875SAjay Kumar Gupta 6829ecb8875SAjay Kumar Gupta static int dsps_resume(struct device *dev) 6839ecb8875SAjay Kumar Gupta { 6849ecb8875SAjay Kumar Gupta struct musb_hdrc_platform_data *plat = dev->platform_data; 6859ecb8875SAjay Kumar Gupta struct omap_musb_board_data *data = plat->board_data; 6869ecb8875SAjay Kumar Gupta 6879ecb8875SAjay Kumar Gupta /* Start the on-chip PHY and its PLL. */ 6889ecb8875SAjay Kumar Gupta if (data->set_phy_power) 6899ecb8875SAjay Kumar Gupta data->set_phy_power(1); 6909ecb8875SAjay Kumar Gupta 6919ecb8875SAjay Kumar Gupta return 0; 6929ecb8875SAjay Kumar Gupta } 6939ecb8875SAjay Kumar Gupta #endif 6949ecb8875SAjay Kumar Gupta 6959ecb8875SAjay Kumar Gupta static SIMPLE_DEV_PM_OPS(dsps_pm_ops, dsps_suspend, dsps_resume); 6969ecb8875SAjay Kumar Gupta 6979ecb8875SAjay Kumar Gupta static const struct dsps_musb_wrapper ti81xx_driver_data __devinitconst = { 6989ecb8875SAjay Kumar Gupta .revision = 0x00, 6999ecb8875SAjay Kumar Gupta .control = 0x14, 7009ecb8875SAjay Kumar Gupta .status = 0x18, 7019ecb8875SAjay Kumar Gupta .eoi = 0x24, 7029ecb8875SAjay Kumar Gupta .epintr_set = 0x38, 7039ecb8875SAjay Kumar Gupta .epintr_clear = 0x40, 7049ecb8875SAjay Kumar Gupta .epintr_status = 0x30, 7059ecb8875SAjay Kumar Gupta .coreintr_set = 0x3c, 7069ecb8875SAjay Kumar Gupta .coreintr_clear = 0x44, 7079ecb8875SAjay Kumar Gupta .coreintr_status = 0x34, 7089ecb8875SAjay Kumar Gupta .phy_utmi = 0xe0, 7099ecb8875SAjay Kumar Gupta .mode = 0xe8, 7109ecb8875SAjay Kumar Gupta .reset = 0, 7119ecb8875SAjay Kumar Gupta .otg_disable = 21, 7129ecb8875SAjay Kumar Gupta .iddig = 8, 7139ecb8875SAjay Kumar Gupta .usb_shift = 0, 7149ecb8875SAjay Kumar Gupta .usb_mask = 0x1ff, 7159ecb8875SAjay Kumar Gupta .usb_bitmap = (0x1ff << 0), 7169ecb8875SAjay Kumar Gupta .drvvbus = 8, 7179ecb8875SAjay Kumar Gupta .txep_shift = 0, 7189ecb8875SAjay Kumar Gupta .txep_mask = 0xffff, 7199ecb8875SAjay Kumar Gupta .txep_bitmap = (0xffff << 0), 7209ecb8875SAjay Kumar Gupta .rxep_shift = 16, 7219ecb8875SAjay Kumar Gupta .rxep_mask = 0xfffe, 7229ecb8875SAjay Kumar Gupta .rxep_bitmap = (0xfffe << 16), 7239ecb8875SAjay Kumar Gupta .musb_core_offset = 0x400, 7249ecb8875SAjay Kumar Gupta .poll_seconds = 2, 725db4a9320SB, Ravi .instances = 2, 7269ecb8875SAjay Kumar Gupta }; 7279ecb8875SAjay Kumar Gupta 7289ecb8875SAjay Kumar Gupta static const struct platform_device_id musb_dsps_id_table[] __devinitconst = { 7299ecb8875SAjay Kumar Gupta { 7309ecb8875SAjay Kumar Gupta .name = "musb-ti81xx", 7319ecb8875SAjay Kumar Gupta .driver_data = (kernel_ulong_t) &ti81xx_driver_data, 7329ecb8875SAjay Kumar Gupta }, 7339ecb8875SAjay Kumar Gupta { }, /* Terminating Entry */ 7349ecb8875SAjay Kumar Gupta }; 7359ecb8875SAjay Kumar Gupta MODULE_DEVICE_TABLE(platform, musb_dsps_id_table); 7369ecb8875SAjay Kumar Gupta 737*65145677SAjay Kumar Gupta #ifdef CONFIG_OF 7389ecb8875SAjay Kumar Gupta static const struct of_device_id musb_dsps_of_match[] __devinitconst = { 739*65145677SAjay Kumar Gupta { .compatible = "ti,musb-am33xx", 740*65145677SAjay Kumar Gupta .data = (void *) &ti81xx_driver_data, }, 7419ecb8875SAjay Kumar Gupta { }, 7429ecb8875SAjay Kumar Gupta }; 7439ecb8875SAjay Kumar Gupta MODULE_DEVICE_TABLE(of, musb_dsps_of_match); 744*65145677SAjay Kumar Gupta #endif 7459ecb8875SAjay Kumar Gupta 7469ecb8875SAjay Kumar Gupta static struct platform_driver dsps_usbss_driver = { 7479ecb8875SAjay Kumar Gupta .probe = dsps_probe, 7489ecb8875SAjay Kumar Gupta .remove = __devexit_p(dsps_remove), 7499ecb8875SAjay Kumar Gupta .driver = { 7509ecb8875SAjay Kumar Gupta .name = "musb-dsps", 7519ecb8875SAjay Kumar Gupta .pm = &dsps_pm_ops, 752*65145677SAjay Kumar Gupta .of_match_table = of_match_ptr(musb_dsps_of_match), 7539ecb8875SAjay Kumar Gupta }, 7549ecb8875SAjay Kumar Gupta .id_table = musb_dsps_id_table, 7559ecb8875SAjay Kumar Gupta }; 7569ecb8875SAjay Kumar Gupta 7579ecb8875SAjay Kumar Gupta MODULE_DESCRIPTION("TI DSPS MUSB Glue Layer"); 7589ecb8875SAjay Kumar Gupta MODULE_AUTHOR("Ravi B <ravibabu@ti.com>"); 7599ecb8875SAjay Kumar Gupta MODULE_AUTHOR("Ajay Kumar Gupta <ajay.gupta@ti.com>"); 7609ecb8875SAjay Kumar Gupta MODULE_LICENSE("GPL v2"); 7619ecb8875SAjay Kumar Gupta 7629ecb8875SAjay Kumar Gupta static int __init dsps_init(void) 7639ecb8875SAjay Kumar Gupta { 7649ecb8875SAjay Kumar Gupta return platform_driver_register(&dsps_usbss_driver); 7659ecb8875SAjay Kumar Gupta } 7669ecb8875SAjay Kumar Gupta subsys_initcall(dsps_init); 7679ecb8875SAjay Kumar Gupta 7689ecb8875SAjay Kumar Gupta static void __exit dsps_exit(void) 7699ecb8875SAjay Kumar Gupta { 7709ecb8875SAjay Kumar Gupta platform_driver_unregister(&dsps_usbss_driver); 7719ecb8875SAjay Kumar Gupta } 7729ecb8875SAjay Kumar Gupta module_exit(dsps_exit); 773