6 * @brief Common control functions for the Omnivision OV7660 series Image Sensors.
8 * @note Copyright (C) Neekhil
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
31 int ov7660_sleep(struct usb_microdia
*dev
);
32 int ov7660_wakeup(struct usb_microdia
*dev
);
33 int ov7660_reset(struct usb_microdia
*dev
);
35 static __u8 ov7660_init
[][2] = {
36 /* System CLK selection, to get a higher Frame Rate */
37 {OV7660_CTL_COM5
, 0x80},
39 /* COM4 is Reserved : using default value 0x40 OR windows driver value 0x08 */
40 {OV7660_CTL_COM4
, 0x08},
41 /* Enable HREF at optical black, Use optical black line as BLC signal
42 Reset all timing when format changes, Enable ADBLC option */
43 {OV7660_CTL_COM6
, 0xc3},
44 /* windows 0x00, default 0x00, trying 0x60 to enable CCIR656 format */
45 {OV7660_CTL_COM1
, 0xc3},
46 /* default is 0x40, windows sets it to 0x00 */
47 {OV7660_CTL_AECH
, 0x40},
48 /* default is 0x00, windows sets it to 0x40 */
49 {OV7660_CTL_CLKRC
, 0x40},
50 /* Set O/P format - RGB Selection, Set O/P format Raw RGB */
51 {OV7660_CTL_COM7
, 0x05},
52 /* default is 0x8f, windows used 0xf8 */
53 /* Enable fast AGC/AEC algorithm, AEC - Step size limit = 1/16 x AEC */
54 /* Banding & Reserved are disabled. AGC, AEC enabled, 0x85 */
55 {OV7660_CTL_COM8
, 0xb8},
56 /* video appears jagged w/o these ADC writes */
57 {OV7660_CTL_ADC
, 0x0f},
58 {OV7660_CTL_ACOM
, 0x02},
59 {OV7660_CTL_OFON
, 0x43},
60 /* video appears jagged w/o this write */
61 /* Default 0x0c sets format to uYvY, Windows driver 0x00 sets format to YuYv */
62 {OV7660_CTL_TSLB
, 0x00},
63 /* Not doing this write makes the video look green */
64 /* Manual Banding Filter MSB , set B & R channel pre-gain */
65 {OV7660_CTL_HV
, 0x90},
66 /* No video stream w/o these ADVFL/ADVFH write totally black */
67 {OV7660_CTL_ADVFL
, 0xf6},
68 {OV7660_CTL_ADVFH
, 0x0b},
69 /* Setting BLUE to 0x78; RED to 0x78 to get natural colors in artificial light */
70 {OV7660_CTL_BLUE
, 0x78},
71 /* Setting RED to 0x50 to get natural colors in natural light */
72 {OV7660_CTL_RED
, 0x50},
75 int ov7660_initialize(struct usb_microdia
*dev
)
80 ret
= sn9c20x_i2c_initialize(dev
);
81 ret
= ov7660_reset(dev
);
83 ret
= ov7660_wakeup(dev
);
85 for (i
= 0; i
< ARRAY_SIZE(ov7660_init
); i
++) {
86 reg
= ov7660_init
[i
][0];
87 value
= ov7660_init
[i
][1];
88 ret
= sn9c20x_write_i2c_data(dev
, dev
->sensor_slave_address
, 1,
89 reg
, dev
->sensor_flags
, &value
);
91 UDIA_INFO("Sensor OV7660: Inititialization Error (%d) on array line %d\n", ret
, i
);
100 * @brief Set exposure for ov7660 sensors
104 * @return 0 or negative error value
108 int ov7660_set_exposure(struct usb_microdia
*dev
)
111 __u8 v1
= (dev
->vsettings
.exposure
>> 4) & 0xff;
112 __u8 v2
= dev
->vsettings
.exposure
>> 12;
114 ret
|= sn9c20x_write_i2c_data(dev
, dev
->sensor_slave_address
, 1, OV7660_CTL_ADVFL
,
115 dev
->sensor_flags
, &v1
);
117 ret
|= sn9c20x_write_i2c_data(dev
, dev
->sensor_slave_address
, 1, OV7660_CTL_ADVFH
,
118 dev
->sensor_flags
, &v2
);
124 * @brief Set autoexposure for ov7660 sensors
128 * @return 0 or negative error value
132 int ov7660_set_autoexposure(struct usb_microdia
*dev
)
137 /* Read current value of the I2C-register
138 * controlling AutoExposureControl:
140 ret
= sn9c20x_read_i2c_data(dev
, dev
->sensor_slave_address
,
141 1, OV7660_CTL_COM8
, dev
->sensor_flags
, buf
);
143 UDIA_ERROR("Error: setting of auto exposure failed: "
144 "error while reading from I2C-register OV7660_CTL_COM8");
148 /* Determine new value for OV7660_CTL_COM8 register */
149 if (dev
->vsettings
.auto_exposure
== 1) {
150 /* Enable automatic exposure: */
152 } else if (dev
->vsettings
.auto_exposure
== 0) {
153 /* Disable automatic exposure: */
158 /* Write new value to I2C-register OV7660_CTL_COM8 */
159 ret
= sn9c20x_write_i2c_data(dev
, dev
->sensor_slave_address
,
160 1, OV7660_CTL_COM8
, dev
->sensor_flags
, buf
);
162 UDIA_ERROR("Error: setting of auto exposure failed: "
163 "error while writing to I2C-register OV7660_CTL_COM8");
170 * @brief Set ov7660 sensors to soft-sleep mode
172 * @return 0 or negative error value
175 int ov7660_sleep(struct usb_microdia
*dev
)
180 /* Set the sensor to Soft Sleep mode, Set O/P drive capability to 4X*/
182 ret
= sn9c20x_write_i2c_data(dev
, dev
->sensor_slave_address
, 1,
183 OV7660_CTL_COM2
, dev
->sensor_flags
, buf
);
190 UDIA_ERROR("Setting Image Sensor to soft sleep failed(%d)!\n", ret
);
195 * @brief Get ov7660 sensors to wake up from soft-sleep mode
197 * @return 0 or negative error value
200 int ov7660_wakeup(struct usb_microdia
*dev
)
205 /* Wake the sensor from Soft Sleep mode, Set O/P drive capability to 4X */
207 ret
= sn9c20x_write_i2c_data(dev
, dev
->sensor_slave_address
, 1,
208 OV7660_CTL_COM2
, dev
->sensor_flags
, buf
);
215 UDIA_ERROR("Image Sensor failed to wake-up from soft sleep (%d)!\n", ret
);
220 * @brief Resets all the registers on ov7660 sensor
222 * @return 0 or negative error value
225 int ov7660_reset(struct usb_microdia
*dev
)
230 /* Reset all registers to default value */
231 /* Set O/P format - RGB Selection, Set O/P format Raw RGB */
233 ret
= sn9c20x_write_i2c_data(dev
, dev
->sensor_slave_address
, 1,
234 OV7660_CTL_COM7
, dev
->sensor_flags
, buf
);
241 UDIA_ERROR("Failed to reset the Image Sensor (%d)!\n", ret
);