dsi_ctrl_hw_2_2.c 6.7 KB

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