Stop sensor_init from being executed twice
[microdia.git] / microdia-dev.c
blobeaadefdeb651d9d5f8362c9d600f24073ff11262
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
65 .id = MT9M111_SENSOR,
66 .name = "MT9M111",
67 .probe = mt9m111_probe
70 .id = MT9V111_SENSOR,
71 .name = "MT9V111",
72 .probe = mt9v111_probe
75 .id = MT9V011_SENSOR,
76 .name = "MT9V011",
77 .probe = mt9v011_probe
80 .id = MT9M001_SENSOR,
81 .name = "MT9M001",
82 .probe = mt9m001_probe
86 /**
87 * @brief Wrapper function for camera-setting functions
89 * @param dev Pointer to device structure
91 * @returns 0
93 int dev_microdia_camera_settings(struct usb_microdia *dev)
95 dev_microdia_camera_set_contrast(dev);
96 dev_microdia_camera_set_brightness(dev);
97 dev_microdia_camera_set_gamma(dev);
98 dev_microdia_camera_set_exposure(dev);
99 dev_microdia_camera_set_hvflip(dev);
100 dev_microdia_camera_set_sharpness(dev);
101 dev_microdia_camera_set_rgb_gain(dev);
102 dev_microdia_camera_set_auto_exposure(dev);
103 dev_microdia_camera_set_auto_whitebalance(dev);
104 return 0;
108 * @brief Wrapper function for device-specific contrast functions
110 * @param dev Pointer to device structure
112 * @returns 0 or negative error value
115 int dev_microdia_camera_set_contrast(struct usb_microdia *dev)
117 int ret = -ENODEV;
118 if (dev && dev->camera.set_contrast)
119 ret = dev->camera.set_contrast(dev);
120 return ret;
124 * @brief Wrapper function for device-specific brightness functions
126 * @param dev Pointer to device structure
128 * @returns 0 or negative error value
131 int dev_microdia_camera_set_brightness(struct usb_microdia *dev)
133 int ret = -ENODEV;
134 if (dev && dev->camera.set_brightness)
135 ret = dev->camera.set_brightness(dev);
136 return ret;
140 * @brief Wrapper function for device-specific gamma functions
142 * @param dev Pointer to device structure
144 * @returns 0 or negative error value
147 int dev_microdia_camera_set_gamma(struct usb_microdia *dev)
149 int ret = -ENODEV;
150 if (dev && dev->camera.set_gamma)
151 ret = dev->camera.set_gamma(dev);
152 return ret;
156 * @brief Wrapper function for device-specific exposure functions
158 * @param dev Pointer to device structure
160 * @returns 0 or negative error value
163 int dev_microdia_camera_set_exposure(struct usb_microdia *dev)
165 if (dev && dev->camera.set_exposure != NULL)
166 return dev->camera.set_exposure(dev);
168 return 0;
172 * @brief Wrapper function for device-specific hvflip functions
174 * @param dev Pointer to device structure
176 * @returns 0 or negative error value
179 int dev_microdia_camera_set_hvflip(struct usb_microdia *dev)
181 int ret = -ENODEV;
182 if (dev && dev->camera.set_hvflip)
183 ret = dev->camera.set_hvflip(dev);
185 return ret;
189 * @brief Wrapper function for device-specific sharpness functions
191 * @param dev Pointer to device structure
193 * @returns 0 or negative error value
196 int dev_microdia_camera_set_sharpness(struct usb_microdia *dev)
198 int ret = -ENODEV;
199 if (dev && dev->camera.set_sharpness)
200 ret = dev->camera.set_sharpness(dev);
202 return ret;
206 * @brief Wrapper function for device-specific rgb-gain functions
208 * @param dev Pointer to device structure
210 * @returns 0 or negative error value
213 int dev_microdia_camera_set_rgb_gain(struct usb_microdia *dev)
215 int ret = -ENODEV;
216 if (dev && dev->camera.set_rgb_gain)
217 ret = dev->camera.set_rgb_gain(dev);
219 return ret;
223 * @brief Wrapper function for device-specific auto-exposure functions
225 * @param dev Pointer to device structure
227 * @returns 0 or negative error value
230 int dev_microdia_camera_set_auto_exposure(struct usb_microdia *dev)
232 int ret = -ENODEV;
233 if (dev && dev->camera.set_auto_exposure)
234 ret = dev->camera.set_auto_exposure(dev);
236 return ret;
240 * @brief Wrapper function for device-specific auto-whitebalance functions
242 * @param dev Pointer to device structure
244 * @returns 0 or negative error value
247 int dev_microdia_camera_set_auto_whitebalance(struct usb_microdia *dev)
249 int ret = -ENODEV;
250 if (dev && dev->camera.set_auto_whitebalance)
251 ret = dev->camera.set_auto_whitebalance(dev);
253 return ret;
257 * @brief function to probe sensor attached to bridge
259 * @param dev pointer to device structure
261 * @returns 0 or negative error value
263 * This function will probe the bridge for the proper sensor
265 int dev_microdia_probe_sensor(struct usb_microdia *dev)
267 int i, ret;
268 dev->camera.sensor_flags = SN9C20X_I2C_2WIRE;
270 for (i = 0; i < ARRAY_SIZE(sensors); i++) {
271 ret = sensors[i].probe(dev);
272 if (ret == sensors[i].id) {
273 UDIA_INFO("Detected sensor: %s\n", sensors[i].name);
274 return ret;
278 return UNKNOWN_SENSOR;
282 * @brief Wrapper function for device-specific initialization functions
284 * @param dev Pointer to device structure
285 * @param flags
287 * @returns 0 or negative error value
290 int dev_microdia_initialize_device(struct usb_microdia *dev, __u32 flags)
292 switch (flags >> 16) {
293 case (SN9C20X_BRIDGE >> 16):
294 UDIA_INFO("Detected SN9C20X Bridge\n");
295 return sn9c20x_initialize(dev);
296 default:
297 UDIA_INFO("Unsupported bridge\n");
299 return -ENODEV;
303 * @brief Wrapper function for for enable video stream for specific bridge
305 * @param dev Pointer to device structure
306 * @param enable Contains the wanted state
308 * @returns 0
311 int dev_microdia_enable_video(struct usb_microdia *dev, int enable)
313 int ret = -ENODEV;
314 if (dev && dev->camera.enable_video)
315 ret = dev->camera.enable_video(dev, enable);
317 return ret;