sde_rotator_r1_ctl.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2015-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #define pr_fmt(fmt) "%s: " fmt, __func__
  6. #include <linux/errno.h>
  7. #include <linux/mutex.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/dma-mapping.h>
  10. #include <linux/delay.h>
  11. #include <linux/sort.h>
  12. #include <linux/clk.h>
  13. #include <linux/bitmap.h>
  14. #include "sde_rotator_r1_hwio.h"
  15. #include "sde_rotator_util.h"
  16. #include "sde_rotator_r1_internal.h"
  17. #include "sde_rotator_core.h"
  18. struct sde_mdp_ctl *sde_mdp_ctl_alloc(struct sde_rot_data_type *mdata,
  19. u32 off)
  20. {
  21. struct sde_mdp_ctl *ctl = NULL;
  22. static struct sde_mdp_ctl sde_ctl[5];
  23. static const u32 offset[] = {0x00002000, 0x00002200, 0x00002400,
  24. 0x00002600, 0x00002800};
  25. if (off >= ARRAY_SIZE(offset)) {
  26. SDEROT_ERR("invalid parameters\n");
  27. return ERR_PTR(-EINVAL);
  28. }
  29. ctl = &sde_ctl[off];
  30. ctl->mdata = mdata;
  31. ctl->num = off;
  32. ctl->offset = offset[ctl->num];
  33. ctl->base = mdata->sde_io.base + ctl->offset;
  34. return ctl;
  35. }
  36. int sde_mdp_ctl_free(struct sde_mdp_ctl *ctl)
  37. {
  38. if (!ctl)
  39. return -ENODEV;
  40. if (ctl->wb)
  41. sde_mdp_wb_free(ctl->wb);
  42. ctl->is_secure = false;
  43. ctl->mixer_left = NULL;
  44. ctl->mixer_right = NULL;
  45. ctl->wb = NULL;
  46. memset(&ctl->ops, 0, sizeof(ctl->ops));
  47. return 0;
  48. }
  49. struct sde_mdp_mixer *sde_mdp_mixer_assign(u32 id, bool wb)
  50. {
  51. struct sde_mdp_mixer *mixer = NULL;
  52. struct sde_rot_data_type *mdata = sde_rot_get_mdata();
  53. static struct sde_mdp_mixer sde_mixer[16];
  54. static const u32 offset[] = {0x00048000, 0x00049000};
  55. if (id >= ARRAY_SIZE(offset)) {
  56. SDEROT_ERR("invalid parameters\n");
  57. return ERR_PTR(-EINVAL);
  58. }
  59. mixer = &sde_mixer[id];
  60. mixer->num = id;
  61. mixer->offset = offset[mixer->num];
  62. mixer->base = mdata->sde_io.base + mixer->offset;
  63. return mixer;
  64. }
  65. static void sde_mdp_mixer_setup(struct sde_mdp_ctl *master_ctl,
  66. int mixer_mux)
  67. {
  68. int i;
  69. struct sde_mdp_ctl *ctl = NULL;
  70. struct sde_mdp_mixer *mixer = sde_mdp_mixer_get(master_ctl,
  71. mixer_mux);
  72. if (!mixer)
  73. return;
  74. ctl = mixer->ctl;
  75. if (!ctl)
  76. return;
  77. /* check if mixer setup for rotator is needed */
  78. if (mixer->rotator_mode) {
  79. int nmixers = 5;
  80. for (i = 0; i < nmixers; i++)
  81. sde_mdp_ctl_write(ctl, SDE_MDP_REG_CTL_LAYER(i), 0);
  82. return;
  83. }
  84. }
  85. struct sde_mdp_mixer *sde_mdp_mixer_get(struct sde_mdp_ctl *ctl, int mux)
  86. {
  87. struct sde_mdp_mixer *mixer = NULL;
  88. if (!ctl) {
  89. SDEROT_ERR("ctl not initialized\n");
  90. return NULL;
  91. }
  92. switch (mux) {
  93. case SDE_MDP_MIXER_MUX_DEFAULT:
  94. case SDE_MDP_MIXER_MUX_LEFT:
  95. mixer = ctl->mixer_left;
  96. break;
  97. case SDE_MDP_MIXER_MUX_RIGHT:
  98. mixer = ctl->mixer_right;
  99. break;
  100. }
  101. return mixer;
  102. }
  103. int sde_mdp_get_pipe_flush_bits(struct sde_mdp_pipe *pipe)
  104. {
  105. u32 flush_bits = 0;
  106. if (pipe->type == SDE_MDP_PIPE_TYPE_DMA)
  107. flush_bits |= BIT(pipe->num) << 5;
  108. else if (pipe->num == SDE_MDP_SSPP_VIG3 ||
  109. pipe->num == SDE_MDP_SSPP_RGB3)
  110. flush_bits |= BIT(pipe->num) << 10;
  111. else if (pipe->type == SDE_MDP_PIPE_TYPE_CURSOR)
  112. flush_bits |= BIT(22 + pipe->num - SDE_MDP_SSPP_CURSOR0);
  113. else /* RGB/VIG 0-2 pipes */
  114. flush_bits |= BIT(pipe->num);
  115. return flush_bits;
  116. }
  117. int sde_mdp_mixer_pipe_update(struct sde_mdp_pipe *pipe,
  118. struct sde_mdp_mixer *mixer, int params_changed)
  119. {
  120. struct sde_mdp_ctl *ctl;
  121. if (!pipe)
  122. return -EINVAL;
  123. if (!mixer)
  124. return -EINVAL;
  125. ctl = mixer->ctl;
  126. if (!ctl)
  127. return -EINVAL;
  128. ctl->flush_bits |= sde_mdp_get_pipe_flush_bits(pipe);
  129. return 0;
  130. }
  131. int sde_mdp_display_wait4comp(struct sde_mdp_ctl *ctl)
  132. {
  133. int ret = 0;
  134. if (!ctl) {
  135. SDEROT_ERR("invalid ctl\n");
  136. return -ENODEV;
  137. }
  138. if (ctl->ops.wait_fnc)
  139. ret = ctl->ops.wait_fnc(ctl, NULL);
  140. return ret;
  141. }
  142. int sde_mdp_display_commit(struct sde_mdp_ctl *ctl, void *arg,
  143. struct sde_mdp_commit_cb *commit_cb)
  144. {
  145. int ret = 0;
  146. u32 ctl_flush_bits = 0;
  147. if (!ctl) {
  148. SDEROT_ERR("display function not set\n");
  149. return -ENODEV;
  150. }
  151. if (ctl->ops.prepare_fnc)
  152. ret = ctl->ops.prepare_fnc(ctl, arg);
  153. if (ret) {
  154. SDEROT_ERR("error preparing display\n");
  155. goto done;
  156. }
  157. sde_mdp_mixer_setup(ctl, SDE_MDP_MIXER_MUX_LEFT);
  158. sde_mdp_mixer_setup(ctl, SDE_MDP_MIXER_MUX_RIGHT);
  159. sde_mdp_ctl_write(ctl, SDE_MDP_REG_CTL_TOP, ctl->opmode);
  160. ctl->flush_bits |= BIT(17); /* CTL */
  161. ctl_flush_bits = ctl->flush_bits;
  162. sde_mdp_ctl_write(ctl, SDE_MDP_REG_CTL_FLUSH, ctl_flush_bits);
  163. /* ensure the flush command is issued after the barrier */
  164. wmb();
  165. ctl->flush_reg_data = ctl_flush_bits;
  166. ctl->flush_bits = 0;
  167. if (ctl->ops.display_fnc)
  168. ret = ctl->ops.display_fnc(ctl, arg); /* DSI0 kickoff */
  169. if (ret)
  170. SDEROT_WARN("ctl %d error displaying frame\n", ctl->num);
  171. done:
  172. return ret;
  173. }
  174. /**
  175. * @sde_mdp_ctl_mixer_switch() - return ctl mixer of @return_type
  176. * @ctl: Pointer to ctl structure to be switched.
  177. * @return_type: wb_type of the ctl to be switched to.
  178. *
  179. * Virtual mixer switch should be performed only when there is no
  180. * dedicated wfd block and writeback block is shared.
  181. */
  182. struct sde_mdp_ctl *sde_mdp_ctl_mixer_switch(struct sde_mdp_ctl *ctl,
  183. u32 return_type)
  184. {
  185. if (ctl->wb_type == return_type)
  186. return ctl;
  187. SDEROT_ERR("unable to switch mixer to type=%d\n", return_type);
  188. return NULL;
  189. }
  190. struct sde_mdp_writeback *sde_mdp_wb_assign(u32 num, u32 reg_index)
  191. {
  192. struct sde_rot_data_type *mdata = sde_rot_get_mdata();
  193. struct sde_mdp_writeback *wb = NULL;
  194. static struct sde_mdp_writeback sde_wb[16];
  195. static const u32 offset[] = {0x00065000, 0x00065800, 0x00066000};
  196. if (num >= ARRAY_SIZE(offset)) {
  197. SDEROT_ERR("invalid parameters\n");
  198. return ERR_PTR(-EINVAL);
  199. }
  200. wb = &sde_wb[num];
  201. wb->num = num;
  202. wb->offset = offset[wb->num];
  203. if (!wb)
  204. return NULL;
  205. wb->base = mdata->sde_io.base;
  206. wb->base += wb->offset;
  207. return wb;
  208. }
  209. void sde_mdp_wb_free(struct sde_mdp_writeback *wb)
  210. {
  211. }