1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
25 #include "powermgmt.h"
29 const unsigned short battery_level_dangerous
[BATTERY_TYPES_COUNT
] =
33 #elif defined IPOD_VIDEO
36 /* FIXME: calibrate value for other 3G+ ipods */
41 const unsigned short battery_level_shutoff
[BATTERY_TYPES_COUNT
] =
45 #elif defined IPOD_VIDEO
48 /* FIXME: calibrate value for other 3G+ ipods */
53 /* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
54 const unsigned short percent_to_volt_discharge
[BATTERY_TYPES_COUNT
][11] =
58 { 3230, 3620, 3700, 3730, 3750, 3780, 3830, 3890, 3950, 4030, 4160 },
59 #elif defined IPOD_VIDEO
60 /* iPOD Video 30GB Li-Ion 400mAh, first approach based upon measurements */
61 { 3450, 3670, 3710, 3750, 3790, 3830, 3870, 3930, 4010, 4100, 4180 },
62 #elif defined IPOD_COLOR
63 /* iPOD Color 60GB Li-Ion, first approach based upon measurements */
64 { 3500, 3676, 3729, 3755, 3778, 3805, 3847, 3919, 3961, 4071, 4109 },
66 /* FIXME: calibrate value for other 3G+ ipods */
67 /* Table is "inherited" from iriver H100. */
68 { 3370, 3650, 3700, 3740, 3780, 3820, 3870, 3930, 4000, 4080, 4160 }
73 /* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
74 const unsigned short percent_to_volt_charge
[11] =
78 3230, 3620, 3700, 3730, 3750, 3780, 3830, 3890, 3950, 4030, 4160
79 #elif defined IPOD_VIDEO
80 /* iPOD Video 30GB Li-Ion 400mAh, first approach based upon measurements */
81 3450, 3670, 3710, 3750, 3790, 3830, 3870, 3930, 4010, 4100, 4180
83 /* FIXME: calibrate value for other 3G+ ipods */
84 /* Table is "inherited" from iriver H100. */
85 3540, 3860, 3930, 3980, 4000, 4020, 4040, 4080, 4130, 4180, 4230
88 #endif /* CONFIG_CHARGING */
90 #define BATTERY_SCALE_FACTOR 6000
91 /* full-scale ADC readout (2^10) in millivolt */
93 /* Returns battery voltage from ADC [millivolts] */
94 unsigned int battery_adc_voltage(void)
96 return (adc_read(ADC_UNREG_POWER
) * BATTERY_SCALE_FACTOR
) >> 10;
99 #ifdef HAVE_ACCESSORY_SUPPLY
100 void accessory_supply_set(bool enable
)
104 /* Accessory voltage supply */
105 pcf50605_write(PCF5060X_D2REGC1
, 0xf8); /* 3.3V ON */
109 /* Accessory voltage supply */
110 pcf50605_write(PCF5060X_D2REGC1
, 0x18); /* OFF */