drivers/media/platform/rockchip/rga/rga.c

Source file repositories/reference/linux-study-clean/drivers/media/platform/rockchip/rga/rga.c

File Facts

System
Linux kernel
Corpus path
drivers/media/platform/rockchip/rga/rga.c
Extension
.c
Size
23353 bytes
Lines
940
Domain
Driver Families
Bucket
drivers/media
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

vb2_is_streaming(v4l2_m2m_get_src_vq(ctx->fh.m2m_ctx))) {
			ret = rga_check_scaling(hw, &ctx->in.crop,
						&ctx->out.crop, ctrl->val);
			if (ret < 0)
				goto s_ctrl_done;
		}
		ctx->rotate = ctrl->val;
		break;
	case V4L2_CID_BG_COLOR:
		ctx->fill_color = ctrl->val;
		break;
	}
	ctx->cmdbuf_dirty = true;

s_ctrl_done:
	spin_unlock_irqrestore(&ctx->rga->ctrl_lock, flags);
	return ret;
}

static const struct v4l2_ctrl_ops rga_ctrl_ops = {
	.s_ctrl = rga_s_ctrl,
};

static int rga_setup_ctrls(struct rga_ctx *ctx)
{
	struct rockchip_rga *rga = ctx->rga;

	v4l2_ctrl_handler_init(&ctx->ctrl_handler, 4);

	if (rga->hw->features & RGA_FEATURE_FLIP) {
		v4l2_ctrl_new_std(&ctx->ctrl_handler, &rga_ctrl_ops,
				  V4L2_CID_HFLIP, 0, 1, 1, 0);

		v4l2_ctrl_new_std(&ctx->ctrl_handler, &rga_ctrl_ops,
				  V4L2_CID_VFLIP, 0, 1, 1, 0);
	}

	if (rga->hw->features & RGA_FEATURE_ROTATE)
		v4l2_ctrl_new_std(&ctx->ctrl_handler, &rga_ctrl_ops,
				  V4L2_CID_ROTATE, 0, 270, 90, 0);

	if (rga->hw->features & RGA_FEATURE_BG_COLOR)
		v4l2_ctrl_new_std(&ctx->ctrl_handler, &rga_ctrl_ops,
				  V4L2_CID_BG_COLOR, 0, 0xffffffff, 1, 0);

	if (ctx->ctrl_handler.error) {
		int err = ctx->ctrl_handler.error;

		v4l2_err(&rga->v4l2_dev, "%s failed\n", __func__);
		v4l2_ctrl_handler_free(&ctx->ctrl_handler);
		return err;
	}

	return 0;
}

static bool check_scaling_factor(const struct rga_hw *hw, u32 src_size,
				 u32 dst_size)
{
	if (src_size < dst_size)
		return src_size * hw->max_scaling_factor >= dst_size;
	else
		return dst_size * hw->max_scaling_factor >= src_size;
}

int rga_check_scaling(const struct rga_hw *hw, const struct v4l2_rect *crop_in,
		      const struct v4l2_rect *crop_out, u32 rotate)
{
	u32 scaled_width;
	u32 scaled_height;

	if (rotate == 90 || rotate == 270) {
		scaled_width = crop_out->height;
		scaled_height = crop_out->width;
	} else {
		scaled_width = crop_out->width;
		scaled_height = crop_out->height;
	}

	if (!check_scaling_factor(hw, crop_in->width, scaled_width))
		return -EINVAL;

	if (!check_scaling_factor(hw, crop_in->height, scaled_height))
		return -EINVAL;

	return 0;
}

struct rga_frame *rga_get_frame(struct rga_ctx *ctx, enum v4l2_buf_type type)
{

Annotation

Implementation Notes