From: Guenter Roeck <linux@roeck-us.net>
To: Vladimir Zapolskiy <vz@mleia.com>, Peter Rosin <peda@axentia.se>,
linux-kernel@vger.kernel.org, Ken Chen <chen.kenyy@inventec.com>
Cc: Wolfram Sang <wsa@the-dreams.de>,
joel@jms.id.au, linux-i2c@vger.kernel.org
Subject: Re: [PATCH 3/3] i2c: mux: pca9541: prepare for PCA9641 support
Date: Tue, 20 Mar 2018 18:19:18 -0700 [thread overview]
Message-ID: <3cfc6e53-a86d-8ef1-b83d-9f3c1b3d7b9c@roeck-us.net> (raw)
In-Reply-To: <bc464354-660a-00ed-e713-eec987407695@mleia.com>
On 03/20/2018 04:17 PM, Vladimir Zapolskiy wrote:
> Hi Peter, Ken,
>
> On 03/20/2018 11:32 AM, Peter Rosin wrote:
>> Make the arbitrate and release_bus implementation chip specific.
>>
>
> by chance I took a look at the original implementation done by Ken, and
> I would say that this 3/3 change is an overkill as a too generic one.
> Is there any next observable extension? And do two abstracted (*arbitrate)
> and (*release_bus) cover it well? Probably no.
>
> At first it would be simpler to add a new chip id field into struct pca9541
> (struct rename would be needed of course), and do a selection of specific
> pca9x41_arbitrate() and pca9x41_release_bus() depending on it:
>
FWIW, I very much prefer Peter's code. I think it is much cleaner.
Guenter
> ----8<----
> diff --git a/drivers/i2c/muxes/i2c-mux-pca9541.c b/drivers/i2c/muxes/i2c-mux-pca9541.c
> index 47685eb..a40e6d8 100644
> --- a/drivers/i2c/muxes/i2c-mux-pca9541.c
> +++ b/drivers/i2c/muxes/i2c-mux-pca9541.c
> @@ -70,8 +70,13 @@
> #define SELECT_DELAY_SHORT 50
> #define SELECT_DELAY_LONG 1000
>
> +enum chip_id {
> + pca9541,
> +};
> +
> struct pca9541 {
> struct i2c_client *client;
> + enum chip_id id;
> unsigned long select_timeout;
> unsigned long arb_timeout;
> };
> @@ -188,10 +193,13 @@ static int pca9541_reg_read(struct i2c_client *client, u8 command)
> */
>
> /* Release bus. Also reset NTESTON and BUSINIT if it was set. */
> -static void pca9541_release_bus(struct i2c_client *client)
> +static void pca9541_release_bus(struct i2c_client *client, enum chip_id id)
> {
> int reg;
>
> + if (id != pca9541)
> + return;
> +
> reg = pca9541_reg_read(client, PCA9541_CONTROL);
> if (reg >= 0 && !pca9541_busoff(reg) && pca9541_mybus(reg))
> pca9541_reg_write(client, PCA9541_CONTROL,
> @@ -235,12 +243,15 @@ static const u8 pca9541_control[16] = {
> * 0 : bus not acquired
> * 1 : bus acquired
> */
> -static int pca9541_arbitrate(struct i2c_client *client)
> +static int pca9541_arbitrate(struct i2c_client *client, enum chip_id id)
> {
> struct i2c_mux_core *muxc = i2c_get_clientdata(client);
> struct pca9541 *data = i2c_mux_priv(muxc);
> int reg;
>
> + if (id != pca9541)
> + return -EOPNOTSUPP;
> +
> reg = pca9541_reg_read(client, PCA9541_CONTROL);
> if (reg < 0)
> return reg;
> @@ -318,7 +329,7 @@ static int pca9541_select_chan(struct i2c_mux_core *muxc, u32 chan)
> /* force bus ownership after this time */
>
> do {
> - ret = pca9541_arbitrate(client);
> + ret = pca9541_arbitrate(client, data->id);
> if (ret)
> return ret < 0 ? ret : 0;
>
> @@ -336,7 +347,7 @@ static int pca9541_release_chan(struct i2c_mux_core *muxc, u32 chan)
> struct pca9541 *data = i2c_mux_priv(muxc);
> struct i2c_client *client = data->client;
>
> - pca9541_release_bus(client);
> + pca9541_release_bus(client, data->id);
> return 0;
> }
>
> @@ -361,7 +372,7 @@ static int pca9541_probe(struct i2c_client *client,
> * We have to lock the adapter before releasing the bus.
> */
> i2c_lock_adapter(adap);
> - pca9541_release_bus(client);
> + pca9541_release_bus(client, pca9541);
> i2c_unlock_adapter(adap);
>
> /* Create mux adapter */
> @@ -377,6 +388,7 @@ static int pca9541_probe(struct i2c_client *client,
>
> data = i2c_mux_priv(muxc);
> data->client = client;
> + data->id = pca9541;
>
> i2c_set_clientdata(client, muxc);
>
> ----8<----
>
>
>> Signed-off-by: Peter Rosin <peda@axentia.se>
>> ---
>> drivers/i2c/muxes/i2c-mux-pca9541.c | 62 +++++++++++++++++++++++++++----------
>> 1 file changed, 45 insertions(+), 17 deletions(-)
>>
>
> The change above is trivial and it does not cancel any further
> extensions similar to your idea, the open question is if there
> is a demand right at the moment.
>
>> diff --git a/drivers/i2c/muxes/i2c-mux-pca9541.c b/drivers/i2c/muxes/i2c-mux-pca9541.c
>> index 47685eb4e0e9..cac629e36bf8 100644
>> --- a/drivers/i2c/muxes/i2c-mux-pca9541.c
>> +++ b/drivers/i2c/muxes/i2c-mux-pca9541.c
>> @@ -23,6 +23,7 @@
>> #include <linux/i2c-mux.h>
>> #include <linux/jiffies.h>
>> #include <linux/module.h>
>> +#include <linux/of_device.h>
>> #include <linux/platform_data/pca954x.h>
>> #include <linux/slab.h>
>>
>> @@ -70,26 +71,22 @@
>> #define SELECT_DELAY_SHORT 50
>> #define SELECT_DELAY_LONG 1000
>>
>> -struct pca9541 {
>> - struct i2c_client *client;
>> - unsigned long select_timeout;
>> - unsigned long arb_timeout;
>> +enum chip_name {
>
> chip_name sound like a string storage, chip_id might be better here.
>
>> + pca9541,
>> };
>>
>
> --
> With best wishes,
> Vladimir
>
next prev parent reply other threads:[~2018-03-21 1:19 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-20 6:19 [PATCH linux dev-4.16 v2] i2c: muxes: pca9641: new driver Ken Chen
2018-03-20 6:34 ` Joel Stanley
2018-03-20 9:31 ` Peter Rosin
2018-03-20 9:31 ` [PATCH 1/3] i2c: mux: pca9541: use the BIT macro Peter Rosin
2018-03-20 13:18 ` Guenter Roeck
2018-03-20 23:25 ` Vladimir Zapolskiy
2018-03-20 9:31 ` [PATCH 2/3] i2c: mux: pca9541: namespace cleanup Peter Rosin
2018-03-20 13:20 ` Guenter Roeck
2018-03-20 21:48 ` Peter Rosin
2018-03-20 21:57 ` Guenter Roeck
2018-03-20 23:24 ` Vladimir Zapolskiy
2018-03-21 5:53 ` Peter Rosin
2018-03-21 6:54 ` Vladimir Zapolskiy
2018-03-21 7:35 ` Peter Rosin
2018-03-20 9:32 ` [PATCH 3/3] i2c: mux: pca9541: prepare for PCA9641 support Peter Rosin
2018-03-20 13:22 ` Guenter Roeck
2018-03-20 23:17 ` Vladimir Zapolskiy
2018-03-21 1:19 ` Guenter Roeck [this message]
2018-03-21 7:01 ` Vladimir Zapolskiy
2018-03-21 8:09 ` Peter Rosin
2018-03-21 7:05 ` Vladimir Zapolskiy
2018-04-11 9:37 ` [PATCH linux dev-4.16 v2] i2c: muxes: pca9641: new driver Peter Rosin
2018-04-13 6:59 ` ChenKenYY 陳永營 TAO
2018-04-13 7:27 ` Peter Rosin
2018-04-16 7:37 ` ChenKenYY 陳永營 TAO
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=3cfc6e53-a86d-8ef1-b83d-9f3c1b3d7b9c@roeck-us.net \
--to=linux@roeck-us.net \
--cc=chen.kenyy@inventec.com \
--cc=joel@jms.id.au \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peda@axentia.se \
--cc=vz@mleia.com \
--cc=wsa@the-dreams.de \
/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).