当前位置:网站首页>Imx6q PWM drive
Imx6q PWM drive
2022-06-12 07:03:00 【Handsome without friends~】
One : Device tree

kernel_imx/arch/arm/boot/dts/imx6q-c-sabresd.dts

kernel_imx/arch/arm/boot/dts/imx6qdl-sabresd.dtsi
pwms = <&pwm3 0 50000>;
pwm3: Indicates that the backlight is connected to pwm3 On
0: Express index by 0,pwm3 There is only 1 individual pwm, So fill in 0
50000: Indicates that the period is 50000ns, The frequency is 20k
default-brightness-level = <60>;
Default backlight brightness ,60Two :pwm drive
pwm Driving dependency backlight Subsystem .
drive :kernel/drivers/video/backlight/pwm_bl.c kernel_imx/drivers/video/backlight/backlight.c
pwm_backlight_probe
pwm_backlight_parse_dt // analysis dts Medium brightness-levels、default-brightness-level
//RK3288 It will also be parsed here enable-gpios , however 3399 No, ,3399 Is in probe with devm_gpiod_get_optional // obtain enable-gpio State of
devm_gpiod_get_optional // It's actually encapsulation gpio_request_one
devm_gpio_request_one // Apply for backlight enable gpio
devm_pwm_get -> /drivers/pwm/core.c // To obtain a pwm
pwm_get ->
of_pwm_get ->
of_parse_phandle_with_args Parse the above dts Medium pwms attribute .
of_node_to_pwmchip
pwm = pc->of_xlate // The resulting struct pwm_device type .
pwm_request // apply pwm, Prevent other drivers from using .
pwm_set_period //pb->pwm->period = data->pwm_period_ns
pwm_get_period // obtain period.
dev_set_name(&pdev->dev, "rk28_bl"); //name Can't change , User space will be used :/sys/class/backlight/rk28_bl
backlight_device_register -> /drivers/video/baklight/backlight.c // Register standard backlight devices
device_register
backlight_register_fb ->
fb_register_client //callback yes fb_notifier_callback
fb_register_client // Register the kernel notification chain
backlight_update_status -> // Update... With default values .
bd->ops->update_status ->
pwm_backlight_update_status ->
compute_duty_cycle // Calculate the duty cycle
pwm_config // To configure pwm
pwm_backlight_power_on //enable Backlight
platform_set_drvdata // Can be pdev Private data saved as platform bus device , When you want to use it later, you just call platform_get_drvdatacompute_duty_cycle Calculate the duty cycle :
static int compute_duty_cycle(struct pwm_bl_data *pb, int brightness)
{
/* Generally, this value is 0*/
unsigned int lth = pb->lth_brightness;
/* Duty cycle */
int duty_cycle;
/*pb->levels This form is from dts node brightness-levels From ,
Suppose that the incoming parameters brightness yes 254, So what you get duty_cycle Namely 1,
Without this form , Then it is directly the incoming brightness value .*/
if (pb->levels)
duty_cycle = pb->levels[brightness];
else
duty_cycle = brightness;
/* Suppose here lth yes 0, So the formula is duty_cycle * pb->period / pb->scale
pb->period That is to say dts node pwms The third parameter period value of is 25000
pb->scale by pb->levels The maximum value in the array
So this formula is based on the following formula Android The pure value of is converted into the duty cycle corresponding to the event cycle value .*/
return (duty_cycle * (pb->period - lth) / pb->scale) + lth;
}Either way, it calls backlight_update_status To change the backlight ,syfs It's also . look down backlight.c,
backlight_class_init -> backlight.c
class_create // establish class, The name is backlight.
among backlight_store_brightness() The final call backlight_update_status().
There is also a case where the screen is on / Call when the screen is off , Remember to register one in front fb notify callback.
static int fb_notifier_callback(struct notifier_block *self,
unsigned long event, void *data)
{
...
/* Only screen on and screen off events are handled .*/
/* If we aren't interested in this event, skip it immediately ... */
if (event != FB_EVENT_BLANK && event != FB_EVENT_CONBLANK)
return 0;
...
if (bd->ops)
if (!bd->ops->check_fb ||
bd->ops->check_fb(bd, evdata->info)) {
bd->props.fb_blank = *(int *)evdata->data;
// On screen condition
if (bd->props.fb_blank == FB_BLANK_UNBLANK)
bd->props.state &= ~BL_CORE_FBBLANK;
// When the screen is off
else
bd->props.state |= BL_CORE_FBBLANK;
backlight_update_status(bd);
}
...
}backlight_update_status Function implementation :

kernel_imx/include/linux/backlight.h
The final call bd->ops->update_status(bd);bd->ops The assignment of is in pwm_bl.c In the document backlight_device_register Function assignment .


Android6.0 Backlight Drive analysis
边栏推荐
猜你喜欢

2021 robocom world robot developer competition - undergraduate group (Preliminary)

I met 15 people recently and found that I couldn't answer the basic question of this test
![Leetcode: offer 60 Points of N dice [math + level DP + cumulative contribution]](/img/2b/41bd6a213892062f4c12721b5d4e8d.png)
Leetcode: offer 60 Points of N dice [math + level DP + cumulative contribution]

CL210OpenStack操作的故障排除--章節實驗

数据库全量SQL分析与审计系统性能优化之旅

Zhang Chi's class: Notice on the time of CAQ Six Sigma test in 2022

esp32 hosted

An error occurred while downloading the remote file The errormessage

leetcode:890. 查找和替换模式【两个dict记录双射(set)】

【图像去噪】基于非局部欧几里德中值 (NLEM) 实现图像去噪附matlab代码
随机推荐
[image denoising] image denoising based on partial differential equation (PDE) with matlab code
SSM integration
Upload file (post form submission form data)
4 expression
Leetcode: Sword finger offer 67 Convert string to integer [simulation + segmentation + discussion]
Unable to load bean of class marked with @configuration
Throw away the ugly toast. The movable toast is more interesting
Are you still using like+% for MySQL fuzzy query?
如何更新 Kubernetes 证书
库里扛起了勇士对凯尔特人的第四场
六月集训 第一日——数组
12.13-12.19 summary
Map to sort
8. 表单标签
PowerDesigner connects to entity database to generate physical model in reverse
June training day 6 - sliding window
推荐17个提升开发效率的“轮子”
3 strings, containers, and arrays
Expansion of D @nogc
I met 15 people recently and found that I couldn't answer the basic question of this test