From: Svyatoslav Ryhel <clamor95@gmail.com>
To: "Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Esben Haabendal" <esben@geanix.com>,
"Kuppuswamy Sathyanarayanan"
<sathyanarayanan.kuppuswamy@linux.intel.com>,
"Svyatoslav Ryhel" <clamor95@gmail.com>,
"Uwe Kleine-König (The Capable Hub)"
<u.kleine-koenig@baylibre.com>, "Pan Chuang" <panchuang@vivo.com>,
"Hemanth Selam" <hemanth.selam@gmail.com>,
"Antoniu Miclaus" <antoniu.miclaus@analog.com>,
"Nikita Travkin" <nikita@trvn.ru>
Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 2/4] iio: light: ltr501: Switch to modern match mechanism
Date: Fri, 6 Nov 2026 11:19:41 +0200 [thread overview]
Message-ID: <20261106091943.35783-3-clamor95@gmail.com> (raw)
In-Reply-To: <20261106091943.35783-1-clamor95@gmail.com>
Remove the chip enum, break the chip list structure into individual
elements, and pass each element using i2c_get_match_data().
Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---
drivers/iio/light/ltr501.c | 165 +++++++++++++++++--------------------
1 file changed, 74 insertions(+), 91 deletions(-)
diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c
index cc5d7af44d77c..d5ce6468a229b 100644
--- a/drivers/iio/light/ltr501.c
+++ b/drivers/iio/light/ltr501.c
@@ -90,14 +90,6 @@ struct ltr501_samp_table {
#define LTR501_RESERVED_GAIN -1
-enum {
- ltr301,
- ltr303,
- ltr329,
- ltr501,
- ltr559,
-};
-
struct ltr501_gain {
int scale;
int uscale;
@@ -1178,62 +1170,64 @@ static const struct iio_info ltr501_info = {
.write_event_config = <r501_write_event_config,
};
-static const struct ltr501_chip_info ltr501_chip_info_tbl[] = {
- [ltr301] = {
- .partid = 0x08,
- .als_gain = ltr501_als_gain_tbl,
- .als_gain_tbl_size = ARRAY_SIZE(ltr501_als_gain_tbl),
- .als_mode_active = BIT(0) | BIT(1),
- .als_gain_mask = BIT(3),
- .als_gain_shift = 3,
- .channels = ltr301_channels,
- .no_channels = ARRAY_SIZE(ltr301_channels),
- },
- [ltr303] = {
- .partid = 0x0A,
- .als_gain = ltr559_als_gain_tbl,
- .als_gain_tbl_size = ARRAY_SIZE(ltr559_als_gain_tbl),
- .als_mode_active = BIT(0),
- .als_gain_mask = BIT(2) | BIT(3) | BIT(4),
- .als_gain_shift = 2,
- .channels = ltr301_channels,
- .no_channels = ARRAY_SIZE(ltr301_channels),
- },
- [ltr329] = {
- .partid = 0x0A,
- .als_gain = ltr559_als_gain_tbl,
- .als_gain_tbl_size = ARRAY_SIZE(ltr559_als_gain_tbl),
- .als_mode_active = BIT(0),
- .als_gain_mask = BIT(2) | BIT(3) | BIT(4),
- .als_gain_shift = 2,
- .no_irq_support = true,
- .channels = ltr301_channels,
- .no_channels = ARRAY_SIZE(ltr301_channels),
- },
- [ltr501] = {
- .partid = 0x08,
- .als_gain = ltr501_als_gain_tbl,
- .als_gain_tbl_size = ARRAY_SIZE(ltr501_als_gain_tbl),
- .ps_gain = ltr501_ps_gain_tbl,
- .ps_gain_tbl_size = ARRAY_SIZE(ltr501_ps_gain_tbl),
- .als_mode_active = BIT(0) | BIT(1),
- .als_gain_mask = BIT(3),
- .als_gain_shift = 3,
- .channels = ltr501_channels,
- .no_channels = ARRAY_SIZE(ltr501_channels),
- },
- [ltr559] = {
- .partid = 0x09,
- .als_gain = ltr559_als_gain_tbl,
- .als_gain_tbl_size = ARRAY_SIZE(ltr559_als_gain_tbl),
- .ps_gain = ltr559_ps_gain_tbl,
- .ps_gain_tbl_size = ARRAY_SIZE(ltr559_ps_gain_tbl),
- .als_mode_active = BIT(0),
- .als_gain_mask = BIT(2) | BIT(3) | BIT(4),
- .als_gain_shift = 2,
- .channels = ltr501_channels,
- .no_channels = ARRAY_SIZE(ltr501_channels),
- },
+static const struct ltr501_chip_info ltr301_chip_info_tbl = {
+ .partid = 0x08,
+ .als_gain = ltr501_als_gain_tbl,
+ .als_gain_tbl_size = ARRAY_SIZE(ltr501_als_gain_tbl),
+ .als_mode_active = BIT(0) | BIT(1),
+ .als_gain_mask = BIT(3),
+ .als_gain_shift = 3,
+ .channels = ltr301_channels,
+ .no_channels = ARRAY_SIZE(ltr301_channels),
+};
+
+static const struct ltr501_chip_info ltr303_chip_info_tbl = {
+ .partid = 0x0A,
+ .als_gain = ltr559_als_gain_tbl,
+ .als_gain_tbl_size = ARRAY_SIZE(ltr559_als_gain_tbl),
+ .als_mode_active = BIT(0),
+ .als_gain_mask = BIT(2) | BIT(3) | BIT(4),
+ .als_gain_shift = 2,
+ .channels = ltr301_channels,
+ .no_channels = ARRAY_SIZE(ltr301_channels),
+};
+
+static const struct ltr501_chip_info ltr329_chip_info_tbl = {
+ .partid = 0x0A,
+ .als_gain = ltr559_als_gain_tbl,
+ .als_gain_tbl_size = ARRAY_SIZE(ltr559_als_gain_tbl),
+ .als_mode_active = BIT(0),
+ .als_gain_mask = BIT(2) | BIT(3) | BIT(4),
+ .als_gain_shift = 2,
+ .no_irq_support = true,
+ .channels = ltr301_channels,
+ .no_channels = ARRAY_SIZE(ltr301_channels),
+};
+
+static const struct ltr501_chip_info ltr501_chip_info_tbl = {
+ .partid = 0x08,
+ .als_gain = ltr501_als_gain_tbl,
+ .als_gain_tbl_size = ARRAY_SIZE(ltr501_als_gain_tbl),
+ .ps_gain = ltr501_ps_gain_tbl,
+ .ps_gain_tbl_size = ARRAY_SIZE(ltr501_ps_gain_tbl),
+ .als_mode_active = BIT(0) | BIT(1),
+ .als_gain_mask = BIT(3),
+ .als_gain_shift = 3,
+ .channels = ltr501_channels,
+ .no_channels = ARRAY_SIZE(ltr501_channels),
+};
+
+static const struct ltr501_chip_info ltr559_chip_info_tbl = {
+ .partid = 0x09,
+ .als_gain = ltr559_als_gain_tbl,
+ .als_gain_tbl_size = ARRAY_SIZE(ltr559_als_gain_tbl),
+ .ps_gain = ltr559_ps_gain_tbl,
+ .ps_gain_tbl_size = ARRAY_SIZE(ltr559_ps_gain_tbl),
+ .als_mode_active = BIT(0),
+ .als_gain_mask = BIT(2) | BIT(3) | BIT(4),
+ .als_gain_shift = 2,
+ .channels = ltr501_channels,
+ .no_channels = ARRAY_SIZE(ltr501_channels),
};
static int ltr501_write_contr(struct ltr501_data *data, u8 als_val, u8 ps_val)
@@ -1393,14 +1387,11 @@ static int ltr501_powerdown(struct ltr501_data *data)
static int ltr501_probe(struct i2c_client *client)
{
- const struct i2c_device_id *id = i2c_client_get_device_id(client);
static const char * const regulator_names[] = { "vdd", "vddio" };
struct ltr501_data *data;
struct iio_dev *indio_dev;
struct regmap *regmap;
- const void *ddata = NULL;
- int partid, chip_idx;
- const char *name;
+ int partid;
int ret;
indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
@@ -1480,18 +1471,10 @@ static int ltr501_probe(struct i2c_client *client)
if (ret < 0)
return ret;
- if (id) {
- name = id->name;
- chip_idx = id->driver_data;
- } else {
- name = iio_get_acpi_device_name_and_data(&client->dev, &ddata);
- chip_idx = (intptr_t)ddata;
- }
- if (!name)
+ data->chip_info = i2c_get_match_data(client);
+ if (!data->chip_info)
return -ENODEV;
- data->chip_info = <r501_chip_info_tbl[chip_idx];
-
if ((partid >> 4) != data->chip_info->partid)
return -ENODEV;
@@ -1502,7 +1485,7 @@ static int ltr501_probe(struct i2c_client *client)
indio_dev->info = <r501_info;
indio_dev->channels = data->chip_info->channels;
indio_dev->num_channels = data->chip_info->no_channels;
- indio_dev->name = name;
+ indio_dev->name = client->name;
indio_dev->modes = INDIO_DIRECT_MODE;
ret = ltr501_init(data);
@@ -1573,29 +1556,29 @@ static int ltr501_resume(struct device *dev)
static DEFINE_SIMPLE_DEV_PM_OPS(ltr501_pm_ops, ltr501_suspend, ltr501_resume);
static const struct acpi_device_id ltr_acpi_match[] = {
- { "LTER0301", ltr301 },
+ { "LTER0301", .driver_data = (kernel_ulong_t)<r301_chip_info_tbl },
/* https://www.catalog.update.microsoft.com/Search.aspx?q=lter0303 */
- { "LTER0303", ltr303 },
+ { "LTER0303", .driver_data = (kernel_ulong_t)<r303_chip_info_tbl },
{ }
};
MODULE_DEVICE_TABLE(acpi, ltr_acpi_match);
static const struct i2c_device_id ltr501_id[] = {
- { .name = "ltr301", .driver_data = ltr301 },
- { .name = "ltr303", .driver_data = ltr303 },
- { .name = "ltr329", .driver_data = ltr329 },
- { .name = "ltr501", .driver_data = ltr501 },
- { .name = "ltr559", .driver_data = ltr559 },
+ { .name = "ltr301", .driver_data = (kernel_ulong_t)<r301_chip_info_tbl },
+ { .name = "ltr303", .driver_data = (kernel_ulong_t)<r303_chip_info_tbl },
+ { .name = "ltr329", .driver_data = (kernel_ulong_t)<r329_chip_info_tbl },
+ { .name = "ltr501", .driver_data = (kernel_ulong_t)<r501_chip_info_tbl },
+ { .name = "ltr559", .driver_data = (kernel_ulong_t)<r559_chip_info_tbl },
{ }
};
MODULE_DEVICE_TABLE(i2c, ltr501_id);
static const struct of_device_id ltr501_of_match[] = {
- { .compatible = "liteon,ltr301", },
- { .compatible = "liteon,ltr303", },
- { .compatible = "liteon,ltr329", },
- { .compatible = "liteon,ltr501", },
- { .compatible = "liteon,ltr559", },
+ { .compatible = "liteon,ltr301", .data = <r301_chip_info_tbl },
+ { .compatible = "liteon,ltr303", .data = <r303_chip_info_tbl },
+ { .compatible = "liteon,ltr329", .data = <r329_chip_info_tbl },
+ { .compatible = "liteon,ltr501", .data = <r501_chip_info_tbl },
+ { .compatible = "liteon,ltr559", .data = <r559_chip_info_tbl },
{ }
};
MODULE_DEVICE_TABLE(of, ltr501_of_match);
--
2.53.0
next prev parent reply other threads:[~2026-11-06 9:20 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 9:19 [PATCH v2 0/4] iio: light: ltr501: Add LTR-659PS-01 prox sensor support Svyatoslav Ryhel
2026-11-06 9:19 ` [PATCH v2 1/4] iio: light: ltr501: Switch to read_avail() op from manual attribute registration Svyatoslav Ryhel
2026-11-06 9:19 ` Svyatoslav Ryhel [this message]
2026-11-06 9:19 ` [PATCH v2 3/4] dt-bindings: iio: light: ltr501: Document LTR659 proximity sensor Svyatoslav Ryhel
2026-11-06 17:31 ` Conor Dooley
2026-11-06 9:19 ` [PATCH v2 4/4] iio: light: ltr501: Add support for the LTR-659PS-01 " Svyatoslav Ryhel
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=20261106091943.35783-3-clamor95@gmail.com \
--to=clamor95@gmail.com \
--cc=andy@kernel.org \
--cc=antoniu.miclaus@analog.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=esben@geanix.com \
--cc=hemanth.selam@gmail.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nikita@trvn.ru \
--cc=nuno.sa@analog.com \
--cc=panchuang@vivo.com \
--cc=robh@kernel.org \
--cc=sathyanarayanan.kuppuswamy@linux.intel.com \
--cc=u.kleine-koenig@baylibre.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
all inboxes | Powered by JetHome®