Skip to content

Commit fcf787c

Browse files
committed
drivers: regulator: add support for AXP2101 power management IC
Add initial support for the AXP2101 power management IC from X-powers. Remark: only DC/DC1 and ALDO have been tested on real hardware. Co-authored-by: TOKITA Hiroshi <[email protected]> Signed-off-by: Lothar Felten <[email protected]>
1 parent 1d8ef88 commit fcf787c

File tree

11 files changed

+544
-106
lines changed

11 files changed

+544
-106
lines changed

boards/m5stack/m5stack_core2/Kconfig.defconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ config GPIO_HOGS_INIT_PRIORITY
1414
config MFD_INIT_PRIORITY
1515
default 70
1616

17-
config REGULATOR_AXP192_INIT_PRIORITY
17+
config REGULATOR_AXP192_AXP2101_INIT_PRIORITY
1818
default 71
1919

2020
config GPIO_AXP192_INIT_PRIORITY

boards/m5stack/m5stickc_plus/Kconfig.defconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ config GPIO_HOGS_INIT_PRIORITY
1111
config MFD_INIT_PRIORITY
1212
default 70
1313

14-
config REGULATOR_AXP192_INIT_PRIORITY
14+
config REGULATOR_AXP192_AXP2101_INIT_PRIORITY
1515
default 71
1616

1717
config GPIO_AXP192_INIT_PRIORITY

drivers/mfd/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ zephyr_library_sources_ifdef(CONFIG_MFD_NCT38XX mfd_nct38xx.c)
99
zephyr_library_sources_ifdef(CONFIG_MFD_NPM1300 mfd_npm1300.c)
1010
zephyr_library_sources_ifdef(CONFIG_MFD_NPM2100 mfd_npm2100.c)
1111
zephyr_library_sources_ifdef(CONFIG_MFD_NPM6001 mfd_npm6001.c)
12-
zephyr_library_sources_ifdef(CONFIG_MFD_AXP192 mfd_axp192.c)
12+
zephyr_library_sources_ifdef(CONFIG_MFD_AXP192_AXP2101 mfd_axp192.c)
1313
zephyr_library_sources_ifdef(CONFIG_MFD_AD559X mfd_ad559x.c)
1414
zephyr_library_sources_ifdef(CONFIG_MFD_AD559X_BUS_I2C mfd_ad559x_i2c.c)
1515
zephyr_library_sources_ifdef(CONFIG_MFD_AD559X_BUS_SPI mfd_ad559x_spi.c)

drivers/mfd/Kconfig.axp192

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Copyright (c) 2023 Martin Kiepfer <[email protected]>
22
# SPDX-License-Identifier: Apache-2.0
33

4-
config MFD_AXP192
5-
bool "AXP192 PMIC multi-function device driver"
4+
config MFD_AXP192_AXP2101
5+
bool "AXP192/AXP2101 PMIC multi-function device driver"
66
default y
7-
depends on DT_HAS_X_POWERS_AXP192_ENABLED
7+
depends on DT_HAS_X_POWERS_AXP192_ENABLED || DT_HAS_X_POWERS_AXP2101_ENABLED
88
select I2C
99
help
10-
Enable the X-Powers AXP192 PMIC multi-function device driver
10+
Enable the X-Powers AXP192/AXP2101 PMIC multi-function device driver

drivers/mfd/mfd_axp192.c

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
#define DT_DRV_COMPAT x_powers_axp192
7-
86
#include <errno.h>
97
#include <stdbool.h>
108

@@ -15,11 +13,26 @@
1513

1614
LOG_MODULE_REGISTER(mfd_axp192, CONFIG_MFD_LOG_LEVEL);
1715

16+
struct mfd_axp192_config {
17+
struct i2c_dt_spec i2c;
18+
#ifdef CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED
19+
bool vbusen_disable;
20+
#endif
21+
uint8_t reg_chip_id;
22+
uint8_t vbus_config_reg;
23+
uint8_t chip_id;
24+
uint8_t val_vbusen_disable;
25+
};
26+
27+
#ifdef CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED
28+
1829
/* Chip ID value */
1930
#define AXP192_CHIP_ID 0x03U
31+
#define AXP2101_CHIP_ID 0x4A
2032

2133
/* Registers definitions */
2234
#define AXP192_REG_CHIP_ID 0x03U
35+
#define AXP2101_REG_CHIP_ID 0x03U
2336

2437
/* AXP192 GPIO register addresses */
2538
#define AXP192_EXTEN_DCDC2_CONTROL_REG 0x10U
@@ -31,9 +44,11 @@ LOG_MODULE_REGISTER(mfd_axp192, CONFIG_MFD_LOG_LEVEL);
3144
#define AXP192_GPIO012_PINVAL_REG 0x94U
3245
#define AXP192_GPIO34_PINVAL_REG 0x96U
3346
#define AXP192_GPIO012_PULLDOWN_REG 0x97U
47+
#define AXP2101_VBUS_CFG_REG 0x00U
3448

3549
/* VBUS control reg values */
3650
#define AXP192_VBUS_CFG_VAL_VBUSEN_DISABLE 0x80U
51+
#define AXP2101_VBUS_CFG_VAL_VBUSEN_DISABLE 0x00U
3752

3853
/* GPIO function control parameters */
3954
#define AXP192_GPIO012_FUNC_VAL_OUTPUT_OD 0x00U
@@ -97,11 +112,6 @@ LOG_MODULE_REGISTER(mfd_axp192, CONFIG_MFD_LOG_LEVEL);
97112
#define AXP192_GPIO5_OUTPUT_VAL 0x04U
98113
#define AXP192_GPIO5_OUTPUT_SHIFT 3U
99114

100-
struct mfd_axp192_config {
101-
struct i2c_dt_spec i2c;
102-
bool vbusen_disable;
103-
};
104-
105115
struct mfd_axp192_data {
106116
const struct device *gpio_mask_used[AXP192_GPIO_MAX_NUM];
107117
uint8_t gpio_mask_output;
@@ -139,12 +149,12 @@ const struct mfd_axp192_func_reg_desc gpio_reg_desc[AXP192_GPIO_MAX_NUM] = {
139149
.mask = AXP192_GPIO4_FUNC_MASK,
140150
},
141151
};
152+
#endif /* CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED */
142153

143154
static int mfd_axp192_init(const struct device *dev)
144155
{
145156
const struct mfd_axp192_config *config = dev->config;
146157
uint8_t chip_id;
147-
uint8_t vbus_val;
148158
int ret;
149159

150160
LOG_DBG("Initializing instance");
@@ -155,29 +165,29 @@ static int mfd_axp192_init(const struct device *dev)
155165
}
156166

157167
/* Check if axp192 chip is available */
158-
ret = i2c_reg_read_byte_dt(&config->i2c, AXP192_REG_CHIP_ID, &chip_id);
168+
ret = i2c_reg_read_byte_dt(&config->i2c, config->reg_chip_id, &chip_id);
159169
if (ret < 0) {
160170
return ret;
161171
}
162-
if (chip_id != AXP192_CHIP_ID) {
172+
if (chip_id != config->chip_id) {
163173
LOG_ERR("Invalid Chip detected (%d)", chip_id);
164174
return -EINVAL;
165175
}
166176

177+
#ifdef CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED
167178
/* Disable N_VBUSEN */
168-
vbus_val = 0;
169-
if (config->vbusen_disable) {
170-
vbus_val = AXP192_VBUS_CFG_VAL_VBUSEN_DISABLE;
171-
}
172-
ret = i2c_reg_update_byte_dt(&config->i2c, AXP192_VBUS_CFG_REG,
173-
AXP192_VBUS_CFG_VAL_VBUSEN_DISABLE, vbus_val);
179+
ret = i2c_reg_update_byte_dt(
180+
&config->i2c, config->vbus_config_reg, config->val_vbusen_disable,
181+
config->vbusen_disable ? config->val_vbusen_disable : 0);
174182
if (ret < 0) {
175183
return ret;
176184
}
185+
#endif
177186

178187
return 0;
179188
}
180189

190+
#ifdef CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED
181191
int mfd_axp192_gpio_func_get(const struct device *dev, uint8_t gpio, enum axp192_gpio_func *func)
182192
{
183193
const struct mfd_axp192_config *config = dev->config;
@@ -605,16 +615,29 @@ int mfd_axp192_gpio_write_port(const struct device *dev, uint8_t value, uint8_t
605615

606616
return 0;
607617
}
608-
609-
#define MFD_AXP192_DEFINE(inst) \
610-
static const struct mfd_axp192_config config##inst = { \
611-
.i2c = I2C_DT_SPEC_INST_GET(inst), \
612-
.vbusen_disable = DT_INST_PROP_OR(inst, vbusen_disable, false), \
618+
#endif
619+
620+
#define MFD_AXP192_CONST_CONFIG(model) \
621+
.reg_chip_id = AXP##model##_REG_CHIP_ID, \
622+
.vbus_config_reg = AXP##model##_VBUS_CFG_REG, \
623+
.chip_id = AXP##model##_CHIP_ID, \
624+
.val_vbusen_disable = AXP##model##_CHIP_ID,
625+
626+
#define MFD_AXP192_DEFINE(node, model) \
627+
static const struct mfd_axp192_config config##node = { \
628+
.i2c = I2C_DT_SPEC_GET(node), \
629+
IF_ENABLED(CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED, \
630+
(.vbusen_disable = DT_PROP_OR(node, vbusen_disable, false),)) \
631+
MFD_AXP192_CONST_CONFIG(model) \
613632
}; \
614633
\
615-
static struct mfd_axp192_data data##inst; \
634+
IF_ENABLED(CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED, \
635+
(static struct mfd_axp192_data data##node;)) \
616636
\
617-
DEVICE_DT_INST_DEFINE(inst, mfd_axp192_init, NULL, &data##inst, &config##inst, \
618-
POST_KERNEL, CONFIG_MFD_INIT_PRIORITY, NULL);
637+
DEVICE_DT_DEFINE(node, mfd_axp192_init, NULL, \
638+
COND_CODE_1(CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED, \
639+
(&data##node), (NULL)), \
640+
&config##node, POST_KERNEL, CONFIG_MFD_INIT_PRIORITY, NULL);
619641

620-
DT_INST_FOREACH_STATUS_OKAY(MFD_AXP192_DEFINE);
642+
DT_FOREACH_STATUS_OKAY_VARGS(x_powers_axp192, MFD_AXP192_DEFINE, 192);
643+
DT_FOREACH_STATUS_OKAY_VARGS(x_powers_axp2101, MFD_AXP192_DEFINE, 2101);

drivers/regulator/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
zephyr_library()
55

66
zephyr_library_sources(regulator_common.c)
7-
zephyr_library_sources_ifdef(CONFIG_REGULATOR_AXP192 regulator_axp192.c)
7+
zephyr_library_sources_ifdef(CONFIG_REGULATOR_AXP192_AXP2101 regulator_axp192.c)
88
zephyr_library_sources_ifdef(CONFIG_REGULATOR_ADP5360 regulator_adp5360.c)
99
zephyr_library_sources_ifdef(CONFIG_REGULATOR_CP9314 regulator_cp9314.c)
1010
zephyr_library_sources_ifdef(CONFIG_REGULATOR_DA1469X regulator_da1469x.c)

drivers/regulator/Kconfig.axp192

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
# Copyright (c) 2023 Martin Kiepfer
22
# SPDX-License-Identifier: Apache-2.0
33

4-
config REGULATOR_AXP192
5-
bool "X-Power AXP192 PMIC regulator driver"
4+
config REGULATOR_AXP192_AXP2101
5+
bool "X-Powers AXP192/AXP2101 PMIC regulator driver"
66
default y
7-
depends on DT_HAS_X_POWERS_AXP192_REGULATOR_ENABLED
8-
depends on DT_HAS_X_POWERS_AXP192_ENABLED
7+
depends on DT_HAS_X_POWERS_AXP192_REGULATOR_ENABLED || DT_HAS_X_POWERS_AXP2101_REGULATOR_ENABLED
8+
depends on DT_HAS_X_POWERS_AXP192_ENABLED || DT_HAS_X_POWERS_AXP2101_ENABLED
99
select I2C
1010
select MFD
1111
help
1212
Enable the AXP PMIC regulator driver
1313

14-
if REGULATOR_AXP192
14+
if REGULATOR_AXP192_AXP2101
1515

16-
config REGULATOR_AXP192_INIT_PRIORITY
17-
int "AXP192 regulator driver init priority"
16+
config REGULATOR_AXP192_AXP2101_INIT_PRIORITY
17+
int "AXP192/AXP2101 regulator driver init priority"
1818
default 86
1919
help
20-
Init priority for the axp192 regulator driver. It must be
20+
Init priority for the axp192/axp2101 regulator driver. It must be
2121
greater than MFD_INIT_PRIORITY.
2222

2323
endif

0 commit comments

Comments
 (0)