change source file mode to 0644 instead of 0755
[profile/mobile/platform/kernel/u-boot-tm1.git] / board / spreadtrum / coreprimelite_marlin / sprd_bl.c
1 #include <common.h>
2 #include <asm/arch/hardware.h>
3 #include <asm/io.h>
4 #include <asm/arch/sprd_reg.h>
5 #include <asm/arch/sprd_reg_base.h>
6
7 #define PWM_INDEX 2
8
9 #define PWM_PRESCALE (0x0000)
10 #define PWM_CNT (0x0004)
11 #define PWM_PAT_LOW (0x000C)
12 #define PWM_PAT_HIG (0x0010)
13
14 #define PWM_ENABLE (1 << 8)
15 #define PWM2_SCALE 0x0
16 #define PWM_REG_MSK 0xffff
17 #define PWM_MOD_MAX 0xff
18
19 void (*lcd_panel_cabc_pwm_bl)(int brightness) = NULL;
20
21 static inline uint32_t pwm_read(int index, uint32_t reg)
22 {
23         return __raw_readl(CTL_BASE_PWM + index * 0x20 + reg);
24 }
25
26 static void pwm_write(int index, uint32_t value, uint32_t reg)
27 {
28         __raw_writel(value, CTL_BASE_PWM + index * 0x20 + reg);
29 }
30
31 void set_backlight(uint32_t brightness)
32 {
33 //    if (lcd_panel_cabc_pwm_bl) {
34 //        lcd_panel_cabc_pwm_bl(brightness); /* lcd panel CABC PWM auto control */
35 //    } else {
36                 int index = PWM_INDEX;
37
38                 __raw_bits_or((0x1 << 0), REG_AON_CLK_PWM0_CFG + index * 4);//ext_26m select
39
40                 if (0 == brightness) {
41                         pwm_write(index, 0, PWM_PRESCALE);
42                         printf("sprd backlight power off. pwm_index=%d  brightness=%d\n", index, brightness);
43                 } else {
44                         __raw_bits_or((0x1 << (index+4)), REG_AON_APB_APB_EB0); //PWMx EN
45
46                         pwm_write(index, PWM2_SCALE, PWM_PRESCALE);
47                         pwm_write(index, (brightness << 8) | PWM_MOD_MAX, PWM_CNT);
48                         pwm_write(index, PWM_REG_MSK, PWM_PAT_LOW);
49                         pwm_write(index, PWM_REG_MSK, PWM_PAT_HIG);
50                         pwm_write(index, PWM_ENABLE, PWM_PRESCALE);
51                         printf("sprd backlight power on. pwm_index=%d  brightness=%d\n", index, brightness);
52                 }
53 //      }
54
55         return;
56 }