aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/saa7127.c
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil@xs4all.nl>2007-09-13 10:21:51 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2008-01-25 16:01:20 -0500
commit77566dd724f118b332b5dbf62eedc869f1263f22 (patch)
tree3ce3bb069075b5787f6037034b4e0274d1225c95 /drivers/media/video/saa7127.c
parentfbaa3d0db482ae55fc054b9446c1ecf699754054 (diff)
V4L/DVB (6456): saa7127: convert to bus-based I2C API
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/video/saa7127.c')
-rw-r--r--drivers/media/video/saa7127.c83
1 files changed, 13 insertions, 70 deletions
diff --git a/drivers/media/video/saa7127.c b/drivers/media/video/saa7127.c
index e35ef321ec71..958ecc7168c3 100644
--- a/drivers/media/video/saa7127.c
+++ b/drivers/media/video/saa7127.c
@@ -55,6 +55,7 @@
55#include <linux/videodev2.h> 55#include <linux/videodev2.h>
56#include <media/v4l2-common.h> 56#include <media/v4l2-common.h>
57#include <media/v4l2-chip-ident.h> 57#include <media/v4l2-chip-ident.h>
58#include <media/v4l2-i2c-drv-legacy.h>
58#include <media/saa7127.h> 59#include <media/saa7127.h>
59 60
60static int debug = 0; 61static int debug = 0;
@@ -662,31 +663,19 @@ static int saa7127_command(struct i2c_client *client,
662 663
663/* ----------------------------------------------------------------------- */ 664/* ----------------------------------------------------------------------- */
664 665
665static struct i2c_driver i2c_driver_saa7127; 666static int saa7127_probe(struct i2c_client *client)
666
667/* ----------------------------------------------------------------------- */
668
669static int saa7127_attach(struct i2c_adapter *adapter, int address, int kind)
670{ 667{
671 struct i2c_client *client;
672 struct saa7127_state *state; 668 struct saa7127_state *state;
673 struct v4l2_sliced_vbi_data vbi = { 0, 0, 0, 0 }; /* set to disabled */ 669 struct v4l2_sliced_vbi_data vbi = { 0, 0, 0, 0 }; /* set to disabled */
674 int read_result = 0; 670 int read_result = 0;
675 671
676 /* Check if the adapter supports the needed features */ 672 /* Check if the adapter supports the needed features */
677 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 673 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
678 return 0; 674 return 0;
679 675
680 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
681 if (client == 0)
682 return -ENOMEM;
683
684 client->addr = address;
685 client->adapter = adapter;
686 client->driver = &i2c_driver_saa7127;
687 snprintf(client->name, sizeof(client->name) - 1, "saa7127"); 676 snprintf(client->name, sizeof(client->name) - 1, "saa7127");
688 677
689 v4l_dbg(1, debug, client, "detecting saa7127 client on address 0x%x\n", address << 1); 678 v4l_dbg(1, debug, client, "detecting saa7127 client on address 0x%x\n", client->addr << 1);
690 679
691 /* First test register 0: Bits 5-7 are a version ID (should be 0), 680 /* First test register 0: Bits 5-7 are a version ID (should be 0),
692 and bit 2 should also be 0. 681 and bit 2 should also be 0.
@@ -696,13 +685,11 @@ static int saa7127_attach(struct i2c_adapter *adapter, int address, int kind)
696 if ((saa7127_read(client, 0) & 0xe4) != 0 || 685 if ((saa7127_read(client, 0) & 0xe4) != 0 ||
697 (saa7127_read(client, 0x29) & 0x3f) != 0x1d) { 686 (saa7127_read(client, 0x29) & 0x3f) != 0x1d) {
698 v4l_dbg(1, debug, client, "saa7127 not found\n"); 687 v4l_dbg(1, debug, client, "saa7127 not found\n");
699 kfree(client);
700 return 0; 688 return 0;
701 } 689 }
702 state = kzalloc(sizeof(struct saa7127_state), GFP_KERNEL); 690 state = kzalloc(sizeof(struct saa7127_state), GFP_KERNEL);
703 691
704 if (state == NULL) { 692 if (state == NULL) {
705 kfree(client);
706 return (-ENOMEM); 693 return (-ENOMEM);
707 } 694 }
708 695
@@ -731,78 +718,34 @@ static int saa7127_attach(struct i2c_adapter *adapter, int address, int kind)
731 read_result = saa7127_read(client, SAA7129_REG_FADE_KEY_COL2); 718 read_result = saa7127_read(client, SAA7129_REG_FADE_KEY_COL2);
732 saa7127_write(client, SAA7129_REG_FADE_KEY_COL2, 0xaa); 719 saa7127_write(client, SAA7129_REG_FADE_KEY_COL2, 0xaa);
733 if (saa7127_read(client, SAA7129_REG_FADE_KEY_COL2) == 0xaa) { 720 if (saa7127_read(client, SAA7129_REG_FADE_KEY_COL2) == 0xaa) {
734 v4l_info(client, "saa7129 found @ 0x%x (%s)\n", address << 1, adapter->name); 721 v4l_info(client, "saa7129 found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name);
735 saa7127_write(client, SAA7129_REG_FADE_KEY_COL2, read_result); 722 saa7127_write(client, SAA7129_REG_FADE_KEY_COL2, read_result);
736 saa7127_write_inittab(client, saa7129_init_config_extra); 723 saa7127_write_inittab(client, saa7129_init_config_extra);
737 state->ident = V4L2_IDENT_SAA7129; 724 state->ident = V4L2_IDENT_SAA7129;
738 } else { 725 } else {
739 v4l_info(client, "saa7127 found @ 0x%x (%s)\n", address << 1, adapter->name); 726 v4l_info(client, "saa7127 found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name);
740 state->ident = V4L2_IDENT_SAA7127; 727 state->ident = V4L2_IDENT_SAA7127;
741 } 728 }
742
743 i2c_attach_client(client);
744
745 return 0;
746}
747
748/* ----------------------------------------------------------------------- */
749
750static int saa7127_probe(struct i2c_adapter *adapter)
751{
752 if (adapter->class & I2C_CLASS_TV_ANALOG)
753 return i2c_probe(adapter, &addr_data, saa7127_attach);
754 return 0; 729 return 0;
755} 730}
756 731
757/* ----------------------------------------------------------------------- */ 732/* ----------------------------------------------------------------------- */
758 733
759static int saa7127_detach(struct i2c_client *client) 734static int saa7127_remove(struct i2c_client *client)
760{ 735{
761 struct saa7127_state *state = i2c_get_clientdata(client);
762 int err;
763
764 /* Turn off TV output */ 736 /* Turn off TV output */
765 saa7127_set_video_enable(client, 0); 737 saa7127_set_video_enable(client, 0);
766 738 kfree(i2c_get_clientdata(client));
767 err = i2c_detach_client(client);
768
769 if (err) {
770 return err;
771 }
772
773 kfree(state);
774 kfree(client);
775 return 0; 739 return 0;
776} 740}
777 741
778/* ----------------------------------------------------------------------- */ 742/* ----------------------------------------------------------------------- */
779 743
780static struct i2c_driver i2c_driver_saa7127 = { 744static struct v4l2_i2c_driver_data v4l2_i2c_data = {
781 .driver = { 745 .name = "saa7127",
782 .name = "saa7127", 746 .driverid = I2C_DRIVERID_SAA7127,
783 },
784 .id = I2C_DRIVERID_SAA7127,
785 .attach_adapter = saa7127_probe,
786 .detach_client = saa7127_detach,
787 .command = saa7127_command, 747 .command = saa7127_command,
748 .probe = saa7127_probe,
749 .remove = saa7127_remove,
788}; 750};
789 751
790
791/* ----------------------------------------------------------------------- */
792
793static int __init saa7127_init_module(void)
794{
795 return i2c_add_driver(&i2c_driver_saa7127);
796}
797
798/* ----------------------------------------------------------------------- */
799
800static void __exit saa7127_cleanup_module(void)
801{
802 i2c_del_driver(&i2c_driver_saa7127);
803}
804
805/* ----------------------------------------------------------------------- */
806
807module_init(saa7127_init_module);
808module_exit(saa7127_cleanup_module);