]> git.karo-electronics.de Git - mv-sheeva.git/blob - drivers/media/video/gspca/stv06xx/stv06xx_vv6410.c
a204b5891f637418e43f75d6665a50a33eb821e0
[mv-sheeva.git] / drivers / media / video / gspca / stv06xx / stv06xx_vv6410.c
1 /*
2  * Copyright (c) 2001 Jean-Fredric Clere, Nikolas Zimmermann, Georg Acher
3  *                    Mark Cave-Ayland, Carlo E Prelz, Dick Streefland
4  * Copyright (c) 2002, 2003 Tuukka Toivonen
5  * Copyright (c) 2008 Erik AndrĂ©n
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  * P/N 861037:      Sensor HDCS1000        ASIC STV0600
22  * P/N 861050-0010: Sensor HDCS1000        ASIC STV0600
23  * P/N 861050-0020: Sensor Photobit PB100  ASIC STV0600-1 - QuickCam Express
24  * P/N 861055:      Sensor ST VV6410       ASIC STV0610   - LEGO cam
25  * P/N 861075-0040: Sensor HDCS1000        ASIC
26  * P/N 961179-0700: Sensor ST VV6410       ASIC STV0602   - Dexxa WebCam USB
27  * P/N 861040-0000: Sensor ST VV6410       ASIC STV0610   - QuickCam Web
28  */
29
30 #include "stv06xx_vv6410.h"
31
32 static struct v4l2_pix_format vv6410_mode[] = {
33         {
34                 356,
35                 292,
36                 V4L2_PIX_FMT_SGRBG8,
37                 V4L2_FIELD_NONE,
38                 .sizeimage = 356 * 292,
39                 .bytesperline = 356,
40                 .colorspace = V4L2_COLORSPACE_SRGB,
41                 .priv = 0
42         }
43 };
44
45 static const struct ctrl vv6410_ctrl[] = {
46         {
47                 {
48                         .id             = V4L2_CID_HFLIP,
49                         .type           = V4L2_CTRL_TYPE_BOOLEAN,
50                         .name           = "horizontal flip",
51                         .minimum        = 0,
52                         .maximum        = 1,
53                         .step           = 1,
54                         .default_value  = 0
55                 },
56                 .set = vv6410_set_hflip,
57                 .get = vv6410_get_hflip
58         }, {
59                 {
60                         .id             = V4L2_CID_VFLIP,
61                         .type           = V4L2_CTRL_TYPE_BOOLEAN,
62                         .name           = "vertical flip",
63                         .minimum        = 0,
64                         .maximum        = 1,
65                         .step           = 1,
66                         .default_value  = 0
67                 },
68                 .set = vv6410_set_vflip,
69                 .get = vv6410_get_vflip
70         }, {
71                 {
72                         .id             = V4L2_CID_GAIN,
73                         .type           = V4L2_CTRL_TYPE_INTEGER,
74                         .name           = "analog gain",
75                         .minimum        = 0,
76                         .maximum        = 15,
77                         .step           = 1,
78                         .default_value  = 0
79                 },
80                 .set = vv6410_set_analog_gain,
81                 .get = vv6410_get_analog_gain
82         }
83 };
84
85 static int vv6410_probe(struct sd *sd)
86 {
87         u16 data;
88         int err;
89
90         err = stv06xx_read_sensor(sd, VV6410_DEVICEH, &data);
91
92         if (err < 0)
93                 return -ENODEV;
94
95         if (data == 0x19) {
96                 info("vv6410 sensor detected");
97
98                 sd->gspca_dev.cam.cam_mode = vv6410_mode;
99                 sd->gspca_dev.cam.nmodes = ARRAY_SIZE(vv6410_mode);
100                 sd->desc.ctrls = vv6410_ctrl;
101                 sd->desc.nctrls = ARRAY_SIZE(vv6410_ctrl);
102                 return 0;
103         }
104
105         return -ENODEV;
106 }
107
108 static int vv6410_init(struct sd *sd)
109 {
110         int err = 0, i;
111
112         for (i = 0; i < ARRAY_SIZE(stv_bridge_init); i++) {
113                 /* if NULL then len contains single value */
114                 if (stv_bridge_init[i].data == NULL) {
115                         err = stv06xx_write_bridge(sd,
116                                 stv_bridge_init[i].start,
117                                 stv_bridge_init[i].len);
118                 } else {
119                         int j;
120                         for (j = 0; j < stv_bridge_init[i].len; j++)
121                                 err = stv06xx_write_bridge(sd,
122                                         stv_bridge_init[i].start + j,
123                                         stv_bridge_init[i].data[j]);
124                 }
125         }
126
127         if (err < 0)
128                 return err;
129
130         err = stv06xx_write_sensor_bytes(sd, (u8 *) vv6410_sensor_init,
131                                          ARRAY_SIZE(vv6410_sensor_init));
132
133         return (err < 0) ? err : 0;
134 }
135
136 static int vv6410_start(struct sd *sd)
137 {
138         int err;
139         struct cam *cam = &sd->gspca_dev.cam;
140         u32 priv = cam->cam_mode[sd->gspca_dev.curr_mode].priv;
141
142         if (priv & VV6410_CROP_TO_QVGA) {
143                 PDEBUG(D_CONF, "Cropping to QVGA");
144                 stv06xx_write_sensor(sd, VV6410_XENDH, 320 - 1);
145                 stv06xx_write_sensor(sd, VV6410_YENDH, 240 - 1);
146         } else {
147                 stv06xx_write_sensor(sd, VV6410_XENDH, 360 - 1);
148                 stv06xx_write_sensor(sd, VV6410_YENDH, 294 - 1);
149         }
150
151         if (priv & VV6410_SUBSAMPLE) {
152                 PDEBUG(D_CONF, "Enabling subsampling");
153                 stv06xx_write_bridge(sd, STV_Y_CTRL, 0x02);
154                 stv06xx_write_bridge(sd, STV_X_CTRL, 0x06);
155
156                 stv06xx_write_bridge(sd, STV_SCAN_RATE, 0x10);
157         } else {
158                 stv06xx_write_bridge(sd, STV_Y_CTRL, 0x01);
159                 stv06xx_write_bridge(sd, STV_X_CTRL, 0x0a);
160
161                 stv06xx_write_bridge(sd, STV_SCAN_RATE, 0x20);
162         }
163
164         /* Turn on LED */
165         err = stv06xx_write_bridge(sd, STV_LED_CTRL, LED_ON);
166         if (err < 0)
167                 return err;
168
169         err = stv06xx_write_sensor(sd, VV6410_SETUP0, 0);
170         if (err < 0)
171                 return err;
172
173         PDEBUG(D_STREAM, "Starting stream");
174
175         return 0;
176 }
177
178 static int vv6410_stop(struct sd *sd)
179 {
180         int err;
181
182         /* Turn off LED */
183         err = stv06xx_write_bridge(sd, STV_LED_CTRL, LED_OFF);
184         if (err < 0)
185                 return err;
186
187         err = stv06xx_write_sensor(sd, VV6410_SETUP0, VV6410_LOW_POWER_MODE);
188         if (err < 0)
189                 return err;
190
191         PDEBUG(D_STREAM, "Halting stream");
192
193         return (err < 0) ? err : 0;
194 }
195
196 static int vv6410_dump(struct sd *sd)
197 {
198         u8 i;
199         int err = 0;
200
201         info("Dumping all vv6410 sensor registers");
202         for (i = 0; i < 0xff && !err; i++) {
203                 u16 data;
204                 err = stv06xx_read_sensor(sd, i, &data);
205                 info("Register 0x%x contained 0x%x", i, data);
206         }
207         return (err < 0) ? err : 0;
208 }
209
210 static int vv6410_get_hflip(struct gspca_dev *gspca_dev, __s32 *val)
211 {
212         int err;
213         u16 i2c_data;
214         struct sd *sd = (struct sd *) gspca_dev;
215
216         err = stv06xx_read_sensor(sd, VV6410_DATAFORMAT, &i2c_data);
217
218         *val = (i2c_data & VV6410_HFLIP) ? 1 : 0;
219
220         PDEBUG(D_V4L2, "Read horizontal flip %d", *val);
221
222         return (err < 0) ? err : 0;
223 }
224
225 static int vv6410_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
226 {
227         int err;
228         u16 i2c_data;
229         struct sd *sd = (struct sd *) gspca_dev;
230         err = stv06xx_read_sensor(sd, VV6410_DATAFORMAT, &i2c_data);
231         if (err < 0)
232                 return err;
233
234         if (val)
235                 i2c_data |= VV6410_HFLIP;
236         else
237                 i2c_data &= ~VV6410_HFLIP;
238
239         PDEBUG(D_V4L2, "Set horizontal flip to %d", val);
240         err = stv06xx_write_sensor(sd, VV6410_DATAFORMAT, i2c_data);
241
242         return (err < 0) ? err : 0;
243 }
244
245 static int vv6410_get_vflip(struct gspca_dev *gspca_dev, __s32 *val)
246 {
247         int err;
248         u16 i2c_data;
249         struct sd *sd = (struct sd *) gspca_dev;
250
251         err = stv06xx_read_sensor(sd, VV6410_DATAFORMAT, &i2c_data);
252
253         *val = (i2c_data & VV6410_VFLIP) ? 1 : 0;
254
255         PDEBUG(D_V4L2, "Read vertical flip %d", *val);
256
257         return (err < 0) ? err : 0;
258 }
259
260 static int vv6410_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
261 {
262         int err;
263         u16 i2c_data;
264         struct sd *sd = (struct sd *) gspca_dev;
265         err = stv06xx_read_sensor(sd, VV6410_DATAFORMAT, &i2c_data);
266         if (err < 0)
267                 return err;
268
269         if (val)
270                 i2c_data |= VV6410_VFLIP;
271         else
272                 i2c_data &= ~VV6410_VFLIP;
273
274         PDEBUG(D_V4L2, "Set vertical flip to %d", val);
275         err = stv06xx_write_sensor(sd, VV6410_DATAFORMAT, i2c_data);
276
277         return (err < 0) ? err : 0;
278 }
279
280 static int vv6410_get_analog_gain(struct gspca_dev *gspca_dev, __s32 *val)
281 {
282         int err;
283         u16 i2c_data;
284         struct sd *sd = (struct sd *) gspca_dev;
285
286         err = stv06xx_read_sensor(sd, VV6410_ANALOGGAIN, &i2c_data);
287
288         *val = i2c_data & 0xf;
289
290         PDEBUG(D_V4L2, "Read analog gain %d", *val);
291
292         return (err < 0) ? err : 0;
293 }
294
295 static int vv6410_set_analog_gain(struct gspca_dev *gspca_dev, __s32 val)
296 {
297         int err;
298         struct sd *sd = (struct sd *) gspca_dev;
299
300         PDEBUG(D_V4L2, "Set analog gain to %d", val);
301         err = stv06xx_write_sensor(sd, VV6410_ANALOGGAIN, 0xf0 | (val & 0xf));
302
303         return (err < 0) ? err : 0;
304 }