···442442443443static struct i2c_client *i2c_acpi_find_client_by_adev(struct acpi_device *adev)444444{445445- struct device *dev;446446- struct i2c_client *client;447447-448448- dev = bus_find_device_by_acpi_dev(&i2c_bus_type, adev);449449- if (!dev)450450- return NULL;451451-452452- client = i2c_verify_client(dev);453453- if (!client)454454- put_device(dev);455455-456456- return client;445445+ return i2c_find_device_by_fwnode(acpi_fwnode_handle(adev));457446}458447459448static int i2c_acpi_notify(struct notifier_block *nb, unsigned long value,
+98
drivers/i2c/i2c-core-base.c
···10121012}10131013EXPORT_SYMBOL_GPL(i2c_unregister_device);1014101410151015+/**10161016+ * i2c_find_device_by_fwnode() - find an i2c_client for the fwnode10171017+ * @fwnode: &struct fwnode_handle corresponding to the &struct i2c_client10181018+ *10191019+ * Look up and return the &struct i2c_client corresponding to the @fwnode.10201020+ * If no client can be found, or @fwnode is NULL, this returns NULL.10211021+ *10221022+ * The user must call put_device(&client->dev) once done with the i2c client.10231023+ */10241024+struct i2c_client *i2c_find_device_by_fwnode(struct fwnode_handle *fwnode)10251025+{10261026+ struct i2c_client *client;10271027+ struct device *dev;10281028+10291029+ if (!fwnode)10301030+ return NULL;10311031+10321032+ dev = bus_find_device_by_fwnode(&i2c_bus_type, fwnode);10331033+ if (!dev)10341034+ return NULL;10351035+10361036+ client = i2c_verify_client(dev);10371037+ if (!client)10381038+ put_device(dev);10391039+10401040+ return client;10411041+}10421042+EXPORT_SYMBOL(i2c_find_device_by_fwnode);10431043+1015104410161045static const struct i2c_device_id dummy_id[] = {10171046 { "dummy", 0 },···17891760 return devm_add_action_or_reset(dev, devm_i2c_del_adapter, adapter);17901761}17911762EXPORT_SYMBOL_GPL(devm_i2c_add_adapter);17631763+17641764+static int i2c_dev_or_parent_fwnode_match(struct device *dev, const void *data)17651765+{17661766+ if (dev_fwnode(dev) == data)17671767+ return 1;17681768+17691769+ if (dev->parent && dev_fwnode(dev->parent) == data)17701770+ return 1;17711771+17721772+ return 0;17731773+}17741774+17751775+/**17761776+ * i2c_find_adapter_by_fwnode() - find an i2c_adapter for the fwnode17771777+ * @fwnode: &struct fwnode_handle corresponding to the &struct i2c_adapter17781778+ *17791779+ * Look up and return the &struct i2c_adapter corresponding to the @fwnode.17801780+ * If no adapter can be found, or @fwnode is NULL, this returns NULL.17811781+ *17821782+ * The user must call put_device(&adapter->dev) once done with the i2c adapter.17831783+ */17841784+struct i2c_adapter *i2c_find_adapter_by_fwnode(struct fwnode_handle *fwnode)17851785+{17861786+ struct i2c_adapter *adapter;17871787+ struct device *dev;17881788+17891789+ if (!fwnode)17901790+ return NULL;17911791+17921792+ dev = bus_find_device(&i2c_bus_type, NULL, fwnode,17931793+ i2c_dev_or_parent_fwnode_match);17941794+ if (!dev)17951795+ return NULL;17961796+17971797+ adapter = i2c_verify_adapter(dev);17981798+ if (!adapter)17991799+ put_device(dev);18001800+18011801+ return adapter;18021802+}18031803+EXPORT_SYMBOL(i2c_find_adapter_by_fwnode);18041804+18051805+/**18061806+ * i2c_get_adapter_by_fwnode() - find an i2c_adapter for the fwnode18071807+ * @fwnode: &struct fwnode_handle corresponding to the &struct i2c_adapter18081808+ *18091809+ * Look up and return the &struct i2c_adapter corresponding to the @fwnode,18101810+ * and increment the adapter module's use count. If no adapter can be found,18111811+ * or @fwnode is NULL, this returns NULL.18121812+ *18131813+ * The user must call i2c_put_adapter(adapter) once done with the i2c adapter.18141814+ * Note that this is different from i2c_find_adapter_by_node().18151815+ */18161816+struct i2c_adapter *i2c_get_adapter_by_fwnode(struct fwnode_handle *fwnode)18171817+{18181818+ struct i2c_adapter *adapter;18191819+18201820+ adapter = i2c_find_adapter_by_fwnode(fwnode);18211821+ if (!adapter)18221822+ return NULL;18231823+18241824+ if (!try_module_get(adapter->owner)) {18251825+ put_device(&adapter->dev);18261826+ adapter = NULL;18271827+ }18281828+18291829+ return adapter;18301830+}18311831+EXPORT_SYMBOL(i2c_get_adapter_by_fwnode);1792183217931833static void i2c_parse_timing(struct device *dev, char *prop_name, u32 *cur_val_p,17941834 u32 def_val, bool use_def)
-66
drivers/i2c/i2c-core-of.c
···113113 of_node_put(bus);114114}115115116116-static int of_dev_or_parent_node_match(struct device *dev, const void *data)117117-{118118- if (dev->of_node == data)119119- return 1;120120-121121- if (dev->parent)122122- return dev->parent->of_node == data;123123-124124- return 0;125125-}126126-127127-/* must call put_device() when done with returned i2c_client device */128128-struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)129129-{130130- struct device *dev;131131- struct i2c_client *client;132132-133133- dev = bus_find_device_by_of_node(&i2c_bus_type, node);134134- if (!dev)135135- return NULL;136136-137137- client = i2c_verify_client(dev);138138- if (!client)139139- put_device(dev);140140-141141- return client;142142-}143143-EXPORT_SYMBOL(of_find_i2c_device_by_node);144144-145145-/* must call put_device() when done with returned i2c_adapter device */146146-struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node)147147-{148148- struct device *dev;149149- struct i2c_adapter *adapter;150150-151151- dev = bus_find_device(&i2c_bus_type, NULL, node,152152- of_dev_or_parent_node_match);153153- if (!dev)154154- return NULL;155155-156156- adapter = i2c_verify_adapter(dev);157157- if (!adapter)158158- put_device(dev);159159-160160- return adapter;161161-}162162-EXPORT_SYMBOL(of_find_i2c_adapter_by_node);163163-164164-/* must call i2c_put_adapter() when done with returned i2c_adapter device */165165-struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node)166166-{167167- struct i2c_adapter *adapter;168168-169169- adapter = of_find_i2c_adapter_by_node(node);170170- if (!adapter)171171- return NULL;172172-173173- if (!try_module_get(adapter->owner)) {174174- put_device(&adapter->dev);175175- adapter = NULL;176176- }177177-178178- return adapter;179179-}180180-EXPORT_SYMBOL(of_get_i2c_adapter_by_node);181181-182116static const struct of_device_id*183117i2c_of_match_device_sysfs(const struct of_device_id *matches,184118 struct i2c_client *client)
+22-4
include/linux/i2c.h
···965965966966#endif /* I2C */967967968968-#if IS_ENABLED(CONFIG_OF)969968/* must call put_device() when done with returned i2c_client device */970970-struct i2c_client *of_find_i2c_device_by_node(struct device_node *node);969969+struct i2c_client *i2c_find_device_by_fwnode(struct fwnode_handle *fwnode);971970972971/* must call put_device() when done with returned i2c_adapter device */973973-struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node);972972+struct i2c_adapter *i2c_find_adapter_by_fwnode(struct fwnode_handle *fwnode);974973975974/* must call i2c_put_adapter() when done with returned i2c_adapter device */976976-struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node);975975+struct i2c_adapter *i2c_get_adapter_by_fwnode(struct fwnode_handle *fwnode);976976+977977+#if IS_ENABLED(CONFIG_OF)978978+/* must call put_device() when done with returned i2c_client device */979979+static inline struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)980980+{981981+ return i2c_find_device_by_fwnode(of_fwnode_handle(node));982982+}983983+984984+/* must call put_device() when done with returned i2c_adapter device */985985+static inline struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node)986986+{987987+ return i2c_find_adapter_by_fwnode(of_fwnode_handle(node));988988+}989989+990990+/* must call i2c_put_adapter() when done with returned i2c_adapter device */991991+static inline struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node)992992+{993993+ return i2c_get_adapter_by_fwnode(of_fwnode_handle(node));994994+}977995978996const struct of_device_id979997*i2c_of_match_device(const struct of_device_id *matches,