slim-msm.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. /* 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. #ifndef _SLIM_MSM_H
  13. #define _SLIM_MSM_H
  14. #include <linux/irq.h>
  15. #include <linux/kthread.h>
  16. #include <mach/msm_qmi_interface.h>
  17. #include <mach/subsystem_notif.h>
  18. #include <mach/msm_ipc_logging.h>
  19. /* Per spec.max 40 bytes per received message */
  20. #define SLIM_MSGQ_BUF_LEN 40
  21. #define MSM_TX_BUFS 32
  22. #define SLIM_USR_MC_GENERIC_ACK 0x25
  23. #define SLIM_USR_MC_MASTER_CAPABILITY 0x0
  24. #define SLIM_USR_MC_REPORT_SATELLITE 0x1
  25. #define SLIM_USR_MC_ADDR_QUERY 0xD
  26. #define SLIM_USR_MC_ADDR_REPLY 0xE
  27. #define SLIM_USR_MC_DEFINE_CHAN 0x20
  28. #define SLIM_USR_MC_DEF_ACT_CHAN 0x21
  29. #define SLIM_USR_MC_CHAN_CTRL 0x23
  30. #define SLIM_USR_MC_RECONFIG_NOW 0x24
  31. #define SLIM_USR_MC_REQ_BW 0x28
  32. #define SLIM_USR_MC_CONNECT_SRC 0x2C
  33. #define SLIM_USR_MC_CONNECT_SINK 0x2D
  34. #define SLIM_USR_MC_DISCONNECT_PORT 0x2E
  35. #define SLIM_USR_MC_REPEAT_CHANGE_VALUE 0x0
  36. #define MSM_SLIM_VE_MAX_MAP_ADDR 0xFFF
  37. #define SLIM_MAX_VE_SLC_BYTES 16
  38. #define MSM_SLIM_AUTOSUSPEND MSEC_PER_SEC
  39. /*
  40. * Messages that can be received simultaneously:
  41. * Client reads, LPASS master responses, announcement messages
  42. * Receive upto 10 messages simultaneously.
  43. */
  44. #define MSM_SLIM_DESC_NUM 32
  45. /* MSM Slimbus peripheral settings */
  46. #define MSM_SLIM_PERF_SUMM_THRESHOLD 0x8000
  47. #define MSM_SLIM_NPORTS 24
  48. #define MSM_SLIM_NCHANS 32
  49. #define QC_MFGID_LSB 0x2
  50. #define QC_MFGID_MSB 0x17
  51. #define QC_CHIPID_SL 0x10
  52. #define QC_DEVID_SAT1 0x3
  53. #define QC_DEVID_SAT2 0x4
  54. #define QC_DEVID_PGD 0x5
  55. #define SLIM_MSG_ASM_FIRST_WORD(l, mt, mc, dt, ad) \
  56. ((l) | ((mt) << 5) | ((mc) << 8) | ((dt) << 15) | ((ad) << 16))
  57. #define INIT_MX_RETRIES 10
  58. #define DEF_RETRY_MS 10
  59. #define MSM_CONCUR_MSG 8
  60. #define SAT_CONCUR_MSG 8
  61. #define DEF_WATERMARK (8 << 1)
  62. #define DEF_ALIGN 0
  63. #define DEF_PACK (1 << 6)
  64. #define ENABLE_PORT 1
  65. #define DEF_BLKSZ 0
  66. #define DEF_TRANSZ 0
  67. #define SAT_MAGIC_LSB 0xD9
  68. #define SAT_MAGIC_MSB 0xC5
  69. #define SAT_MSG_VER 0x1
  70. #define SAT_MSG_PROT 0x1
  71. #define MSM_SAT_SUCCSS 0x20
  72. #define MSM_MAX_NSATS 2
  73. #define MSM_MAX_SATCH 32
  74. /* Slimbus QMI service */
  75. #define SLIMBUS_QMI_SVC_ID 0x0301
  76. #define SLIMBUS_QMI_SVC_V1 1
  77. #define SLIMBUS_QMI_INS_ID 0
  78. #define PGD_THIS_EE(r, v) ((v) ? PGD_THIS_EE_V2(r) : PGD_THIS_EE_V1(r))
  79. #define PGD_PORT(r, p, v) ((v) ? PGD_PORT_V2(r, p) : PGD_PORT_V1(r, p))
  80. #define CFG_PORT(r, v) ((v) ? CFG_PORT_V2(r) : CFG_PORT_V1(r))
  81. #define PGD_THIS_EE_V2(r) (dev->base + (r ## _V2) + (dev->ee * 0x1000))
  82. #define PGD_PORT_V2(r, p) (dev->base + (r ## _V2) + ((p) * 0x1000))
  83. #define CFG_PORT_V2(r) ((r ## _V2))
  84. /* Component registers */
  85. enum comp_reg_v2 {
  86. COMP_CFG_V2 = 4,
  87. COMP_TRUST_CFG_V2 = 0x3000,
  88. };
  89. /* Manager PGD registers */
  90. enum pgd_reg_v2 {
  91. PGD_CFG_V2 = 0x800,
  92. PGD_STAT_V2 = 0x804,
  93. PGD_INT_EN_V2 = 0x810,
  94. PGD_INT_STAT_V2 = 0x814,
  95. PGD_INT_CLR_V2 = 0x818,
  96. PGD_OWN_EEn_V2 = 0x300C,
  97. PGD_PORT_INT_EN_EEn_V2 = 0x5000,
  98. PGD_PORT_INT_ST_EEn_V2 = 0x5004,
  99. PGD_PORT_INT_CL_EEn_V2 = 0x5008,
  100. PGD_PORT_CFGn_V2 = 0x14000,
  101. PGD_PORT_STATn_V2 = 0x14004,
  102. PGD_PORT_PARAMn_V2 = 0x14008,
  103. PGD_PORT_BLKn_V2 = 0x1400C,
  104. PGD_PORT_TRANn_V2 = 0x14010,
  105. PGD_PORT_MCHANn_V2 = 0x14014,
  106. PGD_PORT_PSHPLLn_V2 = 0x14018,
  107. PGD_PORT_PC_CFGn_V2 = 0x8000,
  108. PGD_PORT_PC_VALn_V2 = 0x8004,
  109. PGD_PORT_PC_VFR_TSn_V2 = 0x8008,
  110. PGD_PORT_PC_VFR_STn_V2 = 0x800C,
  111. PGD_PORT_PC_VFR_CLn_V2 = 0x8010,
  112. PGD_IE_STAT_V2 = 0x820,
  113. PGD_VE_STAT_V2 = 0x830,
  114. };
  115. #define PGD_THIS_EE_V1(r) (dev->base + (r ## _V1) + (dev->ee * 16))
  116. #define PGD_PORT_V1(r, p) (dev->base + (r ## _V1) + ((p) * 32))
  117. #define CFG_PORT_V1(r) ((r ## _V1))
  118. /* Component registers */
  119. enum comp_reg_v1 {
  120. COMP_CFG_V1 = 0,
  121. COMP_TRUST_CFG_V1 = 0x14,
  122. };
  123. /* Manager PGD registers */
  124. enum pgd_reg_v1 {
  125. PGD_CFG_V1 = 0x1000,
  126. PGD_STAT_V1 = 0x1004,
  127. PGD_INT_EN_V1 = 0x1010,
  128. PGD_INT_STAT_V1 = 0x1014,
  129. PGD_INT_CLR_V1 = 0x1018,
  130. PGD_OWN_EEn_V1 = 0x1020,
  131. PGD_PORT_INT_EN_EEn_V1 = 0x1030,
  132. PGD_PORT_INT_ST_EEn_V1 = 0x1034,
  133. PGD_PORT_INT_CL_EEn_V1 = 0x1038,
  134. PGD_PORT_CFGn_V1 = 0x1080,
  135. PGD_PORT_STATn_V1 = 0x1084,
  136. PGD_PORT_PARAMn_V1 = 0x1088,
  137. PGD_PORT_BLKn_V1 = 0x108C,
  138. PGD_PORT_TRANn_V1 = 0x1090,
  139. PGD_PORT_MCHANn_V1 = 0x1094,
  140. PGD_PORT_PSHPLLn_V1 = 0x1098,
  141. PGD_PORT_PC_CFGn_V1 = 0x1600,
  142. PGD_PORT_PC_VALn_V1 = 0x1604,
  143. PGD_PORT_PC_VFR_TSn_V1 = 0x1608,
  144. PGD_PORT_PC_VFR_STn_V1 = 0x160C,
  145. PGD_PORT_PC_VFR_CLn_V1 = 0x1610,
  146. PGD_IE_STAT_V1 = 0x1700,
  147. PGD_VE_STAT_V1 = 0x1710,
  148. };
  149. enum msm_slim_port_status {
  150. MSM_PORT_OVERFLOW = 1 << 2,
  151. MSM_PORT_UNDERFLOW = 1 << 3,
  152. MSM_PORT_DISCONNECT = 1 << 19,
  153. };
  154. enum msm_ctrl_state {
  155. MSM_CTRL_AWAKE,
  156. MSM_CTRL_IDLE,
  157. MSM_CTRL_ASLEEP,
  158. MSM_CTRL_DOWN,
  159. };
  160. enum msm_slim_msgq {
  161. MSM_MSGQ_DISABLED,
  162. MSM_MSGQ_RESET,
  163. MSM_MSGQ_ENABLED,
  164. MSM_MSGQ_DOWN,
  165. };
  166. struct msm_slim_sps_bam {
  167. u32 hdl;
  168. void __iomem *base;
  169. int irq;
  170. };
  171. struct msm_slim_endp {
  172. struct sps_pipe *sps;
  173. struct sps_connect config;
  174. struct sps_register_event event;
  175. struct sps_mem_buffer buf;
  176. bool connected;
  177. };
  178. struct msm_slim_qmi {
  179. struct qmi_handle *handle;
  180. struct task_struct *task;
  181. struct task_struct *slave_thread;
  182. struct completion slave_notify;
  183. struct kthread_work kwork;
  184. struct kthread_worker kworker;
  185. struct completion qmi_comp;
  186. struct notifier_block nb;
  187. struct work_struct ssr_down;
  188. struct work_struct ssr_up;
  189. };
  190. struct msm_slim_ss {
  191. struct notifier_block nb;
  192. void *ssr;
  193. enum msm_ctrl_state state;
  194. };
  195. struct msm_slim_pdata {
  196. u32 apps_pipes;
  197. u32 eapc;
  198. };
  199. struct msm_slim_ctrl {
  200. struct slim_controller ctrl;
  201. struct slim_framer framer;
  202. struct device *dev;
  203. void __iomem *base;
  204. struct resource *slew_mem;
  205. struct resource *bam_mem;
  206. u32 curr_bw;
  207. u8 msg_cnt;
  208. u32 tx_buf[10];
  209. u8 rx_msgs[MSM_CONCUR_MSG][SLIM_MSGQ_BUF_LEN];
  210. int tx_tail;
  211. int tx_head;
  212. spinlock_t rx_lock;
  213. int head;
  214. int tail;
  215. int irq;
  216. int err;
  217. int ee;
  218. struct completion **wr_comp;
  219. struct msm_slim_sat *satd[MSM_MAX_NSATS];
  220. struct msm_slim_endp pipes[7];
  221. struct msm_slim_sps_bam bam;
  222. struct msm_slim_endp tx_msgq;
  223. struct msm_slim_endp rx_msgq;
  224. struct completion rx_msgq_notify;
  225. struct task_struct *rx_msgq_thread;
  226. struct clk *rclk;
  227. struct clk *hclk;
  228. struct mutex tx_lock;
  229. struct mutex ssr_lock;
  230. struct mutex tx_buf_lock;
  231. u8 pgdla;
  232. enum msm_slim_msgq use_rx_msgqs;
  233. enum msm_slim_msgq use_tx_msgqs;
  234. int port_b;
  235. struct completion reconf;
  236. bool reconf_busy;
  237. bool chan_active;
  238. enum msm_ctrl_state state;
  239. struct completion ctrl_up;
  240. int nsats;
  241. u32 ver;
  242. struct msm_slim_qmi qmi;
  243. struct msm_slim_pdata pdata;
  244. struct msm_slim_ss ext_mdm;
  245. struct msm_slim_ss dsp;
  246. int default_ipc_log_mask;
  247. int ipc_log_mask;
  248. bool sysfs_created;
  249. void *ipc_slimbus_log;
  250. };
  251. struct msm_sat_chan {
  252. u8 chan;
  253. u16 chanh;
  254. int req_rem;
  255. int req_def;
  256. bool reconf;
  257. };
  258. struct msm_slim_sat {
  259. struct slim_device satcl;
  260. struct msm_slim_ctrl *dev;
  261. struct workqueue_struct *wq;
  262. struct work_struct wd;
  263. u8 sat_msgs[SAT_CONCUR_MSG][40];
  264. struct msm_sat_chan *satch;
  265. u8 nsatch;
  266. bool sent_capability;
  267. bool pending_reconf;
  268. bool pending_capability;
  269. int shead;
  270. int stail;
  271. spinlock_t lock;
  272. };
  273. enum rsc_grp {
  274. EE_MGR_RSC_GRP = 1 << 10,
  275. EE_NGD_2 = 2 << 6,
  276. EE_NGD_1 = 0,
  277. };
  278. /* IPC logging stuff */
  279. #define IPC_SLIMBUS_LOG_PAGES 5
  280. /* Log levels */
  281. enum {
  282. FATAL_LEV = 0U,
  283. ERR_LEV = 1U,
  284. WARN_LEV = 2U,
  285. INFO_LEV = 3U,
  286. DBG_LEV = 4U,
  287. };
  288. /* Default IPC log level INFO */
  289. #define SLIM_DBG(dev, x...) do { \
  290. pr_debug(x); \
  291. if (dev->ipc_slimbus_log && dev->ipc_log_mask >= DBG_LEV) { \
  292. ipc_log_string(dev->ipc_slimbus_log, x); \
  293. } \
  294. } while (0)
  295. #define SLIM_INFO(dev, x...) do { \
  296. pr_debug(x); \
  297. if (dev->ipc_slimbus_log && dev->ipc_log_mask >= INFO_LEV) {\
  298. ipc_log_string(dev->ipc_slimbus_log, x); \
  299. } \
  300. } while (0)
  301. /* warnings and errors show up on console always */
  302. #define SLIM_WARN(dev, x...) do { \
  303. pr_warn(x); \
  304. if (dev->ipc_slimbus_log && dev->ipc_log_mask >= WARN_LEV) \
  305. ipc_log_string(dev->ipc_slimbus_log, x); \
  306. } while (0)
  307. /* ERROR condition in the driver sets the hs_serial_debug_mask
  308. * to ERR_FATAL level, so that this message can be seen
  309. * in IPC logging. Further errors continue to log on the console
  310. */
  311. #define SLIM_ERR(dev, x...) do { \
  312. pr_err(x); \
  313. if (dev->ipc_slimbus_log && dev->ipc_log_mask >= ERR_LEV) { \
  314. ipc_log_string(dev->ipc_slimbus_log, x); \
  315. dev->default_ipc_log_mask = dev->ipc_log_mask; \
  316. dev->ipc_log_mask = FATAL_LEV; \
  317. } \
  318. } while (0)
  319. #define SLIM_RST_LOGLVL(dev) { \
  320. dev->ipc_log_mask = dev->default_ipc_log_mask; \
  321. }
  322. int msm_slim_rx_enqueue(struct msm_slim_ctrl *dev, u32 *buf, u8 len);
  323. int msm_slim_rx_dequeue(struct msm_slim_ctrl *dev, u8 *buf);
  324. int msm_slim_get_ctrl(struct msm_slim_ctrl *dev);
  325. void msm_slim_put_ctrl(struct msm_slim_ctrl *dev);
  326. irqreturn_t msm_slim_port_irq_handler(struct msm_slim_ctrl *dev, u32 pstat);
  327. int msm_slim_init_endpoint(struct msm_slim_ctrl *dev, struct msm_slim_endp *ep);
  328. void msm_slim_free_endpoint(struct msm_slim_endp *ep);
  329. void msm_hw_set_port(struct msm_slim_ctrl *dev, u8 pn);
  330. int msm_alloc_port(struct slim_controller *ctrl, u8 pn);
  331. void msm_dealloc_port(struct slim_controller *ctrl, u8 pn);
  332. int msm_slim_connect_pipe_port(struct msm_slim_ctrl *dev, u8 pn);
  333. enum slim_port_err msm_slim_port_xfer_status(struct slim_controller *ctr,
  334. u8 pn, phys_addr_t *done_buf, u32 *done_len);
  335. int msm_slim_port_xfer(struct slim_controller *ctrl, u8 pn, phys_addr_t iobuf,
  336. u32 len, struct completion *comp);
  337. int msm_send_msg_buf(struct msm_slim_ctrl *dev, u32 *buf, u8 len, u32 tx_reg);
  338. u32 *msm_get_msg_buf(struct msm_slim_ctrl *dev, int len,
  339. struct completion *comp);
  340. u32 *msm_slim_manage_tx_msgq(struct msm_slim_ctrl *dev, bool getbuf,
  341. struct completion *comp);
  342. int msm_slim_rx_msgq_get(struct msm_slim_ctrl *dev, u32 *data, int offset);
  343. int msm_slim_sps_init(struct msm_slim_ctrl *dev, struct resource *bam_mem,
  344. u32 pipe_reg, bool remote);
  345. void msm_slim_sps_exit(struct msm_slim_ctrl *dev, bool dereg);
  346. int msm_slim_connect_endp(struct msm_slim_ctrl *dev,
  347. struct msm_slim_endp *endpoint,
  348. struct completion *notify);
  349. void msm_slim_disconnect_endp(struct msm_slim_ctrl *dev,
  350. struct msm_slim_endp *endpoint,
  351. enum msm_slim_msgq *msgq_flag);
  352. void msm_slim_qmi_exit(struct msm_slim_ctrl *dev);
  353. int msm_slim_qmi_init(struct msm_slim_ctrl *dev, bool apps_is_master);
  354. int msm_slim_qmi_power_request(struct msm_slim_ctrl *dev, bool active);
  355. int msm_slim_qmi_check_framer_request(struct msm_slim_ctrl *dev);
  356. #endif