From: Peter Rosin <peda@axentia.se>
To: Pantelis Antoniou <pantelis.antoniou@konsulko.com>,
Lee Jones <lee.jones@linaro.org>
Cc: Linus Walleij <linus.walleij@linaro.org>,
Alexandre Courbot <gnurou@gmail.com>,
Rob Herring <robh+dt@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Frank Rowand <frowand.list@gmail.com>,
Wolfram Sang <wsa@the-dreams.de>,
Richard Purdie <rpurdie@rpsys.net>,
Jacek Anaszewski <j.anaszewski@samsung.com>,
Jean Delvare <jdelvare@suse.com>,
Avirup Banerjee <abanerjee@juniper.net>,
Georgi Vlaev <gvlaev@juniper.net>,
Guenter Roeck <linux@roeck-us.net>,
JawaharBalaji Thirumalaisamy <jawaharb@juniper.net>,
<devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-gpio@vger.kernel.org>, <linux-i2c@vger.kernel.org>,
<linux-leds@vger.kernel.org>, <linux-hwmon@vger.kernel.org>
Subject: Re: [PATCH 03/10] i2c/muxes: Juniper I2CS RE mux
Date: Mon, 10 Oct 2016 17:29:26 +0200 [thread overview]
Message-ID: <f22cb2cb-0122-bed2-899d-b6e7f4da1fa8@axentia.se> (raw)
In-Reply-To: <1475853669-22480-4-git-send-email-pantelis.antoniou@konsulko.com>
On 2016-10-07 17:21, Pantelis Antoniou wrote:
> From: Georgi Vlaev <gvlaev@juniper.net>
>
> Add support for Juniper I2C Slave RE multiplexer driver.
>
> This I2C multiplexer driver allows the RE to access some of
> the FPC I2C buses. It's compatible only with the FPC variant of the
> I2CS.
>
> Signed-off-by: Georgi Vlaev <gvlaev@juniper.net>
> Signed-off-by: Guenter Roeck <groeck@juniper.net>
> [Ported from Juniper kernel]
> Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
> ---
> drivers/i2c/muxes/Kconfig | 10 +++
> drivers/i2c/muxes/Makefile | 1 +
> drivers/i2c/muxes/i2c-mux-i2cs.c | 155 +++++++++++++++++++++++++++++++++++++++
> 3 files changed, 166 insertions(+)
> create mode 100644 drivers/i2c/muxes/i2c-mux-i2cs.c
>
> diff --git a/drivers/i2c/muxes/Kconfig b/drivers/i2c/muxes/Kconfig
> index f45a9cb..c95380d 100644
> --- a/drivers/i2c/muxes/Kconfig
> +++ b/drivers/i2c/muxes/Kconfig
> @@ -30,6 +30,16 @@ config I2C_MUX_GPIO
> This driver can also be built as a module. If so, the module
> will be called i2c-mux-gpio.
>
> +config I2C_MUX_I2CS
> + tristate "Juniper I2C Slave MFD client RE multiplexer"
> + depends on MFD_JUNIPER_I2CS
> + help
> + Select this to enable the Juniper I2C Slave RE multiplexer driver
> + on the relevant Juniper platforms.
> +
> + This driver can also be built as a module. If so, the module
> + will be called i2c-mux-i2cs.
> +
> config I2C_MUX_PCA9541
> tristate "NXP PCA9541 I2C Master Selector"
> help
> diff --git a/drivers/i2c/muxes/Makefile b/drivers/i2c/muxes/Makefile
> index 78d8cba..45b4287 100644
> --- a/drivers/i2c/muxes/Makefile
> +++ b/drivers/i2c/muxes/Makefile
> @@ -6,6 +6,7 @@ obj-$(CONFIG_I2C_ARB_GPIO_CHALLENGE) += i2c-arb-gpio-challenge.o
> obj-$(CONFIG_I2C_DEMUX_PINCTRL) += i2c-demux-pinctrl.o
>
> obj-$(CONFIG_I2C_MUX_GPIO) += i2c-mux-gpio.o
> +obj-$(CONFIG_I2C_MUX_I2CS) += i2c-mux-i2cs.o
> obj-$(CONFIG_I2C_MUX_PCA9541) += i2c-mux-pca9541.o
> obj-$(CONFIG_I2C_MUX_PCA954x) += i2c-mux-pca954x.o
> obj-$(CONFIG_I2C_MUX_PINCTRL) += i2c-mux-pinctrl.o
> diff --git a/drivers/i2c/muxes/i2c-mux-i2cs.c b/drivers/i2c/muxes/i2c-mux-i2cs.c
Please name the file i2c-mux-jnx-i2cs.c. Or something else a bit more
specific.
> new file mode 100644
> index 0000000..c498a44
> --- /dev/null
> +++ b/drivers/i2c/muxes/i2c-mux-i2cs.c
> @@ -0,0 +1,155 @@
> +/*
> + * Juniper Networks I2CS RE mux driver
> + *
> + * Copyright (C) 2012, 2013, 2014 Juniper Networks. All rights reserved.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + */
> +
> +#include <linux/init.h>
init?
> +#include <linux/device.h>
> +#include <linux/module.h>
> +#include <linux/kernel.h>
> +#include <linux/i2c.h>
> +#include <linux/i2c-mux.h>
> +#include <linux/regmap.h>
regmap?
> +#include <linux/platform_device.h>
> +#include <linux/mfd/jnx-i2cs-core.h>
> +
> +#define MISC_IO_RE_EN 0x01
> +
> +/*
> + * Read/write to mux register.
> + * Don't use i2c_transfer()/i2c_smbus_xfer()
> + * for this as they will try to lock adapter a second time
> + */
If this is the only concern, you should consider making this
gate mux-locked instead of parent-locked. Then you can avoid
all these unlocked games. But there are caveats, so you better
read Documentation/i2c/i2c-topology for the details before
you change.
> +static int i2cs_mux_read_byte(struct i2c_client *client,
> + u8 offset, u8 *val)
> +{
> + struct i2c_msg msg[2];
> +
> + msg[0].addr = client->addr;
> + msg[0].flags = 0;
> + msg[0].len = 1;
> + msg[0].buf = &offset;
> +
> + msg[1].addr = client->addr;
> + msg[1].flags = I2C_M_RD;
> + msg[1].len = 1;
> + msg[1].buf = val;
> +
> + return client->adapter->algo->master_xfer(client->adapter, msg, 2);
If you still want to be parent-locked, use __i2c_transfer. In
either case, consider adding code that handles the case of no
algo->master_xfer (some i2c adapters only support
algo->smbus_xfer).
> +}
> +
> +static int i2cs_mux_write_byte(struct i2c_client *client, u8 offset, u8 val)
> +{
> + struct i2c_msg msg;
> + char buf[2];
> +
> + msg.addr = client->addr;
> + msg.flags = 0;
> + msg.len = 2;
> + buf[0] = offset;
> + buf[1] = val;
> + msg.buf = buf;
> +
> + return client->adapter->algo->master_xfer(client->adapter, &msg, 1);
> +}
> +
> +static int i2cs_mux_select(struct i2c_mux_core *muxc, u32 chan)
> +{
> + int ret;
> + u8 val = 0;
> + struct i2c_client *client = i2c_mux_priv(muxc);
> +
> + ret = i2cs_mux_read_byte(client, I2CS_MISC_IO, &val);
> + if (ret < 0)
> + return ret;
> +
> + val |= MISC_IO_RE_EN;
> + ret = i2cs_mux_write_byte(client, I2CS_MISC_IO, val);
> +
To me, it sounds as if I2CS_MISC_IO is a register with more than
one bit and that you are open to nasty races here. You probably
need to interact with the mfd parent and arrange some locking.
> + return ret;
> +}
> +
> +static int i2cs_mux_deselect(struct i2c_mux_core *muxc, u32 chan)
> +{
> + int ret;
> + u8 val = 0;
> + struct i2c_client *client = i2c_mux_priv(muxc);
> +
> + ret = i2cs_mux_read_byte(client, I2CS_MISC_IO, &val);
> + if (ret < 0)
> + return ret;
> +
> + val &= ~MISC_IO_RE_EN;
> + ret = i2cs_mux_write_byte(client, I2CS_MISC_IO, val);
> +
> + return 0;
> +}
> +
> +static int i2cs_mux_probe(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> + struct i2c_client *client;
> + struct i2c_mux_core *muxc;
> + int ret;
> +
> + if (!dev->parent)
> + return -ENODEV;
> +
> + client = i2c_verify_client(dev->parent);
> + if (!client)
> + return -ENODEV;
> +
> + muxc = i2c_mux_alloc(client->adapter, &client->dev, 1, 0, 0,
> + i2cs_mux_select, i2cs_mux_deselect);
You only have one child adapter, making this a gate. Please use
the I2C_MUX_GATE flag which should be available in 4.9. This also
affects the preferred devicetree, see comment on that patch.
> + if (!muxc)
> + return -ENOMEM;
> + muxc->priv = client;
> +
> + ret = i2c_mux_add_adapter(muxc, 0, 0, 0);
> + if (ret)
> + return ret;
> +
> + platform_set_drvdata(pdev, muxc);
> +
> + return 0;
> +}
> +
> +static int i2cs_mux_remove(struct platform_device *pdev)
> +{
> + i2c_mux_del_adapters(platform_get_drvdata(pdev));
> +
> + return 0;
> +}
> +
> +static const struct of_device_id i2cs_mux_of_match[] = {
> + { .compatible = "jnx,i2c-mux-i2cs", },
> + {},
> +};
> +MODULE_DEVICE_TABLE(of, i2cs_mux_of_match);
> +
> +static struct platform_driver i2cs_mux_driver = {
> + .driver = {
> + .name = "i2c-mux-i2cs",
> + .owner = THIS_MODULE,
Drop this line.
Cheers,
Peter
> + .of_match_table = of_match_ptr(i2cs_mux_of_match),
> + },
> + .probe = i2cs_mux_probe,
> + .remove = i2cs_mux_remove,
> +};
> +module_platform_driver(i2cs_mux_driver);
> +
> +MODULE_DESCRIPTION("Juniper Networks I2CS RE Mux driver");
> +MODULE_AUTHOR("Georgi Vlaev <gvlaev@juniper.net>");
> +MODULE_LICENSE("GPL");
> +MODULE_ALIAS("platform:i2c-mux-i2cs");
>
next prev parent reply other threads:[~2016-10-10 18:02 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-07 15:20 [PATCH 00/10] Introduce Juniper I2CS FPGA driver Pantelis Antoniou
2016-10-07 15:21 ` [PATCH 01/10] mfd: Add Juniper I2CS MFD driver Pantelis Antoniou
2016-10-07 15:21 ` [PATCH 02/10] mfd: dt-bindings: Add bindings for the Juniper I2CS MFD Pantelis Antoniou
2016-10-10 20:23 ` Rob Herring
2016-10-17 19:10 ` Pantelis Antoniou
2016-10-07 15:21 ` [PATCH 03/10] i2c/muxes: Juniper I2CS RE mux Pantelis Antoniou
2016-10-10 15:29 ` Peter Rosin [this message]
2016-10-07 15:21 ` [PATCH 04/10] i2c: i2c-mux-i2cs: Add device tree bindings Pantelis Antoniou
2016-10-10 15:48 ` Peter Rosin
2016-10-17 19:11 ` Pantelis Antoniou
2016-10-10 20:25 ` Rob Herring
2016-10-07 15:21 ` [PATCH 05/10] gpio: i2cs: Juniper I2CS to GPIO pin mapping driver Pantelis Antoniou
2016-10-21 8:41 ` Linus Walleij
2016-10-07 15:21 ` [PATCH 06/10] gpio: gpio-i2cs: Document bindings of I2CS FPGA GPIO block Pantelis Antoniou
2016-10-21 8:59 ` Linus Walleij
2016-10-07 15:21 ` [PATCH 07/10] leds: i2cs: Add I2CS FPGA leds driver Pantelis Antoniou
2016-10-10 9:41 ` Jacek Anaszewski
2016-10-07 15:21 ` [PATCH 08/10] leds: Add binding for Juniper's I2CS FPGA Pantelis Antoniou
2016-10-10 9:41 ` Jacek Anaszewski
2016-10-07 15:21 ` [PATCH 09/10] hwmon: Add driver for Fan Tray on Juniper I2CS FGPA Pantelis Antoniou
2016-10-07 15:21 ` [PATCH 10/10] hwmon: i2cs-fan: Add hwmon dts binding documentation Pantelis Antoniou
2016-10-10 20:29 ` Rob Herring
2016-10-17 19:12 ` Pantelis Antoniou
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=f22cb2cb-0122-bed2-899d-b6e7f4da1fa8@axentia.se \
--to=peda@axentia.se \
--cc=abanerjee@juniper.net \
--cc=devicetree@vger.kernel.org \
--cc=frowand.list@gmail.com \
--cc=gnurou@gmail.com \
--cc=gvlaev@juniper.net \
--cc=j.anaszewski@samsung.com \
--cc=jawaharb@juniper.net \
--cc=jdelvare@suse.com \
--cc=lee.jones@linaro.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=mark.rutland@arm.com \
--cc=pantelis.antoniou@konsulko.com \
--cc=robh+dt@kernel.org \
--cc=rpurdie@rpsys.net \
--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
all inboxes | Powered by JetHome®