From: "Barnabás Czémán" <trabarni@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>,
Lars-Peter Clausen <lars@metafoo.de>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
"Barnabás Czémán" <trabarni@gmail.com>
Subject: [PATCH 2/3] iio: light: stk3310: make chip id check expandable
Date: Tue, 21 May 2024 17:34:52 +0200 [thread overview]
Message-ID: <20240521-stk3311-v1-2-07a4966b355a@gmail.com> (raw)
In-Reply-To: <20240521-stk3311-v1-0-07a4966b355a@gmail.com>
Modify chip id check for support easier additions
for compatible variants.
Signed-off-by: Barnabás Czémán <trabarni@gmail.com>
---
drivers/iio/light/stk3310.c | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c
index 7cae261541c6..5b3fe98af9c9 100644
--- a/drivers/iio/light/stk3310.c
+++ b/drivers/iio/light/stk3310.c
@@ -81,6 +81,13 @@ static const struct reg_field stk3310_reg_field_flag_psint =
static const struct reg_field stk3310_reg_field_flag_nf =
REG_FIELD(STK3310_REG_FLAG, 0, 0);
+static const u8 stk3310_chip_ids[] = {
+ STK3310_CHIP_ID_VAL,
+ STK3311X_CHIP_ID_VAL,
+ STK3311_CHIP_ID_VAL,
+ STK3335_CHIP_ID_VAL,
+};
+
/* Estimate maximum proximity values with regard to measurement scale. */
static const int stk3310_ps_max[4] = {
STK3310_PS_MAX_VAL / 640,
@@ -197,6 +204,16 @@ static const struct attribute_group stk3310_attribute_group = {
.attrs = stk3310_attributes
};
+static int stk3310_check_chip_id(const u8 chip_id)
+{
+ for (int i = 0; i < ARRAY_SIZE(stk3310_chip_ids); i++) {
+ if (chip_id == stk3310_chip_ids[i])
+ return 0;
+ }
+
+ return -ENODEV;
+}
+
static int stk3310_get_index(const int table[][2], int table_size,
int val, int val2)
{
@@ -473,12 +490,9 @@ static int stk3310_init(struct iio_dev *indio_dev)
if (ret < 0)
return ret;
- if (chipid != STK3310_CHIP_ID_VAL &&
- chipid != STK3311_CHIP_ID_VAL &&
- chipid != STK3311X_CHIP_ID_VAL &&
- chipid != STK3335_CHIP_ID_VAL) {
+ ret = stk3310_check_chip_id(chipid);
+ if (ret < 0)
dev_warn(&client->dev, "unknown chip id: 0x%x\n", chipid);
- }
state = STK3310_STATE_EN_ALS | STK3310_STATE_EN_PS;
ret = stk3310_set_state(data, state);
--
2.45.1
next prev parent reply other threads:[~2024-05-21 15:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-21 15:34 [PATCH 0/3] Add support for more stk3311 variant Barnabás Czémán
2024-05-21 15:34 ` [PATCH 1/3] iio: light: stk3310: relax failure to match id Barnabás Czémán
2024-05-21 15:34 ` Barnabás Czémán [this message]
2024-05-21 15:34 ` [PATCH 3/3] iio: light: stk3310: support more stk3311 variants Barnabás Czémán
2024-05-25 16:50 ` [PATCH 0/3] Add support for more stk3311 variant Jonathan Cameron
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=20240521-stk3311-v1-2-07a4966b355a@gmail.com \
--to=trabarni@gmail.com \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.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