rcar_du_crtc.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. /*
  2. * rcar_du_crtc.c -- R-Car Display Unit CRTCs
  3. *
  4. * Copyright (C) 2013-2014 Renesas Electronics 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_atomic.h>
  17. #include <drm/drm_atomic_helper.h>
  18. #include <drm/drm_crtc.h>
  19. #include <drm/drm_crtc_helper.h>
  20. #include <drm/drm_fb_cma_helper.h>
  21. #include <drm/drm_gem_cma_helper.h>
  22. #include <drm/drm_plane_helper.h>
  23. #include "rcar_du_crtc.h"
  24. #include "rcar_du_drv.h"
  25. #include "rcar_du_kms.h"
  26. #include "rcar_du_plane.h"
  27. #include "rcar_du_regs.h"
  28. static u32 rcar_du_crtc_read(struct rcar_du_crtc *rcrtc, u32 reg)
  29. {
  30. struct rcar_du_device *rcdu = rcrtc->group->dev;
  31. return rcar_du_read(rcdu, rcrtc->mmio_offset + reg);
  32. }
  33. static void rcar_du_crtc_write(struct rcar_du_crtc *rcrtc, u32 reg, u32 data)
  34. {
  35. struct rcar_du_device *rcdu = rcrtc->group->dev;
  36. rcar_du_write(rcdu, rcrtc->mmio_offset + reg, data);
  37. }
  38. static void rcar_du_crtc_clr(struct rcar_du_crtc *rcrtc, u32 reg, u32 clr)
  39. {
  40. struct rcar_du_device *rcdu = rcrtc->group->dev;
  41. rcar_du_write(rcdu, rcrtc->mmio_offset + reg,
  42. rcar_du_read(rcdu, rcrtc->mmio_offset + reg) & ~clr);
  43. }
  44. static void rcar_du_crtc_set(struct rcar_du_crtc *rcrtc, u32 reg, u32 set)
  45. {
  46. struct rcar_du_device *rcdu = rcrtc->group->dev;
  47. rcar_du_write(rcdu, rcrtc->mmio_offset + reg,
  48. rcar_du_read(rcdu, rcrtc->mmio_offset + reg) | set);
  49. }
  50. static void rcar_du_crtc_clr_set(struct rcar_du_crtc *rcrtc, u32 reg,
  51. u32 clr, u32 set)
  52. {
  53. struct rcar_du_device *rcdu = rcrtc->group->dev;
  54. u32 value = rcar_du_read(rcdu, rcrtc->mmio_offset + reg);
  55. rcar_du_write(rcdu, rcrtc->mmio_offset + reg, (value & ~clr) | set);
  56. }
  57. static int rcar_du_crtc_get(struct rcar_du_crtc *rcrtc)
  58. {
  59. int ret;
  60. ret = clk_prepare_enable(rcrtc->clock);
  61. if (ret < 0)
  62. return ret;
  63. ret = clk_prepare_enable(rcrtc->extclock);
  64. if (ret < 0)
  65. goto error_clock;
  66. ret = rcar_du_group_get(rcrtc->group);
  67. if (ret < 0)
  68. goto error_group;
  69. return 0;
  70. error_group:
  71. clk_disable_unprepare(rcrtc->extclock);
  72. error_clock:
  73. clk_disable_unprepare(rcrtc->clock);
  74. return ret;
  75. }
  76. static void rcar_du_crtc_put(struct rcar_du_crtc *rcrtc)
  77. {
  78. rcar_du_group_put(rcrtc->group);
  79. clk_disable_unprepare(rcrtc->extclock);
  80. clk_disable_unprepare(rcrtc->clock);
  81. }
  82. /* -----------------------------------------------------------------------------
  83. * Hardware Setup
  84. */
  85. static void rcar_du_crtc_set_display_timing(struct rcar_du_crtc *rcrtc)
  86. {
  87. const struct drm_display_mode *mode = &rcrtc->crtc.state->adjusted_mode;
  88. unsigned long mode_clock = mode->clock * 1000;
  89. unsigned long clk;
  90. u32 value;
  91. u32 escr;
  92. u32 div;
  93. /* Compute the clock divisor and select the internal or external dot
  94. * clock based on the requested frequency.
  95. */
  96. clk = clk_get_rate(rcrtc->clock);
  97. div = DIV_ROUND_CLOSEST(clk, mode_clock);
  98. div = clamp(div, 1U, 64U) - 1;
  99. escr = div | ESCR_DCLKSEL_CLKS;
  100. if (rcrtc->extclock) {
  101. unsigned long extclk;
  102. unsigned long extrate;
  103. unsigned long rate;
  104. u32 extdiv;
  105. extclk = clk_get_rate(rcrtc->extclock);
  106. extdiv = DIV_ROUND_CLOSEST(extclk, mode_clock);
  107. extdiv = clamp(extdiv, 1U, 64U) - 1;
  108. rate = clk / (div + 1);
  109. extrate = extclk / (extdiv + 1);
  110. if (abs((long)extrate - (long)mode_clock) <
  111. abs((long)rate - (long)mode_clock)) {
  112. dev_dbg(rcrtc->group->dev->dev,
  113. "crtc%u: using external clock\n", rcrtc->index);
  114. escr = extdiv | ESCR_DCLKSEL_DCLKIN;
  115. }
  116. }
  117. rcar_du_group_write(rcrtc->group, rcrtc->index % 2 ? ESCR2 : ESCR,
  118. escr);
  119. rcar_du_group_write(rcrtc->group, rcrtc->index % 2 ? OTAR2 : OTAR, 0);
  120. /* Signal polarities */
  121. value = ((mode->flags & DRM_MODE_FLAG_PVSYNC) ? 0 : DSMR_VSL)
  122. | ((mode->flags & DRM_MODE_FLAG_PHSYNC) ? 0 : DSMR_HSL)
  123. | DSMR_DIPM_DE | DSMR_CSPM;
  124. rcar_du_crtc_write(rcrtc, DSMR, value);
  125. /* Display timings */
  126. rcar_du_crtc_write(rcrtc, HDSR, mode->htotal - mode->hsync_start - 19);
  127. rcar_du_crtc_write(rcrtc, HDER, mode->htotal - mode->hsync_start +
  128. mode->hdisplay - 19);
  129. rcar_du_crtc_write(rcrtc, HSWR, mode->hsync_end -
  130. mode->hsync_start - 1);
  131. rcar_du_crtc_write(rcrtc, HCR, mode->htotal - 1);
  132. rcar_du_crtc_write(rcrtc, VDSR, mode->crtc_vtotal -
  133. mode->crtc_vsync_end - 2);
  134. rcar_du_crtc_write(rcrtc, VDER, mode->crtc_vtotal -
  135. mode->crtc_vsync_end +
  136. mode->crtc_vdisplay - 2);
  137. rcar_du_crtc_write(rcrtc, VSPR, mode->crtc_vtotal -
  138. mode->crtc_vsync_end +
  139. mode->crtc_vsync_start - 1);
  140. rcar_du_crtc_write(rcrtc, VCR, mode->crtc_vtotal - 1);
  141. rcar_du_crtc_write(rcrtc, DESR, mode->htotal - mode->hsync_start);
  142. rcar_du_crtc_write(rcrtc, DEWR, mode->hdisplay);
  143. }
  144. void rcar_du_crtc_route_output(struct drm_crtc *crtc,
  145. enum rcar_du_output output)
  146. {
  147. struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc);
  148. struct rcar_du_device *rcdu = rcrtc->group->dev;
  149. /* Store the route from the CRTC output to the DU output. The DU will be
  150. * configured when starting the CRTC.
  151. */
  152. rcrtc->outputs |= BIT(output);
  153. /* Store RGB routing to DPAD0, the hardware will be configured when
  154. * starting the CRTC.
  155. */
  156. if (output == RCAR_DU_OUTPUT_DPAD0)
  157. rcdu->dpad0_source = rcrtc->index;
  158. }
  159. static unsigned int plane_zpos(struct rcar_du_plane *plane)
  160. {
  161. return to_rcar_du_plane_state(plane->plane.state)->zpos;
  162. }
  163. static const struct rcar_du_format_info *
  164. plane_format(struct rcar_du_plane *plane)
  165. {
  166. return to_rcar_du_plane_state(plane->plane.state)->format;
  167. }
  168. static void rcar_du_crtc_update_planes(struct rcar_du_crtc *rcrtc)
  169. {
  170. struct rcar_du_plane *planes[RCAR_DU_NUM_HW_PLANES];
  171. unsigned int num_planes = 0;
  172. unsigned int prio = 0;
  173. unsigned int i;
  174. u32 dptsr = 0;
  175. u32 dspr = 0;
  176. for (i = 0; i < ARRAY_SIZE(rcrtc->group->planes.planes); ++i) {
  177. struct rcar_du_plane *plane = &rcrtc->group->planes.planes[i];
  178. unsigned int j;
  179. if (plane->plane.state->crtc != &rcrtc->crtc)
  180. continue;
  181. /* Insert the plane in the sorted planes array. */
  182. for (j = num_planes++; j > 0; --j) {
  183. if (plane_zpos(planes[j-1]) <= plane_zpos(plane))
  184. break;
  185. planes[j] = planes[j-1];
  186. }
  187. planes[j] = plane;
  188. prio += plane_format(plane)->planes * 4;
  189. }
  190. for (i = 0; i < num_planes; ++i) {
  191. struct rcar_du_plane *plane = planes[i];
  192. struct drm_plane_state *state = plane->plane.state;
  193. unsigned int index = to_rcar_du_plane_state(state)->hwindex;
  194. prio -= 4;
  195. dspr |= (index + 1) << prio;
  196. dptsr |= DPTSR_PnDK(index) | DPTSR_PnTS(index);
  197. if (plane_format(plane)->planes == 2) {
  198. index = (index + 1) % 8;
  199. prio -= 4;
  200. dspr |= (index + 1) << prio;
  201. dptsr |= DPTSR_PnDK(index) | DPTSR_PnTS(index);
  202. }
  203. }
  204. /* Select display timing and dot clock generator 2 for planes associated
  205. * with superposition controller 2.
  206. */
  207. if (rcrtc->index % 2) {
  208. /* The DPTSR register is updated when the display controller is
  209. * stopped. We thus need to restart the DU. Once again, sorry
  210. * for the flicker. One way to mitigate the issue would be to
  211. * pre-associate planes with CRTCs (either with a fixed 4/4
  212. * split, or through a module parameter). Flicker would then
  213. * occur only if we need to break the pre-association.
  214. */
  215. mutex_lock(&rcrtc->group->lock);
  216. if (rcar_du_group_read(rcrtc->group, DPTSR) != dptsr) {
  217. rcar_du_group_write(rcrtc->group, DPTSR, dptsr);
  218. if (rcrtc->group->used_crtcs)
  219. rcar_du_group_restart(rcrtc->group);
  220. }
  221. mutex_unlock(&rcrtc->group->lock);
  222. }
  223. rcar_du_group_write(rcrtc->group, rcrtc->index % 2 ? DS2PR : DS1PR,
  224. dspr);
  225. }
  226. /* -----------------------------------------------------------------------------
  227. * Page Flip
  228. */
  229. void rcar_du_crtc_cancel_page_flip(struct rcar_du_crtc *rcrtc,
  230. struct drm_file *file)
  231. {
  232. struct drm_pending_vblank_event *event;
  233. struct drm_device *dev = rcrtc->crtc.dev;
  234. unsigned long flags;
  235. /* Destroy the pending vertical blanking event associated with the
  236. * pending page flip, if any, and disable vertical blanking interrupts.
  237. */
  238. spin_lock_irqsave(&dev->event_lock, flags);
  239. event = rcrtc->event;
  240. if (event && event->base.file_priv == file) {
  241. rcrtc->event = NULL;
  242. event->base.destroy(&event->base);
  243. drm_crtc_vblank_put(&rcrtc->crtc);
  244. }
  245. spin_unlock_irqrestore(&dev->event_lock, flags);
  246. }
  247. static void rcar_du_crtc_finish_page_flip(struct rcar_du_crtc *rcrtc)
  248. {
  249. struct drm_pending_vblank_event *event;
  250. struct drm_device *dev = rcrtc->crtc.dev;
  251. unsigned long flags;
  252. spin_lock_irqsave(&dev->event_lock, flags);
  253. event = rcrtc->event;
  254. rcrtc->event = NULL;
  255. spin_unlock_irqrestore(&dev->event_lock, flags);
  256. if (event == NULL)
  257. return;
  258. spin_lock_irqsave(&dev->event_lock, flags);
  259. drm_send_vblank_event(dev, rcrtc->index, event);
  260. wake_up(&rcrtc->flip_wait);
  261. spin_unlock_irqrestore(&dev->event_lock, flags);
  262. drm_crtc_vblank_put(&rcrtc->crtc);
  263. }
  264. static bool rcar_du_crtc_page_flip_pending(struct rcar_du_crtc *rcrtc)
  265. {
  266. struct drm_device *dev = rcrtc->crtc.dev;
  267. unsigned long flags;
  268. bool pending;
  269. spin_lock_irqsave(&dev->event_lock, flags);
  270. pending = rcrtc->event != NULL;
  271. spin_unlock_irqrestore(&dev->event_lock, flags);
  272. return pending;
  273. }
  274. static void rcar_du_crtc_wait_page_flip(struct rcar_du_crtc *rcrtc)
  275. {
  276. struct rcar_du_device *rcdu = rcrtc->group->dev;
  277. if (wait_event_timeout(rcrtc->flip_wait,
  278. !rcar_du_crtc_page_flip_pending(rcrtc),
  279. msecs_to_jiffies(50)))
  280. return;
  281. dev_warn(rcdu->dev, "page flip timeout\n");
  282. rcar_du_crtc_finish_page_flip(rcrtc);
  283. }
  284. /* -----------------------------------------------------------------------------
  285. * Start/Stop and Suspend/Resume
  286. */
  287. static void rcar_du_crtc_start(struct rcar_du_crtc *rcrtc)
  288. {
  289. struct drm_crtc *crtc = &rcrtc->crtc;
  290. bool interlaced;
  291. if (rcrtc->started)
  292. return;
  293. /* Set display off and background to black */
  294. rcar_du_crtc_write(rcrtc, DOOR, DOOR_RGB(0, 0, 0));
  295. rcar_du_crtc_write(rcrtc, BPOR, BPOR_RGB(0, 0, 0));
  296. /* Configure display timings and output routing */
  297. rcar_du_crtc_set_display_timing(rcrtc);
  298. rcar_du_group_set_routing(rcrtc->group);
  299. /* Start with all planes disabled. */
  300. rcar_du_group_write(rcrtc->group, rcrtc->index % 2 ? DS2PR : DS1PR, 0);
  301. /* Select master sync mode. This enables display operation in master
  302. * sync mode (with the HSYNC and VSYNC signals configured as outputs and
  303. * actively driven).
  304. */
  305. interlaced = rcrtc->crtc.mode.flags & DRM_MODE_FLAG_INTERLACE;
  306. rcar_du_crtc_clr_set(rcrtc, DSYSR, DSYSR_TVM_MASK | DSYSR_SCM_MASK,
  307. (interlaced ? DSYSR_SCM_INT_VIDEO : 0) |
  308. DSYSR_TVM_MASTER);
  309. rcar_du_group_start_stop(rcrtc->group, true);
  310. /* Turn vertical blanking interrupt reporting back on. */
  311. drm_crtc_vblank_on(crtc);
  312. rcrtc->started = true;
  313. }
  314. static void rcar_du_crtc_stop(struct rcar_du_crtc *rcrtc)
  315. {
  316. struct drm_crtc *crtc = &rcrtc->crtc;
  317. if (!rcrtc->started)
  318. return;
  319. /* Disable vertical blanking interrupt reporting. We first need to wait
  320. * for page flip completion before stopping the CRTC as userspace
  321. * expects page flips to eventually complete.
  322. */
  323. rcar_du_crtc_wait_page_flip(rcrtc);
  324. drm_crtc_vblank_off(crtc);
  325. /* Select switch sync mode. This stops display operation and configures
  326. * the HSYNC and VSYNC signals as inputs.
  327. */
  328. rcar_du_crtc_clr_set(rcrtc, DSYSR, DSYSR_TVM_MASK, DSYSR_TVM_SWITCH);
  329. rcar_du_group_start_stop(rcrtc->group, false);
  330. rcrtc->started = false;
  331. }
  332. void rcar_du_crtc_suspend(struct rcar_du_crtc *rcrtc)
  333. {
  334. rcar_du_crtc_stop(rcrtc);
  335. rcar_du_crtc_put(rcrtc);
  336. }
  337. void rcar_du_crtc_resume(struct rcar_du_crtc *rcrtc)
  338. {
  339. unsigned int i;
  340. if (!rcrtc->enabled)
  341. return;
  342. rcar_du_crtc_get(rcrtc);
  343. rcar_du_crtc_start(rcrtc);
  344. /* Commit the planes state. */
  345. for (i = 0; i < ARRAY_SIZE(rcrtc->group->planes.planes); ++i) {
  346. struct rcar_du_plane *plane = &rcrtc->group->planes.planes[i];
  347. if (plane->plane.state->crtc != &rcrtc->crtc)
  348. continue;
  349. rcar_du_plane_setup(plane);
  350. }
  351. rcar_du_crtc_update_planes(rcrtc);
  352. }
  353. /* -----------------------------------------------------------------------------
  354. * CRTC Functions
  355. */
  356. static void rcar_du_crtc_enable(struct drm_crtc *crtc)
  357. {
  358. struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc);
  359. if (rcrtc->enabled)
  360. return;
  361. rcar_du_crtc_get(rcrtc);
  362. rcar_du_crtc_start(rcrtc);
  363. rcrtc->enabled = true;
  364. }
  365. static void rcar_du_crtc_disable(struct drm_crtc *crtc)
  366. {
  367. struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc);
  368. if (!rcrtc->enabled)
  369. return;
  370. rcar_du_crtc_stop(rcrtc);
  371. rcar_du_crtc_put(rcrtc);
  372. rcrtc->enabled = false;
  373. rcrtc->outputs = 0;
  374. }
  375. static bool rcar_du_crtc_mode_fixup(struct drm_crtc *crtc,
  376. const struct drm_display_mode *mode,
  377. struct drm_display_mode *adjusted_mode)
  378. {
  379. /* TODO Fixup modes */
  380. return true;
  381. }
  382. static void rcar_du_crtc_atomic_begin(struct drm_crtc *crtc)
  383. {
  384. struct drm_pending_vblank_event *event = crtc->state->event;
  385. struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc);
  386. struct drm_device *dev = rcrtc->crtc.dev;
  387. unsigned long flags;
  388. if (event) {
  389. WARN_ON(drm_crtc_vblank_get(crtc) != 0);
  390. spin_lock_irqsave(&dev->event_lock, flags);
  391. rcrtc->event = event;
  392. spin_unlock_irqrestore(&dev->event_lock, flags);
  393. }
  394. }
  395. static void rcar_du_crtc_atomic_flush(struct drm_crtc *crtc)
  396. {
  397. struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc);
  398. rcar_du_crtc_update_planes(rcrtc);
  399. }
  400. static const struct drm_crtc_helper_funcs crtc_helper_funcs = {
  401. .mode_fixup = rcar_du_crtc_mode_fixup,
  402. .disable = rcar_du_crtc_disable,
  403. .enable = rcar_du_crtc_enable,
  404. .atomic_begin = rcar_du_crtc_atomic_begin,
  405. .atomic_flush = rcar_du_crtc_atomic_flush,
  406. };
  407. static const struct drm_crtc_funcs crtc_funcs = {
  408. .reset = drm_atomic_helper_crtc_reset,
  409. .destroy = drm_crtc_cleanup,
  410. .set_config = drm_atomic_helper_set_config,
  411. .page_flip = drm_atomic_helper_page_flip,
  412. .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
  413. .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
  414. };
  415. /* -----------------------------------------------------------------------------
  416. * Interrupt Handling
  417. */
  418. static irqreturn_t rcar_du_crtc_irq(int irq, void *arg)
  419. {
  420. struct rcar_du_crtc *rcrtc = arg;
  421. irqreturn_t ret = IRQ_NONE;
  422. u32 status;
  423. status = rcar_du_crtc_read(rcrtc, DSSR);
  424. rcar_du_crtc_write(rcrtc, DSRCR, status & DSRCR_MASK);
  425. if (status & DSSR_FRM) {
  426. drm_handle_vblank(rcrtc->crtc.dev, rcrtc->index);
  427. rcar_du_crtc_finish_page_flip(rcrtc);
  428. ret = IRQ_HANDLED;
  429. }
  430. return ret;
  431. }
  432. /* -----------------------------------------------------------------------------
  433. * Initialization
  434. */
  435. int rcar_du_crtc_create(struct rcar_du_group *rgrp, unsigned int index)
  436. {
  437. static const unsigned int mmio_offsets[] = {
  438. DU0_REG_OFFSET, DU1_REG_OFFSET, DU2_REG_OFFSET
  439. };
  440. struct rcar_du_device *rcdu = rgrp->dev;
  441. struct platform_device *pdev = to_platform_device(rcdu->dev);
  442. struct rcar_du_crtc *rcrtc = &rcdu->crtcs[index];
  443. struct drm_crtc *crtc = &rcrtc->crtc;
  444. unsigned int irqflags;
  445. struct clk *clk;
  446. char clk_name[9];
  447. char *name;
  448. int irq;
  449. int ret;
  450. /* Get the CRTC clock and the optional external clock. */
  451. if (rcar_du_has(rcdu, RCAR_DU_FEATURE_CRTC_IRQ_CLOCK)) {
  452. sprintf(clk_name, "du.%u", index);
  453. name = clk_name;
  454. } else {
  455. name = NULL;
  456. }
  457. rcrtc->clock = devm_clk_get(rcdu->dev, name);
  458. if (IS_ERR(rcrtc->clock)) {
  459. dev_err(rcdu->dev, "no clock for CRTC %u\n", index);
  460. return PTR_ERR(rcrtc->clock);
  461. }
  462. sprintf(clk_name, "dclkin.%u", index);
  463. clk = devm_clk_get(rcdu->dev, clk_name);
  464. if (!IS_ERR(clk)) {
  465. rcrtc->extclock = clk;
  466. } else if (PTR_ERR(rcrtc->clock) == -EPROBE_DEFER) {
  467. dev_info(rcdu->dev, "can't get external clock %u\n", index);
  468. return -EPROBE_DEFER;
  469. }
  470. init_waitqueue_head(&rcrtc->flip_wait);
  471. rcrtc->group = rgrp;
  472. rcrtc->mmio_offset = mmio_offsets[index];
  473. rcrtc->index = index;
  474. rcrtc->enabled = false;
  475. ret = drm_crtc_init_with_planes(rcdu->ddev, crtc,
  476. &rgrp->planes.planes[index % 2].plane,
  477. NULL, &crtc_funcs);
  478. if (ret < 0)
  479. return ret;
  480. drm_crtc_helper_add(crtc, &crtc_helper_funcs);
  481. /* Start with vertical blanking interrupt reporting disabled. */
  482. drm_crtc_vblank_off(crtc);
  483. /* Register the interrupt handler. */
  484. if (rcar_du_has(rcdu, RCAR_DU_FEATURE_CRTC_IRQ_CLOCK)) {
  485. irq = platform_get_irq(pdev, index);
  486. irqflags = 0;
  487. } else {
  488. irq = platform_get_irq(pdev, 0);
  489. irqflags = IRQF_SHARED;
  490. }
  491. if (irq < 0) {
  492. dev_err(rcdu->dev, "no IRQ for CRTC %u\n", index);
  493. return irq;
  494. }
  495. ret = devm_request_irq(rcdu->dev, irq, rcar_du_crtc_irq, irqflags,
  496. dev_name(rcdu->dev), rcrtc);
  497. if (ret < 0) {
  498. dev_err(rcdu->dev,
  499. "failed to register IRQ for CRTC %u\n", index);
  500. return ret;
  501. }
  502. return 0;
  503. }
  504. void rcar_du_crtc_enable_vblank(struct rcar_du_crtc *rcrtc, bool enable)
  505. {
  506. if (enable) {
  507. rcar_du_crtc_write(rcrtc, DSRCR, DSRCR_VBCL);
  508. rcar_du_crtc_set(rcrtc, DIER, DIER_VBE);
  509. } else {
  510. rcar_du_crtc_clr(rcrtc, DIER, DIER_VBE);
  511. }
  512. }