linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] iio: light: cm3232: make struct cm3232_als_info const
@ 2025-06-28 17:52 David Lechner
  2025-06-28 17:52 ` [PATCH 1/2] iio: light: cm3232: move calibscale to struct cm3232_chip David Lechner
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: David Lechner @ 2025-06-28 17:52 UTC (permalink / raw)
  To: Kevin Tsai, Jonathan Cameron, Nuno Sá, Andy Shevchenko
  Cc: linux-iio, linux-kernel, David Lechner

Typically, chip info structs are const. Before we can make that change,
we need to move the calibscale field to the driver data struct. This
also allows individual instances of the driver to have different
calibscale values.

---
David Lechner (2):
      iio: light: cm3232: move calibscale to struct cm3232_chip
      iio: light: cm3232: make struct cm3232_als_info const

 drivers/iio/light/cm3232.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
---
base-commit: 14071b9cf2d751ff9bc8b5e43fa94fbf08aceea1
change-id: 20250628-iio-const-data-20-1f1a05001890

Best regards,
-- 
David Lechner <dlechner@baylibre.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] iio: light: cm3232: move calibscale to struct cm3232_chip
  2025-06-28 17:52 [PATCH 0/2] iio: light: cm3232: make struct cm3232_als_info const David Lechner
@ 2025-06-28 17:52 ` David Lechner
  2025-06-28 17:52 ` [PATCH 2/2] iio: light: cm3232: make struct cm3232_als_info const David Lechner
  2025-07-06  9:51 ` [PATCH 0/2] " Jonathan Cameron
  2 siblings, 0 replies; 4+ messages in thread
From: David Lechner @ 2025-06-28 17:52 UTC (permalink / raw)
  To: Kevin Tsai, Jonathan Cameron, Nuno Sá, Andy Shevchenko
  Cc: linux-iio, linux-kernel, David Lechner

Move the calibscale field from struct cm3232_als_info to struct
cm3232_chip. The chip info struct is supposed to be const while the
driver data struct should contain mutable fields. Since calibscale
is a mutable field, it should be in the driver data struct.

Signed-off-by: David Lechner <dlechner@baylibre.com>
---
 drivers/iio/light/cm3232.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/iio/light/cm3232.c b/drivers/iio/light/cm3232.c
index e864d2ef036e87b7a3ca286770594681eacd8e58..b6823a5a0860a32a65b6e3e76b4e22bc9cd14312 100644
--- a/drivers/iio/light/cm3232.c
+++ b/drivers/iio/light/cm3232.c
@@ -54,7 +54,6 @@ static const struct {
 struct cm3232_als_info {
 	u8 regs_cmd_default;
 	u8 hw_id;
-	int calibscale;
 	int mlux_per_bit;
 	int mlux_per_bit_base_it;
 };
@@ -62,7 +61,6 @@ struct cm3232_als_info {
 static struct cm3232_als_info cm3232_als_info_default = {
 	.regs_cmd_default = CM3232_CMD_DEFAULT,
 	.hw_id = CM3232_HW_ID,
-	.calibscale = CM3232_CALIBSCALE_DEFAULT,
 	.mlux_per_bit = CM3232_MLUX_PER_BIT_DEFAULT,
 	.mlux_per_bit_base_it = CM3232_MLUX_PER_BIT_BASE_IT,
 };
@@ -70,6 +68,7 @@ static struct cm3232_als_info cm3232_als_info_default = {
 struct cm3232_chip {
 	struct i2c_client *client;
 	struct cm3232_als_info *als_info;
+	int calibscale;
 	u8 regs_cmd;
 	u16 regs_als;
 };
@@ -222,7 +221,7 @@ static int cm3232_get_lux(struct cm3232_chip *chip)
 
 	chip->regs_als = (u16)ret;
 	lux *= chip->regs_als;
-	lux *= als_info->calibscale;
+	lux *= chip->calibscale;
 	lux = div_u64(lux, CM3232_CALIBSCALE_RESOLUTION);
 	lux = div_u64(lux, CM3232_MLUX_PER_LUX);
 
@@ -237,7 +236,6 @@ static int cm3232_read_raw(struct iio_dev *indio_dev,
 			int *val, int *val2, long mask)
 {
 	struct cm3232_chip *chip = iio_priv(indio_dev);
-	struct cm3232_als_info *als_info = chip->als_info;
 	int ret;
 
 	switch (mask) {
@@ -248,7 +246,7 @@ static int cm3232_read_raw(struct iio_dev *indio_dev,
 		*val = ret;
 		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_CALIBSCALE:
-		*val = als_info->calibscale;
+		*val = chip->calibscale;
 		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_INT_TIME:
 		return cm3232_read_als_it(chip, val, val2);
@@ -262,11 +260,10 @@ static int cm3232_write_raw(struct iio_dev *indio_dev,
 			int val, int val2, long mask)
 {
 	struct cm3232_chip *chip = iio_priv(indio_dev);
-	struct cm3232_als_info *als_info = chip->als_info;
 
 	switch (mask) {
 	case IIO_CHAN_INFO_CALIBSCALE:
-		als_info->calibscale = val;
+		chip->calibscale = val;
 		return 0;
 	case IIO_CHAN_INFO_INT_TIME:
 		return cm3232_write_als_it(chip, val, val2);
@@ -339,6 +336,7 @@ static int cm3232_probe(struct i2c_client *client)
 	chip = iio_priv(indio_dev);
 	i2c_set_clientdata(client, indio_dev);
 	chip->client = client;
+	chip->calibscale = CM3232_CALIBSCALE_DEFAULT;
 
 	indio_dev->channels = cm3232_channels;
 	indio_dev->num_channels = ARRAY_SIZE(cm3232_channels);

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] iio: light: cm3232: make struct cm3232_als_info const
  2025-06-28 17:52 [PATCH 0/2] iio: light: cm3232: make struct cm3232_als_info const David Lechner
  2025-06-28 17:52 ` [PATCH 1/2] iio: light: cm3232: move calibscale to struct cm3232_chip David Lechner
@ 2025-06-28 17:52 ` David Lechner
  2025-07-06  9:51 ` [PATCH 0/2] " Jonathan Cameron
  2 siblings, 0 replies; 4+ messages in thread
From: David Lechner @ 2025-06-28 17:52 UTC (permalink / raw)
  To: Kevin Tsai, Jonathan Cameron, Nuno Sá, Andy Shevchenko
  Cc: linux-iio, linux-kernel, David Lechner

Add const qualifier to struct cm3232_als_info. This is read-only data so
it can be made const.

Signed-off-by: David Lechner <dlechner@baylibre.com>
---
 drivers/iio/light/cm3232.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/light/cm3232.c b/drivers/iio/light/cm3232.c
index b6823a5a0860a32a65b6e3e76b4e22bc9cd14312..3a3ad6b4c46860cb401e8084c47d3abe1f3f4169 100644
--- a/drivers/iio/light/cm3232.c
+++ b/drivers/iio/light/cm3232.c
@@ -58,7 +58,7 @@ struct cm3232_als_info {
 	int mlux_per_bit_base_it;
 };
 
-static struct cm3232_als_info cm3232_als_info_default = {
+static const struct cm3232_als_info cm3232_als_info_default = {
 	.regs_cmd_default = CM3232_CMD_DEFAULT,
 	.hw_id = CM3232_HW_ID,
 	.mlux_per_bit = CM3232_MLUX_PER_BIT_DEFAULT,
@@ -67,7 +67,7 @@ static struct cm3232_als_info cm3232_als_info_default = {
 
 struct cm3232_chip {
 	struct i2c_client *client;
-	struct cm3232_als_info *als_info;
+	const struct cm3232_als_info *als_info;
 	int calibscale;
 	u8 regs_cmd;
 	u16 regs_als;
@@ -198,7 +198,7 @@ static int cm3232_write_als_it(struct cm3232_chip *chip, int val, int val2)
 static int cm3232_get_lux(struct cm3232_chip *chip)
 {
 	struct i2c_client *client = chip->client;
-	struct cm3232_als_info *als_info = chip->als_info;
+	const struct cm3232_als_info *als_info = chip->als_info;
 	int ret;
 	int val, val2;
 	int als_it;

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] iio: light: cm3232: make struct cm3232_als_info const
  2025-06-28 17:52 [PATCH 0/2] iio: light: cm3232: make struct cm3232_als_info const David Lechner
  2025-06-28 17:52 ` [PATCH 1/2] iio: light: cm3232: move calibscale to struct cm3232_chip David Lechner
  2025-06-28 17:52 ` [PATCH 2/2] iio: light: cm3232: make struct cm3232_als_info const David Lechner
@ 2025-07-06  9:51 ` Jonathan Cameron
  2 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2025-07-06  9:51 UTC (permalink / raw)
  To: David Lechner
  Cc: Kevin Tsai, Nuno Sá, Andy Shevchenko, linux-iio,
	linux-kernel

On Sat, 28 Jun 2025 12:52:29 -0500
David Lechner <dlechner@baylibre.com> wrote:

> Typically, chip info structs are const. Before we can make that change,
> we need to move the calibscale field to the driver data struct. This
> also allows individual instances of the driver to have different
> calibscale values.
> 
> ---
> David Lechner (2):
>       iio: light: cm3232: move calibscale to struct cm3232_chip
>       iio: light: cm3232: make struct cm3232_als_info const
Applied.

> 
>  drivers/iio/light/cm3232.c | 18 ++++++++----------
>  1 file changed, 8 insertions(+), 10 deletions(-)
> ---
> base-commit: 14071b9cf2d751ff9bc8b5e43fa94fbf08aceea1
> change-id: 20250628-iio-const-data-20-1f1a05001890
> 
> Best regards,


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-07-06  9:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-28 17:52 [PATCH 0/2] iio: light: cm3232: make struct cm3232_als_info const David Lechner
2025-06-28 17:52 ` [PATCH 1/2] iio: light: cm3232: move calibscale to struct cm3232_chip David Lechner
2025-06-28 17:52 ` [PATCH 2/2] iio: light: cm3232: make struct cm3232_als_info const David Lechner
2025-07-06  9:51 ` [PATCH 0/2] " Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).