misc: tegra-baseband: Fix NULL instead of integer
[linux-3.10.git] / drivers / misc / tegra-baseband / tegra_usb_modem_power.c
1 /*
2  * Copyright (c) 2011-2015, NVIDIA CORPORATION.  All rights reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18
19 #include <linux/module.h>
20 #include <linux/init.h>
21 #include <linux/interrupt.h>
22 #include <linux/platform_device.h>
23 #include <linux/platform_data/tegra_usb.h>
24 #include <linux/workqueue.h>
25 #include <linux/gpio.h>
26 #include <linux/of.h>
27 #include <linux/of_device.h>
28 #include <linux/of_gpio.h>
29 #include <linux/usb.h>
30 #include <linux/err.h>
31 #include <linux/pm_runtime.h>
32 #include <linux/suspend.h>
33 #include <linux/slab.h>
34 #include <linux/wakelock.h>
35 #include <linux/pm_qos.h>
36 #include <linux/regulator/consumer.h>
37 #include <linux/sysedp.h>
38 #include <linux/platform_data/tegra_usb_modem_power.h>
39 #include <linux/dma-mapping.h>
40 #include <linux/delay.h>
41 #include "../../../arch/arm/mach-tegra/iomap.h"
42 #include <linux/fs.h>
43 #include <asm/segment.h>
44 #include <asm/uaccess.h>
45 #include <linux/platform_data/modem_thermal.h>
46 #include <linux/platform_data/sysedp_modem.h>
47
48 #define BOOST_CPU_FREQ_MIN      1200000
49 #define BOOST_CPU_FREQ_TIMEOUT  5000
50
51 #define WAKELOCK_TIMEOUT_FOR_USB_ENUM           (HZ * 10)
52 #define WAKELOCK_TIMEOUT_FOR_REMOTE_WAKE        (HZ)
53
54 #define MAX_MODEM_EDP_STATES 10
55
56 /* default autosuspend and short autosuspend delay in ms */
57 #define DEFAULT_AUTOSUSPEND             2000
58 #define DEFAULT_SHORT_AUTOSUSPEND       50
59
60 #define XHCI_HSIC_POWER "/sys/bus/platform/devices/tegra-xhci/hsic0_power"
61
62 static int hsic_power(bool on)
63 {
64         struct file *fp = NULL;
65         mm_segment_t oldfs;
66         loff_t offset = 0;
67
68         oldfs = get_fs();
69         set_fs(get_ds());
70         fp = filp_open(XHCI_HSIC_POWER, O_RDWR, S_IRWXU);
71         if (IS_ERR(fp)) {
72                 pr_err("%s: error opening %s, error:%ld\n",
73                                 __func__, XHCI_HSIC_POWER, PTR_ERR(fp));
74                 return PTR_ERR(fp);
75         }
76
77         if (on)
78                 vfs_write(fp, "1", 1, &offset);
79         else
80                 vfs_write(fp, "0", 1, &offset);
81
82         vfs_fsync(fp, 0);
83         set_fs(oldfs);
84         filp_close(fp, NULL);
85         return 0;
86 }
87
88 static u64 tegra_ehci_dmamask = DMA_BIT_MASK(64);
89
90 static struct resource tegra_usb2_resources[] = {
91         [0] = {
92                 .start  = TEGRA_USB2_BASE,
93                 .end    = TEGRA_USB2_BASE + TEGRA_USB2_SIZE - 1,
94                 .flags  = IORESOURCE_MEM,
95         },
96         [1] = {
97                 .start  = INT_USB2,
98                 .end    = INT_USB2,
99                 .flags  = IORESOURCE_IRQ,
100         },
101 };
102
103 static struct platform_device tegra_ehci2_device = {
104         .name   = "tegra-ehci",
105         .id     = 1,
106         .dev    = {
107                 .dma_mask       = &tegra_ehci_dmamask,
108                 .coherent_dma_mask = DMA_BIT_MASK(64),
109         },
110         .resource = tegra_usb2_resources,
111         .num_resources = ARRAY_SIZE(tegra_usb2_resources),
112 };
113
114 static struct tegra_usb_platform_data tegra_ehci2_hsic_baseband_pdata = {
115         .port_otg = false,
116         .has_hostpc = true,
117         .unaligned_dma_buf_supported = false,
118         .phy_intf = TEGRA_USB_PHY_INTF_HSIC,
119         .op_mode = TEGRA_USB_OPMODE_HOST,
120         .u_data.host = {
121                 .hot_plug = false,
122                 .remote_wakeup_supported = true,
123                 .power_off_on_suspend = true,
124                 .skip_resume = true,
125         },
126 };
127
128 struct tegra_usb_modem {
129         struct tegra_usb_modem_power_platform_data *pdata;
130         struct platform_device *pdev;
131         struct regulator *regulator; /* modem power regulator */
132         unsigned int wake_cnt;  /* remote wakeup counter */
133         unsigned int wake_irq;  /* remote wakeup irq */
134         bool wake_irq_wakeable; /* LP0 wakeable */
135         unsigned int boot_irq;  /* modem boot irq */
136         bool boot_irq_wakeable; /* LP0 wakeable */
137         struct mutex lock;
138         struct wake_lock wake_lock;     /* modem wake lock */
139         unsigned int vid;       /* modem vendor id */
140         unsigned int pid;       /* modem product id */
141         struct usb_device *xusb_roothub;        /* XUSB roothub device */
142         struct usb_device *udev;        /* modem usb device */
143         struct usb_device *parent;      /* parent device */
144         struct usb_interface *intf;     /* first modem usb interface */
145         struct workqueue_struct *wq;    /* modem workqueue */
146         struct delayed_work recovery_work;      /* modem recovery work */
147         struct delayed_work enable_nvhsic_work; /* enable xhci hsic work */
148         bool nvhsic_work_queued;        /* if hsic power work is queued*/
149         struct work_struct host_load_work;      /* usb host load work */
150         struct work_struct host_unload_work;    /* usb host unload work */
151         struct pm_qos_request cpu_boost_req; /* min CPU freq request */
152         struct work_struct cpu_boost_work;      /* CPU freq boost work */
153         struct delayed_work cpu_unboost_work;   /* CPU freq unboost work */
154         const struct tegra_modem_operations *ops;       /* modem operations */
155         unsigned int capability;        /* modem capability */
156         int system_suspend;     /* system suspend flag */
157         struct notifier_block pm_notifier;      /* pm event notifier */
158         struct notifier_block usb_notifier;     /* usb event notifier */
159         int sysfs_file_created;
160         int short_autosuspend_enabled;
161         struct platform_device *hc;     /* USB host controller */
162         struct mutex hc_lock;
163         enum { EHCI_HSIC = 0, XHCI_HSIC, XHCI_UTMI } phy_type;
164         struct platform_device *modem_thermal_pdev;
165         int pre_boost_gpio;             /* control regulator output voltage */
166         int modem_state_file_created;   /* modem_state sysfs created */
167         enum { AIRPLANE = 0, RAT_3G_LTE, RAT_2G} modem_power_state;
168         struct mutex modem_state_lock;
169         struct platform_device *modem_edp_pdev;
170 };
171
172
173 /* supported modems */
174 static const struct usb_device_id modem_list[] = {
175         {USB_DEVICE(0x1983, 0x0310),    /* Icera 450 rev1 */
176          .driver_info = TEGRA_MODEM_AUTOSUSPEND | TEGRA_MODEM_CPU_BOOST,
177          },
178         {USB_DEVICE(0x1983, 0x0321),    /* Icera 450 rev2 */
179          .driver_info = TEGRA_MODEM_AUTOSUSPEND | TEGRA_MODEM_CPU_BOOST,
180          },
181         {USB_DEVICE(0x1983, 0x0327),    /* Icera 450 5AE */
182          .driver_info = TEGRA_MODEM_AUTOSUSPEND | TEGRA_MODEM_CPU_BOOST,
183          },
184         {USB_DEVICE(0x1983, 0x0427),    /* Icera 500 5AN */
185          .driver_info = TEGRA_MODEM_AUTOSUSPEND | TEGRA_MODEM_CPU_BOOST,
186          },
187         {USB_DEVICE(0x1983, 0x1005),    /* Icera 500 5AN (BSD) */
188          .driver_info = TEGRA_MODEM_CPU_BOOST,
189         /* .driver_info = TEGRA_MODEM_AUTOSUSPEND, */
190          },
191         {USB_DEVICE(0x1983, 0x1007),    /* Icera 500 Bruce */
192          .driver_info = TEGRA_USB_HOST_RELOAD|TEGRA_MODEM_AUTOSUSPEND,
193          },
194         {}
195 };
196
197 static ssize_t load_unload_usb_host(struct device *dev,
198                                     struct device_attribute *attr,
199                                     const char *buf, size_t count);
200
201 static void cpu_freq_unboost(struct work_struct *ws)
202 {
203         struct tegra_usb_modem *modem = container_of(ws, struct tegra_usb_modem,
204                                                      cpu_unboost_work.work);
205
206         pm_qos_update_request(&modem->cpu_boost_req, PM_QOS_DEFAULT_VALUE);
207 }
208
209 static void cpu_freq_boost(struct work_struct *ws)
210 {
211         struct tegra_usb_modem *modem = container_of(ws, struct tegra_usb_modem,
212                                                      cpu_boost_work);
213
214         cancel_delayed_work_sync(&modem->cpu_unboost_work);
215         pm_qos_update_request(&modem->cpu_boost_req, BOOST_CPU_FREQ_MIN);
216         queue_delayed_work(modem->wq, &modem->cpu_unboost_work,
217                               msecs_to_jiffies(BOOST_CPU_FREQ_TIMEOUT));
218 }
219
220 static irqreturn_t tegra_usb_modem_wake_thread(int irq, void *data)
221 {
222         struct tegra_usb_modem *modem = (struct tegra_usb_modem *)data;
223
224         mutex_lock(&modem->lock);
225         if (modem->udev && modem->udev->state != USB_STATE_NOTATTACHED) {
226                 wake_lock_timeout(&modem->wake_lock,
227                                   WAKELOCK_TIMEOUT_FOR_REMOTE_WAKE);
228
229                 dev_info(&modem->pdev->dev, "remote wake (%u)\n",
230                          ++(modem->wake_cnt));
231
232                 if (!modem->system_suspend) {
233                         usb_lock_device(modem->udev);
234                         if (usb_autopm_get_interface(modem->intf) == 0)
235                                 usb_autopm_put_interface_async(modem->intf);
236                         usb_unlock_device(modem->udev);
237                 }
238 #ifdef CONFIG_PM
239                 if (modem->capability & TEGRA_MODEM_AUTOSUSPEND &&
240                     modem->short_autosuspend_enabled) {
241                         pm_runtime_set_autosuspend_delay(&modem->udev->dev,
242                                         modem->pdata->autosuspend_delay);
243                         modem->short_autosuspend_enabled = 0;
244                 }
245 #endif
246         }
247         mutex_unlock(&modem->lock);
248
249         return IRQ_HANDLED;
250 }
251
252 static irqreturn_t tegra_usb_modem_boot_thread(int irq, void *data)
253 {
254         struct tegra_usb_modem *modem = (struct tegra_usb_modem *)data;
255         int v = gpio_get_value(modem->pdata->boot_gpio);
256
257         dev_info(&modem->pdev->dev, "MDM_COLDBOOT %s\n", v ? "high" : "low");
258         if (modem->capability & TEGRA_USB_HOST_RELOAD)
259                 if (!work_pending(&modem->host_load_work) &&
260                     !work_pending(&modem->host_unload_work))
261                         queue_work(modem->wq, v ? &modem->host_load_work :
262                                    &modem->host_unload_work);
263
264         /* hold wait lock to complete the enumeration */
265         wake_lock_timeout(&modem->wake_lock, WAKELOCK_TIMEOUT_FOR_USB_ENUM);
266
267         /* boost CPU freq for timing requirements on single flash platforms */
268         if ((modem->capability & TEGRA_MODEM_CPU_BOOST) &&
269              !work_pending(&modem->cpu_boost_work))
270                 queue_work(modem->wq, &modem->cpu_boost_work);
271
272         /* USB disconnect maybe on going... */
273         mutex_lock(&modem->lock);
274         if (modem->udev && modem->udev->state != USB_STATE_NOTATTACHED)
275                 pr_warn("Device is not disconnected!\n");
276         mutex_unlock(&modem->lock);
277
278         return IRQ_HANDLED;
279 }
280
281 static void tegra_usb_modem_recovery(struct work_struct *ws)
282 {
283         struct tegra_usb_modem *modem = container_of(ws, struct tegra_usb_modem,
284                                                      recovery_work.work);
285
286         mutex_lock(&modem->lock);
287         if (!modem->udev) {     /* assume modem crashed */
288                 if (modem->ops && modem->ops->reset)
289                         modem->ops->reset();
290         }
291         mutex_unlock(&modem->lock);
292 }
293
294 static void enable_nvhsic_power(struct work_struct *ws)
295 {
296         struct tegra_usb_modem *modem = container_of(ws, struct tegra_usb_modem,
297                                         enable_nvhsic_work.work);
298         int ret;
299
300         pr_info("Enabing XHCI HSIC\n");
301         mutex_lock(&modem->hc_lock);
302         ret = hsic_power(1);
303         if (ret) {
304                 pr_err("Failed to Enable XHCI HSIC power: %d\n", ret);
305                 modem->hc = NULL;
306                 goto error;
307         }
308         modem->hc = (struct platform_device *)1;
309 error:
310         modem->nvhsic_work_queued = false;
311         mutex_unlock(&modem->hc_lock);
312 }
313
314 static void tegra_usb_host_load(struct work_struct *ws)
315 {
316         struct tegra_usb_modem *modem = container_of(ws, struct tegra_usb_modem,
317                                                      host_load_work);
318         load_unload_usb_host(&modem->pdev->dev, NULL, "1", 1);
319 }
320
321 static void tegra_usb_host_unload(struct work_struct *ws)
322 {
323         struct tegra_usb_modem *modem = container_of(ws, struct tegra_usb_modem,
324                                                      host_unload_work);
325         load_unload_usb_host(&modem->pdev->dev, NULL, "0", 1);
326 }
327
328 static void modem_device_add_handler(struct tegra_usb_modem *modem,
329                                struct usb_device *udev)
330 {
331         const struct usb_device_descriptor *desc = &udev->descriptor;
332         struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
333         const struct usb_device_id *id = NULL;
334
335         if (intf) {
336                 /* only look for specific modems if modem_list is provided in
337                    platform data. Otherwise, look for the modems in the default
338                    supported modem list */
339                 if (modem->pdata->modem_list)
340                         id = usb_match_id(intf, modem->pdata->modem_list);
341                 else
342                         id = usb_match_id(intf, modem_list);
343         }
344
345         if (id) {
346                 /* hold wakelock to ensure ril has enough time to restart */
347                 wake_lock_timeout(&modem->wake_lock,
348                                   WAKELOCK_TIMEOUT_FOR_USB_ENUM);
349
350                 /* enable XUSB ELPG (autosuspend) */
351                 if (modem->phy_type == XHCI_HSIC)
352                         pm_runtime_put(&modem->xusb_roothub->dev);
353
354                 pr_info("Add device %d <%s %s>\n", udev->devnum,
355                         udev->manufacturer, udev->product);
356
357                 mutex_lock(&modem->lock);
358                 modem->udev = udev;
359                 modem->parent = udev->parent;
360                 modem->intf = intf;
361                 modem->vid = desc->idVendor;
362                 modem->pid = desc->idProduct;
363                 modem->wake_cnt = 0;
364                 modem->capability = id->driver_info;
365                 mutex_unlock(&modem->lock);
366
367                 pr_info("persist_enabled: %u\n", udev->persist_enabled);
368
369 #ifdef CONFIG_PM
370                 if (modem->capability & TEGRA_MODEM_AUTOSUSPEND) {
371                         pm_runtime_set_autosuspend_delay(&udev->dev,
372                                         modem->pdata->autosuspend_delay);
373                         modem->short_autosuspend_enabled = 0;
374                         usb_enable_autosuspend(udev);
375                         pr_info("enable autosuspend for %s %s\n",
376                                 udev->manufacturer, udev->product);
377                 }
378
379                 /* allow the device to wake up the system */
380                 if (udev->actconfig->desc.bmAttributes &
381                     USB_CONFIG_ATT_WAKEUP)
382                         device_set_wakeup_enable(&udev->dev, true);
383 #endif
384         }
385 }
386
387 static void modem_device_remove_handler(struct tegra_usb_modem *modem,
388                                   struct usb_device *udev)
389 {
390         const struct usb_device_descriptor *desc = &udev->descriptor;
391
392         if (desc->idVendor == modem->vid && desc->idProduct == modem->pid) {
393                 pr_info("Remove device %d <%s %s>\n", udev->devnum,
394                         udev->manufacturer, udev->product);
395
396                 /* enable XUSB ELPG (autosuspend) */
397                 if (modem->phy_type == XHCI_HSIC)
398                         pm_runtime_put(&modem->xusb_roothub->dev);
399
400                 mutex_lock(&modem->lock);
401                 modem->udev = NULL;
402                 modem->intf = NULL;
403                 modem->vid = 0;
404                 mutex_unlock(&modem->lock);
405
406                 if (modem->capability & TEGRA_MODEM_RECOVERY)
407                         queue_delayed_work(modem->wq,
408                                            &modem->recovery_work, HZ * 10);
409         }
410 }
411
412
413 static void xusb_usb2_roothub_add_handler(struct tegra_usb_modem *modem,
414                 struct usb_device *udev)
415 {
416         const struct usb_device_descriptor *desc = &udev->descriptor;
417
418         if (modem->phy_type == XHCI_HSIC &&
419                 desc->idVendor == 0x1d6b && desc->idProduct == 0x2 &&
420                 !strcmp(udev->serial, "tegra-xhci")) {
421                 pr_info("Add device %d <%s %s>\n", udev->devnum,
422                         udev->manufacturer, udev->product);
423                 mutex_lock(&modem->lock);
424                 modem->xusb_roothub = udev;
425                 mutex_unlock(&modem->lock);
426                 /* HSIC isn't enabled yet, enable it in 1 sec */
427                 if (!modem->hc) {
428                         modem->nvhsic_work_queued = true;
429                         /* disable ELPG */
430                         pm_runtime_get_sync(&modem->xusb_roothub->dev);
431                         queue_delayed_work(modem->wq,
432                                         &modem->enable_nvhsic_work, HZ);
433                 }
434         }
435 }
436
437 static void xusb_usb2_roothub_remove_handler(struct tegra_usb_modem *modem,
438                 struct usb_device *udev)
439 {
440         const struct usb_device_descriptor *desc = &udev->descriptor;
441
442         if (modem->phy_type == XHCI_HSIC &&
443                 desc->idVendor == 0x1d6b && desc->idProduct == 0x2 &&
444                 !strcmp(udev->serial, "tegra-xhci")) {
445                 pr_info("Remove device %d <%s %s>\n", udev->devnum,
446                         udev->manufacturer, udev->product);
447                 mutex_lock(&modem->lock);
448                 modem->xusb_roothub = NULL;
449                 mutex_unlock(&modem->lock);
450         }
451 }
452
453 static int mdm_usb_notifier(struct notifier_block *notifier,
454                             unsigned long usb_event, void *udev)
455 {
456         struct tegra_usb_modem *modem =
457             container_of(notifier, struct tegra_usb_modem, usb_notifier);
458
459         switch (usb_event) {
460         case USB_DEVICE_ADD:
461                 modem_device_add_handler(modem, udev);
462                 xusb_usb2_roothub_add_handler(modem, udev);
463                 break;
464         case USB_DEVICE_REMOVE:
465                 modem_device_remove_handler(modem, udev);
466                 xusb_usb2_roothub_remove_handler(modem, udev);
467                 break;
468         }
469         return NOTIFY_OK;
470 }
471
472 static int mdm_pm_notifier(struct notifier_block *notifier,
473                            unsigned long pm_event, void *unused)
474 {
475         struct tegra_usb_modem *modem =
476             container_of(notifier, struct tegra_usb_modem, pm_notifier);
477
478         mutex_lock(&modem->lock);
479         if (!modem->udev) {
480                 mutex_unlock(&modem->lock);
481                 return NOTIFY_DONE;
482         }
483
484         pr_info("%s: event %ld\n", __func__, pm_event);
485         switch (pm_event) {
486         case PM_SUSPEND_PREPARE:
487                 if (wake_lock_active(&modem->wake_lock)) {
488                         pr_warn("%s: wakelock was active, aborting suspend\n",
489                                 __func__);
490                         mutex_unlock(&modem->lock);
491                         return NOTIFY_STOP;
492                 }
493
494                 modem->system_suspend = 1;
495 #ifdef CONFIG_PM
496                 if (modem->capability & TEGRA_MODEM_AUTOSUSPEND &&
497                     modem->udev &&
498                     modem->udev->state != USB_STATE_NOTATTACHED) {
499                         pm_runtime_set_autosuspend_delay(&modem->udev->dev,
500                                         modem->pdata->short_autosuspend_delay);
501                         modem->short_autosuspend_enabled = 1;
502                 }
503 #endif
504                 mutex_unlock(&modem->lock);
505                 return NOTIFY_OK;
506         case PM_POST_SUSPEND:
507                 modem->system_suspend = 0;
508                 mutex_unlock(&modem->lock);
509                 return NOTIFY_OK;
510         }
511
512         mutex_unlock(&modem->lock);
513         return NOTIFY_DONE;
514 }
515
516 static int mdm_request_irq(struct tegra_usb_modem *modem,
517                            irq_handler_t thread_fn,
518                            unsigned int irq_gpio,
519                            unsigned long irq_flags,
520                            const char *label,
521                            unsigned int *irq,
522                            bool *is_wakeable)
523 {
524         int ret;
525
526         ret = gpio_request(irq_gpio, label);
527         if (ret)
528                 return ret;
529
530         /* enable IRQ for GPIO */
531         *irq = gpio_to_irq(irq_gpio);
532
533         /* request threaded irq for GPIO */
534         ret = request_threaded_irq(*irq, NULL, thread_fn, irq_flags, label,
535                                    modem);
536         if (ret) {
537                 *irq = 0;
538                 return ret;
539         }
540
541         ret = enable_irq_wake(*irq);
542         *is_wakeable = (ret) ? false : true;
543
544         return 0;
545 }
546
547 static void tegra_usb_modem_post_remote_wakeup(void)
548 {
549         struct device *dev;
550         struct tegra_usb_modem *modem;
551
552         dev = bus_find_device_by_name(&platform_bus_type, NULL,
553                                         "MDM");
554         if (!dev) {
555                 pr_warn("%s unable to find device name\n", __func__);
556                 return;
557         }
558
559         modem = dev_get_drvdata(dev);
560
561         mutex_lock(&modem->lock);
562 #ifdef CONFIG_PM
563         if (modem->capability & TEGRA_MODEM_AUTOSUSPEND &&
564             modem->udev &&
565             modem->udev->state != USB_STATE_NOTATTACHED &&
566             modem->short_autosuspend_enabled) {
567                 pm_runtime_set_autosuspend_delay(&modem->udev->dev,
568                                 modem->pdata->autosuspend_delay);
569                 modem->short_autosuspend_enabled = 0;
570         }
571 #endif
572         wake_lock_timeout(&modem->wake_lock, WAKELOCK_TIMEOUT_FOR_REMOTE_WAKE);
573         mutex_unlock(&modem->lock);
574
575         return;
576 }
577
578 /* load USB host controller */
579 static struct platform_device *tegra_usb_host_register(
580                                 const struct tegra_usb_modem *modem)
581 {
582         const struct platform_device *hc_device =
583             modem->pdata->tegra_ehci_device;
584         struct platform_device *pdev;
585         int val;
586
587         pdev = platform_device_alloc(hc_device->name, hc_device->id);
588         if (!pdev)
589                 return NULL;
590
591         val = platform_device_add_resources(pdev, hc_device->resource,
592                                             hc_device->num_resources);
593         if (val)
594                 goto error;
595
596         pdev->dev.dma_mask = hc_device->dev.dma_mask;
597         pdev->dev.coherent_dma_mask = hc_device->dev.coherent_dma_mask;
598
599         val = platform_device_add_data(pdev, modem->pdata->tegra_ehci_pdata,
600                                         sizeof(struct tegra_usb_platform_data));
601         if (val)
602                 goto error;
603
604         val = platform_device_add(pdev);
605         if (val)
606                 goto error;
607
608         return pdev;
609
610 error:
611         pr_err("%s: err %d\n", __func__, val);
612         platform_device_put(pdev);
613         return NULL;
614 }
615
616 /* unload USB host controller */
617 static void tegra_usb_host_unregister(struct platform_device *pdev)
618 {
619         platform_device_unregister(pdev);
620 }
621
622 static ssize_t show_usb_host(struct device *dev,
623                              struct device_attribute *attr, char *buf)
624 {
625         struct tegra_usb_modem *modem = dev_get_drvdata(dev);
626
627         return sprintf(buf, "%d\n", (modem->hc) ? 1 : 0);
628 }
629
630 static ssize_t load_unload_usb_host(struct device *dev,
631                                     struct device_attribute *attr,
632                                     const char *buf, size_t count)
633 {
634         struct tegra_usb_modem *modem = dev_get_drvdata(dev);
635         int host, ret;
636
637         if (sscanf(buf, "%d", &host) != 1 || host < 0 || host > 1)
638                 return -EINVAL;
639
640
641         mutex_lock(&modem->hc_lock);
642         switch (modem->phy_type) {
643         case XHCI_HSIC:
644                 if (host) {
645                         if (modem->xusb_roothub &&
646                                         !modem->nvhsic_work_queued) {
647                                 modem->nvhsic_work_queued = true;
648                                 /* disable ELPG */
649                                 pm_runtime_get_sync(&modem->xusb_roothub->dev);
650                                 /* enable HSIC power now */
651                                 queue_delayed_work(modem->wq,
652                                         &modem->enable_nvhsic_work, 0);
653                         }
654                 } else {
655                         if (modem->xusb_roothub) {
656                                 pr_info("Disable XHCI HSIC\n");
657                                 /* disable ELPG */
658                                 pm_runtime_get_sync(&modem->xusb_roothub->dev);
659                                 ret = hsic_power(0);
660                                 modem->hc = NULL;
661                         } else
662                                 pr_warn("xusb roothub not available!\n");
663                 }
664                 break;
665         case EHCI_HSIC:
666                 pr_info("%s EHCI\n", host ? "Load" : "Unload");
667                 if (host && !modem->hc) {
668                         modem->hc = tegra_usb_host_register(modem);
669                 } else if (!host && modem->hc) {
670                         tegra_usb_host_unregister(modem->hc);
671                         modem->hc = NULL;
672                 }
673                 break;
674         case XHCI_UTMI:
675                 modem->hc = host ? (struct platform_device *)1 : NULL;
676                 break;
677         default:
678                 pr_warn("%s: wrong phy_type:%d\n", __func__, modem->phy_type);
679         }
680         mutex_unlock(&modem->hc_lock);
681
682         return count;
683 }
684
685 static DEVICE_ATTR(load_host, S_IRUSR | S_IWUSR, show_usb_host,
686                    load_unload_usb_host);
687
688 /* Export a new sysfs for the user land (RIL) to notify modem state
689  * Airplane mode = 0
690  * 3G/LTE mode = 1
691  * 2G mode = 2
692 */
693 static ssize_t show_modem_state(struct device *dev,
694                                 struct device_attribute *attr, char *buf)
695 {
696         struct tegra_usb_modem *modem = dev_get_drvdata(dev);
697
698         return sprintf(buf, "%d\n", modem->modem_power_state);
699 }
700
701 static ssize_t set_modem_state(struct device *dev,
702                                 struct device_attribute *attr,
703                                 const char *buf, size_t count)
704 {
705         struct tegra_usb_modem *modem = dev_get_drvdata(dev);
706         int modem_state_value;
707
708         if (sscanf(buf, "%d", &modem_state_value) != 1)
709                 return -EINVAL;
710
711         mutex_lock(&modem->modem_state_lock);
712         switch (modem_state_value) {
713         case AIRPLANE:
714                 modem->modem_power_state = modem_state_value;
715
716                 /* Release BYPASS */
717                 if (regulator_allow_bypass(modem->regulator, false))
718                         dev_warn(dev,
719                         "failed to set modem regulator in non bypass mode\n");
720
721                 /* auto PFM mode*/
722                 if (regulator_set_mode(modem->regulator, REGULATOR_MODE_NORMAL))
723                         dev_warn(dev,
724                         "failed to set modem regulator in normal mode\n");
725                 break;
726         case RAT_2G:
727                 modem->modem_power_state = modem_state_value;
728
729                 /* Release BYPASS */
730                 if (regulator_allow_bypass(modem->regulator, true))
731                         dev_warn(dev,
732                         "failed to set modem regulator in bypass mode\n");
733
734                 /* forced PWM  mode*/
735                 if (regulator_set_mode(modem->regulator, REGULATOR_MODE_FAST))
736                         dev_warn(dev,
737                         "failed to set modem regulator in fast mode\n");
738                 break;
739         case RAT_3G_LTE:
740                 modem->modem_power_state = modem_state_value;
741
742                 /* Release BYPASS */
743                 if (regulator_allow_bypass(modem->regulator, true))
744                         dev_warn(dev,
745                         "failed to set modem regulator in bypass mode\n");
746
747                 /* auto PFM mode*/
748                 if (regulator_set_mode(modem->regulator, REGULATOR_MODE_NORMAL))
749                         dev_warn(dev,
750                         "failed to set modem regulator in normal mode\n");
751                 break;
752         default:
753                 dev_warn(dev, "%s: wrong modem power state:%d\n", __func__,
754                 modem_state_value);
755         }
756         mutex_unlock(&modem->modem_state_lock);
757
758         return count;
759 }
760
761 static DEVICE_ATTR(modem_state, S_IRUSR | S_IWUSR, show_modem_state,
762                         set_modem_state);
763
764 static ssize_t store_sysedp_state(struct device *dev,
765                                 struct device_attribute *attr,
766                                 const char *buf, size_t count)
767 {
768         dev_dbg(dev, "%s: disabled\n", __func__);
769
770         return count;
771 }
772 static DEVICE_ATTR(sysedp_state, S_IWUSR, NULL, store_sysedp_state);
773
774 static struct tegra_usb_phy_platform_ops tegra_usb_modem_platform_ops = {
775         .post_remote_wakeup = tegra_usb_modem_post_remote_wakeup,
776 };
777
778 static struct modem_thermal_platform_data thermdata = {
779         .num_zones = 0,
780 };
781
782 static struct platform_device modem_thermal_device = {
783         .name = "modem-thermal",
784         .id = -1,
785         .num_resources = 0,
786         .dev = {
787                 .platform_data = NULL,
788         },
789 };
790
791 static struct modem_edp_platform_data edpdata = {
792         .mdm_power_report = -1,
793         .consumer_name = "icemdm",
794 };
795
796 static struct platform_device modem_edp_device = {
797         .name = "sysedp_modem",
798         .id = -1,
799         .num_resources = 0,
800         .dev = {
801                 .platform_data = NULL,
802         },
803 };
804
805 static int mdm_init(struct tegra_usb_modem *modem, struct platform_device *pdev)
806 {
807         struct tegra_usb_modem_power_platform_data *pdata =
808             pdev->dev.platform_data;
809         int ret = 0;
810
811         modem->pdata = pdata;
812         modem->pdev = pdev;
813
814         /* WAR to load statically defined ehci device/pdata */
815         pdata->tegra_ehci_device = &tegra_ehci2_device;
816         pdata->tegra_ehci_pdata = &tegra_ehci2_hsic_baseband_pdata;
817
818         pdata->autosuspend_delay = DEFAULT_AUTOSUSPEND;
819         pdata->short_autosuspend_delay = DEFAULT_SHORT_AUTOSUSPEND;
820
821         /* get modem operations from platform data */
822         modem->ops = (const struct tegra_modem_operations *)pdata->ops;
823
824         /* modem init */
825         if (modem->ops && modem->ops->init) {
826                 ret = modem->ops->init();
827                 if (ret)
828                         goto error;
829         }
830
831         mutex_init(&(modem->lock));
832         mutex_init(&modem->hc_lock);
833         wake_lock_init(&modem->wake_lock, WAKE_LOCK_SUSPEND, "mdm_lock");
834
835         /* if wake gpio is not specified we rely on native usb remote wake */
836         if (gpio_is_valid(pdata->wake_gpio)) {
837                 /* request remote wakeup irq from platform data */
838                 ret = mdm_request_irq(modem,
839                                       tegra_usb_modem_wake_thread,
840                                       pdata->wake_gpio,
841                                       pdata->wake_irq_flags,
842                                       "mdm_wake",
843                                       &modem->wake_irq,
844                                       &modem->wake_irq_wakeable);
845                 if (ret) {
846                         dev_err(&pdev->dev, "request wake irq error\n");
847                         goto error;
848                 }
849         } else {
850                 modem->pdata->tegra_ehci_pdata->ops =
851                                                 &tegra_usb_modem_platform_ops;
852         }
853
854         if (gpio_is_valid(pdata->boot_gpio)) {
855                 /* request boot irq from platform data */
856                 ret = mdm_request_irq(modem,
857                                       tegra_usb_modem_boot_thread,
858                                       pdata->boot_gpio,
859                                       pdata->boot_irq_flags,
860                                       "mdm_boot",
861                                       &modem->boot_irq,
862                                       &modem->boot_irq_wakeable);
863                 if (ret) {
864                         dev_err(&pdev->dev, "request boot irq error\n");
865                         goto error;
866                 }
867         } else
868                 dev_warn(&pdev->dev, "boot irq not specified\n");
869
870         /* create sysfs node to load/unload host controller */
871         ret = device_create_file(&pdev->dev, &dev_attr_load_host);
872         if (ret) {
873                 dev_err(&pdev->dev, "can't create sysfs file\n");
874                 goto error;
875         }
876         modem->sysfs_file_created = 1;
877         modem->capability = TEGRA_USB_HOST_RELOAD;
878         if (pdev->id >= 0)
879                 dev_set_name(&pdev->dev, "MDM%d", pdev->id);
880         else
881                 dev_set_name(&pdev->dev, "MDM");
882
883         /* create sysfs node for RIL to report modem power state */
884         /* only if a regulator has been requested          */
885         modem->modem_state_file_created = 0;
886         if (pdata->regulator_name) {
887                 ret = device_create_file(&pdev->dev, &dev_attr_modem_state);
888                 if (ret) {
889                         dev_err(&pdev->dev,
890                         "can't create modem state sysfs file\n");
891                         goto error;
892                 }
893                 modem->modem_state_file_created = 1;
894                 mutex_init(&modem->modem_state_lock);
895         }
896
897         /* create work queue platform_driver_registe */
898         modem->wq = create_workqueue("tegra_usb_mdm_queue");
899         INIT_DELAYED_WORK(&modem->recovery_work, tegra_usb_modem_recovery);
900         INIT_DELAYED_WORK(&modem->enable_nvhsic_work, enable_nvhsic_power);
901         INIT_WORK(&modem->host_load_work, tegra_usb_host_load);
902         INIT_WORK(&modem->host_unload_work, tegra_usb_host_unload);
903         INIT_WORK(&modem->cpu_boost_work, cpu_freq_boost);
904         INIT_DELAYED_WORK(&modem->cpu_unboost_work, cpu_freq_unboost);
905
906         pm_qos_add_request(&modem->cpu_boost_req, PM_QOS_CPU_FREQ_MIN,
907                            PM_QOS_DEFAULT_VALUE);
908
909         modem->pm_notifier.notifier_call = mdm_pm_notifier;
910         modem->usb_notifier.notifier_call = mdm_usb_notifier;
911
912         usb_register_notify(&modem->usb_notifier);
913         register_pm_notifier(&modem->pm_notifier);
914
915         if (pdata->num_temp_sensors) {
916                 thermdata.num_zones = pdata->num_temp_sensors;
917                 modem_thermal_device.dev.platform_data = &thermdata;
918                 modem->modem_thermal_pdev = &modem_thermal_device;
919                 platform_device_register(modem->modem_thermal_pdev);
920         }
921
922         if (pdata->mdm_power_report_gpio) {
923                 edpdata.mdm_power_report = pdata->mdm_power_report_gpio;
924                 modem_edp_device.dev.platform_data = &edpdata;
925                 modem->modem_edp_pdev = &modem_edp_device;
926                 platform_device_register(modem->modem_edp_pdev);
927                 /* to be removed once RIL uses new path */
928                 ret = device_create_file(&pdev->dev, &dev_attr_sysedp_state);
929                 if (ret) {
930                         dev_err(&pdev->dev,
931                         "can't create modem state sysfs file\n");
932                         goto error;
933                 }
934         }
935
936         /* start modem */
937         if (modem->ops && modem->ops->start)
938                 modem->ops->start();
939
940         return ret;
941 error:
942         if (modem->sysfs_file_created)
943                 device_remove_file(&pdev->dev, &dev_attr_load_host);
944
945         if (modem->wake_irq)
946                 free_irq(modem->wake_irq, modem);
947
948         if (modem->boot_irq)
949                 free_irq(modem->boot_irq, modem);
950
951         if (modem->modem_state_file_created)
952                 device_remove_file(&pdev->dev, &dev_attr_modem_state);
953
954         return ret;
955 }
956
957 static int tegra_usb_modem_parse_dt(struct tegra_usb_modem *modem,
958                 struct platform_device *pdev)
959 {
960         struct tegra_usb_modem_power_platform_data *pdata =
961                 pdev->dev.platform_data;
962         struct device_node *node = pdev->dev.of_node;
963         const unsigned int *prop;
964         int gpio;
965         int ret;
966         u32 use_xhci_hsic = 0;
967
968         if (!node)
969                 return 0;
970
971         dev_dbg(&pdev->dev, "read platform data from DT\n");
972
973         /* allocate platform data if necessary */
974         if (!pdata) {
975                 pdata = devm_kzalloc(&pdev->dev,
976                         sizeof(struct tegra_usb_modem_power_platform_data),
977                         GFP_KERNEL);
978                 if (!pdata) {
979                         dev_warn(&pdev->dev, "failed to allocate memory\n");
980                         return -ENOMEM;
981                 }
982                 pdev->dev.platform_data = pdata;
983         }
984
985         /* turn on modem regulator if required */
986         pdata->regulator_name = of_get_property(node, "nvidia,regulator", NULL);
987         if (pdata->regulator_name) {
988                 modem->regulator = regulator_get(&pdev->dev,
989                                 pdata->regulator_name);
990                 if (IS_ERR(modem->regulator)) {
991                         dev_err(&pdev->dev, "failed to get regulator %s\n",
992                                 pdata->regulator_name);
993                         return PTR_ERR(modem->regulator);
994                 }
995                 ret = regulator_enable(modem->regulator);
996                 if (ret) {
997                         dev_err(&pdev->dev, "failed to enable regulator %s\n",
998                                 pdata->regulator_name);
999                         regulator_put(modem->regulator);
1000                         return ret;
1001                 }
1002
1003                 dev_info(&pdev->dev, "set modem regulator:%s\n",
1004                 pdata->regulator_name);
1005
1006                 /* Enable regulator bypass */
1007                 if (regulator_allow_bypass(modem->regulator, true))
1008                         dev_warn(&pdev->dev,
1009                         "failed to set modem regulator in bypass mode\n");
1010                 else
1011                         dev_info(&pdev->dev, "set regulator in bypass mode");
1012
1013                 /* Enable autoPFM */
1014                 if (regulator_set_mode(modem->regulator, REGULATOR_MODE_NORMAL))
1015                         dev_warn(&pdev->dev,
1016                         "failed to set modem regulator in normal mode\n");
1017                 else
1018                         dev_info(&pdev->dev,
1019                         "set modem regulator in normal mode");
1020         }
1021
1022         /* determine phy type */
1023         ret = of_property_read_u32(node, "nvidia,phy-type", &modem->phy_type);
1024         if (modem->phy_type != XHCI_UTMI) {
1025                 ret = of_property_read_u32(node, "nvidia,use-xhci-hsic",
1026                         &use_xhci_hsic);
1027                 modem->phy_type = (ret == 0 && use_xhci_hsic) ? XHCI_HSIC :
1028                         EHCI_HSIC;
1029         }
1030
1031         dev_info(&pdev->dev, "using %s\n",
1032                 modem->phy_type == EHCI_HSIC ? "EHCI HSIC" :
1033                 modem->phy_type == XHCI_HSIC ? "XHCI HSIC" : "XHCI UTMI");
1034
1035         prop = of_get_property(node, "nvidia,num-temp-sensors", NULL);
1036         if (prop)
1037                 pdata->num_temp_sensors = be32_to_cpup(prop);
1038
1039         /* GPIO */
1040         gpio = of_get_named_gpio(node, "nvidia,wake-gpio", 0);
1041         pdata->wake_gpio = gpio_is_valid(gpio) ? gpio : -1;
1042         dev_info(&pdev->dev, "set wake gpio:%d\n", pdata->wake_gpio);
1043
1044         gpio = of_get_named_gpio(node, "nvidia,boot-gpio", 0);
1045         pdata->boot_gpio = gpio_is_valid(gpio) ? gpio : -1;
1046         dev_info(&pdev->dev, "set boot gpio:%d\n", pdata->boot_gpio);
1047
1048         gpio = of_get_named_gpio(node, "nvidia,mdm-power-report-gpio", 0);
1049         pdata->mdm_power_report_gpio = gpio_is_valid(gpio) ? gpio : -1;
1050         dev_info(&pdev->dev, "set mdm power report gpio:%d\n",
1051                 pdata->mdm_power_report_gpio);
1052
1053         gpio = of_get_named_gpio(node, "nvidia,pre-boost-gpio", 0);
1054         if (gpio_is_valid(gpio)) {
1055                 dev_info(&pdev->dev, "set pre boost gpio (%d) to 1\n", gpio);
1056                 ret = gpio_request(gpio, "MODEM PREBOOST");
1057                 if (ret) {
1058                         dev_err(&pdev->dev, "request gpio %d failed\n", gpio);
1059                         return ret;
1060                 }
1061                 gpio_direction_output(gpio, 1);
1062                 modem->pre_boost_gpio = gpio;
1063         } else
1064                 modem->pre_boost_gpio = -1;
1065
1066
1067
1068         /* set GPIO IRQ flags */
1069         pdata->wake_irq_flags = pdata->boot_irq_flags =
1070                 pdata->mdm_power_irq_flags =
1071                 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT;
1072
1073         /* initialize necessary GPIO and start modem here */
1074         gpio = of_get_named_gpio(node, "nvidia,mdm-en-gpio", 0);
1075         if (gpio_is_valid(gpio)) {
1076                 dev_info(&pdev->dev, "set MODEM EN (%d) to 1\n", gpio);
1077                 ret = gpio_request(gpio, "MODEM EN");
1078                 if (ret) {
1079                         dev_err(&pdev->dev, "request gpio %d failed\n", gpio);
1080                         return ret;
1081                 }
1082                 gpio_direction_output(gpio, 1);
1083         }
1084
1085         gpio = of_get_named_gpio(node, "nvidia,mdm-sar0-gpio", 0);
1086         if (gpio_is_valid(gpio)) {
1087                 dev_info(&pdev->dev, "set MODEM SAR0 (%d) to 0\n", gpio);
1088                 ret = gpio_request(gpio, "MODEM SAR0");
1089                 if (ret) {
1090                         dev_err(&pdev->dev, "request gpio %d failed\n", gpio);
1091                         return ret;
1092                 }
1093                 gpio_direction_output(gpio, 0);
1094                 gpio_export(gpio, false);
1095
1096                 /* also create a dedicated sysfs for the modem-sar0 gpio */
1097                 gpio_export_link(&pdev->dev, "modem_sar", gpio);
1098         }
1099
1100         gpio = of_get_named_gpio(node, "nvidia,reset-gpio", 0);
1101         if (gpio_is_valid(gpio)) {
1102                 ret = gpio_request(gpio, "MODEM RESET");
1103                 if (ret) {
1104                         dev_err(&pdev->dev, "request gpio %d failed\n", gpio);
1105                         return ret;
1106                 }
1107                 /* boot modem now */
1108                 /* Modem requires at least 10ms between MDM_EN assertion
1109                 and release of the reset. 20ms is the min value of msleep */
1110                 msleep(20);
1111                 /* Release modem reset to start boot */
1112                 dev_info(&pdev->dev, "set MODEM RESET (%d) to 1\n", gpio);
1113                 gpio_direction_output(gpio, 1);
1114                 gpio_export(gpio, false);
1115
1116                 /* also create a dedicated sysfs for the modem-reset gpio */
1117                 gpio_export_link(&pdev->dev, "modem_reset", gpio);
1118         }
1119
1120         return 0;
1121 }
1122
1123 static int tegra_usb_modem_probe(struct platform_device *pdev)
1124 {
1125         struct tegra_usb_modem *modem;
1126         int ret = 0;
1127
1128         modem = kzalloc(sizeof(struct tegra_usb_modem), GFP_KERNEL);
1129         if (!modem) {
1130                 dev_dbg(&pdev->dev, "failed to allocate memory\n");
1131                 return -ENOMEM;
1132         }
1133
1134         /* initialize from device tree */
1135         ret = tegra_usb_modem_parse_dt(modem, pdev);
1136         if (ret) {
1137                 dev_err(&pdev->dev, "device tree parsing error\n");
1138                 kfree(modem);
1139                 return ret;
1140         }
1141
1142         ret = mdm_init(modem, pdev);
1143         if (ret) {
1144                 kfree(modem);
1145                 return ret;
1146         }
1147
1148         dev_set_drvdata(&pdev->dev, modem);
1149
1150         return ret;
1151 }
1152
1153 static int __exit tegra_usb_modem_remove(struct platform_device *pdev)
1154 {
1155         struct tegra_usb_modem *modem = platform_get_drvdata(pdev);
1156
1157         unregister_pm_notifier(&modem->pm_notifier);
1158         usb_unregister_notify(&modem->usb_notifier);
1159
1160         if (modem->modem_edp_pdev)
1161                 platform_device_unregister(modem->modem_edp_pdev);
1162
1163         if (modem->wake_irq)
1164                 free_irq(modem->wake_irq, modem);
1165
1166         if (modem->boot_irq)
1167                 free_irq(modem->boot_irq, modem);
1168
1169         if (modem->sysfs_file_created)
1170                 device_remove_file(&pdev->dev, &dev_attr_load_host);
1171
1172         if (modem->modem_state_file_created)
1173                 device_remove_file(&pdev->dev, &dev_attr_modem_state);
1174
1175         if (!IS_ERR(modem->regulator))
1176                 regulator_put(modem->regulator);
1177
1178         cancel_delayed_work_sync(&modem->recovery_work);
1179         cancel_delayed_work_sync(&modem->enable_nvhsic_work);
1180         cancel_work_sync(&modem->host_load_work);
1181         cancel_work_sync(&modem->host_unload_work);
1182         cancel_work_sync(&modem->cpu_boost_work);
1183         cancel_delayed_work_sync(&modem->cpu_unboost_work);
1184         destroy_workqueue(modem->wq);
1185
1186         pm_qos_remove_request(&modem->cpu_boost_req);
1187
1188         kfree(modem);
1189         return 0;
1190 }
1191
1192 static void tegra_usb_modem_shutdown(struct platform_device *pdev)
1193 {
1194         struct tegra_usb_modem *modem = platform_get_drvdata(pdev);
1195
1196         if (modem->ops && modem->ops->stop)
1197                 modem->ops->stop();
1198 }
1199
1200 #ifdef CONFIG_PM
1201 static int tegra_usb_modem_suspend(struct platform_device *pdev,
1202                                    pm_message_t state)
1203 {
1204         struct tegra_usb_modem *modem = platform_get_drvdata(pdev);
1205         int ret = 0;
1206
1207         /* send L3 hint to modem */
1208         if (modem->ops && modem->ops->suspend)
1209                 modem->ops->suspend();
1210
1211         if (modem->wake_irq) {
1212                 ret = enable_irq_wake(modem->wake_irq);
1213                 if (ret) {
1214                         pr_info("%s, wake irq=%d, error=%d\n",
1215                                 __func__, modem->wake_irq, ret);
1216                         goto fail;
1217                 }
1218         }
1219
1220         if (modem->boot_irq) {
1221                 ret = enable_irq_wake(modem->boot_irq);
1222                 if (ret)
1223                         pr_info("%s, wake irq=%d, error=%d\n",
1224                                 __func__, modem->boot_irq, ret);
1225         }
1226
1227         if (gpio_is_valid(modem->pre_boost_gpio))
1228                 gpio_set_value(modem->pre_boost_gpio, 0);
1229 fail:
1230         return ret;
1231 }
1232
1233 static int tegra_usb_modem_resume(struct platform_device *pdev)
1234 {
1235         struct tegra_usb_modem *modem = platform_get_drvdata(pdev);
1236         int ret = 0;
1237
1238         if (gpio_is_valid(modem->pre_boost_gpio))
1239                 gpio_set_value(modem->pre_boost_gpio, 1);
1240
1241         if (modem->boot_irq) {
1242                 ret = disable_irq_wake(modem->boot_irq);
1243                 if (ret)
1244                         pr_err("Failed to disable modem boot_irq\n");
1245         }
1246
1247         if (modem->wake_irq) {
1248                 ret = disable_irq_wake(modem->wake_irq);
1249                 if (ret)
1250                         pr_err("Failed to disable modem wake_irq\n");
1251         }
1252
1253         /* send L3->L0 hint to modem */
1254         if (modem->ops && modem->ops->resume)
1255                 modem->ops->resume();
1256         return 0;
1257 }
1258 #endif
1259
1260 static const struct of_device_id tegra_usb_modem_match[] = {
1261         { .compatible = "nvidia,icera-i500", },
1262         {},
1263 };
1264 MODULE_DEVICE_TABLE(of, tegra_usb_modem_match);
1265
1266 static struct platform_driver tegra_usb_modem_power_driver = {
1267         .driver = {
1268                    .name = "tegra_usb_modem_power",
1269                    .owner = THIS_MODULE,
1270                    .of_match_table = of_match_ptr(tegra_usb_modem_match),
1271                    },
1272         .probe = tegra_usb_modem_probe,
1273         .remove = __exit_p(tegra_usb_modem_remove),
1274         .shutdown = tegra_usb_modem_shutdown,
1275 #ifdef CONFIG_PM
1276         .suspend = tegra_usb_modem_suspend,
1277         .resume = tegra_usb_modem_resume,
1278 #endif
1279 };
1280
1281 static int __init tegra_usb_modem_power_init(void)
1282 {
1283         return platform_driver_register(&tegra_usb_modem_power_driver);
1284 }
1285
1286 module_init(tegra_usb_modem_power_init);
1287
1288 static void __exit tegra_usb_modem_power_exit(void)
1289 {
1290         platform_driver_unregister(&tegra_usb_modem_power_driver);
1291 }
1292
1293 module_exit(tegra_usb_modem_power_exit);
1294
1295 MODULE_DESCRIPTION("Tegra usb modem power management driver");
1296 MODULE_LICENSE("GPL");