dsi_ctrl_hw_2_2.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. void dsi_ctrl_hw_22_setup_lane_map(struct dsi_ctrl_hw *ctrl,
  14. struct dsi_lane_map *lane_map)
  15. {
  16. u32 reg_value = lane_map->lane_map_v2[DSI_LOGICAL_LANE_0] |
  17. (lane_map->lane_map_v2[DSI_LOGICAL_LANE_1] << 4) |
  18. (lane_map->lane_map_v2[DSI_LOGICAL_LANE_2] << 8) |
  19. (lane_map->lane_map_v2[DSI_LOGICAL_LANE_3] << 12);
  20. DSI_W32(ctrl, DSI_LANE_SWAP_CTRL, reg_value);
  21. DSI_CTRL_HW_DBG(ctrl, "[DSI_%d] Lane swap setup complete\n",
  22. ctrl->index);
  23. }
  24. int dsi_ctrl_hw_22_wait_for_lane_idle(struct dsi_ctrl_hw *ctrl,
  25. u32 lanes)
  26. {
  27. int rc = 0, val = 0;
  28. u32 fifo_empty_mask = 0;
  29. u32 const sleep_us = 10;
  30. u32 const timeout_us = 100;
  31. if (lanes & DSI_DATA_LANE_0)
  32. fifo_empty_mask |= (BIT(12) | BIT(16));
  33. if (lanes & DSI_DATA_LANE_1)
  34. fifo_empty_mask |= BIT(20);
  35. if (lanes & DSI_DATA_LANE_2)
  36. fifo_empty_mask |= BIT(24);
  37. if (lanes & DSI_DATA_LANE_3)
  38. fifo_empty_mask |= BIT(28);
  39. DSI_CTRL_HW_DBG(ctrl, "%s: polling for fifo empty, mask=0x%08x\n",
  40. __func__, fifo_empty_mask);
  41. rc = readl_poll_timeout(ctrl->base + DSI_FIFO_STATUS, val,
  42. (val & fifo_empty_mask), sleep_us, timeout_us);
  43. if (rc) {
  44. DSI_CTRL_HW_ERR(ctrl,
  45. "%s: fifo not empty, FIFO_STATUS=0x%08x\n",
  46. __func__, val);
  47. goto error;
  48. }
  49. error:
  50. return rc;
  51. }
  52. ssize_t dsi_ctrl_hw_22_reg_dump_to_buffer(struct dsi_ctrl_hw *ctrl,
  53. char *buf,
  54. u32 size)
  55. {
  56. return size;
  57. }
  58. /**
  59. * dsi_ctrl_hw_22_phy_reset_config() - to configure clamp control during ulps
  60. * @ctrl: Pointer to the controller host hardware.
  61. * @enable: boolean to specify enable/disable.
  62. */
  63. void dsi_ctrl_hw_22_phy_reset_config(struct dsi_ctrl_hw *ctrl,
  64. bool enable)
  65. {
  66. u32 reg = 0;
  67. reg = DSI_DISP_CC_R32(ctrl, DISP_CC_MISC_CMD_REG_OFF);
  68. /* Mask/unmask disable PHY reset bit */
  69. if (enable)
  70. reg &= ~BIT(ctrl->index);
  71. else
  72. reg |= BIT(ctrl->index);
  73. DSI_DISP_CC_W32(ctrl, DISP_CC_MISC_CMD_REG_OFF, reg);
  74. }
  75. /**
  76. * dsi_ctrl_hw_22_schedule_dma_cmd() - to schedule DMA command transfer
  77. * @ctrl: Pointer to the controller host hardware.
  78. * @line_no: Line number at which command needs to be sent.
  79. */
  80. void dsi_ctrl_hw_22_schedule_dma_cmd(struct dsi_ctrl_hw *ctrl, int line_no)
  81. {
  82. u32 reg = 0;
  83. reg = DSI_R32(ctrl, DSI_DMA_SCHEDULE_CTRL);
  84. reg |= BIT(28);
  85. reg |= (line_no & 0xffff);
  86. DSI_W32(ctrl, DSI_DMA_SCHEDULE_CTRL, reg);
  87. }
  88. /*
  89. * dsi_ctrl_hw_kickoff_non_embedded_mode()-Kickoff cmd in non-embedded mode
  90. * @ctrl: - Pointer to the controller host hardware.
  91. * @dsi_ctrl_cmd_dma_info: - command buffer information.
  92. * @flags: - DSI CTRL Flags.
  93. */
  94. void dsi_ctrl_hw_kickoff_non_embedded_mode(struct dsi_ctrl_hw *ctrl,
  95. struct dsi_ctrl_cmd_dma_info *cmd,
  96. u32 flags)
  97. {
  98. u32 reg = 0;
  99. reg = DSI_R32(ctrl, DSI_COMMAND_MODE_DMA_CTRL);
  100. reg &= ~BIT(31);/* disable broadcast */
  101. reg &= ~BIT(30);
  102. if (cmd->use_lpm)
  103. reg |= BIT(26);
  104. else
  105. reg &= ~BIT(26);
  106. /* Select non EMBEDDED_MODE, pick the packet header from register */
  107. reg &= ~BIT(28);
  108. reg |= BIT(24);/* long packet */
  109. reg |= BIT(29);/* wc_sel = 1 */
  110. reg |= (((cmd->datatype) & 0x03f) << 16);/* data type */
  111. DSI_W32(ctrl, DSI_COMMAND_MODE_DMA_CTRL, reg);
  112. /* Enable WRITE_WATERMARK_DISABLE and READ_WATERMARK_DISABLE bits */
  113. reg = DSI_R32(ctrl, DSI_DMA_FIFO_CTRL);
  114. reg |= BIT(20);
  115. reg |= BIT(16);
  116. reg |= 0x33;/* Set READ and WRITE watermark levels to maximum */
  117. DSI_W32(ctrl, DSI_DMA_FIFO_CTRL, reg);
  118. DSI_W32(ctrl, DSI_DMA_CMD_OFFSET, cmd->offset);
  119. DSI_W32(ctrl, DSI_DMA_CMD_LENGTH, ((cmd->length) & 0xFFFFFF));
  120. /* wait for writes to complete before kick off */
  121. wmb();
  122. if (!(flags & DSI_CTRL_HW_CMD_WAIT_FOR_TRIGGER))
  123. DSI_W32(ctrl, DSI_CMD_MODE_DMA_SW_TRIGGER, 0x1);
  124. }
  125. /*
  126. * dsi_ctrl_hw_22_config_clk_gating() - enable/disable clk gating on DSI PHY
  127. * @ctrl: Pointer to the controller host hardware.
  128. * @enable: bool to notify enable/disable.
  129. * @clk_selection: clock to enable/disable clock gating.
  130. *
  131. */
  132. void dsi_ctrl_hw_22_config_clk_gating(struct dsi_ctrl_hw *ctrl, bool enable,
  133. enum dsi_clk_gate_type clk_selection)
  134. {
  135. u32 reg = 0;
  136. u32 enable_select = 0;
  137. reg = DSI_DISP_CC_R32(ctrl, DISP_CC_MISC_CMD_REG_OFF);
  138. if (clk_selection & PIXEL_CLK)
  139. enable_select |= ctrl->index ? BIT(6) : BIT(5);
  140. if (clk_selection & BYTE_CLK)
  141. enable_select |= ctrl->index ? BIT(8) : BIT(7);
  142. if (clk_selection & DSI_PHY)
  143. enable_select |= ctrl->index ? BIT(10) : BIT(9);
  144. if (enable)
  145. reg |= enable_select;
  146. else
  147. reg &= ~enable_select;
  148. DSI_DISP_CC_W32(ctrl, DISP_CC_MISC_CMD_REG_OFF, reg);
  149. }