Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1 | /* arch/arm/mach-msm/smd.c |
| 2 | * |
| 3 | * Copyright (C) 2007 Google, Inc. |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 4 | * Copyright (c) 2008-2012, Code Aurora Forum. All rights reserved. |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 5 | * Author: Brian Swetland <swetland@google.com> |
| 6 | * |
| 7 | * This software is licensed under the terms of the GNU General Public |
| 8 | * License version 2, as published by the Free Software Foundation, and |
| 9 | * may be copied, distributed, and modified under those terms. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | */ |
| 17 | |
| 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/fs.h> |
| 21 | #include <linux/cdev.h> |
| 22 | #include <linux/device.h> |
| 23 | #include <linux/wait.h> |
| 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/irq.h> |
| 26 | #include <linux/list.h> |
| 27 | #include <linux/slab.h> |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 28 | #include <linux/delay.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 29 | #include <linux/io.h> |
| 30 | #include <linux/termios.h> |
| 31 | #include <linux/ctype.h> |
| 32 | #include <linux/remote_spinlock.h> |
| 33 | #include <linux/uaccess.h> |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 34 | #include <linux/kfifo.h> |
Eric Holmberg | 59a9f94 | 2012-03-19 10:04:22 -0600 | [diff] [blame^] | 35 | #include <linux/wakelock.h> |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 36 | #include <mach/msm_smd.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 37 | #include <mach/msm_iomap.h> |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 38 | #include <mach/system.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 39 | #include <mach/subsystem_notif.h> |
Angshuman Sarkar | ead67bd | 2011-09-21 20:13:12 +0530 | [diff] [blame] | 40 | #include <mach/socinfo.h> |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 41 | |
| 42 | #include "smd_private.h" |
| 43 | #include "proc_comm.h" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 44 | #include "modem_notifier.h" |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 45 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 46 | #if defined(CONFIG_ARCH_QSD8X50) || defined(CONFIG_ARCH_MSM8X60) \ |
Jeff Hugo | 56b933a | 2011-09-28 14:42:05 -0600 | [diff] [blame] | 47 | || defined(CONFIG_ARCH_MSM8960) || defined(CONFIG_ARCH_FSM9XXX) \ |
Jeff Hugo | 0c0f5e9 | 2011-09-28 13:55:45 -0600 | [diff] [blame] | 48 | || defined(CONFIG_ARCH_MSM9615) || defined(CONFIG_ARCH_APQ8064) |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 49 | #define CONFIG_QDSP6 1 |
| 50 | #endif |
| 51 | |
Jeff Hugo | 0c0f5e9 | 2011-09-28 13:55:45 -0600 | [diff] [blame] | 52 | #if defined(CONFIG_ARCH_MSM8X60) || defined(CONFIG_ARCH_MSM8960) \ |
| 53 | || defined(CONFIG_ARCH_APQ8064) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 54 | #define CONFIG_DSPS 1 |
| 55 | #endif |
| 56 | |
Jeff Hugo | 0c0f5e9 | 2011-09-28 13:55:45 -0600 | [diff] [blame] | 57 | #if defined(CONFIG_ARCH_MSM8960) \ |
| 58 | || defined(CONFIG_ARCH_APQ8064) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 59 | #define CONFIG_WCNSS 1 |
Jeff Hugo | 6a8057c | 2011-08-16 13:47:12 -0600 | [diff] [blame] | 60 | #define CONFIG_DSPS_SMSM 1 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 61 | #endif |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 62 | |
| 63 | #define MODULE_NAME "msm_smd" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 64 | #define SMEM_VERSION 0x000B |
| 65 | #define SMD_VERSION 0x00020000 |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 66 | #define SMSM_SNAPSHOT_CNT 64 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 67 | |
| 68 | uint32_t SMSM_NUM_ENTRIES = 8; |
| 69 | uint32_t SMSM_NUM_HOSTS = 3; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 70 | |
| 71 | enum { |
| 72 | MSM_SMD_DEBUG = 1U << 0, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 73 | MSM_SMSM_DEBUG = 1U << 1, |
| 74 | MSM_SMD_INFO = 1U << 2, |
| 75 | MSM_SMSM_INFO = 1U << 3, |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 76 | MSM_SMx_POWER_INFO = 1U << 4, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | struct smsm_shared_info { |
| 80 | uint32_t *state; |
| 81 | uint32_t *intr_mask; |
| 82 | uint32_t *intr_mux; |
| 83 | }; |
| 84 | |
| 85 | static struct smsm_shared_info smsm_info; |
Eric Holmberg | 59a9f94 | 2012-03-19 10:04:22 -0600 | [diff] [blame^] | 86 | static struct kfifo smsm_snapshot_fifo; |
| 87 | static struct wake_lock smsm_snapshot_wakelock; |
| 88 | static int smsm_snapshot_count; |
| 89 | static DEFINE_SPINLOCK(smsm_snapshot_count_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 90 | |
| 91 | struct smsm_size_info_type { |
| 92 | uint32_t num_hosts; |
| 93 | uint32_t num_entries; |
| 94 | uint32_t reserved0; |
| 95 | uint32_t reserved1; |
| 96 | }; |
| 97 | |
| 98 | struct smsm_state_cb_info { |
| 99 | struct list_head cb_list; |
| 100 | uint32_t mask; |
| 101 | void *data; |
| 102 | void (*notify)(void *data, uint32_t old_state, uint32_t new_state); |
| 103 | }; |
| 104 | |
| 105 | struct smsm_state_info { |
| 106 | struct list_head callbacks; |
| 107 | uint32_t last_value; |
| 108 | }; |
| 109 | |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 110 | struct interrupt_config_item { |
| 111 | /* must be initialized */ |
| 112 | irqreturn_t (*irq_handler)(int req, void *data); |
| 113 | /* outgoing interrupt config (set from platform data) */ |
| 114 | uint32_t out_bit_pos; |
| 115 | void __iomem *out_base; |
| 116 | uint32_t out_offset; |
| 117 | }; |
| 118 | |
| 119 | struct interrupt_config { |
| 120 | struct interrupt_config_item smd; |
| 121 | struct interrupt_config_item smsm; |
| 122 | }; |
| 123 | |
| 124 | static irqreturn_t smd_modem_irq_handler(int irq, void *data); |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 125 | static irqreturn_t smsm_modem_irq_handler(int irq, void *data); |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 126 | static irqreturn_t smd_dsp_irq_handler(int irq, void *data); |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 127 | static irqreturn_t smsm_dsp_irq_handler(int irq, void *data); |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 128 | static irqreturn_t smd_dsps_irq_handler(int irq, void *data); |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 129 | static irqreturn_t smsm_dsps_irq_handler(int irq, void *data); |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 130 | static irqreturn_t smd_wcnss_irq_handler(int irq, void *data); |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 131 | static irqreturn_t smsm_wcnss_irq_handler(int irq, void *data); |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 132 | static irqreturn_t smsm_irq_handler(int irq, void *data); |
| 133 | |
| 134 | static struct interrupt_config private_intr_config[NUM_SMD_SUBSYSTEMS] = { |
| 135 | [SMD_MODEM] = { |
| 136 | .smd.irq_handler = smd_modem_irq_handler, |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 137 | .smsm.irq_handler = smsm_modem_irq_handler, |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 138 | }, |
| 139 | [SMD_Q6] = { |
| 140 | .smd.irq_handler = smd_dsp_irq_handler, |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 141 | .smsm.irq_handler = smsm_dsp_irq_handler, |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 142 | }, |
| 143 | [SMD_DSPS] = { |
| 144 | .smd.irq_handler = smd_dsps_irq_handler, |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 145 | .smsm.irq_handler = smsm_dsps_irq_handler, |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 146 | }, |
| 147 | [SMD_WCNSS] = { |
| 148 | .smd.irq_handler = smd_wcnss_irq_handler, |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 149 | .smsm.irq_handler = smsm_wcnss_irq_handler, |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 150 | }, |
| 151 | }; |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 152 | struct interrupt_stat interrupt_stats[NUM_SMD_SUBSYSTEMS]; |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 153 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 154 | #define SMSM_STATE_ADDR(entry) (smsm_info.state + entry) |
| 155 | #define SMSM_INTR_MASK_ADDR(entry, host) (smsm_info.intr_mask + \ |
| 156 | entry * SMSM_NUM_HOSTS + host) |
| 157 | #define SMSM_INTR_MUX_ADDR(entry) (smsm_info.intr_mux + entry) |
| 158 | |
| 159 | /* Internal definitions which are not exported in some targets */ |
| 160 | enum { |
| 161 | SMSM_APPS_DEM_I = 3, |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 162 | }; |
| 163 | |
| 164 | static int msm_smd_debug_mask; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 165 | module_param_named(debug_mask, msm_smd_debug_mask, |
| 166 | int, S_IRUGO | S_IWUSR | S_IWGRP); |
| 167 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 168 | #if defined(CONFIG_MSM_SMD_DEBUG) |
| 169 | #define SMD_DBG(x...) do { \ |
| 170 | if (msm_smd_debug_mask & MSM_SMD_DEBUG) \ |
| 171 | printk(KERN_DEBUG x); \ |
| 172 | } while (0) |
| 173 | |
| 174 | #define SMSM_DBG(x...) do { \ |
| 175 | if (msm_smd_debug_mask & MSM_SMSM_DEBUG) \ |
| 176 | printk(KERN_DEBUG x); \ |
| 177 | } while (0) |
| 178 | |
| 179 | #define SMD_INFO(x...) do { \ |
| 180 | if (msm_smd_debug_mask & MSM_SMD_INFO) \ |
| 181 | printk(KERN_INFO x); \ |
| 182 | } while (0) |
| 183 | |
| 184 | #define SMSM_INFO(x...) do { \ |
| 185 | if (msm_smd_debug_mask & MSM_SMSM_INFO) \ |
| 186 | printk(KERN_INFO x); \ |
| 187 | } while (0) |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 188 | #define SMx_POWER_INFO(x...) do { \ |
| 189 | if (msm_smd_debug_mask & MSM_SMx_POWER_INFO) \ |
| 190 | printk(KERN_INFO x); \ |
| 191 | } while (0) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 192 | #else |
| 193 | #define SMD_DBG(x...) do { } while (0) |
| 194 | #define SMSM_DBG(x...) do { } while (0) |
| 195 | #define SMD_INFO(x...) do { } while (0) |
| 196 | #define SMSM_INFO(x...) do { } while (0) |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 197 | #define SMx_POWER_INFO(x...) do { } while (0) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 198 | #endif |
| 199 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 200 | static unsigned last_heap_free = 0xffffffff; |
| 201 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 202 | static inline void smd_write_intr(unsigned int val, |
| 203 | const void __iomem *addr); |
| 204 | |
| 205 | #if defined(CONFIG_ARCH_MSM7X30) |
| 206 | #define MSM_TRIG_A2M_SMD_INT \ |
Taniya Das | 298de8c | 2012-02-16 11:45:31 +0530 | [diff] [blame] | 207 | (smd_write_intr(1 << 0, MSM_APCS_GCC_BASE + 0x8)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 208 | #define MSM_TRIG_A2Q6_SMD_INT \ |
Taniya Das | 298de8c | 2012-02-16 11:45:31 +0530 | [diff] [blame] | 209 | (smd_write_intr(1 << 8, MSM_APCS_GCC_BASE + 0x8)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 210 | #define MSM_TRIG_A2M_SMSM_INT \ |
Taniya Das | 298de8c | 2012-02-16 11:45:31 +0530 | [diff] [blame] | 211 | (smd_write_intr(1 << 5, MSM_APCS_GCC_BASE + 0x8)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 212 | #define MSM_TRIG_A2Q6_SMSM_INT \ |
Taniya Das | 298de8c | 2012-02-16 11:45:31 +0530 | [diff] [blame] | 213 | (smd_write_intr(1 << 8, MSM_APCS_GCC_BASE + 0x8)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 214 | #define MSM_TRIG_A2DSPS_SMD_INT |
Jeff Hugo | 6a8057c | 2011-08-16 13:47:12 -0600 | [diff] [blame] | 215 | #define MSM_TRIG_A2DSPS_SMSM_INT |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 216 | #define MSM_TRIG_A2WCNSS_SMD_INT |
| 217 | #define MSM_TRIG_A2WCNSS_SMSM_INT |
| 218 | #elif defined(CONFIG_ARCH_MSM8X60) |
| 219 | #define MSM_TRIG_A2M_SMD_INT \ |
| 220 | (smd_write_intr(1 << 3, MSM_GCC_BASE + 0x8)) |
| 221 | #define MSM_TRIG_A2Q6_SMD_INT \ |
| 222 | (smd_write_intr(1 << 15, MSM_GCC_BASE + 0x8)) |
| 223 | #define MSM_TRIG_A2M_SMSM_INT \ |
| 224 | (smd_write_intr(1 << 4, MSM_GCC_BASE + 0x8)) |
| 225 | #define MSM_TRIG_A2Q6_SMSM_INT \ |
| 226 | (smd_write_intr(1 << 14, MSM_GCC_BASE + 0x8)) |
| 227 | #define MSM_TRIG_A2DSPS_SMD_INT \ |
| 228 | (smd_write_intr(1, MSM_SIC_NON_SECURE_BASE + 0x4080)) |
Jeff Hugo | 6a8057c | 2011-08-16 13:47:12 -0600 | [diff] [blame] | 229 | #define MSM_TRIG_A2DSPS_SMSM_INT |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 230 | #define MSM_TRIG_A2WCNSS_SMD_INT |
| 231 | #define MSM_TRIG_A2WCNSS_SMSM_INT |
Jeff Hugo | 56b933a | 2011-09-28 14:42:05 -0600 | [diff] [blame] | 232 | #elif defined(CONFIG_ARCH_MSM9615) |
| 233 | #define MSM_TRIG_A2M_SMD_INT \ |
| 234 | (smd_write_intr(1 << 3, MSM_APCS_GCC_BASE + 0x8)) |
| 235 | #define MSM_TRIG_A2Q6_SMD_INT \ |
| 236 | (smd_write_intr(1 << 15, MSM_APCS_GCC_BASE + 0x8)) |
| 237 | #define MSM_TRIG_A2M_SMSM_INT \ |
| 238 | (smd_write_intr(1 << 4, MSM_APCS_GCC_BASE + 0x8)) |
| 239 | #define MSM_TRIG_A2Q6_SMSM_INT \ |
| 240 | (smd_write_intr(1 << 14, MSM_APCS_GCC_BASE + 0x8)) |
| 241 | #define MSM_TRIG_A2DSPS_SMD_INT |
| 242 | #define MSM_TRIG_A2DSPS_SMSM_INT |
| 243 | #define MSM_TRIG_A2WCNSS_SMD_INT |
| 244 | #define MSM_TRIG_A2WCNSS_SMSM_INT |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 245 | #elif defined(CONFIG_ARCH_FSM9XXX) |
| 246 | #define MSM_TRIG_A2Q6_SMD_INT \ |
| 247 | (smd_write_intr(1 << 10, MSM_GCC_BASE + 0x8)) |
| 248 | #define MSM_TRIG_A2Q6_SMSM_INT \ |
| 249 | (smd_write_intr(1 << 10, MSM_GCC_BASE + 0x8)) |
| 250 | #define MSM_TRIG_A2M_SMD_INT \ |
| 251 | (smd_write_intr(1 << 0, MSM_GCC_BASE + 0x8)) |
| 252 | #define MSM_TRIG_A2M_SMSM_INT \ |
| 253 | (smd_write_intr(1 << 5, MSM_GCC_BASE + 0x8)) |
| 254 | #define MSM_TRIG_A2DSPS_SMD_INT |
Jeff Hugo | 6a8057c | 2011-08-16 13:47:12 -0600 | [diff] [blame] | 255 | #define MSM_TRIG_A2DSPS_SMSM_INT |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 256 | #define MSM_TRIG_A2WCNSS_SMD_INT |
| 257 | #define MSM_TRIG_A2WCNSS_SMSM_INT |
Eric Holmberg | 73d4546 | 2012-02-28 10:41:31 -0700 | [diff] [blame] | 258 | #elif defined(CONFIG_ARCH_MSM7X01A) || defined(CONFIG_ARCH_MSM7x25) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 259 | #define MSM_TRIG_A2M_SMD_INT \ |
| 260 | (smd_write_intr(1, MSM_CSR_BASE + 0x400 + (0) * 4)) |
Eric Holmberg | 73d4546 | 2012-02-28 10:41:31 -0700 | [diff] [blame] | 261 | #define MSM_TRIG_A2Q6_SMD_INT |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 262 | #define MSM_TRIG_A2M_SMSM_INT \ |
| 263 | (smd_write_intr(1, MSM_CSR_BASE + 0x400 + (5) * 4)) |
Eric Holmberg | 73d4546 | 2012-02-28 10:41:31 -0700 | [diff] [blame] | 264 | #define MSM_TRIG_A2Q6_SMSM_INT |
| 265 | #define MSM_TRIG_A2DSPS_SMD_INT |
| 266 | #define MSM_TRIG_A2DSPS_SMSM_INT |
| 267 | #define MSM_TRIG_A2WCNSS_SMD_INT |
| 268 | #define MSM_TRIG_A2WCNSS_SMSM_INT |
| 269 | #elif defined(CONFIG_ARCH_MSM7X27) || defined(CONFIG_ARCH_MSM7X27A) |
| 270 | #define MSM_TRIG_A2M_SMD_INT \ |
| 271 | (smd_write_intr(1, MSM_CSR_BASE + 0x400 + (0) * 4)) |
| 272 | #define MSM_TRIG_A2Q6_SMD_INT |
| 273 | #define MSM_TRIG_A2M_SMSM_INT \ |
| 274 | (smd_write_intr(1, MSM_CSR_BASE + 0x400 + (5) * 4)) |
| 275 | #define MSM_TRIG_A2Q6_SMSM_INT |
| 276 | #define MSM_TRIG_A2DSPS_SMD_INT |
| 277 | #define MSM_TRIG_A2DSPS_SMSM_INT |
| 278 | #define MSM_TRIG_A2WCNSS_SMD_INT |
| 279 | #define MSM_TRIG_A2WCNSS_SMSM_INT |
| 280 | #else /* use platform device / device tree configuration */ |
| 281 | #define MSM_TRIG_A2M_SMD_INT |
| 282 | #define MSM_TRIG_A2Q6_SMD_INT |
| 283 | #define MSM_TRIG_A2M_SMSM_INT |
| 284 | #define MSM_TRIG_A2Q6_SMSM_INT |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 285 | #define MSM_TRIG_A2DSPS_SMD_INT |
Jeff Hugo | 6a8057c | 2011-08-16 13:47:12 -0600 | [diff] [blame] | 286 | #define MSM_TRIG_A2DSPS_SMSM_INT |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 287 | #define MSM_TRIG_A2WCNSS_SMD_INT |
| 288 | #define MSM_TRIG_A2WCNSS_SMSM_INT |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 289 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 290 | |
Jeff Hugo | ee40b15 | 2012-02-09 17:39:47 -0700 | [diff] [blame] | 291 | /* |
| 292 | * stub out legacy macros if they are not being used so that the legacy |
| 293 | * code compiles even though it is not used |
| 294 | * |
| 295 | * these definitions should not be used in active code and will cause |
| 296 | * an early failure |
| 297 | */ |
| 298 | #ifndef INT_A9_M2A_0 |
| 299 | #define INT_A9_M2A_0 -1 |
| 300 | #endif |
| 301 | #ifndef INT_A9_M2A_5 |
| 302 | #define INT_A9_M2A_5 -1 |
| 303 | #endif |
| 304 | #ifndef INT_ADSP_A11 |
| 305 | #define INT_ADSP_A11 -1 |
| 306 | #endif |
| 307 | #ifndef INT_ADSP_A11_SMSM |
| 308 | #define INT_ADSP_A11_SMSM -1 |
| 309 | #endif |
| 310 | #ifndef INT_DSPS_A11 |
| 311 | #define INT_DSPS_A11 -1 |
| 312 | #endif |
| 313 | #ifndef INT_DSPS_A11_SMSM |
| 314 | #define INT_DSPS_A11_SMSM -1 |
| 315 | #endif |
| 316 | #ifndef INT_WCNSS_A11 |
| 317 | #define INT_WCNSS_A11 -1 |
| 318 | #endif |
| 319 | #ifndef INT_WCNSS_A11_SMSM |
| 320 | #define INT_WCNSS_A11_SMSM -1 |
| 321 | #endif |
| 322 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 323 | #define SMD_LOOPBACK_CID 100 |
| 324 | |
Eric Holmberg | f6d7d1a | 2011-09-23 18:31:04 -0600 | [diff] [blame] | 325 | #define SMEM_SPINLOCK_SMEM_ALLOC "S:3" |
| 326 | static remote_spinlock_t remote_spinlock; |
| 327 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 328 | static LIST_HEAD(smd_ch_list_loopback); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 329 | static void smd_fake_irq_handler(unsigned long arg); |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 330 | static void smsm_cb_snapshot(void); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 331 | |
| 332 | static void notify_smsm_cb_clients_worker(struct work_struct *work); |
| 333 | static DECLARE_WORK(smsm_cb_work, notify_smsm_cb_clients_worker); |
Eric Holmberg | c800290 | 2011-09-16 13:55:57 -0600 | [diff] [blame] | 334 | static DEFINE_MUTEX(smsm_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 335 | static struct smsm_state_info *smsm_states; |
Angshuman Sarkar | 7ee0dca | 2011-08-22 21:37:34 +0530 | [diff] [blame] | 336 | static int spinlocks_initialized; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 337 | |
| 338 | static inline void smd_write_intr(unsigned int val, |
| 339 | const void __iomem *addr) |
| 340 | { |
| 341 | wmb(); |
| 342 | __raw_writel(val, addr); |
| 343 | } |
| 344 | |
| 345 | #ifdef CONFIG_WCNSS |
| 346 | static inline void wakeup_v1_riva(void) |
| 347 | { |
| 348 | /* |
| 349 | * workaround hack for RIVA v1 hardware bug |
| 350 | * trigger GPIO 40 to wake up RIVA from power collaspe |
| 351 | * not to be sent to customers |
| 352 | */ |
Jeff Hugo | afb8c4a | 2011-10-27 15:57:27 -0600 | [diff] [blame] | 353 | if (SOCINFO_VERSION_MAJOR(socinfo_get_version()) == 1) { |
| 354 | __raw_writel(0x0, MSM_TLMM_BASE + 0x1284); |
| 355 | __raw_writel(0x2, MSM_TLMM_BASE + 0x1284); |
| 356 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 357 | /* end workaround */ |
| 358 | } |
| 359 | #else |
| 360 | static inline void wakeup_v1_riva(void) {} |
| 361 | #endif |
| 362 | |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 363 | static inline void notify_modem_smd(void) |
| 364 | { |
| 365 | static const struct interrupt_config_item *intr |
| 366 | = &private_intr_config[SMD_MODEM].smd; |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 367 | if (intr->out_base) { |
| 368 | ++interrupt_stats[SMD_MODEM].smd_out_config_count; |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 369 | smd_write_intr(intr->out_bit_pos, |
| 370 | intr->out_base + intr->out_offset); |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 371 | } else { |
| 372 | ++interrupt_stats[SMD_MODEM].smd_out_hardcode_count; |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 373 | MSM_TRIG_A2M_SMD_INT; |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 374 | } |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | static inline void notify_dsp_smd(void) |
| 378 | { |
| 379 | static const struct interrupt_config_item *intr |
| 380 | = &private_intr_config[SMD_Q6].smd; |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 381 | if (intr->out_base) { |
| 382 | ++interrupt_stats[SMD_Q6].smd_out_config_count; |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 383 | smd_write_intr(intr->out_bit_pos, |
| 384 | intr->out_base + intr->out_offset); |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 385 | } else { |
| 386 | ++interrupt_stats[SMD_Q6].smd_out_hardcode_count; |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 387 | MSM_TRIG_A2Q6_SMD_INT; |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 388 | } |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | static inline void notify_dsps_smd(void) |
| 392 | { |
| 393 | static const struct interrupt_config_item *intr |
| 394 | = &private_intr_config[SMD_DSPS].smd; |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 395 | if (intr->out_base) { |
| 396 | ++interrupt_stats[SMD_DSPS].smd_out_config_count; |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 397 | smd_write_intr(intr->out_bit_pos, |
| 398 | intr->out_base + intr->out_offset); |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 399 | } else { |
| 400 | ++interrupt_stats[SMD_DSPS].smd_out_hardcode_count; |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 401 | MSM_TRIG_A2DSPS_SMD_INT; |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 402 | } |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | static inline void notify_wcnss_smd(void) |
| 406 | { |
| 407 | static const struct interrupt_config_item *intr |
| 408 | = &private_intr_config[SMD_WCNSS].smd; |
| 409 | wakeup_v1_riva(); |
| 410 | |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 411 | if (intr->out_base) { |
| 412 | ++interrupt_stats[SMD_WCNSS].smd_out_config_count; |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 413 | smd_write_intr(intr->out_bit_pos, |
| 414 | intr->out_base + intr->out_offset); |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 415 | } else { |
| 416 | ++interrupt_stats[SMD_WCNSS].smd_out_hardcode_count; |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 417 | MSM_TRIG_A2WCNSS_SMD_INT; |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 418 | } |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | static inline void notify_modem_smsm(void) |
| 422 | { |
| 423 | static const struct interrupt_config_item *intr |
| 424 | = &private_intr_config[SMD_MODEM].smsm; |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 425 | if (intr->out_base) { |
| 426 | ++interrupt_stats[SMD_MODEM].smsm_out_config_count; |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 427 | smd_write_intr(intr->out_bit_pos, |
| 428 | intr->out_base + intr->out_offset); |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 429 | } else { |
| 430 | ++interrupt_stats[SMD_MODEM].smsm_out_hardcode_count; |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 431 | MSM_TRIG_A2M_SMSM_INT; |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 432 | } |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | static inline void notify_dsp_smsm(void) |
| 436 | { |
| 437 | static const struct interrupt_config_item *intr |
| 438 | = &private_intr_config[SMD_Q6].smsm; |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 439 | if (intr->out_base) { |
| 440 | ++interrupt_stats[SMD_Q6].smsm_out_config_count; |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 441 | smd_write_intr(intr->out_bit_pos, |
| 442 | intr->out_base + intr->out_offset); |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 443 | } else { |
| 444 | ++interrupt_stats[SMD_Q6].smsm_out_hardcode_count; |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 445 | MSM_TRIG_A2Q6_SMSM_INT; |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 446 | } |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | static inline void notify_dsps_smsm(void) |
| 450 | { |
| 451 | static const struct interrupt_config_item *intr |
| 452 | = &private_intr_config[SMD_DSPS].smsm; |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 453 | if (intr->out_base) { |
| 454 | ++interrupt_stats[SMD_DSPS].smsm_out_config_count; |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 455 | smd_write_intr(intr->out_bit_pos, |
| 456 | intr->out_base + intr->out_offset); |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 457 | } else { |
| 458 | ++interrupt_stats[SMD_DSPS].smsm_out_hardcode_count; |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 459 | MSM_TRIG_A2DSPS_SMSM_INT; |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 460 | } |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | static inline void notify_wcnss_smsm(void) |
| 464 | { |
| 465 | static const struct interrupt_config_item *intr |
| 466 | = &private_intr_config[SMD_WCNSS].smsm; |
| 467 | wakeup_v1_riva(); |
| 468 | |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 469 | if (intr->out_base) { |
| 470 | ++interrupt_stats[SMD_WCNSS].smsm_out_config_count; |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 471 | smd_write_intr(intr->out_bit_pos, |
| 472 | intr->out_base + intr->out_offset); |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 473 | } else { |
| 474 | ++interrupt_stats[SMD_WCNSS].smsm_out_hardcode_count; |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 475 | MSM_TRIG_A2WCNSS_SMSM_INT; |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 476 | } |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 477 | } |
| 478 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 479 | static void notify_other_smsm(uint32_t smsm_entry, uint32_t notify_mask) |
| 480 | { |
| 481 | /* older protocol don't use smsm_intr_mask, |
| 482 | but still communicates with modem */ |
| 483 | if (!smsm_info.intr_mask || |
| 484 | (__raw_readl(SMSM_INTR_MASK_ADDR(smsm_entry, SMSM_MODEM)) |
| 485 | & notify_mask)) |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 486 | notify_modem_smsm(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 487 | |
| 488 | if (smsm_info.intr_mask && |
| 489 | (__raw_readl(SMSM_INTR_MASK_ADDR(smsm_entry, SMSM_Q6)) |
| 490 | & notify_mask)) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 491 | uint32_t mux_val; |
| 492 | |
Eric Holmberg | 6282c5d | 2011-10-27 17:30:57 -0600 | [diff] [blame] | 493 | if (cpu_is_qsd8x50() && smsm_info.intr_mux) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 494 | mux_val = __raw_readl( |
| 495 | SMSM_INTR_MUX_ADDR(SMEM_APPS_Q6_SMSM)); |
| 496 | mux_val++; |
| 497 | __raw_writel(mux_val, |
| 498 | SMSM_INTR_MUX_ADDR(SMEM_APPS_Q6_SMSM)); |
| 499 | } |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 500 | notify_dsp_smsm(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | if (smsm_info.intr_mask && |
| 504 | (__raw_readl(SMSM_INTR_MASK_ADDR(smsm_entry, SMSM_WCNSS)) |
| 505 | & notify_mask)) { |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 506 | notify_wcnss_smsm(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 507 | } |
| 508 | |
Jeff Hugo | 6a8057c | 2011-08-16 13:47:12 -0600 | [diff] [blame] | 509 | if (smsm_info.intr_mask && |
| 510 | (__raw_readl(SMSM_INTR_MASK_ADDR(smsm_entry, SMSM_DSPS)) |
| 511 | & notify_mask)) { |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 512 | notify_dsps_smsm(); |
Jeff Hugo | 6a8057c | 2011-08-16 13:47:12 -0600 | [diff] [blame] | 513 | } |
| 514 | |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 515 | smsm_cb_snapshot(); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 516 | } |
| 517 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 518 | void smd_diag(void) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 519 | { |
| 520 | char *x; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 521 | int size; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 522 | |
| 523 | x = smem_find(ID_DIAG_ERR_MSG, SZ_DIAG_ERR_MSG); |
| 524 | if (x != 0) { |
| 525 | x[SZ_DIAG_ERR_MSG - 1] = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 526 | SMD_INFO("smem: DIAG '%s'\n", x); |
| 527 | } |
| 528 | |
| 529 | x = smem_get_entry(SMEM_ERR_CRASH_LOG, &size); |
| 530 | if (x != 0) { |
| 531 | x[size - 1] = 0; |
| 532 | pr_err("smem: CRASH LOG\n'%s'\n", x); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 536 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 537 | static void handle_modem_crash(void) |
| 538 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 539 | pr_err("MODEM/AMSS has CRASHED\n"); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 540 | smd_diag(); |
| 541 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 542 | /* hard reboot if possible FIXME |
| 543 | if (msm_reset_hook) |
| 544 | msm_reset_hook(); |
| 545 | */ |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 546 | |
| 547 | /* in this case the modem or watchdog should reboot us */ |
| 548 | for (;;) |
| 549 | ; |
| 550 | } |
| 551 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 552 | int smsm_check_for_modem_crash(void) |
Arve Hjønnevåg | 2837941 | 2009-05-20 16:52:36 -0700 | [diff] [blame] | 553 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 554 | /* if the modem's not ready yet, we have to hope for the best */ |
| 555 | if (!smsm_info.state) |
| 556 | return 0; |
Arve Hjønnevåg | 2837941 | 2009-05-20 16:52:36 -0700 | [diff] [blame] | 557 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 558 | if (__raw_readl(SMSM_STATE_ADDR(SMSM_MODEM_STATE)) & SMSM_RESET) { |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 559 | handle_modem_crash(); |
| 560 | return -1; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 561 | } |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 562 | return 0; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 563 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 564 | EXPORT_SYMBOL(smsm_check_for_modem_crash); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 565 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 566 | /* the spinlock is used to synchronize between the |
Brian Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 567 | * irq handler and code that mutates the channel |
| 568 | * list or fiddles with channel state |
| 569 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 570 | static DEFINE_SPINLOCK(smd_lock); |
Brian Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 571 | DEFINE_SPINLOCK(smem_lock); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 572 | |
| 573 | /* the mutex is used during open() and close() |
Brian Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 574 | * operations to avoid races while creating or |
| 575 | * destroying smd_channel structures |
| 576 | */ |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 577 | static DEFINE_MUTEX(smd_creation_mutex); |
| 578 | |
| 579 | static int smd_initialized; |
| 580 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 581 | struct smd_shared_v1 { |
| 582 | struct smd_half_channel ch0; |
| 583 | unsigned char data0[SMD_BUF_SIZE]; |
| 584 | struct smd_half_channel ch1; |
| 585 | unsigned char data1[SMD_BUF_SIZE]; |
| 586 | }; |
| 587 | |
| 588 | struct smd_shared_v2 { |
| 589 | struct smd_half_channel ch0; |
| 590 | struct smd_half_channel ch1; |
| 591 | }; |
| 592 | |
| 593 | struct smd_channel { |
| 594 | volatile struct smd_half_channel *send; |
| 595 | volatile struct smd_half_channel *recv; |
| 596 | unsigned char *send_data; |
| 597 | unsigned char *recv_data; |
| 598 | unsigned fifo_size; |
| 599 | unsigned fifo_mask; |
| 600 | struct list_head ch_list; |
| 601 | |
| 602 | unsigned current_packet; |
| 603 | unsigned n; |
| 604 | void *priv; |
| 605 | void (*notify)(void *priv, unsigned flags); |
| 606 | |
| 607 | int (*read)(smd_channel_t *ch, void *data, int len, int user_buf); |
| 608 | int (*write)(smd_channel_t *ch, const void *data, int len, |
| 609 | int user_buf); |
| 610 | int (*read_avail)(smd_channel_t *ch); |
| 611 | int (*write_avail)(smd_channel_t *ch); |
| 612 | int (*read_from_cb)(smd_channel_t *ch, void *data, int len, |
| 613 | int user_buf); |
| 614 | |
| 615 | void (*update_state)(smd_channel_t *ch); |
| 616 | unsigned last_state; |
| 617 | void (*notify_other_cpu)(void); |
| 618 | |
| 619 | char name[20]; |
| 620 | struct platform_device pdev; |
| 621 | unsigned type; |
| 622 | |
| 623 | int pending_pkt_sz; |
| 624 | |
| 625 | char is_pkt_ch; |
| 626 | }; |
| 627 | |
| 628 | struct edge_to_pid { |
| 629 | uint32_t local_pid; |
| 630 | uint32_t remote_pid; |
Eric Holmberg | 17992c1 | 2012-02-29 12:54:44 -0700 | [diff] [blame] | 631 | char subsys_name[SMD_MAX_CH_NAME_LEN]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 632 | }; |
| 633 | |
| 634 | /** |
| 635 | * Maps edge type to local and remote processor ID's. |
| 636 | */ |
| 637 | static struct edge_to_pid edge_to_pids[] = { |
Eric Holmberg | 5a55b4a | 2012-03-01 14:41:54 -0700 | [diff] [blame] | 638 | [SMD_APPS_MODEM] = {SMD_APPS, SMD_MODEM, "modem"}, |
| 639 | [SMD_APPS_QDSP] = {SMD_APPS, SMD_Q6, "q6"}, |
| 640 | [SMD_MODEM_QDSP] = {SMD_MODEM, SMD_Q6}, |
| 641 | [SMD_APPS_DSPS] = {SMD_APPS, SMD_DSPS, "dsps"}, |
| 642 | [SMD_MODEM_DSPS] = {SMD_MODEM, SMD_DSPS}, |
| 643 | [SMD_QDSP_DSPS] = {SMD_Q6, SMD_DSPS}, |
| 644 | [SMD_APPS_WCNSS] = {SMD_APPS, SMD_WCNSS, "wcnss"}, |
| 645 | [SMD_MODEM_WCNSS] = {SMD_MODEM, SMD_WCNSS}, |
| 646 | [SMD_QDSP_WCNSS] = {SMD_Q6, SMD_WCNSS}, |
| 647 | [SMD_DSPS_WCNSS] = {SMD_DSPS, SMD_WCNSS}, |
| 648 | [SMD_APPS_Q6FW] = {SMD_APPS, SMD_MODEM_Q6_FW}, |
| 649 | [SMD_MODEM_Q6FW] = {SMD_MODEM, SMD_MODEM_Q6_FW}, |
| 650 | [SMD_QDSP_Q6FW] = {SMD_Q6, SMD_MODEM_Q6_FW}, |
| 651 | [SMD_DSPS_Q6FW] = {SMD_DSPS, SMD_MODEM_Q6_FW}, |
| 652 | [SMD_WCNSS_Q6FW] = {SMD_WCNSS, SMD_MODEM_Q6_FW}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 653 | }; |
| 654 | |
| 655 | struct restart_notifier_block { |
| 656 | unsigned processor; |
| 657 | char *name; |
| 658 | struct notifier_block nb; |
| 659 | }; |
| 660 | |
Eric Holmberg | 2bb6ccd | 2012-03-13 13:05:14 -0600 | [diff] [blame] | 661 | static int disable_smsm_reset_handshake; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 662 | static struct platform_device loopback_tty_pdev = {.name = "LOOPBACK_TTY"}; |
| 663 | |
| 664 | static LIST_HEAD(smd_ch_closed_list); |
| 665 | static LIST_HEAD(smd_ch_closing_list); |
| 666 | static LIST_HEAD(smd_ch_to_close_list); |
| 667 | static LIST_HEAD(smd_ch_list_modem); |
| 668 | static LIST_HEAD(smd_ch_list_dsp); |
| 669 | static LIST_HEAD(smd_ch_list_dsps); |
| 670 | static LIST_HEAD(smd_ch_list_wcnss); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 671 | |
| 672 | static unsigned char smd_ch_allocated[64]; |
| 673 | static struct work_struct probe_work; |
| 674 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 675 | static void finalize_channel_close_fn(struct work_struct *work); |
| 676 | static DECLARE_WORK(finalize_channel_close_work, finalize_channel_close_fn); |
| 677 | static struct workqueue_struct *channel_close_wq; |
| 678 | |
| 679 | static int smd_alloc_channel(struct smd_alloc_elm *alloc_elm); |
| 680 | |
| 681 | /* on smp systems, the probe might get called from multiple cores, |
| 682 | hence use a lock */ |
| 683 | static DEFINE_MUTEX(smd_probe_lock); |
| 684 | |
| 685 | static void smd_channel_probe_worker(struct work_struct *work) |
| 686 | { |
| 687 | struct smd_alloc_elm *shared; |
| 688 | unsigned n; |
| 689 | uint32_t type; |
| 690 | |
| 691 | shared = smem_find(ID_CH_ALLOC_TBL, sizeof(*shared) * 64); |
| 692 | |
| 693 | if (!shared) { |
| 694 | pr_err("%s: allocation table not initialized\n", __func__); |
| 695 | return; |
| 696 | } |
| 697 | |
| 698 | mutex_lock(&smd_probe_lock); |
| 699 | for (n = 0; n < 64; n++) { |
| 700 | if (smd_ch_allocated[n]) |
| 701 | continue; |
| 702 | |
| 703 | /* channel should be allocated only if APPS |
| 704 | processor is involved */ |
| 705 | type = SMD_CHANNEL_TYPE(shared[n].type); |
| 706 | if ((type != SMD_APPS_MODEM) && (type != SMD_APPS_QDSP) && |
| 707 | (type != SMD_APPS_DSPS) && (type != SMD_APPS_WCNSS)) |
| 708 | continue; |
| 709 | if (!shared[n].ref_count) |
| 710 | continue; |
| 711 | if (!shared[n].name[0]) |
| 712 | continue; |
| 713 | |
| 714 | if (!smd_alloc_channel(&shared[n])) |
| 715 | smd_ch_allocated[n] = 1; |
| 716 | else |
| 717 | SMD_INFO("Probe skipping ch %d, not allocated\n", n); |
| 718 | } |
| 719 | mutex_unlock(&smd_probe_lock); |
| 720 | } |
| 721 | |
| 722 | /** |
| 723 | * Lookup processor ID and determine if it belongs to the proved edge |
| 724 | * type. |
| 725 | * |
| 726 | * @shared2: Pointer to v2 shared channel structure |
| 727 | * @type: Edge type |
| 728 | * @pid: Processor ID of processor on edge |
| 729 | * @local_ch: Channel that belongs to processor @pid |
| 730 | * @remote_ch: Other side of edge contained @pid |
| 731 | * |
| 732 | * Returns 0 for not on edge, 1 for found on edge |
| 733 | */ |
| 734 | static int pid_is_on_edge(struct smd_shared_v2 *shared2, |
| 735 | uint32_t type, uint32_t pid, |
| 736 | struct smd_half_channel **local_ch, |
| 737 | struct smd_half_channel **remote_ch |
| 738 | ) |
| 739 | { |
| 740 | int ret = 0; |
| 741 | struct edge_to_pid *edge; |
| 742 | |
| 743 | *local_ch = 0; |
| 744 | *remote_ch = 0; |
| 745 | |
| 746 | if (!shared2 || (type >= ARRAY_SIZE(edge_to_pids))) |
| 747 | return 0; |
| 748 | |
| 749 | edge = &edge_to_pids[type]; |
| 750 | if (edge->local_pid != edge->remote_pid) { |
| 751 | if (pid == edge->local_pid) { |
| 752 | *local_ch = &shared2->ch0; |
| 753 | *remote_ch = &shared2->ch1; |
| 754 | ret = 1; |
| 755 | } else if (pid == edge->remote_pid) { |
| 756 | *local_ch = &shared2->ch1; |
| 757 | *remote_ch = &shared2->ch0; |
| 758 | ret = 1; |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | return ret; |
| 763 | } |
| 764 | |
Eric Holmberg | 17992c1 | 2012-02-29 12:54:44 -0700 | [diff] [blame] | 765 | /* |
| 766 | * Returns a pointer to the subsystem name or NULL if no |
| 767 | * subsystem name is available. |
| 768 | * |
| 769 | * @type - Edge definition |
| 770 | */ |
| 771 | const char *smd_edge_to_subsystem(uint32_t type) |
| 772 | { |
| 773 | const char *subsys = NULL; |
| 774 | |
| 775 | if (type < ARRAY_SIZE(edge_to_pids)) { |
| 776 | subsys = edge_to_pids[type].subsys_name; |
| 777 | if (subsys[0] == 0x0) |
| 778 | subsys = NULL; |
| 779 | } |
| 780 | return subsys; |
| 781 | } |
| 782 | EXPORT_SYMBOL(smd_edge_to_subsystem); |
| 783 | |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 784 | /* |
| 785 | * Returns a pointer to the subsystem name given the |
| 786 | * remote processor ID. |
| 787 | * |
| 788 | * @pid Remote processor ID |
| 789 | * @returns Pointer to subsystem name or NULL if not found |
| 790 | */ |
| 791 | const char *smd_pid_to_subsystem(uint32_t pid) |
| 792 | { |
| 793 | const char *subsys = NULL; |
| 794 | int i; |
| 795 | |
| 796 | for (i = 0; i < ARRAY_SIZE(edge_to_pids); ++i) { |
| 797 | if (pid == edge_to_pids[i].remote_pid && |
| 798 | edge_to_pids[i].subsys_name[0] != 0x0 |
| 799 | ) { |
| 800 | subsys = edge_to_pids[i].subsys_name; |
| 801 | break; |
| 802 | } |
| 803 | } |
| 804 | |
| 805 | return subsys; |
| 806 | } |
| 807 | EXPORT_SYMBOL(smd_pid_to_subsystem); |
Eric Holmberg | 17992c1 | 2012-02-29 12:54:44 -0700 | [diff] [blame] | 808 | |
Eric Holmberg | 2a563c3 | 2011-10-05 14:51:43 -0600 | [diff] [blame] | 809 | static void smd_reset_edge(struct smd_half_channel *ch, unsigned new_state) |
| 810 | { |
| 811 | if (ch->state != SMD_SS_CLOSED) { |
| 812 | ch->state = new_state; |
| 813 | ch->fDSR = 0; |
| 814 | ch->fCTS = 0; |
| 815 | ch->fCD = 0; |
| 816 | ch->fSTATE = 1; |
| 817 | } |
| 818 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 819 | |
| 820 | static void smd_channel_reset_state(struct smd_alloc_elm *shared, |
| 821 | unsigned new_state, unsigned pid) |
| 822 | { |
| 823 | unsigned n; |
| 824 | struct smd_shared_v2 *shared2; |
| 825 | uint32_t type; |
| 826 | struct smd_half_channel *local_ch; |
| 827 | struct smd_half_channel *remote_ch; |
| 828 | |
| 829 | for (n = 0; n < SMD_CHANNELS; n++) { |
| 830 | if (!shared[n].ref_count) |
| 831 | continue; |
| 832 | if (!shared[n].name[0]) |
| 833 | continue; |
| 834 | |
| 835 | type = SMD_CHANNEL_TYPE(shared[n].type); |
| 836 | shared2 = smem_alloc(SMEM_SMD_BASE_ID + n, sizeof(*shared2)); |
| 837 | if (!shared2) |
| 838 | continue; |
| 839 | |
Eric Holmberg | 2a563c3 | 2011-10-05 14:51:43 -0600 | [diff] [blame] | 840 | if (pid_is_on_edge(shared2, type, pid, &local_ch, &remote_ch)) |
| 841 | smd_reset_edge(local_ch, new_state); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 842 | |
Eric Holmberg | 2a563c3 | 2011-10-05 14:51:43 -0600 | [diff] [blame] | 843 | /* |
| 844 | * ModemFW is in the same subsystem as ModemSW, but has |
| 845 | * separate SMD edges that need to be reset. |
| 846 | */ |
| 847 | if (pid == SMSM_MODEM && |
| 848 | pid_is_on_edge(shared2, type, SMD_MODEM_Q6_FW, |
| 849 | &local_ch, &remote_ch)) |
| 850 | smd_reset_edge(local_ch, new_state); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 851 | } |
| 852 | } |
| 853 | |
| 854 | |
| 855 | void smd_channel_reset(uint32_t restart_pid) |
| 856 | { |
| 857 | struct smd_alloc_elm *shared; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 858 | unsigned long flags; |
| 859 | |
| 860 | SMD_DBG("%s: starting reset\n", __func__); |
| 861 | shared = smem_find(ID_CH_ALLOC_TBL, sizeof(*shared) * 64); |
| 862 | if (!shared) { |
| 863 | pr_err("%s: allocation table not initialized\n", __func__); |
| 864 | return; |
| 865 | } |
| 866 | |
Eric Holmberg | f6d7d1a | 2011-09-23 18:31:04 -0600 | [diff] [blame] | 867 | /* release any held spinlocks */ |
| 868 | remote_spin_release(&remote_spinlock, restart_pid); |
| 869 | remote_spin_release_all(restart_pid); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 870 | |
| 871 | /* reset SMSM entry */ |
| 872 | if (smsm_info.state) { |
| 873 | writel_relaxed(0, SMSM_STATE_ADDR(restart_pid)); |
| 874 | |
Eric Holmberg | 351a63c | 2011-12-02 17:49:43 -0700 | [diff] [blame] | 875 | /* restart SMSM init handshake */ |
| 876 | if (restart_pid == SMSM_MODEM) { |
| 877 | smsm_change_state(SMSM_APPS_STATE, |
Eric Holmberg | 6b2f80e | 2012-01-09 12:22:52 -0700 | [diff] [blame] | 878 | SMSM_INIT | SMSM_SMD_LOOPBACK | SMSM_RESET, |
| 879 | 0); |
Eric Holmberg | 351a63c | 2011-12-02 17:49:43 -0700 | [diff] [blame] | 880 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 881 | |
| 882 | /* notify SMSM processors */ |
| 883 | smsm_irq_handler(0, 0); |
Eric Holmberg | b772644 | 2012-03-01 15:31:56 -0700 | [diff] [blame] | 884 | notify_modem_smsm(); |
| 885 | notify_dsp_smsm(); |
| 886 | notify_dsps_smsm(); |
| 887 | notify_wcnss_smsm(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | /* change all remote states to CLOSING */ |
| 891 | mutex_lock(&smd_probe_lock); |
| 892 | spin_lock_irqsave(&smd_lock, flags); |
| 893 | smd_channel_reset_state(shared, SMD_SS_CLOSING, restart_pid); |
| 894 | spin_unlock_irqrestore(&smd_lock, flags); |
| 895 | mutex_unlock(&smd_probe_lock); |
| 896 | |
| 897 | /* notify SMD processors */ |
| 898 | mb(); |
| 899 | smd_fake_irq_handler(0); |
| 900 | notify_modem_smd(); |
| 901 | notify_dsp_smd(); |
| 902 | notify_dsps_smd(); |
| 903 | notify_wcnss_smd(); |
| 904 | |
| 905 | /* change all remote states to CLOSED */ |
| 906 | mutex_lock(&smd_probe_lock); |
| 907 | spin_lock_irqsave(&smd_lock, flags); |
| 908 | smd_channel_reset_state(shared, SMD_SS_CLOSED, restart_pid); |
| 909 | spin_unlock_irqrestore(&smd_lock, flags); |
| 910 | mutex_unlock(&smd_probe_lock); |
| 911 | |
| 912 | /* notify SMD processors */ |
| 913 | mb(); |
| 914 | smd_fake_irq_handler(0); |
| 915 | notify_modem_smd(); |
| 916 | notify_dsp_smd(); |
| 917 | notify_dsps_smd(); |
| 918 | notify_wcnss_smd(); |
| 919 | |
| 920 | SMD_DBG("%s: finished reset\n", __func__); |
| 921 | } |
| 922 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 923 | /* how many bytes are available for reading */ |
| 924 | static int smd_stream_read_avail(struct smd_channel *ch) |
| 925 | { |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 926 | return (ch->recv->head - ch->recv->tail) & ch->fifo_mask; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | /* how many bytes we are free to write */ |
| 930 | static int smd_stream_write_avail(struct smd_channel *ch) |
| 931 | { |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 932 | return ch->fifo_mask - |
| 933 | ((ch->send->head - ch->send->tail) & ch->fifo_mask); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | static int smd_packet_read_avail(struct smd_channel *ch) |
| 937 | { |
| 938 | if (ch->current_packet) { |
| 939 | int n = smd_stream_read_avail(ch); |
| 940 | if (n > ch->current_packet) |
| 941 | n = ch->current_packet; |
| 942 | return n; |
| 943 | } else { |
| 944 | return 0; |
| 945 | } |
| 946 | } |
| 947 | |
| 948 | static int smd_packet_write_avail(struct smd_channel *ch) |
| 949 | { |
| 950 | int n = smd_stream_write_avail(ch); |
| 951 | return n > SMD_HEADER_SIZE ? n - SMD_HEADER_SIZE : 0; |
| 952 | } |
| 953 | |
| 954 | static int ch_is_open(struct smd_channel *ch) |
| 955 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 956 | return (ch->recv->state == SMD_SS_OPENED || |
| 957 | ch->recv->state == SMD_SS_FLUSHING) |
| 958 | && (ch->send->state == SMD_SS_OPENED); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | /* provide a pointer and length to readable data in the fifo */ |
| 962 | static unsigned ch_read_buffer(struct smd_channel *ch, void **ptr) |
| 963 | { |
| 964 | unsigned head = ch->recv->head; |
| 965 | unsigned tail = ch->recv->tail; |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 966 | *ptr = (void *) (ch->recv_data + tail); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 967 | |
| 968 | if (tail <= head) |
| 969 | return head - tail; |
| 970 | else |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 971 | return ch->fifo_size - tail; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 972 | } |
| 973 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 974 | static int read_intr_blocked(struct smd_channel *ch) |
| 975 | { |
| 976 | return ch->recv->fBLOCKREADINTR; |
| 977 | } |
| 978 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 979 | /* advance the fifo read pointer after data from ch_read_buffer is consumed */ |
| 980 | static void ch_read_done(struct smd_channel *ch, unsigned count) |
| 981 | { |
| 982 | BUG_ON(count > smd_stream_read_avail(ch)); |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 983 | ch->recv->tail = (ch->recv->tail + count) & ch->fifo_mask; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 984 | wmb(); |
Haley Teng | 7632fba | 2009-10-12 10:38:10 -0700 | [diff] [blame] | 985 | ch->send->fTAIL = 1; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | /* basic read interface to ch_read_{buffer,done} used |
Brian Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 989 | * by smd_*_read() and update_packet_state() |
| 990 | * will read-and-discard if the _data pointer is null |
| 991 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 992 | static int ch_read(struct smd_channel *ch, void *_data, int len, int user_buf) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 993 | { |
| 994 | void *ptr; |
| 995 | unsigned n; |
| 996 | unsigned char *data = _data; |
| 997 | int orig_len = len; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 998 | int r = 0; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 999 | |
| 1000 | while (len > 0) { |
| 1001 | n = ch_read_buffer(ch, &ptr); |
| 1002 | if (n == 0) |
| 1003 | break; |
| 1004 | |
| 1005 | if (n > len) |
| 1006 | n = len; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1007 | if (_data) { |
| 1008 | if (user_buf) { |
| 1009 | r = copy_to_user(data, ptr, n); |
| 1010 | if (r > 0) { |
| 1011 | pr_err("%s: " |
| 1012 | "copy_to_user could not copy " |
| 1013 | "%i bytes.\n", |
| 1014 | __func__, |
| 1015 | r); |
| 1016 | } |
| 1017 | } else |
| 1018 | memcpy(data, ptr, n); |
| 1019 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1020 | |
| 1021 | data += n; |
| 1022 | len -= n; |
| 1023 | ch_read_done(ch, n); |
| 1024 | } |
| 1025 | |
| 1026 | return orig_len - len; |
| 1027 | } |
| 1028 | |
| 1029 | static void update_stream_state(struct smd_channel *ch) |
| 1030 | { |
| 1031 | /* streams have no special state requiring updating */ |
| 1032 | } |
| 1033 | |
| 1034 | static void update_packet_state(struct smd_channel *ch) |
| 1035 | { |
| 1036 | unsigned hdr[5]; |
| 1037 | int r; |
| 1038 | |
| 1039 | /* can't do anything if we're in the middle of a packet */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1040 | while (ch->current_packet == 0) { |
| 1041 | /* discard 0 length packets if any */ |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1042 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1043 | /* don't bother unless we can get the full header */ |
| 1044 | if (smd_stream_read_avail(ch) < SMD_HEADER_SIZE) |
| 1045 | return; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1046 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1047 | r = ch_read(ch, hdr, SMD_HEADER_SIZE, 0); |
| 1048 | BUG_ON(r != SMD_HEADER_SIZE); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1049 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1050 | ch->current_packet = hdr[0]; |
| 1051 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | /* provide a pointer and length to next free space in the fifo */ |
| 1055 | static unsigned ch_write_buffer(struct smd_channel *ch, void **ptr) |
| 1056 | { |
| 1057 | unsigned head = ch->send->head; |
| 1058 | unsigned tail = ch->send->tail; |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1059 | *ptr = (void *) (ch->send_data + head); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1060 | |
| 1061 | if (head < tail) { |
| 1062 | return tail - head - 1; |
| 1063 | } else { |
| 1064 | if (tail == 0) |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1065 | return ch->fifo_size - head - 1; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1066 | else |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1067 | return ch->fifo_size - head; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | /* advace the fifo write pointer after freespace |
| 1072 | * from ch_write_buffer is filled |
| 1073 | */ |
| 1074 | static void ch_write_done(struct smd_channel *ch, unsigned count) |
| 1075 | { |
| 1076 | BUG_ON(count > smd_stream_write_avail(ch)); |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1077 | ch->send->head = (ch->send->head + count) & ch->fifo_mask; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1078 | wmb(); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1079 | ch->send->fHEAD = 1; |
| 1080 | } |
| 1081 | |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1082 | static void ch_set_state(struct smd_channel *ch, unsigned n) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1083 | { |
| 1084 | if (n == SMD_SS_OPENED) { |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1085 | ch->send->fDSR = 1; |
| 1086 | ch->send->fCTS = 1; |
| 1087 | ch->send->fCD = 1; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1088 | } else { |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1089 | ch->send->fDSR = 0; |
| 1090 | ch->send->fCTS = 0; |
| 1091 | ch->send->fCD = 0; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1092 | } |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1093 | ch->send->state = n; |
| 1094 | ch->send->fSTATE = 1; |
| 1095 | ch->notify_other_cpu(); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | static void do_smd_probe(void) |
| 1099 | { |
| 1100 | struct smem_shared *shared = (void *) MSM_SHARED_RAM_BASE; |
| 1101 | if (shared->heap_info.free_offset != last_heap_free) { |
| 1102 | last_heap_free = shared->heap_info.free_offset; |
| 1103 | schedule_work(&probe_work); |
| 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | static void smd_state_change(struct smd_channel *ch, |
| 1108 | unsigned last, unsigned next) |
| 1109 | { |
| 1110 | ch->last_state = next; |
| 1111 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1112 | SMD_INFO("SMD: ch %d %d -> %d\n", ch->n, last, next); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1113 | |
| 1114 | switch (next) { |
| 1115 | case SMD_SS_OPENING: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1116 | if (ch->send->state == SMD_SS_CLOSING || |
| 1117 | ch->send->state == SMD_SS_CLOSED) { |
| 1118 | ch->recv->tail = 0; |
| 1119 | ch->send->head = 0; |
| 1120 | ch->send->fBLOCKREADINTR = 0; |
| 1121 | ch_set_state(ch, SMD_SS_OPENING); |
| 1122 | } |
| 1123 | break; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1124 | case SMD_SS_OPENED: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1125 | if (ch->send->state == SMD_SS_OPENING) { |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1126 | ch_set_state(ch, SMD_SS_OPENED); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1127 | ch->notify(ch->priv, SMD_EVENT_OPEN); |
| 1128 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1129 | break; |
| 1130 | case SMD_SS_FLUSHING: |
| 1131 | case SMD_SS_RESET: |
| 1132 | /* we should force them to close? */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1133 | break; |
| 1134 | case SMD_SS_CLOSED: |
| 1135 | if (ch->send->state == SMD_SS_OPENED) { |
| 1136 | ch_set_state(ch, SMD_SS_CLOSING); |
| 1137 | ch->current_packet = 0; |
Eric Holmberg | ad4fa8d | 2011-11-11 16:55:13 -0700 | [diff] [blame] | 1138 | ch->pending_pkt_sz = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1139 | ch->notify(ch->priv, SMD_EVENT_CLOSE); |
| 1140 | } |
| 1141 | break; |
| 1142 | case SMD_SS_CLOSING: |
| 1143 | if (ch->send->state == SMD_SS_CLOSED) { |
| 1144 | list_move(&ch->ch_list, |
| 1145 | &smd_ch_to_close_list); |
| 1146 | queue_work(channel_close_wq, |
| 1147 | &finalize_channel_close_work); |
| 1148 | } |
| 1149 | break; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1150 | } |
| 1151 | } |
| 1152 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1153 | static void handle_smd_irq_closing_list(void) |
| 1154 | { |
| 1155 | unsigned long flags; |
| 1156 | struct smd_channel *ch; |
| 1157 | struct smd_channel *index; |
| 1158 | unsigned tmp; |
| 1159 | |
| 1160 | spin_lock_irqsave(&smd_lock, flags); |
| 1161 | list_for_each_entry_safe(ch, index, &smd_ch_closing_list, ch_list) { |
| 1162 | if (ch->recv->fSTATE) |
| 1163 | ch->recv->fSTATE = 0; |
| 1164 | tmp = ch->recv->state; |
| 1165 | if (tmp != ch->last_state) |
| 1166 | smd_state_change(ch, ch->last_state, tmp); |
| 1167 | } |
| 1168 | spin_unlock_irqrestore(&smd_lock, flags); |
| 1169 | } |
| 1170 | |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1171 | static void handle_smd_irq(struct list_head *list, void (*notify)(void)) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1172 | { |
| 1173 | unsigned long flags; |
| 1174 | struct smd_channel *ch; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1175 | unsigned ch_flags; |
| 1176 | unsigned tmp; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1177 | unsigned char state_change; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1178 | |
| 1179 | spin_lock_irqsave(&smd_lock, flags); |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1180 | list_for_each_entry(ch, list, ch_list) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1181 | state_change = 0; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1182 | ch_flags = 0; |
| 1183 | if (ch_is_open(ch)) { |
| 1184 | if (ch->recv->fHEAD) { |
| 1185 | ch->recv->fHEAD = 0; |
| 1186 | ch_flags |= 1; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1187 | } |
| 1188 | if (ch->recv->fTAIL) { |
| 1189 | ch->recv->fTAIL = 0; |
| 1190 | ch_flags |= 2; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1191 | } |
| 1192 | if (ch->recv->fSTATE) { |
| 1193 | ch->recv->fSTATE = 0; |
| 1194 | ch_flags |= 4; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1195 | } |
| 1196 | } |
| 1197 | tmp = ch->recv->state; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1198 | if (tmp != ch->last_state) { |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 1199 | SMx_POWER_INFO("SMD ch%d '%s' State change %d->%d\n", |
| 1200 | ch->n, ch->name, ch->last_state, tmp); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1201 | smd_state_change(ch, ch->last_state, tmp); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1202 | state_change = 1; |
| 1203 | } |
Eric Holmberg | 65a7d43 | 2012-02-24 11:28:56 -0700 | [diff] [blame] | 1204 | if (ch_flags & 0x3) { |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1205 | ch->update_state(ch); |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 1206 | SMx_POWER_INFO("SMD ch%d '%s' Data event r%d/w%d\n", |
| 1207 | ch->n, ch->name, |
| 1208 | ch->read_avail(ch), |
| 1209 | ch->fifo_size - ch->write_avail(ch)); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1210 | ch->notify(ch->priv, SMD_EVENT_DATA); |
| 1211 | } |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 1212 | if (ch_flags & 0x4 && !state_change) { |
| 1213 | SMx_POWER_INFO("SMD ch%d '%s' State update\n", |
| 1214 | ch->n, ch->name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1215 | ch->notify(ch->priv, SMD_EVENT_STATUS); |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 1216 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1217 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1218 | spin_unlock_irqrestore(&smd_lock, flags); |
| 1219 | do_smd_probe(); |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1220 | } |
| 1221 | |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 1222 | static irqreturn_t smd_modem_irq_handler(int irq, void *data) |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1223 | { |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 1224 | SMx_POWER_INFO("SMD Int Modem->Apps\n"); |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 1225 | ++interrupt_stats[SMD_MODEM].smd_in_count; |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 1226 | handle_smd_irq(&smd_ch_list_modem, notify_modem_smd); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1227 | handle_smd_irq_closing_list(); |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 1228 | return IRQ_HANDLED; |
| 1229 | } |
| 1230 | |
| 1231 | static irqreturn_t smd_dsp_irq_handler(int irq, void *data) |
| 1232 | { |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 1233 | SMx_POWER_INFO("SMD Int LPASS->Apps\n"); |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 1234 | ++interrupt_stats[SMD_Q6].smd_in_count; |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 1235 | handle_smd_irq(&smd_ch_list_dsp, notify_dsp_smd); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1236 | handle_smd_irq_closing_list(); |
| 1237 | return IRQ_HANDLED; |
| 1238 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1239 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1240 | static irqreturn_t smd_dsps_irq_handler(int irq, void *data) |
| 1241 | { |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 1242 | SMx_POWER_INFO("SMD Int DSPS->Apps\n"); |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 1243 | ++interrupt_stats[SMD_DSPS].smd_in_count; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1244 | handle_smd_irq(&smd_ch_list_dsps, notify_dsps_smd); |
| 1245 | handle_smd_irq_closing_list(); |
| 1246 | return IRQ_HANDLED; |
| 1247 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1248 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1249 | static irqreturn_t smd_wcnss_irq_handler(int irq, void *data) |
| 1250 | { |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 1251 | SMx_POWER_INFO("SMD Int WCNSS->Apps\n"); |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 1252 | ++interrupt_stats[SMD_WCNSS].smd_in_count; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1253 | handle_smd_irq(&smd_ch_list_wcnss, notify_wcnss_smd); |
| 1254 | handle_smd_irq_closing_list(); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1255 | return IRQ_HANDLED; |
| 1256 | } |
| 1257 | |
| 1258 | static void smd_fake_irq_handler(unsigned long arg) |
| 1259 | { |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 1260 | handle_smd_irq(&smd_ch_list_modem, notify_modem_smd); |
| 1261 | handle_smd_irq(&smd_ch_list_dsp, notify_dsp_smd); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1262 | handle_smd_irq(&smd_ch_list_dsps, notify_dsps_smd); |
| 1263 | handle_smd_irq(&smd_ch_list_wcnss, notify_wcnss_smd); |
| 1264 | handle_smd_irq_closing_list(); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | static DECLARE_TASKLET(smd_fake_irq_tasklet, smd_fake_irq_handler, 0); |
| 1268 | |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 1269 | static inline int smd_need_int(struct smd_channel *ch) |
| 1270 | { |
| 1271 | if (ch_is_open(ch)) { |
| 1272 | if (ch->recv->fHEAD || ch->recv->fTAIL || ch->recv->fSTATE) |
| 1273 | return 1; |
| 1274 | if (ch->recv->state != ch->last_state) |
| 1275 | return 1; |
| 1276 | } |
| 1277 | return 0; |
| 1278 | } |
| 1279 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1280 | void smd_sleep_exit(void) |
| 1281 | { |
| 1282 | unsigned long flags; |
| 1283 | struct smd_channel *ch; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1284 | int need_int = 0; |
| 1285 | |
| 1286 | spin_lock_irqsave(&smd_lock, flags); |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 1287 | list_for_each_entry(ch, &smd_ch_list_modem, ch_list) { |
| 1288 | if (smd_need_int(ch)) { |
| 1289 | need_int = 1; |
| 1290 | break; |
| 1291 | } |
| 1292 | } |
| 1293 | list_for_each_entry(ch, &smd_ch_list_dsp, ch_list) { |
| 1294 | if (smd_need_int(ch)) { |
| 1295 | need_int = 1; |
| 1296 | break; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1297 | } |
| 1298 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1299 | list_for_each_entry(ch, &smd_ch_list_dsps, ch_list) { |
| 1300 | if (smd_need_int(ch)) { |
| 1301 | need_int = 1; |
| 1302 | break; |
| 1303 | } |
| 1304 | } |
| 1305 | list_for_each_entry(ch, &smd_ch_list_wcnss, ch_list) { |
| 1306 | if (smd_need_int(ch)) { |
| 1307 | need_int = 1; |
| 1308 | break; |
| 1309 | } |
| 1310 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1311 | spin_unlock_irqrestore(&smd_lock, flags); |
| 1312 | do_smd_probe(); |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 1313 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1314 | if (need_int) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1315 | SMD_DBG("smd_sleep_exit need interrupt\n"); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1316 | tasklet_schedule(&smd_fake_irq_tasklet); |
| 1317 | } |
| 1318 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1319 | EXPORT_SYMBOL(smd_sleep_exit); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1320 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1321 | static int smd_is_packet(struct smd_alloc_elm *alloc_elm) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1322 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1323 | if (SMD_XFER_TYPE(alloc_elm->type) == 1) |
| 1324 | return 0; |
| 1325 | else if (SMD_XFER_TYPE(alloc_elm->type) == 2) |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1326 | return 1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1327 | |
| 1328 | /* for cases where xfer type is 0 */ |
| 1329 | if (!strncmp(alloc_elm->name, "DAL", 3)) |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1330 | return 0; |
| 1331 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1332 | /* for cases where xfer type is 0 */ |
| 1333 | if (!strncmp(alloc_elm->name, "RPCCALL_QDSP", 12)) |
| 1334 | return 0; |
| 1335 | |
| 1336 | if (alloc_elm->cid > 4 || alloc_elm->cid == 1) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1337 | return 1; |
| 1338 | else |
| 1339 | return 0; |
| 1340 | } |
| 1341 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1342 | static int smd_stream_write(smd_channel_t *ch, const void *_data, int len, |
| 1343 | int user_buf) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1344 | { |
| 1345 | void *ptr; |
| 1346 | const unsigned char *buf = _data; |
| 1347 | unsigned xfer; |
| 1348 | int orig_len = len; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1349 | int r = 0; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1350 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1351 | SMD_DBG("smd_stream_write() %d -> ch%d\n", len, ch->n); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1352 | if (len < 0) |
| 1353 | return -EINVAL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1354 | else if (len == 0) |
| 1355 | return 0; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1356 | |
| 1357 | while ((xfer = ch_write_buffer(ch, &ptr)) != 0) { |
Eric Holmberg | 7a71787 | 2012-02-03 11:58:04 -0700 | [diff] [blame] | 1358 | if (!ch_is_open(ch)) { |
| 1359 | len = orig_len; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1360 | break; |
Eric Holmberg | 7a71787 | 2012-02-03 11:58:04 -0700 | [diff] [blame] | 1361 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1362 | if (xfer > len) |
| 1363 | xfer = len; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1364 | if (user_buf) { |
| 1365 | r = copy_from_user(ptr, buf, xfer); |
| 1366 | if (r > 0) { |
| 1367 | pr_err("%s: " |
| 1368 | "copy_from_user could not copy %i " |
| 1369 | "bytes.\n", |
| 1370 | __func__, |
| 1371 | r); |
| 1372 | } |
| 1373 | } else |
| 1374 | memcpy(ptr, buf, xfer); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1375 | ch_write_done(ch, xfer); |
| 1376 | len -= xfer; |
| 1377 | buf += xfer; |
| 1378 | if (len == 0) |
| 1379 | break; |
| 1380 | } |
| 1381 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1382 | if (orig_len - len) |
| 1383 | ch->notify_other_cpu(); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1384 | |
| 1385 | return orig_len - len; |
| 1386 | } |
| 1387 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1388 | static int smd_packet_write(smd_channel_t *ch, const void *_data, int len, |
| 1389 | int user_buf) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1390 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1391 | int ret; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1392 | unsigned hdr[5]; |
| 1393 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1394 | SMD_DBG("smd_packet_write() %d -> ch%d\n", len, ch->n); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1395 | if (len < 0) |
| 1396 | return -EINVAL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1397 | else if (len == 0) |
| 1398 | return 0; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1399 | |
| 1400 | if (smd_stream_write_avail(ch) < (len + SMD_HEADER_SIZE)) |
| 1401 | return -ENOMEM; |
| 1402 | |
| 1403 | hdr[0] = len; |
| 1404 | hdr[1] = hdr[2] = hdr[3] = hdr[4] = 0; |
| 1405 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1406 | |
| 1407 | ret = smd_stream_write(ch, hdr, sizeof(hdr), 0); |
| 1408 | if (ret < 0 || ret != sizeof(hdr)) { |
| 1409 | SMD_DBG("%s failed to write pkt header: " |
| 1410 | "%d returned\n", __func__, ret); |
| 1411 | return -1; |
| 1412 | } |
| 1413 | |
| 1414 | |
| 1415 | ret = smd_stream_write(ch, _data, len, user_buf); |
| 1416 | if (ret < 0 || ret != len) { |
| 1417 | SMD_DBG("%s failed to write pkt data: " |
| 1418 | "%d returned\n", __func__, ret); |
| 1419 | return ret; |
| 1420 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1421 | |
| 1422 | return len; |
| 1423 | } |
| 1424 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1425 | static int smd_stream_read(smd_channel_t *ch, void *data, int len, int user_buf) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1426 | { |
| 1427 | int r; |
| 1428 | |
| 1429 | if (len < 0) |
| 1430 | return -EINVAL; |
| 1431 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1432 | r = ch_read(ch, data, len, user_buf); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1433 | if (r > 0) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1434 | if (!read_intr_blocked(ch)) |
| 1435 | ch->notify_other_cpu(); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1436 | |
| 1437 | return r; |
| 1438 | } |
| 1439 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1440 | static int smd_packet_read(smd_channel_t *ch, void *data, int len, int user_buf) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1441 | { |
| 1442 | unsigned long flags; |
| 1443 | int r; |
| 1444 | |
| 1445 | if (len < 0) |
| 1446 | return -EINVAL; |
| 1447 | |
| 1448 | if (len > ch->current_packet) |
| 1449 | len = ch->current_packet; |
| 1450 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1451 | r = ch_read(ch, data, len, user_buf); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1452 | if (r > 0) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1453 | if (!read_intr_blocked(ch)) |
| 1454 | ch->notify_other_cpu(); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1455 | |
| 1456 | spin_lock_irqsave(&smd_lock, flags); |
| 1457 | ch->current_packet -= r; |
| 1458 | update_packet_state(ch); |
| 1459 | spin_unlock_irqrestore(&smd_lock, flags); |
| 1460 | |
| 1461 | return r; |
| 1462 | } |
| 1463 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1464 | static int smd_packet_read_from_cb(smd_channel_t *ch, void *data, int len, |
| 1465 | int user_buf) |
| 1466 | { |
| 1467 | int r; |
| 1468 | |
| 1469 | if (len < 0) |
| 1470 | return -EINVAL; |
| 1471 | |
| 1472 | if (len > ch->current_packet) |
| 1473 | len = ch->current_packet; |
| 1474 | |
| 1475 | r = ch_read(ch, data, len, user_buf); |
| 1476 | if (r > 0) |
| 1477 | if (!read_intr_blocked(ch)) |
| 1478 | ch->notify_other_cpu(); |
| 1479 | |
| 1480 | ch->current_packet -= r; |
| 1481 | update_packet_state(ch); |
| 1482 | |
| 1483 | return r; |
| 1484 | } |
| 1485 | |
Angshuman Sarkar | ac7d625 | 2011-09-30 18:20:59 +0530 | [diff] [blame] | 1486 | #if (defined(CONFIG_MSM_SMD_PKG4) || defined(CONFIG_MSM_SMD_PKG3)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1487 | static int smd_alloc_v2(struct smd_channel *ch) |
| 1488 | { |
| 1489 | struct smd_shared_v2 *shared2; |
| 1490 | void *buffer; |
| 1491 | unsigned buffer_sz; |
| 1492 | |
| 1493 | shared2 = smem_alloc(SMEM_SMD_BASE_ID + ch->n, sizeof(*shared2)); |
| 1494 | if (!shared2) { |
| 1495 | SMD_INFO("smem_alloc failed ch=%d\n", ch->n); |
Angshuman Sarkar | ac7d625 | 2011-09-30 18:20:59 +0530 | [diff] [blame] | 1496 | return -EINVAL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1497 | } |
| 1498 | buffer = smem_get_entry(SMEM_SMD_FIFO_BASE_ID + ch->n, &buffer_sz); |
| 1499 | if (!buffer) { |
Angshuman Sarkar | ac7d625 | 2011-09-30 18:20:59 +0530 | [diff] [blame] | 1500 | SMD_INFO("smem_get_entry failed\n"); |
| 1501 | return -EINVAL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1502 | } |
| 1503 | |
| 1504 | /* buffer must be a power-of-two size */ |
Angshuman Sarkar | ac7d625 | 2011-09-30 18:20:59 +0530 | [diff] [blame] | 1505 | if (buffer_sz & (buffer_sz - 1)) { |
| 1506 | SMD_INFO("Buffer size: %u not power of two\n", buffer_sz); |
| 1507 | return -EINVAL; |
| 1508 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1509 | buffer_sz /= 2; |
| 1510 | ch->send = &shared2->ch0; |
| 1511 | ch->recv = &shared2->ch1; |
| 1512 | ch->send_data = buffer; |
| 1513 | ch->recv_data = buffer + buffer_sz; |
| 1514 | ch->fifo_size = buffer_sz; |
| 1515 | return 0; |
| 1516 | } |
| 1517 | |
| 1518 | static int smd_alloc_v1(struct smd_channel *ch) |
| 1519 | { |
Angshuman Sarkar | ac7d625 | 2011-09-30 18:20:59 +0530 | [diff] [blame] | 1520 | return -EINVAL; |
| 1521 | } |
| 1522 | |
| 1523 | #else /* define v1 for older targets */ |
| 1524 | static int smd_alloc_v2(struct smd_channel *ch) |
| 1525 | { |
| 1526 | return -EINVAL; |
| 1527 | } |
| 1528 | |
| 1529 | static int smd_alloc_v1(struct smd_channel *ch) |
| 1530 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1531 | struct smd_shared_v1 *shared1; |
| 1532 | shared1 = smem_alloc(ID_SMD_CHANNELS + ch->n, sizeof(*shared1)); |
| 1533 | if (!shared1) { |
| 1534 | pr_err("smd_alloc_channel() cid %d does not exist\n", ch->n); |
Angshuman Sarkar | ac7d625 | 2011-09-30 18:20:59 +0530 | [diff] [blame] | 1535 | return -EINVAL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1536 | } |
| 1537 | ch->send = &shared1->ch0; |
| 1538 | ch->recv = &shared1->ch1; |
| 1539 | ch->send_data = shared1->data0; |
| 1540 | ch->recv_data = shared1->data1; |
| 1541 | ch->fifo_size = SMD_BUF_SIZE; |
| 1542 | return 0; |
| 1543 | } |
| 1544 | |
Angshuman Sarkar | ac7d625 | 2011-09-30 18:20:59 +0530 | [diff] [blame] | 1545 | #endif |
| 1546 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1547 | static int smd_alloc_channel(struct smd_alloc_elm *alloc_elm) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1548 | { |
| 1549 | struct smd_channel *ch; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1550 | |
| 1551 | ch = kzalloc(sizeof(struct smd_channel), GFP_KERNEL); |
| 1552 | if (ch == 0) { |
| 1553 | pr_err("smd_alloc_channel() out of memory\n"); |
Brian Swetland | 34f719b | 2009-10-30 16:22:05 -0700 | [diff] [blame] | 1554 | return -1; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1555 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1556 | ch->n = alloc_elm->cid; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1557 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1558 | if (smd_alloc_v2(ch) && smd_alloc_v1(ch)) { |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1559 | kfree(ch); |
Brian Swetland | 34f719b | 2009-10-30 16:22:05 -0700 | [diff] [blame] | 1560 | return -1; |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1561 | } |
| 1562 | |
| 1563 | ch->fifo_mask = ch->fifo_size - 1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1564 | ch->type = SMD_CHANNEL_TYPE(alloc_elm->type); |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1565 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1566 | if (ch->type == SMD_APPS_MODEM) |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1567 | ch->notify_other_cpu = notify_modem_smd; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1568 | else if (ch->type == SMD_APPS_QDSP) |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1569 | ch->notify_other_cpu = notify_dsp_smd; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1570 | else if (ch->type == SMD_APPS_DSPS) |
| 1571 | ch->notify_other_cpu = notify_dsps_smd; |
| 1572 | else |
| 1573 | ch->notify_other_cpu = notify_wcnss_smd; |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1574 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1575 | if (smd_is_packet(alloc_elm)) { |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1576 | ch->read = smd_packet_read; |
| 1577 | ch->write = smd_packet_write; |
| 1578 | ch->read_avail = smd_packet_read_avail; |
| 1579 | ch->write_avail = smd_packet_write_avail; |
| 1580 | ch->update_state = update_packet_state; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1581 | ch->read_from_cb = smd_packet_read_from_cb; |
| 1582 | ch->is_pkt_ch = 1; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1583 | } else { |
| 1584 | ch->read = smd_stream_read; |
| 1585 | ch->write = smd_stream_write; |
| 1586 | ch->read_avail = smd_stream_read_avail; |
| 1587 | ch->write_avail = smd_stream_write_avail; |
| 1588 | ch->update_state = update_stream_state; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1589 | ch->read_from_cb = smd_stream_read; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1590 | } |
| 1591 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1592 | memcpy(ch->name, alloc_elm->name, SMD_MAX_CH_NAME_LEN); |
| 1593 | ch->name[SMD_MAX_CH_NAME_LEN-1] = 0; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1594 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1595 | ch->pdev.name = ch->name; |
| 1596 | ch->pdev.id = ch->type; |
| 1597 | |
| 1598 | SMD_INFO("smd_alloc_channel() '%s' cid=%d\n", |
| 1599 | ch->name, ch->n); |
| 1600 | |
| 1601 | mutex_lock(&smd_creation_mutex); |
| 1602 | list_add(&ch->ch_list, &smd_ch_closed_list); |
| 1603 | mutex_unlock(&smd_creation_mutex); |
| 1604 | |
| 1605 | platform_device_register(&ch->pdev); |
| 1606 | if (!strncmp(ch->name, "LOOPBACK", 8) && ch->type == SMD_APPS_MODEM) { |
| 1607 | /* create a platform driver to be used by smd_tty driver |
| 1608 | * so that it can access the loopback port |
| 1609 | */ |
| 1610 | loopback_tty_pdev.id = ch->type; |
| 1611 | platform_device_register(&loopback_tty_pdev); |
| 1612 | } |
| 1613 | return 0; |
| 1614 | } |
| 1615 | |
| 1616 | static inline void notify_loopback_smd(void) |
| 1617 | { |
| 1618 | unsigned long flags; |
| 1619 | struct smd_channel *ch; |
| 1620 | |
| 1621 | spin_lock_irqsave(&smd_lock, flags); |
| 1622 | list_for_each_entry(ch, &smd_ch_list_loopback, ch_list) { |
| 1623 | ch->notify(ch->priv, SMD_EVENT_DATA); |
| 1624 | } |
| 1625 | spin_unlock_irqrestore(&smd_lock, flags); |
| 1626 | } |
| 1627 | |
| 1628 | static int smd_alloc_loopback_channel(void) |
| 1629 | { |
| 1630 | static struct smd_half_channel smd_loopback_ctl; |
| 1631 | static char smd_loopback_data[SMD_BUF_SIZE]; |
| 1632 | struct smd_channel *ch; |
| 1633 | |
| 1634 | ch = kzalloc(sizeof(struct smd_channel), GFP_KERNEL); |
| 1635 | if (ch == 0) { |
| 1636 | pr_err("%s: out of memory\n", __func__); |
| 1637 | return -1; |
| 1638 | } |
| 1639 | ch->n = SMD_LOOPBACK_CID; |
| 1640 | |
| 1641 | ch->send = &smd_loopback_ctl; |
| 1642 | ch->recv = &smd_loopback_ctl; |
| 1643 | ch->send_data = smd_loopback_data; |
| 1644 | ch->recv_data = smd_loopback_data; |
| 1645 | ch->fifo_size = SMD_BUF_SIZE; |
| 1646 | |
| 1647 | ch->fifo_mask = ch->fifo_size - 1; |
| 1648 | ch->type = SMD_LOOPBACK_TYPE; |
| 1649 | ch->notify_other_cpu = notify_loopback_smd; |
| 1650 | |
| 1651 | ch->read = smd_stream_read; |
| 1652 | ch->write = smd_stream_write; |
| 1653 | ch->read_avail = smd_stream_read_avail; |
| 1654 | ch->write_avail = smd_stream_write_avail; |
| 1655 | ch->update_state = update_stream_state; |
| 1656 | ch->read_from_cb = smd_stream_read; |
| 1657 | |
| 1658 | memset(ch->name, 0, 20); |
| 1659 | memcpy(ch->name, "local_loopback", 14); |
| 1660 | |
| 1661 | ch->pdev.name = ch->name; |
| 1662 | ch->pdev.id = ch->type; |
| 1663 | |
| 1664 | SMD_INFO("%s: '%s' cid=%d\n", __func__, ch->name, ch->n); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1665 | |
| 1666 | mutex_lock(&smd_creation_mutex); |
| 1667 | list_add(&ch->ch_list, &smd_ch_closed_list); |
| 1668 | mutex_unlock(&smd_creation_mutex); |
| 1669 | |
| 1670 | platform_device_register(&ch->pdev); |
Brian Swetland | 34f719b | 2009-10-30 16:22:05 -0700 | [diff] [blame] | 1671 | return 0; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1672 | } |
| 1673 | |
| 1674 | static void do_nothing_notify(void *priv, unsigned flags) |
| 1675 | { |
| 1676 | } |
| 1677 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1678 | static void finalize_channel_close_fn(struct work_struct *work) |
| 1679 | { |
| 1680 | unsigned long flags; |
| 1681 | struct smd_channel *ch; |
| 1682 | struct smd_channel *index; |
| 1683 | |
Eric Holmberg | bb2b1fa | 2011-10-12 16:41:37 -0600 | [diff] [blame] | 1684 | mutex_lock(&smd_creation_mutex); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1685 | spin_lock_irqsave(&smd_lock, flags); |
| 1686 | list_for_each_entry_safe(ch, index, &smd_ch_to_close_list, ch_list) { |
| 1687 | list_del(&ch->ch_list); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1688 | list_add(&ch->ch_list, &smd_ch_closed_list); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1689 | ch->notify(ch->priv, SMD_EVENT_REOPEN_READY); |
| 1690 | ch->notify = do_nothing_notify; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1691 | } |
| 1692 | spin_unlock_irqrestore(&smd_lock, flags); |
Eric Holmberg | bb2b1fa | 2011-10-12 16:41:37 -0600 | [diff] [blame] | 1693 | mutex_unlock(&smd_creation_mutex); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1694 | } |
| 1695 | |
| 1696 | struct smd_channel *smd_get_channel(const char *name, uint32_t type) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1697 | { |
| 1698 | struct smd_channel *ch; |
| 1699 | |
| 1700 | mutex_lock(&smd_creation_mutex); |
| 1701 | list_for_each_entry(ch, &smd_ch_closed_list, ch_list) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1702 | if (!strcmp(name, ch->name) && |
| 1703 | (type == ch->type)) { |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1704 | list_del(&ch->ch_list); |
| 1705 | mutex_unlock(&smd_creation_mutex); |
| 1706 | return ch; |
| 1707 | } |
| 1708 | } |
| 1709 | mutex_unlock(&smd_creation_mutex); |
| 1710 | |
| 1711 | return NULL; |
| 1712 | } |
| 1713 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1714 | int smd_named_open_on_edge(const char *name, uint32_t edge, |
| 1715 | smd_channel_t **_ch, |
| 1716 | void *priv, void (*notify)(void *, unsigned)) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1717 | { |
| 1718 | struct smd_channel *ch; |
| 1719 | unsigned long flags; |
| 1720 | |
| 1721 | if (smd_initialized == 0) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1722 | SMD_INFO("smd_open() before smd_init()\n"); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1723 | return -ENODEV; |
| 1724 | } |
| 1725 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1726 | SMD_DBG("smd_open('%s', %p, %p)\n", name, priv, notify); |
| 1727 | |
| 1728 | ch = smd_get_channel(name, edge); |
Eric Holmberg | bb2b1fa | 2011-10-12 16:41:37 -0600 | [diff] [blame] | 1729 | if (!ch) { |
Eric Holmberg | bb2b1fa | 2011-10-12 16:41:37 -0600 | [diff] [blame] | 1730 | /* check closing list for port */ |
| 1731 | spin_lock_irqsave(&smd_lock, flags); |
| 1732 | list_for_each_entry(ch, &smd_ch_closing_list, ch_list) { |
| 1733 | if (!strncmp(name, ch->name, 20) && |
| 1734 | (edge == ch->type)) { |
| 1735 | /* channel exists, but is being closed */ |
| 1736 | spin_unlock_irqrestore(&smd_lock, flags); |
| 1737 | return -EAGAIN; |
| 1738 | } |
| 1739 | } |
| 1740 | |
| 1741 | /* check closing workqueue list for port */ |
| 1742 | list_for_each_entry(ch, &smd_ch_to_close_list, ch_list) { |
| 1743 | if (!strncmp(name, ch->name, 20) && |
| 1744 | (edge == ch->type)) { |
| 1745 | /* channel exists, but is being closed */ |
| 1746 | spin_unlock_irqrestore(&smd_lock, flags); |
| 1747 | return -EAGAIN; |
| 1748 | } |
| 1749 | } |
| 1750 | spin_unlock_irqrestore(&smd_lock, flags); |
| 1751 | |
| 1752 | /* one final check to handle closing->closed race condition */ |
| 1753 | ch = smd_get_channel(name, edge); |
| 1754 | if (!ch) |
| 1755 | return -ENODEV; |
| 1756 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1757 | |
| 1758 | if (notify == 0) |
| 1759 | notify = do_nothing_notify; |
| 1760 | |
| 1761 | ch->notify = notify; |
| 1762 | ch->current_packet = 0; |
| 1763 | ch->last_state = SMD_SS_CLOSED; |
| 1764 | ch->priv = priv; |
| 1765 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1766 | if (edge == SMD_LOOPBACK_TYPE) { |
| 1767 | ch->last_state = SMD_SS_OPENED; |
| 1768 | ch->send->state = SMD_SS_OPENED; |
| 1769 | ch->send->fDSR = 1; |
| 1770 | ch->send->fCTS = 1; |
| 1771 | ch->send->fCD = 1; |
| 1772 | } |
| 1773 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1774 | *_ch = ch; |
| 1775 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1776 | SMD_DBG("smd_open: opening '%s'\n", ch->name); |
| 1777 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1778 | spin_lock_irqsave(&smd_lock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1779 | if (SMD_CHANNEL_TYPE(ch->type) == SMD_APPS_MODEM) |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 1780 | list_add(&ch->ch_list, &smd_ch_list_modem); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1781 | else if (SMD_CHANNEL_TYPE(ch->type) == SMD_APPS_QDSP) |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 1782 | list_add(&ch->ch_list, &smd_ch_list_dsp); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1783 | else if (SMD_CHANNEL_TYPE(ch->type) == SMD_APPS_DSPS) |
| 1784 | list_add(&ch->ch_list, &smd_ch_list_dsps); |
| 1785 | else if (SMD_CHANNEL_TYPE(ch->type) == SMD_APPS_WCNSS) |
| 1786 | list_add(&ch->ch_list, &smd_ch_list_wcnss); |
| 1787 | else |
| 1788 | list_add(&ch->ch_list, &smd_ch_list_loopback); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1789 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1790 | SMD_DBG("%s: opening ch %d\n", __func__, ch->n); |
| 1791 | |
| 1792 | if (edge != SMD_LOOPBACK_TYPE) |
| 1793 | smd_state_change(ch, ch->last_state, SMD_SS_OPENING); |
| 1794 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1795 | spin_unlock_irqrestore(&smd_lock, flags); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1796 | |
| 1797 | return 0; |
| 1798 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1799 | EXPORT_SYMBOL(smd_named_open_on_edge); |
| 1800 | |
| 1801 | |
| 1802 | int smd_open(const char *name, smd_channel_t **_ch, |
| 1803 | void *priv, void (*notify)(void *, unsigned)) |
| 1804 | { |
| 1805 | return smd_named_open_on_edge(name, SMD_APPS_MODEM, _ch, priv, |
| 1806 | notify); |
| 1807 | } |
| 1808 | EXPORT_SYMBOL(smd_open); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1809 | |
| 1810 | int smd_close(smd_channel_t *ch) |
| 1811 | { |
| 1812 | unsigned long flags; |
| 1813 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1814 | if (ch == 0) |
| 1815 | return -1; |
| 1816 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1817 | SMD_INFO("smd_close(%s)\n", ch->name); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1818 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1819 | spin_lock_irqsave(&smd_lock, flags); |
| 1820 | list_del(&ch->ch_list); |
| 1821 | if (ch->n == SMD_LOOPBACK_CID) { |
| 1822 | ch->send->fDSR = 0; |
| 1823 | ch->send->fCTS = 0; |
| 1824 | ch->send->fCD = 0; |
| 1825 | ch->send->state = SMD_SS_CLOSED; |
| 1826 | } else |
| 1827 | ch_set_state(ch, SMD_SS_CLOSED); |
| 1828 | |
| 1829 | if (ch->recv->state == SMD_SS_OPENED) { |
| 1830 | list_add(&ch->ch_list, &smd_ch_closing_list); |
| 1831 | spin_unlock_irqrestore(&smd_lock, flags); |
| 1832 | } else { |
| 1833 | spin_unlock_irqrestore(&smd_lock, flags); |
| 1834 | ch->notify = do_nothing_notify; |
| 1835 | mutex_lock(&smd_creation_mutex); |
| 1836 | list_add(&ch->ch_list, &smd_ch_closed_list); |
| 1837 | mutex_unlock(&smd_creation_mutex); |
| 1838 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1839 | |
| 1840 | return 0; |
| 1841 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1842 | EXPORT_SYMBOL(smd_close); |
| 1843 | |
| 1844 | int smd_write_start(smd_channel_t *ch, int len) |
| 1845 | { |
| 1846 | int ret; |
| 1847 | unsigned hdr[5]; |
| 1848 | |
| 1849 | if (!ch) { |
| 1850 | pr_err("%s: Invalid channel specified\n", __func__); |
| 1851 | return -ENODEV; |
| 1852 | } |
| 1853 | if (!ch->is_pkt_ch) { |
| 1854 | pr_err("%s: non-packet channel specified\n", __func__); |
| 1855 | return -EACCES; |
| 1856 | } |
| 1857 | if (len < 1) { |
| 1858 | pr_err("%s: invalid length: %d\n", __func__, len); |
| 1859 | return -EINVAL; |
| 1860 | } |
| 1861 | |
| 1862 | if (ch->pending_pkt_sz) { |
| 1863 | pr_err("%s: packet of size: %d in progress\n", __func__, |
| 1864 | ch->pending_pkt_sz); |
| 1865 | return -EBUSY; |
| 1866 | } |
| 1867 | ch->pending_pkt_sz = len; |
| 1868 | |
| 1869 | if (smd_stream_write_avail(ch) < (SMD_HEADER_SIZE)) { |
| 1870 | ch->pending_pkt_sz = 0; |
| 1871 | SMD_DBG("%s: no space to write packet header\n", __func__); |
| 1872 | return -EAGAIN; |
| 1873 | } |
| 1874 | |
| 1875 | hdr[0] = len; |
| 1876 | hdr[1] = hdr[2] = hdr[3] = hdr[4] = 0; |
| 1877 | |
| 1878 | |
| 1879 | ret = smd_stream_write(ch, hdr, sizeof(hdr), 0); |
| 1880 | if (ret < 0 || ret != sizeof(hdr)) { |
| 1881 | ch->pending_pkt_sz = 0; |
| 1882 | pr_err("%s: packet header failed to write\n", __func__); |
| 1883 | return -EPERM; |
| 1884 | } |
| 1885 | return 0; |
| 1886 | } |
| 1887 | EXPORT_SYMBOL(smd_write_start); |
| 1888 | |
| 1889 | int smd_write_segment(smd_channel_t *ch, void *data, int len, int user_buf) |
| 1890 | { |
| 1891 | int bytes_written; |
| 1892 | |
| 1893 | if (!ch) { |
| 1894 | pr_err("%s: Invalid channel specified\n", __func__); |
| 1895 | return -ENODEV; |
| 1896 | } |
| 1897 | if (len < 1) { |
| 1898 | pr_err("%s: invalid length: %d\n", __func__, len); |
| 1899 | return -EINVAL; |
| 1900 | } |
| 1901 | |
| 1902 | if (!ch->pending_pkt_sz) { |
| 1903 | pr_err("%s: no transaction in progress\n", __func__); |
| 1904 | return -ENOEXEC; |
| 1905 | } |
| 1906 | if (ch->pending_pkt_sz - len < 0) { |
| 1907 | pr_err("%s: segment of size: %d will make packet go over " |
| 1908 | "length\n", __func__, len); |
| 1909 | return -EINVAL; |
| 1910 | } |
| 1911 | |
| 1912 | bytes_written = smd_stream_write(ch, data, len, user_buf); |
| 1913 | |
| 1914 | ch->pending_pkt_sz -= bytes_written; |
| 1915 | |
| 1916 | return bytes_written; |
| 1917 | } |
| 1918 | EXPORT_SYMBOL(smd_write_segment); |
| 1919 | |
| 1920 | int smd_write_end(smd_channel_t *ch) |
| 1921 | { |
| 1922 | |
| 1923 | if (!ch) { |
| 1924 | pr_err("%s: Invalid channel specified\n", __func__); |
| 1925 | return -ENODEV; |
| 1926 | } |
| 1927 | if (ch->pending_pkt_sz) { |
| 1928 | pr_err("%s: current packet not completely written\n", __func__); |
| 1929 | return -E2BIG; |
| 1930 | } |
| 1931 | |
| 1932 | return 0; |
| 1933 | } |
| 1934 | EXPORT_SYMBOL(smd_write_end); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1935 | |
| 1936 | int smd_read(smd_channel_t *ch, void *data, int len) |
| 1937 | { |
Jack Pham | 1b236d1 | 2012-03-19 15:27:18 -0700 | [diff] [blame] | 1938 | if (!ch) { |
| 1939 | pr_err("%s: Invalid channel specified\n", __func__); |
| 1940 | return -ENODEV; |
| 1941 | } |
| 1942 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1943 | return ch->read(ch, data, len, 0); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1944 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1945 | EXPORT_SYMBOL(smd_read); |
| 1946 | |
| 1947 | int smd_read_user_buffer(smd_channel_t *ch, void *data, int len) |
| 1948 | { |
Jack Pham | 1b236d1 | 2012-03-19 15:27:18 -0700 | [diff] [blame] | 1949 | if (!ch) { |
| 1950 | pr_err("%s: Invalid channel specified\n", __func__); |
| 1951 | return -ENODEV; |
| 1952 | } |
| 1953 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1954 | return ch->read(ch, data, len, 1); |
| 1955 | } |
| 1956 | EXPORT_SYMBOL(smd_read_user_buffer); |
| 1957 | |
| 1958 | int smd_read_from_cb(smd_channel_t *ch, void *data, int len) |
| 1959 | { |
Jack Pham | 1b236d1 | 2012-03-19 15:27:18 -0700 | [diff] [blame] | 1960 | if (!ch) { |
| 1961 | pr_err("%s: Invalid channel specified\n", __func__); |
| 1962 | return -ENODEV; |
| 1963 | } |
| 1964 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1965 | return ch->read_from_cb(ch, data, len, 0); |
| 1966 | } |
| 1967 | EXPORT_SYMBOL(smd_read_from_cb); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1968 | |
| 1969 | int smd_write(smd_channel_t *ch, const void *data, int len) |
| 1970 | { |
Jack Pham | 1b236d1 | 2012-03-19 15:27:18 -0700 | [diff] [blame] | 1971 | if (!ch) { |
| 1972 | pr_err("%s: Invalid channel specified\n", __func__); |
| 1973 | return -ENODEV; |
| 1974 | } |
| 1975 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1976 | return ch->pending_pkt_sz ? -EBUSY : ch->write(ch, data, len, 0); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1977 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1978 | EXPORT_SYMBOL(smd_write); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1979 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1980 | int smd_write_user_buffer(smd_channel_t *ch, const void *data, int len) |
Brian Swetland | 636eb9c | 2009-12-07 15:28:08 -0800 | [diff] [blame] | 1981 | { |
Jack Pham | 1b236d1 | 2012-03-19 15:27:18 -0700 | [diff] [blame] | 1982 | if (!ch) { |
| 1983 | pr_err("%s: Invalid channel specified\n", __func__); |
| 1984 | return -ENODEV; |
| 1985 | } |
| 1986 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1987 | return ch->pending_pkt_sz ? -EBUSY : ch->write(ch, data, len, 1); |
Brian Swetland | 636eb9c | 2009-12-07 15:28:08 -0800 | [diff] [blame] | 1988 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1989 | EXPORT_SYMBOL(smd_write_user_buffer); |
Brian Swetland | 636eb9c | 2009-12-07 15:28:08 -0800 | [diff] [blame] | 1990 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1991 | int smd_read_avail(smd_channel_t *ch) |
| 1992 | { |
Jack Pham | 1b236d1 | 2012-03-19 15:27:18 -0700 | [diff] [blame] | 1993 | if (!ch) { |
| 1994 | pr_err("%s: Invalid channel specified\n", __func__); |
| 1995 | return -ENODEV; |
| 1996 | } |
| 1997 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1998 | return ch->read_avail(ch); |
| 1999 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2000 | EXPORT_SYMBOL(smd_read_avail); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2001 | |
| 2002 | int smd_write_avail(smd_channel_t *ch) |
| 2003 | { |
Jack Pham | 1b236d1 | 2012-03-19 15:27:18 -0700 | [diff] [blame] | 2004 | if (!ch) { |
| 2005 | pr_err("%s: Invalid channel specified\n", __func__); |
| 2006 | return -ENODEV; |
| 2007 | } |
| 2008 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2009 | return ch->write_avail(ch); |
| 2010 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2011 | EXPORT_SYMBOL(smd_write_avail); |
| 2012 | |
| 2013 | void smd_enable_read_intr(smd_channel_t *ch) |
| 2014 | { |
| 2015 | if (ch) |
| 2016 | ch->send->fBLOCKREADINTR = 0; |
| 2017 | } |
| 2018 | EXPORT_SYMBOL(smd_enable_read_intr); |
| 2019 | |
| 2020 | void smd_disable_read_intr(smd_channel_t *ch) |
| 2021 | { |
| 2022 | if (ch) |
| 2023 | ch->send->fBLOCKREADINTR = 1; |
| 2024 | } |
| 2025 | EXPORT_SYMBOL(smd_disable_read_intr); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2026 | |
| 2027 | int smd_wait_until_readable(smd_channel_t *ch, int bytes) |
| 2028 | { |
| 2029 | return -1; |
| 2030 | } |
| 2031 | |
| 2032 | int smd_wait_until_writable(smd_channel_t *ch, int bytes) |
| 2033 | { |
| 2034 | return -1; |
| 2035 | } |
| 2036 | |
| 2037 | int smd_cur_packet_size(smd_channel_t *ch) |
| 2038 | { |
Jack Pham | 1b236d1 | 2012-03-19 15:27:18 -0700 | [diff] [blame] | 2039 | if (!ch) { |
| 2040 | pr_err("%s: Invalid channel specified\n", __func__); |
| 2041 | return -ENODEV; |
| 2042 | } |
| 2043 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2044 | return ch->current_packet; |
| 2045 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2046 | EXPORT_SYMBOL(smd_cur_packet_size); |
| 2047 | |
| 2048 | int smd_tiocmget(smd_channel_t *ch) |
| 2049 | { |
Jack Pham | 1b236d1 | 2012-03-19 15:27:18 -0700 | [diff] [blame] | 2050 | if (!ch) { |
| 2051 | pr_err("%s: Invalid channel specified\n", __func__); |
| 2052 | return -ENODEV; |
| 2053 | } |
| 2054 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2055 | return (ch->recv->fDSR ? TIOCM_DSR : 0) | |
| 2056 | (ch->recv->fCTS ? TIOCM_CTS : 0) | |
| 2057 | (ch->recv->fCD ? TIOCM_CD : 0) | |
| 2058 | (ch->recv->fRI ? TIOCM_RI : 0) | |
| 2059 | (ch->send->fCTS ? TIOCM_RTS : 0) | |
| 2060 | (ch->send->fDSR ? TIOCM_DTR : 0); |
| 2061 | } |
| 2062 | EXPORT_SYMBOL(smd_tiocmget); |
| 2063 | |
Vamsi Krishna | cb12a10 | 2011-08-17 15:18:26 -0700 | [diff] [blame] | 2064 | /* this api will be called while holding smd_lock */ |
| 2065 | int |
| 2066 | smd_tiocmset_from_cb(smd_channel_t *ch, unsigned int set, unsigned int clear) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2067 | { |
Jack Pham | 1b236d1 | 2012-03-19 15:27:18 -0700 | [diff] [blame] | 2068 | if (!ch) { |
| 2069 | pr_err("%s: Invalid channel specified\n", __func__); |
| 2070 | return -ENODEV; |
| 2071 | } |
| 2072 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2073 | if (set & TIOCM_DTR) |
| 2074 | ch->send->fDSR = 1; |
| 2075 | |
| 2076 | if (set & TIOCM_RTS) |
| 2077 | ch->send->fCTS = 1; |
| 2078 | |
| 2079 | if (clear & TIOCM_DTR) |
| 2080 | ch->send->fDSR = 0; |
| 2081 | |
| 2082 | if (clear & TIOCM_RTS) |
| 2083 | ch->send->fCTS = 0; |
| 2084 | |
| 2085 | ch->send->fSTATE = 1; |
| 2086 | barrier(); |
| 2087 | ch->notify_other_cpu(); |
Vamsi Krishna | cb12a10 | 2011-08-17 15:18:26 -0700 | [diff] [blame] | 2088 | |
| 2089 | return 0; |
| 2090 | } |
| 2091 | EXPORT_SYMBOL(smd_tiocmset_from_cb); |
| 2092 | |
| 2093 | int smd_tiocmset(smd_channel_t *ch, unsigned int set, unsigned int clear) |
| 2094 | { |
| 2095 | unsigned long flags; |
| 2096 | |
Jack Pham | 1b236d1 | 2012-03-19 15:27:18 -0700 | [diff] [blame] | 2097 | if (!ch) { |
| 2098 | pr_err("%s: Invalid channel specified\n", __func__); |
| 2099 | return -ENODEV; |
| 2100 | } |
| 2101 | |
Vamsi Krishna | cb12a10 | 2011-08-17 15:18:26 -0700 | [diff] [blame] | 2102 | spin_lock_irqsave(&smd_lock, flags); |
| 2103 | smd_tiocmset_from_cb(ch, set, clear); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2104 | spin_unlock_irqrestore(&smd_lock, flags); |
| 2105 | |
| 2106 | return 0; |
| 2107 | } |
| 2108 | EXPORT_SYMBOL(smd_tiocmset); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2109 | |
| 2110 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2111 | /* -------------------------------------------------------------------------- */ |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2112 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2113 | /* smem_alloc returns the pointer to smem item if it is already allocated. |
| 2114 | * Otherwise, it returns NULL. |
| 2115 | */ |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2116 | void *smem_alloc(unsigned id, unsigned size) |
| 2117 | { |
| 2118 | return smem_find(id, size); |
| 2119 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2120 | EXPORT_SYMBOL(smem_alloc); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2121 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2122 | /* smem_alloc2 returns the pointer to smem item. If it is not allocated, |
| 2123 | * it allocates it and then returns the pointer to it. |
| 2124 | */ |
Angshuman Sarkar | 4eade0d | 2011-08-17 14:06:23 +0530 | [diff] [blame] | 2125 | void *smem_alloc2(unsigned id, unsigned size_in) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2126 | { |
| 2127 | struct smem_shared *shared = (void *) MSM_SHARED_RAM_BASE; |
| 2128 | struct smem_heap_entry *toc = shared->heap_toc; |
| 2129 | unsigned long flags; |
| 2130 | void *ret = NULL; |
| 2131 | |
| 2132 | if (!shared->heap_info.initialized) { |
| 2133 | pr_err("%s: smem heap info not initialized\n", __func__); |
| 2134 | return NULL; |
| 2135 | } |
| 2136 | |
| 2137 | if (id >= SMEM_NUM_ITEMS) |
| 2138 | return NULL; |
| 2139 | |
| 2140 | size_in = ALIGN(size_in, 8); |
| 2141 | remote_spin_lock_irqsave(&remote_spinlock, flags); |
| 2142 | if (toc[id].allocated) { |
| 2143 | SMD_DBG("%s: %u already allocated\n", __func__, id); |
| 2144 | if (size_in != toc[id].size) |
| 2145 | pr_err("%s: wrong size %u (expected %u)\n", |
| 2146 | __func__, toc[id].size, size_in); |
| 2147 | else |
| 2148 | ret = (void *)(MSM_SHARED_RAM_BASE + toc[id].offset); |
| 2149 | } else if (id > SMEM_FIXED_ITEM_LAST) { |
| 2150 | SMD_DBG("%s: allocating %u\n", __func__, id); |
| 2151 | if (shared->heap_info.heap_remaining >= size_in) { |
| 2152 | toc[id].offset = shared->heap_info.free_offset; |
| 2153 | toc[id].size = size_in; |
| 2154 | wmb(); |
| 2155 | toc[id].allocated = 1; |
| 2156 | |
| 2157 | shared->heap_info.free_offset += size_in; |
| 2158 | shared->heap_info.heap_remaining -= size_in; |
| 2159 | ret = (void *)(MSM_SHARED_RAM_BASE + toc[id].offset); |
| 2160 | } else |
| 2161 | pr_err("%s: not enough memory %u (required %u)\n", |
| 2162 | __func__, shared->heap_info.heap_remaining, |
| 2163 | size_in); |
| 2164 | } |
| 2165 | wmb(); |
| 2166 | remote_spin_unlock_irqrestore(&remote_spinlock, flags); |
| 2167 | return ret; |
| 2168 | } |
Angshuman Sarkar | 4eade0d | 2011-08-17 14:06:23 +0530 | [diff] [blame] | 2169 | EXPORT_SYMBOL(smem_alloc2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2170 | |
| 2171 | void *smem_get_entry(unsigned id, unsigned *size) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2172 | { |
| 2173 | struct smem_shared *shared = (void *) MSM_SHARED_RAM_BASE; |
| 2174 | struct smem_heap_entry *toc = shared->heap_toc; |
Angshuman Sarkar | 7ee0dca | 2011-08-22 21:37:34 +0530 | [diff] [blame] | 2175 | int use_spinlocks = spinlocks_initialized; |
| 2176 | void *ret = 0; |
| 2177 | unsigned long flags = 0; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2178 | |
| 2179 | if (id >= SMEM_NUM_ITEMS) |
Angshuman Sarkar | 7ee0dca | 2011-08-22 21:37:34 +0530 | [diff] [blame] | 2180 | return ret; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2181 | |
Angshuman Sarkar | 7ee0dca | 2011-08-22 21:37:34 +0530 | [diff] [blame] | 2182 | if (use_spinlocks) |
| 2183 | remote_spin_lock_irqsave(&remote_spinlock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2184 | /* toc is in device memory and cannot be speculatively accessed */ |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2185 | if (toc[id].allocated) { |
| 2186 | *size = toc[id].size; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2187 | barrier(); |
Angshuman Sarkar | 7ee0dca | 2011-08-22 21:37:34 +0530 | [diff] [blame] | 2188 | ret = (void *) (MSM_SHARED_RAM_BASE + toc[id].offset); |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 2189 | } else { |
| 2190 | *size = 0; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2191 | } |
Angshuman Sarkar | 7ee0dca | 2011-08-22 21:37:34 +0530 | [diff] [blame] | 2192 | if (use_spinlocks) |
| 2193 | remote_spin_unlock_irqrestore(&remote_spinlock, flags); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2194 | |
Angshuman Sarkar | 7ee0dca | 2011-08-22 21:37:34 +0530 | [diff] [blame] | 2195 | return ret; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2196 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2197 | EXPORT_SYMBOL(smem_get_entry); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2198 | |
| 2199 | void *smem_find(unsigned id, unsigned size_in) |
| 2200 | { |
| 2201 | unsigned size; |
| 2202 | void *ptr; |
| 2203 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2204 | ptr = smem_get_entry(id, &size); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2205 | if (!ptr) |
| 2206 | return 0; |
| 2207 | |
| 2208 | size_in = ALIGN(size_in, 8); |
| 2209 | if (size_in != size) { |
| 2210 | pr_err("smem_find(%d, %d): wrong size %d\n", |
| 2211 | id, size_in, size); |
| 2212 | return 0; |
| 2213 | } |
| 2214 | |
| 2215 | return ptr; |
| 2216 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2217 | EXPORT_SYMBOL(smem_find); |
| 2218 | |
| 2219 | static int smsm_cb_init(void) |
| 2220 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2221 | struct smsm_state_info *state_info; |
| 2222 | int n; |
| 2223 | int ret = 0; |
| 2224 | |
| 2225 | smsm_states = kmalloc(sizeof(struct smsm_state_info)*SMSM_NUM_ENTRIES, |
| 2226 | GFP_KERNEL); |
| 2227 | |
| 2228 | if (!smsm_states) { |
| 2229 | pr_err("%s: SMSM init failed\n", __func__); |
| 2230 | return -ENOMEM; |
| 2231 | } |
| 2232 | |
Eric Holmberg | c800290 | 2011-09-16 13:55:57 -0600 | [diff] [blame] | 2233 | mutex_lock(&smsm_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2234 | for (n = 0; n < SMSM_NUM_ENTRIES; n++) { |
| 2235 | state_info = &smsm_states[n]; |
| 2236 | state_info->last_value = __raw_readl(SMSM_STATE_ADDR(n)); |
| 2237 | INIT_LIST_HEAD(&state_info->callbacks); |
| 2238 | } |
Eric Holmberg | c800290 | 2011-09-16 13:55:57 -0600 | [diff] [blame] | 2239 | mutex_unlock(&smsm_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2240 | |
| 2241 | return ret; |
| 2242 | } |
| 2243 | |
| 2244 | static int smsm_init(void) |
| 2245 | { |
| 2246 | struct smem_shared *shared = (void *) MSM_SHARED_RAM_BASE; |
| 2247 | int i; |
| 2248 | struct smsm_size_info_type *smsm_size_info; |
| 2249 | |
| 2250 | i = remote_spin_lock_init(&remote_spinlock, SMEM_SPINLOCK_SMEM_ALLOC); |
| 2251 | if (i) { |
| 2252 | pr_err("%s: remote spinlock init failed %d\n", __func__, i); |
| 2253 | return i; |
| 2254 | } |
Angshuman Sarkar | 7ee0dca | 2011-08-22 21:37:34 +0530 | [diff] [blame] | 2255 | spinlocks_initialized = 1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2256 | |
| 2257 | smsm_size_info = smem_alloc(SMEM_SMSM_SIZE_INFO, |
| 2258 | sizeof(struct smsm_size_info_type)); |
| 2259 | if (smsm_size_info) { |
| 2260 | SMSM_NUM_ENTRIES = smsm_size_info->num_entries; |
| 2261 | SMSM_NUM_HOSTS = smsm_size_info->num_hosts; |
| 2262 | } |
| 2263 | |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 2264 | i = kfifo_alloc(&smsm_snapshot_fifo, |
| 2265 | sizeof(uint32_t) * SMSM_NUM_ENTRIES * SMSM_SNAPSHOT_CNT, |
| 2266 | GFP_KERNEL); |
| 2267 | if (i) { |
| 2268 | pr_err("%s: SMSM state fifo alloc failed %d\n", __func__, i); |
| 2269 | return i; |
| 2270 | } |
Eric Holmberg | 59a9f94 | 2012-03-19 10:04:22 -0600 | [diff] [blame^] | 2271 | wake_lock_init(&smsm_snapshot_wakelock, WAKE_LOCK_SUSPEND, |
| 2272 | "smsm_snapshot"); |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 2273 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2274 | if (!smsm_info.state) { |
| 2275 | smsm_info.state = smem_alloc2(ID_SHARED_STATE, |
| 2276 | SMSM_NUM_ENTRIES * |
| 2277 | sizeof(uint32_t)); |
| 2278 | |
| 2279 | if (smsm_info.state) { |
| 2280 | __raw_writel(0, SMSM_STATE_ADDR(SMSM_APPS_STATE)); |
| 2281 | if ((shared->version[VERSION_MODEM] >> 16) >= 0xB) |
| 2282 | __raw_writel(0, \ |
| 2283 | SMSM_STATE_ADDR(SMSM_APPS_DEM_I)); |
| 2284 | } |
| 2285 | } |
| 2286 | |
| 2287 | if (!smsm_info.intr_mask) { |
| 2288 | smsm_info.intr_mask = smem_alloc2(SMEM_SMSM_CPU_INTR_MASK, |
| 2289 | SMSM_NUM_ENTRIES * |
| 2290 | SMSM_NUM_HOSTS * |
| 2291 | sizeof(uint32_t)); |
| 2292 | |
| 2293 | if (smsm_info.intr_mask) |
| 2294 | for (i = 0; i < SMSM_NUM_ENTRIES; i++) |
| 2295 | __raw_writel(0xffffffff, |
| 2296 | SMSM_INTR_MASK_ADDR(i, SMSM_APPS)); |
| 2297 | } |
| 2298 | |
| 2299 | if (!smsm_info.intr_mux) |
| 2300 | smsm_info.intr_mux = smem_alloc2(SMEM_SMD_SMSM_INTR_MUX, |
| 2301 | SMSM_NUM_INTR_MUX * |
| 2302 | sizeof(uint32_t)); |
| 2303 | |
| 2304 | i = smsm_cb_init(); |
| 2305 | if (i) |
| 2306 | return i; |
| 2307 | |
| 2308 | wmb(); |
| 2309 | return 0; |
| 2310 | } |
| 2311 | |
| 2312 | void smsm_reset_modem(unsigned mode) |
| 2313 | { |
| 2314 | if (mode == SMSM_SYSTEM_DOWNLOAD) { |
| 2315 | mode = SMSM_RESET | SMSM_SYSTEM_DOWNLOAD; |
| 2316 | } else if (mode == SMSM_MODEM_WAIT) { |
| 2317 | mode = SMSM_RESET | SMSM_MODEM_WAIT; |
| 2318 | } else { /* reset_mode is SMSM_RESET or default */ |
| 2319 | mode = SMSM_RESET; |
| 2320 | } |
| 2321 | |
| 2322 | smsm_change_state(SMSM_APPS_STATE, mode, mode); |
| 2323 | } |
| 2324 | EXPORT_SYMBOL(smsm_reset_modem); |
| 2325 | |
| 2326 | void smsm_reset_modem_cont(void) |
| 2327 | { |
| 2328 | unsigned long flags; |
| 2329 | uint32_t state; |
| 2330 | |
| 2331 | if (!smsm_info.state) |
| 2332 | return; |
| 2333 | |
| 2334 | spin_lock_irqsave(&smem_lock, flags); |
| 2335 | state = __raw_readl(SMSM_STATE_ADDR(SMSM_APPS_STATE)) \ |
| 2336 | & ~SMSM_MODEM_WAIT; |
| 2337 | __raw_writel(state, SMSM_STATE_ADDR(SMSM_APPS_STATE)); |
| 2338 | wmb(); |
| 2339 | spin_unlock_irqrestore(&smem_lock, flags); |
| 2340 | } |
| 2341 | EXPORT_SYMBOL(smsm_reset_modem_cont); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2342 | |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 2343 | static void smsm_cb_snapshot(void) |
| 2344 | { |
| 2345 | int n; |
| 2346 | uint32_t new_state; |
Eric Holmberg | 59a9f94 | 2012-03-19 10:04:22 -0600 | [diff] [blame^] | 2347 | unsigned long flags; |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 2348 | int ret; |
| 2349 | |
| 2350 | ret = kfifo_avail(&smsm_snapshot_fifo); |
| 2351 | if (ret < (SMSM_NUM_ENTRIES * 4)) { |
| 2352 | pr_err("%s: SMSM snapshot full %d\n", __func__, ret); |
| 2353 | return; |
| 2354 | } |
| 2355 | |
| 2356 | for (n = 0; n < SMSM_NUM_ENTRIES; n++) { |
| 2357 | new_state = __raw_readl(SMSM_STATE_ADDR(n)); |
| 2358 | |
| 2359 | ret = kfifo_in(&smsm_snapshot_fifo, |
| 2360 | &new_state, sizeof(new_state)); |
| 2361 | if (ret != sizeof(new_state)) { |
| 2362 | pr_err("%s: SMSM snapshot failure %d\n", __func__, ret); |
| 2363 | return; |
| 2364 | } |
| 2365 | } |
Eric Holmberg | 59a9f94 | 2012-03-19 10:04:22 -0600 | [diff] [blame^] | 2366 | |
| 2367 | spin_lock_irqsave(&smsm_snapshot_count_lock, flags); |
| 2368 | if (smsm_snapshot_count == 0) { |
| 2369 | SMx_POWER_INFO("SMSM snapshot wake lock\n"); |
| 2370 | wake_lock(&smsm_snapshot_wakelock); |
| 2371 | } |
| 2372 | ++smsm_snapshot_count; |
| 2373 | spin_unlock_irqrestore(&smsm_snapshot_count_lock, flags); |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 2374 | schedule_work(&smsm_cb_work); |
| 2375 | } |
| 2376 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2377 | static irqreturn_t smsm_irq_handler(int irq, void *data) |
| 2378 | { |
| 2379 | unsigned long flags; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2380 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2381 | if (irq == INT_ADSP_A11_SMSM) { |
Eric Holmberg | 6282c5d | 2011-10-27 17:30:57 -0600 | [diff] [blame] | 2382 | uint32_t mux_val; |
| 2383 | static uint32_t prev_smem_q6_apps_smsm; |
| 2384 | |
| 2385 | if (smsm_info.intr_mux && cpu_is_qsd8x50()) { |
| 2386 | mux_val = __raw_readl( |
| 2387 | SMSM_INTR_MUX_ADDR(SMEM_Q6_APPS_SMSM)); |
| 2388 | if (mux_val != prev_smem_q6_apps_smsm) |
| 2389 | prev_smem_q6_apps_smsm = mux_val; |
| 2390 | } |
| 2391 | |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 2392 | spin_lock_irqsave(&smem_lock, flags); |
| 2393 | smsm_cb_snapshot(); |
| 2394 | spin_unlock_irqrestore(&smem_lock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2395 | return IRQ_HANDLED; |
| 2396 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2397 | |
| 2398 | spin_lock_irqsave(&smem_lock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2399 | if (!smsm_info.state) { |
| 2400 | SMSM_INFO("<SM NO STATE>\n"); |
| 2401 | } else { |
| 2402 | unsigned old_apps, apps; |
| 2403 | unsigned modm = __raw_readl(SMSM_STATE_ADDR(SMSM_MODEM_STATE)); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2404 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2405 | old_apps = apps = __raw_readl(SMSM_STATE_ADDR(SMSM_APPS_STATE)); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2406 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2407 | SMSM_DBG("<SM %08x %08x>\n", apps, modm); |
| 2408 | if (apps & SMSM_RESET) { |
| 2409 | /* If we get an interrupt and the apps SMSM_RESET |
| 2410 | bit is already set, the modem is acking the |
| 2411 | app's reset ack. */ |
Eric Holmberg | 2bb6ccd | 2012-03-13 13:05:14 -0600 | [diff] [blame] | 2412 | if (!disable_smsm_reset_handshake) |
Angshuman Sarkar | ead67bd | 2011-09-21 20:13:12 +0530 | [diff] [blame] | 2413 | apps &= ~SMSM_RESET; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2414 | /* Issue a fake irq to handle any |
| 2415 | * smd state changes during reset |
| 2416 | */ |
| 2417 | smd_fake_irq_handler(0); |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 2418 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2419 | /* queue modem restart notify chain */ |
| 2420 | modem_queue_start_reset_notify(); |
| 2421 | |
| 2422 | } else if (modm & SMSM_RESET) { |
Eric Holmberg | 2bb6ccd | 2012-03-13 13:05:14 -0600 | [diff] [blame] | 2423 | if (!disable_smsm_reset_handshake) |
Angshuman Sarkar | ead67bd | 2011-09-21 20:13:12 +0530 | [diff] [blame] | 2424 | apps |= SMSM_RESET; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2425 | |
| 2426 | pr_err("\nSMSM: Modem SMSM state changed to SMSM_RESET."); |
| 2427 | modem_queue_start_reset_notify(); |
| 2428 | |
| 2429 | } else if (modm & SMSM_INIT) { |
| 2430 | if (!(apps & SMSM_INIT)) { |
| 2431 | apps |= SMSM_INIT; |
| 2432 | modem_queue_smsm_init_notify(); |
| 2433 | } |
| 2434 | |
| 2435 | if (modm & SMSM_SMDINIT) |
| 2436 | apps |= SMSM_SMDINIT; |
| 2437 | if ((apps & (SMSM_INIT | SMSM_SMDINIT | SMSM_RPCINIT)) == |
| 2438 | (SMSM_INIT | SMSM_SMDINIT | SMSM_RPCINIT)) |
| 2439 | apps |= SMSM_RUN; |
| 2440 | } else if (modm & SMSM_SYSTEM_DOWNLOAD) { |
| 2441 | pr_err("\nSMSM: Modem SMSM state changed to SMSM_SYSTEM_DOWNLOAD."); |
| 2442 | modem_queue_start_reset_notify(); |
| 2443 | } |
| 2444 | |
| 2445 | if (old_apps != apps) { |
| 2446 | SMSM_DBG("<SM %08x NOTIFY>\n", apps); |
| 2447 | __raw_writel(apps, SMSM_STATE_ADDR(SMSM_APPS_STATE)); |
| 2448 | do_smd_probe(); |
| 2449 | notify_other_smsm(SMSM_APPS_STATE, (old_apps ^ apps)); |
| 2450 | } |
| 2451 | |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 2452 | smsm_cb_snapshot(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2453 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2454 | spin_unlock_irqrestore(&smem_lock, flags); |
| 2455 | return IRQ_HANDLED; |
| 2456 | } |
| 2457 | |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 2458 | static irqreturn_t smsm_modem_irq_handler(int irq, void *data) |
| 2459 | { |
| 2460 | SMx_POWER_INFO("SMSM Int Modem->Apps\n"); |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 2461 | ++interrupt_stats[SMD_MODEM].smsm_in_count; |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 2462 | return smsm_irq_handler(irq, data); |
| 2463 | } |
| 2464 | |
| 2465 | static irqreturn_t smsm_dsp_irq_handler(int irq, void *data) |
| 2466 | { |
| 2467 | SMx_POWER_INFO("SMSM Int LPASS->Apps\n"); |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 2468 | ++interrupt_stats[SMD_Q6].smsm_in_count; |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 2469 | return smsm_irq_handler(irq, data); |
| 2470 | } |
| 2471 | |
| 2472 | static irqreturn_t smsm_dsps_irq_handler(int irq, void *data) |
| 2473 | { |
| 2474 | SMx_POWER_INFO("SMSM Int DSPS->Apps\n"); |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 2475 | ++interrupt_stats[SMD_DSPS].smsm_in_count; |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 2476 | return smsm_irq_handler(irq, data); |
| 2477 | } |
| 2478 | |
| 2479 | static irqreturn_t smsm_wcnss_irq_handler(int irq, void *data) |
| 2480 | { |
| 2481 | SMx_POWER_INFO("SMSM Int WCNSS->Apps\n"); |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 2482 | ++interrupt_stats[SMD_WCNSS].smsm_in_count; |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 2483 | return smsm_irq_handler(irq, data); |
| 2484 | } |
| 2485 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2486 | int smsm_change_intr_mask(uint32_t smsm_entry, |
| 2487 | uint32_t clear_mask, uint32_t set_mask) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2488 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2489 | uint32_t old_mask, new_mask; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2490 | unsigned long flags; |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 2491 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2492 | if (smsm_entry >= SMSM_NUM_ENTRIES) { |
| 2493 | pr_err("smsm_change_state: Invalid entry %d\n", |
| 2494 | smsm_entry); |
| 2495 | return -EINVAL; |
| 2496 | } |
| 2497 | |
| 2498 | if (!smsm_info.intr_mask) { |
| 2499 | pr_err("smsm_change_intr_mask <SM NO STATE>\n"); |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 2500 | return -EIO; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2501 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2502 | |
| 2503 | spin_lock_irqsave(&smem_lock, flags); |
| 2504 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2505 | old_mask = __raw_readl(SMSM_INTR_MASK_ADDR(smsm_entry, SMSM_APPS)); |
| 2506 | new_mask = (old_mask & ~clear_mask) | set_mask; |
| 2507 | __raw_writel(new_mask, SMSM_INTR_MASK_ADDR(smsm_entry, SMSM_APPS)); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2508 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2509 | wmb(); |
| 2510 | spin_unlock_irqrestore(&smem_lock, flags); |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 2511 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2512 | return 0; |
| 2513 | } |
| 2514 | EXPORT_SYMBOL(smsm_change_intr_mask); |
| 2515 | |
| 2516 | int smsm_get_intr_mask(uint32_t smsm_entry, uint32_t *intr_mask) |
| 2517 | { |
| 2518 | if (smsm_entry >= SMSM_NUM_ENTRIES) { |
| 2519 | pr_err("smsm_change_state: Invalid entry %d\n", |
| 2520 | smsm_entry); |
| 2521 | return -EINVAL; |
| 2522 | } |
| 2523 | |
| 2524 | if (!smsm_info.intr_mask) { |
| 2525 | pr_err("smsm_change_intr_mask <SM NO STATE>\n"); |
| 2526 | return -EIO; |
| 2527 | } |
| 2528 | |
| 2529 | *intr_mask = __raw_readl(SMSM_INTR_MASK_ADDR(smsm_entry, SMSM_APPS)); |
| 2530 | return 0; |
| 2531 | } |
| 2532 | EXPORT_SYMBOL(smsm_get_intr_mask); |
| 2533 | |
| 2534 | int smsm_change_state(uint32_t smsm_entry, |
| 2535 | uint32_t clear_mask, uint32_t set_mask) |
| 2536 | { |
| 2537 | unsigned long flags; |
| 2538 | uint32_t old_state, new_state; |
| 2539 | |
| 2540 | if (smsm_entry >= SMSM_NUM_ENTRIES) { |
| 2541 | pr_err("smsm_change_state: Invalid entry %d", |
| 2542 | smsm_entry); |
| 2543 | return -EINVAL; |
| 2544 | } |
| 2545 | |
| 2546 | if (!smsm_info.state) { |
| 2547 | pr_err("smsm_change_state <SM NO STATE>\n"); |
| 2548 | return -EIO; |
| 2549 | } |
| 2550 | spin_lock_irqsave(&smem_lock, flags); |
| 2551 | |
| 2552 | old_state = __raw_readl(SMSM_STATE_ADDR(smsm_entry)); |
| 2553 | new_state = (old_state & ~clear_mask) | set_mask; |
| 2554 | __raw_writel(new_state, SMSM_STATE_ADDR(smsm_entry)); |
| 2555 | SMSM_DBG("smsm_change_state %x\n", new_state); |
| 2556 | notify_other_smsm(SMSM_APPS_STATE, (old_state ^ new_state)); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2557 | |
| 2558 | spin_unlock_irqrestore(&smem_lock, flags); |
| 2559 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2560 | return 0; |
| 2561 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2562 | EXPORT_SYMBOL(smsm_change_state); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2563 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2564 | uint32_t smsm_get_state(uint32_t smsm_entry) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2565 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2566 | uint32_t rv = 0; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2567 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2568 | /* needs interface change to return error code */ |
| 2569 | if (smsm_entry >= SMSM_NUM_ENTRIES) { |
| 2570 | pr_err("smsm_change_state: Invalid entry %d", |
| 2571 | smsm_entry); |
| 2572 | return 0; |
| 2573 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2574 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2575 | if (!smsm_info.state) { |
| 2576 | pr_err("smsm_get_state <SM NO STATE>\n"); |
| 2577 | } else { |
| 2578 | rv = __raw_readl(SMSM_STATE_ADDR(smsm_entry)); |
| 2579 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2580 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2581 | return rv; |
| 2582 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2583 | EXPORT_SYMBOL(smsm_get_state); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2584 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2585 | /** |
| 2586 | * Performs SMSM callback client notifiction. |
| 2587 | */ |
| 2588 | void notify_smsm_cb_clients_worker(struct work_struct *work) |
Arve Hjønnevåg | ec9d3d1 | 2009-06-16 14:48:21 -0700 | [diff] [blame] | 2589 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2590 | struct smsm_state_cb_info *cb_info; |
| 2591 | struct smsm_state_info *state_info; |
| 2592 | int n; |
| 2593 | uint32_t new_state; |
| 2594 | uint32_t state_changes; |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 2595 | int ret; |
Eric Holmberg | 59a9f94 | 2012-03-19 10:04:22 -0600 | [diff] [blame^] | 2596 | unsigned long flags; |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 2597 | int snapshot_size = SMSM_NUM_ENTRIES * sizeof(uint32_t); |
Brian Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 2598 | |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 2599 | if (!smd_initialized) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2600 | return; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2601 | |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 2602 | while (kfifo_len(&smsm_snapshot_fifo) >= snapshot_size) { |
| 2603 | mutex_lock(&smsm_lock); |
| 2604 | for (n = 0; n < SMSM_NUM_ENTRIES; n++) { |
| 2605 | state_info = &smsm_states[n]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2606 | |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 2607 | ret = kfifo_out(&smsm_snapshot_fifo, &new_state, |
| 2608 | sizeof(new_state)); |
| 2609 | if (ret != sizeof(new_state)) { |
| 2610 | pr_err("%s: snapshot underflow %d\n", |
| 2611 | __func__, ret); |
| 2612 | mutex_unlock(&smsm_lock); |
| 2613 | return; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2614 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2615 | |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 2616 | state_changes = state_info->last_value ^ new_state; |
| 2617 | if (state_changes) { |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 2618 | SMx_POWER_INFO("SMSM Change %d: %08x->%08x\n", |
| 2619 | n, state_info->last_value, |
| 2620 | new_state); |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 2621 | list_for_each_entry(cb_info, |
| 2622 | &state_info->callbacks, cb_list) { |
| 2623 | |
| 2624 | if (cb_info->mask & state_changes) |
| 2625 | cb_info->notify(cb_info->data, |
| 2626 | state_info->last_value, |
| 2627 | new_state); |
| 2628 | } |
| 2629 | state_info->last_value = new_state; |
| 2630 | } |
| 2631 | } |
| 2632 | mutex_unlock(&smsm_lock); |
Eric Holmberg | 59a9f94 | 2012-03-19 10:04:22 -0600 | [diff] [blame^] | 2633 | |
| 2634 | spin_lock_irqsave(&smsm_snapshot_count_lock, flags); |
| 2635 | if (smsm_snapshot_count) { |
| 2636 | --smsm_snapshot_count; |
| 2637 | if (smsm_snapshot_count == 0) { |
| 2638 | SMx_POWER_INFO("SMSM snapshot wake unlock\n"); |
| 2639 | wake_unlock(&smsm_snapshot_wakelock); |
| 2640 | } |
| 2641 | } else { |
| 2642 | pr_err("%s: invalid snapshot count\n", __func__); |
| 2643 | } |
| 2644 | spin_unlock_irqrestore(&smsm_snapshot_count_lock, flags); |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 2645 | } |
Arve Hjønnevåg | ec9d3d1 | 2009-06-16 14:48:21 -0700 | [diff] [blame] | 2646 | } |
| 2647 | |
Arve Hjønnevåg | ec9d3d1 | 2009-06-16 14:48:21 -0700 | [diff] [blame] | 2648 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2649 | /** |
| 2650 | * Registers callback for SMSM state notifications when the specified |
| 2651 | * bits change. |
| 2652 | * |
| 2653 | * @smsm_entry Processor entry to deregister |
| 2654 | * @mask Bits to deregister (if result is 0, callback is removed) |
| 2655 | * @notify Notification function to deregister |
| 2656 | * @data Opaque data passed in to callback |
| 2657 | * |
| 2658 | * @returns Status code |
| 2659 | * <0 error code |
| 2660 | * 0 inserted new entry |
| 2661 | * 1 updated mask of existing entry |
| 2662 | */ |
| 2663 | int smsm_state_cb_register(uint32_t smsm_entry, uint32_t mask, |
| 2664 | void (*notify)(void *, uint32_t, uint32_t), void *data) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2665 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2666 | struct smsm_state_cb_info *cb_info; |
| 2667 | struct smsm_state_cb_info *cb_found = 0; |
| 2668 | int ret = 0; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2669 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2670 | if (smsm_entry >= SMSM_NUM_ENTRIES) |
| 2671 | return -EINVAL; |
| 2672 | |
Eric Holmberg | c800290 | 2011-09-16 13:55:57 -0600 | [diff] [blame] | 2673 | mutex_lock(&smsm_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2674 | |
| 2675 | if (!smsm_states) { |
| 2676 | /* smsm not yet initialized */ |
| 2677 | ret = -ENODEV; |
| 2678 | goto cleanup; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2679 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2680 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2681 | list_for_each_entry(cb_info, |
| 2682 | &smsm_states[smsm_entry].callbacks, cb_list) { |
| 2683 | if ((cb_info->notify == notify) && |
| 2684 | (cb_info->data == data)) { |
| 2685 | cb_info->mask |= mask; |
| 2686 | cb_found = cb_info; |
| 2687 | ret = 1; |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 2688 | break; |
| 2689 | } |
| 2690 | } |
| 2691 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2692 | if (!cb_found) { |
| 2693 | cb_info = kmalloc(sizeof(struct smsm_state_cb_info), |
| 2694 | GFP_ATOMIC); |
| 2695 | if (!cb_info) { |
| 2696 | ret = -ENOMEM; |
| 2697 | goto cleanup; |
| 2698 | } |
| 2699 | |
| 2700 | cb_info->mask = mask; |
| 2701 | cb_info->notify = notify; |
| 2702 | cb_info->data = data; |
| 2703 | INIT_LIST_HEAD(&cb_info->cb_list); |
| 2704 | list_add_tail(&cb_info->cb_list, |
| 2705 | &smsm_states[smsm_entry].callbacks); |
| 2706 | } |
| 2707 | |
| 2708 | cleanup: |
Eric Holmberg | c800290 | 2011-09-16 13:55:57 -0600 | [diff] [blame] | 2709 | mutex_unlock(&smsm_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2710 | return ret; |
| 2711 | } |
| 2712 | EXPORT_SYMBOL(smsm_state_cb_register); |
| 2713 | |
| 2714 | |
| 2715 | /** |
| 2716 | * Deregisters for SMSM state notifications for the specified bits. |
| 2717 | * |
| 2718 | * @smsm_entry Processor entry to deregister |
| 2719 | * @mask Bits to deregister (if result is 0, callback is removed) |
| 2720 | * @notify Notification function to deregister |
| 2721 | * @data Opaque data passed in to callback |
| 2722 | * |
| 2723 | * @returns Status code |
| 2724 | * <0 error code |
| 2725 | * 0 not found |
| 2726 | * 1 updated mask |
| 2727 | * 2 removed callback |
| 2728 | */ |
| 2729 | int smsm_state_cb_deregister(uint32_t smsm_entry, uint32_t mask, |
| 2730 | void (*notify)(void *, uint32_t, uint32_t), void *data) |
| 2731 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2732 | struct smsm_state_cb_info *cb_info; |
| 2733 | int ret = 0; |
| 2734 | |
| 2735 | if (smsm_entry >= SMSM_NUM_ENTRIES) |
| 2736 | return -EINVAL; |
| 2737 | |
Eric Holmberg | c800290 | 2011-09-16 13:55:57 -0600 | [diff] [blame] | 2738 | mutex_lock(&smsm_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2739 | |
| 2740 | if (!smsm_states) { |
| 2741 | /* smsm not yet initialized */ |
Eric Holmberg | c800290 | 2011-09-16 13:55:57 -0600 | [diff] [blame] | 2742 | mutex_unlock(&smsm_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2743 | return -ENODEV; |
| 2744 | } |
| 2745 | |
| 2746 | list_for_each_entry(cb_info, |
| 2747 | &smsm_states[smsm_entry].callbacks, cb_list) { |
| 2748 | if ((cb_info->notify == notify) && |
| 2749 | (cb_info->data == data)) { |
| 2750 | cb_info->mask &= ~mask; |
| 2751 | ret = 1; |
| 2752 | if (!cb_info->mask) { |
| 2753 | /* no mask bits set, remove callback */ |
| 2754 | list_del(&cb_info->cb_list); |
| 2755 | kfree(cb_info); |
| 2756 | ret = 2; |
| 2757 | } |
| 2758 | break; |
| 2759 | } |
| 2760 | } |
| 2761 | |
Eric Holmberg | c800290 | 2011-09-16 13:55:57 -0600 | [diff] [blame] | 2762 | mutex_unlock(&smsm_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2763 | return ret; |
| 2764 | } |
| 2765 | EXPORT_SYMBOL(smsm_state_cb_deregister); |
| 2766 | |
| 2767 | |
| 2768 | int smd_core_init(void) |
| 2769 | { |
| 2770 | int r; |
| 2771 | unsigned long flags = IRQF_TRIGGER_RISING; |
| 2772 | SMD_INFO("smd_core_init()\n"); |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 2773 | |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 2774 | r = request_irq(INT_A9_M2A_0, smd_modem_irq_handler, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2775 | flags, "smd_dev", 0); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2776 | if (r < 0) |
| 2777 | return r; |
| 2778 | r = enable_irq_wake(INT_A9_M2A_0); |
| 2779 | if (r < 0) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2780 | pr_err("smd_core_init: " |
| 2781 | "enable_irq_wake failed for INT_A9_M2A_0\n"); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2782 | |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 2783 | r = request_irq(INT_A9_M2A_5, smsm_modem_irq_handler, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2784 | flags, "smsm_dev", 0); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2785 | if (r < 0) { |
| 2786 | free_irq(INT_A9_M2A_0, 0); |
| 2787 | return r; |
| 2788 | } |
| 2789 | r = enable_irq_wake(INT_A9_M2A_5); |
| 2790 | if (r < 0) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2791 | pr_err("smd_core_init: " |
| 2792 | "enable_irq_wake failed for INT_A9_M2A_5\n"); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2793 | |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 2794 | #if defined(CONFIG_QDSP6) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2795 | #if (INT_ADSP_A11 == INT_ADSP_A11_SMSM) |
| 2796 | flags |= IRQF_SHARED; |
| 2797 | #endif |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 2798 | r = request_irq(INT_ADSP_A11, smd_dsp_irq_handler, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2799 | flags, "smd_dev", smd_dsp_irq_handler); |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 2800 | if (r < 0) { |
| 2801 | free_irq(INT_A9_M2A_0, 0); |
| 2802 | free_irq(INT_A9_M2A_5, 0); |
| 2803 | return r; |
| 2804 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2805 | |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 2806 | r = request_irq(INT_ADSP_A11_SMSM, smsm_dsp_irq_handler, |
| 2807 | flags, "smsm_dev", smsm_dsp_irq_handler); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2808 | if (r < 0) { |
| 2809 | free_irq(INT_A9_M2A_0, 0); |
| 2810 | free_irq(INT_A9_M2A_5, 0); |
| 2811 | free_irq(INT_ADSP_A11, smd_dsp_irq_handler); |
| 2812 | return r; |
| 2813 | } |
| 2814 | |
| 2815 | r = enable_irq_wake(INT_ADSP_A11); |
| 2816 | if (r < 0) |
| 2817 | pr_err("smd_core_init: " |
| 2818 | "enable_irq_wake failed for INT_ADSP_A11\n"); |
| 2819 | |
| 2820 | #if (INT_ADSP_A11 != INT_ADSP_A11_SMSM) |
| 2821 | r = enable_irq_wake(INT_ADSP_A11_SMSM); |
| 2822 | if (r < 0) |
| 2823 | pr_err("smd_core_init: enable_irq_wake " |
| 2824 | "failed for INT_ADSP_A11_SMSM\n"); |
| 2825 | #endif |
| 2826 | flags &= ~IRQF_SHARED; |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 2827 | #endif |
| 2828 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2829 | #if defined(CONFIG_DSPS) |
| 2830 | r = request_irq(INT_DSPS_A11, smd_dsps_irq_handler, |
| 2831 | flags, "smd_dev", smd_dsps_irq_handler); |
| 2832 | if (r < 0) { |
| 2833 | free_irq(INT_A9_M2A_0, 0); |
| 2834 | free_irq(INT_A9_M2A_5, 0); |
| 2835 | free_irq(INT_ADSP_A11, smd_dsp_irq_handler); |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 2836 | free_irq(INT_ADSP_A11_SMSM, smsm_dsp_irq_handler); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2837 | return r; |
| 2838 | } |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 2839 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2840 | r = enable_irq_wake(INT_DSPS_A11); |
| 2841 | if (r < 0) |
| 2842 | pr_err("smd_core_init: " |
| 2843 | "enable_irq_wake failed for INT_ADSP_A11\n"); |
Arve Hjønnevåg | ec9d3d1 | 2009-06-16 14:48:21 -0700 | [diff] [blame] | 2844 | #endif |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2845 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2846 | #if defined(CONFIG_WCNSS) |
| 2847 | r = request_irq(INT_WCNSS_A11, smd_wcnss_irq_handler, |
| 2848 | flags, "smd_dev", smd_wcnss_irq_handler); |
| 2849 | if (r < 0) { |
| 2850 | free_irq(INT_A9_M2A_0, 0); |
| 2851 | free_irq(INT_A9_M2A_5, 0); |
| 2852 | free_irq(INT_ADSP_A11, smd_dsp_irq_handler); |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 2853 | free_irq(INT_ADSP_A11_SMSM, smsm_dsp_irq_handler); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2854 | free_irq(INT_DSPS_A11, smd_dsps_irq_handler); |
| 2855 | return r; |
| 2856 | } |
| 2857 | |
| 2858 | r = enable_irq_wake(INT_WCNSS_A11); |
| 2859 | if (r < 0) |
| 2860 | pr_err("smd_core_init: " |
| 2861 | "enable_irq_wake failed for INT_WCNSS_A11\n"); |
| 2862 | |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 2863 | r = request_irq(INT_WCNSS_A11_SMSM, smsm_wcnss_irq_handler, |
| 2864 | flags, "smsm_dev", smsm_wcnss_irq_handler); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2865 | if (r < 0) { |
| 2866 | free_irq(INT_A9_M2A_0, 0); |
| 2867 | free_irq(INT_A9_M2A_5, 0); |
| 2868 | free_irq(INT_ADSP_A11, smd_dsp_irq_handler); |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 2869 | free_irq(INT_ADSP_A11_SMSM, smsm_dsp_irq_handler); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2870 | free_irq(INT_DSPS_A11, smd_dsps_irq_handler); |
| 2871 | free_irq(INT_WCNSS_A11, smd_wcnss_irq_handler); |
| 2872 | return r; |
| 2873 | } |
| 2874 | |
| 2875 | r = enable_irq_wake(INT_WCNSS_A11_SMSM); |
| 2876 | if (r < 0) |
| 2877 | pr_err("smd_core_init: " |
| 2878 | "enable_irq_wake failed for INT_WCNSS_A11_SMSM\n"); |
| 2879 | #endif |
| 2880 | |
Jeff Hugo | 6a8057c | 2011-08-16 13:47:12 -0600 | [diff] [blame] | 2881 | #if defined(CONFIG_DSPS_SMSM) |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 2882 | r = request_irq(INT_DSPS_A11_SMSM, smsm_dsps_irq_handler, |
| 2883 | flags, "smsm_dev", smsm_dsps_irq_handler); |
Jeff Hugo | 6a8057c | 2011-08-16 13:47:12 -0600 | [diff] [blame] | 2884 | if (r < 0) { |
| 2885 | free_irq(INT_A9_M2A_0, 0); |
| 2886 | free_irq(INT_A9_M2A_5, 0); |
| 2887 | free_irq(INT_ADSP_A11, smd_dsp_irq_handler); |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 2888 | free_irq(INT_ADSP_A11_SMSM, smsm_dsp_irq_handler); |
Jeff Hugo | 6a8057c | 2011-08-16 13:47:12 -0600 | [diff] [blame] | 2889 | free_irq(INT_DSPS_A11, smd_dsps_irq_handler); |
| 2890 | free_irq(INT_WCNSS_A11, smd_wcnss_irq_handler); |
Eric Holmberg | 98c6c64 | 2012-02-24 11:29:35 -0700 | [diff] [blame] | 2891 | free_irq(INT_WCNSS_A11_SMSM, smsm_wcnss_irq_handler); |
Jeff Hugo | 6a8057c | 2011-08-16 13:47:12 -0600 | [diff] [blame] | 2892 | return r; |
| 2893 | } |
| 2894 | |
| 2895 | r = enable_irq_wake(INT_DSPS_A11_SMSM); |
| 2896 | if (r < 0) |
| 2897 | pr_err("smd_core_init: " |
| 2898 | "enable_irq_wake failed for INT_DSPS_A11_SMSM\n"); |
| 2899 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2900 | SMD_INFO("smd_core_init() done\n"); |
| 2901 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2902 | return 0; |
| 2903 | } |
| 2904 | |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 2905 | static int intr_init(struct interrupt_config_item *private_irq, |
| 2906 | struct smd_irq_config *platform_irq, |
| 2907 | struct platform_device *pdev |
| 2908 | ) |
| 2909 | { |
| 2910 | int irq_id; |
| 2911 | int ret; |
| 2912 | int ret_wake; |
| 2913 | |
| 2914 | private_irq->out_bit_pos = platform_irq->out_bit_pos; |
| 2915 | private_irq->out_offset = platform_irq->out_offset; |
| 2916 | private_irq->out_base = platform_irq->out_base; |
| 2917 | |
| 2918 | irq_id = platform_get_irq_byname( |
| 2919 | pdev, |
| 2920 | platform_irq->irq_name |
| 2921 | ); |
| 2922 | SMD_DBG("smd: %s: register irq: %s id: %d\n", __func__, |
| 2923 | platform_irq->irq_name, irq_id); |
| 2924 | ret = request_irq(irq_id, |
| 2925 | private_irq->irq_handler, |
| 2926 | platform_irq->flags, |
| 2927 | platform_irq->device_name, |
| 2928 | (void *)platform_irq->dev_id |
| 2929 | ); |
| 2930 | if (ret < 0) { |
| 2931 | platform_irq->irq_id = ret; |
| 2932 | } else { |
| 2933 | platform_irq->irq_id = irq_id; |
| 2934 | ret_wake = enable_irq_wake(irq_id); |
| 2935 | if (ret_wake < 0) { |
| 2936 | pr_err("smd: enable_irq_wake failed on %s", |
| 2937 | platform_irq->irq_name); |
| 2938 | } |
| 2939 | } |
| 2940 | |
| 2941 | return ret; |
| 2942 | } |
| 2943 | |
| 2944 | int smd_core_platform_init(struct platform_device *pdev) |
| 2945 | { |
| 2946 | int i; |
| 2947 | int ret; |
| 2948 | uint32_t num_ss; |
| 2949 | struct smd_platform *smd_platform_data; |
| 2950 | struct smd_subsystem_config *smd_ss_config_list; |
| 2951 | struct smd_subsystem_config *cfg; |
| 2952 | int err_ret = 0; |
| 2953 | |
| 2954 | smd_platform_data = pdev->dev.platform_data; |
| 2955 | num_ss = smd_platform_data->num_ss_configs; |
| 2956 | smd_ss_config_list = smd_platform_data->smd_ss_configs; |
| 2957 | |
Eric Holmberg | 2bb6ccd | 2012-03-13 13:05:14 -0600 | [diff] [blame] | 2958 | if (smd_platform_data->smd_ssr_config) |
| 2959 | disable_smsm_reset_handshake = smd_platform_data-> |
| 2960 | smd_ssr_config->disable_smsm_reset_handshake; |
| 2961 | |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 2962 | for (i = 0; i < num_ss; i++) { |
| 2963 | cfg = &smd_ss_config_list[i]; |
| 2964 | |
| 2965 | ret = intr_init( |
| 2966 | &private_intr_config[cfg->irq_config_id].smd, |
| 2967 | &cfg->smd_int, |
| 2968 | pdev |
| 2969 | ); |
| 2970 | |
| 2971 | if (ret < 0) { |
| 2972 | err_ret = ret; |
| 2973 | pr_err("smd: register irq failed on %s\n", |
| 2974 | cfg->smd_int.irq_name); |
| 2975 | break; |
| 2976 | } |
| 2977 | |
| 2978 | ret = intr_init( |
| 2979 | &private_intr_config[cfg->irq_config_id].smsm, |
| 2980 | &cfg->smsm_int, |
| 2981 | pdev |
| 2982 | ); |
| 2983 | |
| 2984 | if (ret < 0) { |
| 2985 | err_ret = ret; |
| 2986 | pr_err("smd: register irq failed on %s\n", |
| 2987 | cfg->smsm_int.irq_name); |
| 2988 | break; |
| 2989 | } |
Eric Holmberg | 17992c1 | 2012-02-29 12:54:44 -0700 | [diff] [blame] | 2990 | |
| 2991 | strncpy(edge_to_pids[cfg->edge].subsys_name, |
| 2992 | cfg->subsys_name, SMD_MAX_CH_NAME_LEN); |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 2993 | } |
| 2994 | |
| 2995 | if (err_ret < 0) { |
| 2996 | pr_err("smd: deregistering IRQs\n"); |
| 2997 | for (i = 0; i < num_ss; ++i) { |
| 2998 | cfg = &smd_ss_config_list[i]; |
| 2999 | |
| 3000 | if (cfg->smd_int.irq_id >= 0) |
| 3001 | free_irq(cfg->smd_int.irq_id, |
| 3002 | (void *)cfg->smd_int.dev_id |
| 3003 | ); |
| 3004 | if (cfg->smsm_int.irq_id >= 0) |
| 3005 | free_irq(cfg->smsm_int.irq_id, |
| 3006 | (void *)cfg->smsm_int.dev_id |
| 3007 | ); |
| 3008 | } |
| 3009 | return err_ret; |
| 3010 | } |
| 3011 | |
| 3012 | SMD_INFO("smd_core_platform_init() done\n"); |
| 3013 | return 0; |
| 3014 | |
| 3015 | } |
| 3016 | |
Gregory Bean | 4416e9e | 2010-07-28 10:22:12 -0700 | [diff] [blame] | 3017 | static int __devinit msm_smd_probe(struct platform_device *pdev) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 3018 | { |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 3019 | int ret; |
Daniel Walker | 0aec66d | 2010-03-18 12:31:08 -0700 | [diff] [blame] | 3020 | |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 3021 | SMD_INFO("smd probe\n"); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 3022 | INIT_WORK(&probe_work, smd_channel_probe_worker); |
| 3023 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3024 | channel_close_wq = create_singlethread_workqueue("smd_channel_close"); |
| 3025 | if (IS_ERR(channel_close_wq)) { |
| 3026 | pr_err("%s: create_singlethread_workqueue ENOMEM\n", __func__); |
| 3027 | return -ENOMEM; |
| 3028 | } |
| 3029 | |
| 3030 | if (smsm_init()) { |
| 3031 | pr_err("smsm_init() failed\n"); |
| 3032 | return -1; |
| 3033 | } |
| 3034 | |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 3035 | if (pdev) { |
| 3036 | if (pdev->dev.of_node) { |
| 3037 | pr_err("SMD: Device tree not currently supported\n"); |
| 3038 | return -ENODEV; |
| 3039 | } else if (pdev->dev.platform_data) { |
| 3040 | ret = smd_core_platform_init(pdev); |
| 3041 | if (ret) { |
| 3042 | pr_err( |
| 3043 | "SMD: smd_core_platform_init() failed\n"); |
| 3044 | return -ENODEV; |
| 3045 | } |
| 3046 | } else { |
| 3047 | ret = smd_core_init(); |
| 3048 | if (ret) { |
| 3049 | pr_err("smd_core_init() failed\n"); |
| 3050 | return -ENODEV; |
| 3051 | } |
| 3052 | } |
| 3053 | } else { |
| 3054 | pr_err("SMD: PDEV not found\n"); |
| 3055 | return -ENODEV; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 3056 | } |
| 3057 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 3058 | smd_initialized = 1; |
| 3059 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3060 | smd_alloc_loopback_channel(); |
Eric Holmberg | c33d4ab | 2011-10-24 10:28:25 -0600 | [diff] [blame] | 3061 | smsm_irq_handler(0, 0); |
| 3062 | tasklet_schedule(&smd_fake_irq_tasklet); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3063 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 3064 | return 0; |
| 3065 | } |
| 3066 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3067 | static int restart_notifier_cb(struct notifier_block *this, |
| 3068 | unsigned long code, |
| 3069 | void *data); |
| 3070 | |
| 3071 | static struct restart_notifier_block restart_notifiers[] = { |
Eric Holmberg | ca7ead2 | 2011-12-01 17:21:15 -0700 | [diff] [blame] | 3072 | {SMD_MODEM, "modem", .nb.notifier_call = restart_notifier_cb}, |
| 3073 | {SMD_Q6, "lpass", .nb.notifier_call = restart_notifier_cb}, |
| 3074 | {SMD_WCNSS, "riva", .nb.notifier_call = restart_notifier_cb}, |
| 3075 | {SMD_DSPS, "dsps", .nb.notifier_call = restart_notifier_cb}, |
Eric Holmberg | 8b0e74f | 2012-02-08 09:56:17 -0700 | [diff] [blame] | 3076 | {SMD_MODEM, "gss", .nb.notifier_call = restart_notifier_cb}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3077 | }; |
| 3078 | |
| 3079 | static int restart_notifier_cb(struct notifier_block *this, |
| 3080 | unsigned long code, |
| 3081 | void *data) |
| 3082 | { |
| 3083 | if (code == SUBSYS_AFTER_SHUTDOWN) { |
| 3084 | struct restart_notifier_block *notifier; |
| 3085 | |
| 3086 | notifier = container_of(this, |
| 3087 | struct restart_notifier_block, nb); |
| 3088 | SMD_INFO("%s: ssrestart for processor %d ('%s')\n", |
| 3089 | __func__, notifier->processor, |
| 3090 | notifier->name); |
| 3091 | |
| 3092 | smd_channel_reset(notifier->processor); |
| 3093 | } |
| 3094 | |
| 3095 | return NOTIFY_DONE; |
| 3096 | } |
| 3097 | |
| 3098 | static __init int modem_restart_late_init(void) |
| 3099 | { |
| 3100 | int i; |
| 3101 | void *handle; |
| 3102 | struct restart_notifier_block *nb; |
| 3103 | |
| 3104 | for (i = 0; i < ARRAY_SIZE(restart_notifiers); i++) { |
| 3105 | nb = &restart_notifiers[i]; |
| 3106 | handle = subsys_notif_register_notifier(nb->name, &nb->nb); |
| 3107 | SMD_DBG("%s: registering notif for '%s', handle=%p\n", |
| 3108 | __func__, nb->name, handle); |
| 3109 | } |
| 3110 | return 0; |
| 3111 | } |
| 3112 | late_initcall(modem_restart_late_init); |
| 3113 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 3114 | static struct platform_driver msm_smd_driver = { |
| 3115 | .probe = msm_smd_probe, |
| 3116 | .driver = { |
| 3117 | .name = MODULE_NAME, |
| 3118 | .owner = THIS_MODULE, |
| 3119 | }, |
| 3120 | }; |
| 3121 | |
| 3122 | static int __init msm_smd_init(void) |
| 3123 | { |
| 3124 | return platform_driver_register(&msm_smd_driver); |
| 3125 | } |
| 3126 | |
| 3127 | module_init(msm_smd_init); |
| 3128 | |
| 3129 | MODULE_DESCRIPTION("MSM Shared Memory Core"); |
| 3130 | MODULE_AUTHOR("Brian Swetland <swetland@google.com>"); |
| 3131 | MODULE_LICENSE("GPL"); |