diff options
author | Michael Sparmann <theseven@rockbox.org> | 2009-10-05 20:21:33 +0000 |
---|---|---|
committer | Michael Sparmann <theseven@rockbox.org> | 2009-10-05 20:21:33 +0000 |
commit | be25469b9b481d8f40aeb12aa6de84e1efdc0e68 (patch) | |
tree | 34ebc185287296bce7a3901a1c2a5bd3b1354bb2 /firmware/target/arm/s5l8700/ipodnano2g/pmu-nano2g.c | |
parent | 6b8a78f7939b2eaccce578b68fd5831fc79f0a71 (diff) | |
download | rockbox-be25469b9b481d8f40aeb12aa6de84e1efdc0e68.tar.gz rockbox-be25469b9b481d8f40aeb12aa6de84e1efdc0e68.zip |
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
Diffstat (limited to 'firmware/target/arm/s5l8700/ipodnano2g/pmu-nano2g.c')
-rw-r--r-- | firmware/target/arm/s5l8700/ipodnano2g/pmu-nano2g.c | 90 |
1 files changed, 90 insertions, 0 deletions
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 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright © 2008 Rafaël Carré | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "config.h" | ||
23 | #include "kernel.h" | ||
24 | #include "i2c-s5l8700.h" | ||
25 | |||
26 | static struct mutex pmu_adc_mutex; | ||
27 | int pmu_initialized; | ||
28 | |||
29 | unsigned char pmu_read(int address) | ||
30 | { | ||
31 | unsigned char tmp; | ||
32 | |||
33 | i2c_read(0xe6, address, 1, &tmp); | ||
34 | |||
35 | return tmp; | ||
36 | } | ||
37 | |||
38 | void pmu_write(int address, unsigned char val) | ||
39 | { | ||
40 | i2c_write(0xe6, address, 1, &val); | ||
41 | } | ||
42 | |||
43 | void pmu_read_multiple(int address, int count, unsigned char* buffer) | ||
44 | { | ||
45 | i2c_read(0xe6, address, count, buffer); | ||
46 | } | ||
47 | |||
48 | void pmu_write_multiple(int address, int count, unsigned char* buffer) | ||
49 | { | ||
50 | i2c_write(0xe6, address, count, buffer); | ||
51 | } | ||
52 | |||
53 | void pmu_init(void) | ||
54 | { | ||
55 | if (pmu_initialized) return; | ||
56 | mutex_init(&pmu_adc_mutex); | ||
57 | pmu_initialized = 1; | ||
58 | } | ||
59 | |||
60 | int pmu_read_battery_voltage(void) | ||
61 | { | ||
62 | int data = 0; | ||
63 | if (!pmu_initialized) pmu_init(); | ||
64 | mutex_lock(&pmu_adc_mutex); | ||
65 | pmu_write(0x54, 0x05); | ||
66 | while ((data & 0x80) == 0) | ||
67 | { | ||
68 | yield(); | ||
69 | data = pmu_read(0x57); | ||
70 | } | ||
71 | int millivolts = ((pmu_read(0x55) << 2) | (data & 3)) * 6; | ||
72 | mutex_unlock(&pmu_adc_mutex); | ||
73 | return millivolts; | ||
74 | } | ||
75 | |||
76 | int pmu_read_battery_current(void) | ||
77 | { | ||
78 | int data = 0; | ||
79 | if (!pmu_initialized) pmu_init(); | ||
80 | mutex_lock(&pmu_adc_mutex); | ||
81 | pmu_write(0x54, 0x25); | ||
82 | while ((data & 0x80) == 0) | ||
83 | { | ||
84 | yield(); | ||
85 | data = pmu_read(0x57); | ||
86 | } | ||
87 | int milliamps = (pmu_read(0x55) << 2) | (data & 3); | ||
88 | mutex_unlock(&pmu_adc_mutex); | ||
89 | return milliamps; | ||
90 | } | ||