Skip to content

Commit 1c50c3a

Browse files
lfeltencarlescufi
authored andcommitted
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]> Co-authored-by: Gerard Marull-Paretas <[email protected]> Signed-off-by: Lothar Felten <[email protected]>
1 parent 648b583 commit 1c50c3a

File tree

11 files changed

+553
-104
lines changed

11 files changed

+553
-104
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: 59 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,6 +13,19 @@
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
2031

@@ -97,11 +108,6 @@ LOG_MODULE_REGISTER(mfd_axp192, CONFIG_MFD_LOG_LEVEL);
97108
#define AXP192_GPIO5_OUTPUT_VAL 0x04U
98109
#define AXP192_GPIO5_OUTPUT_SHIFT 3U
99110

100-
struct mfd_axp192_config {
101-
struct i2c_dt_spec i2c;
102-
bool vbusen_disable;
103-
};
104-
105111
struct mfd_axp192_data {
106112
const struct device *gpio_mask_used[AXP192_GPIO_MAX_NUM];
107113
uint8_t gpio_mask_output;
@@ -139,12 +145,27 @@ const struct mfd_axp192_func_reg_desc gpio_reg_desc[AXP192_GPIO_MAX_NUM] = {
139145
.mask = AXP192_GPIO4_FUNC_MASK,
140146
},
141147
};
148+
#endif /* CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED */
149+
150+
#ifdef CONFIG_DT_HAS_X_POWERS_AXP2101_ENABLED
151+
152+
/* Chip ID value */
153+
#define AXP2101_CHIP_ID 0x4AU
154+
155+
/* Registers definitions */
156+
#define AXP2101_REG_CHIP_ID 0x03U
157+
158+
/* AXP210 GPIO register addresses */
159+
#define AXP2101_VBUS_CFG_REG 0x00U
160+
161+
/* VBUS control reg values */
162+
#define AXP2101_VBUS_CFG_VAL_VBUSEN_DISABLE 0x00U
163+
#endif /* CONFIG_DT_HAS_X_POWERS_AXP2101_ENABLED */
142164

143165
static int mfd_axp192_init(const struct device *dev)
144166
{
145167
const struct mfd_axp192_config *config = dev->config;
146168
uint8_t chip_id;
147-
uint8_t vbus_val;
148169
int ret;
149170

150171
LOG_DBG("Initializing instance");
@@ -155,29 +176,29 @@ static int mfd_axp192_init(const struct device *dev)
155176
}
156177

157178
/* Check if axp192 chip is available */
158-
ret = i2c_reg_read_byte_dt(&config->i2c, AXP192_REG_CHIP_ID, &chip_id);
179+
ret = i2c_reg_read_byte_dt(&config->i2c, config->reg_chip_id, &chip_id);
159180
if (ret < 0) {
160181
return ret;
161182
}
162-
if (chip_id != AXP192_CHIP_ID) {
183+
if (chip_id != config->chip_id) {
163184
LOG_ERR("Invalid Chip detected (%d)", chip_id);
164185
return -EINVAL;
165186
}
166187

188+
#ifdef CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED
167189
/* 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);
190+
ret = i2c_reg_update_byte_dt(
191+
&config->i2c, config->vbus_config_reg, config->val_vbusen_disable,
192+
config->vbusen_disable ? config->val_vbusen_disable : 0);
174193
if (ret < 0) {
175194
return ret;
176195
}
196+
#endif
177197

178198
return 0;
179199
}
180200

201+
#ifdef CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED
181202
int mfd_axp192_gpio_func_get(const struct device *dev, uint8_t gpio, enum axp192_gpio_func *func)
182203
{
183204
const struct mfd_axp192_config *config = dev->config;
@@ -605,16 +626,29 @@ int mfd_axp192_gpio_write_port(const struct device *dev, uint8_t value, uint8_t
605626

606627
return 0;
607628
}
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), \
629+
#endif
630+
631+
#define MFD_AXP192_CONST_CONFIG(model) \
632+
.reg_chip_id = AXP##model##_REG_CHIP_ID, \
633+
.vbus_config_reg = AXP##model##_VBUS_CFG_REG, \
634+
.chip_id = AXP##model##_CHIP_ID, \
635+
.val_vbusen_disable = AXP##model##_CHIP_ID,
636+
637+
#define MFD_AXP192_AXP2101_DEFINE(node, model) \
638+
static const struct mfd_axp192_config config##node = { \
639+
.i2c = I2C_DT_SPEC_GET(node), \
640+
IF_ENABLED(CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED, \
641+
(.vbusen_disable = DT_PROP_OR(node, vbusen_disable, false),)) \
642+
MFD_AXP192_CONST_CONFIG(model) \
613643
}; \
614644
\
615-
static struct mfd_axp192_data data##inst; \
645+
IF_ENABLED(CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED, \
646+
(static struct mfd_axp192_data data##node;)) \
616647
\
617-
DEVICE_DT_INST_DEFINE(inst, mfd_axp192_init, NULL, &data##inst, &config##inst, \
618-
POST_KERNEL, CONFIG_MFD_INIT_PRIORITY, NULL);
648+
DEVICE_DT_DEFINE(node, mfd_axp192_init, NULL, \
649+
COND_CODE_1(CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED, \
650+
(&data##node), (NULL)), \
651+
&config##node, POST_KERNEL, CONFIG_MFD_INIT_PRIORITY, NULL);
619652

620-
DT_INST_FOREACH_STATUS_OKAY(MFD_AXP192_DEFINE);
653+
DT_FOREACH_STATUS_OKAY_VARGS(x_powers_axp192, MFD_AXP192_AXP2101_DEFINE, 192);
654+
DT_FOREACH_STATUS_OKAY_VARGS(x_powers_axp2101, MFD_AXP192_AXP2101_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)