Linux IIO development
 help / color / mirror / Atom feed
* [PATCH v3 0/2] iio: adc: ad7192: Fix clock config
@ 2024-06-12 14:16 Alisa-Dariana Roman
  2024-06-12 14:16 ` [PATCH v3 1/2] dt-bindings: " Alisa-Dariana Roman
  2024-06-12 14:16 ` [PATCH v3 2/2] " Alisa-Dariana Roman
  0 siblings, 2 replies; 5+ messages in thread
From: Alisa-Dariana Roman @ 2024-06-12 14:16 UTC (permalink / raw)
  To: Alisa-Dariana Roman, Jonathan Cameron, Michael Hennerich,
	linux-iio, devicetree, linux-kernel
  Cc: Alexandru Tachici, Lars-Peter Clausen, Michael Hennerich,
	Jonathan Cameron, Rob Herring, Krzysztof Kozlowski, Conor Dooley

Dear maintainers,

Thank you very much for your feedback!

Here is the series of only fixes. I will create another series for the
other patches.

King regards,
Alisa-Dariana Roman.

v2 -> v3
  - remove clean up patch
  - remove clk provider part
  - keep name mclk
  - organize in function ad7192_clock_setup
  - change commit messages accordingly



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

* [PATCH v3 1/2] dt-bindings: iio: adc: ad7192: Fix clock config
  2024-06-12 14:16 [PATCH v3 0/2] iio: adc: ad7192: Fix clock config Alisa-Dariana Roman
@ 2024-06-12 14:16 ` Alisa-Dariana Roman
  2024-06-12 16:30   ` Conor Dooley
  2024-06-12 14:16 ` [PATCH v3 2/2] " Alisa-Dariana Roman
  1 sibling, 1 reply; 5+ messages in thread
From: Alisa-Dariana Roman @ 2024-06-12 14:16 UTC (permalink / raw)
  To: Alisa-Dariana Roman, Jonathan Cameron, Michael Hennerich,
	linux-iio, devicetree, linux-kernel
  Cc: Alexandru Tachici, Lars-Peter Clausen, Michael Hennerich,
	Jonathan Cameron, Rob Herring, Krzysztof Kozlowski, Conor Dooley

There are actually 4 configuration modes of clock source for AD719X
devices. Either a crystal can be attached externally between MCLK1 and
MCLK2 pins, or an external CMOS-compatible clock can drive the MCLK2
pin. The other 2 modes make use of the 4.92MHz internal clock.

The presence of an external clock is optional, not required. When
absent, internal clock of the device is used.

Fixes: f7356e47032c ("dt-bindings: iio: adc: ad7192: Add binding documentation for AD7192")
Signed-off-by: Alisa-Dariana Roman <alisa.roman@analog.com>
---
 .../devicetree/bindings/iio/adc/adi,ad7192.yaml    | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml
index a03da9489ed9..3ae2f860d24c 100644
--- a/Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml
@@ -39,11 +39,15 @@ properties:
 
   clocks:
     maxItems: 1
-    description: phandle to the master clock (mclk)
+    description: |
+      Optionally, either a crystal can be attached externally between MCLK1 and
+      MCLK2 pins, or an external CMOS-compatible clock can drive the MCLK2
+      pin. If absent, internal 4.92MHz clock is used.
 
   clock-names:
-    items:
-      - const: mclk
+    enum:
+      - xtal
+      - mclk
 
   interrupts:
     maxItems: 1
@@ -135,8 +139,6 @@ patternProperties:
 required:
   - compatible
   - reg
-  - clocks
-  - clock-names
   - interrupts
   - dvdd-supply
   - avdd-supply
@@ -202,8 +204,6 @@ examples:
             spi-max-frequency = <1000000>;
             spi-cpol;
             spi-cpha;
-            clocks = <&ad7192_mclk>;
-            clock-names = "mclk";
             interrupts = <25 0x2>;
             interrupt-parent = <&gpio>;
             aincom-supply = <&aincom>;
-- 
2.34.1


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

* [PATCH v3 2/2] iio: adc: ad7192: Fix clock config
  2024-06-12 14:16 [PATCH v3 0/2] iio: adc: ad7192: Fix clock config Alisa-Dariana Roman
  2024-06-12 14:16 ` [PATCH v3 1/2] dt-bindings: " Alisa-Dariana Roman
@ 2024-06-12 14:16 ` Alisa-Dariana Roman
  2024-06-12 15:05   ` Nuno Sá
  1 sibling, 1 reply; 5+ messages in thread
From: Alisa-Dariana Roman @ 2024-06-12 14:16 UTC (permalink / raw)
  To: Alisa-Dariana Roman, Jonathan Cameron, Michael Hennerich,
	linux-iio, devicetree, linux-kernel
  Cc: Alexandru Tachici, Lars-Peter Clausen, Michael Hennerich,
	Jonathan Cameron, Rob Herring, Krzysztof Kozlowski, Conor Dooley

There are actually 4 configuration modes of clock source for AD719X
devices. Either a crystal can be attached externally between MCLK1 and
MCLK2 pins, or an external CMOS-compatible clock can drive the MCLK2
pin. The other 2 modes make use of the 4.92MHz internal clock.

Note that the fix tag is for the commit that moved the driver out of
staging.

Fixes: b581f748cce0 ("staging: iio: adc: ad7192: move out of staging")
Signed-off-by: Alisa-Dariana Roman <alisa.roman@analog.com>
---
 drivers/iio/adc/ad7192.c | 58 +++++++++++++++++++---------------------
 1 file changed, 28 insertions(+), 30 deletions(-)

diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c
index 0789121236d6..2301fee9ccd0 100644
--- a/drivers/iio/adc/ad7192.c
+++ b/drivers/iio/adc/ad7192.c
@@ -398,25 +398,37 @@ static inline bool ad7192_valid_external_frequency(u32 freq)
 		freq <= AD7192_EXT_FREQ_MHZ_MAX);
 }
 
-static int ad7192_clock_select(struct ad7192_state *st)
+static const char *const ad7192_clock_names[] = {
+	"xtal",
+	"mclk"
+};
+
+static int ad7192_clock_setup(struct ad7192_state *st)
 {
 	struct device *dev = &st->sd.spi->dev;
-	unsigned int clock_sel;
-
-	clock_sel = AD7192_CLK_INT;
+	int ret;
 
-	/* use internal clock */
-	if (!st->mclk) {
-		if (device_property_read_bool(dev, "adi,int-clock-output-enable"))
-			clock_sel = AD7192_CLK_INT_CO;
+	ret = device_property_match_property_string(dev, "clock-names",
+						    ad7192_clock_names,
+						    ARRAY_SIZE(ad7192_clock_names));
+	if (ret < 0) {
+		st->clock_sel = AD7192_CLK_INT;
+		st->fclk = AD7192_INT_FREQ_MHZ;
 	} else {
-		if (device_property_read_bool(dev, "adi,clock-xtal"))
-			clock_sel = AD7192_CLK_EXT_MCLK1_2;
-		else
-			clock_sel = AD7192_CLK_EXT_MCLK2;
+		st->clock_sel = AD7192_CLK_EXT_MCLK1_2 + ret;
+
+		st->mclk = devm_clk_get_enabled(dev, ad7192_clock_names[ret]);
+		if (IS_ERR(st->mclk))
+			return dev_err_probe(dev, PTR_ERR(st->mclk),
+					     "Failed to get mclk\n");
+
+		st->fclk = clk_get_rate(st->mclk);
+		if (!ad7192_valid_external_frequency(st->fclk))
+			return dev_err_probe(dev, -EINVAL,
+					     "External clock frequency out of bounds\n");
 	}
 
-	return clock_sel;
+	return 0;
 }
 
 static int ad7192_setup(struct iio_dev *indio_dev, struct device *dev)
@@ -1309,23 +1321,9 @@ static int ad7192_probe(struct spi_device *spi)
 	if (ret)
 		return ret;
 
-	st->fclk = AD7192_INT_FREQ_MHZ;
-
-	st->mclk = devm_clk_get_optional_enabled(&spi->dev, "mclk");
-	if (IS_ERR(st->mclk))
-		return PTR_ERR(st->mclk);
-
-	st->clock_sel = ad7192_clock_select(st);
-
-	if (st->clock_sel == AD7192_CLK_EXT_MCLK1_2 ||
-	    st->clock_sel == AD7192_CLK_EXT_MCLK2) {
-		st->fclk = clk_get_rate(st->mclk);
-		if (!ad7192_valid_external_frequency(st->fclk)) {
-			dev_err(&spi->dev,
-				"External clock frequency out of bounds\n");
-			return -EINVAL;
-		}
-	}
+	ret = ad7192_clock_setup(st);
+	if (ret)
+		return ret;
 
 	ret = ad7192_setup(indio_dev, &spi->dev);
 	if (ret)
-- 
2.34.1


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

* Re: [PATCH v3 2/2] iio: adc: ad7192: Fix clock config
  2024-06-12 14:16 ` [PATCH v3 2/2] " Alisa-Dariana Roman
@ 2024-06-12 15:05   ` Nuno Sá
  0 siblings, 0 replies; 5+ messages in thread
From: Nuno Sá @ 2024-06-12 15:05 UTC (permalink / raw)
  To: Alisa-Dariana Roman, Alisa-Dariana Roman, Jonathan Cameron,
	Michael Hennerich, linux-iio, devicetree, linux-kernel
  Cc: Alexandru Tachici, Lars-Peter Clausen, Jonathan Cameron,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley

On Wed, 2024-06-12 at 17:16 +0300, Alisa-Dariana Roman wrote:
> There are actually 4 configuration modes of clock source for AD719X
> devices. Either a crystal can be attached externally between MCLK1 and
> MCLK2 pins, or an external CMOS-compatible clock can drive the MCLK2
> pin. The other 2 modes make use of the 4.92MHz internal clock.
> 
> Note that the fix tag is for the commit that moved the driver out of
> staging.
> 
> Fixes: b581f748cce0 ("staging: iio: adc: ad7192: move out of staging")
> Signed-off-by: Alisa-Dariana Roman <alisa.roman@analog.com>
> ---

Hmmm, I did not looked at the datasheet but looked at the older implementation
and I'm not sure this is an actual fix. Can you elaborate on that?

So on the current implementation I can see that we have some properties that are
not documented:

adi,int-clock-output-enable
adi,clock-xtal

So, I see in your series that you're documenting adi,clock-xtal using clk-names.
I do think your code is cleaner but I don't think the older implementation to be
buggy. Am I missing something?

I can also see that you're ignoring AD7192_CLK_INT_CO... That's also removing
functionality from the driver even though the implementation is not as it should
be I think. If I understand that mode correctly, it's just about having the
internal clock in the MCLK pin. Effectively this would then be a clock provider
with a fixed rate of 4.92MHz. So I believe that exposing it as a clock provider
would likely be the way to go.

- Nuno Sá 



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

* Re: [PATCH v3 1/2] dt-bindings: iio: adc: ad7192: Fix clock config
  2024-06-12 14:16 ` [PATCH v3 1/2] dt-bindings: " Alisa-Dariana Roman
@ 2024-06-12 16:30   ` Conor Dooley
  0 siblings, 0 replies; 5+ messages in thread
From: Conor Dooley @ 2024-06-12 16:30 UTC (permalink / raw)
  To: Alisa-Dariana Roman
  Cc: Alisa-Dariana Roman, Jonathan Cameron, Michael Hennerich,
	linux-iio, devicetree, linux-kernel, Alexandru Tachici,
	Lars-Peter Clausen, Jonathan Cameron, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley

[-- Attachment #1: Type: text/plain, Size: 1687 bytes --]

On Wed, Jun 12, 2024 at 05:16:36PM +0300, Alisa-Dariana Roman wrote:
> There are actually 4 configuration modes of clock source for AD719X
> devices. Either a crystal can be attached externally between MCLK1 and
> MCLK2 pins, or an external CMOS-compatible clock can drive the MCLK2
> pin. The other 2 modes make use of the 4.92MHz internal clock.
> 
> The presence of an external clock is optional, not required. When
> absent, internal clock of the device is used.
> 
> Fixes: f7356e47032c ("dt-bindings: iio: adc: ad7192: Add binding documentation for AD7192")
> Signed-off-by: Alisa-Dariana Roman <alisa.roman@analog.com>
> ---
>  .../devicetree/bindings/iio/adc/adi,ad7192.yaml    | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml
> index a03da9489ed9..3ae2f860d24c 100644
> --- a/Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml
> +++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml
> @@ -39,11 +39,15 @@ properties:
>  
>    clocks:
>      maxItems: 1
> -    description: phandle to the master clock (mclk)
> +    description: |
> +      Optionally, either a crystal can be attached externally between MCLK1 and
> +      MCLK2 pins, or an external CMOS-compatible clock can drive the MCLK2
> +      pin. If absent, internal 4.92MHz clock is used.
>  
>    clock-names:
> -    items:
> -      - const: mclk
> +    enum:
> +      - xtal
> +      - mclk

Nothing in this commit message explains why "mclk" is not a suitable
name for either of the two configurations.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

end of thread, other threads:[~2024-06-12 16:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-12 14:16 [PATCH v3 0/2] iio: adc: ad7192: Fix clock config Alisa-Dariana Roman
2024-06-12 14:16 ` [PATCH v3 1/2] dt-bindings: " Alisa-Dariana Roman
2024-06-12 16:30   ` Conor Dooley
2024-06-12 14:16 ` [PATCH v3 2/2] " Alisa-Dariana Roman
2024-06-12 15:05   ` Nuno Sá

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