blob: 2f2be31b655eeddedd64e3734c3dbfb53ea5ef01 [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
52static void power_on_mdm(struct mdm_modem_drv *mdm_drv)
53{
Vamsi Krishna6aa6b1f2011-12-14 22:55:20 -080054 peripheral_disconnect();
Joel Kingb6f0f612011-11-01 16:59:14 -070055
56 /* Pull both ERR_FATAL and RESET low */
Joel King2a42f502012-02-03 11:36:25 -080057 pr_debug("Pulling PWR and RESET gpio's low\n");
Joel Kingb6f0f612011-11-01 16:59:14 -070058 gpio_direction_output(mdm_drv->ap2mdm_pmic_reset_n_gpio, 0);
59 gpio_direction_output(mdm_drv->ap2mdm_kpdpwr_n_gpio, 0);
60 /* Wait for them to settle. */
61 usleep(1000);
62
63 /* Deassert RESET first and wait for ir to settle. */
Joel King2a42f502012-02-03 11:36:25 -080064 pr_debug("%s: Pulling RESET gpio high\n", __func__);
Joel Kingb6f0f612011-11-01 16:59:14 -070065 gpio_direction_output(mdm_drv->ap2mdm_pmic_reset_n_gpio, 1);
66 usleep(1000);
67
68 /* Pull PWR gpio high and wait for it to settle. */
Joel King2a42f502012-02-03 11:36:25 -080069 pr_debug("%s: Powering on mdm modem\n", __func__);
Joel Kingb6f0f612011-11-01 16:59:14 -070070 gpio_direction_output(mdm_drv->ap2mdm_kpdpwr_n_gpio, 1);
71 usleep(1000);
72
Vamsi Krishna6aa6b1f2011-12-14 22:55:20 -080073 peripheral_connect();
Joel Kingb6f0f612011-11-01 16:59:14 -070074
75 msleep(200);
76}
77
78static void power_down_mdm(struct mdm_modem_drv *mdm_drv)
79{
80 int i;
81
82 for (i = MDM_MODEM_TIMEOUT; i > 0; i -= MDM_MODEM_DELTA) {
83 pet_watchdog();
84 msleep(MDM_MODEM_DELTA);
85 if (gpio_get_value(mdm_drv->mdm2ap_status_gpio) == 0)
86 break;
87 }
88
89 if (i <= 0) {
90 pr_err("%s: MDM2AP_STATUS never went low.\n",
91 __func__);
92 gpio_direction_output(mdm_drv->ap2mdm_pmic_reset_n_gpio, 0);
93
94 for (i = MDM_HOLD_TIME; i > 0; i -= MDM_MODEM_DELTA) {
95 pet_watchdog();
96 msleep(MDM_MODEM_DELTA);
97 }
98 }
Vamsi Krishna6aa6b1f2011-12-14 22:55:20 -080099
100 peripheral_disconnect();
Joel Kingb6f0f612011-11-01 16:59:14 -0700101}
102
Joel Kingb6f0f612011-11-01 16:59:14 -0700103static void debug_state_changed(int value)
104{
105 mdm_debug_on = value;
106}
107
Vamsi Krishna33925632011-12-13 15:43:09 -0800108static void mdm_status_changed(int value)
109{
Joel King2a42f502012-02-03 11:36:25 -0800110 pr_debug("%s: value:%d\n", __func__, value);
Vamsi Krishna33925632011-12-13 15:43:09 -0800111
112 if (value) {
113 peripheral_disconnect();
114 peripheral_connect();
115 }
116}
117
Joel Kinge9cd5272012-01-28 12:48:59 -0800118static struct mdm_ops mdm_cb = {
119 .power_on_mdm_cb = power_on_mdm,
120 .power_down_mdm_cb = power_down_mdm,
121 .debug_state_changed_cb = debug_state_changed,
122 .status_cb = mdm_status_changed,
123};
124
Joel Kingb6f0f612011-11-01 16:59:14 -0700125static int __init mdm_modem_probe(struct platform_device *pdev)
126{
Joel Kingb6f0f612011-11-01 16:59:14 -0700127 return mdm_common_create(pdev, &mdm_cb);
128}
129
130static int __devexit mdm_modem_remove(struct platform_device *pdev)
131{
132 return mdm_common_modem_remove(pdev);
133}
134
135static void mdm_modem_shutdown(struct platform_device *pdev)
136{
137 mdm_common_modem_shutdown(pdev);
138}
139
140static struct platform_driver mdm_modem_driver = {
141 .remove = mdm_modem_remove,
142 .shutdown = mdm_modem_shutdown,
143 .driver = {
144 .name = "mdm2_modem",
145 .owner = THIS_MODULE
146 },
147};
148
149static int __init mdm_modem_init(void)
150{
151 return platform_driver_probe(&mdm_modem_driver, mdm_modem_probe);
152}
153
154static void __exit mdm_modem_exit(void)
155{
156 platform_driver_unregister(&mdm_modem_driver);
157}
158
159module_init(mdm_modem_init);
160module_exit(mdm_modem_exit);
161
162MODULE_LICENSE("GPL v2");
163MODULE_DESCRIPTION("mdm modem driver");
164MODULE_VERSION("2.0");
165MODULE_ALIAS("mdm_modem");