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> |
Vamsi Krishna | 6aa6b1f | 2011-12-14 22:55:20 -0800 | [diff] [blame] | 36 | #include <mach/mdm-peripheral.h> |
Joel King | b6f0f61 | 2011-11-01 16:59:14 -0700 | [diff] [blame] | 37 | #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 King | b6f0f61 | 2011-11-01 16:59:14 -0700 | [diff] [blame] | 49 | |
| 50 | static int mdm_debug_on; |
Joel King | b6f0f61 | 2011-11-01 16:59:14 -0700 | [diff] [blame] | 51 | #define MDM_DBG(...) do { if (mdm_debug_on) \ |
| 52 | pr_info(__VA_ARGS__); \ |
| 53 | } while (0); |
| 54 | |
| 55 | static void power_on_mdm(struct mdm_modem_drv *mdm_drv) |
| 56 | { |
Vamsi Krishna | 6aa6b1f | 2011-12-14 22:55:20 -0800 | [diff] [blame] | 57 | peripheral_disconnect(); |
Joel King | b6f0f61 | 2011-11-01 16:59:14 -0700 | [diff] [blame] | 58 | |
| 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 Krishna | 6aa6b1f | 2011-12-14 22:55:20 -0800 | [diff] [blame] | 76 | peripheral_connect(); |
Joel King | b6f0f61 | 2011-11-01 16:59:14 -0700 | [diff] [blame] | 77 | |
| 78 | msleep(200); |
| 79 | } |
| 80 | |
| 81 | static 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 Krishna | 6aa6b1f | 2011-12-14 22:55:20 -0800 | [diff] [blame] | 102 | |
| 103 | peripheral_disconnect(); |
Joel King | b6f0f61 | 2011-11-01 16:59:14 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Joel King | b6f0f61 | 2011-11-01 16:59:14 -0700 | [diff] [blame] | 106 | static void debug_state_changed(int value) |
| 107 | { |
| 108 | mdm_debug_on = value; |
| 109 | } |
| 110 | |
Vamsi Krishna | 3392563 | 2011-12-13 15:43:09 -0800 | [diff] [blame] | 111 | static 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 King | e9cd527 | 2012-01-28 12:48:59 -0800 | [diff] [blame] | 121 | static 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 King | b6f0f61 | 2011-11-01 16:59:14 -0700 | [diff] [blame] | 128 | static int __init mdm_modem_probe(struct platform_device *pdev) |
| 129 | { |
Joel King | b6f0f61 | 2011-11-01 16:59:14 -0700 | [diff] [blame] | 130 | return mdm_common_create(pdev, &mdm_cb); |
| 131 | } |
| 132 | |
| 133 | static int __devexit mdm_modem_remove(struct platform_device *pdev) |
| 134 | { |
| 135 | return mdm_common_modem_remove(pdev); |
| 136 | } |
| 137 | |
| 138 | static void mdm_modem_shutdown(struct platform_device *pdev) |
| 139 | { |
| 140 | mdm_common_modem_shutdown(pdev); |
| 141 | } |
| 142 | |
| 143 | static 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 | |
| 152 | static int __init mdm_modem_init(void) |
| 153 | { |
| 154 | return platform_driver_probe(&mdm_modem_driver, mdm_modem_probe); |
| 155 | } |
| 156 | |
| 157 | static void __exit mdm_modem_exit(void) |
| 158 | { |
| 159 | platform_driver_unregister(&mdm_modem_driver); |
| 160 | } |
| 161 | |
| 162 | module_init(mdm_modem_init); |
| 163 | module_exit(mdm_modem_exit); |
| 164 | |
| 165 | MODULE_LICENSE("GPL v2"); |
| 166 | MODULE_DESCRIPTION("mdm modem driver"); |
| 167 | MODULE_VERSION("2.0"); |
| 168 | MODULE_ALIAS("mdm_modem"); |