Using pwm without rebuilding kernel


Recommended Posts

Hi Folks,

 

I installed armbian Jessie with Desktop and Kernel 4.6.3 on my Banana Pi. I'm glad to see, that most of modules I need are installed and working properly. Good job, thanks!

But there is one little problem I've got with the kernel. I need pwm (Pin PB2) to control the backlight of my LCD. With Bananian I used sunxi-pwm modul. Worked fine, but isn't installed in the kernel 4.6.3. I know there are ways to build it into the kernel. But befor I'll build an own kernel, I'm hoping of an other way to make pwm for backlight working again. I saw an pwm folder at /sys/class/pwm and also pwm-sun4i modul can be loaded. Unfortunately /sys/class/pwm is empty and stays empty even when I load pwm-sun4i. In the devicetree I can see a pwm device: /sys/firmware/devicetree/base/soc@01c00000/pwm@01c20e00.

 

Has anyone an Idea how I can pwm make working with this System?

 

Yours Martin

Link to post
Share on other sites
Donate and support the project!

You can modify /boo/dtb/*Banana*.dtb

use tool dtc extract *dtb to dos : sudo dtc -I dtb -O dts your_board.dtb -o your_borad.dts

open dos, and find 'pwm@'

 

like this 

                pwm@01c20e00 {
                        compatible = "allwinner,sun7i-a20-pwm";
                        reg = <0x1c20e00 0xc>;
                        clocks = <0xb>;
                        #pwm-cells = <0x3>;
                        status = "okay";
                        pinctrl-names = "default";
                        pinctrl-0 = <0x35 0x36>;
                };
 

 

 

Link to post
Share on other sites

Hi Thomas,

 

did it with your code snippet. I gues the pinctrl-0 musst be the  GPIO - number or the address of the PWM - Pin. So I need the pin PB02 --> GPIO34 --> 0x22. Is that correct?

I tried with 0x35 0x36 and also with 0x22. Don't get any content in /sys/class/pwm. 

Is there more to do?

 

Martin

Link to post
Share on other sites

@MartinKeppler

 

It's easier to recompile DT file for your board and kernel version from sources, adding this section

&pwm {
	pinctrl-names = "default";
	pinctrl-0 = <&pwm0_pins_a>, <&pwm1_pins_a>;
	status = "okay";
};

for example, after &pio section. Check sun7i-a20-cubietruck.dts for example - loading sun4i-pwm on cubietruck with mainline kernel adds new entries to /sys/class/pwm.

 

Numbers like 0xb, 0x35 and 0x36 are phandles and they are specific to decompiled sources, you can't copy-paste them from one decompiled DT to another.

Link to post
Share on other sites

You need to clone https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git

Then checkout tag v4.6.3 (or v4.6.7, doesn't matter)

To minimize download time you can do it like this:

mkdir kernel
cd kernel
git init .
git remote add origin "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git"
git fetch --depth 1 origin tags/v4.6.7
git checkout -f FETCH_HEAD 

Then edit arch/arm/boot/dts/sun7i-a20-bananapi.dts to include changes from my previous post

After that, if you are doing this on the board, run in the top directory of kernel source tree

cp /boot/config-`uname -r` .config
make ARCH=arm dtbs

after the process is finished, you should get compiled DT file arch/arm/boot/dts/sun7i-a20-bananapi.dtb

Link to post
Share on other sites
Guest
This topic is now closed to further replies.