From d3c6bcada47240847cb56f10c1aabd0835f54d0f Mon Sep 17 00:00:00 2001 From: Andrzej Kuros Date: Mon, 2 Sep 2024 15:23:43 +0200 Subject: [PATCH] boards: shields: nrf2240ek: 500mA pmic current limit on bootup Bringing objects close to the PCB antenna of the nRF2240EK might cause voltage drops which could in effect reset the nRF2240 what is invisible to the remaining application. To counteract this phenomenon the current limit of the nPM1300 pmic present on the nRF2240EK is increased to 500mA. Signed-off-by: Andrzej Kuros --- boards/shields/nrf2240ek/CMakeLists.txt | 12 ++++ boards/shields/nrf2240ek/nrf2240ek.overlay | 8 ++- boards/shields/nrf2240ek/src/shield.c | 76 ++++++++++++++++++++++ 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 boards/shields/nrf2240ek/CMakeLists.txt create mode 100644 boards/shields/nrf2240ek/src/shield.c diff --git a/boards/shields/nrf2240ek/CMakeLists.txt b/boards/shields/nrf2240ek/CMakeLists.txt new file mode 100644 index 000000000000..10030db478a8 --- /dev/null +++ b/boards/shields/nrf2240ek/CMakeLists.txt @@ -0,0 +1,12 @@ +# +# Copyright (c) 2024 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +if(CONFIG_SHIELD_NRF2240EK) + +zephyr_library() +zephyr_library_sources(src/shield.c) + +endif() diff --git a/boards/shields/nrf2240ek/nrf2240ek.overlay b/boards/shields/nrf2240ek/nrf2240ek.overlay index 1908ef502567..2839d1a6df08 100644 --- a/boards/shields/nrf2240ek/nrf2240ek.overlay +++ b/boards/shields/nrf2240ek/nrf2240ek.overlay @@ -18,7 +18,7 @@ }; }; -fem_twi: &arduino_i2c { +&arduino_i2c { status = "okay"; compatible = "nordic,nrf-twim"; @@ -27,4 +27,10 @@ fem_twi: &arduino_i2c { status = "okay"; reg = <0x30>; }; + + nrf2240ek_pmic: pmic@6b { + compatible = "nordic,npm1300"; + status = "okay"; + reg = <0x6b>; + }; }; diff --git a/boards/shields/nrf2240ek/src/shield.c b/boards/shields/nrf2240ek/src/shield.c new file mode 100644 index 000000000000..5a87fdb499bc --- /dev/null +++ b/boards/shields/nrf2240ek/src/shield.c @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +#include +#include +#include + +#define NPM1300_REGADDR_VBUSIN_TASKUPDATEILIMSW 0x0200U + +#define NPM1300_REGVAL_VBUSIN_TASKUPDATEILIMSW_NOEFFECT 0x00U +#define NPM1300_REGVAL_VBUSIN_TASKUPDATEILIMSW_SELVBUSILIM0 0x01U + +#define NPM1300_REGADDR_VBUSIN_VBUSINILIM0 0x0201U + +#define NPM1300_REGVAL_VBUSIN_VBUSINILIM0_500MA0 0U + +/** + * @brief Writes a register of a nPM1300 device through I2C. + * + * @param spec I2C specification from the devicetree. + * @param reg_addr Address of the register within nPM1300 device. + * @param value The value to write into the register. + * + * @return As underlying @ref i2c_write_dt function. @c 0 if successful. + */ +static inline int npm1300_reg_write_dt( + const struct i2c_dt_spec *spec, + uint16_t reg_addr, + uint8_t value) +{ + /* Note: There is only 8-bit reg_addr version in drivers/i2c.h provided by Zephyr. + * The nPM1300 uses the 16-bit register address. + */ + + uint8_t tx_buf[3] = { + (uint8_t)(reg_addr >> 8), + (uint8_t)reg_addr, + value + }; + + return i2c_write_dt(spec, tx_buf, 3); +} + +static int nrf2240ek_pmic_init(void) +{ + int err; + struct i2c_dt_spec bus = I2C_DT_SPEC_GET(DT_NODELABEL(nrf2240ek_pmic)); + + err = npm1300_reg_write_dt(&bus, + NPM1300_REGADDR_VBUSIN_TASKUPDATEILIMSW, + NPM1300_REGVAL_VBUSIN_TASKUPDATEILIMSW_SELVBUSILIM0); + + if (err != 0) { + return err; + } + + err = npm1300_reg_write_dt(&bus, + NPM1300_REGADDR_VBUSIN_VBUSINILIM0, + NPM1300_REGVAL_VBUSIN_VBUSINILIM0_500MA0); + + if (err != 0) { + return err; + } + + return 0; +} + +static int shield_init(void) +{ + return nrf2240ek_pmic_init(); +} + +SYS_INIT(shield_init, POST_KERNEL, CONFIG_I2C_INIT_PRIORITY);