diff options
Diffstat (limited to 'firmware/target/arm/s3c2440/mini2440/backlight-mini2440.c')
-rw-r--r-- | firmware/target/arm/s3c2440/mini2440/backlight-mini2440.c | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/firmware/target/arm/s3c2440/mini2440/backlight-mini2440.c b/firmware/target/arm/s3c2440/mini2440/backlight-mini2440.c new file mode 100644 index 0000000000..88c0b5ce2c --- /dev/null +++ b/firmware/target/arm/s3c2440/mini2440/backlight-mini2440.c | |||
@@ -0,0 +1,151 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2009 by Bob Cousins | ||
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 | #include "config.h" | ||
22 | #include "cpu.h" | ||
23 | #include "system.h" | ||
24 | #include "backlight-target.h" | ||
25 | #include "backlight.h" | ||
26 | #include "lcd.h" | ||
27 | #include "power.h" | ||
28 | |||
29 | |||
30 | /* Dummy value at index 0, 1-12 used. */ | ||
31 | static const unsigned char log_brightness[13] = | ||
32 | {0,0,1,2,3,5,7,10,15,22,31,44,63}; | ||
33 | |||
34 | |||
35 | static enum backlight_states | ||
36 | { | ||
37 | BACKLIGHT_CONTROL_IDLE, | ||
38 | BACKLIGHT_CONTROL_OFF, | ||
39 | BACKLIGHT_CONTROL_ON, | ||
40 | BACKLIGHT_CONTROL_SET, | ||
41 | BACKLIGHT_CONTROL_FADE | ||
42 | } backlight_control; | ||
43 | |||
44 | static unsigned char _backlight_brightness; | ||
45 | static unsigned char backlight_target; | ||
46 | |||
47 | |||
48 | /* Assumes that the backlight has been initialized */ | ||
49 | void _backlight_set_brightness(int brightness) | ||
50 | { | ||
51 | /* stop the interrupt from messing us up */ | ||
52 | backlight_control = BACKLIGHT_CONTROL_IDLE; | ||
53 | _backlight_brightness = log_brightness[brightness]; | ||
54 | backlight_control = BACKLIGHT_CONTROL_SET; | ||
55 | } | ||
56 | |||
57 | void _backlight_set_state (unsigned int level) | ||
58 | { | ||
59 | if (level == 0) | ||
60 | GPGDAT &= ~GPIO_LCD_PWR; | ||
61 | else | ||
62 | GPGDAT |= GPIO_LCD_PWR; | ||
63 | } | ||
64 | |||
65 | /* led_control_service runs in interrupt context - be brief! | ||
66 | * This service is called once per interrupt timer tick - 100 times a second. | ||
67 | * | ||
68 | * There should be at most only one i2c operation per call - if more are need | ||
69 | * the calls should be spread across calls. | ||
70 | * | ||
71 | * Putting all led servicing in one thread means that we wont step on any | ||
72 | * i2c operations - they are all serialized here in the ISR tick. It also | ||
73 | * insures that we get called at equal timing for good visual effect. | ||
74 | */ | ||
75 | #ifndef BOOTLOADER | ||
76 | static void led_control_service(void) | ||
77 | { | ||
78 | switch (backlight_control) | ||
79 | { | ||
80 | case BACKLIGHT_CONTROL_IDLE: | ||
81 | backlight_control = BACKLIGHT_CONTROL_IDLE; | ||
82 | break; | ||
83 | case BACKLIGHT_CONTROL_OFF: | ||
84 | _backlight_set_brightness(0); | ||
85 | backlight_control = BACKLIGHT_CONTROL_IDLE; | ||
86 | break; | ||
87 | case BACKLIGHT_CONTROL_ON: | ||
88 | _backlight_set_brightness(255); | ||
89 | backlight_control = BACKLIGHT_CONTROL_IDLE; | ||
90 | break; | ||
91 | case BACKLIGHT_CONTROL_SET: | ||
92 | _backlight_set_brightness(255); | ||
93 | backlight_control = BACKLIGHT_CONTROL_IDLE; | ||
94 | break; | ||
95 | case BACKLIGHT_CONTROL_FADE: | ||
96 | _backlight_set_brightness(0); | ||
97 | backlight_control = BACKLIGHT_CONTROL_IDLE; | ||
98 | break; | ||
99 | default: | ||
100 | backlight_control = BACKLIGHT_CONTROL_IDLE; | ||
101 | break; | ||
102 | } | ||
103 | } | ||
104 | #endif /* BOOTLOADER */ | ||
105 | |||
106 | static void __backlight_dim(bool dim_now) | ||
107 | { | ||
108 | /* dont let the interrupt tick happen */ | ||
109 | backlight_control = BACKLIGHT_CONTROL_IDLE; | ||
110 | backlight_target = dim_now ? 0 : _backlight_brightness; | ||
111 | if(backlight_target==0 && _backlight_brightness==0) | ||
112 | { | ||
113 | if(dim_now == false) | ||
114 | backlight_control = BACKLIGHT_CONTROL_ON; | ||
115 | else | ||
116 | backlight_control = BACKLIGHT_CONTROL_OFF; | ||
117 | } | ||
118 | else | ||
119 | backlight_control = BACKLIGHT_CONTROL_FADE; | ||
120 | } | ||
121 | |||
122 | void _backlight_on(void) | ||
123 | { | ||
124 | #ifdef HAVE_LCD_ENABLE | ||
125 | lcd_enable(true); /* power on lcd + visible display */ | ||
126 | #endif | ||
127 | __backlight_dim(false); | ||
128 | } | ||
129 | |||
130 | void _backlight_off(void) | ||
131 | { | ||
132 | __backlight_dim(true); | ||
133 | } | ||
134 | |||
135 | |||
136 | bool _backlight_init(void) | ||
137 | { | ||
138 | unsigned char brightness = log_brightness[DEFAULT_BRIGHTNESS_SETTING]; | ||
139 | _backlight_brightness = brightness; | ||
140 | |||
141 | backlight_control = BACKLIGHT_CONTROL_ON; | ||
142 | |||
143 | _backlight_set_state (1); | ||
144 | S3C2440_GPIO_CONFIG (GPGCON, 4, GPIO_OUTPUT); | ||
145 | |||
146 | #ifndef BOOTLOADER | ||
147 | /* put the led control on the tick list */ | ||
148 | tick_add_task(led_control_service); | ||
149 | #endif | ||
150 | return true; | ||
151 | } | ||