diff -ur rockbox-19370/apps/main.c rockbox-19370-batfix/apps/main.c --- rockbox-19370/apps/main.c 2008-12-09 12:28:39.000000000 -0500 +++ rockbox-19370-batfix/apps/main.c 2008-12-13 12:54:52.395300000 -0500 @@ -107,6 +107,10 @@ #include "cuesheet.h" +#if CONFIG_CHARGING && (CONFIG_CPU == SH7034) +#include "ata-target.h" +#endif + #ifdef SIMULATOR #include "system-sdl.h" #endif @@ -337,10 +341,6 @@ { int rc; bool mounted = false; -#if CONFIG_CHARGING && (CONFIG_CPU == SH7034) - /* if nobody initialized ATA before, I consider this a cold start */ - bool coldstart = (PACR2 & 0x4000) != 0; /* starting from Flash */ -#endif system_init(); kernel_init(); @@ -402,7 +402,11 @@ button_init(); +/* If ATA power is needed to measure battery voltage, delay until after + it is available */ +#ifndef NEED_ATA_POWER_BATT_MEASURE powermgmt_init(); +#endif #if CONFIG_TUNER radio_init(); @@ -412,22 +416,39 @@ gui_syncstatusbar_init(&statusbars); #if CONFIG_CHARGING && (CONFIG_CPU == SH7034) - if (coldstart && charger_inserted() - && !global_settings.car_adapter_mode -#ifdef ATA_POWER_PLAYERSTYLE - && !ide_powered() /* relies on probing result from bootloader */ -#endif - ) - { - rc = charging_screen(); /* display a "charging" screen */ - if (rc == 1) /* charger removed */ - power_off(); - /* "On" pressed or USB connected: proceed */ - show_logo(); /* again, to provide better visual feedback */ + /* if nobody initialized ATA before, I consider this a cold start */ + if (ata_is_coldstart()) /* starting from Flash */ + { + if (charger_inserted() + && !global_settings.car_adapter_mode +#if defined(ATA_POWER_PLAYERSTYLE) + && !ide_powered() +#endif + ) + { + rc = charging_screen(); /* display a "charging" screen */ + if (rc == 1) /* charger removed */ + power_off(); + /* "On" pressed or USB connected: proceed */ + show_logo(); /* again, to provide better visual feedback */ + } + +#if CONFIG_STORAGE == STORAGE_ATA && !defined(HAVE_ATA_POWER_OFF) + /* No way for ata_init() to see this is needed */ + ide_power_enable(true); + /* Not sure if necessary, but shouldn't slow things down + because we have to wait for spinup anyways */ + sleep(HZ/4); /* allow voltage to build up */ +#endif } #endif rc = storage_init(); +#ifdef NEED_ATA_POWER_BATT_MEASURE + /* ATA power may be turned on by ata_init() + if HAVE_ATA_POWER_OFF is defined */ + powermgmt_init(); +#endif if(rc) { #ifdef HAVE_LCD_BITMAP diff -ur rockbox-19370/apps/screens.c rockbox-19370-batfix/apps/screens.c --- rockbox-19370/apps/screens.c 2008-12-09 12:28:49.000000000 -0500 +++ rockbox-19370-batfix/apps/screens.c 2008-12-12 16:01:01.293100000 -0500 @@ -199,15 +199,17 @@ char buf[32]; (void)buf; -#ifdef NEED_ATA_POWER_BATT_MEASURE - if (ide_powered()) /* FM and V2 can only measure when ATA power is on */ +#if !defined(NEED_ATA_POWER_BATT_MEASURE) + int battv = battery_voltage(); + snprintf(buf, 32, " Batt: %d.%02dV %d%% ", battv / 1000, + (battv % 1000) / 10, battery_level()); + lcd_puts(0, 7, buf); +#elif defined(ARCHOS_FMRECORDER) || defined(ARCHOS_RECORDERV2) + /* IDE power is normally off here, display input current instead */ + snprintf(buf, 32, "%dmA ", + (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 10000); + lcd_puts(7, 7, buf); #endif - { - int battv = battery_voltage(); - snprintf(buf, 32, " Batt: %d.%02dV %d%% ", battv / 1000, - (battv % 1000) / 10, battery_level()); - lcd_puts(0, 7, buf); - } #if CONFIG_CHARGING == CHARGING_CONTROL diff -ur rockbox-19370/firmware/target/sh/archos/fm_v2/power-fm_v2.c rockbox-19370-batfix/firmware/target/sh/archos/fm_v2/power-fm_v2.c --- rockbox-19370/firmware/target/sh/archos/fm_v2/power-fm_v2.c 2008-12-09 12:29:00.000000000 -0500 +++ rockbox-19370-batfix/firmware/target/sh/archos/fm_v2/power-fm_v2.c 2008-12-11 13:39:18.917200000 -0500 @@ -105,7 +105,7 @@ return true; /* would be floating high, disk on */ else return (PADRL & 0x20) != 0; -#else /* !defined(NEEDS_ATA_POWER_ON) && !defined(HAVE_ATA_POWER_OFF) */ +#else /* !defined(HAVE_ATA_POWER_OFF) */ return true; /* pretend always powered if not controlable */ #endif } diff -ur rockbox-19370/firmware/target/sh/archos/player/power-player.c rockbox-19370-batfix/firmware/target/sh/archos/player/power-player.c --- rockbox-19370/firmware/target/sh/archos/player/power-player.c 2008-12-09 12:29:00.000000000 -0500 +++ rockbox-19370-batfix/firmware/target/sh/archos/player/power-player.c 2008-12-11 13:39:41.558400000 -0500 @@ -75,7 +75,7 @@ return false; /* would be floating low, disk off */ else return (PBDRL & 0x10) != 0; -#else /* !defined(NEEDS_ATA_POWER_ON) && !defined(HAVE_ATA_POWER_OFF) */ +#else /* !defined(HAVE_ATA_POWER_OFF) */ return true; /* pretend always powered if not controlable */ #endif } diff -ur rockbox-19370/firmware/target/sh/archos/recorder/power-recorder.c rockbox-19370-batfix/firmware/target/sh/archos/recorder/power-recorder.c --- rockbox-19370/firmware/target/sh/archos/recorder/power-recorder.c 2008-12-09 12:29:00.000000000 -0500 +++ rockbox-19370-batfix/firmware/target/sh/archos/recorder/power-recorder.c 2008-12-11 13:40:05.242800000 -0500 @@ -91,7 +91,7 @@ return true; /* would be floating high, disk on */ else return (PADRL & 0x20) != 0; -#else /* !defined(NEEDS_ATA_POWER_ON) && !defined(HAVE_ATA_POWER_OFF) */ +#else /* !defined(HAVE_ATA_POWER_OFF) */ return true; /* pretend always powered if not controlable */ #endif } diff -ur rockbox-19370/flash/bootbox/main.c rockbox-19370-batfix/flash/bootbox/main.c --- rockbox-19370/flash/bootbox/main.c 2008-12-09 12:29:01.000000000 -0500 +++ rockbox-19370-batfix/flash/bootbox/main.c 2008-12-11 13:29:23.386000000 -0500 @@ -168,6 +168,11 @@ } #endif +#if CONFIG_STORAGE == STORAGE_ATA && !defined(HAVE_ATA_POWER_OFF) + /* No way for ata_init() to see this is needed */ + ide_power_enable(true); +#endif + rc = storage_init(); if(rc) {