* [PATCH v2 1/4] dt-bindings: iio: adc: adi,ad7124: fix clocks properties
2025-08-25 22:54 [PATCH v2 0/4] iio: adc: ad7124: proper clock support David Lechner
@ 2025-08-25 22:55 ` David Lechner
2025-08-25 22:55 ` [PATCH v2 2/4] iio: adc: ad7124: do not require mclk David Lechner
` (2 subsequent siblings)
3 siblings, 0 replies; 12+ messages in thread
From: David Lechner @ 2025-08-25 22:55 UTC (permalink / raw)
To: Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: linux-iio, devicetree, linux-kernel, David Lechner
Use correct clocks properties for the AD7124 family of ADCs.
These ADCs have an internal clock along with an optional external clock
that can be connected to the CLK pin. This pin can be wired up 3 ways:
1. Not connected - the internal clock is used.
2. Connected to an external clock (input) - the external clock is used.
3. Connected to the CLK pin on another ADC (output) - the internal clock
is used on one and the other is configured for an external clock.
The new bindings describe these 3 cases by picking one of the following:
1. Omit both clocks and #clock-cells properties.
2. Include only the clocks property with a phandle to the external clock.
3. Include only the #clock-cells property on the ADC providing the output.
The clock-names property is now deprecated and should not be used. The
MCLK signal that it refers to is an internal counter in the ADC and
therefore does not make sense as a devicetree property as it can't be
connected to anything external to the ADC. Since there is only one
possible external clock, the clock-names property is not needed anyway.
Based on the implementation of the Linux driver, it looks like the
"mclk" clock was basically being used as a control to select the power
mode of the ADC, which is not something that should be done in the
devicetree.
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
.../devicetree/bindings/iio/adc/adi,ad7124.yaml | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml
index 4dd5395730c10925c86782116dfd70a75d033bfb..2e3f84db6193b3d8765e2bdbd2d3175cf1892ba4 100644
--- a/Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml
@@ -28,12 +28,21 @@ properties:
clocks:
maxItems: 1
- description: phandle to the master clock (mclk)
+ description: Optional external clock connected to the CLK pin.
clock-names:
+ deprecated: true
+ description:
+ MCLK is an internal counter in the ADC. Do not use this property.
items:
- const: mclk
+ '#clock-cells':
+ description:
+ The CLK pin can be used as an output. When that is the case, include
+ this property.
+ const: 0
+
interrupts:
description: IRQ line for the ADC
maxItems: 1
@@ -67,10 +76,14 @@ properties:
required:
- compatible
- reg
- - clocks
- - clock-names
- interrupts
+# Can't have both clock input and output at the same time.
+not:
+ required:
+ - '#clock-cells'
+ - clocks
+
patternProperties:
"^channel@([0-9]|1[0-5])$":
$ref: adc.yaml
@@ -136,8 +149,6 @@ examples:
interrupt-parent = <&gpio>;
rdy-gpios = <&gpio 25 GPIO_ACTIVE_LOW>;
refin1-supply = <&adc_vref>;
- clocks = <&ad7124_mclk>;
- clock-names = "mclk";
#address-cells = <1>;
#size-cells = <0>;
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 2/4] iio: adc: ad7124: do not require mclk
2025-08-25 22:54 [PATCH v2 0/4] iio: adc: ad7124: proper clock support David Lechner
2025-08-25 22:55 ` [PATCH v2 1/4] dt-bindings: iio: adc: adi,ad7124: fix clocks properties David Lechner
@ 2025-08-25 22:55 ` David Lechner
2025-08-25 22:55 ` [PATCH v2 3/4] iio: adc: ad7124: add external clock support David Lechner
2025-08-25 22:55 ` [PATCH v2 4/4] iio: adc: ad7124: add clock output support David Lechner
3 siblings, 0 replies; 12+ messages in thread
From: David Lechner @ 2025-08-25 22:55 UTC (permalink / raw)
To: Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: linux-iio, devicetree, linux-kernel, David Lechner
Make the "mclk" clock optional in the ad7124 driver. The MCLK is an
internal counter on the ADC, so it is not something that should be
coming from the devicetree. However, existing users may be using this
to essentially select the power mode of the ADC from the devicetree.
In order to not break those users, we have to keep the existing "mclk"
handling, but now it is optional.
Now, when the "mclk" clock is omitted from the devicetree, the driver
will default to the full power mode. Support for an external clock
and dynamic power mode switching can be added later if needed.
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
drivers/iio/adc/ad7124.c | 62 ++++++++++++++++++++++++++++++++++--------------
1 file changed, 44 insertions(+), 18 deletions(-)
diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
index 3fc24f5fffc8f200c8656cb97f9e7f80546f688b..49003c8436463f49a47564644fd8e405579df829 100644
--- a/drivers/iio/adc/ad7124.c
+++ b/drivers/iio/adc/ad7124.c
@@ -174,7 +174,6 @@ struct ad7124_state {
struct ad_sigma_delta sd;
struct ad7124_channel *channels;
struct regulator *vref[4];
- struct clk *mclk;
unsigned int adc_control;
unsigned int num_channels;
struct mutex cfgs_lock; /* lock for configs access */
@@ -254,7 +253,9 @@ static void ad7124_set_channel_odr(struct ad7124_state *st, unsigned int channel
{
unsigned int fclk, odr_sel_bits;
- fclk = clk_get_rate(st->mclk);
+ fclk = ad7124_master_clk_freq_hz[FIELD_GET(AD7124_ADC_CONTROL_POWER_MODE,
+ st->adc_control)];
+
/*
* FS[10:0] = fCLK / (fADC x 32) where:
* fADC is the output data rate
@@ -1111,21 +1112,50 @@ static int ad7124_parse_channel_config(struct iio_dev *indio_dev,
static int ad7124_setup(struct ad7124_state *st)
{
struct device *dev = &st->sd.spi->dev;
- unsigned int fclk, power_mode;
+ unsigned int power_mode;
+ struct clk *mclk;
int i, ret;
- fclk = clk_get_rate(st->mclk);
- if (!fclk)
- return dev_err_probe(dev, -EINVAL, "Failed to get mclk rate\n");
+ /*
+ * Always use full power mode for max performance. If needed, the driver
+ * could be adapted to use a dynamic power mode based on the requested
+ * output data rate.
+ */
+ power_mode = AD7124_ADC_CONTROL_POWER_MODE_FULL;
- /* The power mode changes the master clock frequency */
- power_mode = ad7124_find_closest_match(ad7124_master_clk_freq_hz,
- ARRAY_SIZE(ad7124_master_clk_freq_hz),
- fclk);
- if (fclk != ad7124_master_clk_freq_hz[power_mode]) {
- ret = clk_set_rate(st->mclk, fclk);
- if (ret)
- return dev_err_probe(dev, ret, "Failed to set mclk rate\n");
+ /*
+ * This "mclk" business is needed for backwards compatibility with old
+ * devicetrees that specified a fake clock named "mclk" to select the
+ * power mode.
+ */
+ mclk = devm_clk_get_optional_enabled(dev, "mclk");
+ if (IS_ERR(mclk))
+ return dev_err_probe(dev, PTR_ERR(mclk), "Failed to get mclk\n");
+
+ if (mclk) {
+ unsigned long mclk_hz;
+
+ mclk_hz = clk_get_rate(mclk);
+ if (!mclk_hz)
+ return dev_err_probe(dev, -EINVAL,
+ "Failed to get mclk rate\n");
+
+ /*
+ * This logic is a bit backwards, which is why it is only here
+ * for backwards compatibility. The driver should be able to set
+ * the power mode as it sees fit and the f_clk/mclk rate should
+ * be dynamic accordingly. But here, we are selecting a fixed
+ * power mode based on the given "mclk" rate.
+ */
+ power_mode = ad7124_find_closest_match(ad7124_master_clk_freq_hz,
+ ARRAY_SIZE(ad7124_master_clk_freq_hz), mclk_hz);
+
+ if (mclk_hz != ad7124_master_clk_freq_hz[power_mode]) {
+ ret = clk_set_rate(mclk, mclk_hz);
+ if (ret)
+ return dev_err_probe(dev, ret,
+ "Failed to set mclk rate\n");
+ }
}
/* Set the power mode */
@@ -1303,10 +1333,6 @@ static int ad7124_probe(struct spi_device *spi)
return ret;
}
- st->mclk = devm_clk_get_enabled(&spi->dev, "mclk");
- if (IS_ERR(st->mclk))
- return dev_err_probe(dev, PTR_ERR(st->mclk), "Failed to get mclk\n");
-
ret = ad7124_soft_reset(st);
if (ret < 0)
return ret;
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 3/4] iio: adc: ad7124: add external clock support
2025-08-25 22:54 [PATCH v2 0/4] iio: adc: ad7124: proper clock support David Lechner
2025-08-25 22:55 ` [PATCH v2 1/4] dt-bindings: iio: adc: adi,ad7124: fix clocks properties David Lechner
2025-08-25 22:55 ` [PATCH v2 2/4] iio: adc: ad7124: do not require mclk David Lechner
@ 2025-08-25 22:55 ` David Lechner
2025-08-26 8:10 ` Andy Shevchenko
2025-08-25 22:55 ` [PATCH v2 4/4] iio: adc: ad7124: add clock output support David Lechner
3 siblings, 1 reply; 12+ messages in thread
From: David Lechner @ 2025-08-25 22:55 UTC (permalink / raw)
To: Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: linux-iio, devicetree, linux-kernel, David Lechner
Add support for an external clock source to the AD7124 ADC driver.
Previously, the driver only supported using the internal clock and had
bad devicetree bindings that used a fake clock to essentially select
the power mode. This is preserved for backwards compatibility.
If the clock is not named "mclk", then we know that the devicetree is
using the correct bindings and we can configure the chip to use an
external clock source rather than internal.
Also drop a redundant comment when configuring the register fields
instead of adding more.
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
drivers/iio/adc/ad7124.c | 44 ++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 42 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
index 49003c8436463f49a47564644fd8e405579df829..4112c484c2371cfa6f26acb0d7c5b2a308a5fb35 100644
--- a/drivers/iio/adc/ad7124.c
+++ b/drivers/iio/adc/ad7124.c
@@ -18,6 +18,7 @@
#include <linux/property.h>
#include <linux/regulator/consumer.h>
#include <linux/spi/spi.h>
+#include <linux/units.h>
#include <linux/iio/iio.h>
#include <linux/iio/adc/ad_sigma_delta.h>
@@ -44,6 +45,11 @@
#define AD7124_STATUS_POR_FLAG BIT(4)
/* AD7124_ADC_CONTROL */
+#define AD7124_ADC_CONTROL_CLK_SEL GENMASK(1, 0)
+#define AD7124_ADC_CONTROL_CLK_SEL_INT 0
+#define AD7124_ADC_CONTROL_CLK_SEL_INT_OUT 1
+#define AD7124_ADC_CONTROL_CLK_SEL_EXT 2
+#define AD7124_ADC_CONTROL_CLK_SEL_EXT_DIV4 3
#define AD7124_ADC_CONTROL_MODE GENMASK(5, 2)
#define AD7124_ADC_CONTROL_MODE_CONTINUOUS 0
#define AD7124_ADC_CONTROL_MODE_SINGLE 1
@@ -1112,7 +1118,7 @@ static int ad7124_parse_channel_config(struct iio_dev *indio_dev,
static int ad7124_setup(struct ad7124_state *st)
{
struct device *dev = &st->sd.spi->dev;
- unsigned int power_mode;
+ unsigned int power_mode, clk_sel;
struct clk *mclk;
int i, ret;
@@ -1156,9 +1162,43 @@ static int ad7124_setup(struct ad7124_state *st)
return dev_err_probe(dev, ret,
"Failed to set mclk rate\n");
}
+
+ clk_sel = AD7124_ADC_CONTROL_CLK_SEL_INT;
+ } else {
+ struct clk *clk;
+
+ clk = devm_clk_get_optional_enabled(dev, NULL);
+ if (IS_ERR(clk))
+ return dev_err_probe(dev, PTR_ERR(clk),
+ "Failed to get external clock\n");
+
+ if (clk) {
+ unsigned long clk_hz;
+
+ clk_hz = clk_get_rate(clk);
+ if (!clk_hz)
+ return dev_err_probe(dev, -EINVAL,
+ "Failed to get external clock rate\n");
+
+ /*
+ * The external clock may be 4x the nominal clock rate,
+ * in which case the ADC needs to be configured to
+ * divide it by 4. Using MEGA is a bit arbitrary, but
+ * the expected clock rates are either 614.4 kHz or
+ * 2.4576 MHz, so this should work.
+ */
+ if (clk_hz > MEGA)
+ clk_sel = AD7124_ADC_CONTROL_CLK_SEL_EXT_DIV4;
+ else
+ clk_sel = AD7124_ADC_CONTROL_CLK_SEL_EXT;
+ } else {
+ clk_sel = AD7124_ADC_CONTROL_CLK_SEL_INT;
+ }
}
- /* Set the power mode */
+ st->adc_control &= ~AD7124_ADC_CONTROL_CLK_SEL;
+ st->adc_control |= FIELD_PREP(AD7124_ADC_CONTROL_CLK_SEL, clk_sel);
+
st->adc_control &= ~AD7124_ADC_CONTROL_POWER_MODE;
st->adc_control |= FIELD_PREP(AD7124_ADC_CONTROL_POWER_MODE, power_mode);
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v2 3/4] iio: adc: ad7124: add external clock support
2025-08-25 22:55 ` [PATCH v2 3/4] iio: adc: ad7124: add external clock support David Lechner
@ 2025-08-26 8:10 ` Andy Shevchenko
2025-08-26 15:17 ` David Lechner
0 siblings, 1 reply; 12+ messages in thread
From: Andy Shevchenko @ 2025-08-26 8:10 UTC (permalink / raw)
To: David Lechner
Cc: Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
linux-iio, devicetree, linux-kernel
On Tue, Aug 26, 2025 at 1:55 AM David Lechner <dlechner@baylibre.com> wrote:
>
> Add support for an external clock source to the AD7124 ADC driver.
>
> Previously, the driver only supported using the internal clock and had
> bad devicetree bindings that used a fake clock to essentially select
> the power mode. This is preserved for backwards compatibility.
>
> If the clock is not named "mclk", then we know that the devicetree is
> using the correct bindings and we can configure the chip to use an
> external clock source rather than internal.
>
> Also drop a redundant comment when configuring the register fields
> instead of adding more.
...
> + /*
> + * The external clock may be 4x the nominal clock rate,
> + * in which case the ADC needs to be configured to
> + * divide it by 4. Using MEGA is a bit arbitrary, but
> + * the expected clock rates are either 614.4 kHz or
> + * 2.4576 MHz, so this should work.
> + */
> + if (clk_hz > MEGA)
This is (1 * HZ_PER_MHZ), but as the comment says, this arbitrary
check may be improved by using the exact values.
> + clk_sel = AD7124_ADC_CONTROL_CLK_SEL_EXT_DIV4;
> + else
> + clk_sel = AD7124_ADC_CONTROL_CLK_SEL_EXT;
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 3/4] iio: adc: ad7124: add external clock support
2025-08-26 8:10 ` Andy Shevchenko
@ 2025-08-26 15:17 ` David Lechner
0 siblings, 0 replies; 12+ messages in thread
From: David Lechner @ 2025-08-26 15:17 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
linux-iio, devicetree, linux-kernel
On 8/26/25 3:10 AM, Andy Shevchenko wrote:
> On Tue, Aug 26, 2025 at 1:55 AM David Lechner <dlechner@baylibre.com> wrote:
>>
>> Add support for an external clock source to the AD7124 ADC driver.
>>
>> Previously, the driver only supported using the internal clock and had
>> bad devicetree bindings that used a fake clock to essentially select
>> the power mode. This is preserved for backwards compatibility.
>>
>> If the clock is not named "mclk", then we know that the devicetree is
>> using the correct bindings and we can configure the chip to use an
>> external clock source rather than internal.
>>
>> Also drop a redundant comment when configuring the register fields
>> instead of adding more.
>
> ...
>
>> + /*
>> + * The external clock may be 4x the nominal clock rate,
>> + * in which case the ADC needs to be configured to
>> + * divide it by 4. Using MEGA is a bit arbitrary, but
>> + * the expected clock rates are either 614.4 kHz or
>> + * 2.4576 MHz, so this should work.
>> + */
>> + if (clk_hz > MEGA)
>
> This is (1 * HZ_PER_MHZ), but as the comment says, this arbitrary
> check may be improved by using the exact values.
The datasheet wasn't clear if an exact value was required or if
there was some tolerance, so this is why I didn't try comparing
to exact values.
>
>> + clk_sel = AD7124_ADC_CONTROL_CLK_SEL_EXT_DIV4;
>> + else
>> + clk_sel = AD7124_ADC_CONTROL_CLK_SEL_EXT;
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2 4/4] iio: adc: ad7124: add clock output support
2025-08-25 22:54 [PATCH v2 0/4] iio: adc: ad7124: proper clock support David Lechner
` (2 preceding siblings ...)
2025-08-25 22:55 ` [PATCH v2 3/4] iio: adc: ad7124: add external clock support David Lechner
@ 2025-08-25 22:55 ` David Lechner
2025-08-26 8:13 ` Andy Shevchenko
` (2 more replies)
3 siblings, 3 replies; 12+ messages in thread
From: David Lechner @ 2025-08-25 22:55 UTC (permalink / raw)
To: Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: linux-iio, devicetree, linux-kernel, David Lechner
Add support for the AD7124's internal clock output. If the #clock-cells
property is present, turn on the internal clock output during probe.
If both the clocks and #clock-names properties are present (not allowed
by devicetree bindings), assume that an external clock is being used so
that we don't accidentally have two outputs fighting each other.
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
We could make this fancier and only turn on the output on demand of a
clock consumer, but then we have to deal with locking of the SPI bus
to be able to write to the register. So I opted for the simpler
solution of always turning it on during probe. This would only be used
for synchronizing with other similar ADCs, so implementing the functions
for a more general-purpose clock seems a bit overkill.
---
drivers/iio/adc/ad7124.c | 37 ++++++++++++++++++++++++++++++++++---
1 file changed, 34 insertions(+), 3 deletions(-)
diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
index 4112c484c2371cfa6f26acb0d7c5b2a308a5fb35..a1c5f059b284c4f8797986628b92b70fd84e90f4 100644
--- a/drivers/iio/adc/ad7124.c
+++ b/drivers/iio/adc/ad7124.c
@@ -7,6 +7,7 @@
#include <linux/bitfield.h>
#include <linux/bitops.h>
#include <linux/clk.h>
+#include <linux/clk-provider.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/err.h>
@@ -18,6 +19,7 @@
#include <linux/property.h>
#include <linux/regulator/consumer.h>
#include <linux/spi/spi.h>
+#include <linux/sprintf.h>
#include <linux/units.h>
#include <linux/iio/iio.h>
@@ -125,10 +127,12 @@ static const unsigned int ad7124_reg_size[] = {
3, 3, 3, 3, 3
};
+#define AD7124_INT_CLK_HZ 614400
+
static const int ad7124_master_clk_freq_hz[3] = {
- [AD7124_LOW_POWER] = 76800,
- [AD7124_MID_POWER] = 153600,
- [AD7124_FULL_POWER] = 614400,
+ [AD7124_LOW_POWER] = AD7124_INT_CLK_HZ / 8,
+ [AD7124_MID_POWER] = AD7124_INT_CLK_HZ / 4,
+ [AD7124_FULL_POWER] = AD7124_INT_CLK_HZ,
};
static const char * const ad7124_ref_names[] = {
@@ -1164,6 +1168,33 @@ static int ad7124_setup(struct ad7124_state *st)
}
clk_sel = AD7124_ADC_CONTROL_CLK_SEL_INT;
+ } else if (!device_property_present(dev, "clocks") &&
+ device_property_present(dev, "clock-names")) {
+ struct clk_hw *clk_hw;
+
+ const char *name __free(kfree) = kasprintf(GFP_KERNEL, "%s-clk",
+ fwnode_get_name(dev_fwnode(dev)));
+ if (!name)
+ return -ENOMEM;
+
+ clk_hw = devm_clk_hw_register_fixed_rate(dev, name, NULL, 0,
+ AD7124_INT_CLK_HZ);
+ if (IS_ERR(clk_hw))
+ return dev_err_probe(dev, PTR_ERR(clk_hw),
+ "Failed to register clock provider\n");
+
+ ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get,
+ clk_hw);
+ if (ret)
+ return dev_err_probe(dev, ret,
+ "Failed to add clock provider\n");
+
+ /*
+ * Treat the clock as always on. This way we don't have to deal
+ * with someone trying to enable/disable the clock while we are
+ * reading samples.
+ */
+ clk_sel = AD7124_ADC_CONTROL_CLK_SEL_INT_OUT;
} else {
struct clk *clk;
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v2 4/4] iio: adc: ad7124: add clock output support
2025-08-25 22:55 ` [PATCH v2 4/4] iio: adc: ad7124: add clock output support David Lechner
@ 2025-08-26 8:13 ` Andy Shevchenko
2025-08-26 15:11 ` David Lechner
2025-08-26 9:21 ` kernel test robot
2025-08-26 16:02 ` David Lechner
2 siblings, 1 reply; 12+ messages in thread
From: Andy Shevchenko @ 2025-08-26 8:13 UTC (permalink / raw)
To: David Lechner
Cc: Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
linux-iio, devicetree, linux-kernel
On Tue, Aug 26, 2025 at 1:55 AM David Lechner <dlechner@baylibre.com> wrote:
>
> Add support for the AD7124's internal clock output. If the #clock-cells
> property is present, turn on the internal clock output during probe.
>
> If both the clocks and #clock-names properties are present (not allowed
> by devicetree bindings), assume that an external clock is being used so
> that we don't accidentally have two outputs fighting each other.
...
> static const int ad7124_master_clk_freq_hz[3] = {
> - [AD7124_LOW_POWER] = 76800,
> - [AD7124_MID_POWER] = 153600,
> - [AD7124_FULL_POWER] = 614400,
> + [AD7124_LOW_POWER] = AD7124_INT_CLK_HZ / 8,
> + [AD7124_MID_POWER] = AD7124_INT_CLK_HZ / 4,
> + [AD7124_FULL_POWER] = AD7124_INT_CLK_HZ,
Perhaps / 1 ?
> };
...
> + const char *name __free(kfree) = kasprintf(GFP_KERNEL, "%s-clk",
> + fwnode_get_name(dev_fwnode(dev)));
What's wrong with the %pfwP specifier?
> + if (!name)
> + return -ENOMEM;
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 4/4] iio: adc: ad7124: add clock output support
2025-08-26 8:13 ` Andy Shevchenko
@ 2025-08-26 15:11 ` David Lechner
2025-08-26 15:32 ` Andy Shevchenko
0 siblings, 1 reply; 12+ messages in thread
From: David Lechner @ 2025-08-26 15:11 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
linux-iio, devicetree, linux-kernel
On 8/26/25 3:13 AM, Andy Shevchenko wrote:
> On Tue, Aug 26, 2025 at 1:55 AM David Lechner <dlechner@baylibre.com> wrote:
>>
>> Add support for the AD7124's internal clock output. If the #clock-cells
>> property is present, turn on the internal clock output during probe.
>>
>> If both the clocks and #clock-names properties are present (not allowed
>> by devicetree bindings), assume that an external clock is being used so
>> that we don't accidentally have two outputs fighting each other.
>
> ...
>
>> static const int ad7124_master_clk_freq_hz[3] = {
>> - [AD7124_LOW_POWER] = 76800,
>> - [AD7124_MID_POWER] = 153600,
>> - [AD7124_FULL_POWER] = 614400,
>> + [AD7124_LOW_POWER] = AD7124_INT_CLK_HZ / 8,
>> + [AD7124_MID_POWER] = AD7124_INT_CLK_HZ / 4,
>> + [AD7124_FULL_POWER] = AD7124_INT_CLK_HZ,
>
> Perhaps / 1 ?
Seems redundant.
>
>> };
>
> ...
>
>> + const char *name __free(kfree) = kasprintf(GFP_KERNEL, "%s-clk",
>> + fwnode_get_name(dev_fwnode(dev)));
>
> What's wrong with the %pfwP specifier?
I didn't know about it.
>
>> + if (!name)
>> + return -ENOMEM;
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 4/4] iio: adc: ad7124: add clock output support
2025-08-26 15:11 ` David Lechner
@ 2025-08-26 15:32 ` Andy Shevchenko
0 siblings, 0 replies; 12+ messages in thread
From: Andy Shevchenko @ 2025-08-26 15:32 UTC (permalink / raw)
To: David Lechner
Cc: Andy Shevchenko, Michael Hennerich, Jonathan Cameron,
Nuno Sá, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, linux-iio, devicetree, linux-kernel
On Tue, Aug 26, 2025 at 10:11:09AM -0500, David Lechner wrote:
> On 8/26/25 3:13 AM, Andy Shevchenko wrote:
> > On Tue, Aug 26, 2025 at 1:55 AM David Lechner <dlechner@baylibre.com> wrote:
...
> >> static const int ad7124_master_clk_freq_hz[3] = {
> >> - [AD7124_LOW_POWER] = 76800,
> >> - [AD7124_MID_POWER] = 153600,
> >> - [AD7124_FULL_POWER] = 614400,
> >> + [AD7124_LOW_POWER] = AD7124_INT_CLK_HZ / 8,
> >> + [AD7124_MID_POWER] = AD7124_INT_CLK_HZ / 4,
> >> + [AD7124_FULL_POWER] = AD7124_INT_CLK_HZ,
> >
> > Perhaps / 1 ?
>
> Seems redundant.
Yes and no. I think that it makes sense to put for the consistency as it makes
reader aware of the divisors. 1 is also valid divisor after all.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 4/4] iio: adc: ad7124: add clock output support
2025-08-25 22:55 ` [PATCH v2 4/4] iio: adc: ad7124: add clock output support David Lechner
2025-08-26 8:13 ` Andy Shevchenko
@ 2025-08-26 9:21 ` kernel test robot
2025-08-26 16:02 ` David Lechner
2 siblings, 0 replies; 12+ messages in thread
From: kernel test robot @ 2025-08-26 9:21 UTC (permalink / raw)
To: David Lechner, Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: oe-kbuild-all, linux-iio, devicetree, linux-kernel, David Lechner
Hi David,
kernel test robot noticed the following build errors:
[auto build test ERROR on 91812d3843409c235f336f32f1c37ddc790f1e03]
url: https://github.com/intel-lab-lkp/linux/commits/David-Lechner/dt-bindings-iio-adc-adi-ad7124-fix-clocks-properties/20250826-065924
base: 91812d3843409c235f336f32f1c37ddc790f1e03
patch link: https://lore.kernel.org/r/20250825-iio-adc-ad7124-proper-clock-support-v2-4-4dcff9db6b35%40baylibre.com
patch subject: [PATCH v2 4/4] iio: adc: ad7124: add clock output support
config: sparc-randconfig-002-20250826 (https://download.01.org/0day-ci/archive/20250826/202508261731.33GQLUPx-lkp@intel.com/config)
compiler: sparc64-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250826/202508261731.33GQLUPx-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202508261731.33GQLUPx-lkp@intel.com/
All errors (new ones prefixed by >>, old ones prefixed by <<):
>> ERROR: modpost: "__clk_hw_register_fixed_rate" [drivers/iio/adc/ad7124.ko] undefined!
>> ERROR: modpost: "of_clk_hw_simple_get" [drivers/iio/adc/ad7124.ko] undefined!
>> ERROR: modpost: "devm_of_clk_add_hw_provider" [drivers/iio/adc/ad7124.ko] undefined!
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 4/4] iio: adc: ad7124: add clock output support
2025-08-25 22:55 ` [PATCH v2 4/4] iio: adc: ad7124: add clock output support David Lechner
2025-08-26 8:13 ` Andy Shevchenko
2025-08-26 9:21 ` kernel test robot
@ 2025-08-26 16:02 ` David Lechner
2 siblings, 0 replies; 12+ messages in thread
From: David Lechner @ 2025-08-26 16:02 UTC (permalink / raw)
To: Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: linux-iio, devicetree, linux-kernel
On 8/25/25 5:55 PM, David Lechner wrote:
> Add support for the AD7124's internal clock output. If the #clock-cells
> property is present, turn on the internal clock output during probe.
>
...
> @@ -1164,6 +1168,33 @@ static int ad7124_setup(struct ad7124_state *st)
> }
>
> clk_sel = AD7124_ADC_CONTROL_CLK_SEL_INT;
> + } else if (!device_property_present(dev, "clocks") &&
> + device_property_present(dev, "clock-names")) {
Found a mistake here. This should be #clock-cells rather than
clock-names.
^ permalink raw reply [flat|nested] 12+ messages in thread