/* * check that the hardware can drive the required clock rate, * but skip the check if the clock is meant to be disabled (req_rate = 0)
*/ long rate, req_rate = mode->crtc_clock * 1000;
if (req_rate) {
rate = clk_round_rate(hwdev->pxlclk, req_rate); if (rate != req_rate) {
DRM_DEBUG_DRIVER("pxlclk doesn't support %ld Hz\n",
req_rate); return MODE_NOCLOCK;
}
}
for (i = 0; i < MALIDP_COEFFTAB_NUM_COEFFS; ++i) {
u32 a, b, delta_in, out_start, out_end;
delta_in = segments[i].end - segments[i].start; /* DP has 12-bit internal precision for its LUTs. */
out_start = drm_color_lut_extract(lut[segments[i].start].green,
12);
out_end = drm_color_lut_extract(lut[segments[i].end].green, 12);
a = (delta_in == 0) ? 0 : ((out_end - out_start) * 256) / delta_in;
b = out_start;
coeffs[i] = DE_COEFTAB_DATA(a, b);
}
}
/* * Check if there is a new gamma LUT and if it is of an acceptable size. Also, * reject any LUTs that use distinct red, green, and blue curves.
*/ staticint malidp_crtc_atomic_check_gamma(struct drm_crtc *crtc, struct drm_crtc_state *state)
{ struct malidp_crtc_state *mc = to_malidp_crtc_state(state); struct drm_color_lut *lut;
size_t lut_size; int i;
if (!state->color_mgmt_changed || !state->gamma_lut) return 0;
if (crtc->state->gamma_lut &&
(crtc->state->gamma_lut->base.id == state->gamma_lut->base.id)) return 0;
if (state->gamma_lut->length % sizeof(struct drm_color_lut)) return -EINVAL;
lut = (struct drm_color_lut *)state->gamma_lut->data; for (i = 0; i < lut_size; ++i) if (!((lut[i].red == lut[i].green) &&
(lut[i].red == lut[i].blue))) return -EINVAL;
if (!state->mode_changed) { int ret;
state->mode_changed = true; /* * Kerneldoc for drm_atomic_helper_check_modeset mandates that * it be invoked when the driver sets ->mode_changed. Since * changing the gamma LUT doesn't depend on any external * resources, it is safe to call it only once.
*/
ret = drm_atomic_helper_check_modeset(crtc->dev, state->state); if (ret) return ret;
}
/* * Check if there is a new CTM and if it contains valid input. Valid here means * that the number is inside the representable range for a Q3.12 number, * excluding truncating the fractional part of the input data. * * The COLORADJ registers can be changed atomically.
*/ staticint malidp_crtc_atomic_check_ctm(struct drm_crtc *crtc, struct drm_crtc_state *state)
{ struct malidp_crtc_state *mc = to_malidp_crtc_state(state); struct drm_color_ctm *ctm; int i;
if (!state->color_mgmt_changed) return 0;
if (!state->ctm) return 0;
if (crtc->state->ctm && (crtc->state->ctm->base.id ==
state->ctm->base.id)) return 0;
/* * The size of the ctm is checked in * drm_property_replace_blob_from_id.
*/
ctm = (struct drm_color_ctm *)state->ctm->data; for (i = 0; i < ARRAY_SIZE(ctm->matrix); ++i) { /* Convert from S31.32 to Q3.12. */
s64 val = ctm->matrix[i];
u32 mag = ((((u64)val) & ~BIT_ULL(63)) >> 20) &
GENMASK_ULL(14, 0);
/* * Convert to 2s complement and check the destination's top bit * for overflow. NB: Can't check before converting or it'd * incorrectly reject the case: * sign == 1 * mag == 0x2000
*/ if (val & BIT_ULL(63))
mag = ~mag + 1; if (!!(val & BIT_ULL(63)) != !!(mag & BIT(14))) return -EINVAL;
mc->coloradj_coeffs[i] = mag;
}
/* * Convert crtc_[w|h] to U32.32, then divide by U16.16 src_[w|h] * to get the U16.16 result.
*/
h_upscale_factor = div_u64((u64)pstate->crtc_w << 32,
pstate->src_w);
v_upscale_factor = div_u64((u64)pstate->crtc_h << 32,
pstate->src_h);
/* * check if there is enough rotation memory available for planes * that need 90° and 270° rotion or planes that are compressed. * Each plane has set its required memory size in the ->plane_check() * callback, here we only make sure that the sums are less that the * total usable memory. * * The rotation memory allocation algorithm (for each plane): * a. If no more rotated or compressed planes exist, all remaining * rotate memory in the bank is available for use by the plane. * b. If other rotated or compressed planes exist, and plane's * layer ID is DE_VIDEO1, it can use all the memory from first bank * if secondary rotation memory bank is available, otherwise it can * use up to half the bank's memory. * c. If other rotated or compressed planes exist, and plane's layer ID * is not DE_VIDEO1, it can use half of the available memory. * * Note: this algorithm assumes that the order in which the planes are * checked always has DE_VIDEO1 plane first in the list if it is * rotated. Because that is how we create the planes in the first * place, under current DRM version things work, but if ever the order * in which drm_atomic_crtc_state_for_each_plane() iterates over planes * changes, we need to pre-sort the planes before validation.
*/
/* first count the number of rotated planes */
drm_atomic_crtc_state_for_each_plane_state(plane, pstate, crtc_state) { struct drm_framebuffer *fb = pstate->fb;
if ((pstate->rotation & MALIDP_ROTATED_MASK) || fb->modifier)
rotated_planes++;
}
rot_mem_free = hwdev->rotation_memory[0]; /* * if we have more than 1 plane using rotation memory, use the second * block of rotation memory as well
*/ if (rotated_planes > 1)
rot_mem_free += hwdev->rotation_memory[1];
if ((pstate->rotation & MALIDP_ROTATED_MASK) || fb->modifier) { /* process current plane */
rotated_planes--;
if (!rotated_planes) { /* no more rotated planes, we can use what's left */
rot_mem_usable = rot_mem_free;
} else { if ((mp->layer->id != DE_VIDEO1) ||
(hwdev->rotation_memory[1] == 0))
rot_mem_usable = rot_mem_free / 2; else
rot_mem_usable = hwdev->rotation_memory[0];
}
rot_mem_free -= rot_mem_usable;
if (ms->rotmem_size > rot_mem_usable) return -EINVAL;
}
}
/* If only the writeback routing has changed, we don't need a modeset */ if (crtc_state->connectors_changed) {
u32 old_mask = crtc->state->connector_mask;
u32 new_mask = crtc_state->connector_mask;
ret = malidp_crtc_atomic_check_gamma(crtc, crtc_state);
ret = ret ? ret : malidp_crtc_atomic_check_ctm(crtc, crtc_state);
ret = ret ? ret : malidp_crtc_atomic_check_scaling(crtc, crtc_state);
if (!primary) {
DRM_ERROR("no primary plane found\n"); return -EINVAL;
}
ret = drmm_crtc_init_with_planes(drm, &malidp->crtc, primary, NULL,
&malidp_crtc_funcs, NULL); if (ret) return ret;
drm_crtc_helper_add(&malidp->crtc, &malidp_crtc_helper_funcs);
drm_mode_crtc_set_gamma_size(&malidp->crtc, MALIDP_GAMMA_LUT_SIZE); /* No inverse-gamma: it is per-plane. */
drm_crtc_enable_color_mgmt(&malidp->crtc, 0, true, MALIDP_GAMMA_LUT_SIZE);
malidp_se_set_enh_coeffs(malidp->dev);
return 0;
}
Messung V0.5
[ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet)
]