GNU Linux-libre 4.19.245-gnu1
[releases.git] / drivers / phy / motorola / phy-mapphone-mdm6600.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Motorola Mapphone MDM6600 modem GPIO controlled USB PHY driver
4  * Copyright (C) 2018 Tony Lindgren <tony@atomide.com>
5  */
6
7 #include <linux/delay.h>
8 #include <linux/err.h>
9 #include <linux/io.h>
10 #include <linux/interrupt.h>
11 #include <linux/module.h>
12 #include <linux/of.h>
13 #include <linux/platform_device.h>
14 #include <linux/slab.h>
15
16 #include <linux/gpio/consumer.h>
17 #include <linux/of_platform.h>
18 #include <linux/phy/phy.h>
19
20 #define PHY_MDM6600_PHY_DELAY_MS        4000    /* PHY enable 2.2s to 3.5s */
21 #define PHY_MDM6600_ENABLED_DELAY_MS    8000    /* 8s more total for MDM6600 */
22 #define PHY_MDM6600_WAKE_KICK_MS        600     /* time on after GPIO toggle */
23 #define MDM6600_MODEM_IDLE_DELAY_MS     1000    /* modem after USB suspend */
24 #define MDM6600_MODEM_WAKE_DELAY_MS     200     /* modem response after idle */
25
26 enum phy_mdm6600_ctrl_lines {
27         PHY_MDM6600_ENABLE,                     /* USB PHY enable */
28         PHY_MDM6600_POWER,                      /* Device power */
29         PHY_MDM6600_RESET,                      /* Device reset */
30         PHY_MDM6600_NR_CTRL_LINES,
31 };
32
33 enum phy_mdm6600_bootmode_lines {
34         PHY_MDM6600_MODE0,                      /* out USB mode0 and OOB wake */
35         PHY_MDM6600_MODE1,                      /* out USB mode1, in OOB wake */
36         PHY_MDM6600_NR_MODE_LINES,
37 };
38
39 enum phy_mdm6600_cmd_lines {
40         PHY_MDM6600_CMD0,
41         PHY_MDM6600_CMD1,
42         PHY_MDM6600_CMD2,
43         PHY_MDM6600_NR_CMD_LINES,
44 };
45
46 enum phy_mdm6600_status_lines {
47         PHY_MDM6600_STATUS0,
48         PHY_MDM6600_STATUS1,
49         PHY_MDM6600_STATUS2,
50         PHY_MDM6600_NR_STATUS_LINES,
51 };
52
53 /*
54  * MDM6600 command codes. These are based on Motorola Mapphone Linux
55  * kernel tree.
56  */
57 enum phy_mdm6600_cmd {
58         PHY_MDM6600_CMD_BP_PANIC_ACK,
59         PHY_MDM6600_CMD_DATA_ONLY_BYPASS,       /* Reroute USB to CPCAP PHY */
60         PHY_MDM6600_CMD_FULL_BYPASS,            /* Reroute USB to CPCAP PHY */
61         PHY_MDM6600_CMD_NO_BYPASS,              /* Request normal USB mode */
62         PHY_MDM6600_CMD_BP_SHUTDOWN_REQ,        /* Request device power off */
63         PHY_MDM6600_CMD_BP_UNKNOWN_5,
64         PHY_MDM6600_CMD_BP_UNKNOWN_6,
65         PHY_MDM6600_CMD_UNDEFINED,
66 };
67
68 /*
69  * MDM6600 status codes. These are based on Motorola Mapphone Linux
70  * kernel tree.
71  */
72 enum phy_mdm6600_status {
73         PHY_MDM6600_STATUS_PANIC,               /* Seems to be really off */
74         PHY_MDM6600_STATUS_PANIC_BUSY_WAIT,
75         PHY_MDM6600_STATUS_QC_DLOAD,
76         PHY_MDM6600_STATUS_RAM_DOWNLOADER,      /* MDM6600 USB flashing mode */
77         PHY_MDM6600_STATUS_PHONE_CODE_AWAKE,    /* MDM6600 normal USB mode */
78         PHY_MDM6600_STATUS_PHONE_CODE_ASLEEP,
79         PHY_MDM6600_STATUS_SHUTDOWN_ACK,
80         PHY_MDM6600_STATUS_UNDEFINED,
81 };
82
83 static const char * const
84 phy_mdm6600_status_name[] = {
85         "off", "busy", "qc_dl", "ram_dl", "awake",
86         "asleep", "shutdown", "undefined",
87 };
88
89 struct phy_mdm6600 {
90         struct device *dev;
91         struct phy *generic_phy;
92         struct phy_provider *phy_provider;
93         struct gpio_desc *ctrl_gpios[PHY_MDM6600_NR_CTRL_LINES];
94         struct gpio_descs *mode_gpios;
95         struct gpio_descs *status_gpios;
96         struct gpio_descs *cmd_gpios;
97         struct delayed_work bootup_work;
98         struct delayed_work status_work;
99         struct delayed_work modem_wake_work;
100         struct completion ack;
101         bool enabled;                           /* mdm6600 phy enabled */
102         bool running;                           /* mdm6600 boot done */
103         bool awake;                             /* mdm6600 respnds on n_gsm */
104         int status;
105 };
106
107 static int phy_mdm6600_init(struct phy *x)
108 {
109         struct phy_mdm6600 *ddata = phy_get_drvdata(x);
110         struct gpio_desc *enable_gpio = ddata->ctrl_gpios[PHY_MDM6600_ENABLE];
111
112         if (!ddata->enabled)
113                 return -EPROBE_DEFER;
114
115         gpiod_set_value_cansleep(enable_gpio, 0);
116
117         return 0;
118 }
119
120 static int phy_mdm6600_power_on(struct phy *x)
121 {
122         struct phy_mdm6600 *ddata = phy_get_drvdata(x);
123         struct gpio_desc *enable_gpio = ddata->ctrl_gpios[PHY_MDM6600_ENABLE];
124
125         if (!ddata->enabled)
126                 return -ENODEV;
127
128         gpiod_set_value_cansleep(enable_gpio, 1);
129
130         return 0;
131 }
132
133 static int phy_mdm6600_power_off(struct phy *x)
134 {
135         struct phy_mdm6600 *ddata = phy_get_drvdata(x);
136         struct gpio_desc *enable_gpio = ddata->ctrl_gpios[PHY_MDM6600_ENABLE];
137
138         if (!ddata->enabled)
139                 return -ENODEV;
140
141         gpiod_set_value_cansleep(enable_gpio, 0);
142
143         return 0;
144 }
145
146 static const struct phy_ops gpio_usb_ops = {
147         .init = phy_mdm6600_init,
148         .power_on = phy_mdm6600_power_on,
149         .power_off = phy_mdm6600_power_off,
150         .owner = THIS_MODULE,
151 };
152
153 /**
154  * phy_mdm6600_cmd() - send a command request to mdm6600
155  * @ddata: device driver data
156  *
157  * Configures the three command request GPIOs to the specified value.
158  */
159 static void phy_mdm6600_cmd(struct phy_mdm6600 *ddata, int val)
160 {
161         int values[PHY_MDM6600_NR_CMD_LINES];
162         int i;
163
164         val &= (1 << PHY_MDM6600_NR_CMD_LINES) - 1;
165         for (i = 0; i < PHY_MDM6600_NR_CMD_LINES; i++)
166                 values[i] = (val & BIT(i)) >> i;
167
168         gpiod_set_array_value_cansleep(PHY_MDM6600_NR_CMD_LINES,
169                                        ddata->cmd_gpios->desc, values);
170 }
171
172 /**
173  * phy_mdm6600_status() - read mdm6600 status lines
174  * @ddata: device driver data
175  */
176 static void phy_mdm6600_status(struct work_struct *work)
177 {
178         struct phy_mdm6600 *ddata;
179         struct device *dev;
180         int values[PHY_MDM6600_NR_STATUS_LINES];
181         int error, i, val = 0;
182
183         ddata = container_of(work, struct phy_mdm6600, status_work.work);
184         dev = ddata->dev;
185
186         error = gpiod_get_array_value_cansleep(PHY_MDM6600_NR_STATUS_LINES,
187                                                ddata->status_gpios->desc,
188                                                values);
189         if (error)
190                 return;
191
192         for (i = 0; i < PHY_MDM6600_NR_STATUS_LINES; i++) {
193                 val |= values[i] << i;
194                 dev_dbg(ddata->dev, "XXX %s: i: %i values[i]: %i val: %i\n",
195                         __func__, i, values[i], val);
196         }
197         ddata->status = val;
198
199         dev_info(dev, "modem status: %i %s\n",
200                  ddata->status,
201                  phy_mdm6600_status_name[ddata->status & 7]);
202         complete(&ddata->ack);
203 }
204
205 static irqreturn_t phy_mdm6600_irq_thread(int irq, void *data)
206 {
207         struct phy_mdm6600 *ddata = data;
208
209         schedule_delayed_work(&ddata->status_work, msecs_to_jiffies(10));
210
211         return IRQ_HANDLED;
212 }
213
214 /**
215  * phy_mdm6600_wakeirq_thread - handle mode1 line OOB wake after booting
216  * @irq: interrupt
217  * @data: interrupt handler data
218  *
219  * GPIO mode1 is used initially as output to configure the USB boot
220  * mode for mdm6600. After booting it is used as input for OOB wake
221  * signal from mdm6600 to the SoC. Just use it for debug info only
222  * for now.
223  */
224 static irqreturn_t phy_mdm6600_wakeirq_thread(int irq, void *data)
225 {
226         struct phy_mdm6600 *ddata = data;
227         struct gpio_desc *mode_gpio1;
228         int error, wakeup;
229
230         mode_gpio1 = ddata->mode_gpios->desc[PHY_MDM6600_MODE1];
231         wakeup = gpiod_get_value(mode_gpio1);
232         if (!wakeup)
233                 return IRQ_NONE;
234
235         dev_dbg(ddata->dev, "OOB wake on mode_gpio1: %i\n", wakeup);
236         error = pm_runtime_get_sync(ddata->dev);
237         if (error < 0) {
238                 pm_runtime_put_noidle(ddata->dev);
239
240                 return IRQ_NONE;
241         }
242
243         /* Just wake-up and kick the autosuspend timer */
244         pm_runtime_mark_last_busy(ddata->dev);
245         pm_runtime_put_autosuspend(ddata->dev);
246
247         return IRQ_HANDLED;
248 }
249
250 /**
251  * phy_mdm6600_init_irq() - initialize mdm6600 status IRQ lines
252  * @ddata: device driver data
253  */
254 static void phy_mdm6600_init_irq(struct phy_mdm6600 *ddata)
255 {
256         struct device *dev = ddata->dev;
257         int i, error, irq;
258
259         for (i = PHY_MDM6600_STATUS0;
260              i <= PHY_MDM6600_STATUS2; i++) {
261                 struct gpio_desc *gpio = ddata->status_gpios->desc[i];
262
263                 irq = gpiod_to_irq(gpio);
264                 if (irq <= 0)
265                         continue;
266
267                 error = devm_request_threaded_irq(dev, irq, NULL,
268                                         phy_mdm6600_irq_thread,
269                                         IRQF_TRIGGER_RISING |
270                                         IRQF_TRIGGER_FALLING |
271                                         IRQF_ONESHOT,
272                                         "mdm6600",
273                                         ddata);
274                 if (error)
275                         dev_warn(dev, "no modem status irq%i: %i\n",
276                                  irq, error);
277         }
278 }
279
280 struct phy_mdm6600_map {
281         const char *name;
282         int direction;
283 };
284
285 static const struct phy_mdm6600_map
286 phy_mdm6600_ctrl_gpio_map[PHY_MDM6600_NR_CTRL_LINES] = {
287         { "enable", GPIOD_OUT_LOW, },           /* low = phy disabled */
288         { "power", GPIOD_OUT_LOW, },            /* low = off */
289         { "reset", GPIOD_OUT_HIGH, },           /* high = reset */
290 };
291
292 /**
293  * phy_mdm6600_init_lines() - initialize mdm6600 GPIO lines
294  * @ddata: device driver data
295  */
296 static int phy_mdm6600_init_lines(struct phy_mdm6600 *ddata)
297 {
298         struct device *dev = ddata->dev;
299         int i;
300
301         /* MDM6600 control lines */
302         for (i = 0; i < ARRAY_SIZE(phy_mdm6600_ctrl_gpio_map); i++) {
303                 const struct phy_mdm6600_map *map =
304                         &phy_mdm6600_ctrl_gpio_map[i];
305                 struct gpio_desc **gpio = &ddata->ctrl_gpios[i];
306
307                 *gpio = devm_gpiod_get(dev, map->name, map->direction);
308                 if (IS_ERR(*gpio)) {
309                         dev_info(dev, "gpio %s error %li\n",
310                                  map->name, PTR_ERR(*gpio));
311                         return PTR_ERR(*gpio);
312                 }
313         }
314
315         /* MDM6600 USB start-up mode output lines */
316         ddata->mode_gpios = devm_gpiod_get_array(dev, "motorola,mode",
317                                                  GPIOD_OUT_LOW);
318         if (IS_ERR(ddata->mode_gpios))
319                 return PTR_ERR(ddata->mode_gpios);
320
321         if (ddata->mode_gpios->ndescs != PHY_MDM6600_NR_MODE_LINES)
322                 return -EINVAL;
323
324         /* MDM6600 status input lines */
325         ddata->status_gpios = devm_gpiod_get_array(dev, "motorola,status",
326                                                    GPIOD_IN);
327         if (IS_ERR(ddata->status_gpios))
328                 return PTR_ERR(ddata->status_gpios);
329
330         if (ddata->status_gpios->ndescs != PHY_MDM6600_NR_STATUS_LINES)
331                 return -EINVAL;
332
333         /* MDM6600 cmd output lines */
334         ddata->cmd_gpios = devm_gpiod_get_array(dev, "motorola,cmd",
335                                                 GPIOD_OUT_LOW);
336         if (IS_ERR(ddata->cmd_gpios))
337                 return PTR_ERR(ddata->cmd_gpios);
338
339         if (ddata->cmd_gpios->ndescs != PHY_MDM6600_NR_CMD_LINES)
340                 return -EINVAL;
341
342         return 0;
343 }
344
345 /**
346  * phy_mdm6600_device_power_on() - power on mdm6600 device
347  * @ddata: device driver data
348  *
349  * To get the integrated USB phy in MDM6600 takes some hoops. We must ensure
350  * the shared USB bootmode GPIOs are configured, then request modem start-up,
351  * reset and power-up.. And then we need to recycle the shared USB bootmode
352  * GPIOs as they are also used for Out of Band (OOB) wake for the USB and
353  * TS 27.010 serial mux.
354  */
355 static int phy_mdm6600_device_power_on(struct phy_mdm6600 *ddata)
356 {
357         struct gpio_desc *mode_gpio0, *mode_gpio1, *reset_gpio, *power_gpio;
358         int error = 0, wakeirq;
359
360         mode_gpio0 = ddata->mode_gpios->desc[PHY_MDM6600_MODE0];
361         mode_gpio1 = ddata->mode_gpios->desc[PHY_MDM6600_MODE1];
362         reset_gpio = ddata->ctrl_gpios[PHY_MDM6600_RESET];
363         power_gpio = ddata->ctrl_gpios[PHY_MDM6600_POWER];
364
365         /*
366          * Shared GPIOs must be low for normal USB mode. After booting
367          * they are used for OOB wake signaling. These can be also used
368          * to configure USB flashing mode later on based on a module
369          * parameter.
370          */
371         gpiod_set_value_cansleep(mode_gpio0, 0);
372         gpiod_set_value_cansleep(mode_gpio1, 0);
373
374         /* Request start-up mode */
375         phy_mdm6600_cmd(ddata, PHY_MDM6600_CMD_NO_BYPASS);
376
377         /* Request a reset first */
378         gpiod_set_value_cansleep(reset_gpio, 0);
379         msleep(100);
380
381         /* Toggle power GPIO to request mdm6600 to start */
382         gpiod_set_value_cansleep(power_gpio, 1);
383         msleep(100);
384         gpiod_set_value_cansleep(power_gpio, 0);
385
386         /*
387          * Looks like the USB PHY needs between 2.2 to 4 seconds.
388          * If we try to use it before that, we will get L3 errors
389          * from omap-usb-host trying to access the PHY. See also
390          * phy_mdm6600_init() for -EPROBE_DEFER.
391          */
392         msleep(PHY_MDM6600_PHY_DELAY_MS);
393         ddata->enabled = true;
394
395         /* Booting up the rest of MDM6600 will take total about 8 seconds */
396         dev_info(ddata->dev, "Waiting for power up request to complete..\n");
397         if (wait_for_completion_timeout(&ddata->ack,
398                         msecs_to_jiffies(PHY_MDM6600_ENABLED_DELAY_MS))) {
399                 if (ddata->status > PHY_MDM6600_STATUS_PANIC &&
400                     ddata->status < PHY_MDM6600_STATUS_SHUTDOWN_ACK)
401                         dev_info(ddata->dev, "Powered up OK\n");
402         } else {
403                 ddata->enabled = false;
404                 error = -ETIMEDOUT;
405                 dev_err(ddata->dev, "Timed out powering up\n");
406         }
407
408         /* Reconfigure mode1 GPIO as input for OOB wake */
409         gpiod_direction_input(mode_gpio1);
410
411         wakeirq = gpiod_to_irq(mode_gpio1);
412         if (wakeirq <= 0)
413                 return wakeirq;
414
415         error = devm_request_threaded_irq(ddata->dev, wakeirq, NULL,
416                                           phy_mdm6600_wakeirq_thread,
417                                           IRQF_TRIGGER_RISING |
418                                           IRQF_TRIGGER_FALLING |
419                                           IRQF_ONESHOT,
420                                           "mdm6600-wake",
421                                           ddata);
422         if (error)
423                 dev_warn(ddata->dev, "no modem wakeirq irq%i: %i\n",
424                          wakeirq, error);
425
426         ddata->running = true;
427
428         return error;
429 }
430
431 /**
432  * phy_mdm6600_device_power_off() - power off mdm6600 device
433  * @ddata: device driver data
434  */
435 static void phy_mdm6600_device_power_off(struct phy_mdm6600 *ddata)
436 {
437         struct gpio_desc *reset_gpio =
438                 ddata->ctrl_gpios[PHY_MDM6600_RESET];
439
440         ddata->enabled = false;
441         phy_mdm6600_cmd(ddata, PHY_MDM6600_CMD_BP_SHUTDOWN_REQ);
442         msleep(100);
443
444         gpiod_set_value_cansleep(reset_gpio, 1);
445
446         dev_info(ddata->dev, "Waiting for power down request to complete.. ");
447         if (wait_for_completion_timeout(&ddata->ack,
448                                         msecs_to_jiffies(5000))) {
449                 if (ddata->status == PHY_MDM6600_STATUS_PANIC)
450                         dev_info(ddata->dev, "Powered down OK\n");
451         } else {
452                 dev_err(ddata->dev, "Timed out powering down\n");
453         }
454 }
455
456 static void phy_mdm6600_deferred_power_on(struct work_struct *work)
457 {
458         struct phy_mdm6600 *ddata;
459         int error;
460
461         ddata = container_of(work, struct phy_mdm6600, bootup_work.work);
462
463         error = phy_mdm6600_device_power_on(ddata);
464         if (error)
465                 dev_err(ddata->dev, "Device not functional\n");
466 }
467
468 /*
469  * USB suspend puts mdm6600 into low power mode. For any n_gsm using apps,
470  * we need to keep the modem awake by kicking it's mode0 GPIO. This will
471  * keep the modem awake for about 1.2 seconds. When no n_gsm apps are using
472  * the modem, runtime PM auto mode can be enabled so modem can enter low
473  * power mode.
474  */
475 static void phy_mdm6600_wake_modem(struct phy_mdm6600 *ddata)
476 {
477         struct gpio_desc *mode_gpio0;
478
479         mode_gpio0 = ddata->mode_gpios->desc[PHY_MDM6600_MODE0];
480         gpiod_set_value_cansleep(mode_gpio0, 1);
481         usleep_range(5, 15);
482         gpiod_set_value_cansleep(mode_gpio0, 0);
483         if (ddata->awake)
484                 usleep_range(5, 15);
485         else
486                 msleep(MDM6600_MODEM_WAKE_DELAY_MS);
487 }
488
489 static void phy_mdm6600_modem_wake(struct work_struct *work)
490 {
491         struct phy_mdm6600 *ddata;
492
493         ddata = container_of(work, struct phy_mdm6600, modem_wake_work.work);
494         phy_mdm6600_wake_modem(ddata);
495
496         /*
497          * The modem does not always stay awake 1.2 seconds after toggling
498          * the wake GPIO, and sometimes it idles after about some 600 ms
499          * making writes time out.
500          */
501         schedule_delayed_work(&ddata->modem_wake_work,
502                               msecs_to_jiffies(PHY_MDM6600_WAKE_KICK_MS));
503 }
504
505 static int __maybe_unused phy_mdm6600_runtime_suspend(struct device *dev)
506 {
507         struct phy_mdm6600 *ddata = dev_get_drvdata(dev);
508
509         cancel_delayed_work_sync(&ddata->modem_wake_work);
510         ddata->awake = false;
511
512         return 0;
513 }
514
515 static int __maybe_unused phy_mdm6600_runtime_resume(struct device *dev)
516 {
517         struct phy_mdm6600 *ddata = dev_get_drvdata(dev);
518
519         phy_mdm6600_modem_wake(&ddata->modem_wake_work.work);
520         ddata->awake = true;
521
522         return 0;
523 }
524
525 static const struct dev_pm_ops phy_mdm6600_pm_ops = {
526         SET_RUNTIME_PM_OPS(phy_mdm6600_runtime_suspend,
527                            phy_mdm6600_runtime_resume, NULL)
528 };
529
530 static const struct of_device_id phy_mdm6600_id_table[] = {
531         { .compatible = "motorola,mapphone-mdm6600", },
532         {},
533 };
534 MODULE_DEVICE_TABLE(of, phy_mdm6600_id_table);
535
536 static int phy_mdm6600_probe(struct platform_device *pdev)
537 {
538         struct phy_mdm6600 *ddata;
539         int error;
540
541         ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
542         if (!ddata)
543                 return -ENOMEM;
544
545         INIT_DELAYED_WORK(&ddata->bootup_work,
546                           phy_mdm6600_deferred_power_on);
547         INIT_DELAYED_WORK(&ddata->status_work, phy_mdm6600_status);
548         INIT_DELAYED_WORK(&ddata->modem_wake_work, phy_mdm6600_modem_wake);
549         init_completion(&ddata->ack);
550
551         ddata->dev = &pdev->dev;
552         platform_set_drvdata(pdev, ddata);
553
554         error = phy_mdm6600_init_lines(ddata);
555         if (error)
556                 return error;
557
558         phy_mdm6600_init_irq(ddata);
559
560         ddata->generic_phy = devm_phy_create(ddata->dev, NULL, &gpio_usb_ops);
561         if (IS_ERR(ddata->generic_phy)) {
562                 error = PTR_ERR(ddata->generic_phy);
563                 goto cleanup;
564         }
565
566         phy_set_drvdata(ddata->generic_phy, ddata);
567
568         ddata->phy_provider =
569                 devm_of_phy_provider_register(ddata->dev,
570                                               of_phy_simple_xlate);
571         if (IS_ERR(ddata->phy_provider)) {
572                 error = PTR_ERR(ddata->phy_provider);
573                 goto cleanup;
574         }
575
576         schedule_delayed_work(&ddata->bootup_work, 0);
577
578         /*
579          * See phy_mdm6600_device_power_on(). We should be able
580          * to remove this eventually when ohci-platform can deal
581          * with -EPROBE_DEFER.
582          */
583         msleep(PHY_MDM6600_PHY_DELAY_MS + 500);
584
585         /*
586          * Enable PM runtime only after PHY has been powered up properly.
587          * It is currently only needed after USB suspends mdm6600 and n_gsm
588          * needs to access the device. We don't want to do this earlier as
589          * gpio mode0 pin doubles as mdm6600 wake-up gpio.
590          */
591         pm_runtime_use_autosuspend(ddata->dev);
592         pm_runtime_set_autosuspend_delay(ddata->dev,
593                                          MDM6600_MODEM_IDLE_DELAY_MS);
594         pm_runtime_enable(ddata->dev);
595         error = pm_runtime_get_sync(ddata->dev);
596         if (error < 0) {
597                 dev_warn(ddata->dev, "failed to wake modem: %i\n", error);
598                 pm_runtime_put_noidle(ddata->dev);
599         }
600         pm_runtime_mark_last_busy(ddata->dev);
601         pm_runtime_put_autosuspend(ddata->dev);
602
603         return 0;
604
605 cleanup:
606         phy_mdm6600_device_power_off(ddata);
607         return error;
608 }
609
610 static int phy_mdm6600_remove(struct platform_device *pdev)
611 {
612         struct phy_mdm6600 *ddata = platform_get_drvdata(pdev);
613         struct gpio_desc *reset_gpio = ddata->ctrl_gpios[PHY_MDM6600_RESET];
614
615         pm_runtime_dont_use_autosuspend(ddata->dev);
616         pm_runtime_put_sync(ddata->dev);
617         pm_runtime_disable(ddata->dev);
618
619         if (!ddata->running)
620                 wait_for_completion_timeout(&ddata->ack,
621                         msecs_to_jiffies(PHY_MDM6600_ENABLED_DELAY_MS));
622
623         gpiod_set_value_cansleep(reset_gpio, 1);
624         phy_mdm6600_device_power_off(ddata);
625
626         cancel_delayed_work_sync(&ddata->modem_wake_work);
627         cancel_delayed_work_sync(&ddata->bootup_work);
628         cancel_delayed_work_sync(&ddata->status_work);
629
630         return 0;
631 }
632
633 static struct platform_driver phy_mdm6600_driver = {
634         .probe = phy_mdm6600_probe,
635         .remove = phy_mdm6600_remove,
636         .driver = {
637                 .name = "phy-mapphone-mdm6600",
638                 .pm = &phy_mdm6600_pm_ops,
639                 .of_match_table = of_match_ptr(phy_mdm6600_id_table),
640         },
641 };
642
643 module_platform_driver(phy_mdm6600_driver);
644
645 MODULE_ALIAS("platform:gpio_usb");
646 MODULE_AUTHOR("Tony Lindgren <tony@atomide.com>");
647 MODULE_DESCRIPTION("mdm6600 gpio usb phy driver");
648 MODULE_LICENSE("GPL v2");