[MT6582_LCD]使用PWM配置背光如何配置,及频率计算
以GPIO52 pin为例:
Mode0 |
Mode1 |
Mode2 |
Mode3 |
GPIO52 |
LPD8 |
PWM_BL |
PWM_A |
/mediatek/custom/XXXXXXXXX/lk/inc/cust_leds.h
./mediatek/custom/XXXXXXXXX/kernel/leds/mt65xx/cust_leds.c
./mediatek/custom/XXXXXXXXX/lk/cust_leds.c
alps\mediatek\kernel\drivers\leds\leds_drv.c
static int mt65xx_led_set_cust(struct cust_mt65xx_led *cust, int level)
{
#ifdef CONTROL_BL_TEMPERATURE
mutex_lock(&bl_level_limit_mutex);
current_level = level;
//LEDS_DRV_DEBUG("brightness_set_cust:current_level=%d\n", current_level);
if(0 == limit_flag){
last_level = level;
//LEDS_DRV_DEBUG("brightness_set_cust:last_level=%d\n", last_level);
}else {
if(limit < current_level){
level = limit;
//LEDS_DRV_DEBUG("backlight_set_cust: control level=%d\n", level);
}
}
mutex_unlock(&bl_level_limit_mutex);
#endif
#ifdef LED_INCREASE_LED_LEVEL_MTKPATCH
if(MT65XX_LED_MODE_CUST_BLS_PWM == cust->mode) {
mt_mt65xx_led_set_cust(cust, ((((1 << LED_INTERNAL_LEVEL_BIT_CNT) - 1)*level + 127)/500)); //降低亮度
}else {
mt_mt65xx_led_set_cust(cust, level);
}
#else
mt_mt65xx_led_set_cust(cust, level);
#endif
return -1;
}
m0022\mediatek\platform\mt6582\kernel\drivers\leds\leds.c
LEDS_DEBUG("[LED]Set Backlight directly %d at time %lu\n",led_data->level,jiffies);
行 960 if(MT65XX_LED_MODE_CUST_BLS_PWM == led_data->cust.mode)
{
mt_mt65xx_led_set_cust(&led_data->cust, ((((1 << MT_LED_INTERNAL_LEVEL_BIT_CNT) - 1)*level + 127)/500));
一、将GPIO52在DCT tool配置成PWM1,用于背光。
static struct cust_mt65xx_led cust_led_list[MT65XX_LED_TYPE_TOTAL] = {
{"red", MT65XX_LED_MODE_NONE, -1,{0}},
{"green", MT65XX_LED_MODE_NONE, -1,{0}},
{"blue", MT65XX_LED_MODE_NONE, -1,{0}},
{"jogball-backlight", MT65XX_LED_MODE_NONE, -1,{0}},
{"keyboard-backlight",MT65XX_LED_MODE_NONE, -1,{0}},
{"button-backlight", MT65XX_LED_MODE_NONE, -1,{0,0,0,0,0}},
{"lcd-backlight", MT65XX_LED_MODE_PWM, PWM1, {0,0,0,0,0}},
};
1. PWM config data结构体解析
clock_source: clock source frequency, can be 0/1
div: clock division, can be any value within 0~7 (i.e. 1/2^(div) = /1, /2, /4, /8, /16, /32, /64, /128)
low_duration: only for BACKLIGHT_LEVEL_PWM_64_FIFO_MODE_SUPPORT
High_duration: only for BACKLIGHT_LEVEL_PWM_64_FIFO_MODE_SUPPORT
2. PWM频率计算:
If BACKLIGHT_LEVEL_PWM_MODE_CONFIG = BACKLIGHT_LEVEL_PWM_256_SUPPORT,
PWM freq. = clock source / 2^(div) / 256
If BACKLIGHT_LEVEL_PWM_MODE_CONFIG = BACKLIGHT_LEVEL_PWM_64_FIFO_MODE_SUPPORT,
PWM freq. = clock source / 2^(div) / [(High_duration+1)(Level')+(low_duration+1)(64 - Level')]
= clock source / 2^(div) / [(High_duration+1)*64] (when low_duration = High_duration)
时钟源:
0: block clock/1625 = 26M/1625 = 16K (MT6571)
1: block clock = 26M (MT6571)
Div: 0~7
例如, in MT6571, PWM_config = {1,1,0,0,0}
==> PWM freq. = 26M/2^1/256 = 50.78 KHz ( when BACKLIGHT_LEVEL_PWM_256_SUPPORT )
==> PWM freq. = 26M/2^1/(0+1)*64 = 203.13 KHz ( when BACKLIGHT_LEVEL_PWM_64_FIFO_MODE_SUPPORT )
二、将GPIO52在DCT Tool配置成PWM_BL.
static struct cust_mt65xx_led cust_led_list[MT65XX_LED_TYPE_TOTAL] = {
{"red", MT65XX_LED_MODE_NONE, -1,{0}},
{"green", MT65XX_LED_MODE_NONE, -1,{0}},
{"blue", MT65XX_LED_MODE_NONE, -1,{0}},
{"jogball-backlight", MT65XX_LED_MODE_NONE, -1,{0}},
{"keyboard-backlight",MT65XX_LED_MODE_NONE, -1,{0}},
{"button-backlight", MT65XX_LED_MODE_NONE, -1,{0,0,0,0,0}},
{"lcd-backlight", MT65XX_LED_MODE_CUST_BLS_PWM, (int)disp_bls_set_backlight, {0,0,0,0,0}},
};
1. PWM config data结构体解析
clock_source: clock source frequency, can be 0/1/2/3
div: clock division, can be any value within 0~1023
low_duration: non-use
High_duration: non-use
pmic_pad: non-use
2. 频率计算
PWM freq.= clock source / (div + 1) /1024
Clock source:
0: 26 MHz
1: 104 MHz
Div: 0~1023
By default, clock_source = 0 and div = 0 => PWM freq. = 26 KHz
以GPIO52 pin为例:
Mode0 |
Mode1 |
Mode2 |
Mode3 |
GPIO52 |
LPD8 |
PWM_BL |
PWM_A |
/mediatek/custom/XXXXXXXXX/lk/inc/cust_leds.h
./mediatek/custom/XXXXXXXXX/kernel/leds/mt65xx/cust_leds.c
./mediatek/custom/XXXXXXXXX/lk/cust_leds.c
alps\mediatek\kernel\drivers\leds\leds_drv.c
static int mt65xx_led_set_cust(struct cust_mt65xx_led *cust, int level)
{
#ifdef CONTROL_BL_TEMPERATURE
mutex_lock(&bl_level_limit_mutex);
current_level = level;
//LEDS_DRV_DEBUG("brightness_set_cust:current_level=%d\n", current_level);
if(0 == limit_flag){
last_level = level;
//LEDS_DRV_DEBUG("brightness_set_cust:last_level=%d\n", last_level);
}else {
if(limit < current_level){
level = limit;
//LEDS_DRV_DEBUG("backlight_set_cust: control level=%d\n", level);
}
}
mutex_unlock(&bl_level_limit_mutex);
#endif
#ifdef LED_INCREASE_LED_LEVEL_MTKPATCH
if(MT65XX_LED_MODE_CUST_BLS_PWM == cust->mode) {
mt_mt65xx_led_set_cust(cust, ((((1 << LED_INTERNAL_LEVEL_BIT_CNT) - 1)*level + 127)/500)); //降低亮度
}else {
mt_mt65xx_led_set_cust(cust, level);
}
#else
mt_mt65xx_led_set_cust(cust, level);
#endif
return -1;
}
m0022\mediatek\platform\mt6582\kernel\drivers\leds\leds.c
LEDS_DEBUG("[LED]Set Backlight directly %d at time %lu\n",led_data->level,jiffies);
行 960 if(MT65XX_LED_MODE_CUST_BLS_PWM == led_data->cust.mode)
{
mt_mt65xx_led_set_cust(&led_data->cust, ((((1 << MT_LED_INTERNAL_LEVEL_BIT_CNT) - 1)*level + 127)/500));
一、将GPIO52在DCT tool配置成PWM1,用于背光。
static struct cust_mt65xx_led cust_led_list[MT65XX_LED_TYPE_TOTAL] = {
{"red", MT65XX_LED_MODE_NONE, -1,{0}},
{"green", MT65XX_LED_MODE_NONE, -1,{0}},
{"blue", MT65XX_LED_MODE_NONE, -1,{0}},
{"jogball-backlight", MT65XX_LED_MODE_NONE, -1,{0}},
{"keyboard-backlight",MT65XX_LED_MODE_NONE, -1,{0}},
{"button-backlight", MT65XX_LED_MODE_NONE, -1,{0,0,0,0,0}},
{"lcd-backlight", MT65XX_LED_MODE_PWM, PWM1, {0,0,0,0,0}},
};
1. PWM config data结构体解析
clock_source: clock source frequency, can be 0/1
div: clock division, can be any value within 0~7 (i.e. 1/2^(div) = /1, /2, /4, /8, /16, /32, /64, /128)
low_duration: only for BACKLIGHT_LEVEL_PWM_64_FIFO_MODE_SUPPORT
High_duration: only for BACKLIGHT_LEVEL_PWM_64_FIFO_MODE_SUPPORT
2. PWM频率计算:
If BACKLIGHT_LEVEL_PWM_MODE_CONFIG = BACKLIGHT_LEVEL_PWM_256_SUPPORT,
PWM freq. = clock source / 2^(div) / 256
If BACKLIGHT_LEVEL_PWM_MODE_CONFIG = BACKLIGHT_LEVEL_PWM_64_FIFO_MODE_SUPPORT,
PWM freq. = clock source / 2^(div) / [(High_duration+1)(Level')+(low_duration+1)(64 - Level')]
= clock source / 2^(div) / [(High_duration+1)*64] (when low_duration = High_duration)
时钟源:
0: block clock/1625 = 26M/1625 = 16K (MT6571)
1: block clock = 26M (MT6571)
Div: 0~7
例如, in MT6571, PWM_config = {1,1,0,0,0}
==> PWM freq. = 26M/2^1/256 = 50.78 KHz ( when BACKLIGHT_LEVEL_PWM_256_SUPPORT )
==> PWM freq. = 26M/2^1/(0+1)*64 = 203.13 KHz ( when BACKLIGHT_LEVEL_PWM_64_FIFO_MODE_SUPPORT )
二、将GPIO52在DCT Tool配置成PWM_BL.
static struct cust_mt65xx_led cust_led_list[MT65XX_LED_TYPE_TOTAL] = {
{"red", MT65XX_LED_MODE_NONE, -1,{0}},
{"green", MT65XX_LED_MODE_NONE, -1,{0}},
{"blue", MT65XX_LED_MODE_NONE, -1,{0}},
{"jogball-backlight", MT65XX_LED_MODE_NONE, -1,{0}},
{"keyboard-backlight",MT65XX_LED_MODE_NONE, -1,{0}},
{"button-backlight", MT65XX_LED_MODE_NONE, -1,{0,0,0,0,0}},
{"lcd-backlight", MT65XX_LED_MODE_CUST_BLS_PWM, (int)disp_bls_set_backlight, {0,0,0,0,0}},
};
1. PWM config data结构体解析
clock_source: clock source frequency, can be 0/1/2/3
div: clock division, can be any value within 0~1023
low_duration: non-use
High_duration: non-use
pmic_pad: non-use
2. 频率计算
PWM freq.= clock source / (div + 1) /1024
Clock source:
0: 26 MHz
1: 104 MHz
Div: 0~1023
By default, clock_source = 0 and div = 0 => PWM freq. = 26 KHz