summaryrefslogtreecommitdiff
path: root/drivers/power/mxs/ddi_bc_hw.c
blob: f1fdb6f2b065d20aca02ae28632e8a0aa8e763f5 (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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
/*
 * Copyright (C) 2010 Freescale Semiconductor, Inc. All Rights Reserved.
 */

/*
 * The code contained herein is licensed under the GNU General Public
 * License. You may obtain a copy of the GNU General Public License
 * Version 2 or later at the following locations:
 *
 * http://www.opensource.org/licenses/gpl-license.html
 * http://www.gnu.org/copyleft/gpl.html
 */

#include "ddi_bc_internal.h"


/* Includes and external references */



/* Variables */



/* Code */



/*  */
/* brief Report if the battery charging hardware is available. */
/*  */
/* fntype Function */
/*  */
/*  This function reports if the battery charging hardware is available by */
/*  reading the corresponding laser fuse bit. */
/*  */
/* retval  Zero if the battery charging hardware is not available. Non-zero */
/*           otherwise. */
/*  */

int ddi_bc_hwBatteryChargerIsEnabled(void)
{
	/* TODO: replace ddi_bc_hwBatteryChargerIsEnabled with the function below in the code */
	return (int)ddi_power_GetBatteryChargerEnabled();
}


/*  */
/* brief Report the battery configuration. */
/*  */
/* fntype Function */
/*  */
/*  This function reports the hardware battery configuration. */
/*  */
/* retval  A value that indicates the battery configuration. */
/*  */

ddi_bc_BatteryMode_t ddi_bc_hwGetBatteryMode(void)
{
	/* TODO: replace ddi_bc_hwGetBatteryMode() with the function below. */
	return (ddi_bc_BatteryMode_t) ddi_power_GetBatteryMode();
}



/*  */
/* brief Report the voltage across the battery. */
/*  */
/* fntype Function */
/*  */
/*  This function reports the voltage across the battery. */
/*  */
/* retval The voltage across the battery, in mV. */
/*  */

uint16_t ddi_bc_hwGetBatteryVoltage(void)
{
	/* TODO: replace ddi_bc_hwGetBattery with function below */
	return ddi_power_GetBattery();
}


/*  */
/* brief Report on the presence of the power supply. */
/*  */
/* fntype Function */
/*  */
/*  This function repots on whether or not the 5V power supply is present. */
/*  */
/* retval  Zero if the power supply is not present. Non-zero otherwise. */
/*  */

int ddi_bc_hwPowerSupplyIsPresent(void)
{
	/* TODO: replace ddi_bc_hwPowerSupplyIsPresent with the functino below. */
	return (int)ddi_power_Get5vPresentFlag();
}


/*  */
/* brief Report the maximum charging current. */
/*  */
/* fntype Function */
/*  */
/*  This function reports the maximum charging current that will be offered to */
/*  the battery, as currently set in the hardware. */
/*  */
/* retval  The maximum current setting in the hardware. */
/*  */

uint16_t ddi_bc_hwGetMaxCurrent(void)
{
	/* TODO: replace ddi_bc_hwGetMaxCurrent() with the below function */
	return (uint16_t) ddi_power_GetMaxBatteryChargeCurrent();
}


/*  */
/* brief Set the maximum charging current. */
/*  */
/* fntype Function */
/*  */
/*  This function sets the maximum charging current that will be offered to the */
/*  battery. */
/*  */
/*  Note that the hardware has a minimum resolution of 10mA and a maximum */
/*  expressible value of 780mA (see the data sheet for details). If the given */
/*  current cannot be expressed exactly, then the largest expressible smaller */
/*  value will be used. The return reports the actual value that was effected. */
/*  */
/* param[in]  u16Limit  The maximum charging current, in mA. */
/*  */
/* retval  The actual value that was effected. */
/*  */

uint16_t ddi_bc_hwSetMaxCurrent(uint16_t u16Limit)
{
	/* TODO: replace ddi_bc_hwSetMaxChargeCurrent */
	return ddi_power_SetMaxBatteryChargeCurrent(u16Limit);
}


/*  */
/* brief Set the charging current threshold. */
/*  */
/* fntype Function */
/*  */
/*  This function sets the charging current threshold. When the actual current */
/*  flow to the battery is less than this threshold, the HW_POWER_STS.CHRGSTS */
/*  flag is clear. */
/*  */
/*  Note that the hardware has a minimum resolution of 10mA and a maximum */
/*  expressible value of 180mA (see the data sheet for details). If the given */
/*  current cannot be expressed exactly, then the largest expressible smaller */
/*  value will be used. The return reports the actual value that was effected. */
/*  */
/* param[in]  u16Threshold  The charging current threshold, in mA. */
/*  */
/* retval  The actual value that was effected. */
/*  */

uint16_t ddi_bc_hwSetCurrentThreshold(uint16_t u16Threshold)
{
	/* TODO: replace calls to ddi_bc_hwSetCurrentThreshold with the one below */
	return ddi_power_SetBatteryChargeCurrentThreshold(u16Threshold);

}


/*  */
/* brief Report the charging current threshold. */
/*  */
/* fntype Function */
/*  */
/*  This function reports the charging current threshold. When the actual */
/*  current flow to the battery is less than this threshold, the */
/*  HW_POWER_STS.CHRGSTS flag is clear. */
/*  */
/*  Note that the hardware has a minimum resolution of 10mA and a maximum */
/*  expressible value of 180mA (see the data sheet for details). */
/*  */
/* retval  The charging current threshold, in mA. */
/*  */

uint16_t ddi_bc_hwGetCurrentThreshold(void)
{
	/* TODO: replace calls to ddi_bc_hwGetCurrentThreshold with function below */
	return ddi_power_GetBatteryChargeCurrentThreshold();
}


/*  */
/* brief Report if the charger hardware power is on. */
/*  */
/* fntype Function */
/*  */
/*  This function reports if the charger hardware power is on. */
/*  */
/* retval  Zero if the charger hardware is not powered. Non-zero otherwise. */
/*  */

int ddi_bc_hwChargerPowerIsOn(void)
{

	/* -------------------------------------------------------------------------- */
	/* Note that the bit we're looking at is named PWD_BATTCHRG. The "PWD" */
	/* stands for "power down". Thus, when the bit is set, the battery charger */
	/* hardware is POWERED DOWN. */
	/* -------------------------------------------------------------------------- */

	/* -------------------------------------------------------------------------- */
	/* Read the register and return the result. */
	/* -------------------------------------------------------------------------- */

	/* TODO: replace ddi_bc_hwChargerPowerIsOn with function below */
	return ddi_power_GetChargerPowered();
}


/*  */
/* brief Turn the charging hardware on or off. */
/*  */
/* fntype Function */
/*  */
/*  This function turns the charging hardware on or off. */
/*  */
/* param[in]  on  Indicates whether the charging hardware should be on or off. */
/*  */

void ddi_bc_hwSetChargerPower(int on)
{

	/* -------------------------------------------------------------------------- */
	/* Note that the bit we're looking at is named PWD_BATTCHRG. The "PWD" */
	/* stands for "power down". Thus, when the bit is set, the battery charger */
	/* hardware is POWERED DOWN. */
	/* -------------------------------------------------------------------------- */

	/* -------------------------------------------------------------------------- */
	/* Hit the power switch. */
	/* -------------------------------------------------------------------------- */

	/* TODO: replace ddi_bc_hwSetChargerPower with functino below */
	ddi_power_SetChargerPowered(on);
}


/*  */
/* brief Reports if the charging current has fallen below the threshold. */
/*  */
/* fntype Function */
/*  */
/*  This function reports if the charging current that the battery is accepting */
/*  has fallen below the threshold. */
/*  */
/*  Note that this bit is regarded by the hardware guys as very slightly */
/*  unreliable. They recommend that you don't believe a value of zero until */
/*  you've sampled it twice. */
/*  */
/* retval  Zero if the battery is accepting less current than indicated by the */
/*           charging threshold. Non-zero otherwise. */
/*  */

int ddi_bc_hwGetChargeStatus(void)
{
	return ddi_power_GetChargeStatus();
}


/*  */
/* brief Report on the die temperature. */
/*  */
/* fntype Function */
/*  */
/*  This function reports on the die temperature. */
/*  */
/* param[out]  pLow   The low  end of the temperature range. */
/* param[out]  pHigh  The high end of the temperature range. */
/*  */

void ddi_bc_hwGetDieTemp(int16_t *pLow, int16_t *pHigh)
{
	/* TODO: replace ddi_bc_hwGetDieTemp with function below */
	ddi_power_GetDieTemp(pLow, pHigh);
}


/*  */
/* brief Report the battery temperature reading. */
/*  */
/* fntype Function */
/*  */
/*  This function examines the configured LRADC channel and reports the battery */
/*  temperature reading. */
/*  */
/* param[out]  pReading  A pointer to a variable that will receive the */
/*                         temperature reading. */
/*  */
/* retval  DDI_BC_STATUS_SUCCESS          If the operation succeeded. */
/* retval  DDI_BC_STATUS_NOT_INITIALIZED  If the Battery Charger is not yet */
/*                                          initialized. */
/*  */

ddi_bc_Status_t ddi_bc_hwGetBatteryTemp(uint16_t *pReading)
{
	return (ddi_bc_Status_t)DDI_BC_STATUS_HARDWARE_DISABLED;
}


/*  */
/* brief Convert a current in mA to a hardware setting. */
/*  */
/* fntype Function */
/*  */
/*  This function converts a current measurement in mA to a hardware setting */
/*  used by HW_POWER_BATTCHRG.STOP_ILIMIT or HW_POWER_BATTCHRG.BATTCHRG_I. */
/*  */
/*  Note that the hardware has a minimum resolution of 10mA and a maximum */
/*  expressible value of 780mA (see the data sheet for details). If the given */
/*  current cannot be expressed exactly, then the largest expressible smaller */
/*  value will be used. */
/*  */
/* param[in]  u16Current  The current of interest. */
/*  */
/* retval  The corresponding setting. */
/*  */

uint8_t ddi_bc_hwCurrentToSetting(uint16_t u16Current)
{
	return ddi_power_convert_current_to_setting(u16Current);
}


/*  */
/* brief Convert a hardware current setting to a value in mA. */
/*  */
/* fntype Function */
/*  */
/*  This function converts a setting used by HW_POWER_BATTCHRG.STOP_ILIMIT or */
/*  HW_POWER_BATTCHRG.BATTCHRG_I into an actual current measurement in mA. */
/*  */
/*  Note that the hardware current fields are 6 bits wide. The higher bits in */
/*  the 8-bit input parameter are ignored. */
/*  */
/* param[in]  u8Setting  A hardware current setting. */
/*  */
/* retval  The corresponding current in mA. */
/*  */

uint16_t ddi_bc_hwSettingToCurrent(uint8_t u8Setting)
{
	return ddi_power_convert_setting_to_current(u8Setting);
}


/*  */
/* brief Compute the actual current expressible in the hardware. */
/*  */
/* fntype Function */
/*  */
/*  Given a desired current, this function computes the actual current */
/*  expressible in the hardware. */
/*  */
/*  Note that the hardware has a minimum resolution of 10mA and a maximum */
/*  expressible value of 780mA (see the data sheet for details). If the given */
/*  current cannot be expressed exactly, then the largest expressible smaller */
/*  value will be used. */
/*  */
/* param[in]  u16Current  The current of interest. */
/*  */
/* retval  The corresponding current in mA. */
/*  */

uint16_t ddi_bc_hwExpressibleCurrent(uint16_t u16Current)
{
	/* TODO: replace the bc function with this one */
	return ddi_power_ExpressibleCurrent(u16Current);
}


/*  */
/* brief Checks to see if the DCDC has been manually enabled */
/*  */
/* fntype Function */
/*  */
/* retval  true if DCDC is ON, false if DCDC is OFF. */
/*  */

bool ddi_bc_hwIsDcdcOn(void)
{
	return ddi_power_IsDcdcOn();
}


/* End of file */

/*  @} */