3 * @author Nicolas VIVIEN
6 * @brief Device specific functions
8 * @note Copyright (C) Nicolas VIVIEN
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
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>
38 struct sensor_info sensors
[] = {
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
)
61 struct usb_device
*udev
= dev
->udev
;
63 ret
= usb_set_interface(udev
, 0, 8);
66 UDIA_ERROR("usb_set_interface failed !\n");
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
)
81 struct usb_device
*udev
= dev
->udev
;
83 ret
= usb_set_interface(udev
, 0, 0);
86 UDIA_ERROR("usb_set_interface failed !\n");
92 * @brief Wrapper function for camera-setting functions
94 * @param dev Pointer to device structure
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
);
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
)
126 if (dev
&& dev
->camera
.set_contrast
)
127 ret
= dev
->camera
.set_contrast(dev
);
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
)
145 if (dev
&& dev
->camera
.set_brightness
)
146 ret
= dev
->camera
.set_brightness(dev
);
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
)
164 if (dev
&& dev
->camera
.set_gamma
)
165 ret
= dev
->camera
.set_gamma(dev
);
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
);
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
)
202 if (dev
&& dev
->camera
.set_hvflip
)
203 ret
= dev
->camera
.set_hvflip(dev
);
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
)
222 if (dev
&& dev
->camera
.set_sharpness
)
223 ret
= dev
->camera
.set_sharpness(dev
);
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
)
242 if (dev
&& dev
->camera
.set_rgb_gain
)
243 ret
= dev
->camera
.set_rgb_gain(dev
);
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
)
262 if (dev
&& dev
->camera
.set_auto_exposure
)
263 ret
= dev
->camera
.set_auto_exposure(dev
);
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
)
282 if (dev
&& dev
->camera
.set_auto_whitebalance
)
283 ret
= dev
->camera
.set_auto_whitebalance(dev
);
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
)
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
);
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
)
328 if (dev
&& dev
->camera
.initialize
)
329 ret
= dev
->camera
.initialize(dev
);
335 * @brief Wrapper function for for enable video stream for specific bridge
337 * @param dev Pointer to device structure
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
)
348 if (dev
&& dev
->camera
.enable_video
)
349 ret
= dev
->camera
.enable_video(dev
, enable
);
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
)
367 ret
= usb_microdia_control_read(dev
, 0x1009, &val
, 1);
371 dev
->vsettings
.vflip
= 1;
373 dev
->vsettings
.vflip
= 0;
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;
391 static __u8 flip_reg = flip_bit;
394 ret = usb_microdia_control_read(dev, 0x1009, &val, 1);
397 if (flip_reg != (val & flip_bit)) {
402 ret = ov7670_auto_flip(dev, vflip);
403 flip_reg = (val & flip_bit);