Duy Truong | 790f06d | 2013-02-13 16:38:12 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2008-2010, 2012, The Linux Foundation. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -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 | * Modem Restart Notifier -- Provides notification |
| 15 | * of modem restart events. |
| 16 | */ |
| 17 | |
| 18 | #include <linux/notifier.h> |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/debugfs.h> |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/workqueue.h> |
| 23 | |
| 24 | #include "modem_notifier.h" |
| 25 | |
| 26 | #define DEBUG |
| 27 | |
| 28 | static struct srcu_notifier_head modem_notifier_list; |
| 29 | static struct workqueue_struct *modem_notifier_wq; |
| 30 | |
| 31 | static void notify_work_smsm_init(struct work_struct *work) |
| 32 | { |
| 33 | modem_notify(0, MODEM_NOTIFIER_SMSM_INIT); |
| 34 | } |
| 35 | static DECLARE_WORK(modem_notifier_smsm_init_work, ¬ify_work_smsm_init); |
| 36 | |
| 37 | void modem_queue_smsm_init_notify(void) |
| 38 | { |
| 39 | int ret; |
| 40 | |
| 41 | ret = queue_work(modem_notifier_wq, &modem_notifier_smsm_init_work); |
| 42 | |
| 43 | if (!ret) |
| 44 | printk(KERN_ERR "%s\n", __func__); |
| 45 | } |
| 46 | EXPORT_SYMBOL(modem_queue_smsm_init_notify); |
| 47 | |
| 48 | static void notify_work_start_reset(struct work_struct *work) |
| 49 | { |
| 50 | modem_notify(0, MODEM_NOTIFIER_START_RESET); |
| 51 | } |
| 52 | static DECLARE_WORK(modem_notifier_start_reset_work, ¬ify_work_start_reset); |
| 53 | |
| 54 | void modem_queue_start_reset_notify(void) |
| 55 | { |
| 56 | int ret; |
| 57 | |
| 58 | ret = queue_work(modem_notifier_wq, &modem_notifier_start_reset_work); |
| 59 | |
| 60 | if (!ret) |
| 61 | printk(KERN_ERR "%s\n", __func__); |
| 62 | } |
| 63 | EXPORT_SYMBOL(modem_queue_start_reset_notify); |
| 64 | |
| 65 | static void notify_work_end_reset(struct work_struct *work) |
| 66 | { |
| 67 | modem_notify(0, MODEM_NOTIFIER_END_RESET); |
| 68 | } |
| 69 | static DECLARE_WORK(modem_notifier_end_reset_work, ¬ify_work_end_reset); |
| 70 | |
| 71 | void modem_queue_end_reset_notify(void) |
| 72 | { |
| 73 | int ret; |
| 74 | |
| 75 | ret = queue_work(modem_notifier_wq, &modem_notifier_end_reset_work); |
| 76 | |
| 77 | if (!ret) |
| 78 | printk(KERN_ERR "%s\n", __func__); |
| 79 | } |
| 80 | EXPORT_SYMBOL(modem_queue_end_reset_notify); |
| 81 | |
| 82 | int modem_register_notifier(struct notifier_block *nb) |
| 83 | { |
| 84 | int ret; |
| 85 | |
| 86 | ret = srcu_notifier_chain_register( |
| 87 | &modem_notifier_list, nb); |
| 88 | |
| 89 | return ret; |
| 90 | } |
| 91 | EXPORT_SYMBOL(modem_register_notifier); |
| 92 | |
| 93 | int modem_unregister_notifier(struct notifier_block *nb) |
| 94 | { |
| 95 | int ret; |
| 96 | |
| 97 | ret = srcu_notifier_chain_unregister( |
| 98 | &modem_notifier_list, nb); |
| 99 | |
| 100 | return ret; |
| 101 | } |
| 102 | EXPORT_SYMBOL(modem_unregister_notifier); |
| 103 | |
| 104 | void modem_notify(void *data, unsigned int state) |
| 105 | { |
| 106 | srcu_notifier_call_chain(&modem_notifier_list, state, data); |
| 107 | } |
| 108 | EXPORT_SYMBOL(modem_notify); |
| 109 | |
| 110 | #if defined(CONFIG_DEBUG_FS) |
| 111 | static int debug_reset_start(const char __user *buf, int count) |
| 112 | { |
| 113 | modem_queue_start_reset_notify(); |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | static int debug_reset_end(const char __user *buf, int count) |
| 118 | { |
| 119 | modem_queue_end_reset_notify(); |
| 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | static ssize_t debug_write(struct file *file, const char __user *buf, |
| 124 | size_t count, loff_t *ppos) |
| 125 | { |
| 126 | int (*fling)(const char __user *buf, int max) = file->private_data; |
| 127 | fling(buf, count); |
| 128 | return count; |
| 129 | } |
| 130 | |
| 131 | static int debug_open(struct inode *inode, struct file *file) |
| 132 | { |
| 133 | file->private_data = inode->i_private; |
| 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | static const struct file_operations debug_ops = { |
| 138 | .write = debug_write, |
| 139 | .open = debug_open, |
| 140 | }; |
| 141 | |
| 142 | static void debug_create(const char *name, mode_t mode, |
| 143 | struct dentry *dent, |
| 144 | int (*fling)(const char __user *buf, int max)) |
| 145 | { |
| 146 | debugfs_create_file(name, mode, dent, fling, &debug_ops); |
| 147 | } |
| 148 | |
| 149 | static void modem_notifier_debugfs_init(void) |
| 150 | { |
| 151 | struct dentry *dent; |
| 152 | |
| 153 | dent = debugfs_create_dir("modem_notifier", 0); |
| 154 | if (IS_ERR(dent)) |
| 155 | return; |
| 156 | |
| 157 | debug_create("reset_start", 0444, dent, debug_reset_start); |
| 158 | debug_create("reset_end", 0444, dent, debug_reset_end); |
| 159 | } |
| 160 | #else |
| 161 | static void modem_notifier_debugfs_init(void) {} |
| 162 | #endif |
| 163 | |
| 164 | #if defined(DEBUG) |
| 165 | static int modem_notifier_test_call(struct notifier_block *this, |
| 166 | unsigned long code, |
| 167 | void *_cmd) |
| 168 | { |
| 169 | switch (code) { |
| 170 | case MODEM_NOTIFIER_START_RESET: |
| 171 | printk(KERN_ERR "Notify: start reset\n"); |
| 172 | break; |
| 173 | case MODEM_NOTIFIER_END_RESET: |
| 174 | printk(KERN_ERR "Notify: end reset\n"); |
| 175 | break; |
| 176 | case MODEM_NOTIFIER_SMSM_INIT: |
| 177 | printk(KERN_ERR "Notify: smsm init\n"); |
| 178 | break; |
| 179 | default: |
| 180 | printk(KERN_ERR "Notify: general\n"); |
| 181 | break; |
| 182 | } |
| 183 | return NOTIFY_DONE; |
| 184 | } |
| 185 | |
| 186 | static struct notifier_block nb = { |
| 187 | .notifier_call = modem_notifier_test_call, |
| 188 | }; |
| 189 | |
| 190 | static void register_test_notifier(void) |
| 191 | { |
| 192 | modem_register_notifier(&nb); |
| 193 | } |
| 194 | #endif |
| 195 | |
Jeff Hugo | 0ce0a90 | 2012-06-11 15:53:18 -0600 | [diff] [blame] | 196 | int __init msm_init_modem_notifier_list(void) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 197 | { |
Jeff Hugo | 0ce0a90 | 2012-06-11 15:53:18 -0600 | [diff] [blame] | 198 | static bool registered; |
| 199 | |
| 200 | if (registered) |
| 201 | return 0; |
| 202 | |
| 203 | registered = true; |
| 204 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 205 | srcu_init_notifier_head(&modem_notifier_list); |
| 206 | modem_notifier_debugfs_init(); |
| 207 | #if defined(DEBUG) |
| 208 | register_test_notifier(); |
| 209 | #endif |
| 210 | |
| 211 | /* Create the workqueue */ |
| 212 | modem_notifier_wq = create_singlethread_workqueue("modem_notifier"); |
| 213 | if (!modem_notifier_wq) { |
| 214 | srcu_cleanup_notifier_head(&modem_notifier_list); |
| 215 | return -ENOMEM; |
| 216 | } |
| 217 | |
| 218 | return 0; |
| 219 | } |
Jeff Hugo | 0ce0a90 | 2012-06-11 15:53:18 -0600 | [diff] [blame] | 220 | module_init(msm_init_modem_notifier_list); |