blob: 91f8fc23085f35e8207622e39ae66d19d843d9e6 [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>
Vamsi Krishna6aa6b1f2011-12-14 22:55:20 -080036#include <mach/mdm-peripheral.h>
Joel Kingb6f0f612011-11-01 16:59:14 -070037#include <mach/restart.h>
38#include <mach/subsystem_notif.h>
39#include <mach/subsystem_restart.h>
40#include <linux/msm_charm.h>
41#include "msm_watchdog.h"
42#include "devices.h"
43#include "clock.h"
44#include "mdm_private.h"
45
46#define MDM_MODEM_TIMEOUT 6000
47#define MDM_HOLD_TIME 4000
48#define MDM_MODEM_DELTA 100
49#define IFLINE_UP 1
50#define IFLINE_DOWN 0
51
52static int mdm_debug_on;
Joel Kingb6f0f612011-11-01 16:59:14 -070053static 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{
Vamsi Krishna6aa6b1f2011-12-14 22:55:20 -080061 peripheral_disconnect();
Joel Kingb6f0f612011-11-01 16:59:14 -070062
63 /* Pull both ERR_FATAL and RESET low */
64 MDM_DBG("Pulling PWR and RESET gpio's low\n");
65 gpio_direction_output(mdm_drv->ap2mdm_pmic_reset_n_gpio, 0);
66 gpio_direction_output(mdm_drv->ap2mdm_kpdpwr_n_gpio, 0);
67 /* Wait for them to settle. */
68 usleep(1000);
69
70 /* Deassert RESET first and wait for ir to settle. */
71 MDM_DBG("%s: Pulling RESET gpio high\n", __func__);
72 gpio_direction_output(mdm_drv->ap2mdm_pmic_reset_n_gpio, 1);
73 usleep(1000);
74
75 /* Pull PWR gpio high and wait for it to settle. */
76 MDM_DBG("%s: Powering on mdm modem\n", __func__);
77 gpio_direction_output(mdm_drv->ap2mdm_kpdpwr_n_gpio, 1);
78 usleep(1000);
79
Vamsi Krishna6aa6b1f2011-12-14 22:55:20 -080080 peripheral_connect();
Joel Kingb6f0f612011-11-01 16:59:14 -070081
82 msleep(200);
83}
84
85static void power_down_mdm(struct mdm_modem_drv *mdm_drv)
86{
87 int i;
88
89 for (i = MDM_MODEM_TIMEOUT; i > 0; i -= MDM_MODEM_DELTA) {
90 pet_watchdog();
91 msleep(MDM_MODEM_DELTA);
92 if (gpio_get_value(mdm_drv->mdm2ap_status_gpio) == 0)
93 break;
94 }
95
96 if (i <= 0) {
97 pr_err("%s: MDM2AP_STATUS never went low.\n",
98 __func__);
99 gpio_direction_output(mdm_drv->ap2mdm_pmic_reset_n_gpio, 0);
100
101 for (i = MDM_HOLD_TIME; i > 0; i -= MDM_MODEM_DELTA) {
102 pet_watchdog();
103 msleep(MDM_MODEM_DELTA);
104 }
105 }
Vamsi Krishna6aa6b1f2011-12-14 22:55:20 -0800106
107 peripheral_disconnect();
Joel Kingb6f0f612011-11-01 16:59:14 -0700108}
109
110static void normal_boot_done(struct mdm_modem_drv *mdm_drv)
111{
112}
113
114static void debug_state_changed(int value)
115{
116 mdm_debug_on = value;
117}
118
119static int __init mdm_modem_probe(struct platform_device *pdev)
120{
121 /* Instantiate driver object. */
122 mdm_cb.power_on_mdm_cb = power_on_mdm;
123 mdm_cb.power_down_mdm_cb = power_down_mdm;
124 mdm_cb.normal_boot_done_cb = normal_boot_done;
125 mdm_cb.debug_state_changed_cb = debug_state_changed;
126 return mdm_common_create(pdev, &mdm_cb);
127}
128
129static int __devexit mdm_modem_remove(struct platform_device *pdev)
130{
131 return mdm_common_modem_remove(pdev);
132}
133
134static void mdm_modem_shutdown(struct platform_device *pdev)
135{
136 mdm_common_modem_shutdown(pdev);
137}
138
139static struct platform_driver mdm_modem_driver = {
140 .remove = mdm_modem_remove,
141 .shutdown = mdm_modem_shutdown,
142 .driver = {
143 .name = "mdm2_modem",
144 .owner = THIS_MODULE
145 },
146};
147
148static int __init mdm_modem_init(void)
149{
150 return platform_driver_probe(&mdm_modem_driver, mdm_modem_probe);
151}
152
153static void __exit mdm_modem_exit(void)
154{
155 platform_driver_unregister(&mdm_modem_driver);
156}
157
158module_init(mdm_modem_init);
159module_exit(mdm_modem_exit);
160
161MODULE_LICENSE("GPL v2");
162MODULE_DESCRIPTION("mdm modem driver");
163MODULE_VERSION("2.0");
164MODULE_ALIAS("mdm_modem");