Skip to content

Conversation

@jansunil
Copy link
Collaborator

@jansunil jansunil commented Nov 7, 2025

PR Description

  • Please replace this comment with a summary of your changes, and add any context
    necessary to understand them. List any dependencies required for this change.
  • To check the checkboxes below, insert a 'x' between square brackets (without
    any space), or simply check them after publishing the PR.
  • If you changes include a breaking change, please specify dependent PRs in the
    description and try to push all related PRs simultaneously.

PR Type

  • Bug fix (a change that fixes an issue)
  • New feature (a change that adds new functionality)
  • Breaking change (a change that affects other repos or cause CIs to fail)

PR Checklist

  • I have conducted a self-review of my own code changes
  • I have compiled my changes, including the documentation
  • I have tested the changes on the relevant hardware
  • I have updated the documentation outside this repo accordingly
  • I have provided links for the relevant upstream lore

Copy link
Contributor

@gastmaier gastmaier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jansunil overall looks good, just some comments from my side.
I believe we can drop the crc feature and really streamline the driver reg access as a consequence.

Best regards,

@nunojsa
Copy link
Collaborator

nunojsa commented Nov 12, 2025

I'll wait this getting out of draft to jump in :)

Copy link
Collaborator

@nunojsa nunojsa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it goes my first round. Couple more points:

  • In the bindings patch do not day "...Add MAX22007 DAC bindings". I mean, dont mention "bindings". Its already obvious from the prefix. So instead say something like "Document MAX22007 DAC". Also refactor a bit the message and add a small description of the device.
  • Also refactor the driver patch commit message. See git log for other examples. Give a small description of the device. It is also a fairly simple driver so I do not think there is any meaningful to state about the implementation in the commit message.

Regarding process, note that I expect this PR to be opened against main (without the overlay). Then after merged with main, you can open a PR against the PI branch only with the overlay.

@jansunil jansunil force-pushed the max22007-dev branch 2 times, most recently from ae84b9d to bb72180 Compare November 14, 2025 10:42
@jansunil
Copy link
Collaborator Author

Changelog V2:

    1) Remove description for spi max frequency in the yaml
2) Remove "|" character in the yaml
3) Add a default field in the properties wherever required
4) Add regmap in the Kconfig
5) Correct copyright year in the driver
6) Rearrange includes in alphabetical order and add  missing includes
7) Pass SPI buffers into state structure
8) Reformat code to meet 80 column limit
9) Remove redundant masking of buffer elements in max22007_spi_reg_write()
10) Remove locking within APIs
11) Remove explicit function for softreset and use regmap directly
12) Add macros for MAX value check for DAC Raw data
13) Implement custom regmap bus
14) Removed caching of channel configuration as it is not used again
15) Add validation for values passed from devicetree
16) Remove spi_setup
17) Add extra spaces at necessary lines of code
18) Parse CRC value from devicetree inside the max22007_configure_crc()
19) Return error code from max22007_parse_channel_cfg() and add an argument to capture the number of channels
20) Add RESET pin gpio support
21) Switch the CRC functionality to use adi,crc-disable instead of adi,crc-enable
22) Remove CRC from the Tx buffer during SPI read operations
    23) Add ABI documentation for per channel LDAC update

Document MAX22007 4-channel 12-bit DAC that drives
a voltage or current output on each channel

Signed-off-by: Janani Sunil <[email protected]>
Add support for the MAX22007 4 channel DAC
that drives a voltage or current output on each channel.

Signed-off-by: Janani Sunil <[email protected]>
Add documentation for MAX22007 driver which describes how the user
can access the driver using dtoverlays

Signed-off-by: Janani Sunil <[email protected]>
Copy link
Contributor

@machschmitt machschmitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jansunil ,

Commenting mostly about the dt docs and proposed ABI. Only superficially looked into the driver code as that might change significantly depending on the discussion about the dt properties and IIO ABI.

Comment on lines +16 to +17
The driver supports runtime LDAC (Latch DAC) control via per-channel sysfs
attributes for precise output timing control.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sysfs is a Linux thing. Device tree is supposed to be project agnostic. Drop these last two lines.

Comment on lines +48 to +52
adi,crc-disable:
type: boolean
description:
Disable CRC8 error checking for SPI communications. By default, CRC8 is
enabled for data integrity verification. Set this property to disable it.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see in the data sheet that SPI transfers can run with CRC disabled (set CRC_EN field to 0x0 within the configuration register (0x03) ). For max22007, CRC is a runtime configuration and has nothing to do with how hardware is set up. Drop this property.

Comment on lines +101 to +102
allOf:
- $ref: /schemas/spi/spi-peripheral-props.yaml#
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpicking: this can be simplified.
Drop allOf: and add $ref: /schemas/spi/spi-peripheral-props.yaml# after the general binding description.


patternProperties:
"^channel@[0-3]$":
type: object
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have bindings for common DAC properties (Documentation/devicetree/bindings/iio/dac/dac.yaml).
Can those simplify things ?
$ref: /schemas/iio/dac/dac.yaml#

I think you won't need

    required:
      - reg

at least.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I would argue that if reg is the only thing we take from it, kind of not sure if we should take it.

Comment on lines +79 to +84
adi,mode:
description:
Output mode for the channel.
$ref: /schemas/types.yaml#/definitions/string
enum: [voltage, current]
default: voltage
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it could use output-range-microamp and/or output-range-microvolt instead (see 1). If a channel has output-range-microamp in dt, then set 0x1 for the specific channel within CHNL_MODE field. With that, adi,mode becomes unneeded.

Comment on lines +1 to +16
What: /sys/bus/iio/devices/iio:deviceX/out_voltageY_ldac_update
KernelVersion: 6.13
Contact: [email protected]
Description:
Trigger LDAC (Load DAC) update for the specified channel. Write 1 to update DAC outputs.

What: /sys/bus/iio/devices/iio:deviceX/out_currentY_ldac_update
KernelVersion: 6.13
Contact: [email protected]
Description:
Trigger LDAC (Load DAC) update for the specified channel.
Writing 1 will transfer the DAC register value to the actual
DAC output, effectively updating the analog output current.
Writing 0 has no effect. This is useful when using the
transparent latch mode is disabled, allowing manual control
over when DAC register changes take effect on the output.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not getting the use case for this DAC latch control feature. Why not always driving the device in 'transparent' mode? We already have out_voltageY_raw for each channel. Why make the user write to out_voltageY_raw and to out_currentY_ldac_update to get the DAC output updated? I'd just always write the proper bits to LD_CTRL whenever the user writes to out_voltageY_raw.

With that, I think adi,dac-latch-mode will no longer be needed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Being it a per channel thing, I'm also not buying it (at least yet). AFAIR, typical case for this sort of thing is to for the latch mode to update all the channels at once which might be useful (in IIO) when buffering and update all channels at once. If we are only supporting raw writes I would (at least for now) just support transparent mode. Or do you have an actual request for this?

Comment on lines +18 to +25
What: /sys/bus/iio/devices/iio:deviceX/out_voltageY_powermode
What: /sys/bus/iio/devices/iio:deviceX/out_currentY_powermode
KernelVersion: 6.13
Contact: [email protected]
Description:
Control the power state of the specified channel. Write "on" to
enable the channel output, or "off" to disable it. Reading
returns the current power state.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't this be supported with out_voltageY_powerdown 1?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. With the above, I guess we do not need any custom ABI

case IIO_CHAN_INFO_SCALE:
if (chan->type == IIO_VOLTAGE) {
*val = 5 * 2500; /* 5 * Vref(2.5V) in mV */
*val2 = 4096 * 1000; /* 12-bit DAC resolution * 1000 to convert mV to V */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks pretty odd. You probably want to use IIO_VAL_FRACTIONAL_LOG2 here. See how other drivers do it.

Comment on lines +486 to +491
iio_chan->type = IIO_VOLTAGE;
iio_chan->output = 1;
iio_chan->indexed = 1;
iio_chan->channel = reg;
iio_chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE);
iio_chan->ext_info = max22007_ext_info;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be tempted to create a channel template (like ad4130 or ad4170-4) to update only what's different for each channel here.

Comment on lines +559 to +563
ret = gpiod_direction_output(reset_gpio, 1);
if (ret) {
dev_err(&spi->dev, "Failed to set GPIO as output: %d\n", ret);
return ret;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this really needed? We already asked for output GPIO (GPIOD_OUT_LOW) above.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. We just want gpiod_set_value_cansleep()

Copy link
Collaborator

@nunojsa nunojsa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more comments from me. An additional note regarding commits. Your git subject for the bindings is nok. Please run git log --oneline Documentation/devicetree/bindings/ and follow the sytle.

maxItems: 1
description:
GPIO used for hardware reset of the device. If not specified, the driver
will use software reset via SPI register.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned by @machschmitt, don't mention things "the driver will....". Bindings is about HW description and we should not talk about any implementation specifics. Hence, I would drop the description in here.


patternProperties:
"^channel@[0-3]$":
type: object
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I would argue that if reg is the only thing we take from it, kind of not sure if we should take it.


adi,dac-latch-mode:
description:
DAC latch control mode for the channel.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the description does not add much when compared to the property name. If you're used to these chips, you know what this is about but if you are not... Please add brief description of what is this about (and remember, just in terms of HW)

- required: [channel@0]
- required: [channel@1]
- required: [channel@2]
- required: [channel@3]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least vdd should be also required. If the other regulators are not optional, they should be also required

/*
* Analog Devices MAX22007
*
* hdl_project: <max22007_rpi>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need an hdl tag in here?!

if (ret)
return ret;
*val = reg_val;
return IIO_VAL_INT;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use any temp variable. Pass val directly and handle things inside max22007_read_channel_data(). Then, here it becomes return max22007_read_channel_data() which looks much better


state->crc_en = crc;

return 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No sure I would support this for now. I would assume CRC always on and have this if and when someone asks for it


iio_chan = &st->iio_chan[i];

iio_chan->type = IIO_VOLTAGE;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop the above given that you're doing it again down below

state->regmap = devm_regmap_init(&spi->dev, &max22007_regmap_bus, state,
&max22007_regmap_config);
if (IS_ERR(state->regmap)) {
dev_err(&spi->dev, "Failed to initialize regmap\n");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dev_err_probe()

if (reset_gpio) {
ret = gpiod_direction_output(reset_gpio, 1);
if (ret) {
dev_err(&spi->dev, "Failed to set GPIO as output: %d\n", ret);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants