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