Lines Matching +full:i2c +full:- +full:mode

3  * SPDX-License-Identifier: Apache-2.0
11 #include <zephyr/drivers/i2c.h>
27 /** @brief Active Discharge configuration for mode 0_0 */
29 /** @brief Mode configuration for mode 0_0 */
31 /** @brief Mode configuration for mode 0_1 */
33 /** @brief Mode configuration for mode 0_2 */
35 /** @brief Mode configuration for mode 0_3 */
47 /** @brief I2C Mode control mask */
52 * @brief Mode control selection mask. When this bit is set, the external
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,
59 * the device will switch to mode 0 when a valid falling edge is applied.
62 /** @brief Mode output voltage mask */
106 /** Offset applied to MODECFG* registers for a given mode */
107 #define PCA9420_MODECFG_OFFSET(mode) ((mode) * 4U) argument
124 struct i2c_dt_spec i2c; member
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
385 /* configure mode voltages */ in regulator_pca9420_init()
386 for (uint8_t i = 0U; i < ARRAY_SIZE(config->modes_uv); i++) { in regulator_pca9420_init()
389 if (config->modes_uv[i] == 0) { in regulator_pca9420_init()
390 /* disable mode if voltage is 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()
401 /* program mode voltage */ 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()
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()
432 return -ENOTSUP; in regulator_pca9420_dvs_state_set()
435 if (config->enable_modesel_pins) { in regulator_pca9420_dvs_state_set()
438 * but they may want to query/set voltages for another mode. in regulator_pca9420_dvs_state_set()
439 * Return -EPERM to indicate change failed, but change the in regulator_pca9420_dvs_state_set()
441 * dvs mode settings. 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()
464 const struct regulator_pca9420_common_config *config = dev->config; 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()
473 /* enable MODESEL0/1 pins for each mode */ 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), \
537 .i2c = I2C_DT_SPEC_INST_GET(inst), \