Lines Matching +full:npm1300 +full:- +full:regulator
3 * SPDX-License-Identifier: Apache-2.0
12 #include <zephyr/drivers/regulator.h>
13 #include <zephyr/drivers/mfd/npm1300.h>
14 #include <zephyr/dt-bindings/regulator/npm1300.h>
18 /* nPM1300 voltage sources */
26 /* nPM1300 gpio control channels */
33 /* nPM1300 regulator base addresses */
38 /* nPM1300 regulator register offsets */
53 /* nPM1300 ldsw register offsets */
62 /* nPM1300 ship register offsets */
101 const struct regulator_npm1300_config *config = dev->config; in regulator_npm1300_count_voltages()
103 switch (config->source) { in regulator_npm1300_count_voltages()
116 const struct regulator_npm1300_config *config = dev->config; in regulator_npm1300_list_voltage()
118 switch (config->source) { in regulator_npm1300_list_voltage()
125 return -EINVAL; in regulator_npm1300_list_voltage()
131 const struct regulator_npm1300_config *config = dev->config; in retention_set_voltage()
136 switch (config->source) { in retention_set_voltage()
144 return -ENOTSUP; in retention_set_voltage()
149 if (ret == -EINVAL) { in retention_set_voltage()
153 return mfd_npm1300_reg_write(config->mfd, BUCK_BASE, BUCK_OFFSET_VOUT_RET + (chan * 2U), in retention_set_voltage()
159 const struct regulator_npm1300_config *config = dev->config; in buck_get_voltage_index()
163 ret = mfd_npm1300_reg_read(config->mfd, BUCK_BASE, BUCK_OFFSET_SW_CTRL, &sel); in buck_get_voltage_index()
171 return mfd_npm1300_reg_read(config->mfd, BUCK_BASE, in buck_get_voltage_index()
176 return mfd_npm1300_reg_read(config->mfd, BUCK_BASE, BUCK_OFFSET_VOUT_STAT + chan, idx); in buck_get_voltage_index()
181 const struct regulator_npm1300_config *config = dev->config; in buck_set_voltage()
189 if (ret == -EINVAL) { in buck_set_voltage()
200 ret = mfd_npm1300_reg_write(config->mfd, BUCK_BASE, BUCK_OFFSET_VOUT_NORM + (chan * 2U), in buck_set_voltage()
209 return mfd_npm1300_reg_update(config->mfd, BUCK_BASE, BUCK_OFFSET_SW_CTRL, mask, mask); in buck_set_voltage()
214 const struct regulator_npm1300_config *config = dev->config; in ldo_set_voltage()
220 if (ret == -EINVAL) { in ldo_set_voltage()
224 return mfd_npm1300_reg_write(config->mfd, LDSW_BASE, LDSW_OFFSET_VOUTSEL + chan, idx); in ldo_set_voltage()
229 const struct regulator_npm1300_config *config = dev->config; in regulator_npm1300_set_voltage()
231 switch (config->source) { in regulator_npm1300_set_voltage()
241 return -ENODEV; in regulator_npm1300_set_voltage()
261 const struct regulator_npm1300_config *config = dev->config; in ldo_get_voltage()
265 ret = mfd_npm1300_reg_read(config->mfd, LDSW_BASE, LDSW_OFFSET_VOUTSEL + chan, &idx); in ldo_get_voltage()
276 const struct regulator_npm1300_config *config = dev->config; in regulator_npm1300_get_voltage()
278 switch (config->source) { in regulator_npm1300_get_voltage()
288 return -ENODEV; in regulator_npm1300_get_voltage()
294 const struct regulator_npm1300_config *config = dev->config; in set_buck_mode()
314 return -ENOTSUP; in set_buck_mode()
317 ret = mfd_npm1300_reg_update(config->mfd, BUCK_BASE, BUCK_OFFSET_CTRL0, pfm_data, pfm_mask); in set_buck_mode()
322 return mfd_npm1300_reg_write(config->mfd, BUCK_BASE, pwm_reg + (chan * 2U), 1U); in set_buck_mode()
327 const struct regulator_npm1300_config *config = dev->config; in set_ldsw_mode()
331 return mfd_npm1300_reg_write(config->mfd, LDSW_BASE, LDSW_OFFSET_LDOSEL + chan, 1U); in set_ldsw_mode()
333 return mfd_npm1300_reg_write(config->mfd, LDSW_BASE, LDSW_OFFSET_LDOSEL + chan, 0U); in set_ldsw_mode()
335 return -ENOTSUP; in set_ldsw_mode()
341 const struct regulator_npm1300_config *config = dev->config; in regulator_npm1300_set_mode()
343 switch (config->source) { in regulator_npm1300_set_mode()
353 return -ENOTSUP; in regulator_npm1300_set_mode()
359 const struct regulator_npm1300_config *config = dev->config; in regulator_npm1300_enable()
361 switch (config->source) { in regulator_npm1300_enable()
363 return mfd_npm1300_reg_write(config->mfd, BUCK_BASE, BUCK_OFFSET_EN_SET, 1U); in regulator_npm1300_enable()
365 return mfd_npm1300_reg_write(config->mfd, BUCK_BASE, BUCK_OFFSET_EN_SET + 2U, 1U); in regulator_npm1300_enable()
367 return mfd_npm1300_reg_write(config->mfd, LDSW_BASE, LDSW_OFFSET_EN_SET, 1U); in regulator_npm1300_enable()
369 return mfd_npm1300_reg_write(config->mfd, LDSW_BASE, LDSW_OFFSET_EN_SET + 2U, 1U); in regulator_npm1300_enable()
377 const struct regulator_npm1300_config *config = dev->config; in regulator_npm1300_disable()
379 switch (config->source) { in regulator_npm1300_disable()
381 return mfd_npm1300_reg_write(config->mfd, BUCK_BASE, BUCK_OFFSET_EN_CLR, 1U); in regulator_npm1300_disable()
383 return mfd_npm1300_reg_write(config->mfd, BUCK_BASE, BUCK_OFFSET_EN_CLR + 2U, 1U); in regulator_npm1300_disable()
385 return mfd_npm1300_reg_write(config->mfd, LDSW_BASE, LDSW_OFFSET_EN_CLR, 1U); in regulator_npm1300_disable()
387 return mfd_npm1300_reg_write(config->mfd, LDSW_BASE, LDSW_OFFSET_EN_CLR + 2U, 1U); in regulator_npm1300_disable()
396 const struct regulator_npm1300_config *config = dev->config; in regulator_npm1300_set_buck_pin_ctrl()
402 /* Invert control in bit 6, pin control in bits 2-0 */ in regulator_npm1300_set_buck_pin_ctrl()
407 /* Invert control in bit 7, pin control in bits 5-3 */ in regulator_npm1300_set_buck_pin_ctrl()
412 return -EINVAL; in regulator_npm1300_set_buck_pin_ctrl()
417 return mfd_npm1300_reg_update(config->mfd, BUCK_BASE, BUCK_OFFSET_EN_CTRL, ctrl, in regulator_npm1300_set_buck_pin_ctrl()
420 return mfd_npm1300_reg_update(config->mfd, BUCK_BASE, BUCK_OFFSET_PWM_CTRL, ctrl, in regulator_npm1300_set_buck_pin_ctrl()
423 return mfd_npm1300_reg_update(config->mfd, BUCK_BASE, BUCK_OFFSET_VRET_CTRL, ctrl, in regulator_npm1300_set_buck_pin_ctrl()
426 return -ENOTSUP; in regulator_npm1300_set_buck_pin_ctrl()
433 const struct regulator_npm1300_config *config = dev->config; in regulator_npm1300_set_ldsw_pin_ctrl()
437 return -ENOTSUP; in regulator_npm1300_set_ldsw_pin_ctrl()
442 return mfd_npm1300_reg_write(config->mfd, LDSW_BASE, LDSW_OFFSET_GPISEL + chan, ctrl); in regulator_npm1300_set_ldsw_pin_ctrl()
448 const struct regulator_npm1300_config *config = dev->config; in regulator_npm1300_set_pin_ctrl()
451 if (spec->port == NULL) { in regulator_npm1300_set_pin_ctrl()
455 inv = (spec->dt_flags & GPIO_ACTIVE_LOW) != 0U; in regulator_npm1300_set_pin_ctrl()
457 switch (config->source) { in regulator_npm1300_set_pin_ctrl()
459 return regulator_npm1300_set_buck_pin_ctrl(dev, 0, spec->pin, inv, type); in regulator_npm1300_set_pin_ctrl()
461 return regulator_npm1300_set_buck_pin_ctrl(dev, 1, spec->pin, inv, type); in regulator_npm1300_set_pin_ctrl()
463 return regulator_npm1300_set_ldsw_pin_ctrl(dev, 0, spec->pin, inv, type); in regulator_npm1300_set_pin_ctrl()
465 return regulator_npm1300_set_ldsw_pin_ctrl(dev, 1, spec->pin, inv, type); in regulator_npm1300_set_pin_ctrl()
467 return -ENODEV; in regulator_npm1300_set_pin_ctrl()
473 const struct regulator_npm1300_pconfig *pconfig = dev->config; in regulator_npm1300_dvs_state_set()
478 spec = &pconfig->dvs_state_pins[idx]; in regulator_npm1300_dvs_state_set()
480 if (spec->port != NULL) { in regulator_npm1300_dvs_state_set()
494 const struct regulator_npm1300_pconfig *pconfig = dev->config; in regulator_npm1300_ship_mode()
496 return mfd_npm1300_reg_write(pconfig->mfd, SHIP_BASE, SHIP_OFFSET_SHIP, 1U); in regulator_npm1300_ship_mode()
506 const struct regulator_npm1300_pconfig *pconfig = dev->config; in regulator_npm1300_common_init()
511 spec = &pconfig->dvs_state_pins[idx]; in regulator_npm1300_common_init()
513 if (spec->port != NULL) { in regulator_npm1300_common_init()
515 return -ENODEV; in regulator_npm1300_common_init()
531 const struct regulator_npm1300_config *config = dev->config; in get_enabled_reg()
534 int ret = mfd_npm1300_reg_read(config->mfd, base, offset, &data); in get_enabled_reg()
547 const struct regulator_npm1300_config *config = dev->config; in get_enabled()
549 switch (config->source) { in get_enabled()
559 return -ENODEV; in get_enabled()
565 const struct regulator_npm1300_config *config = dev->config; in soft_start_set()
567 switch (config->source) { in soft_start_set()
569 return mfd_npm1300_reg_update(config->mfd, LDSW_BASE, LDSW_OFFSET_CONFIG, in soft_start_set()
573 return mfd_npm1300_reg_update(config->mfd, LDSW_BASE, LDSW_OFFSET_CONFIG, in soft_start_set()
577 return -ENOTSUP; in soft_start_set()
583 const struct regulator_npm1300_config *config = dev->config; in regulator_npm1300_init()
587 if (!device_is_ready(config->mfd)) { in regulator_npm1300_init()
588 return -ENODEV; in regulator_npm1300_init()
602 if (config->retention_uv != 0) { in regulator_npm1300_init()
603 ret = retention_set_voltage(dev, config->retention_uv); in regulator_npm1300_init()
610 if (config->soft_start != UINT8_MAX) { in regulator_npm1300_init()
611 ret = soft_start_set(dev, config->soft_start); in regulator_npm1300_init()
618 ret = regulator_npm1300_set_pin_ctrl(dev, &config->enable_gpios, NPM1300_GPIO_TYPE_ENABLE); in regulator_npm1300_init()
623 ret = regulator_npm1300_set_pin_ctrl(dev, &config->retention_gpios, in regulator_npm1300_init()
629 ret = regulator_npm1300_set_pin_ctrl(dev, &config->pwm_gpios, NPM1300_GPIO_TYPE_PWM); in regulator_npm1300_init()
637 static DEVICE_API(regulator, api) = {