diff options
Diffstat (limited to 'firmware/target/arm/rk27xx/ihifi2')
-rw-r--r-- | firmware/target/arm/rk27xx/ihifi2/audio-ihifi770.c | 88 | ||||
-rw-r--r-- | firmware/target/arm/rk27xx/ihifi2/audio-ihifi800.c | 67 | ||||
-rw-r--r-- | firmware/target/arm/rk27xx/ihifi2/button-ihifi.c | 99 | ||||
-rw-r--r-- | firmware/target/arm/rk27xx/ihifi2/button-target.h | 50 | ||||
-rw-r--r-- | firmware/target/arm/rk27xx/ihifi2/lcd-ihifi770.c | 285 | ||||
-rw-r--r-- | firmware/target/arm/rk27xx/ihifi2/lcd-ihifi770c.c | 248 | ||||
-rw-r--r-- | firmware/target/arm/rk27xx/ihifi2/lcd-ihifi800.c | 228 | ||||
-rw-r--r-- | firmware/target/arm/rk27xx/ihifi2/lcd-target.h | 26 | ||||
-rw-r--r-- | firmware/target/arm/rk27xx/ihifi2/power-ihifi.c | 53 | ||||
-rw-r--r-- | firmware/target/arm/rk27xx/ihifi2/powermgmt-ihifi770.c | 64 | ||||
-rw-r--r-- | firmware/target/arm/rk27xx/ihifi2/powermgmt-ihifi770c.c | 64 | ||||
-rw-r--r-- | firmware/target/arm/rk27xx/ihifi2/powermgmt-ihifi800.c | 64 |
12 files changed, 1336 insertions, 0 deletions
diff --git a/firmware/target/arm/rk27xx/ihifi2/audio-ihifi770.c b/firmware/target/arm/rk27xx/ihifi2/audio-ihifi770.c new file mode 100644 index 0000000000..a21ea9cfef --- /dev/null +++ b/firmware/target/arm/rk27xx/ihifi2/audio-ihifi770.c | |||
@@ -0,0 +1,88 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2016 by Roman Stolyarov | ||
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 "system.h" | ||
23 | #include "kernel.h" | ||
24 | #include "audiohw.h" | ||
25 | |||
26 | void wm8740_hw_init(void) | ||
27 | { | ||
28 | GPIO_PADR &= ~(1<<0); /* MD */ | ||
29 | GPIO_PACON |= (1<<0); | ||
30 | |||
31 | GPIO_PADR &= ~(1<<1); /* MC */ | ||
32 | GPIO_PACON |= (1<<1); | ||
33 | |||
34 | SCU_IOMUXB_CON &= ~(1<<2); | ||
35 | GPIO_PCDR |= (1<<4); /* ML */ | ||
36 | GPIO_PCCON |= (1<<4); | ||
37 | } | ||
38 | |||
39 | void wm8740_set_md(const int val) | ||
40 | { | ||
41 | if (val) | ||
42 | GPIO_PADR |= (1<<0); | ||
43 | else | ||
44 | GPIO_PADR &= ~(1<<0); | ||
45 | } | ||
46 | |||
47 | void wm8740_set_mc(const int val) | ||
48 | { | ||
49 | if (val) | ||
50 | GPIO_PADR |= (1<<1); | ||
51 | else | ||
52 | GPIO_PADR &= ~(1<<1); | ||
53 | } | ||
54 | |||
55 | void wm8740_set_ml(const int val) | ||
56 | { | ||
57 | if (val) | ||
58 | GPIO_PCDR |= (1<<4); | ||
59 | else | ||
60 | GPIO_PCDR &= ~(1<<4); | ||
61 | } | ||
62 | |||
63 | static void pop_ctrl(const int val) | ||
64 | { | ||
65 | if (val) | ||
66 | GPIO_PADR |= (1<<7); | ||
67 | else | ||
68 | GPIO_PADR &= ~(1<<7); | ||
69 | } | ||
70 | |||
71 | void audiohw_postinit(void) | ||
72 | { | ||
73 | pop_ctrl(0); | ||
74 | sleep(HZ/4); | ||
75 | wm8740_hw_init(); | ||
76 | audiohw_init(); | ||
77 | sleep(HZ/2); | ||
78 | pop_ctrl(1); | ||
79 | sleep(HZ/4); | ||
80 | audiohw_unmute(); | ||
81 | } | ||
82 | |||
83 | void audiohw_close(void) | ||
84 | { | ||
85 | audiohw_mute(); | ||
86 | pop_ctrl(0); | ||
87 | sleep(HZ/4); | ||
88 | } | ||
diff --git a/firmware/target/arm/rk27xx/ihifi2/audio-ihifi800.c b/firmware/target/arm/rk27xx/ihifi2/audio-ihifi800.c new file mode 100644 index 0000000000..14b126c72a --- /dev/null +++ b/firmware/target/arm/rk27xx/ihifi2/audio-ihifi800.c | |||
@@ -0,0 +1,67 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2016 by Roman Stolyarov | ||
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 "system.h" | ||
23 | #include "kernel.h" | ||
24 | #include "audiohw.h" | ||
25 | #include "i2c-rk27xx.h" | ||
26 | |||
27 | #define ES9018_I2C_ADDR 0x90 | ||
28 | |||
29 | static unsigned char buf; | ||
30 | |||
31 | void es9018_write_reg(uint8_t reg, uint8_t val) | ||
32 | { | ||
33 | buf = val; | ||
34 | i2c_write(ES9018_I2C_ADDR, reg, sizeof(buf), (void*)&buf); | ||
35 | } | ||
36 | |||
37 | uint8_t es9018_read_reg(uint8_t reg) | ||
38 | { | ||
39 | i2c_read(ES9018_I2C_ADDR, reg, sizeof(buf), (void*)&buf); | ||
40 | return buf; | ||
41 | } | ||
42 | |||
43 | static void pop_ctrl(const int val) | ||
44 | { | ||
45 | if (val) | ||
46 | GPIO_PADR |= (1<<7); | ||
47 | else | ||
48 | GPIO_PADR &= ~(1<<7); | ||
49 | } | ||
50 | |||
51 | void audiohw_postinit(void) | ||
52 | { | ||
53 | pop_ctrl(0); | ||
54 | sleep(HZ/4); | ||
55 | audiohw_init(); | ||
56 | sleep(HZ/2); | ||
57 | pop_ctrl(1); | ||
58 | sleep(HZ/4); | ||
59 | audiohw_unmute(); | ||
60 | } | ||
61 | |||
62 | void audiohw_close(void) | ||
63 | { | ||
64 | audiohw_mute(); | ||
65 | pop_ctrl(0); | ||
66 | sleep(HZ/4); | ||
67 | } | ||
diff --git a/firmware/target/arm/rk27xx/ihifi2/button-ihifi.c b/firmware/target/arm/rk27xx/ihifi2/button-ihifi.c new file mode 100644 index 0000000000..172853a83a --- /dev/null +++ b/firmware/target/arm/rk27xx/ihifi2/button-ihifi.c | |||
@@ -0,0 +1,99 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2016 by Roman Stolyarov | ||
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 "system.h" | ||
24 | #include "kernel.h" | ||
25 | #include "button.h" | ||
26 | #include "adc.h" | ||
27 | #include "backlight.h" | ||
28 | |||
29 | static bool soft_hold = false; | ||
30 | #ifndef BOOTLOADER | ||
31 | static unsigned hold_counter = 0; | ||
32 | #ifndef IHIFI800 | ||
33 | #define HOLDBUTTON gpio_btn | ||
34 | #define HOLDCNTMAX HZ | ||
35 | #else | ||
36 | #define HOLDBUTTON (gpio_btn) && (adc_val > 325) && (adc_val < 480) | ||
37 | #define HOLDCNTMAX (HZ/10) | ||
38 | #endif | ||
39 | #endif | ||
40 | |||
41 | void button_init_device(void) { | ||
42 | GPIO_PCCON &= ~(1<<1); /* PWR BTN */ | ||
43 | GPIO_PCCON &= ~(1<<7); /* CD */ | ||
44 | } | ||
45 | |||
46 | bool button_hold(void) | ||
47 | { | ||
48 | return soft_hold; | ||
49 | } | ||
50 | |||
51 | int button_read_device(void) { | ||
52 | int adc_val = adc_read(ADC_BUTTONS); | ||
53 | int gpio_btn = GPIO_PCDR & (1<<1); | ||
54 | |||
55 | int button = BUTTON_NONE; | ||
56 | |||
57 | if (gpio_btn) | ||
58 | button |= BUTTON_POWER; | ||
59 | |||
60 | #ifndef BOOTLOADER | ||
61 | if (HOLDBUTTON) { | ||
62 | if (++hold_counter == HOLDCNTMAX) { | ||
63 | soft_hold = !soft_hold; | ||
64 | backlight_hold_changed(soft_hold); | ||
65 | } | ||
66 | } else { | ||
67 | hold_counter = 0; | ||
68 | } | ||
69 | if (soft_hold) { | ||
70 | return (hold_counter <= HOLDCNTMAX) ? BUTTON_NONE : button; | ||
71 | } | ||
72 | #endif | ||
73 | |||
74 | if (adc_val < 792) { | ||
75 | if (adc_val < 480) { | ||
76 | if (adc_val < 170) { | ||
77 | if (adc_val < 46) { | ||
78 | button |= BUTTON_HOME; // 0-45 | ||
79 | } else { | ||
80 | button |= BUTTON_PLAY; // 46-169 | ||
81 | } | ||
82 | } else { | ||
83 | if (adc_val < 325) { | ||
84 | button |= BUTTON_NEXT; // 170-324 | ||
85 | } else { | ||
86 | button |= BUTTON_VOL_UP;// 325-479 | ||
87 | } | ||
88 | } | ||
89 | } else { | ||
90 | if (adc_val < 636) { | ||
91 | button |= BUTTON_VOL_DOWN;// 480-635 | ||
92 | } else { | ||
93 | button |= BUTTON_PREV; // 636-791 | ||
94 | } | ||
95 | } | ||
96 | } | ||
97 | |||
98 | return button; | ||
99 | } | ||
diff --git a/firmware/target/arm/rk27xx/ihifi2/button-target.h b/firmware/target/arm/rk27xx/ihifi2/button-target.h new file mode 100644 index 0000000000..211e20e1d6 --- /dev/null +++ b/firmware/target/arm/rk27xx/ihifi2/button-target.h | |||
@@ -0,0 +1,50 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2016 by Roman Stolyarov | ||
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 | #ifndef _BUTTON_TARGET_H_ | ||
22 | #define _BUTTON_TARGET_H_ | ||
23 | |||
24 | #define HAS_BUTTON_HOLD | ||
25 | |||
26 | /* Main unit's buttons */ | ||
27 | #define BUTTON_POWER 0x00000001 | ||
28 | #define BUTTON_HOME 0x00000002 | ||
29 | #define BUTTON_PREV 0x00000004 | ||
30 | #define BUTTON_NEXT 0x00000008 | ||
31 | #define BUTTON_PLAY 0x00000010 | ||
32 | #define BUTTON_VOL_UP 0x00000020 | ||
33 | #define BUTTON_VOL_DOWN 0x00000040 | ||
34 | |||
35 | #define BUTTON_LEFT 0 | ||
36 | #define BUTTON_RIGHT 0 | ||
37 | |||
38 | #define BUTTON_MAIN (BUTTON_POWER | BUTTON_HOME | BUTTON_PREV | BUTTON_NEXT | \ | ||
39 | BUTTON_PLAY | BUTTON_VOL_UP | BUTTON_VOL_DOWN) | ||
40 | |||
41 | /* Software power-off */ | ||
42 | #ifndef IHIFI800 | ||
43 | #define POWEROFF_BUTTON BUTTON_POWER | ||
44 | #else | ||
45 | #define POWEROFF_BUTTON BUTTON_HOME | ||
46 | #endif | ||
47 | |||
48 | #define POWEROFF_COUNT 30 | ||
49 | |||
50 | #endif /* _BUTTON_TARGET_H_ */ | ||
diff --git a/firmware/target/arm/rk27xx/ihifi2/lcd-ihifi770.c b/firmware/target/arm/rk27xx/ihifi2/lcd-ihifi770.c new file mode 100644 index 0000000000..23505d9fa0 --- /dev/null +++ b/firmware/target/arm/rk27xx/ihifi2/lcd-ihifi770.c | |||
@@ -0,0 +1,285 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2016 by Roman Stolyarov | ||
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 "kernel.h" | ||
24 | #include "lcd.h" | ||
25 | #include "system.h" | ||
26 | #include "cpu.h" | ||
27 | #include "lcdif-rk27xx.h" | ||
28 | |||
29 | static bool display_on = false; | ||
30 | |||
31 | void lcd_display_init(void) | ||
32 | { | ||
33 | unsigned int i, x, y; | ||
34 | |||
35 | lcd_cmd(0x11); | ||
36 | |||
37 | lcd_cmd(0x13); | ||
38 | |||
39 | mdelay(120); | ||
40 | |||
41 | lcd_cmd(0x29); | ||
42 | |||
43 | lcd_cmd(0xB0); | ||
44 | lcd_data(0x05); | ||
45 | lcd_data(0x00); | ||
46 | lcd_data(0xF0); | ||
47 | lcd_data(0x0A); | ||
48 | lcd_data(0x41); | ||
49 | lcd_data(0x02); | ||
50 | lcd_data(0x0A); | ||
51 | lcd_data(0x30); | ||
52 | lcd_data(0x31); | ||
53 | lcd_data(0x36); | ||
54 | lcd_data(0x37); | ||
55 | lcd_data(0x40); | ||
56 | lcd_data(0x02); | ||
57 | lcd_data(0x3F); | ||
58 | lcd_data(0x40); | ||
59 | lcd_data(0x02); | ||
60 | lcd_data(0x81); | ||
61 | lcd_data(0x04); | ||
62 | lcd_data(0x05); | ||
63 | lcd_data(0x64); | ||
64 | |||
65 | lcd_cmd(0xFC); | ||
66 | lcd_data(0x88); | ||
67 | lcd_data(0x00); | ||
68 | lcd_data(0x10); | ||
69 | lcd_data(0x01); | ||
70 | lcd_data(0x01); | ||
71 | lcd_data(0x10); | ||
72 | lcd_data(0x42); | ||
73 | lcd_data(0x42); | ||
74 | lcd_data(0x22); | ||
75 | lcd_data(0x11); | ||
76 | lcd_data(0x11); | ||
77 | lcd_data(0x22); | ||
78 | lcd_data(0x99); | ||
79 | lcd_data(0xAA); | ||
80 | lcd_data(0xAA); | ||
81 | lcd_data(0xAA); | ||
82 | lcd_data(0xBB); | ||
83 | lcd_data(0xBB); | ||
84 | lcd_data(0xAA); | ||
85 | lcd_data(0x33); | ||
86 | lcd_data(0x33); | ||
87 | lcd_data(0x11); | ||
88 | lcd_data(0x01); | ||
89 | lcd_data(0x01); | ||
90 | lcd_data(0x01); | ||
91 | lcd_data(0x00); | ||
92 | lcd_data(0x00); | ||
93 | lcd_data(0xC0); | ||
94 | lcd_data(0x00); | ||
95 | lcd_data(0x00); | ||
96 | lcd_data(0x00); | ||
97 | lcd_data(0x00); | ||
98 | |||
99 | lcd_cmd(0xFD); | ||
100 | lcd_data(0x88); | ||
101 | lcd_data(0x00); | ||
102 | lcd_data(0x10); | ||
103 | lcd_data(0x01); | ||
104 | lcd_data(0x01); | ||
105 | lcd_data(0x10); | ||
106 | lcd_data(0x42); | ||
107 | lcd_data(0x42); | ||
108 | lcd_data(0x22); | ||
109 | lcd_data(0x11); | ||
110 | lcd_data(0x11); | ||
111 | lcd_data(0x22); | ||
112 | lcd_data(0x99); | ||
113 | lcd_data(0xAA); | ||
114 | lcd_data(0xAA); | ||
115 | lcd_data(0xAA); | ||
116 | lcd_data(0xBB); | ||
117 | lcd_data(0xBB); | ||
118 | lcd_data(0xAA); | ||
119 | lcd_data(0x33); | ||
120 | lcd_data(0x33); | ||
121 | lcd_data(0x11); | ||
122 | lcd_data(0x01); | ||
123 | lcd_data(0x01); | ||
124 | lcd_data(0x01); | ||
125 | lcd_data(0x00); | ||
126 | lcd_data(0x00); | ||
127 | lcd_data(0x00); | ||
128 | lcd_data(0x00); | ||
129 | lcd_data(0x00); | ||
130 | lcd_data(0x00); | ||
131 | lcd_data(0x03); | ||
132 | |||
133 | lcd_cmd(0xBE); | ||
134 | lcd_data(0x00); | ||
135 | lcd_data(0x15); | ||
136 | lcd_data(0x16); | ||
137 | lcd_data(0x08); | ||
138 | lcd_data(0x09); | ||
139 | lcd_data(0x15); | ||
140 | lcd_data(0x10); | ||
141 | lcd_data(0x00); | ||
142 | lcd_data(0x00); | ||
143 | lcd_data(0x00); | ||
144 | |||
145 | lcd_cmd(0xC0); | ||
146 | lcd_data(0x0E); | ||
147 | lcd_data(0x01); | ||
148 | lcd_data(0x00); | ||
149 | lcd_data(0x00); | ||
150 | lcd_data(0x00); | ||
151 | |||
152 | lcd_cmd(0xC1); | ||
153 | lcd_data(0x2F); | ||
154 | lcd_data(0x23); | ||
155 | lcd_data(0xB4); | ||
156 | lcd_data(0xFF); | ||
157 | lcd_data(0x24); | ||
158 | lcd_data(0x03); | ||
159 | lcd_data(0x20); | ||
160 | lcd_data(0x02); | ||
161 | lcd_data(0x02); | ||
162 | lcd_data(0x02); | ||
163 | lcd_data(0x20); | ||
164 | lcd_data(0x20); | ||
165 | lcd_data(0x00); | ||
166 | |||
167 | lcd_cmd(0xC2); | ||
168 | lcd_data(0x03); | ||
169 | |||
170 | lcd_cmd(0x26); | ||
171 | lcd_data(0x08); | ||
172 | |||
173 | lcd_cmd(0x35); | ||
174 | |||
175 | lcd_cmd(0x36); | ||
176 | lcd_data(0x04); | ||
177 | |||
178 | lcd_cmd(0x3A); | ||
179 | lcd_data(0x05); | ||
180 | |||
181 | lcd_cmd(0x2A); | ||
182 | lcd_data(0x013F); | ||
183 | |||
184 | lcd_cmd(0x2B); | ||
185 | lcd_data(0xEF); | ||
186 | |||
187 | lcd_cmd(0x2C); | ||
188 | |||
189 | lcd_cmd(0x2D); | ||
190 | for (i = 0; i < 0x20; i++) { | ||
191 | lcd_data(i << 1); | ||
192 | } | ||
193 | for (i = 0; i < 0x40; i++) { | ||
194 | lcd_data(i); | ||
195 | } | ||
196 | for (i = 0; i < 0x20; i++) { | ||
197 | lcd_data(i << 1); | ||
198 | } | ||
199 | |||
200 | lcd_cmd(0x2A); | ||
201 | lcd_data(0x00); | ||
202 | |||
203 | lcd_cmd(0x2B); | ||
204 | lcd_data(0x00); | ||
205 | |||
206 | lcd_cmd(0x11); | ||
207 | |||
208 | mdelay(120); | ||
209 | |||
210 | lcd_cmd(0x29); | ||
211 | |||
212 | lcd_cmd(0x2C); | ||
213 | |||
214 | for (x = 0; x < LCD_WIDTH; x++) | ||
215 | for(y=0; y < LCD_HEIGHT; y++) | ||
216 | lcd_data(0x00); | ||
217 | |||
218 | display_on = true; | ||
219 | } | ||
220 | |||
221 | void lcd_enable (bool on) | ||
222 | { | ||
223 | if (on == display_on) | ||
224 | return; | ||
225 | |||
226 | lcdctrl_bypass(1); | ||
227 | LCDC_CTRL |= RGB24B; | ||
228 | |||
229 | if (on) { | ||
230 | lcd_cmd(0x11); | ||
231 | mdelay(120); | ||
232 | lcd_cmd(0x29); | ||
233 | lcd_cmd(0x2C); | ||
234 | } else { | ||
235 | lcd_cmd(0x28); | ||
236 | mdelay(120); | ||
237 | lcd_cmd(0x10); | ||
238 | } | ||
239 | |||
240 | display_on = on; | ||
241 | LCDC_CTRL &= ~RGB24B; | ||
242 | } | ||
243 | |||
244 | void lcd_set_gram_area(int x_start, int y_start, | ||
245 | int x_end, int y_end) | ||
246 | { | ||
247 | lcdctrl_bypass(1); | ||
248 | LCDC_CTRL |= RGB24B; | ||
249 | |||
250 | lcd_cmd(0x2A); | ||
251 | lcd_data((x_start&0xff00)>>8); | ||
252 | lcd_data(x_start&0x00ff); | ||
253 | lcd_data((x_end&0xff00)>>8); | ||
254 | lcd_data(x_end&0x00ff); | ||
255 | |||
256 | lcd_cmd(0x2B); | ||
257 | lcd_data((y_start&0xff00)>>8); | ||
258 | lcd_data(y_start&0x00ff); | ||
259 | lcd_data((y_end&0xff00)>>8); | ||
260 | lcd_data(y_end&0x00ff); | ||
261 | |||
262 | lcd_cmd(0x2C); | ||
263 | |||
264 | LCDC_CTRL &= ~RGB24B; | ||
265 | } | ||
266 | |||
267 | bool lcd_active() | ||
268 | { | ||
269 | return display_on; | ||
270 | } | ||
271 | |||
272 | /* Blit a YUV bitmap directly to the LCD */ | ||
273 | void lcd_blit_yuv(unsigned char * const src[3], | ||
274 | int src_x, int src_y, int stride, | ||
275 | int x, int y, int width, int height) | ||
276 | { | ||
277 | (void)src; | ||
278 | (void)src_x; | ||
279 | (void)src_y; | ||
280 | (void)stride; | ||
281 | (void)x; | ||
282 | (void)y; | ||
283 | (void)width; | ||
284 | (void)height; | ||
285 | } | ||
diff --git a/firmware/target/arm/rk27xx/ihifi2/lcd-ihifi770c.c b/firmware/target/arm/rk27xx/ihifi2/lcd-ihifi770c.c new file mode 100644 index 0000000000..311b8057cb --- /dev/null +++ b/firmware/target/arm/rk27xx/ihifi2/lcd-ihifi770c.c | |||
@@ -0,0 +1,248 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2016 by Roman Stolyarov | ||
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 "kernel.h" | ||
24 | #include "lcd.h" | ||
25 | #include "system.h" | ||
26 | #include "cpu.h" | ||
27 | #include "lcdif-rk27xx.h" | ||
28 | |||
29 | static bool display_on = false; | ||
30 | |||
31 | void lcd_display_init(void) | ||
32 | { | ||
33 | unsigned int x, y; | ||
34 | |||
35 | lcd_cmd(0x13); | ||
36 | |||
37 | mdelay(120); | ||
38 | |||
39 | lcd_cmd(0x35); | ||
40 | lcd_data(0x00); | ||
41 | |||
42 | lcd_cmd(0x36); | ||
43 | lcd_data(0x48); | ||
44 | |||
45 | lcd_cmd(0xD0); | ||
46 | lcd_data(0x00); | ||
47 | lcd_data(0x05); | ||
48 | |||
49 | lcd_cmd(0xEF); | ||
50 | lcd_data(0x07); | ||
51 | |||
52 | lcd_cmd(0xF2); | ||
53 | lcd_data(0x1B); | ||
54 | lcd_data(0x16); | ||
55 | lcd_data(0x0F); | ||
56 | lcd_data(0x08); | ||
57 | lcd_data(0x08); | ||
58 | lcd_data(0x08); | ||
59 | lcd_data(0x08); | ||
60 | lcd_data(0x10); | ||
61 | lcd_data(0x00); | ||
62 | lcd_data(0x1C); | ||
63 | lcd_data(0x16); | ||
64 | |||
65 | lcd_cmd(0xF3); | ||
66 | lcd_data(0x01); | ||
67 | lcd_data(0x41); | ||
68 | lcd_data(0x15); | ||
69 | lcd_data(0x0D); | ||
70 | lcd_data(0x33); | ||
71 | lcd_data(0x63); | ||
72 | lcd_data(0x46); | ||
73 | lcd_data(0x10); | ||
74 | |||
75 | lcd_cmd(0xF4); | ||
76 | lcd_data(0x5B); | ||
77 | lcd_data(0x5B); | ||
78 | lcd_data(0x55); | ||
79 | lcd_data(0x55); | ||
80 | lcd_data(0x44); | ||
81 | |||
82 | lcd_cmd(0xF5); | ||
83 | lcd_data(0x12); | ||
84 | lcd_data(0x11); | ||
85 | lcd_data(0x06); | ||
86 | lcd_data(0xF0); | ||
87 | lcd_data(0x00); | ||
88 | lcd_data(0x1F); | ||
89 | |||
90 | lcd_cmd(0xF6); | ||
91 | lcd_data(0x80); | ||
92 | lcd_data(0x10); | ||
93 | lcd_data(0x00); | ||
94 | |||
95 | lcd_cmd(0xFD); | ||
96 | lcd_data(0x11); | ||
97 | lcd_data(0x1D); | ||
98 | lcd_data(0x00); | ||
99 | |||
100 | lcd_cmd(0xF8); | ||
101 | lcd_data(0x00); | ||
102 | lcd_data(0x15); | ||
103 | lcd_data(0x01); | ||
104 | lcd_data(0x08); | ||
105 | lcd_data(0x15); | ||
106 | lcd_data(0x22); | ||
107 | lcd_data(0x25); | ||
108 | lcd_data(0x28); | ||
109 | lcd_data(0x14); | ||
110 | lcd_data(0x13); | ||
111 | lcd_data(0x10); | ||
112 | lcd_data(0x11); | ||
113 | lcd_data(0x09); | ||
114 | lcd_data(0x24); | ||
115 | lcd_data(0x28); | ||
116 | |||
117 | lcd_cmd(0xF9); | ||
118 | lcd_data(0x00); | ||
119 | lcd_data(0x15); | ||
120 | lcd_data(0x01); | ||
121 | lcd_data(0x08); | ||
122 | lcd_data(0x15); | ||
123 | lcd_data(0x22); | ||
124 | lcd_data(0x25); | ||
125 | lcd_data(0x28); | ||
126 | lcd_data(0x14); | ||
127 | lcd_data(0x13); | ||
128 | lcd_data(0x10); | ||
129 | lcd_data(0x11); | ||
130 | lcd_data(0x09); | ||
131 | lcd_data(0x24); | ||
132 | lcd_data(0x28); | ||
133 | |||
134 | lcd_cmd(0xFC); | ||
135 | lcd_data(0x00); | ||
136 | lcd_data(0x15); | ||
137 | lcd_data(0x01); | ||
138 | lcd_data(0x08); | ||
139 | lcd_data(0x15); | ||
140 | lcd_data(0x22); | ||
141 | lcd_data(0x25); | ||
142 | lcd_data(0x28); | ||
143 | lcd_data(0x14); | ||
144 | lcd_data(0x13); | ||
145 | lcd_data(0x10); | ||
146 | lcd_data(0x11); | ||
147 | lcd_data(0x09); | ||
148 | lcd_data(0x24); | ||
149 | lcd_data(0x28); | ||
150 | |||
151 | lcd_cmd(0x36); | ||
152 | lcd_data(0x48); | ||
153 | |||
154 | lcd_cmd(0x3A); | ||
155 | lcd_data(0x55); | ||
156 | |||
157 | lcd_cmd(0x2A); | ||
158 | lcd_data(0x00); | ||
159 | lcd_data(0x00); | ||
160 | lcd_data(0x01); | ||
161 | lcd_data(0x3F); | ||
162 | |||
163 | lcd_cmd(0x2B); | ||
164 | lcd_data(0x00); | ||
165 | lcd_data(0x00); | ||
166 | lcd_data(0x00); | ||
167 | lcd_data(0xEF); | ||
168 | |||
169 | lcd_cmd(0x11); | ||
170 | |||
171 | mdelay(120); | ||
172 | |||
173 | lcd_cmd(0x29); | ||
174 | |||
175 | lcd_cmd(0x2C); | ||
176 | |||
177 | for (x = 0; x < LCD_WIDTH; x++) | ||
178 | for(y=0; y < LCD_HEIGHT; y++) | ||
179 | lcd_data(0x00); | ||
180 | |||
181 | display_on = true; | ||
182 | } | ||
183 | |||
184 | void lcd_enable (bool on) | ||
185 | { | ||
186 | if (on == display_on) | ||
187 | return; | ||
188 | |||
189 | lcdctrl_bypass(1); | ||
190 | LCDC_CTRL |= RGB24B; | ||
191 | |||
192 | if (on) { | ||
193 | lcd_cmd(0x11); | ||
194 | mdelay(120); | ||
195 | lcd_cmd(0x29); | ||
196 | lcd_cmd(0x2C); | ||
197 | } else { | ||
198 | lcd_cmd(0x28); | ||
199 | mdelay(120); | ||
200 | lcd_cmd(0x10); | ||
201 | } | ||
202 | |||
203 | display_on = on; | ||
204 | LCDC_CTRL &= ~RGB24B; | ||
205 | } | ||
206 | |||
207 | void lcd_set_gram_area(int x_start, int y_start, | ||
208 | int x_end, int y_end) | ||
209 | { | ||
210 | lcdctrl_bypass(1); | ||
211 | LCDC_CTRL |= RGB24B; | ||
212 | |||
213 | lcd_cmd(0x2A); | ||
214 | lcd_data((x_start&0xff00)>>8); | ||
215 | lcd_data(x_start&0x00ff); | ||
216 | lcd_data((x_end&0xff00)>>8); | ||
217 | lcd_data(x_end&0x00ff); | ||
218 | |||
219 | lcd_cmd(0x2B); | ||
220 | lcd_data((y_start&0xff00)>>8); | ||
221 | lcd_data(y_start&0x00ff); | ||
222 | lcd_data((y_end&0xff00)>>8); | ||
223 | lcd_data(y_end&0x00ff); | ||
224 | |||
225 | lcd_cmd(0x2C); | ||
226 | |||
227 | LCDC_CTRL &= ~RGB24B; | ||
228 | } | ||
229 | |||
230 | bool lcd_active() | ||
231 | { | ||
232 | return display_on; | ||
233 | } | ||
234 | |||
235 | /* Blit a YUV bitmap directly to the LCD */ | ||
236 | void lcd_blit_yuv(unsigned char * const src[3], | ||
237 | int src_x, int src_y, int stride, | ||
238 | int x, int y, int width, int height) | ||
239 | { | ||
240 | (void)src; | ||
241 | (void)src_x; | ||
242 | (void)src_y; | ||
243 | (void)stride; | ||
244 | (void)x; | ||
245 | (void)y; | ||
246 | (void)width; | ||
247 | (void)height; | ||
248 | } | ||
diff --git a/firmware/target/arm/rk27xx/ihifi2/lcd-ihifi800.c b/firmware/target/arm/rk27xx/ihifi2/lcd-ihifi800.c new file mode 100644 index 0000000000..821b52dcb6 --- /dev/null +++ b/firmware/target/arm/rk27xx/ihifi2/lcd-ihifi800.c | |||
@@ -0,0 +1,228 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2016 by Roman Stolyarov | ||
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 "kernel.h" | ||
24 | #include "lcd.h" | ||
25 | #include "system.h" | ||
26 | #include "cpu.h" | ||
27 | #include "lcdif-rk27xx.h" | ||
28 | |||
29 | static bool display_on = false; | ||
30 | |||
31 | void lcd_display_init(void) | ||
32 | { | ||
33 | unsigned int x, y; | ||
34 | |||
35 | lcd_cmd(0xEF); | ||
36 | lcd_data(0x03); | ||
37 | lcd_data(0x80); | ||
38 | lcd_data(0x02); | ||
39 | |||
40 | lcd_cmd(0xCF); | ||
41 | lcd_data(0x00); | ||
42 | lcd_data(0xC1); | ||
43 | lcd_data(0x30); | ||
44 | |||
45 | lcd_cmd(0xED); | ||
46 | lcd_data(0x67); | ||
47 | lcd_data(0x03); | ||
48 | lcd_data(0x12); | ||
49 | lcd_data(0x81); | ||
50 | |||
51 | lcd_cmd(0xE8); | ||
52 | lcd_data(0x85); | ||
53 | lcd_data(0x11); | ||
54 | lcd_data(0x79); | ||
55 | |||
56 | lcd_cmd(0xCB); | ||
57 | lcd_data(0x39); | ||
58 | lcd_data(0x2C); | ||
59 | lcd_data(0x00); | ||
60 | lcd_data(0x34); | ||
61 | lcd_data(0x06); | ||
62 | |||
63 | lcd_cmd(0xF7); | ||
64 | lcd_data(0x20); | ||
65 | |||
66 | lcd_cmd(0xEA); | ||
67 | lcd_data(0x00); | ||
68 | lcd_data(0x00); | ||
69 | |||
70 | lcd_cmd(0xC0); | ||
71 | lcd_data(0x1D); | ||
72 | |||
73 | lcd_cmd(0xC1); | ||
74 | lcd_data(0x12); | ||
75 | |||
76 | lcd_cmd(0xC5); | ||
77 | lcd_data(0x44); | ||
78 | lcd_data(0x3C); | ||
79 | |||
80 | lcd_cmd(0xC7); | ||
81 | lcd_data(0x88); | ||
82 | |||
83 | lcd_cmd(0x3A); | ||
84 | lcd_data(0x55); | ||
85 | |||
86 | lcd_cmd(0x36); | ||
87 | lcd_data(0x0C); | ||
88 | |||
89 | lcd_cmd(0xB1); | ||
90 | lcd_data(0x00); | ||
91 | lcd_data(0x17); | ||
92 | |||
93 | lcd_cmd(0xB6); | ||
94 | lcd_data(0x0A); | ||
95 | lcd_data(0xA2); | ||
96 | |||
97 | lcd_cmd(0xF2); | ||
98 | lcd_data(0x00); | ||
99 | |||
100 | lcd_cmd(0x26); | ||
101 | lcd_data(0x01); | ||
102 | |||
103 | lcd_cmd(0xE0); | ||
104 | lcd_data(0x0F); | ||
105 | lcd_data(0x22); | ||
106 | lcd_data(0x1C); | ||
107 | lcd_data(0x1B); | ||
108 | lcd_data(0x08); | ||
109 | lcd_data(0x0F); | ||
110 | lcd_data(0x48); | ||
111 | lcd_data(0xB8); | ||
112 | lcd_data(0x34); | ||
113 | lcd_data(0x05); | ||
114 | lcd_data(0x0C); | ||
115 | lcd_data(0x09); | ||
116 | lcd_data(0x0F); | ||
117 | lcd_data(0x07); | ||
118 | lcd_data(0x00); | ||
119 | |||
120 | lcd_cmd(0xE1); | ||
121 | lcd_data(0x00); | ||
122 | lcd_data(0x23); | ||
123 | lcd_data(0x24); | ||
124 | lcd_data(0x07); | ||
125 | lcd_data(0x10); | ||
126 | lcd_data(0x07); | ||
127 | lcd_data(0x38); | ||
128 | lcd_data(0x47); | ||
129 | lcd_data(0x4B); | ||
130 | lcd_data(0x0A); | ||
131 | lcd_data(0x13); | ||
132 | lcd_data(0x06); | ||
133 | lcd_data(0x30); | ||
134 | lcd_data(0x38); | ||
135 | lcd_data(0x0F); | ||
136 | |||
137 | lcd_cmd(0x2A); | ||
138 | lcd_data(0x00); | ||
139 | lcd_data(0x00); | ||
140 | lcd_data(0x00); | ||
141 | lcd_data(0xEF); | ||
142 | |||
143 | lcd_cmd(0x2B); | ||
144 | lcd_data(0x00); | ||
145 | lcd_data(0x00); | ||
146 | lcd_data(0x01); | ||
147 | lcd_data(0x3F); | ||
148 | |||
149 | lcd_cmd(0x11); | ||
150 | |||
151 | mdelay(120); | ||
152 | |||
153 | lcd_cmd(0x29); | ||
154 | |||
155 | lcd_cmd(0x2C); | ||
156 | |||
157 | for (x = 0; x < LCD_WIDTH; x++) | ||
158 | for(y=0; y < LCD_HEIGHT; y++) | ||
159 | lcd_data(0x00); | ||
160 | |||
161 | display_on = true; | ||
162 | } | ||
163 | |||
164 | void lcd_enable (bool on) | ||
165 | { | ||
166 | if (on == display_on) | ||
167 | return; | ||
168 | |||
169 | lcdctrl_bypass(1); | ||
170 | LCDC_CTRL |= RGB24B; | ||
171 | |||
172 | if (on) { | ||
173 | lcd_cmd(0x11); | ||
174 | mdelay(120); | ||
175 | lcd_cmd(0x29); | ||
176 | lcd_cmd(0x2C); | ||
177 | } else { | ||
178 | lcd_cmd(0x28); | ||
179 | mdelay(120); | ||
180 | lcd_cmd(0x10); | ||
181 | } | ||
182 | |||
183 | display_on = on; | ||
184 | LCDC_CTRL &= ~RGB24B; | ||
185 | } | ||
186 | |||
187 | void lcd_set_gram_area(int x_start, int y_start, | ||
188 | int x_end, int y_end) | ||
189 | { | ||
190 | lcdctrl_bypass(1); | ||
191 | LCDC_CTRL |= RGB24B; | ||
192 | |||
193 | lcd_cmd(0x2A); | ||
194 | lcd_data((x_start&0xff00)>>8); | ||
195 | lcd_data(x_start&0x00ff); | ||
196 | lcd_data((x_end&0xff00)>>8); | ||
197 | lcd_data(x_end&0x00ff); | ||
198 | |||
199 | lcd_cmd(0x2B); | ||
200 | lcd_data((y_start&0xff00)>>8); | ||
201 | lcd_data(y_start&0x00ff); | ||
202 | lcd_data((y_end&0xff00)>>8); | ||
203 | lcd_data(y_end&0x00ff); | ||
204 | |||
205 | lcd_cmd(0x2C); | ||
206 | |||
207 | LCDC_CTRL &= ~RGB24B; | ||
208 | } | ||
209 | |||
210 | bool lcd_active() | ||
211 | { | ||
212 | return display_on; | ||
213 | } | ||
214 | |||
215 | /* Blit a YUV bitmap directly to the LCD */ | ||
216 | void lcd_blit_yuv(unsigned char * const src[3], | ||
217 | int src_x, int src_y, int stride, | ||
218 | int x, int y, int width, int height) | ||
219 | { | ||
220 | (void)src; | ||
221 | (void)src_x; | ||
222 | (void)src_y; | ||
223 | (void)stride; | ||
224 | (void)x; | ||
225 | (void)y; | ||
226 | (void)width; | ||
227 | (void)height; | ||
228 | } | ||
diff --git a/firmware/target/arm/rk27xx/ihifi2/lcd-target.h b/firmware/target/arm/rk27xx/ihifi2/lcd-target.h new file mode 100644 index 0000000000..6b2aa5d8a5 --- /dev/null +++ b/firmware/target/arm/rk27xx/ihifi2/lcd-target.h | |||
@@ -0,0 +1,26 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2016 by Roman Stolyarov | ||
11 | * | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or | ||
14 | * modify it under the terms of the GNU General Public License | ||
15 | * as published by the Free Software Foundation; either version 2 | ||
16 | * of the License, or (at your option) any later version. | ||
17 | * | ||
18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
19 | * KIND, either express or implied. | ||
20 | * | ||
21 | ****************************************************************************/ | ||
22 | #ifndef LCD_TARGET_H | ||
23 | #define LCD_TARGET_H | ||
24 | |||
25 | #define LCD_DATABUS_WIDTH LCDIF_16BIT | ||
26 | #endif | ||
diff --git a/firmware/target/arm/rk27xx/ihifi2/power-ihifi.c b/firmware/target/arm/rk27xx/ihifi2/power-ihifi.c new file mode 100644 index 0000000000..cc489eacfe --- /dev/null +++ b/firmware/target/arm/rk27xx/ihifi2/power-ihifi.c | |||
@@ -0,0 +1,53 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2016 by Roman Stolyarov | ||
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 <stdbool.h> | ||
22 | #include "config.h" | ||
23 | #include "inttypes.h" | ||
24 | #include "power.h" | ||
25 | #include "panic.h" | ||
26 | #include "system.h" | ||
27 | #include "usb_core.h" /* for usb_charging_maxcurrent_change */ | ||
28 | #include "adc.h" | ||
29 | |||
30 | void power_off(void) | ||
31 | { | ||
32 | GPIO_PCCON &= ~(1<<0); | ||
33 | while(1); | ||
34 | } | ||
35 | |||
36 | void power_init(void) | ||
37 | { | ||
38 | GPIO_PCDR |= (1<<0); | ||
39 | GPIO_PCCON |= (1<<0); | ||
40 | |||
41 | GPIO_PADR &= ~(1<<7); /* MUTE */ | ||
42 | GPIO_PACON |= (1<<7); | ||
43 | } | ||
44 | |||
45 | unsigned int power_input_status(void) | ||
46 | { | ||
47 | return (usb_detect() == USB_INSERTED) ? POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE; | ||
48 | } | ||
49 | |||
50 | bool charging_state(void) | ||
51 | { | ||
52 | return (adc_read(ADC_EXTRA) < 512); | ||
53 | } | ||
diff --git a/firmware/target/arm/rk27xx/ihifi2/powermgmt-ihifi770.c b/firmware/target/arm/rk27xx/ihifi2/powermgmt-ihifi770.c new file mode 100644 index 0000000000..b0ff4f5a7b --- /dev/null +++ b/firmware/target/arm/rk27xx/ihifi2/powermgmt-ihifi770.c | |||
@@ -0,0 +1,64 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2016 by Roman Stolyarov | ||
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 "adc.h" | ||
24 | #include "adc-target.h" | ||
25 | #include "powermgmt.h" | ||
26 | |||
27 | /* Battery voltage calculation and discharge/charge curves for the iHiFi 770 | ||
28 | |||
29 | Battery voltage is calculated under the assumption that the adc full-scale | ||
30 | readout represents 3.00V and that the battery ADC channel is fed with | ||
31 | exactly half of the battery voltage (through a resistive divider). | ||
32 | Charge curve have not been calibrated yet. | ||
33 | */ | ||
34 | |||
35 | const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = | ||
36 | { | ||
37 | /* 5% */ | ||
38 | 3500, | ||
39 | }; | ||
40 | |||
41 | const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = | ||
42 | { | ||
43 | /* 0% */ | ||
44 | 3300, | ||
45 | }; | ||
46 | |||
47 | /* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */ | ||
48 | const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = | ||
49 | { | ||
50 | { 3300, 3570, 3660, 3696, 3712, 3742, 3798, 3865, 3935, 4020, 4130 } | ||
51 | }; | ||
52 | |||
53 | /* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */ | ||
54 | const unsigned short percent_to_volt_charge[11] = | ||
55 | { 3300, 3570, 3660, 3696, 3712, 3742, 3798, 3865, 3935, 4020, 4130 }; | ||
56 | |||
57 | /* full-scale ADC readout (2^10) in millivolt */ | ||
58 | #define BATTERY_SCALE_FACTOR 6296 | ||
59 | |||
60 | /* Returns battery voltage from ADC [millivolts] */ | ||
61 | int _battery_voltage(void) | ||
62 | { | ||
63 | return (adc_read(ADC_BATTERY) * BATTERY_SCALE_FACTOR) >> 10; | ||
64 | } | ||
diff --git a/firmware/target/arm/rk27xx/ihifi2/powermgmt-ihifi770c.c b/firmware/target/arm/rk27xx/ihifi2/powermgmt-ihifi770c.c new file mode 100644 index 0000000000..613553010b --- /dev/null +++ b/firmware/target/arm/rk27xx/ihifi2/powermgmt-ihifi770c.c | |||
@@ -0,0 +1,64 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2016 by Roman Stolyarov | ||
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 "adc.h" | ||
24 | #include "adc-target.h" | ||
25 | #include "powermgmt.h" | ||
26 | |||
27 | /* Battery voltage calculation and discharge/charge curves for the iHiFi 770C | ||
28 | |||
29 | Battery voltage is calculated under the assumption that the adc full-scale | ||
30 | readout represents 3.00V and that the battery ADC channel is fed with | ||
31 | exactly half of the battery voltage (through a resistive divider). | ||
32 | Charge curve have not been calibrated yet. | ||
33 | */ | ||
34 | |||
35 | const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = | ||
36 | { | ||
37 | /* 5% */ | ||
38 | 3500, | ||
39 | }; | ||
40 | |||
41 | const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = | ||
42 | { | ||
43 | /* 0% */ | ||
44 | 3300, | ||
45 | }; | ||
46 | |||
47 | /* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */ | ||
48 | const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = | ||
49 | { | ||
50 | { 3300, 3570, 3660, 3696, 3712, 3742, 3798, 3865, 3935, 4020, 4130 } | ||
51 | }; | ||
52 | |||
53 | /* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */ | ||
54 | const unsigned short percent_to_volt_charge[11] = | ||
55 | { 3300, 3570, 3660, 3696, 3712, 3742, 3798, 3865, 3935, 4020, 4130 }; | ||
56 | |||
57 | /* full-scale ADC readout (2^10) in millivolt */ | ||
58 | #define BATTERY_SCALE_FACTOR 6296 | ||
59 | |||
60 | /* Returns battery voltage from ADC [millivolts] */ | ||
61 | int _battery_voltage(void) | ||
62 | { | ||
63 | return (adc_read(ADC_BATTERY) * BATTERY_SCALE_FACTOR) >> 10; | ||
64 | } | ||
diff --git a/firmware/target/arm/rk27xx/ihifi2/powermgmt-ihifi800.c b/firmware/target/arm/rk27xx/ihifi2/powermgmt-ihifi800.c new file mode 100644 index 0000000000..26f4e47b93 --- /dev/null +++ b/firmware/target/arm/rk27xx/ihifi2/powermgmt-ihifi800.c | |||
@@ -0,0 +1,64 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2016 by Roman Stolyarov | ||
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 "adc.h" | ||
24 | #include "adc-target.h" | ||
25 | #include "powermgmt.h" | ||
26 | |||
27 | /* Battery voltage calculation and discharge/charge curves for the iHiFi 800 | ||
28 | |||
29 | Battery voltage is calculated under the assumption that the adc full-scale | ||
30 | readout represents 3.00V and that the battery ADC channel is fed with | ||
31 | exactly half of the battery voltage (through a resistive divider). | ||
32 | Charge curve have not been calibrated yet. | ||
33 | */ | ||
34 | |||
35 | const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = | ||
36 | { | ||
37 | /* 5% */ | ||
38 | 3628, | ||
39 | }; | ||
40 | |||
41 | const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = | ||
42 | { | ||
43 | /* 0% */ | ||
44 | 3300, | ||
45 | }; | ||
46 | |||
47 | /* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */ | ||
48 | const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = | ||
49 | { | ||
50 | { 3300, 3649, 3701, 3726, 3745, 3778, 3831, 3904, 3965, 4056, 4160 } | ||
51 | }; | ||
52 | |||
53 | /* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */ | ||
54 | const unsigned short percent_to_volt_charge[11] = | ||
55 | { 3300, 3649, 3701, 3726, 3745, 3778, 3831, 3904, 3965, 4056, 4160 }; | ||
56 | |||
57 | /* full-scale ADC readout (2^10) in millivolt */ | ||
58 | #define BATTERY_SCALE_FACTOR 6296 | ||
59 | |||
60 | /* Returns battery voltage from ADC [millivolts] */ | ||
61 | int _battery_voltage(void) | ||
62 | { | ||
63 | return (adc_read(ADC_BATTERY) * BATTERY_SCALE_FACTOR) >> 10; | ||
64 | } | ||