PWM on Rock3

I have been messing with enabling PWM via Device Tree Overlays and I notice that Rockchip has a module rk_pwm for thier gear.

What I have observed is that Rock4 overlays work fine. 4 PWN pins available on all Rock4 via the official overlays:

To be specific I have tested these successfully on Rock4:
rk3399-pwm0.dts
rk3399-pwm1.dts
rk3399-pwm2.dts


But when I try and enable PWM on Rock3A/C/E boards I get nothing. I have tried via overlays and brute force editing decompiled DTB.

Is anybody using PWM on RK356X?

Any tips? I have rk_pwm in my kernel. I have also tested with default aarch64 ROCKPRO64 FreeBSD 14.1-RELEASE image with no sucess.

Am I missing something?

I tested with PWM8.PWM9,PWM13,PWM14,PWM15 pin muxes.
 
only these have fbsd support
static struct ofw_compat_data compat_data[] = {
{ "rockchip,rk3288-pwm", 1 },
{ "rockchip,rk3399-pwm", 1 },
{ NULL, 0 }
};
dtb wants compatible = "rockchip,rk3568-pwm", "rockchip,rk3328-pwm";
this is on opi3
 
looking at linux src it seems there are no diffs besides 3328 has support for polarity/locking and 3288 has not
it may work if you hack the dts to rockchip,rk3288-pwm
 
rk_pwm even mentions rk356x so I think I am missing something simple.

On rk3399 I have one pwm node without any overlays. I add the three above overlays and I end up with 4 pwm nodes.
Not sure they work yet.
A common mod is to add fan. So maybe one pwm enababled by default.

I have found the Rock3/rk3568 dtb contains all the needed PWM nodes. They are set to disabled. So enabling them is all that is needed.
In the old days you had to stab in the node in the proper spot. So this should be easy.

it may work if you hack the dts to rockchip,rk3288-pwm
It seems sometimes overlays use compatible = and sometimes they don't. I am still learning.

Radxa ovelays carry the top part a little far.
Code:
 {
    metadata {
        title = "Enable PWM2-M0";
        compatible = "radxa,rock-3a", "radxa,rock-3b";
        category = "misc";
        exclusive = "GPIO0_C1";
        description = "Enable PWM2-M0.
On Radxa ROCK 3A <= v1.2 this is pin 17.
On Radxa ROCK 3A >= v1.3 this is pin 22.
On Radxa ROCK 3B this is pin 22.";
    };
 
those are just some metadata extensions
the dts should have something like
Code:
        pwm@fdd70000 {

                compatible = "rockchip,rk3568-pwm", "rockchip,rk3328-pwm";
                reg = <0x0 0xfdd70000 0x0 0x10>;
                clocks = <0x1f 0xd 0x1f 0x30>;
                clock-names = "pwm", "pclk";
                pinctrl-0 = <0x177>;
                pinctrl-names = "default";
                #pwm-cells = <0x3>;
                status = "disabled";
                phandle = <0x34>;
        };
you need to adjust the compatible line there
and maybe the status if the overlay does not do it
 
I am trying for PWM on pin PWM14_m0 to start with.
Address is pwm@fe700020

My rough try:
Code:
/dts-v1/;
/plugin/;

/ {
    compatible =  "radxa,rock-3a","radxa,rock-3c", "radxa,zero3";
    exclusive = "GPIO3_C4";
};
&pwm14 {
    status = "okay";
    pinctrl-names = "active";
    pinctrl-0 = <&pwm14m0_pins>;
}
###&{/pwm@fe700020} {
###    status = "enabled"

The Radxa overlay seems to include the pinmux stuff with pinctl. That is what I am emulating here.

Here is snips of where it needs to go in decompiled dtb:

Code:
            pwm13m0-pins {

                rockchip,pins = <0x3 0x10 0x2 0xb1>;
                phandle = <0xa8>;
            };
        };
        pwm14 {

            pwm14m0-pins {

                rockchip,pins = <0x3 0x14 0x1 0xb1>;
                phandle = <0xa9>;
            };
        };
        pwm15 {

            pwm15m0-pins {

                rockchip,pins = <0x3 0x15 0x1 0xb1>;
                phandle = <0xaa>;

Let me try and write a DTS from your above work and my needed addresses/phandle.

Thanks for helping covacat .
 
Overlay Help:

Code:
/dts-v1/;
/plugin/;
/ {
    compatible =  "radxa,rock-3a","radxa,rock-3c", "radxa,zero3";
    exclusive = "GPIO3_C4";
};
&{/pwm14}

            pwm14m0-pins {
                compatible = "rockchip,rk3568-pwm", "rockchip,rk3328-pwm";
                reg = <0x0 0xfe700020 0x0 0x10>;
                clocks = <0x3 0x14 0x1 0xb1>;
                clock-names = "pwm", "pclk";
                pinctrl-0 = <0x177>;
                pinctrl-names = "default";
                #pwm-cells = <0x3>;
                status = "okay";
                phandle = <0xa9>;
}

So from my understanding we need to create a code structure that will reside under the existing node correct?

Do I need 'status=okay' under both 'pwm14 node' and 'pwm14m0 node' ? It is a tree structure.

Not sure if everything goes under pwm14m0-pins section or where it goes...
 
I noticed that the RK3399 Rock4A has a different structure from the decompiled DTB.
Code:
    pwm@ff420000 {

                compatible = "rockchip,rk3399-pwm", "rockchip,rk3288-pwm";
                reg = <0x0 0xff420000 0x0 0x10>;
                #pwm-cells = <0x3>;
                pinctrl-names = "default";
                pinctrl-0 = <0x8a>;
                clocks = <0x7b 0x1e>;
                status = "disabled";
                phandle = <0x108>;


For my overlay I decided to go the "fragment" method for overlay. Still not working.

Code:
/dts-v1/;
/plugin/;
/ {
        fragment@0 {
                target-path = <&pwm14m0-pins>;
                __overlay__ {
                        compatible = "rockchip,rk3568-pwm", "rockchip,rk3328-pwm
                        pinctrl-names = "active";
                        pinctrl-0 = <&pwm14m0_pins>;
                        status = "okay";
                };
        };
};
 
What a mess. I decided to check Armbian to see if they had PWM under "Aliases" under the DTB and they did not.

So then I checked Radxa Debian and I see their u-boot had a PWM command.

It made me start looking and sure enough my Rock3C u-boot .config file did not have PWM enabled.
# CONFIG_PWM_ROCKCHIP is not set
Whereas on Rock4 u-boot build .config file:
CONFIG_PWM_ROCKCHIP=y

So I need to back up even more...

Figure out which PWM options that Radxa Linux build uses for Rock3C u-boot.

I have blown enough things up to just go turning on things:
# CONFIG_REGULATOR_PWM is not set
And the RockPi 4 setting:
CONFIG_REGULATOR_PWM=y
 
I found different level of u-boot support for PWM on Rock 3.

Rock 3E has "CONFIG_DM_PWM=y". That is u-boot PWM 'device model'.

Rock 3A has CONFIG_DM_PWM=y and CONFIG_PWM_ROCKCHIP=y

Rock 3C has no PWM settings enabled at all.

For PWM settings there is also a CONFIG_CMD_PWM= that gives you a PWM command in u-boots shell.

None of my PWM overlays work. I even tried Armbian DTB as it is larger in size. When I tried Raxda Linux DTB it hangs at boot.
That is the only DTB that contains the 'Aliases' for PWM.

So I give up. On to other pins... Use Rock Pi4 for PWM projects.
 
Back
Top