drivers: mfd: npm6001: initial version
Add an API-less MFD driver for nPM6001. In this case, the MFD device driver doesn't expose any API as plain I2C API is used within other device drivers (regulator, GPIO, watchdog). This driver just initializes some device properties. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
0d3f18d3c4
commit
753bc2b785
5 changed files with 148 additions and 0 deletions
|
@ -2,3 +2,5 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
zephyr_library()
|
||||
|
||||
zephyr_library_sources_ifdef(CONFIG_MFD_NPM6001 mfd_npm6001.c)
|
||||
|
|
|
@ -18,4 +18,6 @@ config MFD_INIT_PRIORITY
|
|||
help
|
||||
Multi-function devices initialization priority.
|
||||
|
||||
source "drivers/mfd/Kconfig.npm6001"
|
||||
|
||||
endif # MFD
|
||||
|
|
10
drivers/mfd/Kconfig.npm6001
Normal file
10
drivers/mfd/Kconfig.npm6001
Normal file
|
@ -0,0 +1,10 @@
|
|||
# Copyright (c) 2023 Nordic Semiconductor ASA
|
||||
# SPDX -License-Identifier: Apache-2.0
|
||||
|
||||
config MFD_NPM6001
|
||||
bool "nPM6001 PMIC multi-function device driver"
|
||||
default y
|
||||
depends on DT_HAS_NORDIC_NPM6001_ENABLED
|
||||
select I2C
|
||||
help
|
||||
Enable the Nordic nPM6001 PMIC multi-function device driver
|
92
drivers/mfd/mfd_npm6001.c
Normal file
92
drivers/mfd/mfd_npm6001.c
Normal file
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Nordic Semiconductor ASA
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#define DT_DRV_COMPAT nordic_npm6001
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <zephyr/drivers/i2c.h>
|
||||
#include <zephyr/sys/util.h>
|
||||
|
||||
/* nPM6001 registers */
|
||||
#define NPM6001_BUCK3SELDAC 0x44U
|
||||
#define NPM6001_BUCKMODEPADCONF 0x4EU
|
||||
#define NPM6001_PADDRIVESTRENGTH 0x53U
|
||||
|
||||
/* nPM6001 BUCKMODEPADCONF fields */
|
||||
#define NPM6001_BUCKMODEPADCONF_BUCKMODE0PADTYPE_CMOS BIT(0)
|
||||
#define NPM6001_BUCKMODEPADCONF_BUCKMODE1PADTYPE_CMOS BIT(1)
|
||||
#define NPM6001_BUCKMODEPADCONF_BUCKMODE2PADTYPE_CMOS BIT(2)
|
||||
#define NPM6001_BUCKMODEPADCONF_BUCKMODE0PULLD_ENABLED BIT(4)
|
||||
#define NPM6001_BUCKMODEPADCONF_BUCKMODE1PULLD_ENABLED BIT(5)
|
||||
#define NPM6001_BUCKMODEPADCONF_BUCKMODE2PULLD_ENABLED BIT(6)
|
||||
|
||||
/* nPM6001 PADDRIVESTRENGTH fields */
|
||||
#define NPM6001_PADDRIVESTRENGTH_READY_HIGH BIT(2)
|
||||
#define NPM6001_PADDRIVESTRENGTH_NINT_HIGH BIT(3)
|
||||
#define NPM6001_PADDRIVESTRENGTH_SDA_HIGH BIT(5)
|
||||
|
||||
struct mfd_npm6001_config {
|
||||
struct i2c_dt_spec i2c;
|
||||
uint8_t buck_pad_val;
|
||||
uint8_t pad_val;
|
||||
};
|
||||
|
||||
static int mfd_npm6001_init(const struct device *dev)
|
||||
{
|
||||
const struct mfd_npm6001_config *config = dev->config;
|
||||
int ret;
|
||||
|
||||
if (!i2c_is_ready_dt(&config->i2c)) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* always select BUCK3 DAC (does not increase power consumption) */
|
||||
ret = i2c_reg_write_byte_dt(&config->i2c, NPM6001_BUCK3SELDAC, 1U);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* configure pad properties */
|
||||
ret = i2c_reg_write_byte_dt(&config->i2c, NPM6001_BUCKMODEPADCONF, config->buck_pad_val);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = i2c_reg_write_byte_dt(&config->i2c, NPM6001_PADDRIVESTRENGTH, config->pad_val);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define MFD_NPM6001_DEFINE(inst) \
|
||||
static const struct mfd_npm6001_config config##inst = { \
|
||||
.i2c = I2C_DT_SPEC_INST_GET(inst), \
|
||||
.buck_pad_val = ((DT_INST_ENUM_IDX(inst, nordic_buck_mode0_input_type) * \
|
||||
NPM6001_BUCKMODEPADCONF_BUCKMODE0PADTYPE_CMOS) | \
|
||||
(DT_INST_ENUM_IDX(inst, nordic_buck_mode1_input_type) * \
|
||||
NPM6001_BUCKMODEPADCONF_BUCKMODE1PADTYPE_CMOS) | \
|
||||
(DT_INST_ENUM_IDX(inst, nordic_buck_mode2_input_type) * \
|
||||
NPM6001_BUCKMODEPADCONF_BUCKMODE2PADTYPE_CMOS) | \
|
||||
(DT_INST_PROP(inst, nordic_buck_mode0_pull_down) * \
|
||||
NPM6001_BUCKMODEPADCONF_BUCKMODE0PULLD_ENABLED) | \
|
||||
(DT_INST_PROP(inst, nordic_buck_mode1_pull_down) * \
|
||||
NPM6001_BUCKMODEPADCONF_BUCKMODE1PULLD_ENABLED) | \
|
||||
(DT_INST_PROP(inst, nordic_buck_mode2_pull_down) * \
|
||||
NPM6001_BUCKMODEPADCONF_BUCKMODE2PULLD_ENABLED)), \
|
||||
.pad_val = ((DT_INST_PROP(inst, nordic_ready_high_drive) * \
|
||||
NPM6001_PADDRIVESTRENGTH_READY_HIGH) | \
|
||||
(DT_INST_PROP(inst, nordic_nint_high_drive) * \
|
||||
NPM6001_PADDRIVESTRENGTH_NINT_HIGH) | \
|
||||
(DT_INST_PROP(inst, nordic_sda_high_drive) * \
|
||||
NPM6001_PADDRIVESTRENGTH_SDA_HIGH)), \
|
||||
}; \
|
||||
\
|
||||
DEVICE_DT_INST_DEFINE(inst, mfd_npm6001_init, NULL, NULL, &config##inst, POST_KERNEL, \
|
||||
CONFIG_MFD_INIT_PRIORITY, NULL);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(MFD_NPM6001_DEFINE)
|
|
@ -10,3 +10,45 @@ include: i2c-device.yaml
|
|||
properties:
|
||||
reg:
|
||||
required: true
|
||||
|
||||
nordic,ready-high-drive:
|
||||
type: boolean
|
||||
description: Set drive strength to high for READY pin.
|
||||
|
||||
nordic,nint-high-drive:
|
||||
type: boolean
|
||||
description: Set drive strength to high for NINT pin.
|
||||
|
||||
nordic,sda-high-drive:
|
||||
type: boolean
|
||||
description: Set drive strength to high for SDA pin.
|
||||
|
||||
nordic,buck-mode0-input-type:
|
||||
type: string
|
||||
default: "schmitt"
|
||||
enum: ["schmitt", "cmos"]
|
||||
description: Input type for BUCK_MODE0 pin. Defaults IC boot-time value.
|
||||
|
||||
nordic,buck-mode0-pull-down:
|
||||
type: boolean
|
||||
description: Enable pull-down resistor for BUCK_MODE0 pin.
|
||||
|
||||
nordic,buck-mode1-input-type:
|
||||
type: string
|
||||
default: "schmitt"
|
||||
enum: ["schmitt", "cmos"]
|
||||
description: Input type for BUCK_MODE1 pin. Defaults IC boot-time value.
|
||||
|
||||
nordic,buck-mode1-pull-down:
|
||||
type: boolean
|
||||
description: Enable pull-down resistor for BUCK_MODE1 pin.
|
||||
|
||||
nordic,buck-mode2-input-type:
|
||||
type: string
|
||||
default: "schmitt"
|
||||
enum: ["schmitt", "cmos"]
|
||||
description: Input type for BUCK_MODE2 pin. Defaults IC boot-time value.
|
||||
|
||||
nordic,buck-mode2-pull-down:
|
||||
type: boolean
|
||||
description: Enable pull-down resistor for BUCK_MODE2 pin.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue