summaryrefslogtreecommitdiff
path: root/firmware/target/arm/s5l8702/ipod6g/pmu-ipod6g.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/s5l8702/ipod6g/pmu-ipod6g.c')
-rw-r--r--firmware/target/arm/s5l8702/ipod6g/pmu-ipod6g.c143
1 files changed, 143 insertions, 0 deletions
diff --git a/firmware/target/arm/s5l8702/ipod6g/pmu-ipod6g.c b/firmware/target/arm/s5l8702/ipod6g/pmu-ipod6g.c
new file mode 100644
index 0000000000..73d8f98083
--- /dev/null
+++ b/firmware/target/arm/s5l8702/ipod6g/pmu-ipod6g.c
@@ -0,0 +1,143 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: pmu-nano2g.c 27752 2010-08-08 10:49:32Z bertrik $
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-s5l8702.h"
25#include "pmu-target.h"
26
27static struct mutex pmu_adc_mutex;
28
29int pmu_read_multiple(int address, int count, unsigned char* buffer)
30{
31 return i2c_read(0, 0xe6, address, count, buffer);
32}
33
34int pmu_write_multiple(int address, int count, unsigned char* buffer)
35{
36 return i2c_write(0, 0xe6, address, count, buffer);
37}
38
39unsigned char pmu_read(int address)
40{
41 unsigned char tmp;
42
43 pmu_read_multiple(address, 1, &tmp);
44
45 return tmp;
46}
47
48int pmu_write(int address, unsigned char val)
49{
50 return pmu_write_multiple(address, 1, &val);
51}
52
53void pmu_init(void)
54{
55 mutex_init(&pmu_adc_mutex);
56}
57
58int pmu_read_adc(unsigned int adc)
59{
60 int data = 0;
61 mutex_lock(&pmu_adc_mutex);
62 pmu_write(0x54, 5 | (adc << 4));
63 while ((data & 0x80) == 0)
64 {
65 yield();
66 data = pmu_read(0x57);
67 }
68 int value = (pmu_read(0x55) << 2) | (data & 3);
69 mutex_unlock(&pmu_adc_mutex);
70 return value;
71}
72
73/* millivolts */
74int pmu_read_battery_voltage(void)
75{
76 return pmu_read_adc(0) * 6;
77}
78
79/* milliamps */
80int pmu_read_battery_current(void)
81{
82// return pmu_read_adc(2);
83 return 0;
84}
85
86void pmu_ldo_on_in_standby(unsigned int ldo, int onoff)
87{
88 if (ldo < 4)
89 {
90 unsigned char newval = pmu_read(0x3B) & ~(1 << (2 * ldo));
91 if (onoff) newval |= 1 << (2 * ldo);
92 pmu_write(0x3B, newval);
93 }
94 else if (ldo < 8)
95 {
96 unsigned char newval = pmu_read(0x3C) & ~(1 << (2 * (ldo - 4)));
97 if (onoff) newval |= 1 << (2 * (ldo - 4));
98 pmu_write(0x3C, newval);
99 }
100}
101
102void pmu_ldo_set_voltage(unsigned int ldo, unsigned char voltage)
103{
104 if (ldo > 6) return;
105 pmu_write(0x2d + (ldo << 1), voltage);
106}
107
108void pmu_hdd_power(bool on)
109{
110 pmu_write(0x1b, on ? 1 : 0);
111}
112
113void pmu_ldo_power_on(unsigned int ldo)
114{
115 if (ldo > 6) return;
116 pmu_write(0x2e + (ldo << 1), 1);
117}
118
119void pmu_ldo_power_off(unsigned int ldo)
120{
121 if (ldo > 6) return;
122 pmu_write(0x2e + (ldo << 1), 0);
123}
124
125void pmu_set_wake_condition(unsigned char condition)
126{
127 pmu_write(0xd, condition);
128}
129
130void pmu_enter_standby(void)
131{
132 pmu_write(0xc, 1);
133}
134
135void pmu_read_rtc(unsigned char* buffer)
136{
137 pmu_read_multiple(0x59, 7, buffer);
138}
139
140void pmu_write_rtc(unsigned char* buffer)
141{
142 pmu_write_multiple(0x59, 7, buffer);
143}