From 93423712023978fdd1725b6c0266aea20fc8a2cf Mon Sep 17 00:00:00 2001 From: Maximilian Deubel Date: Mon, 21 Aug 2023 15:56:08 +0200 Subject: [PATCH] workaround for npm1300 --- boards/arm/nrf9131ek_nrf9131/CMakeLists.txt | 7 +++ boards/arm/nrf9131ek_nrf9131/Kconfig | 18 +++++++ boards/arm/nrf9131ek_nrf9131/npm1300.c | 53 +++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 boards/arm/nrf9131ek_nrf9131/CMakeLists.txt create mode 100644 boards/arm/nrf9131ek_nrf9131/Kconfig create mode 100644 boards/arm/nrf9131ek_nrf9131/npm1300.c diff --git a/boards/arm/nrf9131ek_nrf9131/CMakeLists.txt b/boards/arm/nrf9131ek_nrf9131/CMakeLists.txt new file mode 100644 index 000000000000..81c27d56c9a0 --- /dev/null +++ b/boards/arm/nrf9131ek_nrf9131/CMakeLists.txt @@ -0,0 +1,7 @@ +# Copyright (c) 2023 Nordic Semiconductor ASA. +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + +if (CONFIG_BOARD_NRF9131EK_NRF9131 OR CONFIG_BOARD_NRF9131EK_NRF9131_NS) +zephyr_library() +zephyr_library_sources(npm1300.c) +endif() diff --git a/boards/arm/nrf9131ek_nrf9131/Kconfig b/boards/arm/nrf9131ek_nrf9131/Kconfig new file mode 100644 index 000000000000..35b0102106a2 --- /dev/null +++ b/boards/arm/nrf9131ek_nrf9131/Kconfig @@ -0,0 +1,18 @@ +# Thingy:91 nRF9161 board configuration +# +# Copyright (c) 2019 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + +if BOARD_NRF9131EK_NRF9131 || BOARD_NRF9131EK_NRF9131_NS + +config BOARD_INIT_PRIORITY + int "Initialization priority for board configuration" + default 80 + +endif # BOARD_NRF9131EK_NRF9131 || BOARD_NRF9131EK_NRF9131_NS + +module=BOARD +module-dep=LOG +module-str=Log level for board +source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config" diff --git a/boards/arm/nrf9131ek_nrf9131/npm1300.c b/boards/arm/nrf9131ek_nrf9131/npm1300.c new file mode 100644 index 000000000000..48dbe393d63d --- /dev/null +++ b/boards/arm/nrf9131ek_nrf9131/npm1300.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +#include +#include +#include +#include +#include + +LOG_MODULE_REGISTER(board_secure, CONFIG_BOARD_LOG_LEVEL); + +#define CHECKERR if (err) {LOG_ERR("I2C error: %d", err); return err;} + +static const struct i2c_dt_spec pmic = I2C_DT_SPEC_GET(DT_NODELABEL(pmic_main)); + +static int pmic_write_reg(uint16_t address, uint8_t value) +{ + uint8_t buf[] = { + address >> 8, + address & 0xFF, + value, + }; + + return i2c_write_dt(&pmic, buf, ARRAY_SIZE(buf)); +} + +static int thingy91x_board_init(void) +{ + int err = 0; + + if (!device_is_ready(pmic.bus)) { + LOG_ERR("cannot reach PMIC!"); + return -ENODEV; + } + + // disable charger for config + err = pmic_write_reg(0x0305, 0x03); CHECKERR; + + // set VBUS current limit 500mA + err = pmic_write_reg(0x0201, 0x00); CHECKERR; + err = pmic_write_reg(0x0202, 0x00); CHECKERR; + err = pmic_write_reg(0x0200, 0x01); CHECKERR; + + // enable charger + err = pmic_write_reg(0x0304, 0x03); CHECKERR; + + return err; +} + +SYS_INIT(thingy91x_board_init, POST_KERNEL, CONFIG_BOARD_INIT_PRIORITY);