V4L/DVB (5474): SN9C1xx driver updates
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / media / video / sn9c102 / sn9c102_tas5130d1b.c
1 /***************************************************************************
2 * Plug-in for TAS5130D1B image sensor connected to the SN9C1xx PC Camera *
3 * Controllers *
4 * *
5 * Copyright (C) 2004-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 "sn9c102_sensor.h"
23
24
25 static int tas5130d1b_init(struct sn9c102_device* cam)
26 {
27 int err = 0;
28
29 err += sn9c102_write_reg(cam, 0x01, 0x01);
30 err += sn9c102_write_reg(cam, 0x20, 0x17);
31 err += sn9c102_write_reg(cam, 0x04, 0x01);
32 err += sn9c102_write_reg(cam, 0x01, 0x10);
33 err += sn9c102_write_reg(cam, 0x00, 0x11);
34 err += sn9c102_write_reg(cam, 0x00, 0x14);
35 err += sn9c102_write_reg(cam, 0x60, 0x17);
36 err += sn9c102_write_reg(cam, 0x07, 0x18);
37
38 return err;
39 }
40
41
42 static int tas5130d1b_set_ctrl(struct sn9c102_device* cam,
43 const struct v4l2_control* ctrl)
44 {
45 int err = 0;
46
47 switch (ctrl->id) {
48 case V4L2_CID_GAIN:
49 err += sn9c102_i2c_write(cam, 0x20, 0xf6 - ctrl->value);
50 break;
51 case V4L2_CID_EXPOSURE:
52 err += sn9c102_i2c_write(cam, 0x40, 0x47 - ctrl->value);
53 break;
54 default:
55 return -EINVAL;
56 }
57
58 return err ? -EIO : 0;
59 }
60
61
62 static int tas5130d1b_set_crop(struct sn9c102_device* cam,
63 const struct v4l2_rect* rect)
64 {
65 struct sn9c102_sensor* s = sn9c102_get_sensor(cam);
66 u8 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 104,
67 v_start = (u8)(rect->top - s->cropcap.bounds.top) + 12;
68 int err = 0;
69
70 err += sn9c102_write_reg(cam, h_start, 0x12);
71 err += sn9c102_write_reg(cam, v_start, 0x13);
72
73 /* Do NOT change! */
74 err += sn9c102_write_reg(cam, 0x1f, 0x1a);
75 err += sn9c102_write_reg(cam, 0x1a, 0x1b);
76 err += sn9c102_write_reg(cam, sn9c102_pread_reg(cam, 0x19), 0x19);
77
78 return err;
79 }
80
81
82 static int tas5130d1b_set_pix_format(struct sn9c102_device* cam,
83 const struct v4l2_pix_format* pix)
84 {
85 int err = 0;
86
87 if (pix->pixelformat == V4L2_PIX_FMT_SN9C10X)
88 err += sn9c102_write_reg(cam, 0x63, 0x19);
89 else
90 err += sn9c102_write_reg(cam, 0xf3, 0x19);
91
92 return err;
93 }
94
95
96 static struct sn9c102_sensor tas5130d1b = {
97 .name = "TAS5130D1B",
98 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
99 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102,
100 .sysfs_ops = SN9C102_I2C_WRITE,
101 .frequency = SN9C102_I2C_100KHZ,
102 .interface = SN9C102_I2C_3WIRES,
103 .init = &tas5130d1b_init,
104 .qctrl = {
105 {
106 .id = V4L2_CID_GAIN,
107 .type = V4L2_CTRL_TYPE_INTEGER,
108 .name = "global gain",
109 .minimum = 0x00,
110 .maximum = 0xf6,
111 .step = 0x02,
112 .default_value = 0x00,
113 .flags = 0,
114 },
115 {
116 .id = V4L2_CID_EXPOSURE,
117 .type = V4L2_CTRL_TYPE_INTEGER,
118 .name = "exposure",
119 .minimum = 0x00,
120 .maximum = 0x47,
121 .step = 0x01,
122 .default_value = 0x00,
123 .flags = 0,
124 },
125 },
126 .set_ctrl = &tas5130d1b_set_ctrl,
127 .cropcap = {
128 .bounds = {
129 .left = 0,
130 .top = 0,
131 .width = 640,
132 .height = 480,
133 },
134 .defrect = {
135 .left = 0,
136 .top = 0,
137 .width = 640,
138 .height = 480,
139 },
140 },
141 .set_crop = &tas5130d1b_set_crop,
142 .pix_format = {
143 .width = 640,
144 .height = 480,
145 .pixelformat = V4L2_PIX_FMT_SBGGR8,
146 .priv = 8,
147 },
148 .set_pix_format = &tas5130d1b_set_pix_format
149 };
150
151
152 int sn9c102_probe_tas5130d1b(struct sn9c102_device* cam)
153 {
154 const struct usb_device_id tas5130d1b_id_table[] = {
155 { USB_DEVICE(0x0c45, 0x6024), },
156 { USB_DEVICE(0x0c45, 0x6025), },
157 { USB_DEVICE(0x0c45, 0x60aa), },
158 { }
159 };
160
161 /* Sensor detection is based on USB pid/vid */
162 if (!sn9c102_match_id(cam, tas5130d1b_id_table))
163 return -ENODEV;
164
165 sn9c102_attach_sensor(cam, &tas5130d1b);
166
167 return 0;
168 }