ipuv3-plane.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. /*
  2. * i.MX IPUv3 DP Overlay Planes
  3. *
  4. * Copyright (C) 2013 Philipp Zabel, Pengutronix
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <drm/drmP.h>
  16. #include <drm/drm_atomic.h>
  17. #include <drm/drm_atomic_helper.h>
  18. #include <drm/drm_fb_cma_helper.h>
  19. #include <drm/drm_gem_cma_helper.h>
  20. #include <drm/drm_plane_helper.h>
  21. #include "video/imx-ipu-v3.h"
  22. #include "ipuv3-plane.h"
  23. struct ipu_plane_state {
  24. struct drm_plane_state base;
  25. bool use_pre;
  26. };
  27. static inline struct ipu_plane_state *
  28. to_ipu_plane_state(struct drm_plane_state *p)
  29. {
  30. return container_of(p, struct ipu_plane_state, base);
  31. }
  32. static inline struct ipu_plane *to_ipu_plane(struct drm_plane *p)
  33. {
  34. return container_of(p, struct ipu_plane, base);
  35. }
  36. static const uint32_t ipu_plane_formats[] = {
  37. DRM_FORMAT_ARGB1555,
  38. DRM_FORMAT_XRGB1555,
  39. DRM_FORMAT_ABGR1555,
  40. DRM_FORMAT_XBGR1555,
  41. DRM_FORMAT_RGBA5551,
  42. DRM_FORMAT_BGRA5551,
  43. DRM_FORMAT_ARGB4444,
  44. DRM_FORMAT_ARGB8888,
  45. DRM_FORMAT_XRGB8888,
  46. DRM_FORMAT_ABGR8888,
  47. DRM_FORMAT_XBGR8888,
  48. DRM_FORMAT_RGBA8888,
  49. DRM_FORMAT_RGBX8888,
  50. DRM_FORMAT_BGRA8888,
  51. DRM_FORMAT_BGRA8888,
  52. DRM_FORMAT_UYVY,
  53. DRM_FORMAT_VYUY,
  54. DRM_FORMAT_YUYV,
  55. DRM_FORMAT_YVYU,
  56. DRM_FORMAT_YUV420,
  57. DRM_FORMAT_YVU420,
  58. DRM_FORMAT_YUV422,
  59. DRM_FORMAT_YVU422,
  60. DRM_FORMAT_YUV444,
  61. DRM_FORMAT_YVU444,
  62. DRM_FORMAT_NV12,
  63. DRM_FORMAT_NV16,
  64. DRM_FORMAT_RGB565,
  65. DRM_FORMAT_RGB565_A8,
  66. DRM_FORMAT_BGR565_A8,
  67. DRM_FORMAT_RGB888_A8,
  68. DRM_FORMAT_BGR888_A8,
  69. DRM_FORMAT_RGBX8888_A8,
  70. DRM_FORMAT_BGRX8888_A8,
  71. };
  72. int ipu_plane_irq(struct ipu_plane *ipu_plane)
  73. {
  74. return ipu_idmac_channel_irq(ipu_plane->ipu, ipu_plane->ipu_ch,
  75. IPU_IRQ_EOF);
  76. }
  77. static inline unsigned long
  78. drm_plane_state_to_eba(struct drm_plane_state *state, int plane)
  79. {
  80. struct drm_framebuffer *fb = state->fb;
  81. struct drm_gem_cma_object *cma_obj;
  82. int x = state->src.x1 >> 16;
  83. int y = state->src.y1 >> 16;
  84. cma_obj = drm_fb_cma_get_gem_obj(fb, plane);
  85. BUG_ON(!cma_obj);
  86. return cma_obj->paddr + fb->offsets[plane] + fb->pitches[plane] * y +
  87. fb->format->cpp[plane] * x;
  88. }
  89. static inline unsigned long
  90. drm_plane_state_to_ubo(struct drm_plane_state *state)
  91. {
  92. struct drm_framebuffer *fb = state->fb;
  93. struct drm_gem_cma_object *cma_obj;
  94. unsigned long eba = drm_plane_state_to_eba(state, 0);
  95. int x = state->src.x1 >> 16;
  96. int y = state->src.y1 >> 16;
  97. cma_obj = drm_fb_cma_get_gem_obj(fb, 1);
  98. BUG_ON(!cma_obj);
  99. x /= drm_format_horz_chroma_subsampling(fb->format->format);
  100. y /= drm_format_vert_chroma_subsampling(fb->format->format);
  101. return cma_obj->paddr + fb->offsets[1] + fb->pitches[1] * y +
  102. fb->format->cpp[1] * x - eba;
  103. }
  104. static inline unsigned long
  105. drm_plane_state_to_vbo(struct drm_plane_state *state)
  106. {
  107. struct drm_framebuffer *fb = state->fb;
  108. struct drm_gem_cma_object *cma_obj;
  109. unsigned long eba = drm_plane_state_to_eba(state, 0);
  110. int x = state->src.x1 >> 16;
  111. int y = state->src.y1 >> 16;
  112. cma_obj = drm_fb_cma_get_gem_obj(fb, 2);
  113. BUG_ON(!cma_obj);
  114. x /= drm_format_horz_chroma_subsampling(fb->format->format);
  115. y /= drm_format_vert_chroma_subsampling(fb->format->format);
  116. return cma_obj->paddr + fb->offsets[2] + fb->pitches[2] * y +
  117. fb->format->cpp[2] * x - eba;
  118. }
  119. void ipu_plane_put_resources(struct ipu_plane *ipu_plane)
  120. {
  121. if (!IS_ERR_OR_NULL(ipu_plane->dp))
  122. ipu_dp_put(ipu_plane->dp);
  123. if (!IS_ERR_OR_NULL(ipu_plane->dmfc))
  124. ipu_dmfc_put(ipu_plane->dmfc);
  125. if (!IS_ERR_OR_NULL(ipu_plane->ipu_ch))
  126. ipu_idmac_put(ipu_plane->ipu_ch);
  127. if (!IS_ERR_OR_NULL(ipu_plane->alpha_ch))
  128. ipu_idmac_put(ipu_plane->alpha_ch);
  129. }
  130. int ipu_plane_get_resources(struct ipu_plane *ipu_plane)
  131. {
  132. int ret;
  133. int alpha_ch;
  134. ipu_plane->ipu_ch = ipu_idmac_get(ipu_plane->ipu, ipu_plane->dma);
  135. if (IS_ERR(ipu_plane->ipu_ch)) {
  136. ret = PTR_ERR(ipu_plane->ipu_ch);
  137. DRM_ERROR("failed to get idmac channel: %d\n", ret);
  138. return ret;
  139. }
  140. alpha_ch = ipu_channel_alpha_channel(ipu_plane->dma);
  141. if (alpha_ch >= 0) {
  142. ipu_plane->alpha_ch = ipu_idmac_get(ipu_plane->ipu, alpha_ch);
  143. if (IS_ERR(ipu_plane->alpha_ch)) {
  144. ret = PTR_ERR(ipu_plane->alpha_ch);
  145. DRM_ERROR("failed to get alpha idmac channel %d: %d\n",
  146. alpha_ch, ret);
  147. return ret;
  148. }
  149. }
  150. ipu_plane->dmfc = ipu_dmfc_get(ipu_plane->ipu, ipu_plane->dma);
  151. if (IS_ERR(ipu_plane->dmfc)) {
  152. ret = PTR_ERR(ipu_plane->dmfc);
  153. DRM_ERROR("failed to get dmfc: ret %d\n", ret);
  154. goto err_out;
  155. }
  156. if (ipu_plane->dp_flow >= 0) {
  157. ipu_plane->dp = ipu_dp_get(ipu_plane->ipu, ipu_plane->dp_flow);
  158. if (IS_ERR(ipu_plane->dp)) {
  159. ret = PTR_ERR(ipu_plane->dp);
  160. DRM_ERROR("failed to get dp flow: %d\n", ret);
  161. goto err_out;
  162. }
  163. }
  164. return 0;
  165. err_out:
  166. ipu_plane_put_resources(ipu_plane);
  167. return ret;
  168. }
  169. static bool ipu_plane_separate_alpha(struct ipu_plane *ipu_plane)
  170. {
  171. switch (ipu_plane->base.state->fb->format->format) {
  172. case DRM_FORMAT_RGB565_A8:
  173. case DRM_FORMAT_BGR565_A8:
  174. case DRM_FORMAT_RGB888_A8:
  175. case DRM_FORMAT_BGR888_A8:
  176. case DRM_FORMAT_RGBX8888_A8:
  177. case DRM_FORMAT_BGRX8888_A8:
  178. return true;
  179. default:
  180. return false;
  181. }
  182. }
  183. static void ipu_plane_enable(struct ipu_plane *ipu_plane)
  184. {
  185. if (ipu_plane->dp)
  186. ipu_dp_enable(ipu_plane->ipu);
  187. ipu_dmfc_enable_channel(ipu_plane->dmfc);
  188. ipu_idmac_enable_channel(ipu_plane->ipu_ch);
  189. if (ipu_plane_separate_alpha(ipu_plane))
  190. ipu_idmac_enable_channel(ipu_plane->alpha_ch);
  191. if (ipu_plane->dp)
  192. ipu_dp_enable_channel(ipu_plane->dp);
  193. }
  194. void ipu_plane_disable(struct ipu_plane *ipu_plane, bool disable_dp_channel)
  195. {
  196. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  197. ipu_idmac_wait_busy(ipu_plane->ipu_ch, 50);
  198. if (ipu_plane->dp && disable_dp_channel)
  199. ipu_dp_disable_channel(ipu_plane->dp, false);
  200. ipu_idmac_disable_channel(ipu_plane->ipu_ch);
  201. if (ipu_plane->alpha_ch)
  202. ipu_idmac_disable_channel(ipu_plane->alpha_ch);
  203. ipu_dmfc_disable_channel(ipu_plane->dmfc);
  204. if (ipu_plane->dp)
  205. ipu_dp_disable(ipu_plane->ipu);
  206. if (ipu_prg_present(ipu_plane->ipu))
  207. ipu_prg_channel_disable(ipu_plane->ipu_ch);
  208. }
  209. void ipu_plane_disable_deferred(struct drm_plane *plane)
  210. {
  211. struct ipu_plane *ipu_plane = to_ipu_plane(plane);
  212. if (ipu_plane->disabling) {
  213. ipu_plane->disabling = false;
  214. ipu_plane_disable(ipu_plane, false);
  215. }
  216. }
  217. EXPORT_SYMBOL_GPL(ipu_plane_disable_deferred);
  218. static void ipu_plane_destroy(struct drm_plane *plane)
  219. {
  220. struct ipu_plane *ipu_plane = to_ipu_plane(plane);
  221. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  222. drm_plane_cleanup(plane);
  223. kfree(ipu_plane);
  224. }
  225. void ipu_plane_state_reset(struct drm_plane *plane)
  226. {
  227. struct ipu_plane_state *ipu_state;
  228. if (plane->state) {
  229. ipu_state = to_ipu_plane_state(plane->state);
  230. __drm_atomic_helper_plane_destroy_state(plane->state);
  231. kfree(ipu_state);
  232. }
  233. ipu_state = kzalloc(sizeof(*ipu_state), GFP_KERNEL);
  234. if (ipu_state) {
  235. ipu_state->base.plane = plane;
  236. ipu_state->base.rotation = DRM_ROTATE_0;
  237. }
  238. plane->state = &ipu_state->base;
  239. }
  240. struct drm_plane_state *ipu_plane_duplicate_state(struct drm_plane *plane)
  241. {
  242. struct ipu_plane_state *state;
  243. if (WARN_ON(!plane->state))
  244. return NULL;
  245. state = kmalloc(sizeof(*state), GFP_KERNEL);
  246. if (state)
  247. __drm_atomic_helper_plane_duplicate_state(plane, &state->base);
  248. return &state->base;
  249. }
  250. void ipu_plane_destroy_state(struct drm_plane *plane,
  251. struct drm_plane_state *state)
  252. {
  253. struct ipu_plane_state *ipu_state = to_ipu_plane_state(state);
  254. __drm_atomic_helper_plane_destroy_state(state);
  255. kfree(ipu_state);
  256. }
  257. static const struct drm_plane_funcs ipu_plane_funcs = {
  258. .update_plane = drm_atomic_helper_update_plane,
  259. .disable_plane = drm_atomic_helper_disable_plane,
  260. .destroy = ipu_plane_destroy,
  261. .reset = ipu_plane_state_reset,
  262. .atomic_duplicate_state = ipu_plane_duplicate_state,
  263. .atomic_destroy_state = ipu_plane_destroy_state,
  264. };
  265. static int ipu_plane_atomic_check(struct drm_plane *plane,
  266. struct drm_plane_state *state)
  267. {
  268. struct drm_plane_state *old_state = plane->state;
  269. struct drm_crtc_state *crtc_state;
  270. struct device *dev = plane->dev->dev;
  271. struct drm_framebuffer *fb = state->fb;
  272. struct drm_framebuffer *old_fb = old_state->fb;
  273. unsigned long eba, ubo, vbo, old_ubo, old_vbo, alpha_eba;
  274. bool can_position = (plane->type == DRM_PLANE_TYPE_OVERLAY);
  275. struct drm_rect clip;
  276. int hsub, vsub;
  277. int ret;
  278. /* Ok to disable */
  279. if (!fb)
  280. return 0;
  281. if (!state->crtc)
  282. return -EINVAL;
  283. crtc_state =
  284. drm_atomic_get_existing_crtc_state(state->state, state->crtc);
  285. if (WARN_ON(!crtc_state))
  286. return -EINVAL;
  287. clip.x1 = 0;
  288. clip.y1 = 0;
  289. clip.x2 = crtc_state->adjusted_mode.hdisplay;
  290. clip.y2 = crtc_state->adjusted_mode.vdisplay;
  291. ret = drm_plane_helper_check_state(state, &clip,
  292. DRM_PLANE_HELPER_NO_SCALING,
  293. DRM_PLANE_HELPER_NO_SCALING,
  294. can_position, true);
  295. if (ret)
  296. return ret;
  297. /* CRTC should be enabled */
  298. if (!crtc_state->enable)
  299. return -EINVAL;
  300. switch (plane->type) {
  301. case DRM_PLANE_TYPE_PRIMARY:
  302. /* full plane minimum width is 13 pixels */
  303. if (drm_rect_width(&state->dst) < 13)
  304. return -EINVAL;
  305. break;
  306. case DRM_PLANE_TYPE_OVERLAY:
  307. break;
  308. default:
  309. dev_warn(dev, "Unsupported plane type %d\n", plane->type);
  310. return -EINVAL;
  311. }
  312. if (drm_rect_height(&state->dst) < 2)
  313. return -EINVAL;
  314. /*
  315. * We support resizing active plane or changing its format by
  316. * forcing CRTC mode change in plane's ->atomic_check callback
  317. * and disabling all affected active planes in CRTC's ->atomic_disable
  318. * callback. The planes will be reenabled in plane's ->atomic_update
  319. * callback.
  320. */
  321. if (old_fb &&
  322. (drm_rect_width(&state->dst) != drm_rect_width(&old_state->dst) ||
  323. drm_rect_height(&state->dst) != drm_rect_height(&old_state->dst) ||
  324. fb->format != old_fb->format))
  325. crtc_state->mode_changed = true;
  326. eba = drm_plane_state_to_eba(state, 0);
  327. if (eba & 0x7)
  328. return -EINVAL;
  329. if (fb->pitches[0] < 1 || fb->pitches[0] > 16384)
  330. return -EINVAL;
  331. if (old_fb && fb->pitches[0] != old_fb->pitches[0])
  332. crtc_state->mode_changed = true;
  333. switch (fb->format->format) {
  334. case DRM_FORMAT_YUV420:
  335. case DRM_FORMAT_YVU420:
  336. case DRM_FORMAT_YUV422:
  337. case DRM_FORMAT_YVU422:
  338. case DRM_FORMAT_YUV444:
  339. case DRM_FORMAT_YVU444:
  340. /*
  341. * Multiplanar formats have to meet the following restrictions:
  342. * - The (up to) three plane addresses are EBA, EBA+UBO, EBA+VBO
  343. * - EBA, UBO and VBO are a multiple of 8
  344. * - UBO and VBO are unsigned and not larger than 0xfffff8
  345. * - Only EBA may be changed while scanout is active
  346. * - The strides of U and V planes must be identical.
  347. */
  348. vbo = drm_plane_state_to_vbo(state);
  349. if (vbo & 0x7 || vbo > 0xfffff8)
  350. return -EINVAL;
  351. if (old_fb && (fb->format == old_fb->format)) {
  352. old_vbo = drm_plane_state_to_vbo(old_state);
  353. if (vbo != old_vbo)
  354. crtc_state->mode_changed = true;
  355. }
  356. if (fb->pitches[1] != fb->pitches[2])
  357. return -EINVAL;
  358. /* fall-through */
  359. case DRM_FORMAT_NV12:
  360. case DRM_FORMAT_NV16:
  361. ubo = drm_plane_state_to_ubo(state);
  362. if (ubo & 0x7 || ubo > 0xfffff8)
  363. return -EINVAL;
  364. if (old_fb && (fb->format == old_fb->format)) {
  365. old_ubo = drm_plane_state_to_ubo(old_state);
  366. if (ubo != old_ubo)
  367. crtc_state->mode_changed = true;
  368. }
  369. if (fb->pitches[1] < 1 || fb->pitches[1] > 16384)
  370. return -EINVAL;
  371. if (old_fb && old_fb->pitches[1] != fb->pitches[1])
  372. crtc_state->mode_changed = true;
  373. /*
  374. * The x/y offsets must be even in case of horizontal/vertical
  375. * chroma subsampling.
  376. */
  377. hsub = drm_format_horz_chroma_subsampling(fb->format->format);
  378. vsub = drm_format_vert_chroma_subsampling(fb->format->format);
  379. if (((state->src.x1 >> 16) & (hsub - 1)) ||
  380. ((state->src.y1 >> 16) & (vsub - 1)))
  381. return -EINVAL;
  382. break;
  383. case DRM_FORMAT_RGB565_A8:
  384. case DRM_FORMAT_BGR565_A8:
  385. case DRM_FORMAT_RGB888_A8:
  386. case DRM_FORMAT_BGR888_A8:
  387. case DRM_FORMAT_RGBX8888_A8:
  388. case DRM_FORMAT_BGRX8888_A8:
  389. alpha_eba = drm_plane_state_to_eba(state, 1);
  390. if (alpha_eba & 0x7)
  391. return -EINVAL;
  392. if (fb->pitches[1] < 1 || fb->pitches[1] > 16384)
  393. return -EINVAL;
  394. if (old_fb && old_fb->pitches[1] != fb->pitches[1])
  395. crtc_state->mode_changed = true;
  396. break;
  397. }
  398. return 0;
  399. }
  400. static void ipu_plane_atomic_disable(struct drm_plane *plane,
  401. struct drm_plane_state *old_state)
  402. {
  403. struct ipu_plane *ipu_plane = to_ipu_plane(plane);
  404. if (ipu_plane->dp)
  405. ipu_dp_disable_channel(ipu_plane->dp, true);
  406. ipu_plane->disabling = true;
  407. }
  408. static int ipu_chan_assign_axi_id(int ipu_chan)
  409. {
  410. switch (ipu_chan) {
  411. case IPUV3_CHANNEL_MEM_BG_SYNC:
  412. return 1;
  413. case IPUV3_CHANNEL_MEM_FG_SYNC:
  414. return 2;
  415. case IPUV3_CHANNEL_MEM_DC_SYNC:
  416. return 3;
  417. default:
  418. return 0;
  419. }
  420. }
  421. static void ipu_plane_atomic_update(struct drm_plane *plane,
  422. struct drm_plane_state *old_state)
  423. {
  424. struct ipu_plane *ipu_plane = to_ipu_plane(plane);
  425. struct drm_plane_state *state = plane->state;
  426. struct ipu_plane_state *ipu_state = to_ipu_plane_state(state);
  427. struct drm_crtc_state *crtc_state = state->crtc->state;
  428. struct drm_framebuffer *fb = state->fb;
  429. struct drm_rect *dst = &state->dst;
  430. unsigned long eba, ubo, vbo;
  431. unsigned long alpha_eba = 0;
  432. enum ipu_color_space ics;
  433. unsigned int axi_id = 0;
  434. int active;
  435. if (ipu_plane->dp_flow == IPU_DP_FLOW_SYNC_FG)
  436. ipu_dp_set_window_pos(ipu_plane->dp, dst->x1, dst->y1);
  437. eba = drm_plane_state_to_eba(state, 0);
  438. /*
  439. * Configure PRG channel and attached PRE, this changes the EBA to an
  440. * internal SRAM location.
  441. */
  442. if (ipu_state->use_pre) {
  443. axi_id = ipu_chan_assign_axi_id(ipu_plane->dma);
  444. ipu_prg_channel_configure(ipu_plane->ipu_ch, axi_id,
  445. drm_rect_width(&state->src) >> 16,
  446. drm_rect_height(&state->src) >> 16,
  447. state->fb->pitches[0],
  448. state->fb->format->format, &eba);
  449. }
  450. if (old_state->fb && !drm_atomic_crtc_needs_modeset(crtc_state)) {
  451. /* nothing to do if PRE is used */
  452. if (ipu_state->use_pre)
  453. return;
  454. active = ipu_idmac_get_current_buffer(ipu_plane->ipu_ch);
  455. ipu_cpmem_set_buffer(ipu_plane->ipu_ch, !active, eba);
  456. ipu_idmac_select_buffer(ipu_plane->ipu_ch, !active);
  457. if (ipu_plane_separate_alpha(ipu_plane)) {
  458. active = ipu_idmac_get_current_buffer(ipu_plane->alpha_ch);
  459. ipu_cpmem_set_buffer(ipu_plane->alpha_ch, !active,
  460. alpha_eba);
  461. ipu_idmac_select_buffer(ipu_plane->alpha_ch, !active);
  462. }
  463. return;
  464. }
  465. switch (ipu_plane->dp_flow) {
  466. case IPU_DP_FLOW_SYNC_BG:
  467. ipu_dp_setup_channel(ipu_plane->dp,
  468. IPUV3_COLORSPACE_RGB,
  469. IPUV3_COLORSPACE_RGB);
  470. ipu_dp_set_global_alpha(ipu_plane->dp, true, 0, true);
  471. break;
  472. case IPU_DP_FLOW_SYNC_FG:
  473. ics = ipu_drm_fourcc_to_colorspace(state->fb->format->format);
  474. ipu_dp_setup_channel(ipu_plane->dp, ics,
  475. IPUV3_COLORSPACE_UNKNOWN);
  476. /* Enable local alpha on partial plane */
  477. switch (state->fb->format->format) {
  478. case DRM_FORMAT_ARGB1555:
  479. case DRM_FORMAT_ABGR1555:
  480. case DRM_FORMAT_RGBA5551:
  481. case DRM_FORMAT_BGRA5551:
  482. case DRM_FORMAT_ARGB4444:
  483. case DRM_FORMAT_ARGB8888:
  484. case DRM_FORMAT_ABGR8888:
  485. case DRM_FORMAT_RGBA8888:
  486. case DRM_FORMAT_BGRA8888:
  487. case DRM_FORMAT_RGB565_A8:
  488. case DRM_FORMAT_BGR565_A8:
  489. case DRM_FORMAT_RGB888_A8:
  490. case DRM_FORMAT_BGR888_A8:
  491. case DRM_FORMAT_RGBX8888_A8:
  492. case DRM_FORMAT_BGRX8888_A8:
  493. ipu_dp_set_global_alpha(ipu_plane->dp, false, 0, false);
  494. break;
  495. default:
  496. ipu_dp_set_global_alpha(ipu_plane->dp, true, 0, true);
  497. break;
  498. }
  499. }
  500. ipu_dmfc_config_wait4eot(ipu_plane->dmfc, drm_rect_width(dst));
  501. ipu_cpmem_zero(ipu_plane->ipu_ch);
  502. ipu_cpmem_set_resolution(ipu_plane->ipu_ch,
  503. drm_rect_width(&state->src) >> 16,
  504. drm_rect_height(&state->src) >> 16);
  505. ipu_cpmem_set_fmt(ipu_plane->ipu_ch, state->fb->format->format);
  506. ipu_cpmem_set_high_priority(ipu_plane->ipu_ch);
  507. ipu_idmac_set_double_buffer(ipu_plane->ipu_ch, 1);
  508. ipu_cpmem_set_stride(ipu_plane->ipu_ch, state->fb->pitches[0]);
  509. ipu_cpmem_set_axi_id(ipu_plane->ipu_ch, axi_id);
  510. switch (fb->format->format) {
  511. case DRM_FORMAT_YUV420:
  512. case DRM_FORMAT_YVU420:
  513. case DRM_FORMAT_YUV422:
  514. case DRM_FORMAT_YVU422:
  515. case DRM_FORMAT_YUV444:
  516. case DRM_FORMAT_YVU444:
  517. ubo = drm_plane_state_to_ubo(state);
  518. vbo = drm_plane_state_to_vbo(state);
  519. if (fb->format->format == DRM_FORMAT_YVU420 ||
  520. fb->format->format == DRM_FORMAT_YVU422 ||
  521. fb->format->format == DRM_FORMAT_YVU444)
  522. swap(ubo, vbo);
  523. ipu_cpmem_set_yuv_planar_full(ipu_plane->ipu_ch,
  524. fb->pitches[1], ubo, vbo);
  525. dev_dbg(ipu_plane->base.dev->dev,
  526. "phy = %lu %lu %lu, x = %d, y = %d", eba, ubo, vbo,
  527. state->src.x1 >> 16, state->src.y1 >> 16);
  528. break;
  529. case DRM_FORMAT_NV12:
  530. case DRM_FORMAT_NV16:
  531. ubo = drm_plane_state_to_ubo(state);
  532. ipu_cpmem_set_yuv_planar_full(ipu_plane->ipu_ch,
  533. fb->pitches[1], ubo, ubo);
  534. dev_dbg(ipu_plane->base.dev->dev,
  535. "phy = %lu %lu, x = %d, y = %d", eba, ubo,
  536. state->src.x1 >> 16, state->src.y1 >> 16);
  537. break;
  538. case DRM_FORMAT_RGB565_A8:
  539. case DRM_FORMAT_BGR565_A8:
  540. case DRM_FORMAT_RGB888_A8:
  541. case DRM_FORMAT_BGR888_A8:
  542. case DRM_FORMAT_RGBX8888_A8:
  543. case DRM_FORMAT_BGRX8888_A8:
  544. alpha_eba = drm_plane_state_to_eba(state, 1);
  545. dev_dbg(ipu_plane->base.dev->dev, "phys = %lu %lu, x = %d, y = %d",
  546. eba, alpha_eba, state->src.x1 >> 16, state->src.y1 >> 16);
  547. ipu_cpmem_set_burstsize(ipu_plane->ipu_ch, 16);
  548. ipu_cpmem_zero(ipu_plane->alpha_ch);
  549. ipu_cpmem_set_resolution(ipu_plane->alpha_ch,
  550. drm_rect_width(&state->src) >> 16,
  551. drm_rect_height(&state->src) >> 16);
  552. ipu_cpmem_set_format_passthrough(ipu_plane->alpha_ch, 8);
  553. ipu_cpmem_set_high_priority(ipu_plane->alpha_ch);
  554. ipu_idmac_set_double_buffer(ipu_plane->alpha_ch, 1);
  555. ipu_cpmem_set_stride(ipu_plane->alpha_ch,
  556. state->fb->pitches[1]);
  557. ipu_cpmem_set_burstsize(ipu_plane->alpha_ch, 16);
  558. ipu_cpmem_set_buffer(ipu_plane->alpha_ch, 0, alpha_eba);
  559. ipu_cpmem_set_buffer(ipu_plane->alpha_ch, 1, alpha_eba);
  560. break;
  561. default:
  562. dev_dbg(ipu_plane->base.dev->dev, "phys = %lu, x = %d, y = %d",
  563. eba, state->src.x1 >> 16, state->src.y1 >> 16);
  564. break;
  565. }
  566. ipu_cpmem_set_buffer(ipu_plane->ipu_ch, 0, eba);
  567. ipu_cpmem_set_buffer(ipu_plane->ipu_ch, 1, eba);
  568. ipu_plane_enable(ipu_plane);
  569. }
  570. static const struct drm_plane_helper_funcs ipu_plane_helper_funcs = {
  571. .prepare_fb = drm_fb_cma_prepare_fb,
  572. .atomic_check = ipu_plane_atomic_check,
  573. .atomic_disable = ipu_plane_atomic_disable,
  574. .atomic_update = ipu_plane_atomic_update,
  575. };
  576. int ipu_planes_assign_pre(struct drm_device *dev,
  577. struct drm_atomic_state *state)
  578. {
  579. struct drm_plane_state *plane_state;
  580. struct drm_plane *plane;
  581. int available_pres = ipu_prg_max_active_channels();
  582. int i;
  583. for_each_plane_in_state(state, plane, plane_state, i) {
  584. struct ipu_plane_state *ipu_state =
  585. to_ipu_plane_state(plane_state);
  586. struct ipu_plane *ipu_plane = to_ipu_plane(plane);
  587. if (ipu_prg_present(ipu_plane->ipu) && available_pres &&
  588. plane_state->fb &&
  589. ipu_prg_format_supported(ipu_plane->ipu,
  590. plane_state->fb->format->format,
  591. plane_state->fb->modifier)) {
  592. ipu_state->use_pre = true;
  593. available_pres--;
  594. } else {
  595. ipu_state->use_pre = false;
  596. }
  597. }
  598. return 0;
  599. }
  600. EXPORT_SYMBOL_GPL(ipu_planes_assign_pre);
  601. struct ipu_plane *ipu_plane_init(struct drm_device *dev, struct ipu_soc *ipu,
  602. int dma, int dp, unsigned int possible_crtcs,
  603. enum drm_plane_type type)
  604. {
  605. struct ipu_plane *ipu_plane;
  606. int ret;
  607. DRM_DEBUG_KMS("channel %d, dp flow %d, possible_crtcs=0x%x\n",
  608. dma, dp, possible_crtcs);
  609. ipu_plane = kzalloc(sizeof(*ipu_plane), GFP_KERNEL);
  610. if (!ipu_plane) {
  611. DRM_ERROR("failed to allocate plane\n");
  612. return ERR_PTR(-ENOMEM);
  613. }
  614. ipu_plane->ipu = ipu;
  615. ipu_plane->dma = dma;
  616. ipu_plane->dp_flow = dp;
  617. ret = drm_universal_plane_init(dev, &ipu_plane->base, possible_crtcs,
  618. &ipu_plane_funcs, ipu_plane_formats,
  619. ARRAY_SIZE(ipu_plane_formats), type,
  620. NULL);
  621. if (ret) {
  622. DRM_ERROR("failed to initialize plane\n");
  623. kfree(ipu_plane);
  624. return ERR_PTR(ret);
  625. }
  626. drm_plane_helper_add(&ipu_plane->base, &ipu_plane_helper_funcs);
  627. return ipu_plane;
  628. }