Lines Matching full:fimc
3 * Samsung EXYNOS FIMC-LITE (camera host interface) driver
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
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()
141 if (fimc->inp_frame.fmt == NULL || fimc->out_frame.fmt == NULL) in fimc_lite_hw_init()
145 si = v4l2_get_subdev_hostdata(fimc->sensor); 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()
168 * Set fimc->state to indicate stream off and the hardware shut down state.
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()
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()
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()
287 vbuf->vb.sequence = fimc->frame_count++; in flite_irq_handler()
288 flite_hw_mask_dma_buffer(fimc, vbuf->index); 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()
382 struct fimc_lite *fimc = vq->drv_priv; in buffer_prepare() local
385 if (fimc->out_frame.fmt == NULL) 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()
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()
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()
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()
486 ret = fimc_pipeline_call(&fimc->ve, open, me, true); 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()
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()
572 struct flite_frame *sink = &fimc->inp_frame; 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()
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()
613 r->left = round_down(r->left, fimc->dd->win_hor_offs_align); 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()
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()
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()
669 struct fimc_lite *fimc = video_drvdata(file); in fimc_lite_g_fmt_mplane() local
672 struct flite_frame *frame = &fimc->out_frame; in fimc_lite_g_fmt_mplane()
687 static int fimc_lite_try_fmt(struct fimc_lite *fimc, in fimc_lite_try_fmt() argument
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()
700 * raw Bayer the FIMC-LITE's output format must match its camera 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()
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()
750 ret = fimc_lite_try_fmt(fimc, &f->fmt.pix_mp, &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()
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()
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()
785 sink_fmt.format.code = fimc->inp_frame.fmt->mbus_code; 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()
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
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()
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()
909 fimc_lite_try_compose(fimc, &rect); in fimc_lite_s_selection()
920 spin_lock_irqsave(&fimc->slock, flags); 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()
960 flags, fimc->source_subdev_grp_id); 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()
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()
1029 struct fimc_lite *fimc = v4l2_get_subdevdata(sd); in fimc_lite_subdev_get_fmt() local
1031 struct flite_frame *f = &fimc->inp_frame; in fimc_lite_subdev_get_fmt()
1039 mutex_lock(&fimc->lock); 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
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()
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()
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()
1079 ffmt = fimc_lite_subdev_try_fmt(fimc, sd_state, fmt); in fimc_lite_subdev_set_fmt()
1094 mutex_unlock(&fimc->lock); 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()
1134 mutex_lock(&fimc->lock); in fimc_lite_subdev_get_selection()
1143 mutex_unlock(&fimc->lock); 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()
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()
1170 spin_lock_irqsave(&fimc->slock, flags); 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()
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()
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()
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()
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()
1271 q->drv_priv = fimc; 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()
1291 fimc->ve.pipe = NULL; 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()
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()
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()
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()
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()
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()
1450 struct fimc_lite *fimc; in fimc_lite_probe() local
1457 fimc = devm_kzalloc(dev, sizeof(*fimc), GFP_KERNEL); in fimc_lite_probe()
1458 if (!fimc) 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()
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()
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
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");