Skip to content

iio: dac: ad5592r: Create ADC_BUF_EN sysfs #2817

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Brian-Pellegrino-ARKA
Copy link
Contributor

Add sysfs for ADC_BUF_EN

PR Description

Adds a read/write sysfs file for the
ADC_BUF_EN bit of the GEN_CTRL_REG register

PR Type

  • Bug fix (a change that fixes an issue)
  • New feature (a change that adds new functionality)
  • Breaking change (a change that affects other repos or cause CIs to fail)

PR Checklist

  • I have conducted a self-review of my own code changes
  • I have tested the changes on the relevant hardware
  • I have updated the documentation outside this repo accordingly (if there is the case)

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.

Hi,

I still gave some comments on this patch but please note that this driver is upstream which means that I'll only take this patch after being first accepted upstream.

if (ret)
return ret;

return scnprintf(buf, PAGE_SIZE, "%d\n", !!(reg & AD5592R_GEN_CTRL_ADC_BUF_EN));
Copy link
Collaborator

Choose a reason for hiding this comment

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

sysfs_emit()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replaced with sysfs_emit()


ret = ad5592r_reg_write(st, AD5592R_REG_CTRL, reg);
if (ret)
return ret;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a RMW. Which means, a mutex is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added mutex

static int ad5592r_spi_probe(struct spi_device *spi)
{
const struct spi_device_id *id = spi_get_device_id(spi);
int ret = ad5592r_probe(&spi->dev, id->name, &ad5592r_rw_ops);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not typical kernel pattern calling a function like probe when declaring a variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed declarations to be kernel standard.

if (ret)
return ret;

struct iio_dev *indio = dev_get_drvdata(&spi->dev);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also not linux coding style. No mixed code declarations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed declarations to be kernel standard.


struct iio_dev *indio = dev_get_drvdata(&spi->dev);

ret = device_create_file(&indio->dev, &iio_dev_attr_adc_buf_en.dev_attr);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, in order to properly do this, you would likely need to change ad5592r_probe() so that you could pass this the device ATTR or an ATTR_GROUP down to the IIO register function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The attribute group is now passed to ad5592_probe() and handled there.

return count;
}

static IIO_DEVICE_ATTR(adc_buf_en, 0644, adc_buf_en_show, adc_buf_en_store, 0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is non standard ABI. You'll have to justify why this is needed and what's the usecase for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a justification and use case to the commit message.

Adds a read/write sysfs file for the
ADC_BUF_EN bit of the GEN_CTRL_REG register

ABI Change justification:
Exposes the ADC_BUF_EN bit so user-space applications
can dynamically enable or disable the AD5592R’s internal
adc buffer at runtime, allowing switching between
single-shot and buffered modes.

ABI Change example use case:
On board temperature readings are much more
stable with the adc buffer enabled.

Signed-off-by: Brian Pellegrino <bpellegrino@arka.org>
@Brian-Pellegrino-ARKA
Copy link
Contributor Author

I appreciate you taking a look through despite it needing to be upstreamed. I will make an upstream pull request.

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.

2 participants