rcar_du_crtc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. /*
  2. * rcar_du_crtc.c -- R-Car Display Unit CRTCs
  3. *
  4. * Copyright (C) 2013 Renesas Corporation
  5. *
  6. * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. */
  13. #include <linux/clk.h>
  14. #include <linux/mutex.h>
  15. #include <drm/drmP.h>
  16. #include <drm/drm_crtc.h>
  17. #include <drm/drm_crtc_helper.h>
  18. #include <drm/drm_fb_cma_helper.h>
  19. #include <drm/drm_gem_cma_helper.h>
  20. #include "rcar_du_crtc.h"
  21. #include "rcar_du_drv.h"
  22. #include "rcar_du_kms.h"
  23. #include "rcar_du_plane.h"
  24. #include "rcar_du_regs.h"
  25. #define to_rcar_crtc(c) container_of(c, struct rcar_du_crtc, crtc)
  26. static u32 rcar_du_crtc_read(struct rcar_du_crtc *rcrtc, u32 reg)
  27. {
  28. struct rcar_du_device *rcdu = rcrtc->group->dev;
  29. return rcar_du_read(rcdu, rcrtc->mmio_offset + reg);
  30. }
  31. static void rcar_du_crtc_write(struct rcar_du_crtc *rcrtc, u32 reg, u32 data)
  32. {
  33. struct rcar_du_device *rcdu = rcrtc->group->dev;
  34. rcar_du_write(rcdu, rcrtc->mmio_offset + reg, data);
  35. }
  36. static void rcar_du_crtc_clr(struct rcar_du_crtc *rcrtc, u32 reg, u32 clr)
  37. {
  38. struct rcar_du_device *rcdu = rcrtc->group->dev;
  39. rcar_du_write(rcdu, rcrtc->mmio_offset + reg,
  40. rcar_du_read(rcdu, rcrtc->mmio_offset + reg) & ~clr);
  41. }
  42. static void rcar_du_crtc_set(struct rcar_du_crtc *rcrtc, u32 reg, u32 set)
  43. {
  44. struct rcar_du_device *rcdu = rcrtc->group->dev;
  45. rcar_du_write(rcdu, rcrtc->mmio_offset + reg,
  46. rcar_du_read(rcdu, rcrtc->mmio_offset + reg) | set);
  47. }
  48. static void rcar_du_crtc_clr_set(struct rcar_du_crtc *rcrtc, u32 reg,
  49. u32 clr, u32 set)
  50. {
  51. struct rcar_du_device *rcdu = rcrtc->group->dev;
  52. u32 value = rcar_du_read(rcdu, rcrtc->mmio_offset + reg);
  53. rcar_du_write(rcdu, rcrtc->mmio_offset + reg, (value & ~clr) | set);
  54. }
  55. static int rcar_du_crtc_get(struct rcar_du_crtc *rcrtc)
  56. {
  57. int ret;
  58. ret = clk_prepare_enable(rcrtc->clock);
  59. if (ret < 0)
  60. return ret;
  61. ret = rcar_du_group_get(rcrtc->group);
  62. if (ret < 0)
  63. clk_disable_unprepare(rcrtc->clock);
  64. return ret;
  65. }
  66. static void rcar_du_crtc_put(struct rcar_du_crtc *rcrtc)
  67. {
  68. rcar_du_group_put(rcrtc->group);
  69. clk_disable_unprepare(rcrtc->clock);
  70. }
  71. static void rcar_du_crtc_set_display_timing(struct rcar_du_crtc *rcrtc)
  72. {
  73. const struct drm_display_mode *mode = &rcrtc->crtc.mode;
  74. struct rcar_du_device *rcdu = rcrtc->group->dev;
  75. unsigned long clk;
  76. u32 value;
  77. u32 div;
  78. /* Dot clock */
  79. clk = clk_get_rate(rcrtc->clock);
  80. div = DIV_ROUND_CLOSEST(clk, mode->clock * 1000);
  81. div = clamp(div, 1U, 64U) - 1;
  82. rcar_du_write(rcdu, rcrtc->index ? ESCR2 : ESCR,
  83. ESCR_DCLKSEL_CLKS | div);
  84. rcar_du_write(rcdu, rcrtc->index ? OTAR2 : OTAR, 0);
  85. /* Signal polarities */
  86. value = ((mode->flags & DRM_MODE_FLAG_PVSYNC) ? 0 : DSMR_VSL)
  87. | ((mode->flags & DRM_MODE_FLAG_PHSYNC) ? 0 : DSMR_HSL)
  88. | DSMR_DIPM_DE;
  89. rcar_du_crtc_write(rcrtc, DSMR, value);
  90. /* Display timings */
  91. rcar_du_crtc_write(rcrtc, HDSR, mode->htotal - mode->hsync_start - 19);
  92. rcar_du_crtc_write(rcrtc, HDER, mode->htotal - mode->hsync_start +
  93. mode->hdisplay - 19);
  94. rcar_du_crtc_write(rcrtc, HSWR, mode->hsync_end -
  95. mode->hsync_start - 1);
  96. rcar_du_crtc_write(rcrtc, HCR, mode->htotal - 1);
  97. rcar_du_crtc_write(rcrtc, VDSR, mode->vtotal - mode->vsync_end - 2);
  98. rcar_du_crtc_write(rcrtc, VDER, mode->vtotal - mode->vsync_end +
  99. mode->vdisplay - 2);
  100. rcar_du_crtc_write(rcrtc, VSPR, mode->vtotal - mode->vsync_end +
  101. mode->vsync_start - 1);
  102. rcar_du_crtc_write(rcrtc, VCR, mode->vtotal - 1);
  103. rcar_du_crtc_write(rcrtc, DESR, mode->htotal - mode->hsync_start);
  104. rcar_du_crtc_write(rcrtc, DEWR, mode->hdisplay);
  105. }
  106. static void rcar_du_crtc_set_routing(struct rcar_du_crtc *rcrtc)
  107. {
  108. struct rcar_du_device *rcdu = rcrtc->group->dev;
  109. u32 dorcr = rcar_du_read(rcdu, DORCR);
  110. dorcr &= ~(DORCR_PG2T | DORCR_DK2S | DORCR_PG2D_MASK);
  111. /* Set the DU1 pins sources. Select CRTC 0 if explicitly requested and
  112. * CRTC 1 in all other cases to avoid cloning CRTC 0 to DU0 and DU1 by
  113. * default.
  114. */
  115. if (rcrtc->outputs & (1 << 1) && rcrtc->index == 0)
  116. dorcr |= DORCR_PG2D_DS1;
  117. else
  118. dorcr |= DORCR_PG2T | DORCR_DK2S | DORCR_PG2D_DS2;
  119. rcar_du_write(rcdu, DORCR, dorcr);
  120. }
  121. void rcar_du_crtc_route_output(struct drm_crtc *crtc, unsigned int output)
  122. {
  123. struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc);
  124. /* Store the route from the CRTC output to the DU output. The DU will be
  125. * configured when starting the CRTC.
  126. */
  127. rcrtc->outputs |= 1 << output;
  128. }
  129. void rcar_du_crtc_update_planes(struct drm_crtc *crtc)
  130. {
  131. struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc);
  132. struct rcar_du_device *rcdu = rcrtc->group->dev;
  133. struct rcar_du_plane *planes[RCAR_DU_NUM_HW_PLANES];
  134. unsigned int num_planes = 0;
  135. unsigned int prio = 0;
  136. unsigned int i;
  137. u32 dptsr = 0;
  138. u32 dspr = 0;
  139. for (i = 0; i < ARRAY_SIZE(rcrtc->group->planes.planes); ++i) {
  140. struct rcar_du_plane *plane = &rcrtc->group->planes.planes[i];
  141. unsigned int j;
  142. if (plane->crtc != &rcrtc->crtc || !plane->enabled)
  143. continue;
  144. /* Insert the plane in the sorted planes array. */
  145. for (j = num_planes++; j > 0; --j) {
  146. if (planes[j-1]->zpos <= plane->zpos)
  147. break;
  148. planes[j] = planes[j-1];
  149. }
  150. planes[j] = plane;
  151. prio += plane->format->planes * 4;
  152. }
  153. for (i = 0; i < num_planes; ++i) {
  154. struct rcar_du_plane *plane = planes[i];
  155. unsigned int index = plane->hwindex;
  156. prio -= 4;
  157. dspr |= (index + 1) << prio;
  158. dptsr |= DPTSR_PnDK(index) | DPTSR_PnTS(index);
  159. if (plane->format->planes == 2) {
  160. index = (index + 1) % 8;
  161. prio -= 4;
  162. dspr |= (index + 1) << prio;
  163. dptsr |= DPTSR_PnDK(index) | DPTSR_PnTS(index);
  164. }
  165. }
  166. /* Select display timing and dot clock generator 2 for planes associated
  167. * with superposition controller 2.
  168. */
  169. if (rcrtc->index) {
  170. u32 value = rcar_du_read(rcdu, DPTSR);
  171. /* The DPTSR register is updated when the display controller is
  172. * stopped. We thus need to restart the DU. Once again, sorry
  173. * for the flicker. One way to mitigate the issue would be to
  174. * pre-associate planes with CRTCs (either with a fixed 4/4
  175. * split, or through a module parameter). Flicker would then
  176. * occur only if we need to break the pre-association.
  177. */
  178. if (value != dptsr) {
  179. rcar_du_write(rcdu, DPTSR, dptsr);
  180. if (rcrtc->group->used_crtcs)
  181. rcar_du_group_restart(rcrtc->group);
  182. }
  183. }
  184. rcar_du_write(rcdu, rcrtc->index ? DS2PR : DS1PR, dspr);
  185. }
  186. static void rcar_du_crtc_start(struct rcar_du_crtc *rcrtc)
  187. {
  188. struct drm_crtc *crtc = &rcrtc->crtc;
  189. unsigned int i;
  190. if (rcrtc->started)
  191. return;
  192. if (WARN_ON(rcrtc->plane->format == NULL))
  193. return;
  194. /* Set display off and background to black */
  195. rcar_du_crtc_write(rcrtc, DOOR, DOOR_RGB(0, 0, 0));
  196. rcar_du_crtc_write(rcrtc, BPOR, BPOR_RGB(0, 0, 0));
  197. /* Configure display timings and output routing */
  198. rcar_du_crtc_set_display_timing(rcrtc);
  199. rcar_du_crtc_set_routing(rcrtc);
  200. mutex_lock(&rcrtc->group->planes.lock);
  201. rcrtc->plane->enabled = true;
  202. rcar_du_crtc_update_planes(crtc);
  203. mutex_unlock(&rcrtc->group->planes.lock);
  204. /* Setup planes. */
  205. for (i = 0; i < ARRAY_SIZE(rcrtc->group->planes.planes); ++i) {
  206. struct rcar_du_plane *plane = &rcrtc->group->planes.planes[i];
  207. if (plane->crtc != crtc || !plane->enabled)
  208. continue;
  209. rcar_du_plane_setup(plane);
  210. }
  211. /* Select master sync mode. This enables display operation in master
  212. * sync mode (with the HSYNC and VSYNC signals configured as outputs and
  213. * actively driven).
  214. */
  215. rcar_du_crtc_clr_set(rcrtc, DSYSR, DSYSR_TVM_MASK, DSYSR_TVM_MASTER);
  216. rcar_du_group_start_stop(rcrtc->group, true);
  217. rcrtc->started = true;
  218. }
  219. static void rcar_du_crtc_stop(struct rcar_du_crtc *rcrtc)
  220. {
  221. struct drm_crtc *crtc = &rcrtc->crtc;
  222. if (!rcrtc->started)
  223. return;
  224. mutex_lock(&rcrtc->group->planes.lock);
  225. rcrtc->plane->enabled = false;
  226. rcar_du_crtc_update_planes(crtc);
  227. mutex_unlock(&rcrtc->group->planes.lock);
  228. /* Select switch sync mode. This stops display operation and configures
  229. * the HSYNC and VSYNC signals as inputs.
  230. */
  231. rcar_du_crtc_clr_set(rcrtc, DSYSR, DSYSR_TVM_MASK, DSYSR_TVM_SWITCH);
  232. rcar_du_group_start_stop(rcrtc->group, false);
  233. rcrtc->started = false;
  234. }
  235. void rcar_du_crtc_suspend(struct rcar_du_crtc *rcrtc)
  236. {
  237. rcar_du_crtc_stop(rcrtc);
  238. rcar_du_crtc_put(rcrtc);
  239. }
  240. void rcar_du_crtc_resume(struct rcar_du_crtc *rcrtc)
  241. {
  242. if (rcrtc->dpms != DRM_MODE_DPMS_ON)
  243. return;
  244. rcar_du_crtc_get(rcrtc);
  245. rcar_du_crtc_start(rcrtc);
  246. }
  247. static void rcar_du_crtc_update_base(struct rcar_du_crtc *rcrtc)
  248. {
  249. struct drm_crtc *crtc = &rcrtc->crtc;
  250. rcar_du_plane_compute_base(rcrtc->plane, crtc->fb);
  251. rcar_du_plane_update_base(rcrtc->plane);
  252. }
  253. static void rcar_du_crtc_dpms(struct drm_crtc *crtc, int mode)
  254. {
  255. struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc);
  256. if (rcrtc->dpms == mode)
  257. return;
  258. if (mode == DRM_MODE_DPMS_ON) {
  259. rcar_du_crtc_get(rcrtc);
  260. rcar_du_crtc_start(rcrtc);
  261. } else {
  262. rcar_du_crtc_stop(rcrtc);
  263. rcar_du_crtc_put(rcrtc);
  264. }
  265. rcrtc->dpms = mode;
  266. }
  267. static bool rcar_du_crtc_mode_fixup(struct drm_crtc *crtc,
  268. const struct drm_display_mode *mode,
  269. struct drm_display_mode *adjusted_mode)
  270. {
  271. /* TODO Fixup modes */
  272. return true;
  273. }
  274. static void rcar_du_crtc_mode_prepare(struct drm_crtc *crtc)
  275. {
  276. struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc);
  277. /* We need to access the hardware during mode set, acquire a reference
  278. * to the CRTC.
  279. */
  280. rcar_du_crtc_get(rcrtc);
  281. /* Stop the CRTC and release the plane. Force the DPMS mode to off as a
  282. * result.
  283. */
  284. rcar_du_crtc_stop(rcrtc);
  285. rcar_du_plane_release(rcrtc->plane);
  286. rcrtc->dpms = DRM_MODE_DPMS_OFF;
  287. }
  288. static int rcar_du_crtc_mode_set(struct drm_crtc *crtc,
  289. struct drm_display_mode *mode,
  290. struct drm_display_mode *adjusted_mode,
  291. int x, int y,
  292. struct drm_framebuffer *old_fb)
  293. {
  294. struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc);
  295. struct rcar_du_device *rcdu = rcrtc->group->dev;
  296. const struct rcar_du_format_info *format;
  297. int ret;
  298. format = rcar_du_format_info(crtc->fb->pixel_format);
  299. if (format == NULL) {
  300. dev_dbg(rcdu->dev, "mode_set: unsupported format %08x\n",
  301. crtc->fb->pixel_format);
  302. ret = -EINVAL;
  303. goto error;
  304. }
  305. ret = rcar_du_plane_reserve(rcrtc->plane, format);
  306. if (ret < 0)
  307. goto error;
  308. rcrtc->plane->format = format;
  309. rcrtc->plane->pitch = crtc->fb->pitches[0];
  310. rcrtc->plane->src_x = x;
  311. rcrtc->plane->src_y = y;
  312. rcrtc->plane->width = mode->hdisplay;
  313. rcrtc->plane->height = mode->vdisplay;
  314. rcar_du_plane_compute_base(rcrtc->plane, crtc->fb);
  315. rcrtc->outputs = 0;
  316. return 0;
  317. error:
  318. /* There's no rollback/abort operation to clean up in case of error. We
  319. * thus need to release the reference to the CRTC acquired in prepare()
  320. * here.
  321. */
  322. rcar_du_crtc_put(rcrtc);
  323. return ret;
  324. }
  325. static void rcar_du_crtc_mode_commit(struct drm_crtc *crtc)
  326. {
  327. struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc);
  328. /* We're done, restart the CRTC and set the DPMS mode to on. The
  329. * reference to the DU acquired at prepare() time will thus be released
  330. * by the DPMS handler (possibly called by the disable() handler).
  331. */
  332. rcar_du_crtc_start(rcrtc);
  333. rcrtc->dpms = DRM_MODE_DPMS_ON;
  334. }
  335. static int rcar_du_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
  336. struct drm_framebuffer *old_fb)
  337. {
  338. struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc);
  339. rcrtc->plane->src_x = x;
  340. rcrtc->plane->src_y = y;
  341. rcar_du_crtc_update_base(to_rcar_crtc(crtc));
  342. return 0;
  343. }
  344. static void rcar_du_crtc_disable(struct drm_crtc *crtc)
  345. {
  346. struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc);
  347. rcar_du_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
  348. rcar_du_plane_release(rcrtc->plane);
  349. }
  350. static const struct drm_crtc_helper_funcs crtc_helper_funcs = {
  351. .dpms = rcar_du_crtc_dpms,
  352. .mode_fixup = rcar_du_crtc_mode_fixup,
  353. .prepare = rcar_du_crtc_mode_prepare,
  354. .commit = rcar_du_crtc_mode_commit,
  355. .mode_set = rcar_du_crtc_mode_set,
  356. .mode_set_base = rcar_du_crtc_mode_set_base,
  357. .disable = rcar_du_crtc_disable,
  358. };
  359. void rcar_du_crtc_cancel_page_flip(struct rcar_du_crtc *rcrtc,
  360. struct drm_file *file)
  361. {
  362. struct drm_pending_vblank_event *event;
  363. struct drm_device *dev = rcrtc->crtc.dev;
  364. unsigned long flags;
  365. /* Destroy the pending vertical blanking event associated with the
  366. * pending page flip, if any, and disable vertical blanking interrupts.
  367. */
  368. spin_lock_irqsave(&dev->event_lock, flags);
  369. event = rcrtc->event;
  370. if (event && event->base.file_priv == file) {
  371. rcrtc->event = NULL;
  372. event->base.destroy(&event->base);
  373. drm_vblank_put(dev, rcrtc->index);
  374. }
  375. spin_unlock_irqrestore(&dev->event_lock, flags);
  376. }
  377. static void rcar_du_crtc_finish_page_flip(struct rcar_du_crtc *rcrtc)
  378. {
  379. struct drm_pending_vblank_event *event;
  380. struct drm_device *dev = rcrtc->crtc.dev;
  381. unsigned long flags;
  382. spin_lock_irqsave(&dev->event_lock, flags);
  383. event = rcrtc->event;
  384. rcrtc->event = NULL;
  385. spin_unlock_irqrestore(&dev->event_lock, flags);
  386. if (event == NULL)
  387. return;
  388. spin_lock_irqsave(&dev->event_lock, flags);
  389. drm_send_vblank_event(dev, rcrtc->index, event);
  390. spin_unlock_irqrestore(&dev->event_lock, flags);
  391. drm_vblank_put(dev, rcrtc->index);
  392. }
  393. static irqreturn_t rcar_du_crtc_irq(int irq, void *arg)
  394. {
  395. struct rcar_du_crtc *rcrtc = arg;
  396. irqreturn_t ret = IRQ_NONE;
  397. u32 status;
  398. status = rcar_du_crtc_read(rcrtc, DSSR);
  399. rcar_du_crtc_write(rcrtc, DSRCR, status & DSRCR_MASK);
  400. if (status & DSSR_VBK) {
  401. drm_handle_vblank(rcrtc->crtc.dev, rcrtc->index);
  402. rcar_du_crtc_finish_page_flip(rcrtc);
  403. ret = IRQ_HANDLED;
  404. }
  405. return ret;
  406. }
  407. static int rcar_du_crtc_page_flip(struct drm_crtc *crtc,
  408. struct drm_framebuffer *fb,
  409. struct drm_pending_vblank_event *event)
  410. {
  411. struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc);
  412. struct drm_device *dev = rcrtc->crtc.dev;
  413. unsigned long flags;
  414. spin_lock_irqsave(&dev->event_lock, flags);
  415. if (rcrtc->event != NULL) {
  416. spin_unlock_irqrestore(&dev->event_lock, flags);
  417. return -EBUSY;
  418. }
  419. spin_unlock_irqrestore(&dev->event_lock, flags);
  420. crtc->fb = fb;
  421. rcar_du_crtc_update_base(rcrtc);
  422. if (event) {
  423. event->pipe = rcrtc->index;
  424. drm_vblank_get(dev, rcrtc->index);
  425. spin_lock_irqsave(&dev->event_lock, flags);
  426. rcrtc->event = event;
  427. spin_unlock_irqrestore(&dev->event_lock, flags);
  428. }
  429. return 0;
  430. }
  431. static const struct drm_crtc_funcs crtc_funcs = {
  432. .destroy = drm_crtc_cleanup,
  433. .set_config = drm_crtc_helper_set_config,
  434. .page_flip = rcar_du_crtc_page_flip,
  435. };
  436. int rcar_du_crtc_create(struct rcar_du_group *rgrp, unsigned int index)
  437. {
  438. struct rcar_du_device *rcdu = rgrp->dev;
  439. struct platform_device *pdev = to_platform_device(rcdu->dev);
  440. struct rcar_du_crtc *rcrtc = &rcdu->crtcs[index];
  441. struct drm_crtc *crtc = &rcrtc->crtc;
  442. unsigned int irqflags;
  443. char clk_name[5];
  444. char *name;
  445. int irq;
  446. int ret;
  447. /* Get the CRTC clock. */
  448. if (rcar_du_has(rcdu, RCAR_DU_FEATURE_CRTC_IRQ_CLOCK)) {
  449. sprintf(clk_name, "du.%u", index);
  450. name = clk_name;
  451. } else {
  452. name = NULL;
  453. }
  454. rcrtc->clock = devm_clk_get(rcdu->dev, name);
  455. if (IS_ERR(rcrtc->clock)) {
  456. dev_err(rcdu->dev, "no clock for CRTC %u\n", index);
  457. return PTR_ERR(rcrtc->clock);
  458. }
  459. rcrtc->group = rgrp;
  460. rcrtc->mmio_offset = index ? DISP2_REG_OFFSET : 0;
  461. rcrtc->index = index;
  462. rcrtc->dpms = DRM_MODE_DPMS_OFF;
  463. rcrtc->plane = &rgrp->planes.planes[index];
  464. rcrtc->plane->crtc = crtc;
  465. ret = drm_crtc_init(rcdu->ddev, crtc, &crtc_funcs);
  466. if (ret < 0)
  467. return ret;
  468. drm_crtc_helper_add(crtc, &crtc_helper_funcs);
  469. /* Register the interrupt handler. */
  470. if (rcar_du_has(rcdu, RCAR_DU_FEATURE_CRTC_IRQ_CLOCK)) {
  471. irq = platform_get_irq(pdev, index);
  472. irqflags = 0;
  473. } else {
  474. irq = platform_get_irq(pdev, 0);
  475. irqflags = IRQF_SHARED;
  476. }
  477. if (irq < 0) {
  478. dev_err(rcdu->dev, "no IRQ for CRTC %u\n", index);
  479. return ret;
  480. }
  481. ret = devm_request_irq(rcdu->dev, irq, rcar_du_crtc_irq, irqflags,
  482. dev_name(rcdu->dev), rcrtc);
  483. if (ret < 0) {
  484. dev_err(rcdu->dev,
  485. "failed to register IRQ for CRTC %u\n", index);
  486. return ret;
  487. }
  488. return 0;
  489. }
  490. void rcar_du_crtc_enable_vblank(struct rcar_du_crtc *rcrtc, bool enable)
  491. {
  492. if (enable) {
  493. rcar_du_crtc_write(rcrtc, DSRCR, DSRCR_VBCL);
  494. rcar_du_crtc_set(rcrtc, DIER, DIER_VBE);
  495. } else {
  496. rcar_du_crtc_clr(rcrtc, DIER, DIER_VBE);
  497. }
  498. }