From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: Ben Dooks <ben-i2c@fluff.org>
Cc: devicetree-discuss@lists.ozlabs.org,
Nicolas Ferre <nicolas.ferre@atmel.com>,
linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 1/4 v2] i2c/gpio: add DT support
Date: Tue, 14 Feb 2012 05:06:54 +0100 [thread overview]
Message-ID: <20120214040654.GF3378@game.jcrosoft.org> (raw)
In-Reply-To: <20120213230948.GC2999@freya.fluff.org>
On 23:09 Mon 13 Feb , Ben Dooks wrote:
> On Thu, Feb 09, 2012 at 03:25:05AM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> > Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
> > Cc: linux-i2c@vger.kernel.org
> > Cc: devicetree-discuss@lists.ozlabs.org
> > ---
> > v2:
> >
> > use devm
> > update DT bindings to i2c-gpio and sda-open-drain...
> > update against "of: introduce helper to manage boolean"
> >
> > Best Regards,
> > J.
> > .../devicetree/bindings/gpio/gpio_i2c.txt | 32 +++++++
> > drivers/i2c/busses/i2c-gpio.c | 95 +++++++++++++++----
> > 2 files changed, 107 insertions(+), 20 deletions(-)
> > create mode 100644 Documentation/devicetree/bindings/gpio/gpio_i2c.txt
> >
> > diff --git a/Documentation/devicetree/bindings/gpio/gpio_i2c.txt b/Documentation/devicetree/bindings/gpio/gpio_i2c.txt
> > new file mode 100644
> > index 0000000..9710ed2
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/gpio/gpio_i2c.txt
> > @@ -0,0 +1,32 @@
> > +Device-Tree bindings for i2c gpio driver
> > +
> > +Required properties:
> > + - compatible = "i2c-gpio";
> > + - gpios: sda and scl gpio
> > +
> > +
> > +Optional properties:
> > + - i2c-gpio,sda-open-drain: sda as open drain
> > + - i2c-gpio,scl-open-drain: scl as open drain
> > + - i2c-gpio,scl-output-only: scl as output only
> > + - udelay: delay between GPIO operations (may depend on each platform)
> > + - timeout: timeout to get data (ms)
> > +
> > +Example nodes:
> > +
> > +i2c-gpio@0 {
> > + compatible = "i2c-gpio";
> > + gpios = <&pioA 23 0 /* sda */
> > + &pioA 24 0 /* scl */
> > + >;
> > + i2c-gpio,sda-open-drain;
> > + i2c-gpio,scl-open-drain;
> > + udelay = <2>; /* ~100 kHz */
> > + #address-cells = <1>;
> > + #size-cells = <0>;
> > +
> > + rv3029c2@56 {
> > + compatible = "rv3029c2";
> > + reg = <0x56>;
> > + };
> > +};
> > diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
> > index a651779..d7032c1 100644
> > --- a/drivers/i2c/busses/i2c-gpio.c
> > +++ b/drivers/i2c/busses/i2c-gpio.c
> > @@ -14,8 +14,15 @@
> > #include <linux/module.h>
> > #include <linux/slab.h>
> > #include <linux/platform_device.h>
> > +#include <linux/gpio.h>
> > +#include <linux/of_gpio.h>
> > +#include <linux/of_i2c.h>
> > -#include <asm/gpio.h>
> > +struct i2c_gpio_private_data {
> > + struct i2c_adapter adap;
> > + struct i2c_algo_bit_data bit_data;
> > + struct i2c_gpio_platform_data pdata;
> > +};
> >
> > /* Toggle SDA by changing the direction of the pin */
> > static void i2c_gpio_setsda_dir(void *data, int state)
> > @@ -78,24 +85,63 @@ static int i2c_gpio_getscl(void *data)
> > return gpio_get_value(pdata->scl_pin);
> > }
> >
> > +static int __devinit of_i2c_gpio_probe(struct device_node *np,
> > + struct i2c_gpio_platform_data *pdata)
> > +{
> > + u32 reg;
> > +
> > + if (of_gpio_count(np) < 2)
> > + return -ENODEV;
>
> Hmm, there's no error print and unless updated recently I think the
> driver core will not produce any warnings if ->probe returns an
> -ENODEV. I would prefer to see this printing a warning as for the
> case below if an GPIO fails to be found.
>
> Maybe return -EINVAL as it is not a valid configuration.
>
> > +
> > + pdata->sda_pin = of_get_gpio(np, 0);
> > + pdata->scl_pin = of_get_gpio(np, 1);
> > +
> > + if (pdata->sda_pin < 0 || pdata->scl_pin < 0) {
> > + pr_err("%s: invalid GPIO pins, sda=%d/scl=%d\n",
> > + np->full_name, pdata->sda_pin, pdata->scl_pin);
> > + return -ENODEV;
> > + }
> > +
> > + if (of_property_read_u32(np, "udelay", ®))
> > + pdata->udelay = reg;
>
> This sounds like a "linux" specific property. I would think about
> giving it a name like frequency, or ask Grant if we have a base set
> of properties that a i2c controller should think about implementing.
as example in the doc it's the delay between each gpio operations and it's
platform specific. put frequency will assume you specify the frequency of the
bus you want but we can not calculate here (platform specific).
>
> > + if (of_property_read_u32(np, "timeout", ®))
> > + pdata->timeout = msecs_to_jiffies(reg);
> > +
> > + pdata->sda_is_open_drain =
> > + !!of_property_read_bool(np, "i2c-gpio,sda-open-drain");
> > + pdata->scl_is_open_drain =
> > + !!of_property_read_bool(np, "i2c-gpio,scl-open-drain");
> > + pdata->scl_is_output_only =
> > + !!of_property_read_bool(np, "i2c-gpio,scl-output-only");
>
> I hate !!, why does of_property_read_bool() not return a bool? Also,
> why can't I find of_property_read_bool() in include/linux/* ?
because it's an other patch
>
> Also, does of_property_read_bool() consitently return a useful value if
> the property does not exist, or is not readable? I am most concerned
> with the behaviour if one of these properties has un-parsable contents.
it's use read_u32
and return false if read_u32 return -EINVAL
Best Regards,
J.
prev parent reply other threads:[~2012-02-14 4:06 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-09 2:25 [PATCH 1/4 v2] i2c/gpio: add DT support Jean-Christophe PLAGNIOL-VILLARD
[not found] ` <1328754308-7365-1-git-send-email-plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
2012-02-09 2:25 ` [PATCH 2/4 v2] ARM: at91: sam9g20 add i2c " Jean-Christophe PLAGNIOL-VILLARD
2012-02-09 2:25 ` [PATCH 3/4] ARM: at91: usb_a9g20 add DT i2c support Jean-Christophe PLAGNIOL-VILLARD
2012-02-09 2:25 ` [PATCH 4/4 v2] ARM: at91: sam9g45 add i2c DT support Jean-Christophe PLAGNIOL-VILLARD
2012-02-13 17:17 ` [PATCH 1/4 v2] i2c/gpio: add " Karol Lewandowski
2012-02-20 9:58 ` Jean-Christophe PLAGNIOL-VILLARD
[not found] ` <20120220095813.GB11307-RQcB7r2h9QmfDR2tN2SG5Ni2O/JbrIOy@public.gmane.org>
2012-02-20 10:08 ` Russell King - ARM Linux
[not found] ` <20120220100843.GE22562-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2012-02-20 10:22 ` Jean-Christophe PLAGNIOL-VILLARD
[not found] ` <20120220102231.GC11307-RQcB7r2h9QmfDR2tN2SG5Ni2O/JbrIOy@public.gmane.org>
2012-02-20 12:50 ` Russell King - ARM Linux
[not found] ` <20120220125054.GF22562-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2012-02-20 13:35 ` Jean Delvare
[not found] ` <20120220143557.02787bad-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2012-02-20 13:51 ` Russell King - ARM Linux
[not found] ` <20120220135106.GA26840-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2012-02-20 14:51 ` Jean-Christophe PLAGNIOL-VILLARD
[not found] ` <20120220145137.GG11307-RQcB7r2h9QmfDR2tN2SG5Ni2O/JbrIOy@public.gmane.org>
2012-02-20 15:03 ` Russell King - ARM Linux
2012-02-20 13:37 ` Jean-Christophe PLAGNIOL-VILLARD
[not found] ` <20120220133725.GD11307-RQcB7r2h9QmfDR2tN2SG5Ni2O/JbrIOy@public.gmane.org>
2012-02-20 13:46 ` Jean-Christophe PLAGNIOL-VILLARD
[not found] ` <20120220134634.GE11307-RQcB7r2h9QmfDR2tN2SG5Ni2O/JbrIOy@public.gmane.org>
2012-02-20 13:58 ` Russell King - ARM Linux
[not found] ` <20120220135807.GB26840-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2012-02-20 14:46 ` Jean-Christophe PLAGNIOL-VILLARD
[not found] ` <20120220144635.GF11307-RQcB7r2h9QmfDR2tN2SG5Ni2O/JbrIOy@public.gmane.org>
2012-02-20 15:00 ` Russell King - ARM Linux
[not found] ` <20120220150040.GC26840-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2012-02-20 15:08 ` Jean-Christophe PLAGNIOL-VILLARD
[not found] ` <20120220150810.GH11307-RQcB7r2h9QmfDR2tN2SG5Ni2O/JbrIOy@public.gmane.org>
2012-02-20 15:27 ` Russell King - ARM Linux
[not found] ` <20120220152748.GF26840-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2012-02-20 15:30 ` Jean-Christophe PLAGNIOL-VILLARD
[not found] ` <20120220153006.GK11307-RQcB7r2h9QmfDR2tN2SG5Ni2O/JbrIOy@public.gmane.org>
2012-02-20 15:46 ` Jean-Christophe PLAGNIOL-VILLARD
[not found] ` <20120220154613.GL11307-RQcB7r2h9QmfDR2tN2SG5Ni2O/JbrIOy@public.gmane.org>
2012-02-20 16:08 ` Russell King - ARM Linux
[not found] ` <20120220160855.GG26840-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2012-02-20 16:09 ` Jean-Christophe PLAGNIOL-VILLARD
2012-02-13 23:09 ` Ben Dooks
2012-02-14 4:06 ` Jean-Christophe PLAGNIOL-VILLARD [this message]
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=20120214040654.GF3378@game.jcrosoft.org \
--to=plagnioj@jcrosoft.com \
--cc=ben-i2c@fluff.org \
--cc=devicetree-discuss@lists.ozlabs.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-i2c@vger.kernel.org \
--cc=nicolas.ferre@atmel.com \
/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).