From: Biwen Li <biwen.li@nxp.com>
To: peda@axentia.se, leoyang.li@nxp.com, robh+dt@kernel.org,
mark.rutland@arm.com
Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, Biwen Li <biwen.li@nxp.com>
Subject: [v3,2/2] i2c: mux: pca954x: support property idle-state
Date: Wed, 16 Oct 2019 12:09:20 +0800 [thread overview]
Message-ID: <20191016040920.8511-2-biwen.li@nxp.com> (raw)
In-Reply-To: <20191016040920.8511-1-biwen.li@nxp.com>
This supports property idle-state
Signed-off-by: Biwen Li <biwen.li@nxp.com>
---
Change in v3:
- update subject and description
- add a helper function pca954x_calculate_chan()
Change in v2:
- update subject and description
- add property idle-state
drivers/i2c/muxes/i2c-mux-pca954x.c | 64 ++++++++++++++++++-----------
1 file changed, 39 insertions(+), 25 deletions(-)
diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c b/drivers/i2c/muxes/i2c-mux-pca954x.c
index 923aa3a5a3dc..8777d429269c 100644
--- a/drivers/i2c/muxes/i2c-mux-pca954x.c
+++ b/drivers/i2c/muxes/i2c-mux-pca954x.c
@@ -86,7 +86,7 @@ struct pca954x {
u8 last_chan; /* last register value */
/* MUX_IDLE_AS_IS, MUX_IDLE_DISCONNECT or >= 0 for channel */
- s8 idle_state;
+ s32 idle_state;
struct i2c_client *client;
@@ -229,22 +229,25 @@ static int pca954x_reg_write(struct i2c_adapter *adap,
I2C_SMBUS_BYTE, &dummy);
}
+static int pca954x_calculate_chan(struct pca954x *data, u32 chan)
+{
+ /* we make switches look like muxes, not sure how to be smarter */
+ if (data->chip->muxtype == pca954x_ismux)
+ return chan | data->chip->enable;
+ else
+ return 1 << chan;
+}
+
static int pca954x_select_chan(struct i2c_mux_core *muxc, u32 chan)
{
struct pca954x *data = i2c_mux_priv(muxc);
struct i2c_client *client = data->client;
- const struct chip_desc *chip = data->chip;
u8 regval;
int ret = 0;
- /* we make switches look like muxes, not sure how to be smarter */
- if (chip->muxtype == pca954x_ismux)
- regval = chan | chip->enable;
- else
- regval = 1 << chan;
-
+ regval = pca954x_calculate_chan(data, chan);
/* Only select the channel if its different from the last channel */
- if (data->last_chan != regval) {
+ if ((data->last_chan & 0xff) != regval) {
ret = pca954x_reg_write(muxc->parent, client, regval);
data->last_chan = ret < 0 ? 0 : regval;
}
@@ -256,7 +259,7 @@ static int pca954x_deselect_mux(struct i2c_mux_core *muxc, u32 chan)
{
struct pca954x *data = i2c_mux_priv(muxc);
struct i2c_client *client = data->client;
- s8 idle_state;
+ s32 idle_state;
idle_state = READ_ONCE(data->idle_state);
if (idle_state >= 0)
@@ -402,6 +405,23 @@ static void pca954x_cleanup(struct i2c_mux_core *muxc)
i2c_mux_del_adapters(muxc);
}
+static int pca954x_init(struct i2c_client *client, struct pca954x *data)
+{
+ /*
+ * Write the mux register at addr to verify
+ * that the mux is in fact present. This also
+ * initializes the mux to a channel
+ * or disconnected state.
+ */
+ if (data->idle_state >= 0) {
+ data->last_chan = pca954x_calculate_chan(data, data->idle_state);
+ } else {
+ /* Disconnect multiplexer */
+ data->last_chan = 0;
+ }
+ return i2c_smbus_write_byte(client, data->last_chan);
+}
+
/*
* I2C init/probing/exit functions
*/
@@ -411,7 +431,6 @@ static int pca954x_probe(struct i2c_client *client,
struct i2c_adapter *adap = client->adapter;
struct device *dev = &client->dev;
struct device_node *np = dev->of_node;
- bool idle_disconnect_dt;
struct gpio_desc *gpio;
struct i2c_mux_core *muxc;
struct pca954x *data;
@@ -462,22 +481,18 @@ static int pca954x_probe(struct i2c_client *client,
}
}
- /* Write the mux register at addr to verify
- * that the mux is in fact present. This also
- * initializes the mux to disconnected state.
- */
- if (i2c_smbus_write_byte(client, 0) < 0) {
+ data->idle_state = MUX_IDLE_AS_IS;
+ if (np && of_property_read_u32(np, "idle-state", &data->idle_state)) {
+ if (np && of_property_read_bool(np, "i2c-mux-idle-disconnect"))
+ data->idle_state = MUX_IDLE_DISCONNECT;
+ }
+
+ ret = pca954x_init(client, data);
+ if (ret < 0) {
dev_warn(dev, "probe failed\n");
return -ENODEV;
}
- data->last_chan = 0; /* force the first selection */
- data->idle_state = MUX_IDLE_AS_IS;
-
- idle_disconnect_dt = np &&
- of_property_read_bool(np, "i2c-mux-idle-disconnect");
- if (idle_disconnect_dt)
- data->idle_state = MUX_IDLE_DISCONNECT;
ret = pca954x_irq_setup(muxc);
if (ret)
@@ -531,8 +546,7 @@ static int pca954x_resume(struct device *dev)
struct i2c_mux_core *muxc = i2c_get_clientdata(client);
struct pca954x *data = i2c_mux_priv(muxc);
- data->last_chan = 0;
- return i2c_smbus_write_byte(client, 0);
+ return pca954x_init(client, data);
}
#endif
--
2.17.1
next prev parent reply other threads:[~2019-10-16 4:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-16 4:09 [v3,1/2] dt-bindings: i2c: support property idle-state Biwen Li
2019-10-16 4:09 ` Biwen Li [this message]
2019-10-17 15:40 ` [v3,2/2] i2c: mux: pca954x: " Peter Rosin
2019-10-21 7:40 ` [EXT] " Biwen Li
2019-10-17 14:54 ` [v3,1/2] dt-bindings: i2c: " Rob Herring
2019-10-17 15:38 ` Peter Rosin
2019-10-17 16:45 ` Rob Herring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191016040920.8511-2-biwen.li@nxp.com \
--to=biwen.li@nxp.com \
--cc=devicetree@vger.kernel.org \
--cc=leoyang.li@nxp.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=peda@axentia.se \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).