1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * PWM BACKLIGHT driver for Board based on EXYNOS.
4  *
5  * Author: Donghwa Lee  <dh09.lee@samsung.com>
6  *
7  * Derived from linux/drivers/video/backlight/pwm_backlight.c
8  */
9 
10 #include <common.h>
11 #include <pwm.h>
12 #include <linux/types.h>
13 #include <asm/io.h>
14 #include <asm/arch/cpu.h>
15 #include <asm/arch/gpio.h>
16 #include <asm/arch/pwm.h>
17 #include <asm/arch/pwm_backlight.h>
18 
19 static struct pwm_backlight_data *pwm;
20 
21 static int exynos_pwm_backlight_update_status(void)
22 {
23 	int brightness = pwm->brightness;
24 	int max = pwm->max_brightness;
25 
26 	if (brightness == 0) {
27 		pwm_config(pwm->pwm_id, 0, pwm->period);
28 		pwm_disable(pwm->pwm_id);
29 	} else {
30 		pwm_config(pwm->pwm_id,
31 			brightness * pwm->period / max, pwm->period);
32 		pwm_enable(pwm->pwm_id);
33 	}
34 	return 0;
35 }
36 
37 int exynos_pwm_backlight_init(struct pwm_backlight_data *pd)
38 {
39 	pwm = pd;
40 
41 	exynos_pwm_backlight_update_status();
42 
43 	return 0;
44 }
45