blob: 4664197969527b356142e95004691b4ac4f69907 [file] [log] [blame]
Brian Swetland2eb44eb2008-09-29 16:00:48 -07001/* arch/arm/mach-msm/smd_private.h
2 *
3 * Copyright (C) 2007 Google, Inc.
Eric Holmberg6275b602012-11-19 13:05:04 -07004 * Copyright (c) 2007-2013, The Linux Foundation. All rights reserved.
Brian Swetland2eb44eb2008-09-29 16:00:48 -07005 *
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16#ifndef _ARCH_ARM_MACH_MSM_MSM_SMD_PRIVATE_H_
17#define _ARCH_ARM_MACH_MSM_MSM_SMD_PRIVATE_H_
18
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070019#include <linux/types.h>
Brian Swetland03e00cd2009-07-01 17:58:37 -070020#include <linux/spinlock.h>
Eric Holmberg6275b602012-11-19 13:05:04 -070021#include <linux/errno.h>
22#include <linux/remote_spinlock.h>
Arun Kumar Neelakantam7cffb332013-01-28 15:43:35 +053023#include <linux/platform_device.h>
Arun Kumar Neelakantam804f5162013-07-25 17:58:05 +053024#include <linux/interrupt.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070025#include <mach/msm_smsm.h>
Eric Holmberg7ad623a2012-03-01 14:41:10 -070026#include <mach/msm_smd.h>
Daniel Walker74df1d02010-03-17 10:51:10 -070027
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070028#define PC_APPS 0
29#define PC_MODEM 1
30
31#define VERSION_QDSP6 4
32#define VERSION_APPS_SBL 6
33#define VERSION_MODEM_SBL 7
34#define VERSION_APPS 8
35#define VERSION_MODEM 9
36#define VERSION_DSPS 10
37
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070038#if defined(CONFIG_MSM_SMD_PKG4)
Daniel Walker79848a22010-03-16 15:20:07 -070039struct smsm_interrupt_info {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070040 uint32_t aArm_en_mask;
41 uint32_t aArm_interrupts_pending;
42 uint32_t aArm_wakeup_reason;
43 uint32_t aArm_rpc_prog;
44 uint32_t aArm_rpc_proc;
45 char aArm_smd_port_name[20];
46 uint32_t aArm_gpio_info;
Brian Swetland2eb44eb2008-09-29 16:00:48 -070047};
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070048#elif defined(CONFIG_MSM_SMD_PKG3)
49struct smsm_interrupt_info {
50 uint32_t aArm_en_mask;
51 uint32_t aArm_interrupts_pending;
52 uint32_t aArm_wakeup_reason;
53};
54#elif !defined(CONFIG_MSM_SMD)
Steve Mucklef132c6c2012-06-06 18:30:57 -070055/* Don't trigger the error */
Arve Hjønnevågec9d3d12009-06-16 14:48:21 -070056#else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070057#error No SMD Package Specified; aborting
Arve Hjønnevågec9d3d12009-06-16 14:48:21 -070058#endif
Brian Swetland2eb44eb2008-09-29 16:00:48 -070059
60#define SZ_DIAG_ERR_MSG 0xC8
61#define ID_DIAG_ERR_MSG SMEM_DIAG_ERR_MESSAGE
62#define ID_SMD_CHANNELS SMEM_SMD_BASE_ID
63#define ID_SHARED_STATE SMEM_SMSM_SHARED_STATE
64#define ID_CH_ALLOC_TBL SMEM_CHANNEL_ALLOC_TBL
65
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070066#define SMD_SS_CLOSED 0x00000000
67#define SMD_SS_OPENING 0x00000001
68#define SMD_SS_OPENED 0x00000002
69#define SMD_SS_FLUSHING 0x00000003
70#define SMD_SS_CLOSING 0x00000004
71#define SMD_SS_RESET 0x00000005
72#define SMD_SS_RESET_OPENING 0x00000006
Brian Swetland2eb44eb2008-09-29 16:00:48 -070073
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070074#define SMD_BUF_SIZE 8192
75#define SMD_CHANNELS 64
76#define SMD_HEADER_SIZE 20
Brian Swetland2eb44eb2008-09-29 16:00:48 -070077
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070078/* 'type' field of smd_alloc_elm structure
79 * has the following breakup
80 * bits 0-7 -> channel type
81 * bits 8-11 -> xfer type
82 * bits 12-31 -> reserved
83 */
Brian Swetland03e00cd2009-07-01 17:58:37 -070084struct smd_alloc_elm {
85 char name[20];
86 uint32_t cid;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070087 uint32_t type;
Brian Swetland03e00cd2009-07-01 17:58:37 -070088 uint32_t ref_count;
89};
90
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070091#define SMD_CHANNEL_TYPE(x) ((x) & 0x000000FF)
92#define SMD_XFER_TYPE(x) (((x) & 0x00000F00) >> 8)
93
Brian Swetland03e00cd2009-07-01 17:58:37 -070094struct smd_half_channel {
95 unsigned state;
96 unsigned char fDSR;
97 unsigned char fCTS;
98 unsigned char fCD;
99 unsigned char fRI;
100 unsigned char fHEAD;
101 unsigned char fTAIL;
102 unsigned char fSTATE;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700103 unsigned char fBLOCKREADINTR;
Brian Swetland03e00cd2009-07-01 17:58:37 -0700104 unsigned tail;
105 unsigned head;
Brian Swetland03e00cd2009-07-01 17:58:37 -0700106};
107
Jeff Hugo918b2dc2012-03-21 13:42:09 -0600108struct smd_half_channel_word_access {
109 unsigned state;
110 unsigned fDSR;
111 unsigned fCTS;
112 unsigned fCD;
113 unsigned fRI;
114 unsigned fHEAD;
115 unsigned fTAIL;
116 unsigned fSTATE;
117 unsigned fBLOCKREADINTR;
118 unsigned tail;
119 unsigned head;
Daniel Walker79848a22010-03-16 15:20:07 -0700120};
Brian Swetland03e00cd2009-07-01 17:58:37 -0700121
Jeff Hugo918b2dc2012-03-21 13:42:09 -0600122struct smd_half_channel_access {
Arun Kumar Neelakantam604e7312012-12-10 14:14:19 +0530123 void (*set_state)(volatile void __iomem *half_channel, unsigned data);
124 unsigned (*get_state)(volatile void __iomem *half_channel);
125 void (*set_fDSR)(volatile void __iomem *half_channel,
Jeff Hugo918b2dc2012-03-21 13:42:09 -0600126 unsigned char data);
Arun Kumar Neelakantam604e7312012-12-10 14:14:19 +0530127 unsigned (*get_fDSR)(volatile void __iomem *half_channel);
128 void (*set_fCTS)(volatile void __iomem *half_channel,
129 unsigned char data);
130 unsigned (*get_fCTS)(volatile void __iomem *half_channel);
131 void (*set_fCD)(volatile void __iomem *half_channel,
132 unsigned char data);
133 unsigned (*get_fCD)(volatile void __iomem *half_channel);
134 void (*set_fRI)(volatile void __iomem *half_channel,
135 unsigned char data);
136 unsigned (*get_fRI)(volatile void __iomem *half_channel);
137 void (*set_fHEAD)(volatile void __iomem *half_channel,
138 unsigned char data);
139 unsigned (*get_fHEAD)(volatile void __iomem *half_channel);
140 void (*set_fTAIL)(volatile void __iomem *half_channel,
141 unsigned char data);
142 unsigned (*get_fTAIL)(volatile void __iomem *half_channel);
143 void (*set_fSTATE)(volatile void __iomem *half_channel,
144 unsigned char data);
145 unsigned (*get_fSTATE)(volatile void __iomem *half_channel);
146 void (*set_fBLOCKREADINTR)(volatile void __iomem *half_channel,
147 unsigned char data);
148 unsigned (*get_fBLOCKREADINTR)(volatile void __iomem *half_channel);
149 void (*set_tail)(volatile void __iomem *half_channel, unsigned data);
150 unsigned (*get_tail)(volatile void __iomem *half_channel);
151 void (*set_head)(volatile void __iomem *half_channel, unsigned data);
152 unsigned (*get_head)(volatile void __iomem *half_channel);
Jeff Hugo918b2dc2012-03-21 13:42:09 -0600153};
Brian Swetland03e00cd2009-07-01 17:58:37 -0700154
Jeff Hugo918b2dc2012-03-21 13:42:09 -0600155int is_word_access_ch(unsigned ch_type);
Brian Swetland03e00cd2009-07-01 17:58:37 -0700156
Jeff Hugo918b2dc2012-03-21 13:42:09 -0600157struct smd_half_channel_access *get_half_ch_funcs(unsigned ch_type);
Brian Swetland03e00cd2009-07-01 17:58:37 -0700158
Arun Kumar Neelakantam7cffb332013-01-28 15:43:35 +0530159struct smd_channel {
160 volatile void __iomem *send; /* some variant of smd_half_channel */
161 volatile void __iomem *recv; /* some variant of smd_half_channel */
162 unsigned char *send_data;
163 unsigned char *recv_data;
164 unsigned fifo_size;
165 unsigned fifo_mask;
166 struct list_head ch_list;
167
168 unsigned current_packet;
169 unsigned n;
170 void *priv;
171 void (*notify)(void *priv, unsigned flags);
172
173 int (*read)(smd_channel_t *ch, void *data, int len, int user_buf);
174 int (*write)(smd_channel_t *ch, const void *data, int len,
175 int user_buf);
176 int (*read_avail)(smd_channel_t *ch);
177 int (*write_avail)(smd_channel_t *ch);
178 int (*read_from_cb)(smd_channel_t *ch, void *data, int len,
179 int user_buf);
180
181 void (*update_state)(smd_channel_t *ch);
182 unsigned last_state;
183 void (*notify_other_cpu)(smd_channel_t *ch);
184
185 char name[20];
186 struct platform_device pdev;
187 unsigned type;
188
189 int pending_pkt_sz;
190
191 char is_pkt_ch;
192
193 /*
194 * private internal functions to access *send and *recv.
195 * never to be exported outside of smd
196 */
197 struct smd_half_channel_access *half_ch;
198};
Naveen Ramaraj76483ad2011-09-06 14:25:44 -0700199
Brian Swetland03e00cd2009-07-01 17:58:37 -0700200extern spinlock_t smem_lock;
201
Brian Swetland03e00cd2009-07-01 17:58:37 -0700202
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700203void smd_diag(void);
Daniel Walker79848a22010-03-16 15:20:07 -0700204
Eric Holmberg7ad623a2012-03-01 14:41:10 -0700205struct interrupt_stat {
206 uint32_t smd_in_count;
207 uint32_t smd_out_hardcode_count;
208 uint32_t smd_out_config_count;
Arun Kumar Neelakantamac7c02d2012-10-16 22:17:55 +0530209 uint32_t smd_interrupt_id;
Daniel Walkerbf83de42010-03-16 16:29:44 -0700210
Eric Holmberg7ad623a2012-03-01 14:41:10 -0700211 uint32_t smsm_in_count;
212 uint32_t smsm_out_hardcode_count;
213 uint32_t smsm_out_config_count;
Arun Kumar Neelakantamac7c02d2012-10-16 22:17:55 +0530214 uint32_t smsm_interrupt_id;
Eric Holmberg7ad623a2012-03-01 14:41:10 -0700215};
216extern struct interrupt_stat interrupt_stats[NUM_SMD_SUBSYSTEMS];
Arun Kumar Neelakantam804f5162013-07-25 17:58:05 +0530217
218struct interrupt_config_item {
219 /* must be initialized */
220 irqreturn_t (*irq_handler)(int req, void *data);
221 /* outgoing interrupt config (set from platform data) */
222 uint32_t out_bit_pos;
223 void __iomem *out_base;
224 uint32_t out_offset;
225 int irq_id;
226};
227
228enum {
229 MSM_SMD_DEBUG = 1U << 0,
230 MSM_SMSM_DEBUG = 1U << 1,
231 MSM_SMD_INFO = 1U << 2,
232 MSM_SMSM_INFO = 1U << 3,
233 MSM_SMx_POWER_INFO = 1U << 4,
234};
235
236struct interrupt_config {
237 struct interrupt_config_item smd;
238 struct interrupt_config_item smsm;
239};
240
241struct edge_to_pid {
242 uint32_t local_pid;
243 uint32_t remote_pid;
244 char subsys_name[SMD_MAX_CH_NAME_LEN];
245 bool initialized;
246};
247
248extern void *smd_log_ctx;
249extern int msm_smd_debug_mask;
250extern int disable_smsm_reset_handshake;
251extern bool smem_initialized_check(void);
252
253extern irqreturn_t smd_modem_irq_handler(int irq, void *data);
254extern irqreturn_t smsm_modem_irq_handler(int irq, void *data);
255extern irqreturn_t smd_dsp_irq_handler(int irq, void *data);
256extern irqreturn_t smsm_dsp_irq_handler(int irq, void *data);
257extern irqreturn_t smd_dsps_irq_handler(int irq, void *data);
258extern irqreturn_t smsm_dsps_irq_handler(int irq, void *data);
259extern irqreturn_t smd_wcnss_irq_handler(int irq, void *data);
260extern irqreturn_t smsm_wcnss_irq_handler(int irq, void *data);
261extern irqreturn_t smd_rpm_irq_handler(int irq, void *data);
262
263extern int msm_smd_driver_register(void);
264extern void smd_post_init(bool is_legacy);
265extern int smsm_post_init(void);
266
267extern struct interrupt_config *smd_get_intr_config(uint32_t edge);
268extern int smd_edge_to_remote_pid(uint32_t edge);
269extern void smd_set_edge_subsys_name(uint32_t edge, const char *subsys_name);
270extern void smd_set_edge_initialized(uint32_t edge);
271extern void smd_cfg_smd_intr(uint32_t proc, uint32_t mask, void *ptr);
272extern void smd_cfg_smsm_intr(uint32_t proc, uint32_t mask, void *ptr);
Brian Swetland2eb44eb2008-09-29 16:00:48 -0700273#endif