From: Emil Gedenryd <Emil.Gedenryd@axis.com>
To: "jic23@kernel.org" <jic23@kernel.org>
Cc: "linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
"robh@kernel.org" <robh@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"dannenberg@ti.com" <dannenberg@ti.com>,
"krzk+dt@kernel.org" <krzk+dt@kernel.org>,
"lars@metafoo.de" <lars@metafoo.de>,
"conor+dt@kernel.org" <conor+dt@kernel.org>,
Kernel <Kernel@axis.com>
Subject: Re: [PATCH v3 3/3] iio: light: opt3001: add support for TI's opt3002 light sensor
Date: Mon, 30 Sep 2024 07:53:59 +0000 [thread overview]
Message-ID: <150ebd3af04045efe4d4ee7f298a57044e0f448e.camel@axis.com> (raw)
In-Reply-To: <20240928170520.02a27690@jic23-huawei>
On Sat, 2024-09-28 at 17:05 +0100, Jonathan Cameron wrote:
> On Mon, 16 Sep 2024 16:56:39 +0200
> Emil Gedenryd <emil.gedenryd@axis.com> wrote:
>
> > TI's opt3002 light sensor shares most properties with the opt3001
> > model, with the exception of supporting a wider spectrum range.
> >
> > Add support for TI's opt3002 by extending the TI opt3001 driver.
> >
> > Datasheet: https://www.ti.com/product/OPT3002
> > Signed-off-by: Emil Gedenryd <emil.gedenryd@axis.com>
> Hi Emil,
>
> A few things inline,
>
> Thanks,
>
> Jonathan
Hi Jonathan,
Thank you for the comments, I'll start working on fixing them during
the week.
Best Regards,
Emil
>
> >
> > @@ -610,7 +704,7 @@ static int opt3001_read_id(struct opt3001 *opt)
> > ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_DEVICE_ID);
> > if (ret < 0) {
> > dev_err(opt->dev, "failed to read register %02x\n",
> > - OPT3001_DEVICE_ID);
> > + OPT3001_DEVICE_ID);
>
> Unrelated change so in theory should be in a separate patch but
> meh, it's trivial so leave it here if you like.
Good to know! I'll keep it since it's minor but I'll remember this for
the future.
>
> > return ret;
> > }
>
> > @@ -755,22 +850,25 @@ static int opt3001_probe(struct i2c_client *client)
> > opt = iio_priv(iio);
> > opt->client = client;
> > opt->dev = dev;
> > + opt->chip_info = device_get_match_data(&client->dev);
>
> Use the i2c specific way to to do this.
> https://elixir.bootlin.com/linux/v6.11/source/drivers/i2c/i2c-core-base.c#L120
> i2c_get_match_data() because it will also handle falling back to matching
> via the i2c_match_id() path against the old style match tables in a few
> cases.
Okay!
> >
> > mutex_init(&opt->lock);
> > init_waitqueue_head(&opt->result_ready_queue);
> > i2c_set_clientdata(client, iio);
> >
> > - ret = opt3001_read_id(opt);
> > - if (ret)
> > - return ret;
> > + if (opt->chip_info->has_id) {
> > + ret = opt3001_read_id(opt);
> > + if (ret)
> > + return ret;
> > + }
> >
> > ret = opt3001_configure(opt);
> > if (ret)
> > return ret;
> >
> > iio->name = client->name;
> > - iio->channels = opt3001_channels;
> > - iio->num_channels = ARRAY_SIZE(opt3001_channels);
> > + iio->channels = *opt->chip_info->channels;
> > + iio->num_channels = ARRAY_SIZE(*opt->chip_info->channels);
> This won't work as it has no way to perform a sizeof
> through a pointer.
>
> Add a num_channels filed to your opt3001_chip_info structure
> as then it can be ARRAY_SIZE(&opt3001_channels) which can work.
Good catch and thanks for the suggestion, I'll do it that way!
>
> > iio->modes = INDIO_DIRECT_MODE;
> > iio->info = &opt3001_info;
> >
> > @@ -825,14 +923,36 @@ static void opt3001_remove(struct i2c_client *client)
> > }
> > }
> >
> > +static const struct opt3001_chip_info opt3001_chip_information = {
> > + .channels = &opt3001_channels,
> > + .chan_type = IIO_LIGHT,
> > + .scales = &opt3001_scales,
> > + .factor_whole = 10,
> > + .factor_integer = 1000,
> > + .factor_decimal = 1000,
> > + .has_id = true,
> > +};
> > +
> > +static const struct opt3001_chip_info opt3002_chip_information = {
> > + .channels = &opt3002_channels,
> > + .chan_type = IIO_INTENSITY,
> > + .scales = &opt3002_scales,
> > + .factor_whole = 12,
> > + .factor_integer = 10,
> > + .factor_decimal = 100000,
> > + .has_id = false,
> > +};
> > +
> > static const struct i2c_device_id opt3001_id[] = {
> > - { "opt3001" },
> > + { "opt3001", (kernel_ulong_t)&opt3001_chip_information },
> > + { "opt3002", (kernel_ulong_t)&opt3002_chip_information },
> > { } /* Terminating Entry */
> > };
> > MODULE_DEVICE_TABLE(i2c, opt3001_id);
> >
> > static const struct of_device_id opt3001_of_match[] = {
> > - { .compatible = "ti,opt3001" },
> > + { .compatible = "ti,opt3001", .data = &opt3001_chip_information },
> > + { .compatible = "ti,opt3002", .data = &opt3002_chip_information },
> > { }
> > };
> > MODULE_DEVICE_TABLE(of, opt3001_of_match);
> >
>
prev parent reply other threads:[~2024-09-30 7:54 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-16 14:56 [PATCH v3 0/3] iio: light: opt3001: add support for TI's opt3002 light sensor Emil Gedenryd
2024-09-16 14:56 ` [PATCH v3 1/3] iio: light: opt3001: add missing full-scale range value Emil Gedenryd
2024-09-28 15:57 ` Jonathan Cameron
2024-09-30 7:54 ` Emil Gedenryd
2024-09-16 14:56 ` [PATCH v3 2/3] dt-bindings: iio: light: opt3001: add compatible for opt3002 Emil Gedenryd
2024-09-16 15:24 ` Conor Dooley
2024-09-17 7:06 ` Emil Gedenryd
2024-09-16 14:56 ` [PATCH v3 3/3] iio: light: opt3001: add support for TI's opt3002 light sensor Emil Gedenryd
2024-09-28 16:05 ` Jonathan Cameron
2024-09-30 7:53 ` Emil Gedenryd [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=150ebd3af04045efe4d4ee7f298a57044e0f448e.camel@axis.com \
--to=emil.gedenryd@axis.com \
--cc=Kernel@axis.com \
--cc=conor+dt@kernel.org \
--cc=dannenberg@ti.com \
--cc=devicetree@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh@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