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