diff options
Diffstat (limited to 'firmware/target/mips/ingenic_jz47xx/onda_vx747/backlight-onda_vx7X7.c')
-rw-r--r-- | firmware/target/mips/ingenic_jz47xx/onda_vx747/backlight-onda_vx7X7.c | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/firmware/target/mips/ingenic_jz47xx/onda_vx747/backlight-onda_vx7X7.c b/firmware/target/mips/ingenic_jz47xx/onda_vx747/backlight-onda_vx7X7.c new file mode 100644 index 0000000000..eec48768b2 --- /dev/null +++ b/firmware/target/mips/ingenic_jz47xx/onda_vx747/backlight-onda_vx7X7.c | |||
@@ -0,0 +1,163 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2008 by Maurus Cuelenaere | ||
11 | * | ||
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. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "config.h" | ||
23 | #include "jz4740.h" | ||
24 | #include "backlight-target.h" | ||
25 | |||
26 | /* PWM_CHN7 == GPIO(32*3 + 31) */ | ||
27 | #define BACKLIGHT_GPIO (32*3+31) | ||
28 | #define BACKLIGHT_PWM 7 | ||
29 | |||
30 | #define SW_PWM 1 | ||
31 | |||
32 | #if SW_PWM | ||
33 | |||
34 | static bool backlight_on; | ||
35 | |||
36 | static void set_backlight(int val) | ||
37 | { | ||
38 | (void)val; | ||
39 | } | ||
40 | |||
41 | bool _backlight_init(void) | ||
42 | { | ||
43 | __gpio_as_output(BACKLIGHT_GPIO); | ||
44 | __gpio_set_pin(BACKLIGHT_GPIO); | ||
45 | |||
46 | backlight_on = true; | ||
47 | |||
48 | return true; | ||
49 | } | ||
50 | |||
51 | bool backlight_enabled(void) | ||
52 | { | ||
53 | return backlight_on; | ||
54 | } | ||
55 | |||
56 | void _backlight_on(void) | ||
57 | { | ||
58 | __gpio_set_pin(BACKLIGHT_GPIO); | ||
59 | backlight_on = true; | ||
60 | } | ||
61 | |||
62 | void _backlight_off(void) | ||
63 | { | ||
64 | __gpio_clear_pin(BACKLIGHT_GPIO); | ||
65 | backlight_on = false; | ||
66 | } | ||
67 | |||
68 | #else | ||
69 | |||
70 | static int old_val; | ||
71 | static void set_backlight(int val) | ||
72 | { | ||
73 | if(val == old_val) | ||
74 | return; | ||
75 | |||
76 | /* Taken from the OF */ | ||
77 | int tmp; | ||
78 | tmp = (val/2 + __cpm_get_rtcclk()) / val; | ||
79 | if(tmp > 0xFFFF) | ||
80 | tmp = 0xFFFF; | ||
81 | |||
82 | __tcu_set_half_data(BACKLIGHT_PWM, (tmp * val * 1374389535) >> 5); | ||
83 | __tcu_set_full_data(BACKLIGHT_PWM, tmp); | ||
84 | |||
85 | old_val = val; | ||
86 | } | ||
87 | |||
88 | static void set_backlight_on(void) | ||
89 | { | ||
90 | if(old_val == MAX_BRIGHTNESS_SETTING) | ||
91 | return; | ||
92 | |||
93 | __tcu_start_timer_clock(BACKLIGHT_PWM); | ||
94 | |||
95 | set_backlight(MAX_BRIGHTNESS_SETTING); | ||
96 | |||
97 | __tcu_set_count(BACKLIGHT_PWM, 0); | ||
98 | __tcu_start_counter(BACKLIGHT_PWM); | ||
99 | |||
100 | __tcu_enable_pwm_output(BACKLIGHT_PWM); | ||
101 | } | ||
102 | |||
103 | static void set_backlight_off(void) | ||
104 | { | ||
105 | __tcu_stop_counter(BACKLIGHT_PWM); | ||
106 | __tcu_disable_pwm_output(BACKLIGHT_PWM); | ||
107 | __tcu_stop_timer_clock(BACKLIGHT_PWM); | ||
108 | |||
109 | old_val = -1; | ||
110 | } | ||
111 | |||
112 | bool _backlight_init(void) | ||
113 | { | ||
114 | __gpio_as_pwm(BACKLIGHT_PWM); | ||
115 | __tcu_start_timer_clock(BACKLIGHT_PWM); | ||
116 | |||
117 | __tcu_stop_counter(BACKLIGHT_PWM); | ||
118 | __tcu_disable_pwm_output(BACKLIGHT_PWM); | ||
119 | |||
120 | __tcu_init_pwm_output_low(BACKLIGHT_PWM); | ||
121 | __tcu_select_rtcclk(BACKLIGHT_PWM); | ||
122 | __tcu_select_clk_div1(BACKLIGHT_PWM); | ||
123 | |||
124 | __tcu_mask_half_match_irq(BACKLIGHT_PWM); | ||
125 | __tcu_mask_full_match_irq(BACKLIGHT_PWM); | ||
126 | |||
127 | old_val = -1; | ||
128 | |||
129 | set_backlight_on(); | ||
130 | |||
131 | return true; | ||
132 | } | ||
133 | |||
134 | bool backlight_enabled(void) | ||
135 | { | ||
136 | return old_val > -1 ? true : false; | ||
137 | } | ||
138 | |||
139 | void _backlight_on(void) | ||
140 | { | ||
141 | set_backlight_on(); | ||
142 | } | ||
143 | |||
144 | void _backlight_off(void) | ||
145 | { | ||
146 | set_backlight_off(); | ||
147 | } | ||
148 | #endif /* !SW_PWM */ | ||
149 | |||
150 | #ifdef HAVE_BACKLIGHT_BRIGHTNESS | ||
151 | void _backlight_set_brightness(int brightness) | ||
152 | { | ||
153 | set_backlight(brightness); | ||
154 | } | ||
155 | #endif | ||
156 | |||
157 | #ifdef HAVE_LCD_SLEEP | ||
158 | /* Turn off LED supply */ | ||
159 | void _backlight_lcd_sleep(void) | ||
160 | { | ||
161 | set_backlight_off(); | ||
162 | } | ||
163 | #endif | ||