Skip to content

Commit c2d42fa

Browse files
committed
soc: rp2350: support PWM channels >8
RP2350 adds four more PWM slices from the eight available on RP2030, which are only broken out to package pins on RP2350B. This change fixes the driver to support the correct number of slices on RP2350, and fixes the pinctrl definitions for GPIOs 40 through 47 to avoid referring to PWM channels that do not exist (channels 8 through 11 are connected to both GPIOs 32..39 and 40..47). Tested by confirming that PWM can correctly be configured on GPIO 44 of RP2350B. Signed-off-by: Peter Marheine <[email protected]>
1 parent 4f9a2a4 commit c2d42fa

File tree

3 files changed

+56
-18
lines changed

3 files changed

+56
-18
lines changed

drivers/pwm/pwm_rpi_pico.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,21 @@ LOG_MODULE_REGISTER(pwm_rpi_pico, CONFIG_PWM_LOG_LEVEL);
1717
#include <hardware/pwm.h>
1818
#include <hardware/structs/pwm.h>
1919

20+
/*
21+
* pico-sdk defines PWM_NUMS_SLICES with a 'u' suffix for unsigned, which
22+
* doesn't work with LISTIFY later on in this file.
23+
*/
24+
#ifdef CONFIG_SOC_SERIES_RP2350
25+
#define PWM_RPI_PICO_NUM_SLICES 12
26+
#else
27+
#define PWM_RPI_PICO_NUM_SLICES 8
28+
#endif
29+
BUILD_ASSERT(NUM_PWM_SLICES == PWM_RPI_PICO_NUM_SLICES,
30+
"PWM_RPI_PICO_NUM_SLICES misconfigured for SOC");
31+
2032
#define PWM_RPI_PICO_COUNTER_TOP_MAX UINT16_MAX
21-
#define PWM_RPI_NUM_CHANNELS (16U)
33+
#define PWM_RPI_NUM_CHANNELS (2 * NUM_PWM_SLICES)
34+
2235

2336
struct pwm_rpi_slice_config {
2437
uint8_t integral;
@@ -193,7 +206,7 @@ static int pwm_rpi_init(const struct device *dev)
193206
return 0;
194207
}
195208

196-
#define PWM_INST_RPI_SLICE_DIVIDER(idx, n) \
209+
#define PWM_INST_RPI_SLICE_DIVIDER(n, idx) \
197210
{ \
198211
.integral = DT_INST_PROP_OR(idx, UTIL_CAT(divider_int_, n), 0), \
199212
.frac = DT_INST_PROP_OR(idx, UTIL_CAT(divider_frac_, n), 0), \
@@ -206,14 +219,7 @@ static int pwm_rpi_init(const struct device *dev)
206219
.pwm_controller = (pwm_hw_t *)DT_INST_REG_ADDR(idx), \
207220
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(idx), \
208221
.slice_configs = { \
209-
PWM_INST_RPI_SLICE_DIVIDER(idx, 0), \
210-
PWM_INST_RPI_SLICE_DIVIDER(idx, 1), \
211-
PWM_INST_RPI_SLICE_DIVIDER(idx, 2), \
212-
PWM_INST_RPI_SLICE_DIVIDER(idx, 3), \
213-
PWM_INST_RPI_SLICE_DIVIDER(idx, 4), \
214-
PWM_INST_RPI_SLICE_DIVIDER(idx, 5), \
215-
PWM_INST_RPI_SLICE_DIVIDER(idx, 6), \
216-
PWM_INST_RPI_SLICE_DIVIDER(idx, 7), \
222+
LISTIFY(PWM_RPI_PICO_NUM_SLICES, PWM_INST_RPI_SLICE_DIVIDER, (,), idx) \
217223
}, \
218224
.reset = RESET_DT_SPEC_INST_GET(idx), \
219225
.clk_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(idx)), \

dts/bindings/pwm/raspberrypi,pico-pwm.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,38 @@ properties:
8787
type: int
8888
description: See divider-frac-0 for help
8989

90+
divider-int-8:
91+
type: int
92+
description: See divider-int-0 for help
93+
94+
divider-frac-8:
95+
type: int
96+
description: See divider-frac-0 for help
97+
98+
divider-int-9:
99+
type: int
100+
description: See divider-int-0 for help
101+
102+
divider-frac-9:
103+
type: int
104+
description: See divider-frac-0 for help
105+
106+
divider-int-10:
107+
type: int
108+
description: See divider-int-0 for help
109+
110+
divider-frac-10:
111+
type: int
112+
description: See divider-frac-0 for help
113+
114+
divider-int-11:
115+
type: int
116+
description: See divider-int-0 for help
117+
118+
divider-frac-11:
119+
type: int
120+
description: See divider-frac-0 for help
121+
90122
"#pwm-cells":
91123
const: 3
92124

include/zephyr/dt-bindings/pinctrl/rpi-pico-rp2350b-pinctrl.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@
7979
#define PWM_10B_P37 RP2XXX_PINMUX(37, RP2_PINCTRL_GPIO_FUNC_PWM)
8080
#define PWM_11A_P38 RP2XXX_PINMUX(38, RP2_PINCTRL_GPIO_FUNC_PWM)
8181
#define PWM_11B_P39 RP2XXX_PINMUX(39, RP2_PINCTRL_GPIO_FUNC_PWM)
82-
#define PWM_12A_P40 RP2XXX_PINMUX(40, RP2_PINCTRL_GPIO_FUNC_PWM)
83-
#define PWM_12B_P41 RP2XXX_PINMUX(41, RP2_PINCTRL_GPIO_FUNC_PWM)
84-
#define PWM_13A_P42 RP2XXX_PINMUX(42, RP2_PINCTRL_GPIO_FUNC_PWM)
85-
#define PWM_13B_P43 RP2XXX_PINMUX(43, RP2_PINCTRL_GPIO_FUNC_PWM)
86-
#define PWM_14A_P44 RP2XXX_PINMUX(44, RP2_PINCTRL_GPIO_FUNC_PWM)
87-
#define PWM_14B_P45 RP2XXX_PINMUX(45, RP2_PINCTRL_GPIO_FUNC_PWM)
88-
#define PWM_15A_P46 RP2XXX_PINMUX(46, RP2_PINCTRL_GPIO_FUNC_PWM)
89-
#define PWM_15B_P47 RP2XXX_PINMUX(47, RP2_PINCTRL_GPIO_FUNC_PWM)
82+
#define PWM_8A_P40 RP2XXX_PINMUX(40, RP2_PINCTRL_GPIO_FUNC_PWM)
83+
#define PWM_8B_P41 RP2XXX_PINMUX(41, RP2_PINCTRL_GPIO_FUNC_PWM)
84+
#define PWM_9A_P42 RP2XXX_PINMUX(42, RP2_PINCTRL_GPIO_FUNC_PWM)
85+
#define PWM_9B_P43 RP2XXX_PINMUX(43, RP2_PINCTRL_GPIO_FUNC_PWM)
86+
#define PWM_10A_P44 RP2XXX_PINMUX(44, RP2_PINCTRL_GPIO_FUNC_PWM)
87+
#define PWM_10B_P45 RP2XXX_PINMUX(45, RP2_PINCTRL_GPIO_FUNC_PWM)
88+
#define PWM_11A_P46 RP2XXX_PINMUX(46, RP2_PINCTRL_GPIO_FUNC_PWM)
89+
#define PWM_11B_P47 RP2XXX_PINMUX(47, RP2_PINCTRL_GPIO_FUNC_PWM)
9090

9191
#define PIO0_P30 RP2XXX_PINMUX(30, RP2_PINCTRL_GPIO_FUNC_PIO0)
9292
#define PIO0_P31 RP2XXX_PINMUX(31, RP2_PINCTRL_GPIO_FUNC_PIO0)

0 commit comments

Comments
 (0)