Skip to content

Commit 71e28e2

Browse files
valeriosettifabiobaltieri
authored andcommitted
drivers: mfd: split axp192 and axp2101 drivers
The previous axp192 driver was implementing some basic support for axp2101, but in fact most of the source code was guarded to be compiled in only when axp192 was used and only the chip-id was read in case of axp2101. Next commits are going to introduce some support for the power button found on the axp2101 device, so it would look cleaner to split the 2 drivers. Signed-off-by: Valerio Setti <[email protected]>
1 parent f115e9f commit 71e28e2

File tree

6 files changed

+82
-51
lines changed

6 files changed

+82
-51
lines changed

drivers/mfd/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ zephyr_library_sources_ifdef(CONFIG_MFD_NCT38XX mfd_nct38xx.c)
99
zephyr_library_sources_ifdef(CONFIG_MFD_NPM13XX mfd_npm13xx.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_AXP2101 mfd_axp192.c)
12+
zephyr_library_sources_ifdef(CONFIG_MFD_AXP192 mfd_axp192.c)
13+
zephyr_library_sources_ifdef(CONFIG_MFD_AXP2101 mfd_axp2101.c)
1314
zephyr_library_sources_ifdef(CONFIG_MFD_AD559X mfd_ad559x.c)
1415
zephyr_library_sources_ifdef(CONFIG_MFD_AD559X_BUS_I2C mfd_ad559x_i2c.c)
1516
zephyr_library_sources_ifdef(CONFIG_MFD_AD559X_BUS_SPI mfd_ad559x_spi.c)

drivers/mfd/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ config MFD_INIT_PRIORITY
2121
source "drivers/mfd/Kconfig.ad559x"
2222
source "drivers/mfd/Kconfig.adp5585"
2323
source "drivers/mfd/Kconfig.axp192"
24+
source "drivers/mfd/Kconfig.axp2101"
2425
source "drivers/mfd/Kconfig.aw9523b"
2526
source "drivers/mfd/Kconfig.bd8lb600fs"
2627
source "drivers/mfd/Kconfig.ds3231"

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

drivers/mfd/Kconfig.axp2101

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (c) 2025 BayLibre SAS
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config MFD_AXP2101
5+
bool "AXP2101 PMIC multi-function device driver"
6+
default y
7+
depends on DT_HAS_X_POWERS_AXP2101_ENABLED
8+
select I2C
9+
help
10+
Enable the X-Powers AXP2101 PMIC multi-function device driver

drivers/mfd/mfd_axp192.c

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,11 @@ LOG_MODULE_REGISTER(mfd_axp192, CONFIG_MFD_LOG_LEVEL);
1515

1616
struct mfd_axp192_config {
1717
struct i2c_dt_spec i2c;
18-
#ifdef CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED
1918
bool vbusen_disable;
20-
#endif
21-
uint8_t reg_chip_id;
2219
uint8_t vbus_config_reg;
23-
uint8_t chip_id;
2420
uint8_t val_vbusen_disable;
2521
};
2622

27-
#ifdef CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED
28-
2923
/* Chip ID value */
3024
#define AXP192_CHIP_ID 0x03U
3125

@@ -145,22 +139,6 @@ const struct mfd_axp192_func_reg_desc gpio_reg_desc[AXP192_GPIO_MAX_NUM] = {
145139
.mask = AXP192_GPIO4_FUNC_MASK,
146140
},
147141
};
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 */
164142

165143
static int mfd_axp192_init(const struct device *dev)
166144
{
@@ -175,30 +153,27 @@ static int mfd_axp192_init(const struct device *dev)
175153
return -ENODEV;
176154
}
177155

178-
/* Check if axp192 chip is available */
179-
ret = i2c_reg_read_byte_dt(&config->i2c, config->reg_chip_id, &chip_id);
156+
/* Check if AXP192 chip is available */
157+
ret = i2c_reg_read_byte_dt(&config->i2c, AXP192_REG_CHIP_ID, &chip_id);
180158
if (ret < 0) {
181159
return ret;
182160
}
183-
if (chip_id != config->chip_id) {
161+
if (chip_id != AXP192_CHIP_ID) {
184162
LOG_ERR("Invalid Chip detected (%d)", chip_id);
185163
return -EINVAL;
186164
}
187165

188-
#ifdef CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED
189166
/* Disable N_VBUSEN */
190167
ret = i2c_reg_update_byte_dt(
191168
&config->i2c, config->vbus_config_reg, config->val_vbusen_disable,
192169
config->vbusen_disable ? config->val_vbusen_disable : 0);
193170
if (ret < 0) {
194171
return ret;
195172
}
196-
#endif
197173

198174
return 0;
199175
}
200176

201-
#ifdef CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED
202177
int mfd_axp192_gpio_func_get(const struct device *dev, uint8_t gpio, enum axp192_gpio_func *func)
203178
{
204179
const struct mfd_axp192_config *config = dev->config;
@@ -626,29 +601,18 @@ int mfd_axp192_gpio_write_port(const struct device *dev, uint8_t value, uint8_t
626601

627602
return 0;
628603
}
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,
636604

637-
#define MFD_AXP192_AXP2101_DEFINE(node, model) \
605+
#define MFD_AXP192_DEFINE(node) \
638606
static const struct mfd_axp192_config config##node = { \
639607
.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) \
608+
.vbusen_disable = DT_PROP_OR(node, vbusen_disable, false), \
609+
.vbus_config_reg = AXP192_VBUS_CFG_REG, \
610+
.val_vbusen_disable = AXP192_VBUS_CFG_VAL_VBUSEN_DISABLE, \
643611
}; \
644612
\
645-
IF_ENABLED(CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED, \
646-
(static struct mfd_axp192_data data##node;)) \
613+
static struct mfd_axp192_data data##node; \
647614
\
648-
DEVICE_DT_DEFINE(node, mfd_axp192_init, NULL, \
649-
COND_CODE_1(CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED, \
650-
(&data##node), (NULL)), \
615+
DEVICE_DT_DEFINE(node, mfd_axp192_init, NULL, &data##node, \
651616
&config##node, POST_KERNEL, CONFIG_MFD_INIT_PRIORITY, NULL);
652617

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);
618+
DT_FOREACH_STATUS_OKAY(x_powers_axp192, MFD_AXP192_DEFINE);

drivers/mfd/mfd_axp2101.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2025 BayLibre SAS
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include <errno.h>
7+
#include <stdbool.h>
8+
9+
#include <zephyr/drivers/i2c.h>
10+
#include <zephyr/sys/util.h>
11+
#include <zephyr/logging/log.h>
12+
13+
LOG_MODULE_REGISTER(mfd_axp2101, CONFIG_MFD_LOG_LEVEL);
14+
15+
struct mfd_axp2101_config {
16+
struct i2c_dt_spec i2c;
17+
};
18+
19+
/* Registers */
20+
#define AXP2101_REG_CHIP_ID 0x03U
21+
#define AXP2101_CHIP_ID 0x4AU
22+
23+
static int mfd_axp2101_init(const struct device *dev)
24+
{
25+
const struct mfd_axp2101_config *config = dev->config;
26+
uint8_t chip_id;
27+
int ret;
28+
29+
if (!i2c_is_ready_dt(&config->i2c)) {
30+
LOG_ERR("I2C bus not ready");
31+
return -ENODEV;
32+
}
33+
34+
/* Check if axp2101 chip is available */
35+
ret = i2c_reg_read_byte_dt(&config->i2c, AXP2101_REG_CHIP_ID, &chip_id);
36+
if (ret < 0) {
37+
return ret;
38+
}
39+
if (chip_id != AXP2101_CHIP_ID) {
40+
LOG_ERR("Invalid Chip detected (%d)", chip_id);
41+
return -EINVAL;
42+
}
43+
44+
return 0;
45+
}
46+
47+
#define MFD_AXP2101_DEFINE(node) \
48+
static const struct mfd_axp2101_config config##node = { \
49+
.i2c = I2C_DT_SPEC_GET(node), \
50+
}; \
51+
\
52+
DEVICE_DT_DEFINE(node, mfd_axp2101_init, NULL, NULL, \
53+
&config##node, POST_KERNEL, CONFIG_MFD_INIT_PRIORITY, NULL);
54+
55+
DT_FOREACH_STATUS_OKAY(x_powers_axp2101, MFD_AXP2101_DEFINE);

0 commit comments

Comments
 (0)