Lines Matching refs:dcmi
199 static int dcmi_start_capture(struct stm32_dcmi *dcmi, struct dcmi_buf *buf);
201 static void dcmi_buffer_done(struct stm32_dcmi *dcmi, in dcmi_buffer_done() argument
215 vbuf->sequence = dcmi->sequence++; in dcmi_buffer_done()
221 dev_dbg(dcmi->dev, "buffer[%d] done seq=%d, bytesused=%zu\n", in dcmi_buffer_done()
224 dcmi->buffers_count++; in dcmi_buffer_done()
225 dcmi->active = NULL; in dcmi_buffer_done()
228 static int dcmi_restart_capture(struct stm32_dcmi *dcmi) in dcmi_restart_capture() argument
232 spin_lock_irq(&dcmi->irqlock); in dcmi_restart_capture()
234 if (dcmi->state != RUNNING) { in dcmi_restart_capture()
235 spin_unlock_irq(&dcmi->irqlock); in dcmi_restart_capture()
240 if (list_empty(&dcmi->buffers)) { in dcmi_restart_capture()
241 dev_dbg(dcmi->dev, "Capture restart is deferred to next buffer queueing\n"); in dcmi_restart_capture()
242 dcmi->state = WAIT_FOR_BUFFER; in dcmi_restart_capture()
243 spin_unlock_irq(&dcmi->irqlock); in dcmi_restart_capture()
246 buf = list_entry(dcmi->buffers.next, struct dcmi_buf, list); in dcmi_restart_capture()
247 dcmi->active = buf; in dcmi_restart_capture()
249 spin_unlock_irq(&dcmi->irqlock); in dcmi_restart_capture()
251 return dcmi_start_capture(dcmi, buf); in dcmi_restart_capture()
256 struct stm32_dcmi *dcmi = (struct stm32_dcmi *)param; in dcmi_dma_callback() local
259 struct dcmi_buf *buf = dcmi->active; in dcmi_dma_callback()
261 spin_lock_irq(&dcmi->irqlock); in dcmi_dma_callback()
264 status = dmaengine_tx_status(dcmi->dma_chan, dcmi->dma_cookie, &state); in dcmi_dma_callback()
268 dev_dbg(dcmi->dev, "%s: Received DMA_IN_PROGRESS\n", __func__); in dcmi_dma_callback()
271 dev_err(dcmi->dev, "%s: Received DMA_PAUSED\n", __func__); in dcmi_dma_callback()
274 dev_err(dcmi->dev, "%s: Received DMA_ERROR\n", __func__); in dcmi_dma_callback()
277 dcmi_buffer_done(dcmi, buf, 0, -EIO); in dcmi_dma_callback()
280 dev_dbg(dcmi->dev, "%s: Received DMA_COMPLETE\n", __func__); in dcmi_dma_callback()
283 dcmi_buffer_done(dcmi, buf, buf->size, 0); in dcmi_dma_callback()
285 spin_unlock_irq(&dcmi->irqlock); in dcmi_dma_callback()
288 if (dcmi_restart_capture(dcmi)) in dcmi_dma_callback()
289 dev_err(dcmi->dev, "%s: Cannot restart capture on DMA complete\n", in dcmi_dma_callback()
293 dev_err(dcmi->dev, "%s: Received unknown status\n", __func__); in dcmi_dma_callback()
297 spin_unlock_irq(&dcmi->irqlock); in dcmi_dma_callback()
300 static int dcmi_start_dma(struct stm32_dcmi *dcmi, in dcmi_start_dma() argument
309 config.src_addr = (dma_addr_t)dcmi->res->start + DCMI_DR; in dcmi_start_dma()
315 ret = dmaengine_slave_config(dcmi->dma_chan, &config); in dcmi_start_dma()
317 dev_err(dcmi->dev, "%s: DMA channel config failed (%d)\n", in dcmi_start_dma()
327 mutex_lock(&dcmi->dma_lock); in dcmi_start_dma()
330 desc = dmaengine_prep_slave_sg(dcmi->dma_chan, buf->sgt.sgl, buf->sgt.nents, in dcmi_start_dma()
334 dev_err(dcmi->dev, "%s: DMA dmaengine_prep_slave_sg failed\n", __func__); in dcmi_start_dma()
335 mutex_unlock(&dcmi->dma_lock); in dcmi_start_dma()
341 desc->callback_param = dcmi; in dcmi_start_dma()
344 dcmi->dma_cookie = dmaengine_submit(desc); in dcmi_start_dma()
345 if (dma_submit_error(dcmi->dma_cookie)) { in dcmi_start_dma()
346 dev_err(dcmi->dev, "%s: DMA submission failed\n", __func__); in dcmi_start_dma()
347 mutex_unlock(&dcmi->dma_lock); in dcmi_start_dma()
351 mutex_unlock(&dcmi->dma_lock); in dcmi_start_dma()
353 dma_async_issue_pending(dcmi->dma_chan); in dcmi_start_dma()
358 static int dcmi_start_capture(struct stm32_dcmi *dcmi, struct dcmi_buf *buf) in dcmi_start_capture() argument
365 ret = dcmi_start_dma(dcmi, buf); in dcmi_start_capture()
367 dcmi->errors_count++; in dcmi_start_capture()
372 reg_set(dcmi->regs, DCMI_CR, CR_CAPTURE); in dcmi_start_capture()
377 static void dcmi_set_crop(struct stm32_dcmi *dcmi) in dcmi_set_crop() argument
382 size = ((dcmi->crop.height - 1) << 16) | in dcmi_set_crop()
383 ((dcmi->crop.width << 1) - 1); in dcmi_set_crop()
384 reg_write(dcmi->regs, DCMI_CWSIZE, size); in dcmi_set_crop()
387 start = ((dcmi->crop.top) << 16) | in dcmi_set_crop()
388 ((dcmi->crop.left << 1)); in dcmi_set_crop()
389 reg_write(dcmi->regs, DCMI_CWSTRT, start); in dcmi_set_crop()
391 dev_dbg(dcmi->dev, "Cropping to %ux%u@%u:%u\n", in dcmi_set_crop()
392 dcmi->crop.width, dcmi->crop.height, in dcmi_set_crop()
393 dcmi->crop.left, dcmi->crop.top); in dcmi_set_crop()
396 reg_set(dcmi->regs, DCMI_CR, CR_CROP); in dcmi_set_crop()
399 static void dcmi_process_jpeg(struct stm32_dcmi *dcmi) in dcmi_process_jpeg() argument
403 struct dcmi_buf *buf = dcmi->active; in dcmi_process_jpeg()
419 dmaengine_synchronize(dcmi->dma_chan); in dcmi_process_jpeg()
422 status = dmaengine_tx_status(dcmi->dma_chan, dcmi->dma_cookie, &state); in dcmi_process_jpeg()
425 dcmi_buffer_done(dcmi, buf, buf->size - state.residue, 0); in dcmi_process_jpeg()
427 dcmi->errors_count++; in dcmi_process_jpeg()
428 dev_err(dcmi->dev, "%s: Cannot get JPEG size from DMA\n", in dcmi_process_jpeg()
431 dcmi_buffer_done(dcmi, buf, 0, -EIO); in dcmi_process_jpeg()
435 dmaengine_terminate_sync(dcmi->dma_chan); in dcmi_process_jpeg()
438 if (dcmi_restart_capture(dcmi)) in dcmi_process_jpeg()
439 dev_err(dcmi->dev, "%s: Cannot restart capture on JPEG received\n", in dcmi_process_jpeg()
445 struct stm32_dcmi *dcmi = arg; in dcmi_irq_thread() local
447 spin_lock_irq(&dcmi->irqlock); in dcmi_irq_thread()
449 if (dcmi->misr & IT_OVR) { in dcmi_irq_thread()
450 dcmi->overrun_count++; in dcmi_irq_thread()
451 if (dcmi->overrun_count > OVERRUN_ERROR_THRESHOLD) in dcmi_irq_thread()
452 dcmi->errors_count++; in dcmi_irq_thread()
454 if (dcmi->misr & IT_ERR) in dcmi_irq_thread()
455 dcmi->errors_count++; in dcmi_irq_thread()
457 if (dcmi->sd_format->fourcc == V4L2_PIX_FMT_JPEG && in dcmi_irq_thread()
458 dcmi->misr & IT_FRAME) { in dcmi_irq_thread()
460 spin_unlock_irq(&dcmi->irqlock); in dcmi_irq_thread()
461 dcmi_process_jpeg(dcmi); in dcmi_irq_thread()
465 spin_unlock_irq(&dcmi->irqlock); in dcmi_irq_thread()
471 struct stm32_dcmi *dcmi = arg; in dcmi_irq_callback() local
474 spin_lock_irqsave(&dcmi->irqlock, flags); in dcmi_irq_callback()
476 dcmi->misr = reg_read(dcmi->regs, DCMI_MIS); in dcmi_irq_callback()
479 reg_set(dcmi->regs, DCMI_ICR, IT_FRAME | IT_OVR | IT_ERR); in dcmi_irq_callback()
481 spin_unlock_irqrestore(&dcmi->irqlock, flags); in dcmi_irq_callback()
492 struct stm32_dcmi *dcmi = vb2_get_drv_priv(vq); in dcmi_queue_setup() local
495 size = dcmi->fmt.fmt.pix.sizeimage; in dcmi_queue_setup()
504 dev_dbg(dcmi->dev, "Setup queue, count=%d, size=%d\n", in dcmi_queue_setup()
522 struct stm32_dcmi *dcmi = vb2_get_drv_priv(vb->vb2_queue); in dcmi_buf_prepare() local
531 size = dcmi->fmt.fmt.pix.sizeimage; in dcmi_buf_prepare()
534 dev_err(dcmi->dev, "%s data will not fit into plane (%lu < %lu)\n", in dcmi_buf_prepare()
544 if (buf->size > dcmi->dma_max_burst) in dcmi_buf_prepare()
545 num_sgs = DIV_ROUND_UP(buf->size, dcmi->dma_max_burst); in dcmi_buf_prepare()
549 dev_err(dcmi->dev, "sg table alloc failed\n"); in dcmi_buf_prepare()
555 dev_dbg(dcmi->dev, "buffer[%d] phy=%pad size=%zu\n", in dcmi_buf_prepare()
559 size_t bytes = min_t(size_t, size, dcmi->dma_max_burst); in dcmi_buf_prepare()
577 struct stm32_dcmi *dcmi = vb2_get_drv_priv(vb->vb2_queue); in dcmi_buf_queue() local
581 spin_lock_irq(&dcmi->irqlock); in dcmi_buf_queue()
584 list_add_tail(&buf->list, &dcmi->buffers); in dcmi_buf_queue()
586 if (dcmi->state == WAIT_FOR_BUFFER) { in dcmi_buf_queue()
587 dcmi->state = RUNNING; in dcmi_buf_queue()
588 dcmi->active = buf; in dcmi_buf_queue()
590 dev_dbg(dcmi->dev, "Starting capture on buffer[%d] queued\n", in dcmi_buf_queue()
593 spin_unlock_irq(&dcmi->irqlock); in dcmi_buf_queue()
594 if (dcmi_start_capture(dcmi, buf)) in dcmi_buf_queue()
595 dev_err(dcmi->dev, "%s: Cannot restart capture on overflow or error\n", in dcmi_buf_queue()
600 spin_unlock_irq(&dcmi->irqlock); in dcmi_buf_queue()
603 static struct media_entity *dcmi_find_source(struct stm32_dcmi *dcmi) in dcmi_find_source() argument
605 struct media_entity *entity = &dcmi->vdev->entity; in dcmi_find_source()
624 static int dcmi_pipeline_s_fmt(struct stm32_dcmi *dcmi, in dcmi_pipeline_s_fmt() argument
627 struct media_entity *entity = &dcmi->source->entity; in dcmi_pipeline_s_fmt()
661 dev_dbg(dcmi->dev, "\"%s\":%d pad format set to 0x%x %ux%u\n", in dcmi_pipeline_s_fmt()
668 dev_err(dcmi->dev, "%s: Failed to set format 0x%x %ux%u on \"%s\":%d pad (%d)\n", in dcmi_pipeline_s_fmt()
678 dev_dbg(dcmi->dev, "\"%s\":%d pad format has been changed to 0x%x %ux%u\n", in dcmi_pipeline_s_fmt()
697 struct stm32_dcmi *dcmi = vb2_get_drv_priv(vq); in dcmi_start_streaming() local
702 ret = pm_runtime_resume_and_get(dcmi->dev); in dcmi_start_streaming()
704 dev_err(dcmi->dev, "%s: Failed to start streaming, cannot get sync (%d)\n", in dcmi_start_streaming()
709 ret = video_device_pipeline_start(dcmi->vdev, &dcmi->pipeline); in dcmi_start_streaming()
711 dev_err(dcmi->dev, "%s: Failed to start streaming, media pipeline start error (%d)\n", in dcmi_start_streaming()
716 ret = v4l2_subdev_call(dcmi->s_subdev, video, s_stream, 1); in dcmi_start_streaming()
718 dev_err(dcmi->dev, "%s: Failed to start source subdev, error (%d)\n", in dcmi_start_streaming()
723 spin_lock_irq(&dcmi->irqlock); in dcmi_start_streaming()
726 switch (dcmi->bus.bus_width) { in dcmi_start_streaming()
742 if (dcmi->bus.flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) in dcmi_start_streaming()
746 if (dcmi->bus.flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) in dcmi_start_streaming()
750 if (dcmi->bus.flags & V4L2_MBUS_PCLK_SAMPLE_RISING) in dcmi_start_streaming()
760 if (dcmi->bus_type == V4L2_MBUS_BT656) { in dcmi_start_streaming()
764 reg_write(dcmi->regs, DCMI_ESUR, 0xffffffff);/* FEC:LEC:LSC:FSC */ in dcmi_start_streaming()
767 reg_write(dcmi->regs, DCMI_ESCR, 0xff9d80ff);/* FEC:LEC:LSC:FSC */ in dcmi_start_streaming()
770 reg_write(dcmi->regs, DCMI_CR, val); in dcmi_start_streaming()
773 if (dcmi->do_crop) in dcmi_start_streaming()
774 dcmi_set_crop(dcmi); in dcmi_start_streaming()
777 if (dcmi->sd_format->fourcc == V4L2_PIX_FMT_JPEG) in dcmi_start_streaming()
778 reg_set(dcmi->regs, DCMI_CR, CR_CM);/* Snapshot mode */ in dcmi_start_streaming()
781 reg_set(dcmi->regs, DCMI_CR, CR_ENABLE); in dcmi_start_streaming()
783 dcmi->sequence = 0; in dcmi_start_streaming()
784 dcmi->errors_count = 0; in dcmi_start_streaming()
785 dcmi->overrun_count = 0; in dcmi_start_streaming()
786 dcmi->buffers_count = 0; in dcmi_start_streaming()
792 if (list_empty(&dcmi->buffers)) { in dcmi_start_streaming()
793 dev_dbg(dcmi->dev, "Start streaming is deferred to next buffer queueing\n"); in dcmi_start_streaming()
794 dcmi->state = WAIT_FOR_BUFFER; in dcmi_start_streaming()
795 spin_unlock_irq(&dcmi->irqlock); in dcmi_start_streaming()
799 buf = list_entry(dcmi->buffers.next, struct dcmi_buf, list); in dcmi_start_streaming()
800 dcmi->active = buf; in dcmi_start_streaming()
802 dcmi->state = RUNNING; in dcmi_start_streaming()
804 dev_dbg(dcmi->dev, "Start streaming, starting capture\n"); in dcmi_start_streaming()
806 spin_unlock_irq(&dcmi->irqlock); in dcmi_start_streaming()
807 ret = dcmi_start_capture(dcmi, buf); in dcmi_start_streaming()
809 dev_err(dcmi->dev, "%s: Start streaming failed, cannot start capture\n", in dcmi_start_streaming()
815 if (dcmi->sd_format->fourcc == V4L2_PIX_FMT_JPEG) in dcmi_start_streaming()
816 reg_set(dcmi->regs, DCMI_IER, IT_FRAME | IT_OVR | IT_ERR); in dcmi_start_streaming()
818 reg_set(dcmi->regs, DCMI_IER, IT_OVR | IT_ERR); in dcmi_start_streaming()
823 v4l2_subdev_call(dcmi->s_subdev, video, s_stream, 0); in dcmi_start_streaming()
826 video_device_pipeline_stop(dcmi->vdev); in dcmi_start_streaming()
829 pm_runtime_put(dcmi->dev); in dcmi_start_streaming()
831 spin_lock_irq(&dcmi->irqlock); in dcmi_start_streaming()
836 list_for_each_entry_safe(buf, node, &dcmi->buffers, list) { in dcmi_start_streaming()
840 dcmi->active = NULL; in dcmi_start_streaming()
841 spin_unlock_irq(&dcmi->irqlock); in dcmi_start_streaming()
848 struct stm32_dcmi *dcmi = vb2_get_drv_priv(vq); in dcmi_stop_streaming() local
852 ret = v4l2_subdev_call(dcmi->s_subdev, video, s_stream, 0); in dcmi_stop_streaming()
854 dev_err(dcmi->dev, "%s: Failed to stop source subdev, error (%d)\n", in dcmi_stop_streaming()
857 video_device_pipeline_stop(dcmi->vdev); in dcmi_stop_streaming()
859 spin_lock_irq(&dcmi->irqlock); in dcmi_stop_streaming()
862 reg_clear(dcmi->regs, DCMI_IER, IT_FRAME | IT_OVR | IT_ERR); in dcmi_stop_streaming()
865 reg_clear(dcmi->regs, DCMI_CR, CR_ENABLE); in dcmi_stop_streaming()
868 list_for_each_entry_safe(buf, node, &dcmi->buffers, list) { in dcmi_stop_streaming()
873 dcmi->active = NULL; in dcmi_stop_streaming()
874 dcmi->state = STOPPED; in dcmi_stop_streaming()
876 spin_unlock_irq(&dcmi->irqlock); in dcmi_stop_streaming()
879 mutex_lock(&dcmi->dma_lock); in dcmi_stop_streaming()
880 dmaengine_terminate_sync(dcmi->dma_chan); in dcmi_stop_streaming()
881 mutex_unlock(&dcmi->dma_lock); in dcmi_stop_streaming()
883 pm_runtime_put(dcmi->dev); in dcmi_stop_streaming()
885 if (dcmi->errors_count) in dcmi_stop_streaming()
886 dev_warn(dcmi->dev, "Some errors found while streaming: errors=%d (overrun=%d), buffers=%d\n", in dcmi_stop_streaming()
887 dcmi->errors_count, dcmi->overrun_count, in dcmi_stop_streaming()
888 dcmi->buffers_count); in dcmi_stop_streaming()
889 dev_dbg(dcmi->dev, "Stop streaming, errors=%d (overrun=%d), buffers=%d\n", in dcmi_stop_streaming()
890 dcmi->errors_count, dcmi->overrun_count, in dcmi_stop_streaming()
891 dcmi->buffers_count); in dcmi_stop_streaming()
908 struct stm32_dcmi *dcmi = video_drvdata(file); in dcmi_g_fmt_vid_cap() local
910 *fmt = dcmi->fmt; in dcmi_g_fmt_vid_cap()
915 static const struct dcmi_format *find_format_by_fourcc(struct stm32_dcmi *dcmi, in find_format_by_fourcc() argument
918 unsigned int num_formats = dcmi->num_of_sd_formats; in find_format_by_fourcc()
923 fmt = dcmi->sd_formats[i]; in find_format_by_fourcc()
931 static void __find_outer_frame_size(struct stm32_dcmi *dcmi, in __find_outer_frame_size() argument
939 for (i = 0; i < dcmi->num_of_sd_framesizes; i++) { in __find_outer_frame_size()
940 struct dcmi_framesize *fsize = &dcmi->sd_framesizes[i]; in __find_outer_frame_size()
951 match = &dcmi->sd_framesizes[0]; in __find_outer_frame_size()
956 static int dcmi_try_fmt(struct stm32_dcmi *dcmi, struct v4l2_format *f, in dcmi_try_fmt() argument
969 sd_fmt = find_format_by_fourcc(dcmi, pix->pixelformat); in dcmi_try_fmt()
971 if (!dcmi->num_of_sd_formats) in dcmi_try_fmt()
974 sd_fmt = dcmi->sd_formats[dcmi->num_of_sd_formats - 1]; in dcmi_try_fmt()
983 do_crop = dcmi->do_crop && (pix->pixelformat != V4L2_PIX_FMT_JPEG); in dcmi_try_fmt()
985 if (do_crop && dcmi->num_of_sd_framesizes) { in dcmi_try_fmt()
991 __find_outer_frame_size(dcmi, pix, &outer_sd_fsize); in dcmi_try_fmt()
997 ret = v4l2_subdev_call_state_try(dcmi->source, pad, set_fmt, &format); in dcmi_try_fmt()
1009 struct v4l2_rect c = dcmi->crop; in dcmi_try_fmt()
1023 dcmi->crop = c; in dcmi_try_fmt()
1026 pix->width = dcmi->crop.width; in dcmi_try_fmt()
1027 pix->height = dcmi->crop.height; in dcmi_try_fmt()
1042 static int dcmi_set_fmt(struct stm32_dcmi *dcmi, struct v4l2_format *f) in dcmi_set_fmt() argument
1059 ret = dcmi_try_fmt(dcmi, f, &sd_format, &sd_framesize); in dcmi_set_fmt()
1065 dcmi->bus_type != V4L2_MBUS_BT656) in dcmi_set_fmt()
1066 dcmi->do_crop = false; in dcmi_set_fmt()
1074 ret = dcmi_pipeline_s_fmt(dcmi, &format); in dcmi_set_fmt()
1078 dev_dbg(dcmi->dev, "Sensor format set to 0x%x %ux%u\n", in dcmi_set_fmt()
1080 dev_dbg(dcmi->dev, "Buffer format set to %4.4s %ux%u\n", in dcmi_set_fmt()
1084 dcmi->fmt = *f; in dcmi_set_fmt()
1085 dcmi->sd_format = sd_format; in dcmi_set_fmt()
1086 dcmi->sd_framesize = sd_framesize; in dcmi_set_fmt()
1094 struct stm32_dcmi *dcmi = video_drvdata(file); in dcmi_s_fmt_vid_cap() local
1096 if (vb2_is_streaming(&dcmi->queue)) in dcmi_s_fmt_vid_cap()
1099 return dcmi_set_fmt(dcmi, f); in dcmi_s_fmt_vid_cap()
1105 struct stm32_dcmi *dcmi = video_drvdata(file); in dcmi_try_fmt_vid_cap() local
1107 return dcmi_try_fmt(dcmi, f, NULL, NULL); in dcmi_try_fmt_vid_cap()
1113 struct stm32_dcmi *dcmi = video_drvdata(file); in dcmi_enum_fmt_vid_cap() local
1115 if (f->index >= dcmi->num_of_sd_formats) in dcmi_enum_fmt_vid_cap()
1118 f->pixelformat = dcmi->sd_formats[f->index]->fourcc; in dcmi_enum_fmt_vid_cap()
1122 static int dcmi_get_sensor_format(struct stm32_dcmi *dcmi, in dcmi_get_sensor_format() argument
1130 ret = v4l2_subdev_call(dcmi->source, pad, get_fmt, NULL, &fmt); in dcmi_get_sensor_format()
1139 static int dcmi_set_sensor_format(struct stm32_dcmi *dcmi, in dcmi_set_sensor_format() argument
1148 sd_fmt = find_format_by_fourcc(dcmi, pix->pixelformat); in dcmi_set_sensor_format()
1150 if (!dcmi->num_of_sd_formats) in dcmi_set_sensor_format()
1153 sd_fmt = dcmi->sd_formats[dcmi->num_of_sd_formats - 1]; in dcmi_set_sensor_format()
1158 ret = v4l2_subdev_call_state_try(dcmi->source, pad, set_fmt, &format); in dcmi_set_sensor_format()
1165 static int dcmi_get_sensor_bounds(struct stm32_dcmi *dcmi, in dcmi_get_sensor_bounds() argument
1180 ret = v4l2_subdev_call(dcmi->source, pad, get_selection, in dcmi_get_sensor_bounds()
1195 for (i = 0; i < dcmi->num_of_sd_framesizes; i++) { in dcmi_get_sensor_bounds()
1196 struct dcmi_framesize *fsize = &dcmi->sd_framesizes[i]; in dcmi_get_sensor_bounds()
1217 ret = dcmi_get_sensor_format(dcmi, &pix); in dcmi_get_sensor_bounds()
1232 struct stm32_dcmi *dcmi = video_drvdata(file); in dcmi_g_selection() local
1240 s->r = dcmi->sd_bounds; in dcmi_g_selection()
1243 if (dcmi->do_crop) { in dcmi_g_selection()
1244 s->r = dcmi->crop; in dcmi_g_selection()
1248 s->r.width = dcmi->fmt.fmt.pix.width; in dcmi_g_selection()
1249 s->r.height = dcmi->fmt.fmt.pix.height; in dcmi_g_selection()
1262 struct stm32_dcmi *dcmi = video_drvdata(file); in dcmi_s_selection() local
1272 pix.pixelformat = dcmi->fmt.fmt.pix.pixelformat; in dcmi_s_selection()
1273 pix.width = dcmi->sd_bounds.width; in dcmi_s_selection()
1274 pix.height = dcmi->sd_bounds.height; in dcmi_s_selection()
1275 dcmi_set_sensor_format(dcmi, &pix); in dcmi_s_selection()
1290 if (!(r.top == dcmi->sd_bounds.top && in dcmi_s_selection()
1291 r.left == dcmi->sd_bounds.left && in dcmi_s_selection()
1292 r.width == dcmi->sd_bounds.width && in dcmi_s_selection()
1293 r.height == dcmi->sd_bounds.height)) { in dcmi_s_selection()
1295 dcmi->do_crop = true; in dcmi_s_selection()
1296 dcmi->crop = r; in dcmi_s_selection()
1297 dev_dbg(dcmi->dev, "s_selection: crop %ux%u@(%u,%u) from %ux%u\n", in dcmi_s_selection()
1302 dcmi->do_crop = false; in dcmi_s_selection()
1303 dev_dbg(dcmi->dev, "s_selection: crop is disabled\n"); in dcmi_s_selection()
1347 struct stm32_dcmi *dcmi = video_drvdata(file); in dcmi_enum_framesizes() local
1355 sd_fmt = find_format_by_fourcc(dcmi, fsize->pixel_format); in dcmi_enum_framesizes()
1361 ret = v4l2_subdev_call(dcmi->source, pad, enum_frame_size, in dcmi_enum_framesizes()
1376 struct stm32_dcmi *dcmi = video_drvdata(file); in dcmi_g_parm() local
1378 return v4l2_g_parm_cap(video_devdata(file), dcmi->source, p); in dcmi_g_parm()
1384 struct stm32_dcmi *dcmi = video_drvdata(file); in dcmi_s_parm() local
1386 return v4l2_s_parm_cap(video_devdata(file), dcmi->source, p); in dcmi_s_parm()
1392 struct stm32_dcmi *dcmi = video_drvdata(file); in dcmi_enum_frameintervals() local
1402 sd_fmt = find_format_by_fourcc(dcmi, fival->pixel_format); in dcmi_enum_frameintervals()
1408 ret = v4l2_subdev_call(dcmi->source, pad, in dcmi_enum_frameintervals()
1427 struct stm32_dcmi *dcmi = video_drvdata(file); in dcmi_open() local
1428 struct v4l2_subdev *sd = dcmi->source; in dcmi_open()
1431 if (mutex_lock_interruptible(&dcmi->lock)) in dcmi_open()
1445 ret = dcmi_set_fmt(dcmi, &dcmi->fmt); in dcmi_open()
1452 mutex_unlock(&dcmi->lock); in dcmi_open()
1458 struct stm32_dcmi *dcmi = video_drvdata(file); in dcmi_release() local
1459 struct v4l2_subdev *sd = dcmi->source; in dcmi_release()
1463 mutex_lock(&dcmi->lock); in dcmi_release()
1472 mutex_unlock(&dcmi->lock); in dcmi_release()
1525 static int dcmi_set_default_fmt(struct stm32_dcmi *dcmi) in dcmi_set_default_fmt() argument
1533 .pixelformat = dcmi->sd_formats[0]->fourcc, in dcmi_set_default_fmt()
1538 ret = dcmi_try_fmt(dcmi, &f, NULL, NULL); in dcmi_set_default_fmt()
1541 dcmi->sd_format = dcmi->sd_formats[0]; in dcmi_set_default_fmt()
1542 dcmi->fmt = f; in dcmi_set_default_fmt()
1642 static int dcmi_formats_init(struct stm32_dcmi *dcmi) in dcmi_formats_init() argument
1646 struct v4l2_subdev *subdev = dcmi->source; in dcmi_formats_init()
1659 dcmi->bus_type == V4L2_MBUS_BT656) in dcmi_formats_init()
1667 dev_dbg(dcmi->dev, "Skipping fourcc/code: %4.4s/0x%x\n", in dcmi_formats_init()
1675 dev_dbg(dcmi->dev, "Supported fourcc/code: %4.4s/0x%x\n", in dcmi_formats_init()
1686 dcmi->num_of_sd_formats = num_fmts; in dcmi_formats_init()
1687 dcmi->sd_formats = devm_kcalloc(dcmi->dev, in dcmi_formats_init()
1690 if (!dcmi->sd_formats) { in dcmi_formats_init()
1691 dev_err(dcmi->dev, "Could not allocate memory\n"); in dcmi_formats_init()
1695 memcpy(dcmi->sd_formats, sd_fmts, in dcmi_formats_init()
1697 dcmi->sd_format = dcmi->sd_formats[0]; in dcmi_formats_init()
1702 static int dcmi_framesizes_init(struct stm32_dcmi *dcmi) in dcmi_framesizes_init() argument
1705 struct v4l2_subdev *subdev = dcmi->source; in dcmi_framesizes_init()
1708 .code = dcmi->sd_format->mbus_code, in dcmi_framesizes_init()
1722 dcmi->num_of_sd_framesizes = num_fsize; in dcmi_framesizes_init()
1723 dcmi->sd_framesizes = devm_kcalloc(dcmi->dev, num_fsize, in dcmi_framesizes_init()
1726 if (!dcmi->sd_framesizes) { in dcmi_framesizes_init()
1727 dev_err(dcmi->dev, "Could not allocate memory\n"); in dcmi_framesizes_init()
1732 dev_dbg(dcmi->dev, "Sensor supports %u frame sizes:\n", num_fsize); in dcmi_framesizes_init()
1733 for (i = 0; i < dcmi->num_of_sd_framesizes; i++) { in dcmi_framesizes_init()
1739 dcmi->sd_framesizes[fse.index].width = fse.max_width; in dcmi_framesizes_init()
1740 dcmi->sd_framesizes[fse.index].height = fse.max_height; in dcmi_framesizes_init()
1741 dev_dbg(dcmi->dev, "%ux%u\n", fse.max_width, fse.max_height); in dcmi_framesizes_init()
1749 struct stm32_dcmi *dcmi = notifier_to_dcmi(notifier); in dcmi_graph_notify_complete() local
1757 dcmi->source = media_entity_to_v4l2_subdev(dcmi_find_source(dcmi)); in dcmi_graph_notify_complete()
1758 if (!dcmi->source) { in dcmi_graph_notify_complete()
1759 dev_err(dcmi->dev, "Source subdevice not found\n"); in dcmi_graph_notify_complete()
1763 dcmi->vdev->ctrl_handler = dcmi->source->ctrl_handler; in dcmi_graph_notify_complete()
1765 ret = dcmi_formats_init(dcmi); in dcmi_graph_notify_complete()
1767 dev_err(dcmi->dev, "No supported mediabus format found\n"); in dcmi_graph_notify_complete()
1771 ret = dcmi_framesizes_init(dcmi); in dcmi_graph_notify_complete()
1773 dev_err(dcmi->dev, "Could not initialize framesizes\n"); in dcmi_graph_notify_complete()
1777 ret = dcmi_get_sensor_bounds(dcmi, &dcmi->sd_bounds); in dcmi_graph_notify_complete()
1779 dev_err(dcmi->dev, "Could not get sensor bounds\n"); in dcmi_graph_notify_complete()
1783 ret = dcmi_set_default_fmt(dcmi); in dcmi_graph_notify_complete()
1785 dev_err(dcmi->dev, "Could not set default format\n"); in dcmi_graph_notify_complete()
1789 ret = devm_request_threaded_irq(dcmi->dev, dcmi->irq, dcmi_irq_callback, in dcmi_graph_notify_complete()
1791 dev_name(dcmi->dev), dcmi); in dcmi_graph_notify_complete()
1793 dev_err(dcmi->dev, "Unable to request irq %d\n", dcmi->irq); in dcmi_graph_notify_complete()
1804 struct stm32_dcmi *dcmi = notifier_to_dcmi(notifier); in dcmi_graph_notify_unbind() local
1806 dev_dbg(dcmi->dev, "Removing %s\n", video_device_node_name(dcmi->vdev)); in dcmi_graph_notify_unbind()
1809 video_unregister_device(dcmi->vdev); in dcmi_graph_notify_unbind()
1816 struct stm32_dcmi *dcmi = notifier_to_dcmi(notifier); in dcmi_graph_notify_bound() local
1820 dev_dbg(dcmi->dev, "Subdev \"%s\" bound\n", subdev->name); in dcmi_graph_notify_bound()
1831 &dcmi->vdev->entity, 0, in dcmi_graph_notify_bound()
1835 dev_err(dcmi->dev, "Failed to create media pad link with subdev \"%s\"\n", in dcmi_graph_notify_bound()
1838 dev_dbg(dcmi->dev, "DCMI is now linked to \"%s\"\n", in dcmi_graph_notify_bound()
1841 dcmi->s_subdev = subdev; in dcmi_graph_notify_bound()
1852 static int dcmi_graph_init(struct stm32_dcmi *dcmi) in dcmi_graph_init() argument
1858 ep = of_graph_get_endpoint_by_regs(dcmi->dev->of_node, 0, -1); in dcmi_graph_init()
1860 dev_err(dcmi->dev, "Failed to get next endpoint\n"); in dcmi_graph_init()
1864 v4l2_async_nf_init(&dcmi->notifier, &dcmi->v4l2_dev); in dcmi_graph_init()
1866 asd = v4l2_async_nf_add_fwnode_remote(&dcmi->notifier, in dcmi_graph_init()
1873 dev_err(dcmi->dev, "Failed to add subdev notifier\n"); in dcmi_graph_init()
1877 dcmi->notifier.ops = &dcmi_graph_notify_ops; in dcmi_graph_init()
1879 ret = v4l2_async_nf_register(&dcmi->notifier); in dcmi_graph_init()
1881 dev_err(dcmi->dev, "Failed to register notifier\n"); in dcmi_graph_init()
1882 v4l2_async_nf_cleanup(&dcmi->notifier); in dcmi_graph_init()
1893 struct stm32_dcmi *dcmi; in dcmi_probe() local
1900 dcmi = devm_kzalloc(&pdev->dev, sizeof(struct stm32_dcmi), GFP_KERNEL); in dcmi_probe()
1901 if (!dcmi) in dcmi_probe()
1904 dcmi->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL); in dcmi_probe()
1905 if (IS_ERR(dcmi->rstc)) in dcmi_probe()
1906 return dev_err_probe(&pdev->dev, PTR_ERR(dcmi->rstc), in dcmi_probe()
1935 dcmi->bus.flags = ep.bus.parallel.flags; in dcmi_probe()
1936 dcmi->bus.bus_width = ep.bus.parallel.bus_width; in dcmi_probe()
1937 dcmi->bus.data_shift = ep.bus.parallel.data_shift; in dcmi_probe()
1938 dcmi->bus_type = ep.bus_type; in dcmi_probe()
1940 dcmi->irq = platform_get_irq(pdev, 0); in dcmi_probe()
1941 if (dcmi->irq < 0) in dcmi_probe()
1942 return dcmi->irq; in dcmi_probe()
1944 dcmi->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &dcmi->res); in dcmi_probe()
1945 if (IS_ERR(dcmi->regs)) in dcmi_probe()
1946 return PTR_ERR(dcmi->regs); in dcmi_probe()
1958 dcmi->dma_max_burst = UINT_MAX; in dcmi_probe()
1961 dcmi->dma_max_burst = caps.max_sg_burst * DMA_SLAVE_BUSWIDTH_4_BYTES; in dcmi_probe()
1963 spin_lock_init(&dcmi->irqlock); in dcmi_probe()
1964 mutex_init(&dcmi->lock); in dcmi_probe()
1965 mutex_init(&dcmi->dma_lock); in dcmi_probe()
1966 init_completion(&dcmi->complete); in dcmi_probe()
1967 INIT_LIST_HEAD(&dcmi->buffers); in dcmi_probe()
1969 dcmi->dev = &pdev->dev; in dcmi_probe()
1970 dcmi->mclk = mclk; in dcmi_probe()
1971 dcmi->state = STOPPED; in dcmi_probe()
1972 dcmi->dma_chan = chan; in dcmi_probe()
1974 q = &dcmi->queue; in dcmi_probe()
1976 dcmi->v4l2_dev.mdev = &dcmi->mdev; in dcmi_probe()
1979 strscpy(dcmi->mdev.model, DRV_NAME, sizeof(dcmi->mdev.model)); in dcmi_probe()
1980 dcmi->mdev.dev = &pdev->dev; in dcmi_probe()
1981 media_device_init(&dcmi->mdev); in dcmi_probe()
1984 ret = v4l2_device_register(&pdev->dev, &dcmi->v4l2_dev); in dcmi_probe()
1988 dcmi->vdev = video_device_alloc(); in dcmi_probe()
1989 if (!dcmi->vdev) { in dcmi_probe()
1995 dcmi->vdev->fops = &dcmi_fops; in dcmi_probe()
1996 dcmi->vdev->v4l2_dev = &dcmi->v4l2_dev; in dcmi_probe()
1997 dcmi->vdev->queue = &dcmi->queue; in dcmi_probe()
1998 strscpy(dcmi->vdev->name, KBUILD_MODNAME, sizeof(dcmi->vdev->name)); in dcmi_probe()
1999 dcmi->vdev->release = video_device_release; in dcmi_probe()
2000 dcmi->vdev->ioctl_ops = &dcmi_ioctl_ops; in dcmi_probe()
2001 dcmi->vdev->lock = &dcmi->lock; in dcmi_probe()
2002 dcmi->vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING | in dcmi_probe()
2004 video_set_drvdata(dcmi->vdev, dcmi); in dcmi_probe()
2007 dcmi->vid_cap_pad.flags = MEDIA_PAD_FL_SINK; in dcmi_probe()
2008 ret = media_entity_pads_init(&dcmi->vdev->entity, in dcmi_probe()
2009 1, &dcmi->vid_cap_pad); in dcmi_probe()
2011 dev_err(dcmi->dev, "Failed to init media entity pad\n"); in dcmi_probe()
2014 dcmi->vdev->entity.flags |= MEDIA_ENT_FL_DEFAULT; in dcmi_probe()
2016 ret = video_register_device(dcmi->vdev, VFL_TYPE_VIDEO, -1); in dcmi_probe()
2018 dev_err(dcmi->dev, "Failed to register video device\n"); in dcmi_probe()
2022 dev_dbg(dcmi->dev, "Device registered as %s\n", in dcmi_probe()
2023 video_device_node_name(dcmi->vdev)); in dcmi_probe()
2028 q->lock = &dcmi->lock; in dcmi_probe()
2029 q->drv_priv = dcmi; in dcmi_probe()
2044 ret = dcmi_graph_init(dcmi); in dcmi_probe()
2049 ret = reset_control_assert(dcmi->rstc); in dcmi_probe()
2057 ret = reset_control_deassert(dcmi->rstc); in dcmi_probe()
2065 platform_set_drvdata(pdev, dcmi); in dcmi_probe()
2072 v4l2_async_nf_cleanup(&dcmi->notifier); in dcmi_probe()
2074 media_entity_cleanup(&dcmi->vdev->entity); in dcmi_probe()
2076 video_device_release(dcmi->vdev); in dcmi_probe()
2078 v4l2_device_unregister(&dcmi->v4l2_dev); in dcmi_probe()
2080 media_device_cleanup(&dcmi->mdev); in dcmi_probe()
2081 dma_release_channel(dcmi->dma_chan); in dcmi_probe()
2088 struct stm32_dcmi *dcmi = platform_get_drvdata(pdev); in dcmi_remove() local
2092 v4l2_async_nf_unregister(&dcmi->notifier); in dcmi_remove()
2093 v4l2_async_nf_cleanup(&dcmi->notifier); in dcmi_remove()
2094 media_entity_cleanup(&dcmi->vdev->entity); in dcmi_remove()
2095 v4l2_device_unregister(&dcmi->v4l2_dev); in dcmi_remove()
2096 media_device_cleanup(&dcmi->mdev); in dcmi_remove()
2098 dma_release_channel(dcmi->dma_chan); in dcmi_remove()
2103 struct stm32_dcmi *dcmi = dev_get_drvdata(dev); in dcmi_runtime_suspend() local
2105 clk_disable_unprepare(dcmi->mclk); in dcmi_runtime_suspend()
2112 struct stm32_dcmi *dcmi = dev_get_drvdata(dev); in dcmi_runtime_resume() local
2115 ret = clk_prepare_enable(dcmi->mclk); in dcmi_runtime_resume()