Update README for libv4l instructions
[microdia.git] / microdia-dev.c
blobf3cdf4d1281b4fef7aa690d23618452146149716
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 "omnivision.h"
34 #include "micron.h"
36 struct sensor_info sensors[] = {
38 .id = OV9650_SENSOR,
39 .name = "OV9650",
40 .address = 0x30,
41 .probe = ov_probe
44 .id = OV9655_SENSOR,
45 .name = "OV9655",
46 .address = 0x30,
47 .probe = ov_probe
50 .id = SOI968_SENSOR,
51 .name = "SOI968",
52 .address = 0x30,
53 .probe = ov_probe
56 .id = OV7660_SENSOR,
57 .name = "OV7660",
58 .address = 0x21,
59 .probe = ov_probe
62 .id = OV7670_SENSOR,
63 .name = "OV7670",
64 .address = 0x21,
65 .probe = ov_probe
68 .id = MT9M111_SENSOR,
69 .name = "MT9M111",
70 .address = 0x5d,
71 .probe = mt9m111_probe
74 .id = MT9V111_SENSOR,
75 .name = "MT9V111",
76 .address = 0x5c,
77 .probe = mt9v111_probe
80 .id = MT9V011_SENSOR,
81 .name = "MT9V011",
82 .address = 0x5d,
83 .probe = mt9v011_probe
86 .id = MT9M001_SENSOR,
87 .name = "MT9M001",
88 .address = 0x5d,
89 .probe = mt9m001_probe
93 /**
94 * @brief Wrapper function for camera-setting functions
96 * @param dev Pointer to device structure
98 * @returns 0
100 int dev_microdia_camera_settings(struct usb_microdia *dev)
102 dev_microdia_camera_set_contrast(dev);
103 dev_microdia_camera_set_brightness(dev);
104 dev_microdia_camera_set_gamma(dev);
105 dev_microdia_camera_set_exposure(dev);
106 dev_microdia_camera_set_hvflip(dev);
107 dev_microdia_camera_set_sharpness(dev);
108 dev_microdia_camera_set_rgb_gain(dev);
109 dev_microdia_camera_set_auto_exposure(dev);
110 dev_microdia_camera_set_auto_whitebalance(dev);
111 return 0;
115 * @brief Wrapper function for device-specific contrast functions
117 * @param dev Pointer to device structure
119 * @returns 0 or negative error value
122 int dev_microdia_camera_set_contrast(struct usb_microdia *dev)
124 int ret = -ENODEV;
125 if (dev && dev->camera.set_contrast)
126 ret = dev->camera.set_contrast(dev);
127 return ret;
131 * @brief Wrapper function for device-specific brightness functions
133 * @param dev Pointer to device structure
135 * @returns 0 or negative error value
138 int dev_microdia_camera_set_brightness(struct usb_microdia *dev)
140 int ret = -ENODEV;
141 if (dev && dev->camera.set_brightness)
142 ret = dev->camera.set_brightness(dev);
143 return ret;
147 * @brief Wrapper function for device-specific gamma functions
149 * @param dev Pointer to device structure
151 * @returns 0 or negative error value
154 int dev_microdia_camera_set_gamma(struct usb_microdia *dev)
156 int ret = -ENODEV;
157 if (dev && dev->camera.set_gamma)
158 ret = dev->camera.set_gamma(dev);
159 return ret;
163 * @brief Wrapper function for device-specific exposure functions
165 * @param dev Pointer to device structure
167 * @returns 0 or negative error value
170 int dev_microdia_camera_set_exposure(struct usb_microdia *dev)
172 if (dev && dev->camera.set_exposure != NULL)
173 return dev->camera.set_exposure(dev);
175 return 0;
179 * @brief Wrapper function for device-specific hvflip functions
181 * @param dev Pointer to device structure
183 * @returns 0 or negative error value
186 int dev_microdia_camera_set_hvflip(struct usb_microdia *dev)
188 int ret = -ENODEV;
189 if (dev && dev->camera.set_hvflip)
190 ret = dev->camera.set_hvflip(dev);
192 return ret;
196 * @brief Wrapper function for device-specific sharpness functions
198 * @param dev Pointer to device structure
200 * @returns 0 or negative error value
203 int dev_microdia_camera_set_sharpness(struct usb_microdia *dev)
205 int ret = -ENODEV;
206 if (dev && dev->camera.set_sharpness)
207 ret = dev->camera.set_sharpness(dev);
209 return ret;
213 * @brief Wrapper function for device-specific rgb-gain functions
215 * @param dev Pointer to device structure
217 * @returns 0 or negative error value
220 int dev_microdia_camera_set_rgb_gain(struct usb_microdia *dev)
222 int ret = -ENODEV;
223 if (dev && dev->camera.set_rgb_gain)
224 ret = dev->camera.set_rgb_gain(dev);
226 return ret;
230 * @brief Wrapper function for device-specific auto-exposure functions
232 * @param dev Pointer to device structure
234 * @returns 0 or negative error value
237 int dev_microdia_camera_set_auto_exposure(struct usb_microdia *dev)
239 int ret = -ENODEV;
240 if (dev && dev->camera.set_auto_exposure)
241 ret = dev->camera.set_auto_exposure(dev);
243 return ret;
247 * @brief Wrapper function for device-specific auto-whitebalance functions
249 * @param dev Pointer to device structure
251 * @returns 0 or negative error value
254 int dev_microdia_camera_set_auto_whitebalance(struct usb_microdia *dev)
256 int ret = -ENODEV;
257 if (dev && dev->camera.set_auto_whitebalance)
258 ret = dev->camera.set_auto_whitebalance(dev);
260 return ret;
264 * @brief function to probe sensor attached to bridge
266 * @param dev pointer to device structure
268 * @returns 0 or negative error value
270 * This function will probe the bridge for the proper sensor
272 int dev_microdia_probe_sensor(struct usb_microdia *dev)
274 int i, ret;
275 dev->camera.sensor_flags = SN9C20X_I2C_2WIRE;
277 for (i = 0; i < ARRAY_SIZE(sensors); i++) {
278 dev->camera.sensor_slave_address = sensors[i].address;
279 ret = sensors[i].probe(dev);
280 if (ret == sensors[i].id) {
281 UDIA_INFO("Detected sensor: %s\n", sensors[i].name);
282 return ret;
286 return UNKNOWN_SENSOR;
290 * @brief Wrapper function for device-specific initialization functions
292 * @param dev Pointer to device structure
293 * @param flags
295 * @returns 0 or negative error value
298 int dev_microdia_initialize_device(struct usb_microdia *dev, __u32 flags)
300 switch (flags >> 16) {
301 case (SN9C20X_BRIDGE >> 16):
302 UDIA_INFO("Detected SN9C20X Bridge\n");
303 return sn9c20x_initialize(dev);
304 default:
305 UDIA_INFO("Unsupported bridge\n");
307 return -ENODEV;
311 * @brief Wrapper function for for enable video stream for specific bridge
313 * @param dev Pointer to device structure
314 * @param enable Contains the wanted state
316 * @returns 0
319 int dev_microdia_enable_video(struct usb_microdia *dev, int enable)
321 int ret = -ENODEV;
322 if (dev && dev->camera.enable_video)
323 ret = dev->camera.enable_video(dev, enable);
325 return ret;