1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright © 2008 Rafaël Carré
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
24 #include "i2c-s5l8700.h"
25 #include "pmu-target.h"
27 static struct mutex pmu_adc_mutex
;
29 int pmu_read_multiple(int address
, int count
, unsigned char* buffer
)
31 return i2c_read(0xe6, address
, count
, buffer
);
34 int pmu_write_multiple(int address
, int count
, unsigned char* buffer
)
36 return i2c_write(0xe6, address
, count
, buffer
);
39 unsigned char pmu_read(int address
)
43 pmu_read_multiple(address
, 1, &tmp
);
48 int pmu_write(int address
, unsigned char val
)
50 return pmu_write_multiple(address
, 1, &val
);
55 mutex_init(&pmu_adc_mutex
);
58 int pmu_read_adc(unsigned int adc
)
61 mutex_lock(&pmu_adc_mutex
);
62 pmu_write(0x54, 5 | (adc
<< 4));
63 while ((data
& 0x80) == 0)
66 data
= pmu_read(0x57);
68 int value
= (pmu_read(0x55) << 2) | (data
& 3);
69 mutex_unlock(&pmu_adc_mutex
);
74 int pmu_read_battery_voltage(void)
76 return pmu_read_adc(0) * 6;
80 int pmu_read_battery_current(void)
82 return pmu_read_adc(2);
85 void pmu_ldo_on_in_standby(unsigned int ldo
, int onoff
)
89 unsigned char newval
= pmu_read(0x3B) & ~(1 << (2 * ldo
));
90 if (onoff
) newval
|= 1 << (2 * ldo
);
91 pmu_write(0x3B, newval
);
95 unsigned char newval
= pmu_read(0x3C) & ~(1 << (2 * (ldo
- 4)));
96 if (onoff
) newval
|= 1 << (2 * (ldo
- 4));
97 pmu_write(0x3C, newval
);
101 void pmu_ldo_set_voltage(unsigned int ldo
, unsigned char voltage
)
104 pmu_write(0x2d + (ldo
<< 1), voltage
);
107 void pmu_ldo_power_on(unsigned int ldo
)
110 pmu_write(0x2e + (ldo
<< 1), 1);
113 void pmu_ldo_power_off(unsigned int ldo
)
116 pmu_write(0x2e + (ldo
<< 1), 0);
119 void pmu_set_wake_condition(unsigned char condition
)
121 pmu_write(0xd, condition
);
124 void pmu_enter_standby(void)
129 void pmu_read_rtc(unsigned char* buffer
)
131 pmu_read_multiple(0x59, 7, buffer
);
134 void pmu_write_rtc(unsigned char* buffer
)
136 pmu_write_multiple(0x59, 7, buffer
);