Remove slave and flags param from i2c read/write functions
[microdia.git] / microdia-dev.c
blobb595e61e536c02a51ce8833d4b7010ec3d2d2c86
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 = ov965x_probe
45 .id = OV9655_SENSOR,
46 .name = "OV9655",
47 .probe = ov965x_probe
51 /**
52 * @brief Set USB-bandwidth to maximum
54 * @param dev Pointer to device structure
56 * @returns 0 or negative error value
58 int dev_microdia_camera_on(struct usb_microdia *dev)
60 int ret = -1;
61 struct usb_device *udev = dev->udev;
63 ret = usb_set_interface(udev, 0, 8);
65 if (ret < 0)
66 UDIA_ERROR("usb_set_interface failed !\n");
68 return ret;
71 /**
72 * @brief Set USB-bandwidth to minimum
74 * @param dev Pointer to device structure
76 * @returns 0 or negative error value
78 int dev_microdia_camera_off(struct usb_microdia *dev)
80 int ret = -1;
81 struct usb_device *udev = dev->udev;
83 ret = usb_set_interface(udev, 0, 0);
85 if (ret < 0)
86 UDIA_ERROR("usb_set_interface failed !\n");
88 return 0;
91 /**
92 * @brief Wrapper function for camera-setting functions
94 * @param dev Pointer to device structure
96 * @returns 0
98 int dev_microdia_camera_settings(struct usb_microdia *dev)
100 dev_microdia_camera_set_contrast(dev);
101 dev_microdia_camera_set_brightness(dev);
102 dev_microdia_camera_set_gamma(dev);
103 dev_microdia_camera_set_exposure(dev);
104 dev_microdia_camera_set_hvflip(dev);
105 dev_microdia_camera_set_sharpness(dev);
106 dev_microdia_camera_set_rgb_gain(dev);
107 dev_microdia_camera_set_auto_exposure(dev);
108 dev_microdia_camera_set_auto_whitebalance(dev);
109 return 0;
113 * @brief Wrapper function for device-specific contrast functions
115 * @param dev Pointer to device structure
117 * @returns 0 or negative error value
119 * This will execute a function determined by the array #cameras and
120 * the function find_camera().
123 int dev_microdia_camera_set_contrast(struct usb_microdia *dev)
125 int ret = -ENODEV;
126 if (dev && dev->camera.set_contrast)
127 ret = dev->camera.set_contrast(dev);
128 return ret;
132 * @brief Wrapper function for device-specific brightness functions
134 * @param dev Pointer to device structure
136 * @returns 0 or negative error value
138 * This will execute a function determined by the array #cameras and
139 * the function find_camera().
142 int dev_microdia_camera_set_brightness(struct usb_microdia *dev)
144 int ret = -ENODEV;
145 if (dev && dev->camera.set_brightness)
146 ret = dev->camera.set_brightness(dev);
147 return ret;
151 * @brief Wrapper function for device-specific gamma functions
153 * @param dev Pointer to device structure
155 * @returns 0 or negative error value
157 * This will execute a function determined by the array #cameras and
158 * the function find_camera().
161 int dev_microdia_camera_set_gamma(struct usb_microdia *dev)
163 int ret = -ENODEV;
164 if (dev && dev->camera.set_gamma)
165 ret = dev->camera.set_gamma(dev);
166 return ret;
170 * @brief Wrapper function for device-specific exposure functions
172 * @param dev Pointer to device structure
174 * @returns 0 or negative error value
176 * This will execute a function determined by the array #cameras and
177 * the function find_camera().
180 int dev_microdia_camera_set_exposure(struct usb_microdia *dev)
182 if (dev && dev->camera.set_exposure != NULL)
183 return dev->camera.set_exposure(dev);
185 return 0;
189 * @brief Wrapper function for device-specific hvflip functions
191 * @param dev Pointer to device structure
193 * @returns 0 or negative error value
195 * This will execute a function determined by the array #cameras and
196 * the function find_camera().
199 int dev_microdia_camera_set_hvflip(struct usb_microdia *dev)
201 int ret = -ENODEV;
202 if (dev && dev->camera.set_hvflip)
203 ret = dev->camera.set_hvflip(dev);
205 return ret;
209 * @brief Wrapper function for device-specific sharpness functions
211 * @param dev Pointer to device structure
213 * @returns 0 or negative error value
215 * This will execute a function determined by the array #cameras and
216 * the function find_camera().
219 int dev_microdia_camera_set_sharpness(struct usb_microdia *dev)
221 int ret = -ENODEV;
222 if (dev && dev->camera.set_sharpness)
223 ret = dev->camera.set_sharpness(dev);
225 return ret;
229 * @brief Wrapper function for device-specific rgb-gain functions
231 * @param dev Pointer to device structure
233 * @returns 0 or negative error value
235 * This will execute a function determined by the array #cameras and
236 * the function find_camera().
239 int dev_microdia_camera_set_rgb_gain(struct usb_microdia *dev)
241 int ret = -ENODEV;
242 if (dev && dev->camera.set_rgb_gain)
243 ret = dev->camera.set_rgb_gain(dev);
245 return ret;
249 * @brief Wrapper function for device-specific auto-exposure functions
251 * @param dev Pointer to device structure
253 * @returns 0 or negative error value
255 * This will execute a function determined by the array #cameras and
256 * the function find_camera().
259 int dev_microdia_camera_set_auto_exposure(struct usb_microdia *dev)
261 int ret = -ENODEV;
262 if (dev && dev->camera.set_auto_exposure)
263 ret = dev->camera.set_auto_exposure(dev);
265 return ret;
269 * @brief Wrapper function for device-specific auto-whitebalance functions
271 * @param dev Pointer to device structure
273 * @returns 0 or negative error value
275 * This will execute a function determined by the array #cameras and
276 * the function find_camera().
279 int dev_microdia_camera_set_auto_whitebalance(struct usb_microdia *dev)
281 int ret = -ENODEV;
282 if (dev && dev->camera.set_auto_whitebalance)
283 ret = dev->camera.set_auto_whitebalance(dev);
285 return ret;
289 * @brief function to probe sensor attached to bridge
291 * @param dev pointer to device structure
293 * @returns 0 or negative error value
295 * This function will probe the bridge for the proper sensor
297 int dev_microdia_probe_sensor(struct usb_microdia *dev)
299 int i, ret;
300 dev->camera.sensor_flags = SN9C20X_I2C_2WIRE;
302 for (i = 0; i < ARRAY_SIZE(sensors); i++) {
303 ret = sensors[i].probe(dev);
304 if (ret == sensors[i].id) {
305 UDIA_INFO("Detected sensor: %s\n", sensors[i].name);
306 return ret;
310 return UNKNOWN_SENSOR;
314 * @brief Wrapper function for device-specific initialization functions
316 * @param dev Pointer to device structure
318 * @returns 0 or negative error value
320 * This will execute a function determined by the array #cameras and
321 * the function find_camera().
324 int dev_microdia_initialize_device(struct usb_microdia *dev)
326 int ret = -ENODEV;
328 if (dev && dev->camera.initialize)
329 ret = dev->camera.initialize(dev);
331 return ret;
335 * @brief Wrapper function for for enable video stream for specific bridge
337 * @param dev Pointer to device structure
339 * @returns 0
341 * This will execute a function determined by the array #cameras and
342 * the function find_camera().
345 int dev_microdia_enable_video(struct usb_microdia *dev, int enable)
347 int ret = -ENODEV;
348 if (dev && dev->camera.enable_video)
349 ret = dev->camera.enable_video(dev, enable);
351 return ret;
355 * @brief Detect whether the image for 624f has to be flipped
357 * @param dev Pointer to device structure
359 * @returns 0 or negative error code
362 int microdia_624f_flip_detect(struct usb_microdia *dev)
364 int ret = 0;
365 __u8 val;
367 ret = usb_microdia_control_read(dev, 0x1009, &val, 1);
368 if (ret < 0)
369 return -EAGAIN;
370 if (val & 0x01)
371 dev->vsettings.vflip = 1;
372 else
373 dev->vsettings.vflip = 0;
374 return ret;
378 * @brief Detect whether the image for 6260 has to be flipped
380 * @param dev Pointer to device structure
382 * @returns 0 or negative error code
386 int microdia_6260_flip_detect(struct usb_microdia *dev)
388 const __u8 flip_bit = 0x01;
389 int ret = 0;
390 __u8 val;
391 static __u8 flip_reg = flip_bit;
392 __u8 vflip;
394 ret = usb_microdia_control_read(dev, 0x1009, &val, 1);
395 if (ret < 0)
396 return -EAGAIN;
397 if (flip_reg != (val & flip_bit)) {
398 if (val & flip_bit)
399 vflip = 0;
400 else
401 vflip = 1;
402 ret = ov7670_auto_flip(dev, vflip);
403 flip_reg = (val & flip_bit);
406 return ret;