Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: regulator: add support for AXP2101 power management IC #82474

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion boards/m5stack/m5stack_core2/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ config GPIO_HOGS_INIT_PRIORITY
config MFD_INIT_PRIORITY
default 70

config REGULATOR_AXP192_INIT_PRIORITY
config REGULATOR_AXP192_AXP2101_INIT_PRIORITY
default 71

config GPIO_AXP192_INIT_PRIORITY
Expand Down
2 changes: 1 addition & 1 deletion boards/m5stack/m5stickc_plus/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ config GPIO_HOGS_INIT_PRIORITY
config MFD_INIT_PRIORITY
default 70

config REGULATOR_AXP192_INIT_PRIORITY
config REGULATOR_AXP192_AXP2101_INIT_PRIORITY
default 71

config GPIO_AXP192_INIT_PRIORITY
Expand Down
2 changes: 1 addition & 1 deletion drivers/mfd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ zephyr_library_sources_ifdef(CONFIG_MFD_NCT38XX mfd_nct38xx.c)
zephyr_library_sources_ifdef(CONFIG_MFD_NPM1300 mfd_npm1300.c)
zephyr_library_sources_ifdef(CONFIG_MFD_NPM2100 mfd_npm2100.c)
zephyr_library_sources_ifdef(CONFIG_MFD_NPM6001 mfd_npm6001.c)
zephyr_library_sources_ifdef(CONFIG_MFD_AXP192 mfd_axp192.c)
zephyr_library_sources_ifdef(CONFIG_MFD_AXP192_AXP2101 mfd_axp192.c)
zephyr_library_sources_ifdef(CONFIG_MFD_AD559X mfd_ad559x.c)
zephyr_library_sources_ifdef(CONFIG_MFD_AD559X_BUS_I2C mfd_ad559x_i2c.c)
zephyr_library_sources_ifdef(CONFIG_MFD_AD559X_BUS_SPI mfd_ad559x_spi.c)
Expand Down
8 changes: 4 additions & 4 deletions drivers/mfd/Kconfig.axp192
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Copyright (c) 2023 Martin Kiepfer <[email protected]>
# SPDX-License-Identifier: Apache-2.0

config MFD_AXP192
bool "AXP192 PMIC multi-function device driver"
config MFD_AXP192_AXP2101
bool "AXP192/AXP2101 PMIC multi-function device driver"
default y
depends on DT_HAS_X_POWERS_AXP192_ENABLED
depends on DT_HAS_X_POWERS_AXP192_ENABLED || DT_HAS_X_POWERS_AXP2101_ENABLED
select I2C
help
Enable the X-Powers AXP192 PMIC multi-function device driver
Enable the X-Powers AXP192/AXP2101 PMIC multi-function device driver
70 changes: 45 additions & 25 deletions drivers/mfd/mfd_axp192.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,30 @@
* SPDX-License-Identifier: Apache-2.0
*/

#define DT_DRV_COMPAT x_powers_axp192

#include <errno.h>
#include <stdbool.h>

#include <zephyr/drivers/mfd/axp192.h>
#include <zephyr/drivers/mfd/axp2101.h>
#include <zephyr/drivers/i2c.h>
#include <zephyr/sys/util.h>
#include <zephyr/logging/log.h>

LOG_MODULE_REGISTER(mfd_axp192, CONFIG_MFD_LOG_LEVEL);

struct mfd_axp192_config {
struct i2c_dt_spec i2c;
#ifdef CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED
bool vbusen_disable;
#endif
uint8_t reg_chip_id;
uint8_t vbus_config_reg;
uint8_t chip_id;
uint8_t val_vbusen_disable;
};

#ifdef CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED

/* Chip ID value */
#define AXP192_CHIP_ID 0x03U

Expand Down Expand Up @@ -97,11 +109,6 @@ LOG_MODULE_REGISTER(mfd_axp192, CONFIG_MFD_LOG_LEVEL);
#define AXP192_GPIO5_OUTPUT_VAL 0x04U
#define AXP192_GPIO5_OUTPUT_SHIFT 3U

struct mfd_axp192_config {
struct i2c_dt_spec i2c;
bool vbusen_disable;
};

struct mfd_axp192_data {
const struct device *gpio_mask_used[AXP192_GPIO_MAX_NUM];
uint8_t gpio_mask_output;
Expand Down Expand Up @@ -139,12 +146,12 @@ const struct mfd_axp192_func_reg_desc gpio_reg_desc[AXP192_GPIO_MAX_NUM] = {
.mask = AXP192_GPIO4_FUNC_MASK,
},
};
#endif /* CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED */

static int mfd_axp192_init(const struct device *dev)
{
const struct mfd_axp192_config *config = dev->config;
uint8_t chip_id;
uint8_t vbus_val;
int ret;

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

/* Check if axp192 chip is available */
ret = i2c_reg_read_byte_dt(&config->i2c, AXP192_REG_CHIP_ID, &chip_id);
ret = i2c_reg_read_byte_dt(&config->i2c, config->reg_chip_id, &chip_id);
if (ret < 0) {
return ret;
}
if (chip_id != AXP192_CHIP_ID) {
if (chip_id != config->chip_id) {
LOG_ERR("Invalid Chip detected (%d)", chip_id);
return -EINVAL;
}

#ifdef CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED
/* Disable N_VBUSEN */
vbus_val = 0;
if (config->vbusen_disable) {
vbus_val = AXP192_VBUS_CFG_VAL_VBUSEN_DISABLE;
}
ret = i2c_reg_update_byte_dt(&config->i2c, AXP192_VBUS_CFG_REG,
AXP192_VBUS_CFG_VAL_VBUSEN_DISABLE, vbus_val);
ret = i2c_reg_update_byte_dt(
&config->i2c, config->vbus_config_reg, config->val_vbusen_disable,
config->vbusen_disable ? config->val_vbusen_disable : 0);
if (ret < 0) {
return ret;
}
#endif

return 0;
}

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

return 0;
}

#define MFD_AXP192_DEFINE(inst) \
static const struct mfd_axp192_config config##inst = { \
.i2c = I2C_DT_SPEC_INST_GET(inst), \
.vbusen_disable = DT_INST_PROP_OR(inst, vbusen_disable, false), \
#endif

#define MFD_AXP192_CONST_CONFIG(model) \
.reg_chip_id = AXP##model##_REG_CHIP_ID, \
.vbus_config_reg = AXP##model##_VBUS_CFG_REG, \
.chip_id = AXP##model##_CHIP_ID, \
.val_vbusen_disable = AXP##model##_CHIP_ID,

#define MFD_AXP192_DEFINE(node, model) \
static const struct mfd_axp192_config config##node = { \
.i2c = I2C_DT_SPEC_GET(node), \
IF_ENABLED(CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED, \
(.vbusen_disable = DT_PROP_OR(node, vbusen_disable, false),)) \
MFD_AXP192_CONST_CONFIG(model) \
}; \
\
static struct mfd_axp192_data data##inst; \
IF_ENABLED(CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED, \
(static struct mfd_axp192_data data##node;)) \
\
DEVICE_DT_INST_DEFINE(inst, mfd_axp192_init, NULL, &data##inst, &config##inst, \
POST_KERNEL, CONFIG_MFD_INIT_PRIORITY, NULL);
DEVICE_DT_DEFINE(node, mfd_axp192_init, NULL, \
COND_CODE_1(CONFIG_DT_HAS_X_POWERS_AXP192_ENABLED, \
(&data##node), (NULL)), \
&config##node, POST_KERNEL, CONFIG_MFD_INIT_PRIORITY, NULL);

DT_INST_FOREACH_STATUS_OKAY(MFD_AXP192_DEFINE);
DT_FOREACH_STATUS_OKAY_VARGS(x_powers_axp192, MFD_AXP192_DEFINE, 192);
DT_FOREACH_STATUS_OKAY_VARGS(x_powers_axp2101, MFD_AXP192_DEFINE, 2101);
2 changes: 1 addition & 1 deletion drivers/regulator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
zephyr_library()

zephyr_library_sources(regulator_common.c)
zephyr_library_sources_ifdef(CONFIG_REGULATOR_AXP192 regulator_axp192.c)
zephyr_library_sources_ifdef(CONFIG_REGULATOR_AXP192_AXP2101 regulator_axp192.c)
zephyr_library_sources_ifdef(CONFIG_REGULATOR_ADP5360 regulator_adp5360.c)
zephyr_library_sources_ifdef(CONFIG_REGULATOR_CP9314 regulator_cp9314.c)
zephyr_library_sources_ifdef(CONFIG_REGULATOR_DA1469X regulator_da1469x.c)
Expand Down
16 changes: 8 additions & 8 deletions drivers/regulator/Kconfig.axp192
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# Copyright (c) 2023 Martin Kiepfer
# SPDX-License-Identifier: Apache-2.0

config REGULATOR_AXP192
bool "X-Power AXP192 PMIC regulator driver"
config REGULATOR_AXP192_AXP2101
bool "X-Powers AXP192/AXP2101 PMIC regulator driver"
default y
depends on DT_HAS_X_POWERS_AXP192_REGULATOR_ENABLED
depends on DT_HAS_X_POWERS_AXP192_ENABLED
depends on DT_HAS_X_POWERS_AXP192_REGULATOR_ENABLED || DT_HAS_X_POWERS_AXP2101_REGULATOR_ENABLED
depends on DT_HAS_X_POWERS_AXP192_ENABLED || DT_HAS_X_POWERS_AXP2101_ENABLED
select I2C
select MFD
help
Enable the AXP PMIC regulator driver

if REGULATOR_AXP192
if REGULATOR_AXP192_AXP2101

config REGULATOR_AXP192_INIT_PRIORITY
int "AXP192 regulator driver init priority"
config REGULATOR_AXP192_AXP2101_INIT_PRIORITY
int "AXP192/AXP2101 regulator driver init priority"
default 86
help
Init priority for the axp192 regulator driver. It must be
Init priority for the axp192/axp2101 regulator driver. It must be
greater than MFD_INIT_PRIORITY.

endif
Loading
Loading