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
drivers:iio:dac: add max538x support #2151
base: main
Are you sure you want to change the base?
Conversation
d408cf8
to
257d322
Compare
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.
please send the patches upstream for further review.
23d5d4d
to
b7f38bc
Compare
2c46209
to
141f290
Compare
Hi, can I request an initial review of this PR before sending the patches upstream? Thank you. |
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 would suggest to make this driver a bit more interesting. The part is very simple and looking at the datasheet, I would say the driver should support all max5380 - max5382. That would turn the driver a bit more interesting. If I'm not missing something, you would only need to handle the different VREFs
const: 1 | ||
|
||
'#size-cells': | ||
const: 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.
the above two properties are not needed... On top of this, if you are not adding more into this schema, the part could go to:
That said, you could already add support for the vdd regulator that would justify this bindings.
#address-cells = <1>; | ||
#size-cells = <0>; | ||
|
||
max5380: dac@31 { |
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.
just dac@31
drivers/iio/dac/Kconfig
Outdated
config MAX5380 | ||
tristate "Maxim MAX5380 DAC driver" | ||
depends on I2C | ||
depends on OF |
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.
there's no OF dependency...
drivers/iio/dac/max5380.c
Outdated
#include <linux/iio/iio.h> | ||
#include <linux/iio/sysfs.h> | ||
|
||
#define V_REF 2.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.
use something like define MAX5380_VREF 2
drivers/iio/dac/max5380.c
Outdated
#include <linux/proc_fs.h> | ||
#include <linux/i2c.h> | ||
#include <linux/iio/iio.h> | ||
#include <linux/iio/sysfs.h> |
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.
please cleanup the includes... There are things not needed and others that are missing. Furthermore, they should be placed in alphabetical order
drivers/iio/dac/max5380.c
Outdated
data = iio_priv(indio_dev); | ||
data->client = client; | ||
|
||
indio_dev->dev.parent = &client->dev; |
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 this
drivers/iio/dac/max5380.c
Outdated
return ret; | ||
} | ||
|
||
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.
wrong indentation... furthermore, just do return devm_iio_device_register()
. Note that you need the devm_ variant. Otherwise you would need a .remove hook defined in your struct i2c_driver
drivers/iio/dac/max5380.c
Outdated
|
||
static const struct i2c_device_id max5380_id[] = { | ||
{ "max5380", 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 need to explicitly set .driver_data to 0.
drivers/iio/dac/max5380.c
Outdated
static struct i2c_driver max5380_driver = { | ||
.driver = { | ||
.name = "max5380", | ||
.of_match_table = max5380_of_match, |
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 to have more indentation than needed...
drivers/iio/dac/max5380.c
Outdated
if (val < 0 || val > 255) | ||
return -EINVAL; | ||
data->value = val; | ||
ret = i2c_smbus_write_byte(data->client, data->value); |
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 smbus? from a quick grasp on the datasheet, I do not see any specific smbus mention... Can't we use i2c_master_send()?
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, I have added few updates to support other devices. I will also include the improvements you have mentioned on my next update. Thank you so much.
b66beac
to
d2283cf
Compare
c85477d
to
d3149aa
Compare
const: 1 | ||
|
||
'#size-cells': | ||
const: 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 need for the above two properties..
- maxim,max5382L | ||
- maxim,max5382M | ||
- maxim,max5382N | ||
- maxim,max5382K |
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.
What is the L,M,N,K,L all about? Do we need a sepcific compatible? AFAICT, we have max5380/max5381/max53802
reg=<0x31>; | ||
}; | ||
}; | ||
... |
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 it stands, these could go to trivial devices... But I think you need to add the vdd regulator if supporting all three devices
return ret; | ||
} | ||
|
||
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.
just return devm_iio_device_register()
drivers/iio/dac/max538x.c
Outdated
case MAX5382M: | ||
case MAX5382N: | ||
case MAX5382K: | ||
data->vfactor = 0.9; |
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.
? There's no floating point in the kernel... Also, I do not think this is right. From the datasheet, the internal reference for mx5832 is 0.9 * VDD. Hence, you need to use a regulator and get it's voltage and then do the calculation accordingly.
Look for examples using devm_regulator_get()
and regulator_get_voltage()
You can have a flag (most obvious solution) in your chip info structure to let you know when do you need to get the regulator voltage so that you can calculate the internal reference.
return -EINVAL; | ||
} | ||
|
||
indio_dev->dev.parent = &client->dev; |
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 this. automatically done by IIO core
drivers/iio/dac/max538x.c
Outdated
|
||
indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); | ||
if (!indio_dev) { | ||
dev_err(&client->dev, "Failed to allocate IIO device\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.
remove this log
drivers/iio/dac/max538x.c
Outdated
dev_err(&client->dev, "Invalid device type specified\n"); | ||
|
||
return -EINVAL; | ||
} |
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.
remove the above... should never happen
} | ||
} else { | ||
return -EINVAL; | ||
} |
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.
use a switch() case
.name = "max538x", | ||
.of_match_table = max538x_of_match, | ||
}, | ||
.probe = max538x_probe, |
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.
use probe_new()... You need to see when sending these upstream if probe_new() is still in use or not. If it is, you should use it (I think).
a26e354
to
c984413
Compare
added documentation for max5380/1/2 support Signed-off-by: Marc Paolo Sosa <marcpaolo.sosa@analog.com>
Added driver implementation for MAX5380/1/2 8-bit DAC. More information: analog.com: MAX5380/1/2 Signed-off-by: Marc Paolo Sosa <marcpaolo.sosa@analog.com>
add entry for MAX5380/1/2 driver Signed-off-by: Marc Paolo Sosa <marcpaolo.sosa@analog.com>
c984413
to
c3bc1ae
Compare
Removed: Multiple device list (adjusted to only max5380/1/2) |
@mrcsosa, I completely failed to look again at this one... Can you rebase onto master? For similar situations, just ping me for the review :) |
Added driver implementation for MAX5380/1/2 8-bit DAC.
More info: analog.com: MAX5380-MAX5382
Signed-off-by: Marc Paolo Sosa marcpaolo.sosa@analog.com