Commit | Line | Data |
---|---|---|
b11869db PE |
1 | /* |
2 | * Copyright (C) 2008 Sensoray Company Inc. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License (Version 2) as | |
6 | * published by the Free Software Foundation. | |
7 | * | |
8 | * This program is distributed in the hope that it will be useful, | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | * GNU General Public License for more details. | |
12 | * | |
13 | * You should have received a copy of the GNU General Public License | |
14 | * along with this program; if not, write to the Free Software Foundation, | |
15 | * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. | |
16 | */ | |
17 | ||
18 | #include <linux/module.h> | |
b11869db PE |
19 | #include <linux/usb.h> |
20 | #include <linux/i2c.h> | |
21 | #include <linux/videodev2.h> | |
5a0e3ad6 | 22 | #include <linux/slab.h> |
832b6a89 | 23 | #include <media/v4l2-device.h> |
b11869db | 24 | #include <media/v4l2-common.h> |
05d76f2d | 25 | #include <media/v4l2-subdev.h> |
b11869db | 26 | #include "go7007-priv.h" |
832b6a89 PE |
27 | |
28 | MODULE_DESCRIPTION("Sensoray 2250/2251 i2c v4l2 subdev driver"); | |
29 | MODULE_LICENSE("GPL v2"); | |
b11869db | 30 | |
b20cc073 HV |
31 | /* |
32 | * Note: this board has two i2c devices: a vpx3226f and a tlv320aic23b. | |
33 | * Due to the unusual way these are accessed on this device we do not | |
34 | * reuse the i2c drivers, but instead they are implemented in this | |
35 | * driver. It would be nice to improve on this, though. | |
36 | */ | |
37 | ||
b11869db | 38 | #define TLV320_ADDRESS 0x34 |
b11869db PE |
39 | #define VPX322_ADDR_ANALOGCONTROL1 0x02 |
40 | #define VPX322_ADDR_BRIGHTNESS0 0x0127 | |
41 | #define VPX322_ADDR_BRIGHTNESS1 0x0131 | |
42 | #define VPX322_ADDR_CONTRAST0 0x0128 | |
43 | #define VPX322_ADDR_CONTRAST1 0x0132 | |
44 | #define VPX322_ADDR_HUE 0x00dc | |
028d4c98 | 45 | #define VPX322_ADDR_SAT 0x0030 |
b11869db PE |
46 | |
47 | struct go7007_usb_board { | |
48 | unsigned int flags; | |
49 | struct go7007_board_info main_info; | |
50 | }; | |
51 | ||
52 | struct go7007_usb { | |
53 | struct go7007_usb_board *board; | |
fd9a40da | 54 | struct mutex i2c_lock; |
b11869db PE |
55 | struct usb_device *usbdev; |
56 | struct urb *video_urbs[8]; | |
57 | struct urb *audio_urbs[8]; | |
58 | struct urb *intr_urb; | |
59 | }; | |
60 | ||
61 | static unsigned char aud_regs[] = { | |
62 | 0x1e, 0x00, | |
63 | 0x00, 0x17, | |
64 | 0x02, 0x17, | |
65 | 0x04, 0xf9, | |
66 | 0x06, 0xf9, | |
67 | 0x08, 0x02, | |
68 | 0x0a, 0x00, | |
69 | 0x0c, 0x00, | |
70 | 0x0a, 0x00, | |
71 | 0x0c, 0x00, | |
72 | 0x0e, 0x02, | |
73 | 0x10, 0x00, | |
74 | 0x12, 0x01, | |
75 | 0x00, 0x00, | |
76 | }; | |
77 | ||
78 | ||
79 | static unsigned char vid_regs[] = { | |
80 | 0xF2, 0x0f, | |
81 | 0xAA, 0x00, | |
82 | 0xF8, 0xff, | |
83 | 0x00, 0x00, | |
84 | }; | |
85 | ||
86 | static u16 vid_regs_fp[] = { | |
87 | 0x028, 0x067, | |
88 | 0x120, 0x016, | |
89 | 0x121, 0xcF2, | |
90 | 0x122, 0x0F2, | |
91 | 0x123, 0x00c, | |
92 | 0x124, 0x2d0, | |
93 | 0x125, 0x2e0, | |
94 | 0x126, 0x004, | |
95 | 0x128, 0x1E0, | |
96 | 0x12A, 0x016, | |
97 | 0x12B, 0x0F2, | |
98 | 0x12C, 0x0F2, | |
99 | 0x12D, 0x00c, | |
100 | 0x12E, 0x2d0, | |
101 | 0x12F, 0x2e0, | |
102 | 0x130, 0x004, | |
103 | 0x132, 0x1E0, | |
104 | 0x140, 0x060, | |
105 | 0x153, 0x00C, | |
106 | 0x154, 0x200, | |
107 | 0x150, 0x801, | |
108 | 0x000, 0x000 | |
109 | }; | |
110 | ||
111 | /* PAL specific values */ | |
b91c78e3 | 112 | static u16 vid_regs_fp_pal[] = { |
b11869db PE |
113 | 0x120, 0x017, |
114 | 0x121, 0xd22, | |
115 | 0x122, 0x122, | |
116 | 0x12A, 0x017, | |
117 | 0x12B, 0x122, | |
118 | 0x12C, 0x122, | |
119 | 0x140, 0x060, | |
120 | 0x000, 0x000, | |
121 | }; | |
122 | ||
123 | struct s2250 { | |
05d76f2d | 124 | struct v4l2_subdev sd; |
d3b2ccd9 | 125 | struct v4l2_ctrl_handler hdl; |
047efc7d | 126 | v4l2_std_id std; |
b11869db PE |
127 | int input; |
128 | int brightness; | |
129 | int contrast; | |
130 | int saturation; | |
131 | int hue; | |
132 | int reg12b_val; | |
133 | int audio_input; | |
7400516a | 134 | struct i2c_client *audio; |
b11869db PE |
135 | }; |
136 | ||
05d76f2d PE |
137 | static inline struct s2250 *to_state(struct v4l2_subdev *sd) |
138 | { | |
139 | return container_of(sd, struct s2250, sd); | |
140 | } | |
141 | ||
b11869db PE |
142 | /* from go7007-usb.c which is Copyright (C) 2005-2006 Micronas USA Inc.*/ |
143 | static int go7007_usb_vendor_request(struct go7007 *go, u16 request, | |
144 | u16 value, u16 index, void *transfer_buffer, int length, int in) | |
145 | { | |
146 | struct go7007_usb *usb = go->hpi_context; | |
147 | int timeout = 5000; | |
148 | ||
149 | if (in) { | |
150 | return usb_control_msg(usb->usbdev, | |
151 | usb_rcvctrlpipe(usb->usbdev, 0), request, | |
152 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, | |
153 | value, index, transfer_buffer, length, timeout); | |
154 | } else { | |
155 | return usb_control_msg(usb->usbdev, | |
156 | usb_sndctrlpipe(usb->usbdev, 0), request, | |
157 | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | |
158 | value, index, transfer_buffer, length, timeout); | |
159 | } | |
160 | } | |
161 | /* end from go7007-usb.c which is Copyright (C) 2005-2006 Micronas USA Inc.*/ | |
162 | ||
163 | static int write_reg(struct i2c_client *client, u8 reg, u8 value) | |
164 | { | |
165 | struct go7007 *go = i2c_get_adapdata(client->adapter); | |
41e84789 | 166 | struct go7007_usb *usb; |
b11869db | 167 | int rc; |
986ce451 | 168 | int dev_addr = client->addr << 1; /* firmware wants 8-bit address */ |
b11869db PE |
169 | u8 *buf; |
170 | ||
171 | if (go == NULL) | |
172 | return -ENODEV; | |
173 | ||
174 | if (go->status == STATUS_SHUTDOWN) | |
175 | return -EBUSY; | |
176 | ||
177 | buf = kzalloc(16, GFP_KERNEL); | |
178 | if (buf == NULL) | |
179 | return -ENOMEM; | |
180 | ||
41e84789 | 181 | usb = go->hpi_context; |
fd9a40da | 182 | if (mutex_lock_interruptible(&usb->i2c_lock) != 0) { |
5820debc | 183 | dev_info(&client->dev, "i2c lock failed\n"); |
253d3b13 | 184 | kfree(buf); |
b11869db PE |
185 | return -EINTR; |
186 | } | |
187 | rc = go7007_usb_vendor_request(go, 0x55, dev_addr, | |
188 | (reg<<8 | value), | |
189 | buf, | |
190 | 16, 1); | |
191 | ||
fd9a40da | 192 | mutex_unlock(&usb->i2c_lock); |
b11869db PE |
193 | kfree(buf); |
194 | return rc; | |
195 | } | |
196 | ||
197 | static int write_reg_fp(struct i2c_client *client, u16 addr, u16 val) | |
198 | { | |
199 | struct go7007 *go = i2c_get_adapdata(client->adapter); | |
41e84789 | 200 | struct go7007_usb *usb; |
0c07aec3 | 201 | int rc; |
b11869db PE |
202 | u8 *buf; |
203 | struct s2250 *dec = i2c_get_clientdata(client); | |
204 | ||
205 | if (go == NULL) | |
206 | return -ENODEV; | |
207 | ||
208 | if (go->status == STATUS_SHUTDOWN) | |
209 | return -EBUSY; | |
210 | ||
211 | buf = kzalloc(16, GFP_KERNEL); | |
212 | ||
213 | if (buf == NULL) | |
214 | return -ENOMEM; | |
215 | ||
216 | ||
217 | ||
218 | memset(buf, 0xcd, 6); | |
219 | ||
41e84789 | 220 | usb = go->hpi_context; |
fd9a40da | 221 | if (mutex_lock_interruptible(&usb->i2c_lock) != 0) { |
5820debc | 222 | dev_info(&client->dev, "i2c lock failed\n"); |
d66ddf21 | 223 | kfree(buf); |
b11869db PE |
224 | return -EINTR; |
225 | } | |
0c07aec3 AK |
226 | rc = go7007_usb_vendor_request(go, 0x57, addr, val, buf, 16, 1); |
227 | mutex_unlock(&usb->i2c_lock); | |
228 | if (rc < 0) { | |
d66ddf21 | 229 | kfree(buf); |
0c07aec3 | 230 | return rc; |
d66ddf21 | 231 | } |
b11869db | 232 | |
b11869db PE |
233 | if (buf[0] == 0) { |
234 | unsigned int subaddr, val_read; | |
235 | ||
236 | subaddr = (buf[4] << 8) + buf[5]; | |
237 | val_read = (buf[2] << 8) + buf[3]; | |
d66ddf21 | 238 | kfree(buf); |
b11869db | 239 | if (val_read != val) { |
5820debc YT |
240 | dev_info(&client->dev, "invalid fp write %x %x\n", |
241 | val_read, val); | |
b11869db PE |
242 | return -EFAULT; |
243 | } | |
244 | if (subaddr != addr) { | |
5820debc YT |
245 | dev_info(&client->dev, "invalid fp write addr %x %x\n", |
246 | subaddr, addr); | |
b11869db PE |
247 | return -EFAULT; |
248 | } | |
d66ddf21 PE |
249 | } else { |
250 | kfree(buf); | |
b11869db | 251 | return -EFAULT; |
d66ddf21 | 252 | } |
b11869db PE |
253 | |
254 | /* save last 12b value */ | |
255 | if (addr == 0x12b) | |
256 | dec->reg12b_val = val; | |
257 | ||
258 | return 0; | |
259 | } | |
260 | ||
047efc7d PE |
261 | static int read_reg_fp(struct i2c_client *client, u16 addr, u16 *val) |
262 | { | |
263 | struct go7007 *go = i2c_get_adapdata(client->adapter); | |
264 | struct go7007_usb *usb; | |
0c07aec3 | 265 | int rc; |
047efc7d PE |
266 | u8 *buf; |
267 | ||
268 | if (go == NULL) | |
269 | return -ENODEV; | |
270 | ||
271 | if (go->status == STATUS_SHUTDOWN) | |
272 | return -EBUSY; | |
273 | ||
274 | buf = kzalloc(16, GFP_KERNEL); | |
275 | ||
276 | if (buf == NULL) | |
277 | return -ENOMEM; | |
278 | ||
279 | ||
280 | ||
281 | memset(buf, 0xcd, 6); | |
282 | usb = go->hpi_context; | |
e49bd72f | 283 | if (mutex_lock_interruptible(&usb->i2c_lock) != 0) { |
5820debc | 284 | dev_info(&client->dev, "i2c lock failed\n"); |
047efc7d PE |
285 | kfree(buf); |
286 | return -EINTR; | |
287 | } | |
0c07aec3 AK |
288 | rc = go7007_usb_vendor_request(go, 0x58, addr, 0, buf, 16, 1); |
289 | mutex_unlock(&usb->i2c_lock); | |
290 | if (rc < 0) { | |
047efc7d | 291 | kfree(buf); |
0c07aec3 | 292 | return rc; |
047efc7d | 293 | } |
047efc7d PE |
294 | |
295 | *val = (buf[0] << 8) | buf[1]; | |
296 | kfree(buf); | |
297 | ||
298 | return 0; | |
299 | } | |
300 | ||
301 | ||
b11869db PE |
302 | static int write_regs(struct i2c_client *client, u8 *regs) |
303 | { | |
304 | int i; | |
305 | ||
306 | for (i = 0; !((regs[i] == 0x00) && (regs[i+1] == 0x00)); i += 2) { | |
307 | if (write_reg(client, regs[i], regs[i+1]) < 0) { | |
5820debc | 308 | dev_info(&client->dev, "failed\n"); |
b11869db PE |
309 | return -1; |
310 | } | |
311 | } | |
312 | return 0; | |
313 | } | |
314 | ||
315 | static int write_regs_fp(struct i2c_client *client, u16 *regs) | |
316 | { | |
317 | int i; | |
318 | ||
319 | for (i = 0; !((regs[i] == 0x00) && (regs[i+1] == 0x00)); i += 2) { | |
320 | if (write_reg_fp(client, regs[i], regs[i+1]) < 0) { | |
5820debc | 321 | dev_info(&client->dev, "failed fp\n"); |
b11869db PE |
322 | return -1; |
323 | } | |
324 | } | |
325 | return 0; | |
326 | } | |
327 | ||
328 | ||
05d76f2d PE |
329 | /* ------------------------------------------------------------------------- */ |
330 | ||
331 | static int s2250_s_video_routing(struct v4l2_subdev *sd, u32 input, u32 output, | |
332 | u32 config) | |
b11869db | 333 | { |
05d76f2d PE |
334 | struct s2250 *state = to_state(sd); |
335 | struct i2c_client *client = v4l2_get_subdevdata(sd); | |
336 | int vidsys; | |
337 | ||
338 | vidsys = (state->std == V4L2_STD_NTSC) ? 0x01 : 0x00; | |
339 | if (input == 0) { | |
340 | /* composite */ | |
341 | write_reg_fp(client, 0x20, 0x020 | vidsys); | |
342 | write_reg_fp(client, 0x21, 0x662); | |
343 | write_reg_fp(client, 0x140, 0x060); | |
344 | } else if (input == 1) { | |
345 | /* S-Video */ | |
346 | write_reg_fp(client, 0x20, 0x040 | vidsys); | |
347 | write_reg_fp(client, 0x21, 0x666); | |
348 | write_reg_fp(client, 0x140, 0x060); | |
349 | } else { | |
350 | return -EINVAL; | |
351 | } | |
352 | state->input = input; | |
353 | return 0; | |
354 | } | |
b11869db | 355 | |
05d76f2d PE |
356 | static int s2250_s_std(struct v4l2_subdev *sd, v4l2_std_id norm) |
357 | { | |
358 | struct s2250 *state = to_state(sd); | |
359 | struct i2c_client *client = v4l2_get_subdevdata(sd); | |
360 | u16 vidsource; | |
361 | ||
362 | vidsource = (state->input == 1) ? 0x040 : 0x020; | |
50deb749 | 363 | if (norm & V4L2_STD_625_50) { |
05d76f2d PE |
364 | write_regs_fp(client, vid_regs_fp); |
365 | write_regs_fp(client, vid_regs_fp_pal); | |
366 | write_reg_fp(client, 0x20, vidsource); | |
50deb749 HV |
367 | } else { |
368 | write_regs_fp(client, vid_regs_fp); | |
369 | write_reg_fp(client, 0x20, vidsource | 1); | |
b11869db | 370 | } |
05d76f2d PE |
371 | state->std = norm; |
372 | return 0; | |
373 | } | |
374 | ||
d3b2ccd9 | 375 | static int s2250_s_ctrl(struct v4l2_ctrl *ctrl) |
05d76f2d | 376 | { |
d3b2ccd9 HV |
377 | struct s2250 *state = container_of(ctrl->handler, struct s2250, hdl); |
378 | struct i2c_client *client = v4l2_get_subdevdata(&state->sd); | |
05d76f2d PE |
379 | u16 oldvalue; |
380 | ||
381 | switch (ctrl->id) { | |
382 | case V4L2_CID_BRIGHTNESS: | |
05d76f2d PE |
383 | read_reg_fp(client, VPX322_ADDR_BRIGHTNESS0, &oldvalue); |
384 | write_reg_fp(client, VPX322_ADDR_BRIGHTNESS0, | |
d3b2ccd9 | 385 | ctrl->val | (oldvalue & ~0xff)); |
05d76f2d PE |
386 | read_reg_fp(client, VPX322_ADDR_BRIGHTNESS1, &oldvalue); |
387 | write_reg_fp(client, VPX322_ADDR_BRIGHTNESS1, | |
d3b2ccd9 | 388 | ctrl->val | (oldvalue & ~0xff)); |
05d76f2d | 389 | write_reg_fp(client, 0x140, 0x60); |
b11869db | 390 | break; |
05d76f2d | 391 | case V4L2_CID_CONTRAST: |
05d76f2d PE |
392 | read_reg_fp(client, VPX322_ADDR_CONTRAST0, &oldvalue); |
393 | write_reg_fp(client, VPX322_ADDR_CONTRAST0, | |
d3b2ccd9 | 394 | ctrl->val | (oldvalue & ~0x3f)); |
05d76f2d PE |
395 | read_reg_fp(client, VPX322_ADDR_CONTRAST1, &oldvalue); |
396 | write_reg_fp(client, VPX322_ADDR_CONTRAST1, | |
d3b2ccd9 | 397 | ctrl->val | (oldvalue & ~0x3f)); |
05d76f2d | 398 | write_reg_fp(client, 0x140, 0x60); |
b11869db | 399 | break; |
05d76f2d | 400 | case V4L2_CID_SATURATION: |
d3b2ccd9 | 401 | write_reg_fp(client, VPX322_ADDR_SAT, ctrl->val); |
05d76f2d PE |
402 | break; |
403 | case V4L2_CID_HUE: | |
d3b2ccd9 | 404 | write_reg_fp(client, VPX322_ADDR_HUE, ctrl->val); |
05d76f2d PE |
405 | break; |
406 | default: | |
407 | return -EINVAL; | |
b11869db | 408 | } |
05d76f2d PE |
409 | return 0; |
410 | } | |
411 | ||
b8c75ed8 HV |
412 | static int s2250_s_mbus_fmt(struct v4l2_subdev *sd, |
413 | struct v4l2_mbus_framefmt *fmt) | |
05d76f2d PE |
414 | { |
415 | struct s2250 *state = to_state(sd); | |
416 | struct i2c_client *client = v4l2_get_subdevdata(sd); | |
417 | ||
b8c75ed8 | 418 | if (fmt->height < 640) { |
05d76f2d PE |
419 | write_reg_fp(client, 0x12b, state->reg12b_val | 0x400); |
420 | write_reg_fp(client, 0x140, 0x060); | |
421 | } else { | |
422 | write_reg_fp(client, 0x12b, state->reg12b_val & ~0x400); | |
423 | write_reg_fp(client, 0x140, 0x060); | |
b11869db | 424 | } |
05d76f2d PE |
425 | return 0; |
426 | } | |
b11869db | 427 | |
05d76f2d PE |
428 | static int s2250_s_audio_routing(struct v4l2_subdev *sd, u32 input, u32 output, |
429 | u32 config) | |
430 | { | |
431 | struct s2250 *state = to_state(sd); | |
432 | ||
433 | switch (input) { | |
434 | case 0: | |
435 | write_reg(state->audio, 0x08, 0x02); /* Line In */ | |
436 | break; | |
437 | case 1: | |
438 | write_reg(state->audio, 0x08, 0x04); /* Mic */ | |
b11869db | 439 | break; |
05d76f2d PE |
440 | case 2: |
441 | write_reg(state->audio, 0x08, 0x05); /* Mic Boost */ | |
442 | break; | |
443 | default: | |
444 | return -EINVAL; | |
b11869db | 445 | } |
05d76f2d PE |
446 | state->audio_input = input; |
447 | return 0; | |
448 | } | |
449 | ||
450 | ||
451 | static int s2250_log_status(struct v4l2_subdev *sd) | |
452 | { | |
453 | struct s2250 *state = to_state(sd); | |
454 | ||
455 | v4l2_info(sd, "Standard: %s\n", state->std == V4L2_STD_NTSC ? "NTSC" : | |
456 | state->std == V4L2_STD_PAL ? "PAL" : | |
457 | state->std == V4L2_STD_SECAM ? "SECAM" : | |
458 | "unknown"); | |
459 | v4l2_info(sd, "Input: %s\n", state->input == 0 ? "Composite" : | |
460 | state->input == 1 ? "S-video" : | |
461 | "error"); | |
05d76f2d PE |
462 | v4l2_info(sd, "Audio input: %s\n", state->audio_input == 0 ? "Line In" : |
463 | state->audio_input == 1 ? "Mic" : | |
464 | state->audio_input == 2 ? "Mic Boost" : | |
465 | "error"); | |
d3b2ccd9 | 466 | return v4l2_ctrl_subdev_log_status(sd); |
b11869db PE |
467 | } |
468 | ||
05d76f2d PE |
469 | /* --------------------------------------------------------------------------*/ |
470 | ||
d3b2ccd9 HV |
471 | static const struct v4l2_ctrl_ops s2250_ctrl_ops = { |
472 | .s_ctrl = s2250_s_ctrl, | |
473 | }; | |
474 | ||
05d76f2d PE |
475 | static const struct v4l2_subdev_core_ops s2250_core_ops = { |
476 | .log_status = s2250_log_status, | |
05d76f2d PE |
477 | .s_std = s2250_s_std, |
478 | }; | |
479 | ||
480 | static const struct v4l2_subdev_audio_ops s2250_audio_ops = { | |
481 | .s_routing = s2250_s_audio_routing, | |
482 | }; | |
483 | ||
484 | static const struct v4l2_subdev_video_ops s2250_video_ops = { | |
485 | .s_routing = s2250_s_video_routing, | |
b8c75ed8 | 486 | .s_mbus_fmt = s2250_s_mbus_fmt, |
05d76f2d PE |
487 | }; |
488 | ||
489 | static const struct v4l2_subdev_ops s2250_ops = { | |
490 | .core = &s2250_core_ops, | |
491 | .audio = &s2250_audio_ops, | |
492 | .video = &s2250_video_ops, | |
493 | }; | |
494 | ||
495 | /* --------------------------------------------------------------------------*/ | |
496 | ||
7400516a JD |
497 | static int s2250_probe(struct i2c_client *client, |
498 | const struct i2c_device_id *id) | |
b11869db | 499 | { |
7400516a JD |
500 | struct i2c_client *audio; |
501 | struct i2c_adapter *adapter = client->adapter; | |
05d76f2d PE |
502 | struct s2250 *state; |
503 | struct v4l2_subdev *sd; | |
b11869db PE |
504 | u8 *data; |
505 | struct go7007 *go = i2c_get_adapdata(adapter); | |
506 | struct go7007_usb *usb = go->hpi_context; | |
507 | ||
7400516a JD |
508 | audio = i2c_new_dummy(adapter, TLV320_ADDRESS >> 1); |
509 | if (audio == NULL) | |
b11869db | 510 | return -ENOMEM; |
b11869db | 511 | |
9b6ebf33 | 512 | state = kzalloc(sizeof(struct s2250), GFP_KERNEL); |
05d76f2d | 513 | if (state == NULL) { |
7400516a | 514 | i2c_unregister_device(audio); |
b11869db PE |
515 | return -ENOMEM; |
516 | } | |
517 | ||
05d76f2d PE |
518 | sd = &state->sd; |
519 | v4l2_i2c_subdev_init(sd, client, &s2250_ops); | |
b11869db | 520 | |
05d76f2d PE |
521 | v4l2_info(sd, "initializing %s at address 0x%x on %s\n", |
522 | "Sensoray 2250/2251", client->addr, client->adapter->name); | |
523 | ||
d3b2ccd9 HV |
524 | v4l2_ctrl_handler_init(&state->hdl, 4); |
525 | v4l2_ctrl_new_std(&state->hdl, &s2250_ctrl_ops, | |
526 | V4L2_CID_BRIGHTNESS, -128, 127, 1, 0); | |
527 | v4l2_ctrl_new_std(&state->hdl, &s2250_ctrl_ops, | |
528 | V4L2_CID_CONTRAST, 0, 0x3f, 1, 0x32); | |
529 | v4l2_ctrl_new_std(&state->hdl, &s2250_ctrl_ops, | |
530 | V4L2_CID_SATURATION, 0, 4094, 1, 2070); | |
531 | v4l2_ctrl_new_std(&state->hdl, &s2250_ctrl_ops, | |
532 | V4L2_CID_HUE, -512, 511, 1, 0); | |
533 | sd->ctrl_handler = &state->hdl; | |
534 | if (state->hdl.error) { | |
535 | int err = state->hdl.error; | |
536 | ||
537 | v4l2_ctrl_handler_free(&state->hdl); | |
538 | kfree(state); | |
539 | return err; | |
540 | } | |
541 | ||
05d76f2d PE |
542 | state->std = V4L2_STD_NTSC; |
543 | state->brightness = 50; | |
544 | state->contrast = 50; | |
545 | state->saturation = 50; | |
546 | state->hue = 0; | |
547 | state->audio = audio; | |
b11869db PE |
548 | |
549 | /* initialize the audio */ | |
7400516a | 550 | if (write_regs(audio, aud_regs) < 0) { |
5820debc | 551 | dev_err(&client->dev, "error initializing audio\n"); |
d3b2ccd9 | 552 | goto fail; |
b11869db | 553 | } |
b11869db PE |
554 | |
555 | if (write_regs(client, vid_regs) < 0) { | |
5820debc | 556 | dev_err(&client->dev, "error initializing decoder\n"); |
d3b2ccd9 | 557 | goto fail; |
b11869db PE |
558 | } |
559 | if (write_regs_fp(client, vid_regs_fp) < 0) { | |
5820debc | 560 | dev_err(&client->dev, "error initializing decoder\n"); |
d3b2ccd9 | 561 | goto fail; |
b11869db PE |
562 | } |
563 | /* set default channel */ | |
564 | /* composite */ | |
565 | write_reg_fp(client, 0x20, 0x020 | 1); | |
566 | write_reg_fp(client, 0x21, 0x662); | |
567 | write_reg_fp(client, 0x140, 0x060); | |
568 | ||
569 | /* set default audio input */ | |
05d76f2d | 570 | state->audio_input = 0; |
b11869db PE |
571 | write_reg(client, 0x08, 0x02); /* Line In */ |
572 | ||
fd9a40da | 573 | if (mutex_lock_interruptible(&usb->i2c_lock) == 0) { |
b11869db PE |
574 | data = kzalloc(16, GFP_KERNEL); |
575 | if (data != NULL) { | |
576 | int rc; | |
577 | rc = go7007_usb_vendor_request(go, 0x41, 0, 0, | |
578 | data, 16, 1); | |
579 | if (rc > 0) { | |
580 | u8 mask; | |
581 | data[0] = 0; | |
582 | mask = 1<<5; | |
583 | data[0] &= ~mask; | |
584 | data[1] |= mask; | |
585 | go7007_usb_vendor_request(go, 0x40, 0, | |
586 | (data[1]<<8) | |
587 | + data[1], | |
588 | data, 16, 0); | |
589 | } | |
590 | kfree(data); | |
591 | } | |
fd9a40da | 592 | mutex_unlock(&usb->i2c_lock); |
b11869db PE |
593 | } |
594 | ||
05d76f2d | 595 | v4l2_info(sd, "initialized successfully\n"); |
b11869db | 596 | return 0; |
d3b2ccd9 HV |
597 | |
598 | fail: | |
599 | i2c_unregister_device(audio); | |
600 | v4l2_ctrl_handler_free(&state->hdl); | |
601 | kfree(state); | |
602 | return -EIO; | |
b11869db PE |
603 | } |
604 | ||
7400516a | 605 | static int s2250_remove(struct i2c_client *client) |
b11869db | 606 | { |
d3b2ccd9 | 607 | struct s2250 *state = to_state(i2c_get_clientdata(client)); |
b11869db | 608 | |
d3b2ccd9 HV |
609 | v4l2_device_unregister_subdev(&state->sd); |
610 | v4l2_ctrl_handler_free(&state->hdl); | |
611 | kfree(state); | |
b11869db PE |
612 | return 0; |
613 | } | |
614 | ||
b76a3263 | 615 | static const struct i2c_device_id s2250_id[] = { |
832b6a89 | 616 | { "s2250", 0 }, |
7400516a JD |
617 | { } |
618 | }; | |
832b6a89 PE |
619 | MODULE_DEVICE_TABLE(i2c, s2250_id); |
620 | ||
22ac5f67 HV |
621 | static struct i2c_driver s2250_driver = { |
622 | .driver = { | |
623 | .owner = THIS_MODULE, | |
624 | .name = "s2250", | |
625 | }, | |
626 | .probe = s2250_probe, | |
627 | .remove = s2250_remove, | |
628 | .id_table = s2250_id, | |
b11869db | 629 | }; |
22ac5f67 | 630 | |
74ffbf86 | 631 | module_i2c_driver(s2250_driver); |