2006-08-12 08:01:54 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 by Linus Nielsen Feltzing
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2006-08-12 08:01:54 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "config.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "power.h"
|
|
|
|
#include "pcf50606.h"
|
2006-12-29 02:49:12 +00:00
|
|
|
#include "backlight.h"
|
|
|
|
#include "backlight-target.h"
|
2006-08-12 08:01:54 +00:00
|
|
|
|
|
|
|
#ifndef SIMULATOR
|
|
|
|
|
|
|
|
void power_init(void)
|
|
|
|
{
|
2007-05-15 00:22:51 +00:00
|
|
|
/* Initialize IDE power pin */
|
|
|
|
GPGCON=( GPGCON&~(1<<23) ) | (1<<22); /* Make the pin an output */
|
|
|
|
GPGUP |= 1<<11; /* Disable pullup in SOC as we are now driving */
|
|
|
|
ide_power_enable(true);
|
2006-08-12 08:01:54 +00:00
|
|
|
/* Charger detect */
|
|
|
|
}
|
|
|
|
|
|
|
|
bool charger_inserted(void)
|
|
|
|
{
|
2006-12-29 02:49:12 +00:00
|
|
|
return (GPFDAT & (1 << 4)) ? false : true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns true if the unit is charging the batteries. */
|
|
|
|
bool charging_state(void) {
|
|
|
|
return (GPGDAT & (1 << 8)) ? false : true;
|
2006-08-12 08:01:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ide_power_enable(bool on)
|
|
|
|
{
|
2006-12-29 02:49:12 +00:00
|
|
|
if (on)
|
|
|
|
GPGDAT |= (1 << 11);
|
|
|
|
else
|
|
|
|
GPGDAT &= ~(1 << 11);
|
2006-08-12 08:01:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ide_powered(void)
|
|
|
|
{
|
2006-12-29 02:49:12 +00:00
|
|
|
return (GPGDAT & (1 << 11)) != 0;
|
2006-08-12 08:01:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void power_off(void)
|
|
|
|
{
|
2008-09-26 03:08:19 +00:00
|
|
|
int(*reboot_point)(void);
|
|
|
|
reboot_point=(void*)(unsigned char*) 0x00000000;
|
2006-12-29 02:49:12 +00:00
|
|
|
/* turn off backlight and wait for 1 second */
|
2007-11-12 18:49:53 +00:00
|
|
|
_backlight_off();
|
|
|
|
_buttonlight_off();
|
2007-05-10 03:08:47 +00:00
|
|
|
sleep(HZ);
|
2008-11-12 03:57:32 +00:00
|
|
|
|
|
|
|
/* Do this to allow the drive to properly reset when player restarts
|
|
|
|
* immediately without running OF shutdown.
|
|
|
|
*/
|
|
|
|
GPGCON&=~0x00300000;
|
2008-09-26 03:08:19 +00:00
|
|
|
|
|
|
|
/* Rockbox never properly shutdown the player. When the sleep bit is set
|
|
|
|
* the player actually wakes up in some type of "zombie" state
|
|
|
|
* because the shutdown routine is not set up properly. So far the
|
|
|
|
* shutdown routines tried leave the player consuming excess power
|
|
|
|
* so we rely on the OF to shut everything down instead. (mmu apears to be
|
|
|
|
* reset when the sleep bit is set)
|
|
|
|
*/
|
2006-12-29 02:49:12 +00:00
|
|
|
CLKCON |=(1<<3);
|
2008-09-26 03:08:19 +00:00
|
|
|
|
|
|
|
reboot_point();
|
2008-11-12 03:57:32 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
|
|
GPBCON=0x00015450;
|
|
|
|
GPBDAT=0x403;
|
|
|
|
GPBUP=0x3FD;
|
|
|
|
|
|
|
|
GPCCON =0xAAA054A8;
|
|
|
|
GPCDAT =0x0000038C;
|
|
|
|
GPCUP =0xFFFF;
|
|
|
|
|
|
|
|
|
|
|
|
GPDCON =0xAAA0AAA5;
|
|
|
|
GPDDAT =0x00000300;
|
|
|
|
GPDUP =0xFCFF;
|
|
|
|
|
|
|
|
|
|
|
|
GPECON =0xAA8002AA;
|
|
|
|
GPEDAT =0x0000FFED;
|
|
|
|
GPEUP =0x3817;
|
|
|
|
|
|
|
|
GPFCON =0x00000a00;
|
|
|
|
GPFDAT =0x000000F1;
|
|
|
|
GPFUP =0x000000FF;
|
|
|
|
|
|
|
|
GPGCON =0x01401002;
|
|
|
|
GPGDAT =0x00000180;
|
|
|
|
GPGUP =0x0000FF7F;
|
|
|
|
|
|
|
|
GPHCON =0x001540A5;
|
|
|
|
GPHDAT =0x000006FD;
|
|
|
|
GPHUP =0x00000187;
|
|
|
|
|
|
|
|
// mine
|
|
|
|
INTMSK =0xFFFFFFFF;
|
|
|
|
EINTMASK=0x0FFFFEF0;
|
|
|
|
EXTINT0 =0xFFFFFECF;
|
|
|
|
EXTINT1 =0x07;
|
|
|
|
//
|
|
|
|
|
|
|
|
// INTMSK=0xFFFFFFFF;
|
|
|
|
// EINTMASK=0x00200000;
|
|
|
|
|
|
|
|
// GPHDAT=0x00000004;
|
|
|
|
|
|
|
|
// EXTINT0=~0x00000130;
|
|
|
|
// INTMSK=(~0x00000130)+0x00000100;
|
|
|
|
// GPGUP=0xFFFFFFFF;
|
|
|
|
|
|
|
|
//mine
|
|
|
|
INTMSK =0xFFFFFFDE;
|
|
|
|
//
|
|
|
|
|
|
|
|
SRCPND=0xFFFFFFFF;
|
|
|
|
INTPND=0xFFFFFFFF;
|
|
|
|
GSTATUS1=0x00000600;
|
|
|
|
|
|
|
|
ADCCON=0x00000004;
|
|
|
|
|
|
|
|
// MISCCR=MISCCR&(~0x703000)|0x603000;
|
|
|
|
LCDCON1=0x00000000;
|
|
|
|
LOCKTIME=0xFFFFFFFF;
|
|
|
|
// REFRESH=REFRESH|0x00400000;
|
|
|
|
|
|
|
|
// MISCCR=MISCCR|0x000E0000;
|
|
|
|
|
|
|
|
// CLKCON=CLKCON|0x00004018;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This next piece of code was taken from the linux 2.6.17 sources:
|
|
|
|
* linux/arch/arm/mach-s3c2410/sleep.S
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004 Simtec Electronics
|
|
|
|
* Ben Dooks <ben@simtec.co.uk>
|
|
|
|
*
|
|
|
|
* Based on PXA/SA1100 sleep code by:
|
|
|
|
* Nicolas Pitre, (c) 2002 Monta Vista Software Inc
|
|
|
|
* Cliff Brake, (c) 2001
|
|
|
|
*/
|
|
|
|
|
|
|
|
asm volatile
|
|
|
|
(
|
|
|
|
/* get REFRESH, MISCCR, and CLKCON (and ensure in TLB) */
|
|
|
|
"ldr r4, =0x48000024 \n"
|
|
|
|
"ldr r5, =0x56000080 \n"
|
|
|
|
"ldr r6, =0x4C00000C \n"
|
|
|
|
"ldr r7, [ r4 ] \n"
|
|
|
|
"ldr r8, [ r5 ] \n"
|
|
|
|
"ldr r9, [ r6 ] \n"
|
|
|
|
|
|
|
|
/* Setup register writes */
|
|
|
|
"ldr r2, =0x006E3000 \n"
|
|
|
|
"ldr r3, =0x00004018 \n"
|
|
|
|
"orr r7, r7, #0x00400000 \n" /* SDRAM sleep command */
|
|
|
|
"orr r8, r8, r2 \n" /* SDRAM power-down signals */
|
|
|
|
"orr r9, r9, r3 \n" /* power down command */
|
|
|
|
|
|
|
|
/* first as a trial-run to load cache */
|
|
|
|
"teq pc, #0 \n"
|
|
|
|
"bl s3c2410_do_sleep \n"
|
|
|
|
|
|
|
|
/* now do it for real */
|
|
|
|
"teq r0, r0 \n"
|
|
|
|
"b s3c2410_do_sleep \n"
|
|
|
|
|
|
|
|
/* align next bit of code to cache line */
|
|
|
|
".align 8 \n"
|
|
|
|
"s3c2410_do_sleep: \n"
|
|
|
|
"streq r7, [ r4 ] \n" /* SDRAM sleep command */
|
|
|
|
"streq r8, [ r5 ] \n" /* SDRAM power-down config */
|
|
|
|
"streq r3, [ r6 ] \n" /* CPU sleep */
|
|
|
|
"1: \n"
|
|
|
|
"beq 1b \n"
|
|
|
|
"bx lr \n"
|
|
|
|
);
|
|
|
|
#endif
|
2006-08-12 08:01:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#else /* SIMULATOR */
|
|
|
|
|
|
|
|
bool charger_inserted(void)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void charger_enable(bool on)
|
|
|
|
{
|
|
|
|
(void)on;
|
|
|
|
}
|
|
|
|
|
|
|
|
void power_off(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ide_power_enable(bool on)
|
|
|
|
{
|
|
|
|
(void)on;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* SIMULATOR */
|
|
|
|
|