From be25469b9b481d8f40aeb12aa6de84e1efdc0e68 Mon Sep 17 00:00:00 2001 From: Michael Sparmann Date: Mon, 5 Oct 2009 20:21:33 +0000 Subject: Reworked iPod Nano 2G PMU code, added RTC and battery ADC. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22967 a1c6a512-1295-4272-9138-f99709370657 --- .../target/arm/s5l8700/ipodnano2g/pmu-nano2g.c | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 firmware/target/arm/s5l8700/ipodnano2g/pmu-nano2g.c (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 new file mode 100644 index 0000000000..7a6407e809 --- /dev/null +++ b/firmware/target/arm/s5l8700/ipodnano2g/pmu-nano2g.c @@ -0,0 +1,90 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright © 2008 Rafaël Carré + * + * 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. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "config.h" +#include "kernel.h" +#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); +} + +void pmu_read_multiple(int address, int count, unsigned char* buffer) +{ + i2c_read(0xe6, address, count, buffer); +} + +void pmu_write_multiple(int address, int count, unsigned char* buffer) +{ + i2c_write(0xe6, address, count, buffer); +} + +void pmu_init(void) +{ + if (pmu_initialized) return; + mutex_init(&pmu_adc_mutex); + pmu_initialized = 1; +} + +int pmu_read_battery_voltage(void) +{ + int data = 0; + if (!pmu_initialized) pmu_init(); + mutex_lock(&pmu_adc_mutex); + pmu_write(0x54, 0x05); + while ((data & 0x80) == 0) + { + yield(); + data = pmu_read(0x57); + } + int millivolts = ((pmu_read(0x55) << 2) | (data & 3)) * 6; + mutex_unlock(&pmu_adc_mutex); + return millivolts; +} + +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; +} -- cgit v1.2.3