aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/saa7114.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/saa7114.c')
-rw-r--r--drivers/media/video/saa7114.c364
1 files changed, 108 insertions, 256 deletions
diff --git a/drivers/media/video/saa7114.c b/drivers/media/video/saa7114.c
index e79075533beb..7ca709fda5f4 100644
--- a/drivers/media/video/saa7114.c
+++ b/drivers/media/video/saa7114.c
@@ -29,43 +29,24 @@
29 */ 29 */
30 30
31#include <linux/module.h> 31#include <linux/module.h>
32#include <linux/init.h>
33#include <linux/delay.h>
34#include <linux/errno.h>
35#include <linux/fs.h>
36#include <linux/kernel.h>
37#include <linux/major.h>
38#include <linux/slab.h>
39#include <linux/mm.h>
40#include <linux/signal.h>
41#include <linux/types.h> 32#include <linux/types.h>
42#include <linux/i2c.h> 33#include <linux/ioctl.h>
43#include <asm/io.h>
44#include <asm/pgtable.h>
45#include <asm/page.h>
46#include <asm/uaccess.h> 34#include <asm/uaccess.h>
47 35#include <linux/i2c.h>
36#include <linux/i2c-id.h>
48#include <linux/videodev.h> 37#include <linux/videodev.h>
49#include <linux/video_decoder.h> 38#include <linux/video_decoder.h>
39#include <media/v4l2-common.h>
40#include <media/v4l2-i2c-drv-legacy.h>
50 41
51MODULE_DESCRIPTION("Philips SAA7114H video decoder driver"); 42MODULE_DESCRIPTION("Philips SAA7114H video decoder driver");
52MODULE_AUTHOR("Maxim Yevtyushkin"); 43MODULE_AUTHOR("Maxim Yevtyushkin");
53MODULE_LICENSE("GPL"); 44MODULE_LICENSE("GPL");
54 45
55
56#define I2C_NAME(x) (x)->name
57
58
59static int debug; 46static int debug;
60module_param(debug, int, 0); 47module_param(debug, int, 0);
61MODULE_PARM_DESC(debug, "Debug level (0-1)"); 48MODULE_PARM_DESC(debug, "Debug level (0-1)");
62 49
63#define dprintk(num, format, args...) \
64 do { \
65 if (debug >= num) \
66 printk(format, ##args); \
67 } while (0)
68
69/* ----------------------------------------------------------------------- */ 50/* ----------------------------------------------------------------------- */
70 51
71struct saa7114 { 52struct saa7114 {
@@ -81,9 +62,6 @@ struct saa7114 {
81 int playback; 62 int playback;
82}; 63};
83 64
84#define I2C_SAA7114 0x42
85#define I2C_SAA7114A 0x40
86
87#define I2C_DELAY 10 65#define I2C_DELAY 10
88 66
89 67
@@ -129,18 +107,12 @@ struct saa7114 {
129 107
130/* ----------------------------------------------------------------------- */ 108/* ----------------------------------------------------------------------- */
131 109
132static inline int 110static inline int saa7114_write(struct i2c_client *client, u8 reg, u8 value)
133saa7114_write (struct i2c_client *client,
134 u8 reg,
135 u8 value)
136{ 111{
137 return i2c_smbus_write_byte_data(client, reg, value); 112 return i2c_smbus_write_byte_data(client, reg, value);
138} 113}
139 114
140static int 115static int saa7114_write_block(struct i2c_client *client, const u8 *data, unsigned int len)
141saa7114_write_block (struct i2c_client *client,
142 const u8 *data,
143 unsigned int len)
144{ 116{
145 int ret = -1; 117 int ret = -1;
146 u8 reg; 118 u8 reg;
@@ -160,18 +132,17 @@ saa7114_write_block (struct i2c_client *client,
160 reg++; 132 reg++;
161 len -= 2; 133 len -= 2;
162 data += 2; 134 data += 2;
163 } while (len >= 2 && data[0] == reg && 135 } while (len >= 2 && data[0] == reg && block_len < 32);
164 block_len < 32); 136 ret = i2c_master_send(client, block_data, block_len);
165 if ((ret = i2c_master_send(client, block_data, 137 if (ret < 0)
166 block_len)) < 0)
167 break; 138 break;
168 } 139 }
169 } else { 140 } else {
170 /* do some slow I2C emulation kind of thing */ 141 /* do some slow I2C emulation kind of thing */
171 while (len >= 2) { 142 while (len >= 2) {
172 reg = *data++; 143 reg = *data++;
173 if ((ret = saa7114_write(client, reg, 144 ret = saa7114_write(client, reg, *data++);
174 *data++)) < 0) 145 if (ret < 0)
175 break; 146 break;
176 len -= 2; 147 len -= 2;
177 } 148 }
@@ -180,9 +151,7 @@ saa7114_write_block (struct i2c_client *client,
180 return ret; 151 return ret;
181} 152}
182 153
183static inline int 154static inline int saa7114_read(struct i2c_client *client, u8 reg)
184saa7114_read (struct i2c_client *client,
185 u8 reg)
186{ 155{
187 return i2c_smbus_read_byte_data(client, reg); 156 return i2c_smbus_read_byte_data(client, reg);
188} 157}
@@ -452,15 +421,11 @@ static const unsigned char init[] = {
452 0xef, 0x00 421 0xef, 0x00
453}; 422};
454 423
455static int 424static int saa7114_command(struct i2c_client *client, unsigned cmd, void *arg)
456saa7114_command (struct i2c_client *client,
457 unsigned int cmd,
458 void *arg)
459{ 425{
460 struct saa7114 *decoder = i2c_get_clientdata(client); 426 struct saa7114 *decoder = i2c_get_clientdata(client);
461 427
462 switch (cmd) { 428 switch (cmd) {
463
464 case 0: 429 case 0:
465 //dprintk(1, KERN_INFO "%s: writing init\n", I2C_NAME(client)); 430 //dprintk(1, KERN_INFO "%s: writing init\n", I2C_NAME(client));
466 //saa7114_write_block(client, init, sizeof(init)); 431 //saa7114_write_block(client, init, sizeof(init));
@@ -470,27 +435,28 @@ saa7114_command (struct i2c_client *client,
470 { 435 {
471 int i; 436 int i;
472 437
473 dprintk(1, KERN_INFO "%s: decoder dump\n", I2C_NAME(client)); 438 if (!debug)
439 break;
440 v4l_info(client, "decoder dump\n");
474 441
475 for (i = 0; i < 32; i += 16) { 442 for (i = 0; i < 32; i += 16) {
476 int j; 443 int j;
477 444
478 printk(KERN_DEBUG "%s: %03x", I2C_NAME(client), i); 445 v4l_info(client, "%03x", i);
479 for (j = 0; j < 16; ++j) { 446 for (j = 0; j < 16; ++j) {
480 printk(" %02x", 447 printk(KERN_CONT " %02x",
481 saa7114_read(client, i + j)); 448 saa7114_read(client, i + j));
482 } 449 }
483 printk("\n"); 450 printk(KERN_CONT "\n");
484 } 451 }
485 }
486 break; 452 break;
453 }
487 454
488 case DECODER_GET_CAPABILITIES: 455 case DECODER_GET_CAPABILITIES:
489 { 456 {
490 struct video_decoder_capability *cap = arg; 457 struct video_decoder_capability *cap = arg;
491 458
492 dprintk(1, KERN_DEBUG "%s: decoder get capabilities\n", 459 v4l_dbg(1, debug, client, "get capabilities\n");
493 I2C_NAME(client));
494 460
495 cap->flags = VIDEO_DECODER_PAL | 461 cap->flags = VIDEO_DECODER_PAL |
496 VIDEO_DECODER_NTSC | 462 VIDEO_DECODER_NTSC |
@@ -498,8 +464,8 @@ saa7114_command (struct i2c_client *client,
498 VIDEO_DECODER_CCIR; 464 VIDEO_DECODER_CCIR;
499 cap->inputs = 8; 465 cap->inputs = 8;
500 cap->outputs = 1; 466 cap->outputs = 1;
501 }
502 break; 467 break;
468 }
503 469
504 case DECODER_GET_STATUS: 470 case DECODER_GET_STATUS:
505 { 471 {
@@ -509,8 +475,7 @@ saa7114_command (struct i2c_client *client,
509 475
510 status = saa7114_read(client, 0x1f); 476 status = saa7114_read(client, 0x1f);
511 477
512 dprintk(1, KERN_DEBUG "%s status: 0x%02x\n", I2C_NAME(client), 478 v4l_dbg(1, debug, client, "status: 0x%02x\n", status);
513 status);
514 res = 0; 479 res = 0;
515 if ((status & (1 << 6)) == 0) { 480 if ((status & (1 << 6)) == 0) {
516 res |= DECODER_STATUS_GOOD; 481 res |= DECODER_STATUS_GOOD;
@@ -538,8 +503,8 @@ saa7114_command (struct i2c_client *client,
538 res |= DECODER_STATUS_COLOR; 503 res |= DECODER_STATUS_COLOR;
539 } 504 }
540 *iarg = res; 505 *iarg = res;
541 }
542 break; 506 break;
507 }
543 508
544 case DECODER_SET_NORM: 509 case DECODER_SET_NORM:
545 { 510 {
@@ -547,12 +512,11 @@ saa7114_command (struct i2c_client *client,
547 512
548 short int hoff = 0, voff = 0, w = 0, h = 0; 513 short int hoff = 0, voff = 0, w = 0, h = 0;
549 514
550 dprintk(1, KERN_DEBUG "%s: decoder set norm ", 515 v4l_dbg(1, debug, client, "set norm\n");
551 I2C_NAME(client));
552 switch (*iarg) {
553 516
517 switch (*iarg) {
554 case VIDEO_MODE_NTSC: 518 case VIDEO_MODE_NTSC:
555 dprintk(1, "NTSC\n"); 519 v4l_dbg(1, debug, client, "NTSC\n");
556 decoder->reg[REG_ADDR(0x06)] = 520 decoder->reg[REG_ADDR(0x06)] =
557 SAA_7114_NTSC_HSYNC_START; 521 SAA_7114_NTSC_HSYNC_START;
558 decoder->reg[REG_ADDR(0x07)] = 522 decoder->reg[REG_ADDR(0x07)] =
@@ -571,7 +535,7 @@ saa7114_command (struct i2c_client *client,
571 break; 535 break;
572 536
573 case VIDEO_MODE_PAL: 537 case VIDEO_MODE_PAL:
574 dprintk(1, "PAL\n"); 538 v4l_dbg(1, debug, client, "PAL\n");
575 decoder->reg[REG_ADDR(0x06)] = 539 decoder->reg[REG_ADDR(0x06)] =
576 SAA_7114_PAL_HSYNC_START; 540 SAA_7114_PAL_HSYNC_START;
577 decoder->reg[REG_ADDR(0x07)] = 541 decoder->reg[REG_ADDR(0x07)] =
@@ -590,9 +554,8 @@ saa7114_command (struct i2c_client *client,
590 break; 554 break;
591 555
592 default: 556 default:
593 dprintk(1, " Unknown video mode!!!\n"); 557 v4l_dbg(1, debug, client, "Unknown video mode\n");
594 return -EINVAL; 558 return -EINVAL;
595
596 } 559 }
597 560
598 561
@@ -644,22 +607,20 @@ saa7114_command (struct i2c_client *client,
644 saa7114_write(client, 0x80, 0x36); // i-port and scaler back end clock selection 607 saa7114_write(client, 0x80, 0x36); // i-port and scaler back end clock selection
645 608
646 decoder->norm = *iarg; 609 decoder->norm = *iarg;
647 }
648 break; 610 break;
611 }
649 612
650 case DECODER_SET_INPUT: 613 case DECODER_SET_INPUT:
651 { 614 {
652 int *iarg = arg; 615 int *iarg = arg;
653 616
654 dprintk(1, KERN_DEBUG "%s: decoder set input (%d)\n", 617 v4l_dbg(1, debug, client, "set input (%d)\n", *iarg);
655 I2C_NAME(client), *iarg);
656 if (*iarg < 0 || *iarg > 7) { 618 if (*iarg < 0 || *iarg > 7) {
657 return -EINVAL; 619 return -EINVAL;
658 } 620 }
659 621
660 if (decoder->input != *iarg) { 622 if (decoder->input != *iarg) {
661 dprintk(1, KERN_DEBUG "%s: now setting %s input\n", 623 v4l_dbg(1, debug, client, "now setting %s input\n",
662 I2C_NAME(client),
663 *iarg >= 6 ? "S-Video" : "Composite"); 624 *iarg >= 6 ? "S-Video" : "Composite");
664 decoder->input = *iarg; 625 decoder->input = *iarg;
665 626
@@ -690,30 +651,29 @@ saa7114_command (struct i2c_client *client,
690 saa7114_write(client, 0x0e, 651 saa7114_write(client, 0x0e,
691 decoder->reg[REG_ADDR(0x0e)]); 652 decoder->reg[REG_ADDR(0x0e)]);
692 } 653 }
693 }
694 break; 654 break;
655 }
695 656
696 case DECODER_SET_OUTPUT: 657 case DECODER_SET_OUTPUT:
697 { 658 {
698 int *iarg = arg; 659 int *iarg = arg;
699 660
700 dprintk(1, KERN_DEBUG "%s: decoder set output\n", 661 v4l_dbg(1, debug, client, "set output\n");
701 I2C_NAME(client));
702 662
703 /* not much choice of outputs */ 663 /* not much choice of outputs */
704 if (*iarg != 0) { 664 if (*iarg != 0) {
705 return -EINVAL; 665 return -EINVAL;
706 } 666 }
707 }
708 break; 667 break;
668 }
709 669
710 case DECODER_ENABLE_OUTPUT: 670 case DECODER_ENABLE_OUTPUT:
711 { 671 {
712 int *iarg = arg; 672 int *iarg = arg;
713 int enable = (*iarg != 0); 673 int enable = (*iarg != 0);
714 674
715 dprintk(1, KERN_DEBUG "%s: decoder %s output\n", 675 v4l_dbg(1, debug, client, "%s output\n",
716 I2C_NAME(client), enable ? "enable" : "disable"); 676 enable ? "enable" : "disable");
717 677
718 decoder->playback = !enable; 678 decoder->playback = !enable;
719 679
@@ -754,18 +714,16 @@ saa7114_command (struct i2c_client *client,
754 saa7114_write(client, 0x80, 0x36); 714 saa7114_write(client, 0x80, 0x36);
755 715
756 } 716 }
757 }
758 break; 717 break;
718 }
759 719
760 case DECODER_SET_PICTURE: 720 case DECODER_SET_PICTURE:
761 { 721 {
762 struct video_picture *pic = arg; 722 struct video_picture *pic = arg;
763 723
764 dprintk(1, 724 v4l_dbg(1, debug, client,
765 KERN_DEBUG 725 "decoder set picture bright=%d contrast=%d saturation=%d hue=%d\n",
766 "%s: decoder set picture bright=%d contrast=%d saturation=%d hue=%d\n", 726 pic->brightness, pic->contrast, pic->colour, pic->hue);
767 I2C_NAME(client), pic->brightness, pic->contrast,
768 pic->colour, pic->hue);
769 727
770 if (decoder->bright != pic->brightness) { 728 if (decoder->bright != pic->brightness) {
771 /* We want 0 to 255 we get 0-65535 */ 729 /* We want 0 to 255 we get 0-65535 */
@@ -789,8 +747,8 @@ saa7114_command (struct i2c_client *client,
789 saa7114_write(client, 0x0d, 747 saa7114_write(client, 0x0d,
790 (decoder->hue - 32768) >> 8); 748 (decoder->hue - 32768) >> 8);
791 } 749 }
792 }
793 break; 750 break;
751 }
794 752
795 default: 753 default:
796 return -EINVAL; 754 return -EINVAL;
@@ -801,58 +759,30 @@ saa7114_command (struct i2c_client *client,
801 759
802/* ----------------------------------------------------------------------- */ 760/* ----------------------------------------------------------------------- */
803 761
804/* 762static unsigned short normal_i2c[] = { 0x42 >> 1, 0x40 >> 1, I2C_CLIENT_END };
805 * Generic i2c probe
806 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1'
807 */
808static unsigned short normal_i2c[] =
809 { I2C_SAA7114 >> 1, I2C_SAA7114A >> 1, I2C_CLIENT_END };
810
811static unsigned short ignore = I2C_CLIENT_END;
812
813static struct i2c_client_address_data addr_data = {
814 .normal_i2c = normal_i2c,
815 .probe = &ignore,
816 .ignore = &ignore,
817};
818 763
819static struct i2c_driver i2c_driver_saa7114; 764I2C_CLIENT_INSMOD;
820 765
821static int 766static int saa7114_probe(struct i2c_client *client,
822saa7114_detect_client (struct i2c_adapter *adapter, 767 const struct i2c_device_id *id)
823 int address,
824 int kind)
825{ 768{
826 int i, err[30]; 769 int i, err[30];
827 short int hoff = SAA_7114_NTSC_HOFFSET; 770 short int hoff = SAA_7114_NTSC_HOFFSET;
828 short int voff = SAA_7114_NTSC_VOFFSET; 771 short int voff = SAA_7114_NTSC_VOFFSET;
829 short int w = SAA_7114_NTSC_WIDTH; 772 short int w = SAA_7114_NTSC_WIDTH;
830 short int h = SAA_7114_NTSC_HEIGHT; 773 short int h = SAA_7114_NTSC_HEIGHT;
831 struct i2c_client *client;
832 struct saa7114 *decoder; 774 struct saa7114 *decoder;
833 775
834 dprintk(1,
835 KERN_INFO
836 "saa7114.c: detecting saa7114 client on address 0x%x\n",
837 address << 1);
838
839 /* Check if the adapter supports the needed features */ 776 /* Check if the adapter supports the needed features */
840 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 777 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
841 return 0; 778 return -ENODEV;
842 779
843 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); 780 v4l_info(client, "chip found @ 0x%x (%s)\n",
844 if (!client) 781 client->addr << 1, client->adapter->name);
845 return -ENOMEM;
846 client->addr = address;
847 client->adapter = adapter;
848 client->driver = &i2c_driver_saa7114;
849 strlcpy(I2C_NAME(client), "saa7114", sizeof(I2C_NAME(client)));
850 782
851 decoder = kzalloc(sizeof(struct saa7114), GFP_KERNEL); 783 decoder = kzalloc(sizeof(struct saa7114), GFP_KERNEL);
852 if (decoder == NULL) { 784 if (decoder == NULL)
853 kfree(client);
854 return -ENOMEM; 785 return -ENOMEM;
855 }
856 decoder->norm = VIDEO_MODE_NTSC; 786 decoder->norm = VIDEO_MODE_NTSC;
857 decoder->input = -1; 787 decoder->input = -1;
858 decoder->enable = 1; 788 decoder->enable = 1;
@@ -937,8 +867,7 @@ saa7114_detect_client (struct i2c_adapter *adapter,
937 decoder->reg[REG_ADDR(0x0e)] |= 1; // combfilter on 867 decoder->reg[REG_ADDR(0x0e)] |= 1; // combfilter on
938 868
939 869
940 dprintk(1, KERN_DEBUG "%s_attach: starting decoder init\n", 870 v4l_dbg(1, debug, client, "starting init\n");
941 I2C_NAME(client));
942 871
943 err[0] = 872 err[0] =
944 saa7114_write_block(client, decoder->reg + (0x20 << 1), 873 saa7114_write_block(client, decoder->reg + (0x20 << 1),
@@ -962,28 +891,23 @@ saa7114_detect_client (struct i2c_adapter *adapter,
962 891
963 for (i = 0; i <= 5; i++) { 892 for (i = 0; i <= 5; i++) {
964 if (err[i] < 0) { 893 if (err[i] < 0) {
965 dprintk(1, 894 v4l_dbg(1, debug, client,
966 KERN_ERR 895 "init error %d at stage %d, leaving attach.\n",
967 "%s_attach: init error %d at stage %d, leaving attach.\n", 896 i, err[i]);
968 I2C_NAME(client), i, err[i]);
969 kfree(decoder); 897 kfree(decoder);
970 kfree(client); 898 return -EIO;
971 return 0;
972 } 899 }
973 } 900 }
974 901
975 for (i = 6; i < 8; i++) { 902 for (i = 6; i < 8; i++) {
976 dprintk(1, 903 v4l_dbg(1, debug, client,
977 KERN_DEBUG 904 "reg[0x%02x] = 0x%02x (0x%02x)\n",
978 "%s_attach: reg[0x%02x] = 0x%02x (0x%02x)\n", 905 i, saa7114_read(client, i),
979 I2C_NAME(client), i, saa7114_read(client, i),
980 decoder->reg[REG_ADDR(i)]); 906 decoder->reg[REG_ADDR(i)]);
981 } 907 }
982 908
983 dprintk(1, 909 v4l_dbg(1, debug, client,
984 KERN_DEBUG 910 "performing decoder reset sequence\n");
985 "%s_attach: performing decoder reset sequence\n",
986 I2C_NAME(client));
987 911
988 err[6] = saa7114_write(client, 0x80, 0x06); // i-port and scaler backend clock selection, task A&B off 912 err[6] = saa7114_write(client, 0x80, 0x06); // i-port and scaler backend clock selection, task A&B off
989 err[7] = saa7114_write(client, 0x88, 0xd8); // sw reset scaler 913 err[7] = saa7114_write(client, 0x88, 0xd8); // sw reset scaler
@@ -991,19 +915,15 @@ saa7114_detect_client (struct i2c_adapter *adapter,
991 915
992 for (i = 6; i <= 8; i++) { 916 for (i = 6; i <= 8; i++) {
993 if (err[i] < 0) { 917 if (err[i] < 0) {
994 dprintk(1, 918 v4l_dbg(1, debug, client,
995 KERN_ERR 919 "init error %d at stage %d, leaving attach.\n",
996 "%s_attach: init error %d at stage %d, leaving attach.\n", 920 i, err[i]);
997 I2C_NAME(client), i, err[i]);
998 kfree(decoder); 921 kfree(decoder);
999 kfree(client); 922 return -EIO;
1000 return 0;
1001 } 923 }
1002 } 924 }
1003 925
1004 dprintk(1, KERN_INFO "%s_attach: performing the rest of init\n", 926 v4l_dbg(1, debug, client, "performing the rest of init\n");
1005 I2C_NAME(client));
1006
1007 927
1008 err[9] = saa7114_write(client, 0x01, decoder->reg[REG_ADDR(0x01)]); 928 err[9] = saa7114_write(client, 0x01, decoder->reg[REG_ADDR(0x01)]);
1009 err[10] = saa7114_write_block(client, decoder->reg + (0x03 << 1), (0x1e + 1 - 0x03) << 1); // big seq 929 err[10] = saa7114_write_block(client, decoder->reg + (0x03 << 1), (0x1e + 1 - 0x03) << 1); // big seq
@@ -1039,37 +959,32 @@ saa7114_detect_client (struct i2c_adapter *adapter,
1039 959
1040 for (i = 9; i <= 18; i++) { 960 for (i = 9; i <= 18; i++) {
1041 if (err[i] < 0) { 961 if (err[i] < 0) {
1042 dprintk(1, 962 v4l_dbg(1, debug, client,
1043 KERN_ERR 963 "init error %d at stage %d, leaving attach.\n",
1044 "%s_attach: init error %d at stage %d, leaving attach.\n", 964 i, err[i]);
1045 I2C_NAME(client), i, err[i]);
1046 kfree(decoder); 965 kfree(decoder);
1047 kfree(client); 966 return -EIO;
1048 return 0;
1049 } 967 }
1050 } 968 }
1051 969
1052 970
1053 for (i = 6; i < 8; i++) { 971 for (i = 6; i < 8; i++) {
1054 dprintk(1, 972 v4l_dbg(1, debug, client,
1055 KERN_DEBUG 973 "reg[0x%02x] = 0x%02x (0x%02x)\n",
1056 "%s_attach: reg[0x%02x] = 0x%02x (0x%02x)\n", 974 i, saa7114_read(client, i),
1057 I2C_NAME(client), i, saa7114_read(client, i),
1058 decoder->reg[REG_ADDR(i)]); 975 decoder->reg[REG_ADDR(i)]);
1059 } 976 }
1060 977
1061 978
1062 for (i = 0x11; i <= 0x13; i++) { 979 for (i = 0x11; i <= 0x13; i++) {
1063 dprintk(1, 980 v4l_dbg(1, debug, client,
1064 KERN_DEBUG 981 "reg[0x%02x] = 0x%02x (0x%02x)\n",
1065 "%s_attach: reg[0x%02x] = 0x%02x (0x%02x)\n", 982 i, saa7114_read(client, i),
1066 I2C_NAME(client), i, saa7114_read(client, i),
1067 decoder->reg[REG_ADDR(i)]); 983 decoder->reg[REG_ADDR(i)]);
1068 } 984 }
1069 985
1070 986
1071 dprintk(1, KERN_DEBUG "%s_attach: setting video input\n", 987 v4l_dbg(1, debug, client, "setting video input\n");
1072 I2C_NAME(client));
1073 988
1074 err[19] = 989 err[19] =
1075 saa7114_write(client, 0x02, decoder->reg[REG_ADDR(0x02)]); 990 saa7114_write(client, 0x02, decoder->reg[REG_ADDR(0x02)]);
@@ -1080,20 +995,15 @@ saa7114_detect_client (struct i2c_adapter *adapter,
1080 995
1081 for (i = 19; i <= 21; i++) { 996 for (i = 19; i <= 21; i++) {
1082 if (err[i] < 0) { 997 if (err[i] < 0) {
1083 dprintk(1, 998 v4l_dbg(1, debug, client,
1084 KERN_ERR 999 "init error %d at stage %d, leaving attach.\n",
1085 "%s_attach: init error %d at stage %d, leaving attach.\n", 1000 i, err[i]);
1086 I2C_NAME(client), i, err[i]);
1087 kfree(decoder); 1001 kfree(decoder);
1088 kfree(client); 1002 return -EIO;
1089 return 0;
1090 } 1003 }
1091 } 1004 }
1092 1005
1093 dprintk(1, 1006 v4l_dbg(1, debug, client, "performing decoder reset sequence\n");
1094 KERN_DEBUG
1095 "%s_attach: performing decoder reset sequence\n",
1096 I2C_NAME(client));
1097 1007
1098 err[22] = saa7114_write(client, 0x88, 0xd8); // sw reset scaler 1008 err[22] = saa7114_write(client, 0x88, 0xd8); // sw reset scaler
1099 err[23] = saa7114_write(client, 0x88, 0xf8); // sw reset scaler release 1009 err[23] = saa7114_write(client, 0x88, 0xf8); // sw reset scaler release
@@ -1102,13 +1012,11 @@ saa7114_detect_client (struct i2c_adapter *adapter,
1102 1012
1103 for (i = 22; i <= 24; i++) { 1013 for (i = 22; i <= 24; i++) {
1104 if (err[i] < 0) { 1014 if (err[i] < 0) {
1105 dprintk(1, 1015 v4l_dbg(1, debug, client,
1106 KERN_ERR 1016 "init error %d at stage %d, leaving attach.\n",
1107 "%s_attach: init error %d at stage %d, leaving attach.\n", 1017 i, err[i]);
1108 I2C_NAME(client), i, err[i]);
1109 kfree(decoder); 1018 kfree(decoder);
1110 kfree(client); 1019 return -EIO;
1111 return 0;
1112 } 1020 }
1113 } 1021 }
1114 1022
@@ -1116,101 +1024,45 @@ saa7114_detect_client (struct i2c_adapter *adapter,
1116 err[26] = saa7114_write(client, 0x07, init[REG_ADDR(0x07)]); 1024 err[26] = saa7114_write(client, 0x07, init[REG_ADDR(0x07)]);
1117 err[27] = saa7114_write(client, 0x10, init[REG_ADDR(0x10)]); 1025 err[27] = saa7114_write(client, 0x10, init[REG_ADDR(0x10)]);
1118 1026
1119 dprintk(1, 1027 v4l_dbg(1, debug, client, "chip version %x, decoder status 0x%02x\n",
1120 KERN_INFO 1028 saa7114_read(client, 0x00) >> 4,
1121 "%s_attach: chip version %x, decoder status 0x%02x\n",
1122 I2C_NAME(client), saa7114_read(client, 0x00) >> 4,
1123 saa7114_read(client, 0x1f)); 1029 saa7114_read(client, 0x1f));
1124 dprintk(1, 1030 v4l_dbg(1, debug, client,
1125 KERN_DEBUG 1031 "power save control: 0x%02x, scaler status: 0x%02x\n",
1126 "%s_attach: power save control: 0x%02x, scaler status: 0x%02x\n", 1032 saa7114_read(client, 0x88),
1127 I2C_NAME(client), saa7114_read(client, 0x88),
1128 saa7114_read(client, 0x8f)); 1033 saa7114_read(client, 0x8f));
1129 1034
1130 1035
1131 for (i = 0x94; i < 0x96; i++) { 1036 for (i = 0x94; i < 0x96; i++) {
1132 dprintk(1, 1037 v4l_dbg(1, debug, client,
1133 KERN_DEBUG 1038 "reg[0x%02x] = 0x%02x (0x%02x)\n",
1134 "%s_attach: reg[0x%02x] = 0x%02x (0x%02x)\n", 1039 i, saa7114_read(client, i),
1135 I2C_NAME(client), i, saa7114_read(client, i),
1136 decoder->reg[REG_ADDR(i)]); 1040 decoder->reg[REG_ADDR(i)]);
1137 } 1041 }
1138 1042
1139 i = i2c_attach_client(client);
1140 if (i) {
1141 kfree(client);
1142 kfree(decoder);
1143 return i;
1144 }
1145
1146 //i = saa7114_write_block(client, init, sizeof(init)); 1043 //i = saa7114_write_block(client, init, sizeof(init));
1147 i = 0;
1148 if (i < 0) {
1149 dprintk(1, KERN_ERR "%s_attach error: init status %d\n",
1150 I2C_NAME(client), i);
1151 } else {
1152 dprintk(1,
1153 KERN_INFO
1154 "%s_attach: chip version %x at address 0x%x\n",
1155 I2C_NAME(client), saa7114_read(client, 0x00) >> 4,
1156 client->addr << 1);
1157 }
1158
1159 return 0; 1044 return 0;
1160} 1045}
1161 1046
1162static int 1047static int saa7114_remove(struct i2c_client *client)
1163saa7114_attach_adapter (struct i2c_adapter *adapter)
1164{
1165 dprintk(1,
1166 KERN_INFO
1167 "saa7114.c: starting probe for adapter %s (0x%x)\n",
1168 I2C_NAME(adapter), adapter->id);
1169 return i2c_probe(adapter, &addr_data, &saa7114_detect_client);
1170}
1171
1172static int
1173saa7114_detach_client (struct i2c_client *client)
1174{ 1048{
1175 struct saa7114 *decoder = i2c_get_clientdata(client); 1049 kfree(i2c_get_clientdata(client));
1176 int err;
1177
1178 err = i2c_detach_client(client);
1179 if (err) {
1180 return err;
1181 }
1182
1183 kfree(decoder);
1184 kfree(client);
1185
1186 return 0; 1050 return 0;
1187} 1051}
1188 1052
1189/* ----------------------------------------------------------------------- */ 1053/* ----------------------------------------------------------------------- */
1190 1054
1191static struct i2c_driver i2c_driver_saa7114 = { 1055static const struct i2c_device_id saa7114_id[] = {
1192 .driver = { 1056 { "saa7114_old", 0 }, /* "saa7114" maps to the saa7115 driver */
1193 .name = "saa7114", 1057 { }
1194 }, 1058};
1195 1059MODULE_DEVICE_TABLE(i2c, saa7114_id);
1196 .id = I2C_DRIVERID_SAA7114,
1197 1060
1198 .attach_adapter = saa7114_attach_adapter, 1061static struct v4l2_i2c_driver_data v4l2_i2c_data = {
1199 .detach_client = saa7114_detach_client, 1062 .name = "saa7114",
1063 .driverid = I2C_DRIVERID_SAA7114,
1200 .command = saa7114_command, 1064 .command = saa7114_command,
1065 .probe = saa7114_probe,
1066 .remove = saa7114_remove,
1067 .id_table = saa7114_id,
1201}; 1068};
1202
1203static int __init
1204saa7114_init (void)
1205{
1206 return i2c_add_driver(&i2c_driver_saa7114);
1207}
1208
1209static void __exit
1210saa7114_exit (void)
1211{
1212 i2c_del_driver(&i2c_driver_saa7114);
1213}
1214
1215module_init(saa7114_init);
1216module_exit(saa7114_exit);