summaryrefslogtreecommitdiff
path: root/firmware/target/arm/s5l8700/ipodnano2g/pmu-nano2g.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/s5l8700/ipodnano2g/pmu-nano2g.c')
-rw-r--r--firmware/target/arm/s5l8700/ipodnano2g/pmu-nano2g.c80
1 files changed, 57 insertions, 23 deletions
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)
57 pmu_initialized = 1; 57 pmu_initialized = 1;
58} 58}
59 59
60int pmu_read_battery_voltage(void) 60int pmu_read_adc(unsigned int adc)
61{ 61{
62 int data = 0; 62 int data = 0;
63 if (!pmu_initialized) pmu_init(); 63 if (!pmu_initialized) pmu_init();
64 mutex_lock(&pmu_adc_mutex); 64 mutex_lock(&pmu_adc_mutex);
65 pmu_write(0x54, 0x05); 65 pmu_write(0x54, 5 | (adc << 4));
66 while ((data & 0x80) == 0) 66 while ((data & 0x80) == 0)
67 { 67 {
68 yield(); 68 yield();
69 data = pmu_read(0x57); 69 data = pmu_read(0x57);
70 } 70 }
71 int millivolts = ((pmu_read(0x55) << 2) | (data & 3)) * 6; 71 int value = (pmu_read(0x55) << 2) | (data & 3);
72 mutex_unlock(&pmu_adc_mutex); 72 mutex_unlock(&pmu_adc_mutex);
73 return millivolts; 73 return value;
74}
75
76/* millivolts */
77int pmu_read_battery_voltage(void)
78{
79 return pmu_read_adc(0) * 6;
74} 80}
75 81
82/* milliamps */
76int pmu_read_battery_current(void) 83int pmu_read_battery_current(void)
77{ 84{
78 int data = 0; 85 return pmu_read_adc(2);
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} 86}
91 87
92void pmu_switch_power(int gate, int onoff) 88void pmu_ldo_on_in_standby(unsigned int ldo, int onoff)
93{ 89{
94 if (gate < 4) 90 if (ldo < 4)
95 { 91 {
96 unsigned char newval = pmu_read(0x3B) & ~(1 << (2 * gate)); 92 unsigned char newval = pmu_read(0x3B) & ~(1 << (2 * ldo));
97 if (onoff) newval |= 1 << (2 * gate); 93 if (onoff) newval |= 1 << (2 * ldo);
98 pmu_write(0x3B, newval); 94 pmu_write(0x3B, newval);
99 } 95 }
100 else if (gate < 7) 96 else if (ldo < 8)
101 { 97 {
102 unsigned char newval = pmu_read(0x3C) & ~(1 << (2 * (gate - 4))); 98 unsigned char newval = pmu_read(0x3C) & ~(1 << (2 * (ldo - 4)));
103 if (onoff) newval |= 1 << (2 * (gate - 4)); 99 if (onoff) newval |= 1 << (2 * (ldo - 4));
104 pmu_write(0x3C, newval); 100 pmu_write(0x3C, newval);
105 } 101 }
106} 102}
103
104void pmu_ldo_set_voltage(unsigned int ldo, unsigned char voltage)
105{
106 if (ldo > 6) return;
107 pmu_write(0x2d + (ldo << 1), voltage);
108}
109
110void pmu_ldo_power_on(unsigned int ldo)
111{
112 if (ldo > 6) return;
113 pmu_write(0x2e + (ldo << 1), 1);
114}
115
116void pmu_ldo_power_off(unsigned int ldo)
117{
118 if (ldo > 6) return;
119 pmu_write(0x2e + (ldo << 1), 0);
120}
121
122void pmu_set_wake_condition(unsigned char condition)
123{
124 pmu_write(0xd, condition);
125}
126
127void pmu_enter_standby(void)
128{
129 pmu_write(0xc, 1);
130}
131
132void pmu_read_rtc(unsigned char* buffer)
133{
134 pmu_read_multiple(0x59, 7, buffer);
135}
136
137void pmu_write_rtc(unsigned char* buffer)
138{
139 pmu_write_multiple(0x59, 7, buffer);
140}