2 * Texas Instruments DSPS platforms "glue layer"
4 * Copyright (C) 2012, by Texas Instruments
6 * Based on the am35x "glue layer" code.
8 * This file is part of the Inventra Controller Driver for Linux.
10 * The Inventra Controller Driver for Linux is free software; you
11 * can redistribute it and/or modify it under the terms of the GNU
12 * General Public License version 2 as published by the Free Software
15 * The Inventra Controller Driver for Linux is distributed in
16 * the hope that it will be useful, but WITHOUT ANY WARRANTY;
17 * without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
19 * License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with The Inventra Controller Driver for Linux ; if not,
23 * write to the Free Software Foundation, Inc., 59 Temple Place,
24 * Suite 330, Boston, MA 02111-1307 USA
26 * musb_dsps.c will be a common file for all the TI DSPS platforms
27 * such as dm64x, dm36x, dm35x, da8x, am35x and ti81x.
28 * For now only ti81x is using this and in future davinci.c, am35x.c
29 * da8xx.c would be merged to this file after testing.
33 #include <linux/err.h>
34 #include <linux/platform_device.h>
35 #include <linux/dma-mapping.h>
36 #include <linux/pm_runtime.h>
37 #include <linux/module.h>
38 #include <linux/usb/usb_phy_generic.h>
39 #include <linux/platform_data/usb-omap.h>
40 #include <linux/sizes.h>
43 #include <linux/of_device.h>
44 #include <linux/of_address.h>
45 #include <linux/of_irq.h>
46 #include <linux/usb/of.h>
48 #include <linux/debugfs.h>
50 #include "musb_core.h"
52 static const struct of_device_id musb_dsps_of_match[];
55 * DSPS musb wrapper register offset.
56 * FIXME: This should be expanded to have all the wrapper registers from TI DSPS
59 struct dsps_musb_wrapper {
74 /* bit positions for control */
77 /* bit positions for interrupt */
83 unsigned txep_shift:5;
87 unsigned rxep_shift:5;
91 /* bit positions for phy_utmi */
92 unsigned otg_disable:5;
94 /* bit positions for mode */
97 /* miscellaneous stuff */
98 unsigned poll_timeout;
102 * register shadow for suspend
104 struct dsps_context {
115 * DSPS glue structure.
119 struct platform_device *musb; /* child musb pdev */
120 const struct dsps_musb_wrapper *wrp; /* wrapper register offsets */
121 struct timer_list timer; /* otg_workaround timer */
122 unsigned long last_timer; /* last timer data for each instance */
123 bool sw_babble_enabled;
125 struct dsps_context context;
126 struct debugfs_regset32 regset;
127 struct dentry *dbgfs_root;
130 static const struct debugfs_reg32 dsps_musb_regs[] = {
131 { "revision", 0x00 },
135 { "intr0_stat", 0x30 },
136 { "intr1_stat", 0x34 },
137 { "intr0_set", 0x38 },
138 { "intr1_set", 0x3c },
142 { "srpfixtime", 0xd4 },
144 { "phy_utmi", 0xe0 },
148 static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout)
150 struct device *dev = musb->controller;
151 struct dsps_glue *glue = dev_get_drvdata(dev->parent);
154 timeout = jiffies + msecs_to_jiffies(3);
156 /* Never idle if active, or when VBUS timeout is not set as host */
157 if (musb->is_active || (musb->a_wait_bcon == 0 &&
158 musb->xceiv->otg->state == OTG_STATE_A_WAIT_BCON)) {
159 dev_dbg(musb->controller, "%s active, deleting timer\n",
160 usb_otg_state_string(musb->xceiv->otg->state));
161 del_timer(&glue->timer);
162 glue->last_timer = jiffies;
165 if (musb->port_mode != MUSB_PORT_MODE_DUAL_ROLE)
168 if (!musb->g.dev.driver)
171 if (time_after(glue->last_timer, timeout) &&
172 timer_pending(&glue->timer)) {
173 dev_dbg(musb->controller,
174 "Longer idle timer already pending, ignoring...\n");
177 glue->last_timer = timeout;
179 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n",
180 usb_otg_state_string(musb->xceiv->otg->state),
181 jiffies_to_msecs(timeout - jiffies));
182 mod_timer(&glue->timer, timeout);
186 * dsps_musb_enable - enable interrupts
188 static void dsps_musb_enable(struct musb *musb)
190 struct device *dev = musb->controller;
191 struct platform_device *pdev = to_platform_device(dev->parent);
192 struct dsps_glue *glue = platform_get_drvdata(pdev);
193 const struct dsps_musb_wrapper *wrp = glue->wrp;
194 void __iomem *reg_base = musb->ctrl_base;
195 u32 epmask, coremask;
197 /* Workaround: setup IRQs through both register sets. */
198 epmask = ((musb->epmask & wrp->txep_mask) << wrp->txep_shift) |
199 ((musb->epmask & wrp->rxep_mask) << wrp->rxep_shift);
200 coremask = (wrp->usb_bitmap & ~MUSB_INTR_SOF);
202 musb_writel(reg_base, wrp->epintr_set, epmask);
203 musb_writel(reg_base, wrp->coreintr_set, coremask);
204 /* start polling for ID change in dual-role idle mode */
205 if (musb->xceiv->otg->state == OTG_STATE_B_IDLE &&
206 musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE)
207 mod_timer(&glue->timer, jiffies +
208 msecs_to_jiffies(wrp->poll_timeout));
209 dsps_musb_try_idle(musb, 0);
213 * dsps_musb_disable - disable HDRC and flush interrupts
215 static void dsps_musb_disable(struct musb *musb)
217 struct device *dev = musb->controller;
218 struct platform_device *pdev = to_platform_device(dev->parent);
219 struct dsps_glue *glue = platform_get_drvdata(pdev);
220 const struct dsps_musb_wrapper *wrp = glue->wrp;
221 void __iomem *reg_base = musb->ctrl_base;
223 musb_writel(reg_base, wrp->coreintr_clear, wrp->usb_bitmap);
224 musb_writel(reg_base, wrp->epintr_clear,
225 wrp->txep_bitmap | wrp->rxep_bitmap);
226 musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
229 static void otg_timer(unsigned long _musb)
231 struct musb *musb = (void *)_musb;
232 void __iomem *mregs = musb->mregs;
233 struct device *dev = musb->controller;
234 struct dsps_glue *glue = dev_get_drvdata(dev->parent);
235 const struct dsps_musb_wrapper *wrp = glue->wrp;
238 int skip_session = 0;
241 * We poll because DSPS IP's won't expose several OTG-critical
242 * status change events (from the transceiver) otherwise.
244 devctl = musb_readb(mregs, MUSB_DEVCTL);
245 dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl,
246 usb_otg_state_string(musb->xceiv->otg->state));
248 spin_lock_irqsave(&musb->lock, flags);
249 switch (musb->xceiv->otg->state) {
250 case OTG_STATE_A_WAIT_VRISE:
251 mod_timer(&glue->timer, jiffies +
252 msecs_to_jiffies(wrp->poll_timeout));
254 case OTG_STATE_A_WAIT_BCON:
255 musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
259 case OTG_STATE_A_IDLE:
260 case OTG_STATE_B_IDLE:
261 if (devctl & MUSB_DEVCTL_BDEVICE) {
262 musb->xceiv->otg->state = OTG_STATE_B_IDLE;
265 musb->xceiv->otg->state = OTG_STATE_A_IDLE;
268 if (!(devctl & MUSB_DEVCTL_SESSION) && !skip_session)
269 musb_writeb(mregs, MUSB_DEVCTL, MUSB_DEVCTL_SESSION);
270 mod_timer(&glue->timer, jiffies +
271 msecs_to_jiffies(wrp->poll_timeout));
273 case OTG_STATE_A_WAIT_VFALL:
274 musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
275 musb_writel(musb->ctrl_base, wrp->coreintr_set,
276 MUSB_INTR_VBUSERROR << wrp->usb_shift);
281 spin_unlock_irqrestore(&musb->lock, flags);
284 static irqreturn_t dsps_interrupt(int irq, void *hci)
286 struct musb *musb = hci;
287 void __iomem *reg_base = musb->ctrl_base;
288 struct device *dev = musb->controller;
289 struct dsps_glue *glue = dev_get_drvdata(dev->parent);
290 const struct dsps_musb_wrapper *wrp = glue->wrp;
292 irqreturn_t ret = IRQ_NONE;
295 spin_lock_irqsave(&musb->lock, flags);
297 /* Get endpoint interrupts */
298 epintr = musb_readl(reg_base, wrp->epintr_status);
299 musb->int_rx = (epintr & wrp->rxep_bitmap) >> wrp->rxep_shift;
300 musb->int_tx = (epintr & wrp->txep_bitmap) >> wrp->txep_shift;
303 musb_writel(reg_base, wrp->epintr_status, epintr);
305 /* Get usb core interrupts */
306 usbintr = musb_readl(reg_base, wrp->coreintr_status);
307 if (!usbintr && !epintr)
310 musb->int_usb = (usbintr & wrp->usb_bitmap) >> wrp->usb_shift;
312 musb_writel(reg_base, wrp->coreintr_status, usbintr);
314 dev_dbg(musb->controller, "usbintr (%x) epintr(%x)\n",
317 if (usbintr & ((1 << wrp->drvvbus) << wrp->usb_shift)) {
318 int drvvbus = musb_readl(reg_base, wrp->status);
319 void __iomem *mregs = musb->mregs;
320 u8 devctl = musb_readb(mregs, MUSB_DEVCTL);
323 err = musb->int_usb & MUSB_INTR_VBUSERROR;
326 * The Mentor core doesn't debounce VBUS as needed
327 * to cope with device connect current spikes. This
328 * means it's not uncommon for bus-powered devices
329 * to get VBUS errors during enumeration.
331 * This is a workaround, but newer RTL from Mentor
332 * seems to allow a better one: "re"-starting sessions
333 * without waiting for VBUS to stop registering in
336 musb->int_usb &= ~MUSB_INTR_VBUSERROR;
337 musb->xceiv->otg->state = OTG_STATE_A_WAIT_VFALL;
338 mod_timer(&glue->timer, jiffies +
339 msecs_to_jiffies(wrp->poll_timeout));
340 WARNING("VBUS error workaround (delay coming)\n");
341 } else if (drvvbus) {
343 musb->xceiv->otg->default_a = 1;
344 musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
345 mod_timer(&glue->timer, jiffies +
346 msecs_to_jiffies(wrp->poll_timeout));
350 musb->xceiv->otg->default_a = 0;
351 musb->xceiv->otg->state = OTG_STATE_B_IDLE;
354 /* NOTE: this must complete power-on within 100 ms. */
355 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n",
356 drvvbus ? "on" : "off",
357 usb_otg_state_string(musb->xceiv->otg->state),
363 if (musb->int_tx || musb->int_rx || musb->int_usb)
364 ret |= musb_interrupt(musb);
366 /* Poll for ID change and connect */
367 switch (musb->xceiv->otg->state) {
368 case OTG_STATE_B_IDLE:
369 case OTG_STATE_A_WAIT_BCON:
370 mod_timer(&glue->timer, jiffies +
371 msecs_to_jiffies(wrp->poll_timeout));
378 spin_unlock_irqrestore(&musb->lock, flags);
383 static int dsps_musb_dbg_init(struct musb *musb, struct dsps_glue *glue)
389 sprintf(buf, "%s.dsps", dev_name(musb->controller));
390 root = debugfs_create_dir(buf, NULL);
393 glue->dbgfs_root = root;
395 glue->regset.regs = dsps_musb_regs;
396 glue->regset.nregs = ARRAY_SIZE(dsps_musb_regs);
397 glue->regset.base = musb->ctrl_base;
399 file = debugfs_create_regset32("regdump", S_IRUGO, root, &glue->regset);
401 debugfs_remove_recursive(root);
407 static int dsps_musb_init(struct musb *musb)
409 struct device *dev = musb->controller;
410 struct dsps_glue *glue = dev_get_drvdata(dev->parent);
411 struct platform_device *parent = to_platform_device(dev->parent);
412 const struct dsps_musb_wrapper *wrp = glue->wrp;
413 void __iomem *reg_base;
418 r = platform_get_resource_byname(parent, IORESOURCE_MEM, "control");
419 reg_base = devm_ioremap_resource(dev, r);
420 if (IS_ERR(reg_base))
421 return PTR_ERR(reg_base);
422 musb->ctrl_base = reg_base;
424 /* NOP driver needs change if supporting dual instance */
425 musb->xceiv = devm_usb_get_phy_by_phandle(dev->parent, "phys", 0);
426 if (IS_ERR(musb->xceiv))
427 return PTR_ERR(musb->xceiv);
429 musb->phy = devm_phy_get(dev->parent, "usb2-phy");
431 /* Returns zero if e.g. not clocked */
432 rev = musb_readl(reg_base, wrp->revision);
436 usb_phy_init(musb->xceiv);
437 if (IS_ERR(musb->phy)) {
440 ret = phy_init(musb->phy);
443 ret = phy_power_on(musb->phy);
450 setup_timer(&glue->timer, otg_timer, (unsigned long) musb);
453 musb_writel(reg_base, wrp->control, (1 << wrp->reset));
455 musb->isr = dsps_interrupt;
457 /* reset the otgdisable bit, needed for host mode to work */
458 val = musb_readl(reg_base, wrp->phy_utmi);
459 val &= ~(1 << wrp->otg_disable);
460 musb_writel(musb->ctrl_base, wrp->phy_utmi, val);
463 * Check whether the dsps version has babble control enabled.
464 * In latest silicon revision the babble control logic is enabled.
465 * If MUSB_BABBLE_CTL returns 0x4 then we have the babble control
468 val = musb_readb(musb->mregs, MUSB_BABBLE_CTL);
469 if (val & MUSB_BABBLE_RCV_DISABLE) {
470 glue->sw_babble_enabled = true;
471 val |= MUSB_BABBLE_SW_SESSION_CTRL;
472 musb_writeb(musb->mregs, MUSB_BABBLE_CTL, val);
475 mod_timer(&glue->timer, jiffies +
476 msecs_to_jiffies(glue->wrp->poll_timeout));
478 return dsps_musb_dbg_init(musb, glue);
481 static int dsps_musb_exit(struct musb *musb)
483 struct device *dev = musb->controller;
484 struct dsps_glue *glue = dev_get_drvdata(dev->parent);
486 del_timer_sync(&glue->timer);
487 usb_phy_shutdown(musb->xceiv);
488 phy_power_off(musb->phy);
490 debugfs_remove_recursive(glue->dbgfs_root);
495 static int dsps_musb_set_mode(struct musb *musb, u8 mode)
497 struct device *dev = musb->controller;
498 struct dsps_glue *glue = dev_get_drvdata(dev->parent);
499 const struct dsps_musb_wrapper *wrp = glue->wrp;
500 void __iomem *ctrl_base = musb->ctrl_base;
503 reg = musb_readl(ctrl_base, wrp->mode);
507 reg &= ~(1 << wrp->iddig);
510 * if we're setting mode to host-only or device-only, we're
511 * going to ignore whatever the PHY sends us and just force
512 * ID pin status by SW
514 reg |= (1 << wrp->iddig_mux);
516 musb_writel(ctrl_base, wrp->mode, reg);
517 musb_writel(ctrl_base, wrp->phy_utmi, 0x02);
519 case MUSB_PERIPHERAL:
520 reg |= (1 << wrp->iddig);
523 * if we're setting mode to host-only or device-only, we're
524 * going to ignore whatever the PHY sends us and just force
525 * ID pin status by SW
527 reg |= (1 << wrp->iddig_mux);
529 musb_writel(ctrl_base, wrp->mode, reg);
532 musb_writel(ctrl_base, wrp->phy_utmi, 0x02);
535 dev_err(glue->dev, "unsupported mode %d\n", mode);
542 static bool dsps_sw_babble_control(struct musb *musb)
545 bool session_restart = false;
547 babble_ctl = musb_readb(musb->mregs, MUSB_BABBLE_CTL);
548 dev_dbg(musb->controller, "babble: MUSB_BABBLE_CTL value %x\n",
551 * check line monitor flag to check whether babble is
554 dev_dbg(musb->controller, "STUCK_J is %s\n",
555 babble_ctl & MUSB_BABBLE_STUCK_J ? "set" : "reset");
557 if (babble_ctl & MUSB_BABBLE_STUCK_J) {
561 * babble is due to noise, then set transmit idle (d7 bit)
562 * to resume normal operation
564 babble_ctl = musb_readb(musb->mregs, MUSB_BABBLE_CTL);
565 babble_ctl |= MUSB_BABBLE_FORCE_TXIDLE;
566 musb_writeb(musb->mregs, MUSB_BABBLE_CTL, babble_ctl);
568 /* wait till line monitor flag cleared */
569 dev_dbg(musb->controller, "Set TXIDLE, wait J to clear\n");
571 babble_ctl = musb_readb(musb->mregs, MUSB_BABBLE_CTL);
573 } while ((babble_ctl & MUSB_BABBLE_STUCK_J) && timeout--);
575 /* check whether stuck_at_j bit cleared */
576 if (babble_ctl & MUSB_BABBLE_STUCK_J) {
578 * real babble condition has occurred
579 * restart the controller to start the
582 dev_dbg(musb->controller, "J not cleared, misc (%x)\n",
584 session_restart = true;
587 session_restart = true;
590 return session_restart;
593 static int dsps_musb_recover(struct musb *musb)
595 struct device *dev = musb->controller;
596 struct dsps_glue *glue = dev_get_drvdata(dev->parent);
597 int session_restart = 0;
599 if (glue->sw_babble_enabled)
600 session_restart = dsps_sw_babble_control(musb);
604 return session_restart ? 0 : -EPIPE;
607 /* Similar to am35x, dm81xx support only 32-bit read operation */
608 static void dsps_read_fifo32(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
610 void __iomem *fifo = hw_ep->fifo;
613 ioread32_rep(fifo, dst, len >> 2);
618 /* Read any remaining 1 to 3 bytes */
620 u32 val = musb_readl(fifo, 0);
621 memcpy(dst, &val, len);
625 static struct musb_platform_ops dsps_ops = {
626 .quirks = MUSB_DMA_CPPI41 | MUSB_INDEXED_EP,
627 .init = dsps_musb_init,
628 .exit = dsps_musb_exit,
630 #ifdef CONFIG_USB_TI_CPPI41_DMA
631 .dma_init = cppi41_dma_controller_create,
632 .dma_exit = cppi41_dma_controller_destroy,
634 .enable = dsps_musb_enable,
635 .disable = dsps_musb_disable,
637 .try_idle = dsps_musb_try_idle,
638 .set_mode = dsps_musb_set_mode,
639 .recover = dsps_musb_recover,
642 static u64 musb_dmamask = DMA_BIT_MASK(32);
644 static int get_int_prop(struct device_node *dn, const char *s)
649 ret = of_property_read_u32(dn, s, &val);
655 static int get_musb_port_mode(struct device *dev)
657 enum usb_dr_mode mode;
659 mode = usb_get_dr_mode(dev);
661 case USB_DR_MODE_HOST:
662 return MUSB_PORT_MODE_HOST;
664 case USB_DR_MODE_PERIPHERAL:
665 return MUSB_PORT_MODE_GADGET;
667 case USB_DR_MODE_UNKNOWN:
668 case USB_DR_MODE_OTG:
670 return MUSB_PORT_MODE_DUAL_ROLE;
674 static int dsps_create_musb_pdev(struct dsps_glue *glue,
675 struct platform_device *parent)
677 struct musb_hdrc_platform_data pdata;
678 struct resource resources[2];
679 struct resource *res;
680 struct device *dev = &parent->dev;
681 struct musb_hdrc_config *config;
682 struct platform_device *musb;
683 struct device_node *dn = parent->dev.of_node;
686 memset(resources, 0, sizeof(resources));
687 res = platform_get_resource_byname(parent, IORESOURCE_MEM, "mc");
689 dev_err(dev, "failed to get memory.\n");
694 res = platform_get_resource_byname(parent, IORESOURCE_IRQ, "mc");
696 dev_err(dev, "failed to get irq.\n");
701 /* allocate the child platform device */
702 musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
704 dev_err(dev, "failed to allocate musb device\n");
708 musb->dev.parent = dev;
709 musb->dev.dma_mask = &musb_dmamask;
710 musb->dev.coherent_dma_mask = musb_dmamask;
714 ret = platform_device_add_resources(musb, resources,
715 ARRAY_SIZE(resources));
717 dev_err(dev, "failed to add resources\n");
721 config = devm_kzalloc(&parent->dev, sizeof(*config), GFP_KERNEL);
726 pdata.config = config;
727 pdata.platform_ops = &dsps_ops;
729 config->num_eps = get_int_prop(dn, "mentor,num-eps");
730 config->ram_bits = get_int_prop(dn, "mentor,ram-bits");
731 config->host_port_deassert_reset_at_resume = 1;
732 pdata.mode = get_musb_port_mode(dev);
733 /* DT keeps this entry in mA, musb expects it as per USB spec */
734 pdata.power = get_int_prop(dn, "mentor,power") / 2;
736 ret = of_property_read_u32(dn, "mentor,multipoint", &val);
738 config->multipoint = true;
740 config->maximum_speed = usb_get_maximum_speed(&parent->dev);
741 switch (config->maximum_speed) {
745 case USB_SPEED_SUPER:
746 dev_warn(dev, "ignore incorrect maximum_speed "
747 "(super-speed) setting in dts");
750 config->maximum_speed = USB_SPEED_HIGH;
753 ret = platform_device_add_data(musb, &pdata, sizeof(pdata));
755 dev_err(dev, "failed to add platform_data\n");
759 ret = platform_device_add(musb);
761 dev_err(dev, "failed to register musb device\n");
767 platform_device_put(musb);
771 static int dsps_probe(struct platform_device *pdev)
773 const struct of_device_id *match;
774 const struct dsps_musb_wrapper *wrp;
775 struct dsps_glue *glue;
778 if (!strcmp(pdev->name, "musb-hdrc"))
781 match = of_match_node(musb_dsps_of_match, pdev->dev.of_node);
783 dev_err(&pdev->dev, "fail to get matching of_match struct\n");
788 if (of_device_is_compatible(pdev->dev.of_node, "ti,musb-dm816"))
789 dsps_ops.read_fifo = dsps_read_fifo32;
792 glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
796 glue->dev = &pdev->dev;
799 platform_set_drvdata(pdev, glue);
800 pm_runtime_enable(&pdev->dev);
802 ret = pm_runtime_get_sync(&pdev->dev);
804 dev_err(&pdev->dev, "pm_runtime_get_sync FAILED");
808 ret = dsps_create_musb_pdev(glue, pdev);
815 pm_runtime_put(&pdev->dev);
817 pm_runtime_disable(&pdev->dev);
821 static int dsps_remove(struct platform_device *pdev)
823 struct dsps_glue *glue = platform_get_drvdata(pdev);
825 platform_device_unregister(glue->musb);
827 /* disable usbss clocks */
828 pm_runtime_put(&pdev->dev);
829 pm_runtime_disable(&pdev->dev);
834 static const struct dsps_musb_wrapper am33xx_driver_data = {
839 .epintr_clear = 0x40,
840 .epintr_status = 0x30,
841 .coreintr_set = 0x3c,
842 .coreintr_clear = 0x44,
843 .coreintr_status = 0x34,
854 .usb_bitmap = (0x1ff << 0),
858 .txep_bitmap = (0xffff << 0),
861 .rxep_bitmap = (0xfffe << 16),
862 .poll_timeout = 2000, /* ms */
865 static const struct of_device_id musb_dsps_of_match[] = {
866 { .compatible = "ti,musb-am33xx",
867 .data = &am33xx_driver_data, },
868 { .compatible = "ti,musb-dm816",
869 .data = &am33xx_driver_data, },
872 MODULE_DEVICE_TABLE(of, musb_dsps_of_match);
874 #ifdef CONFIG_PM_SLEEP
875 static int dsps_suspend(struct device *dev)
877 struct dsps_glue *glue = dev_get_drvdata(dev);
878 const struct dsps_musb_wrapper *wrp = glue->wrp;
879 struct musb *musb = platform_get_drvdata(glue->musb);
882 del_timer_sync(&glue->timer);
885 /* This can happen if the musb device is in -EPROBE_DEFER */
888 mbase = musb->ctrl_base;
889 glue->context.control = musb_readl(mbase, wrp->control);
890 glue->context.epintr = musb_readl(mbase, wrp->epintr_set);
891 glue->context.coreintr = musb_readl(mbase, wrp->coreintr_set);
892 glue->context.phy_utmi = musb_readl(mbase, wrp->phy_utmi);
893 glue->context.mode = musb_readl(mbase, wrp->mode);
894 glue->context.tx_mode = musb_readl(mbase, wrp->tx_mode);
895 glue->context.rx_mode = musb_readl(mbase, wrp->rx_mode);
900 static int dsps_resume(struct device *dev)
902 struct dsps_glue *glue = dev_get_drvdata(dev);
903 const struct dsps_musb_wrapper *wrp = glue->wrp;
904 struct musb *musb = platform_get_drvdata(glue->musb);
910 mbase = musb->ctrl_base;
911 musb_writel(mbase, wrp->control, glue->context.control);
912 musb_writel(mbase, wrp->epintr_set, glue->context.epintr);
913 musb_writel(mbase, wrp->coreintr_set, glue->context.coreintr);
914 musb_writel(mbase, wrp->phy_utmi, glue->context.phy_utmi);
915 musb_writel(mbase, wrp->mode, glue->context.mode);
916 musb_writel(mbase, wrp->tx_mode, glue->context.tx_mode);
917 musb_writel(mbase, wrp->rx_mode, glue->context.rx_mode);
918 if (musb->xceiv->otg->state == OTG_STATE_B_IDLE &&
919 musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE)
920 mod_timer(&glue->timer, jiffies +
921 msecs_to_jiffies(wrp->poll_timeout));
927 static SIMPLE_DEV_PM_OPS(dsps_pm_ops, dsps_suspend, dsps_resume);
929 static struct platform_driver dsps_usbss_driver = {
931 .remove = dsps_remove,
935 .of_match_table = musb_dsps_of_match,
939 MODULE_DESCRIPTION("TI DSPS MUSB Glue Layer");
940 MODULE_AUTHOR("Ravi B <ravibabu@ti.com>");
941 MODULE_AUTHOR("Ajay Kumar Gupta <ajay.gupta@ti.com>");
942 MODULE_LICENSE("GPL v2");
944 module_platform_driver(dsps_usbss_driver);