ipuv3-plane.c 21 KB

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