Joel King | e9cd527 | 2012-01-28 12:48:59 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. |
Joel King | b6f0f61 | 2011-11-01 16:59:14 -0700 | [diff] [blame] | 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 |
Joel King | b6f0f61 | 2011-11-01 16:59:14 -0700 | [diff] [blame] | 48 | |
| 49 | static int mdm_debug_on; |
Joel King | d8052c0 | 2012-02-03 12:33:31 -0800 | [diff] [blame^] | 50 | static int hsic_peripheral_status = 1; |
| 51 | static DEFINE_MUTEX(hsic_status_lock); |
| 52 | |
| 53 | static void mdm_peripheral_connect(struct mdm_modem_drv *mdm_drv) |
| 54 | { |
| 55 | mutex_lock(&hsic_status_lock); |
| 56 | if (hsic_peripheral_status) |
| 57 | goto out; |
| 58 | if (mdm_drv->pdata->peripheral_platform_device) |
| 59 | platform_device_add(mdm_drv->pdata->peripheral_platform_device); |
| 60 | hsic_peripheral_status = 1; |
| 61 | out: |
| 62 | mutex_unlock(&hsic_status_lock); |
| 63 | } |
| 64 | |
| 65 | static void mdm_peripheral_disconnect(struct mdm_modem_drv *mdm_drv) |
| 66 | { |
| 67 | mutex_lock(&hsic_status_lock); |
| 68 | if (!hsic_peripheral_status) |
| 69 | goto out; |
| 70 | if (mdm_drv->pdata->peripheral_platform_device) |
| 71 | platform_device_del(mdm_drv->pdata->peripheral_platform_device); |
| 72 | hsic_peripheral_status = 0; |
| 73 | out: |
| 74 | mutex_unlock(&hsic_status_lock); |
| 75 | } |
Joel King | b6f0f61 | 2011-11-01 16:59:14 -0700 | [diff] [blame] | 76 | |
| 77 | static void power_on_mdm(struct mdm_modem_drv *mdm_drv) |
| 78 | { |
Joel King | d8052c0 | 2012-02-03 12:33:31 -0800 | [diff] [blame^] | 79 | mdm_peripheral_disconnect(mdm_drv); |
Joel King | b6f0f61 | 2011-11-01 16:59:14 -0700 | [diff] [blame] | 80 | |
| 81 | /* Pull both ERR_FATAL and RESET low */ |
Joel King | 2a42f50 | 2012-02-03 11:36:25 -0800 | [diff] [blame] | 82 | pr_debug("Pulling PWR and RESET gpio's low\n"); |
Joel King | b6f0f61 | 2011-11-01 16:59:14 -0700 | [diff] [blame] | 83 | gpio_direction_output(mdm_drv->ap2mdm_pmic_reset_n_gpio, 0); |
| 84 | gpio_direction_output(mdm_drv->ap2mdm_kpdpwr_n_gpio, 0); |
| 85 | /* Wait for them to settle. */ |
| 86 | usleep(1000); |
| 87 | |
| 88 | /* Deassert RESET first and wait for ir to settle. */ |
Joel King | 2a42f50 | 2012-02-03 11:36:25 -0800 | [diff] [blame] | 89 | pr_debug("%s: Pulling RESET gpio high\n", __func__); |
Joel King | b6f0f61 | 2011-11-01 16:59:14 -0700 | [diff] [blame] | 90 | gpio_direction_output(mdm_drv->ap2mdm_pmic_reset_n_gpio, 1); |
| 91 | usleep(1000); |
| 92 | |
| 93 | /* Pull PWR gpio high and wait for it to settle. */ |
Joel King | 2a42f50 | 2012-02-03 11:36:25 -0800 | [diff] [blame] | 94 | pr_debug("%s: Powering on mdm modem\n", __func__); |
Joel King | b6f0f61 | 2011-11-01 16:59:14 -0700 | [diff] [blame] | 95 | gpio_direction_output(mdm_drv->ap2mdm_kpdpwr_n_gpio, 1); |
| 96 | usleep(1000); |
| 97 | |
Joel King | d8052c0 | 2012-02-03 12:33:31 -0800 | [diff] [blame^] | 98 | mdm_peripheral_connect(mdm_drv); |
Joel King | b6f0f61 | 2011-11-01 16:59:14 -0700 | [diff] [blame] | 99 | |
| 100 | msleep(200); |
| 101 | } |
| 102 | |
| 103 | static void power_down_mdm(struct mdm_modem_drv *mdm_drv) |
| 104 | { |
| 105 | int i; |
| 106 | |
| 107 | for (i = MDM_MODEM_TIMEOUT; i > 0; i -= MDM_MODEM_DELTA) { |
| 108 | pet_watchdog(); |
| 109 | msleep(MDM_MODEM_DELTA); |
| 110 | if (gpio_get_value(mdm_drv->mdm2ap_status_gpio) == 0) |
| 111 | break; |
| 112 | } |
| 113 | |
| 114 | if (i <= 0) { |
| 115 | pr_err("%s: MDM2AP_STATUS never went low.\n", |
| 116 | __func__); |
| 117 | gpio_direction_output(mdm_drv->ap2mdm_pmic_reset_n_gpio, 0); |
| 118 | |
| 119 | for (i = MDM_HOLD_TIME; i > 0; i -= MDM_MODEM_DELTA) { |
| 120 | pet_watchdog(); |
| 121 | msleep(MDM_MODEM_DELTA); |
| 122 | } |
| 123 | } |
Vamsi Krishna | 6aa6b1f | 2011-12-14 22:55:20 -0800 | [diff] [blame] | 124 | |
Joel King | d8052c0 | 2012-02-03 12:33:31 -0800 | [diff] [blame^] | 125 | mdm_peripheral_disconnect(mdm_drv); |
Joel King | b6f0f61 | 2011-11-01 16:59:14 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Joel King | b6f0f61 | 2011-11-01 16:59:14 -0700 | [diff] [blame] | 128 | static void debug_state_changed(int value) |
| 129 | { |
| 130 | mdm_debug_on = value; |
| 131 | } |
| 132 | |
Joel King | d8052c0 | 2012-02-03 12:33:31 -0800 | [diff] [blame^] | 133 | static void mdm_status_changed(struct mdm_modem_drv *mdm_drv, int value) |
Vamsi Krishna | 3392563 | 2011-12-13 15:43:09 -0800 | [diff] [blame] | 134 | { |
Joel King | 2a42f50 | 2012-02-03 11:36:25 -0800 | [diff] [blame] | 135 | pr_debug("%s: value:%d\n", __func__, value); |
Vamsi Krishna | 3392563 | 2011-12-13 15:43:09 -0800 | [diff] [blame] | 136 | |
| 137 | if (value) { |
Joel King | d8052c0 | 2012-02-03 12:33:31 -0800 | [diff] [blame^] | 138 | mdm_peripheral_disconnect(mdm_drv); |
| 139 | mdm_peripheral_connect(mdm_drv); |
Vamsi Krishna | 3392563 | 2011-12-13 15:43:09 -0800 | [diff] [blame] | 140 | } |
| 141 | } |
| 142 | |
Joel King | e9cd527 | 2012-01-28 12:48:59 -0800 | [diff] [blame] | 143 | static struct mdm_ops mdm_cb = { |
| 144 | .power_on_mdm_cb = power_on_mdm, |
| 145 | .power_down_mdm_cb = power_down_mdm, |
| 146 | .debug_state_changed_cb = debug_state_changed, |
| 147 | .status_cb = mdm_status_changed, |
| 148 | }; |
| 149 | |
Joel King | b6f0f61 | 2011-11-01 16:59:14 -0700 | [diff] [blame] | 150 | static int __init mdm_modem_probe(struct platform_device *pdev) |
| 151 | { |
Joel King | b6f0f61 | 2011-11-01 16:59:14 -0700 | [diff] [blame] | 152 | return mdm_common_create(pdev, &mdm_cb); |
| 153 | } |
| 154 | |
| 155 | static int __devexit mdm_modem_remove(struct platform_device *pdev) |
| 156 | { |
| 157 | return mdm_common_modem_remove(pdev); |
| 158 | } |
| 159 | |
| 160 | static void mdm_modem_shutdown(struct platform_device *pdev) |
| 161 | { |
| 162 | mdm_common_modem_shutdown(pdev); |
| 163 | } |
| 164 | |
| 165 | static struct platform_driver mdm_modem_driver = { |
| 166 | .remove = mdm_modem_remove, |
| 167 | .shutdown = mdm_modem_shutdown, |
| 168 | .driver = { |
| 169 | .name = "mdm2_modem", |
| 170 | .owner = THIS_MODULE |
| 171 | }, |
| 172 | }; |
| 173 | |
| 174 | static int __init mdm_modem_init(void) |
| 175 | { |
| 176 | return platform_driver_probe(&mdm_modem_driver, mdm_modem_probe); |
| 177 | } |
| 178 | |
| 179 | static void __exit mdm_modem_exit(void) |
| 180 | { |
| 181 | platform_driver_unregister(&mdm_modem_driver); |
| 182 | } |
| 183 | |
| 184 | module_init(mdm_modem_init); |
| 185 | module_exit(mdm_modem_exit); |
| 186 | |
| 187 | MODULE_LICENSE("GPL v2"); |
| 188 | MODULE_DESCRIPTION("mdm modem driver"); |
| 189 | MODULE_VERSION("2.0"); |
| 190 | MODULE_ALIAS("mdm_modem"); |