# Setting up the new PWM driver



## Phishfry (Sep 21, 2022)

Has anyone got PWM working on Intel GPIO?

I see a new driver went into FreeBSD 13.
Also a new pwmbus driver.





						pwm(8)
					






					www.freebsd.org
				




I have BananaPi-M1 with PWM along with the UpBoard Z8350 showing PWM pins enabled in BIOS.

How does this stuff work? On BeagleBone is was a matter of DTS editing to enable.
Then sysctl nodes showed.

I am not sure where to start?

Are most all hardware PWM pins supported or is this just for Arm?
BPi A20 has support along with the UpBoard1.
That is my launching pad.

Help. Show me the way or an example.

`pwm -f /dev/pwm/pwmc0.1 -C`
How do I get a pwm device node?

loader.conf?
pwm_load="YES"
pwmbus-load="YES"

Hand load first and see what shows up?

What platform is supported with pwmbus?


----------



## SirDice (Sep 21, 2022)

Man page link refers to the manual page of x11-wm/pwm. The only correct man page I could find is pwmbus(9) and pwm(9). That talks of a `device pwm`, so try `pwm_load="YES"`. On my 13-STABLE I also have a pwm(8).

Oh, clicking around, found the device: pwmc(4), so it's `pwmc_load="YES"`.


----------



## Phishfry (Sep 21, 2022)

Fixed the above manpage path.

I did  miss pwmc(4) manpage and that was the low level code I need to read.

The FDT example looks straight out of BBB stuff I did earlier.
So that is nice not to have to relearn something.


----------



## Phishfry (Sep 25, 2022)

I have the BeagleBone PWM working on four channels with FreeBSD 13-RELEASE.
I am leaving off where I last left off. Now maybe I can try some other platforms with PWM.

Thanks to @ians writings I used labels for each channel.


```
# ls /dev/pwm
ChannelA    ChannelB    ChannelC    ChannelD    pwmc0.0        pwmc0.1        pwmc1.0        pwmc1.1
```


```
# pwm -f pwmc0.0 -E -p 50000 -d 25000

# pwm -f ChannelA -C
period: 50000
duty: 25000
enabled:1
inverted:0
```


----------



## Phishfry (Sep 25, 2022)

Here are FDT Overlay files for pwm0 and pwm1. Feel free to change the labels to suit your application.

/boot/dtb/overlays/pwm0.dtso

```
/dts-v1/;
/plugin/;

/ {
    compatible = "ti,am335x-bone-black", "ti,am335x-bone", "ti,am33xx";
    exclusive-use = "P9.21","P9.22","ehrpwm0_AB";
};

&am33xx_pinmux {
    ehrpwm0_AB_pins: pinmux_ehrpwm0_AB_pins {
        pinctrl-single,pins = <
            0x154 0x03 /* P9.21 */
            0x150 0x03 /* P9.22 */
        >;
    };
};

&ehrpwm0 {
    status = "okay";
    pinctrl-names = "default";
    pinctrl-0 = <&ehrpwm0_AB_pins>;

    pwmcontrol@0 {
        compatible = "freebsd,pwmc";
        reg = <0>;
        label = "ChannelA";
    };

    pwmcontrol@1 {
        compatible = "freebsd,pwmc";
        reg = <1>;
    label = "ChannelB";
    };
};

&epwmss0 {
    status = "okay";
};

&ecap0 {
    status = "okay";
};
```

Here is an overlay for PWM 1
/boot/dtb/overlays/pwm1.dtso


```
/dts-v1/;
/plugin/;

/ {
    compatible = "ti,am335x-bone-black", "ti,am335x-bone", "ti,am33xx";
    exclusive-use = "P9.14","P9.16","ehrpwm1_AB";
};

&am33xx_pinmux {
    ehrpwm1_AB_pins: pinmux_ehrpwm1_AB_pins {
        pinctrl-single,pins = <
            0x048 0x06 /* P9.14 */
            0x04C 0x06 /* P9.16 */
        >;
    };
};

&ehrpwm1 {
    status = "okay";
    pinctrl-names = "default";
    pinctrl-0 = <&ehrpwm1_AB_pins>;

    pwmcontrol@0 {
        compatible = "freebsd,pwmc";
        reg = <0>;
        label = "ChannelC";
    };

    pwmcontrol@1 {
        compatible = "freebsd,pwmc";
        reg = <1>;
    label = "ChannelD";
    };
};

&epwmss1 {
    status = "okay";
};

&ecap1 {
    status = "okay";
};
```
Now you have to compile them.
`cd /boot/dtb/overlays`
`dtc -I dts -O dtb -b0 -@ -o pwm0.dtbo pwm0.dtso`
`dtc -I dts -O dtb -b0 -@ -o pwm1.dtbo pwm1.dtso`

Then add then your PWM overlays to your loader.
/boot/loader.conf

```
fdt_overlays="pwm0.dtbo,pwm1.dtbo"
pwmc_load="YES"
```

That enables 4 channels of PWM on Beaglebone


----------



## Phishfry (Sep 27, 2022)

I have had no luck on the MinnowBoard Max with the pwm driver. Upboard1 failed too.

I even tried to use hints to coax the pwm controller device out.
The hints in the pwmc(4) manual say this:
_hint.pwmc.%d.at_
So I tried various incarnations with no luck.
From the device.hints(5) manpage it should have an = sign at end?
hint._driver_._unit_._keyword_="_value_"
So
hint.pwmc.0.at=??
I tried without "value" and it doesn't take.
I feel like I am missing something there. Forcing things with hints only carries so far.

Moving on to other Arm platforms. MBM and UpBoard failed to produce pwm devices.
Maybe GPIO driver for them does not support PWM I dunno. Need to test more boards.


----------

