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"
30 const unsigned short battery_level_dangerous
[BATTERY_TYPES_COUNT
] =
32 #if defined(IPOD_NANO)
34 #elif defined(IPOD_VIDEO)
36 #elif defined(IPOD_COLOR)
38 #elif defined(IPOD_3G)
41 /* FIXME: calibrate value for other iPods */
46 const unsigned short battery_level_shutoff
[BATTERY_TYPES_COUNT
] =
48 #if defined(IPOD_NANO)
50 #elif defined(IPOD_VIDEO)
52 #elif defined(IPOD_COLOR)
54 #elif defined(IPOD_3G)
57 /* FIXME: calibrate value for other iPods */
62 /* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
63 const unsigned short percent_to_volt_discharge
[BATTERY_TYPES_COUNT
][11] =
65 #if defined(IPOD_NANO)
67 { 3230, 3620, 3700, 3730, 3750, 3780, 3830, 3890, 3950, 4030, 4160 },
68 #elif defined(IPOD_VIDEO)
69 /* iPod Video 30GB Li-Ion 400mAh */
70 { 3600, 3720, 3750, 3780, 3810, 3840, 3880, 3950, 4020, 4100, 4180 },
71 #elif defined(IPOD_COLOR)
72 /* iPod Photo 30GB, see FS#9072 */
73 { 3450, 3660, 3700, 3730, 3750, 3770, 3820, 3870, 3920, 4040, 4170 },
74 #elif defined(IPOD_3G)
75 /* iPod 3G 40GB, first approach based upon measurements */
76 { 3720, 3740, 3760, 3780, 3830, 3870, 3910, 3970, 4020, 4060, 4090 },
78 /* FIXME: calibrate value for other iPods */
79 /* Table is "provisional" from IPOD_COLOR */
80 { 3450, 3660, 3700, 3730, 3750, 3770, 3820, 3870, 3920, 4040, 4170 }
85 /* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
86 const unsigned short percent_to_volt_charge
[11] =
88 #if defined(IPOD_NANO)
90 3230, 3620, 3700, 3730, 3750, 3780, 3830, 3890, 3950, 4030, 4160
91 #elif defined(IPOD_VIDEO)
92 /* iPOD Video 30GB Li-Ion 400mAh */
93 3600, 3720, 3750, 3780, 3810, 3840, 3880, 3950, 4020, 4100, 4180
94 #elif defined(IPOD_COLOR)
95 /* iPod Photo 30GB, see FS#9072 */
96 3450, 3660, 3700, 3730, 3750, 3770, 3820, 3870, 3920, 4040, 4170
97 #elif defined(IPOD_3G)
98 /* iPod 3G 40GB, first approach based upon measurements */
99 3720, 3740, 3760, 3780, 3830, 3870, 3910, 3970, 4020, 4060, 4090
101 /* FIXME: calibrate value for other iPods */
102 /* Table is "provisional" from IPOD_COLOR */
103 3450, 3660, 3700, 3730, 3750, 3770, 3820, 3870, 3920, 4040, 4170
106 #endif /* CONFIG_CHARGING */
108 #define BATTERY_SCALE_FACTOR 6000
109 /* full-scale ADC readout (2^10) in millivolt */
111 /* Returns battery voltage from ADC [millivolts] */
112 unsigned int battery_adc_voltage(void)
114 return (adc_read(ADC_UNREG_POWER
) * BATTERY_SCALE_FACTOR
) >> 10;
117 #ifdef HAVE_ACCESSORY_SUPPLY
118 void accessory_supply_set(bool enable
)
120 /* Set accessory power supply to 3.3V, otherwise switch it off. */
121 unsigned char value
= enable
? 0xf8 : 0x18;
123 /* Write to register. */
124 pcf50605_write(PCF5060X_D2REGC1
, value
);
128 #ifdef HAVE_LINEOUT_POWEROFF
129 void lineout_set(bool enable
)
131 /* Call audio hardware driver implementation */
132 audiohw_enable_lineout(enable
);