diff options
Diffstat (limited to 'drivers/media/platform/vimc/vimc-capture.c')
-rw-r--r-- | drivers/media/platform/vimc/vimc-capture.c | 76 |
1 files changed, 26 insertions, 50 deletions
diff --git a/drivers/media/platform/vimc/vimc-capture.c b/drivers/media/platform/vimc/vimc-capture.c index 664855708fdf..1d56b91830ba 100644 --- a/drivers/media/platform/vimc/vimc-capture.c +++ b/drivers/media/platform/vimc/vimc-capture.c | |||
@@ -18,32 +18,6 @@ | |||
18 | 18 | ||
19 | #define VIMC_CAP_DRV_NAME "vimc-capture" | 19 | #define VIMC_CAP_DRV_NAME "vimc-capture" |
20 | 20 | ||
21 | static const u32 vimc_cap_supported_pixfmt[] = { | ||
22 | V4L2_PIX_FMT_BGR24, | ||
23 | V4L2_PIX_FMT_RGB24, | ||
24 | V4L2_PIX_FMT_ARGB32, | ||
25 | V4L2_PIX_FMT_SBGGR8, | ||
26 | V4L2_PIX_FMT_SGBRG8, | ||
27 | V4L2_PIX_FMT_SGRBG8, | ||
28 | V4L2_PIX_FMT_SRGGB8, | ||
29 | V4L2_PIX_FMT_SBGGR10, | ||
30 | V4L2_PIX_FMT_SGBRG10, | ||
31 | V4L2_PIX_FMT_SGRBG10, | ||
32 | V4L2_PIX_FMT_SRGGB10, | ||
33 | V4L2_PIX_FMT_SBGGR10ALAW8, | ||
34 | V4L2_PIX_FMT_SGBRG10ALAW8, | ||
35 | V4L2_PIX_FMT_SGRBG10ALAW8, | ||
36 | V4L2_PIX_FMT_SRGGB10ALAW8, | ||
37 | V4L2_PIX_FMT_SBGGR10DPCM8, | ||
38 | V4L2_PIX_FMT_SGBRG10DPCM8, | ||
39 | V4L2_PIX_FMT_SGRBG10DPCM8, | ||
40 | V4L2_PIX_FMT_SRGGB10DPCM8, | ||
41 | V4L2_PIX_FMT_SBGGR12, | ||
42 | V4L2_PIX_FMT_SGBRG12, | ||
43 | V4L2_PIX_FMT_SGRBG12, | ||
44 | V4L2_PIX_FMT_SRGGB12, | ||
45 | }; | ||
46 | |||
47 | struct vimc_cap_device { | 21 | struct vimc_cap_device { |
48 | struct vimc_ent_device ved; | 22 | struct vimc_ent_device ved; |
49 | struct video_device vdev; | 23 | struct video_device vdev; |
@@ -117,25 +91,29 @@ static int vimc_cap_try_fmt_vid_cap(struct file *file, void *priv, | |||
117 | struct v4l2_format *f) | 91 | struct v4l2_format *f) |
118 | { | 92 | { |
119 | struct v4l2_pix_format *format = &f->fmt.pix; | 93 | struct v4l2_pix_format *format = &f->fmt.pix; |
94 | const struct vimc_pix_map *vpix; | ||
120 | 95 | ||
121 | format->width = clamp_t(u32, format->width, VIMC_FRAME_MIN_WIDTH, | 96 | format->width = clamp_t(u32, format->width, VIMC_FRAME_MIN_WIDTH, |
122 | VIMC_FRAME_MAX_WIDTH) & ~1; | 97 | VIMC_FRAME_MAX_WIDTH) & ~1; |
123 | format->height = clamp_t(u32, format->height, VIMC_FRAME_MIN_HEIGHT, | 98 | format->height = clamp_t(u32, format->height, VIMC_FRAME_MIN_HEIGHT, |
124 | VIMC_FRAME_MAX_HEIGHT) & ~1; | 99 | VIMC_FRAME_MAX_HEIGHT) & ~1; |
125 | 100 | ||
126 | vimc_colorimetry_clamp(format); | 101 | /* Don't accept a pixelformat that is not on the table */ |
102 | vpix = vimc_pix_map_by_pixelformat(format->pixelformat); | ||
103 | if (!vpix) { | ||
104 | format->pixelformat = fmt_default.pixelformat; | ||
105 | vpix = vimc_pix_map_by_pixelformat(format->pixelformat); | ||
106 | } | ||
107 | /* TODO: Add support for custom bytesperline values */ | ||
108 | format->bytesperline = format->width * vpix->bpp; | ||
109 | format->sizeimage = format->bytesperline * format->height; | ||
127 | 110 | ||
128 | if (format->field == V4L2_FIELD_ANY) | 111 | if (format->field == V4L2_FIELD_ANY) |
129 | format->field = fmt_default.field; | 112 | format->field = fmt_default.field; |
130 | 113 | ||
131 | /* TODO: Add support for custom bytesperline values */ | 114 | vimc_colorimetry_clamp(format); |
132 | |||
133 | /* Don't accept a pixelformat that is not on the table */ | ||
134 | if (!v4l2_format_info(format->pixelformat)) | ||
135 | format->pixelformat = fmt_default.pixelformat; | ||
136 | 115 | ||
137 | return v4l2_fill_pixfmt(format, format->pixelformat, | 116 | return 0; |
138 | format->width, format->height); | ||
139 | } | 117 | } |
140 | 118 | ||
141 | static int vimc_cap_s_fmt_vid_cap(struct file *file, void *priv, | 119 | static int vimc_cap_s_fmt_vid_cap(struct file *file, void *priv, |
@@ -174,31 +152,27 @@ static int vimc_cap_s_fmt_vid_cap(struct file *file, void *priv, | |||
174 | static int vimc_cap_enum_fmt_vid_cap(struct file *file, void *priv, | 152 | static int vimc_cap_enum_fmt_vid_cap(struct file *file, void *priv, |
175 | struct v4l2_fmtdesc *f) | 153 | struct v4l2_fmtdesc *f) |
176 | { | 154 | { |
177 | if (f->index >= ARRAY_SIZE(vimc_cap_supported_pixfmt)) | 155 | const struct vimc_pix_map *vpix = vimc_pix_map_by_index(f->index); |
156 | |||
157 | if (!vpix) | ||
178 | return -EINVAL; | 158 | return -EINVAL; |
179 | 159 | ||
180 | f->pixelformat = vimc_cap_supported_pixfmt[f->index]; | 160 | f->pixelformat = vpix->pixelformat; |
181 | 161 | ||
182 | return 0; | 162 | return 0; |
183 | } | 163 | } |
184 | 164 | ||
185 | static bool vimc_cap_is_pixfmt_supported(u32 pixelformat) | ||
186 | { | ||
187 | unsigned int i; | ||
188 | |||
189 | for (i = 0; i < ARRAY_SIZE(vimc_cap_supported_pixfmt); i++) | ||
190 | if (vimc_cap_supported_pixfmt[i] == pixelformat) | ||
191 | return true; | ||
192 | return false; | ||
193 | } | ||
194 | |||
195 | static int vimc_cap_enum_framesizes(struct file *file, void *fh, | 165 | static int vimc_cap_enum_framesizes(struct file *file, void *fh, |
196 | struct v4l2_frmsizeenum *fsize) | 166 | struct v4l2_frmsizeenum *fsize) |
197 | { | 167 | { |
168 | const struct vimc_pix_map *vpix; | ||
169 | |||
198 | if (fsize->index) | 170 | if (fsize->index) |
199 | return -EINVAL; | 171 | return -EINVAL; |
200 | 172 | ||
201 | if (!vimc_cap_is_pixfmt_supported(fsize->pixel_format)) | 173 | /* Only accept code in the pix map table */ |
174 | vpix = vimc_pix_map_by_code(fsize->pixel_format); | ||
175 | if (!vpix) | ||
202 | return -EINVAL; | 176 | return -EINVAL; |
203 | 177 | ||
204 | fsize->type = V4L2_FRMSIZE_TYPE_CONTINUOUS; | 178 | fsize->type = V4L2_FRMSIZE_TYPE_CONTINUOUS; |
@@ -272,7 +246,6 @@ static int vimc_cap_start_streaming(struct vb2_queue *vq, unsigned int count) | |||
272 | return ret; | 246 | return ret; |
273 | } | 247 | } |
274 | 248 | ||
275 | vcap->stream.producer_pixfmt = vcap->format.pixelformat; | ||
276 | ret = vimc_streamer_s_stream(&vcap->stream, &vcap->ved, 1); | 249 | ret = vimc_streamer_s_stream(&vcap->stream, &vcap->ved, 1); |
277 | if (ret) { | 250 | if (ret) { |
278 | media_pipeline_stop(entity); | 251 | media_pipeline_stop(entity); |
@@ -423,6 +396,7 @@ static int vimc_cap_comp_bind(struct device *comp, struct device *master, | |||
423 | { | 396 | { |
424 | struct v4l2_device *v4l2_dev = master_data; | 397 | struct v4l2_device *v4l2_dev = master_data; |
425 | struct vimc_platform_data *pdata = comp->platform_data; | 398 | struct vimc_platform_data *pdata = comp->platform_data; |
399 | const struct vimc_pix_map *vpix; | ||
426 | struct vimc_cap_device *vcap; | 400 | struct vimc_cap_device *vcap; |
427 | struct video_device *vdev; | 401 | struct video_device *vdev; |
428 | struct vb2_queue *q; | 402 | struct vb2_queue *q; |
@@ -477,8 +451,10 @@ static int vimc_cap_comp_bind(struct device *comp, struct device *master, | |||
477 | 451 | ||
478 | /* Set default frame format */ | 452 | /* Set default frame format */ |
479 | vcap->format = fmt_default; | 453 | vcap->format = fmt_default; |
480 | v4l2_fill_pixfmt(&vcap->format, vcap->format.pixelformat, | 454 | vpix = vimc_pix_map_by_pixelformat(vcap->format.pixelformat); |
481 | vcap->format.width, vcap->format.height); | 455 | vcap->format.bytesperline = vcap->format.width * vpix->bpp; |
456 | vcap->format.sizeimage = vcap->format.bytesperline * | ||
457 | vcap->format.height; | ||
482 | 458 | ||
483 | /* Fill the vimc_ent_device struct */ | 459 | /* Fill the vimc_ent_device struct */ |
484 | vcap->ved.ent = &vcap->vdev.entity; | 460 | vcap->ved.ent = &vcap->vdev.entity; |