Lines Matching full:fimc

29 #include "fimc-core.h"
30 #include "fimc-reg.h"
33 static int fimc_capture_hw_init(struct fimc_dev *fimc) in fimc_capture_hw_init() argument
35 struct fimc_source_info *si = &fimc->vid_cap.source_config; in fimc_capture_hw_init()
36 struct fimc_ctx *ctx = fimc->vid_cap.ctx; in fimc_capture_hw_init()
44 ret = fimc_hw_camblk_cfg_writeback(fimc); in fimc_capture_hw_init()
49 spin_lock_irqsave(&fimc->slock, flags); in fimc_capture_hw_init()
53 fimc_hw_set_camera_polarity(fimc, si); in fimc_capture_hw_init()
54 fimc_hw_set_camera_type(fimc, si); in fimc_capture_hw_init()
55 fimc_hw_set_camera_source(fimc, si); in fimc_capture_hw_init()
56 fimc_hw_set_camera_offset(fimc, &ctx->s_frame); in fimc_capture_hw_init()
68 if (fimc->drv_data->alpha_color) in fimc_capture_hw_init()
70 clear_bit(ST_CAPT_APPLY_CFG, &fimc->state); in fimc_capture_hw_init()
72 spin_unlock_irqrestore(&fimc->slock, flags); in fimc_capture_hw_init()
78 * Set fimc->state to indicate stream off and the hardware shut down state.
81 * can be re-spun when the device is being resumed. Also perform FIMC
84 static int fimc_capture_state_cleanup(struct fimc_dev *fimc, bool suspend) in fimc_capture_state_cleanup() argument
86 struct fimc_vid_cap *cap = &fimc->vid_cap; in fimc_capture_state_cleanup()
91 spin_lock_irqsave(&fimc->slock, flags); in fimc_capture_state_cleanup()
92 streaming = fimc->state & (1 << ST_CAPT_ISP_STREAM); in fimc_capture_state_cleanup()
94 fimc->state &= ~(1 << ST_CAPT_RUN | 1 << ST_CAPT_SHUT | in fimc_capture_state_cleanup()
97 fimc->state |= (1 << ST_CAPT_SUSPENDED); in fimc_capture_state_cleanup()
99 fimc->state &= ~(1 << ST_CAPT_PEND | 1 << ST_CAPT_SUSPENDED); in fimc_capture_state_cleanup()
115 fimc_hw_reset(fimc); in fimc_capture_state_cleanup()
118 spin_unlock_irqrestore(&fimc->slock, flags); in fimc_capture_state_cleanup()
126 static int fimc_stop_capture(struct fimc_dev *fimc, bool suspend) in fimc_stop_capture() argument
130 if (!fimc_capture_active(fimc)) in fimc_stop_capture()
133 spin_lock_irqsave(&fimc->slock, flags); in fimc_stop_capture()
134 set_bit(ST_CAPT_SHUT, &fimc->state); in fimc_stop_capture()
135 fimc_deactivate_capture(fimc); in fimc_stop_capture()
136 spin_unlock_irqrestore(&fimc->slock, flags); in fimc_stop_capture()
138 wait_event_timeout(fimc->irq_queue, in fimc_stop_capture()
139 !test_bit(ST_CAPT_SHUT, &fimc->state), in fimc_stop_capture()
142 return fimc_capture_state_cleanup(fimc, suspend); in fimc_stop_capture()
147 * @ctx: FIMC capture context
149 * To be called from within the interrupt handler with fimc.slock
155 struct fimc_dev *fimc = ctx->fimc_dev; in fimc_capture_config_update() local
158 fimc_hw_set_camera_offset(fimc, &ctx->s_frame); in fimc_capture_config_update()
171 if (fimc->drv_data->alpha_color) in fimc_capture_config_update()
174 clear_bit(ST_CAPT_APPLY_CFG, &fimc->state); in fimc_capture_config_update()
178 void fimc_capture_irq_handler(struct fimc_dev *fimc, int deq_buf) in fimc_capture_irq_handler() argument
180 struct fimc_vid_cap *cap = &fimc->vid_cap; in fimc_capture_irq_handler()
186 if (test_and_clear_bit(ST_CAPT_SHUT, &fimc->state)) { in fimc_capture_irq_handler()
187 wake_up(&fimc->irq_queue); in fimc_capture_irq_handler()
192 test_bit(ST_CAPT_RUN, &fimc->state) && deq_buf) { in fimc_capture_irq_handler()
204 fimc_hw_set_output_addr(fimc, &v_buf->addr, cap->buf_index); in fimc_capture_irq_handler()
211 fimc_hw_get_frame_index(fimc), v_buf->index); in fimc_capture_irq_handler()
223 s32 index = fimc_hw_get_frame_index(fimc); in fimc_capture_irq_handler()
238 clear_bit(ST_CAPT_RUN, &fimc->state); in fimc_capture_irq_handler()
243 set_bit(ST_CAPT_RUN, &fimc->state); in fimc_capture_irq_handler()
246 if (test_bit(ST_CAPT_APPLY_CFG, &fimc->state)) in fimc_capture_irq_handler()
250 fimc_deactivate_capture(fimc); in fimc_capture_irq_handler()
251 clear_bit(ST_CAPT_STREAM, &fimc->state); in fimc_capture_irq_handler()
255 fimc_hw_get_frame_index(fimc), cap->active_buf_cnt); in fimc_capture_irq_handler()
262 struct fimc_dev *fimc = ctx->fimc_dev; in start_streaming() local
263 struct fimc_vid_cap *vid_cap = &fimc->vid_cap; in start_streaming()
269 ret = fimc_capture_hw_init(fimc); in start_streaming()
271 fimc_capture_state_cleanup(fimc, false); in start_streaming()
275 set_bit(ST_CAPT_PEND, &fimc->state); in start_streaming()
277 min_bufs = fimc->vid_cap.reqbufs_count > 1 ? 2 : 1; in start_streaming()
280 !test_and_set_bit(ST_CAPT_STREAM, &fimc->state)) { in start_streaming()
283 if (!test_and_set_bit(ST_CAPT_ISP_STREAM, &fimc->state)) in start_streaming()
293 struct fimc_dev *fimc = ctx->fimc_dev; in stop_streaming() local
295 if (!fimc_capture_active(fimc)) in stop_streaming()
298 fimc_stop_capture(fimc, false); in stop_streaming()
301 int fimc_capture_suspend(struct fimc_dev *fimc) in fimc_capture_suspend() argument
303 bool suspend = fimc_capture_busy(fimc); in fimc_capture_suspend()
305 int ret = fimc_stop_capture(fimc, suspend); in fimc_capture_suspend()
308 return fimc_pipeline_call(&fimc->vid_cap.ve, close); in fimc_capture_suspend()
313 int fimc_capture_resume(struct fimc_dev *fimc) in fimc_capture_resume() argument
315 struct fimc_vid_cap *vid_cap = &fimc->vid_cap; in fimc_capture_resume()
320 if (!test_and_clear_bit(ST_CAPT_SUSPENDED, &fimc->state)) in fimc_capture_resume()
323 INIT_LIST_HEAD(&fimc->vid_cap.active_buf_q); in fimc_capture_resume()
326 fimc_capture_hw_init(fimc); in fimc_capture_resume()
328 clear_bit(ST_CAPT_SUSPENDED, &fimc->state); in fimc_capture_resume()
406 struct fimc_dev *fimc = ctx->fimc_dev; in buffer_queue() local
407 struct fimc_vid_cap *vid_cap = &fimc->vid_cap; in buffer_queue()
412 spin_lock_irqsave(&fimc->slock, flags); in buffer_queue()
415 if (!test_bit(ST_CAPT_SUSPENDED, &fimc->state) && in buffer_queue()
416 !test_bit(ST_CAPT_STREAM, &fimc->state) && in buffer_queue()
422 fimc_hw_set_output_addr(fimc, &buf->addr, buf_id); in buffer_queue()
437 !test_and_set_bit(ST_CAPT_STREAM, &fimc->state)) { in buffer_queue()
441 spin_unlock_irqrestore(&fimc->slock, flags); in buffer_queue()
443 if (test_and_set_bit(ST_CAPT_ISP_STREAM, &fimc->state)) in buffer_queue()
451 spin_unlock_irqrestore(&fimc->slock, flags); in buffer_queue()
464 static int fimc_capture_set_default_format(struct fimc_dev *fimc);
468 struct fimc_dev *fimc = video_drvdata(file); in fimc_capture_open() local
469 struct fimc_vid_cap *vc = &fimc->vid_cap; in fimc_capture_open()
473 dbg("pid: %d, state: 0x%lx", task_pid_nr(current), fimc->state); in fimc_capture_open()
475 mutex_lock(&fimc->lock); in fimc_capture_open()
477 if (fimc_m2m_active(fimc)) in fimc_capture_open()
480 set_bit(ST_CAPT_BUSY, &fimc->state); in fimc_capture_open()
481 ret = pm_runtime_resume_and_get(&fimc->pdev->dev); in fimc_capture_open()
487 pm_runtime_put_sync(&fimc->pdev->dev); in fimc_capture_open()
502 ret = fimc_capture_set_default_format(fimc); in fimc_capture_open()
505 clear_bit(ST_CAPT_BUSY, &fimc->state); in fimc_capture_open()
506 pm_runtime_put_sync(&fimc->pdev->dev); in fimc_capture_open()
511 mutex_unlock(&fimc->lock); in fimc_capture_open()
517 struct fimc_dev *fimc = video_drvdata(file); in fimc_capture_release() local
518 struct fimc_vid_cap *vc = &fimc->vid_cap; in fimc_capture_release()
522 dbg("pid: %d, state: 0x%lx", task_pid_nr(current), fimc->state); in fimc_capture_release()
524 mutex_lock(&fimc->lock); in fimc_capture_release()
534 clear_bit(ST_CAPT_BUSY, &fimc->state); in fimc_capture_release()
536 clear_bit(ST_CAPT_SUSPENDED, &fimc->state); in fimc_capture_release()
543 pm_runtime_put_sync(&fimc->pdev->dev); in fimc_capture_release()
544 mutex_unlock(&fimc->lock); in fimc_capture_release()
567 struct fimc_dev *fimc = ctx->fimc_dev; in fimc_capture_try_format() local
568 const struct fimc_variant *var = fimc->variant; in fimc_capture_try_format()
644 struct fimc_dev *fimc = ctx->fimc_dev; in fimc_capture_try_selection() local
645 const struct fimc_variant *var = fimc->variant; in fimc_capture_try_selection()
716 struct fimc_dev *fimc = video_drvdata(file); in fimc_cap_querycap() local
718 __fimc_vidioc_querycap(&fimc->pdev->dev, cap); in fimc_cap_querycap()
753 * @ctx: FIMC capture context
755 * @fmt_id: fimc pixel format id corresponding to returned @tfmt (output)
763 struct fimc_dev *fimc = ctx->fimc_dev; in fimc_pipeline_try_format() local
764 struct fimc_pipeline *p = to_fimc_pipeline(fimc->vid_cap.ve.pipe); in fimc_pipeline_try_format()
797 while (me != &fimc->vid_cap.subdev.entity) { in fimc_pipeline_try_format()
893 struct fimc_dev *fimc = video_drvdata(file); in fimc_cap_g_fmt_mplane() local
895 __fimc_get_format(&fimc->vid_cap.ctx->d_frame, f); in fimc_cap_g_fmt_mplane()
900 * Try or set format on the fimc.X.capture video node and additionally
904 static int __video_try_or_set_format(struct fimc_dev *fimc, in __video_try_or_set_format() argument
910 struct fimc_vid_cap *vc = &fimc->vid_cap; in __video_try_or_set_format()
948 mf = try ? &mbus_fmt : &fimc->vid_cap.ci_fmt; in __video_try_or_set_format()
988 struct fimc_dev *fimc = video_drvdata(file); in fimc_cap_try_fmt_mplane() local
991 return __video_try_or_set_format(fimc, f, true, &inp_fmt, &out_fmt); in fimc_cap_try_fmt_mplane()
1008 static int __fimc_capture_set_format(struct fimc_dev *fimc, in __fimc_capture_set_format() argument
1011 struct fimc_vid_cap *vc = &fimc->vid_cap; in __fimc_capture_set_format()
1018 if (vb2_is_busy(&fimc->vid_cap.vbq)) in __fimc_capture_set_format()
1021 ret = __video_try_or_set_format(fimc, f, false, &inp_fmt, &ff->fmt); in __fimc_capture_set_format()
1053 struct fimc_dev *fimc = video_drvdata(file); in fimc_cap_s_fmt_mplane() local
1055 return __fimc_capture_set_format(fimc, f); in fimc_cap_s_fmt_mplane()
1061 struct fimc_dev *fimc = video_drvdata(file); in fimc_cap_enum_input() local
1062 struct exynos_video_entity *ve = &fimc->vid_cap.ve; in fimc_cap_enum_input()
1093 * @fimc: the FIMC device this context applies to
1097 static int fimc_pipeline_validate(struct fimc_dev *fimc) in fimc_pipeline_validate() argument
1105 struct fimc_vid_cap *vc = &fimc->vid_cap; in fimc_pipeline_validate()
1133 /* Don't call FIMC subdev operation to avoid nested locking */ in fimc_pipeline_validate()
1181 struct fimc_dev *fimc = video_drvdata(file); in fimc_cap_streamon() local
1182 struct fimc_vid_cap *vc = &fimc->vid_cap; in fimc_cap_streamon()
1187 if (fimc_capture_active(fimc)) in fimc_cap_streamon()
1204 * sensor or other data source, e.g. FIMC-IS. in fimc_cap_streamon()
1212 ret = fimc_pipeline_validate(fimc); in fimc_cap_streamon()
1231 struct fimc_dev *fimc = video_drvdata(file); in fimc_cap_streamoff() local
1232 struct fimc_vid_cap *vc = &fimc->vid_cap; in fimc_cap_streamoff()
1250 struct fimc_dev *fimc = video_drvdata(file); in fimc_cap_reqbufs() local
1256 fimc->vid_cap.reqbufs_count = reqbufs->count; in fimc_cap_reqbufs()
1264 struct fimc_dev *fimc = video_drvdata(file); in fimc_cap_g_selection() local
1265 struct fimc_ctx *ctx = fimc->vid_cap.ctx; in fimc_cap_g_selection()
1301 struct fimc_dev *fimc = video_drvdata(file); in fimc_cap_s_selection() local
1302 struct fimc_ctx *ctx = fimc->vid_cap.ctx; in fimc_cap_s_selection()
1328 spin_lock_irqsave(&fimc->slock, flags); in fimc_cap_s_selection()
1331 spin_unlock_irqrestore(&fimc->slock, flags); in fimc_cap_s_selection()
1333 set_bit(ST_CAPT_APPLY_CFG, &fimc->state); in fimc_cap_s_selection()
1370 struct fimc_dev *fimc = v4l2_get_subdevdata(sd); in fimc_link_setup() local
1371 struct fimc_vid_cap *vc = &fimc->vid_cap; in fimc_link_setup()
1377 if (WARN_ON(fimc == NULL)) in fimc_link_setup()
1382 fimc->vid_cap.input); in fimc_link_setup()
1385 fimc->vid_cap.input = 0; in fimc_link_setup()
1418 * beginning of a frame transmission, FIMC does not issue the LastIrq
1429 struct fimc_dev *fimc; in fimc_sensor_notify() local
1440 fimc = si ? source_to_sensor_info(si)->host : NULL; in fimc_sensor_notify()
1442 if (fimc && arg && notification == S5P_FIMC_TX_END_NOTIFY && in fimc_sensor_notify()
1443 test_bit(ST_CAPT_PEND, &fimc->state)) { in fimc_sensor_notify()
1445 spin_lock_irqsave(&fimc->slock, irq_flags); in fimc_sensor_notify()
1446 if (!list_empty(&fimc->vid_cap.active_buf_q)) { in fimc_sensor_notify()
1447 buf = list_entry(fimc->vid_cap.active_buf_q.next, in fimc_sensor_notify()
1452 fimc_capture_irq_handler(fimc, 1); in fimc_sensor_notify()
1453 fimc_deactivate_capture(fimc); in fimc_sensor_notify()
1454 spin_unlock_irqrestore(&fimc->slock, irq_flags); in fimc_sensor_notify()
1476 struct fimc_dev *fimc = v4l2_get_subdevdata(sd); in fimc_subdev_get_fmt() local
1477 struct fimc_ctx *ctx = fimc->vid_cap.ctx; in fimc_subdev_get_fmt()
1488 mutex_lock(&fimc->lock); in fimc_subdev_get_fmt()
1499 *mf = fimc->vid_cap.wb_fmt; in fimc_subdev_get_fmt()
1503 *mf = fimc->vid_cap.ci_fmt; in fimc_subdev_get_fmt()
1507 mutex_unlock(&fimc->lock); in fimc_subdev_get_fmt()
1517 struct fimc_dev *fimc = v4l2_get_subdevdata(sd); in fimc_subdev_set_fmt() local
1519 struct fimc_vid_cap *vc = &fimc->vid_cap; in fimc_subdev_set_fmt()
1530 mutex_lock(&fimc->lock); in fimc_subdev_set_fmt()
1533 mutex_unlock(&fimc->lock); in fimc_subdev_set_fmt()
1558 mutex_lock(&fimc->lock); in fimc_subdev_set_fmt()
1575 mutex_unlock(&fimc->lock); in fimc_subdev_set_fmt()
1583 struct fimc_dev *fimc = v4l2_get_subdevdata(sd); in fimc_subdev_get_selection() local
1584 struct fimc_ctx *ctx = fimc->vid_cap.ctx; in fimc_subdev_get_selection()
1592 mutex_lock(&fimc->lock); in fimc_subdev_get_selection()
1603 mutex_unlock(&fimc->lock); in fimc_subdev_get_selection()
1614 mutex_unlock(&fimc->lock); in fimc_subdev_get_selection()
1631 mutex_unlock(&fimc->lock); in fimc_subdev_get_selection()
1639 struct fimc_dev *fimc = v4l2_get_subdevdata(sd); in fimc_subdev_set_selection() local
1640 struct fimc_ctx *ctx = fimc->vid_cap.ctx; in fimc_subdev_set_selection()
1649 mutex_lock(&fimc->lock); in fimc_subdev_set_selection()
1661 mutex_unlock(&fimc->lock); in fimc_subdev_set_selection()
1668 spin_lock_irqsave(&fimc->slock, flags); in fimc_subdev_set_selection()
1670 set_bit(ST_CAPT_APPLY_CFG, &fimc->state); in fimc_subdev_set_selection()
1673 spin_unlock_irqrestore(&fimc->slock, flags); in fimc_subdev_set_selection()
1679 mutex_unlock(&fimc->lock); in fimc_subdev_set_selection()
1696 static int fimc_capture_set_default_format(struct fimc_dev *fimc) in fimc_capture_set_default_format() argument
1709 return __fimc_capture_set_format(fimc, &fmt); in fimc_capture_set_default_format()
1712 /* fimc->lock must be already initialized */
1713 static int fimc_register_capture_device(struct fimc_dev *fimc, in fimc_register_capture_device() argument
1716 struct video_device *vfd = &fimc->vid_cap.ve.vdev; in fimc_register_capture_device()
1717 struct vb2_queue *q = &fimc->vid_cap.vbq; in fimc_register_capture_device()
1727 ctx->fimc_dev = fimc; in fimc_register_capture_device()
1735 snprintf(vfd->name, sizeof(vfd->name), "fimc.%d.capture", fimc->id); in fimc_register_capture_device()
1743 vfd->lock = &fimc->lock; in fimc_register_capture_device()
1746 video_set_drvdata(vfd, fimc); in fimc_register_capture_device()
1747 vid_cap = &fimc->vid_cap; in fimc_register_capture_device()
1763 q->lock = &fimc->lock; in fimc_register_capture_device()
1764 q->dev = &fimc->pdev->dev; in fimc_register_capture_device()
1815 struct fimc_dev *fimc = v4l2_get_subdevdata(sd); in fimc_capture_subdev_registered() local
1818 if (fimc == NULL) in fimc_capture_subdev_registered()
1821 ret = fimc_register_m2m_device(fimc, sd->v4l2_dev); in fimc_capture_subdev_registered()
1825 fimc->vid_cap.ve.pipe = v4l2_get_subdev_hostdata(sd); in fimc_capture_subdev_registered()
1827 ret = fimc_register_capture_device(fimc, sd->v4l2_dev); in fimc_capture_subdev_registered()
1829 fimc_unregister_m2m_device(fimc); in fimc_capture_subdev_registered()
1830 fimc->vid_cap.ve.pipe = NULL; in fimc_capture_subdev_registered()
1838 struct fimc_dev *fimc = v4l2_get_subdevdata(sd); in fimc_capture_subdev_unregistered() local
1841 if (fimc == NULL) in fimc_capture_subdev_unregistered()
1844 mutex_lock(&fimc->lock); in fimc_capture_subdev_unregistered()
1846 fimc_unregister_m2m_device(fimc); in fimc_capture_subdev_unregistered()
1847 vdev = &fimc->vid_cap.ve.vdev; in fimc_capture_subdev_unregistered()
1852 fimc_ctrls_delete(fimc->vid_cap.ctx); in fimc_capture_subdev_unregistered()
1853 fimc->vid_cap.ve.pipe = NULL; in fimc_capture_subdev_unregistered()
1855 kfree(fimc->vid_cap.ctx); in fimc_capture_subdev_unregistered()
1856 fimc->vid_cap.ctx = NULL; in fimc_capture_subdev_unregistered()
1858 mutex_unlock(&fimc->lock); in fimc_capture_subdev_unregistered()
1866 int fimc_initialize_capture_subdev(struct fimc_dev *fimc) in fimc_initialize_capture_subdev() argument
1868 struct v4l2_subdev *sd = &fimc->vid_cap.subdev; in fimc_initialize_capture_subdev()
1873 snprintf(sd->name, sizeof(sd->name), "FIMC.%d", fimc->id); in fimc_initialize_capture_subdev()
1875 fimc->vid_cap.sd_pads[FIMC_SD_PAD_SINK_CAM].flags = MEDIA_PAD_FL_SINK; in fimc_initialize_capture_subdev()
1876 fimc->vid_cap.sd_pads[FIMC_SD_PAD_SINK_FIFO].flags = MEDIA_PAD_FL_SINK; in fimc_initialize_capture_subdev()
1877 fimc->vid_cap.sd_pads[FIMC_SD_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE; in fimc_initialize_capture_subdev()
1879 fimc->vid_cap.sd_pads); in fimc_initialize_capture_subdev()
1886 v4l2_set_subdevdata(sd, fimc); in fimc_initialize_capture_subdev()
1890 void fimc_unregister_capture_subdev(struct fimc_dev *fimc) in fimc_unregister_capture_subdev() argument
1892 struct v4l2_subdev *sd = &fimc->vid_cap.subdev; in fimc_unregister_capture_subdev()