Skip to content

Commit 9f6a745

Browse files
JiafeiPancfriedt
authored andcommitted
drivers: watchdog: wdog32: add MMIO mapping support
Added MMIO mapping support in order to support on Cortex-A Core. Signed-off-by: Jiafei Pan <[email protected]>
1 parent 708ffa3 commit 9f6a745

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

drivers/watchdog/wdt_mcux_wdog32.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (2) 2019 Vestas Wind Systems A/S
3+
* Copyright 2025 NXP
34
*
45
* Based on wdt_mcux_wdog.c, which is:
56
* Copyright (c) 2018, NXP
@@ -11,6 +12,7 @@
1112

1213
#include <zephyr/drivers/watchdog.h>
1314
#include <zephyr/drivers/clock_control.h>
15+
#include <zephyr/sys/device_mmio.h>
1416
#include <fsl_wdog32.h>
1517

1618
#define LOG_LEVEL CONFIG_WDT_LOG_LEVEL
@@ -20,8 +22,11 @@ LOG_MODULE_REGISTER(wdt_mcux_wdog32);
2022

2123
#define MIN_TIMEOUT 1
2224

25+
#define DEV_CFG(_dev) ((const struct mcux_wdog32_config *)(_dev)->config)
26+
#define DEV_DATA(_dev) ((struct mcux_wdog32_data *)(_dev)->data)
27+
2328
struct mcux_wdog32_config {
24-
WDOG_Type *base;
29+
DEVICE_MMIO_NAMED_ROM(reg);
2530
#if DT_NODE_HAS_PROP(DT_INST_PHANDLE(0, clocks), clock_frequency)
2631
uint32_t clock_frequency;
2732
#else /* !DT_NODE_HAS_PROP(DT_INST_PHANDLE(0, clocks), clock_frequency) */
@@ -34,16 +39,21 @@ struct mcux_wdog32_config {
3439
};
3540

3641
struct mcux_wdog32_data {
42+
DEVICE_MMIO_NAMED_RAM(reg);
3743
wdt_callback_t callback;
3844
wdog32_config_t wdog_config;
3945
bool timeout_valid;
4046
};
4147

48+
static inline WDOG_Type *get_base_address(const struct device *dev)
49+
{
50+
return (WDOG_Type *)DEVICE_MMIO_NAMED_GET(dev, reg);
51+
}
52+
4253
static int mcux_wdog32_setup(const struct device *dev, uint8_t options)
4354
{
44-
const struct mcux_wdog32_config *config = dev->config;
4555
struct mcux_wdog32_data *data = dev->data;
46-
WDOG_Type *base = config->base;
56+
WDOG_Type *base = get_base_address(dev);
4757

4858
if (!data->timeout_valid) {
4959
LOG_ERR("No valid timeouts installed");
@@ -64,9 +74,8 @@ static int mcux_wdog32_setup(const struct device *dev, uint8_t options)
6474

6575
static int mcux_wdog32_disable(const struct device *dev)
6676
{
67-
const struct mcux_wdog32_config *config = dev->config;
6877
struct mcux_wdog32_data *data = dev->data;
69-
WDOG_Type *base = config->base;
78+
WDOG_Type *base = get_base_address(dev);
7079

7180
WDOG32_Deinit(base);
7281
data->timeout_valid = false;
@@ -140,8 +149,7 @@ static int mcux_wdog32_install_timeout(const struct device *dev,
140149

141150
static int mcux_wdog32_feed(const struct device *dev, int channel_id)
142151
{
143-
const struct mcux_wdog32_config *config = dev->config;
144-
WDOG_Type *base = config->base;
152+
WDOG_Type *base = get_base_address(dev);
145153

146154
if (channel_id != 0) {
147155
LOG_ERR("Invalid channel id");
@@ -156,9 +164,8 @@ static int mcux_wdog32_feed(const struct device *dev, int channel_id)
156164

157165
static void mcux_wdog32_isr(const struct device *dev)
158166
{
159-
const struct mcux_wdog32_config *config = dev->config;
160167
struct mcux_wdog32_data *data = dev->data;
161-
WDOG_Type *base = config->base;
168+
WDOG_Type *base = get_base_address(dev);
162169
uint32_t flags;
163170

164171
flags = WDOG32_GetStatusFlags(base);
@@ -173,6 +180,9 @@ static int mcux_wdog32_init(const struct device *dev)
173180
{
174181
const struct mcux_wdog32_config *config = dev->config;
175182

183+
/* Map the named MMIO region */
184+
DEVICE_MMIO_NAMED_MAP(dev, reg, K_MEM_CACHE_NONE | K_MEM_DIRECT_MAP);
185+
176186
config->irq_config_func(dev);
177187

178188
return 0;
@@ -191,7 +201,7 @@ static DEVICE_API(wdt, mcux_wdog32_api) = {
191201
static void mcux_wdog32_config_func_0(const struct device *dev);
192202

193203
static const struct mcux_wdog32_config mcux_wdog32_config_0 = {
194-
.base = (WDOG_Type *) DT_INST_REG_ADDR(0),
204+
DEVICE_MMIO_NAMED_ROM_INIT(reg, DT_DRV_INST(0)),
195205
#if DT_NODE_HAS_PROP(DT_INST_PHANDLE(0, clocks), clock_frequency)
196206
.clock_frequency = DT_INST_PROP_BY_PHANDLE(0, clocks, clock_frequency),
197207
#else /* !DT_NODE_HAS_PROP(DT_INST_PHANDLE(0, clocks), clock_frequency) */

0 commit comments

Comments
 (0)