2 #include <asm/arch/hardware.h>
4 #include <asm/arch/sprd_reg.h>
5 #include <asm/arch/sprd_reg_base.h>
9 #define PWM_PRESCALE (0x0000)
10 #define PWM_CNT (0x0004)
11 #define PWM_PAT_LOW (0x000C)
12 #define PWM_PAT_HIG (0x0010)
14 #define PWM_ENABLE (1 << 8)
15 #define PWM2_SCALE 0x0
16 #define PWM_REG_MSK 0xffff
17 #define PWM_MOD_MAX 0xff
20 static inline uint32_t pwm_read(int index, uint32_t reg)
22 return __raw_readl(CTL_BASE_PWM + index * 0x20 + reg);
25 static void pwm_write(int index, uint32_t value, uint32_t reg)
27 __raw_writel(value, CTL_BASE_PWM + index * 0x20 + reg);
30 void set_backlight(uint32_t brightness)
32 int index = PWM_INDEX;
34 __raw_bits_or((0x1 << 0), REG_AON_CLK_PWM0_CFG + index * 4);//ext_26m select
36 if (0 == brightness) {
37 pwm_write(index, 0, PWM_PRESCALE);
38 printf("sprd backlight power off. pwm_index=%d brightness=%d\n", index, brightness);
40 __raw_bits_or((0x1 << (index+4)), REG_AON_APB_APB_EB0); //PWMx EN
42 pwm_write(index, PWM2_SCALE, PWM_PRESCALE);
43 pwm_write(index, (brightness << 8) | PWM_MOD_MAX, PWM_CNT);
44 pwm_write(index, PWM_REG_MSK, PWM_PAT_LOW);
45 pwm_write(index, PWM_REG_MSK, PWM_PAT_HIG);
46 pwm_write(index, PWM_ENABLE, PWM_PRESCALE);
47 printf("sprd backlight power on. pwm_index=%d brightness=%d\n", index, brightness);