Bugfixes for omnivision sensors
[microdia.git] / microdia-dev.c
blob6a100dd67a27d58816f59eb10b2e2c05f45b63cc
1 /**
2 * @file microdia-dev.c
3 * @author Nicolas VIVIEN
4 * @date 2008-02-01
6 * @brief Device specific functions
8 * @note Copyright (C) Nicolas VIVIEN
10 * @par Licences
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include <linux/errno.h>
28 #include <linux/string.h>
29 #include <stdarg.h>
31 #include "microdia.h"
32 #include "sn9c20x.h"
33 #include "ov7670.h"
34 #include "ov965x.h"
35 #include "mt9vx11.h"
36 #include "ov7660.h"
38 struct sensor_info sensors[] = {
40 .id = OV9650_SENSOR,
41 .name = "OV9650",
42 .probe = ov_probe
45 .id = OV9655_SENSOR,
46 .name = "OV9655",
47 .probe = ov_probe
50 .id = SOI968_SENSOR,
51 .name = "SOI968",
52 .probe = ov_probe
55 .id = OV7660_SENSOR,
56 .name = "OV7660",
57 .probe = ov_probe
60 .id = OV7670_SENSOR,
61 .name = "OV7670",
62 .probe = ov_probe
66 /**
67 * @brief Wrapper function for camera-setting functions
69 * @param dev Pointer to device structure
71 * @returns 0
73 int dev_microdia_camera_settings(struct usb_microdia *dev)
75 dev_microdia_camera_set_contrast(dev);
76 dev_microdia_camera_set_brightness(dev);
77 dev_microdia_camera_set_gamma(dev);
78 dev_microdia_camera_set_exposure(dev);
79 dev_microdia_camera_set_hvflip(dev);
80 dev_microdia_camera_set_sharpness(dev);
81 dev_microdia_camera_set_rgb_gain(dev);
82 dev_microdia_camera_set_auto_exposure(dev);
83 dev_microdia_camera_set_auto_whitebalance(dev);
84 return 0;
87 /**
88 * @brief Wrapper function for device-specific contrast functions
90 * @param dev Pointer to device structure
92 * @returns 0 or negative error value
95 int dev_microdia_camera_set_contrast(struct usb_microdia *dev)
97 int ret = -ENODEV;
98 if (dev && dev->camera.set_contrast)
99 ret = dev->camera.set_contrast(dev);
100 return ret;
104 * @brief Wrapper function for device-specific brightness functions
106 * @param dev Pointer to device structure
108 * @returns 0 or negative error value
111 int dev_microdia_camera_set_brightness(struct usb_microdia *dev)
113 int ret = -ENODEV;
114 if (dev && dev->camera.set_brightness)
115 ret = dev->camera.set_brightness(dev);
116 return ret;
120 * @brief Wrapper function for device-specific gamma functions
122 * @param dev Pointer to device structure
124 * @returns 0 or negative error value
127 int dev_microdia_camera_set_gamma(struct usb_microdia *dev)
129 int ret = -ENODEV;
130 if (dev && dev->camera.set_gamma)
131 ret = dev->camera.set_gamma(dev);
132 return ret;
136 * @brief Wrapper function for device-specific exposure functions
138 * @param dev Pointer to device structure
140 * @returns 0 or negative error value
143 int dev_microdia_camera_set_exposure(struct usb_microdia *dev)
145 if (dev && dev->camera.set_exposure != NULL)
146 return dev->camera.set_exposure(dev);
148 return 0;
152 * @brief Wrapper function for device-specific hvflip functions
154 * @param dev Pointer to device structure
156 * @returns 0 or negative error value
159 int dev_microdia_camera_set_hvflip(struct usb_microdia *dev)
161 int ret = -ENODEV;
162 if (dev && dev->camera.set_hvflip)
163 ret = dev->camera.set_hvflip(dev);
165 return ret;
169 * @brief Wrapper function for device-specific sharpness functions
171 * @param dev Pointer to device structure
173 * @returns 0 or negative error value
176 int dev_microdia_camera_set_sharpness(struct usb_microdia *dev)
178 int ret = -ENODEV;
179 if (dev && dev->camera.set_sharpness)
180 ret = dev->camera.set_sharpness(dev);
182 return ret;
186 * @brief Wrapper function for device-specific rgb-gain functions
188 * @param dev Pointer to device structure
190 * @returns 0 or negative error value
193 int dev_microdia_camera_set_rgb_gain(struct usb_microdia *dev)
195 int ret = -ENODEV;
196 if (dev && dev->camera.set_rgb_gain)
197 ret = dev->camera.set_rgb_gain(dev);
199 return ret;
203 * @brief Wrapper function for device-specific auto-exposure functions
205 * @param dev Pointer to device structure
207 * @returns 0 or negative error value
210 int dev_microdia_camera_set_auto_exposure(struct usb_microdia *dev)
212 int ret = -ENODEV;
213 if (dev && dev->camera.set_auto_exposure)
214 ret = dev->camera.set_auto_exposure(dev);
216 return ret;
220 * @brief Wrapper function for device-specific auto-whitebalance functions
222 * @param dev Pointer to device structure
224 * @returns 0 or negative error value
227 int dev_microdia_camera_set_auto_whitebalance(struct usb_microdia *dev)
229 int ret = -ENODEV;
230 if (dev && dev->camera.set_auto_whitebalance)
231 ret = dev->camera.set_auto_whitebalance(dev);
233 return ret;
237 * @brief function to probe sensor attached to bridge
239 * @param dev pointer to device structure
241 * @returns 0 or negative error value
243 * This function will probe the bridge for the proper sensor
245 int dev_microdia_probe_sensor(struct usb_microdia *dev)
247 int i, ret;
248 dev->camera.sensor_flags = SN9C20X_I2C_2WIRE;
250 for (i = 0; i < ARRAY_SIZE(sensors); i++) {
251 ret = sensors[i].probe(dev);
252 if (ret == sensors[i].id) {
253 UDIA_INFO("Detected sensor: %s\n", sensors[i].name);
254 return ret;
258 return UNKNOWN_SENSOR;
262 * @brief Wrapper function for device-specific initialization functions
264 * @param dev Pointer to device structure
265 * @param flags
267 * @returns 0 or negative error value
270 int dev_microdia_initialize_device(struct usb_microdia *dev, __u32 flags)
272 switch (flags >> 16) {
273 case (SN9C20X_BRIDGE >> 16):
274 UDIA_INFO("Detected SN9C20X Bridge\n");
275 return sn9c20x_initialize(dev);
276 default:
277 UDIA_INFO("Unsupported bridge\n");
279 return -ENODEV;
283 * @brief Wrapper function for for enable video stream for specific bridge
285 * @param dev Pointer to device structure
286 * @param enable Contains the wanted state
288 * @returns 0
291 int dev_microdia_enable_video(struct usb_microdia *dev, int enable)
293 int ret = -ENODEV;
294 if (dev && dev->camera.enable_video)
295 ret = dev->camera.enable_video(dev, enable);
297 return ret;