mt6739 GPIO复用为PWM模式

本案使用GPIO27,查资料可知,gpio27可能用作PWM2的输出

1.dws设置

2.查看背光如何使用PWM,仿照
查可得:kernel-4.4\drivers\misc\mediatek\leds\mt6739\mtk_leds.c的mt_led_set_pwm函数就是设置背光pwm的
截图如下:

mt6739 GPIO复用为PWM模式_第1张图片

3.在驱动再以下代码就可以
 

#include 

/*设置GPIO27复用为PWM功能 */
int my_set_pwm(int pwm_num, int duty)
{         
    struct pwm_spec_config pwm_setting;
 
    memset(&pwm_setting, 0, sizeof(struct pwm_spec_config));
    pwm_setting.pwm_no = pwm_num;
    pwm_setting.mode = PWM_MODE_OLD;
    printk("my_set_pwm  pwm_no=%d\n",pwm_num);
    /* We won't choose 32K to be the clock src of old mode 
      because of system performance. */
    /* The setting here will be clock src = 26MHz, 
        CLKSEL = 26M/1625 (i.e. 16K) */
    pwm_setting.clk_src = PWM_CLK_OLD_MODE_BLOCK; //pwm_setting.pmic_pad = 0;
                                                  //PWM_BLCK和DDR频率有关
    pwm_setting.PWM_MODE_OLD_REGS.THRESH = duty; 
    pwm_setting.clk_div = CLK_DIV1;//CLK_DIV1 = 1,分频系数
    pwm_setting.PWM_MODE_OLD_REGS.DATA_WIDTH = 100;
 
    pwm_setting.PWM_MODE_FIFO_REGS.IDLE_VALUE = 0;
    pwm_setting.PWM_MODE_FIFO_REGS.GUARD_VALUE = 0;
    pwm_setting.PWM_MODE_FIFO_REGS.GDURATION = 0;
    pwm_setting.PWM_MODE_FIFO_REGS.WAVE_NUM = 0;
    pwm_set_spec_config(&pwm_setting);
 
    return 0;
}

注:
PWM_CLK_OLD_MODE_BLOCK=26MHZ
输出频率为:clk_src/clk_div/DATA_WIDTH
26000/1/100约等于260kHZ
占空比为:THRESH/DATA_WIDTH
50/100=1/2
PWM工作模式有5种:OLD MODE/FIFO MODE/MEMORY MODE/RANDOM MODE/SEQ MODE
图是输入的波形:

可以参考博客:https://blog.csdn.net/sdkdlwk/article/details/92116468

你可能感兴趣的:(MTK驱动)