-
Notifications
You must be signed in to change notification settings - Fork 914
Max22007 dev #3015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: rpi-6.12.y
Are you sure you want to change the base?
Max22007 dev #3015
Conversation
4ab9538 to
bd8314f
Compare
gastmaier
left a comment
There was a problem hiding this 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,
|
I'll wait this getting out of draft to jump in :) |
bd8314f to
39b2409
Compare
nunojsa
left a comment
There was a problem hiding this 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.
ae84b9d to
bb72180
Compare
|
Changelog V2: |
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]>
bb72180 to
6e82321
Compare
machschmitt
left a comment
There was a problem hiding this 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.
| The driver supports runtime LDAC (Latch DAC) control via per-channel sysfs | ||
| attributes for precise output timing control. |
There was a problem hiding this comment.
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.
| 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. |
There was a problem hiding this comment.
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.
| allOf: | ||
| - $ref: /schemas/spi/spi-peripheral-props.yaml# |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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:
- regat least.
There was a problem hiding this comment.
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,mode: | ||
| description: | ||
| Output mode for the channel. | ||
| $ref: /schemas/types.yaml#/definitions/string | ||
| enum: [voltage, current] | ||
| default: voltage |
There was a problem hiding this comment.
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.
| 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
| 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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 */ |
There was a problem hiding this comment.
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.
| 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; |
There was a problem hiding this comment.
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.
| ret = gpiod_direction_output(reset_gpio, 1); | ||
| if (ret) { | ||
| dev_err(&spi->dev, "Failed to set GPIO as output: %d\n", ret); | ||
| return ret; | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()
There was a problem hiding this 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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
PR Description
necessary to understand them. List any dependencies required for this change.
any space), or simply check them after publishing the PR.
description and try to push all related PRs simultaneously.
PR Type
PR Checklist