From b729a7d75ec5b2fb73aa67c8f986e2793f8efcaf Mon Sep 17 00:00:00 2001 From: Michael Sparmann Date: Sun, 11 Oct 2009 18:20:56 +0000 Subject: iPod Nano 2G PMU rework, added backlight brightness setting and USB charging speed setting git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23114 a1c6a512-1295-4272-9138-f99709370657 --- .../target/arm/s5l8700/ipodnano2g/pmu-nano2g.c | 80 +++++++++++++++------- 1 file changed, 57 insertions(+), 23 deletions(-) (limited to 'firmware/target/arm/s5l8700/ipodnano2g/pmu-nano2g.c') diff --git a/firmware/target/arm/s5l8700/ipodnano2g/pmu-nano2g.c b/firmware/target/arm/s5l8700/ipodnano2g/pmu-nano2g.c index ca2b5f2775..be026a8cf4 100644 --- a/firmware/target/arm/s5l8700/ipodnano2g/pmu-nano2g.c +++ b/firmware/target/arm/s5l8700/ipodnano2g/pmu-nano2g.c @@ -57,50 +57,84 @@ void pmu_init(void) pmu_initialized = 1; } -int pmu_read_battery_voltage(void) +int pmu_read_adc(unsigned int adc) { int data = 0; if (!pmu_initialized) pmu_init(); mutex_lock(&pmu_adc_mutex); - pmu_write(0x54, 0x05); + pmu_write(0x54, 5 | (adc << 4)); while ((data & 0x80) == 0) { yield(); data = pmu_read(0x57); } - int millivolts = ((pmu_read(0x55) << 2) | (data & 3)) * 6; + int value = (pmu_read(0x55) << 2) | (data & 3); mutex_unlock(&pmu_adc_mutex); - return millivolts; + return value; +} + +/* millivolts */ +int pmu_read_battery_voltage(void) +{ + return pmu_read_adc(0) * 6; } +/* milliamps */ int pmu_read_battery_current(void) { - int data = 0; - if (!pmu_initialized) pmu_init(); - mutex_lock(&pmu_adc_mutex); - pmu_write(0x54, 0x25); - while ((data & 0x80) == 0) - { - yield(); - data = pmu_read(0x57); - } - int milliamps = (pmu_read(0x55) << 2) | (data & 3); - mutex_unlock(&pmu_adc_mutex); - return milliamps; + return pmu_read_adc(2); } -void pmu_switch_power(int gate, int onoff) +void pmu_ldo_on_in_standby(unsigned int ldo, int onoff) { - if (gate < 4) + if (ldo < 4) { - unsigned char newval = pmu_read(0x3B) & ~(1 << (2 * gate)); - if (onoff) newval |= 1 << (2 * gate); + unsigned char newval = pmu_read(0x3B) & ~(1 << (2 * ldo)); + if (onoff) newval |= 1 << (2 * ldo); pmu_write(0x3B, newval); } - else if (gate < 7) + else if (ldo < 8) { - unsigned char newval = pmu_read(0x3C) & ~(1 << (2 * (gate - 4))); - if (onoff) newval |= 1 << (2 * (gate - 4)); + unsigned char newval = pmu_read(0x3C) & ~(1 << (2 * (ldo - 4))); + if (onoff) newval |= 1 << (2 * (ldo - 4)); pmu_write(0x3C, newval); } } + +void pmu_ldo_set_voltage(unsigned int ldo, unsigned char voltage) +{ + if (ldo > 6) return; + pmu_write(0x2d + (ldo << 1), voltage); +} + +void pmu_ldo_power_on(unsigned int ldo) +{ + if (ldo > 6) return; + pmu_write(0x2e + (ldo << 1), 1); +} + +void pmu_ldo_power_off(unsigned int ldo) +{ + if (ldo > 6) return; + pmu_write(0x2e + (ldo << 1), 0); +} + +void pmu_set_wake_condition(unsigned char condition) +{ + pmu_write(0xd, condition); +} + +void pmu_enter_standby(void) +{ + pmu_write(0xc, 1); +} + +void pmu_read_rtc(unsigned char* buffer) +{ + pmu_read_multiple(0x59, 7, buffer); +} + +void pmu_write_rtc(unsigned char* buffer) +{ + pmu_write_multiple(0x59, 7, buffer); +} -- cgit v1.2.3