1# Copyright (c) 2022 Espressif Systems (Shanghai) Co., Ltd. 2# SPDX-License-Identifier: Apache-2.0 3 4description: | 5 6 Espressif's Motor Control Pulse Width Modulator (MCPWM) controller Node 7 8 The MCPWM peripheral is intended for motor and power control. 9 It provides six PWM outputs that can be set up to operate in several topologies 10 11 ESP32 contains two MCPWM peripherals: MCPWM0 and MCPWM1 12 13 Each MCPWM peripheral has one clock divider (prescaler), three PWM timers, three PWM operators, 14 and a capture module. 15 16 Every PWM operator has two PWM outputs: PWMxA and PWMxB. They can work independently, in symmetric 17 and asymmetric configuration. MCPWMxA and MCPWMxB will share the same timer, thus having the same 18 operating frequency. 19 20 The driver currently always use the timer x for operator x. Timer 0 will use operator 0 for 21 PWM0A/B. 22 Timer 1 will use operator 1 for PWM1A/B, and so on. 23 24 Mapping channel ID: 25 Channel 0 -> Timer 0, Operator 0, output PWM0A 26 Channel 1 -> Timer 0, Operator 0, output PWM0B 27 Channel 2 -> Timer 1, Operator 1, output PWM1A 28 Channel 3 -> Timer 1, Operator 1, output PWM1B 29 Channel 4 -> Timer 2, Operator 2, output PWM2A 30 Channel 5 -> Timer 2, Operator 2, output PWM2B 31 Channel 6 -> Capture 0 32 Channel 7 -> Capture 1 33 Channel 8 -> Capture 2 34 35 Example: Use PWM0A output and capture 0: 36 37 pwm_loopback_0 { 38 compatible = "test-pwm-loopback"; 39 pwms = <&mcpwm0 0 0 PWM_POLARITY_NORMAL>, #Channel 0 -> Output PWM0A 40 <&mcpwm0 6 0 PWM_POLARITY_NORMAL>; #Channel 6 -> Capture 0; 41 }; 42 43 The mapping between the output PWMxA/B or CaptureX and GPIO is done through pinctrl: 44 45 &mcpwm0 { 46 pinctrl-0 = <&mcpwm0_default>; 47 pinctrl-names = "default"; 48 } 49 50 The 'mcpwm0_default' node is defined inside the pinctrl node. 51 52 &pinctrl { 53 mcpwm0_default: mcpwm0_default { 54 group1 { 55 pinmux = <MCPWM0_OUT0A_GPIO0>, 56 <MCPWM0_OUT0B_GPIO2>, 57 <MCPWM0_OUT1A_GPIO4>; 58 output-enable; 59 }; 60 group2 { 61 pinmux = <MCPWM0_CAP0_GPIO5>; 62 }; 63 }; 64 }; 65 66 Note: Check espressif,esp32-pinctrl.yaml for complete documentation regarding pinctrl. 67 68 Use the prescale-timerX property to configure the timers: 69 70 &mcpwm0 { 71 pinctrl-0 = <&mcpwm0_default>; 72 pinctrl-names = "default"; 73 prescale = <255>; 74 prescale-timer0 = <103>; 75 prescale-timer1 = <0>; 76 prescale-timer2 = <255>; 77 status = "okay"; 78 }; 79 80compatible: "espressif,esp32-mcpwm" 81 82include: [pwm-controller.yaml, pinctrl-device.yaml, base.yaml] 83 84properties: 85 prescale: 86 type: int 87 required: true 88 description: | 89 8 bit timer prescale for the global clock. 90 Period of PWM_clk = 6.25ns * (PWM_CLK_PRESCALE + 1). 91 92 "#pwm-cells": 93 const: 3 94 95 prescale-timer0: 96 type: int 97 description: | 98 8 bit timer prescale for timer 0. 99 Period of PT0_clk = Period of PWM_clk * (PWM_TIMER0_PRESCALE + 1). 100 101 prescale-timer1: 102 type: int 103 description: | 104 8 bit timer prescale for timer 1. 105 Period of PT1_clk = Period of PWM_clk * (PWM_TIMER1_PRESCALE + 1). 106 107 prescale-timer2: 108 type: int 109 description: | 110 8 bit timer prescale for timer 2. 111 Period of PT2_clk = Period of PWM_clk * (PWM_TIMER2_PRESCALE + 1). 112 113pwm-cells: 114 - channel 115 - period 116 - flags 117