一.内核层
Led-class.c (kernel-3.10\drivers\leds) 这个文件给HAL层提供接口
led_brightness_store是sysfs文件,在"/sys/class/leds/lcd-backlight/brightness"
__led_set_brightness(led_cdev, i);
led_cdev->brightness_set(led_cdev, value); (Leds.h (kernel-3.10\drivers\leds))
led_cdev->brightness_set在Leds_drv.c (kernel-3.10\drivers\misc\mediatek\leds) 中的probe函数中被赋值 g_leds_data[i]->cdev.brightness_set = mt65xx_led_set;
mt65xx_led_set
mt_mt65xx_led_set(led_cdev, level);
mt_mt65xx_led_set_cust(&led_data->cust, led_data->level); 在Leds.c (kernel-3.10\drivers\misc\mediatek\leds\mt6735) 中
mt_mt65xx_led_set_cust //因为我们是GPIO模式,所以就会进入这个分支
case MT65XX_LED_MODE_GPIO: LEDS_DEBUG("brightness_set_cust:go GPIO mode!!!!!\n"); return ((cust_set_brightness)(cust->data))(level);
cust->data这个函数指针在Cust_leds.c (kernel-3.10\drivers\misc\mediatek\mach\mt6735\lentek6735_65c_l\leds\mt65xx)被赋值
static struct cust_mt65xx_led cust_led_list[MT65XX_LED_TYPE_TOTAL] = {
{"red", MT65XX_LED_MODE_PMIC, MT65XX_LED_PMIC_NLED_ISINK0,{0}}, {"blue", MT65XX_LED_MODE_NONE, -1,{0}}, {"green", MT65XX_LED_MODE_PMIC, MT65XX_LED_PMIC_NLED_ISINK1,{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}}, {"lcd-backlight", MT65XX_LED_MODE_GPIO, (long)Cust_Tintele_SetBacklight,{0}}, {"flashlight", MT65XX_LED_MODE_GPIO, (long)Cust_Tintele_SetFlashlight,{0}},};
因为是16节的控制芯片,就是只有16级亮度,用io模拟这种进行控制
for (; i<=16-level; i++) { mt_set_gpio_out(GPIO_LCD_BACKLIGHT_EN | 0x80000000, 0); udelay(2); mt_set_gpio_out(GPIO_LCD_BACKLIGHT_EN | 0x80000000, 1); udelay(2); } GPIO_LCD_BACKLIGHT_EN | 0x80000000 //是为了让这个执行更快
二.hal层 Lights.c (vendor\mediatek\proprietary\hardware\liblights)
set_light_backlight
write_int(LCD_FILE, brightness); //LCD_FILE就是/sys/class/leds/lcd-backlight/brightness
提供接口给中间层struct hw_module_t HAL_MODULE_INFO_SYM = { .tag = HARDWARE_MODULE_TAG, //.version_major = 1, //.version_minor = 0, .id = LIGHTS_HARDWARE_MODULE_ID, .name = "MTK lights Module", .author = "MediaTek", .methods = &lights_module_methods,};
打开函数static struct hw_module_methods_t lights_module_methods = { .open = open_lights,};
open_lights
if (0 == strcmp(LIGHT_ID_BACKLIGHT, name)) { set_light = set_light_backlight; }
三.jni层init_native
hw_get_module(LIGHTS_HARDWARE_MODULE_ID, (hw_module_t const**)&module); //获得hal层的接口
get_device(module, LIGHT_ID_BACKLIGHT);
module->methods->open(module, name, &device); //调用hal层的open函数
finalize_native 和 setLight_native上层可以调用、
static JNINativeMethod method_table[] = {
{ "init_native", "()J", (void*)init_native }, { "finalize_native", "(J)V", (void*)finalize_native }, { "setLight_native", "(JIIIIII)V", (void*)setLight_native }, };
int register_android_server_LightsService(JNIEnv *env){ return jniRegisterNativeMethods(env, "com/android/server/lights/LightsService", method_table, NELEM(method_table));}
四.framework层 DisplayPowerController.java (frameworks\base\services\core\java\com\android\server\display)
// Brightness animation ramp rate in brightness units per second. private static final int BRIGHTNESS_RAMP_RATE_FAST = 20000; private static final int BRIGHTNESS_RAMP_RATE_SLOW = 2000;我要改变拉动背光条,中间过滤一些数值