blob: ee0f6255fa07413930cd9a572d7b5fd62e8717ba [file] [log] [blame]
Sagar Dhariabe37c9c2016-11-28 23:06:58 -07001/* Copyright (c) 2011-2016, The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#ifndef _SLIM_MSM_H
14#define _SLIM_MSM_H
15
16#include <linux/irq.h>
17#include <linux/kthread.h>
18#include <soc/qcom/msm_qmi_interface.h>
19#include <linux/ipc_logging.h>
20
21/* Per spec.max 40 bytes per received message */
22#define SLIM_MSGQ_BUF_LEN 40
23
24#define MSM_TX_BUFS 32
25
26#define SLIM_USR_MC_GENERIC_ACK 0x25
27#define SLIM_USR_MC_MASTER_CAPABILITY 0x0
28#define SLIM_USR_MC_REPORT_SATELLITE 0x1
29#define SLIM_USR_MC_ADDR_QUERY 0xD
30#define SLIM_USR_MC_ADDR_REPLY 0xE
31#define SLIM_USR_MC_DEFINE_CHAN 0x20
32#define SLIM_USR_MC_DEF_ACT_CHAN 0x21
33#define SLIM_USR_MC_CHAN_CTRL 0x23
34#define SLIM_USR_MC_RECONFIG_NOW 0x24
35#define SLIM_USR_MC_REQ_BW 0x28
36#define SLIM_USR_MC_CONNECT_SRC 0x2C
37#define SLIM_USR_MC_CONNECT_SINK 0x2D
38#define SLIM_USR_MC_DISCONNECT_PORT 0x2E
39
40#define SLIM_USR_MC_REPEAT_CHANGE_VALUE 0x0
41#define MSM_SLIM_VE_MAX_MAP_ADDR 0xFFF
42#define SLIM_MAX_VE_SLC_BYTES 16
43
44#define MSM_SLIM_AUTOSUSPEND MSEC_PER_SEC
45
46#define SLIM_RX_MSGQ_TIMEOUT_VAL 0x10000
47/*
48 * Messages that can be received simultaneously:
49 * Client reads, LPASS master responses, announcement messages
50 * Receive upto 10 messages simultaneously.
51 */
52#define MSM_SLIM_DESC_NUM 32
53
54/* MSM Slimbus peripheral settings */
55#define MSM_SLIM_PERF_SUMM_THRESHOLD 0x8000
56#define MSM_SLIM_NPORTS 24
57#define MSM_SLIM_NCHANS 32
58
59#define QC_MFGID_LSB 0x2
60#define QC_MFGID_MSB 0x17
61#define QC_CHIPID_SL 0x10
62#define QC_DEVID_SAT1 0x3
63#define QC_DEVID_SAT2 0x4
64#define QC_DEVID_PGD 0x5
65
66#define SLIM_MSG_ASM_FIRST_WORD(l, mt, mc, dt, ad) \
67 ((l) | ((mt) << 5) | ((mc) << 8) | ((dt) << 15) | ((ad) << 16))
68
69#define INIT_MX_RETRIES 3
70#define DEF_RETRY_MS 10
71#define MSM_CONCUR_MSG 8
72#define SAT_CONCUR_MSG 8
73
74#define DEF_WATERMARK (8 << 1)
75#define DEF_ALIGN_LSB 0
76#define DEF_ALIGN_MSB (1 << 7)
77#define DEF_PACK (1 << 6)
78#define DEF_NO_PACK 0
79#define ENABLE_PORT 1
80
81#define DEF_BLKSZ 0
82#define DEF_TRANSZ 0
83
84#define SAT_MAGIC_LSB 0xD9
85#define SAT_MAGIC_MSB 0xC5
86#define SAT_MSG_VER 0x1
87#define SAT_MSG_PROT 0x1
88#define MSM_SAT_SUCCSS 0x20
89#define MSM_MAX_NSATS 2
90#define MSM_MAX_SATCH 32
91
92/* Slimbus QMI service */
93#define SLIMBUS_QMI_SVC_ID 0x0301
94#define SLIMBUS_QMI_SVC_V1 1
95#define SLIMBUS_QMI_INS_ID 0
96
97/* QMI response timeout of 500ms */
98#define SLIM_QMI_RESP_TOUT 1000
99
100#define PGD_THIS_EE(r, v) ((v) ? PGD_THIS_EE_V2(r) : PGD_THIS_EE_V1(r))
101#define PGD_PORT(r, p, v) ((v) ? PGD_PORT_V2(r, p) : PGD_PORT_V1(r, p))
102#define CFG_PORT(r, v) ((v) ? CFG_PORT_V2(r) : CFG_PORT_V1(r))
103
104#define PGD_THIS_EE_V2(r) (dev->base + (r ## _V2) + (dev->ee * 0x1000))
105#define PGD_PORT_V2(r, p) (dev->base + (r ## _V2) + ((p) * 0x1000))
106#define CFG_PORT_V2(r) ((r ## _V2))
107/* Component registers */
108enum comp_reg_v2 {
109 COMP_CFG_V2 = 4,
110 COMP_TRUST_CFG_V2 = 0x3000,
111};
112
113/* Manager PGD registers */
114enum pgd_reg_v2 {
115 PGD_CFG_V2 = 0x800,
116 PGD_STAT_V2 = 0x804,
117 PGD_INT_EN_V2 = 0x810,
118 PGD_INT_STAT_V2 = 0x814,
119 PGD_INT_CLR_V2 = 0x818,
120 PGD_OWN_EEn_V2 = 0x300C,
121 PGD_PORT_INT_EN_EEn_V2 = 0x5000,
122 PGD_PORT_INT_ST_EEn_V2 = 0x5004,
123 PGD_PORT_INT_CL_EEn_V2 = 0x5008,
124 PGD_PORT_CFGn_V2 = 0x14000,
125 PGD_PORT_STATn_V2 = 0x14004,
126 PGD_PORT_PARAMn_V2 = 0x14008,
127 PGD_PORT_BLKn_V2 = 0x1400C,
128 PGD_PORT_TRANn_V2 = 0x14010,
129 PGD_PORT_MCHANn_V2 = 0x14014,
130 PGD_PORT_PSHPLLn_V2 = 0x14018,
131 PGD_PORT_PC_CFGn_V2 = 0x8000,
132 PGD_PORT_PC_VALn_V2 = 0x8004,
133 PGD_PORT_PC_VFR_TSn_V2 = 0x8008,
134 PGD_PORT_PC_VFR_STn_V2 = 0x800C,
135 PGD_PORT_PC_VFR_CLn_V2 = 0x8010,
136 PGD_IE_STAT_V2 = 0x820,
137 PGD_VE_STAT_V2 = 0x830,
138};
139
140#define PGD_THIS_EE_V1(r) (dev->base + (r ## _V1) + (dev->ee * 16))
141#define PGD_PORT_V1(r, p) (dev->base + (r ## _V1) + ((p) * 32))
142#define CFG_PORT_V1(r) ((r ## _V1))
143/* Component registers */
144enum comp_reg_v1 {
145 COMP_CFG_V1 = 0,
146 COMP_TRUST_CFG_V1 = 0x14,
147};
148
149/* Manager PGD registers */
150enum pgd_reg_v1 {
151 PGD_CFG_V1 = 0x1000,
152 PGD_STAT_V1 = 0x1004,
153 PGD_INT_EN_V1 = 0x1010,
154 PGD_INT_STAT_V1 = 0x1014,
155 PGD_INT_CLR_V1 = 0x1018,
156 PGD_OWN_EEn_V1 = 0x1020,
157 PGD_PORT_INT_EN_EEn_V1 = 0x1030,
158 PGD_PORT_INT_ST_EEn_V1 = 0x1034,
159 PGD_PORT_INT_CL_EEn_V1 = 0x1038,
160 PGD_PORT_CFGn_V1 = 0x1080,
161 PGD_PORT_STATn_V1 = 0x1084,
162 PGD_PORT_PARAMn_V1 = 0x1088,
163 PGD_PORT_BLKn_V1 = 0x108C,
164 PGD_PORT_TRANn_V1 = 0x1090,
165 PGD_PORT_MCHANn_V1 = 0x1094,
166 PGD_PORT_PSHPLLn_V1 = 0x1098,
167 PGD_PORT_PC_CFGn_V1 = 0x1600,
168 PGD_PORT_PC_VALn_V1 = 0x1604,
169 PGD_PORT_PC_VFR_TSn_V1 = 0x1608,
170 PGD_PORT_PC_VFR_STn_V1 = 0x160C,
171 PGD_PORT_PC_VFR_CLn_V1 = 0x1610,
172 PGD_IE_STAT_V1 = 0x1700,
173 PGD_VE_STAT_V1 = 0x1710,
174};
175
176enum msm_slim_port_status {
177 MSM_PORT_OVERFLOW = 1 << 2,
178 MSM_PORT_UNDERFLOW = 1 << 3,
179 MSM_PORT_DISCONNECT = 1 << 19,
180};
181
182enum msm_ctrl_state {
183 MSM_CTRL_AWAKE,
184 MSM_CTRL_IDLE,
185 MSM_CTRL_ASLEEP,
186 MSM_CTRL_DOWN,
187};
188
189enum msm_slim_msgq {
190 MSM_MSGQ_DISABLED,
191 MSM_MSGQ_RESET,
192 MSM_MSGQ_ENABLED,
193 MSM_MSGQ_DOWN,
194};
195
196struct msm_slim_sps_bam {
197 unsigned long hdl;
198 void __iomem *base;
199 int irq;
200};
201
202/*
203 * struct slim_pshpull_parm: Structure to store push pull protocol parameters
204 * @num_samples: Number of samples in a period
205 * @rpt_period: Repeat period value
206 */
207struct msm_slim_pshpull_parm {
208 int num_samples;
209 int rpt_period;
210};
211
212struct msm_slim_endp {
213 struct sps_pipe *sps;
214 struct sps_connect config;
215 struct sps_register_event event;
216 struct sps_mem_buffer buf;
217 bool connected;
218 int port_b;
219 struct msm_slim_pshpull_parm psh_pull;
220};
221
222struct msm_slim_qmi {
223 struct qmi_handle *handle;
224 struct task_struct *task;
225 struct task_struct *slave_thread;
226 struct completion slave_notify;
227 struct kthread_work kwork;
228 struct kthread_worker kworker;
229 struct completion qmi_comp;
230 struct notifier_block nb;
Sagar Dhariaa4bfae12016-08-25 22:35:24 -0600231 bool deferred_resp;
232 struct qmi_response_type_v01 resp;
233 struct msg_desc resp_desc;
234 struct completion defer_comp;
Sagar Dhariabe37c9c2016-11-28 23:06:58 -0700235};
236
237enum msm_slim_dom {
238 MSM_SLIM_DOM_NONE,
239 MSM_SLIM_DOM_PD,
240 MSM_SLIM_DOM_SS,
241};
242
243struct msm_slim_ss {
244 struct notifier_block nb;
245 void *domr;
246 enum msm_ctrl_state state;
247 struct work_struct dom_up;
248 enum msm_slim_dom dom_t;
249};
250
251struct msm_slim_pdata {
252 u32 apps_pipes;
253 u32 eapc;
254};
255
256struct msm_slim_bulk_wr {
257 dma_addr_t wr_dma;
258 void *base;
259 int size;
260 int buf_sz;
261 int (*cb)(void *ctx, int err);
262 void *ctx;
263 bool in_progress;
264};
265
266struct msm_slim_ctrl {
267 struct slim_controller ctrl;
268 struct slim_framer framer;
269 struct device *dev;
270 void __iomem *base;
271 struct resource *slew_mem;
272 struct resource *bam_mem;
273 u32 curr_bw;
274 u8 msg_cnt;
275 u32 tx_buf[10];
276 u8 rx_msgs[MSM_CONCUR_MSG][SLIM_MSGQ_BUF_LEN];
277 int tx_tail;
278 int tx_head;
279 spinlock_t rx_lock;
280 int head;
281 int tail;
282 int irq;
283 int err;
284 int ee;
285 struct completion **wr_comp;
286 struct msm_slim_sat *satd[MSM_MAX_NSATS];
287 struct msm_slim_endp *pipes;
288 struct msm_slim_sps_bam bam;
289 struct msm_slim_endp tx_msgq;
290 struct msm_slim_endp rx_msgq;
291 struct completion rx_msgq_notify;
292 struct task_struct *rx_msgq_thread;
293 struct clk *rclk;
294 struct clk *hclk;
295 struct mutex tx_lock;
296 struct mutex ssr_lock;
297 spinlock_t tx_buf_lock;
298 u8 pgdla;
299 enum msm_slim_msgq use_rx_msgqs;
300 enum msm_slim_msgq use_tx_msgqs;
301 int port_nums;
302 struct completion reconf;
303 bool reconf_busy;
304 bool chan_active;
305 enum msm_ctrl_state state;
306 struct completion ctrl_up;
307 int nsats;
308 u32 ver;
309 struct msm_slim_qmi qmi;
310 struct msm_slim_pdata pdata;
311 struct msm_slim_ss ext_mdm;
312 struct msm_slim_ss dsp;
313 struct msm_slim_bulk_wr bulk;
314 int default_ipc_log_mask;
315 int ipc_log_mask;
316 bool sysfs_created;
317 void *ipc_slimbus_log;
318 void (*rx_slim)(struct msm_slim_ctrl *dev, u8 *buf);
319 u32 current_rx_buf[10];
320 int current_count;
321 atomic_t ssr_in_progress;
322};
323
324struct msm_sat_chan {
325 u8 chan;
326 u16 chanh;
327 int req_rem;
328 int req_def;
329 bool reconf;
330};
331
332struct msm_slim_sat {
333 struct slim_device satcl;
334 struct msm_slim_ctrl *dev;
335 struct workqueue_struct *wq;
336 struct work_struct wd;
337 u8 sat_msgs[SAT_CONCUR_MSG][40];
338 struct msm_sat_chan *satch;
339 u8 nsatch;
340 bool sent_capability;
341 bool pending_reconf;
342 bool pending_capability;
343 int shead;
344 int stail;
345 spinlock_t lock;
346};
347
348enum rsc_grp {
349 EE_MGR_RSC_GRP = 1 << 10,
350 EE_NGD_2 = 2 << 6,
351 EE_NGD_1 = 0,
352};
353
354
355/* IPC logging stuff */
356#define IPC_SLIMBUS_LOG_PAGES 5
357
358/* Log levels */
359enum {
360 FATAL_LEV = 0U,
361 ERR_LEV = 1U,
362 WARN_LEV = 2U,
363 INFO_LEV = 3U,
364 DBG_LEV = 4U,
365};
366
367/* Default IPC log level INFO */
368#define SLIM_DBG(dev, x...) do { \
369 pr_debug(x); \
370 if (dev->ipc_slimbus_log && dev->ipc_log_mask >= DBG_LEV) { \
371 ipc_log_string(dev->ipc_slimbus_log, x); \
372 } \
373} while (0)
374
375#define SLIM_INFO(dev, x...) do { \
376 pr_debug(x); \
377 if (dev->ipc_slimbus_log && dev->ipc_log_mask >= INFO_LEV) {\
378 ipc_log_string(dev->ipc_slimbus_log, x); \
379 } \
380} while (0)
381
382/* warnings and errors show up on console always */
383#define SLIM_WARN(dev, x...) do { \
384 pr_warn(x); \
385 if (dev->ipc_slimbus_log && dev->ipc_log_mask >= WARN_LEV) \
386 ipc_log_string(dev->ipc_slimbus_log, x); \
387} while (0)
388
389/* ERROR condition in the driver sets the hs_serial_debug_mask
390 * to ERR_FATAL level, so that this message can be seen
391 * in IPC logging. Further errors continue to log on the console
392 */
393#define SLIM_ERR(dev, x...) do { \
394 pr_err(x); \
395 if (dev->ipc_slimbus_log && dev->ipc_log_mask >= ERR_LEV) { \
396 ipc_log_string(dev->ipc_slimbus_log, x); \
397 dev->default_ipc_log_mask = dev->ipc_log_mask; \
398 dev->ipc_log_mask = FATAL_LEV; \
399 } \
400} while (0)
401
402#define SLIM_RST_LOGLVL(dev) { \
403 dev->ipc_log_mask = dev->default_ipc_log_mask; \
404}
405
406int msm_slim_rx_enqueue(struct msm_slim_ctrl *dev, u32 *buf, u8 len);
407int msm_slim_rx_dequeue(struct msm_slim_ctrl *dev, u8 *buf);
408int msm_slim_get_ctrl(struct msm_slim_ctrl *dev);
409void msm_slim_put_ctrl(struct msm_slim_ctrl *dev);
410irqreturn_t msm_slim_port_irq_handler(struct msm_slim_ctrl *dev, u32 pstat);
411int msm_slim_init_endpoint(struct msm_slim_ctrl *dev, struct msm_slim_endp *ep);
412void msm_slim_free_endpoint(struct msm_slim_endp *ep);
413void msm_hw_set_port(struct msm_slim_ctrl *dev, u8 pipenum, u8 portnum);
414int msm_alloc_port(struct slim_controller *ctrl, u8 pn);
415void msm_dealloc_port(struct slim_controller *ctrl, u8 pn);
416int msm_slim_connect_pipe_port(struct msm_slim_ctrl *dev, u8 pn);
417enum slim_port_err msm_slim_port_xfer_status(struct slim_controller *ctr,
418 u8 pn, phys_addr_t *done_buf, u32 *done_len);
419int msm_slim_port_xfer(struct slim_controller *ctrl, u8 pn, phys_addr_t iobuf,
420 u32 len, struct completion *comp);
421int msm_send_msg_buf(struct msm_slim_ctrl *dev, u32 *buf, u8 len, u32 tx_reg);
422u32 *msm_get_msg_buf(struct msm_slim_ctrl *dev, int len,
423 struct completion *comp);
424u32 *msm_slim_manage_tx_msgq(struct msm_slim_ctrl *dev, bool getbuf,
425 struct completion *comp, int err);
426int msm_slim_rx_msgq_get(struct msm_slim_ctrl *dev, u32 *data, int offset);
427int msm_slim_sps_init(struct msm_slim_ctrl *dev, struct resource *bam_mem,
428 u32 pipe_reg, bool remote);
429void msm_slim_sps_exit(struct msm_slim_ctrl *dev, bool dereg);
430
431int msm_slim_connect_endp(struct msm_slim_ctrl *dev,
432 struct msm_slim_endp *endpoint);
433void msm_slim_disconnect_endp(struct msm_slim_ctrl *dev,
434 struct msm_slim_endp *endpoint,
435 enum msm_slim_msgq *msgq_flag);
436void msm_slim_deinit_ep(struct msm_slim_ctrl *dev,
437 struct msm_slim_endp *endpoint,
438 enum msm_slim_msgq *msgq_flag);
439
440void msm_slim_qmi_exit(struct msm_slim_ctrl *dev);
441int msm_slim_qmi_init(struct msm_slim_ctrl *dev, bool apps_is_master);
442int msm_slim_qmi_power_request(struct msm_slim_ctrl *dev, bool active);
443int msm_slim_qmi_check_framer_request(struct msm_slim_ctrl *dev);
Sagar Dhariaa4bfae12016-08-25 22:35:24 -0600444int msm_slim_qmi_deferred_status_req(struct msm_slim_ctrl *dev);
Sagar Dhariabe37c9c2016-11-28 23:06:58 -0700445#endif