dsi_ctrl_hw_2_2.c 7.4 KB

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