static void rcar_du_group_setup(struct rcar_du_group *rgrp) { /* Enable extended features */ rcar_du_group_write(rgrp, DEFR, DEFR_CODE | DEFR_DEFE); rcar_du_group_write(rgrp, DEFR2, DEFR2_CODE | DEFR2_DEFE2G); rcar_du_group_write(rgrp, DEFR3, DEFR3_CODE | DEFR3_DEFE3); rcar_du_group_write(rgrp, DEFR4, DEFR4_CODE); rcar_du_group_write(rgrp, DEFR5, DEFR5_CODE | DEFR5_DEFE5); if (rcar_du_has(rgrp->dev, RCAR_DU_FEATURE_EXT_CTRL_REGS)) { rcar_du_group_setup_defr8(rgrp); /* Configure input dot clock routing. We currently hardcode the * configuration to routing DOTCLKINn to DUn. */ rcar_du_group_write(rgrp, DIDSR, DIDSR_CODE | DIDSR_LCDS_DCLKIN(2) | DIDSR_LCDS_DCLKIN(1) | DIDSR_LCDS_DCLKIN(0) | DIDSR_PDCS_CLK(2, 0) | DIDSR_PDCS_CLK(1, 0) | DIDSR_PDCS_CLK(0, 0)); } /* Use DS1PR and DS2PR to configure planes priorities and connects the * superposition 0 to DU0 pins. DU1 pins will be configured dynamically. */ rcar_du_group_write(rgrp, DORCR, DORCR_PG1D_DS1 | DORCR_DPRS); /* Apply planes to CRTCs association. */ mutex_lock(&rgrp->lock); rcar_du_group_write(rgrp, DPTSR, (rgrp->dptsr_planes << 16) | rgrp->dptsr_planes); mutex_unlock(&rgrp->lock); }
static void rcar_du_crtc_start(struct rcar_du_crtc *rcrtc) { struct drm_crtc *crtc = &rcrtc->crtc; bool interlaced; if (rcrtc->started) return; /* Set display off and background to black */ rcar_du_crtc_write(rcrtc, DOOR, DOOR_RGB(0, 0, 0)); rcar_du_crtc_write(rcrtc, BPOR, BPOR_RGB(0, 0, 0)); /* Configure display timings and output routing */ rcar_du_crtc_set_display_timing(rcrtc); rcar_du_group_set_routing(rcrtc->group); /* Start with all planes disabled. */ rcar_du_group_write(rcrtc->group, rcrtc->index % 2 ? DS2PR : DS1PR, 0); /* Select master sync mode. This enables display operation in master * sync mode (with the HSYNC and VSYNC signals configured as outputs and * actively driven). */ interlaced = rcrtc->crtc.mode.flags & DRM_MODE_FLAG_INTERLACE; rcar_du_crtc_clr_set(rcrtc, DSYSR, DSYSR_TVM_MASK | DSYSR_SCM_MASK, (interlaced ? DSYSR_SCM_INT_VIDEO : 0) | DSYSR_TVM_MASTER); rcar_du_group_start_stop(rcrtc->group, true); /* Turn vertical blanking interrupt reporting back on. */ drm_crtc_vblank_on(crtc); rcrtc->started = true; }
static void rcar_du_group_setup_defr8(struct rcar_du_group *rgrp) { u32 defr8 = DEFR8_CODE | DEFR8_DEFE8; /* The DEFR8 register for the first group also controls RGB output * routing to DPAD0 */ if (rgrp->index == 0) defr8 |= DEFR8_DRGBS_DU(rgrp->dev->dpad0_source); rcar_du_group_write(rgrp, DEFR8, defr8); }
static void rcar_du_crtc_set_display_timing(struct rcar_du_crtc *rcrtc) { const struct drm_display_mode *mode = &rcrtc->crtc.mode; unsigned long clk; u32 value; u32 div; /* Dot clock */ clk = clk_get_rate(rcrtc->clock); div = DIV_ROUND_CLOSEST(clk, mode->clock * 1000); div = clamp(div, 1U, 64U) - 1; rcar_du_group_write(rcrtc->group, rcrtc->index % 2 ? ESCR2 : ESCR, ESCR_DCLKSEL_CLKS | div); rcar_du_group_write(rcrtc->group, rcrtc->index % 2 ? OTAR2 : OTAR, 0); /* Signal polarities */ value = ((mode->flags & DRM_MODE_FLAG_PVSYNC) ? 0 : DSMR_VSL) | ((mode->flags & DRM_MODE_FLAG_PHSYNC) ? 0 : DSMR_HSL) | DSMR_DIPM_DE; rcar_du_crtc_write(rcrtc, DSMR, value); /* Display timings */ rcar_du_crtc_write(rcrtc, HDSR, mode->htotal - mode->hsync_start - 19); rcar_du_crtc_write(rcrtc, HDER, mode->htotal - mode->hsync_start + mode->hdisplay - 19); rcar_du_crtc_write(rcrtc, HSWR, mode->hsync_end - mode->hsync_start - 1); rcar_du_crtc_write(rcrtc, HCR, mode->htotal - 1); rcar_du_crtc_write(rcrtc, VDSR, mode->vtotal - mode->vsync_end - 2); rcar_du_crtc_write(rcrtc, VDER, mode->vtotal - mode->vsync_end + mode->vdisplay - 2); rcar_du_crtc_write(rcrtc, VSPR, mode->vtotal - mode->vsync_end + mode->vsync_start - 1); rcar_du_crtc_write(rcrtc, VCR, mode->vtotal - 1); rcar_du_crtc_write(rcrtc, DESR, mode->htotal - mode->hsync_start); rcar_du_crtc_write(rcrtc, DEWR, mode->hdisplay); }
static void rcar_du_group_setup_defr8(struct rcar_du_group *rgrp) { u32 defr8 = DEFR8_CODE | DEFR8_DEFE8; /* The DEFR8 register for the first group also controls RGB output * routing to DPAD0 for DU instances that support it. */ if (rgrp->dev->info->routes[RCAR_DU_OUTPUT_DPAD0].possible_crtcs > 1 && rgrp->index == 0) defr8 |= DEFR8_DRGBS_DU(rgrp->dev->dpad0_source); rcar_du_group_write(rgrp, DEFR8, defr8); }
int rcar_du_group_set_routing(struct rcar_du_group *rgrp) { struct rcar_du_crtc *crtc0 = &rgrp->dev->crtcs[rgrp->index * 2]; u32 dorcr = rcar_du_group_read(rgrp, DORCR); dorcr &= ~(DORCR_PG2T | DORCR_DK2S | DORCR_PG2D_MASK); /* Set the DPAD1 pins sources. Select CRTC 0 if explicitly requested and * CRTC 1 in all other cases to avoid cloning CRTC 0 to DPAD0 and DPAD1 * by default. */ if (crtc0->outputs & BIT(RCAR_DU_OUTPUT_DPAD1)) dorcr |= DORCR_PG2D_DS1; else dorcr |= DORCR_PG2T | DORCR_DK2S | DORCR_PG2D_DS2; rcar_du_group_write(rgrp, DORCR, dorcr); return rcar_du_set_dpad0_routing(rgrp->dev); }
static void rcar_du_crtc_stop(struct rcar_du_crtc *rcrtc) { struct drm_crtc *crtc = &rcrtc->crtc; if (!rcrtc->started) return; /* Disable all planes and wait for the change to take effect. This is * required as the DSnPR registers are updated on vblank, and no vblank * will occur once the CRTC is stopped. Disabling planes when starting * the CRTC thus wouldn't be enough as it would start scanning out * immediately from old frame buffers until the next vblank. * * This increases the CRTC stop delay, especially when multiple CRTCs * are stopped in one operation as we now wait for one vblank per CRTC. * Whether this can be improved needs to be researched. */ rcar_du_group_write(rcrtc->group, rcrtc->index % 2 ? DS2PR : DS1PR, 0); drm_crtc_wait_one_vblank(crtc); /* Disable vertical blanking interrupt reporting. We first need to wait * for page flip completion before stopping the CRTC as userspace * expects page flips to eventually complete. */ rcar_du_crtc_wait_page_flip(rcrtc); drm_crtc_vblank_off(crtc); /* Disable the VSP compositor. */ if (rcar_du_has(rcrtc->group->dev, RCAR_DU_FEATURE_VSP1_SOURCE)) rcar_du_vsp_disable(rcrtc); /* Select switch sync mode. This stops display operation and configures * the HSYNC and VSYNC signals as inputs. */ rcar_du_crtc_clr_set(rcrtc, DSYSR, DSYSR_TVM_MASK, DSYSR_TVM_SWITCH); rcar_du_group_start_stop(rcrtc->group, false); rcrtc->started = false; }
static void rcar_du_crtc_update_planes(struct rcar_du_crtc *rcrtc) { struct rcar_du_plane *planes[RCAR_DU_NUM_HW_PLANES]; unsigned int num_planes = 0; unsigned int dptsr_planes; unsigned int hwplanes = 0; unsigned int prio = 0; unsigned int i; u32 dspr = 0; for (i = 0; i < rcrtc->group->num_planes; ++i) { struct rcar_du_plane *plane = &rcrtc->group->planes[i]; unsigned int j; if (plane->plane.state->crtc != &rcrtc->crtc) continue; /* Insert the plane in the sorted planes array. */ for (j = num_planes++; j > 0; --j) { if (plane_zpos(planes[j-1]) <= plane_zpos(plane)) break; planes[j] = planes[j-1]; } planes[j] = plane; prio += plane_format(plane)->planes * 4; } for (i = 0; i < num_planes; ++i) { struct rcar_du_plane *plane = planes[i]; struct drm_plane_state *state = plane->plane.state; unsigned int index = to_rcar_plane_state(state)->hwindex; prio -= 4; dspr |= (index + 1) << prio; hwplanes |= 1 << index; if (plane_format(plane)->planes == 2) { index = (index + 1) % 8; prio -= 4; dspr |= (index + 1) << prio; hwplanes |= 1 << index; } } /* Update the planes to display timing and dot clock generator * associations. * * Updating the DPTSR register requires restarting the CRTC group, * resulting in visible flicker. To mitigate the issue only update the * association if needed by enabled planes. Planes being disabled will * keep their current association. */ mutex_lock(&rcrtc->group->lock); dptsr_planes = rcrtc->index % 2 ? rcrtc->group->dptsr_planes | hwplanes : rcrtc->group->dptsr_planes & ~hwplanes; if (dptsr_planes != rcrtc->group->dptsr_planes) { rcar_du_group_write(rcrtc->group, DPTSR, (dptsr_planes << 16) | dptsr_planes); rcrtc->group->dptsr_planes = dptsr_planes; if (rcrtc->group->used_crtcs) rcar_du_group_restart(rcrtc->group); } mutex_unlock(&rcrtc->group->lock); rcar_du_group_write(rcrtc->group, rcrtc->index % 2 ? DS2PR : DS1PR, dspr); }
static void rcar_du_crtc_set_display_timing(struct rcar_du_crtc *rcrtc) { const struct drm_display_mode *mode = &rcrtc->crtc.state->adjusted_mode; unsigned long mode_clock = mode->clock * 1000; unsigned long clk; u32 value; u32 escr; u32 div; /* Compute the clock divisor and select the internal or external dot * clock based on the requested frequency. */ clk = clk_get_rate(rcrtc->clock); div = DIV_ROUND_CLOSEST(clk, mode_clock); div = clamp(div, 1U, 64U) - 1; escr = div | ESCR_DCLKSEL_CLKS; if (rcrtc->extclock) { unsigned long extclk; unsigned long extrate; unsigned long rate; u32 extdiv; extclk = clk_get_rate(rcrtc->extclock); extdiv = DIV_ROUND_CLOSEST(extclk, mode_clock); extdiv = clamp(extdiv, 1U, 64U) - 1; rate = clk / (div + 1); extrate = extclk / (extdiv + 1); if (abs((long)extrate - (long)mode_clock) < abs((long)rate - (long)mode_clock)) { dev_dbg(rcrtc->group->dev->dev, "crtc%u: using external clock\n", rcrtc->index); escr = extdiv | ESCR_DCLKSEL_DCLKIN; } } rcar_du_group_write(rcrtc->group, rcrtc->index % 2 ? ESCR2 : ESCR, escr); rcar_du_group_write(rcrtc->group, rcrtc->index % 2 ? OTAR2 : OTAR, 0); /* Signal polarities */ value = ((mode->flags & DRM_MODE_FLAG_PVSYNC) ? 0 : DSMR_VSL) | ((mode->flags & DRM_MODE_FLAG_PHSYNC) ? 0 : DSMR_HSL) | DSMR_DIPM_DE | DSMR_CSPM; rcar_du_crtc_write(rcrtc, DSMR, value); /* Display timings */ rcar_du_crtc_write(rcrtc, HDSR, mode->htotal - mode->hsync_start - 19); rcar_du_crtc_write(rcrtc, HDER, mode->htotal - mode->hsync_start + mode->hdisplay - 19); rcar_du_crtc_write(rcrtc, HSWR, mode->hsync_end - mode->hsync_start - 1); rcar_du_crtc_write(rcrtc, HCR, mode->htotal - 1); rcar_du_crtc_write(rcrtc, VDSR, mode->crtc_vtotal - mode->crtc_vsync_end - 2); rcar_du_crtc_write(rcrtc, VDER, mode->crtc_vtotal - mode->crtc_vsync_end + mode->crtc_vdisplay - 2); rcar_du_crtc_write(rcrtc, VSPR, mode->crtc_vtotal - mode->crtc_vsync_end + mode->crtc_vsync_start - 1); rcar_du_crtc_write(rcrtc, VCR, mode->crtc_vtotal - 1); rcar_du_crtc_write(rcrtc, DESR, mode->htotal - mode->hsync_start); rcar_du_crtc_write(rcrtc, DEWR, mode->hdisplay); }
static void rcar_du_crtc_set_display_timing(struct rcar_du_crtc *rcrtc) { const struct drm_display_mode *mode = &rcrtc->crtc.mode; unsigned long clk_in = 0, clk_ex = 0; u32 value; u32 div = 0, div_in = 0, div_ex = 0; u32 abs_in = 0, abs_ex = 0; u32 dclksel_bit = 0, dclkoinv_bit = 0; const struct rcar_du_crtc_data *pdata = &rcrtc->group->dev->pdata->crtcs[rcrtc->index]; /* Internal dot clock */ clk_in = clk_get_rate(rcrtc->clock); div_in = DIV_ROUND_CLOSEST(clk_in, mode->clock * 1000); if (pdata->exclk != 0) { /* External dot clock */ clk_ex = pdata->exclk; div_ex = DIV_ROUND_CLOSEST(clk_ex, mode->clock * 1000); /* Select recommand dot clock */ abs_ex = abs((mode->clock * 1000) - (clk_ex / div_ex)); abs_in = abs((mode->clock * 1000) - (clk_in / div_in)); if (abs_ex < abs_in) { div = div_ex; dclksel_bit = ESCR_DCLKSEL_DCLKIN; } else { div = div_in; dclksel_bit = ESCR_DCLKSEL_CLKS; } } else { div = div_in; dclksel_bit = ESCR_DCLKSEL_CLKS; } div = clamp(div, 1U, 64U) - 1; rcar_du_group_write(rcrtc->group, rcrtc->index % 2 ? ESCR2 : ESCR, dclksel_bit | dclkoinv_bit | div); rcar_du_group_write(rcrtc->group, rcrtc->index % 2 ? OTAR2 : OTAR, 0); /* Signal polarities */ value = ((mode->flags & DRM_MODE_FLAG_PVSYNC) ? 0 : DSMR_VSL) | ((mode->flags & DRM_MODE_FLAG_PHSYNC) ? 0 : DSMR_HSL) | DSMR_DIPM_DE; rcar_du_crtc_write(rcrtc, DSMR, value | DSMR_CSPM); /* for HDMI */ /* Display timings */ rcar_du_crtc_write(rcrtc, HDSR, mode->htotal - mode->hsync_start - 19); rcar_du_crtc_write(rcrtc, HDER, mode->htotal - mode->hsync_start + mode->hdisplay - 19); rcar_du_crtc_write(rcrtc, HSWR, mode->hsync_end - mode->hsync_start - 1); rcar_du_crtc_write(rcrtc, HCR, mode->htotal - 1); if (mode->flags & DRM_MODE_FLAG_INTERLACE) { rcar_du_crtc_write(rcrtc, VDSR, (mode->vtotal / 2) - (mode->vsync_end / 2) - 2); rcar_du_crtc_write(rcrtc, VDER, (mode->vtotal / 2) - (mode->vsync_end / 2) + (mode->vdisplay / 2) - 2); rcar_du_crtc_write(rcrtc, VSPR, (mode->vtotal / 2) - (mode->vsync_end / 2) + (mode->vsync_start / 2) - 1); rcar_du_crtc_write(rcrtc, VCR, (mode->vtotal / 2) - 1); } else { rcar_du_crtc_write(rcrtc, VDSR, mode->vtotal - mode->vsync_end - 2); rcar_du_crtc_write(rcrtc, VDER, mode->vtotal - mode->vsync_end + mode->vdisplay - 2); rcar_du_crtc_write(rcrtc, VSPR, mode->vtotal - mode->vsync_end + mode->vsync_start - 1); rcar_du_crtc_write(rcrtc, VCR, mode->vtotal - 1); } rcar_du_crtc_write(rcrtc, DESR, mode->htotal - mode->hsync_start); rcar_du_crtc_write(rcrtc, DEWR, mode->hdisplay); }
void rcar_du_crtc_update_planes(struct drm_crtc *crtc) { struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc); struct rcar_du_plane *planes[RCAR_DU_NUM_HW_PLANES]; unsigned int num_planes = 0; unsigned int prio = 0; unsigned int i; u32 dptsr = 0; u32 dspr = 0; for (i = 0; i < ARRAY_SIZE(rcrtc->group->planes.planes); ++i) { struct rcar_du_plane *plane = &rcrtc->group->planes.planes[i]; unsigned int j; if (plane->crtc != &rcrtc->crtc || !plane->enabled) continue; /* Insert the plane in the sorted planes array. */ for (j = num_planes++; j > 0; --j) { if (planes[j-1]->zpos <= plane->zpos) break; planes[j] = planes[j-1]; } planes[j] = plane; prio += plane->format->planes * 4; } for (i = 0; i < num_planes; ++i) { struct rcar_du_plane *plane = planes[i]; unsigned int index = plane->hwindex; #ifdef CONFIG_DRM_RCAR_DESKTOP_TURN_OFF if (!plane->fb_plane) { prio -= 4; dspr |= (index + 1) << prio; dptsr |= DPTSR_PnDK(index) | DPTSR_PnTS(index); } #else prio -= 4; dspr |= (index + 1) << prio; dptsr |= DPTSR_PnDK(index) | DPTSR_PnTS(index); #endif if (plane->format->planes == 2) { index = (index + 1) % 8; #ifdef CONFIG_DRM_RCAR_DESKTOP_TURN_OFF if (!plane->fb_plane) { prio -= 4; dspr |= (index + 1) << prio; dptsr |= DPTSR_PnDK(index) | DPTSR_PnTS(index); } #else prio -= 4; dspr |= (index + 1) << prio; dptsr |= DPTSR_PnDK(index) | DPTSR_PnTS(index); #endif } } /* Select display timing and dot clock generator 1 for planes associated * with superposition controller 1. */ if (rcrtc->index % 2) { u32 value = rcar_du_group_read(rcrtc->group, DPTSR); /* The DPTSR register is updated when the display controller is * stopped. We thus need to restart the DU. Once again, sorry * for the flicker. One way to mitigate the issue would be to * pre-associate planes with CRTCs (either with a fixed 4/4 * split, or through a module parameter). Flicker would then * occur only if we need to break the pre-association. */ if (value != dptsr) { rcar_du_group_write(rcrtc->group, DPTSR, dptsr); rcar_du_group_restart(rcrtc->group); } } rcar_du_group_write(rcrtc->group, rcrtc->index % 2 ? DS2PR : DS1PR, dspr); }
static void __rcar_du_group_start_stop(struct rcar_du_group *rgrp, bool start) { rcar_du_group_write(rgrp, DSYSR, (rcar_du_group_read(rgrp, DSYSR) & ~(DSYSR_DRES | DSYSR_DEN)) | (start ? DSYSR_DEN : DSYSR_DRES)); }