ARM: use BX when branch to an address in register
[kugel-rb.git] / firmware / target / arm / s3c2440 / gigabeat-fx / powermgmt-meg-fx.c
blob49f7e2e049b7024984600956a6dc9f9a24b10da8
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Heikki Hannikainen, Uwe Freese
11 * Revisions copyright (C) 2005 by Gerald Van Baren
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.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
22 #include "config.h"
23 #include "system.h"
24 #include "adc.h"
25 #include "power.h"
26 #include "powermgmt.h"
28 const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
30 3450
33 const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
35 3400
38 /* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
39 const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
41 /* Toshiba Gigabeat Li Ion 830mAH figured from discharge curve */
42 { 3480, 3550, 3590, 3610, 3630, 3650, 3700, 3760, 3800, 3910, 3990 },
45 /* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
46 const unsigned short percent_to_volt_charge[11] =
48 /* Toshiba Gigabeat Li Ion 830mAH */
49 3480, 3550, 3590, 3610, 3630, 3650, 3700, 3760, 3800, 3910, 3990
52 /* ADC[0] is (530) at discharge and 625 at full charge */
53 #define BATTERY_SCALE_FACTOR 6605
54 /* full-scale ADC readout (2^10) in millivolt */
56 /* Returns battery voltage from ADC [millivolts] */
57 unsigned int battery_adc_voltage(void)
59 return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10;
62 unsigned int input_millivolts(void)
65 unsigned int batt_millivolts = battery_voltage();
67 if ((power_thread_inputs & POWER_INPUT_BATTERY) == 0) {
68 /* Just return a safe value if battery isn't connected */
69 return 4050;
72 return batt_millivolts;