硬件平台:RK3128
Android版本:6.0
Kernel版本:3.10.92
首先来看pwm配置:
pwm1: pwm@20050010 {
compatible = "rockchip,rk-pwm";
reg = <0x20050010 0x10>;
#pwm-cells = <2>;
pinctrl-names = "default";
pinctrl-0 = <&pwm1_pin>;
clocks = <&clk_gates7 10>;
clock-names = "pclk_pwm";
status = "okay";
};
Backlight配置:
backlight: backlight {
compatible = "pwm-backlight"; //匹配名
pwms = <&pwm1 0 25000>; //第一个参数表示使用pwm1来控制背光;第二个参数0表示index,因为pwm1下只有一个PWM,所以一直是0;第三个参数表示周期为25000ns,所以频率就是40k。
brightness-levels = <0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
16 17 18 19 20 21 22 23 24 25 26 27 28
29 30 31 32 33 34 35 36 37 38 39 40 41
42 43 44 45 46 47 48 49 50 51 52 53 54
55 56 57 58 59 60 61 62 63 64 65 66 67
68 69 70 71 72 73 74 75 76 77 78 79 80
81 82 83 84 85 86 87 88 89 90 91 92 93
94 95 96 97 98 99 100 101 102 103 104 105
106 107 108 109 110 111 112 113 114 115 116
117 118 119 120 121 122 123 124 125 126 127
128 129 130 131 132 133 134 135 136 137 138
139 140 141 142 143 144 145 146 147 148 149
150 151 152 153 154 155 156 157 158 159 160
161 162 163 164 165 166 167 168 169 170 171
172 173 174 175 176 177 178 179 180 181 182
183 184 185 186 187 188 189 190 191 192 193
194 195 196 197 198 199 200 201 202 203 204
205 206 207 208 209 210 211 212 213 214 215
216 217 218 219 220 221 222 223 224 225 226
227 228 229 230 231 232 233 234 235 236 237
238 239 240 241 242 243 244 245 246 247 248
249 250 251 252 253 254 255>; //背光等级
default-brightness-level = <128>; //默认背光等级
enable-gpios = <&gpio0 GPIO_D2 GPIO_ACTIVE_LOW>; //使能脚
};
注册流程:
kernel/drivers/video/backlight/pwm_bl.c
pwm_backlight_probe
-> pwm_backlight_parse_dt
-> gpio_request_one //申请使能gpio
-> devm_pwm_get//获取一个PWM
-> pwm_request //申请PWM
-> pwm_set_period //设置周期
-> dev_set_name //设置名字
-> backlight_device_register //注册backlight设备
-> backlight_update_status //注册完成后,更新背光
-> bd->ops->update_status //通过backlight_ops调用pwm_backlight_update_status
-> pwm_backlight_update_status
-> compute_duty_cycle //计算占空比
-> pwm_config //配置pwm
-> pwm_backlight_power_on //打开背光。
设置背光时,上层会通过sys文件系统读写/sys/class/backlight/rk28_bl/brightness:
hardware/rockchip/liblights/lights.cpp
set_backlight_light ->
write_int ->
backlight_store_brightness ->
backlight_update_status
之后流程就跟注册时一样了。
另外在亮屏灭屏时会调用fb_notifier_callback:
static int fb_notifier_callback(struct notifier_block *self,
unsigned long event, void *data)
{
struct backlight_device *bd;
struct fb_event *evdata = data;
/* If we aren't interested in this event, skip it immediately ... */
if (event != FB_EVENT_BLANK && event != FB_EVENT_CONBLANK)
return 0;
bd = container_of(self, struct backlight_device, fb_notif);
mutex_lock(&bd->ops_lock);
if (bd->ops)
if (!bd->ops->check_fb ||
bd->ops->check_fb(bd, evdata->info)) {
bd->props.fb_blank = *(int *)evdata->data;
if (bd->props.fb_blank == FB_BLANK_UNBLANK)
bd->props.state &= ~BL_CORE_FBBLANK; //亮屏
else
bd->props.state |= BL_CORE_FBBLANK; //灭屏
backlight_update_status(bd);
}
mutex_unlock(&bd->ops_lock);
return 0;
}