Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1 | /* |
| 2 | * camera image capture (abstract) bus driver |
| 3 | * |
| 4 | * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de> |
| 5 | * |
| 6 | * This driver provides an interface between platform-specific camera |
| 7 | * busses and camera devices. It should be used if the camera is |
| 8 | * connected not over a "proper" bus like PCI or USB, but over a |
| 9 | * special bus, like, for example, the Quick Capture interface on PXA270 |
| 10 | * SoCs. Later it should also be used for i.MX31 SoCs from Freescale. |
| 11 | * It can handle multiple cameras and / or multiple busses, which can |
| 12 | * be used, e.g., in stereo-vision applications. |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or modify |
| 15 | * it under the terms of the GNU General Public License version 2 as |
| 16 | * published by the Free Software Foundation. |
| 17 | */ |
| 18 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 19 | #include <linux/device.h> |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 20 | #include <linux/err.h> |
Guennadi Liakhovetski | 0fd327b | 2009-05-07 13:25:32 -0300 | [diff] [blame] | 21 | #include <linux/i2c.h> |
| 22 | #include <linux/init.h> |
| 23 | #include <linux/list.h> |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 24 | #include <linux/mutex.h> |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 25 | #include <linux/module.h> |
Guennadi Liakhovetski | 0fd327b | 2009-05-07 13:25:32 -0300 | [diff] [blame] | 26 | #include <linux/platform_device.h> |
Alberto Panizzo | 96e442c | 2010-12-02 07:43:37 -0300 | [diff] [blame] | 27 | #include <linux/regulator/consumer.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 28 | #include <linux/slab.h> |
Mauro Carvalho Chehab | 4f9fb5e | 2010-05-18 00:46:09 -0300 | [diff] [blame] | 29 | #include <linux/pm_runtime.h> |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 30 | #include <linux/vmalloc.h> |
| 31 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 32 | #include <media/soc_camera.h> |
Guennadi Liakhovetski | 0fd327b | 2009-05-07 13:25:32 -0300 | [diff] [blame] | 33 | #include <media/v4l2-common.h> |
Guennadi Liakhovetski | 0fd327b | 2009-05-07 13:25:32 -0300 | [diff] [blame] | 34 | #include <media/v4l2-ioctl.h> |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 35 | #include <media/v4l2-dev.h> |
Guennadi Liakhovetski | 0fd327b | 2009-05-07 13:25:32 -0300 | [diff] [blame] | 36 | #include <media/videobuf-core.h> |
Guennadi Liakhovetski | 592c2ab | 2011-01-29 12:44:51 -0300 | [diff] [blame] | 37 | #include <media/videobuf2-core.h> |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 38 | #include <media/soc_mediabus.h> |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 39 | |
Guennadi Liakhovetski | df2ed07 | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 40 | /* Default to VGA resolution */ |
| 41 | #define DEFAULT_WIDTH 640 |
| 42 | #define DEFAULT_HEIGHT 480 |
| 43 | |
Guennadi Liakhovetski | aee5c2f | 2011-03-28 13:28:28 -0300 | [diff] [blame] | 44 | #define is_streaming(ici, icd) \ |
| 45 | (((ici)->ops->init_videobuf) ? \ |
| 46 | (icd)->vb_vidq.streaming : \ |
| 47 | vb2_is_streaming(&(icd)->vb2_vidq)) |
| 48 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 49 | static LIST_HEAD(hosts); |
| 50 | static LIST_HEAD(devices); |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 51 | static DEFINE_MUTEX(list_lock); /* Protects the list of hosts */ |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 52 | |
Guennadi Liakhovetski | 3dcc731 | 2011-09-05 12:33:21 -0300 | [diff] [blame] | 53 | static int soc_camera_power_on(struct soc_camera_device *icd, |
| 54 | struct soc_camera_link *icl) |
Alberto Panizzo | 96e442c | 2010-12-02 07:43:37 -0300 | [diff] [blame] | 55 | { |
Guennadi Liakhovetski | 7b9d8c3 | 2011-09-08 04:36:06 -0300 | [diff] [blame] | 56 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); |
| 57 | int ret = regulator_bulk_enable(icl->num_regulators, |
| 58 | icl->regulators); |
Guennadi Liakhovetski | 3dcc731 | 2011-09-05 12:33:21 -0300 | [diff] [blame] | 59 | if (ret < 0) { |
| 60 | dev_err(icd->pdev, "Cannot enable regulators\n"); |
| 61 | return ret; |
| 62 | } |
Alberto Panizzo | 96e442c | 2010-12-02 07:43:37 -0300 | [diff] [blame] | 63 | |
Guennadi Liakhovetski | 3dcc731 | 2011-09-05 12:33:21 -0300 | [diff] [blame] | 64 | if (icl->power) { |
| 65 | ret = icl->power(icd->pdev, 1); |
Alberto Panizzo | 96e442c | 2010-12-02 07:43:37 -0300 | [diff] [blame] | 66 | if (ret < 0) { |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 67 | dev_err(icd->pdev, |
Alberto Panizzo | 96e442c | 2010-12-02 07:43:37 -0300 | [diff] [blame] | 68 | "Platform failed to power-on the camera.\n"); |
Guennadi Liakhovetski | 7b9d8c3 | 2011-09-08 04:36:06 -0300 | [diff] [blame] | 69 | goto elinkpwr; |
Alberto Panizzo | 96e442c | 2010-12-02 07:43:37 -0300 | [diff] [blame] | 70 | } |
Guennadi Liakhovetski | 3dcc731 | 2011-09-05 12:33:21 -0300 | [diff] [blame] | 71 | } |
| 72 | |
Guennadi Liakhovetski | 7b9d8c3 | 2011-09-08 04:36:06 -0300 | [diff] [blame] | 73 | ret = v4l2_subdev_call(sd, core, s_power, 1); |
| 74 | if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV) |
| 75 | goto esdpwr; |
| 76 | |
| 77 | return 0; |
| 78 | |
| 79 | esdpwr: |
| 80 | if (icl->power) |
| 81 | icl->power(icd->pdev, 0); |
| 82 | elinkpwr: |
| 83 | regulator_bulk_disable(icl->num_regulators, |
| 84 | icl->regulators); |
Guennadi Liakhovetski | 3dcc731 | 2011-09-05 12:33:21 -0300 | [diff] [blame] | 85 | return ret; |
| 86 | } |
| 87 | |
| 88 | static int soc_camera_power_off(struct soc_camera_device *icd, |
| 89 | struct soc_camera_link *icl) |
| 90 | { |
Guennadi Liakhovetski | 7b9d8c3 | 2011-09-08 04:36:06 -0300 | [diff] [blame] | 91 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); |
| 92 | int ret = v4l2_subdev_call(sd, core, s_power, 0); |
| 93 | |
| 94 | if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV) |
| 95 | return ret; |
Guennadi Liakhovetski | 3dcc731 | 2011-09-05 12:33:21 -0300 | [diff] [blame] | 96 | |
| 97 | if (icl->power) { |
| 98 | ret = icl->power(icd->pdev, 0); |
Alberto Panizzo | 96e442c | 2010-12-02 07:43:37 -0300 | [diff] [blame] | 99 | if (ret < 0) { |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 100 | dev_err(icd->pdev, |
Alberto Panizzo | 96e442c | 2010-12-02 07:43:37 -0300 | [diff] [blame] | 101 | "Platform failed to power-off the camera.\n"); |
| 102 | return ret; |
| 103 | } |
Alberto Panizzo | 96e442c | 2010-12-02 07:43:37 -0300 | [diff] [blame] | 104 | } |
| 105 | |
Guennadi Liakhovetski | 3dcc731 | 2011-09-05 12:33:21 -0300 | [diff] [blame] | 106 | ret = regulator_bulk_disable(icl->num_regulators, |
| 107 | icl->regulators); |
| 108 | if (ret < 0) |
| 109 | dev_err(icd->pdev, "Cannot disable regulators\n"); |
| 110 | |
| 111 | return ret; |
Alberto Panizzo | 96e442c | 2010-12-02 07:43:37 -0300 | [diff] [blame] | 112 | } |
| 113 | |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 114 | const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc( |
| 115 | struct soc_camera_device *icd, unsigned int fourcc) |
| 116 | { |
| 117 | unsigned int i; |
| 118 | |
| 119 | for (i = 0; i < icd->num_user_formats; i++) |
| 120 | if (icd->user_formats[i].host_fmt->fourcc == fourcc) |
| 121 | return icd->user_formats + i; |
| 122 | return NULL; |
| 123 | } |
| 124 | EXPORT_SYMBOL(soc_camera_xlate_by_fourcc); |
| 125 | |
Guennadi Liakhovetski | bd73b36 | 2008-12-23 05:54:45 -0300 | [diff] [blame] | 126 | /** |
Guennadi Liakhovetski | 32c69fcc | 2011-07-26 11:38:01 -0300 | [diff] [blame] | 127 | * soc_camera_apply_board_flags() - apply platform SOCAM_SENSOR_INVERT_* flags |
| 128 | * @icl: camera platform parameters |
| 129 | * @cfg: media bus configuration |
| 130 | * @return: resulting flags |
| 131 | */ |
| 132 | unsigned long soc_camera_apply_board_flags(struct soc_camera_link *icl, |
| 133 | const struct v4l2_mbus_config *cfg) |
| 134 | { |
| 135 | unsigned long f, flags = cfg->flags; |
| 136 | |
| 137 | /* If only one of the two polarities is supported, switch to the opposite */ |
| 138 | if (icl->flags & SOCAM_SENSOR_INVERT_HSYNC) { |
| 139 | f = flags & (V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_LOW); |
| 140 | if (f == V4L2_MBUS_HSYNC_ACTIVE_HIGH || f == V4L2_MBUS_HSYNC_ACTIVE_LOW) |
| 141 | flags ^= V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_LOW; |
| 142 | } |
| 143 | |
| 144 | if (icl->flags & SOCAM_SENSOR_INVERT_VSYNC) { |
| 145 | f = flags & (V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW); |
| 146 | if (f == V4L2_MBUS_VSYNC_ACTIVE_HIGH || f == V4L2_MBUS_VSYNC_ACTIVE_LOW) |
| 147 | flags ^= V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW; |
| 148 | } |
| 149 | |
| 150 | if (icl->flags & SOCAM_SENSOR_INVERT_PCLK) { |
| 151 | f = flags & (V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING); |
| 152 | if (f == V4L2_MBUS_PCLK_SAMPLE_RISING || f == V4L2_MBUS_PCLK_SAMPLE_FALLING) |
| 153 | flags ^= V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING; |
| 154 | } |
| 155 | |
| 156 | return flags; |
| 157 | } |
| 158 | EXPORT_SYMBOL(soc_camera_apply_board_flags); |
| 159 | |
Sergio Aguirre | dca6b6d | 2011-04-11 13:14:33 -0300 | [diff] [blame] | 160 | #define pixfmtstr(x) (x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, \ |
| 161 | ((x) >> 24) & 0xff |
| 162 | |
| 163 | static int soc_camera_try_fmt(struct soc_camera_device *icd, |
| 164 | struct v4l2_format *f) |
| 165 | { |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 166 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
Laurent Pinchart | bed8d80 | 2012-03-21 08:03:26 -0300 | [diff] [blame^] | 167 | const struct soc_camera_format_xlate *xlate; |
Sergio Aguirre | dca6b6d | 2011-04-11 13:14:33 -0300 | [diff] [blame] | 168 | struct v4l2_pix_format *pix = &f->fmt.pix; |
| 169 | int ret; |
| 170 | |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 171 | dev_dbg(icd->pdev, "TRY_FMT(%c%c%c%c, %ux%u)\n", |
Sergio Aguirre | dca6b6d | 2011-04-11 13:14:33 -0300 | [diff] [blame] | 172 | pixfmtstr(pix->pixelformat), pix->width, pix->height); |
| 173 | |
| 174 | pix->bytesperline = 0; |
| 175 | pix->sizeimage = 0; |
| 176 | |
| 177 | ret = ici->ops->try_fmt(icd, f); |
| 178 | if (ret < 0) |
| 179 | return ret; |
| 180 | |
Laurent Pinchart | bed8d80 | 2012-03-21 08:03:26 -0300 | [diff] [blame^] | 181 | xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat); |
| 182 | if (!xlate) |
| 183 | return -EINVAL; |
Sergio Aguirre | dca6b6d | 2011-04-11 13:14:33 -0300 | [diff] [blame] | 184 | |
Laurent Pinchart | bed8d80 | 2012-03-21 08:03:26 -0300 | [diff] [blame^] | 185 | ret = soc_mbus_bytes_per_line(pix->width, xlate->host_fmt); |
| 186 | if (ret < 0) |
| 187 | return ret; |
Sergio Aguirre | dca6b6d | 2011-04-11 13:14:33 -0300 | [diff] [blame] | 188 | |
Laurent Pinchart | bed8d80 | 2012-03-21 08:03:26 -0300 | [diff] [blame^] | 189 | pix->bytesperline = max_t(u32, pix->bytesperline, ret); |
| 190 | |
| 191 | ret = soc_mbus_image_size(xlate->host_fmt, pix->bytesperline, |
| 192 | pix->height); |
| 193 | if (ret < 0) |
| 194 | return ret; |
| 195 | |
| 196 | pix->sizeimage = max_t(u32, pix->sizeimage, ret); |
Sergio Aguirre | dca6b6d | 2011-04-11 13:14:33 -0300 | [diff] [blame] | 197 | |
| 198 | return 0; |
| 199 | } |
| 200 | |
Hans Verkuil | 7293789 | 2008-06-01 10:35:18 -0300 | [diff] [blame] | 201 | static int soc_camera_try_fmt_vid_cap(struct file *file, void *priv, |
Guennadi Liakhovetski | abe4c47 | 2008-12-01 09:44:56 -0300 | [diff] [blame] | 202 | struct v4l2_format *f) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 203 | { |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 204 | struct soc_camera_device *icd = file->private_data; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 205 | |
| 206 | WARN_ON(priv != file->private_data); |
| 207 | |
Guennadi Liakhovetski | d366d4a | 2011-03-21 06:33:25 -0300 | [diff] [blame] | 208 | /* Only single-plane capture is supported so far */ |
| 209 | if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 210 | return -EINVAL; |
| 211 | |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 212 | /* limit format to hardware capabilities */ |
Sergio Aguirre | dca6b6d | 2011-04-11 13:14:33 -0300 | [diff] [blame] | 213 | return soc_camera_try_fmt(icd, f); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | static int soc_camera_enum_input(struct file *file, void *priv, |
| 217 | struct v4l2_input *inp) |
| 218 | { |
| 219 | if (inp->index != 0) |
| 220 | return -EINVAL; |
| 221 | |
Guennadi Liakhovetski | 8318a64 | 2011-06-07 06:24:32 -0300 | [diff] [blame] | 222 | /* default is camera */ |
| 223 | inp->type = V4L2_INPUT_TYPE_CAMERA; |
| 224 | inp->std = V4L2_STD_UNKNOWN; |
| 225 | strcpy(inp->name, "Camera"); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 226 | |
Guennadi Liakhovetski | 8318a64 | 2011-06-07 06:24:32 -0300 | [diff] [blame] | 227 | return 0; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | static int soc_camera_g_input(struct file *file, void *priv, unsigned int *i) |
| 231 | { |
| 232 | *i = 0; |
| 233 | |
| 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | static int soc_camera_s_input(struct file *file, void *priv, unsigned int i) |
| 238 | { |
| 239 | if (i > 0) |
| 240 | return -EINVAL; |
| 241 | |
| 242 | return 0; |
| 243 | } |
| 244 | |
| 245 | static int soc_camera_s_std(struct file *file, void *priv, v4l2_std_id *a) |
| 246 | { |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 247 | struct soc_camera_device *icd = file->private_data; |
Guennadi Liakhovetski | c9c1f1c | 2009-08-25 11:46:59 -0300 | [diff] [blame] | 248 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); |
Kuninori Morimoto | 513791a | 2008-12-18 12:46:45 -0300 | [diff] [blame] | 249 | |
Guennadi Liakhovetski | c9c1f1c | 2009-08-25 11:46:59 -0300 | [diff] [blame] | 250 | return v4l2_subdev_call(sd, core, s_std, *a); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 251 | } |
| 252 | |
Guennadi Liakhovetski | 2f0babb7 | 2011-09-09 13:39:20 -0300 | [diff] [blame] | 253 | static int soc_camera_g_std(struct file *file, void *priv, v4l2_std_id *a) |
| 254 | { |
| 255 | struct soc_camera_device *icd = file->private_data; |
| 256 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); |
| 257 | |
| 258 | return v4l2_subdev_call(sd, core, g_std, a); |
| 259 | } |
| 260 | |
Guennadi Liakhovetski | ad3537b | 2012-05-08 13:00:51 -0300 | [diff] [blame] | 261 | static int soc_camera_enum_framesizes(struct file *file, void *fh, |
Qing Xu | ed5b65d | 2011-01-20 05:19:40 -0300 | [diff] [blame] | 262 | struct v4l2_frmsizeenum *fsize) |
| 263 | { |
| 264 | struct soc_camera_device *icd = file->private_data; |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 265 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
Qing Xu | ed5b65d | 2011-01-20 05:19:40 -0300 | [diff] [blame] | 266 | |
Guennadi Liakhovetski | ad3537b | 2012-05-08 13:00:51 -0300 | [diff] [blame] | 267 | return ici->ops->enum_framesizes(icd, fsize); |
Qing Xu | ed5b65d | 2011-01-20 05:19:40 -0300 | [diff] [blame] | 268 | } |
| 269 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 270 | static int soc_camera_reqbufs(struct file *file, void *priv, |
| 271 | struct v4l2_requestbuffers *p) |
| 272 | { |
| 273 | int ret; |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 274 | struct soc_camera_device *icd = file->private_data; |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 275 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 276 | |
| 277 | WARN_ON(priv != file->private_data); |
| 278 | |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 279 | if (icd->streamer && icd->streamer != file) |
| 280 | return -EBUSY; |
| 281 | |
Guennadi Liakhovetski | 592c2ab | 2011-01-29 12:44:51 -0300 | [diff] [blame] | 282 | if (ici->ops->init_videobuf) { |
| 283 | ret = videobuf_reqbufs(&icd->vb_vidq, p); |
| 284 | if (ret < 0) |
| 285 | return ret; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 286 | |
Guennadi Liakhovetski | 592c2ab | 2011-01-29 12:44:51 -0300 | [diff] [blame] | 287 | ret = ici->ops->reqbufs(icd, p); |
| 288 | } else { |
| 289 | ret = vb2_reqbufs(&icd->vb2_vidq, p); |
| 290 | } |
| 291 | |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 292 | if (!ret && !icd->streamer) |
| 293 | icd->streamer = file; |
| 294 | |
| 295 | return ret; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | static int soc_camera_querybuf(struct file *file, void *priv, |
| 299 | struct v4l2_buffer *p) |
| 300 | { |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 301 | struct soc_camera_device *icd = file->private_data; |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 302 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 303 | |
| 304 | WARN_ON(priv != file->private_data); |
| 305 | |
Guennadi Liakhovetski | 592c2ab | 2011-01-29 12:44:51 -0300 | [diff] [blame] | 306 | if (ici->ops->init_videobuf) |
| 307 | return videobuf_querybuf(&icd->vb_vidq, p); |
| 308 | else |
| 309 | return vb2_querybuf(&icd->vb2_vidq, p); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | static int soc_camera_qbuf(struct file *file, void *priv, |
| 313 | struct v4l2_buffer *p) |
| 314 | { |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 315 | struct soc_camera_device *icd = file->private_data; |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 316 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 317 | |
| 318 | WARN_ON(priv != file->private_data); |
| 319 | |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 320 | if (icd->streamer != file) |
| 321 | return -EBUSY; |
| 322 | |
Guennadi Liakhovetski | 592c2ab | 2011-01-29 12:44:51 -0300 | [diff] [blame] | 323 | if (ici->ops->init_videobuf) |
| 324 | return videobuf_qbuf(&icd->vb_vidq, p); |
| 325 | else |
| 326 | return vb2_qbuf(&icd->vb2_vidq, p); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | static int soc_camera_dqbuf(struct file *file, void *priv, |
| 330 | struct v4l2_buffer *p) |
| 331 | { |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 332 | struct soc_camera_device *icd = file->private_data; |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 333 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 334 | |
| 335 | WARN_ON(priv != file->private_data); |
| 336 | |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 337 | if (icd->streamer != file) |
| 338 | return -EBUSY; |
| 339 | |
Guennadi Liakhovetski | 592c2ab | 2011-01-29 12:44:51 -0300 | [diff] [blame] | 340 | if (ici->ops->init_videobuf) |
| 341 | return videobuf_dqbuf(&icd->vb_vidq, p, file->f_flags & O_NONBLOCK); |
| 342 | else |
| 343 | return vb2_dqbuf(&icd->vb2_vidq, p, file->f_flags & O_NONBLOCK); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 344 | } |
| 345 | |
Guennadi Liakhovetski | 7ae77ee | 2011-09-28 09:25:28 -0300 | [diff] [blame] | 346 | static int soc_camera_create_bufs(struct file *file, void *priv, |
| 347 | struct v4l2_create_buffers *create) |
| 348 | { |
| 349 | struct soc_camera_device *icd = file->private_data; |
| 350 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
| 351 | |
| 352 | /* videobuf2 only */ |
| 353 | if (ici->ops->init_videobuf) |
| 354 | return -EINVAL; |
| 355 | else |
| 356 | return vb2_create_bufs(&icd->vb2_vidq, create); |
| 357 | } |
| 358 | |
| 359 | static int soc_camera_prepare_buf(struct file *file, void *priv, |
| 360 | struct v4l2_buffer *b) |
| 361 | { |
| 362 | struct soc_camera_device *icd = file->private_data; |
| 363 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
| 364 | |
| 365 | /* videobuf2 only */ |
| 366 | if (ici->ops->init_videobuf) |
| 367 | return -EINVAL; |
| 368 | else |
| 369 | return vb2_prepare_buf(&icd->vb2_vidq, b); |
| 370 | } |
| 371 | |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 372 | /* Always entered with .video_lock held */ |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 373 | static int soc_camera_init_user_formats(struct soc_camera_device *icd) |
| 374 | { |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 375 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 376 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
Hans Verkuil | 3805f20 | 2010-05-08 17:55:00 -0300 | [diff] [blame] | 377 | unsigned int i, fmts = 0, raw_fmts = 0; |
| 378 | int ret; |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 379 | enum v4l2_mbus_pixelcode code; |
| 380 | |
| 381 | while (!v4l2_subdev_call(sd, video, enum_mbus_fmt, raw_fmts, &code)) |
| 382 | raw_fmts++; |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 383 | |
| 384 | if (!ici->ops->get_formats) |
| 385 | /* |
| 386 | * Fallback mode - the host will have to serve all |
| 387 | * sensor-provided formats one-to-one to the user |
| 388 | */ |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 389 | fmts = raw_fmts; |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 390 | else |
| 391 | /* |
| 392 | * First pass - only count formats this host-sensor |
| 393 | * configuration can provide |
| 394 | */ |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 395 | for (i = 0; i < raw_fmts; i++) { |
Guennadi Liakhovetski | fa48984 | 2009-08-25 11:46:43 -0300 | [diff] [blame] | 396 | ret = ici->ops->get_formats(icd, i, NULL); |
| 397 | if (ret < 0) |
| 398 | return ret; |
| 399 | fmts += ret; |
| 400 | } |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 401 | |
| 402 | if (!fmts) |
| 403 | return -ENXIO; |
| 404 | |
| 405 | icd->user_formats = |
| 406 | vmalloc(fmts * sizeof(struct soc_camera_format_xlate)); |
| 407 | if (!icd->user_formats) |
| 408 | return -ENOMEM; |
| 409 | |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 410 | dev_dbg(icd->pdev, "Found %d supported formats.\n", fmts); |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 411 | |
| 412 | /* Second pass - actually fill data formats */ |
Stefan Herbrechtsmeier | 14df2cc | 2009-06-24 10:31:25 -0300 | [diff] [blame] | 413 | fmts = 0; |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 414 | for (i = 0; i < raw_fmts; i++) |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 415 | if (!ici->ops->get_formats) { |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 416 | v4l2_subdev_call(sd, video, enum_mbus_fmt, i, &code); |
Guennadi Liakhovetski | d2dcad4 | 2011-05-18 06:49:54 -0300 | [diff] [blame] | 417 | icd->user_formats[fmts].host_fmt = |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 418 | soc_mbus_get_fmtdesc(code); |
Guennadi Liakhovetski | d2dcad4 | 2011-05-18 06:49:54 -0300 | [diff] [blame] | 419 | if (icd->user_formats[fmts].host_fmt) |
| 420 | icd->user_formats[fmts++].code = code; |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 421 | } else { |
Guennadi Liakhovetski | fa48984 | 2009-08-25 11:46:43 -0300 | [diff] [blame] | 422 | ret = ici->ops->get_formats(icd, i, |
| 423 | &icd->user_formats[fmts]); |
| 424 | if (ret < 0) |
| 425 | goto egfmt; |
| 426 | fmts += ret; |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 427 | } |
| 428 | |
Guennadi Liakhovetski | d2dcad4 | 2011-05-18 06:49:54 -0300 | [diff] [blame] | 429 | icd->num_user_formats = fmts; |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 430 | icd->current_fmt = &icd->user_formats[0]; |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 431 | |
| 432 | return 0; |
Guennadi Liakhovetski | fa48984 | 2009-08-25 11:46:43 -0300 | [diff] [blame] | 433 | |
| 434 | egfmt: |
Guennadi Liakhovetski | fa48984 | 2009-08-25 11:46:43 -0300 | [diff] [blame] | 435 | vfree(icd->user_formats); |
| 436 | return ret; |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 437 | } |
| 438 | |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 439 | /* Always entered with .video_lock held */ |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 440 | static void soc_camera_free_user_formats(struct soc_camera_device *icd) |
| 441 | { |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 442 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
Guennadi Liakhovetski | fa48984 | 2009-08-25 11:46:43 -0300 | [diff] [blame] | 443 | |
| 444 | if (ici->ops->put_formats) |
| 445 | ici->ops->put_formats(icd); |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 446 | icd->current_fmt = NULL; |
Guennadi Liakhovetski | fa48984 | 2009-08-25 11:46:43 -0300 | [diff] [blame] | 447 | icd->num_user_formats = 0; |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 448 | vfree(icd->user_formats); |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 449 | icd->user_formats = NULL; |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 450 | } |
| 451 | |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 452 | /* Called with .vb_lock held, or from the first open(2), see comment there */ |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 453 | static int soc_camera_set_fmt(struct soc_camera_device *icd, |
Guennadi Liakhovetski | df2ed07 | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 454 | struct v4l2_format *f) |
| 455 | { |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 456 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
Guennadi Liakhovetski | df2ed07 | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 457 | struct v4l2_pix_format *pix = &f->fmt.pix; |
| 458 | int ret; |
| 459 | |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 460 | dev_dbg(icd->pdev, "S_FMT(%c%c%c%c, %ux%u)\n", |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 461 | pixfmtstr(pix->pixelformat), pix->width, pix->height); |
| 462 | |
Guennadi Liakhovetski | df2ed07 | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 463 | /* We always call try_fmt() before set_fmt() or set_crop() */ |
Sergio Aguirre | dca6b6d | 2011-04-11 13:14:33 -0300 | [diff] [blame] | 464 | ret = soc_camera_try_fmt(icd, f); |
Guennadi Liakhovetski | df2ed07 | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 465 | if (ret < 0) |
| 466 | return ret; |
| 467 | |
| 468 | ret = ici->ops->set_fmt(icd, f); |
| 469 | if (ret < 0) { |
| 470 | return ret; |
| 471 | } else if (!icd->current_fmt || |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 472 | icd->current_fmt->host_fmt->fourcc != pix->pixelformat) { |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 473 | dev_err(icd->pdev, |
Guennadi Liakhovetski | df2ed07 | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 474 | "Host driver hasn't set up current format correctly!\n"); |
| 475 | return -EINVAL; |
| 476 | } |
| 477 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 478 | icd->user_width = pix->width; |
| 479 | icd->user_height = pix->height; |
Sergio Aguirre | 0e4c180 | 2011-03-07 21:49:48 -0300 | [diff] [blame] | 480 | icd->bytesperline = pix->bytesperline; |
| 481 | icd->sizeimage = pix->sizeimage; |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 482 | icd->colorspace = pix->colorspace; |
Guennadi Liakhovetski | 592c2ab | 2011-01-29 12:44:51 -0300 | [diff] [blame] | 483 | icd->field = pix->field; |
| 484 | if (ici->ops->init_videobuf) |
| 485 | icd->vb_vidq.field = pix->field; |
Guennadi Liakhovetski | 025c18a | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 486 | |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 487 | dev_dbg(icd->pdev, "set width: %d height: %d\n", |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 488 | icd->user_width, icd->user_height); |
Guennadi Liakhovetski | df2ed07 | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 489 | |
| 490 | /* set physical bus parameters */ |
Guennadi Liakhovetski | 8843d11 | 2011-09-21 17:52:51 -0300 | [diff] [blame] | 491 | return ici->ops->set_bus_param(icd); |
Guennadi Liakhovetski | df2ed07 | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 492 | } |
| 493 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 494 | static int soc_camera_open(struct file *file) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 495 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 496 | struct video_device *vdev = video_devdata(file); |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 497 | struct soc_camera_device *icd = dev_get_drvdata(vdev->parent); |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 498 | struct soc_camera_link *icl = to_soc_camera_link(icd); |
Guennadi Liakhovetski | 9dc4e48 | 2008-04-22 14:45:32 -0300 | [diff] [blame] | 499 | struct soc_camera_host *ici; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 500 | int ret; |
| 501 | |
Guennadi Liakhovetski | b0050e4 | 2011-07-28 13:57:53 -0300 | [diff] [blame] | 502 | if (!to_soc_camera_control(icd)) |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 503 | /* No device driver attached */ |
| 504 | return -ENODEV; |
| 505 | |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 506 | ici = to_soc_camera_host(icd->parent); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 507 | |
Guennadi Liakhovetski | b8d9904 | 2008-04-04 13:41:25 -0300 | [diff] [blame] | 508 | if (!try_module_get(ici->ops->owner)) { |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 509 | dev_err(icd->pdev, "Couldn't lock capture bus driver.\n"); |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 510 | return -EINVAL; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 511 | } |
| 512 | |
Guennadi Liakhovetski | 1a0063a | 2008-04-04 13:46:34 -0300 | [diff] [blame] | 513 | icd->use_count++; |
| 514 | |
Guennadi Liakhovetski | 9dc4e48 | 2008-04-22 14:45:32 -0300 | [diff] [blame] | 515 | /* Now we really have to activate the camera */ |
| 516 | if (icd->use_count == 1) { |
Guennadi Liakhovetski | 025c18a | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 517 | /* Restore parameters before the last close() per V4L2 API */ |
Guennadi Liakhovetski | df2ed07 | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 518 | struct v4l2_format f = { |
| 519 | .type = V4L2_BUF_TYPE_VIDEO_CAPTURE, |
| 520 | .fmt.pix = { |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 521 | .width = icd->user_width, |
| 522 | .height = icd->user_height, |
Guennadi Liakhovetski | 025c18a | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 523 | .field = icd->field, |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 524 | .colorspace = icd->colorspace, |
| 525 | .pixelformat = |
| 526 | icd->current_fmt->host_fmt->fourcc, |
Guennadi Liakhovetski | df2ed07 | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 527 | }, |
| 528 | }; |
| 529 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 530 | /* The camera could have been already on, try to reset */ |
| 531 | if (icl->reset) |
| 532 | icl->reset(icd->pdev); |
| 533 | |
Guennadi Liakhovetski | 2f9a0c8 | 2012-04-18 06:43:09 -0300 | [diff] [blame] | 534 | /* Don't mess with the host during probe */ |
| 535 | mutex_lock(&ici->host_lock); |
Guennadi Liakhovetski | b8d9904 | 2008-04-04 13:41:25 -0300 | [diff] [blame] | 536 | ret = ici->ops->add(icd); |
Guennadi Liakhovetski | 2f9a0c8 | 2012-04-18 06:43:09 -0300 | [diff] [blame] | 537 | mutex_unlock(&ici->host_lock); |
Guennadi Liakhovetski | 9dc4e48 | 2008-04-22 14:45:32 -0300 | [diff] [blame] | 538 | if (ret < 0) { |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 539 | dev_err(icd->pdev, "Couldn't activate the camera: %d\n", ret); |
Guennadi Liakhovetski | 9dc4e48 | 2008-04-22 14:45:32 -0300 | [diff] [blame] | 540 | goto eiciadd; |
| 541 | } |
Guennadi Liakhovetski | df2ed07 | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 542 | |
Guennadi Liakhovetski | 7705b6d | 2012-03-14 07:22:07 -0300 | [diff] [blame] | 543 | ret = soc_camera_power_on(icd, icl); |
| 544 | if (ret < 0) |
| 545 | goto epower; |
| 546 | |
Mauro Carvalho Chehab | 4f9fb5e | 2010-05-18 00:46:09 -0300 | [diff] [blame] | 547 | pm_runtime_enable(&icd->vdev->dev); |
| 548 | ret = pm_runtime_resume(&icd->vdev->dev); |
| 549 | if (ret < 0 && ret != -ENOSYS) |
| 550 | goto eresume; |
| 551 | |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 552 | /* |
| 553 | * Try to configure with default parameters. Notice: this is the |
| 554 | * very first open, so, we cannot race against other calls, |
| 555 | * apart from someone else calling open() simultaneously, but |
| 556 | * .video_lock is protecting us against it. |
| 557 | */ |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 558 | ret = soc_camera_set_fmt(icd, &f); |
Guennadi Liakhovetski | df2ed07 | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 559 | if (ret < 0) |
| 560 | goto esfmt; |
Guennadi Liakhovetski | 24d8c02 | 2010-12-25 18:29:52 -0300 | [diff] [blame] | 561 | |
Guennadi Liakhovetski | 592c2ab | 2011-01-29 12:44:51 -0300 | [diff] [blame] | 562 | if (ici->ops->init_videobuf) { |
| 563 | ici->ops->init_videobuf(&icd->vb_vidq, icd); |
| 564 | } else { |
| 565 | ret = ici->ops->init_videobuf2(&icd->vb2_vidq, icd); |
| 566 | if (ret < 0) |
| 567 | goto einitvb; |
| 568 | } |
Hans Verkuil | ee02da6 | 2011-09-06 12:36:39 -0300 | [diff] [blame] | 569 | v4l2_ctrl_handler_setup(&icd->ctrl_handler); |
Guennadi Liakhovetski | 9dc4e48 | 2008-04-22 14:45:32 -0300 | [diff] [blame] | 570 | } |
| 571 | |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 572 | file->private_data = icd; |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 573 | dev_dbg(icd->pdev, "camera device open\n"); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 574 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 575 | return 0; |
| 576 | |
Guennadi Liakhovetski | df2ed07 | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 577 | /* |
Mauro Carvalho Chehab | 4f9fb5e | 2010-05-18 00:46:09 -0300 | [diff] [blame] | 578 | * First four errors are entered with the .video_lock held |
Guennadi Liakhovetski | df2ed07 | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 579 | * and use_count == 1 |
| 580 | */ |
Guennadi Liakhovetski | 592c2ab | 2011-01-29 12:44:51 -0300 | [diff] [blame] | 581 | einitvb: |
Guennadi Liakhovetski | df2ed07 | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 582 | esfmt: |
Mauro Carvalho Chehab | 4f9fb5e | 2010-05-18 00:46:09 -0300 | [diff] [blame] | 583 | pm_runtime_disable(&icd->vdev->dev); |
| 584 | eresume: |
Guennadi Liakhovetski | 3dcc731 | 2011-09-05 12:33:21 -0300 | [diff] [blame] | 585 | soc_camera_power_off(icd, icl); |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 586 | epower: |
Guennadi Liakhovetski | 7705b6d | 2012-03-14 07:22:07 -0300 | [diff] [blame] | 587 | ici->ops->remove(icd); |
| 588 | eiciadd: |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 589 | icd->use_count--; |
Guennadi Liakhovetski | b8d9904 | 2008-04-04 13:41:25 -0300 | [diff] [blame] | 590 | module_put(ici->ops->owner); |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 591 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 592 | return ret; |
| 593 | } |
| 594 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 595 | static int soc_camera_close(struct file *file) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 596 | { |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 597 | struct soc_camera_device *icd = file->private_data; |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 598 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 599 | |
Guennadi Liakhovetski | 9dc4e48 | 2008-04-22 14:45:32 -0300 | [diff] [blame] | 600 | icd->use_count--; |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 601 | if (!icd->use_count) { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 602 | struct soc_camera_link *icl = to_soc_camera_link(icd); |
| 603 | |
Mauro Carvalho Chehab | 4f9fb5e | 2010-05-18 00:46:09 -0300 | [diff] [blame] | 604 | pm_runtime_suspend(&icd->vdev->dev); |
| 605 | pm_runtime_disable(&icd->vdev->dev); |
| 606 | |
Guennadi Liakhovetski | 592c2ab | 2011-01-29 12:44:51 -0300 | [diff] [blame] | 607 | if (ici->ops->init_videobuf2) |
| 608 | vb2_queue_release(&icd->vb2_vidq); |
Lei Wen | 48ecf9f | 2011-11-22 11:04:29 -0300 | [diff] [blame] | 609 | ici->ops->remove(icd); |
Mauro Carvalho Chehab | 4f9fb5e | 2010-05-18 00:46:09 -0300 | [diff] [blame] | 610 | |
Guennadi Liakhovetski | 3dcc731 | 2011-09-05 12:33:21 -0300 | [diff] [blame] | 611 | soc_camera_power_off(icd, icl); |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 612 | } |
Guennadi Liakhovetski | 025c18a | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 613 | |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 614 | if (icd->streamer == file) |
| 615 | icd->streamer = NULL; |
| 616 | |
Guennadi Liakhovetski | b8d9904 | 2008-04-04 13:41:25 -0300 | [diff] [blame] | 617 | module_put(ici->ops->owner); |
Guennadi Liakhovetski | 9dc4e48 | 2008-04-22 14:45:32 -0300 | [diff] [blame] | 618 | |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 619 | dev_dbg(icd->pdev, "camera device close\n"); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 620 | |
| 621 | return 0; |
| 622 | } |
| 623 | |
Andrew Morton | aba360d | 2008-04-22 14:45:59 -0300 | [diff] [blame] | 624 | static ssize_t soc_camera_read(struct file *file, char __user *buf, |
Guennadi Liakhovetski | abe4c47 | 2008-12-01 09:44:56 -0300 | [diff] [blame] | 625 | size_t count, loff_t *ppos) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 626 | { |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 627 | struct soc_camera_device *icd = file->private_data; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 628 | int err = -EINVAL; |
| 629 | |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 630 | dev_err(icd->pdev, "camera device read not implemented\n"); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 631 | |
| 632 | return err; |
| 633 | } |
| 634 | |
| 635 | static int soc_camera_mmap(struct file *file, struct vm_area_struct *vma) |
| 636 | { |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 637 | struct soc_camera_device *icd = file->private_data; |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 638 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 639 | int err; |
| 640 | |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 641 | dev_dbg(icd->pdev, "mmap called, vma=0x%08lx\n", (unsigned long)vma); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 642 | |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 643 | if (icd->streamer != file) |
| 644 | return -EBUSY; |
| 645 | |
Guennadi Liakhovetski | 592c2ab | 2011-01-29 12:44:51 -0300 | [diff] [blame] | 646 | if (ici->ops->init_videobuf) |
| 647 | err = videobuf_mmap_mapper(&icd->vb_vidq, vma); |
| 648 | else |
| 649 | err = vb2_mmap(&icd->vb2_vidq, vma); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 650 | |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 651 | dev_dbg(icd->pdev, "vma start=0x%08lx, size=%ld, ret=%d\n", |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 652 | (unsigned long)vma->vm_start, |
| 653 | (unsigned long)vma->vm_end - (unsigned long)vma->vm_start, |
| 654 | err); |
| 655 | |
| 656 | return err; |
| 657 | } |
| 658 | |
| 659 | static unsigned int soc_camera_poll(struct file *file, poll_table *pt) |
| 660 | { |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 661 | struct soc_camera_device *icd = file->private_data; |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 662 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 663 | |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 664 | if (icd->streamer != file) |
| 665 | return -EBUSY; |
| 666 | |
Guennadi Liakhovetski | 592c2ab | 2011-01-29 12:44:51 -0300 | [diff] [blame] | 667 | if (ici->ops->init_videobuf && list_empty(&icd->vb_vidq.stream)) { |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 668 | dev_err(icd->pdev, "Trying to poll with no queued buffers!\n"); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 669 | return POLLERR; |
| 670 | } |
| 671 | |
Guennadi Liakhovetski | b8d9904 | 2008-04-04 13:41:25 -0300 | [diff] [blame] | 672 | return ici->ops->poll(file, pt); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 673 | } |
| 674 | |
Guennadi Liakhovetski | 592c2ab | 2011-01-29 12:44:51 -0300 | [diff] [blame] | 675 | void soc_camera_lock(struct vb2_queue *vq) |
| 676 | { |
| 677 | struct soc_camera_device *icd = vb2_get_drv_priv(vq); |
| 678 | mutex_lock(&icd->video_lock); |
| 679 | } |
| 680 | EXPORT_SYMBOL(soc_camera_lock); |
| 681 | |
| 682 | void soc_camera_unlock(struct vb2_queue *vq) |
| 683 | { |
| 684 | struct soc_camera_device *icd = vb2_get_drv_priv(vq); |
| 685 | mutex_unlock(&icd->video_lock); |
| 686 | } |
| 687 | EXPORT_SYMBOL(soc_camera_unlock); |
| 688 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 689 | static struct v4l2_file_operations soc_camera_fops = { |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 690 | .owner = THIS_MODULE, |
| 691 | .open = soc_camera_open, |
| 692 | .release = soc_camera_close, |
Guennadi Liakhovetski | b6a633c | 2010-12-25 17:40:26 -0300 | [diff] [blame] | 693 | .unlocked_ioctl = video_ioctl2, |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 694 | .read = soc_camera_read, |
| 695 | .mmap = soc_camera_mmap, |
| 696 | .poll = soc_camera_poll, |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 697 | }; |
| 698 | |
Hans Verkuil | 7293789 | 2008-06-01 10:35:18 -0300 | [diff] [blame] | 699 | static int soc_camera_s_fmt_vid_cap(struct file *file, void *priv, |
Guennadi Liakhovetski | abe4c47 | 2008-12-01 09:44:56 -0300 | [diff] [blame] | 700 | struct v4l2_format *f) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 701 | { |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 702 | struct soc_camera_device *icd = file->private_data; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 703 | int ret; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 704 | |
| 705 | WARN_ON(priv != file->private_data); |
| 706 | |
Guennadi Liakhovetski | d366d4a | 2011-03-21 06:33:25 -0300 | [diff] [blame] | 707 | if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 708 | dev_warn(icd->pdev, "Wrong buf-type %d\n", f->type); |
Guennadi Liakhovetski | d366d4a | 2011-03-21 06:33:25 -0300 | [diff] [blame] | 709 | return -EINVAL; |
| 710 | } |
| 711 | |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 712 | if (icd->streamer && icd->streamer != file) |
| 713 | return -EBUSY; |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 714 | |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 715 | if (is_streaming(to_soc_camera_host(icd->parent), icd)) { |
| 716 | dev_err(icd->pdev, "S_FMT denied: queue initialised\n"); |
Guennadi Liakhovetski | b6a633c | 2010-12-25 17:40:26 -0300 | [diff] [blame] | 717 | return -EBUSY; |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 718 | } |
| 719 | |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 720 | ret = soc_camera_set_fmt(icd, f); |
| 721 | |
| 722 | if (!ret && !icd->streamer) |
| 723 | icd->streamer = file; |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 724 | |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 725 | return ret; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 726 | } |
| 727 | |
Hans Verkuil | 7293789 | 2008-06-01 10:35:18 -0300 | [diff] [blame] | 728 | static int soc_camera_enum_fmt_vid_cap(struct file *file, void *priv, |
Guennadi Liakhovetski | abe4c47 | 2008-12-01 09:44:56 -0300 | [diff] [blame] | 729 | struct v4l2_fmtdesc *f) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 730 | { |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 731 | struct soc_camera_device *icd = file->private_data; |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 732 | const struct soc_mbus_pixelfmt *format; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 733 | |
| 734 | WARN_ON(priv != file->private_data); |
| 735 | |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 736 | if (f->index >= icd->num_user_formats) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 737 | return -EINVAL; |
| 738 | |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 739 | format = icd->user_formats[f->index].host_fmt; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 740 | |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 741 | if (format->name) |
| 742 | strlcpy(f->description, format->name, sizeof(f->description)); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 743 | f->pixelformat = format->fourcc; |
| 744 | return 0; |
| 745 | } |
| 746 | |
Hans Verkuil | 7293789 | 2008-06-01 10:35:18 -0300 | [diff] [blame] | 747 | static int soc_camera_g_fmt_vid_cap(struct file *file, void *priv, |
Guennadi Liakhovetski | abe4c47 | 2008-12-01 09:44:56 -0300 | [diff] [blame] | 748 | struct v4l2_format *f) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 749 | { |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 750 | struct soc_camera_device *icd = file->private_data; |
Guennadi Liakhovetski | 64f5905 | 2008-12-18 11:51:55 -0300 | [diff] [blame] | 751 | struct v4l2_pix_format *pix = &f->fmt.pix; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 752 | |
| 753 | WARN_ON(priv != file->private_data); |
| 754 | |
Guennadi Liakhovetski | d366d4a | 2011-03-21 06:33:25 -0300 | [diff] [blame] | 755 | if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 756 | return -EINVAL; |
| 757 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 758 | pix->width = icd->user_width; |
| 759 | pix->height = icd->user_height; |
Sergio Aguirre | 0e4c180 | 2011-03-07 21:49:48 -0300 | [diff] [blame] | 760 | pix->bytesperline = icd->bytesperline; |
| 761 | pix->sizeimage = icd->sizeimage; |
Guennadi Liakhovetski | 592c2ab | 2011-01-29 12:44:51 -0300 | [diff] [blame] | 762 | pix->field = icd->field; |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 763 | pix->pixelformat = icd->current_fmt->host_fmt->fourcc; |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 764 | pix->colorspace = icd->colorspace; |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 765 | dev_dbg(icd->pdev, "current_fmt->fourcc: 0x%08x\n", |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 766 | icd->current_fmt->host_fmt->fourcc); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 767 | return 0; |
| 768 | } |
| 769 | |
| 770 | static int soc_camera_querycap(struct file *file, void *priv, |
| 771 | struct v4l2_capability *cap) |
| 772 | { |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 773 | struct soc_camera_device *icd = file->private_data; |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 774 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 775 | |
| 776 | WARN_ON(priv != file->private_data); |
| 777 | |
| 778 | strlcpy(cap->driver, ici->drv_name, sizeof(cap->driver)); |
Guennadi Liakhovetski | b8d9904 | 2008-04-04 13:41:25 -0300 | [diff] [blame] | 779 | return ici->ops->querycap(ici, cap); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | static int soc_camera_streamon(struct file *file, void *priv, |
| 783 | enum v4l2_buf_type i) |
| 784 | { |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 785 | struct soc_camera_device *icd = file->private_data; |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 786 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
Guennadi Liakhovetski | c9c1f1c | 2009-08-25 11:46:59 -0300 | [diff] [blame] | 787 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 788 | int ret; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 789 | |
| 790 | WARN_ON(priv != file->private_data); |
| 791 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 792 | if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 793 | return -EINVAL; |
| 794 | |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 795 | if (icd->streamer != file) |
| 796 | return -EBUSY; |
| 797 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 798 | /* This calls buf_queue from host driver's videobuf_queue_ops */ |
Guennadi Liakhovetski | 592c2ab | 2011-01-29 12:44:51 -0300 | [diff] [blame] | 799 | if (ici->ops->init_videobuf) |
| 800 | ret = videobuf_streamon(&icd->vb_vidq); |
| 801 | else |
| 802 | ret = vb2_streamon(&icd->vb2_vidq, i); |
| 803 | |
Anatolij Gustschin | 7fdbd85 | 2011-01-31 09:19:32 -0300 | [diff] [blame] | 804 | if (!ret) |
| 805 | v4l2_subdev_call(sd, video, s_stream, 1); |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 806 | |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 807 | return ret; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | static int soc_camera_streamoff(struct file *file, void *priv, |
| 811 | enum v4l2_buf_type i) |
| 812 | { |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 813 | struct soc_camera_device *icd = file->private_data; |
Guennadi Liakhovetski | c9c1f1c | 2009-08-25 11:46:59 -0300 | [diff] [blame] | 814 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 815 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 816 | |
| 817 | WARN_ON(priv != file->private_data); |
| 818 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 819 | if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 820 | return -EINVAL; |
| 821 | |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 822 | if (icd->streamer != file) |
| 823 | return -EBUSY; |
| 824 | |
Guennadi Liakhovetski | 5d28d52 | 2009-12-11 11:15:05 -0300 | [diff] [blame] | 825 | /* |
| 826 | * This calls buf_release from host driver's videobuf_queue_ops for all |
| 827 | * remaining buffers. When the last buffer is freed, stop capture |
| 828 | */ |
Guennadi Liakhovetski | 592c2ab | 2011-01-29 12:44:51 -0300 | [diff] [blame] | 829 | if (ici->ops->init_videobuf) |
| 830 | videobuf_streamoff(&icd->vb_vidq); |
| 831 | else |
| 832 | vb2_streamoff(&icd->vb2_vidq, i); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 833 | |
Guennadi Liakhovetski | c9c1f1c | 2009-08-25 11:46:59 -0300 | [diff] [blame] | 834 | v4l2_subdev_call(sd, video, s_stream, 0); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 835 | |
| 836 | return 0; |
| 837 | } |
| 838 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 839 | static int soc_camera_cropcap(struct file *file, void *fh, |
| 840 | struct v4l2_cropcap *a) |
| 841 | { |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 842 | struct soc_camera_device *icd = file->private_data; |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 843 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 844 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 845 | return ici->ops->cropcap(icd, a); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | static int soc_camera_g_crop(struct file *file, void *fh, |
| 849 | struct v4l2_crop *a) |
| 850 | { |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 851 | struct soc_camera_device *icd = file->private_data; |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 852 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 853 | int ret; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 854 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 855 | ret = ici->ops->get_crop(icd, a); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 856 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 857 | return ret; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 858 | } |
| 859 | |
Guennadi Liakhovetski | 68a54f0 | 2009-08-25 11:46:52 -0300 | [diff] [blame] | 860 | /* |
| 861 | * According to the V4L2 API, drivers shall not update the struct v4l2_crop |
| 862 | * argument with the actual geometry, instead, the user shall use G_CROP to |
Guennadi Liakhovetski | ab56d5e | 2010-03-23 11:31:46 -0300 | [diff] [blame] | 863 | * retrieve it. |
Guennadi Liakhovetski | 68a54f0 | 2009-08-25 11:46:52 -0300 | [diff] [blame] | 864 | */ |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 865 | static int soc_camera_s_crop(struct file *file, void *fh, |
| 866 | struct v4l2_crop *a) |
| 867 | { |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 868 | struct soc_camera_device *icd = file->private_data; |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 869 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 870 | struct v4l2_rect *rect = &a->c; |
| 871 | struct v4l2_crop current_crop; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 872 | int ret; |
| 873 | |
| 874 | if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 875 | return -EINVAL; |
| 876 | |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 877 | dev_dbg(icd->pdev, "S_CROP(%ux%u@%u:%u)\n", |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 878 | rect->width, rect->height, rect->left, rect->top); |
| 879 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 880 | /* If get_crop fails, we'll let host and / or client drivers decide */ |
| 881 | ret = ici->ops->get_crop(icd, ¤t_crop); |
| 882 | |
Guennadi Liakhovetski | b897a91 | 2009-08-25 11:46:53 -0300 | [diff] [blame] | 883 | /* Prohibit window size change with initialised buffers */ |
Guennadi Liakhovetski | 103754a | 2010-08-05 19:23:44 -0300 | [diff] [blame] | 884 | if (ret < 0) { |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 885 | dev_err(icd->pdev, |
Guennadi Liakhovetski | 103754a | 2010-08-05 19:23:44 -0300 | [diff] [blame] | 886 | "S_CROP denied: getting current crop failed\n"); |
Guennadi Liakhovetski | aee5c2f | 2011-03-28 13:28:28 -0300 | [diff] [blame] | 887 | } else if ((a->c.width == current_crop.c.width && |
| 888 | a->c.height == current_crop.c.height) || |
| 889 | !is_streaming(ici, icd)) { |
| 890 | /* same size or not streaming - use .set_crop() */ |
| 891 | ret = ici->ops->set_crop(icd, a); |
| 892 | } else if (ici->ops->set_livecrop) { |
| 893 | ret = ici->ops->set_livecrop(icd, a); |
| 894 | } else { |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 895 | dev_err(icd->pdev, |
Guennadi Liakhovetski | b897a91 | 2009-08-25 11:46:53 -0300 | [diff] [blame] | 896 | "S_CROP denied: queue initialised and sizes differ\n"); |
| 897 | ret = -EBUSY; |
Guennadi Liakhovetski | b897a91 | 2009-08-25 11:46:53 -0300 | [diff] [blame] | 898 | } |
| 899 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 900 | return ret; |
| 901 | } |
| 902 | |
Guennadi Liakhovetski | c9f6ef6 | 2010-02-09 18:00:30 +0100 | [diff] [blame] | 903 | static int soc_camera_g_parm(struct file *file, void *fh, |
| 904 | struct v4l2_streamparm *a) |
| 905 | { |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 906 | struct soc_camera_device *icd = file->private_data; |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 907 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
Guennadi Liakhovetski | c9f6ef6 | 2010-02-09 18:00:30 +0100 | [diff] [blame] | 908 | |
| 909 | if (ici->ops->get_parm) |
| 910 | return ici->ops->get_parm(icd, a); |
| 911 | |
| 912 | return -ENOIOCTLCMD; |
| 913 | } |
| 914 | |
| 915 | static int soc_camera_s_parm(struct file *file, void *fh, |
| 916 | struct v4l2_streamparm *a) |
| 917 | { |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 918 | struct soc_camera_device *icd = file->private_data; |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 919 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
Guennadi Liakhovetski | c9f6ef6 | 2010-02-09 18:00:30 +0100 | [diff] [blame] | 920 | |
| 921 | if (ici->ops->set_parm) |
| 922 | return ici->ops->set_parm(icd, a); |
| 923 | |
| 924 | return -ENOIOCTLCMD; |
| 925 | } |
| 926 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 927 | static int soc_camera_g_chip_ident(struct file *file, void *fh, |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 928 | struct v4l2_dbg_chip_ident *id) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 929 | { |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 930 | struct soc_camera_device *icd = file->private_data; |
Guennadi Liakhovetski | c9c1f1c | 2009-08-25 11:46:59 -0300 | [diff] [blame] | 931 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 932 | |
Guennadi Liakhovetski | c9c1f1c | 2009-08-25 11:46:59 -0300 | [diff] [blame] | 933 | return v4l2_subdev_call(sd, core, g_chip_ident, id); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 937 | static int soc_camera_g_register(struct file *file, void *fh, |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 938 | struct v4l2_dbg_register *reg) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 939 | { |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 940 | struct soc_camera_device *icd = file->private_data; |
Guennadi Liakhovetski | c9c1f1c | 2009-08-25 11:46:59 -0300 | [diff] [blame] | 941 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 942 | |
Guennadi Liakhovetski | c9c1f1c | 2009-08-25 11:46:59 -0300 | [diff] [blame] | 943 | return v4l2_subdev_call(sd, core, g_register, reg); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | static int soc_camera_s_register(struct file *file, void *fh, |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 947 | struct v4l2_dbg_register *reg) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 948 | { |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 949 | struct soc_camera_device *icd = file->private_data; |
Guennadi Liakhovetski | c9c1f1c | 2009-08-25 11:46:59 -0300 | [diff] [blame] | 950 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 951 | |
Guennadi Liakhovetski | c9c1f1c | 2009-08-25 11:46:59 -0300 | [diff] [blame] | 952 | return v4l2_subdev_call(sd, core, s_register, reg); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 953 | } |
| 954 | #endif |
| 955 | |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 956 | static int soc_camera_probe(struct soc_camera_device *icd); |
| 957 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 958 | /* So far this function cannot fail */ |
| 959 | static void scan_add_host(struct soc_camera_host *ici) |
| 960 | { |
| 961 | struct soc_camera_device *icd; |
| 962 | |
Guennadi Liakhovetski | 2f9a0c8 | 2012-04-18 06:43:09 -0300 | [diff] [blame] | 963 | mutex_lock(&ici->host_lock); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 964 | |
| 965 | list_for_each_entry(icd, &devices, list) { |
| 966 | if (icd->iface == ici->nr) { |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 967 | int ret; |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 968 | |
| 969 | icd->parent = ici->v4l2_dev.dev; |
| 970 | ret = soc_camera_probe(icd); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 971 | } |
| 972 | } |
| 973 | |
Guennadi Liakhovetski | 2f9a0c8 | 2012-04-18 06:43:09 -0300 | [diff] [blame] | 974 | mutex_unlock(&ici->host_lock); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 975 | } |
| 976 | |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 977 | #ifdef CONFIG_I2C_BOARDINFO |
| 978 | static int soc_camera_init_i2c(struct soc_camera_device *icd, |
| 979 | struct soc_camera_link *icl) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 980 | { |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 981 | struct i2c_client *client; |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 982 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 983 | struct i2c_adapter *adap = i2c_get_adapter(icl->i2c_adapter_id); |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 984 | struct v4l2_subdev *subdev; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 985 | |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 986 | if (!adap) { |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 987 | dev_err(icd->pdev, "Cannot get I2C adapter #%d. No driver?\n", |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 988 | icl->i2c_adapter_id); |
| 989 | goto ei2cga; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 990 | } |
| 991 | |
Guennadi Liakhovetski | 2f0babb7 | 2011-09-09 13:39:20 -0300 | [diff] [blame] | 992 | icl->board_info->platform_data = icl; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 993 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 994 | subdev = v4l2_i2c_new_subdev_board(&ici->v4l2_dev, adap, |
Laurent Pinchart | 9a1f8b3 | 2010-09-24 10:16:44 -0300 | [diff] [blame] | 995 | icl->board_info, NULL); |
Magnus Damm | d74f841 | 2010-02-09 17:40:40 +0900 | [diff] [blame] | 996 | if (!subdev) |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 997 | goto ei2cnd; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 998 | |
Laurent Pinchart | c4ce6d1 | 2010-07-30 17:24:54 -0300 | [diff] [blame] | 999 | client = v4l2_get_subdevdata(subdev); |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1000 | |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1001 | /* Use to_i2c_client(dev) to recover the i2c client */ |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 1002 | icd->control = &client->dev; |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1003 | |
| 1004 | return 0; |
| 1005 | ei2cnd: |
| 1006 | i2c_put_adapter(adap); |
| 1007 | ei2cga: |
Magnus Damm | d74f841 | 2010-02-09 17:40:40 +0900 | [diff] [blame] | 1008 | return -ENODEV; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1009 | } |
| 1010 | |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1011 | static void soc_camera_free_i2c(struct soc_camera_device *icd) |
| 1012 | { |
| 1013 | struct i2c_client *client = |
| 1014 | to_i2c_client(to_soc_camera_control(icd)); |
Guennadi Liakhovetski | c8dd707 | 2011-03-23 05:26:11 -0300 | [diff] [blame] | 1015 | struct i2c_adapter *adap = client->adapter; |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 1016 | |
| 1017 | icd->control = NULL; |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1018 | v4l2_device_unregister_subdev(i2c_get_clientdata(client)); |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1019 | i2c_unregister_device(client); |
Guennadi Liakhovetski | c8dd707 | 2011-03-23 05:26:11 -0300 | [diff] [blame] | 1020 | i2c_put_adapter(adap); |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1021 | } |
| 1022 | #else |
| 1023 | #define soc_camera_init_i2c(icd, icl) (-ENODEV) |
| 1024 | #define soc_camera_free_i2c(icd) do {} while (0) |
| 1025 | #endif |
| 1026 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1027 | static int soc_camera_video_start(struct soc_camera_device *icd); |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1028 | static int video_dev_create(struct soc_camera_device *icd); |
| 1029 | /* Called during host-driver probe */ |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 1030 | static int soc_camera_probe(struct soc_camera_device *icd) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1031 | { |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 1032 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1033 | struct soc_camera_link *icl = to_soc_camera_link(icd); |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1034 | struct device *control = NULL; |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 1035 | struct v4l2_subdev *sd; |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 1036 | struct v4l2_mbus_framefmt mf; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1037 | int ret; |
| 1038 | |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 1039 | dev_info(icd->pdev, "Probing %s\n", dev_name(icd->pdev)); |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 1040 | |
Hans Verkuil | ee02da6 | 2011-09-06 12:36:39 -0300 | [diff] [blame] | 1041 | /* |
| 1042 | * Currently the subdev with the largest number of controls (13) is |
| 1043 | * ov6550. So let's pick 16 as a hint for the control handler. Note |
| 1044 | * that this is a hint only: too large and you waste some memory, too |
| 1045 | * small and there is a (very) small performance hit when looking up |
| 1046 | * controls in the internal hash. |
| 1047 | */ |
| 1048 | ret = v4l2_ctrl_handler_init(&icd->ctrl_handler, 16); |
| 1049 | if (ret < 0) |
| 1050 | return ret; |
| 1051 | |
Alberto Panizzo | 96e442c | 2010-12-02 07:43:37 -0300 | [diff] [blame] | 1052 | ret = regulator_bulk_get(icd->pdev, icl->num_regulators, |
| 1053 | icl->regulators); |
| 1054 | if (ret < 0) |
| 1055 | goto ereg; |
| 1056 | |
Guennadi Liakhovetski | 7705b6d | 2012-03-14 07:22:07 -0300 | [diff] [blame] | 1057 | /* The camera could have been already on, try to reset */ |
| 1058 | if (icl->reset) |
| 1059 | icl->reset(icd->pdev); |
| 1060 | |
| 1061 | ret = ici->ops->add(icd); |
| 1062 | if (ret < 0) |
| 1063 | goto eadd; |
| 1064 | |
Guennadi Liakhovetski | 7b9d8c3 | 2011-09-08 04:36:06 -0300 | [diff] [blame] | 1065 | /* |
| 1066 | * This will not yet call v4l2_subdev_core_ops::s_power(1), because the |
| 1067 | * subdevice has not been initialised yet. We'll have to call it once |
| 1068 | * again after initialisation, even though it shouldn't be needed, we |
| 1069 | * don't do any IO here. |
| 1070 | */ |
Guennadi Liakhovetski | 3dcc731 | 2011-09-05 12:33:21 -0300 | [diff] [blame] | 1071 | ret = soc_camera_power_on(icd, icl); |
Alberto Panizzo | 96e442c | 2010-12-02 07:43:37 -0300 | [diff] [blame] | 1072 | if (ret < 0) |
| 1073 | goto epower; |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1074 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1075 | /* Must have icd->vdev before registering the device */ |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1076 | ret = video_dev_create(icd); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1077 | if (ret < 0) |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1078 | goto evdc; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1079 | |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1080 | /* Non-i2c cameras, e.g., soc_camera_platform, have no board_info */ |
| 1081 | if (icl->board_info) { |
| 1082 | ret = soc_camera_init_i2c(icd, icl); |
| 1083 | if (ret < 0) |
| 1084 | goto eadddev; |
| 1085 | } else if (!icl->add_device || !icl->del_device) { |
| 1086 | ret = -EINVAL; |
| 1087 | goto eadddev; |
| 1088 | } else { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1089 | if (icl->module_name) |
| 1090 | ret = request_module(icl->module_name); |
| 1091 | |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 1092 | ret = icl->add_device(icd); |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1093 | if (ret < 0) |
| 1094 | goto eadddev; |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1095 | |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 1096 | /* |
| 1097 | * FIXME: this is racy, have to use driver-binding notification, |
| 1098 | * when it is available |
| 1099 | */ |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1100 | control = to_soc_camera_control(icd); |
Guennadi Liakhovetski | 08590b9 | 2009-08-25 11:46:54 -0300 | [diff] [blame] | 1101 | if (!control || !control->driver || !dev_get_drvdata(control) || |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1102 | !try_module_get(control->driver->owner)) { |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 1103 | icl->del_device(icd); |
Guennadi Liakhovetski | 7ae77ee | 2011-09-28 09:25:28 -0300 | [diff] [blame] | 1104 | ret = -ENODEV; |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1105 | goto enodrv; |
| 1106 | } |
Guennadi Liakhovetski | 025c18a | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 1107 | } |
| 1108 | |
Guennadi Liakhovetski | 24105eb | 2011-03-23 05:41:28 -0300 | [diff] [blame] | 1109 | sd = soc_camera_to_subdev(icd); |
Guennadi Liakhovetski | 4c0b036 | 2011-12-05 16:01:13 -0300 | [diff] [blame] | 1110 | sd->grp_id = soc_camera_grp_id(icd); |
| 1111 | v4l2_set_subdev_hostdata(sd, icd); |
Guennadi Liakhovetski | 24105eb | 2011-03-23 05:41:28 -0300 | [diff] [blame] | 1112 | |
Hans Verkuil | ee02da6 | 2011-09-06 12:36:39 -0300 | [diff] [blame] | 1113 | if (v4l2_ctrl_add_handler(&icd->ctrl_handler, sd->ctrl_handler)) |
| 1114 | goto ectrl; |
| 1115 | |
Guennadi Liakhovetski | fa48984 | 2009-08-25 11:46:43 -0300 | [diff] [blame] | 1116 | /* At this point client .probe() should have run already */ |
| 1117 | ret = soc_camera_init_user_formats(icd); |
| 1118 | if (ret < 0) |
| 1119 | goto eiufmt; |
| 1120 | |
Guennadi Liakhovetski | fa48984 | 2009-08-25 11:46:43 -0300 | [diff] [blame] | 1121 | icd->field = V4L2_FIELD_ANY; |
| 1122 | |
Guennadi Liakhovetski | b6a633c | 2010-12-25 17:40:26 -0300 | [diff] [blame] | 1123 | /* |
| 1124 | * ..._video_start() will create a device node, video_register_device() |
| 1125 | * itself is protected against concurrent open() calls, but we also have |
| 1126 | * to protect our data. |
| 1127 | */ |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1128 | mutex_lock(&icd->video_lock); |
| 1129 | |
| 1130 | ret = soc_camera_video_start(icd); |
| 1131 | if (ret < 0) |
| 1132 | goto evidstart; |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1133 | |
Guennadi Liakhovetski | 7b9d8c3 | 2011-09-08 04:36:06 -0300 | [diff] [blame] | 1134 | ret = v4l2_subdev_call(sd, core, s_power, 1); |
| 1135 | if (ret < 0 && ret != -ENOIOCTLCMD) |
| 1136 | goto esdpwr; |
| 1137 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 1138 | /* Try to improve our guess of a reasonable window format */ |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 1139 | if (!v4l2_subdev_call(sd, video, g_mbus_fmt, &mf)) { |
| 1140 | icd->user_width = mf.width; |
| 1141 | icd->user_height = mf.height; |
| 1142 | icd->colorspace = mf.colorspace; |
| 1143 | icd->field = mf.field; |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 1144 | } |
| 1145 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1146 | ici->ops->remove(icd); |
| 1147 | |
Guennadi Liakhovetski | 3dcc731 | 2011-09-05 12:33:21 -0300 | [diff] [blame] | 1148 | soc_camera_power_off(icd, icl); |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1149 | |
| 1150 | mutex_unlock(&icd->video_lock); |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1151 | |
| 1152 | return 0; |
| 1153 | |
Guennadi Liakhovetski | 7b9d8c3 | 2011-09-08 04:36:06 -0300 | [diff] [blame] | 1154 | esdpwr: |
| 1155 | video_unregister_device(icd->vdev); |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1156 | evidstart: |
| 1157 | mutex_unlock(&icd->video_lock); |
Guennadi Liakhovetski | fa48984 | 2009-08-25 11:46:43 -0300 | [diff] [blame] | 1158 | soc_camera_free_user_formats(icd); |
| 1159 | eiufmt: |
Hans Verkuil | ee02da6 | 2011-09-06 12:36:39 -0300 | [diff] [blame] | 1160 | ectrl: |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1161 | if (icl->board_info) { |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1162 | soc_camera_free_i2c(icd); |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1163 | } else { |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 1164 | icl->del_device(icd); |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1165 | module_put(control->driver->owner); |
| 1166 | } |
| 1167 | enodrv: |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1168 | eadddev: |
| 1169 | video_device_release(icd->vdev); |
Guennadi Liakhovetski | 7b9d8c3 | 2011-09-08 04:36:06 -0300 | [diff] [blame] | 1170 | icd->vdev = NULL; |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1171 | evdc: |
Guennadi Liakhovetski | 3dcc731 | 2011-09-05 12:33:21 -0300 | [diff] [blame] | 1172 | soc_camera_power_off(icd, icl); |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1173 | epower: |
Guennadi Liakhovetski | 7705b6d | 2012-03-14 07:22:07 -0300 | [diff] [blame] | 1174 | ici->ops->remove(icd); |
| 1175 | eadd: |
Alberto Panizzo | 96e442c | 2010-12-02 07:43:37 -0300 | [diff] [blame] | 1176 | regulator_bulk_free(icl->num_regulators, icl->regulators); |
| 1177 | ereg: |
Hans Verkuil | ee02da6 | 2011-09-06 12:36:39 -0300 | [diff] [blame] | 1178 | v4l2_ctrl_handler_free(&icd->ctrl_handler); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1179 | return ret; |
| 1180 | } |
| 1181 | |
Guennadi Liakhovetski | 5d28d52 | 2009-12-11 11:15:05 -0300 | [diff] [blame] | 1182 | /* |
| 1183 | * This is called on device_unregister, which only means we have to disconnect |
| 1184 | * from the host, but not remove ourselves from the device list |
| 1185 | */ |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 1186 | static int soc_camera_remove(struct soc_camera_device *icd) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1187 | { |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1188 | struct soc_camera_link *icl = to_soc_camera_link(icd); |
| 1189 | struct video_device *vdev = icd->vdev; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1190 | |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 1191 | BUG_ON(!icd->parent); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1192 | |
Hans Verkuil | ee02da6 | 2011-09-06 12:36:39 -0300 | [diff] [blame] | 1193 | v4l2_ctrl_handler_free(&icd->ctrl_handler); |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1194 | if (vdev) { |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1195 | video_unregister_device(vdev); |
| 1196 | icd->vdev = NULL; |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1197 | } |
| 1198 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1199 | if (icl->board_info) { |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1200 | soc_camera_free_i2c(icd); |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1201 | } else { |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 1202 | struct device_driver *drv = to_soc_camera_control(icd)->driver; |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1203 | if (drv) { |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 1204 | icl->del_device(icd); |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1205 | module_put(drv->owner); |
| 1206 | } |
| 1207 | } |
Guennadi Liakhovetski | fa48984 | 2009-08-25 11:46:43 -0300 | [diff] [blame] | 1208 | soc_camera_free_user_formats(icd); |
Guennadi Liakhovetski | 025c18a | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 1209 | |
Alberto Panizzo | 96e442c | 2010-12-02 07:43:37 -0300 | [diff] [blame] | 1210 | regulator_bulk_free(icl->num_regulators, icl->regulators); |
| 1211 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1212 | return 0; |
| 1213 | } |
| 1214 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 1215 | static int default_cropcap(struct soc_camera_device *icd, |
| 1216 | struct v4l2_cropcap *a) |
| 1217 | { |
| 1218 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); |
| 1219 | return v4l2_subdev_call(sd, video, cropcap, a); |
| 1220 | } |
| 1221 | |
| 1222 | static int default_g_crop(struct soc_camera_device *icd, struct v4l2_crop *a) |
| 1223 | { |
| 1224 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); |
| 1225 | return v4l2_subdev_call(sd, video, g_crop, a); |
| 1226 | } |
| 1227 | |
| 1228 | static int default_s_crop(struct soc_camera_device *icd, struct v4l2_crop *a) |
| 1229 | { |
| 1230 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); |
| 1231 | return v4l2_subdev_call(sd, video, s_crop, a); |
| 1232 | } |
| 1233 | |
Janusz Krzysztofik | 06e1782 | 2010-09-10 22:26:16 -0300 | [diff] [blame] | 1234 | static int default_g_parm(struct soc_camera_device *icd, |
| 1235 | struct v4l2_streamparm *parm) |
| 1236 | { |
| 1237 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); |
| 1238 | return v4l2_subdev_call(sd, video, g_parm, parm); |
| 1239 | } |
| 1240 | |
| 1241 | static int default_s_parm(struct soc_camera_device *icd, |
| 1242 | struct v4l2_streamparm *parm) |
| 1243 | { |
| 1244 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); |
| 1245 | return v4l2_subdev_call(sd, video, s_parm, parm); |
| 1246 | } |
| 1247 | |
Guennadi Liakhovetski | ad3537b | 2012-05-08 13:00:51 -0300 | [diff] [blame] | 1248 | static int default_enum_framesizes(struct soc_camera_device *icd, |
| 1249 | struct v4l2_frmsizeenum *fsize) |
Qing Xu | ed5b65d | 2011-01-20 05:19:40 -0300 | [diff] [blame] | 1250 | { |
| 1251 | int ret; |
| 1252 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); |
| 1253 | const struct soc_camera_format_xlate *xlate; |
| 1254 | __u32 pixfmt = fsize->pixel_format; |
| 1255 | struct v4l2_frmsizeenum fsize_mbus = *fsize; |
| 1256 | |
| 1257 | xlate = soc_camera_xlate_by_fourcc(icd, pixfmt); |
| 1258 | if (!xlate) |
| 1259 | return -EINVAL; |
| 1260 | /* map xlate-code to pixel_format, sensor only handle xlate-code*/ |
| 1261 | fsize_mbus.pixel_format = xlate->code; |
| 1262 | |
| 1263 | ret = v4l2_subdev_call(sd, video, enum_mbus_fsizes, &fsize_mbus); |
| 1264 | if (ret < 0) |
| 1265 | return ret; |
| 1266 | |
| 1267 | *fsize = fsize_mbus; |
| 1268 | fsize->pixel_format = pixfmt; |
| 1269 | |
| 1270 | return 0; |
| 1271 | } |
| 1272 | |
Guennadi Liakhovetski | b8d9904 | 2008-04-04 13:41:25 -0300 | [diff] [blame] | 1273 | int soc_camera_host_register(struct soc_camera_host *ici) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1274 | { |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1275 | struct soc_camera_host *ix; |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1276 | int ret; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1277 | |
Guennadi Liakhovetski | 64f5905 | 2008-12-18 11:51:55 -0300 | [diff] [blame] | 1278 | if (!ici || !ici->ops || |
| 1279 | !ici->ops->try_fmt || |
| 1280 | !ici->ops->set_fmt || |
| 1281 | !ici->ops->set_bus_param || |
| 1282 | !ici->ops->querycap || |
Guennadi Liakhovetski | 592c2ab | 2011-01-29 12:44:51 -0300 | [diff] [blame] | 1283 | ((!ici->ops->init_videobuf || |
| 1284 | !ici->ops->reqbufs) && |
| 1285 | !ici->ops->init_videobuf2) || |
Guennadi Liakhovetski | 64f5905 | 2008-12-18 11:51:55 -0300 | [diff] [blame] | 1286 | !ici->ops->add || |
| 1287 | !ici->ops->remove || |
Guennadi Liakhovetski | eff505f | 2009-04-24 12:55:48 -0300 | [diff] [blame] | 1288 | !ici->ops->poll || |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1289 | !ici->v4l2_dev.dev) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1290 | return -EINVAL; |
| 1291 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 1292 | if (!ici->ops->set_crop) |
| 1293 | ici->ops->set_crop = default_s_crop; |
| 1294 | if (!ici->ops->get_crop) |
| 1295 | ici->ops->get_crop = default_g_crop; |
| 1296 | if (!ici->ops->cropcap) |
| 1297 | ici->ops->cropcap = default_cropcap; |
Janusz Krzysztofik | 06e1782 | 2010-09-10 22:26:16 -0300 | [diff] [blame] | 1298 | if (!ici->ops->set_parm) |
| 1299 | ici->ops->set_parm = default_s_parm; |
| 1300 | if (!ici->ops->get_parm) |
| 1301 | ici->ops->get_parm = default_g_parm; |
Guennadi Liakhovetski | ad3537b | 2012-05-08 13:00:51 -0300 | [diff] [blame] | 1302 | if (!ici->ops->enum_framesizes) |
| 1303 | ici->ops->enum_framesizes = default_enum_framesizes; |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 1304 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1305 | mutex_lock(&list_lock); |
| 1306 | list_for_each_entry(ix, &hosts, list) { |
| 1307 | if (ix->nr == ici->nr) { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1308 | ret = -EBUSY; |
| 1309 | goto edevreg; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1310 | } |
| 1311 | } |
| 1312 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1313 | ret = v4l2_device_register(ici->v4l2_dev.dev, &ici->v4l2_dev); |
| 1314 | if (ret < 0) |
| 1315 | goto edevreg; |
Guennadi Liakhovetski | eff505f | 2009-04-24 12:55:48 -0300 | [diff] [blame] | 1316 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1317 | list_add_tail(&ici->list, &hosts); |
| 1318 | mutex_unlock(&list_lock); |
| 1319 | |
Guennadi Liakhovetski | 2f9a0c8 | 2012-04-18 06:43:09 -0300 | [diff] [blame] | 1320 | mutex_init(&ici->host_lock); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1321 | scan_add_host(ici); |
| 1322 | |
| 1323 | return 0; |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1324 | |
| 1325 | edevreg: |
| 1326 | mutex_unlock(&list_lock); |
| 1327 | return ret; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1328 | } |
| 1329 | EXPORT_SYMBOL(soc_camera_host_register); |
| 1330 | |
| 1331 | /* Unregister all clients! */ |
| 1332 | void soc_camera_host_unregister(struct soc_camera_host *ici) |
| 1333 | { |
| 1334 | struct soc_camera_device *icd; |
| 1335 | |
| 1336 | mutex_lock(&list_lock); |
| 1337 | |
| 1338 | list_del(&ici->list); |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 1339 | list_for_each_entry(icd, &devices, list) |
| 1340 | if (icd->iface == ici->nr && to_soc_camera_control(icd)) |
| 1341 | soc_camera_remove(icd); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1342 | |
| 1343 | mutex_unlock(&list_lock); |
| 1344 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1345 | v4l2_device_unregister(&ici->v4l2_dev); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1346 | } |
| 1347 | EXPORT_SYMBOL(soc_camera_host_unregister); |
| 1348 | |
| 1349 | /* Image capture device */ |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1350 | static int soc_camera_device_register(struct soc_camera_device *icd) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1351 | { |
| 1352 | struct soc_camera_device *ix; |
| 1353 | int num = -1, i; |
| 1354 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1355 | for (i = 0; i < 256 && num < 0; i++) { |
| 1356 | num = i; |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1357 | /* Check if this index is available on this interface */ |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1358 | list_for_each_entry(ix, &devices, list) { |
| 1359 | if (ix->iface == icd->iface && ix->devnum == i) { |
| 1360 | num = -1; |
| 1361 | break; |
| 1362 | } |
| 1363 | } |
| 1364 | } |
| 1365 | |
| 1366 | if (num < 0) |
Guennadi Liakhovetski | 5d28d52 | 2009-12-11 11:15:05 -0300 | [diff] [blame] | 1367 | /* |
| 1368 | * ok, we have 256 cameras on this host... |
| 1369 | * man, stay reasonable... |
| 1370 | */ |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1371 | return -ENOMEM; |
| 1372 | |
Guennadi Liakhovetski | 64ff9ba | 2009-11-09 16:12:37 -0300 | [diff] [blame] | 1373 | icd->devnum = num; |
Guennadi Liakhovetski | 64f5905 | 2008-12-18 11:51:55 -0300 | [diff] [blame] | 1374 | icd->use_count = 0; |
| 1375 | icd->host_priv = NULL; |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 1376 | mutex_init(&icd->video_lock); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1377 | |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1378 | list_add_tail(&icd->list, &devices); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1379 | |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1380 | return 0; |
| 1381 | } |
| 1382 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1383 | static const struct v4l2_ioctl_ops soc_camera_ioctl_ops = { |
| 1384 | .vidioc_querycap = soc_camera_querycap, |
Guennadi Liakhovetski | 7ae77ee | 2011-09-28 09:25:28 -0300 | [diff] [blame] | 1385 | .vidioc_try_fmt_vid_cap = soc_camera_try_fmt_vid_cap, |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1386 | .vidioc_g_fmt_vid_cap = soc_camera_g_fmt_vid_cap, |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1387 | .vidioc_s_fmt_vid_cap = soc_camera_s_fmt_vid_cap, |
Guennadi Liakhovetski | 7ae77ee | 2011-09-28 09:25:28 -0300 | [diff] [blame] | 1388 | .vidioc_enum_fmt_vid_cap = soc_camera_enum_fmt_vid_cap, |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1389 | .vidioc_enum_input = soc_camera_enum_input, |
| 1390 | .vidioc_g_input = soc_camera_g_input, |
| 1391 | .vidioc_s_input = soc_camera_s_input, |
| 1392 | .vidioc_s_std = soc_camera_s_std, |
Guennadi Liakhovetski | 2f0babb7 | 2011-09-09 13:39:20 -0300 | [diff] [blame] | 1393 | .vidioc_g_std = soc_camera_g_std, |
Guennadi Liakhovetski | ad3537b | 2012-05-08 13:00:51 -0300 | [diff] [blame] | 1394 | .vidioc_enum_framesizes = soc_camera_enum_framesizes, |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1395 | .vidioc_reqbufs = soc_camera_reqbufs, |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1396 | .vidioc_querybuf = soc_camera_querybuf, |
| 1397 | .vidioc_qbuf = soc_camera_qbuf, |
| 1398 | .vidioc_dqbuf = soc_camera_dqbuf, |
Guennadi Liakhovetski | 7ae77ee | 2011-09-28 09:25:28 -0300 | [diff] [blame] | 1399 | .vidioc_create_bufs = soc_camera_create_bufs, |
| 1400 | .vidioc_prepare_buf = soc_camera_prepare_buf, |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1401 | .vidioc_streamon = soc_camera_streamon, |
| 1402 | .vidioc_streamoff = soc_camera_streamoff, |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1403 | .vidioc_cropcap = soc_camera_cropcap, |
| 1404 | .vidioc_g_crop = soc_camera_g_crop, |
| 1405 | .vidioc_s_crop = soc_camera_s_crop, |
Guennadi Liakhovetski | c9f6ef6 | 2010-02-09 18:00:30 +0100 | [diff] [blame] | 1406 | .vidioc_g_parm = soc_camera_g_parm, |
| 1407 | .vidioc_s_parm = soc_camera_s_parm, |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1408 | .vidioc_g_chip_ident = soc_camera_g_chip_ident, |
| 1409 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 1410 | .vidioc_g_register = soc_camera_g_register, |
| 1411 | .vidioc_s_register = soc_camera_s_register, |
| 1412 | #endif |
| 1413 | }; |
| 1414 | |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1415 | static int video_dev_create(struct soc_camera_device *icd) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1416 | { |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 1417 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1418 | struct video_device *vdev = video_device_alloc(); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1419 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1420 | if (!vdev) |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1421 | return -ENOMEM; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1422 | |
| 1423 | strlcpy(vdev->name, ici->drv_name, sizeof(vdev->name)); |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 1424 | |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 1425 | vdev->parent = icd->pdev; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1426 | vdev->current_norm = V4L2_STD_UNKNOWN; |
| 1427 | vdev->fops = &soc_camera_fops; |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1428 | vdev->ioctl_ops = &soc_camera_ioctl_ops; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1429 | vdev->release = video_device_release; |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1430 | vdev->tvnorms = V4L2_STD_UNKNOWN; |
Hans Verkuil | ee02da6 | 2011-09-06 12:36:39 -0300 | [diff] [blame] | 1431 | vdev->ctrl_handler = &icd->ctrl_handler; |
Guennadi Liakhovetski | 7a05dfe | 2011-06-29 07:46:40 -0300 | [diff] [blame] | 1432 | vdev->lock = &icd->video_lock; |
Hans Verkuil | 5126f25 | 2012-05-10 04:57:22 -0300 | [diff] [blame] | 1433 | /* Locking in file operations other than ioctl should be done |
| 1434 | by the driver, not the V4L2 core. |
| 1435 | This driver needs auditing so that this flag can be removed. */ |
| 1436 | set_bit(V4L2_FL_LOCK_ALL_FOPS, &vdev->flags); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1437 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1438 | icd->vdev = vdev; |
| 1439 | |
| 1440 | return 0; |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1441 | } |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1442 | |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1443 | /* |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1444 | * Called from soc_camera_probe() above (with .video_lock held???) |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1445 | */ |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1446 | static int soc_camera_video_start(struct soc_camera_device *icd) |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1447 | { |
Mauro Carvalho Chehab | d364ee4 | 2011-06-01 15:03:56 -0300 | [diff] [blame] | 1448 | const struct device_type *type = icd->vdev->dev.type; |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1449 | int ret; |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1450 | |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 1451 | if (!icd->parent) |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1452 | return -ENODEV; |
| 1453 | |
Laurent Pinchart | 46b2109 | 2009-12-10 11:51:38 -0200 | [diff] [blame] | 1454 | ret = video_register_device(icd->vdev, VFL_TYPE_GRABBER, -1); |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1455 | if (ret < 0) { |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 1456 | dev_err(icd->pdev, "video_register_device failed: %d\n", ret); |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1457 | return ret; |
| 1458 | } |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1459 | |
Mauro Carvalho Chehab | 4f9fb5e | 2010-05-18 00:46:09 -0300 | [diff] [blame] | 1460 | /* Restore device type, possibly set by the subdevice driver */ |
| 1461 | icd->vdev->dev.type = type; |
| 1462 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1463 | return 0; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1464 | } |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1465 | |
Guennadi Liakhovetski | c41deba | 2009-08-25 11:06:21 -0300 | [diff] [blame] | 1466 | static int __devinit soc_camera_pdrv_probe(struct platform_device *pdev) |
| 1467 | { |
| 1468 | struct soc_camera_link *icl = pdev->dev.platform_data; |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1469 | struct soc_camera_device *icd; |
| 1470 | int ret; |
Guennadi Liakhovetski | c41deba | 2009-08-25 11:06:21 -0300 | [diff] [blame] | 1471 | |
| 1472 | if (!icl) |
| 1473 | return -EINVAL; |
| 1474 | |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1475 | icd = kzalloc(sizeof(*icd), GFP_KERNEL); |
| 1476 | if (!icd) |
| 1477 | return -ENOMEM; |
Guennadi Liakhovetski | c41deba | 2009-08-25 11:06:21 -0300 | [diff] [blame] | 1478 | |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1479 | icd->iface = icl->bus_id; |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 1480 | icd->link = icl; |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1481 | icd->pdev = &pdev->dev; |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1482 | platform_set_drvdata(pdev, icd); |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1483 | |
| 1484 | ret = soc_camera_device_register(icd); |
| 1485 | if (ret < 0) |
| 1486 | goto escdevreg; |
| 1487 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 1488 | icd->user_width = DEFAULT_WIDTH; |
| 1489 | icd->user_height = DEFAULT_HEIGHT; |
| 1490 | |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1491 | return 0; |
| 1492 | |
| 1493 | escdevreg: |
| 1494 | kfree(icd); |
| 1495 | |
| 1496 | return ret; |
Guennadi Liakhovetski | c41deba | 2009-08-25 11:06:21 -0300 | [diff] [blame] | 1497 | } |
| 1498 | |
Guennadi Liakhovetski | 5d28d52 | 2009-12-11 11:15:05 -0300 | [diff] [blame] | 1499 | /* |
| 1500 | * Only called on rmmod for each platform device, since they are not |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1501 | * hot-pluggable. Now we know, that all our users - hosts and devices have |
Guennadi Liakhovetski | 5d28d52 | 2009-12-11 11:15:05 -0300 | [diff] [blame] | 1502 | * been unloaded already |
| 1503 | */ |
Guennadi Liakhovetski | c41deba | 2009-08-25 11:06:21 -0300 | [diff] [blame] | 1504 | static int __devexit soc_camera_pdrv_remove(struct platform_device *pdev) |
| 1505 | { |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1506 | struct soc_camera_device *icd = platform_get_drvdata(pdev); |
Guennadi Liakhovetski | c41deba | 2009-08-25 11:06:21 -0300 | [diff] [blame] | 1507 | |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1508 | if (!icd) |
| 1509 | return -EINVAL; |
| 1510 | |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 1511 | list_del(&icd->list); |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1512 | |
| 1513 | kfree(icd); |
| 1514 | |
Guennadi Liakhovetski | 0fd327b | 2009-05-07 13:25:32 -0300 | [diff] [blame] | 1515 | return 0; |
| 1516 | } |
| 1517 | |
| 1518 | static struct platform_driver __refdata soc_camera_pdrv = { |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1519 | .remove = __devexit_p(soc_camera_pdrv_remove), |
| 1520 | .driver = { |
| 1521 | .name = "soc-camera-pdrv", |
| 1522 | .owner = THIS_MODULE, |
Guennadi Liakhovetski | 0fd327b | 2009-05-07 13:25:32 -0300 | [diff] [blame] | 1523 | }, |
| 1524 | }; |
| 1525 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1526 | static int __init soc_camera_init(void) |
| 1527 | { |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 1528 | return platform_driver_probe(&soc_camera_pdrv, soc_camera_pdrv_probe); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | static void __exit soc_camera_exit(void) |
| 1532 | { |
Guennadi Liakhovetski | 0fd327b | 2009-05-07 13:25:32 -0300 | [diff] [blame] | 1533 | platform_driver_unregister(&soc_camera_pdrv); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1534 | } |
| 1535 | |
| 1536 | module_init(soc_camera_init); |
| 1537 | module_exit(soc_camera_exit); |
| 1538 | |
| 1539 | MODULE_DESCRIPTION("Image capture bus driver"); |
| 1540 | MODULE_AUTHOR("Guennadi Liakhovetski <kernel@pengutronix.de>"); |
| 1541 | MODULE_LICENSE("GPL"); |
Guennadi Liakhovetski | 0fd327b | 2009-05-07 13:25:32 -0300 | [diff] [blame] | 1542 | MODULE_ALIAS("platform:soc-camera-pdrv"); |