PWM Introduction Face-RK3399 has two PWM outputs: PWM1: LCD_BL_PWM PWM2: VDDLOG power supply This chapter describes how to configure PWM. The PWM driver of Face-RK3399 is "kernel/drivers/pwm/pwm-rockchip.c" Configurtion There are three main steps to configure PWM: configure PWM DTS node, configure PWM kernel driver and control PWM device. DTS Configuration Add the PWM DTS configuration in "kernel/arch/arm64/boot/dts/rockchip/rk3399-firefly-demo.dtsi": pwm_demo: pwm_demo { status = "okay"; compatible = "firefly,rk3399-pwm"; pwm_id = <1>; min_period = <0>; max_period = <10000>; duty_ns = <5000>; }; pwm_id : Number of PWM channels to be applied. min_period : Minimum period length. max_period : Maximum period length. duty_ns : Duty cycle activation time of PWM, unit ns. Interface specification Users can use the PWM nodes generated by the above steps in other driver files. The specific methods are as follows: (1) The following header files are included in the device driver files that need to be controlled by PWM : #include This header file mainly contains the PWM function interface. (2) Apply PWM struct pwm_device *pwm_request(int pwm_id, const char *label); Function to apply for PWM, for example: struct pwm_device * pwm1 = NULL;pwm0 = pwm_request(1, “firefly-pwm”); (3) Configue PWM int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns); Configure the duty cycle of PWM, for example: pwm_config(pwm0, 500000, 1000000); (4) Enable the PWM function int pwm_enable(struct pwm_device *pwm); Used to enable PWM, for example: pwm_enable(pwm0); (5) Control PWM output mainly uses the following interface functions: function: Request a PWM struct pwm_device *pwm_request(int pwm_id, const char *label); function: Release the PWM requested void pwm_free(struct pwm_device *pwm); function: Configure the duty cycle of PWM int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns); function: Enable PWM int pwm_enable(struct pwm_device *pwm); function: Disable PWM void pwm_disable(struct pwm_device *pwm); Refer to the Demo: "kernel/drivers/pwm/pwm-firefly.c". Debugging Check PWM registration status through the rich debug interface of the kernel, "adb shell" or serial port to enter the android terminal and execute: cat /sys/kernel/debug/PWM The interface name and register address will be returned if PWM registration is successful. FAQs Q1: PWM could not register successfully ? A1: Whether the DTS configuration file opens the corresponding PWM. Whether the IO port where PWM is located is occupied by other resources, you can check the reason according to the error return value.