From 8ec05779e3cb42654fd774906561d586b4f1095e Mon Sep 17 00:00:00 2001 From: Jean-Philippe Bernardy Date: Sat, 19 Feb 2005 17:49:58 +0000 Subject: Gmini work: * Better USB * Better comments * Better coding style git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6022 a1c6a512-1295-4272-9138-f99709370657 --- firmware/export/system.h | 4 ++++ firmware/kernel.c | 11 ++++++++- firmware/system.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++- firmware/thread.c | 7 ++++-- firmware/usb.c | 30 ++++++----------------- 5 files changed, 87 insertions(+), 27 deletions(-) (limited to 'firmware') 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) #elif CONFIG_CPU == TCC730 +extern int smsc_version(void); + +extern void smsc_delay(void); + extern void set_pll_freq(int pll_index, long freq_out); 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) { int i; - /* Keep alive (?) */ + /* Mess with smsc chip. No idea what for. + */ + if (smsc_version() < 4) { + P6 |= 0x08; + P10 |= 0x20; + } + + /* Keep alive (?) + * If this is not done, power goes down when DC is unplugged. + */ if (current_tick % 2 == 0) P8 |= 1; 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) { } while ((*pllcon & 0x2) == 0); /* wait for stabilization */ } +int smsc_version(void) { + int v; + int* smsc_ver_addr = (int*)0x4C20; + __asm__ ("ldc %0, @%1" : "=r"(v) : "a"(smsc_ver_addr)); + v &= 0xFF; + if (v < 4 || v == 0xFF) { + return 3; + } + return v; +} + + + +void smsc_delay() { + int i; + /* FIXME: tune the delay. + !!! Delay should depend on CPU speed !!! + */ + for (i = 0; i < 100; i++) { + + } +} + +static void extra_init(void) { + /* Power on + P1 |= 0x01; + P1CON |= 0x01; + */ + + /* SMSC chip config (?) */ + P6CON |= 0x08; + P10CON |= 0x20; + P6 &= 0xF7; + P10 &= 0x20; + smsc_delay(); + if (smsc_version() < 4) { + P6 |= 0x80; + P10 |= 0x20; + } + + /* P5 conf + * line 2 & 4 are digital, other analog. : P5CON = 0xec; + */ + + /* P7 conf + nothing to do: all are inputs + (reset value of the register is good) + */ + +} + /* called by crt0 */ void system_init(void) { @@ -119,7 +170,14 @@ void system_init(void) /* keep alive (?) -- clear the bit to prevent crash at start (??) */ P8 = 0x00; P8CON = 0x01; - + + /* smsc chip init (?) */ + P10 = 0x20; + P6 = 0x08; + + P10CON = 0x20; + P6CON = 0x08; + /******** * CPU */ @@ -170,6 +228,8 @@ void system_init(void) /* IRQ13 IIS0 INT */ /* IRQ14 IIS1 INT */ /* IRQ15 ­ */ + + extra_init(); } #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) #if CONFIG_CPU == MCF5249 asm volatile ("stop #0x2000"); #elif CONFIG_CPU == TCC730 - /* No sleep instr on the CalmRisc. (?) - * TODO: investigate the SYS instruction + /* Sleep mode is triggered by the SYS instr on CalmRisc16. + * Unfortunately, the manual doesn't specify which arg to use. + __asm__ volatile ("sys #0x0f"); + 0x1f seems to trigger a reset; + 0x0f is the only one other argument used by Archos. */ #else 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; static bool last_usb_status; static bool usb_monitor_enabled; -#ifdef USB_GMINISTYLE -static int getSMSCVer(void) { - int v; - int* smscVerAddr = (int*)0x4C20; - __asm__ ("ldc %0, @%1" : "=r"(v) : "a"(smscVerAddr)); - v &= 0xFF; - if (v < 4 || v == 0xFF) { - return 3; - } - return v; -} - -#endif static void usb_enable(bool on) { @@ -118,26 +105,23 @@ static void usb_enable(bool on) or_b(0x28, &PAIORL); /* output for USB enable and card detect */ #elif defined(USB_GMINISTYLE) { - int i; - int smscVer = getSMSCVer(); + int smsc_ver = smsc_version(); if (on) { - if (smscVer < 4) { + if (smsc_ver < 4) { P6 &= ~0x04; P10 &= ~0x20; - for (i=0; i < 20; i++) - ; + smsc_delay(); P6 |= 0x08; P10 |= 0x20; - - for (i=0; i < 20; i++) - ; + + smsc_delay(); } P6 |= 0x10; } else { P6 &= ~0x10; - if (smscVer < 4) { + if (smsc_ver < 4) { P6 &= ~0x04; P10 &= ~0x20; } @@ -355,7 +339,7 @@ bool usb_detect(void) current_status = (GPIO1_READ & 0x80)?true:false; #endif #ifdef USB_GMINISTYLE - current_status = (P5 & 0x80)?true:false; + current_status = (P5 & 0x10)?true:false; #endif return current_status; } -- cgit v1.2.3