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