drivers: regulator-fixed: add possibility to work without enable pins

Possible situation is that in some driver, devices can be controlled in
different ways: in some, we can only turn the power on or off, in others,
we can only control the voltage, and in some, we can control power supply
or voltage level. There may also be devices where there is no control
over power supply at all. A clear example of this can be eMMC devices
where the voltage is usually fixed and they are always powered on.
However, we would like to have a common code for controlling all the
mentioned types of devices, at least the driver shouldn't worry about the
implementation details of voltage regulators. Therefore, there may exist
empty regulators - regulators that only contain information about the
supported voltage, and we cannot change anything in them. The device tree
node description for such a regulator is only necessary for compatibility
with other regulators. Hence, we need to add the possibility of the
existence of such a dummy fixed-regulator.

In this commit, support for a fixed dummy regulator without the ability
for any control has been added. Note that such support also exists in the
Linux kernel. In other words, the logic of the fixed regulator has been
aligned with the logic of the fixed regulator inside the Linux kernel.

Signed-off-by: Mykola Kvach <mykola_kvach@epam.com>
This commit is contained in:
Mykola Kvach 2023-07-12 09:47:06 +03:00 committed by Fabio Baltieri
commit ed9ca0f6d3
3 changed files with 30 additions and 17 deletions

View file

@ -1,6 +1,7 @@
/*
* Copyright 2019-2020 Peter Bigot Consulting, LLC
* Copyright 2022 Nordic Semiconductor ASA
* Copyright 2023 EPAM Systems
* SPDX-License-Identifier: Apache-2.0
*/
@ -31,6 +32,10 @@ static int regulator_fixed_enable(const struct device *dev)
const struct regulator_fixed_config *cfg = dev->config;
int ret;
if (!cfg->enable.port) {
return -ENOTSUP;
}
ret = gpio_pin_set_dt(&cfg->enable, 1);
if (ret < 0) {
return ret;
@ -47,6 +52,10 @@ static int regulator_fixed_disable(const struct device *dev)
{
const struct regulator_fixed_config *cfg = dev->config;
if (!cfg->enable.port) {
return -ENOTSUP;
}
return gpio_pin_set_dt(&cfg->enable, 0);
}
@ -63,24 +72,26 @@ static int regulator_fixed_init(const struct device *dev)
regulator_common_data_init(dev);
if (!device_is_ready(cfg->enable.port)) {
LOG_ERR("GPIO port: %s not ready", cfg->enable.port->name);
return -ENODEV;
}
init_enabled = regulator_common_is_init_enabled(dev);
if (init_enabled) {
ret = gpio_pin_configure_dt(&cfg->enable, GPIO_OUTPUT_ACTIVE);
if (ret < 0) {
return ret;
if (cfg->enable.port != NULL) {
if (!device_is_ready(cfg->enable.port)) {
LOG_ERR("GPIO port: %s not ready", cfg->enable.port->name);
return -ENODEV;
}
k_busy_wait(cfg->startup_delay_us);
} else {
ret = gpio_pin_configure_dt(&cfg->enable, GPIO_OUTPUT_INACTIVE);
if (ret < 0) {
return ret;
if (init_enabled) {
ret = gpio_pin_configure_dt(&cfg->enable, GPIO_OUTPUT_ACTIVE);
if (ret < 0) {
return ret;
}
k_busy_wait(cfg->startup_delay_us);
} else {
ret = gpio_pin_configure_dt(&cfg->enable, GPIO_OUTPUT_INACTIVE);
if (ret < 0) {
return ret;
}
}
}
@ -94,7 +105,7 @@ static int regulator_fixed_init(const struct device *dev)
.common = REGULATOR_DT_INST_COMMON_CONFIG_INIT(inst), \
.startup_delay_us = DT_INST_PROP(inst, startup_delay_us), \
.off_on_delay_us = DT_INST_PROP(inst, off_on_delay_us), \
.enable = GPIO_DT_SPEC_INST_GET(inst, enable_gpios), \
.enable = GPIO_DT_SPEC_INST_GET_OR(inst, enable_gpios, {0}), \
}; \
\
DEVICE_DT_INST_DEFINE(inst, regulator_fixed_init, NULL, &data##inst, \

View file

@ -1,7 +1,8 @@
# Copyright 2019-2020 Peter Bigot Consulting, LLC
# Copyright 2023 EPAM Systems
# SPDX-License-Identifier: Apache-2.0
description: GPIO-controlled regulators
description: Fixed voltage regulators
include:
- name: base.yaml
@ -19,7 +20,6 @@ properties:
enable-gpios:
type: phandle-array
required: true
description: |
GPIO to use to enable/disable the regulator.

View file

@ -322,6 +322,7 @@ static inline int regulator_parent_ship_mode(const struct device *dev)
*
* @retval 0 If regulator has been successfully enabled.
* @retval -errno Negative errno in case of failure.
* @retval -ENOTSUP If regulator enablement can not be controlled.
*/
int regulator_enable(const struct device *dev);
@ -349,6 +350,7 @@ bool regulator_is_enabled(const struct device *dev);
*
* @retval 0 If regulator has been successfully disabled.
* @retval -errno Negative errno in case of failure.
* @retval -ENOTSUP If regulator disablement can not be controlled.
*/
int regulator_disable(const struct device *dev);