dsi_ctrl_hw_2_2.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/iopoll.h>
  6. #include "dsi_ctrl_hw.h"
  7. #include "dsi_ctrl_reg.h"
  8. #include "dsi_hw.h"
  9. #include "dsi_ctrl.h"
  10. #include "dsi_catalog.h"
  11. #define DISP_CC_MISC_CMD_REG_OFF 0x00
  12. /* register to configure DMA scheduling */
  13. #define DSI_DMA_SCHEDULE_CTRL 0x100
  14. #define DSI_DMA_SCHEDULE_CTRL2 0x0104
  15. /* offset addresses of MDP INTF base register, to be mapped for debug feature */
  16. #define MDP_INTF_TEAR_OFFSET 0x280
  17. #define MDP_INTF_TEAR_LINE_COUNT_OFFSET 0x30
  18. #define MDP_INTF_LINE_COUNT_OFFSET 0xB0
  19. void dsi_ctrl_hw_22_setup_lane_map(struct dsi_ctrl_hw *ctrl,
  20. struct dsi_lane_map *lane_map)
  21. {
  22. u32 reg_value = lane_map->lane_map_v2[DSI_LOGICAL_LANE_0] |
  23. (lane_map->lane_map_v2[DSI_LOGICAL_LANE_1] << 4) |
  24. (lane_map->lane_map_v2[DSI_LOGICAL_LANE_2] << 8) |
  25. (lane_map->lane_map_v2[DSI_LOGICAL_LANE_3] << 12);
  26. DSI_W32(ctrl, DSI_LANE_SWAP_CTRL, reg_value);
  27. DSI_CTRL_HW_DBG(ctrl, "[DSI_%d] Lane swap setup complete\n",
  28. ctrl->index);
  29. }
  30. int dsi_ctrl_hw_22_wait_for_lane_idle(struct dsi_ctrl_hw *ctrl,
  31. u32 lanes)
  32. {
  33. int rc = 0, val = 0;
  34. u32 fifo_empty_mask = 0;
  35. u32 const sleep_us = 10;
  36. u32 const timeout_us = 100;
  37. if (lanes & DSI_DATA_LANE_0)
  38. fifo_empty_mask |= (BIT(12) | BIT(16));
  39. if (lanes & DSI_DATA_LANE_1)
  40. fifo_empty_mask |= BIT(20);
  41. if (lanes & DSI_DATA_LANE_2)
  42. fifo_empty_mask |= BIT(24);
  43. if (lanes & DSI_DATA_LANE_3)
  44. fifo_empty_mask |= BIT(28);
  45. DSI_CTRL_HW_DBG(ctrl, "%s: polling for fifo empty, mask=0x%08x\n",
  46. __func__, fifo_empty_mask);
  47. rc = readl_poll_timeout(ctrl->base + DSI_FIFO_STATUS, val,
  48. (val & fifo_empty_mask), sleep_us, timeout_us);
  49. if (rc) {
  50. DSI_CTRL_HW_ERR(ctrl,
  51. "%s: fifo not empty, FIFO_STATUS=0x%08x\n",
  52. __func__, val);
  53. goto error;
  54. }
  55. error:
  56. return rc;
  57. }
  58. ssize_t dsi_ctrl_hw_22_reg_dump_to_buffer(struct dsi_ctrl_hw *ctrl,
  59. char *buf,
  60. u32 size)
  61. {
  62. return size;
  63. }
  64. /**
  65. * dsi_ctrl_hw_22_phy_reset_config() - to configure clamp control during ulps
  66. * @ctrl: Pointer to the controller host hardware.
  67. * @enable: boolean to specify enable/disable.
  68. */
  69. void dsi_ctrl_hw_22_phy_reset_config(struct dsi_ctrl_hw *ctrl,
  70. bool enable)
  71. {
  72. u32 reg = 0;
  73. reg = DSI_DISP_CC_R32(ctrl, DISP_CC_MISC_CMD_REG_OFF);
  74. /* Mask/unmask disable PHY reset bit */
  75. if (enable)
  76. reg &= ~BIT(ctrl->index);
  77. else
  78. reg |= BIT(ctrl->index);
  79. DSI_DISP_CC_W32(ctrl, DISP_CC_MISC_CMD_REG_OFF, reg);
  80. }
  81. /**
  82. * dsi_ctrl_hw_22_schedule_dma_cmd() - to schedule DMA command transfer
  83. * @ctrl: Pointer to the controller host hardware.
  84. * @line_no: Line number at which command needs to be sent.
  85. */
  86. void dsi_ctrl_hw_22_schedule_dma_cmd(struct dsi_ctrl_hw *ctrl, int line_no)
  87. {
  88. u32 reg = 0;
  89. reg = DSI_R32(ctrl, DSI_DMA_SCHEDULE_CTRL);
  90. reg |= BIT(28);
  91. reg |= (line_no & 0xffff);
  92. DSI_W32(ctrl, DSI_DMA_SCHEDULE_CTRL, reg);
  93. ctrl->reset_trig_ctrl = true;
  94. }
  95. /*
  96. * dsi_ctrl_hw_kickoff_non_embedded_mode()-Kickoff cmd in non-embedded mode
  97. * @ctrl: - Pointer to the controller host hardware.
  98. * @dsi_ctrl_cmd_dma_info: - command buffer information.
  99. * @flags: - DSI CTRL Flags.
  100. */
  101. void dsi_ctrl_hw_kickoff_non_embedded_mode(struct dsi_ctrl_hw *ctrl,
  102. struct dsi_ctrl_cmd_dma_info *cmd,
  103. u32 flags)
  104. {
  105. u32 reg = 0;
  106. reg = DSI_R32(ctrl, DSI_COMMAND_MODE_DMA_CTRL);
  107. reg &= ~BIT(31);/* disable broadcast */
  108. reg &= ~BIT(30);
  109. if (cmd->use_lpm)
  110. reg |= BIT(26);
  111. else
  112. reg &= ~BIT(26);
  113. /* Select non EMBEDDED_MODE, pick the packet header from register */
  114. reg &= ~BIT(28);
  115. reg |= BIT(24);/* long packet */
  116. reg |= BIT(29);/* wc_sel = 1 */
  117. reg |= (((cmd->datatype) & 0x03f) << 16);/* data type */
  118. DSI_W32(ctrl, DSI_COMMAND_MODE_DMA_CTRL, reg);
  119. /* Enable WRITE_WATERMARK_DISABLE and READ_WATERMARK_DISABLE bits */
  120. reg = DSI_R32(ctrl, DSI_DMA_FIFO_CTRL);
  121. reg |= BIT(20);
  122. reg |= BIT(16);
  123. reg |= 0x33;/* Set READ and WRITE watermark levels to maximum */
  124. DSI_W32(ctrl, DSI_DMA_FIFO_CTRL, reg);
  125. DSI_W32(ctrl, DSI_DMA_CMD_OFFSET, cmd->offset);
  126. DSI_W32(ctrl, DSI_DMA_CMD_LENGTH, ((cmd->length) & 0xFFFFFF));
  127. /* wait for writes to complete before kick off */
  128. wmb();
  129. if (!(flags & DSI_CTRL_HW_CMD_WAIT_FOR_TRIGGER))
  130. DSI_W32(ctrl, DSI_CMD_MODE_DMA_SW_TRIGGER, 0x1);
  131. }
  132. /*
  133. * dsi_ctrl_hw_22_config_clk_gating() - enable/disable clk gating on DSI PHY
  134. * @ctrl: Pointer to the controller host hardware.
  135. * @enable: bool to notify enable/disable.
  136. * @clk_selection: clock to enable/disable clock gating.
  137. *
  138. */
  139. void dsi_ctrl_hw_22_config_clk_gating(struct dsi_ctrl_hw *ctrl, bool enable,
  140. enum dsi_clk_gate_type clk_selection)
  141. {
  142. u32 reg = 0;
  143. u32 enable_select = 0;
  144. reg = DSI_DISP_CC_R32(ctrl, DISP_CC_MISC_CMD_REG_OFF);
  145. if (clk_selection & PIXEL_CLK)
  146. enable_select |= ctrl->index ? BIT(6) : BIT(5);
  147. if (clk_selection & BYTE_CLK)
  148. enable_select |= ctrl->index ? BIT(8) : BIT(7);
  149. if (clk_selection & DSI_PHY)
  150. enable_select |= ctrl->index ? BIT(10) : BIT(9);
  151. if (enable)
  152. reg |= enable_select;
  153. else
  154. reg &= ~enable_select;
  155. DSI_DISP_CC_W32(ctrl, DISP_CC_MISC_CMD_REG_OFF, reg);
  156. }
  157. /**
  158. * dsi_ctrl_hw_22_configure_cmddma_window() - configure DMA window for CMD TX
  159. * @ctrl: Pointer to the controller host hardware.
  160. * @cmd: Pointer to the DSI DMA command info.
  161. * @line_no: Line number at which the CMD needs to be triggered.
  162. * @window: Width of the DMA CMD window.
  163. */
  164. void dsi_ctrl_hw_22_configure_cmddma_window(struct dsi_ctrl_hw *ctrl,
  165. struct dsi_ctrl_cmd_dma_info *cmd,
  166. u32 line_no, u32 window)
  167. {
  168. u32 reg = 0;
  169. if (cmd->en_broadcast) {
  170. reg = DSI_R32(ctrl, DSI_TRIG_CTRL);
  171. if (cmd->is_master) {
  172. reg &= ~0xF;
  173. reg |= 0xc;
  174. } else {
  175. reg &= ~0xF;
  176. reg |= BIT(16);
  177. }
  178. DSI_W32(ctrl, DSI_TRIG_CTRL, reg);
  179. if (cmd->is_master) {
  180. reg = 0;
  181. reg |= line_no;
  182. reg |= window << 16;
  183. DSI_W32(ctrl, DSI_DMA_SCHEDULE_CTRL2, reg);
  184. }
  185. } else {
  186. reg = DSI_R32(ctrl, DSI_TRIG_CTRL);
  187. reg &= ~0xF;
  188. reg |= 0xc;
  189. DSI_W32(ctrl, DSI_TRIG_CTRL, reg);
  190. reg = 0;
  191. reg |= line_no;
  192. reg |= window << 16;
  193. DSI_W32(ctrl, DSI_DMA_SCHEDULE_CTRL2, reg);
  194. }
  195. ctrl->reset_trig_ctrl = true;
  196. }
  197. /**
  198. * dsi_ctrl_hw_22_reset_trigger_controls() - reset dsi trigger configurations
  199. * @ctrl: Pointer to the controller host hardware.
  200. * @cfg: DSI host configuration that is common to both video and
  201. * command modes.
  202. */
  203. void dsi_ctrl_hw_22_reset_trigger_controls(struct dsi_ctrl_hw *ctrl,
  204. struct dsi_host_common_cfg *cfg)
  205. {
  206. u32 reg = 0;
  207. const u8 trigger_map[DSI_TRIGGER_MAX] = {
  208. 0x0, 0x2, 0x1, 0x4, 0x5, 0x6 };
  209. reg |= (cfg->te_mode == DSI_TE_ON_EXT_PIN) ? BIT(31) : 0;
  210. reg |= (trigger_map[cfg->dma_cmd_trigger] & 0x7);
  211. reg |= (trigger_map[cfg->mdp_cmd_trigger] & 0x7) << 4;
  212. DSI_W32(ctrl, DSI_TRIG_CTRL, reg);
  213. DSI_W32(ctrl, DSI_DMA_SCHEDULE_CTRL2, 0x0);
  214. DSI_W32(ctrl, DSI_DMA_SCHEDULE_CTRL, 0x0);
  215. ctrl->reset_trig_ctrl = false;
  216. }
  217. /**
  218. * dsi_ctrl_hw_22_log_line_count() - reads the MDP interface line count
  219. * registers.
  220. * @ctrl: Pointer to the controller host hardware.
  221. * @cmd_mode: Boolean to indicate command mode operation.
  222. *
  223. * Return: INTF register value.
  224. */
  225. u32 dsi_ctrl_hw_22_log_line_count(struct dsi_ctrl_hw *ctrl, bool cmd_mode)
  226. {
  227. u32 reg = 0;
  228. if (IS_ERR_OR_NULL(ctrl->mdp_intf_base))
  229. return reg;
  230. if (cmd_mode)
  231. reg = readl_relaxed(ctrl->mdp_intf_base + MDP_INTF_TEAR_OFFSET
  232. + MDP_INTF_TEAR_LINE_COUNT_OFFSET);
  233. else
  234. reg = readl_relaxed(ctrl->mdp_intf_base
  235. + MDP_INTF_LINE_COUNT_OFFSET);
  236. return reg;
  237. }
  238. void dsi_ctrl_hw_22_configure_splitlink(struct dsi_ctrl_hw *ctrl,
  239. struct dsi_host_common_cfg *common_cfg, u32 flags)
  240. {
  241. u32 reg = 0;
  242. reg = DSI_R32(ctrl, DSI_SPLIT_LINK);
  243. /* DMA_LINK_SEL */
  244. reg &= ~(0x7 << 12);
  245. /* Send command to both sublinks unless specified */
  246. if (flags & DSI_CTRL_CMD_SUBLINK0)
  247. reg |= BIT(12);
  248. else if (flags & DSI_CTRL_CMD_SUBLINK1)
  249. reg |= BIT(13);
  250. else
  251. reg |= (BIT(12) | BIT(13));
  252. DSI_W32(ctrl, DSI_SPLIT_LINK, reg);
  253. /* Make sure the split link config is updated */
  254. wmb();
  255. }