Lines Matching +full:fimc +full:- +full:is

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Samsung EXYNOS FIMC-LITE (camera host interface) driver
5 * Copyright (C) 2012 - 2013 Samsung Electronics Co., Ltd.
25 #include <media/v4l2-device.h>
26 #include <media/v4l2-ioctl.h>
27 #include <media/v4l2-mem2mem.h>
28 #include <media/v4l2-rect.h>
29 #include <media/videobuf2-v4l2.h>
30 #include <media/videobuf2-dma-contig.h>
31 #include <media/drv-intf/exynos-fimc.h>
34 #include "fimc-core.h"
35 #include "fimc-lite.h"
36 #include "fimc-lite-reg.h"
102 * fimc_lite_find_format - lookup fimc color format by fourcc or media bus code
120 if (mask && !(fmt->flags & mask)) in fimc_lite_find_format()
122 if (pixelformat && fmt->fourcc == *pixelformat) in fimc_lite_find_format()
124 if (mbus_code && fmt->mbus_code == *mbus_code) in fimc_lite_find_format()
133 static int fimc_lite_hw_init(struct fimc_lite *fimc, bool isp_output) in fimc_lite_hw_init() argument
138 if (fimc->sensor == NULL) in fimc_lite_hw_init()
139 return -ENXIO; in fimc_lite_hw_init()
141 if (fimc->inp_frame.fmt == NULL || fimc->out_frame.fmt == NULL) in fimc_lite_hw_init()
142 return -EINVAL; in fimc_lite_hw_init()
145 si = v4l2_get_subdev_hostdata(fimc->sensor); in fimc_lite_hw_init()
147 return -EINVAL; in fimc_lite_hw_init()
149 spin_lock_irqsave(&fimc->slock, flags); in fimc_lite_hw_init()
151 flite_hw_set_camera_bus(fimc, si); in fimc_lite_hw_init()
152 flite_hw_set_source_format(fimc, &fimc->inp_frame); in fimc_lite_hw_init()
153 flite_hw_set_window_offset(fimc, &fimc->inp_frame); in fimc_lite_hw_init()
154 flite_hw_set_dma_buf_mask(fimc, 0); in fimc_lite_hw_init()
155 flite_hw_set_output_dma(fimc, &fimc->out_frame, !isp_output); in fimc_lite_hw_init()
156 flite_hw_set_interrupt_mask(fimc); in fimc_lite_hw_init()
157 flite_hw_set_test_pattern(fimc, fimc->test_pattern->val); in fimc_lite_hw_init()
160 flite_hw_dump_regs(fimc, __func__); in fimc_lite_hw_init()
162 spin_unlock_irqrestore(&fimc->slock, flags); in fimc_lite_hw_init()
167 * Reinitialize the driver so it is ready to start the streaming again.
168 * Set fimc->state to indicate stream off and the hardware shut down state.
169 * If not suspending (@suspend is false), return any buffers to videobuf2.
171 * can be re-spun when the device is being resumed. Also perform FIMC
174 static int fimc_lite_reinit(struct fimc_lite *fimc, bool suspend) in fimc_lite_reinit() argument
180 spin_lock_irqsave(&fimc->slock, flags); in fimc_lite_reinit()
181 streaming = fimc->state & (1 << ST_SENSOR_STREAM); in fimc_lite_reinit()
183 fimc->state &= ~(1 << ST_FLITE_RUN | 1 << ST_FLITE_OFF | in fimc_lite_reinit()
186 fimc->state |= (1 << ST_FLITE_SUSPENDED); in fimc_lite_reinit()
188 fimc->state &= ~(1 << ST_FLITE_PENDING | in fimc_lite_reinit()
192 while (!suspend && !list_empty(&fimc->pending_buf_q)) { in fimc_lite_reinit()
193 buf = fimc_lite_pending_queue_pop(fimc); in fimc_lite_reinit()
194 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR); in fimc_lite_reinit()
197 while (!list_empty(&fimc->active_buf_q)) { in fimc_lite_reinit()
198 buf = fimc_lite_active_queue_pop(fimc); in fimc_lite_reinit()
200 fimc_lite_pending_queue_add(fimc, buf); in fimc_lite_reinit()
202 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR); in fimc_lite_reinit()
205 spin_unlock_irqrestore(&fimc->slock, flags); in fimc_lite_reinit()
207 flite_hw_reset(fimc); in fimc_lite_reinit()
212 return fimc_pipeline_call(&fimc->ve, set_stream, 0); in fimc_lite_reinit()
215 static int fimc_lite_stop_capture(struct fimc_lite *fimc, bool suspend) in fimc_lite_stop_capture() argument
219 if (!fimc_lite_active(fimc)) in fimc_lite_stop_capture()
222 spin_lock_irqsave(&fimc->slock, flags); in fimc_lite_stop_capture()
223 set_bit(ST_FLITE_OFF, &fimc->state); in fimc_lite_stop_capture()
224 flite_hw_capture_stop(fimc); in fimc_lite_stop_capture()
225 spin_unlock_irqrestore(&fimc->slock, flags); in fimc_lite_stop_capture()
227 wait_event_timeout(fimc->irq_queue, in fimc_lite_stop_capture()
228 !test_bit(ST_FLITE_OFF, &fimc->state), in fimc_lite_stop_capture()
231 return fimc_lite_reinit(fimc, suspend); in fimc_lite_stop_capture()
234 /* Must be called with fimc.slock spinlock held. */
235 static void fimc_lite_config_update(struct fimc_lite *fimc) in fimc_lite_config_update() argument
237 flite_hw_set_window_offset(fimc, &fimc->inp_frame); in fimc_lite_config_update()
238 flite_hw_set_dma_window(fimc, &fimc->out_frame); in fimc_lite_config_update()
239 flite_hw_set_test_pattern(fimc, fimc->test_pattern->val); in fimc_lite_config_update()
240 clear_bit(ST_FLITE_CONFIG, &fimc->state); in fimc_lite_config_update()
245 struct fimc_lite *fimc = priv; in flite_irq_handler() local
250 spin_lock_irqsave(&fimc->slock, flags); in flite_irq_handler()
252 intsrc = flite_hw_get_interrupt_source(fimc); in flite_irq_handler()
253 flite_hw_clear_pending_irq(fimc); in flite_irq_handler()
255 if (test_and_clear_bit(ST_FLITE_OFF, &fimc->state)) { in flite_irq_handler()
256 wake_up(&fimc->irq_queue); in flite_irq_handler()
261 clear_bit(ST_FLITE_RUN, &fimc->state); in flite_irq_handler()
262 fimc->events.data_overflow++; in flite_irq_handler()
266 flite_hw_clear_last_capture_end(fimc); in flite_irq_handler()
267 clear_bit(ST_FLITE_STREAM, &fimc->state); in flite_irq_handler()
268 wake_up(&fimc->irq_queue); in flite_irq_handler()
271 if (atomic_read(&fimc->out_path) != FIMC_IO_DMA) in flite_irq_handler()
275 test_bit(ST_FLITE_RUN, &fimc->state) && in flite_irq_handler()
276 !list_empty(&fimc->pending_buf_q)) { in flite_irq_handler()
277 vbuf = fimc_lite_pending_queue_pop(fimc); in flite_irq_handler()
278 flite_hw_set_dma_buffer(fimc, vbuf); in flite_irq_handler()
279 fimc_lite_active_queue_add(fimc, vbuf); in flite_irq_handler()
283 test_bit(ST_FLITE_RUN, &fimc->state) && in flite_irq_handler()
284 !list_empty(&fimc->active_buf_q)) { in flite_irq_handler()
285 vbuf = fimc_lite_active_queue_pop(fimc); in flite_irq_handler()
286 vbuf->vb.vb2_buf.timestamp = ktime_get_ns(); in flite_irq_handler()
287 vbuf->vb.sequence = fimc->frame_count++; in flite_irq_handler()
288 flite_hw_mask_dma_buffer(fimc, vbuf->index); in flite_irq_handler()
289 vb2_buffer_done(&vbuf->vb.vb2_buf, VB2_BUF_STATE_DONE); in flite_irq_handler()
292 if (test_bit(ST_FLITE_CONFIG, &fimc->state)) in flite_irq_handler()
293 fimc_lite_config_update(fimc); in flite_irq_handler()
295 if (list_empty(&fimc->pending_buf_q)) { in flite_irq_handler()
296 flite_hw_capture_stop(fimc); in flite_irq_handler()
297 clear_bit(ST_FLITE_STREAM, &fimc->state); in flite_irq_handler()
300 set_bit(ST_FLITE_RUN, &fimc->state); in flite_irq_handler()
301 spin_unlock_irqrestore(&fimc->slock, flags); in flite_irq_handler()
307 struct fimc_lite *fimc = q->drv_priv; in start_streaming() local
311 spin_lock_irqsave(&fimc->slock, flags); in start_streaming()
313 fimc->buf_index = 0; in start_streaming()
314 fimc->frame_count = 0; in start_streaming()
316 spin_unlock_irqrestore(&fimc->slock, flags); in start_streaming()
318 ret = fimc_lite_hw_init(fimc, false); in start_streaming()
320 fimc_lite_reinit(fimc, false); in start_streaming()
324 set_bit(ST_FLITE_PENDING, &fimc->state); in start_streaming()
326 if (!list_empty(&fimc->active_buf_q) && in start_streaming()
327 !test_and_set_bit(ST_FLITE_STREAM, &fimc->state)) { in start_streaming()
328 flite_hw_capture_start(fimc); in start_streaming()
330 if (!test_and_set_bit(ST_SENSOR_STREAM, &fimc->state)) in start_streaming()
331 fimc_pipeline_call(&fimc->ve, set_stream, 1); in start_streaming()
334 flite_hw_dump_regs(fimc, __func__); in start_streaming()
341 struct fimc_lite *fimc = q->drv_priv; in stop_streaming() local
343 if (!fimc_lite_active(fimc)) in stop_streaming()
346 fimc_lite_stop_capture(fimc, false); in stop_streaming()
353 struct fimc_lite *fimc = vq->drv_priv; in queue_setup() local
354 struct flite_frame *frame = &fimc->out_frame; in queue_setup()
355 const struct fimc_fmt *fmt = frame->fmt; in queue_setup()
356 unsigned long wh = frame->f_width * frame->f_height; in queue_setup()
360 return -EINVAL; in queue_setup()
363 if (*num_planes != fmt->memplanes) in queue_setup()
364 return -EINVAL; in queue_setup()
366 if (sizes[i] < (wh * fmt->depth[i]) / 8) in queue_setup()
367 return -EINVAL; in queue_setup()
371 *num_planes = fmt->memplanes; in queue_setup()
373 for (i = 0; i < fmt->memplanes; i++) in queue_setup()
374 sizes[i] = (wh * fmt->depth[i]) / 8; in queue_setup()
381 struct vb2_queue *vq = vb->vb2_queue; in buffer_prepare()
382 struct fimc_lite *fimc = vq->drv_priv; in buffer_prepare() local
385 if (fimc->out_frame.fmt == NULL) in buffer_prepare()
386 return -EINVAL; in buffer_prepare()
388 for (i = 0; i < fimc->out_frame.fmt->memplanes; i++) { in buffer_prepare()
389 unsigned long size = fimc->payload[i]; in buffer_prepare()
392 v4l2_err(&fimc->ve.vdev, in buffer_prepare()
395 return -EINVAL; in buffer_prepare()
408 struct fimc_lite *fimc = vb2_get_drv_priv(vb->vb2_queue); in buffer_queue() local
411 spin_lock_irqsave(&fimc->slock, flags); in buffer_queue()
412 buf->addr = vb2_dma_contig_plane_dma_addr(vb, 0); in buffer_queue()
414 buf->index = fimc->buf_index++; in buffer_queue()
415 if (fimc->buf_index >= fimc->reqbufs_count) in buffer_queue()
416 fimc->buf_index = 0; in buffer_queue()
418 if (!test_bit(ST_FLITE_SUSPENDED, &fimc->state) && in buffer_queue()
419 !test_bit(ST_FLITE_STREAM, &fimc->state) && in buffer_queue()
420 list_empty(&fimc->active_buf_q)) { in buffer_queue()
421 flite_hw_set_dma_buffer(fimc, buf); in buffer_queue()
422 fimc_lite_active_queue_add(fimc, buf); in buffer_queue()
424 fimc_lite_pending_queue_add(fimc, buf); in buffer_queue()
427 if (vb2_is_streaming(&fimc->vb_queue) && in buffer_queue()
428 !list_empty(&fimc->pending_buf_q) && in buffer_queue()
429 !test_and_set_bit(ST_FLITE_STREAM, &fimc->state)) { in buffer_queue()
430 flite_hw_capture_start(fimc); in buffer_queue()
431 spin_unlock_irqrestore(&fimc->slock, flags); in buffer_queue()
433 if (!test_and_set_bit(ST_SENSOR_STREAM, &fimc->state)) in buffer_queue()
434 fimc_pipeline_call(&fimc->ve, set_stream, 1); in buffer_queue()
437 spin_unlock_irqrestore(&fimc->slock, flags); in buffer_queue()
450 static void fimc_lite_clear_event_counters(struct fimc_lite *fimc) in fimc_lite_clear_event_counters() argument
454 spin_lock_irqsave(&fimc->slock, flags); in fimc_lite_clear_event_counters()
455 memset(&fimc->events, 0, sizeof(fimc->events)); in fimc_lite_clear_event_counters()
456 spin_unlock_irqrestore(&fimc->slock, flags); in fimc_lite_clear_event_counters()
461 struct fimc_lite *fimc = video_drvdata(file); in fimc_lite_open() local
462 struct media_entity *me = &fimc->ve.vdev.entity; in fimc_lite_open()
465 mutex_lock(&fimc->lock); in fimc_lite_open()
466 if (atomic_read(&fimc->out_path) != FIMC_IO_DMA) { in fimc_lite_open()
467 ret = -EBUSY; in fimc_lite_open()
471 set_bit(ST_FLITE_IN_USE, &fimc->state); in fimc_lite_open()
472 ret = pm_runtime_resume_and_get(&fimc->pdev->dev); in fimc_lite_open()
481 atomic_read(&fimc->out_path) != FIMC_IO_DMA) in fimc_lite_open()
484 mutex_lock(&me->graph_obj.mdev->graph_mutex); in fimc_lite_open()
486 ret = fimc_pipeline_call(&fimc->ve, open, me, true); in fimc_lite_open()
490 me->use_count++; in fimc_lite_open()
492 mutex_unlock(&me->graph_obj.mdev->graph_mutex); in fimc_lite_open()
495 fimc_lite_clear_event_counters(fimc); in fimc_lite_open()
501 pm_runtime_put_sync(&fimc->pdev->dev); in fimc_lite_open()
503 clear_bit(ST_FLITE_IN_USE, &fimc->state); in fimc_lite_open()
505 mutex_unlock(&fimc->lock); in fimc_lite_open()
511 struct fimc_lite *fimc = video_drvdata(file); in fimc_lite_release() local
512 struct media_entity *entity = &fimc->ve.vdev.entity; in fimc_lite_release()
514 mutex_lock(&fimc->lock); in fimc_lite_release()
517 atomic_read(&fimc->out_path) == FIMC_IO_DMA) { in fimc_lite_release()
518 if (fimc->streaming) { in fimc_lite_release()
519 video_device_pipeline_stop(&fimc->ve.vdev); in fimc_lite_release()
520 fimc->streaming = false; in fimc_lite_release()
522 fimc_lite_stop_capture(fimc, false); in fimc_lite_release()
523 fimc_pipeline_call(&fimc->ve, close); in fimc_lite_release()
524 clear_bit(ST_FLITE_IN_USE, &fimc->state); in fimc_lite_release()
526 mutex_lock(&entity->graph_obj.mdev->graph_mutex); in fimc_lite_release()
527 entity->use_count--; in fimc_lite_release()
528 mutex_unlock(&entity->graph_obj.mdev->graph_mutex); in fimc_lite_release()
532 pm_runtime_put(&fimc->pdev->dev); in fimc_lite_release()
533 clear_bit(ST_FLITE_SUSPENDED, &fimc->state); in fimc_lite_release()
535 mutex_unlock(&fimc->lock); in fimc_lite_release()
552 static const struct fimc_fmt *fimc_lite_subdev_try_fmt(struct fimc_lite *fimc, in fimc_lite_subdev_try_fmt() argument
556 struct flite_drvdata *dd = fimc->dd; in fimc_lite_subdev_try_fmt()
557 struct v4l2_mbus_framefmt *mf = &format->format; in fimc_lite_subdev_try_fmt()
560 if (format->pad == FLITE_SD_PAD_SINK) { in fimc_lite_subdev_try_fmt()
561 v4l_bound_align_image(&mf->width, 8, dd->max_width, in fimc_lite_subdev_try_fmt()
562 ffs(dd->out_width_align) - 1, in fimc_lite_subdev_try_fmt()
563 &mf->height, 0, dd->max_height, 0, 0); in fimc_lite_subdev_try_fmt()
565 fmt = fimc_lite_find_format(NULL, &mf->code, 0, 0); in fimc_lite_subdev_try_fmt()
569 mf->colorspace = fmt->colorspace; in fimc_lite_subdev_try_fmt()
570 mf->code = fmt->mbus_code; in fimc_lite_subdev_try_fmt()
572 struct flite_frame *sink = &fimc->inp_frame; in fimc_lite_subdev_try_fmt()
576 if (format->which == V4L2_SUBDEV_FORMAT_TRY) { in fimc_lite_subdev_try_fmt()
580 mf->code = sink_fmt->code; in fimc_lite_subdev_try_fmt()
581 mf->colorspace = sink_fmt->colorspace; in fimc_lite_subdev_try_fmt()
586 mf->code = sink->fmt->mbus_code; in fimc_lite_subdev_try_fmt()
587 mf->colorspace = sink->fmt->colorspace; in fimc_lite_subdev_try_fmt()
588 rect = &sink->rect; in fimc_lite_subdev_try_fmt()
592 mf->width = rect->width; in fimc_lite_subdev_try_fmt()
593 mf->height = rect->height; in fimc_lite_subdev_try_fmt()
596 mf->field = V4L2_FIELD_NONE; in fimc_lite_subdev_try_fmt()
598 v4l2_dbg(1, debug, &fimc->subdev, "code: %#x (%d), %dx%d\n", in fimc_lite_subdev_try_fmt()
599 mf->code, mf->colorspace, mf->width, mf->height); in fimc_lite_subdev_try_fmt()
604 static void fimc_lite_try_crop(struct fimc_lite *fimc, struct v4l2_rect *r) in fimc_lite_try_crop() argument
606 struct flite_frame *frame = &fimc->inp_frame; in fimc_lite_try_crop()
608 v4l_bound_align_image(&r->width, 0, frame->f_width, 0, in fimc_lite_try_crop()
609 &r->height, 0, frame->f_height, 0, 0); in fimc_lite_try_crop()
612 r->left = clamp_t(u32, r->left, 0, frame->f_width - r->width); in fimc_lite_try_crop()
613 r->left = round_down(r->left, fimc->dd->win_hor_offs_align); in fimc_lite_try_crop()
614 r->top = clamp_t(u32, r->top, 0, frame->f_height - r->height); in fimc_lite_try_crop()
616 v4l2_dbg(1, debug, &fimc->subdev, "(%d,%d)/%dx%d, sink fmt: %dx%d\n", in fimc_lite_try_crop()
617 r->left, r->top, r->width, r->height, in fimc_lite_try_crop()
618 frame->f_width, frame->f_height); in fimc_lite_try_crop()
621 static void fimc_lite_try_compose(struct fimc_lite *fimc, struct v4l2_rect *r) in fimc_lite_try_compose() argument
623 struct flite_frame *frame = &fimc->out_frame; in fimc_lite_try_compose()
624 struct v4l2_rect *crop_rect = &fimc->inp_frame.rect; in fimc_lite_try_compose()
626 /* Scaling is not supported so we enforce compose rectangle size in fimc_lite_try_compose()
628 r->width = crop_rect->width; in fimc_lite_try_compose()
629 r->height = crop_rect->height; in fimc_lite_try_compose()
632 r->left = clamp_t(u32, r->left, 0, frame->f_width - r->width); in fimc_lite_try_compose()
633 r->left = round_down(r->left, fimc->dd->out_hor_offs_align); in fimc_lite_try_compose()
634 r->top = clamp_t(u32, r->top, 0, fimc->out_frame.f_height - r->height); in fimc_lite_try_compose()
636 v4l2_dbg(1, debug, &fimc->subdev, "(%d,%d)/%dx%d, source fmt: %dx%d\n", in fimc_lite_try_compose()
637 r->left, r->top, r->width, r->height, in fimc_lite_try_compose()
638 frame->f_width, frame->f_height); in fimc_lite_try_compose()
647 strscpy(cap->driver, FIMC_LITE_DRV_NAME, sizeof(cap->driver)); in fimc_lite_querycap()
648 strscpy(cap->card, FIMC_LITE_DRV_NAME, sizeof(cap->card)); in fimc_lite_querycap()
657 if (f->index >= ARRAY_SIZE(fimc_lite_formats)) in fimc_lite_enum_fmt()
658 return -EINVAL; in fimc_lite_enum_fmt()
660 fmt = &fimc_lite_formats[f->index]; in fimc_lite_enum_fmt()
661 f->pixelformat = fmt->fourcc; in fimc_lite_enum_fmt()
669 struct fimc_lite *fimc = video_drvdata(file); in fimc_lite_g_fmt_mplane() local
670 struct v4l2_pix_format_mplane *pixm = &f->fmt.pix_mp; in fimc_lite_g_fmt_mplane()
671 struct v4l2_plane_pix_format *plane_fmt = &pixm->plane_fmt[0]; in fimc_lite_g_fmt_mplane()
672 struct flite_frame *frame = &fimc->out_frame; in fimc_lite_g_fmt_mplane()
673 const struct fimc_fmt *fmt = frame->fmt; in fimc_lite_g_fmt_mplane()
675 plane_fmt->bytesperline = (frame->f_width * fmt->depth[0]) / 8; in fimc_lite_g_fmt_mplane()
676 plane_fmt->sizeimage = plane_fmt->bytesperline * frame->f_height; in fimc_lite_g_fmt_mplane()
678 pixm->num_planes = fmt->memplanes; in fimc_lite_g_fmt_mplane()
679 pixm->pixelformat = fmt->fourcc; in fimc_lite_g_fmt_mplane()
680 pixm->width = frame->f_width; in fimc_lite_g_fmt_mplane()
681 pixm->height = frame->f_height; in fimc_lite_g_fmt_mplane()
682 pixm->field = V4L2_FIELD_NONE; in fimc_lite_g_fmt_mplane()
683 pixm->colorspace = fmt->colorspace; in fimc_lite_g_fmt_mplane()
687 static int fimc_lite_try_fmt(struct fimc_lite *fimc, in fimc_lite_try_fmt() argument
691 u32 bpl = pixm->plane_fmt[0].bytesperline; in fimc_lite_try_fmt()
692 struct flite_drvdata *dd = fimc->dd; in fimc_lite_try_fmt()
693 const struct fimc_fmt *inp_fmt = fimc->inp_frame.fmt; in fimc_lite_try_fmt()
697 return -EINVAL; in fimc_lite_try_fmt()
700 * raw Bayer the FIMC-LITE's output format must match its camera in fimc_lite_try_fmt()
703 if (inp_fmt->flags & FMT_FLAGS_YUV) in fimc_lite_try_fmt()
704 fmt = fimc_lite_find_format(&pixm->pixelformat, NULL, in fimc_lite_try_fmt()
705 inp_fmt->flags, 0); in fimc_lite_try_fmt()
710 return -EINVAL; in fimc_lite_try_fmt()
713 v4l_bound_align_image(&pixm->width, 8, dd->max_width, in fimc_lite_try_fmt()
714 ffs(dd->out_width_align) - 1, in fimc_lite_try_fmt()
715 &pixm->height, 0, dd->max_height, 0, 0); in fimc_lite_try_fmt()
717 if ((bpl == 0 || ((bpl * 8) / fmt->depth[0]) < pixm->width)) in fimc_lite_try_fmt()
718 pixm->plane_fmt[0].bytesperline = (pixm->width * in fimc_lite_try_fmt()
719 fmt->depth[0]) / 8; in fimc_lite_try_fmt()
721 if (pixm->plane_fmt[0].sizeimage == 0) in fimc_lite_try_fmt()
722 pixm->plane_fmt[0].sizeimage = (pixm->width * pixm->height * in fimc_lite_try_fmt()
723 fmt->depth[0]) / 8; in fimc_lite_try_fmt()
724 pixm->num_planes = fmt->memplanes; in fimc_lite_try_fmt()
725 pixm->pixelformat = fmt->fourcc; in fimc_lite_try_fmt()
726 pixm->colorspace = fmt->colorspace; in fimc_lite_try_fmt()
727 pixm->field = V4L2_FIELD_NONE; in fimc_lite_try_fmt()
734 struct fimc_lite *fimc = video_drvdata(file); in fimc_lite_try_fmt_mplane() local
735 return fimc_lite_try_fmt(fimc, &f->fmt.pix_mp, NULL); in fimc_lite_try_fmt_mplane()
741 const struct v4l2_pix_format_mplane *pixm = &f->fmt.pix_mp; in fimc_lite_s_fmt_mplane()
742 struct fimc_lite *fimc = video_drvdata(file); in fimc_lite_s_fmt_mplane() local
743 struct flite_frame *frame = &fimc->out_frame; in fimc_lite_s_fmt_mplane()
747 if (vb2_is_busy(&fimc->vb_queue)) in fimc_lite_s_fmt_mplane()
748 return -EBUSY; in fimc_lite_s_fmt_mplane()
750 ret = fimc_lite_try_fmt(fimc, &f->fmt.pix_mp, &fmt); in fimc_lite_s_fmt_mplane()
754 frame->fmt = fmt; in fimc_lite_s_fmt_mplane()
755 fimc->payload[0] = max((pixm->width * pixm->height * fmt->depth[0]) / 8, in fimc_lite_s_fmt_mplane()
756 pixm->plane_fmt[0].sizeimage); in fimc_lite_s_fmt_mplane()
757 frame->f_width = pixm->width; in fimc_lite_s_fmt_mplane()
758 frame->f_height = pixm->height; in fimc_lite_s_fmt_mplane()
763 static int fimc_pipeline_validate(struct fimc_lite *fimc) in fimc_pipeline_validate() argument
765 struct v4l2_subdev *sd = &fimc->subdev; in fimc_pipeline_validate()
777 pad = &sd->entity.pads[0]; in fimc_pipeline_validate()
778 if (!(pad->flags & MEDIA_PAD_FL_SINK)) in fimc_pipeline_validate()
780 /* Don't call FIMC subdev operation to avoid nested locking */ in fimc_pipeline_validate()
781 if (sd == &fimc->subdev) { in fimc_pipeline_validate()
782 struct flite_frame *ff = &fimc->out_frame; in fimc_pipeline_validate()
783 sink_fmt.format.width = ff->f_width; in fimc_pipeline_validate()
784 sink_fmt.format.height = ff->f_height; in fimc_pipeline_validate()
785 sink_fmt.format.code = fimc->inp_frame.fmt->mbus_code; in fimc_pipeline_validate()
787 sink_fmt.pad = pad->index; in fimc_pipeline_validate()
790 if (ret < 0 && ret != -ENOIOCTLCMD) in fimc_pipeline_validate()
791 return -EPIPE; in fimc_pipeline_validate()
795 if (!pad || !is_media_entity_v4l2_subdev(pad->entity)) in fimc_pipeline_validate()
798 sd = media_entity_to_v4l2_subdev(pad->entity); in fimc_pipeline_validate()
799 src_fmt.pad = pad->index; in fimc_pipeline_validate()
801 if (ret < 0 && ret != -ENOIOCTLCMD) in fimc_pipeline_validate()
802 return -EPIPE; in fimc_pipeline_validate()
807 return -EPIPE; in fimc_pipeline_validate()
815 struct fimc_lite *fimc = video_drvdata(file); in fimc_lite_streamon() local
818 if (fimc_lite_active(fimc)) in fimc_lite_streamon()
819 return -EBUSY; in fimc_lite_streamon()
821 ret = video_device_pipeline_start(&fimc->ve.vdev, &fimc->ve.pipe->mp); in fimc_lite_streamon()
825 ret = fimc_pipeline_validate(fimc); in fimc_lite_streamon()
829 fimc->sensor = fimc_find_remote_sensor(&fimc->subdev.entity); in fimc_lite_streamon()
833 fimc->streaming = true; in fimc_lite_streamon()
838 video_device_pipeline_stop(&fimc->ve.vdev); in fimc_lite_streamon()
845 struct fimc_lite *fimc = video_drvdata(file); in fimc_lite_streamoff() local
852 video_device_pipeline_stop(&fimc->ve.vdev); in fimc_lite_streamoff()
853 fimc->streaming = false; in fimc_lite_streamoff()
860 struct fimc_lite *fimc = video_drvdata(file); in fimc_lite_reqbufs() local
863 reqbufs->count = max_t(u32, FLITE_REQ_BUFS_MIN, reqbufs->count); in fimc_lite_reqbufs()
866 fimc->reqbufs_count = reqbufs->count; in fimc_lite_reqbufs()
874 struct fimc_lite *fimc = video_drvdata(file); in fimc_lite_g_selection() local
875 struct flite_frame *f = &fimc->out_frame; in fimc_lite_g_selection()
877 if (sel->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) in fimc_lite_g_selection()
878 return -EINVAL; in fimc_lite_g_selection()
880 switch (sel->target) { in fimc_lite_g_selection()
883 sel->r.left = 0; in fimc_lite_g_selection()
884 sel->r.top = 0; in fimc_lite_g_selection()
885 sel->r.width = f->f_width; in fimc_lite_g_selection()
886 sel->r.height = f->f_height; in fimc_lite_g_selection()
890 sel->r = f->rect; in fimc_lite_g_selection()
894 return -EINVAL; in fimc_lite_g_selection()
900 struct fimc_lite *fimc = video_drvdata(file); in fimc_lite_s_selection() local
901 struct flite_frame *f = &fimc->out_frame; in fimc_lite_s_selection()
902 struct v4l2_rect rect = sel->r; in fimc_lite_s_selection()
905 if (sel->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || in fimc_lite_s_selection()
906 sel->target != V4L2_SEL_TGT_COMPOSE) in fimc_lite_s_selection()
907 return -EINVAL; in fimc_lite_s_selection()
909 fimc_lite_try_compose(fimc, &rect); in fimc_lite_s_selection()
911 if ((sel->flags & V4L2_SEL_FLAG_LE) && in fimc_lite_s_selection()
912 !v4l2_rect_enclosed(&rect, &sel->r)) in fimc_lite_s_selection()
913 return -ERANGE; in fimc_lite_s_selection()
915 if ((sel->flags & V4L2_SEL_FLAG_GE) && in fimc_lite_s_selection()
916 !v4l2_rect_enclosed(&sel->r, &rect)) in fimc_lite_s_selection()
917 return -ERANGE; in fimc_lite_s_selection()
919 sel->r = rect; in fimc_lite_s_selection()
920 spin_lock_irqsave(&fimc->slock, flags); in fimc_lite_s_selection()
921 f->rect = rect; in fimc_lite_s_selection()
922 set_bit(ST_FLITE_CONFIG, &fimc->state); in fimc_lite_s_selection()
923 spin_unlock_irqrestore(&fimc->slock, flags); in fimc_lite_s_selection()
952 struct fimc_lite *fimc = v4l2_get_subdevdata(sd); in fimc_lite_link_setup() local
955 if (WARN_ON(fimc == NULL)) in fimc_lite_link_setup()
958 v4l2_dbg(1, debug, sd, "%s: %s --> %s, flags: 0x%x. source_id: 0x%x\n", in fimc_lite_link_setup()
959 __func__, remote->entity->name, local->entity->name, in fimc_lite_link_setup()
960 flags, fimc->source_subdev_grp_id); in fimc_lite_link_setup()
962 switch (local->index) { in fimc_lite_link_setup()
965 if (fimc->source_subdev_grp_id == 0) in fimc_lite_link_setup()
966 fimc->source_subdev_grp_id = sd->grp_id; in fimc_lite_link_setup()
968 ret = -EBUSY; in fimc_lite_link_setup()
970 fimc->source_subdev_grp_id = 0; in fimc_lite_link_setup()
971 fimc->sensor = NULL; in fimc_lite_link_setup()
977 atomic_set(&fimc->out_path, FIMC_IO_NONE); in fimc_lite_link_setup()
979 atomic_set(&fimc->out_path, FIMC_IO_DMA); in fimc_lite_link_setup()
984 atomic_set(&fimc->out_path, FIMC_IO_NONE); in fimc_lite_link_setup()
986 atomic_set(&fimc->out_path, FIMC_IO_ISP); in fimc_lite_link_setup()
991 ret = -EINVAL; in fimc_lite_link_setup()
1008 fmt = fimc_lite_find_format(NULL, NULL, 0, code->index); in fimc_lite_subdev_enum_mbus_code()
1010 return -EINVAL; in fimc_lite_subdev_enum_mbus_code()
1011 code->code = fmt->mbus_code; in fimc_lite_subdev_enum_mbus_code()
1029 struct fimc_lite *fimc = v4l2_get_subdevdata(sd); in fimc_lite_subdev_get_fmt() local
1030 struct v4l2_mbus_framefmt *mf = &fmt->format; in fimc_lite_subdev_get_fmt()
1031 struct flite_frame *f = &fimc->inp_frame; in fimc_lite_subdev_get_fmt()
1033 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { in fimc_lite_subdev_get_fmt()
1034 mf = __fimc_lite_subdev_get_try_fmt(sd, sd_state, fmt->pad); in fimc_lite_subdev_get_fmt()
1035 fmt->format = *mf; in fimc_lite_subdev_get_fmt()
1039 mutex_lock(&fimc->lock); in fimc_lite_subdev_get_fmt()
1040 mf->colorspace = f->fmt->colorspace; in fimc_lite_subdev_get_fmt()
1041 mf->code = f->fmt->mbus_code; in fimc_lite_subdev_get_fmt()
1043 if (fmt->pad == FLITE_SD_PAD_SINK) { in fimc_lite_subdev_get_fmt()
1045 mf->width = f->f_width; in fimc_lite_subdev_get_fmt()
1046 mf->height = f->f_height; in fimc_lite_subdev_get_fmt()
1049 mf->width = f->rect.width; in fimc_lite_subdev_get_fmt()
1050 mf->height = f->rect.height; in fimc_lite_subdev_get_fmt()
1052 mutex_unlock(&fimc->lock); in fimc_lite_subdev_get_fmt()
1060 struct fimc_lite *fimc = v4l2_get_subdevdata(sd); in fimc_lite_subdev_set_fmt() local
1061 struct v4l2_mbus_framefmt *mf = &fmt->format; in fimc_lite_subdev_set_fmt()
1062 struct flite_frame *sink = &fimc->inp_frame; in fimc_lite_subdev_set_fmt()
1063 struct flite_frame *source = &fimc->out_frame; in fimc_lite_subdev_set_fmt()
1067 fmt->pad, mf->code, mf->width, mf->height); in fimc_lite_subdev_set_fmt()
1069 mutex_lock(&fimc->lock); in fimc_lite_subdev_set_fmt()
1071 if ((atomic_read(&fimc->out_path) == FIMC_IO_ISP && in fimc_lite_subdev_set_fmt()
1072 media_entity_is_streaming(&sd->entity)) || in fimc_lite_subdev_set_fmt()
1073 (atomic_read(&fimc->out_path) == FIMC_IO_DMA && in fimc_lite_subdev_set_fmt()
1074 vb2_is_busy(&fimc->vb_queue))) { in fimc_lite_subdev_set_fmt()
1075 mutex_unlock(&fimc->lock); in fimc_lite_subdev_set_fmt()
1076 return -EBUSY; in fimc_lite_subdev_set_fmt()
1079 ffmt = fimc_lite_subdev_try_fmt(fimc, sd_state, fmt); in fimc_lite_subdev_set_fmt()
1081 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { in fimc_lite_subdev_set_fmt()
1084 mf = __fimc_lite_subdev_get_try_fmt(sd, sd_state, fmt->pad); in fimc_lite_subdev_set_fmt()
1085 *mf = fmt->format; in fimc_lite_subdev_set_fmt()
1087 if (fmt->pad == FLITE_SD_PAD_SINK) { in fimc_lite_subdev_set_fmt()
1094 mutex_unlock(&fimc->lock); in fimc_lite_subdev_set_fmt()
1098 if (fmt->pad == FLITE_SD_PAD_SINK) { in fimc_lite_subdev_set_fmt()
1099 sink->f_width = mf->width; in fimc_lite_subdev_set_fmt()
1100 sink->f_height = mf->height; in fimc_lite_subdev_set_fmt()
1101 sink->fmt = ffmt; in fimc_lite_subdev_set_fmt()
1103 sink->rect.width = mf->width; in fimc_lite_subdev_set_fmt()
1104 sink->rect.height = mf->height; in fimc_lite_subdev_set_fmt()
1105 sink->rect.left = 0; in fimc_lite_subdev_set_fmt()
1106 sink->rect.top = 0; in fimc_lite_subdev_set_fmt()
1108 source->rect = sink->rect; in fimc_lite_subdev_set_fmt()
1109 source->f_width = mf->width; in fimc_lite_subdev_set_fmt()
1110 source->f_height = mf->height; in fimc_lite_subdev_set_fmt()
1113 mutex_unlock(&fimc->lock); in fimc_lite_subdev_set_fmt()
1121 struct fimc_lite *fimc = v4l2_get_subdevdata(sd); in fimc_lite_subdev_get_selection() local
1122 struct flite_frame *f = &fimc->inp_frame; in fimc_lite_subdev_get_selection()
1124 if ((sel->target != V4L2_SEL_TGT_CROP && in fimc_lite_subdev_get_selection()
1125 sel->target != V4L2_SEL_TGT_CROP_BOUNDS) || in fimc_lite_subdev_get_selection()
1126 sel->pad != FLITE_SD_PAD_SINK) in fimc_lite_subdev_get_selection()
1127 return -EINVAL; in fimc_lite_subdev_get_selection()
1129 if (sel->which == V4L2_SUBDEV_FORMAT_TRY) { in fimc_lite_subdev_get_selection()
1130 sel->r = *v4l2_subdev_state_get_crop(sd_state, sel->pad); in fimc_lite_subdev_get_selection()
1134 mutex_lock(&fimc->lock); in fimc_lite_subdev_get_selection()
1135 if (sel->target == V4L2_SEL_TGT_CROP) { in fimc_lite_subdev_get_selection()
1136 sel->r = f->rect; in fimc_lite_subdev_get_selection()
1138 sel->r.left = 0; in fimc_lite_subdev_get_selection()
1139 sel->r.top = 0; in fimc_lite_subdev_get_selection()
1140 sel->r.width = f->f_width; in fimc_lite_subdev_get_selection()
1141 sel->r.height = f->f_height; in fimc_lite_subdev_get_selection()
1143 mutex_unlock(&fimc->lock); in fimc_lite_subdev_get_selection()
1146 __func__, f->rect.left, f->rect.top, f->rect.width, in fimc_lite_subdev_get_selection()
1147 f->rect.height, f->f_width, f->f_height); in fimc_lite_subdev_get_selection()
1156 struct fimc_lite *fimc = v4l2_get_subdevdata(sd); in fimc_lite_subdev_set_selection() local
1157 struct flite_frame *f = &fimc->inp_frame; in fimc_lite_subdev_set_selection()
1160 if (sel->target != V4L2_SEL_TGT_CROP || sel->pad != FLITE_SD_PAD_SINK) in fimc_lite_subdev_set_selection()
1161 return -EINVAL; in fimc_lite_subdev_set_selection()
1163 mutex_lock(&fimc->lock); in fimc_lite_subdev_set_selection()
1164 fimc_lite_try_crop(fimc, &sel->r); in fimc_lite_subdev_set_selection()
1166 if (sel->which == V4L2_SUBDEV_FORMAT_TRY) { in fimc_lite_subdev_set_selection()
1167 *v4l2_subdev_state_get_crop(sd_state, sel->pad) = sel->r; in fimc_lite_subdev_set_selection()
1170 spin_lock_irqsave(&fimc->slock, flags); in fimc_lite_subdev_set_selection()
1171 f->rect = sel->r; in fimc_lite_subdev_set_selection()
1173 fimc->out_frame.rect = sel->r; in fimc_lite_subdev_set_selection()
1174 set_bit(ST_FLITE_CONFIG, &fimc->state); in fimc_lite_subdev_set_selection()
1175 spin_unlock_irqrestore(&fimc->slock, flags); in fimc_lite_subdev_set_selection()
1177 mutex_unlock(&fimc->lock); in fimc_lite_subdev_set_selection()
1180 __func__, f->rect.left, f->rect.top, f->rect.width, in fimc_lite_subdev_set_selection()
1181 f->rect.height, f->f_width, f->f_height); in fimc_lite_subdev_set_selection()
1188 struct fimc_lite *fimc = v4l2_get_subdevdata(sd); in fimc_lite_subdev_s_stream() local
1193 * Find sensor subdev linked to FIMC-LITE directly or through in fimc_lite_subdev_s_stream()
1194 * MIPI-CSIS. This is required for configuration where FIMC-LITE in fimc_lite_subdev_s_stream()
1195 * is used as a subdev only and feeds data internally to FIMC-IS. in fimc_lite_subdev_s_stream()
1196 * The pipeline links are protected through entity.pipe so there is no in fimc_lite_subdev_s_stream()
1199 fimc->sensor = fimc_find_remote_sensor(&sd->entity); in fimc_lite_subdev_s_stream()
1201 if (atomic_read(&fimc->out_path) != FIMC_IO_ISP) in fimc_lite_subdev_s_stream()
1202 return -ENOIOCTLCMD; in fimc_lite_subdev_s_stream()
1204 mutex_lock(&fimc->lock); in fimc_lite_subdev_s_stream()
1206 flite_hw_reset(fimc); in fimc_lite_subdev_s_stream()
1207 ret = fimc_lite_hw_init(fimc, true); in fimc_lite_subdev_s_stream()
1209 spin_lock_irqsave(&fimc->slock, flags); in fimc_lite_subdev_s_stream()
1210 flite_hw_capture_start(fimc); in fimc_lite_subdev_s_stream()
1211 spin_unlock_irqrestore(&fimc->slock, flags); in fimc_lite_subdev_s_stream()
1214 set_bit(ST_FLITE_OFF, &fimc->state); in fimc_lite_subdev_s_stream()
1216 spin_lock_irqsave(&fimc->slock, flags); in fimc_lite_subdev_s_stream()
1217 flite_hw_capture_stop(fimc); in fimc_lite_subdev_s_stream()
1218 spin_unlock_irqrestore(&fimc->slock, flags); in fimc_lite_subdev_s_stream()
1220 ret = wait_event_timeout(fimc->irq_queue, in fimc_lite_subdev_s_stream()
1221 !test_bit(ST_FLITE_OFF, &fimc->state), in fimc_lite_subdev_s_stream()
1225 clear_bit(ST_FLITE_RUN, &fimc->state); in fimc_lite_subdev_s_stream()
1228 mutex_unlock(&fimc->lock); in fimc_lite_subdev_s_stream()
1234 struct fimc_lite *fimc = v4l2_get_subdevdata(sd); in fimc_lite_log_status() local
1236 flite_hw_dump_regs(fimc, __func__); in fimc_lite_log_status()
1242 struct fimc_lite *fimc = v4l2_get_subdevdata(sd); in fimc_lite_subdev_registered() local
1243 struct vb2_queue *q = &fimc->vb_queue; in fimc_lite_subdev_registered()
1244 struct video_device *vfd = &fimc->ve.vdev; in fimc_lite_subdev_registered()
1248 atomic_set(&fimc->out_path, FIMC_IO_DMA); in fimc_lite_subdev_registered()
1250 snprintf(vfd->name, sizeof(vfd->name), "fimc-lite.%d.capture", in fimc_lite_subdev_registered()
1251 fimc->index); in fimc_lite_subdev_registered()
1253 vfd->fops = &fimc_lite_fops; in fimc_lite_subdev_registered()
1254 vfd->ioctl_ops = &fimc_lite_ioctl_ops; in fimc_lite_subdev_registered()
1255 vfd->v4l2_dev = sd->v4l2_dev; in fimc_lite_subdev_registered()
1256 vfd->minor = -1; in fimc_lite_subdev_registered()
1257 vfd->release = video_device_release_empty; in fimc_lite_subdev_registered()
1258 vfd->queue = q; in fimc_lite_subdev_registered()
1259 vfd->device_caps = V4L2_CAP_VIDEO_CAPTURE_MPLANE | V4L2_CAP_STREAMING; in fimc_lite_subdev_registered()
1260 fimc->reqbufs_count = 0; in fimc_lite_subdev_registered()
1262 INIT_LIST_HEAD(&fimc->pending_buf_q); in fimc_lite_subdev_registered()
1263 INIT_LIST_HEAD(&fimc->active_buf_q); in fimc_lite_subdev_registered()
1266 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; in fimc_lite_subdev_registered()
1267 q->io_modes = VB2_MMAP | VB2_USERPTR; in fimc_lite_subdev_registered()
1268 q->ops = &fimc_lite_qops; in fimc_lite_subdev_registered()
1269 q->mem_ops = &vb2_dma_contig_memops; in fimc_lite_subdev_registered()
1270 q->buf_struct_size = sizeof(struct flite_buffer); in fimc_lite_subdev_registered()
1271 q->drv_priv = fimc; in fimc_lite_subdev_registered()
1272 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in fimc_lite_subdev_registered()
1273 q->lock = &fimc->lock; in fimc_lite_subdev_registered()
1274 q->dev = &fimc->pdev->dev; in fimc_lite_subdev_registered()
1280 fimc->vd_pad.flags = MEDIA_PAD_FL_SINK; in fimc_lite_subdev_registered()
1281 ret = media_entity_pads_init(&vfd->entity, 1, &fimc->vd_pad); in fimc_lite_subdev_registered()
1285 video_set_drvdata(vfd, fimc); in fimc_lite_subdev_registered()
1286 fimc->ve.pipe = v4l2_get_subdev_hostdata(sd); in fimc_lite_subdev_registered()
1288 ret = video_register_device(vfd, VFL_TYPE_VIDEO, -1); in fimc_lite_subdev_registered()
1290 media_entity_cleanup(&vfd->entity); in fimc_lite_subdev_registered()
1291 fimc->ve.pipe = NULL; in fimc_lite_subdev_registered()
1295 v4l2_info(sd->v4l2_dev, "Registered %s as /dev/%s\n", in fimc_lite_subdev_registered()
1296 vfd->name, video_device_node_name(vfd)); in fimc_lite_subdev_registered()
1302 struct fimc_lite *fimc = v4l2_get_subdevdata(sd); in fimc_lite_subdev_unregistered() local
1304 if (fimc == NULL) in fimc_lite_subdev_unregistered()
1307 mutex_lock(&fimc->lock); in fimc_lite_subdev_unregistered()
1309 if (video_is_registered(&fimc->ve.vdev)) { in fimc_lite_subdev_unregistered()
1310 video_unregister_device(&fimc->ve.vdev); in fimc_lite_subdev_unregistered()
1311 media_entity_cleanup(&fimc->ve.vdev.entity); in fimc_lite_subdev_unregistered()
1312 fimc->ve.pipe = NULL; in fimc_lite_subdev_unregistered()
1315 mutex_unlock(&fimc->lock); in fimc_lite_subdev_unregistered()
1347 struct fimc_lite *fimc = container_of(ctrl->handler, struct fimc_lite, in fimc_lite_s_ctrl() local
1349 set_bit(ST_FLITE_CONFIG, &fimc->state); in fimc_lite_s_ctrl()
1365 static void fimc_lite_set_default_config(struct fimc_lite *fimc) in fimc_lite_set_default_config() argument
1367 struct flite_frame *sink = &fimc->inp_frame; in fimc_lite_set_default_config()
1368 struct flite_frame *source = &fimc->out_frame; in fimc_lite_set_default_config()
1370 sink->fmt = &fimc_lite_formats[0]; in fimc_lite_set_default_config()
1371 sink->f_width = FLITE_DEFAULT_WIDTH; in fimc_lite_set_default_config()
1372 sink->f_height = FLITE_DEFAULT_HEIGHT; in fimc_lite_set_default_config()
1374 sink->rect.width = FLITE_DEFAULT_WIDTH; in fimc_lite_set_default_config()
1375 sink->rect.height = FLITE_DEFAULT_HEIGHT; in fimc_lite_set_default_config()
1376 sink->rect.left = 0; in fimc_lite_set_default_config()
1377 sink->rect.top = 0; in fimc_lite_set_default_config()
1382 static int fimc_lite_create_capture_subdev(struct fimc_lite *fimc) in fimc_lite_create_capture_subdev() argument
1384 struct v4l2_ctrl_handler *handler = &fimc->ctrl_handler; in fimc_lite_create_capture_subdev()
1385 struct v4l2_subdev *sd = &fimc->subdev; in fimc_lite_create_capture_subdev()
1389 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in fimc_lite_create_capture_subdev()
1390 snprintf(sd->name, sizeof(sd->name), "FIMC-LITE.%d", fimc->index); in fimc_lite_create_capture_subdev()
1392 fimc->subdev_pads[FLITE_SD_PAD_SINK].flags = MEDIA_PAD_FL_SINK; in fimc_lite_create_capture_subdev()
1393 fimc->subdev_pads[FLITE_SD_PAD_SOURCE_DMA].flags = MEDIA_PAD_FL_SOURCE; in fimc_lite_create_capture_subdev()
1394 fimc->subdev_pads[FLITE_SD_PAD_SOURCE_ISP].flags = MEDIA_PAD_FL_SOURCE; in fimc_lite_create_capture_subdev()
1395 ret = media_entity_pads_init(&sd->entity, FLITE_SD_PADS_NUM, in fimc_lite_create_capture_subdev()
1396 fimc->subdev_pads); in fimc_lite_create_capture_subdev()
1401 fimc->test_pattern = v4l2_ctrl_new_custom(handler, &fimc_lite_ctrl, in fimc_lite_create_capture_subdev()
1403 if (handler->error) { in fimc_lite_create_capture_subdev()
1404 media_entity_cleanup(&sd->entity); in fimc_lite_create_capture_subdev()
1405 return handler->error; in fimc_lite_create_capture_subdev()
1408 sd->ctrl_handler = handler; in fimc_lite_create_capture_subdev()
1409 sd->internal_ops = &fimc_lite_subdev_internal_ops; in fimc_lite_create_capture_subdev()
1410 sd->entity.function = MEDIA_ENT_F_PROC_VIDEO_SCALER; in fimc_lite_create_capture_subdev()
1411 sd->entity.ops = &fimc_lite_subdev_media_ops; in fimc_lite_create_capture_subdev()
1412 sd->owner = THIS_MODULE; in fimc_lite_create_capture_subdev()
1413 v4l2_set_subdevdata(sd, fimc); in fimc_lite_create_capture_subdev()
1418 static void fimc_lite_unregister_capture_subdev(struct fimc_lite *fimc) in fimc_lite_unregister_capture_subdev() argument
1420 struct v4l2_subdev *sd = &fimc->subdev; in fimc_lite_unregister_capture_subdev()
1423 media_entity_cleanup(&sd->entity); in fimc_lite_unregister_capture_subdev()
1424 v4l2_ctrl_handler_free(&fimc->ctrl_handler); in fimc_lite_unregister_capture_subdev()
1428 static void fimc_lite_clk_put(struct fimc_lite *fimc) in fimc_lite_clk_put() argument
1430 if (IS_ERR(fimc->clock)) in fimc_lite_clk_put()
1433 clk_put(fimc->clock); in fimc_lite_clk_put()
1434 fimc->clock = ERR_PTR(-EINVAL); in fimc_lite_clk_put()
1437 static int fimc_lite_clk_get(struct fimc_lite *fimc) in fimc_lite_clk_get() argument
1439 fimc->clock = clk_get(&fimc->pdev->dev, FLITE_CLK_NAME); in fimc_lite_clk_get()
1440 return PTR_ERR_OR_ZERO(fimc->clock); in fimc_lite_clk_get()
1448 struct device *dev = &pdev->dev; in fimc_lite_probe()
1450 struct fimc_lite *fimc; in fimc_lite_probe() local
1454 if (!dev->of_node) in fimc_lite_probe()
1455 return -ENODEV; in fimc_lite_probe()
1457 fimc = devm_kzalloc(dev, sizeof(*fimc), GFP_KERNEL); in fimc_lite_probe()
1458 if (!fimc) in fimc_lite_probe()
1459 return -ENOMEM; in fimc_lite_probe()
1461 of_id = of_match_node(flite_of_match, dev->of_node); in fimc_lite_probe()
1463 drv_data = (struct flite_drvdata *)of_id->data; in fimc_lite_probe()
1464 fimc->index = of_alias_get_id(dev->of_node, "fimc-lite"); in fimc_lite_probe()
1466 if (!drv_data || fimc->index >= drv_data->num_instances || in fimc_lite_probe()
1467 fimc->index < 0) { in fimc_lite_probe()
1468 dev_err(dev, "Wrong %pOF node alias\n", dev->of_node); in fimc_lite_probe()
1469 return -EINVAL; in fimc_lite_probe()
1472 fimc->dd = drv_data; in fimc_lite_probe()
1473 fimc->pdev = pdev; in fimc_lite_probe()
1475 init_waitqueue_head(&fimc->irq_queue); in fimc_lite_probe()
1476 spin_lock_init(&fimc->slock); in fimc_lite_probe()
1477 mutex_init(&fimc->lock); in fimc_lite_probe()
1479 fimc->regs = devm_platform_ioremap_resource(pdev, 0); in fimc_lite_probe()
1480 if (IS_ERR(fimc->regs)) in fimc_lite_probe()
1481 return PTR_ERR(fimc->regs); in fimc_lite_probe()
1487 ret = fimc_lite_clk_get(fimc); in fimc_lite_probe()
1492 0, dev_name(dev), fimc); in fimc_lite_probe()
1499 ret = fimc_lite_create_capture_subdev(fimc); in fimc_lite_probe()
1503 platform_set_drvdata(pdev, fimc); in fimc_lite_probe()
1507 ret = clk_prepare_enable(fimc->clock); in fimc_lite_probe()
1514 fimc_lite_set_default_config(fimc); in fimc_lite_probe()
1516 dev_dbg(dev, "FIMC-LITE.%d registered successfully\n", in fimc_lite_probe()
1517 fimc->index); in fimc_lite_probe()
1521 fimc_lite_unregister_capture_subdev(fimc); in fimc_lite_probe()
1523 fimc_lite_clk_put(fimc); in fimc_lite_probe()
1530 struct fimc_lite *fimc = dev_get_drvdata(dev); in fimc_lite_runtime_resume() local
1532 clk_prepare_enable(fimc->clock); in fimc_lite_runtime_resume()
1538 struct fimc_lite *fimc = dev_get_drvdata(dev); in fimc_lite_runtime_suspend() local
1540 clk_disable_unprepare(fimc->clock); in fimc_lite_runtime_suspend()
1548 struct fimc_lite *fimc = dev_get_drvdata(dev); in fimc_lite_resume() local
1553 spin_lock_irqsave(&fimc->slock, flags); in fimc_lite_resume()
1554 if (!test_and_clear_bit(ST_LPM, &fimc->state) || in fimc_lite_resume()
1555 !test_bit(ST_FLITE_IN_USE, &fimc->state)) { in fimc_lite_resume()
1556 spin_unlock_irqrestore(&fimc->slock, flags); in fimc_lite_resume()
1559 flite_hw_reset(fimc); in fimc_lite_resume()
1560 spin_unlock_irqrestore(&fimc->slock, flags); in fimc_lite_resume()
1562 if (!test_and_clear_bit(ST_FLITE_SUSPENDED, &fimc->state)) in fimc_lite_resume()
1565 INIT_LIST_HEAD(&fimc->active_buf_q); in fimc_lite_resume()
1566 fimc_pipeline_call(&fimc->ve, open, in fimc_lite_resume()
1567 &fimc->ve.vdev.entity, false); in fimc_lite_resume()
1568 fimc_lite_hw_init(fimc, atomic_read(&fimc->out_path) == FIMC_IO_ISP); in fimc_lite_resume()
1569 clear_bit(ST_FLITE_SUSPENDED, &fimc->state); in fimc_lite_resume()
1571 for (i = 0; i < fimc->reqbufs_count; i++) { in fimc_lite_resume()
1572 if (list_empty(&fimc->pending_buf_q)) in fimc_lite_resume()
1574 buf = fimc_lite_pending_queue_pop(fimc); in fimc_lite_resume()
1575 buffer_queue(&buf->vb.vb2_buf); in fimc_lite_resume()
1582 struct fimc_lite *fimc = dev_get_drvdata(dev); in fimc_lite_suspend() local
1583 bool suspend = test_bit(ST_FLITE_IN_USE, &fimc->state); in fimc_lite_suspend()
1586 if (test_and_set_bit(ST_LPM, &fimc->state)) in fimc_lite_suspend()
1589 ret = fimc_lite_stop_capture(fimc, suspend); in fimc_lite_suspend()
1590 if (ret < 0 || !fimc_lite_active(fimc)) in fimc_lite_suspend()
1593 return fimc_pipeline_call(&fimc->ve, close); in fimc_lite_suspend()
1599 struct fimc_lite *fimc = platform_get_drvdata(pdev); in fimc_lite_remove() local
1600 struct device *dev = &pdev->dev; in fimc_lite_remove()
1603 clk_disable_unprepare(fimc->clock); in fimc_lite_remove()
1607 fimc_lite_unregister_capture_subdev(fimc); in fimc_lite_remove()
1609 fimc_lite_clk_put(fimc); in fimc_lite_remove()
1644 .compatible = "samsung,exynos4212-fimc-lite",
1648 .compatible = "samsung,exynos5250-fimc-lite",
1665 MODULE_DESCRIPTION("Samsung EXYNOS FIMC-LITE (camera host interface) driver");