Lines Matching +full:top +full:- +full:left
1 // SPDX-License-Identifier: GPL-2.0+
3 * vsp1_rwpf.c -- R-Car VSP1 Read and Write Pixel Formatters
5 * Copyright (C) 2013-2014 Renesas Electronics Corporation
10 #include <media/v4l2-subdev.h>
25 /* -----------------------------------------------------------------------------
39 if (code->index >= ARRAY_SIZE(codes)) in vsp1_rwpf_enum_mbus_code()
40 return -EINVAL; in vsp1_rwpf_enum_mbus_code()
42 code->code = codes[code->index]; in vsp1_rwpf_enum_mbus_code()
55 RWPF_MIN_HEIGHT, rwpf->max_width, in vsp1_rwpf_enum_frame_size()
56 rwpf->max_height); in vsp1_rwpf_enum_frame_size()
68 mutex_lock(&rwpf->entity.lock); in vsp1_rwpf_set_format()
70 state = vsp1_entity_get_state(&rwpf->entity, sd_state, fmt->which); in vsp1_rwpf_set_format()
72 ret = -EINVAL; in vsp1_rwpf_set_format()
77 if (fmt->format.code != MEDIA_BUS_FMT_ARGB8888_1X32 && in vsp1_rwpf_set_format()
78 fmt->format.code != MEDIA_BUS_FMT_AHSV8888_1X32 && in vsp1_rwpf_set_format()
79 fmt->format.code != MEDIA_BUS_FMT_AYUV8_1X32) in vsp1_rwpf_set_format()
80 fmt->format.code = MEDIA_BUS_FMT_AYUV8_1X32; in vsp1_rwpf_set_format()
82 format = vsp1_entity_get_pad_format(&rwpf->entity, state, fmt->pad); in vsp1_rwpf_set_format()
84 if (fmt->pad == RWPF_PAD_SOURCE) { in vsp1_rwpf_set_format()
89 format->code = fmt->format.code; in vsp1_rwpf_set_format()
90 fmt->format = *format; in vsp1_rwpf_set_format()
94 format->code = fmt->format.code; in vsp1_rwpf_set_format()
95 format->width = clamp_t(unsigned int, fmt->format.width, in vsp1_rwpf_set_format()
96 RWPF_MIN_WIDTH, rwpf->max_width); in vsp1_rwpf_set_format()
97 format->height = clamp_t(unsigned int, fmt->format.height, in vsp1_rwpf_set_format()
98 RWPF_MIN_HEIGHT, rwpf->max_height); in vsp1_rwpf_set_format()
99 format->field = V4L2_FIELD_NONE; in vsp1_rwpf_set_format()
100 format->colorspace = V4L2_COLORSPACE_SRGB; in vsp1_rwpf_set_format()
102 fmt->format = *format; in vsp1_rwpf_set_format()
104 if (rwpf->entity.type == VSP1_ENTITY_RPF) { in vsp1_rwpf_set_format()
109 crop->left = 0; in vsp1_rwpf_set_format()
110 crop->top = 0; in vsp1_rwpf_set_format()
111 crop->width = fmt->format.width; in vsp1_rwpf_set_format()
112 crop->height = fmt->format.height; in vsp1_rwpf_set_format()
116 format = vsp1_entity_get_pad_format(&rwpf->entity, state, in vsp1_rwpf_set_format()
118 *format = fmt->format; in vsp1_rwpf_set_format()
120 if (rwpf->flip.rotate) { in vsp1_rwpf_set_format()
121 format->width = fmt->format.height; in vsp1_rwpf_set_format()
122 format->height = fmt->format.width; in vsp1_rwpf_set_format()
126 mutex_unlock(&rwpf->entity.lock); in vsp1_rwpf_set_format()
143 if (rwpf->entity.type == VSP1_ENTITY_WPF || sel->pad != RWPF_PAD_SINK) in vsp1_rwpf_get_selection()
144 return -EINVAL; in vsp1_rwpf_get_selection()
146 mutex_lock(&rwpf->entity.lock); in vsp1_rwpf_get_selection()
148 state = vsp1_entity_get_state(&rwpf->entity, sd_state, sel->which); in vsp1_rwpf_get_selection()
150 ret = -EINVAL; in vsp1_rwpf_get_selection()
154 switch (sel->target) { in vsp1_rwpf_get_selection()
156 sel->r = *vsp1_rwpf_get_crop(rwpf, state); in vsp1_rwpf_get_selection()
160 format = vsp1_entity_get_pad_format(&rwpf->entity, state, in vsp1_rwpf_get_selection()
162 sel->r.left = 0; in vsp1_rwpf_get_selection()
163 sel->r.top = 0; in vsp1_rwpf_get_selection()
164 sel->r.width = format->width; in vsp1_rwpf_get_selection()
165 sel->r.height = format->height; in vsp1_rwpf_get_selection()
169 ret = -EINVAL; in vsp1_rwpf_get_selection()
174 mutex_unlock(&rwpf->entity.lock); in vsp1_rwpf_get_selection()
192 if (rwpf->entity.type == VSP1_ENTITY_WPF || sel->pad != RWPF_PAD_SINK) in vsp1_rwpf_set_selection()
193 return -EINVAL; in vsp1_rwpf_set_selection()
195 if (sel->target != V4L2_SEL_TGT_CROP) in vsp1_rwpf_set_selection()
196 return -EINVAL; in vsp1_rwpf_set_selection()
198 mutex_lock(&rwpf->entity.lock); in vsp1_rwpf_set_selection()
200 state = vsp1_entity_get_state(&rwpf->entity, sd_state, sel->which); in vsp1_rwpf_set_selection()
202 ret = -EINVAL; in vsp1_rwpf_set_selection()
207 format = vsp1_entity_get_pad_format(&rwpf->entity, state, in vsp1_rwpf_set_selection()
214 if (format->code == MEDIA_BUS_FMT_AYUV8_1X32) { in vsp1_rwpf_set_selection()
215 sel->r.left = ALIGN(sel->r.left, 2); in vsp1_rwpf_set_selection()
216 sel->r.top = ALIGN(sel->r.top, 2); in vsp1_rwpf_set_selection()
217 sel->r.width = round_down(sel->r.width, 2); in vsp1_rwpf_set_selection()
218 sel->r.height = round_down(sel->r.height, 2); in vsp1_rwpf_set_selection()
221 sel->r.left = min_t(unsigned int, sel->r.left, format->width - 2); in vsp1_rwpf_set_selection()
222 sel->r.top = min_t(unsigned int, sel->r.top, format->height - 2); in vsp1_rwpf_set_selection()
223 sel->r.width = min_t(unsigned int, sel->r.width, in vsp1_rwpf_set_selection()
224 format->width - sel->r.left); in vsp1_rwpf_set_selection()
225 sel->r.height = min_t(unsigned int, sel->r.height, in vsp1_rwpf_set_selection()
226 format->height - sel->r.top); in vsp1_rwpf_set_selection()
229 *crop = sel->r; in vsp1_rwpf_set_selection()
232 format = vsp1_entity_get_pad_format(&rwpf->entity, state, in vsp1_rwpf_set_selection()
234 format->width = crop->width; in vsp1_rwpf_set_selection()
235 format->height = crop->height; in vsp1_rwpf_set_selection()
238 mutex_unlock(&rwpf->entity.lock); in vsp1_rwpf_set_selection()
255 /* -----------------------------------------------------------------------------
262 container_of(ctrl->handler, struct vsp1_rwpf, ctrls); in vsp1_rwpf_s_ctrl()
264 switch (ctrl->id) { in vsp1_rwpf_s_ctrl()
266 rwpf->alpha = ctrl->val; in vsp1_rwpf_s_ctrl()
279 v4l2_ctrl_handler_init(&rwpf->ctrls, ncontrols + 1); in vsp1_rwpf_init_ctrls()
280 v4l2_ctrl_new_std(&rwpf->ctrls, &vsp1_rwpf_ctrl_ops, in vsp1_rwpf_init_ctrls()
283 rwpf->entity.subdev.ctrl_handler = &rwpf->ctrls; in vsp1_rwpf_init_ctrls()
285 return rwpf->ctrls.error; in vsp1_rwpf_init_ctrls()