aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDwaine Garden <DwaineGarden@rogers.com>2005-11-09 00:37:34 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2005-11-09 10:56:18 -0500
commit340622c5a9028d70b1238ecafb463125277a30eb (patch)
tree7da21022415d720e5b5a6c5bc17a67c5f826cc4f
parent78f82405ace9415e72a87b16c195675f053381f1 (diff)
[PATCH] v4l: 789: added support for saa7113
- Added support for saa7113. Signed-off-by: Dwaine Garden <DwaineGarden@rogers.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@brturbo.com.br> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--drivers/media/video/saa711x.c597
1 files changed, 597 insertions, 0 deletions
diff --git a/drivers/media/video/saa711x.c b/drivers/media/video/saa711x.c
new file mode 100644
index 000000000000..37653ee87235
--- /dev/null
+++ b/drivers/media/video/saa711x.c
@@ -0,0 +1,597 @@
1/*
2 * saa7111 - Philips SAA7113A video decoder driver version 0.0.3
3 *
4 * Copyright (C) 1998 Dave Perks <dperks@ibm.net>
5 *
6 * Slight changes for video timing and attachment output by
7 * Wolfgang Scherr <scherr@net4you.net>
8 *
9 * Changes by Ronald Bultje <rbultje@ronald.bitfreak.net>
10 * - moved over to linux>=2.4.x i2c protocol (1/1/2003)
11 *
12 * Changes by Michael Hunold <michael@mihu.de>
13 * - implemented DECODER_SET_GPIO, DECODER_INIT, DECODER_SET_VBI_BYPASS
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 */
29
30#include <linux/module.h>
31#include <linux/init.h>
32#include <linux/delay.h>
33#include <linux/errno.h>
34#include <linux/fs.h>
35#include <linux/kernel.h>
36#include <linux/major.h>
37#include <linux/slab.h>
38#include <linux/mm.h>
39#include <linux/pci.h>
40#include <linux/signal.h>
41#include <asm/io.h>
42#include <asm/pgtable.h>
43#include <asm/page.h>
44#include <linux/sched.h>
45#include <asm/segment.h>
46#include <linux/types.h>
47#include <asm/uaccess.h>
48#include <linux/videodev.h>
49
50MODULE_DESCRIPTION("Philips SAA7113 video decoder driver");
51MODULE_AUTHOR("Dave Perks, Jose Ignacio Gijon, Joerg Heckenbach, Mark McClelland, Dwaine Garden");
52MODULE_LICENSE("GPL");
53
54#include <linux/i2c.h>
55#include <linux/i2c-dev.h>
56
57#define I2C_NAME(s) (s)->name
58
59#include <linux/video_decoder.h>
60
61static int debug = 0;
62MODULE_PARM(debug, "i");
63MODULE_PARM_DESC(debug, " Set the default Debug level. Default: 0 (Off) - (0-1)");
64
65
66#define dprintk(num, format, args...) \
67 do { \
68 if (debug >= num) \
69 printk(format , ##args); \
70 } while (0)
71
72/* ----------------------------------------------------------------------- */
73
74struct saa7113 {
75 unsigned char reg[32];
76
77 int norm;
78 int input;
79 int enable;
80 int bright;
81 int contrast;
82 int hue;
83 int sat;
84};
85
86#define I2C_SAA7113 0x4A
87
88/* ----------------------------------------------------------------------- */
89
90static inline int
91saa7113_write (struct i2c_client *client,
92 u8 reg,
93 u8 value)
94{
95 struct saa7113 *decoder = i2c_get_clientdata(client);
96
97 decoder->reg[reg] = value;
98 return i2c_smbus_write_byte_data(client, reg, value);
99}
100
101static int
102saa7113_write_block (struct i2c_client *client,
103 const u8 *data,
104 unsigned int len)
105{
106 int ret = -1;
107 u8 reg;
108
109 /* the saa7113 has an autoincrement function, use it if
110 * the adapter understands raw I2C */
111 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
112 /* do raw I2C, not smbus compatible */
113 struct saa7113 *decoder = i2c_get_clientdata(client);
114 struct i2c_msg msg;
115 u8 block_data[32];
116
117 msg.addr = client->addr;
118 msg.flags = 0;
119 while (len >= 2) {
120 msg.buf = (char *) block_data;
121 msg.len = 0;
122 block_data[msg.len++] = reg = data[0];
123 do {
124 block_data[msg.len++] =
125 decoder->reg[reg++] = data[1];
126 len -= 2;
127 data += 2;
128 } while (len >= 2 && data[0] == reg &&
129 msg.len < 32);
130 if ((ret = i2c_transfer(client->adapter,
131 &msg, 1)) < 0)
132 break;
133 }
134 } else {
135 /* do some slow I2C emulation kind of thing */
136 while (len >= 2) {
137 reg = *data++;
138 if ((ret = saa7113_write(client, reg,
139 *data++)) < 0)
140 break;
141 len -= 2;
142 }
143 }
144
145 return ret;
146}
147
148static int
149saa7113_init_decoder (struct i2c_client *client,
150 struct video_decoder_init *init)
151{
152 return saa7113_write_block(client, init->data, init->len);
153}
154
155static inline int
156saa7113_read (struct i2c_client *client,
157 u8 reg)
158{
159 return i2c_smbus_read_byte_data(client, reg);
160}
161
162/* ----------------------------------------------------------------------- */
163
164static const unsigned char saa7113_i2c_init[] = {
165 0x00, 0x00, /* PH7113_CHIP_VERSION 00 - ID byte */
166 0x01, 0x08, /* PH7113_INCREMENT_DELAY - (1) (1) (1) (1) IDEL3 IDEL2 IDELL1 IDEL0 */
167 0x02, 0xc0, /* PH7113_ANALOG_INPUT_CONTR_1 - FUSE1 FUSE0 GUDL1 GUDL0 MODE3 MODE2 MODE1 MODE0 */
168 0x03, 0x23, /* PH7113_ANALOG_INPUT_CONTR_2 - (1) HLNRS VBSL WPOFF HOLDG GAFIX GAI28 GAI18 */
169 0x04, 0x00, /* PH7113_ANALOG_INPUT_CONTR_3 - GAI17 GAI16 GAI15 GAI14 GAI13 GAI12 GAI11 GAI10 */
170 0x05, 0x00, /* PH7113_ANALOG_INPUT_CONTR_4 - GAI27 GAI26 GAI25 GAI24 GAI23 GAI22 GAI21 GAI20 */
171 0x06, 0xeb, /* PH7113_HORIZONTAL_SYNC_START - HSB7 HSB6 HSB5 HSB4 HSB3 HSB2 HSB1 HSB0 */
172 0x07, 0xe0, /* PH7113_HORIZONTAL_SYNC_STOP - HSS7 HSS6 HSS5 HSS4 HSS3 HSS2 HSS1 HSS0 */
173 0x08, 0x88, /* PH7113_SYNC_CONTROL - AUFD FSEL FOET HTC1 HTC0 HPLL VNOI1 VNOI0 */
174 0x09, 0x00, /* PH7113_LUMINANCE_CONTROL - BYPS PREF BPSS1 BPSS0 VBLB UPTCV APER1 APER0 */
175 0x0a, 0x80, /* PH7113_LUMINANCE_BRIGHTNESS - BRIG7 BRIG6 BRIG5 BRIG4 BRIG3 BRIG2 BRIG1 BRIG0 */
176 0x0b, 0x47, /* PH7113_LUMINANCE_CONTRAST - CONT7 CONT6 CONT5 CONT4 CONT3 CONT2 CONT1 CONT0 */
177 0x0c, 0x40, /* PH7113_CHROMA_SATURATION - SATN7 SATN6 SATN5 SATN4 SATN3 SATN2 SATN1 SATN0 */
178 0x0d, 0x00, /* PH7113_CHROMA_HUE_CONTROL - HUEC7 HUEC6 HUEC5 HUEC4 HUEC3 HUEC2 HUEC1 HUEC0 */
179 0x0e, 0x01, /* PH7113_CHROMA_CONTROL - CDTO CSTD2 CSTD1 CSTD0 DCCF FCTC CHBW1 CHBW0 */
180 0x0f, 0xaa, /* PH7113_CHROMA_GAIN_CONTROL - ACGC CGAIN6 CGAIN5 CGAIN4 CGAIN3 CGAIN2 CGAIN1 CGAIN0 */
181 0x10, 0x00, /* PH7113_FORMAT_DELAY_CONTROL - OFTS1 OFTS0 HDEL1 HDEL0 VRLN YDEL2 YDEL1 YDEL0 */
182 0x11, 0x1C, /* PH7113_OUTPUT_CONTROL_1 - GPSW1 CM99 GPSW0 HLSEL OEYC OERT VIPB COLO */
183 0x12, 0x01, /* PH7113_OUTPUT_CONTROL_2 - RTSE13 RTSE12 RTSE11 RTSE10 RTSE03 RTSE02 RTSE01 RTSE00 */
184 0x13, 0x00, /* PH7113_OUTPUT_CONTROL_3 - ADLSB (1) (1) OLDSB FIDP (1) AOSL1 AOSL0 */
185 0x14, 0x00, /* RESERVED 14 - (1) (1) (1) (1) (1) (1) (1) (1) */
186 0x15, 0x00, /* PH7113_V_GATE1_START - VSTA7 VSTA6 VSTA5 VSTA4 VSTA3 VSTA2 VSTA1 VSTA0 */
187 0x16, 0x00, /* PH7113_V_GATE1_STOP - VSTO7 VSTO6 VSTO5 VSTO4 VSTO3 VSTO2 VSTO1 VSTO0 */
188 0x17, 0x00, /* PH7113_V_GATE1_MSB - (1) (1) (1) (1) (1) (1) VSTO8 VSTA8 */
189};
190
191static int
192saa7113_command (struct i2c_client *client,
193 unsigned int cmd,
194 void *arg)
195{
196 struct saa7113 *decoder = i2c_get_clientdata(client);
197
198 switch (cmd) {
199
200 case 0:
201 case DECODER_INIT:
202 {
203 struct video_decoder_init *init = arg;
204 if (NULL != init)
205 return saa7113_init_decoder(client, init);
206 else {
207 struct video_decoder_init vdi;
208 vdi.data = saa7113_i2c_init;
209 vdi.len = sizeof(saa7113_i2c_init);
210 return saa7113_init_decoder(client, &vdi);
211 }
212 }
213
214 case DECODER_DUMP:
215 {
216 int i;
217
218 for (i = 0; i < 32; i += 16) {
219 int j;
220
221 printk(KERN_DEBUG "%s: %03x", I2C_NAME(client), i);
222 for (j = 0; j < 16; ++j) {
223 printk(" %02x",
224 saa7113_read(client, i + j));
225 }
226 printk("\n");
227 }
228 }
229 break;
230
231 case DECODER_GET_CAPABILITIES:
232 {
233 struct video_decoder_capability *cap = arg;
234
235 cap->flags = VIDEO_DECODER_PAL |
236 VIDEO_DECODER_NTSC |
237 VIDEO_DECODER_SECAM |
238 VIDEO_DECODER_AUTO |
239 VIDEO_DECODER_CCIR;
240 cap->inputs = 8;
241 cap->outputs = 1;
242 }
243 break;
244
245 case DECODER_GET_STATUS:
246 {
247 int *iarg = arg;
248 int status;
249 int res;
250
251 status = saa7113_read(client, 0x1f);
252 dprintk(1, KERN_DEBUG "%s status: 0x%02x\n", I2C_NAME(client),
253 status);
254 res = 0;
255 if ((status & (1 << 6)) == 0) {
256 res |= DECODER_STATUS_GOOD;
257 }
258 switch (decoder->norm) {
259 case VIDEO_MODE_NTSC:
260 res |= DECODER_STATUS_NTSC;
261 break;
262 case VIDEO_MODE_PAL:
263 res |= DECODER_STATUS_PAL;
264 break;
265 case VIDEO_MODE_SECAM:
266 res |= DECODER_STATUS_SECAM;
267 break;
268 default:
269 case VIDEO_MODE_AUTO:
270 if ((status & (1 << 5)) != 0) {
271 res |= DECODER_STATUS_NTSC;
272 } else {
273 res |= DECODER_STATUS_PAL;
274 }
275 break;
276 }
277 if ((status & (1 << 0)) != 0) {
278 res |= DECODER_STATUS_COLOR;
279 }
280 *iarg = res;
281 }
282 break;
283
284 case DECODER_SET_GPIO:
285 {
286 int *iarg = arg;
287 if (0 != *iarg) {
288 saa7113_write(client, 0x11,
289 (decoder->reg[0x11] | 0x80));
290 } else {
291 saa7113_write(client, 0x11,
292 (decoder->reg[0x11] & 0x7f));
293 }
294 break;
295 }
296
297 case DECODER_SET_VBI_BYPASS:
298 {
299 int *iarg = arg;
300 if (0 != *iarg) {
301 saa7113_write(client, 0x13,
302 (decoder->reg[0x13] & 0xf0) | 0x0a);
303 } else {
304 saa7113_write(client, 0x13,
305 (decoder->reg[0x13] & 0xf0));
306 }
307 break;
308 }
309
310 case DECODER_SET_NORM:
311 {
312 int *iarg = arg;
313
314 switch (*iarg) {
315
316 case VIDEO_MODE_NTSC:
317 saa7113_write(client, 0x08,
318 (decoder->reg[0x08] & 0x3f) | 0x40);
319 saa7113_write(client, 0x0e,
320 (decoder->reg[0x0e] & 0x8f));
321 break;
322
323 case VIDEO_MODE_PAL:
324 saa7113_write(client, 0x08,
325 (decoder->reg[0x08] & 0x3f) | 0x00);
326 saa7113_write(client, 0x0e,
327 (decoder->reg[0x0e] & 0x8f));
328 break;
329
330 case VIDEO_MODE_SECAM:
331 saa7113_write(client, 0x08,
332 (decoder->reg[0x0e] & 0x3f) | 0x00);
333 saa7113_write(client, 0x0e,
334 (decoder->reg[0x0e] & 0x8f) | 0x50);
335 break;
336
337 case VIDEO_MODE_AUTO:
338 saa7113_write(client, 0x08,
339 (decoder->reg[0x08] & 0x3f) | 0x80);
340 saa7113_write(client, 0x0e,
341 (decoder->reg[0x0e] & 0x8f));
342 break;
343
344 default:
345 return -EINVAL;
346
347 }
348 decoder->norm = *iarg;
349 }
350 break;
351
352 case DECODER_SET_INPUT:
353 {
354 int *iarg = arg;
355 if (*iarg < 0 || *iarg > 9) {
356 return -EINVAL;
357 }
358 if (decoder->input != *iarg) {
359 decoder->input = *iarg;
360 /* select mode */
361 saa7113_write(client, 0x02,
362 (decoder->reg[0x02] & 0xf0) | decoder->input);
363 /* bypass chrominance trap for modes 4..7 */
364 saa7113_write(client, 0x09,
365 (decoder->reg[0x09] & 0x7f) | ((decoder->input > 3) ? 0x80 : 0));
366 }
367 }
368 break;
369
370 case DECODER_SET_OUTPUT:
371 {
372 int *iarg = arg;
373
374 /* not much choice of outputs */
375 if (*iarg != 0) {
376 return -EINVAL;
377 }
378 }
379 break;
380
381 case DECODER_ENABLE_OUTPUT:
382 {
383 int *iarg = arg;
384 int enable = (*iarg != 0);
385
386 if (decoder->enable != enable) {
387 decoder->enable = enable;
388
389 /* RJ: If output should be disabled (for
390 * playing videos), we also need a open PLL.
391 * The input is set to 0 (where no input
392 * source is connected), although this
393 * is not necessary.
394 *
395 * If output should be enabled, we have to
396 * reverse the above.
397 */
398
399 if (decoder->enable) {
400 saa7113_write(client, 0x02,
401 (decoder->
402 reg[0x02] & 0xf8) |
403 decoder->input);
404 saa7113_write(client, 0x08,
405 (decoder->reg[0x08] & 0xfb));
406 saa7113_write(client, 0x11,
407 (decoder->
408 reg[0x11] & 0xf3) | 0x0c);
409 } else {
410 saa7113_write(client, 0x02,
411 (decoder->reg[0x02] & 0xf8));
412 saa7113_write(client, 0x08,
413 (decoder->
414 reg[0x08] & 0xfb) | 0x04);
415 saa7113_write(client, 0x11,
416 (decoder->reg[0x11] & 0xf3));
417 }
418 }
419 }
420 break;
421
422 case DECODER_SET_PICTURE:
423 {
424 struct video_picture *pic = arg;
425
426 if (decoder->bright != pic->brightness) {
427 /* We want 0 to 255 we get 0-65535 */
428 decoder->bright = pic->brightness;
429 saa7113_write(client, 0x0a, decoder->bright >> 8);
430 }
431 if (decoder->contrast != pic->contrast) {
432 /* We want 0 to 127 we get 0-65535 */
433 decoder->contrast = pic->contrast;
434 saa7113_write(client, 0x0b,
435 decoder->contrast >> 9);
436 }
437 if (decoder->sat != pic->colour) {
438 /* We want 0 to 127 we get 0-65535 */
439 decoder->sat = pic->colour;
440 saa7113_write(client, 0x0c, decoder->sat >> 9);
441 }
442 if (decoder->hue != pic->hue) {
443 /* We want -128 to 127 we get 0-65535 */
444 decoder->hue = pic->hue;
445 saa7113_write(client, 0x0d,
446 (decoder->hue - 32768) >> 8);
447 }
448 }
449 break;
450
451 default:
452 return -EINVAL;
453 }
454
455 return 0;
456}
457
458/* ----------------------------------------------------------------------- */
459
460/*
461 * Generic i2c probe
462 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1'
463 */
464
465/* standard i2c insmod options */
466static unsigned short normal_i2c[] = {
467 I2C_SAA7113>>1, /* saa7113 */
468 I2C_CLIENT_END
469};
470
471I2C_CLIENT_INSMOD;
472
473
474static struct i2c_driver i2c_driver_saa7113;
475
476static int
477saa7113_detect_client (struct i2c_adapter *adapter,
478 int address,
479 int kind)
480{
481 int i;
482 struct i2c_client *client;
483 struct saa7113 *decoder;
484 struct video_decoder_init vdi;
485
486 dprintk(1,
487 KERN_INFO
488 "saa7113.c: detecting saa7113 client on address 0x%x\n",
489 address << 1);
490
491 /* Check if the adapter supports the needed features */
492 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
493 return 0;
494
495 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
496 if (client == 0)
497 return -ENOMEM;
498 memset(client, 0, sizeof(struct i2c_client));
499 client->addr = address;
500 client->adapter = adapter;
501 client->driver = &i2c_driver_saa7113;
502 client->flags = I2C_CLIENT_ALLOW_USE;
503 strlcpy(I2C_NAME(client), "saa7113", sizeof(I2C_NAME(client)));
504 decoder = kmalloc(sizeof(struct saa7113), GFP_KERNEL);
505 if (decoder == NULL) {
506 kfree(client);
507 return -ENOMEM;
508 }
509 memset(decoder, 0, sizeof(struct saa7113));
510 decoder->norm = VIDEO_MODE_NTSC;
511 decoder->input = 0;
512 decoder->enable = 1;
513 decoder->bright = 32768;
514 decoder->contrast = 32768;
515 decoder->hue = 32768;
516 decoder->sat = 32768;
517 i2c_set_clientdata(client, decoder);
518
519 i = i2c_attach_client(client);
520 if (i) {
521 kfree(client);
522 kfree(decoder);
523 return i;
524 }
525
526 vdi.data = saa7113_i2c_init;
527 vdi.len = sizeof(saa7113_i2c_init);
528 i = saa7113_init_decoder(client, &vdi);
529 if (i < 0) {
530 dprintk(1, KERN_ERR "%s_attach error: init status %d\n",
531 I2C_NAME(client), i);
532 } else {
533 dprintk(1,
534 KERN_INFO
535 "%s_attach: chip version %x at address 0x%x\n",
536 I2C_NAME(client), saa7113_read(client, 0x00) >> 4,
537 client->addr << 1);
538 }
539
540 return 0;
541}
542
543static int
544saa7113_attach_adapter (struct i2c_adapter *adapter)
545{
546 dprintk(1,
547 KERN_INFO
548 "saa7113.c: starting probe for adapter %s (0x%x)\n",
549 I2C_NAME(adapter), adapter->id);
550 return i2c_probe(adapter, &addr_data, &saa7113_detect_client);
551}
552
553static int
554saa7113_detach_client (struct i2c_client *client)
555{
556 struct saa7113 *decoder = i2c_get_clientdata(client);
557 int err;
558
559 err = i2c_detach_client(client);
560 if (err) {
561 return err;
562 }
563
564 kfree(decoder);
565 kfree(client);
566
567 return 0;
568}
569
570/* ----------------------------------------------------------------------- */
571
572static struct i2c_driver i2c_driver_saa7113 = {
573 .owner = THIS_MODULE,
574 .name = "saa7113",
575
576 .id = I2C_DRIVERID_SAA7113,
577 .flags = I2C_DF_NOTIFY,
578
579 .attach_adapter = saa7113_attach_adapter,
580 .detach_client = saa7113_detach_client,
581 .command = saa7113_command,
582};
583
584static int __init
585saa7113_init (void)
586{
587 return i2c_add_driver(&i2c_driver_saa7113);
588}
589
590static void __exit
591saa7113_exit (void)
592{
593 i2c_del_driver(&i2c_driver_saa7113);
594}
595
596module_init(saa7113_init);
597module_exit(saa7113_exit);