devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/3] Meson8 / Meson8b support for the meson_saradc driver
@ 2017-05-06 13:49 Martin Blumenstingl
       [not found] ` <20170506134929.31190-1-martin.blumenstingl-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Martin Blumenstingl @ 2017-05-06 13:49 UTC (permalink / raw)
  To: jic23-DgEjT+Ai2ygdnm+yROfE0A, knaack.h-Mmb7MZpHnFY,
	lars-Qo5EllUWu/uELgA04lAiVw, pmeerw-jW+XmwGofnusTnJN9+BGXg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
	linux-iio-u79uwXL29TY76Z2rM5mHXA
  Cc: carlo-KA+7E9HrN00dnm+yROfE0A, khilman-rdvid1DuHRBWk0Htik3J/w,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-amlogic-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	thomas.langer-ral2JQCrhuEAvxtiuMwx3w, Martin Blumenstingl

The SAR ADC register layout seems to be mostly the same on older SoCs.
Thus basically all functionality is already supported by the existing
driver.

There are two small differences though:
- the adc_clk and adc_div clock are not provided by the clock-controller
  on Meson8b. instead the SAR ADC provides an internal "adc_clk" (this
  behavior is already supported by the driver and requires no changes)
- the newer SoCs are using some register bits only the kernel or the
  BL30 (bootloader) are using the SAR ADC. This is the main change of
  this series: guarding all BL30 specific code with a corresponding
  "if"-block.

This also adds a new DT binding for the SAR ADC in Meson8 and Meson8b
because the driver has to specify (for this older version) that there's
no BL30 integration available (and these register bits should not be
touched).

Changes since v3 at [2]:
- the patch that should make the meson_sar_adc_data instances static and
  const only made them static (but not const). thanks to Thomas Langer
  for spotting this. note: this affects patch #1 and #3 (as in #3 there
  are more meson_sar_adc_data instances introduced which were copied from
  the ones in patch #1).

Changes since v2 at [1]:
- re-ordered patches so patch #1 now adds the "static" modifier to the
  existing meson_sar_adc_data instances (was patch #3, now patch #1)
- dropped the "Documentation: " prefix from the devicetree
  documentation patch (patch #2)
- added Rob's ACK to the devicetree Documentation patch (patch #2)
- fixed a copy-and-paste error in the actual driver change (both,
  in the commit message where I claimed that a of_device_id was only
  added for Meson8b as well as in the driver code itself where the Meson8
  meson_sar_adc_data.name was "meson-meson8b-saradc")

Changes since v1 at [0]:
- switched to bool data-type for has_bl30_integration
- also added a "compatible" for Meson8 SoCs (the ADC driver from
  Amlogic's GPL kernel sources handles Meson8 and Meson8b identical)
- added patch #3 to constify some structs (there were supposed to be
  const from the very beginning)


[0] http://lists.infradead.org/pipermail/linux-amlogic/2017-March/003081.html
[1] http://lists.infradead.org/pipermail/linux-amlogic/2017-April/003394.html
[2] http://lists.infradead.org/pipermail/linux-amlogic/2017-May/003439.html

Martin Blumenstingl (3):
  iio: adc: meson-saradc: mark all meson_sar_adc_data static and const
  dt-bindings: iio: adc: add Meson8 and Meson8b support
  iio: adc: meson-saradc: add Meson8b SoC compatibility

 .../bindings/iio/adc/amlogic,meson-saradc.txt      |  2 +
 drivers/iio/adc/meson_saradc.c                     | 86 +++++++++++++++-------
 2 files changed, 61 insertions(+), 27 deletions(-)

-- 
2.12.2

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH v4 1/3] iio: adc: meson-saradc: mark all meson_sar_adc_data static and const
       [not found] ` <20170506134929.31190-1-martin.blumenstingl-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>
@ 2017-05-06 13:49   ` Martin Blumenstingl
  2017-05-07 11:35     ` Jonathan Cameron
  2017-05-06 13:49   ` [PATCH v4 2/3] dt-bindings: iio: adc: add Meson8 and Meson8b support Martin Blumenstingl
  2017-05-06 13:49   ` [PATCH v4 3/3] iio: adc: meson-saradc: add Meson8b SoC compatibility Martin Blumenstingl
  2 siblings, 1 reply; 7+ messages in thread
From: Martin Blumenstingl @ 2017-05-06 13:49 UTC (permalink / raw)
  To: jic23-DgEjT+Ai2ygdnm+yROfE0A, knaack.h-Mmb7MZpHnFY,
	lars-Qo5EllUWu/uELgA04lAiVw, pmeerw-jW+XmwGofnusTnJN9+BGXg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
	linux-iio-u79uwXL29TY76Z2rM5mHXA
  Cc: carlo-KA+7E9HrN00dnm+yROfE0A, khilman-rdvid1DuHRBWk0Htik3J/w,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-amlogic-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	thomas.langer-ral2JQCrhuEAvxtiuMwx3w, Martin Blumenstingl

These are only passed as of_device_id.data and never modified. Thus we
can mark them as static const, just like the of_device_id instances
where they are used.

Signed-off-by: Martin Blumenstingl <martin.blumenstingl-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>
---
 drivers/iio/adc/meson_saradc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c
index dd4190b50df6..2f6fec995264 100644
--- a/drivers/iio/adc/meson_saradc.c
+++ b/drivers/iio/adc/meson_saradc.c
@@ -834,17 +834,17 @@ static const struct iio_info meson_sar_adc_iio_info = {
 	.driver_module = THIS_MODULE,
 };
 
-struct meson_sar_adc_data meson_sar_adc_gxbb_data = {
+static const struct meson_sar_adc_data meson_sar_adc_gxbb_data = {
 	.resolution = 10,
 	.name = "meson-gxbb-saradc",
 };
 
-struct meson_sar_adc_data meson_sar_adc_gxl_data = {
+static const struct meson_sar_adc_data meson_sar_adc_gxl_data = {
 	.resolution = 12,
 	.name = "meson-gxl-saradc",
 };
 
-struct meson_sar_adc_data meson_sar_adc_gxm_data = {
+static const struct meson_sar_adc_data meson_sar_adc_gxm_data = {
 	.resolution = 12,
 	.name = "meson-gxm-saradc",
 };
-- 
2.12.2

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

* [PATCH v4 2/3] dt-bindings: iio: adc: add Meson8 and Meson8b support
       [not found] ` <20170506134929.31190-1-martin.blumenstingl-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>
  2017-05-06 13:49   ` [PATCH v4 1/3] iio: adc: meson-saradc: mark all meson_sar_adc_data static and const Martin Blumenstingl
@ 2017-05-06 13:49   ` Martin Blumenstingl
  2017-05-07 11:35     ` Jonathan Cameron
  2017-05-06 13:49   ` [PATCH v4 3/3] iio: adc: meson-saradc: add Meson8b SoC compatibility Martin Blumenstingl
  2 siblings, 1 reply; 7+ messages in thread
From: Martin Blumenstingl @ 2017-05-06 13:49 UTC (permalink / raw)
  To: jic23-DgEjT+Ai2ygdnm+yROfE0A, knaack.h-Mmb7MZpHnFY,
	lars-Qo5EllUWu/uELgA04lAiVw, pmeerw-jW+XmwGofnusTnJN9+BGXg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
	linux-iio-u79uwXL29TY76Z2rM5mHXA
  Cc: carlo-KA+7E9HrN00dnm+yROfE0A, khilman-rdvid1DuHRBWk0Htik3J/w,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-amlogic-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	thomas.langer-ral2JQCrhuEAvxtiuMwx3w, Martin Blumenstingl

The Amlogic Meson SAR ADC driver can be used on Meson8 and Meson8b
(probably on earlier SoC generations as well, but I don't have any
hardware available for testing that).
Add a separate compatible for Meson8 and Meson8b because it does not
need any of the BL30 magic (unlike the GX SoCs).

Signed-off-by: Martin Blumenstingl <martin.blumenstingl-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>
Acked-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
---
 Documentation/devicetree/bindings/iio/adc/amlogic,meson-saradc.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/iio/adc/amlogic,meson-saradc.txt b/Documentation/devicetree/bindings/iio/adc/amlogic,meson-saradc.txt
index f9e3ff2c656e..08cee82e54c3 100644
--- a/Documentation/devicetree/bindings/iio/adc/amlogic,meson-saradc.txt
+++ b/Documentation/devicetree/bindings/iio/adc/amlogic,meson-saradc.txt
@@ -2,6 +2,8 @@
 
 Required properties:
 - compatible:	depending on the SoC this should be one of:
+			- "amlogic,meson8-saradc" for Meson8
+			- "amlogic,meson8b-saradc" for Meson8b
 			- "amlogic,meson-gxbb-saradc" for GXBB
 			- "amlogic,meson-gxl-saradc" for GXL
 			- "amlogic,meson-gxm-saradc" for GXM
-- 
2.12.2

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH v4 3/3] iio: adc: meson-saradc: add Meson8b SoC compatibility
       [not found] ` <20170506134929.31190-1-martin.blumenstingl-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>
  2017-05-06 13:49   ` [PATCH v4 1/3] iio: adc: meson-saradc: mark all meson_sar_adc_data static and const Martin Blumenstingl
  2017-05-06 13:49   ` [PATCH v4 2/3] dt-bindings: iio: adc: add Meson8 and Meson8b support Martin Blumenstingl
@ 2017-05-06 13:49   ` Martin Blumenstingl
  2017-05-07 11:35     ` Jonathan Cameron
  2 siblings, 1 reply; 7+ messages in thread
From: Martin Blumenstingl @ 2017-05-06 13:49 UTC (permalink / raw)
  To: jic23-DgEjT+Ai2ygdnm+yROfE0A, knaack.h-Mmb7MZpHnFY,
	lars-Qo5EllUWu/uELgA04lAiVw, pmeerw-jW+XmwGofnusTnJN9+BGXg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
	linux-iio-u79uwXL29TY76Z2rM5mHXA
  Cc: carlo-KA+7E9HrN00dnm+yROfE0A, khilman-rdvid1DuHRBWk0Htik3J/w,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-amlogic-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	thomas.langer-ral2JQCrhuEAvxtiuMwx3w, Martin Blumenstingl

Meson GX SoCs however use some magic bits to prevent simultaneous (=
conflicting, because only consumer should use the FIFO buffer with the
ADC results) usage by the Linux kernel and the bootloader (the BL30
bootloader uses the SAR ADC to read the CPU temperature).
This patch changes guards all BL30 functionality so it is skipped on
SoCs which don't have it. Since the hardware itself doesn't know whether
BL30 is available the internal meson_sar_adc_data is extended so this
information can be provided per of_device_id.data inside the driver.

Additionally the clocks "adc_clk" and "adc_sel" are not provided by the
clock-controller itself. "adc_sel" is not available at all. "adc_clk"
is provided by the SAR ADC IP block itself on Meson8b (and earlier).
This is already supported by the meson_saradc driver.

Finally this introduces new of_device_ids for the Meson8 and Meson8b
SoCs so the driver can be wired up in the corresponding DT.

Signed-off-by: Martin Blumenstingl <martin.blumenstingl-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>
---
 drivers/iio/adc/meson_saradc.c | 80 +++++++++++++++++++++++++++++-------------
 1 file changed, 56 insertions(+), 24 deletions(-)

diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c
index 2f6fec995264..81cd39a57fe3 100644
--- a/drivers/iio/adc/meson_saradc.c
+++ b/drivers/iio/adc/meson_saradc.c
@@ -220,6 +220,7 @@ enum meson_sar_adc_chan7_mux_sel {
 };
 
 struct meson_sar_adc_data {
+	bool					has_bl30_integration;
 	unsigned int				resolution;
 	const char				*name;
 };
@@ -437,19 +438,24 @@ static int meson_sar_adc_lock(struct iio_dev *indio_dev)
 
 	mutex_lock(&indio_dev->mlock);
 
-	/* prevent BL30 from using the SAR ADC while we are using it */
-	regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY,
-			   MESON_SAR_ADC_DELAY_KERNEL_BUSY,
-			   MESON_SAR_ADC_DELAY_KERNEL_BUSY);
-
-	/* wait until BL30 releases it's lock (so we can use the SAR ADC) */
-	do {
-		udelay(1);
-		regmap_read(priv->regmap, MESON_SAR_ADC_DELAY, &val);
-	} while (val & MESON_SAR_ADC_DELAY_BL30_BUSY && timeout--);
-
-	if (timeout < 0)
-		return -ETIMEDOUT;
+	if (priv->data->has_bl30_integration) {
+		/* prevent BL30 from using the SAR ADC while we are using it */
+		regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY,
+				MESON_SAR_ADC_DELAY_KERNEL_BUSY,
+				MESON_SAR_ADC_DELAY_KERNEL_BUSY);
+
+		/*
+		 * wait until BL30 releases it's lock (so we can use the SAR
+		 * ADC)
+		 */
+		do {
+			udelay(1);
+			regmap_read(priv->regmap, MESON_SAR_ADC_DELAY, &val);
+		} while (val & MESON_SAR_ADC_DELAY_BL30_BUSY && timeout--);
+
+		if (timeout < 0)
+			return -ETIMEDOUT;
+	}
 
 	return 0;
 }
@@ -458,9 +464,10 @@ static void meson_sar_adc_unlock(struct iio_dev *indio_dev)
 {
 	struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
 
-	/* allow BL30 to use the SAR ADC again */
-	regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY,
-			   MESON_SAR_ADC_DELAY_KERNEL_BUSY, 0);
+	if (priv->data->has_bl30_integration)
+		/* allow BL30 to use the SAR ADC again */
+		regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY,
+				MESON_SAR_ADC_DELAY_KERNEL_BUSY, 0);
 
 	mutex_unlock(&indio_dev->mlock);
 }
@@ -614,14 +621,16 @@ static int meson_sar_adc_init(struct iio_dev *indio_dev)
 	 */
 	meson_sar_adc_set_chan7_mux(indio_dev, CHAN7_MUX_CH7_INPUT);
 
-	/*
-	 * leave sampling delay and the input clocks as configured by BL30 to
-	 * make sure BL30 gets the values it expects when reading the
-	 * temperature sensor.
-	 */
-	regmap_read(priv->regmap, MESON_SAR_ADC_REG3, &regval);
-	if (regval & MESON_SAR_ADC_REG3_BL30_INITIALIZED)
-		return 0;
+	if (priv->data->has_bl30_integration) {
+		/*
+		 * leave sampling delay and the input clocks as configured by
+		 * BL30 to make sure BL30 gets the values it expects when
+		 * reading the temperature sensor.
+		 */
+		regmap_read(priv->regmap, MESON_SAR_ADC_REG3, &regval);
+		if (regval & MESON_SAR_ADC_REG3_BL30_INITIALIZED)
+			return 0;
+	}
 
 	meson_sar_adc_stop_sample_engine(indio_dev);
 
@@ -834,23 +843,46 @@ static const struct iio_info meson_sar_adc_iio_info = {
 	.driver_module = THIS_MODULE,
 };
 
+static const struct meson_sar_adc_data meson_sar_adc_meson8_data = {
+	.has_bl30_integration = false,
+	.resolution = 10,
+	.name = "meson-meson8-saradc",
+};
+
+static const struct meson_sar_adc_data meson_sar_adc_meson8b_data = {
+	.has_bl30_integration = false,
+	.resolution = 10,
+	.name = "meson-meson8b-saradc",
+};
+
 static const struct meson_sar_adc_data meson_sar_adc_gxbb_data = {
+	.has_bl30_integration = true,
 	.resolution = 10,
 	.name = "meson-gxbb-saradc",
 };
 
 static const struct meson_sar_adc_data meson_sar_adc_gxl_data = {
+	.has_bl30_integration = true,
 	.resolution = 12,
 	.name = "meson-gxl-saradc",
 };
 
 static const struct meson_sar_adc_data meson_sar_adc_gxm_data = {
+	.has_bl30_integration = true,
 	.resolution = 12,
 	.name = "meson-gxm-saradc",
 };
 
 static const struct of_device_id meson_sar_adc_of_match[] = {
 	{
+		.compatible = "amlogic,meson8-saradc",
+		.data = &meson_sar_adc_meson8_data,
+	},
+	{
+		.compatible = "amlogic,meson8b-saradc",
+		.data = &meson_sar_adc_meson8b_data,
+	},
+	{
 		.compatible = "amlogic,meson-gxbb-saradc",
 		.data = &meson_sar_adc_gxbb_data,
 	}, {
-- 
2.12.2

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v4 1/3] iio: adc: meson-saradc: mark all meson_sar_adc_data static and const
  2017-05-06 13:49   ` [PATCH v4 1/3] iio: adc: meson-saradc: mark all meson_sar_adc_data static and const Martin Blumenstingl
@ 2017-05-07 11:35     ` Jonathan Cameron
  0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2017-05-07 11:35 UTC (permalink / raw)
  To: Martin Blumenstingl, knaack.h, lars, pmeerw, robh+dt,
	mark.rutland, linux-iio
  Cc: devicetree, khilman, thomas.langer, carlo, linux-amlogic,
	linux-arm-kernel

On 06/05/17 14:49, Martin Blumenstingl wrote:
> These are only passed as of_device_id.data and never modified. Thus we
> can mark them as static const, just like the of_device_id instances
> where they are used.
> 
> Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Good catch indeed on those consts!

Applied to the togreg branch of iio.git and pushed out as testing.

Thanks,

Jonathan
> ---
>  drivers/iio/adc/meson_saradc.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c
> index dd4190b50df6..2f6fec995264 100644
> --- a/drivers/iio/adc/meson_saradc.c
> +++ b/drivers/iio/adc/meson_saradc.c
> @@ -834,17 +834,17 @@ static const struct iio_info meson_sar_adc_iio_info = {
>  	.driver_module = THIS_MODULE,
>  };
>  
> -struct meson_sar_adc_data meson_sar_adc_gxbb_data = {
> +static const struct meson_sar_adc_data meson_sar_adc_gxbb_data = {
>  	.resolution = 10,
>  	.name = "meson-gxbb-saradc",
>  };
>  
> -struct meson_sar_adc_data meson_sar_adc_gxl_data = {
> +static const struct meson_sar_adc_data meson_sar_adc_gxl_data = {
>  	.resolution = 12,
>  	.name = "meson-gxl-saradc",
>  };
>  
> -struct meson_sar_adc_data meson_sar_adc_gxm_data = {
> +static const struct meson_sar_adc_data meson_sar_adc_gxm_data = {
>  	.resolution = 12,
>  	.name = "meson-gxm-saradc",
>  };
> 

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

* Re: [PATCH v4 2/3] dt-bindings: iio: adc: add Meson8 and Meson8b support
  2017-05-06 13:49   ` [PATCH v4 2/3] dt-bindings: iio: adc: add Meson8 and Meson8b support Martin Blumenstingl
@ 2017-05-07 11:35     ` Jonathan Cameron
  0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2017-05-07 11:35 UTC (permalink / raw)
  To: Martin Blumenstingl, knaack.h, lars, pmeerw, robh+dt,
	mark.rutland, linux-iio
  Cc: devicetree, khilman, thomas.langer, carlo, linux-amlogic,
	linux-arm-kernel

On 06/05/17 14:49, Martin Blumenstingl wrote:
> The Amlogic Meson SAR ADC driver can be used on Meson8 and Meson8b
> (probably on earlier SoC generations as well, but I don't have any
> hardware available for testing that).
> Add a separate compatible for Meson8 and Meson8b because it does not
> need any of the BL30 magic (unlike the GX SoCs).
> 
> Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
> Acked-by: Rob Herring <robh@kernel.org>
Applied
> ---
>  Documentation/devicetree/bindings/iio/adc/amlogic,meson-saradc.txt | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/iio/adc/amlogic,meson-saradc.txt b/Documentation/devicetree/bindings/iio/adc/amlogic,meson-saradc.txt
> index f9e3ff2c656e..08cee82e54c3 100644
> --- a/Documentation/devicetree/bindings/iio/adc/amlogic,meson-saradc.txt
> +++ b/Documentation/devicetree/bindings/iio/adc/amlogic,meson-saradc.txt
> @@ -2,6 +2,8 @@
>  
>  Required properties:
>  - compatible:	depending on the SoC this should be one of:
> +			- "amlogic,meson8-saradc" for Meson8
> +			- "amlogic,meson8b-saradc" for Meson8b
>  			- "amlogic,meson-gxbb-saradc" for GXBB
>  			- "amlogic,meson-gxl-saradc" for GXL
>  			- "amlogic,meson-gxm-saradc" for GXM
> 

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

* Re: [PATCH v4 3/3] iio: adc: meson-saradc: add Meson8b SoC compatibility
  2017-05-06 13:49   ` [PATCH v4 3/3] iio: adc: meson-saradc: add Meson8b SoC compatibility Martin Blumenstingl
@ 2017-05-07 11:35     ` Jonathan Cameron
  0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2017-05-07 11:35 UTC (permalink / raw)
  To: Martin Blumenstingl, knaack.h, lars, pmeerw, robh+dt,
	mark.rutland, linux-iio
  Cc: devicetree, khilman, thomas.langer, carlo, linux-amlogic,
	linux-arm-kernel

On 06/05/17 14:49, Martin Blumenstingl wrote:
> Meson GX SoCs however use some magic bits to prevent simultaneous (=
> conflicting, because only consumer should use the FIFO buffer with the
> ADC results) usage by the Linux kernel and the bootloader (the BL30
> bootloader uses the SAR ADC to read the CPU temperature).
> This patch changes guards all BL30 functionality so it is skipped on
> SoCs which don't have it. Since the hardware itself doesn't know whether
> BL30 is available the internal meson_sar_adc_data is extended so this
> information can be provided per of_device_id.data inside the driver.
> 
> Additionally the clocks "adc_clk" and "adc_sel" are not provided by the
> clock-controller itself. "adc_sel" is not available at all. "adc_clk"
> is provided by the SAR ADC IP block itself on Meson8b (and earlier).
> This is already supported by the meson_saradc driver.
> 
> Finally this introduces new of_device_ids for the Meson8 and Meson8b
> SoCs so the driver can be wired up in the corresponding DT.
> 
> Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.

Thanks,

Jonathan
> ---
>  drivers/iio/adc/meson_saradc.c | 80 +++++++++++++++++++++++++++++-------------
>  1 file changed, 56 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c
> index 2f6fec995264..81cd39a57fe3 100644
> --- a/drivers/iio/adc/meson_saradc.c
> +++ b/drivers/iio/adc/meson_saradc.c
> @@ -220,6 +220,7 @@ enum meson_sar_adc_chan7_mux_sel {
>  };
>  
>  struct meson_sar_adc_data {
> +	bool					has_bl30_integration;
>  	unsigned int				resolution;
>  	const char				*name;
>  };
> @@ -437,19 +438,24 @@ static int meson_sar_adc_lock(struct iio_dev *indio_dev)
>  
>  	mutex_lock(&indio_dev->mlock);
>  
> -	/* prevent BL30 from using the SAR ADC while we are using it */
> -	regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY,
> -			   MESON_SAR_ADC_DELAY_KERNEL_BUSY,
> -			   MESON_SAR_ADC_DELAY_KERNEL_BUSY);
> -
> -	/* wait until BL30 releases it's lock (so we can use the SAR ADC) */
> -	do {
> -		udelay(1);
> -		regmap_read(priv->regmap, MESON_SAR_ADC_DELAY, &val);
> -	} while (val & MESON_SAR_ADC_DELAY_BL30_BUSY && timeout--);
> -
> -	if (timeout < 0)
> -		return -ETIMEDOUT;
> +	if (priv->data->has_bl30_integration) {
> +		/* prevent BL30 from using the SAR ADC while we are using it */
> +		regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY,
> +				MESON_SAR_ADC_DELAY_KERNEL_BUSY,
> +				MESON_SAR_ADC_DELAY_KERNEL_BUSY);
> +
> +		/*
> +		 * wait until BL30 releases it's lock (so we can use the SAR
> +		 * ADC)
> +		 */
> +		do {
> +			udelay(1);
> +			regmap_read(priv->regmap, MESON_SAR_ADC_DELAY, &val);
> +		} while (val & MESON_SAR_ADC_DELAY_BL30_BUSY && timeout--);
> +
> +		if (timeout < 0)
> +			return -ETIMEDOUT;
> +	}
>  
>  	return 0;
>  }
> @@ -458,9 +464,10 @@ static void meson_sar_adc_unlock(struct iio_dev *indio_dev)
>  {
>  	struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
>  
> -	/* allow BL30 to use the SAR ADC again */
> -	regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY,
> -			   MESON_SAR_ADC_DELAY_KERNEL_BUSY, 0);
> +	if (priv->data->has_bl30_integration)
> +		/* allow BL30 to use the SAR ADC again */
> +		regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY,
> +				MESON_SAR_ADC_DELAY_KERNEL_BUSY, 0);
>  
>  	mutex_unlock(&indio_dev->mlock);
>  }
> @@ -614,14 +621,16 @@ static int meson_sar_adc_init(struct iio_dev *indio_dev)
>  	 */
>  	meson_sar_adc_set_chan7_mux(indio_dev, CHAN7_MUX_CH7_INPUT);
>  
> -	/*
> -	 * leave sampling delay and the input clocks as configured by BL30 to
> -	 * make sure BL30 gets the values it expects when reading the
> -	 * temperature sensor.
> -	 */
> -	regmap_read(priv->regmap, MESON_SAR_ADC_REG3, &regval);
> -	if (regval & MESON_SAR_ADC_REG3_BL30_INITIALIZED)
> -		return 0;
> +	if (priv->data->has_bl30_integration) {
> +		/*
> +		 * leave sampling delay and the input clocks as configured by
> +		 * BL30 to make sure BL30 gets the values it expects when
> +		 * reading the temperature sensor.
> +		 */
> +		regmap_read(priv->regmap, MESON_SAR_ADC_REG3, &regval);
> +		if (regval & MESON_SAR_ADC_REG3_BL30_INITIALIZED)
> +			return 0;
> +	}
>  
>  	meson_sar_adc_stop_sample_engine(indio_dev);
>  
> @@ -834,23 +843,46 @@ static const struct iio_info meson_sar_adc_iio_info = {
>  	.driver_module = THIS_MODULE,
>  };
>  
> +static const struct meson_sar_adc_data meson_sar_adc_meson8_data = {
> +	.has_bl30_integration = false,
> +	.resolution = 10,
> +	.name = "meson-meson8-saradc",
> +};
> +
> +static const struct meson_sar_adc_data meson_sar_adc_meson8b_data = {
> +	.has_bl30_integration = false,
> +	.resolution = 10,
> +	.name = "meson-meson8b-saradc",
> +};
> +
>  static const struct meson_sar_adc_data meson_sar_adc_gxbb_data = {
> +	.has_bl30_integration = true,
>  	.resolution = 10,
>  	.name = "meson-gxbb-saradc",
>  };
>  
>  static const struct meson_sar_adc_data meson_sar_adc_gxl_data = {
> +	.has_bl30_integration = true,
>  	.resolution = 12,
>  	.name = "meson-gxl-saradc",
>  };
>  
>  static const struct meson_sar_adc_data meson_sar_adc_gxm_data = {
> +	.has_bl30_integration = true,
>  	.resolution = 12,
>  	.name = "meson-gxm-saradc",
>  };
>  
>  static const struct of_device_id meson_sar_adc_of_match[] = {
>  	{
> +		.compatible = "amlogic,meson8-saradc",
> +		.data = &meson_sar_adc_meson8_data,
> +	},
> +	{
> +		.compatible = "amlogic,meson8b-saradc",
> +		.data = &meson_sar_adc_meson8b_data,
> +	},
> +	{
>  		.compatible = "amlogic,meson-gxbb-saradc",
>  		.data = &meson_sar_adc_gxbb_data,
>  	}, {
> 

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

end of thread, other threads:[~2017-05-07 11:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-06 13:49 [PATCH v4 0/3] Meson8 / Meson8b support for the meson_saradc driver Martin Blumenstingl
     [not found] ` <20170506134929.31190-1-martin.blumenstingl-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>
2017-05-06 13:49   ` [PATCH v4 1/3] iio: adc: meson-saradc: mark all meson_sar_adc_data static and const Martin Blumenstingl
2017-05-07 11:35     ` Jonathan Cameron
2017-05-06 13:49   ` [PATCH v4 2/3] dt-bindings: iio: adc: add Meson8 and Meson8b support Martin Blumenstingl
2017-05-07 11:35     ` Jonathan Cameron
2017-05-06 13:49   ` [PATCH v4 3/3] iio: adc: meson-saradc: add Meson8b SoC compatibility Martin Blumenstingl
2017-05-07 11:35     ` 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).