Lines Matching refs:fimc

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()
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()
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_get_sync(&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()
502 clear_bit(ST_FLITE_IN_USE, &fimc->state); in fimc_lite_open()
504 mutex_unlock(&fimc->lock); in fimc_lite_open()
510 struct fimc_lite *fimc = video_drvdata(file); in fimc_lite_release() local
511 struct media_entity *entity = &fimc->ve.vdev.entity; in fimc_lite_release()
513 mutex_lock(&fimc->lock); in fimc_lite_release()
516 atomic_read(&fimc->out_path) == FIMC_IO_DMA) { in fimc_lite_release()
517 if (fimc->streaming) { in fimc_lite_release()
519 fimc->streaming = false; in fimc_lite_release()
521 fimc_lite_stop_capture(fimc, false); in fimc_lite_release()
522 fimc_pipeline_call(&fimc->ve, close); in fimc_lite_release()
523 clear_bit(ST_FLITE_IN_USE, &fimc->state); in fimc_lite_release()
531 pm_runtime_put(&fimc->pdev->dev); in fimc_lite_release()
532 clear_bit(ST_FLITE_SUSPENDED, &fimc->state); in fimc_lite_release()
534 mutex_unlock(&fimc->lock); in fimc_lite_release()
551 static const struct fimc_fmt *fimc_lite_subdev_try_fmt(struct fimc_lite *fimc, in fimc_lite_subdev_try_fmt() argument
555 struct flite_drvdata *dd = fimc->dd; in fimc_lite_subdev_try_fmt()
571 struct flite_frame *sink = &fimc->inp_frame; in fimc_lite_subdev_try_fmt()
576 sink_fmt = v4l2_subdev_get_try_format(&fimc->subdev, cfg, in fimc_lite_subdev_try_fmt()
582 rect = v4l2_subdev_get_try_crop(&fimc->subdev, cfg, in fimc_lite_subdev_try_fmt()
597 v4l2_dbg(1, debug, &fimc->subdev, "code: %#x (%d), %dx%d\n", in fimc_lite_subdev_try_fmt()
603 static void fimc_lite_try_crop(struct fimc_lite *fimc, struct v4l2_rect *r) in fimc_lite_try_crop() argument
605 struct flite_frame *frame = &fimc->inp_frame; in fimc_lite_try_crop()
612 r->left = round_down(r->left, fimc->dd->win_hor_offs_align); in fimc_lite_try_crop()
615 v4l2_dbg(1, debug, &fimc->subdev, "(%d,%d)/%dx%d, sink fmt: %dx%d\n", in fimc_lite_try_crop()
620 static void fimc_lite_try_compose(struct fimc_lite *fimc, struct v4l2_rect *r) in fimc_lite_try_compose() argument
622 struct flite_frame *frame = &fimc->out_frame; in fimc_lite_try_compose()
623 struct v4l2_rect *crop_rect = &fimc->inp_frame.rect; in fimc_lite_try_compose()
632 r->left = round_down(r->left, fimc->dd->out_hor_offs_align); in fimc_lite_try_compose()
633 r->top = clamp_t(u32, r->top, 0, fimc->out_frame.f_height - r->height); in fimc_lite_try_compose()
635 v4l2_dbg(1, debug, &fimc->subdev, "(%d,%d)/%dx%d, source fmt: %dx%d\n", in fimc_lite_try_compose()
646 struct fimc_lite *fimc = video_drvdata(file); in fimc_lite_querycap() local
651 dev_name(&fimc->pdev->dev)); in fimc_lite_querycap()
672 struct fimc_lite *fimc = video_drvdata(file); in fimc_lite_g_fmt_mplane() local
675 struct flite_frame *frame = &fimc->out_frame; in fimc_lite_g_fmt_mplane()
690 static int fimc_lite_try_fmt(struct fimc_lite *fimc, in fimc_lite_try_fmt() argument
695 struct flite_drvdata *dd = fimc->dd; in fimc_lite_try_fmt()
696 const struct fimc_fmt *inp_fmt = fimc->inp_frame.fmt; in fimc_lite_try_fmt()
737 struct fimc_lite *fimc = video_drvdata(file); in fimc_lite_try_fmt_mplane() local
738 return fimc_lite_try_fmt(fimc, &f->fmt.pix_mp, NULL); in fimc_lite_try_fmt_mplane()
745 struct fimc_lite *fimc = video_drvdata(file); in fimc_lite_s_fmt_mplane() local
746 struct flite_frame *frame = &fimc->out_frame; in fimc_lite_s_fmt_mplane()
750 if (vb2_is_busy(&fimc->vb_queue)) in fimc_lite_s_fmt_mplane()
753 ret = fimc_lite_try_fmt(fimc, &f->fmt.pix_mp, &fmt); in fimc_lite_s_fmt_mplane()
758 fimc->payload[0] = max((pixm->width * pixm->height * fmt->depth[0]) / 8, in fimc_lite_s_fmt_mplane()
766 static int fimc_pipeline_validate(struct fimc_lite *fimc) in fimc_pipeline_validate() argument
768 struct v4l2_subdev *sd = &fimc->subdev; in fimc_pipeline_validate()
779 if (sd == &fimc->subdev) { in fimc_pipeline_validate()
780 struct flite_frame *ff = &fimc->out_frame; in fimc_pipeline_validate()
783 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
816 struct media_entity *entity = &fimc->ve.vdev.entity; in fimc_lite_streamon()
819 if (fimc_lite_active(fimc)) in fimc_lite_streamon()
822 ret = media_pipeline_start(entity, &fimc->ve.pipe->mp); in fimc_lite_streamon()
826 ret = fimc_pipeline_validate(fimc); in fimc_lite_streamon()
830 fimc->sensor = fimc_find_remote_sensor(&fimc->subdev.entity); in fimc_lite_streamon()
834 fimc->streaming = true; in fimc_lite_streamon()
846 struct fimc_lite *fimc = video_drvdata(file); in fimc_lite_streamoff() local
853 media_pipeline_stop(&fimc->ve.vdev.entity); in fimc_lite_streamoff()
854 fimc->streaming = false; in fimc_lite_streamoff()
861 struct fimc_lite *fimc = video_drvdata(file); in fimc_lite_reqbufs() local
867 fimc->reqbufs_count = reqbufs->count; in fimc_lite_reqbufs()
875 struct fimc_lite *fimc = video_drvdata(file); in fimc_lite_g_selection() local
876 struct flite_frame *f = &fimc->out_frame; in fimc_lite_g_selection()
901 struct fimc_lite *fimc = video_drvdata(file); in fimc_lite_s_selection() local
902 struct flite_frame *f = &fimc->out_frame; in fimc_lite_s_selection()
910 fimc_lite_try_compose(fimc, &rect); in fimc_lite_s_selection()
921 spin_lock_irqsave(&fimc->slock, flags); in fimc_lite_s_selection()
923 set_bit(ST_FLITE_CONFIG, &fimc->state); in fimc_lite_s_selection()
924 spin_unlock_irqrestore(&fimc->slock, flags); in fimc_lite_s_selection()
953 struct fimc_lite *fimc = v4l2_get_subdevdata(sd); in fimc_lite_link_setup() local
956 if (WARN_ON(fimc == NULL)) in fimc_lite_link_setup()
961 flags, fimc->source_subdev_grp_id); in fimc_lite_link_setup()
966 if (fimc->source_subdev_grp_id == 0) in fimc_lite_link_setup()
967 fimc->source_subdev_grp_id = sd->grp_id; in fimc_lite_link_setup()
971 fimc->source_subdev_grp_id = 0; in fimc_lite_link_setup()
972 fimc->sensor = NULL; in fimc_lite_link_setup()
978 atomic_set(&fimc->out_path, FIMC_IO_NONE); in fimc_lite_link_setup()
980 atomic_set(&fimc->out_path, FIMC_IO_DMA); in fimc_lite_link_setup()
985 atomic_set(&fimc->out_path, FIMC_IO_NONE); in fimc_lite_link_setup()
987 atomic_set(&fimc->out_path, FIMC_IO_ISP); in fimc_lite_link_setup()
1030 struct fimc_lite *fimc = v4l2_get_subdevdata(sd); in fimc_lite_subdev_get_fmt() local
1032 struct flite_frame *f = &fimc->inp_frame; in fimc_lite_subdev_get_fmt()
1040 mutex_lock(&fimc->lock); in fimc_lite_subdev_get_fmt()
1053 mutex_unlock(&fimc->lock); in fimc_lite_subdev_get_fmt()
1061 struct fimc_lite *fimc = v4l2_get_subdevdata(sd); in fimc_lite_subdev_set_fmt() local
1063 struct flite_frame *sink = &fimc->inp_frame; in fimc_lite_subdev_set_fmt()
1064 struct flite_frame *source = &fimc->out_frame; in fimc_lite_subdev_set_fmt()
1070 mutex_lock(&fimc->lock); in fimc_lite_subdev_set_fmt()
1072 if ((atomic_read(&fimc->out_path) == FIMC_IO_ISP && in fimc_lite_subdev_set_fmt()
1074 (atomic_read(&fimc->out_path) == FIMC_IO_DMA && in fimc_lite_subdev_set_fmt()
1075 vb2_is_busy(&fimc->vb_queue))) { in fimc_lite_subdev_set_fmt()
1076 mutex_unlock(&fimc->lock); in fimc_lite_subdev_set_fmt()
1080 ffmt = fimc_lite_subdev_try_fmt(fimc, cfg, 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
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()
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()
1480 fimc->regs = devm_ioremap_resource(dev, res); in fimc_lite_probe()
1481 if (IS_ERR(fimc->regs)) in fimc_lite_probe()
1482 return PTR_ERR(fimc->regs); in fimc_lite_probe()
1490 ret = fimc_lite_clk_get(fimc); in fimc_lite_probe()
1495 0, dev_name(dev), fimc); in fimc_lite_probe()
1502 ret = fimc_lite_create_capture_subdev(fimc); in fimc_lite_probe()
1506 platform_set_drvdata(pdev, fimc); in fimc_lite_probe()
1510 ret = clk_prepare_enable(fimc->clock); in fimc_lite_probe()
1517 fimc_lite_set_default_config(fimc); in fimc_lite_probe()
1520 fimc->index); in fimc_lite_probe()
1524 fimc_lite_unregister_capture_subdev(fimc); in fimc_lite_probe()
1526 fimc_lite_clk_put(fimc); in fimc_lite_probe()
1533 struct fimc_lite *fimc = dev_get_drvdata(dev); in fimc_lite_runtime_resume() local
1535 clk_prepare_enable(fimc->clock); in fimc_lite_runtime_resume()
1541 struct fimc_lite *fimc = dev_get_drvdata(dev); in fimc_lite_runtime_suspend() local
1543 clk_disable_unprepare(fimc->clock); in fimc_lite_runtime_suspend()
1551 struct fimc_lite *fimc = dev_get_drvdata(dev); in fimc_lite_resume() local
1556 spin_lock_irqsave(&fimc->slock, flags); in fimc_lite_resume()
1557 if (!test_and_clear_bit(ST_LPM, &fimc->state) || in fimc_lite_resume()
1558 !test_bit(ST_FLITE_IN_USE, &fimc->state)) { in fimc_lite_resume()
1559 spin_unlock_irqrestore(&fimc->slock, flags); in fimc_lite_resume()
1562 flite_hw_reset(fimc); in fimc_lite_resume()
1563 spin_unlock_irqrestore(&fimc->slock, flags); in fimc_lite_resume()
1565 if (!test_and_clear_bit(ST_FLITE_SUSPENDED, &fimc->state)) in fimc_lite_resume()
1568 INIT_LIST_HEAD(&fimc->active_buf_q); in fimc_lite_resume()
1569 fimc_pipeline_call(&fimc->ve, open, in fimc_lite_resume()
1570 &fimc->ve.vdev.entity, false); in fimc_lite_resume()
1571 fimc_lite_hw_init(fimc, atomic_read(&fimc->out_path) == FIMC_IO_ISP); in fimc_lite_resume()
1572 clear_bit(ST_FLITE_SUSPENDED, &fimc->state); in fimc_lite_resume()
1574 for (i = 0; i < fimc->reqbufs_count; i++) { in fimc_lite_resume()
1575 if (list_empty(&fimc->pending_buf_q)) in fimc_lite_resume()
1577 buf = fimc_lite_pending_queue_pop(fimc); in fimc_lite_resume()
1585 struct fimc_lite *fimc = dev_get_drvdata(dev); in fimc_lite_suspend() local
1586 bool suspend = test_bit(ST_FLITE_IN_USE, &fimc->state); in fimc_lite_suspend()
1589 if (test_and_set_bit(ST_LPM, &fimc->state)) in fimc_lite_suspend()
1592 ret = fimc_lite_stop_capture(fimc, suspend); in fimc_lite_suspend()
1593 if (ret < 0 || !fimc_lite_active(fimc)) in fimc_lite_suspend()
1596 return fimc_pipeline_call(&fimc->ve, close); in fimc_lite_suspend()
1602 struct fimc_lite *fimc = platform_get_drvdata(pdev); in fimc_lite_remove() local
1606 clk_disable_unprepare(fimc->clock); in fimc_lite_remove()
1610 fimc_lite_unregister_capture_subdev(fimc); in fimc_lite_remove()
1612 fimc_lite_clk_put(fimc); in fimc_lite_remove()