summaryrefslogtreecommitdiff
path: root/arch/arm/mach-tegra/odm_kit/adaptations/pmu/pcf50626/pcf50626_batterycharger.c
blob: 7434e2b41ca7d184631118fa42b6d5a19f4d9d04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/*
 * Copyright (c) 2009 NVIDIA Corporation.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include "pcf50626_batterycharger.h"
#include "pcf50626_adc.h"
#include "pcf50626_i2c.h"
#include "pcf50626_reg.h"


/* Get battery Voltage */
NvBool 
Pcf50626BatteryChargerGetVoltage(NvOdmPmuDeviceHandle hDevice, NvU32 *res)
{
    NvU32 volt = 0;
    ///TODO: check on HW to see the relation between adc output and the voltage. for now, assume they are the same.
    if(! Pcf50626AdcVBatSenseRead(hDevice,&volt))
        return NV_FALSE;

    *res = volt;
    return NV_TRUE; 
}



/* check OnKey Level */
NvBool
Pcf50626BatteryChargerOnKeyStatus(NvOdmPmuDeviceHandle hDevice, NvBool *status)
{
    NvU8 data = 0;
    
    if(! Pcf50626I2cRead8(hDevice, PCF50626_OOCS_ADDR, &data))
        return NV_FALSE
        ;
    data = (data >> PCF50626_OOCS_ONKEY_SHIFT) & PCF50626_OOCS_ONKEY_MASK;
    *status = (data == 0 ? NV_FALSE : NV_TRUE ); 

    return NV_TRUE;
}

/* check OnKey Level */
NvBool
Pcf50626BatteryChargerRec1Status(NvOdmPmuDeviceHandle hDevice, NvBool *status)
{
    NvU8 data = 0;
    
    if(! Pcf50626I2cRead8(hDevice, PCF50626_OOCS_ADDR, &data))
        return NV_FALSE;
    data = (data >> PCF50626_OOCS_REC1_SHIFT) & PCF50626_OOCS_REC1_MASK;
    *status = (data == 0 ? NV_FALSE : NV_TRUE ); 

    return NV_TRUE;
}

/* check battery status */
NvBool
Pcf50626BatteryChargerBattStatus(NvOdmPmuDeviceHandle hDevice, NvBool *status)
{
    NvU8 data = 0;
    
    if(! Pcf50626I2cRead8(hDevice, PCF50626_OOCS_ADDR, &data))
        return NV_FALSE;
    data = (data >> PCF50626_OOCS_BATOK_SHIFT) & PCF50626_OOCS_BATOK_MASK;
    *status = (data == 0 ? NV_FALSE : NV_TRUE ); 

    return NV_TRUE;
}

/* check main charger status */
NvBool
Pcf50626BatteryChargerMainChgPresent(NvOdmPmuDeviceHandle hDevice, NvBool *status)
{
    NvU8 data = 0;
    
    if(! Pcf50626I2cRead8(hDevice, PCF50626_OOCS_ADDR, &data))
        return NV_FALSE;

    data = (data >> PCF50626_OOCS_MCHGOK_SHIFT) & PCF50626_OOCS_MCHGOK_MASK;
    *status = (data == 0 ? NV_FALSE : NV_TRUE ); 
    return NV_TRUE;
}


/* check USB charger status */
NvBool
Pcf50626BatteryChargerUsbChgPresent(NvOdmPmuDeviceHandle hDevice, NvBool *status)
{
    NvU8 data = 0;
    
    if(! Pcf50626I2cRead8(hDevice, PCF50626_OOCS_ADDR, &data))
        return NV_FALSE;

    data = (data >> PCF50626_OOCS_UCHGOK_SHIFT) & PCF50626_OOCS_UCHGOK_MASK;
    *status = (data == 0 ? NV_FALSE : NV_TRUE ); 
    return NV_TRUE;
}


/* check temparature status */
NvBool
Pcf50626BatteryChargerTempStatus(NvOdmPmuDeviceHandle hDevice, NvBool *status)
{
    NvU8 data = 0;
    
    if(! Pcf50626I2cRead8(hDevice, PCF50626_OOCS_ADDR, &data))
        return NV_FALSE;

    data = (data >> PCF50626_OOCS_TEMPOK_SHIFT) & PCF50626_OOCS_TEMPOK_MASK;
    *status = (data == 0 ? NV_FALSE : NV_TRUE ); 
    return NV_TRUE;
}

/* check CBC batt_ful status */
NvBool
Pcf50626BatteryChargerCBCBattFul(NvOdmPmuDeviceHandle hDevice, NvBool *status)
{
    NvU8 data = 0;
    
    if(! Pcf50626I2cRead8(hDevice, PCF50626_CBCS1_ADDR, &data))
        return NV_FALSE;

    data = (data >> PCF50626_CBCS1_BATTFUL_SHIFT) & PCF50626_CBCS1_BATTFUL_MASK;
    *status = (data == 0 ? NV_FALSE : NV_TRUE ); 
    return NV_TRUE;
}


/* check CBC thermal limit activation status */
NvBool
Pcf50626BatteryChargerCBCTlimStatus(NvOdmPmuDeviceHandle hDevice, NvBool *status)
{
    NvU8 data = 0;
    
    if(! Pcf50626I2cRead8(hDevice, PCF50626_CBCS1_ADDR, &data))
        return NV_FALSE;

    data = (data >> PCF50626_CBCS1_TLIMIT_SHIFT) & PCF50626_CBCS1_TLIMIT_MASK;
    *status = (data == 0 ? NV_FALSE : NV_TRUE ); 
    return NV_TRUE;
}

/* check CBC batt_ful status */
NvBool
Pcf50626BatteryChargerCBCWdExpired(NvOdmPmuDeviceHandle hDevice, NvBool *status)
{
    NvU8 data = 0;
    
    if(! Pcf50626I2cRead8(hDevice, PCF50626_CBCS1_ADDR, &data))
        return NV_FALSE;

    data = (data >> PCF50626_CBCS1_WDEXP_SHIFT) & PCF50626_CBCS1_WDEXP_MASK;
    *status = (data == 0 ? NV_FALSE : NV_TRUE ); 
    return NV_TRUE;
}


/* check CBC charger current status */
NvBool
Pcf50626BatteryChargerCBCChgCurStatus(NvOdmPmuDeviceHandle hDevice, NvBool *status)
{
    NvU8 data = 0;
    
    if(! Pcf50626I2cRead8(hDevice, PCF50626_CBCS1_ADDR, &data))
        return NV_FALSE;

    data = (data >> PCF50626_CBCS1_ILIMIT_SHIFT) & PCF50626_CBCS1_ILIMIT_MASK;
    *status = (data == 0 ? NV_FALSE : NV_TRUE ); 
    return NV_TRUE;
}

/* check CBC charger voltage status */
NvBool
Pcf50626BatteryChargerCBCChgVoltStatus(NvOdmPmuDeviceHandle hDevice, NvBool *status)
{
    NvU8 data = 0;
    
    if(! Pcf50626I2cRead8(hDevice, PCF50626_CBCS1_ADDR, &data))
        return NV_FALSE;

    data = (data >> PCF50626_CBCS1_VLIMIT_SHIFT) & PCF50626_CBCS1_VLIMIT_MASK;
    *status = (data == 0 ? NV_FALSE : NV_TRUE ); 
    return NV_TRUE;
}

/* check CBC charger resume status */
NvBool
Pcf50626BatteryChargerCBCChgResStatus(NvOdmPmuDeviceHandle hDevice, NvBool *status)
{
    NvU8 data = 0;
    
    if(! Pcf50626I2cRead8(hDevice, PCF50626_CBCS1_ADDR, &data))
        return NV_FALSE;

    data = (data >> PCF50626_CBCS1_RESSTAT_SHIFT) & PCF50626_CBCS1_RESSTAT_MASK;
    *status = (data == 0 ? NV_FALSE : NV_TRUE ); 
    return NV_TRUE;
}


/* check USB suspend status */
NvBool
Pcf50626BatteryChargerCBCUsbSuspStat(NvOdmPmuDeviceHandle hDevice, NvBool *status)
{
    NvU8 data = 0;
    
    if(! Pcf50626I2cRead8(hDevice, PCF50626_CBCS2_ADDR, &data))
        return NV_FALSE;

    data = (data >> PCF50626_CBCS2_USBSUSPSTAT_SHIFT) & PCF50626_CBCS2_USBSUSPSTAT_MASK;
    *status = (data == 0 ? NV_FALSE : NV_TRUE ); 
    return NV_TRUE;
}

/* check charger over-voltage protection status */
NvBool
Pcf50626BatteryChargerCBCChgOvpStat(NvOdmPmuDeviceHandle hDevice, NvBool *status)
{
    NvU8 data = 0;
    
    if(! Pcf50626I2cRead8(hDevice, PCF50626_CBCS2_ADDR, &data))
        return NV_FALSE;

    data = (data >> PCF50626_CBCS2_CHGOVP_SHIFT) & PCF50626_CBCS2_CHGOVP_MASK;
    *status = (data == 0 ? NV_FALSE : NV_TRUE ); 
    return NV_TRUE;
}