blob: 0737a81ff377181aa642eef317e51574968efd7e [file] [log] [blame]
Joel Kingb6f0f612011-11-01 16:59:14 -07001/* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/platform_device.h>
16#include <linux/err.h>
17#include <linux/slab.h>
18#include <linux/io.h>
19#include <linux/mutex.h>
20#include <linux/miscdevice.h>
21#include <linux/fs.h>
22#include <linux/gpio.h>
23#include <linux/kernel.h>
24#include <linux/irq.h>
25#include <linux/ioctl.h>
26#include <linux/delay.h>
27#include <linux/reboot.h>
28#include <linux/debugfs.h>
29#include <linux/completion.h>
30#include <linux/workqueue.h>
31#include <linux/clk.h>
32#include <linux/mfd/pmic8058.h>
33#include <asm/mach-types.h>
34#include <asm/uaccess.h>
35#include <mach/mdm2.h>
36#include <mach/restart.h>
37#include <mach/subsystem_notif.h>
38#include <mach/subsystem_restart.h>
39#include <linux/msm_charm.h>
40#include "msm_watchdog.h"
41#include "devices.h"
42#include "clock.h"
43#include "mdm_private.h"
44
45#define MDM_MODEM_TIMEOUT 6000
46#define MDM_HOLD_TIME 4000
47#define MDM_MODEM_DELTA 100
48#define IFLINE_UP 1
49#define IFLINE_DOWN 0
50
51static int mdm_debug_on;
52static int ifline_status = IFLINE_UP;
53static struct mdm_callbacks mdm_cb;
54
55#define MDM_DBG(...) do { if (mdm_debug_on) \
56 pr_info(__VA_ARGS__); \
57 } while (0);
58
59static void power_on_mdm(struct mdm_modem_drv *mdm_drv)
60{
61 /* Remove hsic driver before powering on the modem. */
62 if (ifline_status == IFLINE_UP) {
63 MDM_DBG("%s: Removing hsic device\n", __func__);
64 platform_device_del(&msm_device_hsic_host);
65 ifline_status = IFLINE_DOWN;
66 }
67
68 /* Pull both ERR_FATAL and RESET low */
69 MDM_DBG("Pulling PWR and RESET gpio's low\n");
70 gpio_direction_output(mdm_drv->ap2mdm_pmic_reset_n_gpio, 0);
71 gpio_direction_output(mdm_drv->ap2mdm_kpdpwr_n_gpio, 0);
72 /* Wait for them to settle. */
73 usleep(1000);
74
75 /* Deassert RESET first and wait for ir to settle. */
76 MDM_DBG("%s: Pulling RESET gpio high\n", __func__);
77 gpio_direction_output(mdm_drv->ap2mdm_pmic_reset_n_gpio, 1);
78 usleep(1000);
79
80 /* Pull PWR gpio high and wait for it to settle. */
81 MDM_DBG("%s: Powering on mdm modem\n", __func__);
82 gpio_direction_output(mdm_drv->ap2mdm_kpdpwr_n_gpio, 1);
83 usleep(1000);
84
85 /* Add back hsic device after modem power up */
86 MDM_DBG("%s: Adding hsic device\n", __func__);
87 platform_device_add(&msm_device_hsic_host);
88 ifline_status = IFLINE_UP;
89
90 msleep(200);
91}
92
93static void power_down_mdm(struct mdm_modem_drv *mdm_drv)
94{
95 int i;
96
97 for (i = MDM_MODEM_TIMEOUT; i > 0; i -= MDM_MODEM_DELTA) {
98 pet_watchdog();
99 msleep(MDM_MODEM_DELTA);
100 if (gpio_get_value(mdm_drv->mdm2ap_status_gpio) == 0)
101 break;
102 }
103
104 if (i <= 0) {
105 pr_err("%s: MDM2AP_STATUS never went low.\n",
106 __func__);
107 gpio_direction_output(mdm_drv->ap2mdm_pmic_reset_n_gpio, 0);
108
109 for (i = MDM_HOLD_TIME; i > 0; i -= MDM_MODEM_DELTA) {
110 pet_watchdog();
111 msleep(MDM_MODEM_DELTA);
112 }
113 }
114 /* Also remove the hsic device on 9k power down. */
115 MDM_DBG("%s: Removing hsic device\n", __func__);
116 if (ifline_status == IFLINE_UP) {
117 platform_device_del(&msm_device_hsic_host);
118 ifline_status = IFLINE_DOWN;
119 }
120}
121
122static void normal_boot_done(struct mdm_modem_drv *mdm_drv)
123{
124}
125
126static void debug_state_changed(int value)
127{
128 mdm_debug_on = value;
129}
130
131static int __init mdm_modem_probe(struct platform_device *pdev)
132{
133 /* Instantiate driver object. */
134 mdm_cb.power_on_mdm_cb = power_on_mdm;
135 mdm_cb.power_down_mdm_cb = power_down_mdm;
136 mdm_cb.normal_boot_done_cb = normal_boot_done;
137 mdm_cb.debug_state_changed_cb = debug_state_changed;
138 return mdm_common_create(pdev, &mdm_cb);
139}
140
141static int __devexit mdm_modem_remove(struct platform_device *pdev)
142{
143 return mdm_common_modem_remove(pdev);
144}
145
146static void mdm_modem_shutdown(struct platform_device *pdev)
147{
148 mdm_common_modem_shutdown(pdev);
149}
150
151static struct platform_driver mdm_modem_driver = {
152 .remove = mdm_modem_remove,
153 .shutdown = mdm_modem_shutdown,
154 .driver = {
155 .name = "mdm2_modem",
156 .owner = THIS_MODULE
157 },
158};
159
160static int __init mdm_modem_init(void)
161{
162 return platform_driver_probe(&mdm_modem_driver, mdm_modem_probe);
163}
164
165static void __exit mdm_modem_exit(void)
166{
167 platform_driver_unregister(&mdm_modem_driver);
168}
169
170module_init(mdm_modem_init);
171module_exit(mdm_modem_exit);
172
173MODULE_LICENSE("GPL v2");
174MODULE_DESCRIPTION("mdm modem driver");
175MODULE_VERSION("2.0");
176MODULE_ALIAS("mdm_modem");