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: regulator: implement active discharge api #61056

Conversation

XenuIsWatching
Copy link
Member

@XenuIsWatching XenuIsWatching commented Aug 2, 2023

Add an active discharge api for regulators. This uses the already existing but previously unused regulator-active-discharge property.

This implements it within the pca9420.

I am currently working on my own PMIC where I need this api but I do not have the pca9420 to test with and verify it... but this seems like a trivial addition

TODO:

  • Add test cases
  • Add shell cmd
  • only allow bool param

@XenuIsWatching XenuIsWatching force-pushed the regulator-active-discharge branch 8 times, most recently from 40021c2 to d4d35f2 Compare August 7, 2023 17:02
@XenuIsWatching XenuIsWatching marked this pull request as ready for review August 7, 2023 20:16
@XenuIsWatching XenuIsWatching force-pushed the regulator-active-discharge branch 3 times, most recently from aac75a6 to 5ad2d4c Compare August 7, 2023 20:48
Copy link
Member

@gmarull gmarull left a comment

Choose a reason for hiding this comment

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

before adding new ops to regulators:

  • Is this feature present across multiple regulator devices? Is this related with e.g. ADP5360 adi,enable-output-discharge?
  • Is this meant to be set/unset at runtime? For example, ADP5360 driver just takes it from DT at init time
  • It may be better to introduce a more generic set/get props API. I fear more properties will pop up, and we can't keep increasing ops table for each one...

@XenuIsWatching
Copy link
Member Author

XenuIsWatching commented Aug 10, 2023

  • Is this feature present across multiple regulator devices? Is this related with e.g. ADP5360 adi,enable-output-discharge?

This is also present in other regulator devices. I am working on the MAX77643. This api is also implemented in the linux regulator driver which this was modeled after.
https://github.com/torvalds/linux/blob/25aa0bebba72b318e71fe205bfd1236550cc9534/include/linux/regulator/driver.h#L186
It looks the ADP5360 is it's own 'vendor' prop when there is already one in the regulator.yaml which is the one I'm using.

  • Is this meant to be set/unset at runtime? For example, ADP5360 driver just takes it from DT at init time

yes. the ADP5360 may want to have this api implemented as well.... but I do not have that part to test out.

  • It may be better to introduce a more generic set/get props API. I fear more properties will pop up, and we can't keep increasing ops table for each one...

I understand your concerns there...I'm not sure what you mean by a 'more generic set/get prop api`, but this active discharge setting appears to be very generic and is within a lot of regulators. Just not implemented in some of the already existing drivers.

Copy link
Member

@gmarull gmarull left a comment

Choose a reason for hiding this comment

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

lgtm, just a few comments, will actually migrate adp driver to this new API.

* @retval -errno In case of any other error.
*/
static inline int regulator_set_active_discharge(const struct device *dev,
uint8_t active_discharge)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
uint8_t active_discharge)
bool enable)

Copy link
Member Author

Choose a reason for hiding this comment

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

my concern with making it a bool would be handle the issue of it not being defined where it just gets set to the max value of a UINT8

Copy link
Contributor

Choose a reason for hiding this comment

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

I think bool would be better if we can assume that active_discharge is always disabled by default. If this is not a safe assumption I think it is OK like this.

Copy link
Member

Choose a reason for hiding this comment

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

From an API client perspective, this function will always be called with either 0 or 1 (bool), am I wrong?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah. I updated to be a bool

* @retval -errno In case of any other error.
*/
static inline int regulator_get_active_discharge(const struct device *dev,
uint8_t *active_discharge)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
uint8_t *active_discharge)
bool *enabled)

note: Linux doesn't seem to offer a getter, is it really needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

correct, but just because Linux doesn't do it doesn't mean we also shouldn't do it. I can't really think of a reason not to have it.

Copy link
Member

Choose a reason for hiding this comment

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

Linux is usually right, Zephyr... not so much ;-)

@@ -611,6 +611,58 @@ ZTEST(regulator_api, test_get_mode_not_implemented)
zassert_equal(ret, -ENOSYS);
}

ZTEST(regulator_api, test_set_active_discharge_not_implemented)
Copy link
Member

Choose a reason for hiding this comment

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

please update test_common_config test as well, to cover correct capture of dt info

@gmarull
Copy link
Member

gmarull commented Aug 11, 2023

  • Is this feature present across multiple regulator devices? Is this related with e.g. ADP5360 adi,enable-output-discharge?

This is also present in other regulator devices. I am working on the MAX77643. This api is also implemented in the linux regulator driver which this was modeled after. https://github.com/torvalds/linux/blob/25aa0bebba72b318e71fe205bfd1236550cc9534/include/linux/regulator/driver.h#L186 It looks the ADP5360 is it's own 'vendor' prop when there is already one in the regulator.yaml which is the one I'm using.

  • Is this meant to be set/unset at runtime? For example, ADP5360 driver just takes it from DT at init time

yes. the ADP5360 may want to have this api implemented as well.... but I do not have that part to test out.

  • It may be better to introduce a more generic set/get props API. I fear more properties will pop up, and we can't keep increasing ops table for each one...

I understand your concerns there...I'm not sure what you mean by a 'more generic set/get prop api`, but this active discharge setting appears to be very generic and is within a lot of regulators. Just not implemented in some of the already existing drivers.

thanks for this info, make sense

@XenuIsWatching XenuIsWatching force-pushed the regulator-active-discharge branch 2 times, most recently from 1e25b52 to 6cb220b Compare August 26, 2023 09:03
@carlescufi
Copy link
Member

@gmarull @aasinclair could you please take a look?

@MaureenHelm
Copy link
Member

@gmarull @aasinclair could you please take a look?

ping

@gmarull
Copy link
Member

gmarull commented Oct 6, 2023

@gmarull @aasinclair could you please take a look?

ping

this PR has unresolved questions, please check.

Add an active discharge api for regulators. This uses the already
existing but previously unused regulator-active-discharge
property.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
Add tests for active discharge apis not being implemented.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
Add the active discharge functions that can be called from the
regulator shell.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
Implement the api for controlling the active discharge setting within
the pca9420.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
@XenuIsWatching
Copy link
Member Author

@gmarull This should be ready for another review. Thanks!

@henrikbrixandersen henrikbrixandersen merged commit 4fb4f71 into zephyrproject-rtos:main Jan 29, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

7 participants