Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'i2c/for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux

Pull i2c updates from Wolfram Sang:
"Some I2C core API additions which are kind of simple but enhance error
checking for users a lot, especially by returning errno now.

There are wrappers to still support the old API but it will be removed
once all users are converted"

* 'i2c/for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux:
i2c: core: add device-managed version of i2c_new_dummy
i2c: core: improve return value handling of i2c_new_device and i2c_new_dummy

+111 -13
+3
Documentation/driver-model/devres.txt
··· 271 271 devm_gpio_request_one() 272 272 devm_gpio_free() 273 273 274 + I2C 275 + devm_i2c_new_dummy_device() 276 + 274 277 IIO 275 278 devm_iio_device_alloc() 276 279 devm_iio_device_free()
+105 -13
drivers/i2c/i2c-core-base.c
··· 714 714 } 715 715 716 716 /** 717 - * i2c_new_device - instantiate an i2c device 717 + * i2c_new_client_device - instantiate an i2c device 718 718 * @adap: the adapter managing the device 719 719 * @info: describes one I2C device; bus_num is ignored 720 720 * Context: can sleep ··· 727 727 * before any i2c_adapter could exist. 728 728 * 729 729 * This returns the new i2c client, which may be saved for later use with 730 - * i2c_unregister_device(); or NULL to indicate an error. 730 + * i2c_unregister_device(); or an ERR_PTR to describe the error. 731 731 */ 732 - struct i2c_client * 733 - i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info) 732 + static struct i2c_client * 733 + i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *info) 734 734 { 735 735 struct i2c_client *client; 736 736 int status; 737 737 738 738 client = kzalloc(sizeof *client, GFP_KERNEL); 739 739 if (!client) 740 - return NULL; 740 + return ERR_PTR(-ENOMEM); 741 741 742 742 client->adapter = adap; 743 743 ··· 803 803 client->name, client->addr, status); 804 804 out_err_silent: 805 805 kfree(client); 806 - return NULL; 806 + return ERR_PTR(status); 807 + } 808 + EXPORT_SYMBOL_GPL(i2c_new_client_device); 809 + 810 + /** 811 + * i2c_new_device - instantiate an i2c device 812 + * @adap: the adapter managing the device 813 + * @info: describes one I2C device; bus_num is ignored 814 + * Context: can sleep 815 + * 816 + * This deprecated function has the same functionality as 817 + * @i2c_new_client_device, it just returns NULL instead of an ERR_PTR in case of 818 + * an error for compatibility with current I2C API. It will be removed once all 819 + * users are converted. 820 + * 821 + * This returns the new i2c client, which may be saved for later use with 822 + * i2c_unregister_device(); or NULL to indicate an error. 823 + */ 824 + struct i2c_client * 825 + i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info) 826 + { 827 + struct i2c_client *ret; 828 + 829 + ret = i2c_new_client_device(adap, info); 830 + return IS_ERR(ret) ? NULL : ret; 807 831 } 808 832 EXPORT_SYMBOL_GPL(i2c_new_device); 809 833 ··· 878 854 }; 879 855 880 856 /** 881 - * i2c_new_dummy - return a new i2c device bound to a dummy driver 857 + * i2c_new_dummy_device - return a new i2c device bound to a dummy driver 882 858 * @adapter: the adapter managing the device 883 859 * @address: seven bit address to be used 884 860 * Context: can sleep ··· 893 869 * different driver. 894 870 * 895 871 * This returns the new i2c client, which should be saved for later use with 896 - * i2c_unregister_device(); or NULL to indicate an error. 872 + * i2c_unregister_device(); or an ERR_PTR to describe the error. 897 873 */ 898 - struct i2c_client *i2c_new_dummy(struct i2c_adapter *adapter, u16 address) 874 + static struct i2c_client * 875 + i2c_new_dummy_device(struct i2c_adapter *adapter, u16 address) 899 876 { 900 877 struct i2c_board_info info = { 901 878 I2C_BOARD_INFO("dummy", address), 902 879 }; 903 880 904 - return i2c_new_device(adapter, &info); 881 + return i2c_new_client_device(adapter, &info); 882 + } 883 + EXPORT_SYMBOL_GPL(i2c_new_dummy_device); 884 + 885 + /** 886 + * i2c_new_dummy - return a new i2c device bound to a dummy driver 887 + * @adapter: the adapter managing the device 888 + * @address: seven bit address to be used 889 + * Context: can sleep 890 + * 891 + * This deprecated function has the same functionality as @i2c_new_dummy_device, 892 + * it just returns NULL instead of an ERR_PTR in case of an error for 893 + * compatibility with current I2C API. It will be removed once all users are 894 + * converted. 895 + * 896 + * This returns the new i2c client, which should be saved for later use with 897 + * i2c_unregister_device(); or NULL to indicate an error. 898 + */ 899 + struct i2c_client *i2c_new_dummy(struct i2c_adapter *adapter, u16 address) 900 + { 901 + struct i2c_client *ret; 902 + 903 + ret = i2c_new_dummy_device(adapter, address); 904 + return IS_ERR(ret) ? NULL : ret; 905 905 } 906 906 EXPORT_SYMBOL_GPL(i2c_new_dummy); 907 + 908 + struct i2c_dummy_devres { 909 + struct i2c_client *client; 910 + }; 911 + 912 + static void devm_i2c_release_dummy(struct device *dev, void *res) 913 + { 914 + struct i2c_dummy_devres *this = res; 915 + 916 + i2c_unregister_device(this->client); 917 + } 918 + 919 + /** 920 + * devm_i2c_new_dummy_device - return a new i2c device bound to a dummy driver 921 + * @dev: device the managed resource is bound to 922 + * @adapter: the adapter managing the device 923 + * @address: seven bit address to be used 924 + * Context: can sleep 925 + * 926 + * This is the device-managed version of @i2c_new_dummy_device. It returns the 927 + * new i2c client or an ERR_PTR in case of an error. 928 + */ 929 + struct i2c_client *devm_i2c_new_dummy_device(struct device *dev, 930 + struct i2c_adapter *adapter, 931 + u16 address) 932 + { 933 + struct i2c_dummy_devres *dr; 934 + struct i2c_client *client; 935 + 936 + dr = devres_alloc(devm_i2c_release_dummy, sizeof(*dr), GFP_KERNEL); 937 + if (!dr) 938 + return ERR_PTR(-ENOMEM); 939 + 940 + client = i2c_new_dummy_device(adapter, address); 941 + if (IS_ERR(client)) { 942 + devres_free(dr); 943 + } else { 944 + dr->client = client; 945 + devres_add(dev, dr); 946 + } 947 + 948 + return client; 949 + } 950 + EXPORT_SYMBOL_GPL(devm_i2c_new_dummy_device); 907 951 908 952 /** 909 953 * i2c_new_secondary_device - Helper to get the instantiated secondary address ··· 1092 1000 info.flags |= I2C_CLIENT_SLAVE; 1093 1001 } 1094 1002 1095 - client = i2c_new_device(adap, &info); 1096 - if (!client) 1097 - return -EINVAL; 1003 + client = i2c_new_client_device(adap, &info); 1004 + if (IS_ERR(client)) 1005 + return PTR_ERR(client); 1098 1006 1099 1007 /* Keep track of the added device */ 1100 1008 mutex_lock(&adap->userspace_clients_lock);
+3
include/linux/i2c.h
··· 470 470 i2c_new_dummy(struct i2c_adapter *adap, u16 address); 471 471 472 472 extern struct i2c_client * 473 + devm_i2c_new_dummy_device(struct device *dev, struct i2c_adapter *adap, u16 address); 474 + 475 + extern struct i2c_client * 473 476 i2c_new_secondary_device(struct i2c_client *client, 474 477 const char *name, 475 478 u16 default_addr);