DA9034驱动程序阅读笔记(2)
转载时请注明出处和作者联系方式
文章出处:http://www.limodev.cn/blog
作者联系方式:李先静 <xianjimli at hotmail dot com>
DA9034是一个集成了电源管理、音频设备、触摸屏控制器和能用A/D|D/A转换的多功能芯片。最近读了一下相关驱动程序,这里记些笔记,不成体系,作为备忘而已。有兴趣的朋友可以一起讨论。
DA9034支持四类LED驱动:LCD背光、键盘背光、FLASH_LED和PC_LED。
在broncho a1中,显示背光是通过LED_DRIVER1连接到LCD控制器的LED1-LED5上的。
LCD背光驱动比较简单,它主要通过操作LED1_CONTROL寄存器来控制LCD背光的开/关/强度。
LED1_CONTROL的描述:
LED1_RAMP LED1_PWM<6> LED1_PWM<5> LED1_PWM<4> LED1_PWM<3> LED1_PWM<2> LED1_PWM<1> LED1_PWM<0>
LCD背光设备是一个platform device,在littleton.c中定义:
static struct platform_device micco_bl_device = {
.name = "micco-bl",
.id = -1,
};
LCD背光驱动程序在drivers/video/backlight/micco_bl.c:
static struct platform_driver miccobl_driver = {
.probe = miccobl_probe,
.remove = miccobl_remove,
.suspend = miccobl_suspend,
.resume = miccobl_resume,
.driver = {
.name = "micco-bl",
},
};
在miccobl_probe函数里,会注册一个backlight设备:
static int __init miccobl_probe(struct platform_device *pdev)
{
struct backlight_device *bd;
bd = backlight_device_register("micco-bl", &pdev->dev, NULL,
&miccobl_ops);
if (IS_ERR(bd))
return PTR_ERR(bd);
platform_set_drvdata(pdev, bd);
bd->props.power = FB_BLANK_UNBLANK;
bd->props.brightness = LCD_LED_DEFAULT;
bd->props.max_brightness = LCD_LED_MAX;
miccobl_send_intensity(bd);
return 0;
}
对于miccobl_ops,主要提供了两个函数:
static struct backlight_ops miccobl_ops = {
.get_brightness = miccobl_get_intensity,
.update_status = miccobl_set_intensity,
};
读取当前的亮度:
static int miccobl_get_intensity(struct backlight_device *bd)
{
return current_intensity;
}
通过修改寄存器MICCO_LED1_CONTROL来设置亮度。
static int miccobl_set_intensity(struct backlight_device *bd)
{
miccobl_send_intensity(bd);
return 0;
}
static int miccobl_send_intensity(struct backlight_device *bd)
{
int intensity = bd->props.brightness;
if (bd->props.power != FB_BLANK_UNBLANK)
intensity = 0;
if (bd->props.fb_blank != FB_BLANK_UNBLANK)
intensity = 0;
if (miccobl_suspended)
intensity = 0;
micco_write(MICCO_LED1_CONTROL, intensity);
current_intensity = intensity;
return 0;
}
键盘背光驱动和LCD背光实现类似,主要的不同是键盘背光用的是LED_DRIVER2,所以通过操作LED2_CONTROL来控制亮度。
用户空间的接口在:hardware/libhardware/modules/lights/lights.c里:
#define LCD_BACKLIGHT "/sys/class/backlight/micco-bl"
#define BUTTON_BACKLIGHT "/sys/class/backlight/micco-kp-bl"
设置LCD背光亮度:
int back_light_set_light (struct light_device_t* dev, struct light_state_t const* state);
设置键盘背光亮度:
int buttons_light_set_light (struct light_device_t* dev, struct light_state_t const* state);