MartinKeppler Posted August 15, 2016 Posted August 15, 2016 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
Thomas Posted August 17, 2016 Posted August 17, 2016 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>; };
MartinKeppler Posted August 17, 2016 Author Posted August 17, 2016 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
zador.blood.stained Posted August 17, 2016 Posted August 17, 2016 @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. 1
MartinKeppler Posted August 17, 2016 Author Posted August 17, 2016 Ok, after adding the section into source, do I have it to compile with the dtc? Could you tell me where I can get the source, please. The sun7i-a20-bananapi.dts is not on my board neither any other.
zador.blood.stained Posted August 17, 2016 Posted August 17, 2016 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 2
MartinKeppler Posted August 17, 2016 Author Posted August 17, 2016 Hi, thanks a lot. It worked. Now with echo 0 > /sys/class/pwm/pwmchip0/export I got a pwm0 with duty_cycle, enable, periode, polarity, power and uevent. Your really great!!!! I'm so happy!!!!
zador.blood.stained Posted August 17, 2016 Posted August 17, 2016 (edited) Keep in mind that if you upgrade the kernel you will loose these changes. You can use something like apt-mark hold linux-image-next-sunxi apt-mark hold linux-dtb-next-sunxi to prevent kernel upgrade or just redo this procedure after each Armbian kernel update Edited August 17, 2016 by zador.blood.stained Typo 3
MartinKeppler Posted August 17, 2016 Author Posted August 17, 2016 He, thats good to know. Thanks for preventing me from new troubles!
MartinKeppler Posted August 24, 2016 Author Posted August 24, 2016 Guys, many thanks to you! PWM now is working again. Martin
Recommended Posts