Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: adc: ad7124: add clock output support

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>
Link: https://patch.msgid.link/20250828-iio-adc-ad7124-proper-clock-support-v3-4-0b317b4605e5@baylibre.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

David Lechner and committed by
Jonathan Cameron
dfbbee09 ed231e25

+33
+33
drivers/iio/adc/ad7124.c
··· 6 6 */ 7 7 #include <linux/bitfield.h> 8 8 #include <linux/bitops.h> 9 + #include <linux/cleanup.h> 9 10 #include <linux/clk.h> 11 + #include <linux/clk-provider.h> 10 12 #include <linux/delay.h> 11 13 #include <linux/device.h> 12 14 #include <linux/err.h> ··· 20 18 #include <linux/property.h> 21 19 #include <linux/regulator/consumer.h> 22 20 #include <linux/spi/spi.h> 21 + #include <linux/sprintf.h> 23 22 #include <linux/units.h> 24 23 25 24 #include <linux/iio/iio.h> ··· 1191 1188 } 1192 1189 1193 1190 clk_sel = AD7124_ADC_CONTROL_CLK_SEL_INT; 1191 + st->clk_hz = AD7124_INT_CLK_HZ; 1192 + } else if (!device_property_present(dev, "clocks") && 1193 + device_property_present(dev, "#clock-cells")) { 1194 + #ifdef CONFIG_COMMON_CLK 1195 + struct clk_hw *clk_hw; 1196 + 1197 + const char *name __free(kfree) = kasprintf(GFP_KERNEL, "%pfwP-clk", 1198 + dev_fwnode(dev)); 1199 + if (!name) 1200 + return -ENOMEM; 1201 + 1202 + clk_hw = devm_clk_hw_register_fixed_rate(dev, name, NULL, 0, 1203 + AD7124_INT_CLK_HZ); 1204 + if (IS_ERR(clk_hw)) 1205 + return dev_err_probe(dev, PTR_ERR(clk_hw), 1206 + "Failed to register clock provider\n"); 1207 + 1208 + ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, 1209 + clk_hw); 1210 + if (ret) 1211 + return dev_err_probe(dev, ret, 1212 + "Failed to add clock provider\n"); 1213 + #endif 1214 + 1215 + /* 1216 + * Treat the clock as always on. This way we don't have to deal 1217 + * with someone trying to enable/disable the clock while we are 1218 + * reading samples. 1219 + */ 1220 + clk_sel = AD7124_ADC_CONTROL_CLK_SEL_INT_OUT; 1194 1221 st->clk_hz = AD7124_INT_CLK_HZ; 1195 1222 } else { 1196 1223 struct clk *clk;