mirror of
https://github.com/torvalds/linux.git
synced 2026-11-06 21:58:01 +01:00
i2c: mux: Propagate firmware nodes to channel adapters
Device Tree channel nodes are associated with the adapters created by i2c-mux, but equivalent firmware-node descriptions are not. Use generic firmware-node operations for the existing channel lookup and associate the returned node with the adapter. Do not restrict the lookup by firmware-node type, so Device Tree, software nodes, and ACPI descriptions all follow the same property traversal. The existing acpi_preset_companion() call remains in place for the standard ACPI channel association. Keep a separate reference to the node returned by the generic lookup because acpi_preset_companion() may replace the device's primary firmware node. Release the saved reference after adapter deletion. Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com> Acked-by: Peter Rosin <peda@axentia.se> Signed-off-by: Andi Shyti <andi.shyti@kernel.org> Link: https://patch.msgid.link/00b33b4b352848ff87dd9089190b35d8732676f3.1788623619.git.ahmadexp@gmail.com
This commit is contained in:
parent
ff9abb5161
commit
25083d5c01
|
|
@ -24,7 +24,7 @@
|
|||
#include <linux/i2c-mux.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/property.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/sysfs.h>
|
||||
|
||||
|
|
@ -33,6 +33,7 @@ struct i2c_mux_priv {
|
|||
struct i2c_adapter adap;
|
||||
struct i2c_algorithm algo;
|
||||
struct i2c_mux_core *muxc;
|
||||
struct fwnode_handle *channel_node;
|
||||
u32 chan_id;
|
||||
};
|
||||
|
||||
|
|
@ -264,48 +265,48 @@ static const struct i2c_lock_operations i2c_parent_lock_ops = {
|
|||
.unlock_bus = i2c_parent_unlock_bus,
|
||||
};
|
||||
|
||||
static struct device_node *
|
||||
static struct fwnode_handle *
|
||||
i2c_mux_get_channel_node(struct i2c_mux_core *muxc, u32 chan_id)
|
||||
{
|
||||
struct device_node *dev_node;
|
||||
struct device_node *mux_node;
|
||||
struct device_node *child;
|
||||
struct fwnode_handle *dev_node;
|
||||
struct fwnode_handle *mux_node;
|
||||
struct fwnode_handle *child;
|
||||
u32 reg;
|
||||
int ret;
|
||||
|
||||
dev_node = dev_of_node(muxc->dev);
|
||||
dev_node = dev_fwnode(muxc->dev);
|
||||
if (!dev_node)
|
||||
return NULL;
|
||||
|
||||
if (muxc->arbitrator)
|
||||
mux_node = of_get_child_by_name(dev_node, "i2c-arb");
|
||||
mux_node = fwnode_get_named_child_node(dev_node, "i2c-arb");
|
||||
else if (muxc->gate)
|
||||
mux_node = of_get_child_by_name(dev_node, "i2c-gate");
|
||||
mux_node = fwnode_get_named_child_node(dev_node, "i2c-gate");
|
||||
else
|
||||
mux_node = of_get_child_by_name(dev_node, "i2c-mux");
|
||||
mux_node = fwnode_get_named_child_node(dev_node, "i2c-mux");
|
||||
|
||||
if (mux_node) {
|
||||
/* A "reg" property indicates an old-style DT entry */
|
||||
if (!of_property_read_u32(mux_node, "reg", ®)) {
|
||||
of_node_put(mux_node);
|
||||
/* A "reg" property indicates an old-style firmware entry. */
|
||||
if (!fwnode_property_read_u32(mux_node, "reg", ®)) {
|
||||
fwnode_handle_put(mux_node);
|
||||
mux_node = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!mux_node)
|
||||
mux_node = of_node_get(dev_node);
|
||||
mux_node = fwnode_handle_get(dev_node);
|
||||
else if (muxc->arbitrator || muxc->gate)
|
||||
return mux_node;
|
||||
|
||||
for_each_child_of_node(mux_node, child) {
|
||||
ret = of_property_read_u32(child, "reg", ®);
|
||||
fwnode_for_each_child_node(mux_node, child) {
|
||||
ret = fwnode_property_read_u32(child, "reg", ®);
|
||||
if (ret)
|
||||
continue;
|
||||
if (chan_id == reg)
|
||||
break;
|
||||
}
|
||||
|
||||
of_node_put(mux_node);
|
||||
fwnode_handle_put(mux_node);
|
||||
return child;
|
||||
}
|
||||
|
||||
|
|
@ -368,11 +369,9 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc,
|
|||
else
|
||||
priv->adap.lock_ops = &i2c_parent_lock_ops;
|
||||
|
||||
/*
|
||||
* Try to populate the mux adapter's of_node, expands to
|
||||
* nothing if !CONFIG_OF.
|
||||
*/
|
||||
priv->adap.dev.of_node = i2c_mux_get_channel_node(muxc, chan_id);
|
||||
/* Associate the mux adapter with its channel firmware node. */
|
||||
priv->channel_node = i2c_mux_get_channel_node(muxc, chan_id);
|
||||
device_set_node(&priv->adap.dev, priv->channel_node);
|
||||
|
||||
/*
|
||||
* Associate the mux channel with an ACPI node.
|
||||
|
|
@ -416,7 +415,7 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc,
|
|||
return 0;
|
||||
|
||||
err_free_priv:
|
||||
of_node_put(priv->adap.dev.of_node);
|
||||
fwnode_handle_put(priv->channel_node);
|
||||
kfree(priv);
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -429,7 +428,6 @@ void i2c_mux_del_adapters(struct i2c_mux_core *muxc)
|
|||
while (muxc->num_adapters) {
|
||||
struct i2c_adapter *adap = muxc->adapter[--muxc->num_adapters];
|
||||
struct i2c_mux_priv *priv = adap->algo_data;
|
||||
struct device_node *np = adap->dev.of_node;
|
||||
|
||||
muxc->adapter[muxc->num_adapters] = NULL;
|
||||
|
||||
|
|
@ -439,7 +437,7 @@ void i2c_mux_del_adapters(struct i2c_mux_core *muxc)
|
|||
|
||||
sysfs_remove_link(&priv->adap.dev.kobj, "mux_device");
|
||||
i2c_del_adapter(adap);
|
||||
of_node_put(np);
|
||||
fwnode_handle_put(priv->channel_node);
|
||||
kfree(priv);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user