Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2008-2009, 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 | * MSM architecture driver to reset the modem |
| 15 | */ |
| 16 | #include <linux/uaccess.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/fs.h> |
| 19 | #include <linux/miscdevice.h> |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 20 | #include <mach/proc_comm.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 21 | |
| 22 | #include "smd_private.h" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 23 | |
| 24 | #define DEBUG |
| 25 | /* #undef DEBUG */ |
| 26 | #ifdef DEBUG |
| 27 | #define D(x...) printk(x) |
| 28 | #else |
| 29 | #define D(x...) do {} while (0) |
| 30 | #endif |
| 31 | |
| 32 | static ssize_t reset_modem_read(struct file *fp, char __user *buf, |
| 33 | size_t count, loff_t *pos) |
| 34 | { |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | static ssize_t reset_modem_write(struct file *fp, const char __user *buf, |
| 39 | size_t count, loff_t *pos) |
| 40 | { |
| 41 | unsigned char cmd[64]; |
| 42 | int len; |
| 43 | int time; |
| 44 | int zero = 0; |
| 45 | int r; |
| 46 | |
| 47 | if (count < 1) |
| 48 | return 0; |
| 49 | |
| 50 | len = count > 63 ? 63 : count; |
| 51 | |
| 52 | if (copy_from_user(cmd, buf, len)) |
| 53 | return -EFAULT; |
| 54 | |
| 55 | cmd[len] = 0; |
| 56 | |
| 57 | /* lazy */ |
| 58 | if (cmd[len-1] == '\n') { |
| 59 | cmd[len-1] = 0; |
| 60 | len--; |
| 61 | } |
| 62 | |
| 63 | if (!strncmp(cmd, "wait", 4)) { |
| 64 | D(KERN_ERR "INFO:%s:%i:%s: " |
| 65 | "MODEM RESTART: WAIT\n", |
| 66 | __FILE__, |
| 67 | __LINE__, |
| 68 | __func__); |
| 69 | smsm_reset_modem(SMSM_MODEM_WAIT); |
| 70 | } else if (!strncmp(cmd, "continue", 8)) { |
| 71 | D(KERN_ERR "INFO:%s:%i:%s: " |
| 72 | "MODEM RESTART: CONTINUE\n", |
| 73 | __FILE__, |
| 74 | __LINE__, |
| 75 | __func__); |
| 76 | smsm_reset_modem_cont(); |
| 77 | } else if (!strncmp(cmd, "download", 8)) { |
| 78 | D(KERN_ERR "INFO:%s:%i:%s: " |
| 79 | "MODEM RESTART: DOWNLOAD\n", |
| 80 | __FILE__, |
| 81 | __LINE__, |
| 82 | __func__); |
| 83 | smsm_reset_modem(SMSM_SYSTEM_DOWNLOAD); |
| 84 | } else if (sscanf(cmd, "deferred reset %i", &time) == 1) { |
| 85 | D(KERN_ERR "INFO:%s:%i:%s: " |
| 86 | "MODEM RESTART: DEFERRED RESET %ims\n", |
| 87 | __FILE__, |
| 88 | __LINE__, |
| 89 | __func__, |
| 90 | time); |
| 91 | if (time == 0) { |
| 92 | r = 0; |
| 93 | msm_proc_comm_reset_modem_now(); |
| 94 | } else { |
| 95 | r = msm_proc_comm(PCOM_RESET_MODEM, &time, &zero); |
| 96 | } |
| 97 | if (r < 0) |
| 98 | return r; |
| 99 | } else if (!strncmp(cmd, "deferred reset", 14)) { |
| 100 | D(KERN_ERR "INFO:%s:%i:%s: " |
| 101 | "MODEM RESTART: DEFERRED RESET 0ms\n", |
| 102 | __FILE__, |
| 103 | __LINE__, |
| 104 | __func__); |
| 105 | r = 0; |
| 106 | msm_proc_comm_reset_modem_now(); |
| 107 | if (r < 0) |
| 108 | return r; |
| 109 | } else if (!strncmp(cmd, "reset chip now", 14)) { |
| 110 | uint param1 = 0x0; |
| 111 | uint param2 = 0x0; |
| 112 | |
| 113 | D(KERN_ERR "INFO:%s:%i:%s: " |
| 114 | "MODEM RESTART: CHIP RESET IMMEDIATE\n", |
| 115 | __FILE__, |
| 116 | __LINE__, |
| 117 | __func__); |
| 118 | |
| 119 | r = msm_proc_comm(PCOM_RESET_CHIP_IMM, ¶m1, ¶m2); |
| 120 | |
| 121 | if (r < 0) |
| 122 | return r; |
| 123 | } else if (!strncmp(cmd, "reset chip", 10)) { |
| 124 | |
| 125 | uint param1 = 0x0; |
| 126 | uint param2 = 0x0; |
| 127 | |
| 128 | D(KERN_ERR "INFO:%s:%i:%s: " |
| 129 | "MODEM RESTART: CHIP RESET \n", |
| 130 | __FILE__, |
| 131 | __LINE__, |
| 132 | __func__); |
| 133 | |
| 134 | r = msm_proc_comm(PCOM_RESET_CHIP, ¶m1, ¶m2); |
| 135 | |
| 136 | if (r < 0) |
| 137 | return r; |
| 138 | } else if (!strncmp(cmd, "reset", 5)) { |
| 139 | printk(KERN_ERR "INFO:%s:%i:%s: " |
| 140 | "MODEM RESTART: RESET\n", |
| 141 | __FILE__, |
| 142 | __LINE__, |
| 143 | __func__); |
| 144 | smsm_reset_modem(SMSM_RESET); |
| 145 | } else |
| 146 | return -EINVAL; |
| 147 | |
| 148 | return count; |
| 149 | } |
| 150 | |
| 151 | static int reset_modem_open(struct inode *ip, struct file *fp) |
| 152 | { |
| 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | static int reset_modem_release(struct inode *ip, struct file *fp) |
| 157 | { |
| 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | static const struct file_operations reset_modem_fops = { |
| 162 | .owner = THIS_MODULE, |
| 163 | .read = reset_modem_read, |
| 164 | .write = reset_modem_write, |
| 165 | .open = reset_modem_open, |
| 166 | .release = reset_modem_release, |
| 167 | }; |
| 168 | |
| 169 | static struct miscdevice reset_modem_dev = { |
| 170 | .minor = MISC_DYNAMIC_MINOR, |
| 171 | .name = "reset_modem", |
| 172 | .fops = &reset_modem_fops, |
| 173 | }; |
| 174 | |
| 175 | static int __init reset_modem_init(void) |
| 176 | { |
| 177 | return misc_register(&reset_modem_dev); |
| 178 | } |
| 179 | |
| 180 | module_init(reset_modem_init); |
| 181 | |
| 182 | MODULE_DESCRIPTION("Reset Modem"); |
| 183 | MODULE_LICENSE("GPL v2"); |