Linux kernel porting based on tiny4412--PWM Subsystem Learning (vii)

Source: Internet
Author: User

Author Information

Author: Pengdonglin

Email: [email protected]

qq:405728433

Platform Introduction

Development Board: TINY4412ADK + S700 + 4GB Flash

Kernel version to port: Linux-4.4.0 (Support device tree)

U-boot version: Friendly arm comes with U-boot 2010.12 (for support uimage boot, made a little change)

BusyBox version: BusyBox 1.25

Cross-compilation Toolchain: ARM-NONE-LINUX-GNUEABI-GCC

(gcc version 4.8.3 20140320 (prerelease) (Sourcery codebench Lite 2014.05-29))

Overview

Exynos4412 can output a total of 4 PWM (Timer0, Timer1, Timer2, Timer3 generated PWM has the corresponding output pin, timer4 no corresponding pin), However, only two PWM leads on the tiny4412 are available for off-chip peripherals, respectively, from Timer0 and timer1, where TIMER0 output PWM0 is used to control the active buzzer (TMB12A05) on the backplane, The PWM1 produced by the timer1 is used to control the backlight brightness of the LCD.

Core board:

Backplane (Active buzzer):

Backplane (LCD backlight):

Let's take a PWM control buzzer as an example to learn about the PWM subsystem and the backlight subsystem.

experiment one, using PWM to control the buzzer on the Board

Modify the device tree file Arch/arm/boot/dts/exynos4412-tiny4412.dts

   1: diff--git A/arch/arm/boot/dts/exynos4412-tiny4412.dts b/arch/arm/boot/dts/ Exynos4412-tiny4412.dts
   2: index 585CAB7. 0425200 100644
   3: ---A/arch/arm/boot/dts/exynos4412-tiny4412.dts
   4: + + + B/arch/arm/boot/dts/exynos4412-tiny4412.dts
   5 : @@ -123,6 +123,13 @@
   6:      cap-mmc-highspeed;
   7:  };
   8:  
   9: +&PWM {
  Ten: +    pinctrl-0 = <&pwm0_out &pwm1_out>;
One   : +    "Default";
  : +    samsung,pwm-outputs = <0>, <1>;
+   : +    "Okay";
  : +};
  : +
  :  &serial_0 {
  :      "Okay";
  :  };

The pinctrl-0 parameter is used to set the use of the Gpio reuse function, pwm0_out is defined in the Arch/arm/boot/dts/exynos4x12-pinctrl.dtsi:

   1: pwm0_out:pwm0-out {
   2:     "gpd0-0";
   3:     samsung,pin-function = <2>;
   4:     samsung,pin-pud = <0>;
   5:     samsung,pin-drv = <0>;
   6: };

What does it mean to set the function multiplexing of the GPIOD0_0 pin setting to 2,2? For Samsung:

Here the 2 is set to Tout_0, which is the PWM0 pulse output pin. The same can understand the meaning of pwm1_out.

The parameters after samsung,pwm_outs indicate that only PWM0 and PWM1 can be used for board-level peripherals, and the parsing process can refer to the driver.

Where PWM is in Arch/arm/boot/dts/exynos4.dtsi

   1: PWM: [email protected] {
   2:     "SAMSUNG,EXYNOS4210-PWM";
   3:     reg = <0x139d0000 0x1000>;
   4:     interrupts = <0 Notoginseng 0> <0 0> <0 0> <0 0> <0 0>;
   5:     clocks = <&clock clk_pwm>;
   6:     "Timers";
   7:     #pwm-cells = <3>;
   8:     "Disabled";
   9: };

To recompile the device tree:

Make Dtbs

Boot the kernel with a new device tree image

[Email protected]]# cd/sys/class/pwm/
[[email protected] pwm]# ls
Pwmchip0
[Email protected] pwm]# CD pwmchip0/
[[email protected] pwmchip0]# ls
Device     export     NPWM       Power      subsystem  uevent     unexport

The pwmchip0,pwm0-3 that are registered in/SYS/CLASS/PWM correspond to this pwmchip0 and are created by calling the Pwmchip_add function.

[[email protected] pwmchip0]# ls
Device     export     NPWM       Power      subsystem  uevent     unexport
5
Export
[[email protected] pwmchip0]# ls
Device     NPWM       pwm0       uevent
Export     Power      Subsystem  Unexport
[Email protected] pwmchip0]# CD pwm0/
[[email protected] pwm0]# ls
Duty_cycle  enable      period      polarity    power       uevent

NPWM means the number of PWM channels supported by Exynos4412 (this value is set to 5 in the driver, and the Timer4 is also included). The buzzer corresponds to the PWM0, so we write 0 to export, and then we create a new directory named PWM0 in the current directory, which is the configuration file that sets the PWM0 parameter.

Under the PWM0 directory:

Polarity: Accepts normal or inversed two parameters, indicating tout_0 level reversal; In the exynos4412 User manual, section 24th:

Period: Indicates the period of PWM Wave (unit: nanosecond);

Duty_cycle: In normal Mode, indicates the duration of the high level in a period (in nanoseconds), so duty_cycle <= period; in reversed mode, indicates the duration of the low level in a period (in nanoseconds);

Enable: Write 1 to the start PWM, write 0, which means to turn off the PWM;

For more information, refer to the kernel documentation: Documentation/pwm.txt

Here's a way to tell if the buzzer on the tiny4412 backplane is active or passive:

First, the PWM is turned off, that is, write 0 to enable, and then write to the polarity inversed, if the buzzer starts to ring, then there is the active buzzer, otherwise it is the passive buzzer. The principle is: After switching off the PWM, under normal, the TOUT_0 output is low, in inversed mode, the TOUT_0 output high level. ( see from the schematic of the tiny4412, the PWM output high-voltage, transistor conduction, buzzer began to ring, the characteristics of the active buzzer is, as long as it is a high level, the sound, and the characteristics of the passive is that the pulse must be given to ring)

An example of a frequency of 1Hz with a duty ratio of 1:9 is implemented below:

[Email protected]]# cd/sys/class/pwm/pwmchip0/
[[email protected] pwmchip0]# ls
Device     export     NPWM       Power      subsystem  uevent     unexport
Export
[[email protected] pwmchip0]# ls
Device     NPWM       pwm0       uevent
Export     Power      Subsystem  Unexport
[Email protected] pwmchip0]# CD pwm0/
[[email protected] pwm0]# ls
Duty_cycle  enable      period      polarity    power       uevent
[Email protected] pwm0]# Echo 1  
[Email protected] pwm0]#

Here: 1 seconds = 1 000 000 000 nanoseconds

Writing the 0,PWM0 directory to Unexport is automatically deleted.

[[email protected] pwmchip0]# ls
Device     NPWM       pwm0       uevent
Export     Power      Subsystem  Unexport
[[email protected] pwmchip0]# ls
Device     export     NPWM       Power      subsystem  uevent     unexport

Not to be continued.

Linux kernel porting based on tiny4412--PWM Subsystem Learning (vii)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.