Subversion Repositories freemyipod

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
54 theseven 1
//
2
//
3
//    Copyright 2010 TheSeven
4
//
5
//
427 farthen 6
//    This file is part of emCORE.
54 theseven 7
//
427 farthen 8
//    emCORE is free software: you can redistribute it and/or
54 theseven 9
//    modify it under the terms of the GNU General Public License as
10
//    published by the Free Software Foundation, either version 2 of the
11
//    License, or (at your option) any later version.
12
//
427 farthen 13
//    emCORE is distributed in the hope that it will be useful,
54 theseven 14
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
//    See the GNU General Public License for more details.
17
//
18
//    You should have received a copy of the GNU General Public License along
427 farthen 19
//    with emCORE.  If not, see <http://www.gnu.org/licenses/>.
54 theseven 20
//
21
//
22
 
23
 
24
#include "global.h"
25
#include "s5l8701.h"
26
#include "power.h"
27
#include "pmu.h"
28
 
29
 
30
void reset();
31
 
32
 
33
void power_off(void)
34
{
35
    pmu_ldo_on_in_standby(0, 0);
36
    pmu_ldo_on_in_standby(1, 0);
37
    pmu_ldo_on_in_standby(2, 0);
38
    pmu_ldo_on_in_standby(3, 0);
39
    pmu_ldo_on_in_standby(4, 0);
40
    pmu_ldo_on_in_standby(5, 0);
41
    pmu_ldo_on_in_standby(6, 0);
42
    pmu_ldo_on_in_standby(7, 0);
43
    pmu_set_wake_condition(0x42); /* USB inserted or EXTON1 */
44
    pmu_enter_standby();
45
 
46
    reset();
47
}
48
 
49
void power_init(void)
50
{
51
    pmu_init();
52
    pmu_write(0x1e, 15);  /* Vcore = 1.000V */
284 theseven 53
    pmu_ldo_set_voltage(2, 0x11); /* LCD   = 2.600V */
221 theseven 54
}                          
54 theseven 55
 
56
bool charging_state(void)
57
{
58
    return (PDAT11 & 0x10) ? false : true;
59
}
221 theseven 60
 
61
bool external_power_state(void)
62
{
63
    return (PDAT14 & 8) ? false : true;
64
}
65
 
66
bool vbus_state(void)
67
{
68
    return (PDAT14 & 8) ? false : true;
69
}
622 theseven 70
 
71
int read_battery_voltage(int battery)
72
{
73
    if (battery == 0) return pmu_read_battery_voltage();
74
    return -1;
75
}
76
 
77
int read_battery_current(int battery)
78
{
79
    if (battery == 0) return pmu_read_battery_current();
80
    return -1;
81
}
82
 
83
int read_battery_mwh_design(int battery)
84
{
85
    if (battery == 0) return 1480;
86
    return -1;
87
}
88
 
89
int read_battery_mwh_full(int battery)
90
{
91
    if (battery == 0) return 1480;
92
    return -1;
93
}
94
 
95
int read_battery_mwh_current(int battery)
96
{
97
    // TODO: Approximate that better
98
    if (battery == 0) return (read_battery_voltage(0) - 3600) * 2;
99
    return -1;
100
}
101
 
102
int read_battery_mw(int battery)
103
{
104
    if (battery == 0) return read_battery_current(0) * 3700 / 1000;
105
    return -1;
106
}
107
 
108
enum battery_state read_battery_state(int battery)
109
{
110
    if (battery != 0) return BATTERY_STATE_INVALID;
111
    if (charging_state()) return BATTERY_STATE_CHARGING;
112
    if (external_power_state()) return BATTERY_STATE_IDLE;
113
    return BATTERY_STATE_DISCHARGING;
114
}
845 theseven 115
 
116
int read_input_voltage(int input)
117
{
118
    return -1;
119
}
120
 
121
int read_input_current(int input)
122
{
123
    return -1;
124
}
125
 
126
int read_input_mw(int input)
127
{
128
    return -1;
129
}
130
 
131
enum input_state read_input_state(int input)
132
{
133
    if (input != 0) return INPUT_STATE_INVALID;
134
    if (external_power_state()) return INPUT_STATE_ACTIVE;
135
    return INPUT_STATE_NONPRESENT;
136
}