diff options
author | Solomon Peachy <pizza@shaftnet.org> | 2018-06-29 16:09:28 -0400 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2019-01-02 08:10:01 -0500 |
commit | d4942cc74c82c465ea395637c77ed06565b8b497 (patch) | |
tree | 8c1fa737c93f8a2ade5a1566857dc4dc8f578bd6 /firmware | |
parent | af9459a7992596e932c6d8cc0a6366ff0f0b0fca (diff) | |
download | rockbox-d4942cc74c82c465ea395637c77ed06565b8b497.tar.gz rockbox-d4942cc74c82c465ea395637c77ed06565b8b497.zip |
Add Xuelin iHIFI 770/770C/800 support
Taken from the xvortex fork (Roman Stolyarov)
Ported, rebased, and cleaned up by myself.
Change-Id: I7b2bca2d29502f2e4544e42f3d122786dd4b7978
Diffstat (limited to 'firmware')
30 files changed, 2687 insertions, 508 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES index 33d59fa429..16ae4cc350 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES | |||
@@ -442,6 +442,8 @@ drivers/audio/audiohw-swcodec.c | |||
442 | #if (CONFIG_PLATFORM & PLATFORM_NATIVE) && !defined(BOOTLOADER) | 442 | #if (CONFIG_PLATFORM & PLATFORM_NATIVE) && !defined(BOOTLOADER) |
443 | #if defined(HAVE_UDA1380) | 443 | #if defined(HAVE_UDA1380) |
444 | drivers/audio/uda1380.c | 444 | drivers/audio/uda1380.c |
445 | #elif defined(HAVE_WM8740) | ||
446 | drivers/audio/wm8740.c | ||
445 | #elif defined(HAVE_WM8751) \ | 447 | #elif defined(HAVE_WM8751) \ |
446 | || defined(HAVE_WM8750) | 448 | || defined(HAVE_WM8750) |
447 | drivers/audio/wm8751.c | 449 | drivers/audio/wm8751.c |
@@ -481,6 +483,8 @@ drivers/audio/df1704.c | |||
481 | drivers/audio/pcm1792.c | 483 | drivers/audio/pcm1792.c |
482 | #elif defined (HAVE_CS4398) | 484 | #elif defined (HAVE_CS4398) |
483 | drivers/audio/cs4398.c | 485 | drivers/audio/cs4398.c |
486 | #elif defined (HAVE_ES9018) | ||
487 | drivers/audio/es9018.c | ||
484 | #endif /* defined(HAVE_*) */ | 488 | #endif /* defined(HAVE_*) */ |
485 | #else /* PLATFORM_HOSTED */ | 489 | #else /* PLATFORM_HOSTED */ |
486 | #if defined(SAMSUNG_YPR0) && defined(HAVE_AS3514) | 490 | #if defined(SAMSUNG_YPR0) && defined(HAVE_AS3514) |
@@ -791,6 +795,12 @@ target/arm/s3c2440/lcd-s3c2440.c | |||
791 | target/arm/rk27xx/ma/lcd-ma.c | 795 | target/arm/rk27xx/ma/lcd-ma.c |
792 | #elif CONFIG_LCD == LCD_IHIFI | 796 | #elif CONFIG_LCD == LCD_IHIFI |
793 | target/arm/rk27xx/ihifi/lcd-ihifi.c | 797 | target/arm/rk27xx/ihifi/lcd-ihifi.c |
798 | #elif CONFIG_LCD == LCD_IHIFI770 | ||
799 | target/arm/rk27xx/ihifi2/lcd-ihifi770.c | ||
800 | #elif CONFIG_LCD == LCD_IHIFI770C | ||
801 | target/arm/rk27xx/ihifi2/lcd-ihifi770c.c | ||
802 | #elif CONFIG_LCD == LCD_IHIFI800 | ||
803 | target/arm/rk27xx/ihifi2/lcd-ihifi800.c | ||
794 | #endif | 804 | #endif |
795 | 805 | ||
796 | /* USB Stack */ | 806 | /* USB Stack */ |
@@ -1904,6 +1914,21 @@ target/arm/rk27xx/ihifi/powermgmt-ihifi960.c | |||
1904 | #endif | 1914 | #endif |
1905 | #endif | 1915 | #endif |
1906 | 1916 | ||
1917 | #if defined(IHIFI770) || defined(IHIFI770C) || defined(IHIFI800) | ||
1918 | target/arm/rk27xx/ihifi2/button-ihifi.c | ||
1919 | target/arm/rk27xx/ihifi2/power-ihifi.c | ||
1920 | #if defined(IHIFI770) | ||
1921 | target/arm/rk27xx/ihifi2/powermgmt-ihifi770.c | ||
1922 | target/arm/rk27xx/ihifi2/audio-ihifi770.c | ||
1923 | #elif defined(IHIFI770C) | ||
1924 | target/arm/rk27xx/ihifi2/powermgmt-ihifi770c.c | ||
1925 | target/arm/rk27xx/ihifi2/audio-ihifi770.c | ||
1926 | #elif defined(IHIFI800) | ||
1927 | target/arm/rk27xx/ihifi2/powermgmt-ihifi800.c | ||
1928 | target/arm/rk27xx/ihifi2/audio-ihifi800.c | ||
1929 | #endif | ||
1930 | #endif | ||
1931 | |||
1907 | #if (CONFIG_PLATFORM & PLATFORM_ANDROID) | 1932 | #if (CONFIG_PLATFORM & PLATFORM_ANDROID) |
1908 | target/hosted/kernel-unix.c | 1933 | target/hosted/kernel-unix.c |
1909 | target/hosted/filesystem-unix.c | 1934 | target/hosted/filesystem-unix.c |
diff --git a/firmware/drivers/audio/es9018.c b/firmware/drivers/audio/es9018.c new file mode 100644 index 0000000000..89e8c1d46f --- /dev/null +++ b/firmware/drivers/audio/es9018.c | |||
@@ -0,0 +1,134 @@ | |||
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 "es9018.h" | ||
24 | #include "config.h" | ||
25 | #include "audio.h" | ||
26 | #include "audiohw.h" | ||
27 | |||
28 | /* NOTE: The register names are not known, as the register numbering | ||
29 | listed in the ES9018 datasheet does not match what is described below.. */ | ||
30 | |||
31 | static uint8_t reg0 = 0x00; /* System settings. Default value of register 0 */ | ||
32 | static uint8_t reg1 = 0x80; /* Input settings. Manual input, I2S, 32-bit (?) */ | ||
33 | static uint8_t reg4 = 0x00; /* Automute time. Default = disabled */ | ||
34 | static uint8_t reg5 = 0x68; /* Automute level. Default is some level */ | ||
35 | static uint8_t reg6 = 0x4A; /* Deemphasis. Default = disabled */ | ||
36 | static uint8_t reg7 = 0x83; /* General settings. Default sharp fir, pcm iir and muted */ | ||
37 | static uint8_t reg8 = 0x10; /* GPIO configuration */ | ||
38 | static uint8_t reg10 = 0x05; /* Master Mode Control. Default value: master mode off */ | ||
39 | static uint8_t reg11 = 0x02; /* Channel Mapping. Default stereo is Ch1=left, Ch2=right */ | ||
40 | static uint8_t reg12 = 0x50; /* DPLL Settings. Default = 005 for I2S, OFF for DSD */ | ||
41 | static uint8_t reg13 = 0x40; /* THD Compensation */ | ||
42 | static uint8_t reg14 = 0x8A; /* Soft Start Settings */ | ||
43 | static uint8_t reg21 = 0x00; /* Oversampling filter. Default: oversampling ON */ | ||
44 | |||
45 | #define bitSet(value, bit) ((value) |= (1UL << (bit))) | ||
46 | #define bitClear(value, bit) ((value) &= ~(1UL << (bit))) | ||
47 | |||
48 | static int vol_tenthdb2hw(const int tdb) | ||
49 | { | ||
50 | if (tdb < ES9018_VOLUME_MIN) { | ||
51 | return 0xff; | ||
52 | } else if (tdb > ES9018_VOLUME_MAX) { | ||
53 | return 0x00; | ||
54 | } else { | ||
55 | return (-tdb/5); | ||
56 | } | ||
57 | } | ||
58 | |||
59 | void audiohw_set_volume(int vol_l, int vol_r) | ||
60 | { | ||
61 | es9018_write_reg(15, vol_tenthdb2hw(vol_l)); | ||
62 | es9018_write_reg(16, vol_tenthdb2hw(vol_r)); | ||
63 | } | ||
64 | |||
65 | void audiohw_mute(void) | ||
66 | { | ||
67 | bitSet(reg7, 0); /* Mute Channel 1 */ | ||
68 | bitSet(reg7, 1); /* Mute Channel 2 */ | ||
69 | es9018_write_reg(0x07, reg7); | ||
70 | } | ||
71 | |||
72 | void audiohw_unmute(void) | ||
73 | { | ||
74 | bitClear(reg7, 0); /* Unmute Channel 1 */ | ||
75 | bitClear(reg7, 1); /* Unmute Channel 2 */ | ||
76 | es9018_write_reg(0x07, reg7); | ||
77 | } | ||
78 | |||
79 | void audiohw_init(void) | ||
80 | { | ||
81 | es9018_write_reg(0x00, reg0); | ||
82 | es9018_write_reg(0x01, reg1); | ||
83 | es9018_write_reg(0x04, reg4); | ||
84 | es9018_write_reg(0x05, reg5); | ||
85 | es9018_write_reg(0x06, reg6); | ||
86 | es9018_write_reg(0x07, reg7); | ||
87 | es9018_write_reg(0x08, reg8); | ||
88 | es9018_write_reg(0x0A, reg10); | ||
89 | es9018_write_reg(0x0B, reg11); | ||
90 | es9018_write_reg(0x0C, reg12); | ||
91 | es9018_write_reg(0x0D, reg13); | ||
92 | es9018_write_reg(0x0E, reg14); | ||
93 | es9018_write_reg(0x15, reg21); | ||
94 | } | ||
95 | |||
96 | void audiohw_preinit(void) | ||
97 | { | ||
98 | } | ||
99 | |||
100 | void audiohw_set_frequency(int fsel) | ||
101 | { | ||
102 | (void)fsel; | ||
103 | } | ||
104 | |||
105 | void audiohw_set_filter_roll_off(int value) | ||
106 | { | ||
107 | /* 0 = Sharp (Default) | ||
108 | 1 = Slow | ||
109 | 2 = Short | ||
110 | 3 = Bypass */ | ||
111 | switch(value) | ||
112 | { | ||
113 | case 0: | ||
114 | bitClear(reg7, 5); | ||
115 | bitClear(reg7, 6); | ||
116 | bitClear(reg21, 0); | ||
117 | break; | ||
118 | case 1: | ||
119 | bitSet(reg7, 5); | ||
120 | bitClear(reg7, 6); | ||
121 | bitClear(reg21, 0); | ||
122 | break; | ||
123 | case 2: | ||
124 | bitClear(reg7, 5); | ||
125 | bitSet(reg7, 6); | ||
126 | bitClear(reg21, 0); | ||
127 | break; | ||
128 | case 3: | ||
129 | bitSet(reg21, 0); | ||
130 | break; | ||
131 | } | ||
132 | es9018_write_reg(0x07, reg7); | ||
133 | es9018_write_reg(0x15, reg21); | ||
134 | } | ||
diff --git a/firmware/drivers/audio/wm8740.c b/firmware/drivers/audio/wm8740.c new file mode 100644 index 0000000000..d88f53bd75 --- /dev/null +++ b/firmware/drivers/audio/wm8740.c | |||
@@ -0,0 +1,106 @@ | |||
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 "wm8740.h" | ||
24 | #include "config.h" | ||
25 | #include "audio.h" | ||
26 | #include "audiohw.h" | ||
27 | |||
28 | static void wm8740_write_reg(const int reg, const unsigned int value) | ||
29 | { | ||
30 | int i; | ||
31 | |||
32 | for (i = (1<<15); i; i >>= 1) { | ||
33 | udelay(1); | ||
34 | wm8740_set_mc(0); | ||
35 | if ((reg|value) & i) { | ||
36 | wm8740_set_md(1); | ||
37 | } else { | ||
38 | wm8740_set_md(0); | ||
39 | } | ||
40 | udelay(1); | ||
41 | wm8740_set_mc(1); | ||
42 | } | ||
43 | udelay(1); | ||
44 | wm8740_set_ml(0); | ||
45 | udelay(1); | ||
46 | wm8740_set_mc(0); | ||
47 | udelay(1); | ||
48 | wm8740_set_ml(1); | ||
49 | udelay(1); | ||
50 | } | ||
51 | |||
52 | static int vol_tenthdb2hw(const int tdb) | ||
53 | { | ||
54 | if (tdb < WM8740_VOLUME_MIN) { | ||
55 | return 0x00; | ||
56 | } else if (tdb > WM8740_VOLUME_MAX) { | ||
57 | return 0xff; | ||
58 | } else { | ||
59 | return ((tdb / 5 + 0xff) & 0xff); | ||
60 | } | ||
61 | } | ||
62 | |||
63 | void audiohw_set_volume(int vol_l, int vol_r) | ||
64 | { | ||
65 | wm8740_write_reg(WM8740_REG0, vol_tenthdb2hw(vol_l)); | ||
66 | wm8740_write_reg(WM8740_REG1, vol_tenthdb2hw(vol_r) | WM8740_LDR); | ||
67 | } | ||
68 | |||
69 | void audiohw_mute(void) | ||
70 | { | ||
71 | wm8740_write_reg(WM8740_REG2, WM8740_MUT); | ||
72 | } | ||
73 | |||
74 | void audiohw_unmute(void) | ||
75 | { | ||
76 | wm8740_write_reg(WM8740_REG2, 0x00); | ||
77 | } | ||
78 | |||
79 | void audiohw_init(void) | ||
80 | { | ||
81 | wm8740_write_reg(WM8740_REG0, 0x00); | ||
82 | wm8740_write_reg(WM8740_REG1, 0x00); | ||
83 | wm8740_write_reg(WM8740_REG2, WM8740_MUT); | ||
84 | wm8740_write_reg(WM8740_REG3, WM8740_I2S); | ||
85 | wm8740_write_reg(WM8740_REG4, 0x00); | ||
86 | } | ||
87 | |||
88 | void audiohw_preinit(void) | ||
89 | { | ||
90 | } | ||
91 | |||
92 | void audiohw_set_frequency(int fsel) | ||
93 | { | ||
94 | (void)fsel; | ||
95 | } | ||
96 | |||
97 | void audiohw_set_filter_roll_off(int value) | ||
98 | { | ||
99 | /* 0 = fast (sharp); | ||
100 | 1 = slow */ | ||
101 | if (value == 0) { | ||
102 | wm8740_write_reg(WM8740_REG3, WM8740_I2S); | ||
103 | } else { | ||
104 | wm8740_write_reg(WM8740_REG3, WM8740_I2S | WM8740_SR0); | ||
105 | } | ||
106 | } | ||
diff --git a/firmware/export/audiohw.h b/firmware/export/audiohw.h index 09001c8045..458fba3412 100644 --- a/firmware/export/audiohw.h +++ b/firmware/export/audiohw.h | |||
@@ -165,6 +165,8 @@ struct sound_settings_info | |||
165 | #include "uda1380.h" | 165 | #include "uda1380.h" |
166 | #elif defined(HAVE_UDA1341) | 166 | #elif defined(HAVE_UDA1341) |
167 | #include "uda1341.h" | 167 | #include "uda1341.h" |
168 | #elif defined(HAVE_WM8740) | ||
169 | #include "wm8740.h" | ||
168 | #elif defined(HAVE_WM8750) || defined(HAVE_WM8751) | 170 | #elif defined(HAVE_WM8750) || defined(HAVE_WM8751) |
169 | #include "wm8751.h" | 171 | #include "wm8751.h" |
170 | #elif defined(HAVE_WM8978) | 172 | #elif defined(HAVE_WM8978) |
@@ -211,6 +213,8 @@ struct sound_settings_info | |||
211 | #include "nwzlinux_codec.h" | 213 | #include "nwzlinux_codec.h" |
212 | #elif defined(HAVE_CS4398) | 214 | #elif defined(HAVE_CS4398) |
213 | #include "cs4398.h" | 215 | #include "cs4398.h" |
216 | #elif defined(HAVE_ES9018) | ||
217 | #include "es9018.h" | ||
214 | #elif (CONFIG_PLATFORM & (PLATFORM_ANDROID | PLATFORM_MAEMO\ | 218 | #elif (CONFIG_PLATFORM & (PLATFORM_ANDROID | PLATFORM_MAEMO\ |
215 | | PLATFORM_PANDORA | PLATFORM_SDL)) | 219 | | PLATFORM_PANDORA | PLATFORM_SDL)) |
216 | #include "hosted_codec.h" | 220 | #include "hosted_codec.h" |
@@ -571,7 +575,7 @@ void audiohw_set_depth_3d(int val); | |||
571 | #ifdef AUDIOHW_HAVE_FILTER_ROLL_OFF | 575 | #ifdef AUDIOHW_HAVE_FILTER_ROLL_OFF |
572 | /** | 576 | /** |
573 | * Set DAC's oversampling filter roll-off. | 577 | * Set DAC's oversampling filter roll-off. |
574 | * @param val 0 - sharp roll-off, 1 - slow roll-off. | 578 | * @param val 0 - sharp roll-off, 1 - slow roll-off, 2 - short roll-off, 3 - bypass. |
575 | * NOTE: AUDIOHW_CAPS need to contain | 579 | * NOTE: AUDIOHW_CAPS need to contain |
576 | * FILTER_ROLL_OFF_CAP | 580 | * FILTER_ROLL_OFF_CAP |
577 | */ | 581 | */ |
diff --git a/firmware/export/config.h b/firmware/export/config.h index 8b177963d3..2db12bea4a 100644 --- a/firmware/export/config.h +++ b/firmware/export/config.h | |||
@@ -169,6 +169,8 @@ | |||
169 | #define SONY_NWZA860_PAD 64 /* The NWZ-A860 is too different (touchscreen) */ | 169 | #define SONY_NWZA860_PAD 64 /* The NWZ-A860 is too different (touchscreen) */ |
170 | #define AGPTEK_ROCKER_PAD 65 | 170 | #define AGPTEK_ROCKER_PAD 65 |
171 | #define XDUOO_X3_PAD 66 | 171 | #define XDUOO_X3_PAD 66 |
172 | #define IHIFI_770_PAD 67 | ||
173 | #define IHIFI_800_PAD 68 | ||
172 | 174 | ||
173 | /* CONFIG_REMOTE_KEYPAD */ | 175 | /* CONFIG_REMOTE_KEYPAD */ |
174 | #define H100_REMOTE 1 | 176 | #define H100_REMOTE 1 |
@@ -284,6 +286,9 @@ | |||
284 | #define LCD_NWZ_LINUX 63 /* as used in the Linux-based NWZ series */ | 286 | #define LCD_NWZ_LINUX 63 /* as used in the Linux-based NWZ series */ |
285 | #define LCD_INGENIC_LINUX 64 | 287 | #define LCD_INGENIC_LINUX 64 |
286 | #define LCD_XDUOOX3 65 /* as used by the xDuoo X3 */ | 288 | #define LCD_XDUOOX3 65 /* as used by the xDuoo X3 */ |
289 | #define LCD_IHIFI770 66 /* as used by IHIFI 770 */ | ||
290 | #define LCD_IHIFI770C 67 /* as used by IHIFI 770C */ | ||
291 | #define LCD_IHIFI800 68 /* as used by IHIFI 800 */ | ||
287 | 292 | ||
288 | /* LCD_PIXELFORMAT */ | 293 | /* LCD_PIXELFORMAT */ |
289 | #define HORIZONTAL_PACKING 1 | 294 | #define HORIZONTAL_PACKING 1 |
@@ -581,6 +586,12 @@ Lyre prototype 1 */ | |||
581 | #include "config/samsungypz5.h" | 586 | #include "config/samsungypz5.h" |
582 | #elif defined(IHIFI760) | 587 | #elif defined(IHIFI760) |
583 | #include "config/ihifi760.h" | 588 | #include "config/ihifi760.h" |
589 | #elif defined(IHIFI770) | ||
590 | #include "config/ihifi770.h" | ||
591 | #elif defined(IHIFI770C) | ||
592 | #include "config/ihifi770c.h" | ||
593 | #elif defined(IHIFI800) | ||
594 | #include "config/ihifi800.h" | ||
584 | #elif defined(IHIFI960) | 595 | #elif defined(IHIFI960) |
585 | #include "config/ihifi960.h" | 596 | #include "config/ihifi960.h" |
586 | #elif defined(CREATIVE_ZENXFISTYLE) | 597 | #elif defined(CREATIVE_ZENXFISTYLE) |
@@ -974,7 +985,6 @@ Lyre prototype 1 */ | |||
974 | #define USB_STATUS_BY_EVENT | 985 | #define USB_STATUS_BY_EVENT |
975 | #define USB_DETECT_BY_REQUEST | 986 | #define USB_DETECT_BY_REQUEST |
976 | #elif CONFIG_USBOTG == USBOTG_RK27XX | 987 | #elif CONFIG_USBOTG == USBOTG_RK27XX |
977 | #define USB_STATUS_BY_EVENT | ||
978 | #define USB_DETECT_BY_REQUEST | 988 | #define USB_DETECT_BY_REQUEST |
979 | #endif /* CONFIG_USB == */ | 989 | #endif /* CONFIG_USB == */ |
980 | #endif /* HAVE_USBSTACK */ | 990 | #endif /* HAVE_USBSTACK */ |
@@ -1193,7 +1203,7 @@ Lyre prototype 1 */ | |||
1193 | #endif /* HAVE_USB_CHARGING_ENABLE && HAVE_USBSTACK */ | 1203 | #endif /* HAVE_USB_CHARGING_ENABLE && HAVE_USBSTACK */ |
1194 | 1204 | ||
1195 | #ifndef SIMULATOR | 1205 | #ifndef SIMULATOR |
1196 | #if defined(HAVE_USBSTACK) || (CONFIG_STORAGE & STORAGE_NAND) | 1206 | #if defined(HAVE_USBSTACK) || (CONFIG_STORAGE & STORAGE_NAND) || (CONFIG_STORAGE & STORAGE_RAMDISK) |
1197 | #define STORAGE_GET_INFO | 1207 | #define STORAGE_GET_INFO |
1198 | #endif | 1208 | #endif |
1199 | #endif | 1209 | #endif |
@@ -1211,7 +1221,8 @@ Lyre prototype 1 */ | |||
1211 | (CONFIG_USBOTG == USBOTG_JZ4760) || \ | 1221 | (CONFIG_USBOTG == USBOTG_JZ4760) || \ |
1212 | (CONFIG_USBOTG == USBOTG_M66591) || \ | 1222 | (CONFIG_USBOTG == USBOTG_M66591) || \ |
1213 | (CONFIG_USBOTG == USBOTG_DESIGNWARE) || \ | 1223 | (CONFIG_USBOTG == USBOTG_DESIGNWARE) || \ |
1214 | (CONFIG_USBOTG == USBOTG_AS3525) | 1224 | (CONFIG_USBOTG == USBOTG_AS3525) || \ |
1225 | (CONFIG_USBOTG == USBOTG_RK27XX) | ||
1215 | #define USB_HAS_BULK | 1226 | #define USB_HAS_BULK |
1216 | #define USB_HAS_INTERRUPT | 1227 | #define USB_HAS_INTERRUPT |
1217 | #elif defined(CPU_TCC780X) || defined(CPU_TCC77X) | 1228 | #elif defined(CPU_TCC780X) || defined(CPU_TCC77X) |
diff --git a/firmware/export/config/ihifi770.h b/firmware/export/config/ihifi770.h new file mode 100644 index 0000000000..af7acff206 --- /dev/null +++ b/firmware/export/config/ihifi770.h | |||
@@ -0,0 +1,197 @@ | |||
1 | /* | ||
2 | * This config file is for IHIFI 770 | ||
3 | */ | ||
4 | |||
5 | /* For Rolo and boot loader */ | ||
6 | #define MODEL_NUMBER 108 | ||
7 | |||
8 | #define MODEL_NAME "IHIFI 770" | ||
9 | |||
10 | /* Define bitmask of input sources - recordable bitmask can be defined | ||
11 | explicitly if different */ | ||
12 | /* #define INPUT_SRC_CAPS (SRC_CAP_MIC | SRC_CAP_FM) */ | ||
13 | |||
14 | /* define the bitmask of hardware sample rates */ | ||
15 | #define HW_SAMPR_CAPS (SAMPR_CAP_96 | SAMPR_CAP_48 | SAMPR_CAP_44 | \ | ||
16 | SAMPR_CAP_32 | SAMPR_CAP_24 | SAMPR_CAP_22 | \ | ||
17 | SAMPR_CAP_16 | SAMPR_CAP_12 | SAMPR_CAP_11 | SAMPR_CAP_8) | ||
18 | |||
19 | #define HAVE_WM8740 | ||
20 | #define CODEC_SLAVE | ||
21 | |||
22 | /* define this if you have a bitmap LCD display */ | ||
23 | #define HAVE_LCD_BITMAP | ||
24 | |||
25 | /* define this if you can flip your LCD */ | ||
26 | /* #define HAVE_LCD_FLIP */ | ||
27 | |||
28 | /* define this if you have a colour LCD */ | ||
29 | #define HAVE_LCD_COLOR | ||
30 | |||
31 | /* define this if you want album art for this target */ | ||
32 | #define HAVE_ALBUMART | ||
33 | |||
34 | /* define this to enable bitmap scaling */ | ||
35 | #define HAVE_BMP_SCALING | ||
36 | |||
37 | /* define this to enable JPEG decoding */ | ||
38 | #define HAVE_JPEG | ||
39 | |||
40 | /* define this if you can invert the colours on your LCD */ | ||
41 | /* #define HAVE_LCD_INVERT */ | ||
42 | |||
43 | /* define this if you have access to the quickscreen */ | ||
44 | #define HAVE_QUICKSCREEN | ||
45 | |||
46 | /* define this if you would like tagcache to build on this target */ | ||
47 | #define HAVE_TAGCACHE | ||
48 | |||
49 | /* define this if you have a flash memory storage */ | ||
50 | #define HAVE_FLASH_STORAGE | ||
51 | |||
52 | #define CONFIG_STORAGE (STORAGE_SD | STORAGE_NAND) | ||
53 | |||
54 | #define CONFIG_NAND NAND_RK27XX | ||
55 | #define HAVE_SW_TONE_CONTROLS | ||
56 | |||
57 | #define HAVE_HOTSWAP | ||
58 | |||
59 | #define NUM_DRIVES 1 | ||
60 | #define SECTOR_SIZE 512 | ||
61 | |||
62 | /* for small(ish) SD cards */ | ||
63 | #define HAVE_FAT16SUPPORT | ||
64 | |||
65 | /* LCD dimensions */ | ||
66 | #define LCD_WIDTH 320 | ||
67 | #define LCD_HEIGHT 240 | ||
68 | /* sqrt(320^2 + 240^2) / 2.4 = 166.7 */ | ||
69 | #define LCD_DPI 167 | ||
70 | #define LCD_DEPTH 16 /* pseudo 262.144 colors */ | ||
71 | #define LCD_PIXELFORMAT RGB565 /* rgb565 */ | ||
72 | |||
73 | /* Define this if the LCD can shut down */ | ||
74 | /* #define HAVE_LCD_SHUTDOWN */ | ||
75 | |||
76 | /* Define this if your LCD can be enabled/disabled */ | ||
77 | #define HAVE_LCD_ENABLE | ||
78 | |||
79 | /* Define this if your LCD can be put to sleep. HAVE_LCD_ENABLE | ||
80 | should be defined as well. */ | ||
81 | #ifndef BOOTLOADER | ||
82 | /* TODO: #define HAVE_LCD_SLEEP */ | ||
83 | /* TODO: #define HAVE_LCD_SLEEP_SETTING */ | ||
84 | #endif | ||
85 | |||
86 | #define CONFIG_KEYPAD IHIFI_770_PAD | ||
87 | |||
88 | /* define this if the target has volume keys which can be used in the lists */ | ||
89 | #define HAVE_VOLUME_IN_LIST | ||
90 | |||
91 | /* Define this if a programmable hotkey is mapped */ | ||
92 | /* #define HAVE_HOTKEY */ | ||
93 | |||
94 | /* Define this if you do software codec */ | ||
95 | #define CONFIG_CODEC SWCODEC | ||
96 | |||
97 | /* define this if you have a real-time clock */ | ||
98 | /* #define CONFIG_RTC RTC_NANO2G */ | ||
99 | |||
100 | /* Define if the device can wake from an RTC alarm */ | ||
101 | /* #define HAVE_RTC_ALARM */ | ||
102 | |||
103 | /* Define the type of audio codec */ | ||
104 | /*#define HAVE_RK27XX_CODEC */ | ||
105 | |||
106 | /* #define HAVE_PCM_DMA_ADDRESS */ | ||
107 | |||
108 | /* Define this for LCD backlight available */ | ||
109 | #define HAVE_BACKLIGHT | ||
110 | #define HAVE_BACKLIGHT_BRIGHTNESS | ||
111 | #define MIN_BRIGHTNESS_SETTING 0 | ||
112 | #define MAX_BRIGHTNESS_SETTING 31 | ||
113 | #define DEFAULT_BRIGHTNESS_SETTING 31 | ||
114 | #define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_SW_HW_REG | ||
115 | |||
116 | /* Define this if you have a software controlled poweroff */ | ||
117 | #define HAVE_SW_POWEROFF | ||
118 | |||
119 | /* The number of bytes reserved for loadable codecs */ | ||
120 | #define CODEC_SIZE 0x100000 | ||
121 | |||
122 | /* The number of bytes reserved for loadable plugins */ | ||
123 | #define PLUGIN_BUFFER_SIZE 0x80000 | ||
124 | |||
125 | #define BATTERY_CAPACITY_DEFAULT 1050 /* default battery capacity */ | ||
126 | #define BATTERY_CAPACITY_MIN 500 /* min. capacity selectable */ | ||
127 | #define BATTERY_CAPACITY_MAX 1050 /* max. capacity selectable */ | ||
128 | #define BATTERY_CAPACITY_INC 10 /* capacity increment */ | ||
129 | #define BATTERY_TYPES_COUNT 1 /* only one type */ | ||
130 | |||
131 | #define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE | ||
132 | |||
133 | /* Hardware controlled charging with monitoring */ | ||
134 | #define CONFIG_CHARGING CHARGING_MONITOR | ||
135 | |||
136 | /* define current usage levels */ | ||
137 | /* TODO: #define CURRENT_NORMAL | ||
138 | * TODO: #define CURRENT_BACKLIGHT 23 | ||
139 | */ | ||
140 | |||
141 | /* define this if the unit can be powered or charged via USB */ | ||
142 | #define HAVE_USB_POWER | ||
143 | |||
144 | /* Define this if your LCD can set contrast */ | ||
145 | /* #define HAVE_LCD_CONTRAST */ | ||
146 | |||
147 | /* Offset ( in the firmware file's header ) to the file CRC */ | ||
148 | #define FIRMWARE_OFFSET_FILE_CRC 0 | ||
149 | |||
150 | /* Offset ( in the firmware file's header ) to the real data */ | ||
151 | #define FIRMWARE_OFFSET_FILE_DATA 8 | ||
152 | |||
153 | #define STORAGE_NEEDS_ALIGN | ||
154 | |||
155 | /* Define this if you have adjustable CPU frequency */ | ||
156 | #define HAVE_ADJUSTABLE_CPU_FREQ | ||
157 | |||
158 | /* Virtual LED (icon) */ | ||
159 | #define CONFIG_LED LED_VIRTUAL | ||
160 | |||
161 | /** Non-simulator section **/ | ||
162 | #ifndef SIMULATOR | ||
163 | |||
164 | /* The exact type of CPU */ | ||
165 | #define CONFIG_CPU RK27XX | ||
166 | |||
167 | /* Define this to the CPU frequency */ | ||
168 | #define CPU_FREQ 200000000 | ||
169 | |||
170 | /* I2C interface */ | ||
171 | #define CONFIG_I2C I2C_RK27XX | ||
172 | |||
173 | /* define this if the hardware can be powered off while charging */ | ||
174 | /* #define HAVE_POWEROFF_WHILE_CHARGING */ | ||
175 | |||
176 | /* Type of LCD */ | ||
177 | #define CONFIG_LCD LCD_IHIFI770 | ||
178 | |||
179 | /* USB On-the-go */ | ||
180 | #define CONFIG_USBOTG USBOTG_RK27XX | ||
181 | |||
182 | /* enable these for the experimental usb stack */ | ||
183 | #define HAVE_USBSTACK | ||
184 | |||
185 | #define USB_VENDOR_ID 0x071b | ||
186 | #define USB_PRODUCT_ID 0x3202 | ||
187 | #define HAVE_BOOTLOADER_USB_MODE | ||
188 | |||
189 | #define RKW_FORMAT | ||
190 | #define BOOTFILE_EXT "rkw" | ||
191 | #define BOOTFILE "rockbox." BOOTFILE_EXT | ||
192 | #define BOOTDIR "/.rockbox" | ||
193 | |||
194 | /* disabled for now */ | ||
195 | #undef HAVE_HOTSWAP | ||
196 | |||
197 | #endif /* SIMULATOR */ | ||
diff --git a/firmware/export/config/ihifi770c.h b/firmware/export/config/ihifi770c.h new file mode 100644 index 0000000000..c4058f337b --- /dev/null +++ b/firmware/export/config/ihifi770c.h | |||
@@ -0,0 +1,197 @@ | |||
1 | /* | ||
2 | * This config file is for IHIFI 770C | ||
3 | */ | ||
4 | |||
5 | /* For Rolo and boot loader */ | ||
6 | #define MODEL_NUMBER 108 | ||
7 | |||
8 | #define MODEL_NAME "IHIFI 770C" | ||
9 | |||
10 | /* Define bitmask of input sources - recordable bitmask can be defined | ||
11 | explicitly if different */ | ||
12 | /* #define INPUT_SRC_CAPS (SRC_CAP_MIC | SRC_CAP_FM) */ | ||
13 | |||
14 | /* define the bitmask of hardware sample rates */ | ||
15 | #define HW_SAMPR_CAPS (SAMPR_CAP_96 | SAMPR_CAP_48 | SAMPR_CAP_44 | \ | ||
16 | SAMPR_CAP_32 | SAMPR_CAP_24 | SAMPR_CAP_22 | \ | ||
17 | SAMPR_CAP_16 | SAMPR_CAP_12 | SAMPR_CAP_11 | SAMPR_CAP_8) | ||
18 | |||
19 | #define HAVE_WM8740 | ||
20 | #define CODEC_SLAVE | ||
21 | |||
22 | /* define this if you have a bitmap LCD display */ | ||
23 | #define HAVE_LCD_BITMAP | ||
24 | |||
25 | /* define this if you can flip your LCD */ | ||
26 | /* #define HAVE_LCD_FLIP */ | ||
27 | |||
28 | /* define this if you have a colour LCD */ | ||
29 | #define HAVE_LCD_COLOR | ||
30 | |||
31 | /* define this if you want album art for this target */ | ||
32 | #define HAVE_ALBUMART | ||
33 | |||
34 | /* define this to enable bitmap scaling */ | ||
35 | #define HAVE_BMP_SCALING | ||
36 | |||
37 | /* define this to enable JPEG decoding */ | ||
38 | #define HAVE_JPEG | ||
39 | |||
40 | /* define this if you can invert the colours on your LCD */ | ||
41 | /* #define HAVE_LCD_INVERT */ | ||
42 | |||
43 | /* define this if you have access to the quickscreen */ | ||
44 | #define HAVE_QUICKSCREEN | ||
45 | |||
46 | /* define this if you would like tagcache to build on this target */ | ||
47 | #define HAVE_TAGCACHE | ||
48 | |||
49 | /* define this if you have a flash memory storage */ | ||
50 | #define HAVE_FLASH_STORAGE | ||
51 | |||
52 | #define CONFIG_STORAGE (STORAGE_SD | STORAGE_NAND) | ||
53 | |||
54 | #define CONFIG_NAND NAND_RK27XX | ||
55 | #define HAVE_SW_TONE_CONTROLS | ||
56 | |||
57 | #define HAVE_HOTSWAP | ||
58 | |||
59 | #define NUM_DRIVES 1 | ||
60 | #define SECTOR_SIZE 512 | ||
61 | |||
62 | /* for small(ish) SD cards */ | ||
63 | #define HAVE_FAT16SUPPORT | ||
64 | |||
65 | /* LCD dimensions */ | ||
66 | #define LCD_WIDTH 320 | ||
67 | #define LCD_HEIGHT 240 | ||
68 | /* sqrt(320^2 + 240^2) / 2.4 = 166.7 */ | ||
69 | #define LCD_DPI 167 | ||
70 | #define LCD_DEPTH 16 /* pseudo 262.144 colors */ | ||
71 | #define LCD_PIXELFORMAT RGB565 /* rgb565 */ | ||
72 | |||
73 | /* Define this if the LCD can shut down */ | ||
74 | /* #define HAVE_LCD_SHUTDOWN */ | ||
75 | |||
76 | /* Define this if your LCD can be enabled/disabled */ | ||
77 | #define HAVE_LCD_ENABLE | ||
78 | |||
79 | /* Define this if your LCD can be put to sleep. HAVE_LCD_ENABLE | ||
80 | should be defined as well. */ | ||
81 | #ifndef BOOTLOADER | ||
82 | /* TODO: #define HAVE_LCD_SLEEP */ | ||
83 | /* TODO: #define HAVE_LCD_SLEEP_SETTING */ | ||
84 | #endif | ||
85 | |||
86 | #define CONFIG_KEYPAD IHIFI_770_PAD | ||
87 | |||
88 | /* define this if the target has volume keys which can be used in the lists */ | ||
89 | #define HAVE_VOLUME_IN_LIST | ||
90 | |||
91 | /* Define this if a programmable hotkey is mapped */ | ||
92 | /* #define HAVE_HOTKEY */ | ||
93 | |||
94 | /* Define this if you do software codec */ | ||
95 | #define CONFIG_CODEC SWCODEC | ||
96 | |||
97 | /* define this if you have a real-time clock */ | ||
98 | /* #define CONFIG_RTC RTC_NANO2G */ | ||
99 | |||
100 | /* Define if the device can wake from an RTC alarm */ | ||
101 | /* #define HAVE_RTC_ALARM */ | ||
102 | |||
103 | /* Define the type of audio codec */ | ||
104 | /*#define HAVE_RK27XX_CODEC */ | ||
105 | |||
106 | /* #define HAVE_PCM_DMA_ADDRESS */ | ||
107 | |||
108 | /* Define this for LCD backlight available */ | ||
109 | #define HAVE_BACKLIGHT | ||
110 | #define HAVE_BACKLIGHT_BRIGHTNESS | ||
111 | #define MIN_BRIGHTNESS_SETTING 0 | ||
112 | #define MAX_BRIGHTNESS_SETTING 31 | ||
113 | #define DEFAULT_BRIGHTNESS_SETTING 31 | ||
114 | #define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_SW_HW_REG | ||
115 | |||
116 | /* Define this if you have a software controlled poweroff */ | ||
117 | #define HAVE_SW_POWEROFF | ||
118 | |||
119 | /* The number of bytes reserved for loadable codecs */ | ||
120 | #define CODEC_SIZE 0x100000 | ||
121 | |||
122 | /* The number of bytes reserved for loadable plugins */ | ||
123 | #define PLUGIN_BUFFER_SIZE 0x80000 | ||
124 | |||
125 | #define BATTERY_CAPACITY_DEFAULT 1050 /* default battery capacity */ | ||
126 | #define BATTERY_CAPACITY_MIN 500 /* min. capacity selectable */ | ||
127 | #define BATTERY_CAPACITY_MAX 1050 /* max. capacity selectable */ | ||
128 | #define BATTERY_CAPACITY_INC 10 /* capacity increment */ | ||
129 | #define BATTERY_TYPES_COUNT 1 /* only one type */ | ||
130 | |||
131 | #define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE | ||
132 | |||
133 | /* Hardware controlled charging with monitoring */ | ||
134 | #define CONFIG_CHARGING CHARGING_MONITOR | ||
135 | |||
136 | /* define current usage levels */ | ||
137 | /* TODO: #define CURRENT_NORMAL | ||
138 | * TODO: #define CURRENT_BACKLIGHT 23 | ||
139 | */ | ||
140 | |||
141 | /* define this if the unit can be powered or charged via USB */ | ||
142 | #define HAVE_USB_POWER | ||
143 | |||
144 | /* Define this if your LCD can set contrast */ | ||
145 | /* #define HAVE_LCD_CONTRAST */ | ||
146 | |||
147 | /* Offset ( in the firmware file's header ) to the file CRC */ | ||
148 | #define FIRMWARE_OFFSET_FILE_CRC 0 | ||
149 | |||
150 | /* Offset ( in the firmware file's header ) to the real data */ | ||
151 | #define FIRMWARE_OFFSET_FILE_DATA 8 | ||
152 | |||
153 | #define STORAGE_NEEDS_ALIGN | ||
154 | |||
155 | /* Define this if you have adjustable CPU frequency */ | ||
156 | #define HAVE_ADJUSTABLE_CPU_FREQ | ||
157 | |||
158 | /* Virtual LED (icon) */ | ||
159 | #define CONFIG_LED LED_VIRTUAL | ||
160 | |||
161 | /** Non-simulator section **/ | ||
162 | #ifndef SIMULATOR | ||
163 | |||
164 | /* The exact type of CPU */ | ||
165 | #define CONFIG_CPU RK27XX | ||
166 | |||
167 | /* Define this to the CPU frequency */ | ||
168 | #define CPU_FREQ 200000000 | ||
169 | |||
170 | /* I2C interface */ | ||
171 | #define CONFIG_I2C I2C_RK27XX | ||
172 | |||
173 | /* define this if the hardware can be powered off while charging */ | ||
174 | /* #define HAVE_POWEROFF_WHILE_CHARGING */ | ||
175 | |||
176 | /* Type of LCD */ | ||
177 | #define CONFIG_LCD LCD_IHIFI770C | ||
178 | |||
179 | /* USB On-the-go */ | ||
180 | #define CONFIG_USBOTG USBOTG_RK27XX | ||
181 | |||
182 | /* enable these for the experimental usb stack */ | ||
183 | #define HAVE_USBSTACK | ||
184 | |||
185 | #define USB_VENDOR_ID 0x071b | ||
186 | #define USB_PRODUCT_ID 0x3202 | ||
187 | #define HAVE_BOOTLOADER_USB_MODE | ||
188 | |||
189 | #define RKW_FORMAT | ||
190 | #define BOOTFILE_EXT "rkw" | ||
191 | #define BOOTFILE "rockbox." BOOTFILE_EXT | ||
192 | #define BOOTDIR "/.rockbox" | ||
193 | |||
194 | /* disabled for now */ | ||
195 | #undef HAVE_HOTSWAP | ||
196 | |||
197 | #endif /* SIMULATOR */ | ||
diff --git a/firmware/export/config/ihifi800.h b/firmware/export/config/ihifi800.h new file mode 100644 index 0000000000..eb1c2015ad --- /dev/null +++ b/firmware/export/config/ihifi800.h | |||
@@ -0,0 +1,198 @@ | |||
1 | /* | ||
2 | * This config file is for IHIFI 800 | ||
3 | */ | ||
4 | |||
5 | /* For Rolo and boot loader */ | ||
6 | #define MODEL_NUMBER 109 | ||
7 | |||
8 | #define MODEL_NAME "IHIFI 800" | ||
9 | |||
10 | /* Define bitmask of input sources - recordable bitmask can be defined | ||
11 | explicitly if different */ | ||
12 | /* #define INPUT_SRC_CAPS (SRC_CAP_MIC | SRC_CAP_FM) */ | ||
13 | |||
14 | /* define the bitmask of hardware sample rates */ | ||
15 | #define HW_SAMPR_CAPS (SAMPR_CAP_96 | SAMPR_CAP_48 | SAMPR_CAP_44 | \ | ||
16 | SAMPR_CAP_32 | SAMPR_CAP_24 | SAMPR_CAP_22 | \ | ||
17 | SAMPR_CAP_16 | SAMPR_CAP_12 | SAMPR_CAP_11 | SAMPR_CAP_8) | ||
18 | |||
19 | #define HAVE_ES9018 | ||
20 | #define CODEC_SLAVE | ||
21 | |||
22 | /* define this if you have a bitmap LCD display */ | ||
23 | #define HAVE_LCD_BITMAP | ||
24 | |||
25 | /* define this if you can flip your LCD */ | ||
26 | /* #define HAVE_LCD_FLIP */ | ||
27 | |||
28 | /* define this if you have a colour LCD */ | ||
29 | #define HAVE_LCD_COLOR | ||
30 | |||
31 | /* define this if you want album art for this target */ | ||
32 | #define HAVE_ALBUMART | ||
33 | |||
34 | /* define this to enable bitmap scaling */ | ||
35 | #define HAVE_BMP_SCALING | ||
36 | |||
37 | /* define this to enable JPEG decoding */ | ||
38 | #define HAVE_JPEG | ||
39 | |||
40 | /* define this if you can invert the colours on your LCD */ | ||
41 | /* #define HAVE_LCD_INVERT */ | ||
42 | |||
43 | /* define this if you have access to the quickscreen */ | ||
44 | #define HAVE_QUICKSCREEN | ||
45 | |||
46 | /* define this if you would like tagcache to build on this target */ | ||
47 | #define HAVE_TAGCACHE | ||
48 | |||
49 | /* define this if you have a flash memory storage */ | ||
50 | #define HAVE_FLASH_STORAGE | ||
51 | |||
52 | #define CONFIG_STORAGE (STORAGE_SD | STORAGE_NAND) | ||
53 | |||
54 | #define CONFIG_NAND NAND_RK27XX | ||
55 | #define HAVE_SW_TONE_CONTROLS | ||
56 | |||
57 | #define HAVE_HOTSWAP | ||
58 | |||
59 | #define NUM_DRIVES 1 | ||
60 | #define SECTOR_SIZE 512 | ||
61 | |||
62 | /* for small(ish) SD cards */ | ||
63 | #define HAVE_FAT16SUPPORT | ||
64 | |||
65 | /* LCD dimensions */ | ||
66 | #define LCD_WIDTH 240 | ||
67 | #define LCD_HEIGHT 320 | ||
68 | /* sqrt(240^2 + 320^2) / 2.4 = 166.7 */ | ||
69 | #define LCD_DPI 167 | ||
70 | #define LCD_DEPTH 16 /* pseudo 262.144 colors */ | ||
71 | #define LCD_PIXELFORMAT RGB565 /* rgb565 */ | ||
72 | |||
73 | /* Define this if the LCD can shut down */ | ||
74 | /* #define HAVE_LCD_SHUTDOWN */ | ||
75 | |||
76 | /* Define this if your LCD can be enabled/disabled */ | ||
77 | #define HAVE_LCD_ENABLE | ||
78 | |||
79 | /* Define this if your LCD can be put to sleep. HAVE_LCD_ENABLE | ||
80 | should be defined as well. */ | ||
81 | #ifndef BOOTLOADER | ||
82 | /* TODO: #define HAVE_LCD_SLEEP */ | ||
83 | /* TODO: #define HAVE_LCD_SLEEP_SETTING */ | ||
84 | #endif | ||
85 | |||
86 | #define CONFIG_KEYPAD IHIFI_800_PAD | ||
87 | |||
88 | /* define this if the target has volume keys which can be used in the lists */ | ||
89 | #define HAVE_VOLUME_IN_LIST | ||
90 | |||
91 | /* Define this if a programmable hotkey is mapped */ | ||
92 | /* #define HAVE_HOTKEY */ | ||
93 | |||
94 | /* Define this if you do software codec */ | ||
95 | #define CONFIG_CODEC SWCODEC | ||
96 | |||
97 | /* define this if you have a real-time clock */ | ||
98 | /* #define CONFIG_RTC RTC_NANO2G */ | ||
99 | |||
100 | /* Define if the device can wake from an RTC alarm */ | ||
101 | /* #define HAVE_RTC_ALARM */ | ||
102 | |||
103 | /* Define the type of audio codec */ | ||
104 | /*#define HAVE_RK27XX_CODEC */ | ||
105 | |||
106 | /* #define HAVE_PCM_DMA_ADDRESS */ | ||
107 | |||
108 | /* Define this for LCD backlight available */ | ||
109 | #define HAVE_BACKLIGHT | ||
110 | #define HAVE_BACKLIGHT_BRIGHTNESS | ||
111 | #define MIN_BRIGHTNESS_SETTING 0 | ||
112 | #define MAX_BRIGHTNESS_SETTING 31 | ||
113 | #define DEFAULT_BRIGHTNESS_SETTING 31 | ||
114 | #define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_SW_HW_REG | ||
115 | |||
116 | /* Define this if you have a software controlled poweroff */ | ||
117 | #define HAVE_SW_POWEROFF | ||
118 | |||
119 | /* The number of bytes reserved for loadable codecs */ | ||
120 | #define CODEC_SIZE 0x100000 | ||
121 | |||
122 | /* The number of bytes reserved for loadable plugins */ | ||
123 | #define PLUGIN_BUFFER_SIZE 0x80000 | ||
124 | |||
125 | /* TODO: Figure out real values */ | ||
126 | #define BATTERY_CAPACITY_DEFAULT 1400 /* default battery capacity */ | ||
127 | #define BATTERY_CAPACITY_MIN 700 /* min. capacity selectable */ | ||
128 | #define BATTERY_CAPACITY_MAX 1400 /* max. capacity selectable */ | ||
129 | #define BATTERY_CAPACITY_INC 10 /* capacity increment */ | ||
130 | #define BATTERY_TYPES_COUNT 1 /* only one type */ | ||
131 | |||
132 | #define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE | ||
133 | |||
134 | /* Hardware controlled charging with monitoring */ | ||
135 | #define CONFIG_CHARGING CHARGING_MONITOR | ||
136 | |||
137 | /* define current usage levels */ | ||
138 | /* TODO: #define CURRENT_NORMAL | ||
139 | * TODO: #define CURRENT_BACKLIGHT 23 | ||
140 | */ | ||
141 | |||
142 | /* define this if the unit can be powered or charged via USB */ | ||
143 | #define HAVE_USB_POWER | ||
144 | |||
145 | /* Define this if your LCD can set contrast */ | ||
146 | /* #define HAVE_LCD_CONTRAST */ | ||
147 | |||
148 | /* Offset ( in the firmware file's header ) to the file CRC */ | ||
149 | #define FIRMWARE_OFFSET_FILE_CRC 0 | ||
150 | |||
151 | /* Offset ( in the firmware file's header ) to the real data */ | ||
152 | #define FIRMWARE_OFFSET_FILE_DATA 8 | ||
153 | |||
154 | #define STORAGE_NEEDS_ALIGN | ||
155 | |||
156 | /* Define this if you have adjustable CPU frequency */ | ||
157 | #define HAVE_ADJUSTABLE_CPU_FREQ | ||
158 | |||
159 | /* Virtual LED (icon) */ | ||
160 | #define CONFIG_LED LED_VIRTUAL | ||
161 | |||
162 | /** Non-simulator section **/ | ||
163 | #ifndef SIMULATOR | ||
164 | |||
165 | /* The exact type of CPU */ | ||
166 | #define CONFIG_CPU RK27XX | ||
167 | |||
168 | /* Define this to the CPU frequency */ | ||
169 | #define CPU_FREQ 200000000 | ||
170 | |||
171 | /* I2C interface */ | ||
172 | #define CONFIG_I2C I2C_RK27XX | ||
173 | |||
174 | /* define this if the hardware can be powered off while charging */ | ||
175 | /* #define HAVE_POWEROFF_WHILE_CHARGING */ | ||
176 | |||
177 | /* Type of LCD */ | ||
178 | #define CONFIG_LCD LCD_IHIFI800 | ||
179 | |||
180 | /* USB On-the-go */ | ||
181 | #define CONFIG_USBOTG USBOTG_RK27XX | ||
182 | |||
183 | /* enable these for the experimental usb stack */ | ||
184 | #define HAVE_USBSTACK | ||
185 | |||
186 | #define USB_VENDOR_ID 0x071b | ||
187 | #define USB_PRODUCT_ID 0x3202 | ||
188 | #define HAVE_BOOTLOADER_USB_MODE | ||
189 | |||
190 | #define RKW_FORMAT | ||
191 | #define BOOTFILE_EXT "rkw" | ||
192 | #define BOOTFILE "rockbox." BOOTFILE_EXT | ||
193 | #define BOOTDIR "/.rockbox" | ||
194 | |||
195 | /* disabled for now */ | ||
196 | #undef HAVE_HOTSWAP | ||
197 | |||
198 | #endif /* SIMULATOR */ | ||
diff --git a/firmware/export/config/rk27generic.h b/firmware/export/config/rk27generic.h index 503857bd43..69cf9f3758 100644 --- a/firmware/export/config/rk27generic.h +++ b/firmware/export/config/rk27generic.h | |||
@@ -63,7 +63,7 @@ | |||
63 | /* commented for now */ | 63 | /* commented for now */ |
64 | /* #define HAVE_HOTSWAP */ | 64 | /* #define HAVE_HOTSWAP */ |
65 | 65 | ||
66 | #define NUM_DRIVES 2 | 66 | #define NUM_DRIVES 1 |
67 | #define SECTOR_SIZE 512 | 67 | #define SECTOR_SIZE 512 |
68 | 68 | ||
69 | /* for small(ish) SD cards */ | 69 | /* for small(ish) SD cards */ |
diff --git a/firmware/export/es9018.h b/firmware/export/es9018.h new file mode 100644 index 0000000000..41ea0d0b1c --- /dev/null +++ b/firmware/export/es9018.h | |||
@@ -0,0 +1,39 @@ | |||
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 | #ifndef _ES9018_H | ||
23 | #define _ES9018_H | ||
24 | |||
25 | #define ES9018_VOLUME_MIN -1270 | ||
26 | #define ES9018_VOLUME_MAX 0 | ||
27 | |||
28 | #define AUDIOHW_CAPS (FILTER_ROLL_OFF_CAP) | ||
29 | #define AUDIOHW_HAVE_SHORT_ROLL_OFF | ||
30 | AUDIOHW_SETTING(VOLUME, "dB", 0, 1, ES9018_VOLUME_MIN/10, ES9018_VOLUME_MAX/10, 0) | ||
31 | AUDIOHW_SETTING(FILTER_ROLL_OFF, "", 0, 1, 0, 3, 0) | ||
32 | |||
33 | void es9018_write_reg(uint8_t reg, uint8_t val); | ||
34 | uint8_t es9018_read_reg(uint8_t reg); | ||
35 | |||
36 | void audiohw_mute(void); | ||
37 | void audiohw_unmute(void); | ||
38 | |||
39 | #endif | ||
diff --git a/firmware/export/rk27xx.h b/firmware/export/rk27xx.h index 58b3fe8166..dc6bca7cbd 100644 --- a/firmware/export/rk27xx.h +++ b/firmware/export/rk27xx.h | |||
@@ -8,7 +8,8 @@ | |||
8 | #define FLASH_BANK1 0x11000000 | 8 | #define FLASH_BANK1 0x11000000 |
9 | 9 | ||
10 | #define USB_NUM_ENDPOINTS 16 | 10 | #define USB_NUM_ENDPOINTS 16 |
11 | #define USB_DEVBSS_ATTR | 11 | /* cache aligned */ |
12 | #define USB_DEVBSS_ATTR __attribute__((aligned(CACHEALIGN_SIZE))) | ||
12 | 13 | ||
13 | /* Timers */ | 14 | /* Timers */ |
14 | #define APB0_TIMER (ARM_BUS0_BASE + 0x00000000) | 15 | #define APB0_TIMER (ARM_BUS0_BASE + 0x00000000) |
@@ -811,6 +812,7 @@ | |||
811 | #define RXVOIDINTEN (1<<5) | 812 | #define RXVOIDINTEN (1<<5) |
812 | #define RXERRINTEN (1<<6) | 813 | #define RXERRINTEN (1<<6) |
813 | #define RXACKINTEN (1<<7) | 814 | #define RXACKINTEN (1<<7) |
815 | #define RXCFINTE (1<<12) | ||
814 | /* bits 31:8 reserved for EP0 */ | 816 | /* bits 31:8 reserved for EP0 */ |
815 | /* bits 31:14 reserved for others */ | 817 | /* bits 31:14 reserved for others */ |
816 | 818 | ||
@@ -833,6 +835,7 @@ | |||
833 | #define TXERRINTEN (1<<5) | 835 | #define TXERRINTEN (1<<5) |
834 | #define TXACKINTEN (1<<6) | 836 | #define TXACKINTEN (1<<6) |
835 | #define TXDMADNEN (1<<7) /* reserved for EP0 */ | 837 | #define TXDMADNEN (1<<7) /* reserved for EP0 */ |
838 | #define TXCFINTE (1<<12) | ||
836 | /* bits 31:8 reserved */ | 839 | /* bits 31:8 reserved */ |
837 | 840 | ||
838 | /* TXnBUF bits */ | 841 | /* TXnBUF bits */ |
diff --git a/firmware/export/wm8740.h b/firmware/export/wm8740.h new file mode 100644 index 0000000000..ff27a7e41e --- /dev/null +++ b/firmware/export/wm8740.h | |||
@@ -0,0 +1,83 @@ | |||
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 | #ifndef _WM8740_H | ||
23 | #define _WM8740_H | ||
24 | |||
25 | #define WM8740_VOLUME_MIN -1270 | ||
26 | #define WM8740_VOLUME_MAX 0 | ||
27 | |||
28 | #define AUDIOHW_CAPS (FILTER_ROLL_OFF_CAP) | ||
29 | AUDIOHW_SETTING(VOLUME, "dB", 0, 1, WM8740_VOLUME_MIN/10, WM8740_VOLUME_MAX/10, 0) | ||
30 | AUDIOHW_SETTING(FILTER_ROLL_OFF, "", 0, 1, 0, 1, 0) | ||
31 | |||
32 | #define WM8740_REG0 0x0000 | ||
33 | #define WM8740_REG1 0x0200 | ||
34 | #define WM8740_REG2 0x0400 | ||
35 | #define WM8740_REG3 0x0600 | ||
36 | #define WM8740_REG4 0x0C00 | ||
37 | |||
38 | /** | ||
39 | * Register #0 | ||
40 | */ | ||
41 | #define WM8740_LDL (1<<8) | ||
42 | |||
43 | /** | ||
44 | * Register #1 | ||
45 | */ | ||
46 | #define WM8740_LDR (1<<8) | ||
47 | |||
48 | /** | ||
49 | * Register #2 | ||
50 | */ | ||
51 | #define WM8740_MUT (1<<0) | ||
52 | #define WM8740_DEM (1<<1) | ||
53 | #define WM8740_OPE (1<<2) | ||
54 | #define WM8740_IW0 (1<<3) | ||
55 | #define WM8740_IW1 (1<<4) | ||
56 | |||
57 | /** | ||
58 | * Register #3 | ||
59 | */ | ||
60 | #define WM8740_I2S (1<<0) | ||
61 | #define WM8740_LRP (1<<1) | ||
62 | #define WM8740_ATC (1<<2) | ||
63 | #define WM8740_SR0 (1<<3) | ||
64 | #define WM8740_REV (1<<4) | ||
65 | #define WM8740_SF0 (1<<6) | ||
66 | #define WM8740_SF1 (1<<7) | ||
67 | #define WM8740_IZD (1<<8) | ||
68 | |||
69 | /** | ||
70 | * Register #4 | ||
71 | */ | ||
72 | #define WM8740_DIFF0 (1<<4) | ||
73 | #define WM8740_DIFF1 (1<<5) | ||
74 | #define WM8740_CDD (1<<6) | ||
75 | |||
76 | void audiohw_mute(void); | ||
77 | void audiohw_unmute(void); | ||
78 | |||
79 | void wm8740_set_ml(const int); | ||
80 | void wm8740_set_mc(const int); | ||
81 | void wm8740_set_md(const int); | ||
82 | |||
83 | #endif | ||
diff --git a/firmware/target/arm/rk27xx/backlight-rk27xx.c b/firmware/target/arm/rk27xx/backlight-rk27xx.c index 1756fcdb29..61e887af46 100644 --- a/firmware/target/arm/rk27xx/backlight-rk27xx.c +++ b/firmware/target/arm/rk27xx/backlight-rk27xx.c | |||
@@ -75,6 +75,13 @@ static const unsigned short lin_brightness[] = { | |||
75 | 759, 768, 778, 788, 800, 812, 826, 841, | 75 | 759, 768, 778, 788, 800, 812, 826, 841, |
76 | 856, 873, 891, 910, 931, 952, 975, 1000 | 76 | 856, 873, 891, 910, 931, 952, 975, 1000 |
77 | }; | 77 | }; |
78 | #elif defined(IHIFI770) || defined(IHIFI770C) || defined(IHIFI800) | ||
79 | static const unsigned short lin_brightness[] = { | ||
80 | 4096, 4215, 4381, 4603, 4887, 5243, 5679, 6201, | ||
81 | 6818, 7538, 8370, 9320, 10397, 11609, 12963, 14469, | ||
82 | 16133, 17963, 19968, 22156, 24534, 27110, 29893, 32890, | ||
83 | 36109, 39559, 43246, 47180, 51368, 55817, 60537, 65535 | ||
84 | }; | ||
78 | #endif | 85 | #endif |
79 | 86 | ||
80 | bool backlight_hw_init(void) | 87 | bool backlight_hw_init(void) |
diff --git a/firmware/target/arm/rk27xx/debug-rk27xx.c b/firmware/target/arm/rk27xx/debug-rk27xx.c index 83bc1a5af6..ea0190049f 100644 --- a/firmware/target/arm/rk27xx/debug-rk27xx.c +++ b/firmware/target/arm/rk27xx/debug-rk27xx.c | |||
@@ -35,6 +35,8 @@ | |||
35 | #elif defined(HM60X) || defined(HM801) || (CONFIG_KEYPAD == MA_PAD) || \ | 35 | #elif defined(HM60X) || defined(HM801) || (CONFIG_KEYPAD == MA_PAD) || \ |
36 | (CONFIG_KEYPAD == IHIFI_PAD) | 36 | (CONFIG_KEYPAD == IHIFI_PAD) |
37 | #define DEBUG_CANCEL BUTTON_LEFT | 37 | #define DEBUG_CANCEL BUTTON_LEFT |
38 | #elif (CONFIG_KEYPAD == IHIFI_770_PAD) || (CONFIG_KEYPAD == IHIFI_800_PAD) | ||
39 | #define DEBUG_CANCEL BUTTON_POWER | ||
38 | #endif | 40 | #endif |
39 | 41 | ||
40 | /* Skeleton for adding target specific debug info to the debug menu | 42 | /* Skeleton for adding target specific debug info to the debug menu |
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 | } | ||
diff --git a/firmware/target/arm/rk27xx/sd-rk27xx.c b/firmware/target/arm/rk27xx/sd-rk27xx.c index 2ddfd0cf0a..e5467058de 100644 --- a/firmware/target/arm/rk27xx/sd-rk27xx.c +++ b/firmware/target/arm/rk27xx/sd-rk27xx.c | |||
@@ -97,7 +97,7 @@ void INT_SD(void) | |||
97 | /* get the status */ | 97 | /* get the status */ |
98 | cmd_error = SD_CMDRES; | 98 | cmd_error = SD_CMDRES; |
99 | semaphore_release(&command_completion_signal); | 99 | semaphore_release(&command_completion_signal); |
100 | } | 100 | } |
101 | 101 | ||
102 | /* data transfer status pending */ | 102 | /* data transfer status pending */ |
103 | if(status & DATA_XFER_STAT) | 103 | if(status & DATA_XFER_STAT) |
@@ -140,13 +140,15 @@ static void mmu_buff_reset(void) | |||
140 | 140 | ||
141 | static inline bool card_detect_target(void) | 141 | static inline bool card_detect_target(void) |
142 | { | 142 | { |
143 | #if defined(RK27_GENERIC) | 143 | #if defined(RK27_GENERIC) || defined(IHIFI770) || defined(IHIFI770C) || defined(IHIFI800) |
144 | /* My generic device uses PC7 pin, active low */ | 144 | /* PC7, active low */ |
145 | return !(GPIO_PCDR & 0x80); | 145 | return !(GPIO_PCDR & 0x80); |
146 | #elif defined(HM60X) || defined(HM801) | 146 | #elif defined(HM60X) || defined(HM801) |
147 | /* PF2, active low */ | ||
147 | return !(GPIO_PFDR & (1<<2)); | 148 | return !(GPIO_PFDR & (1<<2)); |
148 | #elif defined(MA9) || defined(MA9C) || defined(MA8) || defined(MA8C) | 149 | #elif defined(MA9) || defined(MA9C) || defined(MA8) || defined(MA8C) |
149 | return (GPIO_PCDR & 0x80); | 150 | /* PC7, active high */ |
151 | return (GPIO_PCDR & (1<<7)); | ||
150 | #elif defined(IHIFI760) || defined(IHIFI960) | 152 | #elif defined(IHIFI760) || defined(IHIFI960) |
151 | /* TODO: find out pin */ | 153 | /* TODO: find out pin */ |
152 | return true; | 154 | return true; |
@@ -190,7 +192,7 @@ static bool send_cmd(const int cmd, const int arg, const int res, | |||
190 | #if 0 | 192 | #if 0 |
191 | /* for some misterious reason the card does not report itself as being in TRAN | 193 | /* for some misterious reason the card does not report itself as being in TRAN |
192 | * but transfers are successful. Rockchip OF does not check the card state | 194 | * but transfers are successful. Rockchip OF does not check the card state |
193 | * after SELECT. I checked two different cards. | 195 | * after SELECT. I checked two different cards. |
194 | */ | 196 | */ |
195 | static void print_card_status(void) | 197 | static void print_card_status(void) |
196 | { | 198 | { |
@@ -224,7 +226,7 @@ static int sd_wait_for_tran_state(void) | |||
224 | { | 226 | { |
225 | return 0; | 227 | return 0; |
226 | } | 228 | } |
227 | 229 | ||
228 | if(TIME_AFTER(current_tick, timeout)) | 230 | if(TIME_AFTER(current_tick, timeout)) |
229 | { | 231 | { |
230 | return -10 * ((response >> 9) & 0xf); | 232 | return -10 * ((response >> 9) & 0xf); |
@@ -265,7 +267,7 @@ static int sd_init_card(void) | |||
265 | /* CMD0 Go Idle */ | 267 | /* CMD0 Go Idle */ |
266 | if(!send_cmd(SD_GO_IDLE_STATE, 0, RES_NO, NULL)) | 268 | if(!send_cmd(SD_GO_IDLE_STATE, 0, RES_NO, NULL)) |
267 | return -1; | 269 | return -1; |
268 | 270 | ||
269 | sleep(1); | 271 | sleep(1); |
270 | 272 | ||
271 | /* CMD8 Check for v2 sd card. Must be sent before using ACMD41 | 273 | /* CMD8 Check for v2 sd card. Must be sent before using ACMD41 |
@@ -671,7 +673,7 @@ int sd_write_sectors(IF_MD(int drive,) unsigned long start, int count, | |||
671 | #endif | 673 | #endif |
672 | 674 | ||
673 | return ret; | 675 | return ret; |
674 | 676 | ||
675 | #endif /* defined(BOOTLOADER) */ | 677 | #endif /* defined(BOOTLOADER) */ |
676 | } | 678 | } |
677 | 679 | ||
diff --git a/firmware/target/arm/rk27xx/usb-drv-rk27xx.c b/firmware/target/arm/rk27xx/usb-drv-rk27xx.c index badc3ab5ed..057ecf6ebc 100644 --- a/firmware/target/arm/rk27xx/usb-drv-rk27xx.c +++ b/firmware/target/arm/rk27xx/usb-drv-rk27xx.c | |||
@@ -28,37 +28,16 @@ | |||
28 | #include "kernel.h" | 28 | #include "kernel.h" |
29 | #include "panic.h" | 29 | #include "panic.h" |
30 | 30 | ||
31 | //#include "usb-s3c6400x.h" | ||
32 | |||
33 | #include "usb_ch9.h" | 31 | #include "usb_ch9.h" |
34 | #include "usb_core.h" | 32 | #include "usb_core.h" |
35 | #include <inttypes.h> | 33 | #include <inttypes.h> |
36 | #include "power.h" | 34 | #include "power.h" |
37 | 35 | ||
36 | #define LOGF_ENABLE | ||
38 | #include "logf.h" | 37 | #include "logf.h" |
39 | 38 | ||
40 | typedef volatile uint32_t reg32; | 39 | typedef volatile uint32_t reg32; |
41 | 40 | ||
42 | /* Bulk OUT: ep1, ep4, ep7, ep10, ep13 */ | ||
43 | #define BOUT_RXSTAT(ep_num) (*(reg32*)(AHB0_UDC+0x54+0x38*(ep_num/3))) | ||
44 | #define BOUT_RXCON(ep_num) (*(reg32*)(AHB0_UDC+0x58+0x38*(ep_num/3))) | ||
45 | #define BOUT_DMAOUTCTL(ep_num) (*(reg32*)(AHB0_UDC+0x5C+0x38*(ep_num/3))) | ||
46 | #define BOUT_DMAOUTLMADDR(ep_num) (*(reg32*)(AHB0_UDC+0x60+0x38*(ep_num/3))) | ||
47 | |||
48 | /* Bulk IN: ep2, ep5, ep8, ep11, ep4 */ | ||
49 | #define BIN_TXSTAT(ep_num) (*(reg32*)(AHB0_UDC+0x64+0x38*(ep_num/3))) | ||
50 | #define BIN_TXCON(ep_num) (*(reg32*)(AHB0_UDC+0x68+0x38*(ep_num/3))) | ||
51 | #define BIN_TXBUF(ep_num) (*(reg32*)(AHB0_UDC+0x6C+0x38*(ep_num/3))) | ||
52 | #define BIN_DMAINCTL(ep_num) (*(reg32*)(AHB0_UDC+0x70+0x38*(ep_num/3))) | ||
53 | #define BIN_DMAINLMADDR(ep_num) (*(reg32*)(AHB0_UDC+0x74+0x38*(ep_num/3))) | ||
54 | |||
55 | /* INTERRUPT IN: ep3, ep6, ep9, ep12, ep15 */ | ||
56 | #define IIN_TXSTAT(ep_num) (*(reg32*)(AHB0_UDC+0x78+0x38*((ep_num/3)-1))) | ||
57 | #define IIN_TXCON(ep_num) (*(reg32*)(AHB0_UDC+0x7C+0x38*((ep_num/3)-1))) | ||
58 | #define IIN_TXBUF(ep_num) (*(reg32*)(AHB0_UDC+0x80+0x38*((ep_num/3)-1))) | ||
59 | #define IIN_DMAINCTL(ep_num) (*(reg32*)(AHB0_UDC+0x84+0x38*((ep_num/3)-1))) | ||
60 | #define IIN_DMAINLMADDR(ep_num) (*(reg32*)(AHB0_UDC+0x88+0x38*((ep_num/3)-1))) | ||
61 | |||
62 | #ifdef LOGF_ENABLE | 41 | #ifdef LOGF_ENABLE |
63 | #define XFER_DIR_STR(dir) ((dir) ? "IN" : "OUT") | 42 | #define XFER_DIR_STR(dir) ((dir) ? "IN" : "OUT") |
64 | #define XFER_TYPE_STR(type) \ | 43 | #define XFER_TYPE_STR(type) \ |
@@ -68,9 +47,12 @@ typedef volatile uint32_t reg32; | |||
68 | ((type) == USB_ENDPOINT_XFER_INT ? "INTR" : "INVL")))) | 47 | ((type) == USB_ENDPOINT_XFER_INT ? "INTR" : "INVL")))) |
69 | #endif | 48 | #endif |
70 | 49 | ||
71 | struct endpoint_t { | 50 | struct endpoint_t |
51 | { | ||
52 | const int ep_num; /* EP number */ | ||
72 | const int type; /* EP type */ | 53 | const int type; /* EP type */ |
73 | const int dir; /* DIR_IN/DIR_OUT */ | 54 | const int dir; /* DIR_IN/DIR_OUT */ |
55 | volatile unsigned long *stat; /* RXSTAT/TXSTAT register */ | ||
74 | bool allocated; /* flag to mark EPs taken */ | 56 | bool allocated; /* flag to mark EPs taken */ |
75 | volatile void *buf; /* tx/rx buffer address */ | 57 | volatile void *buf; /* tx/rx buffer address */ |
76 | volatile int len; /* size of the transfer (bytes) */ | 58 | volatile int len; /* size of the transfer (bytes) */ |
@@ -79,110 +61,91 @@ struct endpoint_t { | |||
79 | struct semaphore complete; /* semaphore for blocking transfers */ | 61 | struct semaphore complete; /* semaphore for blocking transfers */ |
80 | }; | 62 | }; |
81 | 63 | ||
82 | #define EP_INIT(_type, _dir, _alloced, _buf, _len, _cnt, _block) \ | 64 | /* compute RXCON address from RXSTAT, and so on */ |
83 | { .type = (_type), .dir = (_dir), .allocated = (_alloced), .buf = (_buf), \ | 65 | #define RXSTAT(endp) *((endp)->stat) |
84 | .len = (_len), .cnt = (_cnt), .block = (_block) } | 66 | #define RXCON(endp) *(1 + (endp)->stat) |
85 | 67 | #define DMAOUTCTL(endp) *(2 + (endp)->stat) | |
86 | static struct endpoint_t ctrlep[2] = { | 68 | #define DMAOUTLMADDR(endp) *(3 + (endp)->stat) |
87 | EP_INIT(USB_ENDPOINT_XFER_CONTROL, DIR_OUT, true, NULL, 0, 0, true), | 69 | /* compute TXCON address from TXSTAT, and so on */ |
88 | EP_INIT(USB_ENDPOINT_XFER_CONTROL, DIR_IN, true, NULL, 0, 0, true), | 70 | #define TXSTAT(endp) *((endp)->stat) |
71 | #define TXCON(endp) *(1 + (endp)->stat) | ||
72 | #define TXBUF(endp) *(2 + (endp)->stat) | ||
73 | #define DMAINCTL(endp) *(3 + (endp)->stat) | ||
74 | #define DMAINLMADDR(endp) *(4 + (endp)->stat) | ||
75 | |||
76 | #define ENDPOINT(num, type, dir, reg) \ | ||
77 | {num, USB_ENDPOINT_XFER_##type, USB_DIR_##dir, reg, false, NULL, 0, 0, true, {{0, 0}, 0, 0}} | ||
78 | |||
79 | static struct endpoint_t ctrlep[2] = | ||
80 | { | ||
81 | ENDPOINT(0, CONTROL, OUT, &RX0STAT), | ||
82 | ENDPOINT(0, CONTROL, IN, &TX0STAT), | ||
89 | }; | 83 | }; |
90 | 84 | ||
91 | static struct endpoint_t endpoints[16] = { | 85 | static struct endpoint_t endpoints[16] = |
92 | EP_INIT(USB_ENDPOINT_XFER_CONTROL, 3, true, NULL, 0, 0, true ), /* stub */ | 86 | { |
93 | EP_INIT(USB_ENDPOINT_XFER_BULK, DIR_OUT, false, NULL, 0, 0, false ), /* BOUT1 */ | 87 | ENDPOINT(0, CONTROL, OUT, NULL), /* stub */ |
94 | EP_INIT(USB_ENDPOINT_XFER_BULK, DIR_IN, false, NULL, 0, 0, false ), /* BIN2 */ | 88 | ENDPOINT(1, BULK, OUT, &RX1STAT), /* BOUT1 */ |
95 | EP_INIT(USB_ENDPOINT_XFER_INT, DIR_IN, false, NULL, 0, 0, false ), /* IIN3 */ | 89 | ENDPOINT(2, BULK, IN, &TX2STAT), /* BIN2 */ |
96 | EP_INIT(USB_ENDPOINT_XFER_BULK, DIR_OUT, false, NULL, 0, 0, false ), /* BOUT4 */ | 90 | ENDPOINT(3, INT, IN, &TX3STAT), /* IIN3 */ |
97 | EP_INIT(USB_ENDPOINT_XFER_BULK, DIR_IN, false, NULL, 0, 0, false ), /* BIN5 */ | 91 | ENDPOINT(4, BULK, OUT, &RX4STAT), /* BOUT4 */ |
98 | EP_INIT(USB_ENDPOINT_XFER_INT, DIR_IN, false, NULL, 0, 0, false ), /* IIN6 */ | 92 | ENDPOINT(5, BULK, IN, &TX5STAT), /* BIN5 */ |
99 | EP_INIT(USB_ENDPOINT_XFER_BULK, DIR_OUT, false, NULL, 0, 0, false ), /* BOUT7 */ | 93 | ENDPOINT(6, INT, IN, &TX6STAT), /* IIN6 */ |
100 | EP_INIT(USB_ENDPOINT_XFER_BULK, DIR_IN, false, NULL, 0, 0, false ), /* BIN8 */ | 94 | ENDPOINT(7, BULK, OUT, &RX7STAT), /* BOUT7 */ |
101 | EP_INIT(USB_ENDPOINT_XFER_INT, DIR_IN, false, NULL, 0, 0, false ), /* IIN9 */ | 95 | ENDPOINT(8, BULK, IN, &TX8STAT), /* BIN8 */ |
102 | EP_INIT(USB_ENDPOINT_XFER_BULK, DIR_OUT, false, NULL, 0, 0, false ), /* BOUT10 */ | 96 | ENDPOINT(9, INT, IN, &TX9STAT), /* IIN9 */ |
103 | EP_INIT(USB_ENDPOINT_XFER_BULK, DIR_IN, false, NULL, 0, 0, false ), /* BIN11 */ | 97 | ENDPOINT(10, BULK, OUT, &RX10STAT), /* BOUT10 */ |
104 | EP_INIT(USB_ENDPOINT_XFER_INT, DIR_IN, false, NULL, 0, 0, false ), /* IIN12 */ | 98 | ENDPOINT(11, BULK, IN, &TX11STAT), /* BIN11 */ |
105 | EP_INIT(USB_ENDPOINT_XFER_BULK, DIR_OUT, false, NULL, 0, 0, false ), /* BOUT13 */ | 99 | ENDPOINT(12, INT, IN, &TX12STAT), /* IIN12 */ |
106 | EP_INIT(USB_ENDPOINT_XFER_BULK, DIR_IN, false, NULL, 0, 0, false ), /* BIN14 */ | 100 | ENDPOINT(13, BULK, OUT, &RX13STAT), /* BOUT13 */ |
107 | EP_INIT(USB_ENDPOINT_XFER_INT, DIR_IN, false, NULL, 0, 0, false ), /* IIN15 */ | 101 | ENDPOINT(14, BULK, IN, &TX14STAT), /* BIN14 */ |
102 | ENDPOINT(15, INT, IN, &TX15STAT), /* IIN15 */ | ||
108 | }; | 103 | }; |
109 | 104 | ||
105 | static volatile bool set_address = false; | ||
106 | static volatile bool set_configuration = false; | ||
107 | |||
108 | #undef ENDPOINT | ||
109 | |||
110 | static void setup_received(void) | 110 | static void setup_received(void) |
111 | { | 111 | { |
112 | static uint32_t setup_data[2]; | 112 | static uint32_t setup_data[2]; |
113 | 113 | logf("udc: setup"); | |
114 | |||
114 | /* copy setup data from packet */ | 115 | /* copy setup data from packet */ |
115 | setup_data[0] = SETUP1; | 116 | setup_data[0] = SETUP1; |
116 | setup_data[1] = SETUP2; | 117 | setup_data[1] = SETUP2; |
117 | 118 | ||
118 | /* clear all pending control transfers | ||
119 | * do we need this here? | ||
120 | */ | ||
121 | |||
122 | /* pass setup data to the upper layer */ | 119 | /* pass setup data to the upper layer */ |
123 | usb_core_control_request((struct usb_ctrlrequest*)setup_data); | 120 | usb_core_control_request((struct usb_ctrlrequest*)setup_data); |
124 | } | 121 | } |
125 | 122 | ||
126 | /* service ep0 IN transaction */ | 123 | static int max_pkt_size(struct endpoint_t *endp) |
127 | static void ctr_write(void) | ||
128 | { | 124 | { |
129 | int xfer_size = (ctrlep[DIR_IN].cnt > 64) ? 64 : ctrlep[DIR_IN].cnt; | 125 | switch(endp->type) |
130 | unsigned int timeout = current_tick + HZ/10; | ||
131 | |||
132 | while (TX0BUF & TXFULL) /* TX0FULL flag */ | ||
133 | { | 126 | { |
134 | if(TIME_AFTER(current_tick, timeout)) | 127 | case USB_ENDPOINT_XFER_CONTROL: return 64; |
135 | break; | 128 | case USB_ENDPOINT_XFER_BULK: return usb_drv_port_speed() ? 512 : 64; |
129 | case USB_ENDPOINT_XFER_INT: return usb_drv_port_speed() ? 1024 : 64; | ||
130 | default: panicf("die"); return 0; | ||
136 | } | 131 | } |
137 | |||
138 | TX0STAT = xfer_size; /* size of the transfer */ | ||
139 | TX0DMALM_IADDR = (uint32_t)ctrlep[DIR_IN].buf; /* local buffer address */ | ||
140 | TX0DMAINCTL = DMA_START; /* start DMA */ | ||
141 | TX0CON &= ~TXNAK; /* clear NAK */ | ||
142 | |||
143 | /* Decrement by max packet size is intentional. | ||
144 | * This way if we have final packet short one we will get negative len | ||
145 | * after transfer, which in turn indicates we *don't* need to send | ||
146 | * zero length packet. If the final packet is max sized packet we will | ||
147 | * get zero len after transfer which indicates we need to send | ||
148 | * zero length packet to signal host end of the transfer. | ||
149 | */ | ||
150 | ctrlep[DIR_IN].cnt -= 64; | ||
151 | ctrlep[DIR_IN].buf += xfer_size; | ||
152 | } | ||
153 | |||
154 | static void ctr_read(void) | ||
155 | { | ||
156 | int xfer_size = RX0STAT & 0xffff; | ||
157 | |||
158 | /* clear NAK bit */ | ||
159 | RX0CON &= ~RXNAK; | ||
160 | |||
161 | ctrlep[DIR_OUT].cnt -= xfer_size; | ||
162 | ctrlep[DIR_OUT].buf += xfer_size; | ||
163 | |||
164 | RX0DMAOUTLMADDR = (uint32_t)ctrlep[DIR_OUT].buf; /* buffer address */ | ||
165 | RX0DMACTLO = DMA_START; /* start DMA */ | ||
166 | } | 132 | } |
167 | 133 | ||
168 | static void blk_write(int ep) | 134 | static void ep_write(struct endpoint_t *endp) |
169 | { | 135 | { |
170 | int ep_num = EP_NUM(ep); | 136 | int xfer_size = MIN(max_pkt_size(endp), endp->cnt); |
171 | int max = usb_drv_port_speed() ? 512 : 64; | ||
172 | int xfer_size = (endpoints[ep_num].cnt > max) ? max : endpoints[ep_num].cnt; | ||
173 | unsigned int timeout = current_tick + HZ/10; | 137 | unsigned int timeout = current_tick + HZ/10; |
174 | 138 | ||
175 | while (BIN_TXBUF(ep_num) & TXFULL) /* TXFULL flag */ | 139 | while(TXBUF(endp) & TXFULL) /* TXFULL flag */ |
176 | { | 140 | { |
177 | if(TIME_AFTER(current_tick, timeout)) | 141 | if(TIME_AFTER(current_tick, timeout)) |
178 | break; | 142 | break; |
179 | } | 143 | } |
180 | 144 | ||
181 | BIN_TXSTAT(ep_num) = xfer_size; /* size */ | 145 | /* setup transfer size and DMA */ |
182 | BIN_DMAINLMADDR(ep_num) = (uint32_t)endpoints[ep_num].buf; /* buf address */ | 146 | TXSTAT(endp) = xfer_size; |
183 | BIN_DMAINCTL(ep_num) = DMA_START; /* start DMA */ | 147 | DMAINLMADDR(endp) = (uint32_t)endp->buf; /* local buffer address */ |
184 | BIN_TXCON(ep_num) &= ~TXNAK; /* clear NAK */ | 148 | DMAINCTL(endp) = DMA_START; |
185 | |||
186 | /* Decrement by max packet size is intentional. | 149 | /* Decrement by max packet size is intentional. |
187 | * This way if we have final packet short one we will get negative len | 150 | * This way if we have final packet short one we will get negative len |
188 | * after transfer, which in turn indicates we *don't* need to send | 151 | * after transfer, which in turn indicates we *don't* need to send |
@@ -190,247 +153,141 @@ static void blk_write(int ep) | |||
190 | * get zero len after transfer which indicates we need to send | 153 | * get zero len after transfer which indicates we need to send |
191 | * zero length packet to signal host end of the transfer. | 154 | * zero length packet to signal host end of the transfer. |
192 | */ | 155 | */ |
193 | endpoints[ep_num].cnt -= max; | 156 | endp->cnt -= max_pkt_size(endp); |
194 | endpoints[ep_num].buf += xfer_size; | 157 | endp->buf += xfer_size; |
158 | /* clear NAK */ | ||
159 | TXCON(endp) &= ~TXNAK; | ||
195 | } | 160 | } |
196 | 161 | ||
197 | static void blk_read(int ep) | 162 | static void ep_read(struct endpoint_t *endp) |
198 | { | 163 | { |
199 | int ep_num = EP_NUM(ep); | 164 | /* setup DMA */ |
200 | int xfer_size = BOUT_RXSTAT(ep_num) & 0xffff; | 165 | DMAOUTLMADDR(endp) = (uint32_t)endp->buf; /* local buffer address */ |
201 | 166 | DMAOUTCTL(endp) = DMA_START; | |
202 | /* clear NAK bit */ | 167 | /* clear NAK */ |
203 | BOUT_RXCON(ep_num) &= ~RXNAK; | 168 | RXCON(endp) &= ~RXNAK; |
204 | |||
205 | endpoints[ep_num].cnt -= xfer_size; | ||
206 | endpoints[ep_num].buf += xfer_size; | ||
207 | |||
208 | BOUT_DMAOUTLMADDR(ep_num) = (uint32_t)endpoints[ep_num].buf; | ||
209 | BOUT_DMAOUTCTL(ep_num) = DMA_START; | ||
210 | } | ||
211 | |||
212 | static void int_write(int ep) | ||
213 | { | ||
214 | int ep_num = EP_NUM(ep); | ||
215 | int max = usb_drv_port_speed() ? 1024 : 64; | ||
216 | int xfer_size = (endpoints[ep_num].cnt > max) ? max : endpoints[ep_num].cnt; | ||
217 | unsigned int timeout = current_tick + HZ/10; | ||
218 | |||
219 | while (IIN_TXBUF(ep_num) & TXFULL) /* TXFULL flag */ | ||
220 | { | ||
221 | if(TIME_AFTER(current_tick, timeout)) | ||
222 | break; | ||
223 | } | ||
224 | |||
225 | IIN_TXSTAT(ep_num) = xfer_size; /* size */ | ||
226 | IIN_DMAINLMADDR(ep_num) = (uint32_t)endpoints[ep_num].buf; /* buf address */ | ||
227 | IIN_DMAINCTL(ep_num) = DMA_START; /* start DMA */ | ||
228 | IIN_TXCON(ep_num) &= ~TXNAK; /* clear NAK */ | ||
229 | |||
230 | /* Decrement by max packet size is intentional. | ||
231 | * This way if we have final packet short one we will get negative len | ||
232 | * after transfer, which in turn indicates we *don't* need to send | ||
233 | * zero length packet. If the final packet is max sized packet we will | ||
234 | * get zero len after transfer which indicates we need to send | ||
235 | * zero length packet to signal host end of the transfer. | ||
236 | */ | ||
237 | endpoints[ep_num].cnt -= max; | ||
238 | endpoints[ep_num].buf += xfer_size; | ||
239 | } | 169 | } |
240 | 170 | ||
241 | /* UDC ISR function */ | 171 | static void in_intr(struct endpoint_t *endp) |
242 | void INT_UDC(void) | ||
243 | { | 172 | { |
244 | uint32_t txstat, rxstat; | 173 | uint32_t txstat = TXSTAT(endp); |
245 | int tmp, ep_num; | 174 | /* check if clear feature was sent by host */ |
246 | 175 | if(txstat & TXCFINT) | |
247 | /* read what caused UDC irq */ | ||
248 | uint32_t intsrc = INT2FLAG & 0x7fffff; | ||
249 | |||
250 | if (intsrc & SETUP_INTR) /* setup interrupt */ | ||
251 | { | 176 | { |
252 | setup_received(); | 177 | logf("clear_stall: %d", endp->ep_num); |
178 | usb_drv_stall(endp->ep_num, false, true); | ||
253 | } | 179 | } |
254 | else if (intsrc & IN0_INTR) /* ep0 in interrupt */ | 180 | /* check if a transfer has finished */ |
181 | if(txstat & TXACK) | ||
255 | { | 182 | { |
256 | txstat = TX0STAT; /* read clears flags */ | 183 | logf("udc: ack(%d)", endp->ep_num); |
257 | 184 | /* finished ? */ | |
258 | /* TODO handle errors */ | 185 | if(endp->cnt <= 0) |
259 | if (txstat & TXACK) /* check TxACK flag */ | ||
260 | { | 186 | { |
261 | if (ctrlep[DIR_IN].cnt >= 0) | 187 | usb_core_transfer_complete(endp->ep_num, endp->dir, 0, endp->len); |
262 | { | 188 | /* release semaphore for blocking transfer */ |
263 | /* we still have data to send (or ZLP) */ | 189 | if(endp->block) |
264 | ctr_write(); | 190 | semaphore_release(&endp->complete); |
265 | } | ||
266 | else | ||
267 | { | ||
268 | /* final ack received */ | ||
269 | usb_core_transfer_complete(0, /* ep */ | ||
270 | USB_DIR_IN, /* dir */ | ||
271 | 0, /* status */ | ||
272 | ctrlep[DIR_IN].len); /* length */ | ||
273 | |||
274 | /* release semaphore for blocking transfer */ | ||
275 | if (ctrlep[DIR_IN].block) | ||
276 | semaphore_release(&ctrlep[DIR_IN].complete); | ||
277 | } | ||
278 | } | 191 | } |
192 | else /* more data to send */ | ||
193 | ep_write(endp); | ||
279 | } | 194 | } |
280 | else if (intsrc & OUT0_INTR) /* ep0 out interrupt */ | 195 | } |
281 | { | ||
282 | rxstat = RX0STAT; | ||
283 | 196 | ||
284 | /* TODO handle errors */ | 197 | static void out_intr(struct endpoint_t *endp) |
285 | if (rxstat & RXACK) /* RxACK */ | 198 | { |
286 | { | 199 | uint32_t rxstat = RXSTAT(endp); |
287 | if (ctrlep[DIR_OUT].cnt > 0) | 200 | logf("udc: out intr(%d)", endp->ep_num); |
288 | ctr_read(); | 201 | /* check if clear feature was sent by host */ |
289 | else | 202 | if(rxstat & RXCFINT) |
290 | usb_core_transfer_complete(0, /* ep */ | ||
291 | USB_DIR_OUT, /* dir */ | ||
292 | 0, /* status */ | ||
293 | ctrlep[DIR_OUT].len); /* length */ | ||
294 | } | ||
295 | } | ||
296 | else if (intsrc & USBRST_INTR) /* usb reset */ | ||
297 | { | ||
298 | usb_drv_init(); | ||
299 | } | ||
300 | else if (intsrc & RESUME_INTR) /* usb resume */ | ||
301 | { | ||
302 | TX0CON |= TXCLR; /* TxClr */ | ||
303 | TX0CON &= ~TXCLR; | ||
304 | RX0CON |= RXCLR; /* RxClr */ | ||
305 | RX0CON &= ~RXCLR; | ||
306 | } | ||
307 | else if (intsrc & SUSP_INTR) /* usb suspend */ | ||
308 | { | 203 | { |
204 | logf("clear_stall: %d", endp->ep_num); | ||
205 | usb_drv_stall(endp->ep_num, false, false); | ||
309 | } | 206 | } |
310 | else if (intsrc & CONN_INTR) /* usb connect */ | 207 | /* check if a transfer has finished */ |
208 | if(rxstat & RXACK) | ||
311 | { | 209 | { |
210 | int xfer_size = rxstat & 0xffff; | ||
211 | endp->cnt -= xfer_size; | ||
212 | endp->buf += xfer_size; | ||
213 | logf("udc: ack(%d) -> %d/%d", endp->ep_num, xfer_size, endp->cnt); | ||
214 | /* finished ? */ | ||
215 | if(endp->cnt <= 0 || xfer_size < max_pkt_size(endp)) | ||
216 | usb_core_transfer_complete(endp->ep_num, endp->dir, 0, endp->len); | ||
217 | else | ||
218 | ep_read(endp); | ||
312 | } | 219 | } |
313 | else | 220 | } |
314 | { | 221 | |
315 | /* lets figure out which ep generated irq */ | 222 | static void udc_phy_reset(void) |
316 | tmp = intsrc >> 7; | 223 | { |
317 | for (ep_num=1; ep_num < 15; ep_num++) | 224 | DEV_CTL |= SOFT_POR; |
318 | { | 225 | udelay(10000); /* min 10ms */ |
319 | tmp >>= ep_num; | 226 | DEV_CTL &= ~SOFT_POR; |
320 | if (tmp & 0x01) | 227 | } |
321 | break; | 228 | |
322 | } | 229 | static void udc_soft_connect(void) |
323 | 230 | { | |
324 | if (intsrc & ((1<<8)|(1<<11)|(1<<14)|(1<<17)|(1<<20))) | 231 | DEV_CTL |= CSR_DONE | |
325 | { | 232 | DEV_SOFT_CN | |
326 | /* bulk out */ | 233 | DEV_SELF_PWR; |
327 | rxstat = BOUT_RXSTAT(ep_num); | 234 | } |
328 | 235 | ||
329 | /* TODO handle errors */ | 236 | static void udc_helper(void) |
330 | if (rxstat & (1<<18)) /* RxACK */ | 237 | { |
331 | { | 238 | uint32_t dev_info = DEV_INFO; |
332 | if (endpoints[ep_num].cnt > 0) | 239 | |
333 | blk_read(ep_num); | 240 | /* This polls for DEV_EN bit set in DEV_INFO register |
334 | else | 241 | * as well as tracks current requested configuration |
335 | usb_core_transfer_complete(ep_num, /* ep */ | 242 | * (DEV_INFO [11:8]). On state change it notifies usb stack |
336 | USB_DIR_OUT, /* dir */ | 243 | * about it. |
337 | 0, /* status */ | 244 | */ |
338 | endpoints[ep_num].len); /* length */ | 245 | |
339 | } | 246 | /* SET ADDRESS request */ |
340 | } | 247 | if(!set_address) |
341 | else if (intsrc & ((1<<9)|(1<<12)|(1<<15)|(1<<18)|(1<<21))) | 248 | if(dev_info & 0x7f) |
342 | { | 249 | { |
343 | /* bulk in */ | 250 | set_address = true; |
344 | txstat = BIN_TXSTAT(ep_num); | 251 | usb_core_notify_set_address(dev_info & 0x7f); |
345 | |||
346 | /* TODO handle errors */ | ||
347 | if (txstat & (1<<18)) /* check TxACK flag */ | ||
348 | { | ||
349 | if (endpoints[ep_num].cnt >= 0) | ||
350 | { | ||
351 | /* we still have data to send (or ZLP) */ | ||
352 | blk_write(ep_num); | ||
353 | } | ||
354 | else | ||
355 | { | ||
356 | /* final ack received */ | ||
357 | usb_core_transfer_complete(ep_num, /* ep */ | ||
358 | USB_DIR_IN, /* dir */ | ||
359 | 0, /* status */ | ||
360 | endpoints[ep_num].len); /* length */ | ||
361 | |||
362 | /* release semaphore for blocking transfer */ | ||
363 | if (endpoints[ep_num].block) | ||
364 | semaphore_release(&endpoints[ep_num].complete); | ||
365 | } | ||
366 | } | ||
367 | } | 252 | } |
368 | else if (intsrc & ((1<<10)|(1<13)|(1<<16)|(1<<19)|(1<<22))) | 253 | |
254 | /* SET CONFIGURATION request */ | ||
255 | if(!set_configuration) | ||
256 | if(dev_info & DEV_EN) | ||
369 | { | 257 | { |
370 | /* int in */ | 258 | set_configuration = true; |
371 | txstat = IIN_TXSTAT(ep_num); | 259 | usb_core_notify_set_config(((dev_info >> 7) & 0xf) + 1); |
372 | |||
373 | /* TODO handle errors */ | ||
374 | if (txstat & TXACK) /* check TxACK flag */ | ||
375 | { | ||
376 | if (endpoints[ep_num].cnt >= 0) | ||
377 | { | ||
378 | /* we still have data to send (or ZLP) */ | ||
379 | int_write(ep_num); | ||
380 | } | ||
381 | else | ||
382 | { | ||
383 | /* final ack received */ | ||
384 | usb_core_transfer_complete(ep_num, /* ep */ | ||
385 | USB_DIR_IN, /* dir */ | ||
386 | 0, /* status */ | ||
387 | endpoints[ep_num].len); /* length */ | ||
388 | |||
389 | /* release semaphore for blocking transfer */ | ||
390 | if (endpoints[ep_num].block) | ||
391 | semaphore_release(&endpoints[ep_num].complete); | ||
392 | } | ||
393 | } | ||
394 | } | 260 | } |
395 | } | ||
396 | } | 261 | } |
397 | 262 | ||
398 | /* return port speed FS=0, HS=1 */ | 263 | /* return port speed FS=0, HS=1 */ |
399 | int usb_drv_port_speed(void) | 264 | int usb_drv_port_speed(void) |
400 | { | 265 | { |
401 | return ((DEV_INFO & DEV_SPEED) == 0) ? 0 : 1; | 266 | return (DEV_INFO & DEV_SPEED) ? 0 : 1; |
402 | } | 267 | } |
403 | 268 | ||
404 | /* Reserve endpoint */ | 269 | /* Reserve endpoint */ |
405 | int usb_drv_request_endpoint(int type, int dir) | 270 | int usb_drv_request_endpoint(int type, int dir) |
406 | { | 271 | { |
407 | int ep_num, ep_dir; | 272 | logf("req: %s %s", XFER_DIR_STR(dir), XFER_TYPE_STR(type)); |
408 | int ep_type; | ||
409 | |||
410 | /* Safety */ | ||
411 | ep_dir = EP_DIR(dir); | ||
412 | ep_type = type & USB_ENDPOINT_XFERTYPE_MASK; | ||
413 | 273 | ||
414 | logf("req: %s %s", XFER_DIR_STR(ep_dir), XFER_TYPE_STR(ep_type)); | ||
415 | |||
416 | /* Find an available ep/dir pair */ | 274 | /* Find an available ep/dir pair */ |
417 | for (ep_num=1;ep_num<USB_NUM_ENDPOINTS;ep_num++) | 275 | for(int ep_num = 1; ep_num<USB_NUM_ENDPOINTS;ep_num++) |
418 | { | 276 | { |
419 | struct endpoint_t* endpoint = &endpoints[ep_num]; | 277 | struct endpoint_t *endp = &endpoints[ep_num]; |
420 | 278 | ||
421 | if (endpoint->type == ep_type && | 279 | if(endp->allocated || endp->type != type || endp->dir != dir) |
422 | endpoint->dir == ep_dir && | 280 | continue; |
423 | !endpoint->allocated) | 281 | /* allocate endpoint and enable interrupt */ |
424 | { | 282 | endp->allocated = true; |
425 | /* mark endpoint as taken */ | 283 | if(dir == USB_DIR_IN) |
426 | endpoint->allocated = true; | 284 | TXCON(endp) = (ep_num << 8) | TXEPEN | TXNAK | TXACKINTEN | TXCFINTE; |
427 | 285 | else | |
428 | /* enable interrupt from this endpoint */ | 286 | RXCON(endp) = (ep_num << 8) | RXEPEN | RXNAK | RXACKINTEN | RXCFINTE | RXERRINTEN; |
429 | EN_INT |= (1<<(ep_num+7)); | 287 | EN_INT |= 1 << (ep_num + 7); |
430 | 288 | ||
431 | logf("add: ep%d %s", ep_num, XFER_DIR_STR(ep_dir)); | 289 | logf("add: ep%d %s", ep_num, XFER_DIR_STR(dir)); |
432 | return (ep_num | (dir & USB_ENDPOINT_DIR_MASK)); | 290 | return ep_num | dir; |
433 | } | ||
434 | } | 291 | } |
435 | return -1; | 292 | return -1; |
436 | } | 293 | } |
@@ -439,14 +296,12 @@ int usb_drv_request_endpoint(int type, int dir) | |||
439 | void usb_drv_release_endpoint(int ep) | 296 | void usb_drv_release_endpoint(int ep) |
440 | { | 297 | { |
441 | int ep_num = EP_NUM(ep); | 298 | int ep_num = EP_NUM(ep); |
442 | int ep_dir = EP_DIR(ep); | ||
443 | (void) ep_dir; | ||
444 | 299 | ||
445 | logf("rel: ep%d %s", ep_num, XFER_DIR_STR(ep_dir)); | 300 | logf("rel: ep%d", ep_num); |
446 | endpoints[ep_num].allocated = false; | 301 | endpoints[ep_num].allocated = false; |
447 | 302 | ||
448 | /* disable interrupt from this endpoint */ | 303 | /* disable interrupt from this endpoint */ |
449 | EN_INT &= ~(1<<(ep_num+7)); | 304 | EN_INT &= ~(1 << (ep_num + 7)); |
450 | } | 305 | } |
451 | 306 | ||
452 | /* Set the address (usually it's in a register). | 307 | /* Set the address (usually it's in a register). |
@@ -463,39 +318,25 @@ void usb_drv_set_address(int address) | |||
463 | 318 | ||
464 | static int _usb_drv_send(int endpoint, void *ptr, int length, bool block) | 319 | static int _usb_drv_send(int endpoint, void *ptr, int length, bool block) |
465 | { | 320 | { |
321 | logf("udc: send(%x)", endpoint); | ||
466 | struct endpoint_t *ep; | 322 | struct endpoint_t *ep; |
467 | int ep_num = EP_NUM(endpoint); | 323 | int ep_num = EP_NUM(endpoint); |
468 | 324 | ||
469 | if (ep_num == 0) | 325 | if (ep_num == 0) |
470 | ep = &ctrlep[DIR_IN]; | 326 | ep = &ctrlep[DIR_IN]; |
471 | else | 327 | else |
472 | ep = &endpoints[ep_num]; | 328 | ep = &endpoints[ep_num]; |
473 | 329 | ||
330 | /* for send transfers, make sure the data is committed */ | ||
331 | commit_discard_dcache_range(ptr, length); | ||
474 | ep->buf = ptr; | 332 | ep->buf = ptr; |
475 | ep->len = ep->cnt = length; | 333 | ep->len = ep->cnt = length; |
476 | 334 | ep->block = block; | |
477 | if (block) | 335 | |
478 | ep->block = true; | 336 | ep_write(ep); |
479 | else | 337 | |
480 | ep->block = false; | 338 | /* wait for transfer to end */ |
481 | 339 | if(block) | |
482 | switch (ep->type) | ||
483 | { | ||
484 | case USB_ENDPOINT_XFER_CONTROL: | ||
485 | ctr_write(); | ||
486 | break; | ||
487 | |||
488 | case USB_ENDPOINT_XFER_BULK: | ||
489 | blk_write(ep_num); | ||
490 | break; | ||
491 | |||
492 | case USB_ENDPOINT_XFER_INT: | ||
493 | int_write(ep_num); | ||
494 | break; | ||
495 | } | ||
496 | |||
497 | if (block) | ||
498 | /* wait for transfer to end */ | ||
499 | semaphore_wait(&ep->complete, TIMEOUT_BLOCK); | 340 | semaphore_wait(&ep->complete, TIMEOUT_BLOCK); |
500 | 341 | ||
501 | return 0; | 342 | return 0; |
@@ -516,28 +357,20 @@ int usb_drv_send_nonblocking(int endpoint, void *ptr, int length) | |||
516 | /* Setup a receive transfer. (non blocking) */ | 357 | /* Setup a receive transfer. (non blocking) */ |
517 | int usb_drv_recv(int endpoint, void* ptr, int length) | 358 | int usb_drv_recv(int endpoint, void* ptr, int length) |
518 | { | 359 | { |
360 | logf("udc: recv(%x)", endpoint); | ||
519 | struct endpoint_t *ep; | 361 | struct endpoint_t *ep; |
520 | int ep_num = EP_NUM(endpoint); | 362 | int ep_num = EP_NUM(endpoint); |
521 | 363 | ||
522 | if (ep_num == 0) | 364 | if(ep_num == 0) |
523 | { | ||
524 | ep = &ctrlep[DIR_OUT]; | 365 | ep = &ctrlep[DIR_OUT]; |
525 | |||
526 | ctr_read(); | ||
527 | } | ||
528 | else | 366 | else |
529 | { | ||
530 | ep = &endpoints[ep_num]; | 367 | ep = &endpoints[ep_num]; |
531 | 368 | ||
532 | /* clear NAK bit */ | 369 | /* for recv, discard the cache lines related to the buffer */ |
533 | BOUT_RXCON(ep_num) &= ~RXNAK; | 370 | commit_discard_dcache_range(ptr, length); |
534 | BOUT_DMAOUTLMADDR(ep_num) = (uint32_t)ptr; | ||
535 | BOUT_DMAOUTCTL(ep_num) = DMA_START; | ||
536 | } | ||
537 | |||
538 | ep->buf = ptr; | 371 | ep->buf = ptr; |
539 | ep->len = ep->cnt = length; | 372 | ep->len = ep->cnt = length; |
540 | 373 | ep_read(ep); | |
541 | return 0; | 374 | return 0; |
542 | } | 375 | } |
543 | 376 | ||
@@ -560,173 +393,54 @@ void usb_drv_set_test_mode(int mode) | |||
560 | /* Check if endpoint is in stall state */ | 393 | /* Check if endpoint is in stall state */ |
561 | bool usb_drv_stalled(int endpoint, bool in) | 394 | bool usb_drv_stalled(int endpoint, bool in) |
562 | { | 395 | { |
563 | int ep_num = EP_NUM(endpoint); | 396 | struct endpoint_t *endp = &endpoints[EP_NUM(endpoint)]; |
564 | |||
565 | switch (endpoints[ep_num].type) | ||
566 | { | ||
567 | case USB_ENDPOINT_XFER_CONTROL: | ||
568 | if (in) | ||
569 | return (TX0CON & TXSTALL) ? true : false; | ||
570 | else | ||
571 | return (RX0CON & RXSTALL) ? true : false; | ||
572 | |||
573 | break; | ||
574 | 397 | ||
575 | case USB_ENDPOINT_XFER_BULK: | 398 | if(in) |
576 | if (in) | 399 | return !!(TXCON(endp) & TXSTALL); |
577 | return (BIN_TXCON(ep_num) & TXSTALL) ? true : false; | 400 | else |
578 | else | 401 | return !!(RXCON(endp) & RXSTALL); |
579 | return (BOUT_RXCON(ep_num) & RXSTALL) ? true : false; | ||
580 | |||
581 | break; | ||
582 | |||
583 | case USB_ENDPOINT_XFER_INT: | ||
584 | if (in) | ||
585 | return (IIN_TXCON(ep_num) & TXSTALL) ? true : false; | ||
586 | else | ||
587 | return false; /* we don't have such endpoint anyway */ | ||
588 | |||
589 | break; | ||
590 | } | ||
591 | |||
592 | return false; | ||
593 | } | 402 | } |
594 | 403 | ||
595 | /* Stall the endpoint. Usually set a flag in the controller */ | 404 | /* Stall the endpoint. Usually set a flag in the controller */ |
596 | void usb_drv_stall(int endpoint, bool stall, bool in) | 405 | void usb_drv_stall(int endpoint, bool stall, bool in) |
597 | { | 406 | { |
598 | int ep_num = EP_NUM(endpoint); | 407 | struct endpoint_t *endp = &endpoints[EP_NUM(endpoint)]; |
599 | 408 | if(in) | |
600 | switch (endpoints[ep_num].type) | ||
601 | { | 409 | { |
602 | case USB_ENDPOINT_XFER_CONTROL: | 410 | if(stall) |
603 | if (in) | 411 | TXCON(endp) |= TXSTALL; |
604 | { | 412 | else |
605 | if (stall) | 413 | TXCON(endp) &= ~TXSTALL; |
606 | TX0CON |= TXSTALL; | 414 | } |
607 | else | 415 | else |
608 | TX0CON &= ~TXSTALL; | 416 | { |
609 | } | 417 | if(stall) |
610 | else | 418 | RXCON(endp) |= RXSTALL; |
611 | { | 419 | else |
612 | if (stall) | 420 | RXCON(endp) &= ~RXSTALL; |
613 | RX0CON |= RXSTALL; | ||
614 | else | ||
615 | RX0CON &= ~RXSTALL; /* doc says Auto clear by UDC 2.0 */ | ||
616 | } | ||
617 | break; | ||
618 | |||
619 | case USB_ENDPOINT_XFER_BULK: | ||
620 | if (in) | ||
621 | { | ||
622 | if (stall) | ||
623 | BIN_TXCON(ep_num) |= TXSTALL; | ||
624 | else | ||
625 | BIN_TXCON(ep_num) &= ~TXSTALL; | ||
626 | } | ||
627 | else | ||
628 | { | ||
629 | if (stall) | ||
630 | BOUT_RXCON(ep_num) |= RXSTALL; | ||
631 | else | ||
632 | BOUT_RXCON(ep_num) &= ~RXSTALL; | ||
633 | } | ||
634 | break; | ||
635 | |||
636 | case USB_ENDPOINT_XFER_INT: | ||
637 | if (in) | ||
638 | { | ||
639 | if (stall) | ||
640 | IIN_TXCON(ep_num) |= TXSTALL; | ||
641 | else | ||
642 | IIN_TXCON(ep_num) &= ~TXSTALL; | ||
643 | } | ||
644 | break; | ||
645 | } | 421 | } |
646 | } | 422 | } |
647 | 423 | ||
648 | /* one time init (once per connection) - basicaly enable usb core */ | 424 | /* one time init (once per connection) - basicaly enable usb core */ |
649 | void usb_drv_init(void) | 425 | void usb_drv_init(void) |
650 | { | 426 | { |
651 | int ep_num; | ||
652 | |||
653 | /* enable USB clock */ | ||
654 | SCU_CLKCFG &= ~CLKCFG_UDC; | ||
655 | |||
656 | /* 1. do soft disconnect */ | ||
657 | DEV_CTL = DEV_SELF_PWR; | ||
658 | |||
659 | /* 2. do power on reset to PHY */ | ||
660 | DEV_CTL = DEV_SELF_PWR | | ||
661 | SOFT_POR; | ||
662 | |||
663 | /* 3. wait more than 10ms */ | ||
664 | udelay(20000); | ||
665 | |||
666 | /* 4. clear SOFT_POR bit */ | ||
667 | DEV_CTL &= ~SOFT_POR; | ||
668 | |||
669 | /* 5. configure minimal EN_INT */ | ||
670 | EN_INT = EN_SUSP_INTR | /* Enable Suspend Interrupt */ | ||
671 | EN_RESUME_INTR | /* Enable Resume Interrupt */ | ||
672 | EN_USBRST_INTR | /* Enable USB Reset Interrupt */ | ||
673 | EN_OUT0_INTR | /* Enable OUT Token receive Interrupt EP0 */ | ||
674 | EN_IN0_INTR | /* Enable IN Token transmits Interrupt EP0 */ | ||
675 | EN_SETUP_INTR; /* Enable SETUP Packet Receive Interrupt */ | ||
676 | |||
677 | /* 6. configure INTCON */ | ||
678 | INTCON = UDC_INTHIGH_ACT | /* interrupt high active */ | ||
679 | UDC_INTEN; /* enable EP0 interrupts */ | ||
680 | |||
681 | /* 7. configure EP0 control registers */ | ||
682 | TX0CON = TXACKINTEN | /* Set as one to enable the EP0 tx irq */ | ||
683 | TXNAK; /* Set as one to response NAK handshake */ | ||
684 | |||
685 | RX0CON = RXACKINTEN | | ||
686 | RXEPEN | /* Endpoint 0 Enable. When cleared the endpoint does | ||
687 | * not respond to an SETUP or OUT token | ||
688 | */ | ||
689 | |||
690 | RXNAK; /* Set as one to response NAK handshake */ | ||
691 | |||
692 | /* 8. write final bits to DEV_CTL */ | ||
693 | DEV_CTL = CSR_DONE | /* Configure CSR done */ | ||
694 | DEV_PHY16BIT | /* 16-bit data path enabled. udc_clk = 30MHz */ | ||
695 | DEV_SOFT_CN | /* Device soft connect */ | ||
696 | DEV_SELF_PWR; /* Device self power */ | ||
697 | |||
698 | /* init semaphore of ep0 */ | 427 | /* init semaphore of ep0 */ |
699 | semaphore_init(&ctrlep[DIR_OUT].complete, 1, 0); | 428 | semaphore_init(&ctrlep[DIR_OUT].complete, 1, 0); |
700 | semaphore_init(&ctrlep[DIR_IN].complete, 1, 0); | 429 | semaphore_init(&ctrlep[DIR_IN].complete, 1, 0); |
701 | 430 | ||
702 | for (ep_num = 1; ep_num < USB_NUM_ENDPOINTS; ep_num++) | 431 | for(int ep_num = 1; ep_num < USB_NUM_ENDPOINTS; ep_num++) |
703 | { | ||
704 | semaphore_init(&endpoints[ep_num].complete, 1, 0); | 432 | semaphore_init(&endpoints[ep_num].complete, 1, 0); |
705 | |||
706 | if (ep_num%3 == 0) /* IIN 3, 6, 9, 12, 15 */ | ||
707 | { | ||
708 | IIN_TXCON(ep_num) |= (ep_num<<8)|TXEPEN|TXNAK; /* ep_num, enable, NAK */ | ||
709 | } | ||
710 | else if (ep_num%3 == 1) /* BOUT 1, 4, 7, 10, 13 */ | ||
711 | { | ||
712 | BOUT_RXCON(ep_num) |= (ep_num<<8)|RXEPEN|RXNAK; /* ep_num, NAK, enable */ | ||
713 | } | ||
714 | else if (ep_num%3 == 2) /* BIN 2, 5, 8, 11, 14 */ | ||
715 | { | ||
716 | BIN_TXCON(ep_num) |= (ep_num<<8)|TXEPEN|TXNAK; /* ep_num, enable, NAK */ | ||
717 | } | ||
718 | } | ||
719 | } | 433 | } |
720 | 434 | ||
721 | /* turn off usb core */ | 435 | /* turn off usb core */ |
722 | void usb_drv_exit(void) | 436 | void usb_drv_exit(void) |
723 | { | 437 | { |
724 | DEV_CTL = DEV_SELF_PWR; | 438 | DEV_CTL = DEV_SELF_PWR; |
725 | 439 | ||
726 | /* disable USB interrupts in interrupt controller */ | 440 | /* disable USB interrupts in interrupt controller */ |
727 | INTC_IMR &= ~IRQ_ARM_UDC; | 441 | INTC_IMR &= ~IRQ_ARM_UDC; |
728 | INTC_IECR &= ~IRQ_ARM_UDC; | 442 | INTC_IECR &= ~IRQ_ARM_UDC; |
729 | 443 | ||
730 | /* we cannot disable UDC clock since this causes data abort | 444 | /* we cannot disable UDC clock since this causes data abort |
731 | * when reading DEV_INFO in order to check usb connect event | 445 | * when reading DEV_INFO in order to check usb connect event |
732 | */ | 446 | */ |
@@ -734,9 +448,94 @@ void usb_drv_exit(void) | |||
734 | 448 | ||
735 | int usb_detect(void) | 449 | int usb_detect(void) |
736 | { | 450 | { |
737 | if (DEV_INFO & VBUS_STS) | 451 | if(DEV_INFO & VBUS_STS) |
738 | return USB_INSERTED; | 452 | return USB_INSERTED; |
739 | else | 453 | else |
740 | return USB_EXTRACTED; | 454 | return USB_EXTRACTED; |
741 | } | 455 | } |
742 | 456 | ||
457 | /* UDC ISR function */ | ||
458 | void INT_UDC(void) | ||
459 | { | ||
460 | /* read what caused UDC irq */ | ||
461 | uint32_t intsrc = INT2FLAG & 0x7fffff; | ||
462 | |||
463 | if(intsrc & USBRST_INTR) /* usb reset */ | ||
464 | { | ||
465 | logf("udc_int: reset, %ld", current_tick); | ||
466 | |||
467 | EN_INT = EN_SUSP_INTR | /* Enable Suspend Irq */ | ||
468 | EN_RESUME_INTR | /* Enable Resume Irq */ | ||
469 | EN_USBRST_INTR | /* Enable USB Reset Irq */ | ||
470 | EN_OUT0_INTR | /* Enable OUT Token receive Irq EP0 */ | ||
471 | EN_IN0_INTR | /* Enable IN Token transmit Irq EP0 */ | ||
472 | EN_SETUP_INTR; /* Enable SETUP Packet Receive Irq */ | ||
473 | |||
474 | INTCON = UDC_INTHIGH_ACT | /* interrupt high active */ | ||
475 | UDC_INTEN; /* enable EP0 irqs */ | ||
476 | |||
477 | TX0CON = TXACKINTEN | /* Set as one to enable the EP0 tx irq */ | ||
478 | TXNAK; /* Set as one to response NAK handshake */ | ||
479 | |||
480 | RX0CON = RXACKINTEN | | ||
481 | RXEPEN | /* Endpoint 0 Enable. When cleared the | ||
482 | * endpoint does not respond to an SETUP | ||
483 | * or OUT token */ | ||
484 | RXNAK; /* Set as one to response NAK handshake */ | ||
485 | |||
486 | set_address = false; | ||
487 | set_configuration = false; | ||
488 | } | ||
489 | /* This needs to be processed AFTER usb reset */ | ||
490 | udc_helper(); | ||
491 | |||
492 | if(intsrc & SETUP_INTR) /* setup interrupt */ | ||
493 | { | ||
494 | setup_received(); | ||
495 | } | ||
496 | if(intsrc & IN0_INTR) | ||
497 | { | ||
498 | /* EP0 IN done */ | ||
499 | in_intr(&ctrlep[DIR_IN]); | ||
500 | } | ||
501 | if(intsrc & OUT0_INTR) | ||
502 | { | ||
503 | /* EP0 OUT done */ | ||
504 | out_intr(&ctrlep[DIR_OUT]); | ||
505 | } | ||
506 | if(intsrc & USBRST_INTR) | ||
507 | { | ||
508 | /* usb reset */ | ||
509 | usb_drv_init(); | ||
510 | } | ||
511 | if(intsrc & RESUME_INTR) | ||
512 | { | ||
513 | /* usb resume */ | ||
514 | TX0CON |= TXCLR; /* TxClr */ | ||
515 | TX0CON &= ~TXCLR; | ||
516 | RX0CON |= RXCLR; /* RxClr */ | ||
517 | RX0CON &= ~RXCLR; | ||
518 | } | ||
519 | if(intsrc & SUSP_INTR) | ||
520 | { | ||
521 | /* usb suspend */ | ||
522 | } | ||
523 | if(intsrc & CONN_INTR) | ||
524 | { | ||
525 | /* usb connect */ | ||
526 | udc_phy_reset(); | ||
527 | udelay(10000); /* wait at least 10ms */ | ||
528 | udc_soft_connect(); | ||
529 | } | ||
530 | /* other endpoints */ | ||
531 | for(int ep_num = 1; ep_num < 16; ep_num++) | ||
532 | { | ||
533 | if(!(intsrc & (1 << (ep_num + 7)))) | ||
534 | continue; | ||
535 | struct endpoint_t *endp = &endpoints[ep_num]; | ||
536 | if(endp->dir == USB_DIR_IN) | ||
537 | in_intr(endp); | ||
538 | else | ||
539 | out_intr(endp); | ||
540 | } | ||
541 | } | ||
diff --git a/firmware/target/arm/rk27xx/usb-rk27xx.c b/firmware/target/arm/rk27xx/usb-rk27xx.c index 20bf867c8d..09c9090a3b 100644 --- a/firmware/target/arm/rk27xx/usb-rk27xx.c +++ b/firmware/target/arm/rk27xx/usb-rk27xx.c | |||
@@ -32,6 +32,20 @@ int usb_status = USB_EXTRACTED; | |||
32 | 32 | ||
33 | void usb_init_device(void) | 33 | void usb_init_device(void) |
34 | { | 34 | { |
35 | /* enable UDC interrupt */ | ||
36 | INTC_IMR |= (1<<16); | ||
37 | INTC_IECR |= (1<<16); | ||
38 | |||
39 | EN_INT = EN_SUSP_INTR | /* Enable Suspend Interrupt */ | ||
40 | EN_RESUME_INTR | /* Enable Resume Interrupt */ | ||
41 | EN_USBRST_INTR | /* Enable USB Reset Interrupt */ | ||
42 | EN_OUT0_INTR | /* Enable OUT Token receive Interrupt EP0 */ | ||
43 | EN_IN0_INTR | /* Enable IN Token transmits Interrupt EP0 */ | ||
44 | EN_SETUP_INTR; /* Enable SETUP Packet Receive Interrupt */ | ||
45 | |||
46 | /* configure INTCON */ | ||
47 | INTCON = UDC_INTHIGH_ACT | /* interrupt high active */ | ||
48 | UDC_INTEN; /* enable EP0 interrupts */ | ||
35 | } | 49 | } |
36 | 50 | ||
37 | void usb_attach(void) | 51 | void usb_attach(void) |
diff --git a/firmware/target/hosted/sdl/sim-ui-defines.h b/firmware/target/hosted/sdl/sim-ui-defines.h index 0303ac8ca2..99ae062595 100644 --- a/firmware/target/hosted/sdl/sim-ui-defines.h +++ b/firmware/target/hosted/sdl/sim-ui-defines.h | |||
@@ -527,6 +527,28 @@ | |||
527 | #define UI_HEIGHT 457 /* height of GUI window */ | 527 | #define UI_HEIGHT 457 /* height of GUI window */ |
528 | #define UI_LCD_POSX 34 | 528 | #define UI_LCD_POSX 34 |
529 | #define UI_LCD_POSY 73 | 529 | #define UI_LCD_POSY 73 |
530 | |||
531 | #elif defined(IHIFI770) | ||
532 | #define UI_TITLE "iHiFi 770" | ||
533 | #define UI_WIDTH 382 /* width of GUI window */ | ||
534 | #define UI_HEIGHT 690 /* height of GUI window */ | ||
535 | #define UI_LCD_POSX 32 | ||
536 | #define UI_LCD_POSY 86 | ||
537 | |||
538 | #elif defined(IHIFI770C) | ||
539 | #define UI_TITLE "iHiFi 770C" | ||
540 | #define UI_WIDTH 382 /* width of GUI window */ | ||
541 | #define UI_HEIGHT 690 /* height of GUI window */ | ||
542 | #define UI_LCD_POSX 32 | ||
543 | #define UI_LCD_POSY 86 | ||
544 | |||
545 | #elif defined(IHIFI800) | ||
546 | #define UI_TITLE "iHiFi 800" | ||
547 | #define UI_WIDTH 300 /* width of GUI window */ | ||
548 | #define UI_HEIGHT 670 /* height of GUI window */ | ||
549 | #define UI_LCD_POSX 26 | ||
550 | #define UI_LCD_POSY 40 | ||
551 | |||
530 | #elif defined(SIMULATOR) | 552 | #elif defined(SIMULATOR) |
531 | #error no UI defines | 553 | #error no UI defines |
532 | #endif | 554 | #endif |