aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Rosin <peda@axentia.se>2016-04-20 02:42:47 -0400
committerWolfram Sang <wsa@the-dreams.de>2016-04-22 09:00:18 -0400
commitb6e3b7171b1e416963e36bb91ff6cce1caaaf675 (patch)
tree77aaf8dac1d43c13358332a2887df2609bca1934
parent05e0dfd0311bd6dd3cdb6cb32acd1e701c451e9b (diff)
of/unittest: convert to use an explicit i2c mux core
Allocate an explicit i2c mux core to handle parent and child adapters etc. Update the select op to be in terms of the i2c mux core instead of the child adapter. Acked-by: Rob Herring <robh@kernel.org> Signed-off-by: Peter Rosin <peda@axentia.se> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
-rw-r--r--drivers/of/unittest.c37
1 files changed, 12 insertions, 25 deletions
diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index e986e6ee52e0..c1ebbfb79453 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -1692,13 +1692,7 @@ static struct i2c_driver unittest_i2c_dev_driver = {
1692 1692
1693#if IS_BUILTIN(CONFIG_I2C_MUX) 1693#if IS_BUILTIN(CONFIG_I2C_MUX)
1694 1694
1695struct unittest_i2c_mux_data { 1695static int unittest_i2c_mux_select_chan(struct i2c_mux_core *muxc, u32 chan)
1696 int nchans;
1697 struct i2c_adapter *adap[];
1698};
1699
1700static int unittest_i2c_mux_select_chan(struct i2c_adapter *adap,
1701 void *client, u32 chan)
1702{ 1696{
1703 return 0; 1697 return 0;
1704} 1698}
@@ -1706,11 +1700,11 @@ static int unittest_i2c_mux_select_chan(struct i2c_adapter *adap,
1706static int unittest_i2c_mux_probe(struct i2c_client *client, 1700static int unittest_i2c_mux_probe(struct i2c_client *client,
1707 const struct i2c_device_id *id) 1701 const struct i2c_device_id *id)
1708{ 1702{
1709 int ret, i, nchans, size; 1703 int ret, i, nchans;
1710 struct device *dev = &client->dev; 1704 struct device *dev = &client->dev;
1711 struct i2c_adapter *adap = to_i2c_adapter(dev->parent); 1705 struct i2c_adapter *adap = to_i2c_adapter(dev->parent);
1712 struct device_node *np = client->dev.of_node, *child; 1706 struct device_node *np = client->dev.of_node, *child;
1713 struct unittest_i2c_mux_data *stm; 1707 struct i2c_mux_core *muxc;
1714 u32 reg, max_reg; 1708 u32 reg, max_reg;
1715 1709
1716 dev_dbg(dev, "%s for node @%s\n", __func__, np->full_name); 1710 dev_dbg(dev, "%s for node @%s\n", __func__, np->full_name);
@@ -1734,25 +1728,20 @@ static int unittest_i2c_mux_probe(struct i2c_client *client,
1734 return -EINVAL; 1728 return -EINVAL;
1735 } 1729 }
1736 1730
1737 size = offsetof(struct unittest_i2c_mux_data, adap[nchans]); 1731 muxc = i2c_mux_alloc(adap, dev, nchans, 0, 0,
1738 stm = devm_kzalloc(dev, size, GFP_KERNEL); 1732 unittest_i2c_mux_select_chan, NULL);
1739 if (!stm) { 1733 if (!muxc)
1740 dev_err(dev, "Out of memory\n");
1741 return -ENOMEM; 1734 return -ENOMEM;
1742 }
1743 stm->nchans = nchans;
1744 for (i = 0; i < nchans; i++) { 1735 for (i = 0; i < nchans; i++) {
1745 stm->adap[i] = i2c_add_mux_adapter(adap, dev, client, 1736 ret = i2c_mux_add_adapter(muxc, 0, i, 0);
1746 0, i, 0, unittest_i2c_mux_select_chan, NULL); 1737 if (ret) {
1747 if (!stm->adap[i]) {
1748 dev_err(dev, "Failed to register mux #%d\n", i); 1738 dev_err(dev, "Failed to register mux #%d\n", i);
1749 for (i--; i >= 0; i--) 1739 i2c_mux_del_adapters(muxc);
1750 i2c_del_mux_adapter(stm->adap[i]);
1751 return -ENODEV; 1740 return -ENODEV;
1752 } 1741 }
1753 } 1742 }
1754 1743
1755 i2c_set_clientdata(client, stm); 1744 i2c_set_clientdata(client, muxc);
1756 1745
1757 return 0; 1746 return 0;
1758}; 1747};
@@ -1761,12 +1750,10 @@ static int unittest_i2c_mux_remove(struct i2c_client *client)
1761{ 1750{
1762 struct device *dev = &client->dev; 1751 struct device *dev = &client->dev;
1763 struct device_node *np = client->dev.of_node; 1752 struct device_node *np = client->dev.of_node;
1764 struct unittest_i2c_mux_data *stm = i2c_get_clientdata(client); 1753 struct i2c_mux_core *muxc = i2c_get_clientdata(client);
1765 int i;
1766 1754
1767 dev_dbg(dev, "%s for node @%s\n", __func__, np->full_name); 1755 dev_dbg(dev, "%s for node @%s\n", __func__, np->full_name);
1768 for (i = stm->nchans - 1; i >= 0; i--) 1756 i2c_mux_del_adapters(muxc);
1769 i2c_del_mux_adapter(stm->adap[i]);
1770 return 0; 1757 return 0;
1771} 1758}
1772 1759