blob: 309f192a84c66837952fe304f6d0c75dc16a6279 [file] [log] [blame]
Joel Kinge9cd5272012-01-28 12:48:59 -08001/* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
Joel Kingb6f0f612011-11-01 16:59:14 -07002 *
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
Joel Kingb6f0f612011-11-01 16:59:14 -070049
50static int mdm_debug_on;
Joel Kingb6f0f612011-11-01 16:59:14 -070051#define MDM_DBG(...) do { if (mdm_debug_on) \
52 pr_info(__VA_ARGS__); \
53 } while (0);
54
55static void power_on_mdm(struct mdm_modem_drv *mdm_drv)
56{
Vamsi Krishna6aa6b1f2011-12-14 22:55:20 -080057 peripheral_disconnect();
Joel Kingb6f0f612011-11-01 16:59:14 -070058
59 /* Pull both ERR_FATAL and RESET low */
60 MDM_DBG("Pulling PWR and RESET gpio's low\n");
61 gpio_direction_output(mdm_drv->ap2mdm_pmic_reset_n_gpio, 0);
62 gpio_direction_output(mdm_drv->ap2mdm_kpdpwr_n_gpio, 0);
63 /* Wait for them to settle. */
64 usleep(1000);
65
66 /* Deassert RESET first and wait for ir to settle. */
67 MDM_DBG("%s: Pulling RESET gpio high\n", __func__);
68 gpio_direction_output(mdm_drv->ap2mdm_pmic_reset_n_gpio, 1);
69 usleep(1000);
70
71 /* Pull PWR gpio high and wait for it to settle. */
72 MDM_DBG("%s: Powering on mdm modem\n", __func__);
73 gpio_direction_output(mdm_drv->ap2mdm_kpdpwr_n_gpio, 1);
74 usleep(1000);
75
Vamsi Krishna6aa6b1f2011-12-14 22:55:20 -080076 peripheral_connect();
Joel Kingb6f0f612011-11-01 16:59:14 -070077
78 msleep(200);
79}
80
81static void power_down_mdm(struct mdm_modem_drv *mdm_drv)
82{
83 int i;
84
85 for (i = MDM_MODEM_TIMEOUT; i > 0; i -= MDM_MODEM_DELTA) {
86 pet_watchdog();
87 msleep(MDM_MODEM_DELTA);
88 if (gpio_get_value(mdm_drv->mdm2ap_status_gpio) == 0)
89 break;
90 }
91
92 if (i <= 0) {
93 pr_err("%s: MDM2AP_STATUS never went low.\n",
94 __func__);
95 gpio_direction_output(mdm_drv->ap2mdm_pmic_reset_n_gpio, 0);
96
97 for (i = MDM_HOLD_TIME; i > 0; i -= MDM_MODEM_DELTA) {
98 pet_watchdog();
99 msleep(MDM_MODEM_DELTA);
100 }
101 }
Vamsi Krishna6aa6b1f2011-12-14 22:55:20 -0800102
103 peripheral_disconnect();
Joel Kingb6f0f612011-11-01 16:59:14 -0700104}
105
Joel Kingb6f0f612011-11-01 16:59:14 -0700106static void debug_state_changed(int value)
107{
108 mdm_debug_on = value;
109}
110
Vamsi Krishna33925632011-12-13 15:43:09 -0800111static void mdm_status_changed(int value)
112{
113 MDM_DBG("%s: value:%d\n", __func__, value);
114
115 if (value) {
116 peripheral_disconnect();
117 peripheral_connect();
118 }
119}
120
Joel Kinge9cd5272012-01-28 12:48:59 -0800121static struct mdm_ops mdm_cb = {
122 .power_on_mdm_cb = power_on_mdm,
123 .power_down_mdm_cb = power_down_mdm,
124 .debug_state_changed_cb = debug_state_changed,
125 .status_cb = mdm_status_changed,
126};
127
Joel Kingb6f0f612011-11-01 16:59:14 -0700128static int __init mdm_modem_probe(struct platform_device *pdev)
129{
Joel Kingb6f0f612011-11-01 16:59:14 -0700130 return mdm_common_create(pdev, &mdm_cb);
131}
132
133static int __devexit mdm_modem_remove(struct platform_device *pdev)
134{
135 return mdm_common_modem_remove(pdev);
136}
137
138static void mdm_modem_shutdown(struct platform_device *pdev)
139{
140 mdm_common_modem_shutdown(pdev);
141}
142
143static struct platform_driver mdm_modem_driver = {
144 .remove = mdm_modem_remove,
145 .shutdown = mdm_modem_shutdown,
146 .driver = {
147 .name = "mdm2_modem",
148 .owner = THIS_MODULE
149 },
150};
151
152static int __init mdm_modem_init(void)
153{
154 return platform_driver_probe(&mdm_modem_driver, mdm_modem_probe);
155}
156
157static void __exit mdm_modem_exit(void)
158{
159 platform_driver_unregister(&mdm_modem_driver);
160}
161
162module_init(mdm_modem_init);
163module_exit(mdm_modem_exit);
164
165MODULE_LICENSE("GPL v2");
166MODULE_DESCRIPTION("mdm modem driver");
167MODULE_VERSION("2.0");
168MODULE_ALIAS("mdm_modem");