summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Giacomelli <giac2000@hotmail.com>2008-02-10 05:39:20 +0000
committerMichael Giacomelli <giac2000@hotmail.com>2008-02-10 05:39:20 +0000
commit054447f9e6037e4feb1a4c4313bd0afd4eb382a6 (patch)
tree57d78a645d2700d78a66f1807cc26dca9b6c45c9
parent2b3136e1f350721fa65cc304cad7a00504390850 (diff)
downloadrockbox-054447f9e6037e4feb1a4c4313bd0afd4eb382a6.tar.gz
rockbox-054447f9e6037e4feb1a4c4313bd0afd4eb382a6.zip
Commit FS#8379 by Andree Buschmann. Disables much of the remaining unneeded hardware on PP50xx targets (Ipods, Sansa, H10s, etc) resulting in a large savings in power and consequent increase in battery life. Results vary from target to target and from codec to codec, but we now approach the OF runtime on several PP devices. For now, leave base CPU clock at 30MHz, although further savings is possible with some codecs if clock is reduced. Additionally, fix battery capacity on c200 and use my measurements to improve runtime estimation for Sandisk targets.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16259 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/debug_menu.c125
-rw-r--r--apps/main.c4
-rw-r--r--firmware/drivers/audio/as3514.c10
-rw-r--r--firmware/drivers/pcf50605.c43
-rw-r--r--firmware/export/config-c200.h6
-rw-r--r--firmware/export/powermgmt.h18
-rw-r--r--firmware/export/pp5020.h7
-rw-r--r--firmware/target/arm/adc-pp5020.c2
-rw-r--r--firmware/target/arm/ipod/backlight-4g_color.c2
-rw-r--r--firmware/target/arm/ipod/button-clickwheel.c97
-rw-r--r--firmware/target/arm/ipod/power-ipod.c12
-rw-r--r--firmware/target/arm/ipod/powermgmt-ipod-pcf.c4
-rw-r--r--firmware/target/arm/system-pp502x.c230
-rw-r--r--firmware/target/arm/usb-fw-pp502x.c46
-rw-r--r--firmware/target/arm/wmcodec-pp.c8
15 files changed, 433 insertions, 181 deletions
diff --git a/apps/debug_menu.c b/apps/debug_menu.c
index f5dbbf17a5..2e075479bf 100644
--- a/apps/debug_menu.c
+++ b/apps/debug_menu.c
@@ -87,6 +87,10 @@
87#include "ds2411.h" 87#include "ds2411.h"
88#endif 88#endif
89#include "hwcompat.h" 89#include "hwcompat.h"
90#include "button.h"
91#if CONFIG_RTC == RTC_PCF50605
92#include "pcf50605.h"
93#endif
90 94
91#if CONFIG_CPU == DM320 || CONFIG_CPU == S3C2440 95#if CONFIG_CPU == DM320 || CONFIG_CPU == S3C2440
92#include "debug-target.h" 96#include "debug-target.h"
@@ -1167,14 +1171,20 @@ bool dbg_ports(void)
1167 lcd_puts(0, line++, buf); 1171 lcd_puts(0, line++, buf);
1168 line++; 1172 line++;
1169 1173
1170 snprintf(buf, sizeof(buf), "GPO32: %08lx", GPO32_VAL); 1174 snprintf(buf, sizeof(buf), "GPO32_VAL: %08lx", GPO32_VAL);
1175 lcd_puts(0, line++, buf);
1176 snprintf(buf, sizeof(buf), "GPO32_EN: %08lx", GPO32_ENABLE);
1171 lcd_puts(0, line++, buf); 1177 lcd_puts(0, line++, buf);
1172 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN); 1178 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1173 lcd_puts(0, line++, buf); 1179 lcd_puts(0, line++, buf);
1174 snprintf(buf, sizeof(buf), "DEV_EN2: %08lx", DEV_EN2); 1180 snprintf(buf, sizeof(buf), "DEV_EN2: %08lx", DEV_EN2);
1175 lcd_puts(0, line++, buf); 1181 lcd_puts(0, line++, buf);
1176 snprintf(buf, sizeof(buf), "DEV_EN3: %08lx", inl(0x60006044)); 1182 snprintf(buf, sizeof(buf), "DEV_EN3: %08lx", inl(0x60006044));
1177 lcd_puts(0, line++, buf); /* to be verified */ 1183 lcd_puts(0, line++, buf); /* to be verified */
1184 snprintf(buf, sizeof(buf), "DEV_INIT1: %08lx", DEV_INIT1);
1185 lcd_puts(0, line++, buf);
1186 snprintf(buf, sizeof(buf), "DEV_INIT2: %08lx", DEV_INIT2);
1187 lcd_puts(0, line++, buf);
1178 1188
1179#if defined(IRIVER_H10) || defined(IRIVER_H10_5GB) 1189#if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1180 line++; 1190 line++;
@@ -1353,6 +1363,60 @@ bool dbg_ports(void)
1353#endif /* !HAVE_LCD_BITMAP */ 1363#endif /* !HAVE_LCD_BITMAP */
1354#endif /* !SIMULATOR */ 1364#endif /* !SIMULATOR */
1355 1365
1366#if CONFIG_RTC == RTC_PCF50605
1367static bool dbg_pcf(void)
1368{
1369 char buf[128];
1370 int line;
1371
1372#ifdef HAVE_LCD_BITMAP
1373 lcd_setmargins(0, 0);
1374 lcd_setfont(FONT_SYSFIXED);
1375#endif
1376 lcd_clear_display();
1377
1378 while(1)
1379 {
1380 line = 0;
1381
1382 snprintf(buf, sizeof(buf), "DCDC1: %02x", pcf50605_read(0x1b));
1383 lcd_puts(0, line++, buf);
1384 snprintf(buf, sizeof(buf), "DCDC2: %02x", pcf50605_read(0x1c));
1385 lcd_puts(0, line++, buf);
1386 snprintf(buf, sizeof(buf), "DCDC3: %02x", pcf50605_read(0x1d));
1387 lcd_puts(0, line++, buf);
1388 snprintf(buf, sizeof(buf), "DCDC4: %02x", pcf50605_read(0x1e));
1389 lcd_puts(0, line++, buf);
1390 snprintf(buf, sizeof(buf), "DCDEC1: %02x", pcf50605_read(0x1f));
1391 lcd_puts(0, line++, buf);
1392 snprintf(buf, sizeof(buf), "DCDEC2: %02x", pcf50605_read(0x20));
1393 lcd_puts(0, line++, buf);
1394 snprintf(buf, sizeof(buf), "DCUDC1: %02x", pcf50605_read(0x21));
1395 lcd_puts(0, line++, buf);
1396 snprintf(buf, sizeof(buf), "DCUDC2: %02x", pcf50605_read(0x22));
1397 lcd_puts(0, line++, buf);
1398 snprintf(buf, sizeof(buf), "IOREGC: %02x", pcf50605_read(0x23));
1399 lcd_puts(0, line++, buf);
1400 snprintf(buf, sizeof(buf), "D1REGC: %02x", pcf50605_read(0x24));
1401 lcd_puts(0, line++, buf);
1402 snprintf(buf, sizeof(buf), "D2REGC: %02x", pcf50605_read(0x25));
1403 lcd_puts(0, line++, buf);
1404 snprintf(buf, sizeof(buf), "D3REGC: %02x", pcf50605_read(0x26));
1405 lcd_puts(0, line++, buf);
1406 snprintf(buf, sizeof(buf), "LPREG1: %02x", pcf50605_read(0x27));
1407 lcd_puts(0, line++, buf);
1408
1409 lcd_update();
1410 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1411 {
1412 return false;
1413 }
1414 }
1415
1416 return false;
1417}
1418#endif
1419
1356#ifdef HAVE_ADJUSTABLE_CPU_FREQ 1420#ifdef HAVE_ADJUSTABLE_CPU_FREQ
1357static bool dbg_cpufreq(void) 1421static bool dbg_cpufreq(void)
1358{ 1422{
@@ -2251,6 +2315,53 @@ static bool cpu_boost_log(void)
2251} 2315}
2252#endif 2316#endif
2253 2317
2318#if (defined(HAVE_SCROLLWHEEL) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2319extern bool wheel_is_touched;
2320extern int old_wheel_value;
2321extern int new_wheel_value;
2322extern int wheel_delta;
2323extern unsigned int accumulated_wheel_delta;
2324extern unsigned int wheel_velocity;
2325
2326static bool dbg_scrollwheel(void)
2327{
2328 char buf[64];
2329 unsigned int speed;
2330
2331 lcd_setmargins(0, 0);
2332 lcd_setfont(FONT_SYSFIXED);
2333
2334 while (1)
2335 {
2336 if (action_userabort(HZ/10))
2337 return false;
2338
2339 lcd_clear_display();
2340
2341 /* show internal variables of scrollwheel driver */
2342 snprintf(buf, sizeof(buf), "wheel touched: %s", (wheel_is_touched) ? "true" : "false");
2343 lcd_puts(0, 0, buf);
2344 snprintf(buf, sizeof(buf), "new position: %2d", new_wheel_value);
2345 lcd_puts(0, 1, buf);
2346 snprintf(buf, sizeof(buf), "old position: %2d", old_wheel_value);
2347 lcd_puts(0, 2, buf);
2348 snprintf(buf, sizeof(buf), "wheel delta: %2d", wheel_delta);
2349 lcd_puts(0, 3, buf);
2350 snprintf(buf, sizeof(buf), "accumulated delta: %2d", accumulated_wheel_delta);
2351 lcd_puts(0, 4, buf);
2352 snprintf(buf, sizeof(buf), "velo [deg/s]: %4d", (int)wheel_velocity);
2353 lcd_puts(0, 5, buf);
2354
2355 /* show effective accelerated scrollspeed */
2356 speed = button_apply_acceleration( (1<<31)|(1<<24)|wheel_velocity);
2357 snprintf(buf, sizeof(buf), "accel. speed: %4d", speed);
2358 lcd_puts(0, 6, buf);
2359
2360 lcd_update();
2361 }
2362 return false;
2363}
2364#endif
2254 2365
2255 2366
2256/****** The menu *********/ 2367/****** The menu *********/
@@ -2269,6 +2380,9 @@ static const struct the_menu_item menuitems[] = {
2269#if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) || CONFIG_CPU == S3C2440 2380#if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) || CONFIG_CPU == S3C2440
2270 { "View I/O ports", dbg_ports }, 2381 { "View I/O ports", dbg_ports },
2271#endif 2382#endif
2383#if CONFIG_RTC == RTC_PCF50605
2384 { "View PCF registers", dbg_pcf },
2385#endif
2272#if defined(HAVE_TSC2100) && !defined(SIMULATOR) 2386#if defined(HAVE_TSC2100) && !defined(SIMULATOR)
2273 { "TSC2100 debug", tsc2100_debug }, 2387 { "TSC2100 debug", tsc2100_debug },
2274#endif 2388#endif
@@ -2328,6 +2442,9 @@ static const struct the_menu_item menuitems[] = {
2328#ifdef CPU_BOOST_LOGGING 2442#ifdef CPU_BOOST_LOGGING
2329 {"cpu_boost log",cpu_boost_log}, 2443 {"cpu_boost log",cpu_boost_log},
2330#endif 2444#endif
2445#if (defined(HAVE_SCROLLWHEEL) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2446 {"Debug scrollwheel", dbg_scrollwheel},
2447#endif
2331 }; 2448 };
2332static int menu_action_callback(int btn, struct gui_synclist *lists) 2449static int menu_action_callback(int btn, struct gui_synclist *lists)
2333{ 2450{
diff --git a/apps/main.c b/apps/main.c
index 0ce8bcc7ac..92e7149fe8 100644
--- a/apps/main.c
+++ b/apps/main.c
@@ -351,6 +351,8 @@ static void init(void)
351 351
352 settings_reset(); 352 settings_reset();
353 353
354 i2c_init();
355
354 power_init(); 356 power_init();
355 357
356 set_irq_level(0); 358 set_irq_level(0);
@@ -374,8 +376,6 @@ static void init(void)
374#endif 376#endif
375#endif 377#endif
376 378
377 i2c_init();
378
379#if CONFIG_RTC 379#if CONFIG_RTC
380 rtc_init(); 380 rtc_init();
381#endif 381#endif
diff --git a/firmware/drivers/audio/as3514.c b/firmware/drivers/audio/as3514.c
index 2dc1513668..80ada46f80 100644
--- a/firmware/drivers/audio/as3514.c
+++ b/firmware/drivers/audio/as3514.c
@@ -146,11 +146,15 @@ void audiohw_init(void)
146 DEV_RS |= DEV_I2S; 146 DEV_RS |= DEV_I2S;
147 DEV_RS &=~DEV_I2S; 147 DEV_RS &=~DEV_I2S;
148 148
149 /* device enable */ 149 /* I2S device reset */
150 DEV_EN |= (DEV_I2S | 0x7); 150 DEV_RS |= DEV_I2S;
151 DEV_RS &=~DEV_I2S;
152
153 /* I2S device enable */
154 DEV_EN |= DEV_I2S;
151 155
152 /* enable external dev clock clocks */ 156 /* enable external dev clock clocks */
153 DEV_EN |= 0x2; 157 DEV_EN |= DEV_EXTCLOCKS;
154 158
155 /* external dev clock to 24MHz */ 159 /* external dev clock to 24MHz */
156 outl(inl(0x70000018) & ~0xc, 0x70000018); 160 outl(inl(0x70000018) & ~0xc, 0x70000018);
diff --git a/firmware/drivers/pcf50605.c b/firmware/drivers/pcf50605.c
index d34e8512c1..afa0a5ca11 100644
--- a/firmware/drivers/pcf50605.c
+++ b/firmware/drivers/pcf50605.c
@@ -63,11 +63,20 @@
63#define PSSC 0x18 63#define PSSC 0x18
64#define PWROKM 0x19 64#define PWROKM 0x19
65#define PWROKS 0x1a 65#define PWROKS 0x1a
66#define DCDC1 0x1b
67#define DCDC2 0x1c
68#define DCDC3 0x1d
69#define DCDC4 0x1e
70#define DCDEC1 0x1f
71#define DCDEC2 0x20
72#define DCUDC1 0x21
73#define DCUDC2 0x22
74#define IOREGC 0x23
66#define D1REGC1 0x24 75#define D1REGC1 0x24
67 #define VOUT_3000mV 0xf5
68 #define VOUT_3300mV 0xf8
69#define D2REGC1 0x25 76#define D2REGC1 0x25
70#define D3REGC1 0x26 77#define D3REGC1 0x26
78#define LPREG1C 0x27
79
71 80
72unsigned char pcf50605_wakeup_flags = 0; 81unsigned char pcf50605_wakeup_flags = 0;
73 82
@@ -113,8 +122,30 @@ void pcf50605_standby_mode(void)
113 122
114void pcf50605_init(void) 123void pcf50605_init(void)
115{ 124{
116 /* The following values were taken from the ipodlinux kernel source */ 125#if defined (IPOD_VIDEO)
117 pcf50605_write(D1REGC1, VOUT_3000mV); /* Unknown */ 126 /* I/O and GPO voltage supply (default: 0xf8 = 3.3V ON) */
118 pcf50605_write(D2REGC1, VOUT_3300mV); /* Dock Connector pin 17 */ 127 /* ECO not allowed regarding data sheet */
119 pcf50605_write(D3REGC1, VOUT_3000mV); /* Unknown */ 128 pcf50605_write(IOREGC, 0xf8); /* 3.3V ON */
129
130 /* core voltage supply (default DCDC1/DCDC2: 0xec = 1.2V ON) */
131 /* ECO not stable, assumed due to less precision of voltage in ECO mode */
132 pcf50605_write(DCDC1, 0xec); /* 1.2V ON */
133 pcf50605_write(DCDC2, 0x0c); /* OFF */
134
135 /* unknown (default: 0xe3 = 1.8V ON) */
136 pcf50605_write(DCUDC1, 0xe3); /* 1.8V ON */
137
138 /* WM8758 voltage supply (default: 0xf5 = 3.0V ON) */
139 /* ECO not allowed as max. current of 5mA is not sufficient */
140 pcf50605_write(D1REGC1, 0xf0); /* 2.5V ON */
141
142 /* LCD voltage supply (default: 0xf5 = 3.0V ON) */
143 pcf50605_write(D3REGC1, 0xf1); /* 2.6V ON */
144#else
145 /* keep initialization from svn for other iPods */
146 pcf50605_write(D1REGC1, 0xf5); /* 3.0V ON */
147 pcf50605_write(D3REGC1, 0xf5); /* 3.0V ON */
148#endif
149 /* Dock Connector pin 17 (default: OFF) */
150 pcf50605_write(D2REGC1, 0xf8); /* 3.3V ON */
120} 151}
diff --git a/firmware/export/config-c200.h b/firmware/export/config-c200.h
index 53ff97326a..a0bb1aeb2c 100644
--- a/firmware/export/config-c200.h
+++ b/firmware/export/config-c200.h
@@ -113,9 +113,9 @@
113/* define this if you have a flash memory storage */ 113/* define this if you have a flash memory storage */
114#define HAVE_FLASH_STORAGE 114#define HAVE_FLASH_STORAGE
115 115
116#define BATTERY_CAPACITY_DEFAULT 750 /* default battery capacity */ 116#define BATTERY_CAPACITY_DEFAULT 530 /* default battery capacity */
117#define BATTERY_CAPACITY_MIN 750 /* min. capacity selectable */ 117#define BATTERY_CAPACITY_MIN 530 /* min. capacity selectable */
118#define BATTERY_CAPACITY_MAX 750 /* max. capacity selectable */ 118#define BATTERY_CAPACITY_MAX 530 /* max. capacity selectable */
119#define BATTERY_CAPACITY_INC 0 /* capacity increment */ 119#define BATTERY_CAPACITY_INC 0 /* capacity increment */
120#define BATTERY_TYPES_COUNT 1 /* only one type */ 120#define BATTERY_TYPES_COUNT 1 /* only one type */
121 121
diff --git a/firmware/export/powermgmt.h b/firmware/export/powermgmt.h
index 0666b5af37..56e14b3741 100644
--- a/firmware/export/powermgmt.h
+++ b/firmware/export/powermgmt.h
@@ -105,22 +105,26 @@ extern int trickle_sec; /* trickle charge: How many seconds per minute
105# define CURRENT_BACKLIGHT 23 /* FIXME: This needs to be measured, copied from H100 */ 105# define CURRENT_BACKLIGHT 23 /* FIXME: This needs to be measured, copied from H100 */
106# define CURRENT_RECORD 110 /* additional current while recording */ 106# define CURRENT_RECORD 110 /* additional current while recording */
107#elif defined(IPOD_NANO) /* iPOD Nano */ 107#elif defined(IPOD_NANO) /* iPOD Nano */
108# define CURRENT_NORMAL 35 /* 8.5-9.0h playback out of 300mAh battery from IpodRuntime */ 108# define CURRENT_NORMAL 32 /* MP3: ~9h playback out of 300mAh battery */
109# define CURRENT_BACKLIGHT 20 /* FIXME: this needs adjusting */ 109# define CURRENT_BACKLIGHT 20 /* FIXME: this needs adjusting */
110#if defined(HAVE_RECORDING) 110#if defined(HAVE_RECORDING)
111# define CURRENT_RECORD 35 /* FIXME: this needs adjusting */ 111# define CURRENT_RECORD 35 /* FIXME: this needs adjusting */
112#endif 112#endif
113#elif defined(IPOD_VIDEO) /* iPOD Video */ 113#elif defined(IPOD_VIDEO) /* iPOD Video */
114# define CURRENT_NORMAL 42 /* 9.5h out of 400mAh battery (30GB) or 14h out of 600mAh (60GB) from IpodRuntime */ 114# define CURRENT_NORMAL 35 /* MP3: ~11h out of 400mAh battery (30GB) or ~17h out of 600mAh (60GB) */
115# define CURRENT_BACKLIGHT 20 /* FIXME: this needs adjusting */ 115# define CURRENT_BACKLIGHT 20 /* FIXME: this needs adjusting */
116#if defined(HAVE_RECORDING) 116#if defined(HAVE_RECORDING)
117# define CURRENT_RECORD 35 /* FIXME: this needs adjusting */ 117# define CURRENT_RECORD 35 /* FIXME: this needs adjusting */
118#endif 118#endif
119#elif defined(SANSA_E200) /* Sandisk players */ 119#elif defined(SANSA_E200) /* Sandisk E200v1 */
120# define CURRENT_NORMAL 50 /* Toni's measurements in spring 2007 suggests 50 ma during normal operation */ 120# define CURRENT_NORMAL 45 /* Mike's measurements in Jan 2008 */
121# define CURRENT_BACKLIGHT 20 /* seems like a reasonible value for now */ 121# define CURRENT_BACKLIGHT 40 /* Screen is about 20, blue LEDs are another 20, so 40 if both */
122# define CURRENT_RECORD 35 /* FIXME: this needs adjusting */ 122# define CURRENT_RECORD 40 /* flash player, so this is just unboosted current*/
123#else /* Not iriver H1x0, H3x0, nor Archos Ondio, nor iPODVideo, nor Sansas */ 123#elif defined(SANSA_C200) /* Sandisk C200v1 */
124# define CURRENT_NORMAL 45 /* Should be nearly identical to E200 */
125# define CURRENT_BACKLIGHT 40 /* Screen is about 20, blue LEDs are another 20, so 40 if both */
126# define CURRENT_RECORD 40 /* flash player, so this is just unboosted current*/
127#else /* Not iriver H1x0, H3x0, nor Archos Ondio, nor iPod nano/Video, nor Sansas */
124# define CURRENT_NORMAL 145 /* usual current in mA when using the AJB including some disk/backlight/... activity */ 128# define CURRENT_NORMAL 145 /* usual current in mA when using the AJB including some disk/backlight/... activity */
125# define CURRENT_BACKLIGHT 30 /* additional current when backlight always on */ 129# define CURRENT_BACKLIGHT 30 /* additional current when backlight always on */
126#if defined(HAVE_RECORDING) 130#if defined(HAVE_RECORDING)
diff --git a/firmware/export/pp5020.h b/firmware/export/pp5020.h
index 845c89c616..0dcd7b362d 100644
--- a/firmware/export/pp5020.h
+++ b/firmware/export/pp5020.h
@@ -132,7 +132,9 @@
132#define DEV_EN (*(volatile unsigned long *)(0x6000600c)) 132#define DEV_EN (*(volatile unsigned long *)(0x6000600c))
133#define DEV_EN2 (*(volatile unsigned long *)(0x60006010)) 133#define DEV_EN2 (*(volatile unsigned long *)(0x60006010))
134 134
135#define DEV_EXTCLOCKS 0x00000002
135#define DEV_SYSTEM 0x00000004 136#define DEV_SYSTEM 0x00000004
137#define DEV_USB0 0x00000008
136#define DEV_SER0 0x00000040 138#define DEV_SER0 0x00000040
137#define DEV_SER1 0x00000080 139#define DEV_SER1 0x00000080
138#define DEV_I2S 0x00000800 140#define DEV_I2S 0x00000800
@@ -140,7 +142,8 @@
140#define DEV_ATA 0x00004000 142#define DEV_ATA 0x00004000
141#define DEV_OPTO 0x00010000 143#define DEV_OPTO 0x00010000
142#define DEV_PIEZO 0x00010000 144#define DEV_PIEZO 0x00010000
143#define DEV_USB 0x00400000 145#define DEV_PWM 0x00020000
146#define DEV_USB1 0x00400000
144#define DEV_FIREWIRE 0x00800000 147#define DEV_FIREWIRE 0x00800000
145#define DEV_IDE0 0x02000000 148#define DEV_IDE0 0x02000000
146#define DEV_LCD 0x04000000 149#define DEV_LCD 0x04000000
@@ -332,6 +335,8 @@
332#define XMB_NOR_CFG (*(volatile unsigned long *)(0x70000038)) 335#define XMB_NOR_CFG (*(volatile unsigned long *)(0x70000038))
333#define XMB_RAM_CFG (*(volatile unsigned long *)(0x7000003c)) 336#define XMB_RAM_CFG (*(volatile unsigned long *)(0x7000003c))
334 337
338#define INIT_BUTTONS 0x00040000
339#define INIT_PLL 0x40000000
335#define INIT_USB 0x80000000 340#define INIT_USB 0x80000000
336 341
337/* 32 bit GPO port */ 342/* 32 bit GPO port */
diff --git a/firmware/target/arm/adc-pp5020.c b/firmware/target/arm/adc-pp5020.c
index 616ef04861..7ce5ac7011 100644
--- a/firmware/target/arm/adc-pp5020.c
+++ b/firmware/target/arm/adc-pp5020.c
@@ -119,6 +119,7 @@ void adc_init(void)
119 ADC_ADDR |= 0x2000000; 119 ADC_ADDR |= 0x2000000;
120 ADC_STATUS |= 0x2000; 120 ADC_STATUS |= 0x2000;
121 121
122#if defined (IRIVER_H10) || defined(IRIVER_H10_5GB)
122 /* Enable channel 2 (H10:remote) */ 123 /* Enable channel 2 (H10:remote) */
123 DEV_INIT1 &=~0x300; 124 DEV_INIT1 &=~0x300;
124 DEV_INIT1 |= 0x100; 125 DEV_INIT1 |= 0x100;
@@ -130,6 +131,7 @@ void adc_init(void)
130 DEV_INIT1 |= 0x1000; 131 DEV_INIT1 |= 0x1000;
131 ADC_ADDR |= 0x8000000; 132 ADC_ADDR |= 0x8000000;
132 ADC_STATUS |= 0x20000000; 133 ADC_STATUS |= 0x20000000;
134#endif
133 135
134 /* Force a scan of all channels to get initial values */ 136 /* Force a scan of all channels to get initial values */
135 adc_scan(0); 137 adc_scan(0);
diff --git a/firmware/target/arm/ipod/backlight-4g_color.c b/firmware/target/arm/ipod/backlight-4g_color.c
index 982bfd53ac..4e46546ef6 100644
--- a/firmware/target/arm/ipod/backlight-4g_color.c
+++ b/firmware/target/arm/ipod/backlight-4g_color.c
@@ -53,7 +53,7 @@ bool _backlight_init(void)
53 GPIOB_ENABLE |= 0x8; /* B03 enable */ 53 GPIOB_ENABLE |= 0x8; /* B03 enable */
54 GPO32_ENABLE |= 0x2000000; /* D01 enable */ 54 GPO32_ENABLE |= 0x2000000; /* D01 enable */
55 GPO32_VAL |= 0x2000000; /* D01 =1 */ 55 GPO32_VAL |= 0x2000000; /* D01 =1 */
56 DEV_EN |= 0x20000; /* PWM enable */ 56 DEV_EN |= DEV_PWM; /* PWM enable */
57 57
58 _backlight_on(); 58 _backlight_on();
59 return true; 59 return true;
diff --git a/firmware/target/arm/ipod/button-clickwheel.c b/firmware/target/arm/ipod/button-clickwheel.c
index f01666a8b8..f8dd818a01 100644
--- a/firmware/target/arm/ipod/button-clickwheel.c
+++ b/firmware/target/arm/ipod/button-clickwheel.c
@@ -73,64 +73,40 @@ int int_btn = BUTTON_NONE;
73 73
74static void opto_i2c_init(void) 74static void opto_i2c_init(void)
75{ 75{
76 int i, curr_value; 76 DEV_EN |= DEV_OPTO;
77 77 DEV_RS |= DEV_OPTO;
78 /* wait for value to settle */
79 i = 1000;
80 curr_value = (inl(0x7000c104) << 16) >> 24;
81 while (i > 0)
82 {
83 int new_value = (inl(0x7000c104) << 16) >> 24;
84
85 if (new_value != curr_value) {
86 i = 10000;
87 curr_value = new_value;
88 }
89 else {
90 i--;
91 }
92 }
93
94 GPIOB_OUTPUT_VAL |= 0x10;
95 DEV_EN |= 0x10000;
96 DEV_RS |= 0x10000;
97 udelay(5); 78 udelay(5);
98 DEV_RS &= ~0x10000; /* finish reset */ 79 DEV_RS &= ~DEV_OPTO; /* finish reset */
80 DEV_INIT1 |= INIT_BUTTONS; /* enable buttons (needed for "hold"-detection) */
99 81
100 outl(0xffffffff, 0x7000c120);
101 outl(0xffffffff, 0x7000c124);
102 outl(0xc00a1f00, 0x7000c100); 82 outl(0xc00a1f00, 0x7000c100);
103 outl(0x1000000, 0x7000c104); 83 outl(0x01000000, 0x7000c104);
104} 84}
105 85
106static inline int ipod_4g_button_read(void) 86static inline int ipod_4g_button_read(void)
107{ 87{
108 int whl = -1; 88 int whl = -1;
89 int btn = BUTTON_NONE;
109 90
110 /* The ipodlinux source had a udelay(250) here, but testing has shown that 91 /* The following delay was 250 in the ipodlinux source, but 50 seems to
111 it is not needed - tested on Nano, Color/Photo and Video. */ 92 work fine - tested on Nano, Color/Photo and Video. */
112 /* udelay(250);*/ 93 udelay(50);
113 94
114 int btn = BUTTON_NONE; 95 if ((inl(0x7000c104) & 0x04000000) != 0)
115 unsigned reg = 0x7000c104;
116 if ((inl(0x7000c104) & 0x4000000) != 0)
117 { 96 {
118 unsigned status = inl(0x7000c140); 97 unsigned status = inl(0x7000c140);
119 98
120 reg = reg + 0x3C; /* 0x7000c140 */
121 outl(0x0, 0x7000c140); /* clear interrupt status? */
122
123 if ((status & 0x800000ff) == 0x8000001a) 99 if ((status & 0x800000ff) == 0x8000001a)
124 { 100 {
125 if (status & 0x100) 101 if (status & 0x00000100)
126 btn |= BUTTON_SELECT; 102 btn |= BUTTON_SELECT;
127 if (status & 0x200) 103 if (status & 0x00000200)
128 btn |= BUTTON_RIGHT; 104 btn |= BUTTON_RIGHT;
129 if (status & 0x400) 105 if (status & 0x00000400)
130 btn |= BUTTON_LEFT; 106 btn |= BUTTON_LEFT;
131 if (status & 0x800) 107 if (status & 0x00000800)
132 btn |= BUTTON_PLAY; 108 btn |= BUTTON_PLAY;
133 if (status & 0x1000) 109 if (status & 0x00001000)
134 btn |= BUTTON_MENU; 110 btn |= BUTTON_MENU;
135 if (status & 0x40000000) 111 if (status & 0x40000000)
136 { 112 {
@@ -263,19 +239,10 @@ static inline int ipod_4g_button_read(void)
263 } 239 }
264 240
265 } 241 }
266 else if (status == 0xffffffff)
267 {
268 opto_i2c_init();
269 }
270 } 242 }
271 243
272 if ((inl(reg) & 0x8000000) != 0)
273 {
274 outl(0xffffffff, 0x7000c120);
275 outl(0xffffffff, 0x7000c124);
276 }
277 /* Save the new absolute wheel position */
278#ifdef HAVE_WHEEL_POSITION 244#ifdef HAVE_WHEEL_POSITION
245 /* Save the new absolute wheel position */
279 wheel_position = whl; 246 wheel_position = whl;
280#endif 247#endif
281 return btn; 248 return btn;
@@ -296,16 +263,12 @@ void wheel_send_events(bool send)
296void ipod_4g_button_int(void) 263void ipod_4g_button_int(void)
297{ 264{
298 CPU_HI_INT_CLR = I2C_MASK; 265 CPU_HI_INT_CLR = I2C_MASK;
299 /* The following delay was 250 in the ipodlinux source, but 50 seems to 266
300 work fine - tested on Nano, Color/Photo and Video. */
301 udelay(50);
302 outl(0x0, 0x7000c140);
303 int_btn = ipod_4g_button_read(); 267 int_btn = ipod_4g_button_read();
304 outl(inl(0x7000c104) | 0xC000000, 0x7000c104); 268
269 outl(inl(0x7000c104) | 0x0c000000, 0x7000c104);
305 outl(0x400a1f00, 0x7000c100); 270 outl(0x400a1f00, 0x7000c100);
306 271
307 GPIOB_OUTPUT_VAL |= 0x10;
308 CPU_INT_EN = 0x40000000;
309 CPU_HI_INT_EN = I2C_MASK; 272 CPU_HI_INT_EN = I2C_MASK;
310} 273}
311 274
@@ -317,15 +280,8 @@ void button_init_device(void)
317 GPIOA_ENABLE |= 0x20; 280 GPIOA_ENABLE |= 0x20;
318 GPIOA_OUTPUT_EN &= ~0x20; 281 GPIOA_OUTPUT_EN &= ~0x20;
319 282
320 /* hold button - set interrupt levels */
321 GPIOA_INT_LEV = ~(GPIOA_INPUT_VAL & 0x20);
322 GPIOA_INT_CLR = GPIOA_INT_STAT & 0x20;
323
324 /* enable interrupts */
325 GPIOA_INT_EN = 0x20;
326
327 /* unmask interrupt */ 283 /* unmask interrupt */
328 CPU_INT_EN = 0x40000000; 284 CPU_INT_EN = HI_MASK;
329 CPU_HI_INT_EN = I2C_MASK; 285 CPU_HI_INT_EN = I2C_MASK;
330} 286}
331 287
@@ -342,7 +298,20 @@ int button_read_device(void)
342 hold_button = button_hold(); 298 hold_button = button_hold();
343 299
344 if (hold_button != hold_button_old) 300 if (hold_button != hold_button_old)
301 {
345 backlight_hold_changed(hold_button); 302 backlight_hold_changed(hold_button);
303
304 if (hold_button)
305 {
306 /* lock -> disable wheel sensor */
307 DEV_EN &= ~DEV_OPTO;
308 }
309 else
310 {
311 /* unlock -> enable wheel sensor */
312 DEV_EN |= DEV_OPTO;
313 }
314 }
346 315
347 /* The int_btn variable is set in the button interrupt handler */ 316 /* The int_btn variable is set in the button interrupt handler */
348 return int_btn; 317 return int_btn;
diff --git a/firmware/target/arm/ipod/power-ipod.c b/firmware/target/arm/ipod/power-ipod.c
index 4c6f6a8db5..475e55c732 100644
--- a/firmware/target/arm/ipod/power-ipod.c
+++ b/firmware/target/arm/ipod/power-ipod.c
@@ -70,14 +70,26 @@ void ide_power_enable(bool on)
70#elif defined(IPOD_4G) || defined(IPOD_COLOR) \ 70#elif defined(IPOD_4G) || defined(IPOD_COLOR) \
71 || defined(IPOD_MINI) || defined(IPOD_MINI2G) 71 || defined(IPOD_MINI) || defined(IPOD_MINI2G)
72 if (on) 72 if (on)
73 {
73 GPIO_CLEAR_BITWISE(GPIOJ_OUTPUT_VAL, 0x04); 74 GPIO_CLEAR_BITWISE(GPIOJ_OUTPUT_VAL, 0x04);
75 DEV_EN |= DEV_IDE0;
76 }
74 else 77 else
78 {
79 DEV_EN &= ~DEV_IDE0;
75 GPIO_SET_BITWISE(GPIOJ_OUTPUT_VAL, 0x04); 80 GPIO_SET_BITWISE(GPIOJ_OUTPUT_VAL, 0x04);
81 }
76#elif defined(IPOD_VIDEO) 82#elif defined(IPOD_VIDEO)
77 if (on) 83 if (on)
84 {
78 GPO32_VAL &= ~0x40000000; 85 GPO32_VAL &= ~0x40000000;
86 DEV_EN |= DEV_IDE0;
87 }
79 else 88 else
89 {
90 DEV_EN &= ~DEV_IDE0;
80 GPO32_VAL |= 0x40000000; 91 GPO32_VAL |= 0x40000000;
92 }
81#else /* Nano */ 93#else /* Nano */
82 (void)on; /* Do nothing. */ 94 (void)on; /* Do nothing. */
83#endif 95#endif
diff --git a/firmware/target/arm/ipod/powermgmt-ipod-pcf.c b/firmware/target/arm/ipod/powermgmt-ipod-pcf.c
index d2f88a20f2..aaf4fabf52 100644
--- a/firmware/target/arm/ipod/powermgmt-ipod-pcf.c
+++ b/firmware/target/arm/ipod/powermgmt-ipod-pcf.c
@@ -27,7 +27,7 @@ const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
27#ifdef IPOD_NANO 27#ifdef IPOD_NANO
28 3330 28 3330
29#elif defined IPOD_VIDEO 29#elif defined IPOD_VIDEO
30 3450 30 3300
31#else 31#else
32 /* FIXME: calibrate value for other 3G+ ipods */ 32 /* FIXME: calibrate value for other 3G+ ipods */
33 3380 33 3380
@@ -39,7 +39,7 @@ const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
39#ifdef IPOD_NANO 39#ifdef IPOD_NANO
40 3230 40 3230
41#elif defined IPOD_VIDEO 41#elif defined IPOD_VIDEO
42 3450 42 3300
43#else 43#else
44 /* FIXME: calibrate value for other 3G+ ipods */ 44 /* FIXME: calibrate value for other 3G+ ipods */
45 3020 45 3020
diff --git a/firmware/target/arm/system-pp502x.c b/firmware/target/arm/system-pp502x.c
index 4ca58208ad..0b5e9e1c13 100644
--- a/firmware/target/arm/system-pp502x.c
+++ b/firmware/target/arm/system-pp502x.c
@@ -161,97 +161,118 @@ void set_cpu_frequency(long frequency)
161#else 161#else
162static void pp_set_cpu_frequency(long frequency) 162static void pp_set_cpu_frequency(long frequency)
163#endif 163#endif
164{ 164{
165#if defined(HAVE_ADJUSTABLE_CPU_FREQ) && (NUM_CORES > 1) 165#if defined(HAVE_ADJUSTABLE_CPU_FREQ) && (NUM_CORES > 1)
166 spinlock_lock(&boostctrl_spin); 166 spinlock_lock(&boostctrl_spin);
167#endif 167#endif
168 168
169 scale_suspend_core(true);
170
171 cpu_frequency = frequency;
172
173 switch (frequency) 169 switch (frequency)
174 { 170 {
175 /* Note: The PP5022 PLL must be run at >= 96MHz 171 /* Note1: The PP5022 PLL must be run at >= 96MHz
176 * Bits 20..21 select the post divider (1/2/4/8). 172 * Bits 20..21 select the post divider (1/2/4/8).
177 * PP5026 is similar to PP5022 except it doesn't 173 * PP5026 is similar to PP5022 except it doesn't
178 * have this limitation (and the post divider?) */ 174 * have this limitation (and the post divider?)
175 * Note2: CLOCK_SOURCE is set via 0=32kHz, 1=16MHz,
176 * 2=24MHz, 3=33MHz, 4=48MHz, 5=SLOW, 6=FAST, 7=PLL.
177 * SLOW = 24MHz / (DIV_SLOW + 1), DIV = Bits 16-19
178 * FAST = PLL / (DIV_FAST + 1), DIV = Bits 20-23 */
179 case CPUFREQ_SLEEP:
180 cpu_frequency = CPUFREQ_SLEEP;
181 PLL_CONTROL |= 0x0c000000;
182 scale_suspend_core(true);
183 CLOCK_SOURCE = 0x20000000; /* source #1, #2, #3, #4: 32kHz (#2 active) */
184 scale_suspend_core(false);
185 PLL_CONTROL &= ~0x80000000; /* disable PLL */
186 DEV_INIT2 &= ~INIT_PLL; /* disable PLL power */
187 break;
188
179 case CPUFREQ_MAX: 189 case CPUFREQ_MAX:
180 CLOCK_SOURCE = 0x10007772; /* source #1: 24MHz, #2, #3, #4: PLL */ 190 cpu_frequency = CPUFREQ_MAX;
181 DEV_TIMING1 = 0x00000303; 191 DEV_INIT2 |= INIT_PLL; /* enable PLL power */
182#ifdef IPOD_NANO 192 PLL_CONTROL |= 0x88000000; /* enable PLL */
183 IDE0_CFG |= (0x10000000); /* Set CPU > 65MHz bit */ 193 scale_suspend_core(true);
184#endif 194 CLOCK_SOURCE = 0x20002222; /* source #1, #2, #3, #4: 24MHz (#2 active) */
185#ifdef IPOD_MINI2G 195 DEV_TIMING1 = 0x00000303;
196 scale_suspend_core(false);
197#if defined(IPOD_MINI2G)
186 MLCD_SCLK_DIV = 0x00000001; /* Mono LCD bridge serial clock divider */ 198 MLCD_SCLK_DIV = 0x00000001; /* Mono LCD bridge serial clock divider */
199#elif defined(IPOD_NANO)
200 IDE0_CFG |= 0x10000000; /* set ">65MHz" bit */
187#endif 201#endif
188#if CONFIG_CPU == PP5020 202#if CONFIG_CPU == PP5020
189 PLL_CONTROL = 0x8a020a03; /* 10/3 * 24MHz */ 203 PLL_CONTROL = 0x8a020a03; /* 80 MHz = 10/3 * 24MHz */
190 PLL_STATUS = 0xd19b; /* unlock frequencies > 66MHz */ 204 PLL_STATUS = 0xd19b; /* unlock frequencies > 66MHz */
191 PLL_CONTROL = 0x8a020a03; /* repeat setup */ 205 PLL_CONTROL = 0x8a020a03; /* repeat setup */
192 scale_suspend_core(false);
193 udelay(500); /* wait for relock */ 206 udelay(500); /* wait for relock */
194#elif (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024) 207#elif (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024)
195 PLL_CONTROL = 0x8a121403; /* (20/3 * 24MHz) / 2 */ 208 PLL_CONTROL = 0x8a121403; /* 80 MHz = (20/3 * 24MHz) / 2 */
196 scale_suspend_core(false);
197 udelay(250);
198 while (!(PLL_STATUS & 0x80000000)); /* wait for relock */ 209 while (!(PLL_STATUS & 0x80000000)); /* wait for relock */
199#endif 210#endif
200 scale_suspend_core(true); 211 scale_suspend_core(true);
212 DEV_TIMING1 = 0x00000808;
213 CLOCK_SOURCE = 0x20007777; /* source #1, #2, #3, #4: PLL (#2 active) */
214 scale_suspend_core(false);
201 break; 215 break;
202 216#if 0 /******** CPUFREQ_NORMAL = 24MHz without PLL ********/
203 case CPUFREQ_NORMAL: 217 case CPUFREQ_NORMAL:
204 CLOCK_SOURCE = 0x10007772; /* source #1: 24MHz, #2, #3, #4: PLL */ 218 cpu_frequency = CPUFREQ_NORMAL;
205 DEV_TIMING1 = 0x00000303; 219 PLL_CONTROL |= 0x08000000;
206#ifdef IPOD_NANO 220 scale_suspend_core(true);
207 IDE0_CFG &=~(0x10000000); /* clear > 65MHz bit */ 221 CLOCK_SOURCE = 0x20002222; /* source #1, #2, #3, #4: 24MHz (#2 active) */
222 DEV_TIMING1 = 0x00000303;
223#if defined(IPOD_MINI2G)
224 MLCD_SCLK_DIV = 0x00000000; /* Mono LCD bridge serial clock divider */
225#elif defined(IPOD_NANO)
226 IDE0_CFG &= ~0x10000000; /* clear ">65MHz" bit */
208#endif 227#endif
209#ifdef IPOD_MINI2G 228 scale_suspend_core(false);
210 MLCD_SCLK_DIV = 0x00000000; /* Mono LCD bridge serial clock divider */ 229 PLL_CONTROL &= ~0x80000000; /* disable PLL */
230 DEV_INIT2 &= ~INIT_PLL; /* disable PLL power */
231 break;
232#else /******** CPUFREQ_NORMAL = 30MHz with PLL ********/
233 case CPUFREQ_NORMAL:
234 cpu_frequency = CPUFREQ_NORMAL;
235 DEV_INIT2 |= INIT_PLL; /* enable PLL power */
236 PLL_CONTROL |= 0x88000000; /* enable PLL */
237 scale_suspend_core(true);
238 CLOCK_SOURCE = 0x20002222; /* source #1, #2, #3, #4: 24MHz (#2 active) */
239 DEV_TIMING1 = 0x00000303;
240 scale_suspend_core(false);
241#if defined(IPOD_MINI2G)
242 MLCD_SCLK_DIV = 0x00000000; /* Mono LCD bridge serial clock divider */
243#elif defined(IPOD_NANO)
244 IDE0_CFG &= ~0x10000000; /* clear ">65MHz" bit */
211#endif 245#endif
212#if CONFIG_CPU == PP5020 246#if CONFIG_CPU == PP5020
213 PLL_CONTROL = 0x8a020504; /* 5/4 * 24MHz */ 247 PLL_CONTROL = 0x8a020504; /* 30 MHz = 5/4 * 24MHz */
214 scale_suspend_core(false);
215 udelay(500); /* wait for relock */ 248 udelay(500); /* wait for relock */
216#elif (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024) 249#elif (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024)
217 PLL_CONTROL = 0x8a220501; /* (5/1 * 24MHz) / 4 */ 250 PLL_CONTROL = 0x8a220501; /* 30 MHz = (5/1 * 24MHz) / 4 */
218 scale_suspend_core(false);
219 udelay(250);
220 while (!(PLL_STATUS & 0x80000000)); /* wait for relock */ 251 while (!(PLL_STATUS & 0x80000000)); /* wait for relock */
221#endif 252#endif
222 scale_suspend_core(true); 253 scale_suspend_core(true);
223 break; 254 DEV_TIMING1 = 0x00000808;
224 255 CLOCK_SOURCE = 0x20007777; /* source #1, #2, #3, #4: PLL (#2 active) */
225 case CPUFREQ_SLEEP:
226 CLOCK_SOURCE = 0x10002202; /* source #2: 32kHz, #1, #3, #4: 24MHz */
227 PLL_CONTROL &= ~0x80000000; /* disable PLL */
228 scale_suspend_core(false); 256 scale_suspend_core(false);
229 udelay(10000); /* let 32kHz source stabilize? */
230 scale_suspend_core(true);
231 break; 257 break;
232 258#endif /******** CPUFREQ_NORMAL end ********/
233 default: 259 default:
234 CLOCK_SOURCE = 0x10002222; /* source #1, #2, #3, #4: 24MHz */ 260 cpu_frequency = CPUFREQ_DEFAULT;
235 DEV_TIMING1 = 0x00000303; 261 PLL_CONTROL |= 0x08000000;
236#ifdef IPOD_MINI2G 262 scale_suspend_core(true);
237 MLCD_SCLK_DIV = 0x00000000; /* Mono LCD bridge serial clock divider */ 263 CLOCK_SOURCE = 0x20002222; /* source #1, #2, #3, #4: 24MHz (#2 active) */
238#endif 264 DEV_TIMING1 = 0x00000303;
239#ifdef IPOD_NANO 265#if defined(IPOD_MINI2G)
240 IDE0_CFG &=~(0x10000000); /* clear > 65MHz bit */ 266 MLCD_SCLK_DIV = 0x00000000; /* Mono LCD bridge serial clock divider */
267#elif defined(IPOD_NANO)
268 IDE0_CFG &= ~0x10000000; /* clear ">65MHz" bit */
241#endif 269#endif
242 PLL_CONTROL &= ~0x80000000; /* disable PLL */ 270 scale_suspend_core(false);
243 cpu_frequency = CPUFREQ_DEFAULT; 271 PLL_CONTROL &= ~0x80000000; /* disable PLL */
244 PROC_CTL(CURRENT_CORE) = 0x4800001f; nop; 272 DEV_INIT2 &= ~INIT_PLL; /* disable PLL power */
245 break; 273 break;
246 } 274 }
247 275
248 if (frequency == CPUFREQ_MAX)
249 DEV_TIMING1 = 0x00000808;
250
251 CLOCK_SOURCE = (CLOCK_SOURCE & ~0xf0000000) | 0x20000000; /* select source #2 */
252
253 scale_suspend_core(false);
254
255#if defined(HAVE_ADJUSTABLE_CPU_FREQ) && (NUM_CORES > 1) 276#if defined(HAVE_ADJUSTABLE_CPU_FREQ) && (NUM_CORES > 1)
256 spinlock_unlock(&boostctrl_spin); 277 spinlock_unlock(&boostctrl_spin);
257#endif 278#endif
@@ -263,19 +284,84 @@ void system_init(void)
263#ifndef BOOTLOADER 284#ifndef BOOTLOADER
264 if (CURRENT_CORE == CPU) 285 if (CURRENT_CORE == CPU)
265 { 286 {
266#if defined(SANSA_E200) || defined(SANSA_C200) 287#if defined (IRIVER_H10) || defined(IRIVER_H10_5GB) || defined(IPOD_COLOR)
267 /* Reset all devices */ 288 /* set minimum startup configuration */
268 DEV_RS2 |= 0x20; 289 DEV_EN = 0xc2000124;
269 DEV_RS = 0x3bfffef8; 290 DEV_EN2 = 0x00002000;
270 DEV_RS2 = -1; 291 CACHE_PRIORITY = 0x0000003f;
271 DEV_RS = 0; 292 GPO32_VAL = 0x20000000;
272 DEV_RS2 = 0; 293 DEV_INIT1 = 0xdc000000;
273#elif defined (IRIVER_H10) || defined(MROBE_100) 294 DEV_INIT2 = 0x40000000;
274 DEV_RS = 0x3ffffef8; 295
275 DEV_RS2 = -1; 296 /* reset all allowed devices */
276 DEV_RS = 0; 297 DEV_RS = 0x3ffffef8;
277 DEV_RS2 = 0; 298 DEV_RS2 = 0xffffdfff;
278 outl(inl(0x70000024) | 0xc0, 0x70000024); 299 DEV_RS = 0x00000000;
300 DEV_RS2 = 0x00000000;
301#elif defined (IPOD_VIDEO)
302 /* set minimum startup configuration */
303 DEV_EN = 0xc2000124;
304 DEV_EN2 = 0x00000000;
305 CACHE_PRIORITY = 0x0000003f;
306 GPO32_VAL = 0x00004000;
307 DEV_INIT1 = 0x00000000;
308 DEV_INIT2 = 0x40000000;
309
310 /* reset all allowed devices */
311 DEV_RS = 0x3ffffef8;
312 DEV_RS2 = 0xffffffff;
313 DEV_RS = 0x00000000;
314 DEV_RS2 = 0x00000000;
315#elif defined (IPOD_NANO)
316 /* set minimum startup configuration */
317 DEV_EN = 0xc2000124;
318 DEV_EN2 = 0x00002000;
319 CACHE_PRIORITY = 0x0000003f;
320 GPO32_VAL = 0x50000000;
321 DEV_INIT1 = 0xa8000000;
322 DEV_INIT2 = 0x40000000;
323
324 /* reset all allowed devices */
325 DEV_RS = 0x3ffffef8;
326 DEV_RS2 = 0xffffdfff;
327 DEV_RS = 0x00000000;
328 DEV_RS2 = 0x00000000;
329#elif defined(SANSA_C200) || defined (SANSA_E200)
330 /* set minimum startup configuration */
331 DEV_EN = 0xc4000124;
332 DEV_EN2 = 0x00000000;
333 CACHE_PRIORITY = 0x0000003f;
334 GPO32_VAL = 0x10000000;
335 DEV_INIT1 = 0x54000000;
336 DEV_INIT2 = 0x40000000;
337
338 /* reset all allowed devices */
339 DEV_RS = 0x3bfffef8;
340 DEV_RS2 = 0xffffffff;
341 DEV_RS = 0x00000000;
342 DEV_RS2 = 0x00000000;
343#elif defined(IPOD_4G)
344 /* set minimum startup configuration */
345 DEV_EN = 0xc2020124;
346 DEV_EN2 = 0x00000000;
347 CACHE_PRIORITY = 0x0000003f;
348 GPO32_VAL = 0x02000000;
349 DEV_INIT1 = 0x00000000;
350 DEV_INIT2 = 0x40000000;
351
352 /* reset all allowed devices */
353 DEV_RS = 0x3ffdfef8;
354 DEV_RS2 = 0xffffffff;
355 DEV_RS = 0x00000000;
356 DEV_RS2 = 0x00000000;
357#elif defined (IPOD_MINI)
358 /* to be done */
359#elif defined (IPOD_MINI2G)
360 /* to be done */
361#elif defined (MROBE_100)
362 /* to be done */
363#elif defined (ELIO_TPJ1022)
364 /* to be done */
279#endif 365#endif
280 366
281#if !defined(SANSA_E200) && !defined(SANSA_C200) 367#if !defined(SANSA_E200) && !defined(SANSA_C200)
@@ -314,8 +400,6 @@ void system_init(void)
314 outl(inl(0x6000a000) | 0x80000000, 0x6000a000); /* Init DMA controller? */ 400 outl(inl(0x6000a000) | 0x80000000, 0x6000a000); /* Init DMA controller? */
315#endif 401#endif
316 402
317 DEV_INIT2 |= 1 << 30; /* enable PLL power */
318
319#ifdef HAVE_ADJUSTABLE_CPU_FREQ 403#ifdef HAVE_ADJUSTABLE_CPU_FREQ
320#if NUM_CORES > 1 404#if NUM_CORES > 1
321 cpu_boost_init(); 405 cpu_boost_init();
diff --git a/firmware/target/arm/usb-fw-pp502x.c b/firmware/target/arm/usb-fw-pp502x.c
index 7af699c064..0813ae1c59 100644
--- a/firmware/target/arm/usb-fw-pp502x.c
+++ b/firmware/target/arm/usb-fw-pp502x.c
@@ -33,18 +33,29 @@
33void usb_init_device(void) 33void usb_init_device(void)
34{ 34{
35 /* enable usb module */ 35 /* enable usb module */
36 GPO32_ENABLE |= 0x200;
37
38 outl(inl(0x7000002C) | 0x3000000, 0x7000002C); 36 outl(inl(0x7000002C) | 0x3000000, 0x7000002C);
39 DEV_EN |= DEV_USB; 37 DEV_EN |= DEV_USB0;
38 DEV_EN |= DEV_USB1;
40 39
41 DEV_RS |= DEV_USB; /* reset usb start */ 40 /* reset both USBs */
42 DEV_RS &=~DEV_USB;/* reset usb end */ 41 DEV_RS |= DEV_USB0;
42 DEV_RS &=~DEV_USB0;
43 DEV_RS |= DEV_USB1;
44 DEV_RS &=~DEV_USB1;
43 45
46#if CONFIG_CPU == PP5020
44 DEV_INIT2 |= INIT_USB; 47 DEV_INIT2 |= INIT_USB;
48#endif
45 while ((inl(0x70000028) & 0x80) == 0); 49 while ((inl(0x70000028) & 0x80) == 0);
46 outl(inl(0x70000028) | 0x2, 0x70000028); 50 outl(inl(0x70000028) | 0x2, 0x70000028);
47 udelay(0x186A0); 51 udelay(0x186A0);
52
53 /* disable USB-devices until USB is detected via GPIO */
54 DEV_EN &= ~DEV_USB0;
55 DEV_EN &= ~DEV_USB1;
56#if CONFIG_CPU == PP5020
57 DEV_INIT2 &= ~INIT_USB;
58#endif
48 59
49#if defined(IPOD_COLOR) || defined(IPOD_4G) \ 60#if defined(IPOD_COLOR) || defined(IPOD_4G) \
50 || defined(IPOD_MINI) || defined(IPOD_MINI2G) 61 || defined(IPOD_MINI) || defined(IPOD_MINI2G)
@@ -85,33 +96,46 @@ void usb_enable(bool on)
85 96
86static bool usb_pin_detect(void) 97static bool usb_pin_detect(void)
87{ 98{
99 bool retval = false;
100
88#if defined(IPOD_4G) || defined(IPOD_COLOR) \ 101#if defined(IPOD_4G) || defined(IPOD_COLOR) \
89 || defined(IPOD_MINI) || defined(IPOD_MINI2G) 102 || defined(IPOD_MINI) || defined(IPOD_MINI2G)
90 /* GPIO D bit 3 is usb detect */ 103 /* GPIO D bit 3 is usb detect */
91 if (GPIOD_INPUT_VAL & 0x08) 104 if (GPIOD_INPUT_VAL & 0x08)
92 return true; 105 retval = true;
93 106
94#elif defined(IPOD_NANO) || defined(IPOD_VIDEO) 107#elif defined(IPOD_NANO) || defined(IPOD_VIDEO)
95 /* GPIO L bit 4 is usb detect */ 108 /* GPIO L bit 4 is usb detect */
96 if (GPIOL_INPUT_VAL & 0x10) 109 if (GPIOL_INPUT_VAL & 0x10)
97 return true; 110 retval = true;
98 111
99#elif defined(SANSA_C200) 112#elif defined(SANSA_C200)
100 /* GPIO H bit 1 is usb detect */ 113 /* GPIO H bit 1 is usb detect */
101 if (GPIOH_INPUT_VAL & 0x02) 114 if (GPIOH_INPUT_VAL & 0x02)
102 return true; 115 retval = true;
103 116
104#elif defined(SANSA_E200) 117#elif defined(SANSA_E200)
105 /* GPIO B bit 4 is usb detect */ 118 /* GPIO B bit 4 is usb detect */
106 if (GPIOB_INPUT_VAL & 0x10) 119 if (GPIOB_INPUT_VAL & 0x10)
107 return true; 120 retval = true;
108 121
109#elif defined(IRIVER_H10) || defined(IRIVER_H10_5GB) 122#elif defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
110 /* GPIO L bit 2 is usb detect */ 123 /* GPIO L bit 2 is usb detect */
111 if (GPIOL_INPUT_VAL & 0x4) 124 if (GPIOL_INPUT_VAL & 0x4)
112 return true; 125 retval = true;
113#endif 126#endif
114 return false; 127
128 /* if USB is detected, re-enable the USB-devices */
129 if (retval)
130 {
131 DEV_EN |= DEV_USB0;
132 DEV_EN |= DEV_USB1;
133#if CONFIG_CPU == PP5020
134 DEV_INIT2 |= INIT_USB;
135#endif
136 }
137
138 return retval;
115} 139}
116 140
117/* detect host or charger (INSERTED or POWERED) */ 141/* detect host or charger (INSERTED or POWERED) */
diff --git a/firmware/target/arm/wmcodec-pp.c b/firmware/target/arm/wmcodec-pp.c
index c9e034a188..3bd9d7fd2b 100644
--- a/firmware/target/arm/wmcodec-pp.c
+++ b/firmware/target/arm/wmcodec-pp.c
@@ -52,15 +52,15 @@ void audiohw_init(void) {
52 DEV_INIT1 &=~0x3000000; 52 DEV_INIT1 &=~0x3000000;
53 /*mini2?*/ 53 /*mini2?*/
54 54
55 /* device reset */ 55 /* I2S device reset */
56 DEV_RS |= DEV_I2S; 56 DEV_RS |= DEV_I2S;
57 DEV_RS &=~DEV_I2S; 57 DEV_RS &=~DEV_I2S;
58 58
59 /* device enable */ 59 /* I2S device enable */
60 DEV_EN |= (DEV_I2S | 0x7); 60 DEV_EN |= DEV_I2S;
61 61
62 /* enable external dev clock clocks */ 62 /* enable external dev clock clocks */
63 DEV_EN |= 0x2; 63 DEV_EN |= DEV_EXTCLOCKS;
64 64
65 /* external dev clock to 24MHz */ 65 /* external dev clock to 24MHz */
66 outl(inl(0x70000018) & ~0xc, 0x70000018); 66 outl(inl(0x70000018) & ~0xc, 0x70000018);