public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] iio: adc: meson: a few improvements
@ 2024-12-24 14:29 Martin Blumenstingl
  2024-12-24 14:29 ` [PATCH v2 1/3] iio: adc: meson: fix voltage reference selection field name typo Martin Blumenstingl
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Martin Blumenstingl @ 2024-12-24 14:29 UTC (permalink / raw)
  To: linux-iio, linux-amlogic
  Cc: jic23, lars, gnstark, linux-arm-kernel, linux-kernel,
	neil.armstrong, Martin Blumenstingl

This series contains three improvements to the meson SAR ADC driver.
None of them are meant to change the existing behavior. The goal is
to make the driver code easier to read and understand.

Changes since v1 at [0]:
- drop the patch 2 "iio: adc: meson: consistently use bool/enum in
  struct meson_sar_adc_param" for now as the purpose of the fields is
  unfortunately still not clarified
- add space to tab conversion from former patch 2 as a separate patch
- Cc linux-iio (which was forgotton in v1)


[0] https://lore.kernel.org/linux-arm-kernel/20240324140429.5484eb54@jic23-huawei/T/#m81d92c2192de1936646543543501d8a62527da8d


Martin Blumenstingl (3):
  iio: adc: meson: fix voltage reference selection field name typo
  iio: adc: meson: use tabs instead of spaces for some REG11 bit fields
  iio: adc: meson: simplify MESON_SAR_ADC_REG11 register access

 drivers/iio/adc/meson_saradc.c | 47 ++++++++++++----------------------
 1 file changed, 17 insertions(+), 30 deletions(-)

-- 
2.47.1



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

* [PATCH v2 1/3] iio: adc: meson: fix voltage reference selection field name typo
  2024-12-24 14:29 [PATCH v2 0/3] iio: adc: meson: a few improvements Martin Blumenstingl
@ 2024-12-24 14:29 ` Martin Blumenstingl
  2024-12-24 14:29 ` [PATCH v2 2/3] iio: adc: meson: use tabs instead of spaces for some REG11 bit fields Martin Blumenstingl
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Martin Blumenstingl @ 2024-12-24 14:29 UTC (permalink / raw)
  To: linux-iio, linux-amlogic
  Cc: jic23, lars, gnstark, linux-arm-kernel, linux-kernel,
	neil.armstrong, Martin Blumenstingl

The field should be called "vref_voltage", without a typo in the word
voltage. No functional changes intended.

Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
---
 drivers/iio/adc/meson_saradc.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c
index 2d475b43e717..4cfbb3482a2e 100644
--- a/drivers/iio/adc/meson_saradc.c
+++ b/drivers/iio/adc/meson_saradc.c
@@ -327,7 +327,7 @@ struct meson_sar_adc_param {
 	u8					vref_select;
 	u8					cmv_select;
 	u8					adc_eoc;
-	enum meson_sar_adc_vref_sel		vref_volatge;
+	enum meson_sar_adc_vref_sel		vref_voltage;
 };
 
 struct meson_sar_adc_data {
@@ -989,7 +989,7 @@ static int meson_sar_adc_init(struct iio_dev *indio_dev)
 		}
 
 		regval = FIELD_PREP(MESON_SAR_ADC_REG11_VREF_VOLTAGE,
-				    priv->param->vref_volatge);
+				    priv->param->vref_voltage);
 		regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG11,
 				   MESON_SAR_ADC_REG11_VREF_VOLTAGE, regval);
 
@@ -1212,7 +1212,7 @@ static const struct meson_sar_adc_param meson_sar_adc_gxbb_param = {
 	.regmap_config = &meson_sar_adc_regmap_config_gxbb,
 	.resolution = 10,
 	.has_reg11 = true,
-	.vref_volatge = 1,
+	.vref_voltage = 1,
 	.cmv_select = 1,
 };
 
@@ -1224,7 +1224,7 @@ static const struct meson_sar_adc_param meson_sar_adc_gxl_param = {
 	.resolution = 12,
 	.disable_ring_counter = 1,
 	.has_reg11 = true,
-	.vref_volatge = 1,
+	.vref_voltage = 1,
 	.cmv_select = 1,
 };
 
@@ -1236,7 +1236,7 @@ static const struct meson_sar_adc_param meson_sar_adc_axg_param = {
 	.resolution = 12,
 	.disable_ring_counter = 1,
 	.has_reg11 = true,
-	.vref_volatge = 1,
+	.vref_voltage = 1,
 	.has_vref_select = true,
 	.vref_select = VREF_VDDA,
 	.cmv_select = 1,
-- 
2.47.1



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

* [PATCH v2 2/3] iio: adc: meson: use tabs instead of spaces for some REG11 bit fields
  2024-12-24 14:29 [PATCH v2 0/3] iio: adc: meson: a few improvements Martin Blumenstingl
  2024-12-24 14:29 ` [PATCH v2 1/3] iio: adc: meson: fix voltage reference selection field name typo Martin Blumenstingl
@ 2024-12-24 14:29 ` Martin Blumenstingl
  2024-12-24 14:29 ` [PATCH v2 3/3] iio: adc: meson: simplify MESON_SAR_ADC_REG11 register access Martin Blumenstingl
  2024-12-28 13:40 ` [PATCH v2 0/3] iio: adc: meson: a few improvements Jonathan Cameron
  3 siblings, 0 replies; 5+ messages in thread
From: Martin Blumenstingl @ 2024-12-24 14:29 UTC (permalink / raw)
  To: linux-iio, linux-amlogic
  Cc: jic23, lars, gnstark, linux-arm-kernel, linux-kernel,
	neil.armstrong, Martin Blumenstingl

This makes them consistent with the rest of the driver. No functional
changes.

Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
---
 drivers/iio/adc/meson_saradc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c
index 4cfbb3482a2e..469af3c57066 100644
--- a/drivers/iio/adc/meson_saradc.c
+++ b/drivers/iio/adc/meson_saradc.c
@@ -155,10 +155,10 @@
  */
 #define MESON_SAR_ADC_REG11					0x2c
 	#define MESON_SAR_ADC_REG11_BANDGAP_EN			BIT(13)
-	#define MESON_SAR_ADC_REG11_CMV_SEL                     BIT(6)
-	#define MESON_SAR_ADC_REG11_VREF_VOLTAGE                BIT(5)
-	#define MESON_SAR_ADC_REG11_EOC                         BIT(1)
-	#define MESON_SAR_ADC_REG11_VREF_SEL                    BIT(0)
+	#define MESON_SAR_ADC_REG11_CMV_SEL			BIT(6)
+	#define MESON_SAR_ADC_REG11_VREF_VOLTAGE		BIT(5)
+	#define MESON_SAR_ADC_REG11_EOC				BIT(1)
+	#define MESON_SAR_ADC_REG11_VREF_SEL			BIT(0)
 
 #define MESON_SAR_ADC_REG13					0x34
 	#define MESON_SAR_ADC_REG13_12BIT_CALIBRATION_MASK	GENMASK(13, 8)
-- 
2.47.1



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

* [PATCH v2 3/3] iio: adc: meson: simplify MESON_SAR_ADC_REG11 register access
  2024-12-24 14:29 [PATCH v2 0/3] iio: adc: meson: a few improvements Martin Blumenstingl
  2024-12-24 14:29 ` [PATCH v2 1/3] iio: adc: meson: fix voltage reference selection field name typo Martin Blumenstingl
  2024-12-24 14:29 ` [PATCH v2 2/3] iio: adc: meson: use tabs instead of spaces for some REG11 bit fields Martin Blumenstingl
@ 2024-12-24 14:29 ` Martin Blumenstingl
  2024-12-28 13:40 ` [PATCH v2 0/3] iio: adc: meson: a few improvements Jonathan Cameron
  3 siblings, 0 replies; 5+ messages in thread
From: Martin Blumenstingl @ 2024-12-24 14:29 UTC (permalink / raw)
  To: linux-iio, linux-amlogic
  Cc: jic23, lars, gnstark, linux-arm-kernel, linux-kernel,
	neil.armstrong, Martin Blumenstingl

Simply check the max_register value to decide whether
MESON_SAR_ADC_REG11 is present on the current IP revision. This allows
dropping two additional bool fields from struct meson_sar_adc_param
which previously had to be manually kept in sync. No functional changes
intended.

Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
---
 drivers/iio/adc/meson_saradc.c | 29 ++++++++---------------------
 1 file changed, 8 insertions(+), 21 deletions(-)

diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c
index 469af3c57066..997def4a4d2f 100644
--- a/drivers/iio/adc/meson_saradc.c
+++ b/drivers/iio/adc/meson_saradc.c
@@ -315,14 +315,12 @@ static const struct iio_chan_spec meson_sar_adc_and_temp_iio_channels[] = {
 struct meson_sar_adc_param {
 	bool					has_bl30_integration;
 	unsigned long				clock_rate;
-	u32					bandgap_reg;
 	unsigned int				resolution;
 	const struct regmap_config		*regmap_config;
 	u8					temperature_trimming_bits;
 	unsigned int				temperature_multiplier;
 	unsigned int				temperature_divider;
 	u8					disable_ring_counter;
-	bool					has_reg11;
 	bool					has_vref_select;
 	u8					vref_select;
 	u8					cmv_select;
@@ -976,7 +974,7 @@ static int meson_sar_adc_init(struct iio_dev *indio_dev)
 			   MESON_SAR_ADC_REG3_CTRL_CONT_RING_COUNTER_EN,
 			   regval);
 
-	if (priv->param->has_reg11) {
+	if (priv->param->regmap_config->max_register >= MESON_SAR_ADC_REG11) {
 		regval = FIELD_PREP(MESON_SAR_ADC_REG11_EOC, priv->param->adc_eoc);
 		regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG11,
 				   MESON_SAR_ADC_REG11_EOC, regval);
@@ -1013,16 +1011,15 @@ static int meson_sar_adc_init(struct iio_dev *indio_dev)
 static void meson_sar_adc_set_bandgap(struct iio_dev *indio_dev, bool on_off)
 {
 	struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
-	const struct meson_sar_adc_param *param = priv->param;
-	u32 enable_mask;
 
-	if (param->bandgap_reg == MESON_SAR_ADC_REG11)
-		enable_mask = MESON_SAR_ADC_REG11_BANDGAP_EN;
+	if (priv->param->regmap_config->max_register >= MESON_SAR_ADC_REG11)
+		regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG11,
+				   MESON_SAR_ADC_REG11_BANDGAP_EN,
+				   on_off ? MESON_SAR_ADC_REG11_BANDGAP_EN : 0);
 	else
-		enable_mask = MESON_SAR_ADC_DELTA_10_TS_VBG_EN;
-
-	regmap_update_bits(priv->regmap, param->bandgap_reg, enable_mask,
-			   on_off ? enable_mask : 0);
+		regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELTA_10,
+				   MESON_SAR_ADC_DELTA_10_TS_VBG_EN,
+				   on_off ? MESON_SAR_ADC_DELTA_10_TS_VBG_EN : 0);
 }
 
 static int meson_sar_adc_hw_enable(struct iio_dev *indio_dev)
@@ -1186,7 +1183,6 @@ static const struct iio_info meson_sar_adc_iio_info = {
 static const struct meson_sar_adc_param meson_sar_adc_meson8_param = {
 	.has_bl30_integration = false,
 	.clock_rate = 1150000,
-	.bandgap_reg = MESON_SAR_ADC_DELTA_10,
 	.regmap_config = &meson_sar_adc_regmap_config_meson8,
 	.resolution = 10,
 	.temperature_trimming_bits = 4,
@@ -1197,7 +1193,6 @@ static const struct meson_sar_adc_param meson_sar_adc_meson8_param = {
 static const struct meson_sar_adc_param meson_sar_adc_meson8b_param = {
 	.has_bl30_integration = false,
 	.clock_rate = 1150000,
-	.bandgap_reg = MESON_SAR_ADC_DELTA_10,
 	.regmap_config = &meson_sar_adc_regmap_config_meson8,
 	.resolution = 10,
 	.temperature_trimming_bits = 5,
@@ -1208,10 +1203,8 @@ static const struct meson_sar_adc_param meson_sar_adc_meson8b_param = {
 static const struct meson_sar_adc_param meson_sar_adc_gxbb_param = {
 	.has_bl30_integration = true,
 	.clock_rate = 1200000,
-	.bandgap_reg = MESON_SAR_ADC_REG11,
 	.regmap_config = &meson_sar_adc_regmap_config_gxbb,
 	.resolution = 10,
-	.has_reg11 = true,
 	.vref_voltage = 1,
 	.cmv_select = 1,
 };
@@ -1219,11 +1212,9 @@ static const struct meson_sar_adc_param meson_sar_adc_gxbb_param = {
 static const struct meson_sar_adc_param meson_sar_adc_gxl_param = {
 	.has_bl30_integration = true,
 	.clock_rate = 1200000,
-	.bandgap_reg = MESON_SAR_ADC_REG11,
 	.regmap_config = &meson_sar_adc_regmap_config_gxbb,
 	.resolution = 12,
 	.disable_ring_counter = 1,
-	.has_reg11 = true,
 	.vref_voltage = 1,
 	.cmv_select = 1,
 };
@@ -1231,11 +1222,9 @@ static const struct meson_sar_adc_param meson_sar_adc_gxl_param = {
 static const struct meson_sar_adc_param meson_sar_adc_axg_param = {
 	.has_bl30_integration = true,
 	.clock_rate = 1200000,
-	.bandgap_reg = MESON_SAR_ADC_REG11,
 	.regmap_config = &meson_sar_adc_regmap_config_gxbb,
 	.resolution = 12,
 	.disable_ring_counter = 1,
-	.has_reg11 = true,
 	.vref_voltage = 1,
 	.has_vref_select = true,
 	.vref_select = VREF_VDDA,
@@ -1245,11 +1234,9 @@ static const struct meson_sar_adc_param meson_sar_adc_axg_param = {
 static const struct meson_sar_adc_param meson_sar_adc_g12a_param = {
 	.has_bl30_integration = false,
 	.clock_rate = 1200000,
-	.bandgap_reg = MESON_SAR_ADC_REG11,
 	.regmap_config = &meson_sar_adc_regmap_config_gxbb,
 	.resolution = 12,
 	.disable_ring_counter = 1,
-	.has_reg11 = true,
 	.adc_eoc = 1,
 	.has_vref_select = true,
 	.vref_select = VREF_VDDA,
-- 
2.47.1



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

* Re: [PATCH v2 0/3] iio: adc: meson: a few improvements
  2024-12-24 14:29 [PATCH v2 0/3] iio: adc: meson: a few improvements Martin Blumenstingl
                   ` (2 preceding siblings ...)
  2024-12-24 14:29 ` [PATCH v2 3/3] iio: adc: meson: simplify MESON_SAR_ADC_REG11 register access Martin Blumenstingl
@ 2024-12-28 13:40 ` Jonathan Cameron
  3 siblings, 0 replies; 5+ messages in thread
From: Jonathan Cameron @ 2024-12-28 13:40 UTC (permalink / raw)
  To: Martin Blumenstingl
  Cc: linux-iio, linux-amlogic, lars, gnstark, linux-arm-kernel,
	linux-kernel, neil.armstrong

On Tue, 24 Dec 2024 15:29:38 +0100
Martin Blumenstingl <martin.blumenstingl@googlemail.com> wrote:

> This series contains three improvements to the meson SAR ADC driver.
> None of them are meant to change the existing behavior. The goal is
> to make the driver code easier to read and understand.
> 
> Changes since v1 at [0]:
> - drop the patch 2 "iio: adc: meson: consistently use bool/enum in
>   struct meson_sar_adc_param" for now as the purpose of the fields is
>   unfortunately still not clarified
> - add space to tab conversion from former patch 2 as a separate patch
> - Cc linux-iio (which was forgotton in v1)
> 
Applied to the togreg branch of iio.git

Dropped fixes tag from patch 1.   A typo fix on something entirely internal
to the driver is just cleanup, not a fix and definitely not something
we want anyone to backport!

Thanks,

Jonathan
> 
> [0] https://lore.kernel.org/linux-arm-kernel/20240324140429.5484eb54@jic23-huawei/T/#m81d92c2192de1936646543543501d8a62527da8d
> 
> 
> Martin Blumenstingl (3):
>   iio: adc: meson: fix voltage reference selection field name typo
>   iio: adc: meson: use tabs instead of spaces for some REG11 bit fields
>   iio: adc: meson: simplify MESON_SAR_ADC_REG11 register access
> 
>  drivers/iio/adc/meson_saradc.c | 47 ++++++++++++----------------------
>  1 file changed, 17 insertions(+), 30 deletions(-)
> 



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

end of thread, other threads:[~2024-12-28 13:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-24 14:29 [PATCH v2 0/3] iio: adc: meson: a few improvements Martin Blumenstingl
2024-12-24 14:29 ` [PATCH v2 1/3] iio: adc: meson: fix voltage reference selection field name typo Martin Blumenstingl
2024-12-24 14:29 ` [PATCH v2 2/3] iio: adc: meson: use tabs instead of spaces for some REG11 bit fields Martin Blumenstingl
2024-12-24 14:29 ` [PATCH v2 3/3] iio: adc: meson: simplify MESON_SAR_ADC_REG11 register access Martin Blumenstingl
2024-12-28 13:40 ` [PATCH v2 0/3] iio: adc: meson: a few improvements Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox