Lines Matching +full:lcdif +full:- +full:axi
1 // SPDX-License-Identifier: GPL-2.0-or-later
12 #include <linux/media-bus-format.h>
46 /* -----------------------------------------------------------------------------
68 * |R| |1.1644 0.0000 1.5960| |Y - 16 |
69 * |G| = |1.1644 -0.3917 -0.8129| * |Cb - 128|
70 * |B| |1.1644 2.0172 0.0000| |Cr - 128|
83 * |R| |1.0000 0.0000 1.4020| |Y - 0 |
84 * |G| = |1.0000 -0.3441 -0.7141| * |Cb - 128|
85 * |B| |1.0000 1.7720 0.0000| |Cr - 128|
100 * |R| |1.1644 0.0000 1.7927| |Y - 16 |
101 * |G| = |1.1644 -0.2132 -0.5329| * |Cb - 128|
102 * |B| |1.1644 2.1124 0.0000| |Cr - 128|
115 * |R| |1.0000 0.0000 1.5748| |Y - 0 |
116 * |G| = |1.0000 -0.1873 -0.4681| * |Cb - 128|
117 * |B| |1.0000 1.8556 0.0000| |Cr - 128|
132 * |R| |1.1644 0.0000 1.6787| |Y - 16 |
133 * |G| = |1.1644 -0.1874 -0.6505| * |Cb - 128|
134 * |B| |1.1644 2.1418 0.0000| |Cr - 128|
147 * |R| |1.0000 0.0000 1.4746| |Y - 0 |
148 * |G| = |1.0000 -0.1646 -0.5714| * |Cb - 128|
149 * |B| |1.0000 1.8814 0.0000| |Cr - 128|
161 static void lcdif_set_formats(struct lcdif_drm_private *lcdif, in lcdif_set_formats() argument
165 struct drm_device *drm = lcdif->drm; in lcdif_set_formats()
166 const u32 format = plane_state->fb->format->format; in lcdif_set_formats()
173 lcdif->base + LCDC_V8_DISP_PARA); in lcdif_set_formats()
177 lcdif->base + LCDC_V8_DISP_PARA); in lcdif_set_formats()
181 lcdif->base + LCDC_V8_DISP_PARA); in lcdif_set_formats()
185 dev_err(drm->dev, "Unknown media bus format 0x%x\n", bus_format); in lcdif_set_formats()
193 lcdif->base + LCDC_V8_CTRLDESCL0_5); in lcdif_set_formats()
197 lcdif->base + LCDC_V8_CTRLDESCL0_5); in lcdif_set_formats()
201 lcdif->base + LCDC_V8_CTRLDESCL0_5); in lcdif_set_formats()
205 lcdif->base + LCDC_V8_CTRLDESCL0_5); in lcdif_set_formats()
209 lcdif->base + LCDC_V8_CTRLDESCL0_5); in lcdif_set_formats()
213 lcdif->base + LCDC_V8_CTRLDESCL0_5); in lcdif_set_formats()
219 lcdif->base + LCDC_V8_CTRLDESCL0_5); in lcdif_set_formats()
224 lcdif->base + LCDC_V8_CTRLDESCL0_5); in lcdif_set_formats()
229 lcdif->base + LCDC_V8_CTRLDESCL0_5); in lcdif_set_formats()
234 lcdif->base + LCDC_V8_CTRLDESCL0_5); in lcdif_set_formats()
239 dev_err(drm->dev, "Unknown pixel format 0x%x\n", format); in lcdif_set_formats()
251 /* RGB -> YCbCr */ in lcdif_set_formats()
253 lcdif->base + LCDC_V8_CSC0_CTRL); in lcdif_set_formats()
259 * |Cb| = |-0.1482 -0.2910 0.4392| * |G| + |128| in lcdif_set_formats()
260 * |Cr| | 0.4392 0.4392 -0.3678| |B| |128| in lcdif_set_formats()
263 lcdif->base + LCDC_V8_CSC0_COEF0); in lcdif_set_formats()
265 lcdif->base + LCDC_V8_CSC0_COEF1); in lcdif_set_formats()
267 lcdif->base + LCDC_V8_CSC0_COEF2); in lcdif_set_formats()
269 lcdif->base + LCDC_V8_CSC0_COEF3); in lcdif_set_formats()
271 lcdif->base + LCDC_V8_CSC0_COEF4); in lcdif_set_formats()
273 lcdif->base + LCDC_V8_CSC0_COEF5); in lcdif_set_formats()
275 /* YCbCr -> RGB */ in lcdif_set_formats()
277 lcdif_yuv2rgb_coeffs[plane_state->color_encoding] in lcdif_set_formats()
278 [plane_state->color_range]; in lcdif_set_formats()
281 lcdif->base + LCDC_V8_CSC0_CTRL); in lcdif_set_formats()
283 writel(coeffs[0], lcdif->base + LCDC_V8_CSC0_COEF0); in lcdif_set_formats()
284 writel(coeffs[1], lcdif->base + LCDC_V8_CSC0_COEF1); in lcdif_set_formats()
285 writel(coeffs[2], lcdif->base + LCDC_V8_CSC0_COEF2); in lcdif_set_formats()
286 writel(coeffs[3], lcdif->base + LCDC_V8_CSC0_COEF3); in lcdif_set_formats()
287 writel(coeffs[4], lcdif->base + LCDC_V8_CSC0_COEF4); in lcdif_set_formats()
288 writel(coeffs[5], lcdif->base + LCDC_V8_CSC0_COEF5); in lcdif_set_formats()
290 /* RGB -> RGB, YCbCr -> YCbCr: bypass colorspace converter. */ in lcdif_set_formats()
291 writel(CSC0_CTRL_BYPASS, lcdif->base + LCDC_V8_CSC0_CTRL); in lcdif_set_formats()
295 static void lcdif_set_mode(struct lcdif_drm_private *lcdif, u32 bus_flags) in lcdif_set_mode() argument
297 struct drm_display_mode *m = &lcdif->crtc.state->adjusted_mode; in lcdif_set_mode()
300 if (m->flags & DRM_MODE_FLAG_NHSYNC) in lcdif_set_mode()
302 if (m->flags & DRM_MODE_FLAG_NVSYNC) in lcdif_set_mode()
309 writel(ctrl, lcdif->base + LCDC_V8_CTRL); in lcdif_set_mode()
311 writel(DISP_SIZE_DELTA_Y(m->vdisplay) | in lcdif_set_mode()
312 DISP_SIZE_DELTA_X(m->hdisplay), in lcdif_set_mode()
313 lcdif->base + LCDC_V8_DISP_SIZE); in lcdif_set_mode()
315 writel(HSYN_PARA_BP_H(m->htotal - m->hsync_end) | in lcdif_set_mode()
316 HSYN_PARA_FP_H(m->hsync_start - m->hdisplay), in lcdif_set_mode()
317 lcdif->base + LCDC_V8_HSYN_PARA); in lcdif_set_mode()
319 writel(VSYN_PARA_BP_V(m->vtotal - m->vsync_end) | in lcdif_set_mode()
320 VSYN_PARA_FP_V(m->vsync_start - m->vdisplay), in lcdif_set_mode()
321 lcdif->base + LCDC_V8_VSYN_PARA); in lcdif_set_mode()
323 writel(VSYN_HSYN_WIDTH_PW_V(m->vsync_end - m->vsync_start) | in lcdif_set_mode()
324 VSYN_HSYN_WIDTH_PW_H(m->hsync_end - m->hsync_start), in lcdif_set_mode()
325 lcdif->base + LCDC_V8_VSYN_HSYN_WIDTH); in lcdif_set_mode()
327 writel(CTRLDESCL0_1_HEIGHT(m->vdisplay) | in lcdif_set_mode()
328 CTRLDESCL0_1_WIDTH(m->hdisplay), in lcdif_set_mode()
329 lcdif->base + LCDC_V8_CTRLDESCL0_1); in lcdif_set_mode()
333 * downstream kernel those registers control the AXI burst size. As of in lcdif_set_mode()
335 * 1 - 128Byte in lcdif_set_mode()
336 * 2 - 256Byte in lcdif_set_mode()
341 CTRLDESCL0_3_PITCH(lcdif->crtc.primary->state->fb->pitches[0]); in lcdif_set_mode()
342 writel(ctrl, lcdif->base + LCDC_V8_CTRLDESCL0_3); in lcdif_set_mode()
345 static void lcdif_enable_controller(struct lcdif_drm_private *lcdif) in lcdif_enable_controller() argument
352 lcdif->base + LCDC_V8_PANIC0_THRES); in lcdif_enable_controller()
359 lcdif->base + LCDC_V8_INT_ENABLE_D1); in lcdif_enable_controller()
361 reg = readl(lcdif->base + LCDC_V8_DISP_PARA); in lcdif_enable_controller()
363 writel(reg, lcdif->base + LCDC_V8_DISP_PARA); in lcdif_enable_controller()
365 reg = readl(lcdif->base + LCDC_V8_CTRLDESCL0_5); in lcdif_enable_controller()
367 writel(reg, lcdif->base + LCDC_V8_CTRLDESCL0_5); in lcdif_enable_controller()
370 static void lcdif_disable_controller(struct lcdif_drm_private *lcdif) in lcdif_disable_controller() argument
375 reg = readl(lcdif->base + LCDC_V8_CTRLDESCL0_5); in lcdif_disable_controller()
377 writel(reg, lcdif->base + LCDC_V8_CTRLDESCL0_5); in lcdif_disable_controller()
379 ret = readl_poll_timeout(lcdif->base + LCDC_V8_CTRLDESCL0_5, in lcdif_disable_controller()
383 drm_err(lcdif->drm, "Failed to disable controller!\n"); in lcdif_disable_controller()
385 reg = readl(lcdif->base + LCDC_V8_DISP_PARA); in lcdif_disable_controller()
387 writel(reg, lcdif->base + LCDC_V8_DISP_PARA); in lcdif_disable_controller()
390 writel(0, lcdif->base + LCDC_V8_INT_ENABLE_D1); in lcdif_disable_controller()
393 static void lcdif_reset_block(struct lcdif_drm_private *lcdif) in lcdif_reset_block() argument
395 writel(CTRL_SW_RESET, lcdif->base + LCDC_V8_CTRL + REG_SET); in lcdif_reset_block()
396 readl(lcdif->base + LCDC_V8_CTRL); in lcdif_reset_block()
397 writel(CTRL_SW_RESET, lcdif->base + LCDC_V8_CTRL + REG_CLR); in lcdif_reset_block()
398 readl(lcdif->base + LCDC_V8_CTRL); in lcdif_reset_block()
405 struct drm_device *drm = crtc_state->crtc->dev; in lcdif_crtc_mode_set_nofb()
406 struct lcdif_drm_private *lcdif = to_lcdif_drm_private(drm); in lcdif_crtc_mode_set_nofb() local
407 struct drm_display_mode *m = &crtc_state->adjusted_mode; in lcdif_crtc_mode_set_nofb()
409 DRM_DEV_DEBUG_DRIVER(drm->dev, "Pixel clock: %dkHz (actual: %dkHz)\n", in lcdif_crtc_mode_set_nofb()
410 m->clock, (int)(clk_get_rate(lcdif->clk) / 1000)); in lcdif_crtc_mode_set_nofb()
411 DRM_DEV_DEBUG_DRIVER(drm->dev, "Bridge bus_flags: 0x%08X\n", in lcdif_crtc_mode_set_nofb()
412 lcdif_crtc_state->bus_flags); in lcdif_crtc_mode_set_nofb()
413 DRM_DEV_DEBUG_DRIVER(drm->dev, "Mode flags: 0x%08X\n", m->flags); in lcdif_crtc_mode_set_nofb()
416 lcdif_reset_block(lcdif); in lcdif_crtc_mode_set_nofb()
418 lcdif_set_formats(lcdif, plane_state, lcdif_crtc_state->bus_format); in lcdif_crtc_mode_set_nofb()
420 lcdif_set_mode(lcdif, lcdif_crtc_state->bus_flags); in lcdif_crtc_mode_set_nofb()
426 struct drm_device *drm = crtc->dev; in lcdif_crtc_atomic_check()
430 bool has_primary = crtc_state->plane_mask & in lcdif_crtc_atomic_check()
431 drm_plane_mask(crtc->primary); in lcdif_crtc_atomic_check()
442 if (crtc_state->active && !has_primary) in lcdif_crtc_atomic_check()
443 return -EINVAL; in lcdif_crtc_atomic_check()
451 if (!connector_state->crtc) in lcdif_crtc_atomic_check()
454 encoder = connector_state->best_encoder; in lcdif_crtc_atomic_check()
464 bus_format = bridge_state->input_bus_cfg.format; in lcdif_crtc_atomic_check()
467 dev_warn(drm->dev, in lcdif_crtc_atomic_check()
470 encoder->base.id, encoder->name); in lcdif_crtc_atomic_check()
478 lcdif_crtc_state->bus_format = bus_format; in lcdif_crtc_atomic_check()
480 } else if (lcdif_crtc_state->bus_format != bus_format) { in lcdif_crtc_atomic_check()
481 DRM_DEV_DEBUG_DRIVER(drm->dev, "inconsistent bus format\n"); in lcdif_crtc_atomic_check()
482 return -EINVAL; in lcdif_crtc_atomic_check()
485 if (bridge->timings) in lcdif_crtc_atomic_check()
486 bus_flags = bridge->timings->input_bus_flags; in lcdif_crtc_atomic_check()
488 bus_flags = bridge_state->input_bus_cfg.flags; in lcdif_crtc_atomic_check()
493 lcdif_crtc_state->bus_flags = bus_flags; in lcdif_crtc_atomic_check()
495 } else if (lcdif_crtc_state->bus_flags != bus_flags) { in lcdif_crtc_atomic_check()
496 DRM_DEV_DEBUG_DRIVER(drm->dev, "inconsistent bus flags\n"); in lcdif_crtc_atomic_check()
497 return -EINVAL; in lcdif_crtc_atomic_check()
507 struct lcdif_drm_private *lcdif = to_lcdif_drm_private(crtc->dev); in lcdif_crtc_atomic_flush() local
511 reg = readl(lcdif->base + LCDC_V8_CTRLDESCL0_5); in lcdif_crtc_atomic_flush()
513 writel(reg, lcdif->base + LCDC_V8_CTRLDESCL0_5); in lcdif_crtc_atomic_flush()
515 event = crtc->state->event; in lcdif_crtc_atomic_flush()
516 crtc->state->event = NULL; in lcdif_crtc_atomic_flush()
521 spin_lock_irq(&crtc->dev->event_lock); in lcdif_crtc_atomic_flush()
526 spin_unlock_irq(&crtc->dev->event_lock); in lcdif_crtc_atomic_flush()
532 struct lcdif_drm_private *lcdif = to_lcdif_drm_private(crtc->dev); in lcdif_crtc_atomic_enable() local
535 crtc->primary); in lcdif_crtc_atomic_enable()
536 struct drm_display_mode *m = &lcdif->crtc.state->adjusted_mode; in lcdif_crtc_atomic_enable()
537 struct drm_device *drm = lcdif->drm; in lcdif_crtc_atomic_enable()
540 clk_set_rate(lcdif->clk, m->clock * 1000); in lcdif_crtc_atomic_enable()
542 pm_runtime_get_sync(drm->dev); in lcdif_crtc_atomic_enable()
547 paddr = drm_fb_dma_get_gem_addr(new_pstate->fb, new_pstate, 0); in lcdif_crtc_atomic_enable()
550 lcdif->base + LCDC_V8_CTRLDESCL_LOW0_4); in lcdif_crtc_atomic_enable()
552 lcdif->base + LCDC_V8_CTRLDESCL_HIGH0_4); in lcdif_crtc_atomic_enable()
554 lcdif_enable_controller(lcdif); in lcdif_crtc_atomic_enable()
562 struct lcdif_drm_private *lcdif = to_lcdif_drm_private(crtc->dev); in lcdif_crtc_atomic_disable() local
563 struct drm_device *drm = lcdif->drm; in lcdif_crtc_atomic_disable()
568 lcdif_disable_controller(lcdif); in lcdif_crtc_atomic_disable()
570 spin_lock_irq(&drm->event_lock); in lcdif_crtc_atomic_disable()
571 event = crtc->state->event; in lcdif_crtc_atomic_disable()
573 crtc->state->event = NULL; in lcdif_crtc_atomic_disable()
576 spin_unlock_irq(&drm->event_lock); in lcdif_crtc_atomic_disable()
578 pm_runtime_put_sync(drm->dev); in lcdif_crtc_atomic_disable()
592 if (crtc->state) in lcdif_crtc_reset()
593 lcdif_crtc_atomic_destroy_state(crtc, crtc->state); in lcdif_crtc_reset()
595 crtc->state = NULL; in lcdif_crtc_reset()
599 __drm_atomic_helper_crtc_reset(crtc, &state->base); in lcdif_crtc_reset()
605 struct lcdif_crtc_state *old = to_lcdif_crtc_state(crtc->state); in lcdif_crtc_atomic_duplicate_state()
608 if (WARN_ON(!crtc->state)) in lcdif_crtc_atomic_duplicate_state()
615 __drm_atomic_helper_crtc_duplicate_state(crtc, &new->base); in lcdif_crtc_atomic_duplicate_state()
617 new->bus_format = old->bus_format; in lcdif_crtc_atomic_duplicate_state()
618 new->bus_flags = old->bus_flags; in lcdif_crtc_atomic_duplicate_state()
620 return &new->base; in lcdif_crtc_atomic_duplicate_state()
625 struct lcdif_drm_private *lcdif = to_lcdif_drm_private(crtc->dev); in lcdif_crtc_enable_vblank() local
628 writel(INT_STATUS_D0_VS_BLANK, lcdif->base + LCDC_V8_INT_STATUS_D0); in lcdif_crtc_enable_vblank()
629 writel(INT_ENABLE_D0_VS_BLANK_EN, lcdif->base + LCDC_V8_INT_ENABLE_D0); in lcdif_crtc_enable_vblank()
636 struct lcdif_drm_private *lcdif = to_lcdif_drm_private(crtc->dev); in lcdif_crtc_disable_vblank() local
639 writel(0, lcdif->base + LCDC_V8_INT_ENABLE_D0); in lcdif_crtc_disable_vblank()
640 writel(INT_STATUS_D0_VS_BLANK, lcdif->base + LCDC_V8_INT_STATUS_D0); in lcdif_crtc_disable_vblank()
661 /* -----------------------------------------------------------------------------
670 struct lcdif_drm_private *lcdif = to_lcdif_drm_private(plane->dev); in lcdif_plane_atomic_check() local
674 &lcdif->crtc); in lcdif_plane_atomic_check()
685 struct lcdif_drm_private *lcdif = to_lcdif_drm_private(plane->dev); in lcdif_plane_primary_atomic_update() local
690 paddr = drm_fb_dma_get_gem_addr(new_pstate->fb, new_pstate, 0); in lcdif_plane_primary_atomic_update()
693 lcdif->base + LCDC_V8_CTRLDESCL_LOW0_4); in lcdif_plane_primary_atomic_update()
695 lcdif->base + LCDC_V8_CTRLDESCL_HIGH0_4); in lcdif_plane_primary_atomic_update()
742 /* -----------------------------------------------------------------------------
746 int lcdif_kms_init(struct lcdif_drm_private *lcdif) in lcdif_kms_init() argument
753 struct drm_crtc *crtc = &lcdif->crtc; in lcdif_kms_init()
756 drm_plane_helper_add(&lcdif->planes.primary, in lcdif_kms_init()
758 ret = drm_universal_plane_init(lcdif->drm, &lcdif->planes.primary, 1, in lcdif_kms_init()
767 ret = drm_plane_create_color_properties(&lcdif->planes.primary, in lcdif_kms_init()
776 return drm_crtc_init_with_planes(lcdif->drm, crtc, in lcdif_kms_init()
777 &lcdif->planes.primary, NULL, in lcdif_kms_init()