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