Tweaking iPod Video battery configuration. Dangerous battery level is latest reached...
[kugel-rb.git] / firmware / target / arm / ipod / powermgmt-ipod-pcf.c
blob44e908a4a2aee2bced86b6490a4cf48f79ce5072
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 ****************************************************************************/
23 #include "config.h"
24 #include "adc.h"
25 #include "powermgmt.h"
26 #include "pcf5060x.h"
27 #include "pcf50605.h"
28 #include "audiohw.h"
30 const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
32 #if defined(IPOD_NANO)
33 3330
34 #elif defined(IPOD_VIDEO)
35 3500
36 #elif defined(IPOD_COLOR)
37 3300
38 #elif defined(IPOD_3G)
39 3700
40 #else
41 /* FIXME: calibrate value for other iPods */
42 3300
43 #endif
46 const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
48 #if defined(IPOD_NANO)
49 3230
50 #elif defined(IPOD_VIDEO)
51 3300
52 #elif defined(IPOD_COLOR)
53 3300
54 #elif defined(IPOD_3G)
55 3500
56 #else
57 /* FIXME: calibrate value for other iPods */
58 3000
59 #endif
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)
66 /* measured values */
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 },
77 #else
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 }
81 #endif
84 #if CONFIG_CHARGING
85 /* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
86 const unsigned short percent_to_volt_charge[11] =
88 #if defined(IPOD_NANO)
89 /* measured values */
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
100 #else
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
104 #endif
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);
126 #endif
128 #ifdef HAVE_LINEOUT_POWEROFF
129 void lineout_set(bool enable)
131 /* Call audio hardware driver implementation */
132 audiohw_enable_lineout(enable);
134 #endif