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 | |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/device.h> |
| 22 | #include <linux/list.h> |
| 23 | #include <linux/err.h> |
| 24 | #include <linux/mutex.h> |
| 25 | #include <linux/vmalloc.h> |
| 26 | |
| 27 | #include <media/v4l2-common.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 28 | #include <media/v4l2-ioctl.h> |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 29 | #include <media/v4l2-dev.h> |
Paulius Zaleckas | 092d392 | 2008-07-11 20:50:31 -0300 | [diff] [blame] | 30 | #include <media/videobuf-core.h> |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 31 | #include <media/soc_camera.h> |
| 32 | |
| 33 | static LIST_HEAD(hosts); |
| 34 | static LIST_HEAD(devices); |
| 35 | static DEFINE_MUTEX(list_lock); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 36 | |
Guennadi Liakhovetski | 25c4d74 | 2008-12-01 09:44:59 -0300 | [diff] [blame] | 37 | const struct soc_camera_data_format *soc_camera_format_by_fourcc( |
Guennadi Liakhovetski | abe4c47 | 2008-12-01 09:44:56 -0300 | [diff] [blame] | 38 | struct soc_camera_device *icd, unsigned int fourcc) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 39 | { |
| 40 | unsigned int i; |
| 41 | |
Guennadi Liakhovetski | 26f1b94 | 2008-03-24 12:18:36 -0300 | [diff] [blame] | 42 | for (i = 0; i < icd->num_formats; i++) |
| 43 | if (icd->formats[i].fourcc == fourcc) |
| 44 | return icd->formats + i; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 45 | return NULL; |
| 46 | } |
Guennadi Liakhovetski | 25c4d74 | 2008-12-01 09:44:59 -0300 | [diff] [blame] | 47 | EXPORT_SYMBOL(soc_camera_format_by_fourcc); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 48 | |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 49 | const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc( |
| 50 | struct soc_camera_device *icd, unsigned int fourcc) |
| 51 | { |
| 52 | unsigned int i; |
| 53 | |
| 54 | for (i = 0; i < icd->num_user_formats; i++) |
| 55 | if (icd->user_formats[i].host_fmt->fourcc == fourcc) |
| 56 | return icd->user_formats + i; |
| 57 | return NULL; |
| 58 | } |
| 59 | EXPORT_SYMBOL(soc_camera_xlate_by_fourcc); |
| 60 | |
Guennadi Liakhovetski | bd73b36 | 2008-12-23 05:54:45 -0300 | [diff] [blame] | 61 | /** |
| 62 | * soc_camera_apply_sensor_flags() - apply platform SOCAM_SENSOR_INVERT_* flags |
| 63 | * @icl: camera platform parameters |
| 64 | * @flags: flags to be inverted according to platform configuration |
| 65 | * @return: resulting flags |
| 66 | */ |
| 67 | unsigned long soc_camera_apply_sensor_flags(struct soc_camera_link *icl, |
| 68 | unsigned long flags) |
| 69 | { |
| 70 | unsigned long f; |
| 71 | |
| 72 | /* If only one of the two polarities is supported, switch to the opposite */ |
| 73 | if (icl->flags & SOCAM_SENSOR_INVERT_HSYNC) { |
| 74 | f = flags & (SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW); |
| 75 | if (f == SOCAM_HSYNC_ACTIVE_HIGH || f == SOCAM_HSYNC_ACTIVE_LOW) |
| 76 | flags ^= SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW; |
| 77 | } |
| 78 | |
| 79 | if (icl->flags & SOCAM_SENSOR_INVERT_VSYNC) { |
| 80 | f = flags & (SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW); |
| 81 | if (f == SOCAM_VSYNC_ACTIVE_HIGH || f == SOCAM_VSYNC_ACTIVE_LOW) |
| 82 | flags ^= SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW; |
| 83 | } |
| 84 | |
| 85 | if (icl->flags & SOCAM_SENSOR_INVERT_PCLK) { |
| 86 | f = flags & (SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING); |
| 87 | if (f == SOCAM_PCLK_SAMPLE_RISING || f == SOCAM_PCLK_SAMPLE_FALLING) |
| 88 | flags ^= SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING; |
| 89 | } |
| 90 | |
| 91 | return flags; |
| 92 | } |
| 93 | EXPORT_SYMBOL(soc_camera_apply_sensor_flags); |
| 94 | |
Hans Verkuil | 7293789 | 2008-06-01 10:35:18 -0300 | [diff] [blame] | 95 | 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] | 96 | struct v4l2_format *f) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 97 | { |
| 98 | struct soc_camera_file *icf = file->private_data; |
| 99 | struct soc_camera_device *icd = icf->icd; |
Guennadi Liakhovetski | 64f5905 | 2008-12-18 11:51:55 -0300 | [diff] [blame] | 100 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 101 | |
| 102 | WARN_ON(priv != file->private_data); |
| 103 | |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 104 | /* limit format to hardware capabilities */ |
Guennadi Liakhovetski | 06daa1a | 2008-12-18 12:52:08 -0300 | [diff] [blame] | 105 | return ici->ops->try_fmt(icd, f); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | static int soc_camera_enum_input(struct file *file, void *priv, |
| 109 | struct v4l2_input *inp) |
| 110 | { |
Kuninori Morimoto | 34d359d | 2008-12-18 12:47:46 -0300 | [diff] [blame] | 111 | struct soc_camera_file *icf = file->private_data; |
| 112 | struct soc_camera_device *icd = icf->icd; |
| 113 | int ret = 0; |
| 114 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 115 | if (inp->index != 0) |
| 116 | return -EINVAL; |
| 117 | |
Kuninori Morimoto | 34d359d | 2008-12-18 12:47:46 -0300 | [diff] [blame] | 118 | if (icd->ops->enum_input) |
| 119 | ret = icd->ops->enum_input(icd, inp); |
| 120 | else { |
| 121 | /* default is camera */ |
| 122 | inp->type = V4L2_INPUT_TYPE_CAMERA; |
| 123 | inp->std = V4L2_STD_UNKNOWN; |
| 124 | strcpy(inp->name, "Camera"); |
| 125 | } |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 126 | |
Kuninori Morimoto | 34d359d | 2008-12-18 12:47:46 -0300 | [diff] [blame] | 127 | return ret; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | static int soc_camera_g_input(struct file *file, void *priv, unsigned int *i) |
| 131 | { |
| 132 | *i = 0; |
| 133 | |
| 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | static int soc_camera_s_input(struct file *file, void *priv, unsigned int i) |
| 138 | { |
| 139 | if (i > 0) |
| 140 | return -EINVAL; |
| 141 | |
| 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | static int soc_camera_s_std(struct file *file, void *priv, v4l2_std_id *a) |
| 146 | { |
Kuninori Morimoto | 513791a | 2008-12-18 12:46:45 -0300 | [diff] [blame] | 147 | struct soc_camera_file *icf = file->private_data; |
| 148 | struct soc_camera_device *icd = icf->icd; |
| 149 | int ret = 0; |
| 150 | |
| 151 | if (icd->ops->set_std) |
| 152 | ret = icd->ops->set_std(icd, a); |
| 153 | |
| 154 | return ret; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | static int soc_camera_reqbufs(struct file *file, void *priv, |
| 158 | struct v4l2_requestbuffers *p) |
| 159 | { |
| 160 | int ret; |
| 161 | struct soc_camera_file *icf = file->private_data; |
| 162 | struct soc_camera_device *icd = icf->icd; |
Guennadi Liakhovetski | 64f5905 | 2008-12-18 11:51:55 -0300 | [diff] [blame] | 163 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 164 | |
| 165 | WARN_ON(priv != file->private_data); |
| 166 | |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 167 | dev_dbg(&icd->dev, "%s: %d\n", __func__, p->memory); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 168 | |
| 169 | ret = videobuf_reqbufs(&icf->vb_vidq, p); |
| 170 | if (ret < 0) |
| 171 | return ret; |
| 172 | |
Guennadi Liakhovetski | b8d9904 | 2008-04-04 13:41:25 -0300 | [diff] [blame] | 173 | return ici->ops->reqbufs(icf, p); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | static int soc_camera_querybuf(struct file *file, void *priv, |
| 177 | struct v4l2_buffer *p) |
| 178 | { |
| 179 | struct soc_camera_file *icf = file->private_data; |
| 180 | |
| 181 | WARN_ON(priv != file->private_data); |
| 182 | |
| 183 | return videobuf_querybuf(&icf->vb_vidq, p); |
| 184 | } |
| 185 | |
| 186 | static int soc_camera_qbuf(struct file *file, void *priv, |
| 187 | struct v4l2_buffer *p) |
| 188 | { |
| 189 | struct soc_camera_file *icf = file->private_data; |
| 190 | |
| 191 | WARN_ON(priv != file->private_data); |
| 192 | |
| 193 | return videobuf_qbuf(&icf->vb_vidq, p); |
| 194 | } |
| 195 | |
| 196 | static int soc_camera_dqbuf(struct file *file, void *priv, |
| 197 | struct v4l2_buffer *p) |
| 198 | { |
| 199 | struct soc_camera_file *icf = file->private_data; |
| 200 | |
| 201 | WARN_ON(priv != file->private_data); |
| 202 | |
| 203 | return videobuf_dqbuf(&icf->vb_vidq, p, file->f_flags & O_NONBLOCK); |
| 204 | } |
| 205 | |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 206 | static int soc_camera_init_user_formats(struct soc_camera_device *icd) |
| 207 | { |
| 208 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
| 209 | int i, fmts = 0; |
| 210 | |
| 211 | if (!ici->ops->get_formats) |
| 212 | /* |
| 213 | * Fallback mode - the host will have to serve all |
| 214 | * sensor-provided formats one-to-one to the user |
| 215 | */ |
| 216 | fmts = icd->num_formats; |
| 217 | else |
| 218 | /* |
| 219 | * First pass - only count formats this host-sensor |
| 220 | * configuration can provide |
| 221 | */ |
| 222 | for (i = 0; i < icd->num_formats; i++) |
| 223 | fmts += ici->ops->get_formats(icd, i, NULL); |
| 224 | |
| 225 | if (!fmts) |
| 226 | return -ENXIO; |
| 227 | |
| 228 | icd->user_formats = |
| 229 | vmalloc(fmts * sizeof(struct soc_camera_format_xlate)); |
| 230 | if (!icd->user_formats) |
| 231 | return -ENOMEM; |
| 232 | |
| 233 | icd->num_user_formats = fmts; |
| 234 | fmts = 0; |
| 235 | |
| 236 | dev_dbg(&icd->dev, "Found %d supported formats.\n", fmts); |
| 237 | |
| 238 | /* Second pass - actually fill data formats */ |
| 239 | for (i = 0; i < icd->num_formats; i++) |
| 240 | if (!ici->ops->get_formats) { |
| 241 | icd->user_formats[i].host_fmt = icd->formats + i; |
| 242 | icd->user_formats[i].cam_fmt = icd->formats + i; |
| 243 | icd->user_formats[i].buswidth = icd->formats[i].depth; |
| 244 | } else { |
| 245 | fmts += ici->ops->get_formats(icd, i, |
| 246 | &icd->user_formats[fmts]); |
| 247 | } |
| 248 | |
| 249 | icd->current_fmt = icd->user_formats[0].host_fmt; |
| 250 | |
| 251 | return 0; |
| 252 | } |
| 253 | |
| 254 | static void soc_camera_free_user_formats(struct soc_camera_device *icd) |
| 255 | { |
| 256 | vfree(icd->user_formats); |
| 257 | } |
| 258 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 259 | static int soc_camera_open(struct file *file) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 260 | { |
Guennadi Liakhovetski | 9dc4e48 | 2008-04-22 14:45:32 -0300 | [diff] [blame] | 261 | struct video_device *vdev; |
| 262 | struct soc_camera_device *icd; |
| 263 | struct soc_camera_host *ici; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 264 | struct soc_camera_file *icf; |
| 265 | int ret; |
| 266 | |
| 267 | icf = vmalloc(sizeof(*icf)); |
| 268 | if (!icf) |
| 269 | return -ENOMEM; |
| 270 | |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 271 | /* |
| 272 | * It is safe to dereference these pointers now as long as a user has |
| 273 | * the video device open - we are protected by the held cdev reference. |
| 274 | */ |
Guennadi Liakhovetski | 9dc4e48 | 2008-04-22 14:45:32 -0300 | [diff] [blame] | 275 | |
| 276 | vdev = video_devdata(file); |
Hans Verkuil | 5e85e73 | 2008-07-20 06:31:39 -0300 | [diff] [blame] | 277 | icd = container_of(vdev->parent, struct soc_camera_device, dev); |
Guennadi Liakhovetski | 9dc4e48 | 2008-04-22 14:45:32 -0300 | [diff] [blame] | 278 | ici = to_soc_camera_host(icd->dev.parent); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 279 | |
| 280 | if (!try_module_get(icd->ops->owner)) { |
| 281 | dev_err(&icd->dev, "Couldn't lock sensor driver.\n"); |
| 282 | ret = -EINVAL; |
| 283 | goto emgd; |
| 284 | } |
| 285 | |
Guennadi Liakhovetski | b8d9904 | 2008-04-04 13:41:25 -0300 | [diff] [blame] | 286 | if (!try_module_get(ici->ops->owner)) { |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 287 | dev_err(&icd->dev, "Couldn't lock capture bus driver.\n"); |
| 288 | ret = -EINVAL; |
| 289 | goto emgi; |
| 290 | } |
| 291 | |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 292 | /* Protect against icd->remove() until we module_get() both drivers. */ |
| 293 | mutex_lock(&icd->video_lock); |
| 294 | |
Guennadi Liakhovetski | 9dc4e48 | 2008-04-22 14:45:32 -0300 | [diff] [blame] | 295 | icf->icd = icd; |
Guennadi Liakhovetski | 1a0063a | 2008-04-04 13:46:34 -0300 | [diff] [blame] | 296 | icd->use_count++; |
| 297 | |
Guennadi Liakhovetski | 9dc4e48 | 2008-04-22 14:45:32 -0300 | [diff] [blame] | 298 | /* Now we really have to activate the camera */ |
| 299 | if (icd->use_count == 1) { |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 300 | ret = soc_camera_init_user_formats(icd); |
| 301 | if (ret < 0) |
| 302 | goto eiufmt; |
Guennadi Liakhovetski | b8d9904 | 2008-04-04 13:41:25 -0300 | [diff] [blame] | 303 | ret = ici->ops->add(icd); |
Guennadi Liakhovetski | 9dc4e48 | 2008-04-22 14:45:32 -0300 | [diff] [blame] | 304 | if (ret < 0) { |
| 305 | dev_err(&icd->dev, "Couldn't activate the camera: %d\n", ret); |
Guennadi Liakhovetski | 9dc4e48 | 2008-04-22 14:45:32 -0300 | [diff] [blame] | 306 | goto eiciadd; |
| 307 | } |
| 308 | } |
| 309 | |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 310 | mutex_unlock(&icd->video_lock); |
Guennadi Liakhovetski | 9dc4e48 | 2008-04-22 14:45:32 -0300 | [diff] [blame] | 311 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 312 | file->private_data = icf; |
| 313 | dev_dbg(&icd->dev, "camera device open\n"); |
| 314 | |
Magnus Damm | a034d1b | 2008-07-11 20:59:34 -0300 | [diff] [blame] | 315 | ici->ops->init_videobuf(&icf->vb_vidq, icd); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 316 | |
| 317 | return 0; |
| 318 | |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 319 | /* First two errors are entered with the .video_lock held */ |
Guennadi Liakhovetski | 9dc4e48 | 2008-04-22 14:45:32 -0300 | [diff] [blame] | 320 | eiciadd: |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 321 | soc_camera_free_user_formats(icd); |
| 322 | eiufmt: |
| 323 | icd->use_count--; |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 324 | mutex_unlock(&icd->video_lock); |
Guennadi Liakhovetski | b8d9904 | 2008-04-04 13:41:25 -0300 | [diff] [blame] | 325 | module_put(ici->ops->owner); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 326 | emgi: |
| 327 | module_put(icd->ops->owner); |
| 328 | emgd: |
| 329 | vfree(icf); |
| 330 | return ret; |
| 331 | } |
| 332 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 333 | static int soc_camera_close(struct file *file) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 334 | { |
| 335 | struct soc_camera_file *icf = file->private_data; |
| 336 | struct soc_camera_device *icd = icf->icd; |
| 337 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
| 338 | struct video_device *vdev = icd->vdev; |
| 339 | |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 340 | mutex_lock(&icd->video_lock); |
Guennadi Liakhovetski | 9dc4e48 | 2008-04-22 14:45:32 -0300 | [diff] [blame] | 341 | icd->use_count--; |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 342 | if (!icd->use_count) { |
Guennadi Liakhovetski | b8d9904 | 2008-04-04 13:41:25 -0300 | [diff] [blame] | 343 | ici->ops->remove(icd); |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 344 | soc_camera_free_user_formats(icd); |
| 345 | } |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 346 | mutex_unlock(&icd->video_lock); |
| 347 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 348 | module_put(icd->ops->owner); |
Guennadi Liakhovetski | b8d9904 | 2008-04-04 13:41:25 -0300 | [diff] [blame] | 349 | module_put(ici->ops->owner); |
Guennadi Liakhovetski | 9dc4e48 | 2008-04-22 14:45:32 -0300 | [diff] [blame] | 350 | |
Guennadi Liakhovetski | 1a0063a | 2008-04-04 13:46:34 -0300 | [diff] [blame] | 351 | vfree(icf); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 352 | |
Hans Verkuil | 5e85e73 | 2008-07-20 06:31:39 -0300 | [diff] [blame] | 353 | dev_dbg(vdev->parent, "camera device close\n"); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 354 | |
| 355 | return 0; |
| 356 | } |
| 357 | |
Andrew Morton | aba360d | 2008-04-22 14:45:59 -0300 | [diff] [blame] | 358 | static ssize_t soc_camera_read(struct file *file, char __user *buf, |
Guennadi Liakhovetski | abe4c47 | 2008-12-01 09:44:56 -0300 | [diff] [blame] | 359 | size_t count, loff_t *ppos) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 360 | { |
| 361 | struct soc_camera_file *icf = file->private_data; |
| 362 | struct soc_camera_device *icd = icf->icd; |
| 363 | struct video_device *vdev = icd->vdev; |
| 364 | int err = -EINVAL; |
| 365 | |
Hans Verkuil | 5e85e73 | 2008-07-20 06:31:39 -0300 | [diff] [blame] | 366 | dev_err(vdev->parent, "camera device read not implemented\n"); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 367 | |
| 368 | return err; |
| 369 | } |
| 370 | |
| 371 | static int soc_camera_mmap(struct file *file, struct vm_area_struct *vma) |
| 372 | { |
| 373 | struct soc_camera_file *icf = file->private_data; |
| 374 | struct soc_camera_device *icd = icf->icd; |
| 375 | int err; |
| 376 | |
| 377 | dev_dbg(&icd->dev, "mmap called, vma=0x%08lx\n", (unsigned long)vma); |
| 378 | |
| 379 | err = videobuf_mmap_mapper(&icf->vb_vidq, vma); |
| 380 | |
| 381 | dev_dbg(&icd->dev, "vma start=0x%08lx, size=%ld, ret=%d\n", |
| 382 | (unsigned long)vma->vm_start, |
| 383 | (unsigned long)vma->vm_end - (unsigned long)vma->vm_start, |
| 384 | err); |
| 385 | |
| 386 | return err; |
| 387 | } |
| 388 | |
| 389 | static unsigned int soc_camera_poll(struct file *file, poll_table *pt) |
| 390 | { |
| 391 | struct soc_camera_file *icf = file->private_data; |
| 392 | struct soc_camera_device *icd = icf->icd; |
Guennadi Liakhovetski | 64f5905 | 2008-12-18 11:51:55 -0300 | [diff] [blame] | 393 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 394 | |
| 395 | if (list_empty(&icf->vb_vidq.stream)) { |
| 396 | dev_err(&icd->dev, "Trying to poll with no queued buffers!\n"); |
| 397 | return POLLERR; |
| 398 | } |
| 399 | |
Guennadi Liakhovetski | b8d9904 | 2008-04-04 13:41:25 -0300 | [diff] [blame] | 400 | return ici->ops->poll(file, pt); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 401 | } |
| 402 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 403 | static struct v4l2_file_operations soc_camera_fops = { |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 404 | .owner = THIS_MODULE, |
| 405 | .open = soc_camera_open, |
| 406 | .release = soc_camera_close, |
| 407 | .ioctl = video_ioctl2, |
| 408 | .read = soc_camera_read, |
| 409 | .mmap = soc_camera_mmap, |
| 410 | .poll = soc_camera_poll, |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 411 | }; |
| 412 | |
Hans Verkuil | 7293789 | 2008-06-01 10:35:18 -0300 | [diff] [blame] | 413 | 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] | 414 | struct v4l2_format *f) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 415 | { |
| 416 | struct soc_camera_file *icf = file->private_data; |
| 417 | struct soc_camera_device *icd = icf->icd; |
Guennadi Liakhovetski | 64f5905 | 2008-12-18 11:51:55 -0300 | [diff] [blame] | 418 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
| 419 | struct v4l2_pix_format *pix = &f->fmt.pix; |
| 420 | __u32 pixfmt = pix->pixelformat; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 421 | int ret; |
| 422 | struct v4l2_rect rect; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 423 | |
| 424 | WARN_ON(priv != file->private_data); |
| 425 | |
Guennadi Liakhovetski | 25c4d74 | 2008-12-01 09:44:59 -0300 | [diff] [blame] | 426 | ret = soc_camera_try_fmt_vid_cap(file, priv, f); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 427 | if (ret < 0) |
| 428 | return ret; |
| 429 | |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 430 | mutex_lock(&icf->vb_vidq.vb_lock); |
| 431 | |
| 432 | if (videobuf_queue_is_busy(&icf->vb_vidq)) { |
| 433 | dev_err(&icd->dev, "S_FMT denied: queue busy\n"); |
| 434 | ret = -EBUSY; |
| 435 | goto unlock; |
| 436 | } |
| 437 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 438 | rect.left = icd->x_current; |
| 439 | rect.top = icd->y_current; |
Guennadi Liakhovetski | 64f5905 | 2008-12-18 11:51:55 -0300 | [diff] [blame] | 440 | rect.width = pix->width; |
| 441 | rect.height = pix->height; |
| 442 | ret = ici->ops->set_fmt(icd, pix->pixelformat, &rect); |
Guennadi Liakhovetski | 25c4d74 | 2008-12-01 09:44:59 -0300 | [diff] [blame] | 443 | if (ret < 0) { |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 444 | goto unlock; |
Guennadi Liakhovetski | 25c4d74 | 2008-12-01 09:44:59 -0300 | [diff] [blame] | 445 | } else if (!icd->current_fmt || |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 446 | icd->current_fmt->fourcc != pixfmt) { |
| 447 | dev_err(&ici->dev, |
| 448 | "Host driver hasn't set up current format correctly!\n"); |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 449 | ret = -EINVAL; |
| 450 | goto unlock; |
Guennadi Liakhovetski | 25c4d74 | 2008-12-01 09:44:59 -0300 | [diff] [blame] | 451 | } |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 452 | |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 453 | icd->width = rect.width; |
| 454 | icd->height = rect.height; |
Guennadi Liakhovetski | 64f5905 | 2008-12-18 11:51:55 -0300 | [diff] [blame] | 455 | icf->vb_vidq.field = pix->field; |
Guennadi Liakhovetski | 25c4d74 | 2008-12-01 09:44:59 -0300 | [diff] [blame] | 456 | if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 457 | dev_warn(&icd->dev, "Attention! Wrong buf-type %d\n", |
| 458 | f->type); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 459 | |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 460 | dev_dbg(&icd->dev, "set width: %d height: %d\n", |
| 461 | icd->width, icd->height); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 462 | |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 463 | /* set physical bus parameters */ |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 464 | ret = ici->ops->set_bus_param(icd, pixfmt); |
| 465 | |
| 466 | unlock: |
| 467 | mutex_unlock(&icf->vb_vidq.vb_lock); |
| 468 | |
| 469 | return ret; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 470 | } |
| 471 | |
Hans Verkuil | 7293789 | 2008-06-01 10:35:18 -0300 | [diff] [blame] | 472 | 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] | 473 | struct v4l2_fmtdesc *f) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 474 | { |
| 475 | struct soc_camera_file *icf = file->private_data; |
| 476 | struct soc_camera_device *icd = icf->icd; |
| 477 | const struct soc_camera_data_format *format; |
| 478 | |
| 479 | WARN_ON(priv != file->private_data); |
| 480 | |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 481 | if (f->index >= icd->num_user_formats) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 482 | return -EINVAL; |
| 483 | |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 484 | format = icd->user_formats[f->index].host_fmt; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 485 | |
| 486 | strlcpy(f->description, format->name, sizeof(f->description)); |
| 487 | f->pixelformat = format->fourcc; |
| 488 | return 0; |
| 489 | } |
| 490 | |
Hans Verkuil | 7293789 | 2008-06-01 10:35:18 -0300 | [diff] [blame] | 491 | 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] | 492 | struct v4l2_format *f) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 493 | { |
| 494 | struct soc_camera_file *icf = file->private_data; |
| 495 | struct soc_camera_device *icd = icf->icd; |
Guennadi Liakhovetski | 64f5905 | 2008-12-18 11:51:55 -0300 | [diff] [blame] | 496 | struct v4l2_pix_format *pix = &f->fmt.pix; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 497 | |
| 498 | WARN_ON(priv != file->private_data); |
| 499 | |
Guennadi Liakhovetski | 64f5905 | 2008-12-18 11:51:55 -0300 | [diff] [blame] | 500 | pix->width = icd->width; |
| 501 | pix->height = icd->height; |
| 502 | pix->field = icf->vb_vidq.field; |
| 503 | pix->pixelformat = icd->current_fmt->fourcc; |
| 504 | pix->bytesperline = pix->width * |
Guennadi Liakhovetski | 25c4d74 | 2008-12-01 09:44:59 -0300 | [diff] [blame] | 505 | DIV_ROUND_UP(icd->current_fmt->depth, 8); |
Guennadi Liakhovetski | 64f5905 | 2008-12-18 11:51:55 -0300 | [diff] [blame] | 506 | pix->sizeimage = pix->height * pix->bytesperline; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 507 | dev_dbg(&icd->dev, "current_fmt->fourcc: 0x%08x\n", |
| 508 | icd->current_fmt->fourcc); |
| 509 | return 0; |
| 510 | } |
| 511 | |
| 512 | static int soc_camera_querycap(struct file *file, void *priv, |
| 513 | struct v4l2_capability *cap) |
| 514 | { |
| 515 | struct soc_camera_file *icf = file->private_data; |
| 516 | struct soc_camera_device *icd = icf->icd; |
Guennadi Liakhovetski | 64f5905 | 2008-12-18 11:51:55 -0300 | [diff] [blame] | 517 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 518 | |
| 519 | WARN_ON(priv != file->private_data); |
| 520 | |
| 521 | strlcpy(cap->driver, ici->drv_name, sizeof(cap->driver)); |
Guennadi Liakhovetski | b8d9904 | 2008-04-04 13:41:25 -0300 | [diff] [blame] | 522 | return ici->ops->querycap(ici, cap); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | static int soc_camera_streamon(struct file *file, void *priv, |
| 526 | enum v4l2_buf_type i) |
| 527 | { |
| 528 | struct soc_camera_file *icf = file->private_data; |
| 529 | struct soc_camera_device *icd = icf->icd; |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 530 | int ret; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 531 | |
| 532 | WARN_ON(priv != file->private_data); |
| 533 | |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 534 | dev_dbg(&icd->dev, "%s\n", __func__); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 535 | |
| 536 | if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 537 | return -EINVAL; |
| 538 | |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 539 | mutex_lock(&icd->video_lock); |
| 540 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 541 | icd->ops->start_capture(icd); |
| 542 | |
| 543 | /* This calls buf_queue from host driver's videobuf_queue_ops */ |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 544 | ret = videobuf_streamon(&icf->vb_vidq); |
| 545 | |
| 546 | mutex_unlock(&icd->video_lock); |
| 547 | |
| 548 | return ret; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | static int soc_camera_streamoff(struct file *file, void *priv, |
| 552 | enum v4l2_buf_type i) |
| 553 | { |
| 554 | struct soc_camera_file *icf = file->private_data; |
| 555 | struct soc_camera_device *icd = icf->icd; |
| 556 | |
| 557 | WARN_ON(priv != file->private_data); |
| 558 | |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 559 | dev_dbg(&icd->dev, "%s\n", __func__); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 560 | |
| 561 | if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 562 | return -EINVAL; |
| 563 | |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 564 | mutex_lock(&icd->video_lock); |
| 565 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 566 | /* This calls buf_release from host driver's videobuf_queue_ops for all |
| 567 | * remaining buffers. When the last buffer is freed, stop capture */ |
| 568 | videobuf_streamoff(&icf->vb_vidq); |
| 569 | |
| 570 | icd->ops->stop_capture(icd); |
| 571 | |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 572 | mutex_unlock(&icd->video_lock); |
| 573 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 574 | return 0; |
| 575 | } |
| 576 | |
| 577 | static int soc_camera_queryctrl(struct file *file, void *priv, |
| 578 | struct v4l2_queryctrl *qc) |
| 579 | { |
| 580 | struct soc_camera_file *icf = file->private_data; |
| 581 | struct soc_camera_device *icd = icf->icd; |
| 582 | int i; |
| 583 | |
| 584 | WARN_ON(priv != file->private_data); |
| 585 | |
| 586 | if (!qc->id) |
| 587 | return -EINVAL; |
| 588 | |
| 589 | for (i = 0; i < icd->ops->num_controls; i++) |
| 590 | if (qc->id == icd->ops->controls[i].id) { |
| 591 | memcpy(qc, &(icd->ops->controls[i]), |
| 592 | sizeof(*qc)); |
| 593 | return 0; |
| 594 | } |
| 595 | |
| 596 | return -EINVAL; |
| 597 | } |
| 598 | |
| 599 | static int soc_camera_g_ctrl(struct file *file, void *priv, |
| 600 | struct v4l2_control *ctrl) |
| 601 | { |
| 602 | struct soc_camera_file *icf = file->private_data; |
| 603 | struct soc_camera_device *icd = icf->icd; |
| 604 | |
| 605 | WARN_ON(priv != file->private_data); |
| 606 | |
| 607 | switch (ctrl->id) { |
| 608 | case V4L2_CID_GAIN: |
| 609 | if (icd->gain == (unsigned short)~0) |
| 610 | return -EINVAL; |
| 611 | ctrl->value = icd->gain; |
| 612 | return 0; |
| 613 | case V4L2_CID_EXPOSURE: |
| 614 | if (icd->exposure == (unsigned short)~0) |
| 615 | return -EINVAL; |
| 616 | ctrl->value = icd->exposure; |
| 617 | return 0; |
| 618 | } |
| 619 | |
| 620 | if (icd->ops->get_control) |
| 621 | return icd->ops->get_control(icd, ctrl); |
| 622 | return -EINVAL; |
| 623 | } |
| 624 | |
| 625 | static int soc_camera_s_ctrl(struct file *file, void *priv, |
| 626 | struct v4l2_control *ctrl) |
| 627 | { |
| 628 | struct soc_camera_file *icf = file->private_data; |
| 629 | struct soc_camera_device *icd = icf->icd; |
| 630 | |
| 631 | WARN_ON(priv != file->private_data); |
| 632 | |
| 633 | if (icd->ops->set_control) |
| 634 | return icd->ops->set_control(icd, ctrl); |
| 635 | return -EINVAL; |
| 636 | } |
| 637 | |
| 638 | static int soc_camera_cropcap(struct file *file, void *fh, |
| 639 | struct v4l2_cropcap *a) |
| 640 | { |
| 641 | struct soc_camera_file *icf = file->private_data; |
| 642 | struct soc_camera_device *icd = icf->icd; |
| 643 | |
| 644 | a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 645 | a->bounds.left = icd->x_min; |
| 646 | a->bounds.top = icd->y_min; |
| 647 | a->bounds.width = icd->width_max; |
| 648 | a->bounds.height = icd->height_max; |
| 649 | a->defrect.left = icd->x_min; |
| 650 | a->defrect.top = icd->y_min; |
| 651 | a->defrect.width = 640; |
| 652 | a->defrect.height = 480; |
| 653 | a->pixelaspect.numerator = 1; |
| 654 | a->pixelaspect.denominator = 1; |
| 655 | |
| 656 | return 0; |
| 657 | } |
| 658 | |
| 659 | static int soc_camera_g_crop(struct file *file, void *fh, |
| 660 | struct v4l2_crop *a) |
| 661 | { |
| 662 | struct soc_camera_file *icf = file->private_data; |
| 663 | struct soc_camera_device *icd = icf->icd; |
| 664 | |
| 665 | a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 666 | a->c.left = icd->x_current; |
| 667 | a->c.top = icd->y_current; |
| 668 | a->c.width = icd->width; |
| 669 | a->c.height = icd->height; |
| 670 | |
| 671 | return 0; |
| 672 | } |
| 673 | |
| 674 | static int soc_camera_s_crop(struct file *file, void *fh, |
| 675 | struct v4l2_crop *a) |
| 676 | { |
| 677 | struct soc_camera_file *icf = file->private_data; |
| 678 | struct soc_camera_device *icd = icf->icd; |
Guennadi Liakhovetski | 64f5905 | 2008-12-18 11:51:55 -0300 | [diff] [blame] | 679 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 680 | int ret; |
| 681 | |
| 682 | if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 683 | return -EINVAL; |
| 684 | |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 685 | /* Cropping is allowed during a running capture, guard consistency */ |
| 686 | mutex_lock(&icf->vb_vidq.vb_lock); |
| 687 | |
Guennadi Liakhovetski | d8fac21 | 2008-12-01 09:45:21 -0300 | [diff] [blame] | 688 | ret = ici->ops->set_fmt(icd, 0, &a->c); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 689 | if (!ret) { |
| 690 | icd->width = a->c.width; |
| 691 | icd->height = a->c.height; |
| 692 | icd->x_current = a->c.left; |
| 693 | icd->y_current = a->c.top; |
| 694 | } |
| 695 | |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 696 | mutex_unlock(&icf->vb_vidq.vb_lock); |
| 697 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 698 | return ret; |
| 699 | } |
| 700 | |
| 701 | static int soc_camera_g_chip_ident(struct file *file, void *fh, |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 702 | struct v4l2_dbg_chip_ident *id) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 703 | { |
| 704 | struct soc_camera_file *icf = file->private_data; |
| 705 | struct soc_camera_device *icd = icf->icd; |
| 706 | |
| 707 | if (!icd->ops->get_chip_id) |
| 708 | return -EINVAL; |
| 709 | |
| 710 | return icd->ops->get_chip_id(icd, id); |
| 711 | } |
| 712 | |
| 713 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 714 | static int soc_camera_g_register(struct file *file, void *fh, |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 715 | struct v4l2_dbg_register *reg) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 716 | { |
| 717 | struct soc_camera_file *icf = file->private_data; |
| 718 | struct soc_camera_device *icd = icf->icd; |
| 719 | |
| 720 | if (!icd->ops->get_register) |
| 721 | return -EINVAL; |
| 722 | |
| 723 | return icd->ops->get_register(icd, reg); |
| 724 | } |
| 725 | |
| 726 | static int soc_camera_s_register(struct file *file, void *fh, |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 727 | struct v4l2_dbg_register *reg) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 728 | { |
| 729 | struct soc_camera_file *icf = file->private_data; |
| 730 | struct soc_camera_device *icd = icf->icd; |
| 731 | |
| 732 | if (!icd->ops->set_register) |
| 733 | return -EINVAL; |
| 734 | |
| 735 | return icd->ops->set_register(icd, reg); |
| 736 | } |
| 737 | #endif |
| 738 | |
| 739 | static int device_register_link(struct soc_camera_device *icd) |
| 740 | { |
| 741 | int ret = device_register(&icd->dev); |
| 742 | |
| 743 | if (ret < 0) { |
| 744 | /* Prevent calling device_unregister() */ |
| 745 | icd->dev.parent = NULL; |
| 746 | dev_err(&icd->dev, "Cannot register device: %d\n", ret); |
| 747 | /* Even if probe() was unsuccessful for all registered drivers, |
| 748 | * device_register() returns 0, and we add the link, just to |
| 749 | * document this camera's control device */ |
| 750 | } else if (icd->control) |
| 751 | /* Have to sysfs_remove_link() before device_unregister()? */ |
| 752 | if (sysfs_create_link(&icd->dev.kobj, &icd->control->kobj, |
| 753 | "control")) |
| 754 | dev_warn(&icd->dev, |
| 755 | "Failed creating the control symlink\n"); |
| 756 | return ret; |
| 757 | } |
| 758 | |
| 759 | /* So far this function cannot fail */ |
| 760 | static void scan_add_host(struct soc_camera_host *ici) |
| 761 | { |
| 762 | struct soc_camera_device *icd; |
| 763 | |
| 764 | mutex_lock(&list_lock); |
| 765 | |
| 766 | list_for_each_entry(icd, &devices, list) { |
| 767 | if (icd->iface == ici->nr) { |
| 768 | icd->dev.parent = &ici->dev; |
| 769 | device_register_link(icd); |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | mutex_unlock(&list_lock); |
| 774 | } |
| 775 | |
| 776 | /* return: 0 if no match found or a match found and |
| 777 | * device_register() successful, error code otherwise */ |
| 778 | static int scan_add_device(struct soc_camera_device *icd) |
| 779 | { |
| 780 | struct soc_camera_host *ici; |
| 781 | int ret = 0; |
| 782 | |
| 783 | mutex_lock(&list_lock); |
| 784 | |
| 785 | list_add_tail(&icd->list, &devices); |
| 786 | |
| 787 | /* Watch out for class_for_each_device / class_find_device API by |
| 788 | * Dave Young <hidave.darkstar@gmail.com> */ |
| 789 | list_for_each_entry(ici, &hosts, list) { |
| 790 | if (icd->iface == ici->nr) { |
| 791 | ret = 1; |
| 792 | icd->dev.parent = &ici->dev; |
| 793 | break; |
| 794 | } |
| 795 | } |
| 796 | |
| 797 | mutex_unlock(&list_lock); |
| 798 | |
| 799 | if (ret) |
| 800 | ret = device_register_link(icd); |
| 801 | |
| 802 | return ret; |
| 803 | } |
| 804 | |
| 805 | static int soc_camera_probe(struct device *dev) |
| 806 | { |
| 807 | struct soc_camera_device *icd = to_soc_camera_dev(dev); |
Guennadi Liakhovetski | 64f5905 | 2008-12-18 11:51:55 -0300 | [diff] [blame] | 808 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 809 | int ret; |
| 810 | |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 811 | /* |
| 812 | * Possible race scenario: |
| 813 | * modprobe <camera-host-driver> triggers __func__ |
| 814 | * at this moment respective <camera-sensor-driver> gets rmmod'ed |
| 815 | * to protect take module references. |
| 816 | */ |
| 817 | |
| 818 | if (!try_module_get(icd->ops->owner)) { |
| 819 | dev_err(&icd->dev, "Couldn't lock sensor driver.\n"); |
| 820 | ret = -EINVAL; |
| 821 | goto emgd; |
| 822 | } |
| 823 | |
| 824 | if (!try_module_get(ici->ops->owner)) { |
| 825 | dev_err(&icd->dev, "Couldn't lock capture bus driver.\n"); |
| 826 | ret = -EINVAL; |
| 827 | goto emgi; |
| 828 | } |
| 829 | |
| 830 | mutex_lock(&icd->video_lock); |
| 831 | |
Guennadi Liakhovetski | 9dc4e48 | 2008-04-22 14:45:32 -0300 | [diff] [blame] | 832 | /* We only call ->add() here to activate and probe the camera. |
| 833 | * We shall ->remove() and deactivate it immediately afterwards. */ |
Guennadi Liakhovetski | b8d9904 | 2008-04-04 13:41:25 -0300 | [diff] [blame] | 834 | ret = ici->ops->add(icd); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 835 | if (ret < 0) |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 836 | goto eiadd; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 837 | |
Guennadi Liakhovetski | 26f1b94 | 2008-03-24 12:18:36 -0300 | [diff] [blame] | 838 | ret = icd->ops->probe(icd); |
Guennadi Liakhovetski | 9dc4e48 | 2008-04-22 14:45:32 -0300 | [diff] [blame] | 839 | if (ret >= 0) { |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 840 | const struct v4l2_queryctrl *qctrl; |
| 841 | |
| 842 | qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_GAIN); |
| 843 | icd->gain = qctrl ? qctrl->default_value : (unsigned short)~0; |
| 844 | qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_EXPOSURE); |
| 845 | icd->exposure = qctrl ? qctrl->default_value : |
| 846 | (unsigned short)~0; |
| 847 | } |
Guennadi Liakhovetski | b8d9904 | 2008-04-04 13:41:25 -0300 | [diff] [blame] | 848 | ici->ops->remove(icd); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 849 | |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 850 | eiadd: |
| 851 | mutex_unlock(&icd->video_lock); |
| 852 | module_put(ici->ops->owner); |
| 853 | emgi: |
| 854 | module_put(icd->ops->owner); |
| 855 | emgd: |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 856 | return ret; |
| 857 | } |
| 858 | |
| 859 | /* This is called on device_unregister, which only means we have to disconnect |
| 860 | * from the host, but not remove ourselves from the device list */ |
| 861 | static int soc_camera_remove(struct device *dev) |
| 862 | { |
| 863 | struct soc_camera_device *icd = to_soc_camera_dev(dev); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 864 | |
Guennadi Liakhovetski | 26f1b94 | 2008-03-24 12:18:36 -0300 | [diff] [blame] | 865 | if (icd->ops->remove) |
| 866 | icd->ops->remove(icd); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 867 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 868 | return 0; |
| 869 | } |
| 870 | |
Robert Jarzmik | 2e52106 | 2008-08-01 20:14:50 -0300 | [diff] [blame] | 871 | static int soc_camera_suspend(struct device *dev, pm_message_t state) |
| 872 | { |
| 873 | struct soc_camera_device *icd = to_soc_camera_dev(dev); |
| 874 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
| 875 | int ret = 0; |
| 876 | |
| 877 | if (ici->ops->suspend) |
| 878 | ret = ici->ops->suspend(icd, state); |
| 879 | |
| 880 | return ret; |
| 881 | } |
| 882 | |
| 883 | static int soc_camera_resume(struct device *dev) |
| 884 | { |
| 885 | struct soc_camera_device *icd = to_soc_camera_dev(dev); |
| 886 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
| 887 | int ret = 0; |
| 888 | |
| 889 | if (ici->ops->resume) |
| 890 | ret = ici->ops->resume(icd); |
| 891 | |
| 892 | return ret; |
| 893 | } |
| 894 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 895 | static struct bus_type soc_camera_bus_type = { |
| 896 | .name = "soc-camera", |
| 897 | .probe = soc_camera_probe, |
| 898 | .remove = soc_camera_remove, |
Robert Jarzmik | 2e52106 | 2008-08-01 20:14:50 -0300 | [diff] [blame] | 899 | .suspend = soc_camera_suspend, |
| 900 | .resume = soc_camera_resume, |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 901 | }; |
| 902 | |
| 903 | static struct device_driver ic_drv = { |
| 904 | .name = "camera", |
| 905 | .bus = &soc_camera_bus_type, |
| 906 | .owner = THIS_MODULE, |
| 907 | }; |
| 908 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 909 | static void dummy_release(struct device *dev) |
| 910 | { |
| 911 | } |
| 912 | |
Guennadi Liakhovetski | b8d9904 | 2008-04-04 13:41:25 -0300 | [diff] [blame] | 913 | int soc_camera_host_register(struct soc_camera_host *ici) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 914 | { |
| 915 | int ret; |
| 916 | struct soc_camera_host *ix; |
| 917 | |
Guennadi Liakhovetski | 64f5905 | 2008-12-18 11:51:55 -0300 | [diff] [blame] | 918 | if (!ici || !ici->ops || |
| 919 | !ici->ops->try_fmt || |
| 920 | !ici->ops->set_fmt || |
| 921 | !ici->ops->set_bus_param || |
| 922 | !ici->ops->querycap || |
| 923 | !ici->ops->init_videobuf || |
| 924 | !ici->ops->reqbufs || |
| 925 | !ici->ops->add || |
| 926 | !ici->ops->remove || |
| 927 | !ici->ops->poll) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 928 | return -EINVAL; |
| 929 | |
| 930 | /* Number might be equal to the platform device ID */ |
Kay Sievers | af128a1 | 2008-10-30 00:51:46 -0300 | [diff] [blame] | 931 | dev_set_name(&ici->dev, "camera_host%d", ici->nr); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 932 | |
| 933 | mutex_lock(&list_lock); |
| 934 | list_for_each_entry(ix, &hosts, list) { |
| 935 | if (ix->nr == ici->nr) { |
| 936 | mutex_unlock(&list_lock); |
| 937 | return -EBUSY; |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | list_add_tail(&ici->list, &hosts); |
| 942 | mutex_unlock(&list_lock); |
| 943 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 944 | ici->dev.release = dummy_release; |
| 945 | |
| 946 | ret = device_register(&ici->dev); |
| 947 | |
| 948 | if (ret) |
| 949 | goto edevr; |
| 950 | |
| 951 | scan_add_host(ici); |
| 952 | |
| 953 | return 0; |
| 954 | |
| 955 | edevr: |
| 956 | mutex_lock(&list_lock); |
| 957 | list_del(&ici->list); |
| 958 | mutex_unlock(&list_lock); |
| 959 | |
| 960 | return ret; |
| 961 | } |
| 962 | EXPORT_SYMBOL(soc_camera_host_register); |
| 963 | |
| 964 | /* Unregister all clients! */ |
| 965 | void soc_camera_host_unregister(struct soc_camera_host *ici) |
| 966 | { |
| 967 | struct soc_camera_device *icd; |
| 968 | |
| 969 | mutex_lock(&list_lock); |
| 970 | |
| 971 | list_del(&ici->list); |
| 972 | |
| 973 | list_for_each_entry(icd, &devices, list) { |
| 974 | if (icd->dev.parent == &ici->dev) { |
| 975 | device_unregister(&icd->dev); |
| 976 | /* Not before device_unregister(), .remove |
Guennadi Liakhovetski | b8d9904 | 2008-04-04 13:41:25 -0300 | [diff] [blame] | 977 | * needs parent to call ici->ops->remove() */ |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 978 | icd->dev.parent = NULL; |
| 979 | memset(&icd->dev.kobj, 0, sizeof(icd->dev.kobj)); |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | mutex_unlock(&list_lock); |
| 984 | |
| 985 | device_unregister(&ici->dev); |
| 986 | } |
| 987 | EXPORT_SYMBOL(soc_camera_host_unregister); |
| 988 | |
| 989 | /* Image capture device */ |
| 990 | int soc_camera_device_register(struct soc_camera_device *icd) |
| 991 | { |
| 992 | struct soc_camera_device *ix; |
| 993 | int num = -1, i; |
| 994 | |
Guennadi Liakhovetski | 64f5905 | 2008-12-18 11:51:55 -0300 | [diff] [blame] | 995 | if (!icd || !icd->ops || |
| 996 | !icd->ops->probe || |
| 997 | !icd->ops->init || |
| 998 | !icd->ops->release || |
| 999 | !icd->ops->start_capture || |
| 1000 | !icd->ops->stop_capture || |
| 1001 | !icd->ops->set_fmt || |
| 1002 | !icd->ops->try_fmt || |
| 1003 | !icd->ops->query_bus_param || |
| 1004 | !icd->ops->set_bus_param) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1005 | return -EINVAL; |
| 1006 | |
| 1007 | for (i = 0; i < 256 && num < 0; i++) { |
| 1008 | num = i; |
| 1009 | list_for_each_entry(ix, &devices, list) { |
| 1010 | if (ix->iface == icd->iface && ix->devnum == i) { |
| 1011 | num = -1; |
| 1012 | break; |
| 1013 | } |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | if (num < 0) |
| 1018 | /* ok, we have 256 cameras on this host... |
| 1019 | * man, stay reasonable... */ |
| 1020 | return -ENOMEM; |
| 1021 | |
| 1022 | icd->devnum = num; |
| 1023 | icd->dev.bus = &soc_camera_bus_type; |
Kay Sievers | af128a1 | 2008-10-30 00:51:46 -0300 | [diff] [blame] | 1024 | dev_set_name(&icd->dev, "%u-%u", icd->iface, icd->devnum); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1025 | |
Guennadi Liakhovetski | 64f5905 | 2008-12-18 11:51:55 -0300 | [diff] [blame] | 1026 | icd->dev.release = dummy_release; |
| 1027 | icd->use_count = 0; |
| 1028 | icd->host_priv = NULL; |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 1029 | mutex_init(&icd->video_lock); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1030 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1031 | return scan_add_device(icd); |
| 1032 | } |
| 1033 | EXPORT_SYMBOL(soc_camera_device_register); |
| 1034 | |
| 1035 | void soc_camera_device_unregister(struct soc_camera_device *icd) |
| 1036 | { |
| 1037 | mutex_lock(&list_lock); |
| 1038 | list_del(&icd->list); |
| 1039 | |
| 1040 | /* The bus->remove will be eventually called */ |
| 1041 | if (icd->dev.parent) |
| 1042 | device_unregister(&icd->dev); |
| 1043 | mutex_unlock(&list_lock); |
| 1044 | } |
| 1045 | EXPORT_SYMBOL(soc_camera_device_unregister); |
| 1046 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1047 | static const struct v4l2_ioctl_ops soc_camera_ioctl_ops = { |
| 1048 | .vidioc_querycap = soc_camera_querycap, |
| 1049 | .vidioc_g_fmt_vid_cap = soc_camera_g_fmt_vid_cap, |
| 1050 | .vidioc_enum_fmt_vid_cap = soc_camera_enum_fmt_vid_cap, |
| 1051 | .vidioc_s_fmt_vid_cap = soc_camera_s_fmt_vid_cap, |
| 1052 | .vidioc_enum_input = soc_camera_enum_input, |
| 1053 | .vidioc_g_input = soc_camera_g_input, |
| 1054 | .vidioc_s_input = soc_camera_s_input, |
| 1055 | .vidioc_s_std = soc_camera_s_std, |
| 1056 | .vidioc_reqbufs = soc_camera_reqbufs, |
| 1057 | .vidioc_try_fmt_vid_cap = soc_camera_try_fmt_vid_cap, |
| 1058 | .vidioc_querybuf = soc_camera_querybuf, |
| 1059 | .vidioc_qbuf = soc_camera_qbuf, |
| 1060 | .vidioc_dqbuf = soc_camera_dqbuf, |
| 1061 | .vidioc_streamon = soc_camera_streamon, |
| 1062 | .vidioc_streamoff = soc_camera_streamoff, |
| 1063 | .vidioc_queryctrl = soc_camera_queryctrl, |
| 1064 | .vidioc_g_ctrl = soc_camera_g_ctrl, |
| 1065 | .vidioc_s_ctrl = soc_camera_s_ctrl, |
| 1066 | .vidioc_cropcap = soc_camera_cropcap, |
| 1067 | .vidioc_g_crop = soc_camera_g_crop, |
| 1068 | .vidioc_s_crop = soc_camera_s_crop, |
| 1069 | .vidioc_g_chip_ident = soc_camera_g_chip_ident, |
| 1070 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 1071 | .vidioc_g_register = soc_camera_g_register, |
| 1072 | .vidioc_s_register = soc_camera_s_register, |
| 1073 | #endif |
| 1074 | }; |
| 1075 | |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 1076 | /* |
| 1077 | * Usually called from the struct soc_camera_ops .probe() method, i.e., from |
| 1078 | * soc_camera_probe() above with .video_lock held |
| 1079 | */ |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1080 | int soc_camera_video_start(struct soc_camera_device *icd) |
| 1081 | { |
| 1082 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
| 1083 | int err = -ENOMEM; |
| 1084 | struct video_device *vdev; |
| 1085 | |
| 1086 | if (!icd->dev.parent) |
| 1087 | return -ENODEV; |
| 1088 | |
| 1089 | vdev = video_device_alloc(); |
| 1090 | if (!vdev) |
| 1091 | goto evidallocd; |
| 1092 | dev_dbg(&ici->dev, "Allocated video_device %p\n", vdev); |
| 1093 | |
| 1094 | strlcpy(vdev->name, ici->drv_name, sizeof(vdev->name)); |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 1095 | |
Hans Verkuil | 5e85e73 | 2008-07-20 06:31:39 -0300 | [diff] [blame] | 1096 | vdev->parent = &icd->dev; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1097 | vdev->current_norm = V4L2_STD_UNKNOWN; |
| 1098 | vdev->fops = &soc_camera_fops; |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1099 | vdev->ioctl_ops = &soc_camera_ioctl_ops; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1100 | vdev->release = video_device_release; |
| 1101 | vdev->minor = -1; |
| 1102 | vdev->tvnorms = V4L2_STD_UNKNOWN, |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1103 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1104 | err = video_register_device(vdev, VFL_TYPE_GRABBER, vdev->minor); |
| 1105 | if (err < 0) { |
Hans Verkuil | 5e85e73 | 2008-07-20 06:31:39 -0300 | [diff] [blame] | 1106 | dev_err(vdev->parent, "video_register_device failed\n"); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1107 | goto evidregd; |
| 1108 | } |
| 1109 | icd->vdev = vdev; |
| 1110 | |
| 1111 | return 0; |
| 1112 | |
| 1113 | evidregd: |
| 1114 | video_device_release(vdev); |
| 1115 | evidallocd: |
| 1116 | return err; |
| 1117 | } |
| 1118 | EXPORT_SYMBOL(soc_camera_video_start); |
| 1119 | |
| 1120 | void soc_camera_video_stop(struct soc_camera_device *icd) |
| 1121 | { |
| 1122 | struct video_device *vdev = icd->vdev; |
| 1123 | |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 1124 | dev_dbg(&icd->dev, "%s\n", __func__); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1125 | |
| 1126 | if (!icd->dev.parent || !vdev) |
| 1127 | return; |
| 1128 | |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 1129 | mutex_lock(&icd->video_lock); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1130 | video_unregister_device(vdev); |
| 1131 | icd->vdev = NULL; |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 1132 | mutex_unlock(&icd->video_lock); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1133 | } |
| 1134 | EXPORT_SYMBOL(soc_camera_video_stop); |
| 1135 | |
| 1136 | static int __init soc_camera_init(void) |
| 1137 | { |
| 1138 | int ret = bus_register(&soc_camera_bus_type); |
| 1139 | if (ret) |
| 1140 | return ret; |
| 1141 | ret = driver_register(&ic_drv); |
| 1142 | if (ret) |
| 1143 | goto edrvr; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1144 | |
| 1145 | return 0; |
| 1146 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1147 | edrvr: |
| 1148 | bus_unregister(&soc_camera_bus_type); |
| 1149 | return ret; |
| 1150 | } |
| 1151 | |
| 1152 | static void __exit soc_camera_exit(void) |
| 1153 | { |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 1154 | driver_unregister(&ic_drv); |
| 1155 | bus_unregister(&soc_camera_bus_type); |
| 1156 | } |
| 1157 | |
| 1158 | module_init(soc_camera_init); |
| 1159 | module_exit(soc_camera_exit); |
| 1160 | |
| 1161 | MODULE_DESCRIPTION("Image capture bus driver"); |
| 1162 | MODULE_AUTHOR("Guennadi Liakhovetski <kernel@pengutronix.de>"); |
| 1163 | MODULE_LICENSE("GPL"); |