diff options
| author | Sylwester Nawrocki <s.nawrocki@samsung.com> | 2013-12-20 17:35:06 -0500 |
|---|---|---|
| committer | Mauro Carvalho Chehab <m.chehab@samsung.com> | 2014-03-14 09:37:12 -0400 |
| commit | 34947b8aebe3f2d4eceb65fceafa92bf8dc97d96 (patch) | |
| tree | df4846111c30f6dea67c284057daad23aef446d5 | |
| parent | fa91f1056f17c87bc0fa601f80d1b1a4487fd701 (diff) | |
[media] exynos4-is: Add the FIMC-IS ISP capture DMA driver
Add a video capture node for the FIMC-IS ISP IP block. The Exynos4x12
FIMC-IS ISP IP block has 2 DMA interfaces that allow to capture raw
Bayer and YUV data to memory. Currently only the DMA2 output is and
raw Bayer data capture is supported.
Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Acked-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
| -rw-r--r-- | drivers/media/platform/exynos4-is/Kconfig | 9 | ||||
| -rw-r--r-- | drivers/media/platform/exynos4-is/Makefile | 4 | ||||
| -rw-r--r-- | drivers/media/platform/exynos4-is/fimc-is-param.c | 2 | ||||
| -rw-r--r-- | drivers/media/platform/exynos4-is/fimc-is-param.h | 5 | ||||
| -rw-r--r-- | drivers/media/platform/exynos4-is/fimc-is-regs.c | 14 | ||||
| -rw-r--r-- | drivers/media/platform/exynos4-is/fimc-is-regs.h | 1 | ||||
| -rw-r--r-- | drivers/media/platform/exynos4-is/fimc-is.c | 3 | ||||
| -rw-r--r-- | drivers/media/platform/exynos4-is/fimc-is.h | 5 | ||||
| -rw-r--r-- | drivers/media/platform/exynos4-is/fimc-isp-video.c | 660 | ||||
| -rw-r--r-- | drivers/media/platform/exynos4-is/fimc-isp-video.h | 44 | ||||
| -rw-r--r-- | drivers/media/platform/exynos4-is/fimc-isp.c | 29 | ||||
| -rw-r--r-- | drivers/media/platform/exynos4-is/fimc-isp.h | 27 | ||||
| -rw-r--r-- | drivers/media/platform/exynos4-is/media-dev.c | 23 |
13 files changed, 817 insertions, 9 deletions
diff --git a/drivers/media/platform/exynos4-is/Kconfig b/drivers/media/platform/exynos4-is/Kconfig index 01ed1ecdff7e..e1b2ceba00c1 100644 --- a/drivers/media/platform/exynos4-is/Kconfig +++ b/drivers/media/platform/exynos4-is/Kconfig | |||
| @@ -64,4 +64,13 @@ config VIDEO_EXYNOS4_FIMC_IS | |||
| 64 | To compile this driver as a module, choose M here: the | 64 | To compile this driver as a module, choose M here: the |
| 65 | module will be called exynos4-fimc-is. | 65 | module will be called exynos4-fimc-is. |
| 66 | 66 | ||
| 67 | config VIDEO_EXYNOS4_ISP_DMA_CAPTURE | ||
| 68 | bool "EXYNOS4x12 FIMC-IS ISP Direct DMA capture support" | ||
| 69 | depends on VIDEO_EXYNOS4_FIMC_IS | ||
| 70 | select VIDEO_EXYNOS4_IS_COMMON | ||
| 71 | default y | ||
| 72 | help | ||
| 73 | This option enables an additional video device node exposing a V4L2 | ||
| 74 | video capture interface for the FIMC-IS ISP raw (Bayer) capture DMA. | ||
| 75 | |||
| 67 | endif # VIDEO_SAMSUNG_EXYNOS4_IS | 76 | endif # VIDEO_SAMSUNG_EXYNOS4_IS |
diff --git a/drivers/media/platform/exynos4-is/Makefile b/drivers/media/platform/exynos4-is/Makefile index c2ff29ba6856..eed1b185d813 100644 --- a/drivers/media/platform/exynos4-is/Makefile +++ b/drivers/media/platform/exynos4-is/Makefile | |||
| @@ -6,6 +6,10 @@ exynos4-is-common-objs := common.o | |||
| 6 | exynos-fimc-is-objs := fimc-is.o fimc-isp.o fimc-is-sensor.o fimc-is-regs.o | 6 | exynos-fimc-is-objs := fimc-is.o fimc-isp.o fimc-is-sensor.o fimc-is-regs.o |
| 7 | exynos-fimc-is-objs += fimc-is-param.o fimc-is-errno.o fimc-is-i2c.o | 7 | exynos-fimc-is-objs += fimc-is-param.o fimc-is-errno.o fimc-is-i2c.o |
| 8 | 8 | ||
| 9 | ifeq ($(CONFIG_VIDEO_EXYNOS4_ISP_DMA_CAPTURE),y) | ||
| 10 | exynos-fimc-is-objs += fimc-isp-video.o | ||
| 11 | endif | ||
| 12 | |||
| 9 | obj-$(CONFIG_VIDEO_S5P_MIPI_CSIS) += s5p-csis.o | 13 | obj-$(CONFIG_VIDEO_S5P_MIPI_CSIS) += s5p-csis.o |
| 10 | obj-$(CONFIG_VIDEO_EXYNOS_FIMC_LITE) += exynos-fimc-lite.o | 14 | obj-$(CONFIG_VIDEO_EXYNOS_FIMC_LITE) += exynos-fimc-lite.o |
| 11 | obj-$(CONFIG_VIDEO_EXYNOS4_FIMC_IS) += exynos-fimc-is.o | 15 | obj-$(CONFIG_VIDEO_EXYNOS4_FIMC_IS) += exynos-fimc-is.o |
diff --git a/drivers/media/platform/exynos4-is/fimc-is-param.c b/drivers/media/platform/exynos4-is/fimc-is-param.c index 9bf3ddd9e028..bf1465d1bf6d 100644 --- a/drivers/media/platform/exynos4-is/fimc-is-param.c +++ b/drivers/media/platform/exynos4-is/fimc-is-param.c | |||
| @@ -56,7 +56,7 @@ static void __fimc_is_hw_update_param_sensor_framerate(struct fimc_is *is) | |||
| 56 | __hw_param_copy(dst, src); | 56 | __hw_param_copy(dst, src); |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | static int __fimc_is_hw_update_param(struct fimc_is *is, u32 offset) | 59 | int __fimc_is_hw_update_param(struct fimc_is *is, u32 offset) |
| 60 | { | 60 | { |
| 61 | struct is_param_region *par = &is->is_p_region->parameter; | 61 | struct is_param_region *par = &is->is_p_region->parameter; |
| 62 | struct chain_config *cfg = &is->config[is->config_index]; | 62 | struct chain_config *cfg = &is->config[is->config_index]; |
diff --git a/drivers/media/platform/exynos4-is/fimc-is-param.h b/drivers/media/platform/exynos4-is/fimc-is-param.h index f9358c27ae2d..8e31f7642776 100644 --- a/drivers/media/platform/exynos4-is/fimc-is-param.h +++ b/drivers/media/platform/exynos4-is/fimc-is-param.h | |||
| @@ -911,6 +911,10 @@ struct is_region { | |||
| 911 | u32 shared[MAX_SHARED_COUNT]; | 911 | u32 shared[MAX_SHARED_COUNT]; |
| 912 | } __packed; | 912 | } __packed; |
| 913 | 913 | ||
| 914 | /* Offset to the ISP DMA2 output buffer address array. */ | ||
| 915 | #define DMA2_OUTPUT_ADDR_ARRAY_OFFS \ | ||
| 916 | (offsetof(struct is_region, shared) + 32 * sizeof(u32)) | ||
| 917 | |||
| 914 | struct is_debug_frame_descriptor { | 918 | struct is_debug_frame_descriptor { |
| 915 | u32 sensor_frame_time; | 919 | u32 sensor_frame_time; |
| 916 | u32 sensor_exposure_time; | 920 | u32 sensor_exposure_time; |
| @@ -988,6 +992,7 @@ struct sensor_open_extended { | |||
| 988 | struct fimc_is; | 992 | struct fimc_is; |
| 989 | 993 | ||
| 990 | int fimc_is_hw_get_sensor_max_framerate(struct fimc_is *is); | 994 | int fimc_is_hw_get_sensor_max_framerate(struct fimc_is *is); |
| 995 | int __fimc_is_hw_update_param(struct fimc_is *is, u32 offset); | ||
| 991 | void fimc_is_set_initial_params(struct fimc_is *is); | 996 | void fimc_is_set_initial_params(struct fimc_is *is); |
| 992 | unsigned int __get_pending_param_count(struct fimc_is *is); | 997 | unsigned int __get_pending_param_count(struct fimc_is *is); |
| 993 | 998 | ||
diff --git a/drivers/media/platform/exynos4-is/fimc-is-regs.c b/drivers/media/platform/exynos4-is/fimc-is-regs.c index 5c7bd2ac40d2..cfe4406a83ff 100644 --- a/drivers/media/platform/exynos4-is/fimc-is-regs.c +++ b/drivers/media/platform/exynos4-is/fimc-is-regs.c | |||
| @@ -105,6 +105,20 @@ int fimc_is_hw_get_params(struct fimc_is *is, unsigned int num_args) | |||
| 105 | return 0; | 105 | return 0; |
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | void fimc_is_hw_set_isp_buf_mask(struct fimc_is *is, unsigned int mask) | ||
| 109 | { | ||
| 110 | if (hweight32(mask) == 1) { | ||
| 111 | dev_err(&is->pdev->dev, "%s(): not enough buffers (mask %#x)\n", | ||
| 112 | __func__, mask); | ||
| 113 | return; | ||
| 114 | } | ||
| 115 | |||
| 116 | if (mcuctl_read(is, MCUCTL_REG_ISSR(23)) != 0) | ||
| 117 | dev_dbg(&is->pdev->dev, "non-zero DMA buffer mask\n"); | ||
| 118 | |||
| 119 | mcuctl_write(mask, is, MCUCTL_REG_ISSR(23)); | ||
| 120 | } | ||
| 121 | |||
| 108 | void fimc_is_hw_set_sensor_num(struct fimc_is *is) | 122 | void fimc_is_hw_set_sensor_num(struct fimc_is *is) |
| 109 | { | 123 | { |
| 110 | pr_debug("setting sensor index to: %d\n", is->sensor_index); | 124 | pr_debug("setting sensor index to: %d\n", is->sensor_index); |
diff --git a/drivers/media/platform/exynos4-is/fimc-is-regs.h b/drivers/media/platform/exynos4-is/fimc-is-regs.h index 1d9d4ffc6ad5..141e5ddadbeb 100644 --- a/drivers/media/platform/exynos4-is/fimc-is-regs.h +++ b/drivers/media/platform/exynos4-is/fimc-is-regs.h | |||
| @@ -147,6 +147,7 @@ int fimc_is_hw_get_params(struct fimc_is *is, unsigned int num); | |||
| 147 | void fimc_is_hw_set_intgr0_gd0(struct fimc_is *is); | 147 | void fimc_is_hw_set_intgr0_gd0(struct fimc_is *is); |
| 148 | int fimc_is_hw_wait_intmsr0_intmsd0(struct fimc_is *is); | 148 | int fimc_is_hw_wait_intmsr0_intmsd0(struct fimc_is *is); |
| 149 | void fimc_is_hw_set_sensor_num(struct fimc_is *is); | 149 | void fimc_is_hw_set_sensor_num(struct fimc_is *is); |
| 150 | void fimc_is_hw_set_isp_buf_mask(struct fimc_is *is, unsigned int mask); | ||
| 150 | void fimc_is_hw_stream_on(struct fimc_is *is); | 151 | void fimc_is_hw_stream_on(struct fimc_is *is); |
| 151 | void fimc_is_hw_stream_off(struct fimc_is *is); | 152 | void fimc_is_hw_stream_off(struct fimc_is *is); |
| 152 | int fimc_is_hw_set_param(struct fimc_is *is); | 153 | int fimc_is_hw_set_param(struct fimc_is *is); |
diff --git a/drivers/media/platform/exynos4-is/fimc-is.c b/drivers/media/platform/exynos4-is/fimc-is.c index a8f58451e261..c289d5a69d09 100644 --- a/drivers/media/platform/exynos4-is/fimc-is.c +++ b/drivers/media/platform/exynos4-is/fimc-is.c | |||
| @@ -204,6 +204,9 @@ static int fimc_is_register_subdevs(struct fimc_is *is) | |||
| 204 | if (ret < 0) | 204 | if (ret < 0) |
| 205 | return ret; | 205 | return ret; |
| 206 | 206 | ||
| 207 | /* Initialize memory allocator context for the ISP DMA. */ | ||
| 208 | is->isp.alloc_ctx = is->alloc_ctx; | ||
| 209 | |||
| 207 | for_each_compatible_node(i2c_bus, NULL, FIMC_IS_I2C_COMPATIBLE) { | 210 | for_each_compatible_node(i2c_bus, NULL, FIMC_IS_I2C_COMPATIBLE) { |
| 208 | for_each_available_child_of_node(i2c_bus, child) { | 211 | for_each_available_child_of_node(i2c_bus, child) { |
| 209 | ret = fimc_is_parse_sensor_config(is, index, child); | 212 | ret = fimc_is_parse_sensor_config(is, index, child); |
diff --git a/drivers/media/platform/exynos4-is/fimc-is.h b/drivers/media/platform/exynos4-is/fimc-is.h index 01f802f90003..e0be691af2d3 100644 --- a/drivers/media/platform/exynos4-is/fimc-is.h +++ b/drivers/media/platform/exynos4-is/fimc-is.h | |||
| @@ -292,6 +292,11 @@ static inline struct fimc_is *fimc_isp_to_is(struct fimc_isp *isp) | |||
| 292 | return container_of(isp, struct fimc_is, isp); | 292 | return container_of(isp, struct fimc_is, isp); |
| 293 | } | 293 | } |
| 294 | 294 | ||
| 295 | static inline struct chain_config *__get_curr_is_config(struct fimc_is *is) | ||
| 296 | { | ||
| 297 | return &is->config[is->config_index]; | ||
| 298 | } | ||
| 299 | |||
| 295 | static inline void fimc_is_mem_barrier(void) | 300 | static inline void fimc_is_mem_barrier(void) |
| 296 | { | 301 | { |
| 297 | mb(); | 302 | mb(); |
diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c new file mode 100644 index 000000000000..e92b4e115adb --- /dev/null +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c | |||
| @@ -0,0 +1,660 @@ | |||
| 1 | /* | ||
| 2 | * Samsung EXYNOS4x12 FIMC-IS (Imaging Subsystem) driver | ||
| 3 | * | ||
| 4 | * FIMC-IS ISP video input and video output DMA interface driver | ||
| 5 | * | ||
| 6 | * Copyright (C) 2013 Samsung Electronics Co., Ltd. | ||
| 7 | * Author: Sylwester Nawrocki <s.nawrocki@samsung.com> | ||
| 8 | * | ||
| 9 | * The hardware handling code derived from a driver written by | ||
| 10 | * Younghwan Joo <yhwan.joo@samsung.com>. | ||
| 11 | * | ||
| 12 | * This program is free software; you can redistribute it and/or modify | ||
| 13 | * it under the terms of the GNU General Public License version 2 as | ||
| 14 | * published by the Free Software Foundation. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include <linux/bitops.h> | ||
| 18 | #include <linux/device.h> | ||
| 19 | #include <linux/delay.h> | ||
| 20 | #include <linux/errno.h> | ||
| 21 | #include <linux/kernel.h> | ||
| 22 | #include <linux/module.h> | ||
| 23 | #include <linux/types.h> | ||
| 24 | #include <linux/printk.h> | ||
| 25 | #include <linux/pm_runtime.h> | ||
| 26 | #include <linux/slab.h> | ||
| 27 | #include <linux/videodev2.h> | ||
| 28 | |||
| 29 | #include <media/v4l2-device.h> | ||
| 30 | #include <media/v4l2-ioctl.h> | ||
| 31 | #include <media/videobuf2-core.h> | ||
| 32 | #include <media/videobuf2-dma-contig.h> | ||
| 33 | #include <media/s5p_fimc.h> | ||
| 34 | |||
| 35 | #include "common.h" | ||
| 36 | #include "media-dev.h" | ||
| 37 | #include "fimc-is.h" | ||
| 38 | #include "fimc-isp-video.h" | ||
| 39 | #include "fimc-is-param.h" | ||
| 40 | |||
| 41 | static int isp_video_capture_queue_setup(struct vb2_queue *vq, | ||
| 42 | const struct v4l2_format *pfmt, | ||
| 43 | unsigned int *num_buffers, unsigned int *num_planes, | ||
| 44 | unsigned int sizes[], void *allocators[]) | ||
| 45 | { | ||
| 46 | struct fimc_isp *isp = vb2_get_drv_priv(vq); | ||
| 47 | struct v4l2_pix_format_mplane *vid_fmt = &isp->video_capture.pixfmt; | ||
| 48 | const struct v4l2_pix_format_mplane *pixm = NULL; | ||
| 49 | const struct fimc_fmt *fmt; | ||
| 50 | unsigned int wh, i; | ||
| 51 | |||
| 52 | if (pfmt) { | ||
| 53 | pixm = &pfmt->fmt.pix_mp; | ||
| 54 | fmt = fimc_isp_find_format(&pixm->pixelformat, NULL, -1); | ||
| 55 | wh = pixm->width * pixm->height; | ||
| 56 | } else { | ||
| 57 | fmt = isp->video_capture.format; | ||
| 58 | wh = vid_fmt->width * vid_fmt->height; | ||
| 59 | } | ||
| 60 | |||
| 61 | if (fmt == NULL) | ||
| 62 | return -EINVAL; | ||
| 63 | |||
| 64 | *num_buffers = clamp_t(u32, *num_buffers, FIMC_ISP_REQ_BUFS_MIN, | ||
| 65 | FIMC_ISP_REQ_BUFS_MAX); | ||
| 66 | *num_planes = fmt->memplanes; | ||
| 67 | |||
| 68 | for (i = 0; i < fmt->memplanes; i++) { | ||
| 69 | unsigned int size = (wh * fmt->depth[i]) / 8; | ||
| 70 | if (pixm) | ||
| 71 | sizes[i] = max(size, pixm->plane_fmt[i].sizeimage); | ||
| 72 | else | ||
| 73 | sizes[i] = size; | ||
| 74 | allocators[i] = isp->alloc_ctx; | ||
| 75 | } | ||
| 76 | |||
| 77 | return 0; | ||
| 78 | } | ||
| 79 | |||
| 80 | static inline struct param_dma_output *__get_isp_dma2(struct fimc_is *is) | ||
| 81 | { | ||
| 82 | return &__get_curr_is_config(is)->isp.dma2_output; | ||
| 83 | } | ||
| 84 | |||
| 85 | static int isp_video_capture_start_streaming(struct vb2_queue *q, | ||
| 86 | unsigned int count) | ||
| 87 | { | ||
| 88 | struct fimc_isp *isp = vb2_get_drv_priv(q); | ||
| 89 | struct fimc_is *is = fimc_isp_to_is(isp); | ||
| 90 | struct param_dma_output *dma = __get_isp_dma2(is); | ||
| 91 | struct fimc_is_video *video = &isp->video_capture; | ||
| 92 | int ret; | ||
| 93 | |||
| 94 | if (!test_bit(ST_ISP_VID_CAP_BUF_PREP, &isp->state) || | ||
| 95 | test_bit(ST_ISP_VID_CAP_STREAMING, &isp->state)) | ||
| 96 | return 0; | ||
| 97 | |||
| 98 | |||
| 99 | dma->cmd = DMA_OUTPUT_COMMAND_ENABLE; | ||
| 100 | dma->notify_dma_done = DMA_OUTPUT_NOTIFY_DMA_DONE_ENABLE; | ||
| 101 | dma->buffer_address = is->is_dma_p_region + | ||
| 102 | DMA2_OUTPUT_ADDR_ARRAY_OFFS; | ||
| 103 | dma->buffer_number = video->reqbufs_count; | ||
| 104 | dma->dma_out_mask = video->buf_mask; | ||
| 105 | |||
| 106 | isp_dbg(2, &video->ve.vdev, | ||
| 107 | "buf_count: %d, planes: %d, dma addr table: %#x\n", | ||
| 108 | video->buf_count, video->format->memplanes, | ||
| 109 | dma->buffer_address); | ||
| 110 | |||
| 111 | fimc_is_mem_barrier(); | ||
| 112 | |||
| 113 | fimc_is_set_param_bit(is, PARAM_ISP_DMA2_OUTPUT); | ||
| 114 | __fimc_is_hw_update_param(is, PARAM_ISP_DMA2_OUTPUT); | ||
| 115 | |||
| 116 | ret = fimc_is_itf_s_param(is, false); | ||
| 117 | if (ret < 0) | ||
| 118 | return ret; | ||
| 119 | |||
| 120 | ret = fimc_pipeline_call(&video->ve, set_stream, 1); | ||
| 121 | if (ret < 0) | ||
| 122 | return ret; | ||
| 123 | |||
| 124 | set_bit(ST_ISP_VID_CAP_STREAMING, &isp->state); | ||
| 125 | return ret; | ||
| 126 | } | ||
| 127 | |||
| 128 | static int isp_video_capture_stop_streaming(struct vb2_queue *q) | ||
| 129 | { | ||
| 130 | struct fimc_isp *isp = vb2_get_drv_priv(q); | ||
| 131 | struct fimc_is *is = fimc_isp_to_is(isp); | ||
| 132 | struct param_dma_output *dma = __get_isp_dma2(is); | ||
| 133 | int ret; | ||
| 134 | |||
| 135 | ret = fimc_pipeline_call(&isp->video_capture.ve, set_stream, 0); | ||
| 136 | if (ret < 0) | ||
| 137 | return ret; | ||
| 138 | |||
| 139 | dma->cmd = DMA_OUTPUT_COMMAND_DISABLE; | ||
| 140 | dma->notify_dma_done = DMA_OUTPUT_NOTIFY_DMA_DONE_DISABLE; | ||
| 141 | dma->buffer_number = 0; | ||
| 142 | dma->buffer_address = 0; | ||
| 143 | dma->dma_out_mask = 0; | ||
| 144 | |||
| 145 | fimc_is_set_param_bit(is, PARAM_ISP_DMA2_OUTPUT); | ||
| 146 | __fimc_is_hw_update_param(is, PARAM_ISP_DMA2_OUTPUT); | ||
| 147 | |||
| 148 | ret = fimc_is_itf_s_param(is, false); | ||
| 149 | if (ret < 0) | ||
| 150 | dev_warn(&is->pdev->dev, "%s: DMA stop failed\n", __func__); | ||
| 151 | |||
| 152 | fimc_is_hw_set_isp_buf_mask(is, 0); | ||
| 153 | |||
| 154 | clear_bit(ST_ISP_VID_CAP_BUF_PREP, &isp->state); | ||
| 155 | clear_bit(ST_ISP_VID_CAP_STREAMING, &isp->state); | ||
| 156 | |||
| 157 | isp->video_capture.buf_count = 0; | ||
| 158 | return 0; | ||
| 159 | } | ||
| 160 | |||
| 161 | static int isp_video_capture_buffer_prepare(struct vb2_buffer *vb) | ||
| 162 | { | ||
| 163 | struct fimc_isp *isp = vb2_get_drv_priv(vb->vb2_queue); | ||
| 164 | struct fimc_is_video *video = &isp->video_capture; | ||
| 165 | int i; | ||
| 166 | |||
| 167 | if (video->format == NULL) | ||
| 168 | return -EINVAL; | ||
| 169 | |||
| 170 | for (i = 0; i < video->format->memplanes; i++) { | ||
| 171 | unsigned long size = video->pixfmt.plane_fmt[i].sizeimage; | ||
| 172 | |||
| 173 | if (vb2_plane_size(vb, i) < size) { | ||
| 174 | v4l2_err(&video->ve.vdev, | ||
| 175 | "User buffer too small (%ld < %ld)\n", | ||
| 176 | vb2_plane_size(vb, i), size); | ||
| 177 | return -EINVAL; | ||
| 178 | } | ||
| 179 | vb2_set_plane_payload(vb, i, size); | ||
| 180 | } | ||
| 181 | |||
| 182 | /* Check if we get one of the already known buffers. */ | ||
| 183 | if (test_bit(ST_ISP_VID_CAP_BUF_PREP, &isp->state)) { | ||
| 184 | dma_addr_t dma_addr = vb2_dma_contig_plane_dma_addr(vb, 0); | ||
| 185 | int i; | ||
| 186 | |||
| 187 | for (i = 0; i < video->buf_count; i++) | ||
| 188 | if (video->buffers[i]->dma_addr[0] == dma_addr) | ||
| 189 | return 0; | ||
| 190 | return -ENXIO; | ||
| 191 | } | ||
| 192 | |||
| 193 | return 0; | ||
| 194 | } | ||
| 195 | |||
| 196 | static void isp_video_capture_buffer_queue(struct vb2_buffer *vb) | ||
| 197 | { | ||
| 198 | struct fimc_isp *isp = vb2_get_drv_priv(vb->vb2_queue); | ||
| 199 | struct fimc_is_video *video = &isp->video_capture; | ||
| 200 | struct fimc_is *is = fimc_isp_to_is(isp); | ||
| 201 | struct isp_video_buf *ivb = to_isp_video_buf(vb); | ||
| 202 | unsigned long flags; | ||
| 203 | unsigned int i; | ||
| 204 | |||
| 205 | if (test_bit(ST_ISP_VID_CAP_BUF_PREP, &isp->state)) { | ||
| 206 | spin_lock_irqsave(&is->slock, flags); | ||
| 207 | video->buf_mask |= BIT(ivb->index); | ||
| 208 | spin_unlock_irqrestore(&is->slock, flags); | ||
| 209 | } else { | ||
| 210 | unsigned int num_planes = video->format->memplanes; | ||
| 211 | |||
| 212 | ivb->index = video->buf_count; | ||
| 213 | video->buffers[ivb->index] = ivb; | ||
| 214 | |||
| 215 | for (i = 0; i < num_planes; i++) { | ||
| 216 | int buf_index = ivb->index * num_planes + i; | ||
| 217 | |||
| 218 | ivb->dma_addr[i] = vb2_dma_contig_plane_dma_addr(vb, i); | ||
| 219 | is->is_p_region->shared[32 + buf_index] = | ||
| 220 | ivb->dma_addr[i]; | ||
| 221 | |||
| 222 | isp_dbg(2, &video->ve.vdev, | ||
| 223 | "dma_buf %d (%d/%d/%d) addr: %#x\n", | ||
| 224 | buf_index, ivb->index, i, vb->v4l2_buf.index, | ||
| 225 | ivb->dma_addr[i]); | ||
| 226 | } | ||
| 227 | |||
| 228 | if (++video->buf_count < video->reqbufs_count) | ||
| 229 | return; | ||
| 230 | |||
| 231 | video->buf_mask = (1UL << video->buf_count) - 1; | ||
| 232 | set_bit(ST_ISP_VID_CAP_BUF_PREP, &isp->state); | ||
| 233 | } | ||
| 234 | |||
| 235 | if (!test_bit(ST_ISP_VID_CAP_STREAMING, &isp->state)) | ||
| 236 | isp_video_capture_start_streaming(vb->vb2_queue, 0); | ||
| 237 | } | ||
| 238 | |||
| 239 | /* | ||
| 240 | * FIMC-IS ISP input and output DMA interface interrupt handler. | ||
| 241 | * Locking: called with is->slock spinlock held. | ||
| 242 | */ | ||
| 243 | void fimc_isp_video_irq_handler(struct fimc_is *is) | ||
| 244 | { | ||
| 245 | struct fimc_is_video *video = &is->isp.video_capture; | ||
| 246 | struct vb2_buffer *vb; | ||
| 247 | int buf_index; | ||
| 248 | |||
| 249 | /* TODO: Ensure the DMA is really stopped in stop_streaming callback */ | ||
| 250 | if (!test_bit(ST_ISP_VID_CAP_STREAMING, &is->isp.state)) | ||
| 251 | return; | ||
| 252 | |||
| 253 | buf_index = (is->i2h_cmd.args[1] - 1) % video->buf_count; | ||
| 254 | vb = &video->buffers[buf_index]->vb; | ||
| 255 | |||
| 256 | v4l2_get_timestamp(&vb->v4l2_buf.timestamp); | ||
| 257 | vb2_buffer_done(vb, VB2_BUF_STATE_DONE); | ||
| 258 | |||
| 259 | video->buf_mask &= ~BIT(buf_index); | ||
| 260 | fimc_is_hw_set_isp_buf_mask(is, video->buf_mask); | ||
| 261 | } | ||
| 262 | |||
| 263 | static const struct vb2_ops isp_video_capture_qops = { | ||
| 264 | .queue_setup = isp_video_capture_queue_setup, | ||
| 265 | .buf_prepare = isp_video_capture_buffer_prepare, | ||
| 266 | .buf_queue = isp_video_capture_buffer_queue, | ||
| 267 | .wait_prepare = vb2_ops_wait_prepare, | ||
| 268 | .wait_finish = vb2_ops_wait_finish, | ||
| 269 | .start_streaming = isp_video_capture_start_streaming, | ||
| 270 | .stop_streaming = isp_video_capture_stop_streaming, | ||
| 271 | }; | ||
| 272 | |||
| 273 | static int isp_video_open(struct file *file) | ||
| 274 | { | ||
| 275 | struct fimc_isp *isp = video_drvdata(file); | ||
| 276 | struct exynos_video_entity *ve = &isp->video_capture.ve; | ||
| 277 | struct media_entity *me = &ve->vdev.entity; | ||
| 278 | int ret; | ||
| 279 | |||
| 280 | if (mutex_lock_interruptible(&isp->video_lock)) | ||
| 281 | return -ERESTARTSYS; | ||
| 282 | |||
| 283 | ret = v4l2_fh_open(file); | ||
| 284 | if (ret < 0) | ||
| 285 | goto unlock; | ||
| 286 | |||
| 287 | ret = pm_runtime_get_sync(&isp->pdev->dev); | ||
| 288 | if (ret < 0) | ||
| 289 | goto rel_fh; | ||
| 290 | |||
| 291 | if (v4l2_fh_is_singular_file(file)) { | ||
| 292 | mutex_lock(&me->parent->graph_mutex); | ||
| 293 | |||
| 294 | ret = fimc_pipeline_call(ve, open, me, true); | ||
| 295 | |||
| 296 | /* Mark the video pipeline as in use. */ | ||
| 297 | if (ret == 0) | ||
| 298 | me->use_count++; | ||
| 299 | |||
| 300 | mutex_unlock(&me->parent->graph_mutex); | ||
| 301 | } | ||
| 302 | if (!ret) | ||
| 303 | goto unlock; | ||
| 304 | rel_fh: | ||
| 305 | v4l2_fh_release(file); | ||
| 306 | unlock: | ||
| 307 | mutex_unlock(&isp->video_lock); | ||
| 308 | return ret; | ||
| 309 | } | ||
| 310 | |||
| 311 | static int isp_video_release(struct file *file) | ||
| 312 | { | ||
| 313 | struct fimc_isp *isp = video_drvdata(file); | ||
| 314 | struct fimc_is_video *ivc = &isp->video_capture; | ||
| 315 | struct media_entity *entity = &ivc->ve.vdev.entity; | ||
| 316 | struct media_device *mdev = entity->parent; | ||
| 317 | int ret = 0; | ||
| 318 | |||
| 319 | mutex_lock(&isp->video_lock); | ||
| 320 | |||
| 321 | if (v4l2_fh_is_singular_file(file) && ivc->streaming) { | ||
| 322 | media_entity_pipeline_stop(entity); | ||
| 323 | ivc->streaming = 0; | ||
| 324 | } | ||
| 325 | |||
| 326 | vb2_fop_release(file); | ||
| 327 | |||
| 328 | if (v4l2_fh_is_singular_file(file)) { | ||
| 329 | fimc_pipeline_call(&ivc->ve, close); | ||
| 330 | |||
| 331 | mutex_lock(&mdev->graph_mutex); | ||
| 332 | entity->use_count--; | ||
| 333 | mutex_unlock(&mdev->graph_mutex); | ||
| 334 | } | ||
| 335 | |||
| 336 | pm_runtime_put(&isp->pdev->dev); | ||
| 337 | mutex_unlock(&isp->video_lock); | ||
| 338 | |||
| 339 | return ret; | ||
| 340 | } | ||
| 341 | |||
| 342 | static const struct v4l2_file_operations isp_video_fops = { | ||
| 343 | .owner = THIS_MODULE, | ||
| 344 | .open = isp_video_open, | ||
| 345 | .release = isp_video_release, | ||
| 346 | .poll = vb2_fop_poll, | ||
| 347 | .unlocked_ioctl = video_ioctl2, | ||
| 348 | .mmap = vb2_fop_mmap, | ||
| 349 | }; | ||
| 350 | |||
| 351 | /* | ||
| 352 | * Video node ioctl operations | ||
| 353 | */ | ||
| 354 | static int isp_video_querycap(struct file *file, void *priv, | ||
| 355 | struct v4l2_capability *cap) | ||
| 356 | { | ||
| 357 | struct fimc_isp *isp = video_drvdata(file); | ||
| 358 | |||
| 359 | __fimc_vidioc_querycap(&isp->pdev->dev, cap, V4L2_CAP_STREAMING); | ||
| 360 | return 0; | ||
| 361 | } | ||
| 362 | |||
| 363 | static int isp_video_enum_fmt_mplane(struct file *file, void *priv, | ||
| 364 | struct v4l2_fmtdesc *f) | ||
| 365 | { | ||
| 366 | const struct fimc_fmt *fmt; | ||
| 367 | |||
| 368 | if (f->index >= FIMC_ISP_NUM_FORMATS) | ||
| 369 | return -EINVAL; | ||
| 370 | |||
| 371 | fmt = fimc_isp_find_format(NULL, NULL, f->index); | ||
| 372 | if (WARN_ON(fmt == NULL)) | ||
| 373 | return -EINVAL; | ||
| 374 | |||
| 375 | strlcpy(f->description, fmt->name, sizeof(f->description)); | ||
| 376 | f->pixelformat = fmt->fourcc; | ||
| 377 | |||
| 378 | return 0; | ||
| 379 | } | ||
| 380 | |||
| 381 | static int isp_video_g_fmt_mplane(struct file *file, void *fh, | ||
| 382 | struct v4l2_format *f) | ||
| 383 | { | ||
| 384 | struct fimc_isp *isp = video_drvdata(file); | ||
| 385 | |||
| 386 | f->fmt.pix_mp = isp->video_capture.pixfmt; | ||
| 387 | return 0; | ||
| 388 | } | ||
| 389 | |||
| 390 | static void __isp_video_try_fmt(struct fimc_isp *isp, | ||
| 391 | struct v4l2_pix_format_mplane *pixm, | ||
| 392 | const struct fimc_fmt **fmt) | ||
| 393 | { | ||
| 394 | *fmt = fimc_isp_find_format(&pixm->pixelformat, NULL, 2); | ||
| 395 | |||
| 396 | pixm->colorspace = V4L2_COLORSPACE_SRGB; | ||
| 397 | pixm->field = V4L2_FIELD_NONE; | ||
| 398 | pixm->num_planes = (*fmt)->memplanes; | ||
| 399 | pixm->pixelformat = (*fmt)->fourcc; | ||
| 400 | /* | ||
| 401 | * TODO: double check with the docmentation these width/height | ||
| 402 | * constraints are correct. | ||
| 403 | */ | ||
| 404 | v4l_bound_align_image(&pixm->width, FIMC_ISP_SOURCE_WIDTH_MIN, | ||
| 405 | FIMC_ISP_SOURCE_WIDTH_MAX, 3, | ||
| 406 | &pixm->height, FIMC_ISP_SOURCE_HEIGHT_MIN, | ||
| 407 | FIMC_ISP_SOURCE_HEIGHT_MAX, 0, 0); | ||
| 408 | } | ||
| 409 | |||
| 410 | static int isp_video_try_fmt_mplane(struct file *file, void *fh, | ||
| 411 | struct v4l2_format *f) | ||
| 412 | { | ||
| 413 | struct fimc_isp *isp = video_drvdata(file); | ||
| 414 | |||
| 415 | __isp_video_try_fmt(isp, &f->fmt.pix_mp, NULL); | ||
| 416 | return 0; | ||
| 417 | } | ||
| 418 | |||
| 419 | static int isp_video_s_fmt_mplane(struct file *file, void *priv, | ||
| 420 | struct v4l2_format *f) | ||
| 421 | { | ||
| 422 | struct fimc_isp *isp = video_drvdata(file); | ||
| 423 | struct fimc_is *is = fimc_isp_to_is(isp); | ||
| 424 | struct v4l2_pix_format_mplane *pixm = &f->fmt.pix_mp; | ||
| 425 | const struct fimc_fmt *ifmt = NULL; | ||
| 426 | struct param_dma_output *dma = __get_isp_dma2(is); | ||
| 427 | |||
| 428 | __isp_video_try_fmt(isp, pixm, &ifmt); | ||
| 429 | |||
| 430 | if (WARN_ON(ifmt == NULL)) | ||
| 431 | return -EINVAL; | ||
| 432 | |||
| 433 | dma->format = DMA_OUTPUT_FORMAT_BAYER; | ||
| 434 | dma->order = DMA_OUTPUT_ORDER_GB_BG; | ||
| 435 | dma->plane = ifmt->memplanes; | ||
| 436 | dma->bitwidth = ifmt->depth[0]; | ||
| 437 | dma->width = pixm->width; | ||
| 438 | dma->height = pixm->height; | ||
| 439 | |||
| 440 | fimc_is_mem_barrier(); | ||
| 441 | |||
| 442 | isp->video_capture.format = ifmt; | ||
| 443 | isp->video_capture.pixfmt = *pixm; | ||
| 444 | |||
| 445 | return 0; | ||
| 446 | } | ||
| 447 | |||
| 448 | /* | ||
| 449 | * Check for source/sink format differences at each link. | ||
| 450 | * Return 0 if the formats match or -EPIPE otherwise. | ||
| 451 | */ | ||
| 452 | static int isp_video_pipeline_validate(struct fimc_isp *isp) | ||
| 453 | { | ||
| 454 | struct v4l2_subdev *sd = &isp->subdev; | ||
| 455 | struct v4l2_subdev_format sink_fmt, src_fmt; | ||
| 456 | struct media_pad *pad; | ||
| 457 | int ret; | ||
| 458 | |||
| 459 | while (1) { | ||
| 460 | /* Retrieve format at the sink pad */ | ||
| 461 | pad = &sd->entity.pads[0]; | ||
| 462 | if (!(pad->flags & MEDIA_PAD_FL_SINK)) | ||
| 463 | break; | ||
| 464 | sink_fmt.pad = pad->index; | ||
| 465 | sink_fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE; | ||
| 466 | ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &sink_fmt); | ||
| 467 | if (ret < 0 && ret != -ENOIOCTLCMD) | ||
| 468 | return -EPIPE; | ||
| 469 | |||
| 470 | /* Retrieve format at the source pad */ | ||
| 471 | pad = media_entity_remote_pad(pad); | ||
| 472 | if (pad == NULL || | ||
| 473 | media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV) | ||
| 474 | break; | ||
| 475 | |||
| 476 | sd = media_entity_to_v4l2_subdev(pad->entity); | ||
| 477 | src_fmt.pad = pad->index; | ||
| 478 | src_fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE; | ||
| 479 | ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &src_fmt); | ||
| 480 | if (ret < 0 && ret != -ENOIOCTLCMD) | ||
| 481 | return -EPIPE; | ||
| 482 | |||
| 483 | if (src_fmt.format.width != sink_fmt.format.width || | ||
| 484 | src_fmt.format.height != sink_fmt.format.height || | ||
| 485 | src_fmt.format.code != sink_fmt.format.code) | ||
| 486 | return -EPIPE; | ||
| 487 | } | ||
| 488 | |||
| 489 | return 0; | ||
| 490 | } | ||
| 491 | |||
| 492 | static int isp_video_streamon(struct file *file, void *priv, | ||
| 493 | enum v4l2_buf_type type) | ||
| 494 | { | ||
| 495 | struct fimc_isp *isp = video_drvdata(file); | ||
| 496 | struct exynos_video_entity *ve = &isp->video_capture.ve; | ||
| 497 | struct media_entity *me = &ve->vdev.entity; | ||
| 498 | int ret; | ||
| 499 | |||
| 500 | ret = media_entity_pipeline_start(me, &ve->pipe->mp); | ||
| 501 | if (ret < 0) | ||
| 502 | return ret; | ||
| 503 | |||
| 504 | ret = isp_video_pipeline_validate(isp); | ||
| 505 | if (ret < 0) | ||
| 506 | goto p_stop; | ||
| 507 | |||
| 508 | ret = vb2_ioctl_streamon(file, priv, type); | ||
| 509 | if (ret < 0) | ||
| 510 | goto p_stop; | ||
| 511 | |||
| 512 | isp->video_capture.streaming = 1; | ||
| 513 | return 0; | ||
| 514 | p_stop: | ||
| 515 | media_entity_pipeline_stop(me); | ||
| 516 | return ret; | ||
| 517 | } | ||
| 518 | |||
| 519 | static int isp_video_streamoff(struct file *file, void *priv, | ||
| 520 | enum v4l2_buf_type type) | ||
| 521 | { | ||
| 522 | struct fimc_isp *isp = video_drvdata(file); | ||
| 523 | struct fimc_is_video *video = &isp->video_capture; | ||
| 524 | int ret; | ||
| 525 | |||
| 526 | ret = vb2_ioctl_streamoff(file, priv, type); | ||
| 527 | if (ret < 0) | ||
| 528 | return ret; | ||
| 529 | |||
| 530 | media_entity_pipeline_stop(&video->ve.vdev.entity); | ||
| 531 | video->streaming = 0; | ||
| 532 | return 0; | ||
| 533 | } | ||
| 534 | |||
| 535 | static int isp_video_reqbufs(struct file *file, void *priv, | ||
| 536 | struct v4l2_requestbuffers *rb) | ||
| 537 | { | ||
| 538 | struct fimc_isp *isp = video_drvdata(file); | ||
| 539 | int ret; | ||
| 540 | |||
| 541 | ret = vb2_ioctl_reqbufs(file, priv, rb); | ||
| 542 | if (ret < 0) | ||
| 543 | return ret; | ||
| 544 | |||
| 545 | if (rb->count && rb->count < FIMC_ISP_REQ_BUFS_MIN) { | ||
| 546 | rb->count = 0; | ||
| 547 | vb2_ioctl_reqbufs(file, priv, rb); | ||
| 548 | ret = -ENOMEM; | ||
| 549 | } | ||
| 550 | |||
| 551 | isp->video_capture.reqbufs_count = rb->count; | ||
| 552 | return ret; | ||
| 553 | } | ||
| 554 | |||
| 555 | static const struct v4l2_ioctl_ops isp_video_ioctl_ops = { | ||
| 556 | .vidioc_querycap = isp_video_querycap, | ||
| 557 | .vidioc_enum_fmt_vid_cap_mplane = isp_video_enum_fmt_mplane, | ||
| 558 | .vidioc_try_fmt_vid_cap_mplane = isp_video_try_fmt_mplane, | ||
| 559 | .vidioc_s_fmt_vid_cap_mplane = isp_video_s_fmt_mplane, | ||
| 560 | .vidioc_g_fmt_vid_cap_mplane = isp_video_g_fmt_mplane, | ||
| 561 | .vidioc_reqbufs = isp_video_reqbufs, | ||
| 562 | .vidioc_querybuf = vb2_ioctl_querybuf, | ||
| 563 | .vidioc_prepare_buf = vb2_ioctl_prepare_buf, | ||
| 564 | .vidioc_create_bufs = vb2_ioctl_create_bufs, | ||
| 565 | .vidioc_qbuf = vb2_ioctl_qbuf, | ||
| 566 | .vidioc_dqbuf = vb2_ioctl_dqbuf, | ||
| 567 | .vidioc_streamon = isp_video_streamon, | ||
| 568 | .vidioc_streamoff = isp_video_streamoff, | ||
| 569 | }; | ||
| 570 | |||
| 571 | int fimc_isp_video_device_register(struct fimc_isp *isp, | ||
| 572 | struct v4l2_device *v4l2_dev, | ||
| 573 | enum v4l2_buf_type type) | ||
| 574 | { | ||
| 575 | struct vb2_queue *q = &isp->video_capture.vb_queue; | ||
| 576 | struct fimc_is_video *iv; | ||
| 577 | struct video_device *vdev; | ||
| 578 | int ret; | ||
| 579 | |||
| 580 | if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) | ||
| 581 | iv = &isp->video_capture; | ||
| 582 | else | ||
| 583 | return -ENOSYS; | ||
| 584 | |||
| 585 | mutex_init(&isp->video_lock); | ||
| 586 | INIT_LIST_HEAD(&iv->pending_buf_q); | ||
| 587 | INIT_LIST_HEAD(&iv->active_buf_q); | ||
| 588 | iv->format = fimc_isp_find_format(NULL, NULL, 0); | ||
| 589 | iv->pixfmt.width = IS_DEFAULT_WIDTH; | ||
| 590 | iv->pixfmt.height = IS_DEFAULT_HEIGHT; | ||
| 591 | iv->pixfmt.pixelformat = iv->format->fourcc; | ||
| 592 | iv->pixfmt.colorspace = V4L2_COLORSPACE_SRGB; | ||
| 593 | iv->reqbufs_count = 0; | ||
| 594 | |||
| 595 | memset(q, 0, sizeof(*q)); | ||
| 596 | q->type = type; | ||
| 597 | q->io_modes = VB2_MMAP | VB2_USERPTR; | ||
| 598 | q->ops = &isp_video_capture_qops; | ||
| 599 | q->mem_ops = &vb2_dma_contig_memops; | ||
| 600 | q->buf_struct_size = sizeof(struct isp_video_buf); | ||
| 601 | q->drv_priv = isp; | ||
| 602 | q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; | ||
| 603 | q->lock = &isp->video_lock; | ||
| 604 | |||
| 605 | ret = vb2_queue_init(q); | ||
| 606 | if (ret < 0) | ||
| 607 | return ret; | ||
| 608 | |||
| 609 | vdev = &iv->ve.vdev; | ||
| 610 | memset(vdev, 0, sizeof(*vdev)); | ||
| 611 | snprintf(vdev->name, sizeof(vdev->name), "fimc-is-isp.%s", | ||
| 612 | type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ? | ||
| 613 | "capture" : "output"); | ||
| 614 | vdev->queue = q; | ||
| 615 | vdev->fops = &isp_video_fops; | ||
| 616 | vdev->ioctl_ops = &isp_video_ioctl_ops; | ||
| 617 | vdev->v4l2_dev = v4l2_dev; | ||
| 618 | vdev->minor = -1; | ||
| 619 | vdev->release = video_device_release_empty; | ||
| 620 | vdev->lock = &isp->video_lock; | ||
| 621 | |||
| 622 | iv->pad.flags = MEDIA_PAD_FL_SINK; | ||
| 623 | ret = media_entity_init(&vdev->entity, 1, &iv->pad, 0); | ||
| 624 | if (ret < 0) | ||
| 625 | return ret; | ||
| 626 | |||
| 627 | video_set_drvdata(vdev, isp); | ||
| 628 | |||
| 629 | ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1); | ||
| 630 | if (ret < 0) { | ||
| 631 | media_entity_cleanup(&vdev->entity); | ||
| 632 | return ret; | ||
| 633 | } | ||
| 634 | |||
| 635 | v4l2_info(v4l2_dev, "Registered %s as /dev/%s\n", | ||
| 636 | vdev->name, video_device_node_name(vdev)); | ||
| 637 | |||
| 638 | return 0; | ||
| 639 | } | ||
| 640 | |||
| 641 | void fimc_isp_video_device_unregister(struct fimc_isp *isp, | ||
| 642 | enum v4l2_buf_type type) | ||
| 643 | { | ||
| 644 | struct exynos_video_entity *ve; | ||
| 645 | |||
| 646 | if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) | ||
| 647 | ve = &isp->video_capture.ve; | ||
| 648 | else | ||
| 649 | return; | ||
| 650 | |||
| 651 | mutex_lock(&isp->video_lock); | ||
| 652 | |||
| 653 | if (video_is_registered(&ve->vdev)) { | ||
| 654 | video_unregister_device(&ve->vdev); | ||
| 655 | media_entity_cleanup(&ve->vdev.entity); | ||
| 656 | ve->pipe = NULL; | ||
| 657 | } | ||
| 658 | |||
| 659 | mutex_unlock(&isp->video_lock); | ||
| 660 | } | ||
diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.h b/drivers/media/platform/exynos4-is/fimc-isp-video.h new file mode 100644 index 000000000000..98c662654bb6 --- /dev/null +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.h | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | /* | ||
| 2 | * Samsung EXYNOS4x12 FIMC-IS (Imaging Subsystem) driver | ||
| 3 | * | ||
| 4 | * Copyright (C) 2013 Samsung Electronics Co., Ltd. | ||
| 5 | * Sylwester Nawrocki <s.nawrocki@samsung.com> | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify | ||
| 8 | * it under the terms of the GNU General Public License version 2 as | ||
| 9 | * published by the Free Software Foundation. | ||
| 10 | */ | ||
| 11 | #ifndef FIMC_ISP_VIDEO__ | ||
| 12 | #define FIMC_ISP_VIDEO__ | ||
| 13 | |||
| 14 | #include <media/videobuf2-core.h> | ||
| 15 | #include "fimc-isp.h" | ||
| 16 | |||
| 17 | #ifdef CONFIG_VIDEO_EXYNOS4_ISP_DMA_CAPTURE | ||
| 18 | int fimc_isp_video_device_register(struct fimc_isp *isp, | ||
| 19 | struct v4l2_device *v4l2_dev, | ||
| 20 | enum v4l2_buf_type type); | ||
| 21 | |||
| 22 | void fimc_isp_video_device_unregister(struct fimc_isp *isp, | ||
| 23 | enum v4l2_buf_type type); | ||
| 24 | |||
| 25 | void fimc_isp_video_irq_handler(struct fimc_is *is); | ||
| 26 | #else | ||
| 27 | static inline void fimc_isp_video_irq_handler(struct fimc_is *is) | ||
| 28 | { | ||
| 29 | } | ||
| 30 | |||
| 31 | static inline int fimc_isp_video_device_register(struct fimc_isp *isp, | ||
| 32 | struct v4l2_device *v4l2_dev, | ||
| 33 | enum v4l2_buf_type type) | ||
| 34 | { | ||
| 35 | return 0; | ||
| 36 | } | ||
| 37 | |||
| 38 | void fimc_isp_video_device_unregister(struct fimc_isp *isp, | ||
| 39 | enum v4l2_buf_type type) | ||
| 40 | { | ||
| 41 | } | ||
| 42 | #endif /* !CONFIG_VIDEO_EXYNOS4_ISP_DMA_CAPTURE */ | ||
| 43 | |||
| 44 | #endif /* FIMC_ISP_VIDEO__ */ | ||
diff --git a/drivers/media/platform/exynos4-is/fimc-isp.c b/drivers/media/platform/exynos4-is/fimc-isp.c index f3c6136aa5b4..be62d6b9ac48 100644 --- a/drivers/media/platform/exynos4-is/fimc-isp.c +++ b/drivers/media/platform/exynos4-is/fimc-isp.c | |||
| @@ -25,6 +25,7 @@ | |||
| 25 | #include <media/v4l2-device.h> | 25 | #include <media/v4l2-device.h> |
| 26 | 26 | ||
| 27 | #include "media-dev.h" | 27 | #include "media-dev.h" |
| 28 | #include "fimc-isp-video.h" | ||
| 28 | #include "fimc-is-command.h" | 29 | #include "fimc-is-command.h" |
| 29 | #include "fimc-is-param.h" | 30 | #include "fimc-is-param.h" |
| 30 | #include "fimc-is-regs.h" | 31 | #include "fimc-is-regs.h" |
| @@ -93,8 +94,8 @@ void fimc_isp_irq_handler(struct fimc_is *is) | |||
| 93 | is->i2h_cmd.args[1] = mcuctl_read(is, MCUCTL_REG_ISSR(21)); | 94 | is->i2h_cmd.args[1] = mcuctl_read(is, MCUCTL_REG_ISSR(21)); |
| 94 | 95 | ||
| 95 | fimc_is_fw_clear_irq1(is, FIMC_IS_INT_FRAME_DONE_ISP); | 96 | fimc_is_fw_clear_irq1(is, FIMC_IS_INT_FRAME_DONE_ISP); |
| 97 | fimc_isp_video_irq_handler(is); | ||
| 96 | 98 | ||
| 97 | /* TODO: Complete ISP DMA interrupt handler */ | ||
| 98 | wake_up(&is->irq_queue); | 99 | wake_up(&is->irq_queue); |
| 99 | } | 100 | } |
| 100 | 101 | ||
| @@ -388,7 +389,33 @@ static int fimc_isp_subdev_open(struct v4l2_subdev *sd, | |||
| 388 | return 0; | 389 | return 0; |
| 389 | } | 390 | } |
| 390 | 391 | ||
| 392 | static int fimc_isp_subdev_registered(struct v4l2_subdev *sd) | ||
| 393 | { | ||
| 394 | struct fimc_isp *isp = v4l2_get_subdevdata(sd); | ||
| 395 | int ret; | ||
| 396 | |||
| 397 | /* Use pipeline object allocated by the media device. */ | ||
| 398 | isp->video_capture.ve.pipe = v4l2_get_subdev_hostdata(sd); | ||
| 399 | |||
| 400 | ret = fimc_isp_video_device_register(isp, sd->v4l2_dev, | ||
| 401 | V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); | ||
| 402 | if (ret < 0) | ||
| 403 | isp->video_capture.ve.pipe = NULL; | ||
| 404 | |||
| 405 | return ret; | ||
| 406 | } | ||
| 407 | |||
| 408 | static void fimc_isp_subdev_unregistered(struct v4l2_subdev *sd) | ||
| 409 | { | ||
| 410 | struct fimc_isp *isp = v4l2_get_subdevdata(sd); | ||
| 411 | |||
| 412 | fimc_isp_video_device_unregister(isp, | ||
| 413 | V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); | ||
| 414 | } | ||
| 415 | |||
| 391 | static const struct v4l2_subdev_internal_ops fimc_is_subdev_internal_ops = { | 416 | static const struct v4l2_subdev_internal_ops fimc_is_subdev_internal_ops = { |
| 417 | .registered = fimc_isp_subdev_registered, | ||
| 418 | .unregistered = fimc_isp_subdev_unregistered, | ||
| 392 | .open = fimc_isp_subdev_open, | 419 | .open = fimc_isp_subdev_open, |
| 393 | }; | 420 | }; |
| 394 | 421 | ||
diff --git a/drivers/media/platform/exynos4-is/fimc-isp.h b/drivers/media/platform/exynos4-is/fimc-isp.h index 03bf95ab017b..4dc55a18d978 100644 --- a/drivers/media/platform/exynos4-is/fimc-isp.h +++ b/drivers/media/platform/exynos4-is/fimc-isp.h | |||
| @@ -35,17 +35,18 @@ extern int fimc_isp_debug; | |||
| 35 | #define FIMC_ISP_SINK_WIDTH_MIN (16 + 8) | 35 | #define FIMC_ISP_SINK_WIDTH_MIN (16 + 8) |
| 36 | #define FIMC_ISP_SINK_HEIGHT_MIN (12 + 8) | 36 | #define FIMC_ISP_SINK_HEIGHT_MIN (12 + 8) |
| 37 | #define FIMC_ISP_SOURCE_WIDTH_MIN 8 | 37 | #define FIMC_ISP_SOURCE_WIDTH_MIN 8 |
| 38 | #define FIMC_ISP_SOURC_HEIGHT_MIN 8 | 38 | #define FIMC_ISP_SOURCE_HEIGHT_MIN 8 |
| 39 | #define FIMC_ISP_CAC_MARGIN_WIDTH 16 | 39 | #define FIMC_ISP_CAC_MARGIN_WIDTH 16 |
| 40 | #define FIMC_ISP_CAC_MARGIN_HEIGHT 12 | 40 | #define FIMC_ISP_CAC_MARGIN_HEIGHT 12 |
| 41 | 41 | ||
| 42 | #define FIMC_ISP_SINK_WIDTH_MAX (4000 - 16) | 42 | #define FIMC_ISP_SINK_WIDTH_MAX (4000 - 16) |
| 43 | #define FIMC_ISP_SINK_HEIGHT_MAX (4000 + 12) | 43 | #define FIMC_ISP_SINK_HEIGHT_MAX (4000 + 12) |
| 44 | #define FIMC_ISP_SOURCE_WIDTH_MAX 4000 | 44 | #define FIMC_ISP_SOURCE_WIDTH_MAX 4000 |
| 45 | #define FIMC_ISP_SOURC_HEIGHT_MAX 4000 | 45 | #define FIMC_ISP_SOURCE_HEIGHT_MAX 4000 |
| 46 | 46 | ||
| 47 | #define FIMC_ISP_NUM_FORMATS 3 | 47 | #define FIMC_ISP_NUM_FORMATS 3 |
| 48 | #define FIMC_ISP_REQ_BUFS_MIN 2 | 48 | #define FIMC_ISP_REQ_BUFS_MIN 2 |
| 49 | #define FIMC_ISP_REQ_BUFS_MAX 32 | ||
| 49 | 50 | ||
| 50 | #define FIMC_ISP_SD_PAD_SINK 0 | 51 | #define FIMC_ISP_SD_PAD_SINK 0 |
| 51 | #define FIMC_ISP_SD_PAD_SRC_FIFO 1 | 52 | #define FIMC_ISP_SD_PAD_SRC_FIFO 1 |
| @@ -100,6 +101,16 @@ struct fimc_isp_ctrls { | |||
| 100 | struct v4l2_ctrl *colorfx; | 101 | struct v4l2_ctrl *colorfx; |
| 101 | }; | 102 | }; |
| 102 | 103 | ||
| 104 | struct isp_video_buf { | ||
| 105 | struct vb2_buffer vb; | ||
| 106 | dma_addr_t dma_addr[FIMC_ISP_MAX_PLANES]; | ||
| 107 | unsigned int index; | ||
| 108 | }; | ||
| 109 | |||
| 110 | #define to_isp_video_buf(_b) container_of(_b, struct isp_video_buf, vb) | ||
| 111 | |||
| 112 | #define FIMC_ISP_MAX_BUFS 4 | ||
| 113 | |||
| 103 | /** | 114 | /** |
| 104 | * struct fimc_is_video - fimc-is video device structure | 115 | * struct fimc_is_video - fimc-is video device structure |
| 105 | * @vdev: video_device structure | 116 | * @vdev: video_device structure |
| @@ -114,18 +125,26 @@ struct fimc_isp_ctrls { | |||
| 114 | * @format: current pixel format | 125 | * @format: current pixel format |
| 115 | */ | 126 | */ |
| 116 | struct fimc_is_video { | 127 | struct fimc_is_video { |
| 117 | struct video_device vdev; | 128 | struct exynos_video_entity ve; |
| 118 | enum v4l2_buf_type type; | 129 | enum v4l2_buf_type type; |
| 119 | struct media_pad pad; | 130 | struct media_pad pad; |
| 120 | struct list_head pending_buf_q; | 131 | struct list_head pending_buf_q; |
| 121 | struct list_head active_buf_q; | 132 | struct list_head active_buf_q; |
| 122 | struct vb2_queue vb_queue; | 133 | struct vb2_queue vb_queue; |
| 123 | unsigned int frame_count; | ||
| 124 | unsigned int reqbufs_count; | 134 | unsigned int reqbufs_count; |
| 135 | unsigned int buf_count; | ||
| 136 | unsigned int buf_mask; | ||
| 137 | unsigned int frame_count; | ||
| 125 | int streaming; | 138 | int streaming; |
| 139 | struct isp_video_buf *buffers[FIMC_ISP_MAX_BUFS]; | ||
| 126 | const struct fimc_fmt *format; | 140 | const struct fimc_fmt *format; |
| 141 | struct v4l2_pix_format_mplane pixfmt; | ||
| 127 | }; | 142 | }; |
| 128 | 143 | ||
| 144 | /* struct fimc_isp:state bit definitions */ | ||
| 145 | #define ST_ISP_VID_CAP_BUF_PREP 0 | ||
| 146 | #define ST_ISP_VID_CAP_STREAMING 1 | ||
| 147 | |||
| 129 | /** | 148 | /** |
| 130 | * struct fimc_isp - FIMC-IS ISP data structure | 149 | * struct fimc_isp - FIMC-IS ISP data structure |
| 131 | * @pdev: pointer to FIMC-IS platform device | 150 | * @pdev: pointer to FIMC-IS platform device |
diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c index c670d67001f7..9bec34c4ac94 100644 --- a/drivers/media/platform/exynos4-is/media-dev.c +++ b/drivers/media/platform/exynos4-is/media-dev.c | |||
| @@ -684,8 +684,16 @@ static int register_csis_entity(struct fimc_md *fmd, | |||
| 684 | static int register_fimc_is_entity(struct fimc_md *fmd, struct fimc_is *is) | 684 | static int register_fimc_is_entity(struct fimc_md *fmd, struct fimc_is *is) |
| 685 | { | 685 | { |
| 686 | struct v4l2_subdev *sd = &is->isp.subdev; | 686 | struct v4l2_subdev *sd = &is->isp.subdev; |
| 687 | struct exynos_media_pipeline *ep; | ||
| 687 | int ret; | 688 | int ret; |
| 688 | 689 | ||
| 690 | /* Allocate pipeline object for the ISP capture video node. */ | ||
| 691 | ep = fimc_md_pipeline_create(fmd); | ||
| 692 | if (!ep) | ||
| 693 | return -ENOMEM; | ||
| 694 | |||
| 695 | v4l2_set_subdev_hostdata(sd, ep); | ||
| 696 | |||
| 689 | ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd); | 697 | ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd); |
| 690 | if (ret) { | 698 | if (ret) { |
| 691 | v4l2_err(&fmd->v4l2_dev, | 699 | v4l2_err(&fmd->v4l2_dev, |
| @@ -959,16 +967,17 @@ static int __fimc_md_create_flite_source_links(struct fimc_md *fmd) | |||
| 959 | /* Create FIMC-IS links */ | 967 | /* Create FIMC-IS links */ |
| 960 | static int __fimc_md_create_fimc_is_links(struct fimc_md *fmd) | 968 | static int __fimc_md_create_fimc_is_links(struct fimc_md *fmd) |
| 961 | { | 969 | { |
| 970 | struct fimc_isp *isp = &fmd->fimc_is->isp; | ||
| 962 | struct media_entity *source, *sink; | 971 | struct media_entity *source, *sink; |
| 963 | int i, ret; | 972 | int i, ret; |
| 964 | 973 | ||
| 965 | source = &fmd->fimc_is->isp.subdev.entity; | 974 | source = &isp->subdev.entity; |
| 966 | 975 | ||
| 967 | for (i = 0; i < FIMC_MAX_DEVS; i++) { | 976 | for (i = 0; i < FIMC_MAX_DEVS; i++) { |
| 968 | if (fmd->fimc[i] == NULL) | 977 | if (fmd->fimc[i] == NULL) |
| 969 | continue; | 978 | continue; |
| 970 | 979 | ||
| 971 | /* Link from IS-ISP subdev to FIMC */ | 980 | /* Link from FIMC-IS-ISP subdev to FIMC */ |
| 972 | sink = &fmd->fimc[i]->vid_cap.subdev.entity; | 981 | sink = &fmd->fimc[i]->vid_cap.subdev.entity; |
| 973 | ret = media_entity_create_link(source, FIMC_ISP_SD_PAD_SRC_FIFO, | 982 | ret = media_entity_create_link(source, FIMC_ISP_SD_PAD_SRC_FIFO, |
| 974 | sink, FIMC_SD_PAD_SINK_FIFO, 0); | 983 | sink, FIMC_SD_PAD_SINK_FIFO, 0); |
| @@ -976,7 +985,15 @@ static int __fimc_md_create_fimc_is_links(struct fimc_md *fmd) | |||
| 976 | return ret; | 985 | return ret; |
| 977 | } | 986 | } |
| 978 | 987 | ||
| 979 | return ret; | 988 | /* Link from FIMC-IS-ISP subdev to fimc-is-isp.capture video node */ |
| 989 | sink = &isp->video_capture.ve.vdev.entity; | ||
| 990 | |||
| 991 | /* Skip this link if the fimc-is-isp video node driver isn't built-in */ | ||
| 992 | if (sink->num_pads == 0) | ||
| 993 | return 0; | ||
| 994 | |||
| 995 | return media_entity_create_link(source, FIMC_ISP_SD_PAD_SRC_DMA, | ||
| 996 | sink, 0, 0); | ||
| 980 | } | 997 | } |
| 981 | 998 | ||
| 982 | /** | 999 | /** |
