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