@ -15,27 +15,27 @@
@@ -15,27 +15,27 @@
# include <zephyr/sys/linear_range.h>
# include <zephyr/sys/util.h>
/* nPM1300 voltage sources */
enum npm1300 _sources {
NPM1300 _SOURCE_BUCK1 ,
NPM1300 _SOURCE_BUCK2 ,
NPM1300 _SOURCE_LDO1 ,
NPM1300 _SOURCE_LDO2 ,
/* nPM13xx voltage sources */
enum npm13xx _sources {
NPM13XX _SOURCE_BUCK1 ,
NPM13XX _SOURCE_BUCK2 ,
NPM13XX _SOURCE_LDO1 ,
NPM13XX _SOURCE_LDO2 ,
} ;
/* nPM1300 gpio control channels */
enum npm1300 _gpio_type {
NPM1300 _GPIO_TYPE_ENABLE ,
NPM1300 _GPIO_TYPE_RETENTION ,
NPM1300 _GPIO_TYPE_PWM
/* nPM13xx gpio control channels */
enum npm13xx _gpio_type {
NPM13XX _GPIO_TYPE_ENABLE ,
NPM13XX _GPIO_TYPE_RETENTION ,
NPM13XX _GPIO_TYPE_PWM
} ;
/* nPM1300 regulator base addresses */
/* nPM13xx regulator base addresses */
# define BUCK_BASE 0x04U
# define LDSW_BASE 0x08U
# define SHIP_BASE 0x0BU
/* nPM1300 regulator register offsets */
/* nPM13xx regulator register offsets */
# define BUCK_OFFSET_EN_SET 0x00U
# define BUCK_OFFSET_EN_CLR 0x01U
# define BUCK_OFFSET_PWM_SET 0x04U
@ -50,7 +50,7 @@ enum npm1300_gpio_type {
@@ -50,7 +50,7 @@ enum npm1300_gpio_type {
# define BUCK_OFFSET_CTRL0 0x15U
# define BUCK_OFFSET_STATUS 0x34U
/* nPM1300 ldsw register offsets */
/* nPM13xx ldsw register offsets */
# define LDSW_OFFSET_EN_SET 0x00U
# define LDSW_OFFSET_EN_CLR 0x01U
# define LDSW_OFFSET_STATUS 0x04U
@ -59,7 +59,7 @@ enum npm1300_gpio_type {
@@ -59,7 +59,7 @@ enum npm1300_gpio_type {
# define LDSW_OFFSET_LDOSEL 0x08U
# define LDSW_OFFSET_VOUTSEL 0x0CU
/* nPM1300 ship register offsets */
/* nPM13xx ship register offsets */
# define SHIP_OFFSET_SHIP 0x02U
# define BUCK1_ON_MASK 0x04U
@ -77,62 +77,62 @@ enum npm1300_gpio_type {
@@ -77,62 +77,62 @@ enum npm1300_gpio_type {
# define LDSW2_SOFTSTART_SHIFT 4U
# define LDSW2_ACTIVE_DISCHARGE_MASK BIT(7)
# define NPM1300 _GPIO_UNUSED UINT8_MAX
# define NPM13XX _GPIO_UNUSED UINT8_MAX
struct npm1300 _gpio_info {
struct npm13xx _gpio_info {
uint8_t pin ;
bool invert ;
} ;
struct regulator_npm1300 _pconfig {
struct regulator_npm13xx _pconfig {
const struct device * mfd ;
struct gpio_dt_spec dvs_state_pins [ 5 ] ;
} ;
struct regulator_npm1300 _config {
struct regulator_npm13xx _config {
struct regulator_common_config common ;
const struct device * mfd ;
uint8_t source ;
int32_t retention_uv ;
struct npm1300 _gpio_info enable_gpios ;
struct npm1300 _gpio_info retention_gpios ;
struct npm1300 _gpio_info pwm_gpios ;
struct npm13xx _gpio_info enable_gpios ;
struct npm13xx _gpio_info retention_gpios ;
struct npm13xx _gpio_info pwm_gpios ;
uint8_t soft_start ;
bool active_discharge ;
bool ldo_disable_workaround ;
} ;
struct regulator_npm1300 _data {
struct regulator_npm13xx _data {
struct regulator_common_data data ;
} ;
/* Linear range for output voltage, common for all bucks and LDOs on this device */
static const struct linear_range buckldo_range = LINEAR_RANGE_INIT ( 1000000 , 100000 , 0U , 23U ) ;
unsigned int regulator_npm1300 _count_voltages ( const struct device * dev )
unsigned int regulator_npm13xx _count_voltages ( const struct device * dev )
{
const struct regulator_npm1300 _config * config = dev - > config ;
const struct regulator_npm13xx _config * config = dev - > config ;
switch ( config - > source ) {
case NPM1300 _SOURCE_BUCK1 :
case NPM1300 _SOURCE_BUCK2 :
case NPM1300 _SOURCE_LDO1 :
case NPM1300 _SOURCE_LDO2 :
case NPM13XX _SOURCE_BUCK1 :
case NPM13XX _SOURCE_BUCK2 :
case NPM13XX _SOURCE_LDO1 :
case NPM13XX _SOURCE_LDO2 :
return linear_range_values_count ( & buckldo_range ) ;
default :
return 0 ;
}
}
int regulator_npm1300 _list_voltage ( const struct device * dev , unsigned int idx , int32_t * volt_uv )
int regulator_npm13xx _list_voltage ( const struct device * dev , unsigned int idx , int32_t * volt_uv )
{
const struct regulator_npm1300 _config * config = dev - > config ;
const struct regulator_npm13xx _config * config = dev - > config ;
switch ( config - > source ) {
case NPM1300 _SOURCE_BUCK1 :
case NPM1300 _SOURCE_BUCK2 :
case NPM1300 _SOURCE_LDO1 :
case NPM1300 _SOURCE_LDO2 :
case NPM13XX _SOURCE_BUCK1 :
case NPM13XX _SOURCE_BUCK2 :
case NPM13XX _SOURCE_LDO1 :
case NPM13XX _SOURCE_LDO2 :
return linear_range_get_value ( & buckldo_range , idx , volt_uv ) ;
default :
return - EINVAL ;
@ -141,16 +141,16 @@ int regulator_npm1300_list_voltage(const struct device *dev, unsigned int idx, i
@@ -141,16 +141,16 @@ int regulator_npm1300_list_voltage(const struct device *dev, unsigned int idx, i
static int retention_set_voltage ( const struct device * dev , int32_t retention_uv )
{
const struct regulator_npm1300 _config * config = dev - > config ;
const struct regulator_npm13xx _config * config = dev - > config ;
uint16_t idx ;
uint8_t chan ;
int ret ;
switch ( config - > source ) {
case NPM1300 _SOURCE_BUCK1 :
case NPM13XX _SOURCE_BUCK1 :
chan = 0U ;
break ;
case NPM1300 _SOURCE_BUCK2 :
case NPM13XX _SOURCE_BUCK2 :
chan = 1U ;
break ;
default :
@ -163,17 +163,17 @@ static int retention_set_voltage(const struct device *dev, int32_t retention_uv)
@@ -163,17 +163,17 @@ static int retention_set_voltage(const struct device *dev, int32_t retention_uv)
return ret ;
}
return mfd_npm1300 _reg_write ( config - > mfd , BUCK_BASE , BUCK_OFFSET_VOUT_RET + ( chan * 2U ) ,
return mfd_npm13xx _reg_write ( config - > mfd , BUCK_BASE , BUCK_OFFSET_VOUT_RET + ( chan * 2U ) ,
idx ) ;
}
static int buck_get_voltage_index ( const struct device * dev , uint8_t chan , uint8_t * idx )
{
const struct regulator_npm1300 _config * config = dev - > config ;
const struct regulator_npm13xx _config * config = dev - > config ;
uint8_t sel ;
int ret ;
ret = mfd_npm1300 _reg_read ( config - > mfd , BUCK_BASE , BUCK_OFFSET_SW_CTRL , & sel ) ;
ret = mfd_npm13xx _reg_read ( config - > mfd , BUCK_BASE , BUCK_OFFSET_SW_CTRL , & sel ) ;
if ( ret < 0 ) {
return ret ;
@ -181,17 +181,17 @@ static int buck_get_voltage_index(const struct device *dev, uint8_t chan, uint8_
@@ -181,17 +181,17 @@ static int buck_get_voltage_index(const struct device *dev, uint8_t chan, uint8_
if ( ( sel > > chan ) & 1U ) {
/* SW control */
return mfd_npm1300 _reg_read ( config - > mfd , BUCK_BASE ,
return mfd_npm13xx _reg_read ( config - > mfd , BUCK_BASE ,
BUCK_OFFSET_VOUT_NORM + ( chan * 2U ) , idx ) ;
}
/* VSET pin control */
return mfd_npm1300 _reg_read ( config - > mfd , BUCK_BASE , BUCK_OFFSET_VOUT_STAT + chan , idx ) ;
return mfd_npm13xx _reg_read ( config - > mfd , BUCK_BASE , BUCK_OFFSET_VOUT_STAT + chan , idx ) ;
}
static int buck_set_voltage ( const struct device * dev , uint8_t chan , int32_t min_uv , int32_t max_uv )
{
const struct regulator_npm1300 _config * config = dev - > config ;
const struct regulator_npm13xx _config * config = dev - > config ;
uint8_t mask ;
uint8_t curr_idx ;
uint16_t idx ;
@ -210,7 +210,7 @@ static int buck_set_voltage(const struct device *dev, uint8_t chan, int32_t min_
@@ -210,7 +210,7 @@ static int buck_set_voltage(const struct device *dev, uint8_t chan, int32_t min_
return ret ;
}
ret = mfd_npm1300 _reg_write ( config - > mfd , BUCK_BASE , BUCK_OFFSET_VOUT_NORM + ( chan * 2U ) ,
ret = mfd_npm13xx _reg_write ( config - > mfd , BUCK_BASE , BUCK_OFFSET_VOUT_NORM + ( chan * 2U ) ,
idx ) ;
if ( ret < 0 ) {
@ -219,12 +219,12 @@ static int buck_set_voltage(const struct device *dev, uint8_t chan, int32_t min_
@@ -219,12 +219,12 @@ static int buck_set_voltage(const struct device *dev, uint8_t chan, int32_t min_
/* Enable SW control of buck output */
mask = BIT ( chan ) ;
return mfd_npm1300 _reg_update ( config - > mfd , BUCK_BASE , BUCK_OFFSET_SW_CTRL , mask , mask ) ;
return mfd_npm13xx _reg_update ( config - > mfd , BUCK_BASE , BUCK_OFFSET_SW_CTRL , mask , mask ) ;
}
static int ldo_set_voltage ( const struct device * dev , uint8_t chan , int32_t min_uv , int32_t max_uv )
{
const struct regulator_npm1300 _config * config = dev - > config ;
const struct regulator_npm13xx _config * config = dev - > config ;
uint16_t idx ;
int ret ;
@ -234,21 +234,21 @@ static int ldo_set_voltage(const struct device *dev, uint8_t chan, int32_t min_u
@@ -234,21 +234,21 @@ static int ldo_set_voltage(const struct device *dev, uint8_t chan, int32_t min_u
return ret ;
}
return mfd_npm1300 _reg_write ( config - > mfd , LDSW_BASE , LDSW_OFFSET_VOUTSEL + chan , idx ) ;
return mfd_npm13xx _reg_write ( config - > mfd , LDSW_BASE , LDSW_OFFSET_VOUTSEL + chan , idx ) ;
}
int regulator_npm1300 _set_voltage ( const struct device * dev , int32_t min_uv , int32_t max_uv )
int regulator_npm13xx _set_voltage ( const struct device * dev , int32_t min_uv , int32_t max_uv )
{
const struct regulator_npm1300 _config * config = dev - > config ;
const struct regulator_npm13xx _config * config = dev - > config ;
switch ( config - > source ) {
case NPM1300 _SOURCE_BUCK1 :
case NPM13XX _SOURCE_BUCK1 :
return buck_set_voltage ( dev , 0 , min_uv , max_uv ) ;
case NPM1300 _SOURCE_BUCK2 :
case NPM13XX _SOURCE_BUCK2 :
return buck_set_voltage ( dev , 1 , min_uv , max_uv ) ;
case NPM1300 _SOURCE_LDO1 :
case NPM13XX _SOURCE_LDO1 :
return ldo_set_voltage ( dev , 0 , min_uv , max_uv ) ;
case NPM1300 _SOURCE_LDO2 :
case NPM13XX _SOURCE_LDO2 :
return ldo_set_voltage ( dev , 1 , min_uv , max_uv ) ;
default :
return - ENODEV ;
@ -271,11 +271,11 @@ static int buck_get_voltage(const struct device *dev, uint8_t chan, int32_t *vol
@@ -271,11 +271,11 @@ static int buck_get_voltage(const struct device *dev, uint8_t chan, int32_t *vol
static int ldo_get_voltage ( const struct device * dev , uint8_t chan , int32_t * volt_uv )
{
const struct regulator_npm1300 _config * config = dev - > config ;
const struct regulator_npm13xx _config * config = dev - > config ;
uint8_t idx ;
int ret ;
ret = mfd_npm1300 _reg_read ( config - > mfd , LDSW_BASE , LDSW_OFFSET_VOUTSEL + chan , & idx ) ;
ret = mfd_npm13xx _reg_read ( config - > mfd , LDSW_BASE , LDSW_OFFSET_VOUTSEL + chan , & idx ) ;
if ( ret < 0 ) {
return ret ;
@ -284,18 +284,18 @@ static int ldo_get_voltage(const struct device *dev, uint8_t chan, int32_t *volt
@@ -284,18 +284,18 @@ static int ldo_get_voltage(const struct device *dev, uint8_t chan, int32_t *volt
return linear_range_get_value ( & buckldo_range , idx , volt_uv ) ;
}
int regulator_npm1300 _get_voltage ( const struct device * dev , int32_t * volt_uv )
int regulator_npm13xx _get_voltage ( const struct device * dev , int32_t * volt_uv )
{
const struct regulator_npm1300 _config * config = dev - > config ;
const struct regulator_npm13xx _config * config = dev - > config ;
switch ( config - > source ) {
case NPM1300 _SOURCE_BUCK1 :
case NPM13XX _SOURCE_BUCK1 :
return buck_get_voltage ( dev , 0 , volt_uv ) ;
case NPM1300 _SOURCE_BUCK2 :
case NPM13XX _SOURCE_BUCK2 :
return buck_get_voltage ( dev , 1 , volt_uv ) ;
case NPM1300 _SOURCE_LDO1 :
case NPM13XX _SOURCE_LDO1 :
return ldo_get_voltage ( dev , 0 , volt_uv ) ;
case NPM1300 _SOURCE_LDO2 :
case NPM13XX _SOURCE_LDO2 :
return ldo_get_voltage ( dev , 1 , volt_uv ) ;
default :
return - ENODEV ;
@ -304,22 +304,22 @@ int regulator_npm1300_get_voltage(const struct device *dev, int32_t *volt_uv)
@@ -304,22 +304,22 @@ int regulator_npm1300_get_voltage(const struct device *dev, int32_t *volt_uv)
static int set_buck_mode ( const struct device * dev , uint8_t chan , regulator_mode_t mode )
{
const struct regulator_npm1300 _config * config = dev - > config ;
const struct regulator_npm13xx _config * config = dev - > config ;
uint8_t pfm_mask = BIT ( chan ) ;
uint8_t pfm_data ;
uint8_t pwm_reg ;
int ret ;
switch ( mode ) {
case NPM1300 _BUCK_MODE_PWM :
case NPM13XX _BUCK_MODE_PWM :
pfm_data = 0U ;
pwm_reg = BUCK_OFFSET_PWM_SET ;
break ;
case NPM1300 _BUCK_MODE_AUTO :
case NPM13XX _BUCK_MODE_AUTO :
pfm_data = 0U ;
pwm_reg = BUCK_OFFSET_PWM_CLR ;
break ;
case NPM1300 _BUCK_MODE_PFM :
case NPM13XX _BUCK_MODE_PFM :
pfm_data = pfm_mask ;
pwm_reg = BUCK_OFFSET_PWM_CLR ;
break ;
@ -327,61 +327,61 @@ static int set_buck_mode(const struct device *dev, uint8_t chan, regulator_mode_
@@ -327,61 +327,61 @@ static int set_buck_mode(const struct device *dev, uint8_t chan, regulator_mode_
return - ENOTSUP ;
}
ret = mfd_npm1300 _reg_update ( config - > mfd , BUCK_BASE , BUCK_OFFSET_CTRL0 , pfm_data , pfm_mask ) ;
ret = mfd_npm13xx _reg_update ( config - > mfd , BUCK_BASE , BUCK_OFFSET_CTRL0 , pfm_data , pfm_mask ) ;
if ( ret < 0 ) {
return ret ;
}
return mfd_npm1300 _reg_write ( config - > mfd , BUCK_BASE , pwm_reg + ( chan * 2U ) , 1U ) ;
return mfd_npm13xx _reg_write ( config - > mfd , BUCK_BASE , pwm_reg + ( chan * 2U ) , 1U ) ;
}
static int set_ldsw_mode ( const struct device * dev , uint8_t chan , regulator_mode_t mode )
{
const struct regulator_npm1300 _config * config = dev - > config ;
const struct regulator_npm13xx _config * config = dev - > config ;
switch ( mode ) {
case NPM1300 _LDSW_MODE_LDO :
return mfd_npm1300 _reg_write ( config - > mfd , LDSW_BASE , LDSW_OFFSET_LDOSEL + chan , 1U ) ;
case NPM1300 _LDSW_MODE_LDSW :
return mfd_npm1300 _reg_write ( config - > mfd , LDSW_BASE , LDSW_OFFSET_LDOSEL + chan , 0U ) ;
case NPM13XX _LDSW_MODE_LDO :
return mfd_npm13xx _reg_write ( config - > mfd , LDSW_BASE , LDSW_OFFSET_LDOSEL + chan , 1U ) ;
case NPM13XX _LDSW_MODE_LDSW :
return mfd_npm13xx _reg_write ( config - > mfd , LDSW_BASE , LDSW_OFFSET_LDOSEL + chan , 0U ) ;
default :
return - ENOTSUP ;
}
}
int regulator_npm1300 _set_mode ( const struct device * dev , regulator_mode_t mode )
int regulator_npm13xx _set_mode ( const struct device * dev , regulator_mode_t mode )
{
const struct regulator_npm1300 _config * config = dev - > config ;
const struct regulator_npm13xx _config * config = dev - > config ;
switch ( config - > source ) {
case NPM1300 _SOURCE_BUCK1 :
case NPM13XX _SOURCE_BUCK1 :
return set_buck_mode ( dev , 0 , mode ) ;
case NPM1300 _SOURCE_BUCK2 :
case NPM13XX _SOURCE_BUCK2 :
return set_buck_mode ( dev , 1 , mode ) ;
case NPM1300 _SOURCE_LDO1 :
case NPM13XX _SOURCE_LDO1 :
return set_ldsw_mode ( dev , 0 , mode ) ;
case NPM1300 _SOURCE_LDO2 :
case NPM13XX _SOURCE_LDO2 :
return set_ldsw_mode ( dev , 1 , mode ) ;
default :
return - ENOTSUP ;
}
}
int regulator_npm1300 _enable ( const struct device * dev )
int regulator_npm13xx _enable ( const struct device * dev )
{
const struct regulator_npm1300 _config * config = dev - > config ;
const struct regulator_npm13xx _config * config = dev - > config ;
int ret ;
switch ( config - > source ) {
case NPM1300 _SOURCE_BUCK1 :
return mfd_npm1300 _reg_write ( config - > mfd , BUCK_BASE , BUCK_OFFSET_EN_SET , 1U ) ;
case NPM1300 _SOURCE_BUCK2 :
return mfd_npm1300 _reg_write ( config - > mfd , BUCK_BASE , BUCK_OFFSET_EN_SET + 2U , 1U ) ;
case NPM1300 _SOURCE_LDO1 :
ret = mfd_npm1300 _reg_write ( config - > mfd , LDSW_BASE , LDSW_OFFSET_EN_SET , 1U ) ;
case NPM13XX _SOURCE_BUCK1 :
return mfd_npm13xx _reg_write ( config - > mfd , BUCK_BASE , BUCK_OFFSET_EN_SET , 1U ) ;
case NPM13XX _SOURCE_BUCK2 :
return mfd_npm13xx _reg_write ( config - > mfd , BUCK_BASE , BUCK_OFFSET_EN_SET + 2U , 1U ) ;
case NPM13XX _SOURCE_LDO1 :
ret = mfd_npm13xx _reg_write ( config - > mfd , LDSW_BASE , LDSW_OFFSET_EN_SET , 1U ) ;
break ;
case NPM1300 _SOURCE_LDO2 :
ret = mfd_npm1300 _reg_write ( config - > mfd , LDSW_BASE , LDSW_OFFSET_EN_SET + 2U , 1U ) ;
case NPM13XX _SOURCE_LDO2 :
ret = mfd_npm13xx _reg_write ( config - > mfd , LDSW_BASE , LDSW_OFFSET_EN_SET + 2U , 1U ) ;
break ;
default :
return 0 ;
@ -395,35 +395,35 @@ int regulator_npm1300_enable(const struct device *dev)
@@ -395,35 +395,35 @@ int regulator_npm1300_enable(const struct device *dev)
uint8_t unused ;
k_msleep ( 2 ) ;
return mfd_npm1300 _reg_read ( config - > mfd , LDSW_BASE , LDSW_OFFSET_STATUS , & unused ) ;
return mfd_npm13xx _reg_read ( config - > mfd , LDSW_BASE , LDSW_OFFSET_STATUS , & unused ) ;
}
return ret ;
}
int regulator_npm1300 _disable ( const struct device * dev )
int regulator_npm13xx _disable ( const struct device * dev )
{
const struct regulator_npm1300 _config * config = dev - > config ;
const struct regulator_npm13xx _config * config = dev - > config ;
switch ( config - > source ) {
case NPM1300 _SOURCE_BUCK1 :
return mfd_npm1300 _reg_write ( config - > mfd , BUCK_BASE , BUCK_OFFSET_EN_CLR , 1U ) ;
case NPM1300 _SOURCE_BUCK2 :
return mfd_npm1300 _reg_write ( config - > mfd , BUCK_BASE , BUCK_OFFSET_EN_CLR + 2U , 1U ) ;
case NPM1300 _SOURCE_LDO1 :
return mfd_npm1300 _reg_write ( config - > mfd , LDSW_BASE , LDSW_OFFSET_EN_CLR , 1U ) ;
case NPM1300 _SOURCE_LDO2 :
return mfd_npm1300 _reg_write ( config - > mfd , LDSW_BASE , LDSW_OFFSET_EN_CLR + 2U , 1U ) ;
case NPM13XX _SOURCE_BUCK1 :
return mfd_npm13xx _reg_write ( config - > mfd , BUCK_BASE , BUCK_OFFSET_EN_CLR , 1U ) ;
case NPM13XX _SOURCE_BUCK2 :
return mfd_npm13xx _reg_write ( config - > mfd , BUCK_BASE , BUCK_OFFSET_EN_CLR + 2U , 1U ) ;
case NPM13XX _SOURCE_LDO1 :
return mfd_npm13xx _reg_write ( config - > mfd , LDSW_BASE , LDSW_OFFSET_EN_CLR , 1U ) ;
case NPM13XX _SOURCE_LDO2 :
return mfd_npm13xx _reg_write ( config - > mfd , LDSW_BASE , LDSW_OFFSET_EN_CLR + 2U , 1U ) ;
default :
return 0 ;
}
}
static int regulator_npm1300 _set_buck_pin_ctrl ( const struct device * dev , uint8_t chan ,
const struct npm1300 _gpio_info * pin_info ,
enum npm1300 _gpio_type type )
static int regulator_npm13xx _set_buck_pin_ctrl ( const struct device * dev , uint8_t chan ,
const struct npm13xx _gpio_info * pin_info ,
enum npm13xx _gpio_type type )
{
const struct regulator_npm1300 _config * config = dev - > config ;
const struct regulator_npm13xx _config * config = dev - > config ;
uint8_t inv = pin_info - > invert ? 1 : 0 ;
uint8_t ctrl ;
uint8_t mask ;
@ -444,63 +444,63 @@ static int regulator_npm1300_set_buck_pin_ctrl(const struct device *dev, uint8_t
@@ -444,63 +444,63 @@ static int regulator_npm1300_set_buck_pin_ctrl(const struct device *dev, uint8_t
}
switch ( type ) {
case NPM1300 _GPIO_TYPE_ENABLE :
return mfd_npm1300 _reg_update ( config - > mfd , BUCK_BASE , BUCK_OFFSET_EN_CTRL , ctrl ,
case NPM13XX _GPIO_TYPE_ENABLE :
return mfd_npm13xx _reg_update ( config - > mfd , BUCK_BASE , BUCK_OFFSET_EN_CTRL , ctrl ,
mask ) ;
case NPM1300 _GPIO_TYPE_PWM :
return mfd_npm1300 _reg_update ( config - > mfd , BUCK_BASE , BUCK_OFFSET_PWM_CTRL , ctrl ,
case NPM13XX _GPIO_TYPE_PWM :
return mfd_npm13xx _reg_update ( config - > mfd , BUCK_BASE , BUCK_OFFSET_PWM_CTRL , ctrl ,
mask ) ;
case NPM1300 _GPIO_TYPE_RETENTION :
return mfd_npm1300 _reg_update ( config - > mfd , BUCK_BASE , BUCK_OFFSET_VRET_CTRL , ctrl ,
case NPM13XX _GPIO_TYPE_RETENTION :
return mfd_npm13xx _reg_update ( config - > mfd , BUCK_BASE , BUCK_OFFSET_VRET_CTRL , ctrl ,
mask ) ;
default :
return - ENOTSUP ;
}
}
static int regulator_npm1300 _set_ldsw_pin_ctrl ( const struct device * dev , uint8_t chan ,
const struct npm1300 _gpio_info * pin_info ,
enum npm1300 _gpio_type type )
static int regulator_npm13xx _set_ldsw_pin_ctrl ( const struct device * dev , uint8_t chan ,
const struct npm13xx _gpio_info * pin_info ,
enum npm13xx _gpio_type type )
{
const struct regulator_npm1300 _config * config = dev - > config ;
const struct regulator_npm13xx _config * config = dev - > config ;
uint8_t inv = pin_info - > invert ? 1 : 0 ;
uint8_t ctrl ;
if ( type ! = NPM1300 _GPIO_TYPE_ENABLE ) {
if ( type ! = NPM13XX _GPIO_TYPE_ENABLE ) {
return - ENOTSUP ;
}
ctrl = ( pin_info - > pin + 1U ) | ( inv < < 3U ) ;
return mfd_npm1300 _reg_write ( config - > mfd , LDSW_BASE , LDSW_OFFSET_GPISEL + chan , ctrl ) ;
return mfd_npm13xx _reg_write ( config - > mfd , LDSW_BASE , LDSW_OFFSET_GPISEL + chan , ctrl ) ;
}
int regulator_npm1300 _set_pin_ctrl ( const struct device * dev , const struct npm1300 _gpio_info * info ,
enum npm1300 _gpio_type type )
int regulator_npm13xx _set_pin_ctrl ( const struct device * dev , const struct npm13xx _gpio_info * info ,
enum npm13xx _gpio_type type )
{
const struct regulator_npm1300 _config * config = dev - > config ;
const struct regulator_npm13xx _config * config = dev - > config ;
if ( info - > pin = = NPM1300 _GPIO_UNUSED ) {
if ( info - > pin = = NPM13XX _GPIO_UNUSED ) {
return 0 ;
}
switch ( config - > source ) {
case NPM1300 _SOURCE_BUCK1 :
return regulator_npm1300 _set_buck_pin_ctrl ( dev , 0 , info , type ) ;
case NPM1300 _SOURCE_BUCK2 :
return regulator_npm1300 _set_buck_pin_ctrl ( dev , 1 , info , type ) ;
case NPM1300 _SOURCE_LDO1 :
return regulator_npm1300 _set_ldsw_pin_ctrl ( dev , 0 , info , type ) ;
case NPM1300 _SOURCE_LDO2 :
return regulator_npm1300 _set_ldsw_pin_ctrl ( dev , 1 , info , type ) ;
case NPM13XX _SOURCE_BUCK1 :
return regulator_npm13xx _set_buck_pin_ctrl ( dev , 0 , info , type ) ;
case NPM13XX _SOURCE_BUCK2 :
return regulator_npm13xx _set_buck_pin_ctrl ( dev , 1 , info , type ) ;
case NPM13XX _SOURCE_LDO1 :
return regulator_npm13xx _set_ldsw_pin_ctrl ( dev , 0 , info , type ) ;
case NPM13XX _SOURCE_LDO2 :
return regulator_npm13xx _set_ldsw_pin_ctrl ( dev , 1 , info , type ) ;
default :
return - ENODEV ;
}
}
int regulator_npm1300 _dvs_state_set ( const struct device * dev , regulator_dvs_state_t state )
int regulator_npm13xx _dvs_state_set ( const struct device * dev , regulator_dvs_state_t state )
{
const struct regulator_npm1300 _pconfig * pconfig = dev - > config ;
const struct regulator_npm13xx _pconfig * pconfig = dev - > config ;
const struct gpio_dt_spec * spec ;
int ret ;
@ -519,21 +519,21 @@ int regulator_npm1300_dvs_state_set(const struct device *dev, regulator_dvs_stat
@@ -519,21 +519,21 @@ int regulator_npm1300_dvs_state_set(const struct device *dev, regulator_dvs_stat
return 0 ;
}
int regulator_npm1300 _ship_mode ( const struct device * dev )
int regulator_npm13xx _ship_mode ( const struct device * dev )
{
const struct regulator_npm1300 _pconfig * pconfig = dev - > config ;
const struct regulator_npm13xx _pconfig * pconfig = dev - > config ;
return mfd_npm1300 _reg_write ( pconfig - > mfd , SHIP_BASE , SHIP_OFFSET_SHIP , 1U ) ;
return mfd_npm13xx _reg_write ( pconfig - > mfd , SHIP_BASE , SHIP_OFFSET_SHIP , 1U ) ;
}
static DEVICE_API ( regulator_parent , parent_api ) = {
. dvs_state_set = regulator_npm1300 _dvs_state_set ,
. ship_mode = regulator_npm1300 _ship_mode ,
. dvs_state_set = regulator_npm13xx _dvs_state_set ,
. ship_mode = regulator_npm13xx _ship_mode ,
} ;
int regulator_npm1300 _common_init ( const struct device * dev )
int regulator_npm13xx _common_init ( const struct device * dev )
{
const struct regulator_npm1300 _pconfig * pconfig = dev - > config ;
const struct regulator_npm13xx _pconfig * pconfig = dev - > config ;
const struct gpio_dt_spec * spec ;
int ret ;
@ -558,10 +558,10 @@ int regulator_npm1300_common_init(const struct device *dev)
@@ -558,10 +558,10 @@ int regulator_npm1300_common_init(const struct device *dev)
static int get_enabled_reg ( const struct device * dev , uint8_t base , uint8_t offset , uint8_t mask ,
bool * enabled )
{
const struct regulator_npm1300 _config * config = dev - > config ;
const struct regulator_npm13xx _config * config = dev - > config ;
uint8_t data ;
int ret = mfd_npm1300 _reg_read ( config - > mfd , base , offset , & data ) ;
int ret = mfd_npm13xx _reg_read ( config - > mfd , base , offset , & data ) ;
if ( ret < 0 ) {
return ret ;
@ -574,16 +574,16 @@ static int get_enabled_reg(const struct device *dev, uint8_t base, uint8_t offse
@@ -574,16 +574,16 @@ static int get_enabled_reg(const struct device *dev, uint8_t base, uint8_t offse
static int get_enabled ( const struct device * dev , bool * enabled )
{
const struct regulator_npm1300 _config * config = dev - > config ;
const struct regulator_npm13xx _config * config = dev - > config ;
switch ( config - > source ) {
case NPM1300 _SOURCE_BUCK1 :
case NPM13XX _SOURCE_BUCK1 :
return get_enabled_reg ( dev , BUCK_BASE , BUCK_OFFSET_STATUS , BUCK1_ON_MASK , enabled ) ;
case NPM1300 _SOURCE_BUCK2 :
case NPM13XX _SOURCE_BUCK2 :
return get_enabled_reg ( dev , BUCK_BASE , BUCK_OFFSET_STATUS , BUCK2_ON_MASK , enabled ) ;
case NPM1300 _SOURCE_LDO1 :
case NPM13XX _SOURCE_LDO1 :
return get_enabled_reg ( dev , LDSW_BASE , LDSW_OFFSET_STATUS , LDSW1_ON_MASK , enabled ) ;
case NPM1300 _SOURCE_LDO2 :
case NPM13XX _SOURCE_LDO2 :
return get_enabled_reg ( dev , LDSW_BASE , LDSW_OFFSET_STATUS , LDSW2_ON_MASK , enabled ) ;
default :
return - ENODEV ;
@ -592,15 +592,15 @@ static int get_enabled(const struct device *dev, bool *enabled)
@@ -592,15 +592,15 @@ static int get_enabled(const struct device *dev, bool *enabled)
static int soft_start_set ( const struct device * dev , uint8_t soft_start )
{
const struct regulator_npm1300 _config * config = dev - > config ;
const struct regulator_npm13xx _config * config = dev - > config ;
switch ( config - > source ) {
case NPM1300 _SOURCE_LDO1 :
return mfd_npm1300 _reg_update ( config - > mfd , LDSW_BASE , LDSW_OFFSET_CONFIG ,
case NPM13XX _SOURCE_LDO1 :
return mfd_npm13xx _reg_update ( config - > mfd , LDSW_BASE , LDSW_OFFSET_CONFIG ,
soft_start < < LDSW1_SOFTSTART_SHIFT ,
LDSW1_SOFTSTART_MASK ) ;
case NPM1300 _SOURCE_LDO2 :
return mfd_npm1300 _reg_update ( config - > mfd , LDSW_BASE , LDSW_OFFSET_CONFIG ,
case NPM13XX _SOURCE_LDO2 :
return mfd_npm13xx _reg_update ( config - > mfd , LDSW_BASE , LDSW_OFFSET_CONFIG ,
soft_start < < LDSW2_SOFTSTART_SHIFT ,
LDSW2_SOFTSTART_MASK ) ;
default :
@ -610,23 +610,23 @@ static int soft_start_set(const struct device *dev, uint8_t soft_start)
@@ -610,23 +610,23 @@ static int soft_start_set(const struct device *dev, uint8_t soft_start)
static int active_discharge_set ( const struct device * dev , bool enabled )
{
const struct regulator_npm1300 _config * config = dev - > config ;
const struct regulator_npm13xx _config * config = dev - > config ;
switch ( config - > source ) {
case NPM1300 _SOURCE_BUCK1 :
return mfd_npm1300 _reg_update ( config - > mfd , BUCK_BASE , BUCK_OFFSET_CTRL0 ,
case NPM13XX _SOURCE_BUCK1 :
return mfd_npm13xx _reg_update ( config - > mfd , BUCK_BASE , BUCK_OFFSET_CTRL0 ,
enabled ? BUCK1_EN_PULLDOWN_MASK : 0 ,
BUCK1_EN_PULLDOWN_MASK ) ;
case NPM1300 _SOURCE_BUCK2 :
return mfd_npm1300 _reg_update ( config - > mfd , BUCK_BASE , BUCK_OFFSET_CTRL0 ,
case NPM13XX _SOURCE_BUCK2 :
return mfd_npm13xx _reg_update ( config - > mfd , BUCK_BASE , BUCK_OFFSET_CTRL0 ,
enabled ? BUCK2_EN_PULLDOWN_MASK : 0 ,
BUCK2_EN_PULLDOWN_MASK ) ;
case NPM1300 _SOURCE_LDO1 :
return mfd_npm1300 _reg_update ( config - > mfd , LDSW_BASE , LDSW_OFFSET_CONFIG ,
case NPM13XX _SOURCE_LDO1 :
return mfd_npm13xx _reg_update ( config - > mfd , LDSW_BASE , LDSW_OFFSET_CONFIG ,
enabled ? LDSW1_ACTIVE_DISCHARGE_MASK : 0 ,
LDSW1_ACTIVE_DISCHARGE_MASK ) ;
case NPM1300 _SOURCE_LDO2 :
return mfd_npm1300 _reg_update ( config - > mfd , LDSW_BASE , LDSW_OFFSET_CONFIG ,
case NPM13XX _SOURCE_LDO2 :
return mfd_npm13xx _reg_update ( config - > mfd , LDSW_BASE , LDSW_OFFSET_CONFIG ,
enabled ? LDSW2_ACTIVE_DISCHARGE_MASK : 0 ,
LDSW2_ACTIVE_DISCHARGE_MASK ) ;
default :
@ -634,9 +634,9 @@ static int active_discharge_set(const struct device *dev, bool enabled)
@@ -634,9 +634,9 @@ static int active_discharge_set(const struct device *dev, bool enabled)
}
}
int regulator_npm1300 _init ( const struct device * dev )
int regulator_npm13xx _init ( const struct device * dev )
{
const struct regulator_npm1300 _config * config = dev - > config ;
const struct regulator_npm13xx _config * config = dev - > config ;
bool enabled ;
int ret = 0 ;
@ -677,18 +677,18 @@ int regulator_npm1300_init(const struct device *dev)
@@ -677,18 +677,18 @@ int regulator_npm1300_init(const struct device *dev)
}
/* Configure GPIO pin control */
ret = regulator_npm1300 _set_pin_ctrl ( dev , & config - > enable_gpios , NPM1300 _GPIO_TYPE_ENABLE ) ;
ret = regulator_npm13xx _set_pin_ctrl ( dev , & config - > enable_gpios , NPM13XX _GPIO_TYPE_ENABLE ) ;
if ( ret ! = 0 ) {
return ret ;
}
ret = regulator_npm1300 _set_pin_ctrl ( dev , & config - > retention_gpios ,
NPM1300 _GPIO_TYPE_RETENTION ) ;
ret = regulator_npm13xx _set_pin_ctrl ( dev , & config - > retention_gpios ,
NPM13XX _GPIO_TYPE_RETENTION ) ;
if ( ret ! = 0 ) {
return ret ;
}
ret = regulator_npm1300 _set_pin_ctrl ( dev , & config - > pwm_gpios , NPM1300 _GPIO_TYPE_PWM ) ;
ret = regulator_npm13xx _set_pin_ctrl ( dev , & config - > pwm_gpios , NPM13XX _GPIO_TYPE_PWM ) ;
if ( ret ! = 0 ) {
return ret ;
}
@ -697,28 +697,28 @@ int regulator_npm1300_init(const struct device *dev)
@@ -697,28 +697,28 @@ int regulator_npm1300_init(const struct device *dev)
}
static DEVICE_API ( regulator , api ) = {
. enable = regulator_npm1300 _enable ,
. disable = regulator_npm1300 _disable ,
. count_voltages = regulator_npm1300 _count_voltages ,
. list_voltage = regulator_npm1300 _list_voltage ,
. set_voltage = regulator_npm1300 _set_voltage ,
. get_voltage = regulator_npm1300 _get_voltage ,
. set_mode = regulator_npm1300 _set_mode ,
. enable = regulator_npm13xx _enable ,
. disable = regulator_npm13xx _disable ,
. count_voltages = regulator_npm13xx _count_voltages ,
. list_voltage = regulator_npm13xx _list_voltage ,
. set_voltage = regulator_npm13xx _set_voltage ,
. get_voltage = regulator_npm13xx _get_voltage ,
. set_mode = regulator_npm13xx _set_mode ,
} ;
# define GPIO_CONFIG_DEFINE(node_id, prop) \
COND_CODE_1 ( DT_NODE_HAS_PROP ( node_id , prop ) , \
( { DT_PROP_BY_IDX ( node_id , prop , 0 ) , \
! ! ( DT_PROP_BY_IDX ( node_id , prop , 1 ) & GPIO_ACTIVE_LOW ) } ) , \
( { NPM1300 _GPIO_UNUSED , false } ) )
( { NPM13XX _GPIO_UNUSED , false } ) )
# define REGULATOR_NPM1300 _DEFINE(node_id, id, _source) \
# define REGULATOR_NPM13XX _DEFINE(node_id, id, _source) \
BUILD_ASSERT ( DT_PROP_LEN_OR ( node_id , enable_gpio_config , 2 ) = = 2 ) ; \
BUILD_ASSERT ( DT_PROP_LEN_OR ( node_id , retention_gpio_config , 2 ) = = 2 ) ; \
BUILD_ASSERT ( DT_PROP_LEN_OR ( node_id , pwm_gpio_config , 2 ) = = 2 ) ; \
static struct regulator_npm1300 _data data_ # # id ; \
static struct regulator_npm13xx _data data_ # # id ; \
\
static const struct regulator_npm1300 _config config_ # # id = { \
static const struct regulator_npm13xx _config config_ # # id = { \
. common = REGULATOR_DT_COMMON_CONFIG_INIT ( node_id ) , \
. mfd = DEVICE_DT_GET ( DT_GPARENT ( node_id ) ) , \
. source = _source , \
@ -730,16 +730,16 @@ static DEVICE_API(regulator, api) = {
@@ -730,16 +730,16 @@ static DEVICE_API(regulator, api) = {
. active_discharge = DT_PROP ( node_id , active_discharge ) , \
. ldo_disable_workaround = DT_PROP ( node_id , nordic_anomaly38_disable_workaround ) } ; \
\
DEVICE_DT_DEFINE ( node_id , regulator_npm1300 _init , NULL , & data_ # # id , & config_ # # id , \
POST_KERNEL , CONFIG_REGULATOR_NPM1300 _INIT_PRIORITY , & api ) ;
DEVICE_DT_DEFINE ( node_id , regulator_npm13xx _init , NULL , & data_ # # id , & config_ # # id , \
POST_KERNEL , CONFIG_REGULATOR_NPM13XX _INIT_PRIORITY , & api ) ;
# define REGULATOR_NPM1300 _DEFINE_COND(inst, child, source) \
# define REGULATOR_NPM13XX _DEFINE_COND(inst, child, source) \
COND_CODE_1 ( DT_NODE_EXISTS ( DT_INST_CHILD ( inst , child ) ) , \
( REGULATOR_NPM1300 _DEFINE ( DT_INST_CHILD ( inst , child ) , child # # inst , source ) ) , \
( REGULATOR_NPM13XX _DEFINE ( DT_INST_CHILD ( inst , child ) , child # # inst , source ) ) , \
( ) )
# define REGULATOR_NPM1300 _DEFINE_ALL(inst) \
static const struct regulator_npm1300 _pconfig config_ # # inst = { \
# define REGULATOR_NPM13XX _DEFINE_ALL(inst) \
static const struct regulator_npm13xx _pconfig config_ # # inst = { \
. mfd = DEVICE_DT_GET ( DT_INST_PARENT ( inst ) ) , \
. dvs_state_pins = { GPIO_DT_SPEC_INST_GET_BY_IDX_OR ( inst , dvs_gpios , 0 , { 0 } ) , \
GPIO_DT_SPEC_INST_GET_BY_IDX_OR ( inst , dvs_gpios , 1 , { 0 } ) , \
@ -747,13 +747,13 @@ static DEVICE_API(regulator, api) = {
@@ -747,13 +747,13 @@ static DEVICE_API(regulator, api) = {
GPIO_DT_SPEC_INST_GET_BY_IDX_OR ( inst , dvs_gpios , 3 , { 0 } ) , \
GPIO_DT_SPEC_INST_GET_BY_IDX_OR ( inst , dvs_gpios , 4 , { 0 } ) } } ; \
\
DEVICE_DT_INST_DEFINE ( inst , regulator_npm1300 _common_init , NULL , NULL , & config_ # # inst , \
POST_KERNEL , CONFIG_REGULATOR_NPM1300 _COMMON_INIT_PRIORITY , \
DEVICE_DT_INST_DEFINE ( inst , regulator_npm13xx _common_init , NULL , NULL , & config_ # # inst , \
POST_KERNEL , CONFIG_REGULATOR_NPM13XX _COMMON_INIT_PRIORITY , \
& parent_api ) ; \
\
REGULATOR_NPM1300 _DEFINE_COND ( inst , buck1 , NPM1300 _SOURCE_BUCK1 ) \
REGULATOR_NPM1300 _DEFINE_COND ( inst , buck2 , NPM1300 _SOURCE_BUCK2 ) \
REGULATOR_NPM1300 _DEFINE_COND ( inst , ldo1 , NPM1300 _SOURCE_LDO1 ) \
REGULATOR_NPM1300 _DEFINE_COND ( inst , ldo2 , NPM1300 _SOURCE_LDO2 )
REGULATOR_NPM13XX _DEFINE_COND ( inst , buck1 , NPM13XX _SOURCE_BUCK1 ) \
REGULATOR_NPM13XX _DEFINE_COND ( inst , buck2 , NPM13XX _SOURCE_BUCK2 ) \
REGULATOR_NPM13XX _DEFINE_COND ( inst , ldo1 , NPM13XX _SOURCE_LDO1 ) \
REGULATOR_NPM13XX _DEFINE_COND ( inst , ldo2 , NPM13XX _SOURCE_LDO2 )
DT_INST_FOREACH_STATUS_OKAY ( REGULATOR_NPM1300 _DEFINE_ALL )
DT_INST_FOREACH_STATUS_OKAY ( REGULATOR_NPM13XX _DEFINE_ALL )