Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mrcsosa
Copy link

@mrcsosa mrcsosa commented Mar 23, 2023

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

@mrcsosa mrcsosa marked this pull request as draft March 23, 2023 00:49
@mrcsosa mrcsosa force-pushed the dev/max538x-master branch 15 times, most recently from d408cf8 to 257d322 Compare March 24, 2023 03:39
Copy link
Contributor

@amiclaus amiclaus left a 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.

@mrcsosa mrcsosa force-pushed the dev/max538x-master branch 7 times, most recently from 23d5d4d to b7f38bc Compare April 11, 2023 00:58
@mrcsosa mrcsosa marked this pull request as ready for review April 11, 2023 01:23
@mrcsosa mrcsosa force-pushed the dev/max538x-master branch 3 times, most recently from 2c46209 to 141f290 Compare April 14, 2023 00:49
@mrcsosa mrcsosa changed the title drivers:iio:dac: add max538x support drivers:iio:dac: add max5380 support Apr 19, 2023
@mrcsosa
Copy link
Author

mrcsosa commented Apr 20, 2023

Hi, can I request an initial review of this PR before sending the patches upstream? Thank you.

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.

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
Copy link
Collaborator

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:

https://elixir.bootlin.com/linux/latest/source/Documentation/devicetree/bindings/trivial-devices.yaml

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 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

just dac@31

config MAX5380
tristate "Maxim MAX5380 DAC driver"
depends on I2C
depends on OF
Copy link
Collaborator

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...

#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>

#define V_REF 2.0
Copy link
Collaborator

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

#include <linux/proc_fs.h>
#include <linux/i2c.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
Copy link
Collaborator

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

data = iio_priv(indio_dev);
data->client = client;

indio_dev->dev.parent = &client->dev;
Copy link
Collaborator

Choose a reason for hiding this comment

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

drop this

return ret;
}

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.

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


static const struct i2c_device_id max5380_id[] = {
{ "max5380", 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 need to explicitly set .driver_data to 0.

static struct i2c_driver max5380_driver = {
.driver = {
.name = "max5380",
.of_match_table = max5380_of_match,
Copy link
Collaborator

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...

if (val < 0 || val > 255)
return -EINVAL;
data->value = val;
ret = i2c_smbus_write_byte(data->client, data->value);
Copy link
Collaborator

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()?

Copy link
Author

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.

@mrcsosa mrcsosa force-pushed the dev/max538x-master branch 2 times, most recently from b66beac to d2283cf Compare April 26, 2023 01:02
@mrcsosa mrcsosa changed the title drivers:iio:dac: add max5380 support drivers:iio:dac: add max538x support Apr 26, 2023
@mrcsosa mrcsosa force-pushed the dev/max538x-master branch 4 times, most recently from c85477d to d3149aa Compare May 2, 2023 03:53
const: 1

'#size-cells':
const: 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 need for the above two properties..

- maxim,max5382L
- maxim,max5382M
- maxim,max5382N
- maxim,max5382K
Copy link
Collaborator

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>;
};
};
...
Copy link
Collaborator

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;
Copy link
Collaborator

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()

case MAX5382M:
case MAX5382N:
case MAX5382K:
data->vfactor = 0.9;
Copy link
Collaborator

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;
Copy link
Collaborator

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


indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
if (!indio_dev) {
dev_err(&client->dev, "Failed to allocate IIO device\n");
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove this log

dev_err(&client->dev, "Invalid device type specified\n");

return -EINVAL;
}
Copy link
Collaborator

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;
}
Copy link
Collaborator

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,
Copy link
Collaborator

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).

@mrcsosa mrcsosa force-pushed the dev/max538x-master branch 3 times, most recently from a26e354 to c984413 Compare May 24, 2023 00:44
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>
@mrcsosa
Copy link
Author

mrcsosa commented May 24, 2023

Removed: Multiple device list (adjusted to only max5380/1/2)
Removed: Unnecessary error checking and logs
Adjusted: if statements to switch case
Added: voltage regulator for external vref.

@SRaus SRaus changed the base branch from master to main January 9, 2024 09:49
@nunojsa
Copy link
Collaborator

nunojsa commented Jan 15, 2024

@mrcsosa, I completely failed to look again at this one... Can you rebase onto master?

For similar situations, just ping me for the review :)

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.

None yet

3 participants