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: power: ltc2992: Add LTC2992 driver #2165

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

Conversation

cencarna
Copy link

@cencarna cencarna commented Apr 29, 2024

Pull Request Description

The LTC2992 is a rail-to-rail system monitor that measures current,
voltage, and power of two supplies. It features an operating range of
2.7V to 100V and includes a shunt regulator for supplies above 100V.
Minimum and maximum values are stored and an overrange alert with
programmable thresholds minimizes the need for software polling. Data is
reported via a standard I2C interface.

PR Type

  • Bug fix (change that fixes an issue)
  • New feature (change that adds new functionality)
  • Breaking change (has dependencies in other repos or will cause CI to fail)

PR Checklist

  • I have followed the Coding style guidelines
  • I have performed a self-review of the changes
  • I have commented my code, at least hard-to-understand parts
  • I have build all projects affected by the changes in this PR
  • I have tested in hardware affected projects, at the relevant boards
  • I have signed off all commits from this PR
  • I have updated the documentation (wiki pages, ReadMe etc), if applies

@CLAassistant
Copy link

CLAassistant commented Apr 29, 2024

CLA assistant check
All committers have signed the CLA.

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.

looks good overall at first sight.

struct ltc2992_init_param {
struct no_os_i2c_init_param i2c_init;

#if LTC2992_USE_GPIO
Copy link
Contributor

Choose a reason for hiding this comment

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

This macro is redundant. The user already has the option to use or not the gpio via no_os_gpio_get_optional

Copy link
Author

Choose a reason for hiding this comment

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

will remove LTC2992_USE_GPIO macro in struct ltc2992_dev, struct ltc2992_init_param, ltc2992_init, and ltc2992_remove. Should I also remove the same macro at the beginning of gpio-specific functions and variables? I made this macro so that they will not be included at compile-time if the user opt not to use the gpios.

drivers/power/ltc2992/ltc2992.c Outdated Show resolved Hide resolved
drivers/power/ltc2992/ltc2992.h Outdated Show resolved Hide resolved
drivers/power/ltc2992/ltc2992.c Outdated Show resolved Hide resolved
drivers/power/ltc2992/ltc2992.c Outdated Show resolved Hide resolved
drivers/power/ltc2992/ltc2992.c Outdated Show resolved Hide resolved

i2c_err :
no_os_free(dev);
return ret;
Copy link
Contributor

Choose a reason for hiding this comment

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

revert the order of i2c_err and dev_err. Then you would only have 1 return ret

Copy link
Author

@cencarna cencarna Apr 30, 2024

Choose a reason for hiding this comment

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

Removing the first return ret may result to double frees. Will this be okay? Alternatively, I can just call no_os_gpio_remove and no_os_i2c_remove directly in dev_err

dev_err:
	no_os_gpio_remove(dev->alert_gpio_desc);
	no_os_i2c_remove(dev->i2c_desc);
i2c_err:
	no_os_free(dev);
	return ret;

Will this be a better implementation?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for the delay, yes, that's what I've meant

drivers/power/ltc2992/ltc2992.c Outdated Show resolved Hide resolved
@rbolboac
Copy link
Contributor

/AzurePipelines run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Copy link

Commenter does not have sufficient privileges for PR 2165 in repo analogdevicesinc/no-OS

@cencarna
Copy link
Author

cencarna commented May 2, 2024

Changelog:
Addressed comments from reviewers with few questions. Fixed unsuccessful documentation check.

@rbolboac
Copy link
Contributor

rbolboac commented May 9, 2024

/AzurePipelines run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

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.

do not forget to add documentation commit for the driver. Example (f3c60c0)

@cencarna cencarna force-pushed the staging/ltc2992 branch 2 times, most recently from d14a005 to d2902b4 Compare May 21, 2024 10:13
@cencarna
Copy link
Author

Changelog:
Added driver documentation.

The LTC2992 is a rail-to-rail system monitor that measures current,
voltage, and power of two supplies. It features an operating range of
2.7V to 100V and includes a shunt regulator for supplies above 100V.
Minimum and maximum values are stored and an overrange alert with
programmable thresholds minimizes the need for software polling. Data is
reported via a standard I2C interface.

Signed-off-by: Cedric Encarnacion <cedricjustine.encarnacion@analog.com>
Add README.rst file containing documentation of the LTC2992 driver.

Signed-off-by: Cedric Encarnacion <cedricjustine.encarnacion@analog.com>
@cencarna
Copy link
Author

Change log:
Addressed reviews. Solved merge conflict in docs.

* @note The default is @p TRUE.
*/
#ifndef LTC2992_USE_GPIO
#define LTC2992_USE_GPIO 1
Copy link
Contributor

Choose a reason for hiding this comment

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

I still don't quite like this approach of guarding part functionalities using macro definitions. Moreover you enable all features by default here. I'd suggest dropping it completely, but let's see what others have to say.

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

6 participants