From: Gabriel Braga Lagrotaria <gabrielblo@ime.usp.br>
To: andy@kernel.org, dlechner@baylibre.com,
javier.carrasco.cruz@gmail.com, jic23@kernel.org,
nuno.sa@analog.com
Cc: ricardo.kojo@ime.usp.br, elliancarlos@gmail.com,
linux-iio@vger.kernel.org
Subject: [PATCH v2 2/2] iio: light: veml6030: Generalize hw_init for veml6030 and veml6035
Date: Sat, 2 May 2026 20:41:04 -0300 [thread overview]
Message-ID: <20260502234348.131563-3-gabrielblo@ime.usp.br> (raw)
In-Reply-To: <20260502234348.131563-1-gabrielblo@ime.usp.br>
Modify veml6030_hw_init() function to deduplicate the setup logic
for veml6030_hw_init() and veml6035_hw_init(), and remove
veml6035_hw_init().
Additionally, introduce struct veml6030_hw_init_config_desc to store and
pass the custom configuration values specific to each device variation.
Signed-off-by: Gabriel Braga Lagrotaria <gabrielblo@ime.usp.br>
Co-developed-by: Ricardo H H Kojo <ricardo.kojo@ime.usp.br>
Signed-off-by: Ricardo H H Kojo <ricardo.kojo@ime.usp.br>
Co-developed-by: Ellian Carlos <elliancarlos@gmail.com>
Signed-off-by: Ellian Carlos <elliancarlos@gmail.com>
---
drivers/iio/light/veml6030.c | 92 +++++++++++++++---------------------
1 file changed, 37 insertions(+), 55 deletions(-)
diff --git a/drivers/iio/light/veml6030.c b/drivers/iio/light/veml6030.c
index 3d11e4736330..132ef6136da8 100644
--- a/drivers/iio/light/veml6030.c
+++ b/drivers/iio/light/veml6030.c
@@ -82,6 +82,14 @@ struct veml6030_rf {
struct regmap_field *gain;
};
+struct veml6030_hw_init_config_desc {
+ const struct iio_gain_sel_pair *gain_sel;
+ int gain_sel_size;
+ int gain_max_scale_int;
+ int gain_max_scale_nano;
+ unsigned int reg_als_conf_value;
+};
+
struct veml6030_chip_desc {
const char *name;
const struct iio_chan_spec *channels;
@@ -89,6 +97,7 @@ struct veml6030_chip_desc {
const struct reg_field gain_rf;
const struct reg_field it_rf;
const int max_scale;
+ const struct veml6030_hw_init_config_desc *hw_init_cfg;
int (*hw_init)(struct iio_dev *indio_dev, struct device *dev);
int (*set_info)(struct iio_dev *indio_dev);
};
@@ -963,61 +972,21 @@ static int veml6030_regfield_init(struct iio_dev *indio_dev)
return 0;
}
+
/*
* Set ALS gain to 1/8, integration time to 100 ms, PSM to mode 2,
* persistence to 1 x integration time and the threshold
* interrupt disabled by default. First shutdown the sensor,
* update registers and then power on the sensor.
*/
-static int veml6030_hw_init(struct iio_dev *indio_dev, struct device *dev)
-{
- int ret, val;
- struct veml6030_data *data = iio_priv(indio_dev);
-
- ret = devm_iio_init_iio_gts(dev, 2, 150400000,
- veml6030_gain_sel, ARRAY_SIZE(veml6030_gain_sel),
- veml6030_it_sel, ARRAY_SIZE(veml6030_it_sel),
- &data->gts);
- if (ret)
- return dev_err_probe(dev, ret, "failed to init iio gts\n");
-
- ret = veml6030_als_shut_down(data);
- if (ret)
- return dev_err_probe(dev, ret, "can't shutdown als\n");
-
- ret = regmap_write(data->regmap, VEML6030_REG_ALS_CONF, 0x1001);
- if (ret)
- return dev_err_probe(dev, ret, "can't setup als configs\n");
-
- ret = regmap_update_bits(data->regmap, VEML6030_REG_ALS_PSM,
- VEML6030_PSM | VEML6030_PSM_EN, 0x03);
- if (ret)
- return dev_err_probe(dev, ret, "can't setup default PSM\n");
-
- ret = regmap_write(data->regmap, VEML6030_REG_ALS_WH, 0xFFFF);
- if (ret)
- return dev_err_probe(dev, ret, "can't setup high threshold\n");
-
- ret = regmap_write(data->regmap, VEML6030_REG_ALS_WL, 0x0000);
- if (ret)
- return dev_err_probe(dev, ret, "can't setup low threshold\n");
-
- ret = veml6030_als_pwr_on(data);
- if (ret)
- return dev_err_probe(dev, ret, "can't poweron als\n");
-
- ret = devm_add_action_or_reset(dev, veml6030_als_shut_down_action, data);
- if (ret < 0)
- return ret;
-
- /* Clear stale interrupt status bits if any during start */
- ret = regmap_read(data->regmap, VEML6030_REG_ALS_INT, &val);
- if (ret < 0)
- return dev_err_probe(dev, ret,
- "can't clear als interrupt status\n");
+static const struct veml6030_hw_init_config_desc veml6030_hw_init_config = {
+ .gain_sel = veml6030_gain_sel,
+ .gain_sel_size = ARRAY_SIZE(veml6030_gain_sel),
+ .gain_max_scale_int = 2,
+ .gain_max_scale_nano = 150400000,
+ .reg_als_conf_value = 0x1001,
+};
- return ret;
-}
/*
* Set ALS gain to 1/8, integration time to 100 ms, ALS and WHITE
@@ -1026,13 +995,22 @@ static int veml6030_hw_init(struct iio_dev *indio_dev, struct device *dev)
* threshold interrupt disabled by default. First shutdown the sensor,
* update registers and then power on the sensor.
*/
-static int veml6035_hw_init(struct iio_dev *indio_dev, struct device *dev)
+static const struct veml6030_hw_init_config_desc veml6035_hw_init_config = {
+ .gain_sel = veml6035_gain_sel,
+ .gain_sel_size = ARRAY_SIZE(veml6035_gain_sel),
+ .gain_max_scale_int = 0,
+ .gain_max_scale_nano = 409600000,
+ .reg_als_conf_value = VEML6035_SENS | VEML6035_CHAN_EN | VEML6030_ALS_SD,
+};
+
+static int veml6030_hw_init(struct iio_dev *indio_dev, struct device *dev)
{
int ret, val;
struct veml6030_data *data = iio_priv(indio_dev);
+ const struct veml6030_hw_init_config_desc *cfg = data->chip->hw_init_cfg;
- ret = devm_iio_init_iio_gts(dev, 0, 409600000,
- veml6035_gain_sel, ARRAY_SIZE(veml6035_gain_sel),
+ ret = devm_iio_init_iio_gts(dev, cfg->gain_max_scale_int, cfg->gain_max_scale_nano,
+ cfg->gain_sel, cfg->gain_sel_size,
veml6030_it_sel, ARRAY_SIZE(veml6030_it_sel),
&data->gts);
if (ret)
@@ -1042,8 +1020,7 @@ static int veml6035_hw_init(struct iio_dev *indio_dev, struct device *dev)
if (ret)
return dev_err_probe(dev, ret, "can't shutdown als\n");
- ret = regmap_write(data->regmap, VEML6030_REG_ALS_CONF,
- VEML6035_SENS | VEML6035_CHAN_EN | VEML6030_ALS_SD);
+ ret = regmap_write(data->regmap, VEML6030_REG_ALS_CONF, cfg->reg_als_conf_value);
if (ret)
return dev_err_probe(dev, ret, "can't setup als configs\n");
@@ -1074,9 +1051,11 @@ static int veml6035_hw_init(struct iio_dev *indio_dev, struct device *dev)
return dev_err_probe(dev, ret,
"can't clear als interrupt status\n");
- return 0;
+ return ret;
}
+
+
static int veml6030_probe(struct i2c_client *client)
{
int ret;
@@ -1167,6 +1146,7 @@ static int veml6030_runtime_resume(struct device *dev)
static DEFINE_RUNTIME_DEV_PM_OPS(veml6030_pm_ops, veml6030_runtime_suspend,
veml6030_runtime_resume, NULL);
+
static const struct veml6030_chip_desc veml6030_chip = {
.name = "veml6030",
.channels = veml6030_channels,
@@ -1174,6 +1154,7 @@ static const struct veml6030_chip_desc veml6030_chip = {
.gain_rf = VEML6030_GAIN_RF,
.it_rf = VEML6030_IT_RF,
.max_scale = VEML6030_MAX_SCALE,
+ .hw_init_cfg = &veml6030_hw_init_config,
.hw_init = veml6030_hw_init,
.set_info = veml6030_set_info,
};
@@ -1185,7 +1166,8 @@ static const struct veml6030_chip_desc veml6035_chip = {
.gain_rf = VEML6035_GAIN_RF,
.it_rf = VEML6030_IT_RF,
.max_scale = VEML6035_MAX_SCALE,
- .hw_init = veml6035_hw_init,
+ .hw_init_cfg = &veml6035_hw_init_config,
+ .hw_init = veml6030_hw_init,
.set_info = veml6030_set_info,
};
--
2.54.0
next prev parent reply other threads:[~2026-05-02 23:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-02 23:41 [PATCH v2 0/2] iio: light: veml6030: Generalize hw_init and cleanup naming Gabriel Braga Lagrotaria
2026-05-02 23:41 ` [PATCH v2 1/2] iio: light: veml6030: Remove 'x' wildcard usages in file Gabriel Braga Lagrotaria
2026-05-03 9:23 ` Joshua Crofts
2026-05-02 23:41 ` Gabriel Braga Lagrotaria [this message]
2026-05-03 0:02 ` [PATCH v2 2/2] iio: light: veml6030: Generalize hw_init for veml6030 and veml6035 Maxwell Doose
2026-05-04 14:14 ` Andy Shevchenko
2026-05-04 16:28 ` Jonathan Cameron
2026-05-04 16:35 ` 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=20260502234348.131563-3-gabrielblo@ime.usp.br \
--to=gabrielblo@ime.usp.br \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=elliancarlos@gmail.com \
--cc=javier.carrasco.cruz@gmail.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=ricardo.kojo@ime.usp.br \
/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