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

Merge branch 'i2c/fwnode-api' into i2c/for-mergewindow

+121 -82
+1 -12
drivers/i2c/i2c-core-acpi.c
··· 442 442 443 443 static struct i2c_client *i2c_acpi_find_client_by_adev(struct acpi_device *adev) 444 444 { 445 - struct device *dev; 446 - struct i2c_client *client; 447 - 448 - dev = bus_find_device_by_acpi_dev(&i2c_bus_type, adev); 449 - if (!dev) 450 - return NULL; 451 - 452 - client = i2c_verify_client(dev); 453 - if (!client) 454 - put_device(dev); 455 - 456 - return client; 445 + return i2c_find_device_by_fwnode(acpi_fwnode_handle(adev)); 457 446 } 458 447 459 448 static int i2c_acpi_notify(struct notifier_block *nb, unsigned long value,
+98
drivers/i2c/i2c-core-base.c
··· 1012 1012 } 1013 1013 EXPORT_SYMBOL_GPL(i2c_unregister_device); 1014 1014 1015 + /** 1016 + * i2c_find_device_by_fwnode() - find an i2c_client for the fwnode 1017 + * @fwnode: &struct fwnode_handle corresponding to the &struct i2c_client 1018 + * 1019 + * Look up and return the &struct i2c_client corresponding to the @fwnode. 1020 + * If no client can be found, or @fwnode is NULL, this returns NULL. 1021 + * 1022 + * The user must call put_device(&client->dev) once done with the i2c client. 1023 + */ 1024 + struct i2c_client *i2c_find_device_by_fwnode(struct fwnode_handle *fwnode) 1025 + { 1026 + struct i2c_client *client; 1027 + struct device *dev; 1028 + 1029 + if (!fwnode) 1030 + return NULL; 1031 + 1032 + dev = bus_find_device_by_fwnode(&i2c_bus_type, fwnode); 1033 + if (!dev) 1034 + return NULL; 1035 + 1036 + client = i2c_verify_client(dev); 1037 + if (!client) 1038 + put_device(dev); 1039 + 1040 + return client; 1041 + } 1042 + EXPORT_SYMBOL(i2c_find_device_by_fwnode); 1043 + 1015 1044 1016 1045 static const struct i2c_device_id dummy_id[] = { 1017 1046 { "dummy", 0 }, ··· 1789 1760 return devm_add_action_or_reset(dev, devm_i2c_del_adapter, adapter); 1790 1761 } 1791 1762 EXPORT_SYMBOL_GPL(devm_i2c_add_adapter); 1763 + 1764 + static int i2c_dev_or_parent_fwnode_match(struct device *dev, const void *data) 1765 + { 1766 + if (dev_fwnode(dev) == data) 1767 + return 1; 1768 + 1769 + if (dev->parent && dev_fwnode(dev->parent) == data) 1770 + return 1; 1771 + 1772 + return 0; 1773 + } 1774 + 1775 + /** 1776 + * i2c_find_adapter_by_fwnode() - find an i2c_adapter for the fwnode 1777 + * @fwnode: &struct fwnode_handle corresponding to the &struct i2c_adapter 1778 + * 1779 + * Look up and return the &struct i2c_adapter corresponding to the @fwnode. 1780 + * If no adapter can be found, or @fwnode is NULL, this returns NULL. 1781 + * 1782 + * The user must call put_device(&adapter->dev) once done with the i2c adapter. 1783 + */ 1784 + struct i2c_adapter *i2c_find_adapter_by_fwnode(struct fwnode_handle *fwnode) 1785 + { 1786 + struct i2c_adapter *adapter; 1787 + struct device *dev; 1788 + 1789 + if (!fwnode) 1790 + return NULL; 1791 + 1792 + dev = bus_find_device(&i2c_bus_type, NULL, fwnode, 1793 + i2c_dev_or_parent_fwnode_match); 1794 + if (!dev) 1795 + return NULL; 1796 + 1797 + adapter = i2c_verify_adapter(dev); 1798 + if (!adapter) 1799 + put_device(dev); 1800 + 1801 + return adapter; 1802 + } 1803 + EXPORT_SYMBOL(i2c_find_adapter_by_fwnode); 1804 + 1805 + /** 1806 + * i2c_get_adapter_by_fwnode() - find an i2c_adapter for the fwnode 1807 + * @fwnode: &struct fwnode_handle corresponding to the &struct i2c_adapter 1808 + * 1809 + * Look up and return the &struct i2c_adapter corresponding to the @fwnode, 1810 + * and increment the adapter module's use count. If no adapter can be found, 1811 + * or @fwnode is NULL, this returns NULL. 1812 + * 1813 + * The user must call i2c_put_adapter(adapter) once done with the i2c adapter. 1814 + * Note that this is different from i2c_find_adapter_by_node(). 1815 + */ 1816 + struct i2c_adapter *i2c_get_adapter_by_fwnode(struct fwnode_handle *fwnode) 1817 + { 1818 + struct i2c_adapter *adapter; 1819 + 1820 + adapter = i2c_find_adapter_by_fwnode(fwnode); 1821 + if (!adapter) 1822 + return NULL; 1823 + 1824 + if (!try_module_get(adapter->owner)) { 1825 + put_device(&adapter->dev); 1826 + adapter = NULL; 1827 + } 1828 + 1829 + return adapter; 1830 + } 1831 + EXPORT_SYMBOL(i2c_get_adapter_by_fwnode); 1792 1832 1793 1833 static void i2c_parse_timing(struct device *dev, char *prop_name, u32 *cur_val_p, 1794 1834 u32 def_val, bool use_def)
-66
drivers/i2c/i2c-core-of.c
··· 113 113 of_node_put(bus); 114 114 } 115 115 116 - static int of_dev_or_parent_node_match(struct device *dev, const void *data) 117 - { 118 - if (dev->of_node == data) 119 - return 1; 120 - 121 - if (dev->parent) 122 - return dev->parent->of_node == data; 123 - 124 - return 0; 125 - } 126 - 127 - /* must call put_device() when done with returned i2c_client device */ 128 - struct i2c_client *of_find_i2c_device_by_node(struct device_node *node) 129 - { 130 - struct device *dev; 131 - struct i2c_client *client; 132 - 133 - dev = bus_find_device_by_of_node(&i2c_bus_type, node); 134 - if (!dev) 135 - return NULL; 136 - 137 - client = i2c_verify_client(dev); 138 - if (!client) 139 - put_device(dev); 140 - 141 - return client; 142 - } 143 - EXPORT_SYMBOL(of_find_i2c_device_by_node); 144 - 145 - /* must call put_device() when done with returned i2c_adapter device */ 146 - struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node) 147 - { 148 - struct device *dev; 149 - struct i2c_adapter *adapter; 150 - 151 - dev = bus_find_device(&i2c_bus_type, NULL, node, 152 - of_dev_or_parent_node_match); 153 - if (!dev) 154 - return NULL; 155 - 156 - adapter = i2c_verify_adapter(dev); 157 - if (!adapter) 158 - put_device(dev); 159 - 160 - return adapter; 161 - } 162 - EXPORT_SYMBOL(of_find_i2c_adapter_by_node); 163 - 164 - /* must call i2c_put_adapter() when done with returned i2c_adapter device */ 165 - struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node) 166 - { 167 - struct i2c_adapter *adapter; 168 - 169 - adapter = of_find_i2c_adapter_by_node(node); 170 - if (!adapter) 171 - return NULL; 172 - 173 - if (!try_module_get(adapter->owner)) { 174 - put_device(&adapter->dev); 175 - adapter = NULL; 176 - } 177 - 178 - return adapter; 179 - } 180 - EXPORT_SYMBOL(of_get_i2c_adapter_by_node); 181 - 182 116 static const struct of_device_id* 183 117 i2c_of_match_device_sysfs(const struct of_device_id *matches, 184 118 struct i2c_client *client)
+22 -4
include/linux/i2c.h
··· 965 965 966 966 #endif /* I2C */ 967 967 968 - #if IS_ENABLED(CONFIG_OF) 969 968 /* must call put_device() when done with returned i2c_client device */ 970 - struct i2c_client *of_find_i2c_device_by_node(struct device_node *node); 969 + struct i2c_client *i2c_find_device_by_fwnode(struct fwnode_handle *fwnode); 971 970 972 971 /* must call put_device() when done with returned i2c_adapter device */ 973 - struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node); 972 + struct i2c_adapter *i2c_find_adapter_by_fwnode(struct fwnode_handle *fwnode); 974 973 975 974 /* must call i2c_put_adapter() when done with returned i2c_adapter device */ 976 - struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node); 975 + struct i2c_adapter *i2c_get_adapter_by_fwnode(struct fwnode_handle *fwnode); 976 + 977 + #if IS_ENABLED(CONFIG_OF) 978 + /* must call put_device() when done with returned i2c_client device */ 979 + static inline struct i2c_client *of_find_i2c_device_by_node(struct device_node *node) 980 + { 981 + return i2c_find_device_by_fwnode(of_fwnode_handle(node)); 982 + } 983 + 984 + /* must call put_device() when done with returned i2c_adapter device */ 985 + static inline struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node) 986 + { 987 + return i2c_find_adapter_by_fwnode(of_fwnode_handle(node)); 988 + } 989 + 990 + /* must call i2c_put_adapter() when done with returned i2c_adapter device */ 991 + static inline struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node) 992 + { 993 + return i2c_get_adapter_by_fwnode(of_fwnode_handle(node)); 994 + } 977 995 978 996 const struct of_device_id 979 997 *i2c_of_match_device(const struct of_device_id *matches,