Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions drivers/pwm/pwm_rpi_pico.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,21 @@ LOG_MODULE_REGISTER(pwm_rpi_pico, CONFIG_PWM_LOG_LEVEL);
#include <hardware/pwm.h>
#include <hardware/structs/pwm.h>

/*
* pico-sdk defines PWM_NUM_SLICES with a 'u' suffix for unsigned, which
* doesn't work with LISTIFY later on in this file.
*/
#ifdef CONFIG_SOC_SERIES_RP2350
#define PWM_RPI_PICO_NUM_SLICES 12
#else
#define PWM_RPI_PICO_NUM_SLICES 8
#endif
BUILD_ASSERT(NUM_PWM_SLICES == PWM_RPI_PICO_NUM_SLICES,
"PWM_RPI_PICO_NUM_SLICES misconfigured for SOC");

#define PWM_RPI_PICO_COUNTER_TOP_MAX UINT16_MAX
#define PWM_RPI_NUM_CHANNELS (16U)
#define PWM_RPI_NUM_CHANNELS (2 * NUM_PWM_SLICES)


struct pwm_rpi_slice_config {
uint8_t integral;
Expand Down Expand Up @@ -193,7 +206,7 @@ static int pwm_rpi_init(const struct device *dev)
return 0;
}

#define PWM_INST_RPI_SLICE_DIVIDER(idx, n) \
#define PWM_INST_RPI_SLICE_DIVIDER(n, idx) \
{ \
.integral = DT_INST_PROP_OR(idx, UTIL_CAT(divider_int_, n), 0), \
.frac = DT_INST_PROP_OR(idx, UTIL_CAT(divider_frac_, n), 0), \
Expand All @@ -206,14 +219,7 @@ static int pwm_rpi_init(const struct device *dev)
.pwm_controller = (pwm_hw_t *)DT_INST_REG_ADDR(idx), \
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(idx), \
.slice_configs = { \
PWM_INST_RPI_SLICE_DIVIDER(idx, 0), \
PWM_INST_RPI_SLICE_DIVIDER(idx, 1), \
PWM_INST_RPI_SLICE_DIVIDER(idx, 2), \
PWM_INST_RPI_SLICE_DIVIDER(idx, 3), \
PWM_INST_RPI_SLICE_DIVIDER(idx, 4), \
PWM_INST_RPI_SLICE_DIVIDER(idx, 5), \
PWM_INST_RPI_SLICE_DIVIDER(idx, 6), \
PWM_INST_RPI_SLICE_DIVIDER(idx, 7), \
LISTIFY(PWM_RPI_PICO_NUM_SLICES, PWM_INST_RPI_SLICE_DIVIDER, (,), idx) \
}, \
.reset = RESET_DT_SPEC_INST_GET(idx), \
.clk_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(idx)), \
Expand Down
36 changes: 36 additions & 0 deletions dts/bindings/pwm/raspberrypi,pico-pwm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,42 @@ properties:
type: int
description: See divider-frac-0 for help

divider-int-8:
type: int
description: |
See divider-int-0 for help, however this PWM slice is not available on
RP2040.

divider-frac-8:
type: int
description: |
See divider-frac-0 for help, however this PWM slice is not available on
RP2040.

divider-int-9:
type: int
description: See divider-int-8 for help

divider-frac-9:
type: int
description: See divider-frac-8 for help

divider-int-10:
type: int
description: See divider-int-8 for help

divider-frac-10:
type: int
description: See divider-frac-8 for help

divider-int-11:
type: int
description: See divider-int-8 for help

divider-frac-11:
type: int
description: See divider-frac-8 for help

"#pwm-cells":
const: 3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#define RP2_ALT_FUNC_MASK 0xf

#define RP2_PIN_NUM_POS 5
#define RP2_PIN_NUM_MASK 0x1f
#define RP2_PIN_NUM_MASK 0x3f

#define RP2_GPIO_OVERRIDE_NORMAL 0
#define RP2_GPIO_OVERRIDE_INVERT 1
Expand Down
16 changes: 8 additions & 8 deletions include/zephyr/dt-bindings/pinctrl/rpi-pico-rp2350b-pinctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@
#define PWM_10B_P37 RP2XXX_PINMUX(37, RP2_PINCTRL_GPIO_FUNC_PWM)
#define PWM_11A_P38 RP2XXX_PINMUX(38, RP2_PINCTRL_GPIO_FUNC_PWM)
#define PWM_11B_P39 RP2XXX_PINMUX(39, RP2_PINCTRL_GPIO_FUNC_PWM)
#define PWM_12A_P40 RP2XXX_PINMUX(40, RP2_PINCTRL_GPIO_FUNC_PWM)
#define PWM_12B_P41 RP2XXX_PINMUX(41, RP2_PINCTRL_GPIO_FUNC_PWM)
#define PWM_13A_P42 RP2XXX_PINMUX(42, RP2_PINCTRL_GPIO_FUNC_PWM)
#define PWM_13B_P43 RP2XXX_PINMUX(43, RP2_PINCTRL_GPIO_FUNC_PWM)
#define PWM_14A_P44 RP2XXX_PINMUX(44, RP2_PINCTRL_GPIO_FUNC_PWM)
#define PWM_14B_P45 RP2XXX_PINMUX(45, RP2_PINCTRL_GPIO_FUNC_PWM)
#define PWM_15A_P46 RP2XXX_PINMUX(46, RP2_PINCTRL_GPIO_FUNC_PWM)
#define PWM_15B_P47 RP2XXX_PINMUX(47, RP2_PINCTRL_GPIO_FUNC_PWM)
#define PWM_8A_P40 RP2XXX_PINMUX(40, RP2_PINCTRL_GPIO_FUNC_PWM)
#define PWM_8B_P41 RP2XXX_PINMUX(41, RP2_PINCTRL_GPIO_FUNC_PWM)
#define PWM_9A_P42 RP2XXX_PINMUX(42, RP2_PINCTRL_GPIO_FUNC_PWM)
#define PWM_9B_P43 RP2XXX_PINMUX(43, RP2_PINCTRL_GPIO_FUNC_PWM)
#define PWM_10A_P44 RP2XXX_PINMUX(44, RP2_PINCTRL_GPIO_FUNC_PWM)
#define PWM_10B_P45 RP2XXX_PINMUX(45, RP2_PINCTRL_GPIO_FUNC_PWM)
#define PWM_11A_P46 RP2XXX_PINMUX(46, RP2_PINCTRL_GPIO_FUNC_PWM)
#define PWM_11B_P47 RP2XXX_PINMUX(47, RP2_PINCTRL_GPIO_FUNC_PWM)

#define PIO0_P30 RP2XXX_PINMUX(30, RP2_PINCTRL_GPIO_FUNC_PIO0)
#define PIO0_P31 RP2XXX_PINMUX(31, RP2_PINCTRL_GPIO_FUNC_PIO0)
Expand Down
4 changes: 2 additions & 2 deletions soc/raspberrypi/rpi_pico/common/pinctrl_soc.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* @brief Type to hold a pin's pinctrl configuration.
*/
struct rpi_pinctrl_soc_pin {
/** Pin number 0..29 */
uint32_t pin_num: 5;
/** Pin number 0..29 on RP2040, 0..47 on RP2350 */
uint32_t pin_num: 6;
/** Alternative function (UART, SPI, etc.) */
uint32_t alt_func: 5;
/** Maximum current used by a pin, in mA */
Expand Down