sde_hw_lm.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2015-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/iopoll.h>
  6. #include "sde_kms.h"
  7. #include "sde_hw_catalog.h"
  8. #include "sde_hwio.h"
  9. #include "sde_hw_lm.h"
  10. #include "sde_hw_mdss.h"
  11. #include "sde_dbg.h"
  12. #include "sde_kms.h"
  13. #define LM_OP_MODE 0x00
  14. #define LM_OUT_SIZE 0x04
  15. #define LM_BORDER_COLOR_0 0x08
  16. #define LM_BORDER_COLOR_1 0x010
  17. /* These register are offset to mixer base + stage base */
  18. #define LM_BLEND0_OP 0x00
  19. #define LM_BLEND0_CONST_ALPHA 0x04
  20. #define LM_FG_COLOR_FILL_COLOR_0 0x08
  21. #define LM_FG_COLOR_FILL_COLOR_1 0x0C
  22. #define LM_FG_COLOR_FILL_SIZE 0x10
  23. #define LM_FG_COLOR_FILL_XY 0x14
  24. #define LM_BLEND0_FG_ALPHA 0x04
  25. #define LM_BLEND0_BG_ALPHA 0x08
  26. #define LM_MISR_CTRL 0x310
  27. #define LM_MISR_SIGNATURE 0x314
  28. static struct sde_lm_cfg *_lm_offset(enum sde_lm mixer,
  29. struct sde_mdss_cfg *m,
  30. void __iomem *addr,
  31. struct sde_hw_blk_reg_map *b)
  32. {
  33. int i;
  34. for (i = 0; i < m->mixer_count; i++) {
  35. if (mixer == m->mixer[i].id) {
  36. b->base_off = addr;
  37. b->blk_off = m->mixer[i].base;
  38. b->length = m->mixer[i].len;
  39. b->hwversion = m->hwversion;
  40. b->log_mask = SDE_DBG_MASK_LM;
  41. return &m->mixer[i];
  42. }
  43. }
  44. return ERR_PTR(-ENOMEM);
  45. }
  46. /**
  47. * _stage_offset(): returns the relative offset of the blend registers
  48. * for the stage to be setup
  49. * @c: mixer ctx contains the mixer to be programmed
  50. * @stage: stage index to setup
  51. */
  52. static inline int _stage_offset(struct sde_hw_mixer *ctx, enum sde_stage stage)
  53. {
  54. const struct sde_lm_sub_blks *sblk = ctx->cap->sblk;
  55. int rc;
  56. if (stage == SDE_STAGE_BASE)
  57. rc = -EINVAL;
  58. else if (stage <= sblk->maxblendstages)
  59. rc = sblk->blendstage_base[stage - SDE_STAGE_0];
  60. else
  61. rc = -EINVAL;
  62. return rc;
  63. }
  64. static void sde_hw_lm_setup_out(struct sde_hw_mixer *ctx,
  65. struct sde_hw_mixer_cfg *mixer)
  66. {
  67. struct sde_hw_blk_reg_map *c = &ctx->hw;
  68. u32 outsize;
  69. u32 op_mode;
  70. op_mode = SDE_REG_READ(c, LM_OP_MODE);
  71. outsize = mixer->out_height << 16 | mixer->out_width;
  72. SDE_REG_WRITE(c, LM_OUT_SIZE, outsize);
  73. /* SPLIT_LEFT_RIGHT */
  74. if (mixer->right_mixer)
  75. op_mode |= BIT(31);
  76. else
  77. op_mode &= ~BIT(31);
  78. SDE_REG_WRITE(c, LM_OP_MODE, op_mode);
  79. }
  80. static void sde_hw_lm_setup_border_color(struct sde_hw_mixer *ctx,
  81. struct sde_mdss_color *color,
  82. u8 border_en)
  83. {
  84. struct sde_hw_blk_reg_map *c = &ctx->hw;
  85. if (border_en) {
  86. SDE_REG_WRITE(c, LM_BORDER_COLOR_0,
  87. (color->color_0 & 0xFFF) |
  88. ((color->color_1 & 0xFFF) << 0x10));
  89. SDE_REG_WRITE(c, LM_BORDER_COLOR_1,
  90. (color->color_2 & 0xFFF) |
  91. ((color->color_3 & 0xFFF) << 0x10));
  92. }
  93. }
  94. static void sde_hw_lm_setup_blend_config_sdm845(struct sde_hw_mixer *ctx,
  95. u32 stage, u32 fg_alpha, u32 bg_alpha, u32 blend_op)
  96. {
  97. struct sde_hw_blk_reg_map *c = &ctx->hw;
  98. int stage_off;
  99. u32 const_alpha;
  100. if (stage == SDE_STAGE_BASE)
  101. return;
  102. stage_off = _stage_offset(ctx, stage);
  103. if (WARN_ON(stage_off < 0))
  104. return;
  105. const_alpha = (bg_alpha & 0xFF) | ((fg_alpha & 0xFF) << 16);
  106. SDE_REG_WRITE(c, LM_BLEND0_CONST_ALPHA + stage_off, const_alpha);
  107. SDE_REG_WRITE(c, LM_BLEND0_OP + stage_off, blend_op);
  108. }
  109. static void sde_hw_lm_setup_blend_config(struct sde_hw_mixer *ctx,
  110. u32 stage, u32 fg_alpha, u32 bg_alpha, u32 blend_op)
  111. {
  112. struct sde_hw_blk_reg_map *c = &ctx->hw;
  113. int stage_off;
  114. if (stage == SDE_STAGE_BASE)
  115. return;
  116. stage_off = _stage_offset(ctx, stage);
  117. if (WARN_ON(stage_off < 0))
  118. return;
  119. SDE_REG_WRITE(c, LM_BLEND0_FG_ALPHA + stage_off, fg_alpha);
  120. SDE_REG_WRITE(c, LM_BLEND0_BG_ALPHA + stage_off, bg_alpha);
  121. SDE_REG_WRITE(c, LM_BLEND0_OP + stage_off, blend_op);
  122. }
  123. static void sde_hw_lm_setup_color3(struct sde_hw_mixer *ctx,
  124. uint32_t mixer_op_mode)
  125. {
  126. struct sde_hw_blk_reg_map *c = &ctx->hw;
  127. int op_mode;
  128. /* read the existing op_mode configuration */
  129. op_mode = SDE_REG_READ(c, LM_OP_MODE);
  130. op_mode = (op_mode & (BIT(31) | BIT(30))) | mixer_op_mode;
  131. SDE_REG_WRITE(c, LM_OP_MODE, op_mode);
  132. }
  133. static void sde_hw_lm_gc(struct sde_hw_mixer *mixer,
  134. void *cfg)
  135. {
  136. }
  137. static void sde_hw_lm_clear_dim_layer(struct sde_hw_mixer *ctx)
  138. {
  139. struct sde_hw_blk_reg_map *c = &ctx->hw;
  140. const struct sde_lm_sub_blks *sblk = ctx->cap->sblk;
  141. int stage_off, i;
  142. u32 reset = BIT(16), val;
  143. reset = ~reset;
  144. for (i = SDE_STAGE_0; i <= sblk->maxblendstages; i++) {
  145. stage_off = _stage_offset(ctx, i);
  146. if (WARN_ON(stage_off < 0))
  147. return;
  148. /*
  149. * read the existing blendn_op register and clear only DIM layer
  150. * bit (color_fill bit)
  151. */
  152. val = SDE_REG_READ(c, LM_BLEND0_OP + stage_off);
  153. val &= reset;
  154. SDE_REG_WRITE(c, LM_BLEND0_OP + stage_off, val);
  155. }
  156. }
  157. static void sde_hw_lm_setup_dim_layer(struct sde_hw_mixer *ctx,
  158. struct sde_hw_dim_layer *dim_layer)
  159. {
  160. struct sde_hw_blk_reg_map *c = &ctx->hw;
  161. int stage_off;
  162. u32 val = 0, alpha = 0;
  163. stage_off = _stage_offset(ctx, dim_layer->stage);
  164. if (stage_off < 0) {
  165. SDE_ERROR("invalid stage_off:%d for dim layer\n", stage_off);
  166. return;
  167. }
  168. alpha = dim_layer->color_fill.color_3 & 0xFF;
  169. val = ((dim_layer->color_fill.color_1 << 2) & 0xFFF) << 16 |
  170. ((dim_layer->color_fill.color_0 << 2) & 0xFFF);
  171. SDE_REG_WRITE(c, LM_FG_COLOR_FILL_COLOR_0 + stage_off, val);
  172. val = (alpha << 4) << 16 |
  173. ((dim_layer->color_fill.color_2 << 2) & 0xFFF);
  174. SDE_REG_WRITE(c, LM_FG_COLOR_FILL_COLOR_1 + stage_off, val);
  175. val = dim_layer->rect.h << 16 | dim_layer->rect.w;
  176. SDE_REG_WRITE(c, LM_FG_COLOR_FILL_SIZE + stage_off, val);
  177. val = dim_layer->rect.y << 16 | dim_layer->rect.x;
  178. SDE_REG_WRITE(c, LM_FG_COLOR_FILL_XY + stage_off, val);
  179. val = BIT(16); /* enable dim layer */
  180. val |= SDE_BLEND_FG_ALPHA_FG_CONST | SDE_BLEND_BG_ALPHA_BG_CONST;
  181. if (dim_layer->flags & SDE_DRM_DIM_LAYER_EXCLUSIVE)
  182. val |= BIT(17);
  183. else
  184. val &= ~BIT(17);
  185. SDE_REG_WRITE(c, LM_BLEND0_OP + stage_off, val);
  186. val = (alpha << 16) | (0xff - alpha);
  187. SDE_REG_WRITE(c, LM_BLEND0_CONST_ALPHA + stage_off, val);
  188. }
  189. static void sde_hw_lm_setup_misr(struct sde_hw_mixer *ctx,
  190. bool enable, u32 frame_count)
  191. {
  192. struct sde_hw_blk_reg_map *c = &ctx->hw;
  193. u32 config = 0;
  194. SDE_REG_WRITE(c, LM_MISR_CTRL, MISR_CTRL_STATUS_CLEAR);
  195. /* clear misr data */
  196. wmb();
  197. if (enable)
  198. config = (frame_count & MISR_FRAME_COUNT_MASK) |
  199. MISR_CTRL_ENABLE | INTF_MISR_CTRL_FREE_RUN_MASK;
  200. SDE_REG_WRITE(c, LM_MISR_CTRL, config);
  201. }
  202. static int sde_hw_lm_collect_misr(struct sde_hw_mixer *ctx, bool nonblock,
  203. u32 *misr_value)
  204. {
  205. struct sde_hw_blk_reg_map *c = &ctx->hw;
  206. u32 ctrl = 0;
  207. if (!misr_value)
  208. return -EINVAL;
  209. ctrl = SDE_REG_READ(c, LM_MISR_CTRL);
  210. if (!nonblock) {
  211. if (ctrl & MISR_CTRL_ENABLE) {
  212. int rc;
  213. rc = readl_poll_timeout(c->base_off + c->blk_off +
  214. LM_MISR_CTRL, ctrl,
  215. (ctrl & MISR_CTRL_STATUS) > 0, 500,
  216. 84000);
  217. if (rc)
  218. return rc;
  219. } else {
  220. return -EINVAL;
  221. }
  222. }
  223. *misr_value = SDE_REG_READ(c, LM_MISR_SIGNATURE);
  224. return 0;
  225. }
  226. static void _setup_mixer_ops(struct sde_mdss_cfg *m,
  227. struct sde_hw_lm_ops *ops,
  228. unsigned long features)
  229. {
  230. ops->setup_mixer_out = sde_hw_lm_setup_out;
  231. if (IS_SDM845_TARGET(m->hwversion) || IS_SDM670_TARGET(m->hwversion) ||
  232. IS_SM8150_TARGET(m->hwversion) ||
  233. IS_SDMSHRIKE_TARGET(m->hwversion) ||
  234. IS_SM6150_TARGET(m->hwversion) ||
  235. IS_SDMMAGPIE_TARGET(m->hwversion) ||
  236. IS_KONA_TARGET(m->hwversion) ||
  237. IS_SAIPAN_TARGET(m->hwversion) ||
  238. IS_SDMTRINKET_TARGET(m->hwversion))
  239. ops->setup_blend_config = sde_hw_lm_setup_blend_config_sdm845;
  240. else
  241. ops->setup_blend_config = sde_hw_lm_setup_blend_config;
  242. ops->setup_alpha_out = sde_hw_lm_setup_color3;
  243. ops->setup_border_color = sde_hw_lm_setup_border_color;
  244. ops->setup_gc = sde_hw_lm_gc;
  245. ops->setup_misr = sde_hw_lm_setup_misr;
  246. ops->collect_misr = sde_hw_lm_collect_misr;
  247. if (test_bit(SDE_DIM_LAYER, &features)) {
  248. ops->setup_dim_layer = sde_hw_lm_setup_dim_layer;
  249. ops->clear_dim_layer = sde_hw_lm_clear_dim_layer;
  250. }
  251. };
  252. static struct sde_hw_blk_ops sde_hw_ops = {
  253. .start = NULL,
  254. .stop = NULL,
  255. };
  256. struct sde_hw_mixer *sde_hw_lm_init(enum sde_lm idx,
  257. void __iomem *addr,
  258. struct sde_mdss_cfg *m)
  259. {
  260. struct sde_hw_mixer *c;
  261. struct sde_lm_cfg *cfg;
  262. int rc;
  263. c = kzalloc(sizeof(*c), GFP_KERNEL);
  264. if (!c)
  265. return ERR_PTR(-ENOMEM);
  266. cfg = _lm_offset(idx, m, addr, &c->hw);
  267. if (IS_ERR_OR_NULL(cfg)) {
  268. kfree(c);
  269. return ERR_PTR(-EINVAL);
  270. }
  271. /* Assign ops */
  272. c->idx = idx;
  273. c->cap = cfg;
  274. _setup_mixer_ops(m, &c->ops, c->cap->features);
  275. rc = sde_hw_blk_init(&c->base, SDE_HW_BLK_LM, idx, &sde_hw_ops);
  276. if (rc) {
  277. SDE_ERROR("failed to init hw blk %d\n", rc);
  278. goto blk_init_error;
  279. }
  280. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, cfg->name, c->hw.blk_off,
  281. c->hw.blk_off + c->hw.length, c->hw.xin_id);
  282. return c;
  283. blk_init_error:
  284. kzfree(c);
  285. return ERR_PTR(rc);
  286. }
  287. void sde_hw_lm_destroy(struct sde_hw_mixer *lm)
  288. {
  289. if (lm)
  290. sde_hw_blk_destroy(&lm->base);
  291. kfree(lm);
  292. }