Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 ST-Ericsson AB |
| 3 | * Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com> |
| 4 | * |
| 5 | * Based on omap2430.c |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | */ |
| 21 | |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/kernel.h> |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 24 | #include <linux/clk.h> |
Kishon Vijay Abraham I | ded017e | 2012-06-26 17:40:32 +0530 | [diff] [blame] | 25 | #include <linux/err.h> |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 26 | #include <linux/io.h> |
Lee Jones | 313bdb11 | 2013-05-15 10:51:48 +0100 | [diff] [blame] | 27 | #include <linux/of.h> |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 28 | #include <linux/platform_device.h> |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 29 | #include <linux/usb/musb-ux500.h> |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 30 | |
| 31 | #include "musb_core.h" |
| 32 | |
Lee Jones | a20b1b7 | 2013-05-15 10:51:44 +0100 | [diff] [blame] | 33 | static struct musb_hdrc_config ux500_musb_hdrc_config = { |
| 34 | .multipoint = true, |
| 35 | .dyn_fifo = true, |
| 36 | .num_eps = 16, |
| 37 | .ram_bits = 16, |
| 38 | }; |
| 39 | |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 40 | struct ux500_glue { |
| 41 | struct device *dev; |
| 42 | struct platform_device *musb; |
| 43 | struct clk *clk; |
| 44 | }; |
| 45 | #define glue_to_musb(g) platform_get_drvdata(g->musb) |
| 46 | |
Fabio Baltieri | 996a9d2 | 2013-03-08 10:27:06 +0800 | [diff] [blame] | 47 | static void ux500_musb_set_vbus(struct musb *musb, int is_on) |
| 48 | { |
| 49 | u8 devctl; |
| 50 | unsigned long timeout = jiffies + msecs_to_jiffies(1000); |
| 51 | /* HDRC controls CPEN, but beware current surges during device |
| 52 | * connect. They can trigger transient overcurrent conditions |
| 53 | * that must be ignored. |
| 54 | */ |
| 55 | |
| 56 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); |
| 57 | |
| 58 | if (is_on) { |
Antoine Tenart | e47d925 | 2014-10-30 18:41:13 +0100 | [diff] [blame] | 59 | if (musb->xceiv->otg->state == OTG_STATE_A_IDLE) { |
Fabio Baltieri | 996a9d2 | 2013-03-08 10:27:06 +0800 | [diff] [blame] | 60 | /* start the session */ |
| 61 | devctl |= MUSB_DEVCTL_SESSION; |
| 62 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); |
| 63 | /* |
| 64 | * Wait for the musb to set as A device to enable the |
| 65 | * VBUS |
| 66 | */ |
| 67 | while (musb_readb(musb->mregs, MUSB_DEVCTL) & 0x80) { |
| 68 | |
| 69 | if (time_after(jiffies, timeout)) { |
| 70 | dev_err(musb->controller, |
| 71 | "configured as A device timeout"); |
| 72 | break; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | } else { |
| 77 | musb->is_active = 1; |
| 78 | musb->xceiv->otg->default_a = 1; |
Antoine Tenart | e47d925 | 2014-10-30 18:41:13 +0100 | [diff] [blame] | 79 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; |
Fabio Baltieri | 996a9d2 | 2013-03-08 10:27:06 +0800 | [diff] [blame] | 80 | devctl |= MUSB_DEVCTL_SESSION; |
| 81 | MUSB_HST_MODE(musb); |
| 82 | } |
| 83 | } else { |
| 84 | musb->is_active = 0; |
| 85 | |
| 86 | /* NOTE: we're skipping A_WAIT_VFALL -> A_IDLE and jumping |
| 87 | * right to B_IDLE... |
| 88 | */ |
| 89 | musb->xceiv->otg->default_a = 0; |
| 90 | devctl &= ~MUSB_DEVCTL_SESSION; |
| 91 | MUSB_DEV_MODE(musb); |
| 92 | } |
| 93 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); |
| 94 | |
| 95 | /* |
| 96 | * Devctl values will be updated after vbus goes below |
| 97 | * session_valid. The time taken depends on the capacitance |
| 98 | * on VBUS line. The max discharge time can be upto 1 sec |
| 99 | * as per the spec. Typically on our platform, it is 200ms |
| 100 | */ |
| 101 | if (!is_on) |
| 102 | mdelay(200); |
| 103 | |
| 104 | dev_dbg(musb->controller, "VBUS %s, devctl %02x\n", |
Antoine Tenart | e47d925 | 2014-10-30 18:41:13 +0100 | [diff] [blame] | 105 | usb_otg_state_string(musb->xceiv->otg->state), |
Fabio Baltieri | 996a9d2 | 2013-03-08 10:27:06 +0800 | [diff] [blame] | 106 | musb_readb(musb->mregs, MUSB_DEVCTL)); |
| 107 | } |
| 108 | |
Fabio Baltieri | 0135522 | 2013-03-08 10:27:07 +0800 | [diff] [blame] | 109 | static int musb_otg_notifications(struct notifier_block *nb, |
| 110 | unsigned long event, void *unused) |
| 111 | { |
| 112 | struct musb *musb = container_of(nb, struct musb, nb); |
| 113 | |
| 114 | dev_dbg(musb->controller, "musb_otg_notifications %ld %s\n", |
Antoine Tenart | e47d925 | 2014-10-30 18:41:13 +0100 | [diff] [blame] | 115 | event, usb_otg_state_string(musb->xceiv->otg->state)); |
Fabio Baltieri | 0135522 | 2013-03-08 10:27:07 +0800 | [diff] [blame] | 116 | |
| 117 | switch (event) { |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 118 | case UX500_MUSB_ID: |
Fabio Baltieri | 0135522 | 2013-03-08 10:27:07 +0800 | [diff] [blame] | 119 | dev_dbg(musb->controller, "ID GND\n"); |
| 120 | ux500_musb_set_vbus(musb, 1); |
| 121 | break; |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 122 | case UX500_MUSB_VBUS: |
Fabio Baltieri | 0135522 | 2013-03-08 10:27:07 +0800 | [diff] [blame] | 123 | dev_dbg(musb->controller, "VBUS Connect\n"); |
Fabio Baltieri | 0135522 | 2013-03-08 10:27:07 +0800 | [diff] [blame] | 124 | break; |
Fabio Baltieri | af6882b | 2013-03-08 10:27:09 +0800 | [diff] [blame] | 125 | case UX500_MUSB_NONE: |
Fabio Baltieri | 0135522 | 2013-03-08 10:27:07 +0800 | [diff] [blame] | 126 | dev_dbg(musb->controller, "VBUS Disconnect\n"); |
| 127 | if (is_host_active(musb)) |
| 128 | ux500_musb_set_vbus(musb, 0); |
| 129 | else |
Antoine Tenart | e47d925 | 2014-10-30 18:41:13 +0100 | [diff] [blame] | 130 | musb->xceiv->otg->state = OTG_STATE_B_IDLE; |
Fabio Baltieri | 0135522 | 2013-03-08 10:27:07 +0800 | [diff] [blame] | 131 | break; |
| 132 | default: |
| 133 | dev_dbg(musb->controller, "ID float\n"); |
| 134 | return NOTIFY_DONE; |
| 135 | } |
| 136 | return NOTIFY_OK; |
| 137 | } |
| 138 | |
Philippe De Swert | baef653 | 2012-11-06 15:32:13 +0200 | [diff] [blame] | 139 | static irqreturn_t ux500_musb_interrupt(int irq, void *__hci) |
| 140 | { |
| 141 | unsigned long flags; |
| 142 | irqreturn_t retval = IRQ_NONE; |
| 143 | struct musb *musb = __hci; |
| 144 | |
| 145 | spin_lock_irqsave(&musb->lock, flags); |
| 146 | |
| 147 | musb->int_usb = musb_readb(musb->mregs, MUSB_INTRUSB); |
| 148 | musb->int_tx = musb_readw(musb->mregs, MUSB_INTRTX); |
| 149 | musb->int_rx = musb_readw(musb->mregs, MUSB_INTRRX); |
| 150 | |
| 151 | if (musb->int_usb || musb->int_tx || musb->int_rx) |
| 152 | retval = musb_interrupt(musb); |
| 153 | |
| 154 | spin_unlock_irqrestore(&musb->lock, flags); |
| 155 | |
| 156 | return retval; |
| 157 | } |
| 158 | |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 159 | static int ux500_musb_init(struct musb *musb) |
| 160 | { |
Fabio Baltieri | 0135522 | 2013-03-08 10:27:07 +0800 | [diff] [blame] | 161 | int status; |
| 162 | |
Kishon Vijay Abraham I | 662dca5 | 2012-06-22 17:02:46 +0530 | [diff] [blame] | 163 | musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); |
Kishon Vijay Abraham I | ded017e | 2012-06-26 17:40:32 +0530 | [diff] [blame] | 164 | if (IS_ERR_OR_NULL(musb->xceiv)) { |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 165 | pr_err("HS USB OTG: no transceiver configured\n"); |
Ming Lei | 25736e0 | 2013-01-04 23:13:58 +0800 | [diff] [blame] | 166 | return -EPROBE_DEFER; |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 167 | } |
| 168 | |
Fabio Baltieri | 0135522 | 2013-03-08 10:27:07 +0800 | [diff] [blame] | 169 | musb->nb.notifier_call = musb_otg_notifications; |
| 170 | status = usb_register_notifier(musb->xceiv, &musb->nb); |
| 171 | if (status < 0) { |
| 172 | dev_dbg(musb->controller, "notification register failed\n"); |
| 173 | return status; |
| 174 | } |
| 175 | |
Philippe De Swert | baef653 | 2012-11-06 15:32:13 +0200 | [diff] [blame] | 176 | musb->isr = ux500_musb_interrupt; |
| 177 | |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 178 | return 0; |
| 179 | } |
| 180 | |
| 181 | static int ux500_musb_exit(struct musb *musb) |
| 182 | { |
Fabio Baltieri | 0135522 | 2013-03-08 10:27:07 +0800 | [diff] [blame] | 183 | usb_unregister_notifier(musb->xceiv, &musb->nb); |
| 184 | |
Kishon Vijay Abraham I | 721002e | 2012-06-22 17:02:45 +0530 | [diff] [blame] | 185 | usb_put_phy(musb->xceiv); |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 186 | |
| 187 | return 0; |
| 188 | } |
| 189 | |
| 190 | static const struct musb_platform_ops ux500_ops = { |
Tony Lindgren | f8e9f34f | 2015-05-01 12:29:27 -0700 | [diff] [blame] | 191 | .quirks = MUSB_DMA_UX500 | MUSB_INDEXED_EP, |
Tony Lindgren | 7f6283e | 2015-05-01 12:29:28 -0700 | [diff] [blame] | 192 | #ifdef CONFIG_USB_UX500_DMA |
| 193 | .dma_init = ux500_dma_controller_create, |
| 194 | .dma_exit = ux500_dma_controller_destroy, |
| 195 | #endif |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 196 | .init = ux500_musb_init, |
| 197 | .exit = ux500_musb_exit, |
Tony Lindgren | 8a77f05 | 2014-11-24 11:05:04 -0800 | [diff] [blame] | 198 | .fifo_mode = 5, |
Fabio Baltieri | 996a9d2 | 2013-03-08 10:27:06 +0800 | [diff] [blame] | 199 | |
| 200 | .set_vbus = ux500_musb_set_vbus, |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 201 | }; |
| 202 | |
Lee Jones | 313bdb11 | 2013-05-15 10:51:48 +0100 | [diff] [blame] | 203 | static struct musb_hdrc_platform_data * |
| 204 | ux500_of_probe(struct platform_device *pdev, struct device_node *np) |
| 205 | { |
| 206 | struct musb_hdrc_platform_data *pdata; |
| 207 | const char *mode; |
| 208 | int strlen; |
| 209 | |
| 210 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
| 211 | if (!pdata) |
| 212 | return NULL; |
| 213 | |
| 214 | mode = of_get_property(np, "dr_mode", &strlen); |
| 215 | if (!mode) { |
| 216 | dev_err(&pdev->dev, "No 'dr_mode' property found\n"); |
| 217 | return NULL; |
| 218 | } |
| 219 | |
| 220 | if (strlen > 0) { |
| 221 | if (!strcmp(mode, "host")) |
| 222 | pdata->mode = MUSB_HOST; |
| 223 | if (!strcmp(mode, "otg")) |
| 224 | pdata->mode = MUSB_OTG; |
| 225 | if (!strcmp(mode, "peripheral")) |
| 226 | pdata->mode = MUSB_PERIPHERAL; |
| 227 | } |
| 228 | |
| 229 | return pdata; |
| 230 | } |
| 231 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 232 | static int ux500_probe(struct platform_device *pdev) |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 233 | { |
Felipe Balbi | 09fc7d2 | 2013-04-24 17:21:42 +0300 | [diff] [blame] | 234 | struct resource musb_resources[2]; |
Jingoo Han | c1a7d67 | 2013-07-30 17:03:12 +0900 | [diff] [blame] | 235 | struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); |
Lee Jones | 313bdb11 | 2013-05-15 10:51:48 +0100 | [diff] [blame] | 236 | struct device_node *np = pdev->dev.of_node; |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 237 | struct platform_device *musb; |
| 238 | struct ux500_glue *glue; |
| 239 | struct clk *clk; |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 240 | int ret = -ENOMEM; |
| 241 | |
Lee Jones | 313bdb11 | 2013-05-15 10:51:48 +0100 | [diff] [blame] | 242 | if (!pdata) { |
| 243 | if (np) { |
| 244 | pdata = ux500_of_probe(pdev, np); |
| 245 | if (!pdata) |
| 246 | goto err0; |
| 247 | |
| 248 | pdev->dev.platform_data = pdata; |
| 249 | } else { |
| 250 | dev_err(&pdev->dev, "no pdata or device tree found\n"); |
| 251 | goto err0; |
| 252 | } |
| 253 | } |
| 254 | |
Himangi Saraogi | d7dc5bd | 2014-06-21 02:10:25 +0530 | [diff] [blame] | 255 | glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); |
Peter Chen | 24c611b | 2014-10-14 15:56:07 +0800 | [diff] [blame] | 256 | if (!glue) |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 257 | goto err0; |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 258 | |
Sebastian Andrzej Siewior | 2f77116 | 2012-10-31 16:12:43 +0100 | [diff] [blame] | 259 | musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 260 | if (!musb) { |
| 261 | dev_err(&pdev->dev, "failed to allocate musb device\n"); |
Himangi Saraogi | d7dc5bd | 2014-06-21 02:10:25 +0530 | [diff] [blame] | 262 | goto err0; |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 263 | } |
| 264 | |
Himangi Saraogi | d7dc5bd | 2014-06-21 02:10:25 +0530 | [diff] [blame] | 265 | clk = devm_clk_get(&pdev->dev, NULL); |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 266 | if (IS_ERR(clk)) { |
| 267 | dev_err(&pdev->dev, "failed to get clock\n"); |
| 268 | ret = PTR_ERR(clk); |
Himangi Saraogi | d7dc5bd | 2014-06-21 02:10:25 +0530 | [diff] [blame] | 269 | goto err1; |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 270 | } |
| 271 | |
Fabio Baltieri | 99d17cf | 2013-01-07 17:47:41 +0100 | [diff] [blame] | 272 | ret = clk_prepare_enable(clk); |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 273 | if (ret) { |
| 274 | dev_err(&pdev->dev, "failed to enable clock\n"); |
Himangi Saraogi | d7dc5bd | 2014-06-21 02:10:25 +0530 | [diff] [blame] | 275 | goto err1; |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | musb->dev.parent = &pdev->dev; |
Lee Jones | 1e6eebb | 2013-05-15 10:51:45 +0100 | [diff] [blame] | 279 | musb->dev.dma_mask = &pdev->dev.coherent_dma_mask; |
Mian Yousaf Kaukab | 8726606 | 2011-03-15 16:24:29 +0100 | [diff] [blame] | 280 | musb->dev.coherent_dma_mask = pdev->dev.coherent_dma_mask; |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 281 | |
| 282 | glue->dev = &pdev->dev; |
| 283 | glue->musb = musb; |
| 284 | glue->clk = clk; |
| 285 | |
| 286 | pdata->platform_ops = &ux500_ops; |
Lee Jones | a20b1b7 | 2013-05-15 10:51:44 +0100 | [diff] [blame] | 287 | pdata->config = &ux500_musb_hdrc_config; |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 288 | |
| 289 | platform_set_drvdata(pdev, glue); |
| 290 | |
Felipe Balbi | 09fc7d2 | 2013-04-24 17:21:42 +0300 | [diff] [blame] | 291 | memset(musb_resources, 0x00, sizeof(*musb_resources) * |
| 292 | ARRAY_SIZE(musb_resources)); |
| 293 | |
| 294 | musb_resources[0].name = pdev->resource[0].name; |
| 295 | musb_resources[0].start = pdev->resource[0].start; |
| 296 | musb_resources[0].end = pdev->resource[0].end; |
| 297 | musb_resources[0].flags = pdev->resource[0].flags; |
| 298 | |
| 299 | musb_resources[1].name = pdev->resource[1].name; |
| 300 | musb_resources[1].start = pdev->resource[1].start; |
| 301 | musb_resources[1].end = pdev->resource[1].end; |
| 302 | musb_resources[1].flags = pdev->resource[1].flags; |
| 303 | |
| 304 | ret = platform_device_add_resources(musb, musb_resources, |
| 305 | ARRAY_SIZE(musb_resources)); |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 306 | if (ret) { |
| 307 | dev_err(&pdev->dev, "failed to add resources\n"); |
Himangi Saraogi | d7dc5bd | 2014-06-21 02:10:25 +0530 | [diff] [blame] | 308 | goto err2; |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); |
| 312 | if (ret) { |
| 313 | dev_err(&pdev->dev, "failed to add platform_data\n"); |
Himangi Saraogi | d7dc5bd | 2014-06-21 02:10:25 +0530 | [diff] [blame] | 314 | goto err2; |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | ret = platform_device_add(musb); |
| 318 | if (ret) { |
| 319 | dev_err(&pdev->dev, "failed to register musb device\n"); |
Himangi Saraogi | d7dc5bd | 2014-06-21 02:10:25 +0530 | [diff] [blame] | 320 | goto err2; |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | return 0; |
| 324 | |
Himangi Saraogi | d7dc5bd | 2014-06-21 02:10:25 +0530 | [diff] [blame] | 325 | err2: |
Fabio Baltieri | 99d17cf | 2013-01-07 17:47:41 +0100 | [diff] [blame] | 326 | clk_disable_unprepare(clk); |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 327 | |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 328 | err1: |
Himangi Saraogi | d7dc5bd | 2014-06-21 02:10:25 +0530 | [diff] [blame] | 329 | platform_device_put(musb); |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 330 | |
| 331 | err0: |
| 332 | return ret; |
| 333 | } |
| 334 | |
Bill Pemberton | fb4e98a | 2012-11-19 13:26:20 -0500 | [diff] [blame] | 335 | static int ux500_remove(struct platform_device *pdev) |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 336 | { |
| 337 | struct ux500_glue *glue = platform_get_drvdata(pdev); |
| 338 | |
Wei Yongjun | 4b0de6f | 2012-10-23 13:36:43 +0800 | [diff] [blame] | 339 | platform_device_unregister(glue->musb); |
Fabio Baltieri | 99d17cf | 2013-01-07 17:47:41 +0100 | [diff] [blame] | 340 | clk_disable_unprepare(glue->clk); |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 341 | |
| 342 | return 0; |
| 343 | } |
| 344 | |
Felipe Balbi | 30d0922 | 2015-05-27 12:25:40 -0500 | [diff] [blame] | 345 | #ifdef CONFIG_PM_SLEEP |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 346 | static int ux500_suspend(struct device *dev) |
| 347 | { |
| 348 | struct ux500_glue *glue = dev_get_drvdata(dev); |
| 349 | struct musb *musb = glue_to_musb(glue); |
| 350 | |
Ulf Hansson | 79c5623 | 2016-01-25 13:01:29 +0100 | [diff] [blame] | 351 | if (musb) |
| 352 | usb_phy_set_suspend(musb->xceiv, 1); |
| 353 | |
Fabio Baltieri | 99d17cf | 2013-01-07 17:47:41 +0100 | [diff] [blame] | 354 | clk_disable_unprepare(glue->clk); |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 355 | |
| 356 | return 0; |
| 357 | } |
| 358 | |
| 359 | static int ux500_resume(struct device *dev) |
| 360 | { |
| 361 | struct ux500_glue *glue = dev_get_drvdata(dev); |
| 362 | struct musb *musb = glue_to_musb(glue); |
| 363 | int ret; |
| 364 | |
Fabio Baltieri | 99d17cf | 2013-01-07 17:47:41 +0100 | [diff] [blame] | 365 | ret = clk_prepare_enable(glue->clk); |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 366 | if (ret) { |
| 367 | dev_err(dev, "failed to enable clock\n"); |
| 368 | return ret; |
| 369 | } |
| 370 | |
Ulf Hansson | 79c5623 | 2016-01-25 13:01:29 +0100 | [diff] [blame] | 371 | if (musb) |
| 372 | usb_phy_set_suspend(musb->xceiv, 0); |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 373 | |
| 374 | return 0; |
| 375 | } |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 376 | #endif |
| 377 | |
Daniel Mack | a89adb0 | 2013-09-30 21:02:09 +0200 | [diff] [blame] | 378 | static SIMPLE_DEV_PM_OPS(ux500_pm_ops, ux500_suspend, ux500_resume); |
| 379 | |
Lee Jones | 313bdb11 | 2013-05-15 10:51:48 +0100 | [diff] [blame] | 380 | static const struct of_device_id ux500_match[] = { |
| 381 | { .compatible = "stericsson,db8500-musb", }, |
| 382 | {} |
| 383 | }; |
| 384 | |
Luis de Bethencourt | 523d5da | 2015-08-27 17:45:37 +0200 | [diff] [blame] | 385 | MODULE_DEVICE_TABLE(of, ux500_match); |
| 386 | |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 387 | static struct platform_driver ux500_driver = { |
Felipe Balbi | e9e8c85 | 2012-01-26 12:40:23 +0200 | [diff] [blame] | 388 | .probe = ux500_probe, |
Bill Pemberton | 7690417 | 2012-11-19 13:21:08 -0500 | [diff] [blame] | 389 | .remove = ux500_remove, |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 390 | .driver = { |
| 391 | .name = "musb-ux500", |
Daniel Mack | a89adb0 | 2013-09-30 21:02:09 +0200 | [diff] [blame] | 392 | .pm = &ux500_pm_ops, |
Lee Jones | 313bdb11 | 2013-05-15 10:51:48 +0100 | [diff] [blame] | 393 | .of_match_table = ux500_match, |
Mian Yousaf Kaukab | 4bc36fd | 2010-12-09 13:05:01 +0100 | [diff] [blame] | 394 | }, |
| 395 | }; |
| 396 | |
| 397 | MODULE_DESCRIPTION("UX500 MUSB Glue Layer"); |
| 398 | MODULE_AUTHOR("Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>"); |
| 399 | MODULE_LICENSE("GPL v2"); |
Srinivas Kandagatla | 0e7090a | 2012-10-10 19:37:21 +0100 | [diff] [blame] | 400 | module_platform_driver(ux500_driver); |