Skip to content

Commit c19a915

Browse files
committed
drivers: regulator: add support for AXP2101 power management IC
add initial support for the AXP2101 power management IC from X-powers Co-authored-by: TOKITA Hiroshi <[email protected]> Signed-off-by: Lothar Felten <[email protected]>
1 parent 020cb79 commit c19a915

File tree

13 files changed

+562
-114
lines changed

13 files changed

+562
-114
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: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,30 @@
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

119
#include <zephyr/drivers/mfd/axp192.h>
10+
#include <zephyr/drivers/mfd/axp2101.h>
1211
#include <zephyr/drivers/i2c.h>
1312
#include <zephyr/sys/util.h>
1413
#include <zephyr/logging/log.h>
1514

1615
LOG_MODULE_REGISTER(mfd_axp192, CONFIG_MFD_LOG_LEVEL);
1716

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

@@ -97,11 +109,6 @@ LOG_MODULE_REGISTER(mfd_axp192, CONFIG_MFD_LOG_LEVEL);
97109
#define AXP192_GPIO5_OUTPUT_VAL 0x04U
98110
#define AXP192_GPIO5_OUTPUT_SHIFT 3U
99111

100-
struct mfd_axp192_config {
101-
struct i2c_dt_spec i2c;
102-
bool vbusen_disable;
103-
};
104-
105112
struct mfd_axp192_data {
106113
const struct device *gpio_mask_used[AXP192_GPIO_MAX_NUM];
107114
uint8_t gpio_mask_output;
@@ -139,12 +146,12 @@ const struct mfd_axp192_func_reg_desc gpio_reg_desc[AXP192_GPIO_MAX_NUM] = {
139146
.mask = AXP192_GPIO4_FUNC_MASK,
140147
},
141148
};
149+
#endif /* CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED */
142150

143151
static int mfd_axp192_init(const struct device *dev)
144152
{
145153
const struct mfd_axp192_config *config = dev->config;
146154
uint8_t chip_id;
147-
uint8_t vbus_val;
148155
int ret;
149156

150157
LOG_DBG("Initializing instance");
@@ -155,29 +162,29 @@ static int mfd_axp192_init(const struct device *dev)
155162
}
156163

157164
/* Check if axp192 chip is available */
158-
ret = i2c_reg_read_byte_dt(&config->i2c, AXP192_REG_CHIP_ID, &chip_id);
165+
ret = i2c_reg_read_byte_dt(&config->i2c, config->reg_chip_id, &chip_id);
159166
if (ret < 0) {
160167
return ret;
161168
}
162-
if (chip_id != AXP192_CHIP_ID) {
169+
if (chip_id != config->chip_id) {
163170
LOG_ERR("Invalid Chip detected (%d)", chip_id);
164171
return -EINVAL;
165172
}
166173

174+
#ifdef CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED
167175
/* 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);
176+
ret = i2c_reg_update_byte_dt(
177+
&config->i2c, config->vbus_config_reg, config->val_vbusen_disable,
178+
config->vbusen_disable ? config->val_vbusen_disable : 0);
174179
if (ret < 0) {
175180
return ret;
176181
}
182+
#endif
177183

178184
return 0;
179185
}
180186

187+
#ifdef CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED
181188
int mfd_axp192_gpio_func_get(const struct device *dev, uint8_t gpio, enum axp192_gpio_func *func)
182189
{
183190
const struct mfd_axp192_config *config = dev->config;
@@ -605,16 +612,29 @@ int mfd_axp192_gpio_write_port(const struct device *dev, uint8_t value, uint8_t
605612

606613
return 0;
607614
}
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), \
615+
#endif
616+
617+
#define MFD_AXP192_CONST_CONFIG(model) \
618+
.reg_chip_id = AXP##model##_REG_CHIP_ID, \
619+
.vbus_config_reg = AXP##model##_VBUS_CFG_REG, \
620+
.chip_id = AXP##model##_CHIP_ID, \
621+
.val_vbusen_disable = AXP##model##_CHIP_ID,
622+
623+
#define MFD_AXP192_DEFINE(node, model) \
624+
static const struct mfd_axp192_config config##node = { \
625+
.i2c = I2C_DT_SPEC_GET(node), \
626+
IF_ENABLED(CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED, \
627+
(.vbusen_disable = DT_PROP_OR(node, vbusen_disable, false),)) \
628+
MFD_AXP192_CONST_CONFIG(model) \
613629
}; \
614630
\
615-
static struct mfd_axp192_data data##inst; \
631+
IF_ENABLED(CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED, \
632+
(static struct mfd_axp192_data data##node;)) \
616633
\
617-
DEVICE_DT_INST_DEFINE(inst, mfd_axp192_init, NULL, &data##inst, &config##inst, \
618-
POST_KERNEL, CONFIG_MFD_INIT_PRIORITY, NULL);
634+
DEVICE_DT_DEFINE(node, mfd_axp192_init, NULL, \
635+
COND_CODE_1(CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED, \
636+
(&data##node), (NULL)), \
637+
&config##node, POST_KERNEL, CONFIG_MFD_INIT_PRIORITY, NULL);
619638

620-
DT_INST_FOREACH_STATUS_OKAY(MFD_AXP192_DEFINE);
639+
DT_FOREACH_STATUS_OKAY_VARGS(x_powers_axp192, MFD_AXP192_DEFINE, 192);
640+
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)