Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2005-2007 by Texas Instruments |
| 3 | * Some code has been taken from tusb6010.c |
| 4 | * Copyrights for that are attributable to: |
| 5 | * Copyright (C) 2006 Nokia Corporation |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 6 | * Tony Lindgren <tony@atomide.com> |
| 7 | * |
| 8 | * This file is part of the Inventra Controller Driver for Linux. |
| 9 | * |
| 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 |
| 13 | * Foundation. |
| 14 | * |
| 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. |
| 20 | * |
| 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 |
| 25 | * |
| 26 | */ |
| 27 | #include <linux/module.h> |
| 28 | #include <linux/kernel.h> |
| 29 | #include <linux/sched.h> |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 30 | #include <linux/init.h> |
| 31 | #include <linux/list.h> |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 32 | #include <linux/io.h> |
Felipe Balbi | dc09886 | 2010-12-01 15:01:11 +0200 | [diff] [blame] | 33 | #include <linux/platform_device.h> |
| 34 | #include <linux/dma-mapping.h> |
Hema HK | 207b0e1 | 2011-02-17 12:07:22 +0530 | [diff] [blame] | 35 | #include <linux/pm_runtime.h> |
| 36 | #include <linux/err.h> |
NeilBrown | 12a19b5 | 2012-08-13 12:32:58 +1000 | [diff] [blame] | 37 | #include <linux/delay.h> |
Kishon Vijay Abraham I | c972143 | 2012-06-22 17:40:52 +0530 | [diff] [blame] | 38 | #include <linux/usb/musb-omap.h> |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 39 | |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 40 | #include "musb_core.h" |
| 41 | #include "omap2430.h" |
| 42 | |
Felipe Balbi | a3cee12 | 2010-12-02 09:27:29 +0200 | [diff] [blame] | 43 | struct omap2430_glue { |
| 44 | struct device *dev; |
| 45 | struct platform_device *musb; |
Kishon Vijay Abraham I | c972143 | 2012-06-22 17:40:52 +0530 | [diff] [blame] | 46 | enum omap_musb_vbus_id_status status; |
Kishon Vijay Abraham I | 1e5acb8 | 2012-06-22 17:40:51 +0530 | [diff] [blame] | 47 | struct work_struct omap_musb_mailbox_work; |
Kishon Vijay Abraham I | 5ec4059 | 2012-09-11 14:39:39 +0530 | [diff] [blame^] | 48 | u32 __iomem *control_otghs; |
Felipe Balbi | a3cee12 | 2010-12-02 09:27:29 +0200 | [diff] [blame] | 49 | }; |
Felipe Balbi | c20aebb | 2010-12-02 12:44:40 +0200 | [diff] [blame] | 50 | #define glue_to_musb(g) platform_get_drvdata(g->musb) |
Felipe Balbi | a3cee12 | 2010-12-02 09:27:29 +0200 | [diff] [blame] | 51 | |
Kishon Vijay Abraham I | c972143 | 2012-06-22 17:40:52 +0530 | [diff] [blame] | 52 | struct omap2430_glue *_glue; |
| 53 | |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 54 | static struct timer_list musb_idle_timer; |
| 55 | |
Kishon Vijay Abraham I | 5ec4059 | 2012-09-11 14:39:39 +0530 | [diff] [blame^] | 56 | /** |
| 57 | * omap4_usb_phy_mailbox - write to usb otg mailbox |
| 58 | * @glue: struct omap2430_glue * |
| 59 | * @val: the value to be written to the mailbox |
| 60 | * |
| 61 | * On detection of a device (ID pin is grounded), this API should be called |
| 62 | * to set AVALID, VBUSVALID and ID pin is grounded. |
| 63 | * |
| 64 | * When OMAP is connected to a host (OMAP in device mode), this API |
| 65 | * is called to set AVALID, VBUSVALID and ID pin in high impedance. |
| 66 | * |
| 67 | * XXX: This function will be removed once we have a seperate driver for |
| 68 | * control module |
| 69 | */ |
| 70 | static void omap4_usb_phy_mailbox(struct omap2430_glue *glue, u32 val) |
| 71 | { |
| 72 | if (glue->control_otghs) |
| 73 | writel(val, glue->control_otghs); |
| 74 | } |
| 75 | |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 76 | static void musb_do_idle(unsigned long _musb) |
| 77 | { |
| 78 | struct musb *musb = (void *)_musb; |
| 79 | unsigned long flags; |
| 80 | u8 power; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 81 | u8 devctl; |
| 82 | |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 83 | spin_lock_irqsave(&musb->lock, flags); |
| 84 | |
David Brownell | 84e250f | 2009-03-31 12:30:04 -0700 | [diff] [blame] | 85 | switch (musb->xceiv->state) { |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 86 | case OTG_STATE_A_WAIT_BCON: |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 87 | |
| 88 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); |
| 89 | if (devctl & MUSB_DEVCTL_BDEVICE) { |
David Brownell | 84e250f | 2009-03-31 12:30:04 -0700 | [diff] [blame] | 90 | musb->xceiv->state = OTG_STATE_B_IDLE; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 91 | MUSB_DEV_MODE(musb); |
| 92 | } else { |
David Brownell | 84e250f | 2009-03-31 12:30:04 -0700 | [diff] [blame] | 93 | musb->xceiv->state = OTG_STATE_A_IDLE; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 94 | MUSB_HST_MODE(musb); |
| 95 | } |
| 96 | break; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 97 | case OTG_STATE_A_SUSPEND: |
| 98 | /* finish RESUME signaling? */ |
| 99 | if (musb->port1_status & MUSB_PORT_STAT_RESUME) { |
| 100 | power = musb_readb(musb->mregs, MUSB_POWER); |
| 101 | power &= ~MUSB_POWER_RESUME; |
Felipe Balbi | 5c8a86e | 2011-05-11 12:44:08 +0300 | [diff] [blame] | 102 | dev_dbg(musb->controller, "root port resume stopped, power %02x\n", power); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 103 | musb_writeb(musb->mregs, MUSB_POWER, power); |
| 104 | musb->is_active = 1; |
| 105 | musb->port1_status &= ~(USB_PORT_STAT_SUSPEND |
| 106 | | MUSB_PORT_STAT_RESUME); |
| 107 | musb->port1_status |= USB_PORT_STAT_C_SUSPEND << 16; |
| 108 | usb_hcd_poll_rh_status(musb_to_hcd(musb)); |
| 109 | /* NOTE: it might really be A_WAIT_BCON ... */ |
David Brownell | 84e250f | 2009-03-31 12:30:04 -0700 | [diff] [blame] | 110 | musb->xceiv->state = OTG_STATE_A_HOST; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 111 | } |
| 112 | break; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 113 | case OTG_STATE_A_HOST: |
| 114 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); |
| 115 | if (devctl & MUSB_DEVCTL_BDEVICE) |
David Brownell | 84e250f | 2009-03-31 12:30:04 -0700 | [diff] [blame] | 116 | musb->xceiv->state = OTG_STATE_B_IDLE; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 117 | else |
David Brownell | 84e250f | 2009-03-31 12:30:04 -0700 | [diff] [blame] | 118 | musb->xceiv->state = OTG_STATE_A_WAIT_BCON; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 119 | default: |
| 120 | break; |
| 121 | } |
| 122 | spin_unlock_irqrestore(&musb->lock, flags); |
| 123 | } |
| 124 | |
| 125 | |
Felipe Balbi | 743411b | 2010-12-01 13:22:05 +0200 | [diff] [blame] | 126 | static void omap2430_musb_try_idle(struct musb *musb, unsigned long timeout) |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 127 | { |
| 128 | unsigned long default_timeout = jiffies + msecs_to_jiffies(3); |
| 129 | static unsigned long last_timer; |
| 130 | |
| 131 | if (timeout == 0) |
| 132 | timeout = default_timeout; |
| 133 | |
| 134 | /* Never idle if active, or when VBUS timeout is not set as host */ |
| 135 | if (musb->is_active || ((musb->a_wait_bcon == 0) |
David Brownell | 84e250f | 2009-03-31 12:30:04 -0700 | [diff] [blame] | 136 | && (musb->xceiv->state == OTG_STATE_A_WAIT_BCON))) { |
Felipe Balbi | 5c8a86e | 2011-05-11 12:44:08 +0300 | [diff] [blame] | 137 | dev_dbg(musb->controller, "%s active, deleting timer\n", |
Anatolij Gustschin | 3df0045 | 2011-05-05 12:11:21 +0200 | [diff] [blame] | 138 | otg_state_string(musb->xceiv->state)); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 139 | del_timer(&musb_idle_timer); |
| 140 | last_timer = jiffies; |
| 141 | return; |
| 142 | } |
| 143 | |
| 144 | if (time_after(last_timer, timeout)) { |
| 145 | if (!timer_pending(&musb_idle_timer)) |
| 146 | last_timer = timeout; |
| 147 | else { |
Felipe Balbi | 5c8a86e | 2011-05-11 12:44:08 +0300 | [diff] [blame] | 148 | dev_dbg(musb->controller, "Longer idle timer already pending, ignoring\n"); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 149 | return; |
| 150 | } |
| 151 | } |
| 152 | last_timer = timeout; |
| 153 | |
Felipe Balbi | 5c8a86e | 2011-05-11 12:44:08 +0300 | [diff] [blame] | 154 | dev_dbg(musb->controller, "%s inactive, for idle timer for %lu ms\n", |
Anatolij Gustschin | 3df0045 | 2011-05-05 12:11:21 +0200 | [diff] [blame] | 155 | otg_state_string(musb->xceiv->state), |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 156 | (unsigned long)jiffies_to_msecs(timeout - jiffies)); |
| 157 | mod_timer(&musb_idle_timer, timeout); |
| 158 | } |
| 159 | |
Felipe Balbi | 743411b | 2010-12-01 13:22:05 +0200 | [diff] [blame] | 160 | static void omap2430_musb_set_vbus(struct musb *musb, int is_on) |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 161 | { |
Heikki Krogerus | d445b6d | 2012-02-13 13:24:15 +0200 | [diff] [blame] | 162 | struct usb_otg *otg = musb->xceiv->otg; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 163 | u8 devctl; |
Hema HK | 594632e | 2010-12-10 18:10:51 +0530 | [diff] [blame] | 164 | unsigned long timeout = jiffies + msecs_to_jiffies(1000); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 165 | /* HDRC controls CPEN, but beware current surges during device |
| 166 | * connect. They can trigger transient overcurrent conditions |
| 167 | * that must be ignored. |
| 168 | */ |
| 169 | |
| 170 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); |
| 171 | |
| 172 | if (is_on) { |
Hema HK | 594632e | 2010-12-10 18:10:51 +0530 | [diff] [blame] | 173 | if (musb->xceiv->state == OTG_STATE_A_IDLE) { |
NeilBrown | 12a19b5 | 2012-08-13 12:32:58 +1000 | [diff] [blame] | 174 | int loops = 100; |
Hema HK | 594632e | 2010-12-10 18:10:51 +0530 | [diff] [blame] | 175 | /* start the session */ |
| 176 | devctl |= MUSB_DEVCTL_SESSION; |
| 177 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); |
| 178 | /* |
| 179 | * Wait for the musb to set as A device to enable the |
| 180 | * VBUS |
| 181 | */ |
| 182 | while (musb_readb(musb->mregs, MUSB_DEVCTL) & 0x80) { |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 183 | |
NeilBrown | 12a19b5 | 2012-08-13 12:32:58 +1000 | [diff] [blame] | 184 | mdelay(5); |
Hema HK | 594632e | 2010-12-10 18:10:51 +0530 | [diff] [blame] | 185 | cpu_relax(); |
| 186 | |
NeilBrown | 12a19b5 | 2012-08-13 12:32:58 +1000 | [diff] [blame] | 187 | if (time_after(jiffies, timeout) |
| 188 | || loops-- <= 0) { |
Hema HK | 594632e | 2010-12-10 18:10:51 +0530 | [diff] [blame] | 189 | dev_err(musb->controller, |
| 190 | "configured as A device timeout"); |
Hema HK | 594632e | 2010-12-10 18:10:51 +0530 | [diff] [blame] | 191 | break; |
| 192 | } |
| 193 | } |
| 194 | |
Matthias Brugger | 10770c5 | 2012-08-16 13:00:25 +0200 | [diff] [blame] | 195 | if (otg->set_vbus) |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 196 | otg_set_vbus(otg, 1); |
Hema HK | 594632e | 2010-12-10 18:10:51 +0530 | [diff] [blame] | 197 | } else { |
| 198 | musb->is_active = 1; |
Heikki Krogerus | d445b6d | 2012-02-13 13:24:15 +0200 | [diff] [blame] | 199 | otg->default_a = 1; |
Hema HK | 594632e | 2010-12-10 18:10:51 +0530 | [diff] [blame] | 200 | musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; |
| 201 | devctl |= MUSB_DEVCTL_SESSION; |
| 202 | MUSB_HST_MODE(musb); |
| 203 | } |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 204 | } else { |
| 205 | musb->is_active = 0; |
| 206 | |
| 207 | /* NOTE: we're skipping A_WAIT_VFALL -> A_IDLE and |
| 208 | * jumping right to B_IDLE... |
| 209 | */ |
| 210 | |
Heikki Krogerus | d445b6d | 2012-02-13 13:24:15 +0200 | [diff] [blame] | 211 | otg->default_a = 0; |
David Brownell | 84e250f | 2009-03-31 12:30:04 -0700 | [diff] [blame] | 212 | musb->xceiv->state = OTG_STATE_B_IDLE; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 213 | devctl &= ~MUSB_DEVCTL_SESSION; |
| 214 | |
| 215 | MUSB_DEV_MODE(musb); |
| 216 | } |
| 217 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); |
| 218 | |
Felipe Balbi | 5c8a86e | 2011-05-11 12:44:08 +0300 | [diff] [blame] | 219 | dev_dbg(musb->controller, "VBUS %s, devctl %02x " |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 220 | /* otg %3x conf %08x prcm %08x */ "\n", |
Anatolij Gustschin | 3df0045 | 2011-05-05 12:11:21 +0200 | [diff] [blame] | 221 | otg_state_string(musb->xceiv->state), |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 222 | musb_readb(musb->mregs, MUSB_DEVCTL)); |
| 223 | } |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 224 | |
Felipe Balbi | 743411b | 2010-12-01 13:22:05 +0200 | [diff] [blame] | 225 | static int omap2430_musb_set_mode(struct musb *musb, u8 musb_mode) |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 226 | { |
| 227 | u8 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); |
| 228 | |
| 229 | devctl |= MUSB_DEVCTL_SESSION; |
| 230 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); |
| 231 | |
David Brownell | 96a274d | 2008-11-24 13:06:47 +0200 | [diff] [blame] | 232 | return 0; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 233 | } |
| 234 | |
Felipe Balbi | c20aebb | 2010-12-02 12:44:40 +0200 | [diff] [blame] | 235 | static inline void omap2430_low_level_exit(struct musb *musb) |
| 236 | { |
| 237 | u32 l; |
| 238 | |
| 239 | /* in any role */ |
| 240 | l = musb_readl(musb->mregs, OTG_FORCESTDBY); |
| 241 | l |= ENABLEFORCE; /* enable MSTANDBY */ |
| 242 | musb_writel(musb->mregs, OTG_FORCESTDBY, l); |
Felipe Balbi | c20aebb | 2010-12-02 12:44:40 +0200 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | static inline void omap2430_low_level_init(struct musb *musb) |
| 246 | { |
| 247 | u32 l; |
| 248 | |
Felipe Balbi | c20aebb | 2010-12-02 12:44:40 +0200 | [diff] [blame] | 249 | l = musb_readl(musb->mregs, OTG_FORCESTDBY); |
| 250 | l &= ~ENABLEFORCE; /* disable MSTANDBY */ |
| 251 | musb_writel(musb->mregs, OTG_FORCESTDBY, l); |
| 252 | } |
| 253 | |
Kishon Vijay Abraham I | c972143 | 2012-06-22 17:40:52 +0530 | [diff] [blame] | 254 | void omap_musb_mailbox(enum omap_musb_vbus_id_status status) |
Hema HK | 594632e | 2010-12-10 18:10:51 +0530 | [diff] [blame] | 255 | { |
Kishon Vijay Abraham I | c972143 | 2012-06-22 17:40:52 +0530 | [diff] [blame] | 256 | struct omap2430_glue *glue = _glue; |
| 257 | struct musb *musb = glue_to_musb(glue); |
Vikram Pandita | 712d8ef | 2011-08-12 07:38:51 -0700 | [diff] [blame] | 258 | |
Kishon Vijay Abraham I | c972143 | 2012-06-22 17:40:52 +0530 | [diff] [blame] | 259 | glue->status = status; |
| 260 | if (!musb) { |
| 261 | dev_err(glue->dev, "musb core is not yet ready\n"); |
| 262 | return; |
| 263 | } |
| 264 | |
Kishon Vijay Abraham I | 1e5acb8 | 2012-06-22 17:40:51 +0530 | [diff] [blame] | 265 | schedule_work(&glue->omap_musb_mailbox_work); |
Vikram Pandita | 712d8ef | 2011-08-12 07:38:51 -0700 | [diff] [blame] | 266 | } |
Kishon Vijay Abraham I | c972143 | 2012-06-22 17:40:52 +0530 | [diff] [blame] | 267 | EXPORT_SYMBOL_GPL(omap_musb_mailbox); |
Vikram Pandita | 712d8ef | 2011-08-12 07:38:51 -0700 | [diff] [blame] | 268 | |
Kishon Vijay Abraham I | c972143 | 2012-06-22 17:40:52 +0530 | [diff] [blame] | 269 | static void omap_musb_set_mailbox(struct omap2430_glue *glue) |
Vikram Pandita | 712d8ef | 2011-08-12 07:38:51 -0700 | [diff] [blame] | 270 | { |
Kishon Vijay Abraham I | 5ec4059 | 2012-09-11 14:39:39 +0530 | [diff] [blame^] | 271 | u32 val; |
Kishon Vijay Abraham I | 1e5acb8 | 2012-06-22 17:40:51 +0530 | [diff] [blame] | 272 | struct musb *musb = glue_to_musb(glue); |
Hema HK | 594632e | 2010-12-10 18:10:51 +0530 | [diff] [blame] | 273 | struct device *dev = musb->controller; |
| 274 | struct musb_hdrc_platform_data *pdata = dev->platform_data; |
| 275 | struct omap_musb_board_data *data = pdata->board_data; |
Kishon Vijay Abraham I | c83a854 | 2012-06-22 17:40:53 +0530 | [diff] [blame] | 276 | struct usb_otg *otg = musb->xceiv->otg; |
Hema HK | 594632e | 2010-12-10 18:10:51 +0530 | [diff] [blame] | 277 | |
Kishon Vijay Abraham I | c972143 | 2012-06-22 17:40:52 +0530 | [diff] [blame] | 278 | switch (glue->status) { |
| 279 | case OMAP_MUSB_ID_GROUND: |
| 280 | dev_dbg(dev, "ID GND\n"); |
Hema HK | 594632e | 2010-12-10 18:10:51 +0530 | [diff] [blame] | 281 | |
Kishon Vijay Abraham I | c83a854 | 2012-06-22 17:40:53 +0530 | [diff] [blame] | 282 | otg->default_a = true; |
| 283 | musb->xceiv->state = OTG_STATE_A_IDLE; |
Kishon Vijay Abraham I | c972143 | 2012-06-22 17:40:52 +0530 | [diff] [blame] | 284 | musb->xceiv->last_event = USB_EVENT_ID; |
Felipe Balbi | 032ec49 | 2011-11-24 15:46:26 +0200 | [diff] [blame] | 285 | if (musb->gadget_driver) { |
Kishon Vijay Abraham I | c972143 | 2012-06-22 17:40:52 +0530 | [diff] [blame] | 286 | pm_runtime_get_sync(dev); |
Kishon Vijay Abraham I | 5ec4059 | 2012-09-11 14:39:39 +0530 | [diff] [blame^] | 287 | val = AVALID | VBUSVALID; |
| 288 | omap4_usb_phy_mailbox(glue, val); |
Hema HK | 70045c5 | 2011-02-28 15:05:29 +0530 | [diff] [blame] | 289 | omap2430_musb_set_vbus(musb, 1); |
Hema HK | 594632e | 2010-12-10 18:10:51 +0530 | [diff] [blame] | 290 | } |
| 291 | break; |
| 292 | |
Kishon Vijay Abraham I | c972143 | 2012-06-22 17:40:52 +0530 | [diff] [blame] | 293 | case OMAP_MUSB_VBUS_VALID: |
| 294 | dev_dbg(dev, "VBUS Connect\n"); |
Hema HK | 594632e | 2010-12-10 18:10:51 +0530 | [diff] [blame] | 295 | |
Kishon Vijay Abraham I | c83a854 | 2012-06-22 17:40:53 +0530 | [diff] [blame] | 296 | otg->default_a = false; |
| 297 | musb->xceiv->state = OTG_STATE_B_IDLE; |
Kishon Vijay Abraham I | c972143 | 2012-06-22 17:40:52 +0530 | [diff] [blame] | 298 | musb->xceiv->last_event = USB_EVENT_VBUS; |
Hema HK | 7acc619 | 2011-02-28 14:19:34 +0530 | [diff] [blame] | 299 | if (musb->gadget_driver) |
Kishon Vijay Abraham I | c972143 | 2012-06-22 17:40:52 +0530 | [diff] [blame] | 300 | pm_runtime_get_sync(dev); |
Kishon Vijay Abraham I | 5ec4059 | 2012-09-11 14:39:39 +0530 | [diff] [blame^] | 301 | val = IDDIG | AVALID | VBUSVALID; |
| 302 | omap4_usb_phy_mailbox(glue, val); |
Hema HK | 594632e | 2010-12-10 18:10:51 +0530 | [diff] [blame] | 303 | break; |
| 304 | |
Kishon Vijay Abraham I | c972143 | 2012-06-22 17:40:52 +0530 | [diff] [blame] | 305 | case OMAP_MUSB_ID_FLOAT: |
| 306 | case OMAP_MUSB_VBUS_OFF: |
| 307 | dev_dbg(dev, "VBUS Disconnect\n"); |
Hema HK | 594632e | 2010-12-10 18:10:51 +0530 | [diff] [blame] | 308 | |
Kishon Vijay Abraham I | c972143 | 2012-06-22 17:40:52 +0530 | [diff] [blame] | 309 | musb->xceiv->last_event = USB_EVENT_NONE; |
Felipe Balbi | 032ec49 | 2011-11-24 15:46:26 +0200 | [diff] [blame] | 310 | if (musb->gadget_driver) { |
| 311 | pm_runtime_mark_last_busy(dev); |
| 312 | pm_runtime_put_autosuspend(dev); |
| 313 | } |
Hema HK | 7acc619 | 2011-02-28 14:19:34 +0530 | [diff] [blame] | 314 | |
Hema HK | 594632e | 2010-12-10 18:10:51 +0530 | [diff] [blame] | 315 | if (data->interface_type == MUSB_INTERFACE_UTMI) { |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 316 | if (musb->xceiv->otg->set_vbus) |
| 317 | otg_set_vbus(musb->xceiv->otg, 0); |
Hema HK | 594632e | 2010-12-10 18:10:51 +0530 | [diff] [blame] | 318 | } |
Kishon Vijay Abraham I | 5ec4059 | 2012-09-11 14:39:39 +0530 | [diff] [blame^] | 319 | val = SESSEND | IDDIG; |
| 320 | omap4_usb_phy_mailbox(glue, val); |
Hema HK | 594632e | 2010-12-10 18:10:51 +0530 | [diff] [blame] | 321 | break; |
| 322 | default: |
Kishon Vijay Abraham I | c972143 | 2012-06-22 17:40:52 +0530 | [diff] [blame] | 323 | dev_dbg(dev, "ID float\n"); |
Hema HK | 594632e | 2010-12-10 18:10:51 +0530 | [diff] [blame] | 324 | } |
Hema HK | 594632e | 2010-12-10 18:10:51 +0530 | [diff] [blame] | 325 | } |
| 326 | |
Kishon Vijay Abraham I | c972143 | 2012-06-22 17:40:52 +0530 | [diff] [blame] | 327 | |
| 328 | static void omap_musb_mailbox_work(struct work_struct *mailbox_work) |
| 329 | { |
| 330 | struct omap2430_glue *glue = container_of(mailbox_work, |
| 331 | struct omap2430_glue, omap_musb_mailbox_work); |
| 332 | omap_musb_set_mailbox(glue); |
| 333 | } |
| 334 | |
Felipe Balbi | 743411b | 2010-12-01 13:22:05 +0200 | [diff] [blame] | 335 | static int omap2430_musb_init(struct musb *musb) |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 336 | { |
Shubhrajyoti D | ad57969 | 2012-03-22 12:48:06 +0530 | [diff] [blame] | 337 | u32 l; |
| 338 | int status = 0; |
Hema Kalliguddi | ea65df5 | 2010-09-22 19:27:40 -0500 | [diff] [blame] | 339 | struct device *dev = musb->controller; |
Kishon Vijay Abraham I | c972143 | 2012-06-22 17:40:52 +0530 | [diff] [blame] | 340 | struct omap2430_glue *glue = dev_get_drvdata(dev->parent); |
Hema Kalliguddi | ea65df5 | 2010-09-22 19:27:40 -0500 | [diff] [blame] | 341 | struct musb_hdrc_platform_data *plat = dev->platform_data; |
| 342 | struct omap_musb_board_data *data = plat->board_data; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 343 | |
David Brownell | 84e250f | 2009-03-31 12:30:04 -0700 | [diff] [blame] | 344 | /* We require some kind of external transceiver, hooked |
| 345 | * up through ULPI. TWL4030-family PMICs include one, |
| 346 | * which needs a driver, drivers aren't always needed. |
| 347 | */ |
Kishon Vijay Abraham I | b1183c2 | 2012-06-22 17:40:54 +0530 | [diff] [blame] | 348 | musb->xceiv = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); |
Kishon Vijay Abraham I | ded017e | 2012-06-26 17:40:32 +0530 | [diff] [blame] | 349 | if (IS_ERR_OR_NULL(musb->xceiv)) { |
David Brownell | 84e250f | 2009-03-31 12:30:04 -0700 | [diff] [blame] | 350 | pr_err("HS USB OTG: no transceiver configured\n"); |
| 351 | return -ENODEV; |
| 352 | } |
| 353 | |
Hema HK | 7acc619 | 2011-02-28 14:19:34 +0530 | [diff] [blame] | 354 | status = pm_runtime_get_sync(dev); |
| 355 | if (status < 0) { |
Shubhrajyoti D | ad57969 | 2012-03-22 12:48:06 +0530 | [diff] [blame] | 356 | dev_err(dev, "pm_runtime_get_sync FAILED %d\n", status); |
Hema HK | 7acc619 | 2011-02-28 14:19:34 +0530 | [diff] [blame] | 357 | goto err1; |
| 358 | } |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 359 | |
Felipe Balbi | 8573e6a | 2010-01-21 15:33:53 +0200 | [diff] [blame] | 360 | l = musb_readl(musb->mregs, OTG_INTERFSEL); |
Maulik Mankad | de2e1b0 | 2010-03-12 10:29:07 +0200 | [diff] [blame] | 361 | |
| 362 | if (data->interface_type == MUSB_INTERFACE_UTMI) { |
| 363 | /* OMAP4 uses Internal PHY GS70 which uses UTMI interface */ |
| 364 | l &= ~ULPI_12PIN; /* Disable ULPI */ |
| 365 | l |= UTMI_8BIT; /* Enable UTMI */ |
| 366 | } else { |
| 367 | l |= ULPI_12PIN; |
| 368 | } |
| 369 | |
Felipe Balbi | 8573e6a | 2010-01-21 15:33:53 +0200 | [diff] [blame] | 370 | musb_writel(musb->mregs, OTG_INTERFSEL, l); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 371 | |
| 372 | pr_debug("HS USB OTG: revision 0x%x, sysconfig 0x%02x, " |
| 373 | "sysstatus 0x%x, intrfsel 0x%x, simenable 0x%x\n", |
Felipe Balbi | 8573e6a | 2010-01-21 15:33:53 +0200 | [diff] [blame] | 374 | musb_readl(musb->mregs, OTG_REVISION), |
| 375 | musb_readl(musb->mregs, OTG_SYSCONFIG), |
| 376 | musb_readl(musb->mregs, OTG_SYSSTATUS), |
| 377 | musb_readl(musb->mregs, OTG_INTERFSEL), |
| 378 | musb_readl(musb->mregs, OTG_SIMENABLE)); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 379 | |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 380 | setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb); |
| 381 | |
Kishon Vijay Abraham I | c972143 | 2012-06-22 17:40:52 +0530 | [diff] [blame] | 382 | if (glue->status != OMAP_MUSB_UNKNOWN) |
| 383 | omap_musb_set_mailbox(glue); |
| 384 | |
Grazvydas Ignotas | c04352a | 2012-02-04 19:43:51 +0200 | [diff] [blame] | 385 | pm_runtime_put_noidle(musb->controller); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 386 | return 0; |
Hema HK | 7acc619 | 2011-02-28 14:19:34 +0530 | [diff] [blame] | 387 | |
| 388 | err1: |
Hema HK | 7acc619 | 2011-02-28 14:19:34 +0530 | [diff] [blame] | 389 | return status; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 390 | } |
| 391 | |
Hema HK | 002eda1 | 2011-02-17 12:06:10 +0530 | [diff] [blame] | 392 | static void omap2430_musb_enable(struct musb *musb) |
| 393 | { |
| 394 | u8 devctl; |
Kishon Vijay Abraham I | 5ec4059 | 2012-09-11 14:39:39 +0530 | [diff] [blame^] | 395 | u32 val; |
Hema HK | 002eda1 | 2011-02-17 12:06:10 +0530 | [diff] [blame] | 396 | unsigned long timeout = jiffies + msecs_to_jiffies(1000); |
| 397 | struct device *dev = musb->controller; |
Kishon Vijay Abraham I | c972143 | 2012-06-22 17:40:52 +0530 | [diff] [blame] | 398 | struct omap2430_glue *glue = dev_get_drvdata(dev->parent); |
Hema HK | 002eda1 | 2011-02-17 12:06:10 +0530 | [diff] [blame] | 399 | struct musb_hdrc_platform_data *pdata = dev->platform_data; |
| 400 | struct omap_musb_board_data *data = pdata->board_data; |
| 401 | |
Kishon Vijay Abraham I | c972143 | 2012-06-22 17:40:52 +0530 | [diff] [blame] | 402 | switch (glue->status) { |
Hema HK | 002eda1 | 2011-02-17 12:06:10 +0530 | [diff] [blame] | 403 | |
Kishon Vijay Abraham I | c972143 | 2012-06-22 17:40:52 +0530 | [diff] [blame] | 404 | case OMAP_MUSB_ID_GROUND: |
Kishon Vijay Abraham I | 5ec4059 | 2012-09-11 14:39:39 +0530 | [diff] [blame^] | 405 | val = AVALID | VBUSVALID; |
| 406 | omap4_usb_phy_mailbox(glue, val); |
Felipe Contreras | 08dec56 | 2011-12-19 22:17:50 +0200 | [diff] [blame] | 407 | if (data->interface_type != MUSB_INTERFACE_UTMI) |
| 408 | break; |
| 409 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); |
| 410 | /* start the session */ |
| 411 | devctl |= MUSB_DEVCTL_SESSION; |
| 412 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); |
| 413 | while (musb_readb(musb->mregs, MUSB_DEVCTL) & |
| 414 | MUSB_DEVCTL_BDEVICE) { |
| 415 | cpu_relax(); |
Hema HK | 002eda1 | 2011-02-17 12:06:10 +0530 | [diff] [blame] | 416 | |
Felipe Contreras | 08dec56 | 2011-12-19 22:17:50 +0200 | [diff] [blame] | 417 | if (time_after(jiffies, timeout)) { |
| 418 | dev_err(dev, "configured as A device timeout"); |
| 419 | break; |
Hema HK | 002eda1 | 2011-02-17 12:06:10 +0530 | [diff] [blame] | 420 | } |
| 421 | } |
| 422 | break; |
| 423 | |
Kishon Vijay Abraham I | c972143 | 2012-06-22 17:40:52 +0530 | [diff] [blame] | 424 | case OMAP_MUSB_VBUS_VALID: |
Kishon Vijay Abraham I | 5ec4059 | 2012-09-11 14:39:39 +0530 | [diff] [blame^] | 425 | val = IDDIG | AVALID | VBUSVALID; |
| 426 | omap4_usb_phy_mailbox(glue, val); |
Hema HK | 002eda1 | 2011-02-17 12:06:10 +0530 | [diff] [blame] | 427 | break; |
| 428 | |
| 429 | default: |
| 430 | break; |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | static void omap2430_musb_disable(struct musb *musb) |
| 435 | { |
Kishon Vijay Abraham I | 5ec4059 | 2012-09-11 14:39:39 +0530 | [diff] [blame^] | 436 | u32 val; |
Kishon Vijay Abraham I | c972143 | 2012-06-22 17:40:52 +0530 | [diff] [blame] | 437 | struct device *dev = musb->controller; |
| 438 | struct omap2430_glue *glue = dev_get_drvdata(dev->parent); |
| 439 | |
Kishon Vijay Abraham I | 5ec4059 | 2012-09-11 14:39:39 +0530 | [diff] [blame^] | 440 | if (glue->status != OMAP_MUSB_UNKNOWN) { |
| 441 | val = SESSEND | IDDIG; |
| 442 | omap4_usb_phy_mailbox(glue, val); |
| 443 | } |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 444 | } |
| 445 | |
Felipe Balbi | 743411b | 2010-12-01 13:22:05 +0200 | [diff] [blame] | 446 | static int omap2430_musb_exit(struct musb *musb) |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 447 | { |
Johan Hovold | 19b9a83 | 2011-02-11 16:57:08 +0100 | [diff] [blame] | 448 | del_timer_sync(&musb_idle_timer); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 449 | |
Felipe Balbi | c20aebb | 2010-12-02 12:44:40 +0200 | [diff] [blame] | 450 | omap2430_low_level_exit(musb); |
Felipe Balbi | c20aebb | 2010-12-02 12:44:40 +0200 | [diff] [blame] | 451 | |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 452 | return 0; |
| 453 | } |
Felipe Balbi | 743411b | 2010-12-01 13:22:05 +0200 | [diff] [blame] | 454 | |
Felipe Balbi | f7ec943 | 2010-12-02 09:48:58 +0200 | [diff] [blame] | 455 | static const struct musb_platform_ops omap2430_ops = { |
Felipe Balbi | 743411b | 2010-12-01 13:22:05 +0200 | [diff] [blame] | 456 | .init = omap2430_musb_init, |
| 457 | .exit = omap2430_musb_exit, |
| 458 | |
Felipe Balbi | 743411b | 2010-12-01 13:22:05 +0200 | [diff] [blame] | 459 | .set_mode = omap2430_musb_set_mode, |
| 460 | .try_idle = omap2430_musb_try_idle, |
| 461 | |
| 462 | .set_vbus = omap2430_musb_set_vbus, |
Hema HK | 002eda1 | 2011-02-17 12:06:10 +0530 | [diff] [blame] | 463 | |
| 464 | .enable = omap2430_musb_enable, |
| 465 | .disable = omap2430_musb_disable, |
Felipe Balbi | 743411b | 2010-12-01 13:22:05 +0200 | [diff] [blame] | 466 | }; |
Felipe Balbi | dc09886 | 2010-12-01 15:01:11 +0200 | [diff] [blame] | 467 | |
| 468 | static u64 omap2430_dmamask = DMA_BIT_MASK(32); |
| 469 | |
Felipe Balbi | e9e8c85 | 2012-01-26 12:40:23 +0200 | [diff] [blame] | 470 | static int __devinit omap2430_probe(struct platform_device *pdev) |
Felipe Balbi | dc09886 | 2010-12-01 15:01:11 +0200 | [diff] [blame] | 471 | { |
| 472 | struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data; |
| 473 | struct platform_device *musb; |
Felipe Balbi | a3cee12 | 2010-12-02 09:27:29 +0200 | [diff] [blame] | 474 | struct omap2430_glue *glue; |
Kishon Vijay Abraham I | 5ec4059 | 2012-09-11 14:39:39 +0530 | [diff] [blame^] | 475 | struct resource *res; |
Felipe Balbi | dc09886 | 2010-12-01 15:01:11 +0200 | [diff] [blame] | 476 | int ret = -ENOMEM; |
| 477 | |
Kishon Vijay Abraham I | b1183c2 | 2012-06-22 17:40:54 +0530 | [diff] [blame] | 478 | glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); |
Felipe Balbi | a3cee12 | 2010-12-02 09:27:29 +0200 | [diff] [blame] | 479 | if (!glue) { |
| 480 | dev_err(&pdev->dev, "failed to allocate glue context\n"); |
| 481 | goto err0; |
| 482 | } |
| 483 | |
Felipe Balbi | dc09886 | 2010-12-01 15:01:11 +0200 | [diff] [blame] | 484 | musb = platform_device_alloc("musb-hdrc", -1); |
| 485 | if (!musb) { |
| 486 | dev_err(&pdev->dev, "failed to allocate musb device\n"); |
Kishon Vijay Abraham I | b1183c2 | 2012-06-22 17:40:54 +0530 | [diff] [blame] | 487 | goto err0; |
Felipe Balbi | dc09886 | 2010-12-01 15:01:11 +0200 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | musb->dev.parent = &pdev->dev; |
| 491 | musb->dev.dma_mask = &omap2430_dmamask; |
| 492 | musb->dev.coherent_dma_mask = omap2430_dmamask; |
| 493 | |
Felipe Balbi | a3cee12 | 2010-12-02 09:27:29 +0200 | [diff] [blame] | 494 | glue->dev = &pdev->dev; |
| 495 | glue->musb = musb; |
Kishon Vijay Abraham I | c972143 | 2012-06-22 17:40:52 +0530 | [diff] [blame] | 496 | glue->status = OMAP_MUSB_UNKNOWN; |
Felipe Balbi | a3cee12 | 2010-12-02 09:27:29 +0200 | [diff] [blame] | 497 | |
Kishon Vijay Abraham I | 5ec4059 | 2012-09-11 14:39:39 +0530 | [diff] [blame^] | 498 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 499 | |
| 500 | glue->control_otghs = devm_request_and_ioremap(&pdev->dev, res); |
| 501 | if (glue->control_otghs == NULL) |
| 502 | dev_dbg(&pdev->dev, "Failed to obtain control memory\n"); |
| 503 | |
Felipe Balbi | f7ec943 | 2010-12-02 09:48:58 +0200 | [diff] [blame] | 504 | pdata->platform_ops = &omap2430_ops; |
| 505 | |
Felipe Balbi | a3cee12 | 2010-12-02 09:27:29 +0200 | [diff] [blame] | 506 | platform_set_drvdata(pdev, glue); |
Felipe Balbi | dc09886 | 2010-12-01 15:01:11 +0200 | [diff] [blame] | 507 | |
Kishon Vijay Abraham I | c972143 | 2012-06-22 17:40:52 +0530 | [diff] [blame] | 508 | /* |
| 509 | * REVISIT if we ever have two instances of the wrapper, we will be |
| 510 | * in big trouble |
| 511 | */ |
| 512 | _glue = glue; |
| 513 | |
Kishon Vijay Abraham I | 1e5acb8 | 2012-06-22 17:40:51 +0530 | [diff] [blame] | 514 | INIT_WORK(&glue->omap_musb_mailbox_work, omap_musb_mailbox_work); |
| 515 | |
Felipe Balbi | dc09886 | 2010-12-01 15:01:11 +0200 | [diff] [blame] | 516 | ret = platform_device_add_resources(musb, pdev->resource, |
| 517 | pdev->num_resources); |
| 518 | if (ret) { |
| 519 | dev_err(&pdev->dev, "failed to add resources\n"); |
Kishon Vijay Abraham I | b1183c2 | 2012-06-22 17:40:54 +0530 | [diff] [blame] | 520 | goto err1; |
Felipe Balbi | dc09886 | 2010-12-01 15:01:11 +0200 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); |
| 524 | if (ret) { |
| 525 | dev_err(&pdev->dev, "failed to add platform_data\n"); |
Kishon Vijay Abraham I | b1183c2 | 2012-06-22 17:40:54 +0530 | [diff] [blame] | 526 | goto err1; |
Felipe Balbi | dc09886 | 2010-12-01 15:01:11 +0200 | [diff] [blame] | 527 | } |
| 528 | |
Kishon Vijay Abraham I | 3006dc8 | 2012-03-21 21:30:20 +0530 | [diff] [blame] | 529 | pm_runtime_enable(&pdev->dev); |
| 530 | |
Felipe Balbi | dc09886 | 2010-12-01 15:01:11 +0200 | [diff] [blame] | 531 | ret = platform_device_add(musb); |
| 532 | if (ret) { |
| 533 | dev_err(&pdev->dev, "failed to register musb device\n"); |
Kishon Vijay Abraham I | b1183c2 | 2012-06-22 17:40:54 +0530 | [diff] [blame] | 534 | goto err1; |
Felipe Balbi | dc09886 | 2010-12-01 15:01:11 +0200 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | return 0; |
| 538 | |
Felipe Balbi | a3cee12 | 2010-12-02 09:27:29 +0200 | [diff] [blame] | 539 | err1: |
Kishon Vijay Abraham I | b1183c2 | 2012-06-22 17:40:54 +0530 | [diff] [blame] | 540 | platform_device_put(musb); |
Felipe Balbi | a3cee12 | 2010-12-02 09:27:29 +0200 | [diff] [blame] | 541 | |
Felipe Balbi | dc09886 | 2010-12-01 15:01:11 +0200 | [diff] [blame] | 542 | err0: |
| 543 | return ret; |
| 544 | } |
| 545 | |
Felipe Balbi | e9e8c85 | 2012-01-26 12:40:23 +0200 | [diff] [blame] | 546 | static int __devexit omap2430_remove(struct platform_device *pdev) |
Felipe Balbi | dc09886 | 2010-12-01 15:01:11 +0200 | [diff] [blame] | 547 | { |
Felipe Balbi | a3cee12 | 2010-12-02 09:27:29 +0200 | [diff] [blame] | 548 | struct omap2430_glue *glue = platform_get_drvdata(pdev); |
Felipe Balbi | dc09886 | 2010-12-01 15:01:11 +0200 | [diff] [blame] | 549 | |
Kishon Vijay Abraham I | 1e5acb8 | 2012-06-22 17:40:51 +0530 | [diff] [blame] | 550 | cancel_work_sync(&glue->omap_musb_mailbox_work); |
Kishon Vijay Abraham I | f039df5 | 2012-08-02 15:30:07 +0530 | [diff] [blame] | 551 | platform_device_unregister(glue->musb); |
Felipe Balbi | dc09886 | 2010-12-01 15:01:11 +0200 | [diff] [blame] | 552 | |
| 553 | return 0; |
| 554 | } |
| 555 | |
Felipe Balbi | c20aebb | 2010-12-02 12:44:40 +0200 | [diff] [blame] | 556 | #ifdef CONFIG_PM |
Felipe Balbi | c20aebb | 2010-12-02 12:44:40 +0200 | [diff] [blame] | 557 | |
Hema HK | 7acc619 | 2011-02-28 14:19:34 +0530 | [diff] [blame] | 558 | static int omap2430_runtime_suspend(struct device *dev) |
Felipe Balbi | c20aebb | 2010-12-02 12:44:40 +0200 | [diff] [blame] | 559 | { |
| 560 | struct omap2430_glue *glue = dev_get_drvdata(dev); |
| 561 | struct musb *musb = glue_to_musb(glue); |
| 562 | |
Vladimir Zapolskiy | afb76df | 2011-12-23 18:37:18 +0200 | [diff] [blame] | 563 | if (musb) { |
| 564 | musb->context.otg_interfsel = musb_readl(musb->mregs, |
| 565 | OTG_INTERFSEL); |
Hema HK | e25bec1 | 2011-09-07 09:19:24 -0700 | [diff] [blame] | 566 | |
Vladimir Zapolskiy | afb76df | 2011-12-23 18:37:18 +0200 | [diff] [blame] | 567 | omap2430_low_level_exit(musb); |
| 568 | usb_phy_set_suspend(musb->xceiv, 1); |
| 569 | } |
Felipe Balbi | c20aebb | 2010-12-02 12:44:40 +0200 | [diff] [blame] | 570 | |
| 571 | return 0; |
| 572 | } |
| 573 | |
Hema HK | 7acc619 | 2011-02-28 14:19:34 +0530 | [diff] [blame] | 574 | static int omap2430_runtime_resume(struct device *dev) |
Felipe Balbi | c20aebb | 2010-12-02 12:44:40 +0200 | [diff] [blame] | 575 | { |
| 576 | struct omap2430_glue *glue = dev_get_drvdata(dev); |
| 577 | struct musb *musb = glue_to_musb(glue); |
Felipe Balbi | c20aebb | 2010-12-02 12:44:40 +0200 | [diff] [blame] | 578 | |
Vladimir Zapolskiy | afb76df | 2011-12-23 18:37:18 +0200 | [diff] [blame] | 579 | if (musb) { |
| 580 | omap2430_low_level_init(musb); |
| 581 | musb_writel(musb->mregs, OTG_INTERFSEL, |
| 582 | musb->context.otg_interfsel); |
Hema HK | e25bec1 | 2011-09-07 09:19:24 -0700 | [diff] [blame] | 583 | |
Vladimir Zapolskiy | afb76df | 2011-12-23 18:37:18 +0200 | [diff] [blame] | 584 | usb_phy_set_suspend(musb->xceiv, 0); |
| 585 | } |
Felipe Balbi | c20aebb | 2010-12-02 12:44:40 +0200 | [diff] [blame] | 586 | |
| 587 | return 0; |
| 588 | } |
| 589 | |
| 590 | static struct dev_pm_ops omap2430_pm_ops = { |
Hema HK | 7acc619 | 2011-02-28 14:19:34 +0530 | [diff] [blame] | 591 | .runtime_suspend = omap2430_runtime_suspend, |
| 592 | .runtime_resume = omap2430_runtime_resume, |
Felipe Balbi | c20aebb | 2010-12-02 12:44:40 +0200 | [diff] [blame] | 593 | }; |
| 594 | |
| 595 | #define DEV_PM_OPS (&omap2430_pm_ops) |
| 596 | #else |
| 597 | #define DEV_PM_OPS NULL |
| 598 | #endif |
| 599 | |
Felipe Balbi | dc09886 | 2010-12-01 15:01:11 +0200 | [diff] [blame] | 600 | static struct platform_driver omap2430_driver = { |
Felipe Balbi | e9e8c85 | 2012-01-26 12:40:23 +0200 | [diff] [blame] | 601 | .probe = omap2430_probe, |
| 602 | .remove = __devexit_p(omap2430_remove), |
Felipe Balbi | dc09886 | 2010-12-01 15:01:11 +0200 | [diff] [blame] | 603 | .driver = { |
| 604 | .name = "musb-omap2430", |
Felipe Balbi | c20aebb | 2010-12-02 12:44:40 +0200 | [diff] [blame] | 605 | .pm = DEV_PM_OPS, |
Felipe Balbi | dc09886 | 2010-12-01 15:01:11 +0200 | [diff] [blame] | 606 | }, |
| 607 | }; |
| 608 | |
| 609 | MODULE_DESCRIPTION("OMAP2PLUS MUSB Glue Layer"); |
| 610 | MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); |
| 611 | MODULE_LICENSE("GPL v2"); |
| 612 | |
| 613 | static int __init omap2430_init(void) |
| 614 | { |
Felipe Balbi | e9e8c85 | 2012-01-26 12:40:23 +0200 | [diff] [blame] | 615 | return platform_driver_register(&omap2430_driver); |
Felipe Balbi | dc09886 | 2010-12-01 15:01:11 +0200 | [diff] [blame] | 616 | } |
Kishon Vijay Abraham I | c972143 | 2012-06-22 17:40:52 +0530 | [diff] [blame] | 617 | subsys_initcall(omap2430_init); |
Felipe Balbi | dc09886 | 2010-12-01 15:01:11 +0200 | [diff] [blame] | 618 | |
| 619 | static void __exit omap2430_exit(void) |
| 620 | { |
| 621 | platform_driver_unregister(&omap2430_driver); |
| 622 | } |
| 623 | module_exit(omap2430_exit); |