-
Notifications
You must be signed in to change notification settings - Fork 845
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
Add support for MAX30210 #2544
base: main
Are you sure you want to change the base?
Add support for MAX30210 #2544
Conversation
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.
Alright, I'm done for a first round of reviewing
adi,comp-mode: | ||
description: | | ||
If present, comparator mode is used. If not present, interrupt mode is | ||
used (default). |
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 this property? Can't we assume this mode in the absence of an interrupt?
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 adapted this from the existing code below:
adi,comp-int: |
Comparator mode still uses interrupts. It just uses some register values differently, i.e., low temp alarm is used as high temp hysteresis.
This can also be controlled using debugfs_reg_access; should I just remove 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.
Hmm, we can try the DT parameter but I think the description should be improved. More in line with that explanation stating that behavior of the device will change. With the above, it seems that interrupts won't be used at all in comparator mode.
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 will use the following description:
If present, the device is in comparator mode. In this mode, the low
temperature threshold value acts as high temperature hysteresis. If not
present, interrupt mode is used (default).
Documentation/devicetree/bindings/iio/temperature/adi,max30210.yaml
Outdated
Show resolved
Hide resolved
Documentation/devicetree/bindings/iio/temperature/adi,max30210.yaml
Outdated
Show resolved
Hide resolved
Documentation/devicetree/bindings/iio/temperature/adi,max30210.yaml
Outdated
Show resolved
Hide resolved
745144f
to
9bd27aa
Compare
Add entry for the MAX30210 driver. Signed-off-by: John Erasmus Mari Geronimo <[email protected]>
82e4345
to
7a24de3
Compare
V2
|
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 stuff that still needs to be addressed but I would say that this is already in shape to be sent upstream.
Documentation/devicetree/bindings/iio/temperature/adi,max30210.yaml
Outdated
Show resolved
Hide resolved
adi,comp-mode: | ||
description: | | ||
If present, comparator mode is used. If not present, interrupt mode is | ||
used (default). |
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.
Hmm, we can try the DT parameter but I think the description should be improved. More in line with that explanation stating that behavior of the device will change. With the above, it seems that interrupts won't be used at all in comparator mode.
if (ret) | ||
return ret; | ||
|
||
st->watermark = val; |
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 needs a lock... Also, should we be allowed to change the watermark while buffering? Would that work out?
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.
If I remember correctly, the hwfifo_set_watermark()
runs every after preenable of the triggered buffer. I think
st->watermark
does not need a lock in this situation.
Add documentation for devicetree bindings for max30210 Signed-off-by: John Erasmus Mari Geronimo <[email protected]>
41c93cb
to
21ffe8b
Compare
21ffe8b
to
8f1207b
Compare
V3
|
MAX30210 ±0.1°C Accurate Ultra-Small Low-Power Digital Temperature Sensor Signed-off-by: John Erasmus Mari Geronimo <[email protected]>
8f1207b
to
a0108de
Compare
static int max30210_read_temp_raw(struct regmap *regmap, unsigned int reg, | ||
int *temp) | ||
{ | ||
u8 uval[2] __aligned(IIO_DMA_MINALIGN); |
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.
Wouldn't it be better to have the cache aligned buffers declared in struct max30210_state
?
Most IIO drivers declare their transfer buffers that need to be aligned in their state structs.
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 can do that. Or can I just remove __aligned(IIO_DMA_MINALIGN)
? I honestly don't know the use cases of this alignment. I will appreciate an explanation. Thanks.
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.
Not an expert on DMA, but I don't think removing the alignment pragma would be a good thing. I think it is likely that upstream IIO maintainer will ask for explicit buffer alignment to enforce DMA safety. IIRC, the SPI controller in some platforms can talk to the DMA controller and ask SPI transfers to be DMA mapped (rpi can do this IIRC). That would happen seamlessly to the device driver. In those cases, the buffer data can get corrupted if it's not properly aligned on cache lines or miss-handled by the DMA controller. There are other situations in which buffers can get corrupted when data moves along through DMA. Some upstream content about DMA buffer alignment:
https://lore.kernel.org/linux-iio/20240413173409.63d33a0a@jic23-huawei/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
Anyway, I'm not expert on DMA so other reviewers may provide better guided suggestions here.
static void max30210_fifo_read(struct iio_dev *indio_dev) | ||
{ | ||
struct max30210_state *st = iio_priv(indio_dev); | ||
u8 data[3 * MAX30210_FIFO_SIZE] __aligned(IIO_DMA_MINALIGN); |
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.
Can this buffer reside in the device state struct?
if (ret) | ||
return dev_err_probe(dev, ret, "Failed to read Part ID.\n"); | ||
if (val != MAX30210_PART_ID) | ||
dev_err_probe(dev, -ENODEV, "Part ID mismatch.\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.
Don't know how maintainers are considering warnings from IIO devices but, not long ago, Greg K-H said to avoid kernel warnings https://www.youtube.com/watch?v=Rg_VPMT0XXw.
In sum, everything that can trigger a dev_warn() would be considered a kernel CVE.
If panic_on_warn is enabled, reboot would happen.
PR Description
PR Type
PR Checklist