Immutable branch adding fwnode API to the I2C core

-----BEGIN PGP SIGNATURE-----
 
 iQJDBAABCgAtFiEEOZGx6rniZ1Gk92RdFA3kzBSgKbYFAmPGXegPHHdzYUBrZXJu
 ZWwub3JnAAoJEBQN5MwUoCm2tTEQAK/UC61oDlUrsA3OoKH5lGJbBcht+5516SCe
 zDutM5S0xcw6Fo9J1CRAI66GWXPfkibjiT4TDy8EnXdhCvXFC+9D97fsz5zwUc8J
 cYdqUZ3MFur1zknOvmrdy/E9k0k4uRPTzpvsz4/4fd5vzhShQFEiNMrYulCLnNRl
 tkue26OglhN8mFiCgTg4+lqH18P2+5Qj3wVvlew03ghYZIYERjpuIxUjDQgCPlFv
 lDdxtGXNy+O2CL9KW5xqYYYdsqWjtf17BgJevDDTaq+Ip0QIpO95A/FW1ojWSBiD
 wbaGuNlzvqT7skF7fA6Yj4h3UK8Xpxv6isUw8THY+aRVFGcaa1Z5qMvMCOceUyGd
 x0c5qFbKTdQULHbqQF6scCPSUVVcul6DQCqqLvZbVY/9yUCqyZ+vwvSQlBZvDDS2
 dBAYnP/RHnXjwQY3bpxNHFrK1NAosQwDsferoM7nMoaCItC+XCQVDB3kqXRDtdne
 nNxD7Ph/EsJI7Zrfh3j+F4cjuQf86iOJJg4rmYN0qBu4H4H0To05hTTx2ZzRQDP4
 pAT6LiBdOi49M+6DkZjvMdqBNXg+UdUjqhYfccsqv17ZT+Ld5HAiz2P1EftvwCef
 RanUrQTdJDZKlneU66m/rBeYbkxQItwh3LOT+Iuwqyj0xoxaxa4AXakBeUgtcfKs
 xQzku/7M
 =KgqH
 -----END PGP SIGNATURE-----

Merge tag 'i2c-fwnode-api-2023017' of https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux

Wolfram Sang says:

====================
Immutable branch adding fwnode API to the I2C core

I2C changes requested by Russell King.
This allows him to rework SFP code further.

* tag 'i2c-fwnode-api-2023017' of https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux:
  i2c: add fwnode APIs
====================

Link: https://lore.kernel.org/r/Y8ZhI4g0wsvpjokd@ninjato/
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Jakub Kicinski 2023-01-17 19:16:28 -08:00
commit f3a1e0c896
4 changed files with 121 additions and 82 deletions

View File

@ -442,18 +442,7 @@ EXPORT_SYMBOL_GPL(i2c_acpi_find_adapter_by_handle);
static struct i2c_client *i2c_acpi_find_client_by_adev(struct acpi_device *adev)
{
struct device *dev;
struct i2c_client *client;
dev = bus_find_device_by_acpi_dev(&i2c_bus_type, adev);
if (!dev)
return NULL;
client = i2c_verify_client(dev);
if (!client)
put_device(dev);
return client;
return i2c_find_device_by_fwnode(acpi_fwnode_handle(adev));
}
static int i2c_acpi_notify(struct notifier_block *nb, unsigned long value,

View File

@ -1012,6 +1012,35 @@ void i2c_unregister_device(struct i2c_client *client)
}
EXPORT_SYMBOL_GPL(i2c_unregister_device);
/**
* i2c_find_device_by_fwnode() - find an i2c_client for the fwnode
* @fwnode: &struct fwnode_handle corresponding to the &struct i2c_client
*
* Look up and return the &struct i2c_client corresponding to the @fwnode.
* If no client can be found, or @fwnode is NULL, this returns NULL.
*
* The user must call put_device(&client->dev) once done with the i2c client.
*/
struct i2c_client *i2c_find_device_by_fwnode(struct fwnode_handle *fwnode)
{
struct i2c_client *client;
struct device *dev;
if (!fwnode)
return NULL;
dev = bus_find_device_by_fwnode(&i2c_bus_type, fwnode);
if (!dev)
return NULL;
client = i2c_verify_client(dev);
if (!client)
put_device(dev);
return client;
}
EXPORT_SYMBOL(i2c_find_device_by_fwnode);
static const struct i2c_device_id dummy_id[] = {
{ "dummy", 0 },
@ -1761,6 +1790,75 @@ int devm_i2c_add_adapter(struct device *dev, struct i2c_adapter *adapter)
}
EXPORT_SYMBOL_GPL(devm_i2c_add_adapter);
static int i2c_dev_or_parent_fwnode_match(struct device *dev, const void *data)
{
if (dev_fwnode(dev) == data)
return 1;
if (dev->parent && dev_fwnode(dev->parent) == data)
return 1;
return 0;
}
/**
* i2c_find_adapter_by_fwnode() - find an i2c_adapter for the fwnode
* @fwnode: &struct fwnode_handle corresponding to the &struct i2c_adapter
*
* Look up and return the &struct i2c_adapter corresponding to the @fwnode.
* If no adapter can be found, or @fwnode is NULL, this returns NULL.
*
* The user must call put_device(&adapter->dev) once done with the i2c adapter.
*/
struct i2c_adapter *i2c_find_adapter_by_fwnode(struct fwnode_handle *fwnode)
{
struct i2c_adapter *adapter;
struct device *dev;
if (!fwnode)
return NULL;
dev = bus_find_device(&i2c_bus_type, NULL, fwnode,
i2c_dev_or_parent_fwnode_match);
if (!dev)
return NULL;
adapter = i2c_verify_adapter(dev);
if (!adapter)
put_device(dev);
return adapter;
}
EXPORT_SYMBOL(i2c_find_adapter_by_fwnode);
/**
* i2c_get_adapter_by_fwnode() - find an i2c_adapter for the fwnode
* @fwnode: &struct fwnode_handle corresponding to the &struct i2c_adapter
*
* Look up and return the &struct i2c_adapter corresponding to the @fwnode,
* and increment the adapter module's use count. If no adapter can be found,
* or @fwnode is NULL, this returns NULL.
*
* The user must call i2c_put_adapter(adapter) once done with the i2c adapter.
* Note that this is different from i2c_find_adapter_by_node().
*/
struct i2c_adapter *i2c_get_adapter_by_fwnode(struct fwnode_handle *fwnode)
{
struct i2c_adapter *adapter;
adapter = i2c_find_adapter_by_fwnode(fwnode);
if (!adapter)
return NULL;
if (!try_module_get(adapter->owner)) {
put_device(&adapter->dev);
adapter = NULL;
}
return adapter;
}
EXPORT_SYMBOL(i2c_get_adapter_by_fwnode);
static void i2c_parse_timing(struct device *dev, char *prop_name, u32 *cur_val_p,
u32 def_val, bool use_def)
{

View File

@ -113,72 +113,6 @@ void of_i2c_register_devices(struct i2c_adapter *adap)
of_node_put(bus);
}
static int of_dev_or_parent_node_match(struct device *dev, const void *data)
{
if (dev->of_node == data)
return 1;
if (dev->parent)
return dev->parent->of_node == data;
return 0;
}
/* must call put_device() when done with returned i2c_client device */
struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
{
struct device *dev;
struct i2c_client *client;
dev = bus_find_device_by_of_node(&i2c_bus_type, node);
if (!dev)
return NULL;
client = i2c_verify_client(dev);
if (!client)
put_device(dev);
return client;
}
EXPORT_SYMBOL(of_find_i2c_device_by_node);
/* must call put_device() when done with returned i2c_adapter device */
struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node)
{
struct device *dev;
struct i2c_adapter *adapter;
dev = bus_find_device(&i2c_bus_type, NULL, node,
of_dev_or_parent_node_match);
if (!dev)
return NULL;
adapter = i2c_verify_adapter(dev);
if (!adapter)
put_device(dev);
return adapter;
}
EXPORT_SYMBOL(of_find_i2c_adapter_by_node);
/* must call i2c_put_adapter() when done with returned i2c_adapter device */
struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node)
{
struct i2c_adapter *adapter;
adapter = of_find_i2c_adapter_by_node(node);
if (!adapter)
return NULL;
if (!try_module_get(adapter->owner)) {
put_device(&adapter->dev);
adapter = NULL;
}
return adapter;
}
EXPORT_SYMBOL(of_get_i2c_adapter_by_node);
static const struct of_device_id*
i2c_of_match_device_sysfs(const struct of_device_id *matches,
struct i2c_client *client)

View File

@ -965,15 +965,33 @@ int i2c_handle_smbus_host_notify(struct i2c_adapter *adap, unsigned short addr);
#endif /* I2C */
#if IS_ENABLED(CONFIG_OF)
/* must call put_device() when done with returned i2c_client device */
struct i2c_client *of_find_i2c_device_by_node(struct device_node *node);
struct i2c_client *i2c_find_device_by_fwnode(struct fwnode_handle *fwnode);
/* must call put_device() when done with returned i2c_adapter device */
struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node);
struct i2c_adapter *i2c_find_adapter_by_fwnode(struct fwnode_handle *fwnode);
/* must call i2c_put_adapter() when done with returned i2c_adapter device */
struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node);
struct i2c_adapter *i2c_get_adapter_by_fwnode(struct fwnode_handle *fwnode);
#if IS_ENABLED(CONFIG_OF)
/* must call put_device() when done with returned i2c_client device */
static inline struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
{
return i2c_find_device_by_fwnode(of_fwnode_handle(node));
}
/* must call put_device() when done with returned i2c_adapter device */
static inline struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node)
{
return i2c_find_adapter_by_fwnode(of_fwnode_handle(node));
}
/* must call i2c_put_adapter() when done with returned i2c_adapter device */
static inline struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node)
{
return i2c_get_adapter_by_fwnode(of_fwnode_handle(node));
}
const struct of_device_id
*i2c_of_match_device(const struct of_device_id *matches,