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