Skip to content

Commit 2368aea

Browse files
MulinChaonashif
authored andcommitted
dts: pwm: npcx: add override mechanism for pwm input clock assignment.
This CL adds a override mechanism for pwm module's input clock source assignment. If the 'clock-bus' property exists, the NPCX_DT_PROP_ENUM_OR macro function will return an enum upper token value. Otherwise, it expands to default value in 'clocks' property. For example, if the users want to select LFCLK as pwm0's input clock, ths node can be overridden by adding 'clock-bus' property with an enum string, "NPCX_CLOCK_BUS_LFCLK". &pwm0 { status = "okay"; clock-bus = "NPCX_CLOCK_BUS_LFCLK"; }; Signed-off-by: Keith Short <[email protected]> Signed-off-by: Mulin Chao <[email protected]>
1 parent a3469a0 commit 2368aea

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

dts/bindings/pwm/nuvoton,npcx-pwm.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ properties:
2323
description: |
2424
The PWM output will be configured as open-drain. If not set,
2525
defaults to push-pull.
26+
clock-bus:
27+
required: false
28+
type: string
29+
description: |
30+
Select a specific input clock source for the PWM module. If this
31+
property doesn't exist, fallback to default value in clocks property.
32+
enum:
33+
- NPCX_CLOCK_BUS_APB2
34+
- NPCX_CLOCK_BUS_LFCLK
2635

2736
pwm-cells:
2837
- channel

soc/arm/nuvoton_npcx/common/soc_dt.h

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,35 @@
77
#ifndef _NUVOTON_NPCX_SOC_DT_H_
88
#define _NUVOTON_NPCX_SOC_DT_H_
99

10+
/**
11+
* @brief Like DT_PROP(), but expand parameters with
12+
* DT_ENUM_UPPER_TOKEN not DT_PROP
13+
*
14+
* If the prop exists, this expands to DT_ENUM_UPPER_TOKEN(node_id, prop).
15+
* The default_value parameter is not expanded in this case.
16+
*
17+
* Otherwise, this expands to default_value.
18+
*
19+
* @param node_id node identifier
20+
* @param prop lowercase-and-underscores property name
21+
* @param default_value a fallback value to expand to
22+
* @return the property's enum upper token value or default_value
23+
*/
24+
#define NPCX_DT_PROP_ENUM_OR(node_id, prop, default_value) \
25+
COND_CODE_1(DT_NODE_HAS_PROP(node_id, prop), \
26+
(DT_ENUM_UPPER_TOKEN(node_id, prop)), (default_value))
27+
28+
/**
29+
* @brief Like DT_INST_PROP_OR(), but expand parameters with
30+
* NPCX_DT_PROP_ENUM_OR not DT_PROP_OR
31+
* @param inst instance number
32+
* @param prop lowercase-and-underscores property name
33+
* @param default_value a fallback value to expand to
34+
* @return the property's enum upper token value or default_value
35+
*/
36+
#define NPCX_DT_INST_PROP_ENUM_OR(inst, prop, default_value) \
37+
NPCX_DT_PROP_ENUM_OR(DT_DRV_INST(inst), prop, default_value)
38+
1039
/**
1140
* @brief Construct a npcx_clk_cfg item from first item in 'clocks' prop which
1241
* type is 'phandle-array' to handle "clock-cells" in current driver.
@@ -27,7 +56,8 @@
2756
*/
2857
#define NPCX_DT_CLK_CFG_ITEM(inst) \
2958
{ \
30-
.bus = DT_PHA(DT_DRV_INST(inst), clocks, bus), \
59+
.bus = NPCX_DT_INST_PROP_ENUM_OR(inst, clock_bus, \
60+
DT_PHA(DT_DRV_INST(inst), clocks, bus)), \
3161
.ctrl = DT_PHA(DT_DRV_INST(inst), clocks, ctl), \
3262
.bit = DT_PHA(DT_DRV_INST(inst), clocks, bit), \
3363
}

0 commit comments

Comments
 (0)