Skip to content

Commit b7dfbeb

Browse files
committed
pinctrl: npcx: config pwm open-drain without enabling STORE_REG
Config pwm open-drain mode without enabling STORE_REG. This CL collects all active PWM's base address and related index in an array. Then, pinctrl driver configs its open-drain mode by finding the corresponding 'channel' index. Signed-off-by: Mulin Chao <[email protected]>
1 parent 703422f commit b7dfbeb

File tree

8 files changed

+54
-35
lines changed

8 files changed

+54
-35
lines changed

drivers/pinctrl/Kconfig.npcx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ DT_COMPAT_ST_PINCTRL_NPCX := nuvoton,npcx-pinctrl
88
config PINCTRL_NPCX
99
bool "Nuvoton NPCX embedded controller (EC) pin controller driver"
1010
depends on SOC_FAMILY_NPCX
11-
select PINCTRL_STORE_REG
1211
default $(dt_compat_enabled,$(DT_COMPAT_ST_PINCTRL_NPCX))
1312
help
1413
This option enables the pin controller driver for NPCX family of

drivers/pinctrl/pinctrl_npcx.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,22 @@ static const struct npcx_pinctrl_config npcx_pinctrl_cfg = {
1717
.base_scfg = DT_REG_ADDR_BY_NAME(DT_NODELABEL(scfg), scfg),
1818
};
1919

20+
/* PWM pinctrl config */
21+
struct npcx_pwm_pinctrl_config {
22+
uintptr_t base;
23+
int channel;
24+
};
25+
26+
#define NPCX_PWM_PINCTRL_CFG_INIT(node_id) \
27+
{ \
28+
.base = DT_REG_ADDR(node_id), \
29+
.channel = DT_PROP(node_id, pwm_channel), \
30+
},
31+
32+
static const struct npcx_pwm_pinctrl_config pwm_pinctrl_cfg[] = {
33+
DT_FOREACH_STATUS_OKAY(nuvoton_npcx_pwm, NPCX_PWM_PINCTRL_CFG_INIT)
34+
};
35+
2036
/* Pin-control local functions for peripheral devices */
2137
static bool npcx_periph_pinmux_has_lock(int group)
2238
{
@@ -70,8 +86,23 @@ static void npcx_periph_pupd_configure(const struct npcx_periph *pupd,
7086
}
7187
}
7288

73-
static void npcx_periph_pwm_drive_mode_configure(uintptr_t reg, bool is_od)
89+
static void npcx_periph_pwm_drive_mode_configure(const struct npcx_periph *periph,
90+
bool is_od)
7491
{
92+
uintptr_t reg = 0;
93+
94+
/* Find selected pwm module which enables open-drain prop. */
95+
for (int i = 0; i < ARRAY_SIZE(pwm_pinctrl_cfg); i++) {
96+
if (periph->group == pwm_pinctrl_cfg[i].channel) {
97+
reg = pwm_pinctrl_cfg[i].base;
98+
break;
99+
}
100+
}
101+
102+
if (reg == 0) {
103+
return;
104+
}
105+
75106
struct pwm_reg *const inst = (struct pwm_reg *)(reg);
76107

77108
if (is_od) {
@@ -94,7 +125,7 @@ static void npcx_periph_configure(const pinctrl_soc_pin_t *pin, uintptr_t reg)
94125
pin->flags.io_bias_type);
95126
} else if (pin->cfg.periph.type == NPCX_PINCTRL_TYPE_PERIPH_DRIVE) {
96127
/* Configure peripheral device's drive mode. (Only PWM pads support it) */
97-
npcx_periph_pwm_drive_mode_configure(reg,
128+
npcx_periph_pwm_drive_mode_configure(&pin->cfg.periph,
98129
pin->flags.io_drive_type == NPCX_DRIVE_TYPE_OPEN_DRAIN);
99130
}
100131
}

dts/arm/nuvoton/npcx.dtsi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@
293293
pwm0: pwm@40080000 {
294294
compatible = "nuvoton,npcx-pwm";
295295
reg = <0x40080000 0x2000>;
296+
pwm-channel = <0>;
296297
clocks = <&pcc NPCX_CLOCK_BUS_APB2 NPCX_PWDWN_CTL2 0>;
297298
#pwm-cells = <3>;
298299
status = "disabled";
@@ -302,6 +303,7 @@
302303
pwm1: pwm@40082000 {
303304
compatible = "nuvoton,npcx-pwm";
304305
reg = <0x40082000 0x2000>;
306+
pwm-channel = <1>;
305307
clocks = <&pcc NPCX_CLOCK_BUS_APB2 NPCX_PWDWN_CTL2 1>;
306308
#pwm-cells = <3>;
307309
status = "disabled";
@@ -311,6 +313,7 @@
311313
pwm2: pwm@40084000 {
312314
compatible = "nuvoton,npcx-pwm";
313315
reg = <0x40084000 0x2000>;
316+
pwm-channel = <2>;
314317
clocks = <&pcc NPCX_CLOCK_BUS_APB2 NPCX_PWDWN_CTL2 2>;
315318
#pwm-cells = <3>;
316319
status = "disabled";
@@ -320,6 +323,7 @@
320323
pwm3: pwm@40086000 {
321324
compatible = "nuvoton,npcx-pwm";
322325
reg = <0x40086000 0x2000>;
326+
pwm-channel = <3>;
323327
clocks = <&pcc NPCX_CLOCK_BUS_APB2 NPCX_PWDWN_CTL2 3>;
324328
#pwm-cells = <3>;
325329
status = "disabled";
@@ -329,6 +333,7 @@
329333
pwm4: pwm@40088000 {
330334
compatible = "nuvoton,npcx-pwm";
331335
reg = <0x40088000 0x2000>;
336+
pwm-channel = <4>;
332337
clocks = <&pcc NPCX_CLOCK_BUS_APB2 NPCX_PWDWN_CTL2 4>;
333338
#pwm-cells = <3>;
334339
status = "disabled";
@@ -338,6 +343,7 @@
338343
pwm5: pwm@4008a000 {
339344
compatible = "nuvoton,npcx-pwm";
340345
reg = <0x4008a000 0x2000>;
346+
pwm-channel = <5>;
341347
clocks = <&pcc NPCX_CLOCK_BUS_APB2 NPCX_PWDWN_CTL2 5>;
342348
#pwm-cells = <3>;
343349
status = "disabled";
@@ -347,6 +353,7 @@
347353
pwm6: pwm@4008c000 {
348354
compatible = "nuvoton,npcx-pwm";
349355
reg = <0x4008c000 0x2000>;
356+
pwm-channel = <6>;
350357
clocks = <&pcc NPCX_CLOCK_BUS_APB2 NPCX_PWDWN_CTL2 6>;
351358
#pwm-cells = <3>;
352359
status = "disabled";
@@ -356,6 +363,7 @@
356363
pwm7: pwm@4008e000 {
357364
compatible = "nuvoton,npcx-pwm";
358365
reg = <0x4008e000 0x2000>;
366+
pwm-channel = <7>;
359367
clocks = <&pcc NPCX_CLOCK_BUS_APB2 NPCX_PWDWN_CTL2 7>;
360368
#pwm-cells = <3>;
361369
status = "disabled";

dts/arm/nuvoton/npcx/npcx7/npcx7-pinctrl.dtsi

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,42 +111,34 @@
111111
/* PWM peripheral interfaces */
112112
/omit-if-no-ref/ pwm0_gpc3: periph-pwm0 {
113113
pinmux = <&alt4_pwm0_sl>;
114-
drive-supported;
115114
};
116115

117116
/omit-if-no-ref/ pwm1_gpc2: periph-pwm1 {
118117
pinmux = <&alt4_pwm1_sl>;
119-
drive-supported;
120118
};
121119

122120
/omit-if-no-ref/ pwm2_gpc4: periph-pwm2 {
123121
pinmux = <&alt4_pwm2_sl>;
124-
drive-supported;
125122
};
126123

127124
/omit-if-no-ref/ pwm3_gp80: periph-pwm3 {
128125
pinmux = <&alt4_pwm3_sl>;
129-
drive-supported;
130126
};
131127

132128
/omit-if-no-ref/ pwm4_gpb6: periph-pwm4 {
133129
pinmux = <&alt4_pwm4_sl>;
134-
drive-supported;
135130
};
136131

137132
/omit-if-no-ref/ pwm5_gpb7: periph-pwm5 {
138133
pinmux = <&alt4_pwm5_sl>;
139-
drive-supported;
140134
};
141135

142136
/omit-if-no-ref/ pwm6_gpc0: periph-pwm6 {
143137
pinmux = <&alt4_pwm6_sl>;
144-
drive-supported;
145138
};
146139

147140
/omit-if-no-ref/ pwm7_gp60: periph-pwm7 {
148141
pinmux = <&alt4_pwm7_sl>;
149-
drive-supported;
150142
};
151143

152144
/* Keyboard peripheral interfaces. */

dts/arm/nuvoton/npcx/npcx9/npcx9-pinctrl.dtsi

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,42 +111,34 @@
111111
/* PWM peripheral interfaces */
112112
/omit-if-no-ref/ pwm0_gpc3: periph-pwm0 {
113113
pinmux = <&alt4_pwm0_sl>;
114-
drive-supported;
115114
};
116115

117116
/omit-if-no-ref/ pwm1_gpc2: periph-pwm1 {
118117
pinmux = <&alt4_pwm1_sl>;
119-
drive-supported;
120118
};
121119

122120
/omit-if-no-ref/ pwm2_gpc4: periph-pwm2 {
123121
pinmux = <&alt4_pwm2_sl>;
124-
drive-supported;
125122
};
126123

127124
/omit-if-no-ref/ pwm3_gp80: periph-pwm3 {
128125
pinmux = <&alt4_pwm3_sl>;
129-
drive-supported;
130126
};
131127

132128
/omit-if-no-ref/ pwm4_gpb6: periph-pwm4 {
133129
pinmux = <&alt4_pwm4_sl>;
134-
drive-supported;
135130
};
136131

137132
/omit-if-no-ref/ pwm5_gpb7: periph-pwm5 {
138133
pinmux = <&alt4_pwm5_sl>;
139-
drive-supported;
140134
};
141135

142136
/omit-if-no-ref/ pwm6_gpc0: periph-pwm6 {
143137
pinmux = <&alt4_pwm6_sl>;
144-
drive-supported;
145138
};
146139

147140
/omit-if-no-ref/ pwm7_gp60: periph-pwm7 {
148141
pinmux = <&alt4_pwm7_sl>;
149-
drive-supported;
150142
};
151143

152144
/* Keyboard peripheral interfaces. */

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,6 @@ child-binding:
6161
description: |
6262
A map to PUPD_ENn register/bit that enable pull-up/down of NPCX peripheral devices.
6363
Please don't overwrite this property in the board-level DT driver.
64-
drive-supported:
65-
required: false
66-
type: boolean
67-
description: |
68-
It indicates the pad's drive mode is selectable. So far, only PWM's pad has this
69-
property in npcx series. Please don't overwrite it in the board-level DT driver.
7064
pinmux-locked:
7165
required: false
7266
type: boolean

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ properties:
1818
required: true
1919
pinctrl-names:
2020
required: true
21-
drive-open-drain:
22-
type: boolean
21+
pwm-channel:
22+
type: int
2323
description: |
24-
The PWM output will be configured as open-drain. If not set,
25-
defaults to push-pull.
24+
A index to indicate PWM module that generates a single PWM signal.
25+
Please don't overwrite it in the board-level DT driver.
2626
clock-bus:
2727
required: false
2828
type: string

soc/arm/nuvoton_npcx/common/pinctrl_soc.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ typedef struct npcx_pinctrl pinctrl_soc_pin_t;
102102
UTIL_OR(DT_PROP(node_id, bias_pull_down), \
103103
DT_PROP(node_id, bias_pull_up))
104104

105-
#define Z_PINCTRL_NPCX_HAS_DRIVE_PROP(node_id) \
106-
UTIL_AND(DT_PROP(node_id, drive_open_drain), \
107-
DT_PROP(node_id, drive_supported))
105+
#define Z_PINCTRL_NPCX_HAS_DRIVE_PROP(node_id, node_periph) \
106+
UTIL_AND(DT_PROP(node_id, drive_open_drain), \
107+
DT_NODE_HAS_PROP(node_periph, pwm_channel))
108108

109109
/**
110110
* @brief Utility macro to initialize a periphral pinmux configuration.
@@ -142,12 +142,14 @@ typedef struct npcx_pinctrl pinctrl_soc_pin_t;
142142
* @brief Utility macro to initialize a periphral drive mode configuration.
143143
*
144144
* @param node_id Node identifier.
145+
* @param node_periph Peripheral node identifier.
145146
*/
146-
#define Z_PINCTRL_NPCX_PERIPH_DRIVE_INIT(node_id) \
147+
#define Z_PINCTRL_NPCX_PERIPH_DRIVE_INIT(node_id, node_periph) \
147148
{ \
148149
.flags.type = NPCX_PINCTRL_TYPE_PERIPH, \
149150
.flags.io_drive_type = Z_PINCTRL_NPCX_DRIVE_TYPE(node_id), \
150151
.cfg.periph.type = NPCX_PINCTRL_TYPE_PERIPH_DRIVE, \
152+
.cfg.periph.group = DT_PROP(node_periph, pwm_channel), \
151153
},
152154

153155
/**
@@ -158,9 +160,10 @@ typedef struct npcx_pinctrl pinctrl_soc_pin_t;
158160
* @param idx Property entry index.
159161
*/
160162
#define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx) \
161-
COND_CODE_1(Z_PINCTRL_NPCX_HAS_DRIVE_PROP(DT_PROP_BY_IDX(node_id, prop, idx)), \
163+
COND_CODE_1(Z_PINCTRL_NPCX_HAS_DRIVE_PROP( \
164+
DT_PROP_BY_IDX(node_id, prop, idx), node_id), \
162165
(Z_PINCTRL_NPCX_PERIPH_DRIVE_INIT( \
163-
DT_PROP_BY_IDX(node_id, prop, idx))), ()) \
166+
DT_PROP_BY_IDX(node_id, prop, idx), node_id)), ()) \
164167
COND_CODE_1(Z_PINCTRL_NPCX_HAS_PUPD_PROP(DT_PROP_BY_IDX(node_id, prop, idx)), \
165168
(Z_PINCTRL_NPCX_PERIPH_PUPD_INIT( \
166169
DT_PROP_BY_IDX(node_id, prop, idx), periph_pupd)), ()) \

0 commit comments

Comments
 (0)