diff options
Diffstat (limited to 'drivers/media/video/v4l2-common.c')
-rw-r--r-- | drivers/media/video/v4l2-common.c | 62 |
1 files changed, 22 insertions, 40 deletions
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c index 1da8cb836cb6..f576ef66b807 100644 --- a/drivers/media/video/v4l2-common.c +++ b/drivers/media/video/v4l2-common.c | |||
@@ -739,33 +739,8 @@ EXPORT_SYMBOL(v4l2_chip_ident_i2c_client); | |||
739 | 739 | ||
740 | /* ----------------------------------------------------------------- */ | 740 | /* ----------------------------------------------------------------- */ |
741 | 741 | ||
742 | /* Helper function for I2C legacy drivers */ | 742 | /* I2C Helper functions */ |
743 | 743 | ||
744 | int v4l2_i2c_attach(struct i2c_adapter *adapter, int address, struct i2c_driver *driver, | ||
745 | const char *name, | ||
746 | int (*probe)(struct i2c_client *, const struct i2c_device_id *)) | ||
747 | { | ||
748 | struct i2c_client *client; | ||
749 | int err; | ||
750 | |||
751 | client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); | ||
752 | if (!client) | ||
753 | return -ENOMEM; | ||
754 | |||
755 | client->addr = address; | ||
756 | client->adapter = adapter; | ||
757 | client->driver = driver; | ||
758 | strlcpy(client->name, name, sizeof(client->name)); | ||
759 | |||
760 | err = probe(client, NULL); | ||
761 | if (err == 0) { | ||
762 | i2c_attach_client(client); | ||
763 | } else { | ||
764 | kfree(client); | ||
765 | } | ||
766 | return err != -ENOMEM ? 0 : err; | ||
767 | } | ||
768 | EXPORT_SYMBOL(v4l2_i2c_attach); | ||
769 | 744 | ||
770 | void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client, | 745 | void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client, |
771 | const struct v4l2_subdev_ops *ops) | 746 | const struct v4l2_subdev_ops *ops) |
@@ -785,18 +760,16 @@ EXPORT_SYMBOL_GPL(v4l2_i2c_subdev_init); | |||
785 | 760 | ||
786 | 761 | ||
787 | 762 | ||
788 | /* Load an i2c sub-device. It assumes that i2c_get_adapdata(adapter) | 763 | /* Load an i2c sub-device. */ |
789 | returns the v4l2_device and that i2c_get_clientdata(client) | 764 | struct v4l2_subdev *v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev, |
790 | returns the v4l2_subdev. */ | 765 | struct i2c_adapter *adapter, |
791 | struct v4l2_subdev *v4l2_i2c_new_subdev(struct i2c_adapter *adapter, | ||
792 | const char *module_name, const char *client_type, u8 addr) | 766 | const char *module_name, const char *client_type, u8 addr) |
793 | { | 767 | { |
794 | struct v4l2_device *dev = i2c_get_adapdata(adapter); | ||
795 | struct v4l2_subdev *sd = NULL; | 768 | struct v4l2_subdev *sd = NULL; |
796 | struct i2c_client *client; | 769 | struct i2c_client *client; |
797 | struct i2c_board_info info; | 770 | struct i2c_board_info info; |
798 | 771 | ||
799 | BUG_ON(!dev); | 772 | BUG_ON(!v4l2_dev); |
800 | 773 | ||
801 | if (module_name) | 774 | if (module_name) |
802 | request_module(module_name); | 775 | request_module(module_name); |
@@ -823,7 +796,7 @@ struct v4l2_subdev *v4l2_i2c_new_subdev(struct i2c_adapter *adapter, | |||
823 | 796 | ||
824 | /* Register with the v4l2_device which increases the module's | 797 | /* Register with the v4l2_device which increases the module's |
825 | use count as well. */ | 798 | use count as well. */ |
826 | if (v4l2_device_register_subdev(dev, sd)) | 799 | if (v4l2_device_register_subdev(v4l2_dev, sd)) |
827 | sd = NULL; | 800 | sd = NULL; |
828 | /* Decrease the module use count to match the first try_module_get. */ | 801 | /* Decrease the module use count to match the first try_module_get. */ |
829 | module_put(client->driver->driver.owner); | 802 | module_put(client->driver->driver.owner); |
@@ -837,19 +810,17 @@ error: | |||
837 | } | 810 | } |
838 | EXPORT_SYMBOL_GPL(v4l2_i2c_new_subdev); | 811 | EXPORT_SYMBOL_GPL(v4l2_i2c_new_subdev); |
839 | 812 | ||
840 | /* Probe and load an i2c sub-device. It assumes that i2c_get_adapdata(adapter) | 813 | /* Probe and load an i2c sub-device. */ |
841 | returns the v4l2_device and that i2c_get_clientdata(client) | 814 | struct v4l2_subdev *v4l2_i2c_new_probed_subdev(struct v4l2_device *v4l2_dev, |
842 | returns the v4l2_subdev. */ | 815 | struct i2c_adapter *adapter, |
843 | struct v4l2_subdev *v4l2_i2c_new_probed_subdev(struct i2c_adapter *adapter, | ||
844 | const char *module_name, const char *client_type, | 816 | const char *module_name, const char *client_type, |
845 | const unsigned short *addrs) | 817 | const unsigned short *addrs) |
846 | { | 818 | { |
847 | struct v4l2_device *dev = i2c_get_adapdata(adapter); | ||
848 | struct v4l2_subdev *sd = NULL; | 819 | struct v4l2_subdev *sd = NULL; |
849 | struct i2c_client *client = NULL; | 820 | struct i2c_client *client = NULL; |
850 | struct i2c_board_info info; | 821 | struct i2c_board_info info; |
851 | 822 | ||
852 | BUG_ON(!dev); | 823 | BUG_ON(!v4l2_dev); |
853 | 824 | ||
854 | if (module_name) | 825 | if (module_name) |
855 | request_module(module_name); | 826 | request_module(module_name); |
@@ -875,7 +846,7 @@ struct v4l2_subdev *v4l2_i2c_new_probed_subdev(struct i2c_adapter *adapter, | |||
875 | 846 | ||
876 | /* Register with the v4l2_device which increases the module's | 847 | /* Register with the v4l2_device which increases the module's |
877 | use count as well. */ | 848 | use count as well. */ |
878 | if (v4l2_device_register_subdev(dev, sd)) | 849 | if (v4l2_device_register_subdev(v4l2_dev, sd)) |
879 | sd = NULL; | 850 | sd = NULL; |
880 | /* Decrease the module use count to match the first try_module_get. */ | 851 | /* Decrease the module use count to match the first try_module_get. */ |
881 | module_put(client->driver->driver.owner); | 852 | module_put(client->driver->driver.owner); |
@@ -889,6 +860,17 @@ error: | |||
889 | } | 860 | } |
890 | EXPORT_SYMBOL_GPL(v4l2_i2c_new_probed_subdev); | 861 | EXPORT_SYMBOL_GPL(v4l2_i2c_new_probed_subdev); |
891 | 862 | ||
863 | struct v4l2_subdev *v4l2_i2c_new_probed_subdev_addr(struct v4l2_device *v4l2_dev, | ||
864 | struct i2c_adapter *adapter, | ||
865 | const char *module_name, const char *client_type, u8 addr) | ||
866 | { | ||
867 | unsigned short addrs[2] = { addr, I2C_CLIENT_END }; | ||
868 | |||
869 | return v4l2_i2c_new_probed_subdev(v4l2_dev, adapter, | ||
870 | module_name, client_type, addrs); | ||
871 | } | ||
872 | EXPORT_SYMBOL_GPL(v4l2_i2c_new_probed_subdev_addr); | ||
873 | |||
892 | /* Return i2c client address of v4l2_subdev. */ | 874 | /* Return i2c client address of v4l2_subdev. */ |
893 | unsigned short v4l2_i2c_subdev_addr(struct v4l2_subdev *sd) | 875 | unsigned short v4l2_i2c_subdev_addr(struct v4l2_subdev *sd) |
894 | { | 876 | { |