Implemented iPod Nano 2G power_off()

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23014 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Michael Sparmann 2009-10-08 20:56:51 +00:00
parent 32b367b042
commit 1fa5d49380
4 changed files with 79 additions and 23 deletions

View file

@ -24,21 +24,7 @@
#include "i2c-s5l8700.h"
static struct mutex pmu_adc_mutex;
int pmu_initialized;
unsigned char pmu_read(int address)
{
unsigned char tmp;
i2c_read(0xe6, address, 1, &tmp);
return tmp;
}
void pmu_write(int address, unsigned char val)
{
i2c_write(0xe6, address, 1, &val);
}
int pmu_initialized = 0;
void pmu_read_multiple(int address, int count, unsigned char* buffer)
{
@ -50,6 +36,20 @@ void pmu_write_multiple(int address, int count, unsigned char* buffer)
i2c_write(0xe6, address, count, buffer);
}
unsigned char pmu_read(int address)
{
unsigned char tmp;
pmu_read_multiple(address, 1, &tmp);
return tmp;
}
void pmu_write(int address, unsigned char val)
{
pmu_write_multiple(address, 1, &val);
}
void pmu_init(void)
{
if (pmu_initialized) return;
@ -88,3 +88,19 @@ int pmu_read_battery_current(void)
mutex_unlock(&pmu_adc_mutex);
return milliamps;
}
void pmu_switch_power(int gate, int onoff)
{
if (gate < 4)
{
unsigned char newval = pmu_read(0x3B) & ~(1 << (2 * gate));
if (onoff) newval |= 1 << (2 * gate);
pmu_write(0x3B, newval);
}
else if (gate < 7)
{
unsigned char newval = pmu_read(0x3C) & ~(1 << (2 * (gate - 4)));
if (onoff) newval |= 1 << (2 * (gate - 4));
pmu_write(0x3C, newval);
}
}