drivers: retained_mem: Add nRF GPREGRET driver

Adds a driver for the Nordic nRF GPREGRET registers and adds
entries to the SoCs for this peripheral.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
This commit is contained in:
Jamie McCrae 2023-02-22 12:54:13 +00:00 committed by Carles Cufí
parent 2fedb306f7
commit 9bda013e5d
16 changed files with 309 additions and 0 deletions

View file

@ -1,3 +1,4 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
zephyr_library() zephyr_library()
zephyr_library_sources_ifdef(CONFIG_RETAINED_MEM_NRF_GPREGRET retained_mem_nrf_gpregret.c)

View file

@ -19,4 +19,6 @@ module = RETAINED_MEM
module-str = retained_mem module-str = retained_mem
source "subsys/logging/Kconfig.template.log_config" source "subsys/logging/Kconfig.template.log_config"
source "drivers/retained_mem/Kconfig.nrf"
endif # RETAINED_MEM endif # RETAINED_MEM

View file

@ -0,0 +1,10 @@
# Copyright (c) 2023 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
config RETAINED_MEM_NRF_GPREGRET
bool "nRF GPREGRET driver"
default y
depends on DT_HAS_NORDIC_NRF_GPREGRET_ENABLED
help
Enable driver for Nordic nRF GPREGRET-based retained memory
register support.

View file

@ -0,0 +1,136 @@
/*
* Copyright (c) 2023, Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT nordic_nrf_gpregret
#include <string.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/retained_mem.h>
#include <zephyr/kernel.h>
#include <zephyr/sys/util.h>
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(retained_mem_nrf_gpregret, CONFIG_RETAINED_MEM_LOG_LEVEL);
#ifdef CONFIG_MULTITHREADING
struct nrf_gpregret_data {
struct k_mutex lock;
};
#endif
struct nrf_gpregret_config {
uint8_t *addr;
size_t size;
};
static inline void nrf_gpregret_lock_take(const struct device *dev)
{
#ifdef CONFIG_MULTITHREADING
struct nrf_gpregret_data *data = dev->data;
k_mutex_lock(&data->lock, K_FOREVER);
#else
ARG_UNUSED(dev);
#endif
}
static inline void nrf_gpregret_lock_release(const struct device *dev)
{
#ifdef CONFIG_MULTITHREADING
struct nrf_gpregret_data *data = dev->data;
k_mutex_unlock(&data->lock);
#else
ARG_UNUSED(dev);
#endif
}
static int nrf_gpregret_init(const struct device *dev)
{
#ifdef CONFIG_MULTITHREADING
struct nrf_gpregret_data *data = dev->data;
k_mutex_init(&data->lock);
#endif
return 0;
}
static ssize_t nrf_gpregret_size(const struct device *dev)
{
const struct nrf_gpregret_config *config = dev->config;
return (ssize_t)config->size;
}
static int nrf_gpregret_read(const struct device *dev, off_t offset, uint8_t *buffer, size_t size)
{
const struct nrf_gpregret_config *config = dev->config;
nrf_gpregret_lock_take(dev);
memcpy(buffer, (config->addr + offset), size);
nrf_gpregret_lock_release(dev);
return 0;
}
static int nrf_gpregret_write(const struct device *dev, off_t offset, const uint8_t *buffer,
size_t size)
{
const struct nrf_gpregret_config *config = dev->config;
nrf_gpregret_lock_take(dev);
memcpy((config->addr + offset), buffer, size);
nrf_gpregret_lock_release(dev);
return 0;
}
static int nrf_gpregret_clear(const struct device *dev)
{
const struct nrf_gpregret_config *config = dev->config;
nrf_gpregret_lock_take(dev);
memset(config->addr, 0, config->size);
nrf_gpregret_lock_release(dev);
return 0;
}
static const struct retained_mem_driver_api nrf_gpregret_api = {
.size = nrf_gpregret_size,
.read = nrf_gpregret_read,
.write = nrf_gpregret_write,
.clear = nrf_gpregret_clear,
};
#define NRF_GPREGRET_DEVICE(inst) \
IF_ENABLED(CONFIG_MULTITHREADING, \
(static struct nrf_gpregret_data nrf_gpregret_data_##inst;) \
) \
static const struct nrf_gpregret_config nrf_gpregret_config_##inst = { \
.addr = (uint8_t *)DT_INST_REG_ADDR(inst), \
.size = DT_INST_REG_SIZE(inst), \
}; \
DEVICE_DT_INST_DEFINE(inst, \
&nrf_gpregret_init, \
NULL, \
COND_CODE_1(CONFIG_MULTITHREADING, \
(&nrf_gpregret_data_##inst), (NULL) \
), \
&nrf_gpregret_config_##inst, \
POST_KERNEL, \
CONFIG_RETAINED_MEM_INIT_PRIORITY, \
&nrf_gpregret_api);
DT_INST_FOREACH_STATUS_OKAY(NRF_GPREGRET_DEVICE)

View file

@ -42,6 +42,14 @@
reg = <0x40000000 0x1000>; reg = <0x40000000 0x1000>;
interrupts = <0 NRF_DEFAULT_IRQ_PRIORITY>; interrupts = <0 NRF_DEFAULT_IRQ_PRIORITY>;
status = "okay"; status = "okay";
#address-cells = <1>;
#size-cells = <1>;
gpregret1: gpregret1@4000051c {
compatible = "nordic,nrf-gpregret";
reg = <0x4000051c 0x1>;
status = "okay";
};
}; };
clock: clock@40000000 { clock: clock@40000000 {

View file

@ -53,6 +53,20 @@
reg = <0x40000000 0x1000>; reg = <0x40000000 0x1000>;
interrupts = <0 NRF_DEFAULT_IRQ_PRIORITY>; interrupts = <0 NRF_DEFAULT_IRQ_PRIORITY>;
status = "okay"; status = "okay";
#address-cells = <1>;
#size-cells = <1>;
gpregret1: gpregret1@4000051c {
compatible = "nordic,nrf-gpregret";
reg = <0x4000051c 0x1>;
status = "okay";
};
gpregret2: gpregret2@40000520 {
compatible = "nordic,nrf-gpregret";
reg = <0x40000520 0x1>;
status = "okay";
};
}; };
bprot: bprot@40000000 { bprot: bprot@40000000 {

View file

@ -57,6 +57,20 @@
reg = <0x40000000 0x1000>; reg = <0x40000000 0x1000>;
interrupts = <0 NRF_DEFAULT_IRQ_PRIORITY>; interrupts = <0 NRF_DEFAULT_IRQ_PRIORITY>;
status = "okay"; status = "okay";
#address-cells = <1>;
#size-cells = <1>;
gpregret1: gpregret1@4000051c {
compatible = "nordic,nrf-gpregret";
reg = <0x4000051c 0x1>;
status = "okay";
};
gpregret2: gpregret2@40000520 {
compatible = "nordic,nrf-gpregret";
reg = <0x40000520 0x1>;
status = "okay";
};
}; };
bprot: bprot@40000000 { bprot: bprot@40000000 {

View file

@ -61,6 +61,20 @@
reg = <0x40000000 0x1000>; reg = <0x40000000 0x1000>;
interrupts = <0 NRF_DEFAULT_IRQ_PRIORITY>; interrupts = <0 NRF_DEFAULT_IRQ_PRIORITY>;
status = "okay"; status = "okay";
#address-cells = <1>;
#size-cells = <1>;
gpregret1: gpregret1@4000051c {
compatible = "nordic,nrf-gpregret";
reg = <0x4000051c 0x1>;
status = "okay";
};
gpregret2: gpregret2@40000520 {
compatible = "nordic,nrf-gpregret";
reg = <0x40000520 0x1>;
status = "okay";
};
}; };
bprot: bprot@40000000 { bprot: bprot@40000000 {

View file

@ -62,6 +62,20 @@
reg = <0x40000000 0x1000>; reg = <0x40000000 0x1000>;
interrupts = <0 NRF_DEFAULT_IRQ_PRIORITY>; interrupts = <0 NRF_DEFAULT_IRQ_PRIORITY>;
status = "okay"; status = "okay";
#address-cells = <1>;
#size-cells = <1>;
gpregret1: gpregret1@4000051c {
compatible = "nordic,nrf-gpregret";
reg = <0x4000051c 0x1>;
status = "okay";
};
gpregret2: gpregret2@40000520 {
compatible = "nordic,nrf-gpregret";
reg = <0x40000520 0x1>;
status = "okay";
};
}; };
radio: radio@40001000 { radio: radio@40001000 {

View file

@ -57,6 +57,20 @@
reg = <0x40000000 0x1000>; reg = <0x40000000 0x1000>;
interrupts = <0 NRF_DEFAULT_IRQ_PRIORITY>; interrupts = <0 NRF_DEFAULT_IRQ_PRIORITY>;
status = "okay"; status = "okay";
#address-cells = <1>;
#size-cells = <1>;
gpregret1: gpregret1@4000051c {
compatible = "nordic,nrf-gpregret";
reg = <0x4000051c 0x1>;
status = "okay";
};
gpregret2: gpregret2@40000520 {
compatible = "nordic,nrf-gpregret";
reg = <0x40000520 0x1>;
status = "okay";
};
}; };
bprot: bprot@40000000 { bprot: bprot@40000000 {

View file

@ -61,6 +61,20 @@
reg = <0x40000000 0x1000>; reg = <0x40000000 0x1000>;
interrupts = <0 NRF_DEFAULT_IRQ_PRIORITY>; interrupts = <0 NRF_DEFAULT_IRQ_PRIORITY>;
status = "okay"; status = "okay";
#address-cells = <1>;
#size-cells = <1>;
gpregret1: gpregret1@4000051c {
compatible = "nordic,nrf-gpregret";
reg = <0x4000051c 0x1>;
status = "okay";
};
gpregret2: gpregret2@40000520 {
compatible = "nordic,nrf-gpregret";
reg = <0x40000520 0x1>;
status = "okay";
};
}; };
radio: radio@40001000 { radio: radio@40001000 {

View file

@ -57,6 +57,20 @@
reg = <0x40000000 0x1000>; reg = <0x40000000 0x1000>;
interrupts = <0 NRF_DEFAULT_IRQ_PRIORITY>; interrupts = <0 NRF_DEFAULT_IRQ_PRIORITY>;
status = "okay"; status = "okay";
#address-cells = <1>;
#size-cells = <1>;
gpregret1: gpregret1@4000051c {
compatible = "nordic,nrf-gpregret";
reg = <0x4000051c 0x1>;
status = "okay";
};
gpregret2: gpregret2@40000520 {
compatible = "nordic,nrf-gpregret";
reg = <0x40000520 0x1>;
status = "okay";
};
}; };
radio: radio@40001000 { radio: radio@40001000 {

View file

@ -34,6 +34,20 @@ power: power@5000 {
reg = <0x5000 0x1000>; reg = <0x5000 0x1000>;
interrupts = <5 NRF_DEFAULT_IRQ_PRIORITY>; interrupts = <5 NRF_DEFAULT_IRQ_PRIORITY>;
status = "okay"; status = "okay";
#address-cells = <1>;
#size-cells = <1>;
gpregret1: gpregret1@551c {
compatible = "nordic,nrf-gpregret";
reg = <0x551c 0x1>;
status = "okay";
};
gpregret2: gpregret2@5520 {
compatible = "nordic,nrf-gpregret";
reg = <0x5520 0x1>;
status = "okay";
};
}; };
reset: reset-controller@5000 { reset: reset-controller@5000 {

View file

@ -65,6 +65,20 @@
reg = <0x41005000 0x1000>; reg = <0x41005000 0x1000>;
interrupts = <5 NRF_DEFAULT_IRQ_PRIORITY>; interrupts = <5 NRF_DEFAULT_IRQ_PRIORITY>;
status = "okay"; status = "okay";
#address-cells = <1>;
#size-cells = <1>;
gpregret1: gpregret1@4100551c {
compatible = "nordic,nrf-gpregret";
reg = <0x4100551c 0x1>;
status = "okay";
};
gpregret2: gpregret2@41005520 {
compatible = "nordic,nrf-gpregret";
reg = <0x41005520 0x1>;
status = "okay";
};
}; };
radio: radio@41008000 { radio: radio@41008000 {

View file

@ -339,6 +339,20 @@ power: power@5000 {
reg = <0x5000 0x1000>; reg = <0x5000 0x1000>;
interrupts = <5 NRF_DEFAULT_IRQ_PRIORITY>; interrupts = <5 NRF_DEFAULT_IRQ_PRIORITY>;
status = "okay"; status = "okay";
#address-cells = <1>;
#size-cells = <1>;
gpregret1: gpregret1@551c {
compatible = "nordic,nrf-gpregret";
reg = <0x551c 0x1>;
status = "okay";
};
gpregret2: gpregret2@5520 {
compatible = "nordic,nrf-gpregret";
reg = <0x5520 0x1>;
status = "okay";
};
}; };
wdt: wdt0: watchdog@18000 { wdt: wdt0: watchdog@18000 {

View file

@ -0,0 +1,12 @@
# Copyright (c) 2023 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
description: Nordic GPREGRET (General Purpose Register Retention) device.
compatible: "nordic,nrf-gpregret"
include: base.yaml
properties:
reg:
required: true