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()
695 static int dcmi_pipeline_s_stream(struct stm32_dcmi *dcmi, int state) in dcmi_pipeline_s_stream() argument
697 struct media_entity *entity = &dcmi->vdev->entity; in dcmi_pipeline_s_stream()
717 dev_err(dcmi->dev, "%s: \"%s\" failed to %s streaming (%d)\n", in dcmi_pipeline_s_stream()
723 dev_dbg(dcmi->dev, "\"%s\" is %s\n", in dcmi_pipeline_s_stream()
730 static int dcmi_pipeline_start(struct stm32_dcmi *dcmi) in dcmi_pipeline_start() argument
732 return dcmi_pipeline_s_stream(dcmi, 1); in dcmi_pipeline_start()
735 static void dcmi_pipeline_stop(struct stm32_dcmi *dcmi) in dcmi_pipeline_stop() argument
737 dcmi_pipeline_s_stream(dcmi, 0); in dcmi_pipeline_stop()
742 struct stm32_dcmi *dcmi = vb2_get_drv_priv(vq); in dcmi_start_streaming() local
747 ret = pm_runtime_resume_and_get(dcmi->dev); in dcmi_start_streaming()
749 dev_err(dcmi->dev, "%s: Failed to start streaming, cannot get sync (%d)\n", in dcmi_start_streaming()
754 ret = video_device_pipeline_start(dcmi->vdev, &dcmi->pipeline); in dcmi_start_streaming()
756 dev_err(dcmi->dev, "%s: Failed to start streaming, media pipeline start error (%d)\n", in dcmi_start_streaming()
761 ret = dcmi_pipeline_start(dcmi); in dcmi_start_streaming()
765 spin_lock_irq(&dcmi->irqlock); in dcmi_start_streaming()
768 switch (dcmi->bus.bus_width) { in dcmi_start_streaming()
784 if (dcmi->bus.flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) in dcmi_start_streaming()
788 if (dcmi->bus.flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) in dcmi_start_streaming()
792 if (dcmi->bus.flags & V4L2_MBUS_PCLK_SAMPLE_RISING) in dcmi_start_streaming()
802 if (dcmi->bus_type == V4L2_MBUS_BT656) { in dcmi_start_streaming()
806 reg_write(dcmi->regs, DCMI_ESUR, 0xffffffff);/* FEC:LEC:LSC:FSC */ in dcmi_start_streaming()
809 reg_write(dcmi->regs, DCMI_ESCR, 0xff9d80ff);/* FEC:LEC:LSC:FSC */ in dcmi_start_streaming()
812 reg_write(dcmi->regs, DCMI_CR, val); in dcmi_start_streaming()
815 if (dcmi->do_crop) in dcmi_start_streaming()
816 dcmi_set_crop(dcmi); in dcmi_start_streaming()
819 if (dcmi->sd_format->fourcc == V4L2_PIX_FMT_JPEG) in dcmi_start_streaming()
820 reg_set(dcmi->regs, DCMI_CR, CR_CM);/* Snapshot mode */ in dcmi_start_streaming()
823 reg_set(dcmi->regs, DCMI_CR, CR_ENABLE); in dcmi_start_streaming()
825 dcmi->sequence = 0; in dcmi_start_streaming()
826 dcmi->errors_count = 0; in dcmi_start_streaming()
827 dcmi->overrun_count = 0; in dcmi_start_streaming()
828 dcmi->buffers_count = 0; in dcmi_start_streaming()
834 if (list_empty(&dcmi->buffers)) { in dcmi_start_streaming()
835 dev_dbg(dcmi->dev, "Start streaming is deferred to next buffer queueing\n"); in dcmi_start_streaming()
836 dcmi->state = WAIT_FOR_BUFFER; in dcmi_start_streaming()
837 spin_unlock_irq(&dcmi->irqlock); in dcmi_start_streaming()
841 buf = list_entry(dcmi->buffers.next, struct dcmi_buf, list); in dcmi_start_streaming()
842 dcmi->active = buf; in dcmi_start_streaming()
844 dcmi->state = RUNNING; in dcmi_start_streaming()
846 dev_dbg(dcmi->dev, "Start streaming, starting capture\n"); in dcmi_start_streaming()
848 spin_unlock_irq(&dcmi->irqlock); in dcmi_start_streaming()
849 ret = dcmi_start_capture(dcmi, buf); in dcmi_start_streaming()
851 dev_err(dcmi->dev, "%s: Start streaming failed, cannot start capture\n", in dcmi_start_streaming()
857 if (dcmi->sd_format->fourcc == V4L2_PIX_FMT_JPEG) in dcmi_start_streaming()
858 reg_set(dcmi->regs, DCMI_IER, IT_FRAME | IT_OVR | IT_ERR); in dcmi_start_streaming()
860 reg_set(dcmi->regs, DCMI_IER, IT_OVR | IT_ERR); in dcmi_start_streaming()
865 dcmi_pipeline_stop(dcmi); in dcmi_start_streaming()
868 video_device_pipeline_stop(dcmi->vdev); in dcmi_start_streaming()
871 pm_runtime_put(dcmi->dev); in dcmi_start_streaming()
873 spin_lock_irq(&dcmi->irqlock); in dcmi_start_streaming()
878 list_for_each_entry_safe(buf, node, &dcmi->buffers, list) { in dcmi_start_streaming()
882 dcmi->active = NULL; in dcmi_start_streaming()
883 spin_unlock_irq(&dcmi->irqlock); in dcmi_start_streaming()
890 struct stm32_dcmi *dcmi = vb2_get_drv_priv(vq); in dcmi_stop_streaming() local
893 dcmi_pipeline_stop(dcmi); in dcmi_stop_streaming()
895 video_device_pipeline_stop(dcmi->vdev); in dcmi_stop_streaming()
897 spin_lock_irq(&dcmi->irqlock); in dcmi_stop_streaming()
900 reg_clear(dcmi->regs, DCMI_IER, IT_FRAME | IT_OVR | IT_ERR); in dcmi_stop_streaming()
903 reg_clear(dcmi->regs, DCMI_CR, CR_ENABLE); in dcmi_stop_streaming()
906 list_for_each_entry_safe(buf, node, &dcmi->buffers, list) { in dcmi_stop_streaming()
911 dcmi->active = NULL; in dcmi_stop_streaming()
912 dcmi->state = STOPPED; in dcmi_stop_streaming()
914 spin_unlock_irq(&dcmi->irqlock); in dcmi_stop_streaming()
917 mutex_lock(&dcmi->dma_lock); in dcmi_stop_streaming()
918 dmaengine_terminate_sync(dcmi->dma_chan); in dcmi_stop_streaming()
919 mutex_unlock(&dcmi->dma_lock); in dcmi_stop_streaming()
921 pm_runtime_put(dcmi->dev); in dcmi_stop_streaming()
923 if (dcmi->errors_count) in dcmi_stop_streaming()
924 dev_warn(dcmi->dev, "Some errors found while streaming: errors=%d (overrun=%d), buffers=%d\n", in dcmi_stop_streaming()
925 dcmi->errors_count, dcmi->overrun_count, in dcmi_stop_streaming()
926 dcmi->buffers_count); in dcmi_stop_streaming()
927 dev_dbg(dcmi->dev, "Stop streaming, errors=%d (overrun=%d), buffers=%d\n", in dcmi_stop_streaming()
928 dcmi->errors_count, dcmi->overrun_count, in dcmi_stop_streaming()
929 dcmi->buffers_count); in dcmi_stop_streaming()
946 struct stm32_dcmi *dcmi = video_drvdata(file); in dcmi_g_fmt_vid_cap() local
948 *fmt = dcmi->fmt; in dcmi_g_fmt_vid_cap()
953 static const struct dcmi_format *find_format_by_fourcc(struct stm32_dcmi *dcmi, in find_format_by_fourcc() argument
956 unsigned int num_formats = dcmi->num_of_sd_formats; in find_format_by_fourcc()
961 fmt = dcmi->sd_formats[i]; in find_format_by_fourcc()
969 static void __find_outer_frame_size(struct stm32_dcmi *dcmi, in __find_outer_frame_size() argument
977 for (i = 0; i < dcmi->num_of_sd_framesizes; i++) { in __find_outer_frame_size()
978 struct dcmi_framesize *fsize = &dcmi->sd_framesizes[i]; in __find_outer_frame_size()
989 match = &dcmi->sd_framesizes[0]; in __find_outer_frame_size()
994 static int dcmi_try_fmt(struct stm32_dcmi *dcmi, struct v4l2_format *f, in dcmi_try_fmt() argument
1007 sd_fmt = find_format_by_fourcc(dcmi, pix->pixelformat); in dcmi_try_fmt()
1009 if (!dcmi->num_of_sd_formats) in dcmi_try_fmt()
1012 sd_fmt = dcmi->sd_formats[dcmi->num_of_sd_formats - 1]; in dcmi_try_fmt()
1021 do_crop = dcmi->do_crop && (pix->pixelformat != V4L2_PIX_FMT_JPEG); in dcmi_try_fmt()
1023 if (do_crop && dcmi->num_of_sd_framesizes) { in dcmi_try_fmt()
1029 __find_outer_frame_size(dcmi, pix, &outer_sd_fsize); in dcmi_try_fmt()
1035 ret = v4l2_subdev_call_state_try(dcmi->source, pad, set_fmt, &format); in dcmi_try_fmt()
1047 struct v4l2_rect c = dcmi->crop; in dcmi_try_fmt()
1061 dcmi->crop = c; in dcmi_try_fmt()
1064 pix->width = dcmi->crop.width; in dcmi_try_fmt()
1065 pix->height = dcmi->crop.height; in dcmi_try_fmt()
1080 static int dcmi_set_fmt(struct stm32_dcmi *dcmi, struct v4l2_format *f) in dcmi_set_fmt() argument
1097 ret = dcmi_try_fmt(dcmi, f, &sd_format, &sd_framesize); in dcmi_set_fmt()
1103 dcmi->bus_type != V4L2_MBUS_BT656) in dcmi_set_fmt()
1104 dcmi->do_crop = false; in dcmi_set_fmt()
1112 ret = dcmi_pipeline_s_fmt(dcmi, &format); in dcmi_set_fmt()
1116 dev_dbg(dcmi->dev, "Sensor format set to 0x%x %ux%u\n", in dcmi_set_fmt()
1118 dev_dbg(dcmi->dev, "Buffer format set to %4.4s %ux%u\n", in dcmi_set_fmt()
1122 dcmi->fmt = *f; in dcmi_set_fmt()
1123 dcmi->sd_format = sd_format; in dcmi_set_fmt()
1124 dcmi->sd_framesize = sd_framesize; in dcmi_set_fmt()
1132 struct stm32_dcmi *dcmi = video_drvdata(file); in dcmi_s_fmt_vid_cap() local
1134 if (vb2_is_streaming(&dcmi->queue)) in dcmi_s_fmt_vid_cap()
1137 return dcmi_set_fmt(dcmi, f); in dcmi_s_fmt_vid_cap()
1143 struct stm32_dcmi *dcmi = video_drvdata(file); in dcmi_try_fmt_vid_cap() local
1145 return dcmi_try_fmt(dcmi, f, NULL, NULL); in dcmi_try_fmt_vid_cap()
1151 struct stm32_dcmi *dcmi = video_drvdata(file); in dcmi_enum_fmt_vid_cap() local
1153 if (f->index >= dcmi->num_of_sd_formats) in dcmi_enum_fmt_vid_cap()
1156 f->pixelformat = dcmi->sd_formats[f->index]->fourcc; in dcmi_enum_fmt_vid_cap()
1160 static int dcmi_get_sensor_format(struct stm32_dcmi *dcmi, in dcmi_get_sensor_format() argument
1168 ret = v4l2_subdev_call(dcmi->source, pad, get_fmt, NULL, &fmt); in dcmi_get_sensor_format()
1177 static int dcmi_set_sensor_format(struct stm32_dcmi *dcmi, in dcmi_set_sensor_format() argument
1186 sd_fmt = find_format_by_fourcc(dcmi, pix->pixelformat); in dcmi_set_sensor_format()
1188 if (!dcmi->num_of_sd_formats) in dcmi_set_sensor_format()
1191 sd_fmt = dcmi->sd_formats[dcmi->num_of_sd_formats - 1]; in dcmi_set_sensor_format()
1196 ret = v4l2_subdev_call_state_try(dcmi->source, pad, set_fmt, &format); in dcmi_set_sensor_format()
1203 static int dcmi_get_sensor_bounds(struct stm32_dcmi *dcmi, in dcmi_get_sensor_bounds() argument
1218 ret = v4l2_subdev_call(dcmi->source, pad, get_selection, in dcmi_get_sensor_bounds()
1233 for (i = 0; i < dcmi->num_of_sd_framesizes; i++) { in dcmi_get_sensor_bounds()
1234 struct dcmi_framesize *fsize = &dcmi->sd_framesizes[i]; in dcmi_get_sensor_bounds()
1255 ret = dcmi_get_sensor_format(dcmi, &pix); in dcmi_get_sensor_bounds()
1270 struct stm32_dcmi *dcmi = video_drvdata(file); in dcmi_g_selection() local
1278 s->r = dcmi->sd_bounds; in dcmi_g_selection()
1281 if (dcmi->do_crop) { in dcmi_g_selection()
1282 s->r = dcmi->crop; in dcmi_g_selection()
1286 s->r.width = dcmi->fmt.fmt.pix.width; in dcmi_g_selection()
1287 s->r.height = dcmi->fmt.fmt.pix.height; in dcmi_g_selection()
1300 struct stm32_dcmi *dcmi = video_drvdata(file); in dcmi_s_selection() local
1310 pix.pixelformat = dcmi->fmt.fmt.pix.pixelformat; in dcmi_s_selection()
1311 pix.width = dcmi->sd_bounds.width; in dcmi_s_selection()
1312 pix.height = dcmi->sd_bounds.height; in dcmi_s_selection()
1313 dcmi_set_sensor_format(dcmi, &pix); in dcmi_s_selection()
1328 if (!(r.top == dcmi->sd_bounds.top && in dcmi_s_selection()
1329 r.left == dcmi->sd_bounds.left && in dcmi_s_selection()
1330 r.width == dcmi->sd_bounds.width && in dcmi_s_selection()
1331 r.height == dcmi->sd_bounds.height)) { in dcmi_s_selection()
1333 dcmi->do_crop = true; in dcmi_s_selection()
1334 dcmi->crop = r; in dcmi_s_selection()
1335 dev_dbg(dcmi->dev, "s_selection: crop %ux%u@(%u,%u) from %ux%u\n", in dcmi_s_selection()
1340 dcmi->do_crop = false; in dcmi_s_selection()
1341 dev_dbg(dcmi->dev, "s_selection: crop is disabled\n"); in dcmi_s_selection()
1385 struct stm32_dcmi *dcmi = video_drvdata(file); in dcmi_enum_framesizes() local
1393 sd_fmt = find_format_by_fourcc(dcmi, fsize->pixel_format); in dcmi_enum_framesizes()
1399 ret = v4l2_subdev_call(dcmi->source, pad, enum_frame_size, in dcmi_enum_framesizes()
1414 struct stm32_dcmi *dcmi = video_drvdata(file); in dcmi_g_parm() local
1416 return v4l2_g_parm_cap(video_devdata(file), dcmi->source, p); in dcmi_g_parm()
1422 struct stm32_dcmi *dcmi = video_drvdata(file); in dcmi_s_parm() local
1424 return v4l2_s_parm_cap(video_devdata(file), dcmi->source, p); in dcmi_s_parm()
1430 struct stm32_dcmi *dcmi = video_drvdata(file); in dcmi_enum_frameintervals() local
1440 sd_fmt = find_format_by_fourcc(dcmi, fival->pixel_format); in dcmi_enum_frameintervals()
1446 ret = v4l2_subdev_call(dcmi->source, pad, in dcmi_enum_frameintervals()
1465 struct stm32_dcmi *dcmi = video_drvdata(file); in dcmi_open() local
1466 struct v4l2_subdev *sd = dcmi->source; in dcmi_open()
1469 if (mutex_lock_interruptible(&dcmi->lock)) in dcmi_open()
1483 ret = dcmi_set_fmt(dcmi, &dcmi->fmt); in dcmi_open()
1490 mutex_unlock(&dcmi->lock); in dcmi_open()
1496 struct stm32_dcmi *dcmi = video_drvdata(file); in dcmi_release() local
1497 struct v4l2_subdev *sd = dcmi->source; in dcmi_release()
1501 mutex_lock(&dcmi->lock); in dcmi_release()
1510 mutex_unlock(&dcmi->lock); in dcmi_release()
1563 static int dcmi_set_default_fmt(struct stm32_dcmi *dcmi) in dcmi_set_default_fmt() argument
1571 .pixelformat = dcmi->sd_formats[0]->fourcc, in dcmi_set_default_fmt()
1576 ret = dcmi_try_fmt(dcmi, &f, NULL, NULL); in dcmi_set_default_fmt()
1579 dcmi->sd_format = dcmi->sd_formats[0]; in dcmi_set_default_fmt()
1580 dcmi->fmt = f; in dcmi_set_default_fmt()
1680 static int dcmi_formats_init(struct stm32_dcmi *dcmi) in dcmi_formats_init() argument
1684 struct v4l2_subdev *subdev = dcmi->source; in dcmi_formats_init()
1697 dcmi->bus_type == V4L2_MBUS_BT656) in dcmi_formats_init()
1705 dev_dbg(dcmi->dev, "Skipping fourcc/code: %4.4s/0x%x\n", in dcmi_formats_init()
1713 dev_dbg(dcmi->dev, "Supported fourcc/code: %4.4s/0x%x\n", in dcmi_formats_init()
1724 dcmi->num_of_sd_formats = num_fmts; in dcmi_formats_init()
1725 dcmi->sd_formats = devm_kcalloc(dcmi->dev, in dcmi_formats_init()
1728 if (!dcmi->sd_formats) { in dcmi_formats_init()
1729 dev_err(dcmi->dev, "Could not allocate memory\n"); in dcmi_formats_init()
1733 memcpy(dcmi->sd_formats, sd_fmts, in dcmi_formats_init()
1735 dcmi->sd_format = dcmi->sd_formats[0]; in dcmi_formats_init()
1740 static int dcmi_framesizes_init(struct stm32_dcmi *dcmi) in dcmi_framesizes_init() argument
1743 struct v4l2_subdev *subdev = dcmi->source; in dcmi_framesizes_init()
1746 .code = dcmi->sd_format->mbus_code, in dcmi_framesizes_init()
1760 dcmi->num_of_sd_framesizes = num_fsize; in dcmi_framesizes_init()
1761 dcmi->sd_framesizes = devm_kcalloc(dcmi->dev, num_fsize, in dcmi_framesizes_init()
1764 if (!dcmi->sd_framesizes) { in dcmi_framesizes_init()
1765 dev_err(dcmi->dev, "Could not allocate memory\n"); in dcmi_framesizes_init()
1770 dev_dbg(dcmi->dev, "Sensor supports %u frame sizes:\n", num_fsize); in dcmi_framesizes_init()
1771 for (i = 0; i < dcmi->num_of_sd_framesizes; i++) { in dcmi_framesizes_init()
1777 dcmi->sd_framesizes[fse.index].width = fse.max_width; in dcmi_framesizes_init()
1778 dcmi->sd_framesizes[fse.index].height = fse.max_height; in dcmi_framesizes_init()
1779 dev_dbg(dcmi->dev, "%ux%u\n", fse.max_width, fse.max_height); in dcmi_framesizes_init()
1787 struct stm32_dcmi *dcmi = notifier_to_dcmi(notifier); in dcmi_graph_notify_complete() local
1795 dcmi->source = media_entity_to_v4l2_subdev(dcmi_find_source(dcmi)); in dcmi_graph_notify_complete()
1796 if (!dcmi->source) { in dcmi_graph_notify_complete()
1797 dev_err(dcmi->dev, "Source subdevice not found\n"); in dcmi_graph_notify_complete()
1801 dcmi->vdev->ctrl_handler = dcmi->source->ctrl_handler; in dcmi_graph_notify_complete()
1803 ret = dcmi_formats_init(dcmi); in dcmi_graph_notify_complete()
1805 dev_err(dcmi->dev, "No supported mediabus format found\n"); in dcmi_graph_notify_complete()
1809 ret = dcmi_framesizes_init(dcmi); in dcmi_graph_notify_complete()
1811 dev_err(dcmi->dev, "Could not initialize framesizes\n"); in dcmi_graph_notify_complete()
1815 ret = dcmi_get_sensor_bounds(dcmi, &dcmi->sd_bounds); in dcmi_graph_notify_complete()
1817 dev_err(dcmi->dev, "Could not get sensor bounds\n"); in dcmi_graph_notify_complete()
1821 ret = dcmi_set_default_fmt(dcmi); in dcmi_graph_notify_complete()
1823 dev_err(dcmi->dev, "Could not set default format\n"); in dcmi_graph_notify_complete()
1827 ret = devm_request_threaded_irq(dcmi->dev, dcmi->irq, dcmi_irq_callback, in dcmi_graph_notify_complete()
1829 dev_name(dcmi->dev), dcmi); in dcmi_graph_notify_complete()
1831 dev_err(dcmi->dev, "Unable to request irq %d\n", dcmi->irq); in dcmi_graph_notify_complete()
1842 struct stm32_dcmi *dcmi = notifier_to_dcmi(notifier); in dcmi_graph_notify_unbind() local
1844 dev_dbg(dcmi->dev, "Removing %s\n", video_device_node_name(dcmi->vdev)); in dcmi_graph_notify_unbind()
1847 video_unregister_device(dcmi->vdev); in dcmi_graph_notify_unbind()
1854 struct stm32_dcmi *dcmi = notifier_to_dcmi(notifier); in dcmi_graph_notify_bound() local
1858 dev_dbg(dcmi->dev, "Subdev \"%s\" bound\n", subdev->name); in dcmi_graph_notify_bound()
1869 &dcmi->vdev->entity, 0, in dcmi_graph_notify_bound()
1873 dev_err(dcmi->dev, "Failed to create media pad link with subdev \"%s\"\n", in dcmi_graph_notify_bound()
1876 dev_dbg(dcmi->dev, "DCMI is now linked to \"%s\"\n", in dcmi_graph_notify_bound()
1888 static int dcmi_graph_init(struct stm32_dcmi *dcmi) in dcmi_graph_init() argument
1894 ep = of_graph_get_next_endpoint(dcmi->dev->of_node, NULL); in dcmi_graph_init()
1896 dev_err(dcmi->dev, "Failed to get next endpoint\n"); in dcmi_graph_init()
1900 v4l2_async_nf_init(&dcmi->notifier); in dcmi_graph_init()
1902 asd = v4l2_async_nf_add_fwnode_remote(&dcmi->notifier, in dcmi_graph_init()
1909 dev_err(dcmi->dev, "Failed to add subdev notifier\n"); in dcmi_graph_init()
1913 dcmi->notifier.ops = &dcmi_graph_notify_ops; in dcmi_graph_init()
1915 ret = v4l2_async_nf_register(&dcmi->v4l2_dev, &dcmi->notifier); in dcmi_graph_init()
1917 dev_err(dcmi->dev, "Failed to register notifier\n"); in dcmi_graph_init()
1918 v4l2_async_nf_cleanup(&dcmi->notifier); in dcmi_graph_init()
1930 struct stm32_dcmi *dcmi; in dcmi_probe() local
1944 dcmi = devm_kzalloc(&pdev->dev, sizeof(struct stm32_dcmi), GFP_KERNEL); in dcmi_probe()
1945 if (!dcmi) in dcmi_probe()
1948 dcmi->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL); in dcmi_probe()
1949 if (IS_ERR(dcmi->rstc)) { in dcmi_probe()
1950 if (PTR_ERR(dcmi->rstc) != -EPROBE_DEFER) in dcmi_probe()
1953 return PTR_ERR(dcmi->rstc); in dcmi_probe()
1982 dcmi->bus.flags = ep.bus.parallel.flags; in dcmi_probe()
1983 dcmi->bus.bus_width = ep.bus.parallel.bus_width; in dcmi_probe()
1984 dcmi->bus.data_shift = ep.bus.parallel.data_shift; in dcmi_probe()
1985 dcmi->bus_type = ep.bus_type; in dcmi_probe()
1991 dcmi->irq = irq; in dcmi_probe()
1993 dcmi->res = platform_get_resource(pdev, IORESOURCE_MEM, 0); in dcmi_probe()
1994 if (!dcmi->res) { in dcmi_probe()
1999 dcmi->regs = devm_ioremap_resource(&pdev->dev, dcmi->res); in dcmi_probe()
2000 if (IS_ERR(dcmi->regs)) { in dcmi_probe()
2002 return PTR_ERR(dcmi->regs); in dcmi_probe()
2021 dcmi->dma_max_burst = UINT_MAX; in dcmi_probe()
2024 dcmi->dma_max_burst = caps.max_sg_burst * DMA_SLAVE_BUSWIDTH_4_BYTES; in dcmi_probe()
2026 spin_lock_init(&dcmi->irqlock); in dcmi_probe()
2027 mutex_init(&dcmi->lock); in dcmi_probe()
2028 mutex_init(&dcmi->dma_lock); in dcmi_probe()
2029 init_completion(&dcmi->complete); in dcmi_probe()
2030 INIT_LIST_HEAD(&dcmi->buffers); in dcmi_probe()
2032 dcmi->dev = &pdev->dev; in dcmi_probe()
2033 dcmi->mclk = mclk; in dcmi_probe()
2034 dcmi->state = STOPPED; in dcmi_probe()
2035 dcmi->dma_chan = chan; in dcmi_probe()
2037 q = &dcmi->queue; in dcmi_probe()
2039 dcmi->v4l2_dev.mdev = &dcmi->mdev; in dcmi_probe()
2042 strscpy(dcmi->mdev.model, DRV_NAME, sizeof(dcmi->mdev.model)); in dcmi_probe()
2043 dcmi->mdev.dev = &pdev->dev; in dcmi_probe()
2044 media_device_init(&dcmi->mdev); in dcmi_probe()
2047 ret = v4l2_device_register(&pdev->dev, &dcmi->v4l2_dev); in dcmi_probe()
2051 dcmi->vdev = video_device_alloc(); in dcmi_probe()
2052 if (!dcmi->vdev) { in dcmi_probe()
2058 dcmi->vdev->fops = &dcmi_fops; in dcmi_probe()
2059 dcmi->vdev->v4l2_dev = &dcmi->v4l2_dev; in dcmi_probe()
2060 dcmi->vdev->queue = &dcmi->queue; in dcmi_probe()
2061 strscpy(dcmi->vdev->name, KBUILD_MODNAME, sizeof(dcmi->vdev->name)); in dcmi_probe()
2062 dcmi->vdev->release = video_device_release; in dcmi_probe()
2063 dcmi->vdev->ioctl_ops = &dcmi_ioctl_ops; in dcmi_probe()
2064 dcmi->vdev->lock = &dcmi->lock; in dcmi_probe()
2065 dcmi->vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING | in dcmi_probe()
2067 video_set_drvdata(dcmi->vdev, dcmi); in dcmi_probe()
2070 dcmi->vid_cap_pad.flags = MEDIA_PAD_FL_SINK; in dcmi_probe()
2071 ret = media_entity_pads_init(&dcmi->vdev->entity, in dcmi_probe()
2072 1, &dcmi->vid_cap_pad); in dcmi_probe()
2074 dev_err(dcmi->dev, "Failed to init media entity pad\n"); in dcmi_probe()
2077 dcmi->vdev->entity.flags |= MEDIA_ENT_FL_DEFAULT; in dcmi_probe()
2079 ret = video_register_device(dcmi->vdev, VFL_TYPE_VIDEO, -1); in dcmi_probe()
2081 dev_err(dcmi->dev, "Failed to register video device\n"); in dcmi_probe()
2085 dev_dbg(dcmi->dev, "Device registered as %s\n", in dcmi_probe()
2086 video_device_node_name(dcmi->vdev)); in dcmi_probe()
2091 q->lock = &dcmi->lock; in dcmi_probe()
2092 q->drv_priv = dcmi; in dcmi_probe()
2106 ret = dcmi_graph_init(dcmi); in dcmi_probe()
2111 ret = reset_control_assert(dcmi->rstc); in dcmi_probe()
2119 ret = reset_control_deassert(dcmi->rstc); in dcmi_probe()
2127 platform_set_drvdata(pdev, dcmi); in dcmi_probe()
2134 v4l2_async_nf_cleanup(&dcmi->notifier); in dcmi_probe()
2136 media_entity_cleanup(&dcmi->vdev->entity); in dcmi_probe()
2138 video_device_release(dcmi->vdev); in dcmi_probe()
2140 v4l2_device_unregister(&dcmi->v4l2_dev); in dcmi_probe()
2142 media_device_cleanup(&dcmi->mdev); in dcmi_probe()
2143 dma_release_channel(dcmi->dma_chan); in dcmi_probe()
2150 struct stm32_dcmi *dcmi = platform_get_drvdata(pdev); in dcmi_remove() local
2154 v4l2_async_nf_unregister(&dcmi->notifier); in dcmi_remove()
2155 v4l2_async_nf_cleanup(&dcmi->notifier); in dcmi_remove()
2156 media_entity_cleanup(&dcmi->vdev->entity); in dcmi_remove()
2157 v4l2_device_unregister(&dcmi->v4l2_dev); in dcmi_remove()
2158 media_device_cleanup(&dcmi->mdev); in dcmi_remove()
2160 dma_release_channel(dcmi->dma_chan); in dcmi_remove()
2167 struct stm32_dcmi *dcmi = dev_get_drvdata(dev); in dcmi_runtime_suspend() local
2169 clk_disable_unprepare(dcmi->mclk); in dcmi_runtime_suspend()
2176 struct stm32_dcmi *dcmi = dev_get_drvdata(dev); in dcmi_runtime_resume() local
2179 ret = clk_prepare_enable(dcmi->mclk); in dcmi_runtime_resume()