Skip to content

Commit 86a1fc8

Browse files
committed
[nrf fromtree] drivers: npm13xx: add support for nPM1304
Add support for nPM1304 in the npm13xx drivers. The nPM1304 supports different voltage and current ranges which are handled through the initialization macros. Signed-off-by: Sergei Ovchinnikov <[email protected]> (cherry picked from commit 645159d)
1 parent 5591c2d commit 86a1fc8

File tree

12 files changed

+177
-118
lines changed

12 files changed

+177
-118
lines changed

drivers/gpio/Kconfig.npm13xx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
config GPIO_NPM13XX
55
bool "nPM13xx GPIO driver"
66
default y
7-
depends on DT_HAS_NORDIC_NPM1300_GPIO_ENABLED
7+
depends on DT_HAS_NORDIC_NPM1300_GPIO_ENABLED || DT_HAS_NORDIC_NPM1304_GPIO_ENABLED
88
select I2C
99
select MFD
1010
help

drivers/gpio/gpio_npm13xx.c

Lines changed: 13 additions & 8 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 nordic_npm1300_gpio
7-
86
#include <errno.h>
97

108
#include <zephyr/drivers/gpio.h>
@@ -212,18 +210,25 @@ static int gpio_npm13xx_init(const struct device *dev)
212210
return 0;
213211
}
214212

215-
#define GPIO_NPM13XX_DEFINE(n) \
216-
static const struct gpio_npm13xx_config gpio_npm13xx_config##n = { \
213+
#define GPIO_NPM13XX_DEFINE(partno, n) \
214+
static const struct gpio_npm13xx_config gpio_##partno##_config##n = { \
217215
.common = \
218216
{ \
219217
.port_pin_mask = GPIO_PORT_PIN_MASK_FROM_DT_INST(n), \
220218
}, \
221219
.mfd = DEVICE_DT_GET(DT_INST_PARENT(n))}; \
222220
\
223-
static struct gpio_npm13xx_data gpio_npm13xx_data##n; \
221+
static struct gpio_npm13xx_data gpio_##partno##_data##n; \
224222
\
225-
DEVICE_DT_INST_DEFINE(n, gpio_npm13xx_init, NULL, &gpio_npm13xx_data##n, \
226-
&gpio_npm13xx_config##n, POST_KERNEL, \
223+
DEVICE_DT_INST_DEFINE(n, gpio_npm13xx_init, NULL, &gpio_##partno##_data##n, \
224+
&gpio_##partno##_config##n, POST_KERNEL, \
227225
CONFIG_GPIO_NPM13XX_INIT_PRIORITY, &gpio_npm13xx_api);
228226

229-
DT_INST_FOREACH_STATUS_OKAY(GPIO_NPM13XX_DEFINE)
227+
#define DT_DRV_COMPAT nordic_npm1300_gpio
228+
#define GPIO_NPM1300_DEFINE(n) GPIO_NPM13XX_DEFINE(npm1300, n)
229+
DT_INST_FOREACH_STATUS_OKAY(GPIO_NPM1300_DEFINE)
230+
231+
#undef DT_DRV_COMPAT
232+
#define DT_DRV_COMPAT nordic_npm1304_gpio
233+
#define GPIO_NPM1304_DEFINE(n) GPIO_NPM13XX_DEFINE(npm1304, n)
234+
DT_INST_FOREACH_STATUS_OKAY(GPIO_NPM1304_DEFINE)

drivers/led/Kconfig.npm13xx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
config LED_NPM13XX
55
bool "nPM13xx LED driver"
66
default y
7-
depends on DT_HAS_NORDIC_NPM1300_LED_ENABLED
7+
depends on DT_HAS_NORDIC_NPM1300_LED_ENABLED || DT_HAS_NORDIC_NPM1304_LED_ENABLED
88
select I2C
99
select MFD
1010
help

drivers/led/led_npm13xx.c

Lines changed: 11 additions & 6 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 nordic_npm1300_led
7-
86
#include <errno.h>
97

108
#include <zephyr/device.h>
@@ -87,14 +85,21 @@ static int led_npm13xx_init(const struct device *dev)
8785
return 0;
8886
}
8987

90-
#define LED_NPM13XX_DEFINE(n) \
91-
static const struct led_npm13xx_config led_npm13xx_config##n = { \
88+
#define LED_NPM13XX_DEFINE(partno, n) \
89+
static const struct led_npm13xx_config led_##partno##_config##n = { \
9290
.mfd = DEVICE_DT_GET(DT_INST_PARENT(n)), \
9391
.mode = {DT_INST_ENUM_IDX(n, nordic_led0_mode), \
9492
DT_INST_ENUM_IDX(n, nordic_led1_mode), \
9593
DT_INST_ENUM_IDX(n, nordic_led2_mode)}}; \
9694
\
97-
DEVICE_DT_INST_DEFINE(n, &led_npm13xx_init, NULL, NULL, &led_npm13xx_config##n, \
95+
DEVICE_DT_INST_DEFINE(n, &led_npm13xx_init, NULL, NULL, &led_##partno##_config##n, \
9896
POST_KERNEL, CONFIG_LED_INIT_PRIORITY, &led_npm13xx_api);
9997

100-
DT_INST_FOREACH_STATUS_OKAY(LED_NPM13XX_DEFINE)
98+
#define DT_DRV_COMPAT nordic_npm1300_led
99+
#define LED_NPM1300_DEFINE(n) LED_NPM13XX_DEFINE(npm1300, n)
100+
DT_INST_FOREACH_STATUS_OKAY(LED_NPM1300_DEFINE)
101+
102+
#undef DT_DRV_COMPAT
103+
#define DT_DRV_COMPAT nordic_npm1304_led
104+
#define LED_NPM1304_DEFINE(n) LED_NPM13XX_DEFINE(npm1304, n)
105+
DT_INST_FOREACH_STATUS_OKAY(LED_NPM1304_DEFINE)

drivers/mfd/Kconfig.npm13xx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
config MFD_NPM13XX
55
bool "nPM13xx PMIC multi-function device driver"
66
default y
7-
depends on DT_HAS_NORDIC_NPM1300_ENABLED
7+
depends on DT_HAS_NORDIC_NPM1300_ENABLED || DT_HAS_NORDIC_NPM1304_ENABLED
88
select I2C
99
help
1010
Enable the Nordic nPM13xx PMIC multi-function device driver

drivers/mfd/mfd_npm13xx.c

Lines changed: 19 additions & 13 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 nordic_npm1300
7-
86
#include <errno.h>
97

108
#include <zephyr/drivers/i2c.h>
@@ -308,18 +306,26 @@ int mfd_npm13xx_remove_callback(const struct device *dev, struct gpio_callback *
308306
return gpio_manage_callback(&data->callbacks, callback, false);
309307
}
310308

311-
#define MFD_NPM13XX_DEFINE(inst) \
312-
static struct mfd_npm13xx_data data_##inst; \
309+
#define MFD_NPM13XX_DEFINE(partno, n) \
310+
static struct mfd_npm13xx_data mfd_##partno##_data##n; \
313311
\
314-
static const struct mfd_npm13xx_config config##inst = { \
315-
.i2c = I2C_DT_SPEC_INST_GET(inst), \
316-
.host_int_gpios = GPIO_DT_SPEC_INST_GET_OR(inst, host_int_gpios, {0}), \
317-
.pmic_int_pin = DT_INST_PROP_OR(inst, pmic_int_pin, 0), \
318-
.active_time = DT_INST_ENUM_IDX(inst, ship_to_active_time_ms), \
319-
.lp_reset = DT_INST_ENUM_IDX_OR(inst, long_press_reset, 0), \
312+
static const struct mfd_npm13xx_config mfd_##partno##_config##n = { \
313+
.i2c = I2C_DT_SPEC_INST_GET(n), \
314+
.host_int_gpios = GPIO_DT_SPEC_INST_GET_OR(n, host_int_gpios, {0}), \
315+
.pmic_int_pin = DT_INST_PROP_OR(n, pmic_int_pin, 0), \
316+
.active_time = DT_INST_ENUM_IDX(n, ship_to_active_time_ms), \
317+
.lp_reset = DT_INST_ENUM_IDX_OR(n, long_press_reset, 0), \
320318
}; \
321319
\
322-
DEVICE_DT_INST_DEFINE(inst, mfd_npm13xx_init, NULL, &data_##inst, &config##inst, \
323-
POST_KERNEL, CONFIG_MFD_NPM13XX_INIT_PRIORITY, NULL);
320+
DEVICE_DT_INST_DEFINE(n, mfd_npm13xx_init, NULL, &mfd_##partno##_data##n, \
321+
&mfd_##partno##_config##n, POST_KERNEL, \
322+
CONFIG_MFD_NPM13XX_INIT_PRIORITY, NULL);
323+
324+
#define DT_DRV_COMPAT nordic_npm1300
325+
#define MFD_NPM1300_DEFINE(n) MFD_NPM13XX_DEFINE(npm1300, n)
326+
DT_INST_FOREACH_STATUS_OKAY(MFD_NPM1300_DEFINE)
324327

325-
DT_INST_FOREACH_STATUS_OKAY(MFD_NPM13XX_DEFINE)
328+
#undef DT_DRV_COMPAT
329+
#define DT_DRV_COMPAT nordic_npm1304
330+
#define MFD_NPM1304_DEFINE(n) MFD_NPM13XX_DEFINE(npm1304, n)
331+
DT_INST_FOREACH_STATUS_OKAY(MFD_NPM1304_DEFINE)

drivers/regulator/Kconfig.npm13xx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
config REGULATOR_NPM13XX
55
bool "nPM13xx PMIC regulator driver"
66
default y
7-
depends on DT_HAS_NORDIC_NPM1300_REGULATOR_ENABLED
7+
depends on DT_HAS_NORDIC_NPM1300_REGULATOR_ENABLED || DT_HAS_NORDIC_NPM1304_REGULATOR_ENABLED
88
select I2C
99
select MFD
1010
help

drivers/regulator/regulator_npm13xx.c

Lines changed: 32 additions & 28 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 nordic_npm1300_regulator
7-
86
#include <errno.h>
97
#include <string.h>
108

@@ -689,9 +687,6 @@ int regulator_npm13xx_init(const struct device *dev)
689687
}
690688

691689
ret = regulator_npm13xx_set_pin_ctrl(dev, &config->pwm_gpios, NPM13XX_GPIO_TYPE_PWM);
692-
if (ret != 0) {
693-
return ret;
694-
}
695690

696691
return ret;
697692
}
@@ -712,13 +707,13 @@ static DEVICE_API(regulator, api) = {
712707
!!(DT_PROP_BY_IDX(node_id, prop, 1) & GPIO_ACTIVE_LOW)}), \
713708
({NPM13XX_GPIO_UNUSED, false}))
714709

715-
#define REGULATOR_NPM13XX_DEFINE(node_id, id, _source) \
710+
#define REGULATOR_NPM13XX_DEFINE(partno, node_id, id, _source) \
716711
BUILD_ASSERT(DT_PROP_LEN_OR(node_id, enable_gpio_config, 2) == 2); \
717712
BUILD_ASSERT(DT_PROP_LEN_OR(node_id, retention_gpio_config, 2) == 2); \
718713
BUILD_ASSERT(DT_PROP_LEN_OR(node_id, pwm_gpio_config, 2) == 2); \
719-
static struct regulator_npm13xx_data data_##id; \
714+
static struct regulator_npm13xx_data regulator_##partno##_data_##id; \
720715
\
721-
static const struct regulator_npm13xx_config config_##id = { \
716+
static const struct regulator_npm13xx_config regulator_##partno##_config_##id = { \
722717
.common = REGULATOR_DT_COMMON_CONFIG_INIT(node_id), \
723718
.mfd = DEVICE_DT_GET(DT_GPARENT(node_id)), \
724719
.source = _source, \
@@ -730,30 +725,39 @@ static DEVICE_API(regulator, api) = {
730725
.active_discharge = DT_PROP(node_id, active_discharge), \
731726
.ldo_disable_workaround = DT_PROP(node_id, nordic_anomaly38_disable_workaround)}; \
732727
\
733-
DEVICE_DT_DEFINE(node_id, regulator_npm13xx_init, NULL, &data_##id, &config_##id, \
734-
POST_KERNEL, CONFIG_REGULATOR_NPM13XX_INIT_PRIORITY, &api);
728+
DEVICE_DT_DEFINE(node_id, regulator_npm13xx_init, NULL, &regulator_##partno##_data_##id, \
729+
&regulator_##partno##_config_##id, POST_KERNEL, \
730+
CONFIG_REGULATOR_NPM13XX_INIT_PRIORITY, &api);
735731

736-
#define REGULATOR_NPM13XX_DEFINE_COND(inst, child, source) \
737-
COND_CODE_1(DT_NODE_EXISTS(DT_INST_CHILD(inst, child)), \
738-
(REGULATOR_NPM13XX_DEFINE(DT_INST_CHILD(inst, child), child##inst, source)), \
732+
#define REGULATOR_NPM13XX_DEFINE_COND(partno, n, child, source) \
733+
COND_CODE_1(DT_NODE_EXISTS(DT_INST_CHILD(n, child)), \
734+
(REGULATOR_NPM13XX_DEFINE(partno, DT_INST_CHILD(n, child), child##n, source)), \
739735
())
740736

741-
#define REGULATOR_NPM13XX_DEFINE_ALL(inst) \
742-
static const struct regulator_npm13xx_pconfig config_##inst = { \
743-
.mfd = DEVICE_DT_GET(DT_INST_PARENT(inst)), \
744-
.dvs_state_pins = {GPIO_DT_SPEC_INST_GET_BY_IDX_OR(inst, dvs_gpios, 0, {0}), \
745-
GPIO_DT_SPEC_INST_GET_BY_IDX_OR(inst, dvs_gpios, 1, {0}), \
746-
GPIO_DT_SPEC_INST_GET_BY_IDX_OR(inst, dvs_gpios, 2, {0}), \
747-
GPIO_DT_SPEC_INST_GET_BY_IDX_OR(inst, dvs_gpios, 3, {0}), \
748-
GPIO_DT_SPEC_INST_GET_BY_IDX_OR(inst, dvs_gpios, 4, {0})}}; \
737+
#define REGULATOR_NPM13XX_DEFINE_ALL(partno, n) \
738+
static const struct regulator_npm13xx_pconfig regulator_##partno##_config##n = { \
739+
.mfd = DEVICE_DT_GET(DT_INST_PARENT(n)), \
740+
.dvs_state_pins = {GPIO_DT_SPEC_INST_GET_BY_IDX_OR(n, dvs_gpios, 0, {0}), \
741+
GPIO_DT_SPEC_INST_GET_BY_IDX_OR(n, dvs_gpios, 1, {0}), \
742+
GPIO_DT_SPEC_INST_GET_BY_IDX_OR(n, dvs_gpios, 2, {0}), \
743+
GPIO_DT_SPEC_INST_GET_BY_IDX_OR(n, dvs_gpios, 3, {0}), \
744+
GPIO_DT_SPEC_INST_GET_BY_IDX_OR(n, dvs_gpios, 4, {0})}}; \
749745
\
750-
DEVICE_DT_INST_DEFINE(inst, regulator_npm13xx_common_init, NULL, NULL, &config_##inst, \
751-
POST_KERNEL, CONFIG_REGULATOR_NPM13XX_COMMON_INIT_PRIORITY, \
746+
DEVICE_DT_INST_DEFINE(n, regulator_npm13xx_common_init, NULL, NULL, \
747+
&regulator_##partno##_config##n, POST_KERNEL, \
748+
CONFIG_REGULATOR_NPM13XX_COMMON_INIT_PRIORITY, \
752749
&parent_api); \
753750
\
754-
REGULATOR_NPM13XX_DEFINE_COND(inst, buck1, NPM13XX_SOURCE_BUCK1) \
755-
REGULATOR_NPM13XX_DEFINE_COND(inst, buck2, NPM13XX_SOURCE_BUCK2) \
756-
REGULATOR_NPM13XX_DEFINE_COND(inst, ldo1, NPM13XX_SOURCE_LDO1) \
757-
REGULATOR_NPM13XX_DEFINE_COND(inst, ldo2, NPM13XX_SOURCE_LDO2)
751+
REGULATOR_NPM13XX_DEFINE_COND(partno, n, buck1, NPM13XX_SOURCE_BUCK1) \
752+
REGULATOR_NPM13XX_DEFINE_COND(partno, n, buck2, NPM13XX_SOURCE_BUCK2) \
753+
REGULATOR_NPM13XX_DEFINE_COND(partno, n, ldo1, NPM13XX_SOURCE_LDO1) \
754+
REGULATOR_NPM13XX_DEFINE_COND(partno, n, ldo2, NPM13XX_SOURCE_LDO2)
755+
756+
#define DT_DRV_COMPAT nordic_npm1300_regulator
757+
#define REGULATOR_NPM1300_DEFINE_ALL(n) REGULATOR_NPM13XX_DEFINE_ALL(npm1300, n)
758+
DT_INST_FOREACH_STATUS_OKAY(REGULATOR_NPM1300_DEFINE_ALL)
758759

759-
DT_INST_FOREACH_STATUS_OKAY(REGULATOR_NPM13XX_DEFINE_ALL)
760+
#undef DT_DRV_COMPAT
761+
#define DT_DRV_COMPAT nordic_npm1304_regulator
762+
#define REGULATOR_NPM1304_DEFINE_ALL(n) REGULATOR_NPM13XX_DEFINE_ALL(npm1304, n)
763+
DT_INST_FOREACH_STATUS_OKAY(REGULATOR_NPM1304_DEFINE_ALL)

drivers/sensor/nordic/npm13xx_charger/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
config NPM13XX_CHARGER
66
bool "nPM13xx Charger"
77
default y
8-
depends on DT_HAS_NORDIC_NPM1300_CHARGER_ENABLED
8+
depends on DT_HAS_NORDIC_NPM1300_CHARGER_ENABLED || DT_HAS_NORDIC_NPM1304_CHARGER_ENABLED
99
select I2C
1010
select MFD
1111
select REQUIRES_FULL_LIBC

0 commit comments

Comments
 (0)