summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--firmware/export/system.h4
-rw-r--r--firmware/kernel.c11
-rw-r--r--firmware/system.c62
-rw-r--r--firmware/thread.c7
-rw-r--r--firmware/usb.c30
5 files changed, 87 insertions, 27 deletions
diff --git a/firmware/export/system.h b/firmware/export/system.h
index f9da0d2e67..626cdfa257 100644
--- a/firmware/export/system.h
+++ b/firmware/export/system.h
@@ -190,6 +190,10 @@ static inline void invalidate_icache(void)
190 190
191#elif CONFIG_CPU == TCC730 191#elif CONFIG_CPU == TCC730
192 192
193extern int smsc_version(void);
194
195extern void smsc_delay(void);
196
193extern void set_pll_freq(int pll_index, long freq_out); 197extern void set_pll_freq(int pll_index, long freq_out);
194 198
195 199
diff --git a/firmware/kernel.c b/firmware/kernel.c
index 71daac1bd7..ca0dcf5458 100644
--- a/firmware/kernel.c
+++ b/firmware/kernel.c
@@ -258,7 +258,16 @@ void TIMER0(void)
258{ 258{
259 int i; 259 int i;
260 260
261 /* Keep alive (?) */ 261 /* Mess with smsc chip. No idea what for.
262 */
263 if (smsc_version() < 4) {
264 P6 |= 0x08;
265 P10 |= 0x20;
266 }
267
268 /* Keep alive (?)
269 * If this is not done, power goes down when DC is unplugged.
270 */
262 if (current_tick % 2 == 0) 271 if (current_tick % 2 == 0)
263 P8 |= 1; 272 P8 |= 1;
264 else 273 else
diff --git a/firmware/system.c b/firmware/system.c
index eb6c6eedb4..3ead7c6be3 100644
--- a/firmware/system.c
+++ b/firmware/system.c
@@ -106,6 +106,57 @@ void set_pll_freq(int pll_index, long freq_out) {
106 } while ((*pllcon & 0x2) == 0); /* wait for stabilization */ 106 } while ((*pllcon & 0x2) == 0); /* wait for stabilization */
107} 107}
108 108
109int smsc_version(void) {
110 int v;
111 int* smsc_ver_addr = (int*)0x4C20;
112 __asm__ ("ldc %0, @%1" : "=r"(v) : "a"(smsc_ver_addr));
113 v &= 0xFF;
114 if (v < 4 || v == 0xFF) {
115 return 3;
116 }
117 return v;
118}
119
120
121
122void smsc_delay() {
123 int i;
124 /* FIXME: tune the delay.
125 !!! Delay should depend on CPU speed !!!
126 */
127 for (i = 0; i < 100; i++) {
128
129 }
130}
131
132static void extra_init(void) {
133 /* Power on
134 P1 |= 0x01;
135 P1CON |= 0x01;
136 */
137
138 /* SMSC chip config (?) */
139 P6CON |= 0x08;
140 P10CON |= 0x20;
141 P6 &= 0xF7;
142 P10 &= 0x20;
143 smsc_delay();
144 if (smsc_version() < 4) {
145 P6 |= 0x80;
146 P10 |= 0x20;
147 }
148
149 /* P5 conf
150 * line 2 & 4 are digital, other analog. : P5CON = 0xec;
151 */
152
153 /* P7 conf
154 nothing to do: all are inputs
155 (reset value of the register is good)
156 */
157
158}
159
109/* called by crt0 */ 160/* called by crt0 */
110void system_init(void) 161void system_init(void)
111{ 162{
@@ -119,7 +170,14 @@ void system_init(void)
119 /* keep alive (?) -- clear the bit to prevent crash at start (??) */ 170 /* keep alive (?) -- clear the bit to prevent crash at start (??) */
120 P8 = 0x00; 171 P8 = 0x00;
121 P8CON = 0x01; 172 P8CON = 0x01;
122 173
174 /* smsc chip init (?) */
175 P10 = 0x20;
176 P6 = 0x08;
177
178 P10CON = 0x20;
179 P6CON = 0x08;
180
123 /******** 181 /********
124 * CPU 182 * CPU
125 */ 183 */
@@ -170,6 +228,8 @@ void system_init(void)
170/* IRQ13 IIS0 INT */ 228/* IRQ13 IIS0 INT */
171/* IRQ14 IIS1 INT */ 229/* IRQ14 IIS1 INT */
172/* IRQ15 ­ */ 230/* IRQ15 ­ */
231
232 extra_init();
173} 233}
174 234
175#elif CONFIG_CPU == MCF5249 235#elif CONFIG_CPU == MCF5249
diff --git a/firmware/thread.c b/firmware/thread.c
index d59c05e1fc..d79c53834e 100644
--- a/firmware/thread.c
+++ b/firmware/thread.c
@@ -188,8 +188,11 @@ void switch_thread(void)
188#if CONFIG_CPU == MCF5249 188#if CONFIG_CPU == MCF5249
189 asm volatile ("stop #0x2000"); 189 asm volatile ("stop #0x2000");
190#elif CONFIG_CPU == TCC730 190#elif CONFIG_CPU == TCC730
191 /* No sleep instr on the CalmRisc. (?) 191 /* Sleep mode is triggered by the SYS instr on CalmRisc16.
192 * TODO: investigate the SYS instruction 192 * Unfortunately, the manual doesn't specify which arg to use.
193 __asm__ volatile ("sys #0x0f");
194 0x1f seems to trigger a reset;
195 0x0f is the only one other argument used by Archos.
193 */ 196 */
194#else 197#else
195 SBYCR &= 0x7F; 198 SBYCR &= 0x7F;
diff --git a/firmware/usb.c b/firmware/usb.c
index 8bb320c49d..1400805c33 100644
--- a/firmware/usb.c
+++ b/firmware/usb.c
@@ -80,19 +80,6 @@ static struct event_queue usb_queue;
80static bool last_usb_status; 80static bool last_usb_status;
81static bool usb_monitor_enabled; 81static bool usb_monitor_enabled;
82 82
83#ifdef USB_GMINISTYLE
84static int getSMSCVer(void) {
85 int v;
86 int* smscVerAddr = (int*)0x4C20;
87 __asm__ ("ldc %0, @%1" : "=r"(v) : "a"(smscVerAddr));
88 v &= 0xFF;
89 if (v < 4 || v == 0xFF) {
90 return 3;
91 }
92 return v;
93}
94
95#endif
96 83
97static void usb_enable(bool on) 84static void usb_enable(bool on)
98{ 85{
@@ -118,26 +105,23 @@ static void usb_enable(bool on)
118 or_b(0x28, &PAIORL); /* output for USB enable and card detect */ 105 or_b(0x28, &PAIORL); /* output for USB enable and card detect */
119#elif defined(USB_GMINISTYLE) 106#elif defined(USB_GMINISTYLE)
120 { 107 {
121 int i; 108 int smsc_ver = smsc_version();
122 int smscVer = getSMSCVer();
123 if (on) { 109 if (on) {
124 if (smscVer < 4) { 110 if (smsc_ver < 4) {
125 P6 &= ~0x04; 111 P6 &= ~0x04;
126 P10 &= ~0x20; 112 P10 &= ~0x20;
127 113
128 for (i=0; i < 20; i++) 114 smsc_delay();
129 ;
130 115
131 P6 |= 0x08; 116 P6 |= 0x08;
132 P10 |= 0x20; 117 P10 |= 0x20;
133 118
134 for (i=0; i < 20; i++) 119 smsc_delay();
135 ;
136 } 120 }
137 P6 |= 0x10; 121 P6 |= 0x10;
138 } else { 122 } else {
139 P6 &= ~0x10; 123 P6 &= ~0x10;
140 if (smscVer < 4) { 124 if (smsc_ver < 4) {
141 P6 &= ~0x04; 125 P6 &= ~0x04;
142 P10 &= ~0x20; 126 P10 &= ~0x20;
143 } 127 }
@@ -355,7 +339,7 @@ bool usb_detect(void)
355 current_status = (GPIO1_READ & 0x80)?true:false; 339 current_status = (GPIO1_READ & 0x80)?true:false;
356#endif 340#endif
357#ifdef USB_GMINISTYLE 341#ifdef USB_GMINISTYLE
358 current_status = (P5 & 0x80)?true:false; 342 current_status = (P5 & 0x10)?true:false;
359#endif 343#endif
360 return current_status; 344 return current_status;
361} 345}