Resupport MT9M111 sensors (6242)
[microdia.git] / microdia-dev.c
blob57e29cc84d3f754c7e4916b580b2b59440c82a15
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
71 /**
72 * @brief Wrapper function for camera-setting functions
74 * @param dev Pointer to device structure
76 * @returns 0
78 int dev_microdia_camera_settings(struct usb_microdia *dev)
80 dev_microdia_camera_set_contrast(dev);
81 dev_microdia_camera_set_brightness(dev);
82 dev_microdia_camera_set_gamma(dev);
83 dev_microdia_camera_set_exposure(dev);
84 dev_microdia_camera_set_hvflip(dev);
85 dev_microdia_camera_set_sharpness(dev);
86 dev_microdia_camera_set_rgb_gain(dev);
87 dev_microdia_camera_set_auto_exposure(dev);
88 dev_microdia_camera_set_auto_whitebalance(dev);
89 return 0;
92 /**
93 * @brief Wrapper function for device-specific contrast functions
95 * @param dev Pointer to device structure
97 * @returns 0 or negative error value
100 int dev_microdia_camera_set_contrast(struct usb_microdia *dev)
102 int ret = -ENODEV;
103 if (dev && dev->camera.set_contrast)
104 ret = dev->camera.set_contrast(dev);
105 return ret;
109 * @brief Wrapper function for device-specific brightness functions
111 * @param dev Pointer to device structure
113 * @returns 0 or negative error value
116 int dev_microdia_camera_set_brightness(struct usb_microdia *dev)
118 int ret = -ENODEV;
119 if (dev && dev->camera.set_brightness)
120 ret = dev->camera.set_brightness(dev);
121 return ret;
125 * @brief Wrapper function for device-specific gamma functions
127 * @param dev Pointer to device structure
129 * @returns 0 or negative error value
132 int dev_microdia_camera_set_gamma(struct usb_microdia *dev)
134 int ret = -ENODEV;
135 if (dev && dev->camera.set_gamma)
136 ret = dev->camera.set_gamma(dev);
137 return ret;
141 * @brief Wrapper function for device-specific exposure functions
143 * @param dev Pointer to device structure
145 * @returns 0 or negative error value
148 int dev_microdia_camera_set_exposure(struct usb_microdia *dev)
150 if (dev && dev->camera.set_exposure != NULL)
151 return dev->camera.set_exposure(dev);
153 return 0;
157 * @brief Wrapper function for device-specific hvflip functions
159 * @param dev Pointer to device structure
161 * @returns 0 or negative error value
164 int dev_microdia_camera_set_hvflip(struct usb_microdia *dev)
166 int ret = -ENODEV;
167 if (dev && dev->camera.set_hvflip)
168 ret = dev->camera.set_hvflip(dev);
170 return ret;
174 * @brief Wrapper function for device-specific sharpness functions
176 * @param dev Pointer to device structure
178 * @returns 0 or negative error value
181 int dev_microdia_camera_set_sharpness(struct usb_microdia *dev)
183 int ret = -ENODEV;
184 if (dev && dev->camera.set_sharpness)
185 ret = dev->camera.set_sharpness(dev);
187 return ret;
191 * @brief Wrapper function for device-specific rgb-gain functions
193 * @param dev Pointer to device structure
195 * @returns 0 or negative error value
198 int dev_microdia_camera_set_rgb_gain(struct usb_microdia *dev)
200 int ret = -ENODEV;
201 if (dev && dev->camera.set_rgb_gain)
202 ret = dev->camera.set_rgb_gain(dev);
204 return ret;
208 * @brief Wrapper function for device-specific auto-exposure functions
210 * @param dev Pointer to device structure
212 * @returns 0 or negative error value
215 int dev_microdia_camera_set_auto_exposure(struct usb_microdia *dev)
217 int ret = -ENODEV;
218 if (dev && dev->camera.set_auto_exposure)
219 ret = dev->camera.set_auto_exposure(dev);
221 return ret;
225 * @brief Wrapper function for device-specific auto-whitebalance functions
227 * @param dev Pointer to device structure
229 * @returns 0 or negative error value
232 int dev_microdia_camera_set_auto_whitebalance(struct usb_microdia *dev)
234 int ret = -ENODEV;
235 if (dev && dev->camera.set_auto_whitebalance)
236 ret = dev->camera.set_auto_whitebalance(dev);
238 return ret;
242 * @brief function to probe sensor attached to bridge
244 * @param dev pointer to device structure
246 * @returns 0 or negative error value
248 * This function will probe the bridge for the proper sensor
250 int dev_microdia_probe_sensor(struct usb_microdia *dev)
252 int i, ret;
253 dev->camera.sensor_flags = SN9C20X_I2C_2WIRE;
255 for (i = 0; i < ARRAY_SIZE(sensors); i++) {
256 ret = sensors[i].probe(dev);
257 if (ret == sensors[i].id) {
258 UDIA_INFO("Detected sensor: %s\n", sensors[i].name);
259 return ret;
263 return UNKNOWN_SENSOR;
267 * @brief Wrapper function for device-specific initialization functions
269 * @param dev Pointer to device structure
270 * @param flags
272 * @returns 0 or negative error value
275 int dev_microdia_initialize_device(struct usb_microdia *dev, __u32 flags)
277 switch (flags >> 16) {
278 case (SN9C20X_BRIDGE >> 16):
279 UDIA_INFO("Detected SN9C20X Bridge\n");
280 return sn9c20x_initialize(dev);
281 default:
282 UDIA_INFO("Unsupported bridge\n");
284 return -ENODEV;
288 * @brief Wrapper function for for enable video stream for specific bridge
290 * @param dev Pointer to device structure
291 * @param enable Contains the wanted state
293 * @returns 0
296 int dev_microdia_enable_video(struct usb_microdia *dev, int enable)
298 int ret = -ENODEV;
299 if (dev && dev->camera.enable_video)
300 ret = dev->camera.enable_video(dev, enable);
302 return ret;