Merge branch 'for-linus' of git://git.o-hand.com/linux-rpurdie-leds
[sfrench/cifs-2.6.git] / drivers / media / video / et61x251 / et61x251_tas5130d1b.c
1 /***************************************************************************
2  * Plug-in for TAS5130D1B image sensor connected to the ET61X[12]51        *
3  * PC Camera Controllers                                                   *
4  *                                                                         *
5  * Copyright (C) 2006-2007 by Luca Risolia <luca.risolia@studio.unibo.it>  *
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., 675 Mass Ave, Cambridge, MA 02139, USA.               *
20  ***************************************************************************/
21
22 #include "et61x251_sensor.h"
23
24
25 static int tas5130d1b_init(struct et61x251_device* cam)
26 {
27         int err = 0;
28
29         err += et61x251_write_reg(cam, 0x14, 0x01);
30         err += et61x251_write_reg(cam, 0x1b, 0x02);
31         err += et61x251_write_reg(cam, 0x02, 0x12);
32         err += et61x251_write_reg(cam, 0x0e, 0x60);
33         err += et61x251_write_reg(cam, 0x80, 0x61);
34         err += et61x251_write_reg(cam, 0xf0, 0x62);
35         err += et61x251_write_reg(cam, 0x03, 0x63);
36         err += et61x251_write_reg(cam, 0x14, 0x64);
37         err += et61x251_write_reg(cam, 0xf4, 0x65);
38         err += et61x251_write_reg(cam, 0x01, 0x66);
39         err += et61x251_write_reg(cam, 0x05, 0x67);
40         err += et61x251_write_reg(cam, 0x8f, 0x68);
41         err += et61x251_write_reg(cam, 0x0f, 0x8d);
42         err += et61x251_write_reg(cam, 0x08, 0x8e);
43
44         return err;
45 }
46
47
48 static int tas5130d1b_set_ctrl(struct et61x251_device* cam,
49                                const struct v4l2_control* ctrl)
50 {
51         int err = 0;
52
53         switch (ctrl->id) {
54         case V4L2_CID_GAIN:
55                 err += et61x251_i2c_raw_write(cam, 2, 0x20,
56                                               0xf6-ctrl->value, 0, 0, 0,
57                                               0, 0, 0, 0);
58                 break;
59         case V4L2_CID_EXPOSURE:
60                 err += et61x251_i2c_raw_write(cam, 2, 0x40,
61                                               0x47-ctrl->value, 0, 0, 0,
62                                               0, 0, 0, 0);
63                 break;
64         default:
65                 return -EINVAL;
66         }
67
68         return err ? -EIO : 0;
69 }
70
71
72 static struct et61x251_sensor tas5130d1b = {
73         .name = "TAS5130D1B",
74         .interface = ET61X251_I2C_3WIRES,
75         .rsta = ET61X251_I2C_RSTA_STOP,
76         .active_pixel = {
77                 .left = 106,
78                 .top = 13,
79         },
80         .init = &tas5130d1b_init,
81         .qctrl = {
82                 {
83                         .id = V4L2_CID_GAIN,
84                         .type = V4L2_CTRL_TYPE_INTEGER,
85                         .name = "global gain",
86                         .minimum = 0x00,
87                         .maximum = 0xf6,
88                         .step = 0x02,
89                         .default_value = 0x0d,
90                         .flags = 0,
91                 },
92                 {
93                         .id = V4L2_CID_EXPOSURE,
94                         .type = V4L2_CTRL_TYPE_INTEGER,
95                         .name = "exposure",
96                         .minimum = 0x00,
97                         .maximum = 0x47,
98                         .step = 0x01,
99                         .default_value = 0x23,
100                         .flags = 0,
101                 },
102         },
103         .set_ctrl = &tas5130d1b_set_ctrl,
104         .cropcap = {
105                 .bounds = {
106                         .left = 0,
107                         .top = 0,
108                         .width = 640,
109                         .height = 480,
110                 },
111                 .defrect = {
112                         .left = 0,
113                         .top = 0,
114                         .width = 640,
115                         .height = 480,
116                 },
117         },
118         .pix_format = {
119                 .width = 640,
120                 .height = 480,
121                 .pixelformat = V4L2_PIX_FMT_SBGGR8,
122                 .priv = 8,
123         },
124 };
125
126
127 int et61x251_probe_tas5130d1b(struct et61x251_device* cam)
128 {
129         const struct usb_device_id tas5130d1b_id_table[] = {
130                 { USB_DEVICE(0x102c, 0x6251), },
131                 { }
132         };
133
134         /* Sensor detection is based on USB pid/vid */
135         if (!et61x251_match_id(cam, tas5130d1b_id_table))
136                 return -ENODEV;
137
138         et61x251_attach_sensor(cam, &tas5130d1b);
139
140         return 0;
141 }