Skip to content

Commit 81f5aa9

Browse files
iio: adc: Add MAX14001/Max14002 device tree documentation
- Fix memory validation fault related to verification registers values at power-on-reset (POR) - Add device tree documentation for MAX14001/MAX14002 - Move regulators initialization logic to probe function Signed-off-by: Marilene A Garcia <[email protected]>
1 parent b77c248 commit 81f5aa9

File tree

3 files changed

+143
-53
lines changed

3 files changed

+143
-53
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2+
# Copyright 2025 Marilene Andrade Garcia
3+
%YAML 1.2
4+
---
5+
$id: http://devicetree.org/schemas/iio/adc/adi,max14001.yaml#
6+
$schema: http://devicetree.org/meta-schemas/core.yaml#
7+
8+
title: Analog Devices MAX14001-MAX14002 10-bit ADCs
9+
10+
maintainers:
11+
- Marilene Andrade Garcia <[email protected]>
12+
13+
description:
14+
Bindings for the Analog Devices MAX14001-MAX14002 Configurable,
15+
Isolated 10-bit ADCs for Multi-Range Binary Inputs.
16+
17+
Datasheet can be found here:
18+
https://www.analog.com/media/en/technical-documentation/data-sheets/MAX14001-MAX14002.pdf
19+
20+
properties:
21+
compatible:
22+
enum:
23+
- adi,max14001
24+
- adi,max14002
25+
26+
reg:
27+
maxItems: 1
28+
29+
'#address-cells':
30+
const: 1
31+
32+
'#size-cells':
33+
const: 0
34+
35+
vdd-supply:
36+
description:
37+
Isolated DC-DC power supply input voltage.
38+
39+
vddl-supply:
40+
description:
41+
Logic power supply.
42+
43+
vrefin-supply:
44+
description:
45+
Reference input range.
46+
47+
spi-max-frequency:
48+
maximum: 5000000
49+
50+
current-channel:
51+
description:
52+
Enable handle current channel measures instead the default
53+
voltage channel measures.
54+
type: boolean
55+
56+
required:
57+
- compatible
58+
- reg
59+
- vdd-supply
60+
- vddl-supply
61+
62+
allOf:
63+
- $ref: /schemas/spi/spi-peripheral-props.yaml#
64+
65+
unevaluatedProperties: false
66+
67+
examples:
68+
- |
69+
spi {
70+
#address-cells = <1>;
71+
#size-cells = <0>;
72+
73+
max14001: adc@0 {
74+
compatible = "adi,max14001";
75+
reg = <0>;
76+
spi-max-frequency = <5000000>;
77+
vdd-supply = <&vdd>;
78+
vddl-supply = <&vddl>;
79+
};
80+
};
81+
...

arch/arm/boot/dts/overlays/rpi-max14001-pmb-overlay.dts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
&spi0 {
4848
status = "okay";
4949
max14001_voltage_channel: max14001@0 {
50-
compatible = "max14001";
50+
compatible = "adi,max14001";
5151
reg = <0x0>;
5252
spi-max-frequency = <5000000>;
5353
vdd-supply = <&vdd>;
@@ -56,7 +56,7 @@
5656
status = "okay";
5757
};
5858
max14001_current_channel: max14001@1 {
59-
compatible = "max14001";
59+
compatible = "adi,max14001";
6060
reg = <0x1>;
6161
spi-max-frequency = <5000000>;
6262
current-channel;

drivers/iio/adc/max14001.c

Lines changed: 60 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -101,42 +101,10 @@ struct max14001_state {
101101
int vref_mv;
102102
};
103103

104-
static int max14001_get_vref_mv(struct max14001_state *st)
105-
{
106-
struct device *dev = &st->spi->dev;
107-
int ret = 0;
108-
109-
ret = devm_regulator_get_enable_read_voltage(dev, "vrefin");
110-
if (ret < 0){
111-
st->vref_mv = 1250000 / 1000;
112-
dev_info(&st->spi->dev, "%s: vrefin not found. vref_mv %d\n", __func__, st->vref_mv);
113-
} else {
114-
st->vref_mv = ret / 1000;
115-
dev_info(&st->spi->dev, "%s: vrefin found. vref_mv %d\n", __func__, st->vref_mv);
116-
}
117-
118-
return ret;
119-
}
120-
121-
static int max14001_init_required_regulators(struct max14001_state *st)
122-
{
123-
struct device *dev = &st->spi->dev;
124-
int ret = 0;
125-
126-
ret = devm_regulator_get_enable(dev, "vdd");
127-
if (ret)
128-
return dev_err_probe(dev, ret, "Failed to enable specified Vdd supply\n");
129-
130-
ret = devm_regulator_get_enable(dev, "vddl");
131-
if (ret)
132-
return dev_err_probe(dev, ret, "Failed to enable specified Vddl supply\n");
133-
134-
return ret;
135-
}
136-
137104
static int max14001_spi_read(struct max14001_state *st, u16 reg, int *val)
138105
{
139-
u16 tx, rx, reversed;
106+
u16 rx, reversed;
107+
u16 tx = 0;
140108
int ret;
141109

142110
dev_info(&st->spi->dev, "%s: reg: %x, val: %x\n", __func__, reg, *val);
@@ -207,6 +175,43 @@ static int max14001_spi_write_single_reg(struct max14001_state *st, u16 reg, u16
207175
return ret;
208176
}
209177

178+
static int max14001_set_verification_registers_values(struct max14001_state *st)
179+
{
180+
struct device *dev = &st->spi->dev;
181+
int i, val_read_reg, ret;
182+
u16 val_write_reg;
183+
184+
/* Enable register write */
185+
ret = max14001_spi_write(st, MAX14001_REG_WEN, MAX14001_REG_WEN_WRITE_ENABLE);
186+
if (ret < 0)
187+
goto erro_condition;
188+
189+
for (i = MAX14001_REG_FLTEN; i <= MAX14001_REG_ENBL; i++) {
190+
/* Read register value */
191+
val_read_reg = 0;
192+
ret = max14001_spi_read(st, i, &val_read_reg);
193+
if (ret < 0)
194+
goto erro_condition;
195+
196+
/* Write verification register value */
197+
val_write_reg = (u16)val_read_reg;
198+
ret = max14001_spi_write(st, MAX14001_REG_VERIFICATION(i), val_write_reg);
199+
if (ret < 0)
200+
goto erro_condition;
201+
}
202+
203+
/* Disable register write */
204+
ret = max14001_spi_write(st, MAX14001_REG_WEN, MAX14001_REG_WEN_WRITE_DISABLE);
205+
if (ret < 0)
206+
goto erro_condition;
207+
208+
return ret;
209+
210+
erro_condition:
211+
return dev_err_probe(dev, ret, "Failed to set verification registers\n");
212+
213+
}
214+
210215
static int max14001_read_raw(struct iio_dev *indio_dev,
211216
struct iio_chan_spec const *chan,
212217
int *val, int *val2, long mask)
@@ -240,22 +245,8 @@ static int max14001_read_raw(struct iio_dev *indio_dev,
240245
return -EINVAL;
241246
}
242247

243-
/* TODO: Check if this method is nedeed */
244-
static int max14001_write_raw(struct iio_dev *indio_dev,
245-
struct iio_chan_spec const *chan,
246-
int val, int val2, long mask)
247-
{
248-
struct max14001_state *st = iio_priv(indio_dev);
249-
250-
switch (mask) {
251-
}
252-
253-
return -EINVAL;
254-
}
255-
256248
static const struct iio_info max14001_info = {
257249
.read_raw = max14001_read_raw,
258-
.write_raw = max14001_write_raw,
259250
};
260251

261252
static const struct iio_chan_spec max14001_channel_voltage[] = {
@@ -305,6 +296,23 @@ static int max14001_probe(struct spi_device *spi)
305296
indio_dev->modes = INDIO_DIRECT_MODE;
306297
indio_dev->info = &max14001_info;
307298

299+
ret = devm_regulator_get_enable(dev, "vdd");
300+
if (ret)
301+
return dev_err_probe(dev, ret, "Failed to enable specified Vdd supply\n");
302+
303+
ret = devm_regulator_get_enable(dev, "vddl");
304+
if (ret)
305+
return dev_err_probe(dev, ret, "Failed to enable specified Vddl supply\n");
306+
307+
ret = devm_regulator_get_enable_read_voltage(dev, "vrefin-supply");
308+
if (ret < 0) {
309+
st->vref_mv = 1250000 / 1000;
310+
dev_info(&st->spi->dev, "%s: vrefin not found. vref_mv %d\n", __func__, st->vref_mv);
311+
} else {
312+
st->vref_mv = ret / 1000;
313+
dev_info(&st->spi->dev, "%s: vrefin found. vref_mv %d\n", __func__, st->vref_mv);
314+
}
315+
308316
for_each_available_child_of_node_scoped(spi->dev.of_node, child) {
309317
current_channel = of_property_read_bool(child, "current-channel");
310318
if (current_channel)
@@ -321,8 +329,10 @@ static int max14001_probe(struct spi_device *spi)
321329

322330
dev_info(&st->spi->dev, "%s: probe\n", __func__);
323331

324-
max14001_init_required_regulators(st);
325-
max14001_get_vref_mv(st);
332+
/* Write the appropriate verification registers values to clear the
333+
* failed memory validation (MV Fault)
334+
*/
335+
max14001_set_verification_registers_values(st);
326336

327337
return devm_iio_device_register(&spi->dev, indio_dev);
328338
}
@@ -356,4 +366,3 @@ module_spi_driver(max14001_driver);
356366
MODULE_AUTHOR("Marilene Andrade Garcia <[email protected]>");
357367
MODULE_DESCRIPTION("Analog Devices MAX14001/MAX14002 ADCs driver");
358368
MODULE_LICENSE("GPL v2");
359-

0 commit comments

Comments
 (0)