Lines Matching +full:pmic +full:- +full:int +full:- +full:pin

3  * SPDX-License-Identifier: Apache-2.0
53 * PMIC pins MODESEL0 and MODESEL1 can be used to select the active mode
58 * @brief Mode configuration upon falling edge applied to ON pin. If set,
60 * to the ON pin
227 static unsigned int regulator_pca9420_count_voltages(const struct device *dev) in regulator_pca9420_count_voltages()
229 const struct regulator_pca9420_config *config = dev->config; in regulator_pca9420_count_voltages()
231 return linear_range_group_values_count(config->desc->ranges, in regulator_pca9420_count_voltages()
232 config->desc->num_ranges); in regulator_pca9420_count_voltages()
235 static int regulator_pca9420_list_voltage(const struct device *dev, in regulator_pca9420_list_voltage()
236 unsigned int idx, int32_t *volt_uv) in regulator_pca9420_list_voltage()
238 const struct regulator_pca9420_config *config = dev->config; in regulator_pca9420_list_voltage()
240 return linear_range_group_get_value(config->desc->ranges, in regulator_pca9420_list_voltage()
241 config->desc->num_ranges, idx, in regulator_pca9420_list_voltage()
245 static int regulator_pca9420_set_voltage(const struct device *dev, in regulator_pca9420_set_voltage()
248 const struct regulator_pca9420_config *config = dev->config; in regulator_pca9420_set_voltage()
249 const struct regulator_pca9420_common_config *cconfig = config->parent->config; in regulator_pca9420_set_voltage()
250 struct regulator_pca9420_common_data *cdata = config->parent->data; in regulator_pca9420_set_voltage()
252 int ret; in regulator_pca9420_set_voltage()
254 ret = linear_range_group_get_win_index(config->desc->ranges, in regulator_pca9420_set_voltage()
255 config->desc->num_ranges, min_uv, in regulator_pca9420_set_voltage()
257 if (ret == -EINVAL) { in regulator_pca9420_set_voltage()
261 idx <<= config->desc->vsel_pos; in regulator_pca9420_set_voltage()
263 return i2c_reg_update_byte_dt(&cconfig->i2c, config->desc->vsel_reg + in regulator_pca9420_set_voltage()
264 PCA9420_MODECFG_OFFSET(cdata->dvs_state), in regulator_pca9420_set_voltage()
265 config->desc->vsel_mask, (uint8_t)idx); in regulator_pca9420_set_voltage()
268 static int regulator_pca9420_get_voltage(const struct device *dev, in regulator_pca9420_get_voltage()
271 const struct regulator_pca9420_config *config = dev->config; in regulator_pca9420_get_voltage()
272 const struct regulator_pca9420_common_config *cconfig = config->parent->config; in regulator_pca9420_get_voltage()
273 struct regulator_pca9420_common_data *cdata = config->parent->data; in regulator_pca9420_get_voltage()
274 int ret; in regulator_pca9420_get_voltage()
277 ret = i2c_reg_read_byte_dt(&cconfig->i2c, config->desc->vsel_reg + in regulator_pca9420_get_voltage()
278 PCA9420_MODECFG_OFFSET(cdata->dvs_state), in regulator_pca9420_get_voltage()
284 raw_reg = (raw_reg & config->desc->vsel_mask) >> config->desc->vsel_pos; in regulator_pca9420_get_voltage()
286 return linear_range_group_get_value(config->desc->ranges, in regulator_pca9420_get_voltage()
287 config->desc->num_ranges, raw_reg, in regulator_pca9420_get_voltage()
291 static int regulator_pca9420_get_current_limit(const struct device *dev, in regulator_pca9420_get_current_limit()
294 const struct regulator_pca9420_config *config = dev->config; in regulator_pca9420_get_current_limit()
295 const struct regulator_pca9420_common_config *cconfig = config->parent->config; in regulator_pca9420_get_current_limit()
297 if (cconfig->vin_ilim_ua == 0U) { in regulator_pca9420_get_current_limit()
298 *curr_ua = config->desc->max_ua; in regulator_pca9420_get_current_limit()
300 *curr_ua = MIN(config->desc->max_ua, cconfig->vin_ilim_ua); in regulator_pca9420_get_current_limit()
306 static int regulator_pca9420_set_active_discharge(const struct device *dev, in regulator_pca9420_set_active_discharge()
309 const struct regulator_pca9420_config *config = dev->config; in regulator_pca9420_set_active_discharge()
310 const struct regulator_pca9420_common_config *cconfig = config->parent->config; in regulator_pca9420_set_active_discharge()
313 dis_val = (!active_discharge) << config->desc->ad_pos; in regulator_pca9420_set_active_discharge()
314 return i2c_reg_update_byte_dt(&cconfig->i2c, PCA9420_ACT_DISCHARGE_CNTL, in regulator_pca9420_set_active_discharge()
315 config->desc->ad_mask, dis_val); in regulator_pca9420_set_active_discharge()
318 static int regulator_pca9420_get_active_discharge(const struct device *dev, in regulator_pca9420_get_active_discharge()
321 const struct regulator_pca9420_config *config = dev->config; in regulator_pca9420_get_active_discharge()
322 const struct regulator_pca9420_common_config *cconfig = config->parent->config; in regulator_pca9420_get_active_discharge()
324 int ret; in regulator_pca9420_get_active_discharge()
326 ret = i2c_reg_read_byte_dt(&cconfig->i2c, PCA9420_ACT_DISCHARGE_CNTL, &raw_reg); in regulator_pca9420_get_active_discharge()
331 *active_discharge = !((raw_reg & config->desc->ad_mask) >> config->desc->ad_pos); in regulator_pca9420_get_active_discharge()
336 static int regulator_pca9420_enable(const struct device *dev) in regulator_pca9420_enable()
338 const struct regulator_pca9420_config *config = dev->config; in regulator_pca9420_enable()
339 const struct regulator_pca9420_common_config *cconfig = config->parent->config; in regulator_pca9420_enable()
340 struct regulator_pca9420_common_data *cdata = config->parent->data; in regulator_pca9420_enable()
343 en_val = config->enable_inverted ? 0 : config->desc->enable_val; in regulator_pca9420_enable()
344 return i2c_reg_update_byte_dt(&cconfig->i2c, config->desc->enable_reg in regulator_pca9420_enable()
345 + PCA9420_MODECFG_OFFSET(cdata->dvs_state), in regulator_pca9420_enable()
346 config->desc->enable_mask, en_val); in regulator_pca9420_enable()
349 static int regulator_pca9420_disable(const struct device *dev) in regulator_pca9420_disable()
351 const struct regulator_pca9420_config *config = dev->config; in regulator_pca9420_disable()
352 const struct regulator_pca9420_common_config *cconfig = config->parent->config; in regulator_pca9420_disable()
353 struct regulator_pca9420_common_data *cdata = config->parent->data; in regulator_pca9420_disable()
356 dis_val = config->enable_inverted ? config->desc->enable_val : 0; in regulator_pca9420_disable()
357 return i2c_reg_update_byte_dt(&cconfig->i2c, config->desc->enable_reg in regulator_pca9420_disable()
358 + PCA9420_MODECFG_OFFSET(cdata->dvs_state), in regulator_pca9420_disable()
359 config->desc->enable_mask, dis_val); in regulator_pca9420_disable()
374 static int regulator_pca9420_init(const struct device *dev) in regulator_pca9420_init()
376 const struct regulator_pca9420_config *config = dev->config; in regulator_pca9420_init()
377 const struct regulator_pca9420_common_config *cconfig = config->parent->config; in regulator_pca9420_init()
381 if (!device_is_ready(config->parent)) { in regulator_pca9420_init()
382 return -ENODEV; in regulator_pca9420_init()
386 for (uint8_t i = 0U; i < ARRAY_SIZE(config->modes_uv); i++) { in regulator_pca9420_init()
387 int ret; in regulator_pca9420_init()
389 if (config->modes_uv[i] == 0) { in regulator_pca9420_init()
392 &cconfig->i2c, in regulator_pca9420_init()
393 config->desc->enable_reg + PCA9420_MODECFG_OFFSET(i), in regulator_pca9420_init()
394 config->desc->enable_mask, 0U); in regulator_pca9420_init()
398 } else if (config->modes_uv[i] > 0) { in regulator_pca9420_init()
403 config->desc->ranges, config->desc->num_ranges, in regulator_pca9420_init()
404 config->modes_uv[i], config->modes_uv[i], &idx); in regulator_pca9420_init()
405 if (ret == -EINVAL) { in regulator_pca9420_init()
409 idx <<= config->desc->vsel_pos; in regulator_pca9420_init()
412 &cconfig->i2c, in regulator_pca9420_init()
413 config->desc->vsel_reg + PCA9420_MODECFG_OFFSET(i), in regulator_pca9420_init()
414 config->desc->vsel_mask, (uint8_t)idx); in regulator_pca9420_init()
424 int regulator_pca9420_dvs_state_set(const struct device *dev, in regulator_pca9420_dvs_state_set()
427 const struct regulator_pca9420_common_config *config = dev->config; in regulator_pca9420_dvs_state_set()
428 struct regulator_pca9420_common_data *data = dev->data; in regulator_pca9420_dvs_state_set()
429 int ret; in regulator_pca9420_dvs_state_set()
432 return -ENOTSUP; in regulator_pca9420_dvs_state_set()
435 if (config->enable_modesel_pins) { in regulator_pca9420_dvs_state_set()
439 * Return -EPERM to indicate change failed, but change the in regulator_pca9420_dvs_state_set()
443 data->dvs_state = state; in regulator_pca9420_dvs_state_set()
444 return -EPERM; in regulator_pca9420_dvs_state_set()
447 ret = i2c_reg_update_byte_dt(&config->i2c, PCA9420_TOP_CNTL3, in regulator_pca9420_dvs_state_set()
454 data->dvs_state = state; in regulator_pca9420_dvs_state_set()
462 static int regulator_pca9420_common_init(const struct device *dev) in regulator_pca9420_common_init()
464 const struct regulator_pca9420_common_config *config = dev->config; in regulator_pca9420_common_init()
466 int ret; in regulator_pca9420_common_init()
468 if (!device_is_ready(config->i2c.bus)) { in regulator_pca9420_common_init()
469 return -ENODEV; in regulator_pca9420_common_init()
472 if (config->enable_modesel_pins) { in regulator_pca9420_common_init()
476 &config->i2c, in regulator_pca9420_common_init()
488 if (config->vin_ilim_ua != 0U) { in regulator_pca9420_common_init()
489 reg_val = (config->vin_ilim_ua - PCA9420_VIN_ILIM_MIN_UA) / in regulator_pca9420_common_init()
494 &config->i2c, PCA9420_TOP_CNTL0, in regulator_pca9420_common_init()
503 return i2c_reg_update_byte_dt(&config->i2c, PCA9420_TOP_CNTL2, in regulator_pca9420_common_init()
505 config->asys_uvlo_sel_mv << in regulator_pca9420_common_init()
516 DT_PROP_OR(node_id, nxp_mode0_microvolt, -1), \
517 DT_PROP_OR(node_id, nxp_mode1_microvolt, -1), \
518 DT_PROP_OR(node_id, nxp_mode2_microvolt, -1), \
519 DT_PROP_OR(node_id, nxp_mode3_microvolt, -1), \