Gigabeat S: Use longer battery filter; lag is not a problem with voltage for charging...
[kugel-rb.git] / firmware / target / arm / imx31 / gigabeat-s / powermgmt-target.h
blobc881bed68cffdd06689e7341dc8b8d398f704530
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2008 by Michael Sevakis
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #ifndef POWERMGMT_TARGET_H
22 #define POWERMGMT_TARGET_H
24 /* Can't just run this code willy-nilly. Do not allow charger engagement
25 * without carefully verifying compatibility.
27 * Things to check:
28 * 1) Charge path configuration for the PMIC.
29 * 2) Correct thermistor reading
30 * 3) Accurate voltage readings
31 * 4) Accurate current sense for the charge path as the sense resistor may
32 * deviate from the 0.1 ohms assumed by the charge path regulator.
34 #ifdef TOSHIBA_GIGABEAT_S
36 * Gigabeat S qualifications:
37 * 1) Setup for dual-supply mode with separate inputs and providing USB
38 * charging capability through external components.
39 * 2) Curve obtained experimentally - extreme deviation from "optimized"
40 * characteristics.
41 * 3) Verified at battery terminals - no deviation from datasheet formula.
42 * 4) 0.316 ohms <=?? - verified by comparitive current readings on device
43 * with ammeter readings and measurement of on-board components.
45 #ifndef BOOTLOADER
46 #define IMX31_ALLOW_CHARGING
47 #endif
49 #else
50 #warning This iMX31 target requires validation of charging algorithm - charging disabled
51 #endif
53 #define BATT_VTRICKLE_CHARGE 2900 /* Must charge slowly */
54 #define BATT_VSLOW_CHARGE 3500 /* Lower-current charge mode below
55 * this level */
56 #define BATT_FULL_VOLTAGE 4161 /* Battery already topped */
57 #define BATT_VAUTO_RECHARGE 4100 /* When to begin another cycle */
58 #define BATT_USB_VAUTO_RECHARGE 4000 /* When to cycle with USB only */
59 #define BATT_USB_VSTOP 4140 /* When to "stop" when USB only */
60 #define BATT_TOO_LOW 2400 /* No battery? Short? Can't
61 read below 2400mV. */
62 #define BATT_TOO_HIGH 4220 /* Extra care. Don't totally
63 rely upon battery protection
64 circutry. Stop it early if too
65 high. */
66 #define CHARGER_TOTAL_TIMER 300 /* minutes */
68 /* Temperature readings - w/hysteresis */
70 /* Temperature range before beginning charging */
71 #define BATTERY_CHARGE_MIN 0
72 #define BATTERY_CHARGE_MAX 50
73 /* Temperature range after out-of-range detected - charging will
74 * self-resume */
75 #define BATTERY_CHARGE_RESTART_MIN 5
76 #define BATTERY_CHARGE_RESTART_MAX 45
78 /* .316 ohms is closest standard value as measured in 1% tolerance - adjust
79 * relative to .100 ohm which is what the PMIC is "tuned" for. */
80 #define ILEVEL_ADJUST_IN(I) (100*(I) / 316)
81 #define ILEVEL_ADJUST_OUT(I) (316*(I) / 100)
83 /* Relative draw to battery capacity - adjusted for sense resistor */
84 #define BATTERY_ICHARGE_COMPLETE (505*9/100) /* 9% of nominal max output */
85 /* All charging modes use 4.200V for regulator */
86 #define BATTERY_VCHARGING MC13783_VCHRG_4_200V
87 /* Slow charging - MAIN - Still below 3.5V (avoid excessive reg. dissipation) */
88 /* #define BATTERY_ISLOW */
89 /* Fast charging - MAIN */
90 #define BATTERY_IFAST MC13783_ICHRG_1596MA /* 505mA */
91 /* Trickle charging low battery - MAIN (~10% Imax) */
92 #define BATTERY_ITRICKLE MC13783_ICHRG_177MA /* 56mA */
93 /* Slow charging - USB - Still below 3.5V (avoid excessive reg. dissipation) */
94 /* #define BATTERY_ISLOW_USB */
95 /* Fast charging - USB */
96 #define BATTERY_IFAST_USB MC13783_ICHRG_1152MA /* 365mA */
97 /* Trickle charging low battery - USB (Ibat = Icccv - Idevice) */
98 #define BATTERY_ITRICKLE_USB MC13783_ICHRG_532MA /* 168mA */
99 /* Maintain charge - USB 500mA */
100 #define BATTERY_IFLOAT_USB MC13783_ICHRG_1152MA /* 365mA */
101 #define BATTERY_VFLOAT_USB MC13783_VCHRG_4_150V
102 /* Maintain charge - USB 100mA */
103 #define BATTERY_IMAINTAIN_USB MC13783_ICHRG_266MA /* 84mA */
104 #define BATTERY_VMAINTAIN_USB MC13783_VCHRG_4_150V
106 /* Battery filter lengths in samples */
107 #define BATT_AVE_SAMPLES 128
108 #define ICHARGER_AVE_SAMPLES 32
110 void powermgmt_init_target(void);
111 void charging_algorithm_step(void);
112 void charging_algorithm_close(void);
114 /* Provide filtered charge current */
115 int battery_charge_current(void);
117 #if 0
118 #define CURRENT_MAX_CHG battery_charge_current()
119 #endif
121 #endif /* POWERMGMT_TARGET_H */