File tree Expand file tree Collapse file tree 4 files changed +49
-16
lines changed
Expand file tree Collapse file tree 4 files changed +49
-16
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,30 @@ void regulator_common_data_init(const struct device *dev)
1414 data -> refcnt = 0 ;
1515}
1616
17+ int regulator_common_init_enable (const struct device * dev )
18+ {
19+ const struct regulator_common_config * config =
20+ (struct regulator_common_config * )dev -> config ;
21+ struct regulator_common_data * data =
22+ (struct regulator_common_data * )dev -> data ;
23+
24+ if ((config -> flags & REGULATOR_INIT_ENABLED ) != 0U ) {
25+ const struct regulator_driver_api * api =
26+ (const struct regulator_driver_api * )dev -> api ;
27+
28+ int ret ;
29+
30+ ret = api -> enable (dev );
31+ if (ret < 0 ) {
32+ return ret ;
33+ }
34+
35+ data -> refcnt ++ ;
36+ }
37+
38+ return 0 ;
39+ }
40+
1741int regulator_enable (const struct device * dev )
1842{
1943 const struct regulator_driver_api * api =
Original file line number Diff line number Diff line change @@ -67,18 +67,18 @@ static int regulator_fixed_init(const struct device *dev)
6767 return - ENODEV ;
6868 }
6969
70- if ((cfg -> common .flags & REGULATOR_INIT_ENABLED ) != 0U ) {
71- ret = gpio_pin_configure_dt (& cfg -> enable , GPIO_OUTPUT_ACTIVE );
72- if (ret < 0 ) {
73- return ret ;
74- }
70+ ret = gpio_pin_configure_dt (& cfg -> enable , GPIO_OUTPUT_INACTIVE );
71+ if (ret < 0 ) {
72+ return ret ;
73+ }
74+
75+ ret = regulator_common_init_enable (dev );
76+ if (ret < 0 ) {
77+ return ret ;
78+ }
7579
80+ if (regulator_is_enabled (dev )) {
7681 k_busy_wait (cfg -> startup_delay_us );
77- } else {
78- ret = gpio_pin_configure_dt (& cfg -> enable , GPIO_OUTPUT_INACTIVE );
79- if (ret < 0 ) {
80- return ret ;
81- }
8282 }
8383
8484 return 0 ;
Original file line number Diff line number Diff line change @@ -300,7 +300,6 @@ static int regulator_pca9420_init(const struct device *dev)
300300{
301301 const struct regulator_pca9420_config * config = dev -> config ;
302302 const struct regulator_pca9420_common_config * cconfig = config -> parent -> config ;
303- int rc = 0 ;
304303
305304 regulator_common_data_init (dev );
306305
@@ -344,11 +343,7 @@ static int regulator_pca9420_init(const struct device *dev)
344343 }
345344 }
346345
347- if ((config -> common .flags & REGULATOR_INIT_ENABLED ) != 0U ) {
348- rc = regulator_pca9420_enable (dev );
349- }
350-
351- return rc ;
346+ return regulator_common_init_enable (dev );
352347}
353348
354349int regulator_pca9420_dvs_state_set (const struct device * dev ,
Original file line number Diff line number Diff line change @@ -153,6 +153,20 @@ struct regulator_common_data {
153153 */
154154void regulator_common_data_init (const struct device * dev );
155155
156+ /**
157+ * @brief Common function to enable regulator at init time.
158+ *
159+ * This function can be called after drivers initialize the regulator. It
160+ * will automatically enable the regulator if it is set to `regulator-boot-on`
161+ * or `regulator-always-on` and increase its usage count.
162+ *
163+ * @param dev Regulator device instance
164+ *
165+ * @retval 0 If enabled successfully.
166+ * @retval -errno Negative errno in case of failure.
167+ */
168+ int regulator_common_init_enable (const struct device * dev );
169+
156170/** @endcond */
157171
158172/**
You can’t perform that action at this time.
0 commit comments