forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
drivers: regulator: drop async enable
Drop the async enable function. This feature is rarely/never used, complicates driver design, and doesn't really follow the sync/async API design/naming used in other areas. In the future we can introduce regulator_enable_async if needed, with support from the driver class (no onoff). Note that drivers like PCA9420 did not implement any asynchronous behavior. regulator-fixed implemented in the past asynchronous behavior using work queues, an overkill for most GPIO driven regulators. Let's keep things simple for now and extend the API when needed, based on specific usecases. In the current implementation, reference counting is managed by the driver class. \isr-ok attribute is dropped, since calls are potentially blocking. Note that drivers like PCA9420 already violated such rule. Signed-off-by: Gerard Marull-Paretas <[email protected]>
- Loading branch information
1 parent
e0c8de1
commit a29bdc2
Showing
7 changed files
with
132 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2022 Nordic Semiconductor ASA | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/drivers/regulator.h> | ||
|
||
void regulator_common_data_init(const struct device *dev) | ||
{ | ||
struct regulator_common_data *data = | ||
(struct regulator_common_data *)dev->data; | ||
|
||
(void)k_mutex_init(&data->lock); | ||
data->refcnt = 0; | ||
} | ||
|
||
int regulator_enable(const struct device *dev) | ||
{ | ||
struct regulator_common_data *data = | ||
(struct regulator_common_data *)dev->data; | ||
int ret = 0; | ||
|
||
(void)k_mutex_lock(&data->lock, K_FOREVER); | ||
|
||
data->refcnt++; | ||
|
||
if (data->refcnt == 1) { | ||
const struct regulator_driver_api *api = | ||
(const struct regulator_driver_api *)dev->api; | ||
|
||
ret = api->enable(dev); | ||
if (ret < 0) { | ||
data->refcnt--; | ||
} | ||
} | ||
|
||
k_mutex_unlock(&data->lock); | ||
|
||
return ret; | ||
} | ||
|
||
int regulator_disable(const struct device *dev) | ||
{ | ||
struct regulator_common_data *data = | ||
(struct regulator_common_data *)dev->data; | ||
int ret = 0; | ||
|
||
(void)k_mutex_lock(&data->lock, K_FOREVER); | ||
|
||
data->refcnt--; | ||
|
||
if (data->refcnt == 0) { | ||
const struct regulator_driver_api *api = | ||
(const struct regulator_driver_api *)dev->api; | ||
|
||
ret = api->disable(dev); | ||
if (ret < 0) { | ||
data->refcnt++; | ||
} | ||
} | ||
|
||
k_mutex_unlock(&data->lock); | ||
|
||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.