Skip to content

Commit 8f94c91

Browse files
lucien-nxpjhedberg
authored andcommitted
drivers: watchdog: wdt_nxp_ewm.c: add clk_sel feature for ewm IP
emw clk designed on RT1180 can be chosen by CLKCTRL register, add code to get sel from dts and configure it in driver. Signed-off-by: Lucien Zhao <[email protected]>
1 parent 7ee39d1 commit 8f94c91

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

drivers/watchdog/wdt_nxp_ewm.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct nxp_ewm_config {
2020
void (*irq_config_func)(const struct device *dev);
2121
bool is_input_enabled;
2222
bool is_input_active_high;
23+
uint8_t clk_sel;
2324
uint8_t clk_divider;
2425
};
2526

@@ -141,6 +142,27 @@ static int nxp_ewm_init(const struct device *dev)
141142
const struct nxp_ewm_config *config = dev->config;
142143
EWM_Type *base = config->base;
143144

145+
#if DT_INST_NODE_HAS_PROP(0, clk_sel)
146+
/* Set clock select value for CLKCTRL register */
147+
switch (config->clk_sel) {
148+
case 0:
149+
base->CLKCTRL = EWM_CLKCTRL_CLKSEL(0);
150+
break;
151+
case 1:
152+
base->CLKCTRL = EWM_CLKCTRL_CLKSEL(1);
153+
break;
154+
case 2:
155+
base->CLKCTRL = EWM_CLKCTRL_CLKSEL(2);
156+
break;
157+
case 3:
158+
base->CLKCTRL = EWM_CLKCTRL_CLKSEL(3);
159+
break;
160+
default:
161+
LOG_ERR("Invalid clock select value: %d", config->clk_sel);
162+
return -EINVAL;
163+
}
164+
#endif /* DT_INST_NODE_HAS_PROP(0, clk_sel) */
165+
144166
if (config->clk_divider >= 0 && config->clk_divider <= 0xFF) {
145167
base->CLKPRESCALER = EWM_CLKPRESCALER_CLK_DIV(config->clk_divider);
146168
}
@@ -156,6 +178,11 @@ static DEVICE_API(wdt, nxp_ewm_api) = {
156178
.feed = nxp_ewm_feed,
157179
};
158180

181+
#define CLK_SEL_DEFAULT 0
182+
#define EWM_CONFIG_CLK_SEL_INIT(n)\
183+
.clk_sel = COND_CODE_1(DT_INST_NODE_HAS_PROP(n, clk_sel), \
184+
(DT_INST_ENUM_IDX(n, clk_sel)), \
185+
(CLK_SEL_DEFAULT)),
159186
#define WDT_EWM_INIT(n) \
160187
static void nxp_ewm_config_func_##n(const struct device *dev); \
161188
\
@@ -165,6 +192,7 @@ static DEVICE_API(wdt, nxp_ewm_api) = {
165192
.is_input_enabled = DT_INST_PROP(n, input_trigger_en), \
166193
.is_input_active_high = \
167194
DT_INST_PROP(n, input_trigger_active_high), \
195+
EWM_CONFIG_CLK_SEL_INIT(n) \
168196
.clk_divider = DT_INST_PROP(n, clk_divider), \
169197
}; \
170198
\

dts/bindings/watchdog/nxp,ewm.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ properties:
1414
interrupts:
1515
required: true
1616

17+
clk-sel:
18+
type: string
19+
description: |
20+
Watchdog clock select
21+
(See the chip-specific information for clock sources used.)
22+
enum:
23+
- "lpo_clk[0]"
24+
- "lpo_clk[1]"
25+
- "lpo_clk[2]"
26+
- "lpo_clk[3]"
27+
1728
clk-divider:
1829
type: int
1930
description: Watchdog clock divider

0 commit comments

Comments
 (0)