summaryrefslogtreecommitdiff
path: root/firmware/target/arm/as3525/sansa-c200v2
diff options
context:
space:
mode:
authorTobias Diedrich <ranma+coreboot@tdiedrich.de>2010-04-06 18:32:47 +0000
committerTobias Diedrich <ranma+coreboot@tdiedrich.de>2010-04-06 18:32:47 +0000
commitea907b31ae6595fc2b92e2da5da3cb12d4a6abff (patch)
treeda937983aa859472fdbea6625b8fa784b29de4b9 /firmware/target/arm/as3525/sansa-c200v2
parent36c16ea05d67567ee75faaf4f3a5f29ca734ac6d (diff)
downloadrockbox-ea907b31ae6595fc2b92e2da5da3cb12d4a6abff.tar.gz
rockbox-ea907b31ae6595fc2b92e2da5da3cb12d4a6abff.zip
Detect C200v2 variant by reading A7, use A5 or A7 to control backlight and buttonlight depending on the result.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25499 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/arm/as3525/sansa-c200v2')
-rw-r--r--firmware/target/arm/as3525/sansa-c200v2/backlight-c200v2.c106
1 files changed, 88 insertions, 18 deletions
diff --git a/firmware/target/arm/as3525/sansa-c200v2/backlight-c200v2.c b/firmware/target/arm/as3525/sansa-c200v2/backlight-c200v2.c
index e094cca8fe..9c236d3653 100644
--- a/firmware/target/arm/as3525/sansa-c200v2/backlight-c200v2.c
+++ b/firmware/target/arm/as3525/sansa-c200v2/backlight-c200v2.c
@@ -37,26 +37,75 @@ static const int brightness_table[MAX_BRIGHTNESS_SETTING+1] = {
37 37
38static void _ll_backlight_on(void) 38static void _ll_backlight_on(void)
39{ 39{
40 GPIOA_PIN(5) = 1<<5; 40 if (c200v2_variant == 0) {
41 GPIOA_PIN(5) = 1<<5;
42 } else {
43 GPIOA_PIN(7) = 1<<7;
44 }
41} 45}
42 46
43static void _ll_backlight_off(void) 47static void _ll_backlight_off(void)
44{ 48{
45 GPIOA_PIN(5) = 0; 49 if (c200v2_variant == 0) {
50 GPIOA_PIN(5) = 0;
51 } else {
52 GPIOA_PIN(7) = 0;
53 }
54}
55
56static void _ll_buttonlight_on(void)
57{
58 if (c200v2_variant == 1) {
59 /* Main buttonlight is on A5 */
60 GPIOA_PIN(5) = 1<<5;
61 } else {
62 /* Needed for buttonlight and MicroSD to work at the same time */
63 /* Turn ROD control on, as the OF does */
64 GPIOD_DIR |= (1<<7);
65 SD_MCI_POWER |= (1<<7);
66 GPIOD_PIN(7) = (1<<7);
67 }
68}
69
70static void _ll_buttonlight_off(void)
71{
72 if (c200v2_variant == 1) {
73 /* Main buttonlight is on A5 */
74 GPIOA_PIN(5) = 0;
75 } else {
76 /* Needed for buttonlight and MicroSD to work at the same time */
77 /* Turn ROD control off, as the OF does */
78 SD_MCI_POWER &= ~(1<<7);
79 GPIOD_PIN(7) = 0;
80 GPIOD_DIR &= ~(1<<7);
81 }
46} 82}
47 83
48void _backlight_pwm(int on) 84void _backlight_pwm(int on)
49{ 85{
50 if (on) { 86 if (on) {
51 _ll_backlight_on(); 87 if (backlight_is_on)
88 _ll_backlight_on();
89
90 if (buttonlight_is_on)
91 _ll_buttonlight_on();
52 } else { 92 } else {
53 _ll_backlight_off(); 93 if (backlight_is_on)
94 _ll_backlight_off();
95
96 if (buttonlight_is_on)
97 _ll_buttonlight_off();
54 } 98 }
55} 99}
56 100
57bool _backlight_init(void) 101bool _backlight_init(void)
58{ 102{
59 GPIOA_DIR |= 1<<5; 103 GPIOA_DIR |= 1<<5;
104 if (c200v2_variant == 1) {
105 /* On this variant A7 is the backlight and
106 * A5 is the buttonlight */
107 GPIOA_DIR |= 1<<7;
108 }
60 return true; 109 return true;
61} 110}
62 111
@@ -70,21 +119,40 @@ void _backlight_set_brightness(int brightness)
70 _backlight_off(); 119 _backlight_off();
71} 120}
72 121
122static void _pwm_on(void)
123{
124 _set_timer2_pwm_ratio(backlight_level);
125}
126
127static void _pwm_off(void)
128{
129 if (buttonlight_is_on == 0 && backlight_is_on == 0)
130 _set_timer2_pwm_ratio(0);
131}
132
73void _backlight_on(void) 133void _backlight_on(void)
74{ 134{
135 if (backlight_is_on == 1) {
136 /* Update pwm ratio in case user changed the brightness */
137 _pwm_on();
138 return;
139 }
140
75#ifdef HAVE_LCD_ENABLE 141#ifdef HAVE_LCD_ENABLE
76 lcd_enable(true); /* power on lcd + visible display */ 142 lcd_enable(true); /* power on lcd + visible display */
77#endif 143#endif
78 if (!backlight_is_on) 144 _ll_backlight_on();
79 _ll_backlight_on(); 145 _pwm_on();
80 _set_timer2_pwm_ratio(backlight_level);
81 backlight_is_on = 1; 146 backlight_is_on = 1;
82} 147}
83 148
84void _backlight_off(void) 149void _backlight_off(void)
85{ 150{
151 if (backlight_is_on == 0)
152 return;
153
86 backlight_is_on = 0; 154 backlight_is_on = 0;
87 _set_timer2_pwm_ratio(0); 155 _pwm_off();
88 _ll_backlight_off(); 156 _ll_backlight_off();
89#ifdef HAVE_LCD_ENABLE 157#ifdef HAVE_LCD_ENABLE
90 lcd_enable(false); /* power off visible display */ 158 lcd_enable(false); /* power off visible display */
@@ -93,20 +161,22 @@ void _backlight_off(void)
93 161
94void _buttonlight_on(void) 162void _buttonlight_on(void)
95{ 163{
96 /* Needed for buttonlight and MicroSD to work at the same time */ 164 if (buttonlight_is_on == 1)
97 /* Turn ROD control on, as the OF does */ 165 return;
98 GPIOD_DIR |= (1<<7); 166
99 SD_MCI_POWER |= (1<<7); 167 _ll_buttonlight_on();
100 GPIOD_PIN(7) = (1<<7); 168 _pwm_on();
101 buttonlight_is_on = 1; 169 buttonlight_is_on = 1;
102} 170}
103 171
104void _buttonlight_off(void) 172void _buttonlight_off(void)
105{ 173{
106 /* Needed for buttonlight and MicroSD to work at the same time */ 174 if (buttonlight_is_on == 0)
107 /* Turn ROD control off, as the OF does */ 175 return;
108 SD_MCI_POWER &= ~(1<<7); 176
109 GPIOD_PIN(7) = 0;
110 GPIOD_DIR &= ~(1<<7);
111 buttonlight_is_on = 0; 177 buttonlight_is_on = 0;
178 _pwm_off();
179 _ll_buttonlight_off();
112} 180}
181
182/* vim:set ts=4 sw=4 et: */