drivers: regulator: pca9420: implement active discharge api
Implement the api for controlling the active discharge setting within the pca9420. Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
This commit is contained in:
parent
0f8ab3cf2d
commit
4fb4f71f08
|
@ -24,6 +24,8 @@
|
|||
#define PCA9420_TOP_CNTL3 0x0CU
|
||||
|
||||
/** Regulator status indication registers */
|
||||
/** @brief Active Discharge configuration for mode 0_0 */
|
||||
#define PCA9420_ACT_DISCHARGE_CNTL 0x21U
|
||||
/** @brief Mode configuration for mode 0_0 */
|
||||
#define PCA9420_MODECFG_0_0 0x22U
|
||||
/** @brief Mode configuration for mode 0_1 */
|
||||
|
@ -81,6 +83,18 @@
|
|||
/** @brief LDO2_OUT offset and voltage level mask */
|
||||
#define PCA9420_MODECFG_3_LDO2_OUT_MASK 0x3FU
|
||||
#define PCA9420_MODECFG_3_LDO2_OUT_POS 0U
|
||||
/** @brief SW1 active discharge control */
|
||||
#define PCA9420_ACT_DISCHARGE_CNTL_SW1_MASK 0x08U
|
||||
#define PCA9420_ACT_DISCHARGE_CNTL_SW1_POS 4U
|
||||
/** @brief SW2 active discharge control */
|
||||
#define PCA9420_ACT_DISCHARGE_CNTL_SW2_MASK 0x04U
|
||||
#define PCA9420_ACT_DISCHARGE_CNTL_SW2_POS 3U
|
||||
/** @brief LDO1 active discharge control */
|
||||
#define PCA9420_ACT_DISCHARGE_CNTL_LDO1_MASK 0x02U
|
||||
#define PCA9420_ACT_DISCHARGE_CNTL_LDO1_POS 2U
|
||||
/** @brief LDO2 active discharge control */
|
||||
#define PCA9420_ACT_DISCHARGE_CNTL_LDO2_MASK 0x01U
|
||||
#define PCA9420_ACT_DISCHARGE_CNTL_LDO2_POS 1U
|
||||
|
||||
/** VIN ILIM resolution, uA/LSB */
|
||||
#define PCA9420_VIN_ILIM_UA_LSB 170000
|
||||
|
@ -99,6 +113,8 @@ struct regulator_pca9420_desc {
|
|||
uint8_t vsel_reg;
|
||||
uint8_t vsel_mask;
|
||||
uint8_t vsel_pos;
|
||||
uint8_t ad_mask;
|
||||
uint8_t ad_pos;
|
||||
int32_t max_ua;
|
||||
uint8_t num_ranges;
|
||||
const struct linear_range *ranges;
|
||||
|
@ -159,6 +175,8 @@ static const struct regulator_pca9420_desc buck1_desc = {
|
|||
.vsel_mask = PCA9420_MODECFG_0_SW1_OUT_MASK,
|
||||
.vsel_pos = PCA9420_MODECFG_0_SW1_OUT_POS,
|
||||
.vsel_reg = PCA9420_MODECFG_0_0,
|
||||
.ad_mask = PCA9420_ACT_DISCHARGE_CNTL_SW1_MASK,
|
||||
.ad_pos = PCA9420_ACT_DISCHARGE_CNTL_SW1_POS,
|
||||
.max_ua = 250000,
|
||||
.ranges = buck1_ranges,
|
||||
.num_ranges = ARRAY_SIZE(buck1_ranges),
|
||||
|
@ -171,6 +189,8 @@ static const struct regulator_pca9420_desc buck2_desc = {
|
|||
.vsel_mask = PCA9420_MODECFG_1_SW2_OUT_MASK,
|
||||
.vsel_pos = PCA9420_MODECFG_1_SW2_OUT_POS,
|
||||
.vsel_reg = PCA9420_MODECFG_0_1,
|
||||
.ad_mask = PCA9420_ACT_DISCHARGE_CNTL_SW2_MASK,
|
||||
.ad_pos = PCA9420_ACT_DISCHARGE_CNTL_SW2_POS,
|
||||
.max_ua = 500000,
|
||||
.ranges = buck2_ranges,
|
||||
.num_ranges = ARRAY_SIZE(buck2_ranges),
|
||||
|
@ -183,6 +203,8 @@ static const struct regulator_pca9420_desc ldo1_desc = {
|
|||
.vsel_mask = PCA9420_MODECFG_2_LDO1_OUT_MASK,
|
||||
.vsel_pos = PCA9420_MODECFG_2_LDO1_OUT_POS,
|
||||
.vsel_reg = PCA9420_MODECFG_0_2,
|
||||
.ad_mask = PCA9420_ACT_DISCHARGE_CNTL_LDO1_MASK,
|
||||
.ad_pos = PCA9420_ACT_DISCHARGE_CNTL_LDO1_POS,
|
||||
.max_ua = 1000,
|
||||
.ranges = ldo1_ranges,
|
||||
.num_ranges = ARRAY_SIZE(ldo1_ranges),
|
||||
|
@ -195,6 +217,8 @@ static const struct regulator_pca9420_desc ldo2_desc = {
|
|||
.vsel_reg = PCA9420_MODECFG_0_3,
|
||||
.vsel_mask = PCA9420_MODECFG_3_LDO2_OUT_MASK,
|
||||
.vsel_pos = PCA9420_MODECFG_3_LDO2_OUT_POS,
|
||||
.ad_mask = PCA9420_ACT_DISCHARGE_CNTL_LDO2_MASK,
|
||||
.ad_pos = PCA9420_ACT_DISCHARGE_CNTL_LDO2_POS,
|
||||
.max_ua = 250000,
|
||||
.ranges = ldo2_ranges,
|
||||
.num_ranges = ARRAY_SIZE(ldo2_ranges),
|
||||
|
@ -279,6 +303,36 @@ static int regulator_pca9420_get_current_limit(const struct device *dev,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int regulator_pca9420_set_active_discharge(const struct device *dev,
|
||||
bool active_discharge)
|
||||
{
|
||||
const struct regulator_pca9420_config *config = dev->config;
|
||||
const struct regulator_pca9420_common_config *cconfig = config->parent->config;
|
||||
uint8_t dis_val;
|
||||
|
||||
dis_val = (!active_discharge) << config->desc->ad_pos;
|
||||
return i2c_reg_update_byte_dt(&cconfig->i2c, PCA9420_ACT_DISCHARGE_CNTL,
|
||||
config->desc->ad_mask, dis_val);
|
||||
}
|
||||
|
||||
static int regulator_pca9420_get_active_discharge(const struct device *dev,
|
||||
bool *active_discharge)
|
||||
{
|
||||
const struct regulator_pca9420_config *config = dev->config;
|
||||
const struct regulator_pca9420_common_config *cconfig = config->parent->config;
|
||||
uint8_t raw_reg;
|
||||
int ret;
|
||||
|
||||
ret = i2c_reg_read_byte_dt(&cconfig->i2c, PCA9420_ACT_DISCHARGE_CNTL, &raw_reg);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
*active_discharge = !((raw_reg & config->desc->ad_mask) >> config->desc->ad_pos);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int regulator_pca9420_enable(const struct device *dev)
|
||||
{
|
||||
const struct regulator_pca9420_config *config = dev->config;
|
||||
|
@ -313,6 +367,8 @@ static const struct regulator_driver_api api = {
|
|||
.set_voltage = regulator_pca9420_set_voltage,
|
||||
.get_voltage = regulator_pca9420_get_voltage,
|
||||
.get_current_limit = regulator_pca9420_get_current_limit,
|
||||
.set_active_discharge = regulator_pca9420_set_active_discharge,
|
||||
.get_active_discharge = regulator_pca9420_get_active_discharge,
|
||||
};
|
||||
|
||||
static int regulator_pca9420_init(const struct device *dev)
|
||||
|
|
Loading…
Reference in a new issue