exynos7_drm_decon.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  1. /* drivers/gpu/drm/exynos/exynos7_drm_decon.c
  2. *
  3. * Copyright (C) 2014 Samsung Electronics Co.Ltd
  4. * Authors:
  5. * Akshu Agarwal <akshua@gmail.com>
  6. * Ajay Kumar <ajaykumar.rs@samsung.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. */
  14. #include <drm/drmP.h>
  15. #include <drm/exynos_drm.h>
  16. #include <linux/clk.h>
  17. #include <linux/component.h>
  18. #include <linux/kernel.h>
  19. #include <linux/of.h>
  20. #include <linux/of_address.h>
  21. #include <linux/of_device.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/pm_runtime.h>
  24. #include <video/of_display_timing.h>
  25. #include <video/of_videomode.h>
  26. #include <video/exynos7_decon.h>
  27. #include "exynos_drm_crtc.h"
  28. #include "exynos_drm_plane.h"
  29. #include "exynos_drm_drv.h"
  30. #include "exynos_drm_fbdev.h"
  31. #include "exynos_drm_iommu.h"
  32. /*
  33. * DECON stands for Display and Enhancement controller.
  34. */
  35. #define MIN_FB_WIDTH_FOR_16WORD_BURST 128
  36. #define WINDOWS_NR 2
  37. #define CURSOR_WIN 1
  38. struct decon_context {
  39. struct device *dev;
  40. struct drm_device *drm_dev;
  41. struct exynos_drm_crtc *crtc;
  42. struct exynos_drm_plane planes[WINDOWS_NR];
  43. struct clk *pclk;
  44. struct clk *aclk;
  45. struct clk *eclk;
  46. struct clk *vclk;
  47. void __iomem *regs;
  48. unsigned long irq_flags;
  49. bool i80_if;
  50. bool suspended;
  51. int pipe;
  52. wait_queue_head_t wait_vsync_queue;
  53. atomic_t wait_vsync_event;
  54. struct exynos_drm_panel_info panel;
  55. struct drm_encoder *encoder;
  56. };
  57. static const struct of_device_id decon_driver_dt_match[] = {
  58. {.compatible = "samsung,exynos7-decon"},
  59. {},
  60. };
  61. MODULE_DEVICE_TABLE(of, decon_driver_dt_match);
  62. static const uint32_t decon_formats[] = {
  63. DRM_FORMAT_RGB565,
  64. DRM_FORMAT_XRGB8888,
  65. DRM_FORMAT_XBGR8888,
  66. DRM_FORMAT_RGBX8888,
  67. DRM_FORMAT_BGRX8888,
  68. DRM_FORMAT_ARGB8888,
  69. DRM_FORMAT_ABGR8888,
  70. DRM_FORMAT_RGBA8888,
  71. DRM_FORMAT_BGRA8888,
  72. };
  73. static void decon_wait_for_vblank(struct exynos_drm_crtc *crtc)
  74. {
  75. struct decon_context *ctx = crtc->ctx;
  76. if (ctx->suspended)
  77. return;
  78. atomic_set(&ctx->wait_vsync_event, 1);
  79. /*
  80. * wait for DECON to signal VSYNC interrupt or return after
  81. * timeout which is set to 50ms (refresh rate of 20).
  82. */
  83. if (!wait_event_timeout(ctx->wait_vsync_queue,
  84. !atomic_read(&ctx->wait_vsync_event),
  85. HZ/20))
  86. DRM_DEBUG_KMS("vblank wait timed out.\n");
  87. }
  88. static void decon_clear_channels(struct exynos_drm_crtc *crtc)
  89. {
  90. struct decon_context *ctx = crtc->ctx;
  91. unsigned int win, ch_enabled = 0;
  92. DRM_DEBUG_KMS("%s\n", __FILE__);
  93. /* Check if any channel is enabled. */
  94. for (win = 0; win < WINDOWS_NR; win++) {
  95. u32 val = readl(ctx->regs + WINCON(win));
  96. if (val & WINCONx_ENWIN) {
  97. val &= ~WINCONx_ENWIN;
  98. writel(val, ctx->regs + WINCON(win));
  99. ch_enabled = 1;
  100. }
  101. }
  102. /* Wait for vsync, as disable channel takes effect at next vsync */
  103. if (ch_enabled) {
  104. unsigned int state = ctx->suspended;
  105. ctx->suspended = 0;
  106. decon_wait_for_vblank(ctx->crtc);
  107. ctx->suspended = state;
  108. }
  109. }
  110. static int decon_ctx_initialize(struct decon_context *ctx,
  111. struct drm_device *drm_dev)
  112. {
  113. struct exynos_drm_private *priv = drm_dev->dev_private;
  114. int ret;
  115. ctx->drm_dev = drm_dev;
  116. ctx->pipe = priv->pipe++;
  117. decon_clear_channels(ctx->crtc);
  118. ret = drm_iommu_attach_device(drm_dev, ctx->dev);
  119. if (ret)
  120. priv->pipe--;
  121. return ret;
  122. }
  123. static void decon_ctx_remove(struct decon_context *ctx)
  124. {
  125. /* detach this sub driver from iommu mapping if supported. */
  126. drm_iommu_detach_device(ctx->drm_dev, ctx->dev);
  127. }
  128. static u32 decon_calc_clkdiv(struct decon_context *ctx,
  129. const struct drm_display_mode *mode)
  130. {
  131. unsigned long ideal_clk = mode->htotal * mode->vtotal * mode->vrefresh;
  132. u32 clkdiv;
  133. /* Find the clock divider value that gets us closest to ideal_clk */
  134. clkdiv = DIV_ROUND_UP(clk_get_rate(ctx->vclk), ideal_clk);
  135. return (clkdiv < 0x100) ? clkdiv : 0xff;
  136. }
  137. static void decon_commit(struct exynos_drm_crtc *crtc)
  138. {
  139. struct decon_context *ctx = crtc->ctx;
  140. struct drm_display_mode *mode = &crtc->base.state->adjusted_mode;
  141. u32 val, clkdiv;
  142. if (ctx->suspended)
  143. return;
  144. /* nothing to do if we haven't set the mode yet */
  145. if (mode->htotal == 0 || mode->vtotal == 0)
  146. return;
  147. if (!ctx->i80_if) {
  148. int vsync_len, vbpd, vfpd, hsync_len, hbpd, hfpd;
  149. /* setup vertical timing values. */
  150. vsync_len = mode->crtc_vsync_end - mode->crtc_vsync_start;
  151. vbpd = mode->crtc_vtotal - mode->crtc_vsync_end;
  152. vfpd = mode->crtc_vsync_start - mode->crtc_vdisplay;
  153. val = VIDTCON0_VBPD(vbpd - 1) | VIDTCON0_VFPD(vfpd - 1);
  154. writel(val, ctx->regs + VIDTCON0);
  155. val = VIDTCON1_VSPW(vsync_len - 1);
  156. writel(val, ctx->regs + VIDTCON1);
  157. /* setup horizontal timing values. */
  158. hsync_len = mode->crtc_hsync_end - mode->crtc_hsync_start;
  159. hbpd = mode->crtc_htotal - mode->crtc_hsync_end;
  160. hfpd = mode->crtc_hsync_start - mode->crtc_hdisplay;
  161. /* setup horizontal timing values. */
  162. val = VIDTCON2_HBPD(hbpd - 1) | VIDTCON2_HFPD(hfpd - 1);
  163. writel(val, ctx->regs + VIDTCON2);
  164. val = VIDTCON3_HSPW(hsync_len - 1);
  165. writel(val, ctx->regs + VIDTCON3);
  166. }
  167. /* setup horizontal and vertical display size. */
  168. val = VIDTCON4_LINEVAL(mode->vdisplay - 1) |
  169. VIDTCON4_HOZVAL(mode->hdisplay - 1);
  170. writel(val, ctx->regs + VIDTCON4);
  171. writel(mode->vdisplay - 1, ctx->regs + LINECNT_OP_THRESHOLD);
  172. /*
  173. * fields of register with prefix '_F' would be updated
  174. * at vsync(same as dma start)
  175. */
  176. val = VIDCON0_ENVID | VIDCON0_ENVID_F;
  177. writel(val, ctx->regs + VIDCON0);
  178. clkdiv = decon_calc_clkdiv(ctx, mode);
  179. if (clkdiv > 1) {
  180. val = VCLKCON1_CLKVAL_NUM_VCLK(clkdiv - 1);
  181. writel(val, ctx->regs + VCLKCON1);
  182. writel(val, ctx->regs + VCLKCON2);
  183. }
  184. val = readl(ctx->regs + DECON_UPDATE);
  185. val |= DECON_UPDATE_STANDALONE_F;
  186. writel(val, ctx->regs + DECON_UPDATE);
  187. }
  188. static int decon_enable_vblank(struct exynos_drm_crtc *crtc)
  189. {
  190. struct decon_context *ctx = crtc->ctx;
  191. u32 val;
  192. if (ctx->suspended)
  193. return -EPERM;
  194. if (!test_and_set_bit(0, &ctx->irq_flags)) {
  195. val = readl(ctx->regs + VIDINTCON0);
  196. val |= VIDINTCON0_INT_ENABLE;
  197. if (!ctx->i80_if) {
  198. val |= VIDINTCON0_INT_FRAME;
  199. val &= ~VIDINTCON0_FRAMESEL0_MASK;
  200. val |= VIDINTCON0_FRAMESEL0_VSYNC;
  201. }
  202. writel(val, ctx->regs + VIDINTCON0);
  203. }
  204. return 0;
  205. }
  206. static void decon_disable_vblank(struct exynos_drm_crtc *crtc)
  207. {
  208. struct decon_context *ctx = crtc->ctx;
  209. u32 val;
  210. if (ctx->suspended)
  211. return;
  212. if (test_and_clear_bit(0, &ctx->irq_flags)) {
  213. val = readl(ctx->regs + VIDINTCON0);
  214. val &= ~VIDINTCON0_INT_ENABLE;
  215. if (!ctx->i80_if)
  216. val &= ~VIDINTCON0_INT_FRAME;
  217. writel(val, ctx->regs + VIDINTCON0);
  218. }
  219. }
  220. static void decon_win_set_pixfmt(struct decon_context *ctx, unsigned int win,
  221. struct drm_framebuffer *fb)
  222. {
  223. unsigned long val;
  224. int padding;
  225. val = readl(ctx->regs + WINCON(win));
  226. val &= ~WINCONx_BPPMODE_MASK;
  227. switch (fb->pixel_format) {
  228. case DRM_FORMAT_RGB565:
  229. val |= WINCONx_BPPMODE_16BPP_565;
  230. val |= WINCONx_BURSTLEN_16WORD;
  231. break;
  232. case DRM_FORMAT_XRGB8888:
  233. val |= WINCONx_BPPMODE_24BPP_xRGB;
  234. val |= WINCONx_BURSTLEN_16WORD;
  235. break;
  236. case DRM_FORMAT_XBGR8888:
  237. val |= WINCONx_BPPMODE_24BPP_xBGR;
  238. val |= WINCONx_BURSTLEN_16WORD;
  239. break;
  240. case DRM_FORMAT_RGBX8888:
  241. val |= WINCONx_BPPMODE_24BPP_RGBx;
  242. val |= WINCONx_BURSTLEN_16WORD;
  243. break;
  244. case DRM_FORMAT_BGRX8888:
  245. val |= WINCONx_BPPMODE_24BPP_BGRx;
  246. val |= WINCONx_BURSTLEN_16WORD;
  247. break;
  248. case DRM_FORMAT_ARGB8888:
  249. val |= WINCONx_BPPMODE_32BPP_ARGB | WINCONx_BLD_PIX |
  250. WINCONx_ALPHA_SEL;
  251. val |= WINCONx_BURSTLEN_16WORD;
  252. break;
  253. case DRM_FORMAT_ABGR8888:
  254. val |= WINCONx_BPPMODE_32BPP_ABGR | WINCONx_BLD_PIX |
  255. WINCONx_ALPHA_SEL;
  256. val |= WINCONx_BURSTLEN_16WORD;
  257. break;
  258. case DRM_FORMAT_RGBA8888:
  259. val |= WINCONx_BPPMODE_32BPP_RGBA | WINCONx_BLD_PIX |
  260. WINCONx_ALPHA_SEL;
  261. val |= WINCONx_BURSTLEN_16WORD;
  262. break;
  263. case DRM_FORMAT_BGRA8888:
  264. val |= WINCONx_BPPMODE_32BPP_BGRA | WINCONx_BLD_PIX |
  265. WINCONx_ALPHA_SEL;
  266. val |= WINCONx_BURSTLEN_16WORD;
  267. break;
  268. default:
  269. DRM_DEBUG_KMS("invalid pixel size so using unpacked 24bpp.\n");
  270. val |= WINCONx_BPPMODE_24BPP_xRGB;
  271. val |= WINCONx_BURSTLEN_16WORD;
  272. break;
  273. }
  274. DRM_DEBUG_KMS("bpp = %d\n", fb->bits_per_pixel);
  275. /*
  276. * In case of exynos, setting dma-burst to 16Word causes permanent
  277. * tearing for very small buffers, e.g. cursor buffer. Burst Mode
  278. * switching which is based on plane size is not recommended as
  279. * plane size varies a lot towards the end of the screen and rapid
  280. * movement causes unstable DMA which results into iommu crash/tear.
  281. */
  282. padding = (fb->pitches[0] / (fb->bits_per_pixel >> 3)) - fb->width;
  283. if (fb->width + padding < MIN_FB_WIDTH_FOR_16WORD_BURST) {
  284. val &= ~WINCONx_BURSTLEN_MASK;
  285. val |= WINCONx_BURSTLEN_8WORD;
  286. }
  287. writel(val, ctx->regs + WINCON(win));
  288. }
  289. static void decon_win_set_colkey(struct decon_context *ctx, unsigned int win)
  290. {
  291. unsigned int keycon0 = 0, keycon1 = 0;
  292. keycon0 = ~(WxKEYCON0_KEYBL_EN | WxKEYCON0_KEYEN_F |
  293. WxKEYCON0_DIRCON) | WxKEYCON0_COMPKEY(0);
  294. keycon1 = WxKEYCON1_COLVAL(0xffffffff);
  295. writel(keycon0, ctx->regs + WKEYCON0_BASE(win));
  296. writel(keycon1, ctx->regs + WKEYCON1_BASE(win));
  297. }
  298. /**
  299. * shadow_protect_win() - disable updating values from shadow registers at vsync
  300. *
  301. * @win: window to protect registers for
  302. * @protect: 1 to protect (disable updates)
  303. */
  304. static void decon_shadow_protect_win(struct decon_context *ctx,
  305. unsigned int win, bool protect)
  306. {
  307. u32 bits, val;
  308. bits = SHADOWCON_WINx_PROTECT(win);
  309. val = readl(ctx->regs + SHADOWCON);
  310. if (protect)
  311. val |= bits;
  312. else
  313. val &= ~bits;
  314. writel(val, ctx->regs + SHADOWCON);
  315. }
  316. static void decon_atomic_begin(struct exynos_drm_crtc *crtc,
  317. struct exynos_drm_plane *plane)
  318. {
  319. struct decon_context *ctx = crtc->ctx;
  320. if (ctx->suspended)
  321. return;
  322. decon_shadow_protect_win(ctx, plane->zpos, true);
  323. }
  324. static void decon_update_plane(struct exynos_drm_crtc *crtc,
  325. struct exynos_drm_plane *plane)
  326. {
  327. struct decon_context *ctx = crtc->ctx;
  328. struct drm_display_mode *mode = &crtc->base.state->adjusted_mode;
  329. struct drm_plane_state *state = plane->base.state;
  330. int padding;
  331. unsigned long val, alpha;
  332. unsigned int last_x;
  333. unsigned int last_y;
  334. unsigned int win = plane->zpos;
  335. unsigned int bpp = state->fb->bits_per_pixel >> 3;
  336. unsigned int pitch = state->fb->pitches[0];
  337. if (ctx->suspended)
  338. return;
  339. /*
  340. * SHADOWCON/PRTCON register is used for enabling timing.
  341. *
  342. * for example, once only width value of a register is set,
  343. * if the dma is started then decon hardware could malfunction so
  344. * with protect window setting, the register fields with prefix '_F'
  345. * wouldn't be updated at vsync also but updated once unprotect window
  346. * is set.
  347. */
  348. /* buffer start address */
  349. val = (unsigned long)plane->dma_addr[0];
  350. writel(val, ctx->regs + VIDW_BUF_START(win));
  351. padding = (pitch / bpp) - state->fb->width;
  352. /* buffer size */
  353. writel(state->fb->width + padding, ctx->regs + VIDW_WHOLE_X(win));
  354. writel(state->fb->height, ctx->regs + VIDW_WHOLE_Y(win));
  355. /* offset from the start of the buffer to read */
  356. writel(plane->src_x, ctx->regs + VIDW_OFFSET_X(win));
  357. writel(plane->src_y, ctx->regs + VIDW_OFFSET_Y(win));
  358. DRM_DEBUG_KMS("start addr = 0x%lx\n",
  359. (unsigned long)val);
  360. DRM_DEBUG_KMS("ovl_width = %d, ovl_height = %d\n",
  361. plane->crtc_w, plane->crtc_h);
  362. /*
  363. * OSD position.
  364. * In case the window layout goes of LCD layout, DECON fails.
  365. */
  366. if ((plane->crtc_x + plane->crtc_w) > mode->hdisplay)
  367. plane->crtc_x = mode->hdisplay - plane->crtc_w;
  368. if ((plane->crtc_y + plane->crtc_h) > mode->vdisplay)
  369. plane->crtc_y = mode->vdisplay - plane->crtc_h;
  370. val = VIDOSDxA_TOPLEFT_X(plane->crtc_x) |
  371. VIDOSDxA_TOPLEFT_Y(plane->crtc_y);
  372. writel(val, ctx->regs + VIDOSD_A(win));
  373. last_x = plane->crtc_x + plane->crtc_w;
  374. if (last_x)
  375. last_x--;
  376. last_y = plane->crtc_y + plane->crtc_h;
  377. if (last_y)
  378. last_y--;
  379. val = VIDOSDxB_BOTRIGHT_X(last_x) | VIDOSDxB_BOTRIGHT_Y(last_y);
  380. writel(val, ctx->regs + VIDOSD_B(win));
  381. DRM_DEBUG_KMS("osd pos: tx = %d, ty = %d, bx = %d, by = %d\n",
  382. plane->crtc_x, plane->crtc_y, last_x, last_y);
  383. /* OSD alpha */
  384. alpha = VIDOSDxC_ALPHA0_R_F(0x0) |
  385. VIDOSDxC_ALPHA0_G_F(0x0) |
  386. VIDOSDxC_ALPHA0_B_F(0x0);
  387. writel(alpha, ctx->regs + VIDOSD_C(win));
  388. alpha = VIDOSDxD_ALPHA1_R_F(0xff) |
  389. VIDOSDxD_ALPHA1_G_F(0xff) |
  390. VIDOSDxD_ALPHA1_B_F(0xff);
  391. writel(alpha, ctx->regs + VIDOSD_D(win));
  392. decon_win_set_pixfmt(ctx, win, state->fb);
  393. /* hardware window 0 doesn't support color key. */
  394. if (win != 0)
  395. decon_win_set_colkey(ctx, win);
  396. /* wincon */
  397. val = readl(ctx->regs + WINCON(win));
  398. val |= WINCONx_TRIPLE_BUF_MODE;
  399. val |= WINCONx_ENWIN;
  400. writel(val, ctx->regs + WINCON(win));
  401. /* Enable DMA channel and unprotect windows */
  402. decon_shadow_protect_win(ctx, win, false);
  403. val = readl(ctx->regs + DECON_UPDATE);
  404. val |= DECON_UPDATE_STANDALONE_F;
  405. writel(val, ctx->regs + DECON_UPDATE);
  406. }
  407. static void decon_disable_plane(struct exynos_drm_crtc *crtc,
  408. struct exynos_drm_plane *plane)
  409. {
  410. struct decon_context *ctx = crtc->ctx;
  411. unsigned int win = plane->zpos;
  412. u32 val;
  413. if (ctx->suspended)
  414. return;
  415. /* protect windows */
  416. decon_shadow_protect_win(ctx, win, true);
  417. /* wincon */
  418. val = readl(ctx->regs + WINCON(win));
  419. val &= ~WINCONx_ENWIN;
  420. writel(val, ctx->regs + WINCON(win));
  421. val = readl(ctx->regs + DECON_UPDATE);
  422. val |= DECON_UPDATE_STANDALONE_F;
  423. writel(val, ctx->regs + DECON_UPDATE);
  424. }
  425. static void decon_atomic_flush(struct exynos_drm_crtc *crtc,
  426. struct exynos_drm_plane *plane)
  427. {
  428. struct decon_context *ctx = crtc->ctx;
  429. if (ctx->suspended)
  430. return;
  431. decon_shadow_protect_win(ctx, plane->zpos, false);
  432. }
  433. static void decon_init(struct decon_context *ctx)
  434. {
  435. u32 val;
  436. writel(VIDCON0_SWRESET, ctx->regs + VIDCON0);
  437. val = VIDOUTCON0_DISP_IF_0_ON;
  438. if (!ctx->i80_if)
  439. val |= VIDOUTCON0_RGBIF;
  440. writel(val, ctx->regs + VIDOUTCON0);
  441. writel(VCLKCON0_CLKVALUP | VCLKCON0_VCLKFREE, ctx->regs + VCLKCON0);
  442. if (!ctx->i80_if)
  443. writel(VIDCON1_VCLK_HOLD, ctx->regs + VIDCON1(0));
  444. }
  445. static void decon_enable(struct exynos_drm_crtc *crtc)
  446. {
  447. struct decon_context *ctx = crtc->ctx;
  448. int ret;
  449. if (!ctx->suspended)
  450. return;
  451. ctx->suspended = false;
  452. pm_runtime_get_sync(ctx->dev);
  453. ret = clk_prepare_enable(ctx->pclk);
  454. if (ret < 0) {
  455. DRM_ERROR("Failed to prepare_enable the pclk [%d]\n", ret);
  456. return;
  457. }
  458. ret = clk_prepare_enable(ctx->aclk);
  459. if (ret < 0) {
  460. DRM_ERROR("Failed to prepare_enable the aclk [%d]\n", ret);
  461. return;
  462. }
  463. ret = clk_prepare_enable(ctx->eclk);
  464. if (ret < 0) {
  465. DRM_ERROR("Failed to prepare_enable the eclk [%d]\n", ret);
  466. return;
  467. }
  468. ret = clk_prepare_enable(ctx->vclk);
  469. if (ret < 0) {
  470. DRM_ERROR("Failed to prepare_enable the vclk [%d]\n", ret);
  471. return;
  472. }
  473. decon_init(ctx);
  474. /* if vblank was enabled status, enable it again. */
  475. if (test_and_clear_bit(0, &ctx->irq_flags))
  476. decon_enable_vblank(ctx->crtc);
  477. decon_commit(ctx->crtc);
  478. }
  479. static void decon_disable(struct exynos_drm_crtc *crtc)
  480. {
  481. struct decon_context *ctx = crtc->ctx;
  482. int i;
  483. if (ctx->suspended)
  484. return;
  485. /*
  486. * We need to make sure that all windows are disabled before we
  487. * suspend that connector. Otherwise we might try to scan from
  488. * a destroyed buffer later.
  489. */
  490. for (i = 0; i < WINDOWS_NR; i++)
  491. decon_disable_plane(crtc, &ctx->planes[i]);
  492. clk_disable_unprepare(ctx->vclk);
  493. clk_disable_unprepare(ctx->eclk);
  494. clk_disable_unprepare(ctx->aclk);
  495. clk_disable_unprepare(ctx->pclk);
  496. pm_runtime_put_sync(ctx->dev);
  497. ctx->suspended = true;
  498. }
  499. static const struct exynos_drm_crtc_ops decon_crtc_ops = {
  500. .enable = decon_enable,
  501. .disable = decon_disable,
  502. .commit = decon_commit,
  503. .enable_vblank = decon_enable_vblank,
  504. .disable_vblank = decon_disable_vblank,
  505. .wait_for_vblank = decon_wait_for_vblank,
  506. .atomic_begin = decon_atomic_begin,
  507. .update_plane = decon_update_plane,
  508. .disable_plane = decon_disable_plane,
  509. .atomic_flush = decon_atomic_flush,
  510. };
  511. static irqreturn_t decon_irq_handler(int irq, void *dev_id)
  512. {
  513. struct decon_context *ctx = (struct decon_context *)dev_id;
  514. u32 val, clear_bit;
  515. int win;
  516. val = readl(ctx->regs + VIDINTCON1);
  517. clear_bit = ctx->i80_if ? VIDINTCON1_INT_I80 : VIDINTCON1_INT_FRAME;
  518. if (val & clear_bit)
  519. writel(clear_bit, ctx->regs + VIDINTCON1);
  520. /* check the crtc is detached already from encoder */
  521. if (ctx->pipe < 0 || !ctx->drm_dev)
  522. goto out;
  523. if (!ctx->i80_if) {
  524. drm_crtc_handle_vblank(&ctx->crtc->base);
  525. for (win = 0 ; win < WINDOWS_NR ; win++) {
  526. struct exynos_drm_plane *plane = &ctx->planes[win];
  527. if (!plane->pending_fb)
  528. continue;
  529. exynos_drm_crtc_finish_update(ctx->crtc, plane);
  530. }
  531. /* set wait vsync event to zero and wake up queue. */
  532. if (atomic_read(&ctx->wait_vsync_event)) {
  533. atomic_set(&ctx->wait_vsync_event, 0);
  534. wake_up(&ctx->wait_vsync_queue);
  535. }
  536. }
  537. out:
  538. return IRQ_HANDLED;
  539. }
  540. static int decon_bind(struct device *dev, struct device *master, void *data)
  541. {
  542. struct decon_context *ctx = dev_get_drvdata(dev);
  543. struct drm_device *drm_dev = data;
  544. struct exynos_drm_plane *exynos_plane;
  545. enum drm_plane_type type;
  546. unsigned int zpos;
  547. int ret;
  548. ret = decon_ctx_initialize(ctx, drm_dev);
  549. if (ret) {
  550. DRM_ERROR("decon_ctx_initialize failed.\n");
  551. return ret;
  552. }
  553. for (zpos = 0; zpos < WINDOWS_NR; zpos++) {
  554. type = exynos_plane_get_type(zpos, CURSOR_WIN);
  555. ret = exynos_plane_init(drm_dev, &ctx->planes[zpos],
  556. 1 << ctx->pipe, type, decon_formats,
  557. ARRAY_SIZE(decon_formats), zpos);
  558. if (ret)
  559. return ret;
  560. }
  561. exynos_plane = &ctx->planes[DEFAULT_WIN];
  562. ctx->crtc = exynos_drm_crtc_create(drm_dev, &exynos_plane->base,
  563. ctx->pipe, EXYNOS_DISPLAY_TYPE_LCD,
  564. &decon_crtc_ops, ctx);
  565. if (IS_ERR(ctx->crtc)) {
  566. decon_ctx_remove(ctx);
  567. return PTR_ERR(ctx->crtc);
  568. }
  569. if (ctx->encoder)
  570. exynos_dpi_bind(drm_dev, ctx->encoder);
  571. return 0;
  572. }
  573. static void decon_unbind(struct device *dev, struct device *master,
  574. void *data)
  575. {
  576. struct decon_context *ctx = dev_get_drvdata(dev);
  577. decon_disable(ctx->crtc);
  578. if (ctx->encoder)
  579. exynos_dpi_remove(ctx->encoder);
  580. decon_ctx_remove(ctx);
  581. }
  582. static const struct component_ops decon_component_ops = {
  583. .bind = decon_bind,
  584. .unbind = decon_unbind,
  585. };
  586. static int decon_probe(struct platform_device *pdev)
  587. {
  588. struct device *dev = &pdev->dev;
  589. struct decon_context *ctx;
  590. struct device_node *i80_if_timings;
  591. struct resource *res;
  592. int ret;
  593. if (!dev->of_node)
  594. return -ENODEV;
  595. ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
  596. if (!ctx)
  597. return -ENOMEM;
  598. ctx->dev = dev;
  599. ctx->suspended = true;
  600. i80_if_timings = of_get_child_by_name(dev->of_node, "i80-if-timings");
  601. if (i80_if_timings)
  602. ctx->i80_if = true;
  603. of_node_put(i80_if_timings);
  604. ctx->regs = of_iomap(dev->of_node, 0);
  605. if (!ctx->regs)
  606. return -ENOMEM;
  607. ctx->pclk = devm_clk_get(dev, "pclk_decon0");
  608. if (IS_ERR(ctx->pclk)) {
  609. dev_err(dev, "failed to get bus clock pclk\n");
  610. ret = PTR_ERR(ctx->pclk);
  611. goto err_iounmap;
  612. }
  613. ctx->aclk = devm_clk_get(dev, "aclk_decon0");
  614. if (IS_ERR(ctx->aclk)) {
  615. dev_err(dev, "failed to get bus clock aclk\n");
  616. ret = PTR_ERR(ctx->aclk);
  617. goto err_iounmap;
  618. }
  619. ctx->eclk = devm_clk_get(dev, "decon0_eclk");
  620. if (IS_ERR(ctx->eclk)) {
  621. dev_err(dev, "failed to get eclock\n");
  622. ret = PTR_ERR(ctx->eclk);
  623. goto err_iounmap;
  624. }
  625. ctx->vclk = devm_clk_get(dev, "decon0_vclk");
  626. if (IS_ERR(ctx->vclk)) {
  627. dev_err(dev, "failed to get vclock\n");
  628. ret = PTR_ERR(ctx->vclk);
  629. goto err_iounmap;
  630. }
  631. res = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
  632. ctx->i80_if ? "lcd_sys" : "vsync");
  633. if (!res) {
  634. dev_err(dev, "irq request failed.\n");
  635. ret = -ENXIO;
  636. goto err_iounmap;
  637. }
  638. ret = devm_request_irq(dev, res->start, decon_irq_handler,
  639. 0, "drm_decon", ctx);
  640. if (ret) {
  641. dev_err(dev, "irq request failed.\n");
  642. goto err_iounmap;
  643. }
  644. init_waitqueue_head(&ctx->wait_vsync_queue);
  645. atomic_set(&ctx->wait_vsync_event, 0);
  646. platform_set_drvdata(pdev, ctx);
  647. ctx->encoder = exynos_dpi_probe(dev);
  648. if (IS_ERR(ctx->encoder)) {
  649. ret = PTR_ERR(ctx->encoder);
  650. goto err_iounmap;
  651. }
  652. pm_runtime_enable(dev);
  653. ret = component_add(dev, &decon_component_ops);
  654. if (ret)
  655. goto err_disable_pm_runtime;
  656. return ret;
  657. err_disable_pm_runtime:
  658. pm_runtime_disable(dev);
  659. err_iounmap:
  660. iounmap(ctx->regs);
  661. return ret;
  662. }
  663. static int decon_remove(struct platform_device *pdev)
  664. {
  665. struct decon_context *ctx = dev_get_drvdata(&pdev->dev);
  666. pm_runtime_disable(&pdev->dev);
  667. iounmap(ctx->regs);
  668. component_del(&pdev->dev, &decon_component_ops);
  669. return 0;
  670. }
  671. struct platform_driver decon_driver = {
  672. .probe = decon_probe,
  673. .remove = decon_remove,
  674. .driver = {
  675. .name = "exynos-decon",
  676. .of_match_table = decon_driver_dt_match,
  677. },
  678. };