Skip to content

Commit 92c40db

Browse files
danieldegrassecarlescufi
authored andcommitted
drivers: regulator: remove mode awareness from PMIC
Remove mode awareness from PMIC voltage setting, current setting, and enable/disable functions. Concepts such as regulator consumers do not work well with multiple modes, so support for changing voltages or disabling regulators in each mode has been removed. Signed-off-by: Daniel DeGrasse <[email protected]>
1 parent d354179 commit 92c40db

File tree

2 files changed

+5
-32
lines changed

2 files changed

+5
-32
lines changed

drivers/regulator/regulator_pmic.c

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ struct regulator_data {
3939
struct onoff_sync_service srv;
4040
const struct voltage_range *voltages;
4141
const struct current_range *current_levels;
42-
uint8_t reg_offset;
4342
};
4443

4544
struct regulator_config {
@@ -74,11 +73,8 @@ static int regulator_read_register(const struct device *dev,
7473
uint8_t reg, uint8_t *out)
7574
{
7675
const struct regulator_config *conf = dev->config;
77-
struct regulator_data *data = dev->data;
7876
int ret;
7977

80-
/* Apply mode offset to register */
81-
reg += data->reg_offset;
8278
ret = i2c_reg_read_byte_dt(&conf->i2c, reg, out);
8379
LOG_DBG("READ 0x%x: 0x%x", reg, *out);
8480
return ret;
@@ -92,7 +88,6 @@ static int regulator_modify_register(const struct device *dev,
9288
uint8_t reg, uint8_t reg_mask, uint8_t reg_val)
9389
{
9490
const struct regulator_config *conf = dev->config;
95-
struct regulator_data *data = dev->data;
9691
uint8_t reg_current;
9792
int rc;
9893

@@ -101,8 +96,6 @@ static int regulator_modify_register(const struct device *dev,
10196
return rc;
10297
}
10398

104-
/* Apply mode offset to register */
105-
reg += data->reg_offset;
10699
reg_current &= ~reg_mask;
107100
reg_current |= (reg_val & reg_mask);
108101
LOG_DBG("WRITE 0x%02X to 0x%02X at I2C addr 0x%02X", reg_current,
@@ -281,14 +274,11 @@ int regulator_get_current_limit(const struct device *dev)
281274
/*
282275
* Part of the extended regulator consumer API
283276
* switches the regulator to a given mode. This API will apply a mode for
284-
* the regulator, and also configure the remainder of the regulator APIs,
285-
* such as those disabling, changing voltage/current targets, or querying
286-
* voltage/current targets to target that mode.
277+
* the regulator.
287278
*/
288279
int regulator_set_mode(const struct device *dev, uint32_t mode)
289280
{
290281
const struct regulator_config *config = dev->config;
291-
struct regulator_data *data = dev->data;
292282
int rc;
293283
uint8_t i, sel_off;
294284

@@ -310,26 +300,13 @@ int regulator_set_mode(const struct device *dev, uint32_t mode)
310300
/* Configure mode */
311301
if (mode & PMIC_MODE_FLAG_MODESEL_MULTI_REG) {
312302
/* Select mode with offset calculation */
313-
/* Set reg_offset here so it takes effect for the write
314-
* to modesel_reg
315-
*/
316-
data->reg_offset = sel_off;
317-
rc = regulator_modify_register(dev, config->modesel_reg,
303+
rc = regulator_modify_register(dev,
304+
config->modesel_reg + sel_off,
318305
mode & PMIC_MODE_SELECTOR_MASK, config->modesel_mask);
319306
} else {
320307
/* Select mode without offset to modesel_reg */
321-
/* Clear register offset */
322-
data->reg_offset = 0;
323308
rc = regulator_modify_register(dev, config->modesel_reg,
324309
mode & PMIC_MODE_SELECTOR_MASK, config->modesel_mask);
325-
if (rc) {
326-
return rc;
327-
}
328-
/* Since we did not use a register offset when selecting the
329-
* mode, but we now are targeting a specific mode's bank
330-
* of registers, we must still set the register offset here
331-
*/
332-
data->reg_offset = sel_off;
333310
}
334311
return rc;
335312
}
@@ -421,9 +398,7 @@ static const struct regulator_driver_api api = {
421398
DT_PROP(node, voltage_range); \
422399
static uint16_t pmic_reg_##ord##_allowed_modes[] = \
423400
DT_PROP_OR(DT_PARENT(node), regulator_allowed_modes, {}); \
424-
static struct regulator_data pmic_reg_##ord##_data = { \
425-
.reg_offset = 0, \
426-
}; \
401+
static struct regulator_data pmic_reg_##ord##_data; \
427402
static struct regulator_config pmic_reg_##ord##_cfg = { \
428403
.vsel_mask = DT_PROP(node, vsel_mask), \
429404
.vsel_reg = DT_PROP(node, vsel_reg), \

include/zephyr/drivers/regulator/consumer.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,7 @@ int regulator_get_current_limit(const struct device *dev);
106106
* @brief Select mode of regulator
107107
* Regulators can support multiple modes in order to permit different voltage
108108
* configuration or better power savings. This API will apply a mode for
109-
* the regulator, and also configure the remainder of the regulator APIs,
110-
* such as those disabling, changing voltage/current targets, or querying
111-
* voltage/current targets to target that mode.
109+
* the regulator.
112110
* @param dev: regulator to switch mode for
113111
* @param mode: Mode to select for this regulator. Only modes present
114112
* in the regulator-allowed-modes property are permitted.

0 commit comments

Comments
 (0)