blob: edebfd935483aa452f3be355e6595f8d9fd5c18a [file] [log] [blame]
Dilip Kota81c88552017-10-24 12:18:23 +05301/* Copyright (c) 2011-2018, The Linux Foundation. All rights reserved.
Sagar Dhariabe37c9c2016-11-28 23:06:58 -07002 *
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
Karthikeyan Ramasubramanian9cd18ff2017-05-09 17:11:26 -0600266struct msm_slim_iommu {
267 struct device *cb_dev;
268 struct dma_iommu_mapping *iommu_map;
269 bool s1_bypass;
270};
271
Sagar Dhariabe37c9c2016-11-28 23:06:58 -0700272struct msm_slim_ctrl {
273 struct slim_controller ctrl;
274 struct slim_framer framer;
275 struct device *dev;
Karthikeyan Ramasubramanian9cd18ff2017-05-09 17:11:26 -0600276 struct msm_slim_iommu iommu_desc;
Sagar Dhariabe37c9c2016-11-28 23:06:58 -0700277 void __iomem *base;
278 struct resource *slew_mem;
279 struct resource *bam_mem;
280 u32 curr_bw;
281 u8 msg_cnt;
282 u32 tx_buf[10];
283 u8 rx_msgs[MSM_CONCUR_MSG][SLIM_MSGQ_BUF_LEN];
284 int tx_tail;
285 int tx_head;
286 spinlock_t rx_lock;
287 int head;
288 int tail;
289 int irq;
290 int err;
291 int ee;
292 struct completion **wr_comp;
293 struct msm_slim_sat *satd[MSM_MAX_NSATS];
294 struct msm_slim_endp *pipes;
295 struct msm_slim_sps_bam bam;
296 struct msm_slim_endp tx_msgq;
297 struct msm_slim_endp rx_msgq;
298 struct completion rx_msgq_notify;
299 struct task_struct *rx_msgq_thread;
300 struct clk *rclk;
301 struct clk *hclk;
302 struct mutex tx_lock;
303 struct mutex ssr_lock;
304 spinlock_t tx_buf_lock;
305 u8 pgdla;
306 enum msm_slim_msgq use_rx_msgqs;
307 enum msm_slim_msgq use_tx_msgqs;
308 int port_nums;
309 struct completion reconf;
310 bool reconf_busy;
311 bool chan_active;
312 enum msm_ctrl_state state;
313 struct completion ctrl_up;
314 int nsats;
315 u32 ver;
316 struct msm_slim_qmi qmi;
317 struct msm_slim_pdata pdata;
318 struct msm_slim_ss ext_mdm;
319 struct msm_slim_ss dsp;
320 struct msm_slim_bulk_wr bulk;
321 int default_ipc_log_mask;
322 int ipc_log_mask;
323 bool sysfs_created;
324 void *ipc_slimbus_log;
325 void (*rx_slim)(struct msm_slim_ctrl *dev, u8 *buf);
326 u32 current_rx_buf[10];
327 int current_count;
328 atomic_t ssr_in_progress;
329};
330
331struct msm_sat_chan {
332 u8 chan;
333 u16 chanh;
334 int req_rem;
335 int req_def;
336 bool reconf;
337};
338
339struct msm_slim_sat {
340 struct slim_device satcl;
341 struct msm_slim_ctrl *dev;
342 struct workqueue_struct *wq;
343 struct work_struct wd;
344 u8 sat_msgs[SAT_CONCUR_MSG][40];
345 struct msm_sat_chan *satch;
346 u8 nsatch;
347 bool sent_capability;
348 bool pending_reconf;
349 bool pending_capability;
350 int shead;
351 int stail;
352 spinlock_t lock;
353};
354
355enum rsc_grp {
356 EE_MGR_RSC_GRP = 1 << 10,
357 EE_NGD_2 = 2 << 6,
358 EE_NGD_1 = 0,
359};
360
361
362/* IPC logging stuff */
363#define IPC_SLIMBUS_LOG_PAGES 5
364
365/* Log levels */
366enum {
367 FATAL_LEV = 0U,
368 ERR_LEV = 1U,
369 WARN_LEV = 2U,
370 INFO_LEV = 3U,
371 DBG_LEV = 4U,
372};
373
374/* Default IPC log level INFO */
375#define SLIM_DBG(dev, x...) do { \
376 pr_debug(x); \
377 if (dev->ipc_slimbus_log && dev->ipc_log_mask >= DBG_LEV) { \
378 ipc_log_string(dev->ipc_slimbus_log, x); \
379 } \
380} while (0)
381
382#define SLIM_INFO(dev, x...) do { \
383 pr_debug(x); \
384 if (dev->ipc_slimbus_log && dev->ipc_log_mask >= INFO_LEV) {\
385 ipc_log_string(dev->ipc_slimbus_log, x); \
386 } \
387} while (0)
388
389/* warnings and errors show up on console always */
390#define SLIM_WARN(dev, x...) do { \
391 pr_warn(x); \
392 if (dev->ipc_slimbus_log && dev->ipc_log_mask >= WARN_LEV) \
393 ipc_log_string(dev->ipc_slimbus_log, x); \
394} while (0)
395
396/* ERROR condition in the driver sets the hs_serial_debug_mask
397 * to ERR_FATAL level, so that this message can be seen
398 * in IPC logging. Further errors continue to log on the console
399 */
400#define SLIM_ERR(dev, x...) do { \
401 pr_err(x); \
402 if (dev->ipc_slimbus_log && dev->ipc_log_mask >= ERR_LEV) { \
403 ipc_log_string(dev->ipc_slimbus_log, x); \
404 dev->default_ipc_log_mask = dev->ipc_log_mask; \
405 dev->ipc_log_mask = FATAL_LEV; \
406 } \
407} while (0)
408
409#define SLIM_RST_LOGLVL(dev) { \
410 dev->ipc_log_mask = dev->default_ipc_log_mask; \
411}
412
413int msm_slim_rx_enqueue(struct msm_slim_ctrl *dev, u32 *buf, u8 len);
414int msm_slim_rx_dequeue(struct msm_slim_ctrl *dev, u8 *buf);
415int msm_slim_get_ctrl(struct msm_slim_ctrl *dev);
416void msm_slim_put_ctrl(struct msm_slim_ctrl *dev);
417irqreturn_t msm_slim_port_irq_handler(struct msm_slim_ctrl *dev, u32 pstat);
418int msm_slim_init_endpoint(struct msm_slim_ctrl *dev, struct msm_slim_endp *ep);
419void msm_slim_free_endpoint(struct msm_slim_endp *ep);
420void msm_hw_set_port(struct msm_slim_ctrl *dev, u8 pipenum, u8 portnum);
421int msm_alloc_port(struct slim_controller *ctrl, u8 pn);
422void msm_dealloc_port(struct slim_controller *ctrl, u8 pn);
423int msm_slim_connect_pipe_port(struct msm_slim_ctrl *dev, u8 pn);
424enum slim_port_err msm_slim_port_xfer_status(struct slim_controller *ctr,
425 u8 pn, phys_addr_t *done_buf, u32 *done_len);
Dilip Kota81c88552017-10-24 12:18:23 +0530426int msm_slim_port_xfer(struct slim_controller *ctrl, u8 pn, void *buf,
Sagar Dhariabe37c9c2016-11-28 23:06:58 -0700427 u32 len, struct completion *comp);
428int msm_send_msg_buf(struct msm_slim_ctrl *dev, u32 *buf, u8 len, u32 tx_reg);
429u32 *msm_get_msg_buf(struct msm_slim_ctrl *dev, int len,
430 struct completion *comp);
431u32 *msm_slim_manage_tx_msgq(struct msm_slim_ctrl *dev, bool getbuf,
432 struct completion *comp, int err);
433int msm_slim_rx_msgq_get(struct msm_slim_ctrl *dev, u32 *data, int offset);
434int msm_slim_sps_init(struct msm_slim_ctrl *dev, struct resource *bam_mem,
435 u32 pipe_reg, bool remote);
436void msm_slim_sps_exit(struct msm_slim_ctrl *dev, bool dereg);
437
438int msm_slim_connect_endp(struct msm_slim_ctrl *dev,
439 struct msm_slim_endp *endpoint);
440void msm_slim_disconnect_endp(struct msm_slim_ctrl *dev,
441 struct msm_slim_endp *endpoint,
442 enum msm_slim_msgq *msgq_flag);
443void msm_slim_deinit_ep(struct msm_slim_ctrl *dev,
444 struct msm_slim_endp *endpoint,
445 enum msm_slim_msgq *msgq_flag);
446
447void msm_slim_qmi_exit(struct msm_slim_ctrl *dev);
448int msm_slim_qmi_init(struct msm_slim_ctrl *dev, bool apps_is_master);
449int msm_slim_qmi_power_request(struct msm_slim_ctrl *dev, bool active);
450int msm_slim_qmi_check_framer_request(struct msm_slim_ctrl *dev);
Sagar Dhariaa4bfae12016-08-25 22:35:24 -0600451int msm_slim_qmi_deferred_status_req(struct msm_slim_ctrl *dev);
Sagar Dhariabe37c9c2016-11-28 23:06:58 -0700452#endif