[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240115133023.3465-5-mitrutzceclan@gmail.com>
Date: Mon, 15 Jan 2024 15:30:17 +0200
From: Dumitru Ceclan <mitrutzceclan@...il.com>
To:
Cc: Lars-Peter Clausen <lars@...afoo.de>,
Jonathan Cameron <jic23@...nel.org>,
Rob Herring <robh+dt@...nel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>,
Conor Dooley <conor+dt@...nel.org>,
linux-iio@...r.kernel.org,
devicetree@...r.kernel.org,
linux-kernel@...r.kernel.org,
Ceclan Dumitru <dumitru.ceclan@...log.com>,
Dumitru Ceclan <mitrutzceclan@...il.com>
Subject: [PATCH v3 4/5] iio: amplifiers: hmc425a: use pointers in match table
Change the match table to use pointers instead of device ids.
Alignment of the hmc425a_state was changed because of the const
specifier for hmc425a_chip_info.
Signed-off-by: Dumitru Ceclan <mitrutzceclan@...il.com>
---
drivers/iio/amplifiers/hmc425a.c | 39 ++++++++++++++++++--------------
1 file changed, 22 insertions(+), 17 deletions(-)
diff --git a/drivers/iio/amplifiers/hmc425a.c b/drivers/iio/amplifiers/hmc425a.c
index e1162a500daf..b116b54e4206 100644
--- a/drivers/iio/amplifiers/hmc425a.c
+++ b/drivers/iio/amplifiers/hmc425a.c
@@ -37,11 +37,11 @@ struct hmc425a_chip_info {
};
struct hmc425a_state {
- struct mutex lock; /* protect sensor state */
- struct hmc425a_chip_info *chip_info;
- struct gpio_descs *gpios;
- enum hmc425a_type type;
- u32 gain;
+ struct mutex lock; /* protect sensor state */
+ const struct hmc425a_chip_info *chip_info;
+ struct gpio_descs *gpios;
+ enum hmc425a_type type;
+ u32 gain;
};
static int hmc425a_write(struct iio_dev *indio_dev, u32 value)
@@ -58,7 +58,7 @@ static int hmc425a_write(struct iio_dev *indio_dev, u32 value)
static int hmc425a_gain_dB_to_code(struct hmc425a_state *st, int val, int val2, int *code)
{
- struct hmc425a_chip_info *inf = st->chip_info;
+ const struct hmc425a_chip_info *inf = st->chip_info;
int gain, temp;
if (val < 0)
@@ -187,15 +187,6 @@ static const struct iio_chan_spec hmc425a_channels[] = {
HMC425A_CHAN(0),
};
-/* Match table for of_platform binding */
-static const struct of_device_id hmc425a_of_match[] = {
- { .compatible = "adi,hmc425a", .data = (void *)ID_HMC425A },
- { .compatible = "adi,hmc540s", .data = (void *)ID_HMC540S },
- { .compatible = "adi,adrf5740", .data = (void *)ID_ADRF5740 },
- {},
-};
-MODULE_DEVICE_TABLE(of, hmc425a_of_match);
-
static struct hmc425a_chip_info hmc425a_chip_info_tbl[] = {
[ID_HMC425A] = {
.name = "hmc425a",
@@ -226,6 +217,18 @@ static struct hmc425a_chip_info hmc425a_chip_info_tbl[] = {
},
};
+/* Match table for of_platform binding */
+static const struct of_device_id hmc425a_of_match[] = {
+ { .compatible = "adi,hmc425a",
+ .data = &hmc425a_chip_info_tbl[ID_HMC425A]},
+ { .compatible = "adi,hmc540s",
+ .data = &hmc425a_chip_info_tbl[ID_HMC540S]},
+ { .compatible = "adi,adrf5740",
+ .data = &hmc425a_chip_info_tbl[ID_ADRF5740]},
+ {},
+};
+MODULE_DEVICE_TABLE(of, hmc425a_of_match);
+
static int hmc425a_probe(struct platform_device *pdev)
{
struct iio_dev *indio_dev;
@@ -237,14 +240,16 @@ static int hmc425a_probe(struct platform_device *pdev)
return -ENOMEM;
st = iio_priv(indio_dev);
- st->type = (uintptr_t)device_get_match_data(&pdev->dev);
- st->chip_info = &hmc425a_chip_info_tbl[st->type];
+ st->chip_info = device_get_match_data(&pdev->dev);
indio_dev->num_channels = st->chip_info->num_channels;
indio_dev->channels = st->chip_info->channels;
indio_dev->name = st->chip_info->name;
st->gain = st->chip_info->default_gain;
+ /* Compute index of the acquired chip info in the array */
+ st->type = st->chip_info - hmc425a_chip_info_tbl;
+
st->gpios = devm_gpiod_get_array(&pdev->dev, "ctrl", GPIOD_OUT_LOW);
if (IS_ERR(st->gpios))
return dev_err_probe(&pdev->dev, PTR_ERR(st->gpios),
--
2.42.0
Powered by blists - more mailing lists