Example #1
0
static int sti_hqvdp_atomic_check(struct drm_plane *drm_plane,
				  struct drm_plane_state *state)
{
	struct sti_plane *plane = to_sti_plane(drm_plane);
	struct sti_hqvdp *hqvdp = to_sti_hqvdp(plane);
	struct drm_crtc *crtc = state->crtc;
	struct drm_framebuffer *fb = state->fb;
	bool first_prepare = plane->status == STI_PLANE_DISABLED ? true : false;
	struct drm_crtc_state *crtc_state;
	struct drm_display_mode *mode;
	int dst_x, dst_y, dst_w, dst_h;
	int src_x, src_y, src_w, src_h;

	/* no need for further checks if the plane is being disabled */
	if (!crtc || !fb)
		return 0;

	crtc_state = drm_atomic_get_crtc_state(state->state, crtc);
	mode = &crtc_state->mode;
	dst_x = state->crtc_x;
	dst_y = state->crtc_y;
	dst_w = clamp_val(state->crtc_w, 0, mode->crtc_hdisplay - dst_x);
	dst_h = clamp_val(state->crtc_h, 0, mode->crtc_vdisplay - dst_y);
	/* src_x are in 16.16 format */
	src_x = state->src_x >> 16;
	src_y = state->src_y >> 16;
	src_w = state->src_w >> 16;
	src_h = state->src_h >> 16;

	if (!sti_hqvdp_check_hw_scaling(hqvdp, mode,
					src_w, src_h,
					dst_w, dst_h)) {
		DRM_ERROR("Scaling beyond HW capabilities\n");
		return -EINVAL;
	}

	if (!drm_fb_cma_get_gem_obj(fb, 0)) {
		DRM_ERROR("Can't get CMA GEM object for fb\n");
		return -EINVAL;
	}

	/*
	 * Input / output size
	 * Align to upper even value
	 */
	dst_w = ALIGN(dst_w, 2);
	dst_h = ALIGN(dst_h, 2);

	if ((src_w > MAX_WIDTH) || (src_w < MIN_WIDTH) ||
	    (src_h > MAX_HEIGHT) || (src_h < MIN_HEIGHT) ||
	    (dst_w > MAX_WIDTH) || (dst_w < MIN_WIDTH) ||
	    (dst_h > MAX_HEIGHT) || (dst_h < MIN_HEIGHT)) {
		DRM_ERROR("Invalid in/out size %dx%d -> %dx%d\n",
			  src_w, src_h,
			  dst_w, dst_h);
		return -EINVAL;
	}

	if (first_prepare) {
		/* Start HQVDP XP70 coprocessor */
		sti_hqvdp_start_xp70(hqvdp);

		/* Prevent VTG shutdown */
		if (clk_prepare_enable(hqvdp->clk_pix_main)) {
			DRM_ERROR("Failed to prepare/enable pix main clk\n");
			return -EINVAL;
		}

		/* Register VTG Vsync callback to handle bottom fields */
		if (sti_vtg_register_client(hqvdp->vtg,
					    &hqvdp->vtg_nb,
					    crtc)) {
			DRM_ERROR("Cannot register VTG notifier\n");
			return -EINVAL;
		}
	}

	DRM_DEBUG_KMS("CRTC:%d (%s) drm plane:%d (%s)\n",
		      crtc->base.id, sti_mixer_to_str(to_sti_mixer(crtc)),
		      drm_plane->base.id, sti_plane_to_str(plane));
	DRM_DEBUG_KMS("%s dst=(%dx%d)@(%d,%d) - src=(%dx%d)@(%d,%d)\n",
		      sti_plane_to_str(plane),
		      dst_w, dst_h, dst_x, dst_y,
		      src_w, src_h, src_x, src_y);

	return 0;
}
Example #2
0
/**
 * sti_gdp_prepare_layer
 * @lay: gdp layer
 * @first_prepare: true if it is the first time this function is called
 *
 * Update the free GDP node list according to the layer properties.
 *
 * RETURNS:
 * 0 on success.
 */
static int sti_gdp_prepare_layer(struct sti_layer *layer, bool first_prepare)
{
    struct sti_gdp_node_list *list;
    struct sti_gdp_node *top_field, *btm_field;
    struct drm_display_mode *mode = layer->mode;
    struct device *dev = layer->dev;
    struct sti_gdp *gdp = to_sti_gdp(layer);
    struct sti_compositor *compo = dev_get_drvdata(dev);
    int format;
    unsigned int depth, bpp;
    int rate = mode->clock * 1000;
    int res;
    u32 ydo, xdo, yds, xds;

    list = sti_gdp_get_free_nodes(layer);
    top_field = list->top_field;
    btm_field = list->btm_field;

    dev_dbg(dev, "%s %s top_node:0x%p btm_node:0x%p\n", __func__,
            sti_layer_to_str(layer), top_field, btm_field);

    /* Build the top field from layer params */
    top_field->gam_gdp_agc = GAM_GDP_AGC_FULL_RANGE;
    top_field->gam_gdp_ctl = WAIT_NEXT_VSYNC;
    format = sti_gdp_fourcc2format(layer->format);
    if (format == -1) {
        DRM_ERROR("Format not supported by GDP %.4s\n",
                  (char *)&layer->format);
        return 1;
    }
    top_field->gam_gdp_ctl |= format;
    top_field->gam_gdp_ctl |= sti_gdp_get_alpharange(format);
    top_field->gam_gdp_ppt &= ~GAM_GDP_PPT_IGNORE;

    /* pixel memory location */
    drm_fb_get_bpp_depth(layer->format, &depth, &bpp);
    top_field->gam_gdp_pml = (u32) layer->paddr + layer->offsets[0];
    top_field->gam_gdp_pml += layer->src_x * (bpp >> 3);
    top_field->gam_gdp_pml += layer->src_y * layer->pitches[0];

    /* input parameters */
    top_field->gam_gdp_pmp = layer->pitches[0];
    top_field->gam_gdp_size =
        clamp_val(layer->src_h, 0, GAM_GDP_SIZE_MAX) << 16 |
        clamp_val(layer->src_w, 0, GAM_GDP_SIZE_MAX);

    /* output parameters */
    ydo = sti_vtg_get_line_number(*mode, layer->dst_y);
    yds = sti_vtg_get_line_number(*mode, layer->dst_y + layer->dst_h - 1);
    xdo = sti_vtg_get_pixel_number(*mode, layer->dst_x);
    xds = sti_vtg_get_pixel_number(*mode, layer->dst_x + layer->dst_w - 1);
    top_field->gam_gdp_vpo = (ydo << 16) | xdo;
    top_field->gam_gdp_vps = (yds << 16) | xds;

    /* Same content and chained together */
    memcpy(btm_field, top_field, sizeof(*btm_field));
    top_field->gam_gdp_nvn = virt_to_dma(dev, btm_field);
    btm_field->gam_gdp_nvn = virt_to_dma(dev, top_field);

    /* Interlaced mode */
    if (layer->mode->flags & DRM_MODE_FLAG_INTERLACE)
        btm_field->gam_gdp_pml = top_field->gam_gdp_pml +
                                 layer->pitches[0];

    if (first_prepare) {
        /* Register gdp callback */
        if (sti_vtg_register_client(layer->mixer_id == STI_MIXER_MAIN ?
                                    compo->vtg_main : compo->vtg_aux,
                                    &gdp->vtg_field_nb, layer->mixer_id)) {
            DRM_ERROR("Cannot register VTG notifier\n");
            return 1;
        }

        /* Set and enable gdp clock */
        if (gdp->clk_pix) {
            res = clk_set_rate(gdp->clk_pix, rate);
            if (res < 0) {
                DRM_ERROR("Cannot set rate (%dHz) for gdp\n",
                          rate);
                return 1;
            }

            if (clk_prepare_enable(gdp->clk_pix)) {
                DRM_ERROR("Failed to prepare/enable gdp\n");
                return 1;
            }
        }
    }

    return 0;
}