1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2005 by Linus Nielsen Feltzing
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
28 #include "powermgmt.h"
30 #include "lcd-remote.h"
35 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
36 (CONFIG_KEYPAD == IRIVER_H300_PAD)
37 # define DEBUG_CANCEL BUTTON_OFF
39 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
40 # define DEBUG_CANCEL BUTTON_REC
42 #elif (CONFIG_KEYPAD == IAUDIO_M3_PAD)
43 # define DEBUG_CANCEL BUTTON_RC_REC
45 #elif (CONFIG_KEYPAD == MPIO_HD200_PAD)
46 # define DEBUG_CANCEL BUTTON_REC
48 #elif (CONFIG_KEYPAD == MPIO_HD300_PAD)
49 # define DEBUG_CANCEL BUTTON_MENU
51 /* Tool function to read the flash manufacturer and type, if available.
52 Only chips which could be reprogrammed in system will return values.
53 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
54 /* In IRAM to avoid problems when running directly from Flash */
55 static bool dbg_flash_id(unsigned* p_manufacturer
, unsigned* p_device
,
56 unsigned addr1
, unsigned addr2
)
57 ICODE_ATTR
__attribute__((noinline
));
58 static bool dbg_flash_id(unsigned* p_manufacturer
, unsigned* p_device
,
59 unsigned addr1
, unsigned addr2
)
62 unsigned not_manu
, not_id
; /* read values before switching to ID mode */
63 unsigned manu
, id
; /* read values when in ID mode */
65 volatile unsigned short* flash
= (unsigned short*)0; /* flash mapping */
66 int old_level
; /* saved interrupt level */
68 not_manu
= flash
[0]; /* read the normal content */
69 not_id
= flash
[1]; /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
71 /* disable interrupts, prevent any stray flash access */
72 old_level
= disable_irq_save();
74 flash
[addr1
] = 0xAA; /* enter command mode */
76 flash
[addr1
] = 0x90; /* ID command */
77 /* Atmel wants 20ms pause here */
78 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
79 manu
= flash
[0]; /* read the IDs */
82 flash
[0] = 0xF0; /* reset flash (back to normal read mode) */
83 /* Atmel wants 20ms pause here */
84 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
86 restore_irq(old_level
); /* enable interrupts again */
88 /* I assume success if the obtained values are different from
89 the normal flash content. This is not perfectly bulletproof, they
90 could theoretically be the same by chance, causing us to fail. */
91 if (not_manu
!= manu
|| not_id
!= id
) /* a value has changed */
93 *p_manufacturer
= manu
; /* return the results */
95 return true; /* success */
97 return false; /* fail */
102 unsigned int gpio_out
;
103 unsigned int gpio1_out
;
104 unsigned int gpio_read
;
105 unsigned int gpio1_read
;
106 unsigned int gpio_function
;
107 unsigned int gpio1_function
;
108 unsigned int gpio_enable
;
109 unsigned int gpio1_enable
;
110 int adc_battery_voltage
, adc_battery_level
;
111 int adc_buttons
, adc_remote
;
115 lcd_setfont(FONT_SYSFIXED
);
120 gpio_read
= GPIO_READ
;
121 gpio1_read
= GPIO1_READ
;
123 gpio1_out
= GPIO1_OUT
;
124 gpio_function
= GPIO_FUNCTION
;
125 gpio1_function
= GPIO1_FUNCTION
;
126 gpio_enable
= GPIO_ENABLE
;
127 gpio1_enable
= GPIO1_ENABLE
;
129 lcd_putsf(0, line
++, "GPIO_READ: %08x", gpio_read
);
130 lcd_putsf(0, line
++, "GPIO_OUT: %08x", gpio_out
);
131 lcd_putsf(0, line
++, "GPIO_FUNC: %08x", gpio_function
);
132 lcd_putsf(0, line
++, "GPIO_ENA: %08x", gpio_enable
);
133 lcd_putsf(0, line
++, "GPIO1_READ: %08x", gpio1_read
);
134 lcd_putsf(0, line
++, "GPIO1_OUT: %08x", gpio1_out
);
135 lcd_putsf(0, line
++, "GPIO1_FUNC: %08x", gpio1_function
);
136 lcd_putsf(0, line
++, "GPIO1_ENA: %08x", gpio1_enable
);
138 adc_buttons
= adc_read(ADC_BUTTONS
);
139 adc_remote
= adc_read(ADC_REMOTE
);
140 battery_read_info(&adc_battery_voltage
, &adc_battery_level
);
141 #if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
142 lcd_putsf(0, line
++, "ADC_BUTTONS (%c): %02x",
143 button_scan_enabled() ? '+' : '-', adc_buttons
);
145 lcd_putsf(0, line
++, "ADC_BUTTONS: %02x", adc_buttons
);
147 #if defined(IAUDIO_X5) || defined(IAUDIO_M5)
148 lcd_putsf(0, line
++, "ADC_REMOTE (%c): %02x",
149 remote_detect() ? '+' : '-', adc_remote
);
151 lcd_putsf(0, line
++, "ADC_REMOTE: %02x", adc_remote
);
153 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
154 lcd_putsf(0, line
++, "ADC_REMOTEDETECT: %02x",
155 adc_read(ADC_REMOTEDETECT
));
158 battery_read_info(&adc_battery_voltage
, &adc_battery_level
);
159 lcd_putsf(0, line
++, "Batt: %d.%03dV %d%% ", adc_battery_voltage
/ 1000,
160 adc_battery_voltage
% 1000, adc_battery_level
);
162 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
163 lcd_putsf(0, line
++, "remotetype: %d", remote_type());
167 if (button_get_w_tmo(HZ
/10) == (DEBUG_CANCEL
|BUTTON_REL
))
169 lcd_setfont(FONT_UI
);
176 bool dbg_hw_info(void)
178 unsigned manu
, id
; /* flash IDs */
179 int got_id
; /* flag if we managed to get the flash IDs */
180 int oldmode
; /* saved memory guard mode */
183 oldmode
= system_memory_guard(MEMGUARD_NONE
); /* disable memory guard */
185 /* get flash ROM type */
186 got_id
= dbg_flash_id(&manu
, &id
, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
188 got_id
= dbg_flash_id(&manu
, &id
, 0x555, 0x2AA); /* try AMD, Macronix */
190 system_memory_guard(oldmode
); /* re-enable memory guard */
192 lcd_setfont(FONT_SYSFIXED
);
195 lcd_puts(0, line
++, "[Hardware info]");
198 lcd_putsf(0, line
++, "Flash: M=%04x D=%04x", manu
, id
);
200 lcd_puts(0, line
++, "Flash: M=???? D=????"); /* unknown, sorry */
206 lcd_puts(0, ++line
, "Serial Number:");
208 got_id
= ds2411_read_id(&id
);
210 if (got_id
== DS2411_OK
)
212 lcd_putsf(0, ++line
, " FC=%02x", (unsigned)id
.family_code
);
213 lcd_putsf(0, ++line
, " ID=%02X %02X %02X %02X %02X %02X",
214 (unsigned)id
.uid
[0], (unsigned)id
.uid
[1], (unsigned)id
.uid
[2],
215 (unsigned)id
.uid
[3], (unsigned)id
.uid
[4], (unsigned)id
.uid
[5]);
216 lcd_putsf(0, ++line
, " CRC=%02X", (unsigned)id
.crc
);
220 lcd_putsf(0, ++line
, "READ ERR=%d", got_id
);
228 while (button_get_w_tmo(HZ
/10) != (DEBUG_CANCEL
|BUTTON_REL
));
230 lcd_setfont(FONT_UI
);