summaryrefslogtreecommitdiff
path: root/firmware/target/arm/philips/hdd6330/powermgmt-hdd6330.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/philips/hdd6330/powermgmt-hdd6330.c')
-rw-r--r--firmware/target/arm/philips/hdd6330/powermgmt-hdd6330.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/firmware/target/arm/philips/hdd6330/powermgmt-hdd6330.c b/firmware/target/arm/philips/hdd6330/powermgmt-hdd6330.c
new file mode 100644
index 0000000000..33bbb6af48
--- /dev/null
+++ b/firmware/target/arm/philips/hdd6330/powermgmt-hdd6330.c
@@ -0,0 +1,72 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Heikki Hannikainen, Uwe Freese
11 * Revisions copyright (C) 2005 by Gerald Van Baren
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ****************************************************************************/
22
23#include "config.h"
24#include "adc.h"
25#include "powermgmt.h"
26
27#define SMLAL(lo, hi, x, y) \
28 asm volatile ("smlal %0, %1, %2, %3" \
29 : "+r" (lo), "+r" (hi) \
30 : "%r" (x), "r" (y))
31
32const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
33{
34 3550
35};
36
37const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
38{
39 3500
40};
41
42/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
43const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
44{
45 { 3480, 3550, 3590, 3610, 3630, 3650, 3700, 3760, 3800, 3910, 3990 },
46};
47
48#if CONFIG_CHARGING
49/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
50const unsigned short percent_to_volt_charge[11] =
51{
52 3480, 3550, 3590, 3610, 3630, 3650, 3700, 3760, 3800, 3910, 3990
53};
54#endif /* CONFIG_CHARGING */
55
56#define BATTERY_SCALE_FACTOR 4200
57/* full-scale ADC readout (2^10) in millivolt */
58
59/* Returns battery voltage from ADC [millivolts] */
60unsigned int battery_adc_voltage(void)
61{
62 /* return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10; */
63
64 /* This may be overly complicated (pulled from the OF) */
65 int lo = 0;
66 int val = adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR;
67
68 SMLAL(lo, val, 0x8a42f871, val);
69 val>>= 9;
70 val -= (val >> 31);
71 return val;
72}