Meizu M3: implement logarithmic brightness curve (curve provided by markun) and incre...
[kugel-rb.git] / firmware / target / arm / s5l8700 / backlight-meizu.c
blob23dcbb18205ef9f6e5e02735712c5299bb77f14c
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2009 by Bertrik Sikken
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 ****************************************************************************/
21 #include <stdbool.h>
23 #include "config.h"
24 #include "backlight.h"
25 #include "backlight-target.h"
26 #include "system.h"
29 Interrupt-driven backlight driver using the PWM mode of a hardware timer.
31 Backlight brightness is implemented by configuring one of the timers in
32 the SoC for PWM mode. In this mode, two interrupts are generated for each
33 cycle, one at the start of the cycle and another one sometime between the
34 first interrupt and the start of the next cycle. The backlight is switched
35 on at the first interrupt and switched off at the second interrupt. This
36 way, the position in time of the second interrupt determines the duty cycle
37 and thereby the brightness of the backlight.
38 The backlight is switched on and off by means of a GPIO pin.
41 void INT_TIMERA(void)
43 unsigned int tacon = TACON;
45 /* clear interrupts */
46 TACON = tacon;
48 /* TA_INT1, start of PWM cycle: enable backlight */
49 if (tacon & (1 << 17)) {
50 PDAT0 |= (1 << 2);
53 /* TA_INT0, disable backlight until next cycle */
54 if (tacon & (1 << 16)) {
55 PDAT0 &= ~(1 << 2);
59 void _backlight_set_brightness(int brightness)
61 static const unsigned char logtable[] = {0, 1, 2, 3, 5, 7, 10, 15, 22, 31, 44, 63, 90, 127, 180, 255};
63 if (brightness == MIN_BRIGHTNESS_SETTING) {
64 /* turn backlight fully off and disable interrupt */
65 PDAT0 &= ~(1 << 2);
66 INTMSK &= ~(1 << 5);
68 else if (brightness == MAX_BRIGHTNESS_SETTING) {
69 /* turn backlight fully on and disable interrupt */
70 PDAT0 |= (1 << 2);
71 INTMSK &= ~(1 << 5);
73 else {
74 /* set PWM width and enable interrupt */
75 TADATA0 = logtable[brightness];
76 INTMSK |= (1 << 5);
80 void _backlight_on(void)
82 _backlight_set_brightness(backlight_brightness);
85 void _backlight_off(void)
87 _backlight_set_brightness(MIN_BRIGHTNESS_SETTING);
90 bool _backlight_init(void)
92 /* enable backlight pin as GPIO */
93 PCON0 = ((PCON0 & ~(3 << 4)) | (1 << 4));
95 /* enable timer clock */
96 PWRCON &= ~(1 << 4);
98 /* configure timer */
99 TACMD = (1 << 1); /* TA_CLR */
100 TACMD = (1 << 0); /* TA_EN */
101 TACON = (1 << 13) | /* TA_INT1_EN */
102 (1 << 12) | /* TA_INT0_EN */
103 (1 << 11) | /* TA_START */
104 (3 << 8) | /* TA_CS = PCLK / 64 */
105 (1 << 4); /* TA_MODE_SEL = PWM mode */
106 TADATA1 = 255; /* set PWM period */
107 TAPRE = 30; /* prescaler */
109 _backlight_on();
111 return true;