1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
31#include "stv06xx_st6422.h"
32
33static struct v4l2_pix_format st6422_mode[] = {
34
35
36 {
37 162,
38 120,
39 V4L2_PIX_FMT_SGRBG8,
40 V4L2_FIELD_NONE,
41 .sizeimage = 162 * 120,
42 .bytesperline = 162,
43 .colorspace = V4L2_COLORSPACE_SRGB,
44 .priv = 1
45 },
46
47
48
49
50 {
51 324,
52 240,
53 V4L2_PIX_FMT_SGRBG8,
54 V4L2_FIELD_NONE,
55 .sizeimage = 324 * 244,
56 .bytesperline = 324,
57 .colorspace = V4L2_COLORSPACE_SRGB,
58 .priv = 0
59 },
60};
61
62
63static int setbrightness(struct sd *sd, s32 val);
64static int setcontrast(struct sd *sd, s32 val);
65static int setgain(struct sd *sd, u8 gain);
66static int setexposure(struct sd *sd, s16 expo);
67
68static int st6422_s_ctrl(struct v4l2_ctrl *ctrl)
69{
70 struct gspca_dev *gspca_dev =
71 container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
72 struct sd *sd = (struct sd *)gspca_dev;
73 int err = -EINVAL;
74
75 switch (ctrl->id) {
76 case V4L2_CID_BRIGHTNESS:
77 err = setbrightness(sd, ctrl->val);
78 break;
79 case V4L2_CID_CONTRAST:
80 err = setcontrast(sd, ctrl->val);
81 break;
82 case V4L2_CID_GAIN:
83 err = setgain(sd, ctrl->val);
84 break;
85 case V4L2_CID_EXPOSURE:
86 err = setexposure(sd, ctrl->val);
87 break;
88 }
89
90
91 if (err >= 0)
92 err = stv06xx_write_bridge(sd, 0x143f, 0x01);
93 sd->gspca_dev.usb_err = err;
94 return err;
95}
96
97static const struct v4l2_ctrl_ops st6422_ctrl_ops = {
98 .s_ctrl = st6422_s_ctrl,
99};
100
101static int st6422_init_controls(struct sd *sd)
102{
103 struct v4l2_ctrl_handler *hdl = &sd->gspca_dev.ctrl_handler;
104
105 v4l2_ctrl_handler_init(hdl, 4);
106 v4l2_ctrl_new_std(hdl, &st6422_ctrl_ops,
107 V4L2_CID_BRIGHTNESS, 0, 31, 1, 3);
108 v4l2_ctrl_new_std(hdl, &st6422_ctrl_ops,
109 V4L2_CID_CONTRAST, 0, 15, 1, 11);
110 v4l2_ctrl_new_std(hdl, &st6422_ctrl_ops,
111 V4L2_CID_EXPOSURE, 0, 1023, 1, 256);
112 v4l2_ctrl_new_std(hdl, &st6422_ctrl_ops,
113 V4L2_CID_GAIN, 0, 255, 1, 64);
114
115 return hdl->error;
116}
117
118static int st6422_probe(struct sd *sd)
119{
120 if (sd->bridge != BRIDGE_ST6422)
121 return -ENODEV;
122
123 pr_info("st6422 sensor detected\n");
124
125 sd->gspca_dev.cam.cam_mode = st6422_mode;
126 sd->gspca_dev.cam.nmodes = ARRAY_SIZE(st6422_mode);
127 return 0;
128}
129
130static int st6422_init(struct sd *sd)
131{
132 int err = 0, i;
133
134 const u16 st6422_bridge_init[][2] = {
135 { STV_ISO_ENABLE, 0x00 },
136 { 0x1436, 0x00 },
137 { 0x1432, 0x03 },
138 { 0x143a, 0xf9 },
139 { 0x0509, 0x38 },
140 { 0x050a, 0x38 },
141 { 0x050b, 0x38 },
142 { 0x050c, 0x2a },
143 { 0x050d, 0x01 },
144
145
146 { 0x1431, 0x00 },
147 { 0x1433, 0x34 },
148 { 0x1438, 0x18 },
149
150
151
152 { 0x1439, 0x00 },
153
154
155 { 0x143b, 0x05 },
156 { 0x143c, 0x00 },
157
158
159
160
161
162 { 0x143e, 0x01 },
163 { 0x143d, 0x00 },
164
165 { 0x1442, 0xe2 },
166
167
168
169
170
171
172
173
174
175
176
177
178
179 { 0x1500, 0xd0 },
180 { 0x1500, 0xd0 },
181 { 0x1500, 0x50 },
182
183 { 0x1501, 0xaf },
184
185
186 { 0x1502, 0xc2 },
187
188
189 { 0x1503, 0x45 },
190
191
192 { 0x1505, 0x02 },
193
194
195
196
197 { 0x150e, 0x8e },
198 { 0x150f, 0x37 },
199 { 0x15c0, 0x00 },
200 { 0x15c3, 0x08 },
201
202
203 { 0x143f, 0x01 },
204
205 };
206
207 for (i = 0; i < ARRAY_SIZE(st6422_bridge_init) && !err; i++) {
208 err = stv06xx_write_bridge(sd, st6422_bridge_init[i][0],
209 st6422_bridge_init[i][1]);
210 }
211
212 return err;
213}
214
215static int setbrightness(struct sd *sd, s32 val)
216{
217
218 return stv06xx_write_bridge(sd, 0x1432, val);
219}
220
221static int setcontrast(struct sd *sd, s32 val)
222{
223
224 return stv06xx_write_bridge(sd, 0x143a, val | 0xf0);
225}
226
227static int setgain(struct sd *sd, u8 gain)
228{
229 int err;
230
231
232 err = stv06xx_write_bridge(sd, 0x0509, gain);
233 if (err < 0)
234 return err;
235
236 err = stv06xx_write_bridge(sd, 0x050a, gain);
237 if (err < 0)
238 return err;
239
240 err = stv06xx_write_bridge(sd, 0x050b, gain);
241 if (err < 0)
242 return err;
243
244
245 err = stv06xx_write_bridge(sd, 0x050c, 0x2a);
246 if (err < 0)
247 return err;
248
249 return stv06xx_write_bridge(sd, 0x050d, 0x01);
250}
251
252static int setexposure(struct sd *sd, s16 expo)
253{
254 int err;
255
256 err = stv06xx_write_bridge(sd, 0x143d, expo & 0xff);
257 if (err < 0)
258 return err;
259
260 return stv06xx_write_bridge(sd, 0x143e, expo >> 8);
261}
262
263static int st6422_start(struct sd *sd)
264{
265 int err;
266 struct cam *cam = &sd->gspca_dev.cam;
267
268 if (cam->cam_mode[sd->gspca_dev.curr_mode].priv)
269 err = stv06xx_write_bridge(sd, 0x1505, 0x0f);
270 else
271 err = stv06xx_write_bridge(sd, 0x1505, 0x02);
272 if (err < 0)
273 return err;
274
275
276 err = stv06xx_write_bridge(sd, 0x143f, 0x01);
277 return (err < 0) ? err : 0;
278}
279
280static int st6422_stop(struct sd *sd)
281{
282 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
283
284 PDEBUG(D_STREAM, "Halting stream");
285
286 return 0;
287}
288