rcar_du_crtc.c 16 KB

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