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

add ltc2672 and ltc2664 #2456

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

Conversation

kseerp
Copy link
Contributor

@kseerp kseerp commented Mar 15, 2024

LTC2664 4 channel, 16 bit Voltage Output SoftSpan DAC
LTC2672 5 channel, 16 bit Current Output Softspan DAC

since ltc2664 and ltc2672 have the same registers/softspan, thus leveraging the use of this PR #2408 and there's plenty of shared codes

i'll plan to utilize also the automatic cleanup for mutex but my current kernel used does not yet support that

@nunojsa nunojsa mentioned this pull request Mar 15, 2024
@nunojsa nunojsa requested a review from a team March 15, 2024 08:17
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.

You're also not updating the MAINTAINERS file. Again, make sure to add Michael as someone how also developed significantly the driver (with a Co-developed-by; tag)

Documentation/devicetree/bindings/iio/dac/adi,ltc2664.yaml Outdated Show resolved Hide resolved
drivers/iio/dac/ltc2664.c Outdated Show resolved Hide resolved
drivers/iio/dac/ltc2664.c Show resolved Hide resolved
drivers/iio/dac/ltc2664.c Outdated Show resolved Hide resolved
drivers/iio/dac/ltc2664.c Outdated Show resolved Hide resolved
drivers/iio/dac/ltc2664.c Outdated Show resolved Hide resolved
drivers/iio/dac/ltc2664.c Outdated Show resolved Hide resolved
drivers/iio/dac/ltc2664.c Outdated Show resolved Hide resolved
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 as it makes it easier to explain my points about chip_info

drivers/iio/dac/ltc2664.c Outdated Show resolved Hide resolved
drivers/iio/dac/ltc2664.c Outdated Show resolved Hide resolved
drivers/iio/dac/ltc2664.c Outdated Show resolved Hide resolved
drivers/iio/dac/ltc2664.c Outdated Show resolved Hide resolved
drivers/iio/dac/ltc2664.c Outdated Show resolved Hide resolved
drivers/iio/dac/ltc2664.c Outdated Show resolved Hide resolved
Add documentation for ltc2664 and ltc2672.

Co-developed-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Kim Seer Paller <kimseer.paller@analog.com>
LTC2664 4 channel, 16 bit Voltage Output SoftSpan DAC
LTC2672 5 channel, 16 bit Current Output Softspan DAC

Co-developed-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Kim Seer Paller <kimseer.paller@analog.com>
Add entry for the LTC2664 driver.

Signed-off-by: Kim Seer Paller <kimseer.paller@analog.com>
@kseerp
Copy link
Contributor Author

kseerp commented Mar 27, 2024

appreciate all the reviews, here are the changelogs for v2 and changes have been tested on relevant hardware

  • vcc and iovcc added as required property
  • updated MAINTAINERS file
  • utilized cleanup for mutex automatic release
  • added span_helper and num_span in chip_info, and restructured the ltc2672_span_helper into a 2d array to simplify the span_lookup function (uncertain if I implemented it properly or in standard implementation)
  • refactored offset and scale function
  • made iio_chan constant for default channel specification and moved dynamic variable to ltc2664_state struct
  • dropped switch case and refactored channel_config function
  • utilized spi_get_device_match_data()
  • added Co-developed-by tag

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.

Just some minor comments. I think it's good enough to send upstream

Set the channel as a toggle enabled channel. Toggle operation
enables fast switching of a DAC output between two different DAC
codes without any SPI transaction.
type: boolean
Copy link
Collaborator

Choose a reason for hiding this comment

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

The toggle mode seems to be similar to both devices. Maybe something like this will make things better.

Just something you may wanna try before sending upstream.


/* internal reference */
if (chip_info->id == LTC2672)
st->vref = 1250;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm and in this case why is vref_reg not NULL? We did not got one and are we still going to configure it in ltc2664_setup()?

/*
* Duplicate the default channel configuration as it can change during
* @ltc2664_channel_config()
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: no need for this new line


st->rfsadj = 20000;
ret = device_property_read_u32(dev, "adi,rfsadj-ohms", &st->rfsadj);
if (!ret) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

After a second thought, I think (to be on the safe side) having a second check on the device id would make sense... So, we make sure no one skips bindings validations and uses properties o devices that don't support them . I would just another if() before checking the property values. Ditto for all specific properties...

if (ret)
break;
st->global_toggle = en;
break;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would just return len in here..

case LTC2664_GLOBAL_TOGGLE:
ret = regmap_write(st->regmap, LTC2664_CMD_GLOBAL_TOGGLE, en);
if (ret)
break;
Copy link
Collaborator

Choose a reason for hiding this comment

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

And return ret here so the last return len at the end of the function is not needed

return -EINVAL;
}

return sysfs_emit(buf, "%u\n", val);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same thing... No need for val. Return sysfs_emit() on every case directly

static int ltc2664_offset_get(const struct ltc2664_state *st, int c, int *val)
{
const struct ltc2664_chan *chan = &st->channels[c];
const int (*span_helper)[2] = st->chip_info->span_helper;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I would likely use st->chip_info->span_helper directly

ltc2664_reg_bool_get, ltc2664_reg_bool_set),
LTC2664_CHAN_EXT_INFO("toggle_en", LTC2664_TOGGLE_EN,
IIO_SEPARATE, ltc2664_reg_bool_get,
ltc2664_reg_bool_set),
Copy link
Collaborator

Choose a reason for hiding this comment

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

You're missing the ABI docs. I guess you can copy it from ltc2668.

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

2 participants