OSDN Git Service

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