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