armada_crtc.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100
  1. /*
  2. * Copyright (C) 2012 Russell King
  3. * Rewritten from the dovefb driver, and Armada510 manuals.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #include <linux/clk.h>
  10. #include <drm/drmP.h>
  11. #include <drm/drm_crtc_helper.h>
  12. #include "armada_crtc.h"
  13. #include "armada_drm.h"
  14. #include "armada_fb.h"
  15. #include "armada_gem.h"
  16. #include "armada_hw.h"
  17. struct armada_frame_work {
  18. struct drm_pending_vblank_event *event;
  19. struct armada_regs regs[4];
  20. struct drm_framebuffer *old_fb;
  21. };
  22. enum csc_mode {
  23. CSC_AUTO = 0,
  24. CSC_YUV_CCIR601 = 1,
  25. CSC_YUV_CCIR709 = 2,
  26. CSC_RGB_COMPUTER = 1,
  27. CSC_RGB_STUDIO = 2,
  28. };
  29. /*
  30. * A note about interlacing. Let's consider HDMI 1920x1080i.
  31. * The timing parameters we have from X are:
  32. * Hact HsyA HsyI Htot Vact VsyA VsyI Vtot
  33. * 1920 2448 2492 2640 1080 1084 1094 1125
  34. * Which get translated to:
  35. * Hact HsyA HsyI Htot Vact VsyA VsyI Vtot
  36. * 1920 2448 2492 2640 540 542 547 562
  37. *
  38. * This is how it is defined by CEA-861-D - line and pixel numbers are
  39. * referenced to the rising edge of VSYNC and HSYNC. Total clocks per
  40. * line: 2640. The odd frame, the first active line is at line 21, and
  41. * the even frame, the first active line is 584.
  42. *
  43. * LN: 560 561 562 563 567 568 569
  44. * DE: ~~~|____________________________//__________________________
  45. * HSYNC: ____|~|_____|~|_____|~|_____|~|_//__|~|_____|~|_____|~|_____
  46. * VSYNC: _________________________|~~~~~~//~~~~~~~~~~~~~~~|__________
  47. * 22 blanking lines. VSYNC at 1320 (referenced to the HSYNC rising edge).
  48. *
  49. * LN: 1123 1124 1125 1 5 6 7
  50. * DE: ~~~|____________________________//__________________________
  51. * HSYNC: ____|~|_____|~|_____|~|_____|~|_//__|~|_____|~|_____|~|_____
  52. * VSYNC: ____________________|~~~~~~~~~~~//~~~~~~~~~~|_______________
  53. * 23 blanking lines
  54. *
  55. * The Armada LCD Controller line and pixel numbers are, like X timings,
  56. * referenced to the top left of the active frame.
  57. *
  58. * So, translating these to our LCD controller:
  59. * Odd frame, 563 total lines, VSYNC at line 543-548, pixel 1128.
  60. * Even frame, 562 total lines, VSYNC at line 542-547, pixel 2448.
  61. * Note: Vsync front porch remains constant!
  62. *
  63. * if (odd_frame) {
  64. * vtotal = mode->crtc_vtotal + 1;
  65. * vbackporch = mode->crtc_vsync_start - mode->crtc_vdisplay + 1;
  66. * vhorizpos = mode->crtc_hsync_start - mode->crtc_htotal / 2
  67. * } else {
  68. * vtotal = mode->crtc_vtotal;
  69. * vbackporch = mode->crtc_vsync_start - mode->crtc_vdisplay;
  70. * vhorizpos = mode->crtc_hsync_start;
  71. * }
  72. * vfrontporch = mode->crtc_vtotal - mode->crtc_vsync_end;
  73. *
  74. * So, we need to reprogram these registers on each vsync event:
  75. * LCD_SPU_V_PORCH, LCD_SPU_ADV_REG, LCD_SPUT_V_H_TOTAL
  76. *
  77. * Note: we do not use the frame done interrupts because these appear
  78. * to happen too early, and lead to jitter on the display (presumably
  79. * they occur at the end of the last active line, before the vsync back
  80. * porch, which we're reprogramming.)
  81. */
  82. void
  83. armada_drm_crtc_update_regs(struct armada_crtc *dcrtc, struct armada_regs *regs)
  84. {
  85. while (regs->offset != ~0) {
  86. void __iomem *reg = dcrtc->base + regs->offset;
  87. uint32_t val;
  88. val = regs->mask;
  89. if (val != 0)
  90. val &= readl_relaxed(reg);
  91. writel_relaxed(val | regs->val, reg);
  92. ++regs;
  93. }
  94. }
  95. #define dpms_blanked(dpms) ((dpms) != DRM_MODE_DPMS_ON)
  96. static void armada_drm_crtc_update(struct armada_crtc *dcrtc)
  97. {
  98. uint32_t dumb_ctrl;
  99. dumb_ctrl = dcrtc->cfg_dumb_ctrl;
  100. if (!dpms_blanked(dcrtc->dpms))
  101. dumb_ctrl |= CFG_DUMB_ENA;
  102. /*
  103. * When the dumb interface isn't in DUMB24_RGB888_0 mode, it might
  104. * be using SPI or GPIO. If we set this to DUMB_BLANK, we will
  105. * force LCD_D[23:0] to output blank color, overriding the GPIO or
  106. * SPI usage. So leave it as-is unless in DUMB24_RGB888_0 mode.
  107. */
  108. if (dpms_blanked(dcrtc->dpms) &&
  109. (dumb_ctrl & DUMB_MASK) == DUMB24_RGB888_0) {
  110. dumb_ctrl &= ~DUMB_MASK;
  111. dumb_ctrl |= DUMB_BLANK;
  112. }
  113. /*
  114. * The documentation doesn't indicate what the normal state of
  115. * the sync signals are. Sebastian Hesselbart kindly probed
  116. * these signals on his board to determine their state.
  117. *
  118. * The non-inverted state of the sync signals is active high.
  119. * Setting these bits makes the appropriate signal active low.
  120. */
  121. if (dcrtc->crtc.mode.flags & DRM_MODE_FLAG_NCSYNC)
  122. dumb_ctrl |= CFG_INV_CSYNC;
  123. if (dcrtc->crtc.mode.flags & DRM_MODE_FLAG_NHSYNC)
  124. dumb_ctrl |= CFG_INV_HSYNC;
  125. if (dcrtc->crtc.mode.flags & DRM_MODE_FLAG_NVSYNC)
  126. dumb_ctrl |= CFG_INV_VSYNC;
  127. if (dcrtc->dumb_ctrl != dumb_ctrl) {
  128. dcrtc->dumb_ctrl = dumb_ctrl;
  129. writel_relaxed(dumb_ctrl, dcrtc->base + LCD_SPU_DUMB_CTRL);
  130. }
  131. }
  132. static unsigned armada_drm_crtc_calc_fb(struct drm_framebuffer *fb,
  133. int x, int y, struct armada_regs *regs, bool interlaced)
  134. {
  135. struct armada_gem_object *obj = drm_fb_obj(fb);
  136. unsigned pitch = fb->pitches[0];
  137. unsigned offset = y * pitch + x * fb->bits_per_pixel / 8;
  138. uint32_t addr_odd, addr_even;
  139. unsigned i = 0;
  140. DRM_DEBUG_DRIVER("pitch %u x %d y %d bpp %d\n",
  141. pitch, x, y, fb->bits_per_pixel);
  142. addr_odd = addr_even = obj->dev_addr + offset;
  143. if (interlaced) {
  144. addr_even += pitch;
  145. pitch *= 2;
  146. }
  147. /* write offset, base, and pitch */
  148. armada_reg_queue_set(regs, i, addr_odd, LCD_CFG_GRA_START_ADDR0);
  149. armada_reg_queue_set(regs, i, addr_even, LCD_CFG_GRA_START_ADDR1);
  150. armada_reg_queue_mod(regs, i, pitch, 0xffff, LCD_CFG_GRA_PITCH);
  151. return i;
  152. }
  153. static int armada_drm_crtc_queue_frame_work(struct armada_crtc *dcrtc,
  154. struct armada_frame_work *work)
  155. {
  156. struct drm_device *dev = dcrtc->crtc.dev;
  157. unsigned long flags;
  158. int ret;
  159. ret = drm_vblank_get(dev, dcrtc->num);
  160. if (ret) {
  161. DRM_ERROR("failed to acquire vblank counter\n");
  162. return ret;
  163. }
  164. spin_lock_irqsave(&dev->event_lock, flags);
  165. if (!dcrtc->frame_work)
  166. dcrtc->frame_work = work;
  167. else
  168. ret = -EBUSY;
  169. spin_unlock_irqrestore(&dev->event_lock, flags);
  170. if (ret)
  171. drm_vblank_put(dev, dcrtc->num);
  172. return ret;
  173. }
  174. static void armada_drm_crtc_complete_frame_work(struct armada_crtc *dcrtc)
  175. {
  176. struct drm_device *dev = dcrtc->crtc.dev;
  177. struct armada_frame_work *work = dcrtc->frame_work;
  178. dcrtc->frame_work = NULL;
  179. armada_drm_crtc_update_regs(dcrtc, work->regs);
  180. if (work->event)
  181. drm_send_vblank_event(dev, dcrtc->num, work->event);
  182. drm_vblank_put(dev, dcrtc->num);
  183. /* Finally, queue the process-half of the cleanup. */
  184. __armada_drm_queue_unref_work(dcrtc->crtc.dev, work->old_fb);
  185. kfree(work);
  186. }
  187. static void armada_drm_crtc_finish_fb(struct armada_crtc *dcrtc,
  188. struct drm_framebuffer *fb, bool force)
  189. {
  190. struct armada_frame_work *work;
  191. if (!fb)
  192. return;
  193. if (force) {
  194. /* Display is disabled, so just drop the old fb */
  195. drm_framebuffer_unreference(fb);
  196. return;
  197. }
  198. work = kmalloc(sizeof(*work), GFP_KERNEL);
  199. if (work) {
  200. int i = 0;
  201. work->event = NULL;
  202. work->old_fb = fb;
  203. armada_reg_queue_end(work->regs, i);
  204. if (armada_drm_crtc_queue_frame_work(dcrtc, work) == 0)
  205. return;
  206. kfree(work);
  207. }
  208. /*
  209. * Oops - just drop the reference immediately and hope for
  210. * the best. The worst that will happen is the buffer gets
  211. * reused before it has finished being displayed.
  212. */
  213. drm_framebuffer_unreference(fb);
  214. }
  215. static void armada_drm_vblank_off(struct armada_crtc *dcrtc)
  216. {
  217. struct drm_device *dev = dcrtc->crtc.dev;
  218. /*
  219. * Tell the DRM core that vblank IRQs aren't going to happen for
  220. * a while. This cleans up any pending vblank events for us.
  221. */
  222. drm_vblank_off(dev, dcrtc->num);
  223. /* Handle any pending flip event. */
  224. spin_lock_irq(&dev->event_lock);
  225. if (dcrtc->frame_work)
  226. armada_drm_crtc_complete_frame_work(dcrtc);
  227. spin_unlock_irq(&dev->event_lock);
  228. }
  229. void armada_drm_crtc_gamma_set(struct drm_crtc *crtc, u16 r, u16 g, u16 b,
  230. int idx)
  231. {
  232. }
  233. void armada_drm_crtc_gamma_get(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
  234. int idx)
  235. {
  236. }
  237. /* The mode_config.mutex will be held for this call */
  238. static void armada_drm_crtc_dpms(struct drm_crtc *crtc, int dpms)
  239. {
  240. struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
  241. if (dcrtc->dpms != dpms) {
  242. dcrtc->dpms = dpms;
  243. armada_drm_crtc_update(dcrtc);
  244. if (dpms_blanked(dpms))
  245. armada_drm_vblank_off(dcrtc);
  246. }
  247. }
  248. /*
  249. * Prepare for a mode set. Turn off overlay to ensure that we don't end
  250. * up with the overlay size being bigger than the active screen size.
  251. * We rely upon X refreshing this state after the mode set has completed.
  252. *
  253. * The mode_config.mutex will be held for this call
  254. */
  255. static void armada_drm_crtc_prepare(struct drm_crtc *crtc)
  256. {
  257. struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
  258. struct drm_plane *plane;
  259. /*
  260. * If we have an overlay plane associated with this CRTC, disable
  261. * it before the modeset to avoid its coordinates being outside
  262. * the new mode parameters. DRM doesn't provide help with this.
  263. */
  264. plane = dcrtc->plane;
  265. if (plane) {
  266. struct drm_framebuffer *fb = plane->fb;
  267. plane->funcs->disable_plane(plane);
  268. plane->fb = NULL;
  269. plane->crtc = NULL;
  270. drm_framebuffer_unreference(fb);
  271. }
  272. }
  273. /* The mode_config.mutex will be held for this call */
  274. static void armada_drm_crtc_commit(struct drm_crtc *crtc)
  275. {
  276. struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
  277. if (dcrtc->dpms != DRM_MODE_DPMS_ON) {
  278. dcrtc->dpms = DRM_MODE_DPMS_ON;
  279. armada_drm_crtc_update(dcrtc);
  280. }
  281. }
  282. /* The mode_config.mutex will be held for this call */
  283. static bool armada_drm_crtc_mode_fixup(struct drm_crtc *crtc,
  284. const struct drm_display_mode *mode, struct drm_display_mode *adj)
  285. {
  286. struct armada_private *priv = crtc->dev->dev_private;
  287. struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
  288. int ret;
  289. /* We can't do interlaced modes if we don't have the SPU_ADV_REG */
  290. if (!priv->variant->has_spu_adv_reg &&
  291. adj->flags & DRM_MODE_FLAG_INTERLACE)
  292. return false;
  293. /* Check whether the display mode is possible */
  294. ret = priv->variant->crtc_compute_clock(dcrtc, adj, NULL);
  295. if (ret)
  296. return false;
  297. return true;
  298. }
  299. void armada_drm_crtc_irq(struct armada_crtc *dcrtc, u32 stat)
  300. {
  301. struct armada_vbl_event *e, *n;
  302. void __iomem *base = dcrtc->base;
  303. if (stat & DMA_FF_UNDERFLOW)
  304. DRM_ERROR("video underflow on crtc %u\n", dcrtc->num);
  305. if (stat & GRA_FF_UNDERFLOW)
  306. DRM_ERROR("graphics underflow on crtc %u\n", dcrtc->num);
  307. if (stat & VSYNC_IRQ)
  308. drm_handle_vblank(dcrtc->crtc.dev, dcrtc->num);
  309. spin_lock(&dcrtc->irq_lock);
  310. list_for_each_entry_safe(e, n, &dcrtc->vbl_list, node) {
  311. list_del_init(&e->node);
  312. drm_vblank_put(dcrtc->crtc.dev, dcrtc->num);
  313. e->fn(dcrtc, e->data);
  314. }
  315. if (stat & GRA_FRAME_IRQ && dcrtc->interlaced) {
  316. int i = stat & GRA_FRAME_IRQ0 ? 0 : 1;
  317. uint32_t val;
  318. writel_relaxed(dcrtc->v[i].spu_v_porch, base + LCD_SPU_V_PORCH);
  319. writel_relaxed(dcrtc->v[i].spu_v_h_total,
  320. base + LCD_SPUT_V_H_TOTAL);
  321. val = readl_relaxed(base + LCD_SPU_ADV_REG);
  322. val &= ~(ADV_VSYNC_L_OFF | ADV_VSYNC_H_OFF | ADV_VSYNCOFFEN);
  323. val |= dcrtc->v[i].spu_adv_reg;
  324. writel_relaxed(val, base + LCD_SPU_ADV_REG);
  325. }
  326. if (stat & DUMB_FRAMEDONE && dcrtc->cursor_update) {
  327. writel_relaxed(dcrtc->cursor_hw_pos,
  328. base + LCD_SPU_HWC_OVSA_HPXL_VLN);
  329. writel_relaxed(dcrtc->cursor_hw_sz,
  330. base + LCD_SPU_HWC_HPXL_VLN);
  331. armada_updatel(CFG_HWC_ENA,
  332. CFG_HWC_ENA | CFG_HWC_1BITMOD | CFG_HWC_1BITENA,
  333. base + LCD_SPU_DMA_CTRL0);
  334. dcrtc->cursor_update = false;
  335. armada_drm_crtc_disable_irq(dcrtc, DUMB_FRAMEDONE_ENA);
  336. }
  337. spin_unlock(&dcrtc->irq_lock);
  338. if (stat & GRA_FRAME_IRQ) {
  339. struct drm_device *dev = dcrtc->crtc.dev;
  340. spin_lock(&dev->event_lock);
  341. if (dcrtc->frame_work)
  342. armada_drm_crtc_complete_frame_work(dcrtc);
  343. spin_unlock(&dev->event_lock);
  344. wake_up(&dcrtc->frame_wait);
  345. }
  346. }
  347. /* These are locked by dev->vbl_lock */
  348. void armada_drm_crtc_disable_irq(struct armada_crtc *dcrtc, u32 mask)
  349. {
  350. if (dcrtc->irq_ena & mask) {
  351. dcrtc->irq_ena &= ~mask;
  352. writel(dcrtc->irq_ena, dcrtc->base + LCD_SPU_IRQ_ENA);
  353. }
  354. }
  355. void armada_drm_crtc_enable_irq(struct armada_crtc *dcrtc, u32 mask)
  356. {
  357. if ((dcrtc->irq_ena & mask) != mask) {
  358. dcrtc->irq_ena |= mask;
  359. writel(dcrtc->irq_ena, dcrtc->base + LCD_SPU_IRQ_ENA);
  360. if (readl_relaxed(dcrtc->base + LCD_SPU_IRQ_ISR) & mask)
  361. writel(0, dcrtc->base + LCD_SPU_IRQ_ISR);
  362. }
  363. }
  364. static uint32_t armada_drm_crtc_calculate_csc(struct armada_crtc *dcrtc)
  365. {
  366. struct drm_display_mode *adj = &dcrtc->crtc.mode;
  367. uint32_t val = 0;
  368. if (dcrtc->csc_yuv_mode == CSC_YUV_CCIR709)
  369. val |= CFG_CSC_YUV_CCIR709;
  370. if (dcrtc->csc_rgb_mode == CSC_RGB_STUDIO)
  371. val |= CFG_CSC_RGB_STUDIO;
  372. /*
  373. * In auto mode, set the colorimetry, based upon the HDMI spec.
  374. * 1280x720p, 1920x1080p and 1920x1080i use ITU709, others use
  375. * ITU601. It may be more appropriate to set this depending on
  376. * the source - but what if the graphic frame is YUV and the
  377. * video frame is RGB?
  378. */
  379. if ((adj->hdisplay == 1280 && adj->vdisplay == 720 &&
  380. !(adj->flags & DRM_MODE_FLAG_INTERLACE)) ||
  381. (adj->hdisplay == 1920 && adj->vdisplay == 1080)) {
  382. if (dcrtc->csc_yuv_mode == CSC_AUTO)
  383. val |= CFG_CSC_YUV_CCIR709;
  384. }
  385. /*
  386. * We assume we're connected to a TV-like device, so the YUV->RGB
  387. * conversion should produce a limited range. We should set this
  388. * depending on the connectors attached to this CRTC, and what
  389. * kind of device they report being connected.
  390. */
  391. if (dcrtc->csc_rgb_mode == CSC_AUTO)
  392. val |= CFG_CSC_RGB_STUDIO;
  393. return val;
  394. }
  395. /* The mode_config.mutex will be held for this call */
  396. static int armada_drm_crtc_mode_set(struct drm_crtc *crtc,
  397. struct drm_display_mode *mode, struct drm_display_mode *adj,
  398. int x, int y, struct drm_framebuffer *old_fb)
  399. {
  400. struct armada_private *priv = crtc->dev->dev_private;
  401. struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
  402. struct armada_regs regs[17];
  403. uint32_t lm, rm, tm, bm, val, sclk;
  404. unsigned long flags;
  405. unsigned i;
  406. bool interlaced;
  407. drm_framebuffer_reference(crtc->primary->fb);
  408. interlaced = !!(adj->flags & DRM_MODE_FLAG_INTERLACE);
  409. i = armada_drm_crtc_calc_fb(dcrtc->crtc.primary->fb,
  410. x, y, regs, interlaced);
  411. rm = adj->crtc_hsync_start - adj->crtc_hdisplay;
  412. lm = adj->crtc_htotal - adj->crtc_hsync_end;
  413. bm = adj->crtc_vsync_start - adj->crtc_vdisplay;
  414. tm = adj->crtc_vtotal - adj->crtc_vsync_end;
  415. DRM_DEBUG_DRIVER("H: %d %d %d %d lm %d rm %d\n",
  416. adj->crtc_hdisplay,
  417. adj->crtc_hsync_start,
  418. adj->crtc_hsync_end,
  419. adj->crtc_htotal, lm, rm);
  420. DRM_DEBUG_DRIVER("V: %d %d %d %d tm %d bm %d\n",
  421. adj->crtc_vdisplay,
  422. adj->crtc_vsync_start,
  423. adj->crtc_vsync_end,
  424. adj->crtc_vtotal, tm, bm);
  425. /* Wait for pending flips to complete */
  426. wait_event(dcrtc->frame_wait, !dcrtc->frame_work);
  427. drm_vblank_pre_modeset(crtc->dev, dcrtc->num);
  428. crtc->mode = *adj;
  429. val = dcrtc->dumb_ctrl & ~CFG_DUMB_ENA;
  430. if (val != dcrtc->dumb_ctrl) {
  431. dcrtc->dumb_ctrl = val;
  432. writel_relaxed(val, dcrtc->base + LCD_SPU_DUMB_CTRL);
  433. }
  434. /* Now compute the divider for real */
  435. priv->variant->crtc_compute_clock(dcrtc, adj, &sclk);
  436. /* Ensure graphic fifo is enabled */
  437. armada_reg_queue_mod(regs, i, 0, CFG_PDWN64x66, LCD_SPU_SRAM_PARA1);
  438. armada_reg_queue_set(regs, i, sclk, LCD_CFG_SCLK_DIV);
  439. if (interlaced ^ dcrtc->interlaced) {
  440. if (adj->flags & DRM_MODE_FLAG_INTERLACE)
  441. drm_vblank_get(dcrtc->crtc.dev, dcrtc->num);
  442. else
  443. drm_vblank_put(dcrtc->crtc.dev, dcrtc->num);
  444. dcrtc->interlaced = interlaced;
  445. }
  446. spin_lock_irqsave(&dcrtc->irq_lock, flags);
  447. /* Even interlaced/progressive frame */
  448. dcrtc->v[1].spu_v_h_total = adj->crtc_vtotal << 16 |
  449. adj->crtc_htotal;
  450. dcrtc->v[1].spu_v_porch = tm << 16 | bm;
  451. val = adj->crtc_hsync_start;
  452. dcrtc->v[1].spu_adv_reg = val << 20 | val | ADV_VSYNCOFFEN |
  453. priv->variant->spu_adv_reg;
  454. if (interlaced) {
  455. /* Odd interlaced frame */
  456. dcrtc->v[0].spu_v_h_total = dcrtc->v[1].spu_v_h_total +
  457. (1 << 16);
  458. dcrtc->v[0].spu_v_porch = dcrtc->v[1].spu_v_porch + 1;
  459. val = adj->crtc_hsync_start - adj->crtc_htotal / 2;
  460. dcrtc->v[0].spu_adv_reg = val << 20 | val | ADV_VSYNCOFFEN |
  461. priv->variant->spu_adv_reg;
  462. } else {
  463. dcrtc->v[0] = dcrtc->v[1];
  464. }
  465. val = adj->crtc_vdisplay << 16 | adj->crtc_hdisplay;
  466. armada_reg_queue_set(regs, i, val, LCD_SPU_V_H_ACTIVE);
  467. armada_reg_queue_set(regs, i, val, LCD_SPU_GRA_HPXL_VLN);
  468. armada_reg_queue_set(regs, i, val, LCD_SPU_GZM_HPXL_VLN);
  469. armada_reg_queue_set(regs, i, (lm << 16) | rm, LCD_SPU_H_PORCH);
  470. armada_reg_queue_set(regs, i, dcrtc->v[0].spu_v_porch, LCD_SPU_V_PORCH);
  471. armada_reg_queue_set(regs, i, dcrtc->v[0].spu_v_h_total,
  472. LCD_SPUT_V_H_TOTAL);
  473. if (priv->variant->has_spu_adv_reg) {
  474. armada_reg_queue_mod(regs, i, dcrtc->v[0].spu_adv_reg,
  475. ADV_VSYNC_L_OFF | ADV_VSYNC_H_OFF |
  476. ADV_VSYNCOFFEN, LCD_SPU_ADV_REG);
  477. }
  478. val = CFG_GRA_ENA | CFG_GRA_HSMOOTH;
  479. val |= CFG_GRA_FMT(drm_fb_to_armada_fb(dcrtc->crtc.primary->fb)->fmt);
  480. val |= CFG_GRA_MOD(drm_fb_to_armada_fb(dcrtc->crtc.primary->fb)->mod);
  481. if (drm_fb_to_armada_fb(dcrtc->crtc.primary->fb)->fmt > CFG_420)
  482. val |= CFG_PALETTE_ENA;
  483. if (interlaced)
  484. val |= CFG_GRA_FTOGGLE;
  485. armada_reg_queue_mod(regs, i, val, CFG_GRAFORMAT |
  486. CFG_GRA_MOD(CFG_SWAPRB | CFG_SWAPUV |
  487. CFG_SWAPYU | CFG_YUV2RGB) |
  488. CFG_PALETTE_ENA | CFG_GRA_FTOGGLE,
  489. LCD_SPU_DMA_CTRL0);
  490. val = adj->flags & DRM_MODE_FLAG_NVSYNC ? CFG_VSYNC_INV : 0;
  491. armada_reg_queue_mod(regs, i, val, CFG_VSYNC_INV, LCD_SPU_DMA_CTRL1);
  492. val = dcrtc->spu_iopad_ctrl | armada_drm_crtc_calculate_csc(dcrtc);
  493. armada_reg_queue_set(regs, i, val, LCD_SPU_IOPAD_CONTROL);
  494. armada_reg_queue_end(regs, i);
  495. armada_drm_crtc_update_regs(dcrtc, regs);
  496. spin_unlock_irqrestore(&dcrtc->irq_lock, flags);
  497. armada_drm_crtc_update(dcrtc);
  498. drm_vblank_post_modeset(crtc->dev, dcrtc->num);
  499. armada_drm_crtc_finish_fb(dcrtc, old_fb, dpms_blanked(dcrtc->dpms));
  500. return 0;
  501. }
  502. /* The mode_config.mutex will be held for this call */
  503. static int armada_drm_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
  504. struct drm_framebuffer *old_fb)
  505. {
  506. struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
  507. struct armada_regs regs[4];
  508. unsigned i;
  509. i = armada_drm_crtc_calc_fb(crtc->primary->fb, crtc->x, crtc->y, regs,
  510. dcrtc->interlaced);
  511. armada_reg_queue_end(regs, i);
  512. /* Wait for pending flips to complete */
  513. wait_event(dcrtc->frame_wait, !dcrtc->frame_work);
  514. /* Take a reference to the new fb as we're using it */
  515. drm_framebuffer_reference(crtc->primary->fb);
  516. /* Update the base in the CRTC */
  517. armada_drm_crtc_update_regs(dcrtc, regs);
  518. /* Drop our previously held reference */
  519. armada_drm_crtc_finish_fb(dcrtc, old_fb, dpms_blanked(dcrtc->dpms));
  520. return 0;
  521. }
  522. static void armada_drm_crtc_load_lut(struct drm_crtc *crtc)
  523. {
  524. }
  525. /* The mode_config.mutex will be held for this call */
  526. static void armada_drm_crtc_disable(struct drm_crtc *crtc)
  527. {
  528. struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
  529. armada_drm_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
  530. armada_drm_crtc_finish_fb(dcrtc, crtc->primary->fb, true);
  531. /* Power down most RAMs and FIFOs */
  532. writel_relaxed(CFG_PDWN256x32 | CFG_PDWN256x24 | CFG_PDWN256x8 |
  533. CFG_PDWN32x32 | CFG_PDWN16x66 | CFG_PDWN32x66 |
  534. CFG_PDWN64x66, dcrtc->base + LCD_SPU_SRAM_PARA1);
  535. }
  536. static const struct drm_crtc_helper_funcs armada_crtc_helper_funcs = {
  537. .dpms = armada_drm_crtc_dpms,
  538. .prepare = armada_drm_crtc_prepare,
  539. .commit = armada_drm_crtc_commit,
  540. .mode_fixup = armada_drm_crtc_mode_fixup,
  541. .mode_set = armada_drm_crtc_mode_set,
  542. .mode_set_base = armada_drm_crtc_mode_set_base,
  543. .load_lut = armada_drm_crtc_load_lut,
  544. .disable = armada_drm_crtc_disable,
  545. };
  546. static void armada_load_cursor_argb(void __iomem *base, uint32_t *pix,
  547. unsigned stride, unsigned width, unsigned height)
  548. {
  549. uint32_t addr;
  550. unsigned y;
  551. addr = SRAM_HWC32_RAM1;
  552. for (y = 0; y < height; y++) {
  553. uint32_t *p = &pix[y * stride];
  554. unsigned x;
  555. for (x = 0; x < width; x++, p++) {
  556. uint32_t val = *p;
  557. val = (val & 0xff00ff00) |
  558. (val & 0x000000ff) << 16 |
  559. (val & 0x00ff0000) >> 16;
  560. writel_relaxed(val,
  561. base + LCD_SPU_SRAM_WRDAT);
  562. writel_relaxed(addr | SRAM_WRITE,
  563. base + LCD_SPU_SRAM_CTRL);
  564. readl_relaxed(base + LCD_SPU_HWC_OVSA_HPXL_VLN);
  565. addr += 1;
  566. if ((addr & 0x00ff) == 0)
  567. addr += 0xf00;
  568. if ((addr & 0x30ff) == 0)
  569. addr = SRAM_HWC32_RAM2;
  570. }
  571. }
  572. }
  573. static void armada_drm_crtc_cursor_tran(void __iomem *base)
  574. {
  575. unsigned addr;
  576. for (addr = 0; addr < 256; addr++) {
  577. /* write the default value */
  578. writel_relaxed(0x55555555, base + LCD_SPU_SRAM_WRDAT);
  579. writel_relaxed(addr | SRAM_WRITE | SRAM_HWC32_TRAN,
  580. base + LCD_SPU_SRAM_CTRL);
  581. }
  582. }
  583. static int armada_drm_crtc_cursor_update(struct armada_crtc *dcrtc, bool reload)
  584. {
  585. uint32_t xoff, xscr, w = dcrtc->cursor_w, s;
  586. uint32_t yoff, yscr, h = dcrtc->cursor_h;
  587. uint32_t para1;
  588. /*
  589. * Calculate the visible width and height of the cursor,
  590. * screen position, and the position in the cursor bitmap.
  591. */
  592. if (dcrtc->cursor_x < 0) {
  593. xoff = -dcrtc->cursor_x;
  594. xscr = 0;
  595. w -= min(xoff, w);
  596. } else if (dcrtc->cursor_x + w > dcrtc->crtc.mode.hdisplay) {
  597. xoff = 0;
  598. xscr = dcrtc->cursor_x;
  599. w = max_t(int, dcrtc->crtc.mode.hdisplay - dcrtc->cursor_x, 0);
  600. } else {
  601. xoff = 0;
  602. xscr = dcrtc->cursor_x;
  603. }
  604. if (dcrtc->cursor_y < 0) {
  605. yoff = -dcrtc->cursor_y;
  606. yscr = 0;
  607. h -= min(yoff, h);
  608. } else if (dcrtc->cursor_y + h > dcrtc->crtc.mode.vdisplay) {
  609. yoff = 0;
  610. yscr = dcrtc->cursor_y;
  611. h = max_t(int, dcrtc->crtc.mode.vdisplay - dcrtc->cursor_y, 0);
  612. } else {
  613. yoff = 0;
  614. yscr = dcrtc->cursor_y;
  615. }
  616. /* On interlaced modes, the vertical cursor size must be halved */
  617. s = dcrtc->cursor_w;
  618. if (dcrtc->interlaced) {
  619. s *= 2;
  620. yscr /= 2;
  621. h /= 2;
  622. }
  623. if (!dcrtc->cursor_obj || !h || !w) {
  624. spin_lock_irq(&dcrtc->irq_lock);
  625. armada_drm_crtc_disable_irq(dcrtc, DUMB_FRAMEDONE_ENA);
  626. dcrtc->cursor_update = false;
  627. armada_updatel(0, CFG_HWC_ENA, dcrtc->base + LCD_SPU_DMA_CTRL0);
  628. spin_unlock_irq(&dcrtc->irq_lock);
  629. return 0;
  630. }
  631. para1 = readl_relaxed(dcrtc->base + LCD_SPU_SRAM_PARA1);
  632. armada_updatel(CFG_CSB_256x32, CFG_CSB_256x32 | CFG_PDWN256x32,
  633. dcrtc->base + LCD_SPU_SRAM_PARA1);
  634. /*
  635. * Initialize the transparency if the SRAM was powered down.
  636. * We must also reload the cursor data as well.
  637. */
  638. if (!(para1 & CFG_CSB_256x32)) {
  639. armada_drm_crtc_cursor_tran(dcrtc->base);
  640. reload = true;
  641. }
  642. if (dcrtc->cursor_hw_sz != (h << 16 | w)) {
  643. spin_lock_irq(&dcrtc->irq_lock);
  644. armada_drm_crtc_disable_irq(dcrtc, DUMB_FRAMEDONE_ENA);
  645. dcrtc->cursor_update = false;
  646. armada_updatel(0, CFG_HWC_ENA, dcrtc->base + LCD_SPU_DMA_CTRL0);
  647. spin_unlock_irq(&dcrtc->irq_lock);
  648. reload = true;
  649. }
  650. if (reload) {
  651. struct armada_gem_object *obj = dcrtc->cursor_obj;
  652. uint32_t *pix;
  653. /* Set the top-left corner of the cursor image */
  654. pix = obj->addr;
  655. pix += yoff * s + xoff;
  656. armada_load_cursor_argb(dcrtc->base, pix, s, w, h);
  657. }
  658. /* Reload the cursor position, size and enable in the IRQ handler */
  659. spin_lock_irq(&dcrtc->irq_lock);
  660. dcrtc->cursor_hw_pos = yscr << 16 | xscr;
  661. dcrtc->cursor_hw_sz = h << 16 | w;
  662. dcrtc->cursor_update = true;
  663. armada_drm_crtc_enable_irq(dcrtc, DUMB_FRAMEDONE_ENA);
  664. spin_unlock_irq(&dcrtc->irq_lock);
  665. return 0;
  666. }
  667. static void cursor_update(void *data)
  668. {
  669. armada_drm_crtc_cursor_update(data, true);
  670. }
  671. static int armada_drm_crtc_cursor_set(struct drm_crtc *crtc,
  672. struct drm_file *file, uint32_t handle, uint32_t w, uint32_t h)
  673. {
  674. struct drm_device *dev = crtc->dev;
  675. struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
  676. struct armada_private *priv = crtc->dev->dev_private;
  677. struct armada_gem_object *obj = NULL;
  678. int ret;
  679. /* If no cursor support, replicate drm's return value */
  680. if (!priv->variant->has_spu_adv_reg)
  681. return -ENXIO;
  682. if (handle && w > 0 && h > 0) {
  683. /* maximum size is 64x32 or 32x64 */
  684. if (w > 64 || h > 64 || (w > 32 && h > 32))
  685. return -ENOMEM;
  686. obj = armada_gem_object_lookup(dev, file, handle);
  687. if (!obj)
  688. return -ENOENT;
  689. /* Must be a kernel-mapped object */
  690. if (!obj->addr) {
  691. drm_gem_object_unreference_unlocked(&obj->obj);
  692. return -EINVAL;
  693. }
  694. if (obj->obj.size < w * h * 4) {
  695. DRM_ERROR("buffer is too small\n");
  696. drm_gem_object_unreference_unlocked(&obj->obj);
  697. return -ENOMEM;
  698. }
  699. }
  700. mutex_lock(&dev->struct_mutex);
  701. if (dcrtc->cursor_obj) {
  702. dcrtc->cursor_obj->update = NULL;
  703. dcrtc->cursor_obj->update_data = NULL;
  704. drm_gem_object_unreference(&dcrtc->cursor_obj->obj);
  705. }
  706. dcrtc->cursor_obj = obj;
  707. dcrtc->cursor_w = w;
  708. dcrtc->cursor_h = h;
  709. ret = armada_drm_crtc_cursor_update(dcrtc, true);
  710. if (obj) {
  711. obj->update_data = dcrtc;
  712. obj->update = cursor_update;
  713. }
  714. mutex_unlock(&dev->struct_mutex);
  715. return ret;
  716. }
  717. static int armada_drm_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
  718. {
  719. struct drm_device *dev = crtc->dev;
  720. struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
  721. struct armada_private *priv = crtc->dev->dev_private;
  722. int ret;
  723. /* If no cursor support, replicate drm's return value */
  724. if (!priv->variant->has_spu_adv_reg)
  725. return -EFAULT;
  726. mutex_lock(&dev->struct_mutex);
  727. dcrtc->cursor_x = x;
  728. dcrtc->cursor_y = y;
  729. ret = armada_drm_crtc_cursor_update(dcrtc, false);
  730. mutex_unlock(&dev->struct_mutex);
  731. return ret;
  732. }
  733. static void armada_drm_crtc_destroy(struct drm_crtc *crtc)
  734. {
  735. struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
  736. struct armada_private *priv = crtc->dev->dev_private;
  737. if (dcrtc->cursor_obj)
  738. drm_gem_object_unreference(&dcrtc->cursor_obj->obj);
  739. priv->dcrtc[dcrtc->num] = NULL;
  740. drm_crtc_cleanup(&dcrtc->crtc);
  741. if (!IS_ERR(dcrtc->clk))
  742. clk_disable_unprepare(dcrtc->clk);
  743. kfree(dcrtc);
  744. }
  745. /*
  746. * The mode_config lock is held here, to prevent races between this
  747. * and a mode_set.
  748. */
  749. static int armada_drm_crtc_page_flip(struct drm_crtc *crtc,
  750. struct drm_framebuffer *fb, struct drm_pending_vblank_event *event, uint32_t page_flip_flags)
  751. {
  752. struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
  753. struct armada_frame_work *work;
  754. struct drm_device *dev = crtc->dev;
  755. unsigned long flags;
  756. unsigned i;
  757. int ret;
  758. /* We don't support changing the pixel format */
  759. if (fb->pixel_format != crtc->primary->fb->pixel_format)
  760. return -EINVAL;
  761. work = kmalloc(sizeof(*work), GFP_KERNEL);
  762. if (!work)
  763. return -ENOMEM;
  764. work->event = event;
  765. work->old_fb = dcrtc->crtc.primary->fb;
  766. i = armada_drm_crtc_calc_fb(fb, crtc->x, crtc->y, work->regs,
  767. dcrtc->interlaced);
  768. armada_reg_queue_end(work->regs, i);
  769. /*
  770. * Hold the old framebuffer for the work - DRM appears to drop our
  771. * reference to the old framebuffer in drm_mode_page_flip_ioctl().
  772. */
  773. drm_framebuffer_reference(work->old_fb);
  774. ret = armada_drm_crtc_queue_frame_work(dcrtc, work);
  775. if (ret) {
  776. /*
  777. * Undo our reference above; DRM does not drop the reference
  778. * to this object on error, so that's okay.
  779. */
  780. drm_framebuffer_unreference(work->old_fb);
  781. kfree(work);
  782. return ret;
  783. }
  784. /*
  785. * Don't take a reference on the new framebuffer;
  786. * drm_mode_page_flip_ioctl() has already grabbed a reference and
  787. * will _not_ drop that reference on successful return from this
  788. * function. Simply mark this new framebuffer as the current one.
  789. */
  790. dcrtc->crtc.primary->fb = fb;
  791. /*
  792. * Finally, if the display is blanked, we won't receive an
  793. * interrupt, so complete it now.
  794. */
  795. if (dpms_blanked(dcrtc->dpms)) {
  796. spin_lock_irqsave(&dev->event_lock, flags);
  797. if (dcrtc->frame_work)
  798. armada_drm_crtc_complete_frame_work(dcrtc);
  799. spin_unlock_irqrestore(&dev->event_lock, flags);
  800. }
  801. return 0;
  802. }
  803. static int
  804. armada_drm_crtc_set_property(struct drm_crtc *crtc,
  805. struct drm_property *property, uint64_t val)
  806. {
  807. struct armada_private *priv = crtc->dev->dev_private;
  808. struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
  809. bool update_csc = false;
  810. if (property == priv->csc_yuv_prop) {
  811. dcrtc->csc_yuv_mode = val;
  812. update_csc = true;
  813. } else if (property == priv->csc_rgb_prop) {
  814. dcrtc->csc_rgb_mode = val;
  815. update_csc = true;
  816. }
  817. if (update_csc) {
  818. uint32_t val;
  819. val = dcrtc->spu_iopad_ctrl |
  820. armada_drm_crtc_calculate_csc(dcrtc);
  821. writel_relaxed(val, dcrtc->base + LCD_SPU_IOPAD_CONTROL);
  822. }
  823. return 0;
  824. }
  825. static struct drm_crtc_funcs armada_crtc_funcs = {
  826. .cursor_set = armada_drm_crtc_cursor_set,
  827. .cursor_move = armada_drm_crtc_cursor_move,
  828. .destroy = armada_drm_crtc_destroy,
  829. .set_config = drm_crtc_helper_set_config,
  830. .page_flip = armada_drm_crtc_page_flip,
  831. .set_property = armada_drm_crtc_set_property,
  832. };
  833. static struct drm_prop_enum_list armada_drm_csc_yuv_enum_list[] = {
  834. { CSC_AUTO, "Auto" },
  835. { CSC_YUV_CCIR601, "CCIR601" },
  836. { CSC_YUV_CCIR709, "CCIR709" },
  837. };
  838. static struct drm_prop_enum_list armada_drm_csc_rgb_enum_list[] = {
  839. { CSC_AUTO, "Auto" },
  840. { CSC_RGB_COMPUTER, "Computer system" },
  841. { CSC_RGB_STUDIO, "Studio" },
  842. };
  843. static int armada_drm_crtc_create_properties(struct drm_device *dev)
  844. {
  845. struct armada_private *priv = dev->dev_private;
  846. if (priv->csc_yuv_prop)
  847. return 0;
  848. priv->csc_yuv_prop = drm_property_create_enum(dev, 0,
  849. "CSC_YUV", armada_drm_csc_yuv_enum_list,
  850. ARRAY_SIZE(armada_drm_csc_yuv_enum_list));
  851. priv->csc_rgb_prop = drm_property_create_enum(dev, 0,
  852. "CSC_RGB", armada_drm_csc_rgb_enum_list,
  853. ARRAY_SIZE(armada_drm_csc_rgb_enum_list));
  854. if (!priv->csc_yuv_prop || !priv->csc_rgb_prop)
  855. return -ENOMEM;
  856. return 0;
  857. }
  858. int armada_drm_crtc_create(struct drm_device *dev, unsigned num,
  859. struct resource *res)
  860. {
  861. struct armada_private *priv = dev->dev_private;
  862. struct armada_crtc *dcrtc;
  863. void __iomem *base;
  864. int ret;
  865. ret = armada_drm_crtc_create_properties(dev);
  866. if (ret)
  867. return ret;
  868. base = devm_request_and_ioremap(dev->dev, res);
  869. if (!base) {
  870. DRM_ERROR("failed to ioremap register\n");
  871. return -ENOMEM;
  872. }
  873. dcrtc = kzalloc(sizeof(*dcrtc), GFP_KERNEL);
  874. if (!dcrtc) {
  875. DRM_ERROR("failed to allocate Armada crtc\n");
  876. return -ENOMEM;
  877. }
  878. dcrtc->base = base;
  879. dcrtc->num = num;
  880. dcrtc->clk = ERR_PTR(-EINVAL);
  881. dcrtc->csc_yuv_mode = CSC_AUTO;
  882. dcrtc->csc_rgb_mode = CSC_AUTO;
  883. dcrtc->cfg_dumb_ctrl = DUMB24_RGB888_0;
  884. dcrtc->spu_iopad_ctrl = CFG_VSCALE_LN_EN | CFG_IOPAD_DUMB24;
  885. spin_lock_init(&dcrtc->irq_lock);
  886. dcrtc->irq_ena = CLEAN_SPU_IRQ_ISR;
  887. INIT_LIST_HEAD(&dcrtc->vbl_list);
  888. init_waitqueue_head(&dcrtc->frame_wait);
  889. /* Initialize some registers which we don't otherwise set */
  890. writel_relaxed(0x00000001, dcrtc->base + LCD_CFG_SCLK_DIV);
  891. writel_relaxed(0x00000000, dcrtc->base + LCD_SPU_BLANKCOLOR);
  892. writel_relaxed(dcrtc->spu_iopad_ctrl,
  893. dcrtc->base + LCD_SPU_IOPAD_CONTROL);
  894. writel_relaxed(0x00000000, dcrtc->base + LCD_SPU_SRAM_PARA0);
  895. writel_relaxed(CFG_PDWN256x32 | CFG_PDWN256x24 | CFG_PDWN256x8 |
  896. CFG_PDWN32x32 | CFG_PDWN16x66 | CFG_PDWN32x66 |
  897. CFG_PDWN64x66, dcrtc->base + LCD_SPU_SRAM_PARA1);
  898. writel_relaxed(0x2032ff81, dcrtc->base + LCD_SPU_DMA_CTRL1);
  899. writel_relaxed(0x00000000, dcrtc->base + LCD_SPU_GRA_OVSA_HPXL_VLN);
  900. if (priv->variant->crtc_init) {
  901. ret = priv->variant->crtc_init(dcrtc);
  902. if (ret) {
  903. kfree(dcrtc);
  904. return ret;
  905. }
  906. }
  907. /* Ensure AXI pipeline is enabled */
  908. armada_updatel(CFG_ARBFAST_ENA, 0, dcrtc->base + LCD_SPU_DMA_CTRL0);
  909. priv->dcrtc[dcrtc->num] = dcrtc;
  910. drm_crtc_init(dev, &dcrtc->crtc, &armada_crtc_funcs);
  911. drm_crtc_helper_add(&dcrtc->crtc, &armada_crtc_helper_funcs);
  912. drm_object_attach_property(&dcrtc->crtc.base, priv->csc_yuv_prop,
  913. dcrtc->csc_yuv_mode);
  914. drm_object_attach_property(&dcrtc->crtc.base, priv->csc_rgb_prop,
  915. dcrtc->csc_rgb_mode);
  916. return armada_overlay_plane_create(dev, 1 << dcrtc->num);
  917. }