diff options
Diffstat (limited to 'drivers/media/video/soc_camera.c')
-rw-r--r-- | drivers/media/video/soc_camera.c | 55 |
1 files changed, 47 insertions, 8 deletions
diff --git a/drivers/media/video/soc_camera.c b/drivers/media/video/soc_camera.c index 46284489e4eb..ddb4c091dedc 100644 --- a/drivers/media/video/soc_camera.c +++ b/drivers/media/video/soc_camera.c | |||
@@ -136,11 +136,50 @@ unsigned long soc_camera_apply_sensor_flags(struct soc_camera_link *icl, | |||
136 | } | 136 | } |
137 | EXPORT_SYMBOL(soc_camera_apply_sensor_flags); | 137 | EXPORT_SYMBOL(soc_camera_apply_sensor_flags); |
138 | 138 | ||
139 | #define pixfmtstr(x) (x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, \ | ||
140 | ((x) >> 24) & 0xff | ||
141 | |||
142 | static int soc_camera_try_fmt(struct soc_camera_device *icd, | ||
143 | struct v4l2_format *f) | ||
144 | { | ||
145 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); | ||
146 | struct v4l2_pix_format *pix = &f->fmt.pix; | ||
147 | int ret; | ||
148 | |||
149 | dev_dbg(&icd->dev, "TRY_FMT(%c%c%c%c, %ux%u)\n", | ||
150 | pixfmtstr(pix->pixelformat), pix->width, pix->height); | ||
151 | |||
152 | pix->bytesperline = 0; | ||
153 | pix->sizeimage = 0; | ||
154 | |||
155 | ret = ici->ops->try_fmt(icd, f); | ||
156 | if (ret < 0) | ||
157 | return ret; | ||
158 | |||
159 | if (!pix->sizeimage) { | ||
160 | if (!pix->bytesperline) { | ||
161 | const struct soc_camera_format_xlate *xlate; | ||
162 | |||
163 | xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat); | ||
164 | if (!xlate) | ||
165 | return -EINVAL; | ||
166 | |||
167 | ret = soc_mbus_bytes_per_line(pix->width, | ||
168 | xlate->host_fmt); | ||
169 | if (ret > 0) | ||
170 | pix->bytesperline = ret; | ||
171 | } | ||
172 | if (pix->bytesperline) | ||
173 | pix->sizeimage = pix->bytesperline * pix->height; | ||
174 | } | ||
175 | |||
176 | return 0; | ||
177 | } | ||
178 | |||
139 | static int soc_camera_try_fmt_vid_cap(struct file *file, void *priv, | 179 | static int soc_camera_try_fmt_vid_cap(struct file *file, void *priv, |
140 | struct v4l2_format *f) | 180 | struct v4l2_format *f) |
141 | { | 181 | { |
142 | struct soc_camera_device *icd = file->private_data; | 182 | struct soc_camera_device *icd = file->private_data; |
143 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); | ||
144 | 183 | ||
145 | WARN_ON(priv != file->private_data); | 184 | WARN_ON(priv != file->private_data); |
146 | 185 | ||
@@ -149,7 +188,7 @@ static int soc_camera_try_fmt_vid_cap(struct file *file, void *priv, | |||
149 | return -EINVAL; | 188 | return -EINVAL; |
150 | 189 | ||
151 | /* limit format to hardware capabilities */ | 190 | /* limit format to hardware capabilities */ |
152 | return ici->ops->try_fmt(icd, f); | 191 | return soc_camera_try_fmt(icd, f); |
153 | } | 192 | } |
154 | 193 | ||
155 | static int soc_camera_enum_input(struct file *file, void *priv, | 194 | static int soc_camera_enum_input(struct file *file, void *priv, |
@@ -362,9 +401,6 @@ static void soc_camera_free_user_formats(struct soc_camera_device *icd) | |||
362 | icd->user_formats = NULL; | 401 | icd->user_formats = NULL; |
363 | } | 402 | } |
364 | 403 | ||
365 | #define pixfmtstr(x) (x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, \ | ||
366 | ((x) >> 24) & 0xff | ||
367 | |||
368 | /* Called with .vb_lock held, or from the first open(2), see comment there */ | 404 | /* Called with .vb_lock held, or from the first open(2), see comment there */ |
369 | static int soc_camera_set_fmt(struct soc_camera_device *icd, | 405 | static int soc_camera_set_fmt(struct soc_camera_device *icd, |
370 | struct v4l2_format *f) | 406 | struct v4l2_format *f) |
@@ -377,7 +413,7 @@ static int soc_camera_set_fmt(struct soc_camera_device *icd, | |||
377 | pixfmtstr(pix->pixelformat), pix->width, pix->height); | 413 | pixfmtstr(pix->pixelformat), pix->width, pix->height); |
378 | 414 | ||
379 | /* We always call try_fmt() before set_fmt() or set_crop() */ | 415 | /* We always call try_fmt() before set_fmt() or set_crop() */ |
380 | ret = ici->ops->try_fmt(icd, f); | 416 | ret = soc_camera_try_fmt(icd, f); |
381 | if (ret < 0) | 417 | if (ret < 0) |
382 | return ret; | 418 | return ret; |
383 | 419 | ||
@@ -996,10 +1032,11 @@ static void soc_camera_free_i2c(struct soc_camera_device *icd) | |||
996 | { | 1032 | { |
997 | struct i2c_client *client = | 1033 | struct i2c_client *client = |
998 | to_i2c_client(to_soc_camera_control(icd)); | 1034 | to_i2c_client(to_soc_camera_control(icd)); |
1035 | struct i2c_adapter *adap = client->adapter; | ||
999 | dev_set_drvdata(&icd->dev, NULL); | 1036 | dev_set_drvdata(&icd->dev, NULL); |
1000 | v4l2_device_unregister_subdev(i2c_get_clientdata(client)); | 1037 | v4l2_device_unregister_subdev(i2c_get_clientdata(client)); |
1001 | i2c_unregister_device(client); | 1038 | i2c_unregister_device(client); |
1002 | i2c_put_adapter(client->adapter); | 1039 | i2c_put_adapter(adap); |
1003 | } | 1040 | } |
1004 | #else | 1041 | #else |
1005 | #define soc_camera_init_i2c(icd, icl) (-ENODEV) | 1042 | #define soc_camera_init_i2c(icd, icl) (-ENODEV) |
@@ -1071,6 +1108,9 @@ static int soc_camera_probe(struct device *dev) | |||
1071 | } | 1108 | } |
1072 | } | 1109 | } |
1073 | 1110 | ||
1111 | sd = soc_camera_to_subdev(icd); | ||
1112 | sd->grp_id = (long)icd; | ||
1113 | |||
1074 | /* At this point client .probe() should have run already */ | 1114 | /* At this point client .probe() should have run already */ |
1075 | ret = soc_camera_init_user_formats(icd); | 1115 | ret = soc_camera_init_user_formats(icd); |
1076 | if (ret < 0) | 1116 | if (ret < 0) |
@@ -1092,7 +1132,6 @@ static int soc_camera_probe(struct device *dev) | |||
1092 | goto evidstart; | 1132 | goto evidstart; |
1093 | 1133 | ||
1094 | /* Try to improve our guess of a reasonable window format */ | 1134 | /* Try to improve our guess of a reasonable window format */ |
1095 | sd = soc_camera_to_subdev(icd); | ||
1096 | if (!v4l2_subdev_call(sd, video, g_mbus_fmt, &mf)) { | 1135 | if (!v4l2_subdev_call(sd, video, g_mbus_fmt, &mf)) { |
1097 | icd->user_width = mf.width; | 1136 | icd->user_width = mf.width; |
1098 | icd->user_height = mf.height; | 1137 | icd->user_height = mf.height; |