Lines Matching +full:top +full:- +full:left

1 // SPDX-License-Identifier: GPL-2.0
12 #include <linux/v4l2-mediabus.h>
13 #include <media/v4l2-rect.h>
14 #include <media/v4l2-subdev.h>
16 #include "dcmipp-common.h"
98 .top = 0,
99 .left = 0,
113 r->top = 0; in dcmipp_byteproc_adjust_compose()
114 r->left = 0; in dcmipp_byteproc_adjust_compose()
117 if (fmt->code == MEDIA_BUS_FMT_JPEG_1X8 || in dcmipp_byteproc_adjust_compose()
118 fmt->code == MEDIA_BUS_FMT_SBGGR8_1X8 || in dcmipp_byteproc_adjust_compose()
119 fmt->code == MEDIA_BUS_FMT_SGBRG8_1X8 || in dcmipp_byteproc_adjust_compose()
120 fmt->code == MEDIA_BUS_FMT_SGRBG8_1X8 || in dcmipp_byteproc_adjust_compose()
121 fmt->code == MEDIA_BUS_FMT_SRGGB8_1X8) { in dcmipp_byteproc_adjust_compose()
122 r->width = fmt->width; in dcmipp_byteproc_adjust_compose()
123 r->height = fmt->height; in dcmipp_byteproc_adjust_compose()
127 /* Adjust height - we can only perform 1/2 decimation */ in dcmipp_byteproc_adjust_compose()
128 if (r->height <= (fmt->height / 2)) in dcmipp_byteproc_adjust_compose()
129 r->height = fmt->height / 2; in dcmipp_byteproc_adjust_compose()
131 r->height = fmt->height; in dcmipp_byteproc_adjust_compose()
134 if (fmt->code == MEDIA_BUS_FMT_Y8_1X8 && r->width <= (fmt->width / 4)) in dcmipp_byteproc_adjust_compose()
135 r->width = fmt->width / 4; in dcmipp_byteproc_adjust_compose()
136 else if (r->width <= (fmt->width / 2)) in dcmipp_byteproc_adjust_compose()
137 r->width = fmt->width / 2; in dcmipp_byteproc_adjust_compose()
139 r->width = fmt->width; in dcmipp_byteproc_adjust_compose()
147 vpix = dcmipp_byteproc_pix_map_by_code(fmt->code); in dcmipp_byteproc_adjust_fmt()
149 fmt->code = fmt_default.code; in dcmipp_byteproc_adjust_fmt()
151 fmt->width = clamp_t(u32, fmt->width, DCMIPP_FRAME_MIN_WIDTH, in dcmipp_byteproc_adjust_fmt()
153 fmt->height = clamp_t(u32, fmt->height, DCMIPP_FRAME_MIN_HEIGHT, in dcmipp_byteproc_adjust_fmt()
156 if (fmt->field == V4L2_FIELD_ANY || fmt->field == V4L2_FIELD_ALTERNATE) in dcmipp_byteproc_adjust_fmt()
157 fmt->field = fmt_default.field; in dcmipp_byteproc_adjust_fmt()
167 for (i = 0; i < sd->entity.num_pads; i++) { in dcmipp_byteproc_init_state()
179 r->top = 0; in dcmipp_byteproc_init_state()
180 r->left = 0; in dcmipp_byteproc_init_state()
181 r->width = DCMIPP_FMT_WIDTH_DEFAULT; in dcmipp_byteproc_init_state()
182 r->height = DCMIPP_FMT_HEIGHT_DEFAULT; in dcmipp_byteproc_init_state()
196 if (IS_SINK(code->pad)) { in dcmipp_byteproc_enum_mbus_code()
197 if (code->index >= ARRAY_SIZE(dcmipp_byteproc_pix_map_list)) in dcmipp_byteproc_enum_mbus_code()
198 return -EINVAL; in dcmipp_byteproc_enum_mbus_code()
199 vpix = &dcmipp_byteproc_pix_map_list[code->index]; in dcmipp_byteproc_enum_mbus_code()
200 code->code = vpix->code; in dcmipp_byteproc_enum_mbus_code()
203 if (code->index > 0) in dcmipp_byteproc_enum_mbus_code()
204 return -EINVAL; in dcmipp_byteproc_enum_mbus_code()
207 code->code = sink_fmt->code; in dcmipp_byteproc_enum_mbus_code()
220 if (fse->index) in dcmipp_byteproc_enum_frame_size()
221 return -EINVAL; in dcmipp_byteproc_enum_frame_size()
223 fse->min_width = DCMIPP_FRAME_MIN_WIDTH; in dcmipp_byteproc_enum_frame_size()
224 fse->min_height = DCMIPP_FRAME_MIN_HEIGHT; in dcmipp_byteproc_enum_frame_size()
226 if (IS_SINK(fse->pad)) { in dcmipp_byteproc_enum_frame_size()
227 fse->max_width = DCMIPP_FRAME_MAX_WIDTH; in dcmipp_byteproc_enum_frame_size()
228 fse->max_height = DCMIPP_FRAME_MAX_HEIGHT; in dcmipp_byteproc_enum_frame_size()
231 fse->max_width = compose->width; in dcmipp_byteproc_enum_frame_size()
232 fse->max_height = compose->height; in dcmipp_byteproc_enum_frame_size()
246 if (byteproc->streaming) in dcmipp_byteproc_set_fmt()
247 return -EBUSY; in dcmipp_byteproc_set_fmt()
249 mf = v4l2_subdev_state_get_format(sd_state, fmt->pad); in dcmipp_byteproc_set_fmt()
254 if (IS_SRC(fmt->pad)) { in dcmipp_byteproc_set_fmt()
255 fmt->format = *v4l2_subdev_state_get_format(sd_state, 0); in dcmipp_byteproc_set_fmt()
256 fmt->format.width = crop->width; in dcmipp_byteproc_set_fmt()
257 fmt->format.height = crop->height; in dcmipp_byteproc_set_fmt()
259 dcmipp_byteproc_adjust_fmt(&fmt->format); in dcmipp_byteproc_set_fmt()
260 crop->top = 0; in dcmipp_byteproc_set_fmt()
261 crop->left = 0; in dcmipp_byteproc_set_fmt()
262 crop->width = fmt->format.width; in dcmipp_byteproc_set_fmt()
263 crop->height = fmt->format.height; in dcmipp_byteproc_set_fmt()
266 *v4l2_subdev_state_get_format(sd_state, 1) = fmt->format; in dcmipp_byteproc_set_fmt()
268 *mf = fmt->format; in dcmipp_byteproc_set_fmt()
285 if (IS_SINK(s->pad) && in dcmipp_byteproc_get_selection()
286 (s->target == V4L2_SEL_TGT_CROP || in dcmipp_byteproc_get_selection()
287 s->target == V4L2_SEL_TGT_CROP_BOUNDS || in dcmipp_byteproc_get_selection()
288 s->target == V4L2_SEL_TGT_CROP_DEFAULT)) in dcmipp_byteproc_get_selection()
289 return -EINVAL; in dcmipp_byteproc_get_selection()
291 if (IS_SRC(s->pad) && in dcmipp_byteproc_get_selection()
292 (s->target == V4L2_SEL_TGT_COMPOSE || in dcmipp_byteproc_get_selection()
293 s->target == V4L2_SEL_TGT_COMPOSE_BOUNDS || in dcmipp_byteproc_get_selection()
294 s->target == V4L2_SEL_TGT_COMPOSE_DEFAULT)) in dcmipp_byteproc_get_selection()
295 return -EINVAL; in dcmipp_byteproc_get_selection()
301 switch (s->target) { in dcmipp_byteproc_get_selection()
303 s->r = *crop; in dcmipp_byteproc_get_selection()
307 s->r = *compose; in dcmipp_byteproc_get_selection()
310 s->r = *compose; in dcmipp_byteproc_get_selection()
314 s->r.top = 0; in dcmipp_byteproc_get_selection()
315 s->r.left = 0; in dcmipp_byteproc_get_selection()
316 s->r.width = sink_fmt->width; in dcmipp_byteproc_get_selection()
317 s->r.height = sink_fmt->height; in dcmipp_byteproc_get_selection()
320 return -EINVAL; in dcmipp_byteproc_get_selection()
339 if ((s->target == V4L2_SEL_TGT_CROP || in dcmipp_byteproc_set_selection()
340 s->target == V4L2_SEL_TGT_CROP_BOUNDS || in dcmipp_byteproc_set_selection()
341 s->target == V4L2_SEL_TGT_CROP_DEFAULT) && IS_SINK(s->pad)) in dcmipp_byteproc_set_selection()
342 return -EINVAL; in dcmipp_byteproc_set_selection()
344 if ((s->target == V4L2_SEL_TGT_COMPOSE || in dcmipp_byteproc_set_selection()
345 s->target == V4L2_SEL_TGT_COMPOSE_BOUNDS || in dcmipp_byteproc_set_selection()
346 s->target == V4L2_SEL_TGT_COMPOSE_DEFAULT) && IS_SRC(s->pad)) in dcmipp_byteproc_set_selection()
347 return -EINVAL; in dcmipp_byteproc_set_selection()
352 switch (s->target) { in dcmipp_byteproc_set_selection()
354 dcmipp_byteproc_adjust_crop(&s->r, compose); in dcmipp_byteproc_set_selection()
356 *crop = s->r; in dcmipp_byteproc_set_selection()
358 mf->width = s->r.width; in dcmipp_byteproc_set_selection()
359 mf->height = s->r.height; in dcmipp_byteproc_set_selection()
361 dev_dbg(byteproc->dev, "s_selection: crop %ux%u@(%u,%u)\n", in dcmipp_byteproc_set_selection()
362 crop->width, crop->height, crop->left, crop->top); in dcmipp_byteproc_set_selection()
366 dcmipp_byteproc_adjust_compose(&s->r, mf); in dcmipp_byteproc_set_selection()
367 *compose = s->r; in dcmipp_byteproc_set_selection()
368 *crop = s->r; in dcmipp_byteproc_set_selection()
371 mf->width = s->r.width; in dcmipp_byteproc_set_selection()
372 mf->height = s->r.height; in dcmipp_byteproc_set_selection()
374 dev_dbg(byteproc->dev, "s_selection: compose %ux%u@(%u,%u)\n", in dcmipp_byteproc_set_selection()
375 compose->width, compose->height, in dcmipp_byteproc_set_selection()
376 compose->left, compose->top); in dcmipp_byteproc_set_selection()
379 return -EINVAL; in dcmipp_byteproc_set_selection()
404 state = v4l2_subdev_lock_and_get_active_state(&byteproc->sd); in dcmipp_byteproc_configure_scale_crop()
411 vpix = dcmipp_byteproc_pix_map_by_code(sink_fmt->code); in dcmipp_byteproc_configure_scale_crop()
413 return -EINVAL; in dcmipp_byteproc_configure_scale_crop()
422 if (vpix->code == MEDIA_BUS_FMT_JPEG_1X8) in dcmipp_byteproc_configure_scale_crop()
426 hprediv = sink_fmt->width / compose->width; in dcmipp_byteproc_configure_scale_crop()
429 else if ((vpix->code == MEDIA_BUS_FMT_Y8_1X8) && (hprediv == 2)) in dcmipp_byteproc_configure_scale_crop()
434 vprediv = sink_fmt->height / compose->height; in dcmipp_byteproc_configure_scale_crop()
442 dev_dbg(byteproc->dev, "decimate to %dx%d [prediv=%dx%d]\n", in dcmipp_byteproc_configure_scale_crop()
443 compose->width, compose->height, in dcmipp_byteproc_configure_scale_crop()
447 dev_dbg(byteproc->dev, "crop to %dx%d\n", crop->width, crop->height); in dcmipp_byteproc_configure_scale_crop()
449 /* expressed in 32-bits words on X axis, lines on Y axis */ in dcmipp_byteproc_configure_scale_crop()
451 (((crop->left * vpix->bpp) / 4) << in dcmipp_byteproc_configure_scale_crop()
453 (crop->top << DCMIPP_P0SCSTR_VSTART_SHIFT)); in dcmipp_byteproc_configure_scale_crop()
456 (((crop->width * vpix->bpp) / 4) << in dcmipp_byteproc_configure_scale_crop()
458 (crop->height << DCMIPP_P0SCSZR_VSIZE_SHIFT)); in dcmipp_byteproc_configure_scale_crop()
471 pad = media_pad_remote_pad_first(&sd->entity.pads[0]); in dcmipp_byteproc_s_stream()
472 if (!pad || !is_media_entity_v4l2_subdev(pad->entity)) in dcmipp_byteproc_s_stream()
473 return -EINVAL; in dcmipp_byteproc_s_stream()
474 s_subdev = media_entity_to_v4l2_subdev(pad->entity); in dcmipp_byteproc_s_stream()
483 dev_err(byteproc->dev, in dcmipp_byteproc_s_stream()
491 dev_err(byteproc->dev, in dcmipp_byteproc_s_stream()
498 byteproc->streaming = enable; in dcmipp_byteproc_s_stream()
529 dcmipp_ent_sd_unregister(ved, &byteproc->sd); in dcmipp_byteproc_ent_release()
545 return ERR_PTR(-ENOMEM); in dcmipp_byteproc_ent_init()
547 byteproc->regs = regs; in dcmipp_byteproc_ent_init()
550 ret = dcmipp_ent_sd_register(&byteproc->ved, &byteproc->sd, in dcmipp_byteproc_ent_init()
562 byteproc->dev = dev; in dcmipp_byteproc_ent_init()
564 return &byteproc->ved; in dcmipp_byteproc_ent_init()