1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2011 by Marcin Bukat
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
24 #include "backlight.h"
25 #include "backlight-target.h"
28 static int brightness
= DEFAULT_BRIGHTNESS_SETTING
;
29 static const unsigned short log_brightness
[] = {
30 0x2710, 0x27ac, 0x2849, 0x2983, 0x2abd, 0x2c93, 0x2e6a, 0x30dd,
31 0x3351, 0x3661, 0x3971, 0x3d1f, 0x40cc, 0x4516, 0x4960, 0x4e47,
32 0x532e, 0x58b1, 0x5e35, 0x6456, 0x6a76, 0x7134, 0x77f1, 0x7f4c,
33 0x86a6, 0x8e9d, 0x9695, 0x9f29, 0xa7bd, 0xb0ee, 0xba1f, 0xc350
36 bool _backlight_init(void)
38 /* configure PD4 as output */
41 /* set PD4 low (backlight off) */
44 /* IOMUXB - set PWM0 pin as GPIO */
45 SCU_IOMUXB_CON
&= ~(1 << 11); /* type<<11<<channel */
47 /* DIV/2, PWM reset */
48 PWMT0_CTRL
= (0<<9) | (1<<7);
50 /* set pwm frequency to 500Hz - my lcd panel can't cope more reliably */
51 /* (apb_freq/pwm_freq)/pwm_div = (50 000 000/500)/2 */
53 PWMT0_HRC
= log_brightness
[brightness
];
58 /* DIV/2, PWM output enable, PWM timer enable */
59 PWMT0_CTRL
= (0<<9) | (1<<3) | (1<<0);
64 void _backlight_on(void)
66 /* enable PWM clock */
67 SCU_CLKCFG
&= ~(1<<29);
69 /* set output pin as PWM pin */
70 SCU_IOMUXB_CON
|= (1<<11); /* type<<11<<channel */
73 PWMT0_CTRL
|= (1<<3) | (1<<0);
76 void _backlight_off(void)
78 /* setup PWM0 pin as GPIO which is pulled low */
79 SCU_IOMUXB_CON
&= ~(1<<11);
82 PWMT0_CTRL
&= ~(1<<3) | (1<<0);
84 /* disable PWM clock */
85 SCU_CLKCFG
|= (1<<29);
88 void _backlight_set_brightness(int val
)
90 brightness
= val
& 0x1f;
91 PWMT0_HRC
= log_brightness
[brightness
];