1 .cpu arm7tdmi 2 .arch armv4t 3 .fpu softvfp 4 .eabi_attribute 20, 1 5 .eabi_attribute 21, 1 6 .eabi_attribute 23, 3 7 .eabi_attribute 24, 1 8 .eabi_attribute 25, 1 9 .eabi_attribute 26, 1 10 .eabi_attribute 30, 4 11 .eabi_attribute 34, 0 12 .eabi_attribute 18, 4 13 .file "compal_e88.c" 14 .text 15 .Ltext0: 16 .cfi_sections .debug_frame 17 .file 1 "battery/compal_e88.c" 18 .section .rodata.str1.1,"aMS",%progbits,1 19 .LC0: 20 0000 1B5B3334 .ascii "\033[34;1mCHARGER: %s --> %s.\033[0m\012\000" 20 3B316D43 20 48415247 20 45523A20 20 2573202D 21 .LC1: 22 0020 42434943 .ascii "BCICTL2 is 0x%03x, CHGREG=%d\012\000" 22 544C3220 22 69732030 22 78253033 22 782C2043 23 .section .text.bat_compal_e88_goto_state,"ax",%progbits 24 .align 2 25 .syntax unified 26 .arm 28 bat_compal_e88_goto_state: 29 .LVL0: 30 .LFB35: 1:battery/compal_e88.c **** /* Battery management for compal_e88 */ 2:battery/compal_e88.c **** 3:battery/compal_e88.c **** /* (C) 2010 by Christian Vogel 4:battery/compal_e88.c **** * 5:battery/compal_e88.c **** * All Rights Reserved 6:battery/compal_e88.c **** * 7:battery/compal_e88.c **** * This program is free software; you can redistribute it and/or modify 8:battery/compal_e88.c **** * it under the terms of the GNU General Public License as published by 9:battery/compal_e88.c **** * the Free Software Foundation; either version 2 of the License, or 10:battery/compal_e88.c **** * (at your option) any later version. 11:battery/compal_e88.c **** * 12:battery/compal_e88.c **** * This program is distributed in the hope that it will be useful, 13:battery/compal_e88.c **** * but WITHOUT ANY WARRANTY; without even the implied warranty of 14:battery/compal_e88.c **** * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15:battery/compal_e88.c **** * GNU General Public License for more details. 16:battery/compal_e88.c **** * 17:battery/compal_e88.c **** */ 18:battery/compal_e88.c **** 19:battery/compal_e88.c **** /* 20:battery/compal_e88.c **** * ___C123 (compal e88) very simplified diagram of charging circuitry___ 21:battery/compal_e88.c **** * 22:battery/compal_e88.c **** * ICTL 23:battery/compal_e88.c **** * | 24:battery/compal_e88.c **** * v 25:battery/compal_e88.c **** * Charger -> OVP -------> P-Mosfet --->[0.15 Ohm]---> Battery 26:battery/compal_e88.c **** * (NCP345, | | | 27:battery/compal_e88.c **** * 6.85V) v v v 28:battery/compal_e88.c **** * VCHG VCCS VBAT & 29:battery/compal_e88.c **** * VBATS 30:battery/compal_e88.c **** * 31:battery/compal_e88.c **** * Inputs to IOTA: 32:battery/compal_e88.c **** * VCHG: senses voltage on the charger input 33:battery/compal_e88.c **** * VCSS/VBATS: to difference amplifier, to measure charge current 34:battery/compal_e88.c **** * VBAT: senses voltage on the battery terminal 35:battery/compal_e88.c **** * Outputs from IOTA: 36:battery/compal_e88.c **** * ICTL: Control signal for the switching mosfet 37:battery/compal_e88.c **** * 38:battery/compal_e88.c **** */ 39:battery/compal_e88.c **** 40:battery/compal_e88.c **** #include 41:battery/compal_e88.c **** #include 42:battery/compal_e88.c **** 43:battery/compal_e88.c **** #include 44:battery/compal_e88.c **** #include 45:battery/compal_e88.c **** #include 46:battery/compal_e88.c **** #include 47:battery/compal_e88.c **** 48:battery/compal_e88.c **** /* ADC calibration, scale is LSB/uV or LSB/uA, physical unit is mV or mA */ 49:battery/compal_e88.c **** #define ADC_TO_PHYSICAL(adc,scale) (((adc)*(scale)+500)/1000) 50:battery/compal_e88.c **** #define PHYSICAL_TO_ADC(phy,scale) (((phy)*1000+(scale)/2)/(scale)) 51:battery/compal_e88.c **** 52:battery/compal_e88.c **** /* conversion factors for internal IOTA battery charging/sensing circuitry */ 53:battery/compal_e88.c **** #define VREF_LSB_uV 1709 /* VREF = 1.75V --> 1.709 mV/LSB */ 54:battery/compal_e88.c **** #define VBAT_LSB_uV 6836 /* VBAT = 7.0 V FS --> 6.836 mV/LSB */ 55:battery/compal_e88.c **** #define VCHG_LSB_uV 8545 /* VCHG = 8.75V FS --> 8.545 mV/LSB */ 56:battery/compal_e88.c **** #define ICHG_LSB_uA 854 /* ICHG = 875mA FS --> 0.854 mA/LSB */ 57:battery/compal_e88.c **** 58:battery/compal_e88.c **** /* battery is considered full/empty at these thresholds... */ 59:battery/compal_e88.c **** #define VBAT_full PHYSICAL_TO_ADC(4000,VBAT_LSB_uV) 60:battery/compal_e88.c **** #define VBAT_empty PHYSICAL_TO_ADC(3200,VBAT_LSB_uV) 61:battery/compal_e88.c **** 62:battery/compal_e88.c **** /* we declare overvoltage at this point... */ 63:battery/compal_e88.c **** #define VBAT_fail PHYSICAL_TO_ADC(4250,VBAT_LSB_uV) 64:battery/compal_e88.c **** 65:battery/compal_e88.c **** /* DAC to ADC offsets in CC mode with my C123 66:battery/compal_e88.c **** IMEI 358317015976471, P329431014 67:battery/compal_e88.c **** 68:battery/compal_e88.c **** I/mA DAC ADC 69:battery/compal_e88.c **** ---------------- 70:battery/compal_e88.c **** 100 117 108 71:battery/compal_e88.c **** 150 176 168 72:battery/compal_e88.c **** 200 234 227 73:battery/compal_e88.c **** 250 293 291 74:battery/compal_e88.c **** 300 351 349 75:battery/compal_e88.c **** 350 410 410 76:battery/compal_e88.c **** */ 77:battery/compal_e88.c **** 78:battery/compal_e88.c **** #define CHGDAC_GAIN 967 /* times 0.001 */ 79:battery/compal_e88.c **** #define CHGDAC_OFFS 13 80:battery/compal_e88.c **** 81:battery/compal_e88.c **** /* convert ADC reading to DAC value, according to calibration values 82:battery/compal_e88.c **** given above */ 83:battery/compal_e88.c **** #define CHGDAC_ADJ(x) (CHGDAC_GAIN*(x)/1000+CHGDAC_OFFS) 84:battery/compal_e88.c **** 85:battery/compal_e88.c **** /* charging current in DAC LSBs, same ref. and # of bits, but keep 86:battery/compal_e88.c **** the correction specified above in mind! */ 87:battery/compal_e88.c **** 88:battery/compal_e88.c **** #define ICHG_set CHGDAC_ADJ(PHYSICAL_TO_ADC(200,ICHG_LSB_uA)) 89:battery/compal_e88.c **** #define VCHG_set CHGDAC_ADJ(VBAT_full) 90:battery/compal_e88.c **** 91:battery/compal_e88.c **** struct battery_info battery_info; /* global battery info */ 92:battery/compal_e88.c **** uint16_t bat_compal_e88_madc[MADC_NUM_CHANNELS]; /* MADC measurements */ 93:battery/compal_e88.c **** 94:battery/compal_e88.c **** static const int BATTERY_TIMER_DELAY=5000; /* 5000ms for control loop */ 95:battery/compal_e88.c **** static const int ADC_TIMER_DELAY=100; /* 100ms for ADC conversion */ 96:battery/compal_e88.c **** 97:battery/compal_e88.c **** /* thermistor sense current, turn it up to eleven! */ 98:battery/compal_e88.c **** #define TH_SENS (THSENS0|THSENS1|THSENS2|THEN) 99:battery/compal_e88.c **** #define BATTERY_ALL_SENSE (TH_SENS|MESBAT|TYPEN) 100:battery/compal_e88.c **** 101:battery/compal_e88.c **** /* 102:battery/compal_e88.c **** * charger modes state machine 103:battery/compal_e88.c **** * 104:battery/compal_e88.c **** * +------------------+-------------------+ 105:battery/compal_e88.c **** * | | | lost AC power 106:battery/compal_e88.c **** * | ^ ^ 107:battery/compal_e88.c **** * V on AC power | @VBAT_full | 108:battery/compal_e88.c **** * +-----+ +------------+ -----> +------------+ 109:battery/compal_e88.c **** * | OFF | -----> | CONST_CURR | | CONST_VOLT | 110:battery/compal_e88.c **** * +-----+ +------------+ +------------+ 111:battery/compal_e88.c **** * ^ ^ | | 112:battery/compal_e88.c **** * | /failure v v failure 113:battery/compal_e88.c **** * +---------+ / gone | | condition 114:battery/compal_e88.c **** * | FAILURE | <----------+-------------------+ 115:battery/compal_e88.c **** * +---------+ 116:battery/compal_e88.c **** * 117:battery/compal_e88.c **** * Failure modes currently detected: 118:battery/compal_e88.c **** * + high battery voltage 119:battery/compal_e88.c **** * Failure modes TODO: 120:battery/compal_e88.c **** * + high battery temperature 121:battery/compal_e88.c **** */ 122:battery/compal_e88.c **** enum bat_compal_e88_chg_state { 123:battery/compal_e88.c **** CHARG_OFF, 124:battery/compal_e88.c **** CHARG_CONST_CURR, 125:battery/compal_e88.c **** CHARG_CONST_VOLT, 126:battery/compal_e88.c **** CHARG_FAIL 127:battery/compal_e88.c **** }; 128:battery/compal_e88.c **** static enum bat_compal_e88_chg_state bat_compal_e88_chg_state; 129:battery/compal_e88.c **** 130:battery/compal_e88.c **** static const char *bat_compal_e88_chg_state_names[]={ 131:battery/compal_e88.c **** "Off", 132:battery/compal_e88.c **** "Constant Current", 133:battery/compal_e88.c **** "Constant Voltage", 134:battery/compal_e88.c **** "Battery Failure" 135:battery/compal_e88.c **** }; 136:battery/compal_e88.c **** 137:battery/compal_e88.c **** static void 138:battery/compal_e88.c **** bat_compal_e88_goto_state(enum bat_compal_e88_chg_state newstate){ 31 .loc 1 138 66 view -0 32 .cfi_startproc 33 @ Function supports interworking. 34 @ args = 0, pretend = 0, frame = 0 35 @ frame_needed = 0, uses_anonymous_args = 0 139:battery/compal_e88.c **** 140:battery/compal_e88.c **** if(bat_compal_e88_chg_state == newstate) /* already there? */ 36 .loc 1 140 2 view .LVU1 138:battery/compal_e88.c **** 37 .loc 1 138 66 is_stmt 0 view .LVU2 38 0000 70402DE9 push {r4, r5, r6, lr} 39 .LCFI0: 40 .cfi_def_cfa_offset 16 41 .cfi_offset 4, -16 42 .cfi_offset 5, -12 43 .cfi_offset 6, -8 44 .cfi_offset 14, -4 45 .loc 1 140 30 view .LVU3 46 0004 F4509FE5 ldr r5, .L10 47 0008 0010D5E5 ldrb r1, [r5] @ zero_extendqisi2 48 .loc 1 140 4 view .LVU4 49 000c 000051E1 cmp r1, r0 50 0010 2A00000A beq .L1 51 0014 0040A0E1 mov r4, r0 141:battery/compal_e88.c **** return; 142:battery/compal_e88.c **** 143:battery/compal_e88.c **** printf("\033[34;1mCHARGER: %s --> %s.\033[0m\n", 52 .loc 1 143 2 is_stmt 1 view .LVU5 53 0018 E4309FE5 ldr r3, .L10+4 54 001c 002193E7 ldr r2, [r3, r0, lsl #2] 55 0020 011193E7 ldr r1, [r3, r1, lsl #2] 56 0024 DC009FE5 ldr r0, .L10+8 57 .LVL1: 58 .loc 1 143 2 is_stmt 0 view .LVU6 59 0028 FEFFFFEB bl printf 60 .LVL2: 144:battery/compal_e88.c **** bat_compal_e88_chg_state_names[bat_compal_e88_chg_state], 145:battery/compal_e88.c **** bat_compal_e88_chg_state_names[newstate]); 146:battery/compal_e88.c **** 147:battery/compal_e88.c **** /* update user visible flags, set registers */ 148:battery/compal_e88.c **** switch(newstate){ 61 .loc 1 148 2 is_stmt 1 view .LVU7 62 002c 010054E3 cmp r4, #1 63 0030 0430D5E5 ldrb r3, [r5, #4] @ zero_extendqisi2 64 0034 0800000A beq .L3 65 0038 020054E3 cmp r4, #2 66 003c 2100000A beq .L4 149:battery/compal_e88.c **** case CHARG_CONST_CURR: 150:battery/compal_e88.c **** battery_info.flags &= ~BATTERY_FAILURE; 151:battery/compal_e88.c **** battery_info.flags |= (BATTERY_CHG_ENABLED| 152:battery/compal_e88.c **** BATTERY_CHARGING); 153:battery/compal_e88.c **** twl3025_reg_write(BCICTL2,0); 154:battery/compal_e88.c **** twl3025_reg_write(CHGREG,0); 155:battery/compal_e88.c **** twl3025_reg_write(BCICTL2,CHEN|LEDC|CHIV); 156:battery/compal_e88.c **** twl3025_reg_write(CHGREG,ICHG_set); 157:battery/compal_e88.c **** 158:battery/compal_e88.c **** break; 159:battery/compal_e88.c **** 160:battery/compal_e88.c **** case CHARG_CONST_VOLT: 161:battery/compal_e88.c **** battery_info.flags &= ~( BATTERY_CHARGING | 162:battery/compal_e88.c **** BATTERY_FAILURE ); 163:battery/compal_e88.c **** battery_info.flags |= BATTERY_CHG_ENABLED; 164:battery/compal_e88.c **** twl3025_reg_write(BCICTL2,0); 165:battery/compal_e88.c **** twl3025_reg_write(CHGREG,0); 166:battery/compal_e88.c **** twl3025_reg_write(BCICTL2,CHEN|LEDC); 167:battery/compal_e88.c **** twl3025_reg_write(CHGREG,VCHG_set); 168:battery/compal_e88.c **** break; 169:battery/compal_e88.c **** 170:battery/compal_e88.c **** case CHARG_FAIL: 171:battery/compal_e88.c **** case CHARG_OFF: 172:battery/compal_e88.c **** default: 173:battery/compal_e88.c **** battery_info.flags &= ~( BATTERY_CHG_ENABLED | 67 .loc 1 173 3 view .LVU8 174:battery/compal_e88.c **** BATTERY_CHARGING | BATTERY_FAILURE ); 175:battery/compal_e88.c **** twl3025_reg_write(BCICTL2,0); /* turn off charger */ 68 .loc 1 175 3 is_stmt 0 view .LVU9 69 0040 0010A0E3 mov r1, #0 173:battery/compal_e88.c **** BATTERY_CHARGING | BATTERY_FAILURE ); 70 .loc 1 173 22 view .LVU10 71 0044 0E30C3E3 bic r3, r3, #14 72 .loc 1 175 3 view .LVU11 73 0048 1D00A0E3 mov r0, #29 173:battery/compal_e88.c **** BATTERY_CHARGING | BATTERY_FAILURE ); 74 .loc 1 173 22 view .LVU12 75 004c 0430C5E5 strb r3, [r5, #4] 76 .loc 1 175 3 is_stmt 1 view .LVU13 77 0050 FEFFFFEB bl twl3025_reg_write 78 .LVL3: 176:battery/compal_e88.c **** twl3025_reg_write(CHGREG,0); 79 .loc 1 176 3 view .LVU14 80 0054 0010A0E3 mov r1, #0 81 0058 0C0000EA b .L9 82 .L3: 150:battery/compal_e88.c **** battery_info.flags |= (BATTERY_CHG_ENABLED| 83 .loc 1 150 3 view .LVU15 151:battery/compal_e88.c **** BATTERY_CHARGING); 84 .loc 1 151 3 view .LVU16 150:battery/compal_e88.c **** battery_info.flags |= (BATTERY_CHG_ENABLED| 85 .loc 1 150 22 is_stmt 0 view .LVU17 86 005c 0830C3E3 bic r3, r3, #8 151:battery/compal_e88.c **** BATTERY_CHARGING); 87 .loc 1 151 22 view .LVU18 88 0060 063083E3 orr r3, r3, #6 153:battery/compal_e88.c **** twl3025_reg_write(CHGREG,0); 89 .loc 1 153 3 view .LVU19 90 0064 0010A0E3 mov r1, #0 91 0068 1D00A0E3 mov r0, #29 151:battery/compal_e88.c **** BATTERY_CHARGING); 92 .loc 1 151 22 view .LVU20 93 006c 0430C5E5 strb r3, [r5, #4] 153:battery/compal_e88.c **** twl3025_reg_write(CHGREG,0); 94 .loc 1 153 3 is_stmt 1 view .LVU21 95 0070 FEFFFFEB bl twl3025_reg_write 96 .LVL4: 154:battery/compal_e88.c **** twl3025_reg_write(BCICTL2,CHEN|LEDC|CHIV); 97 .loc 1 154 3 view .LVU22 98 0074 0010A0E3 mov r1, #0 99 0078 1900A0E3 mov r0, #25 100 007c FEFFFFEB bl twl3025_reg_write 101 .LVL5: 155:battery/compal_e88.c **** twl3025_reg_write(CHGREG,ICHG_set); 102 .loc 1 155 3 view .LVU23 103 0080 2310A0E3 mov r1, #35 104 0084 1D00A0E3 mov r0, #29 105 0088 FEFFFFEB bl twl3025_reg_write 106 .LVL6: 156:battery/compal_e88.c **** 107 .loc 1 156 3 view .LVU24 108 008c EF10A0E3 mov r1, #239 109 .L9: 110 .loc 1 176 3 is_stmt 0 view .LVU25 111 0090 1900A0E3 mov r0, #25 112 0094 FEFFFFEB bl twl3025_reg_write 113 .LVL7: 177:battery/compal_e88.c **** break; 114 .loc 1 177 3 is_stmt 1 view .LVU26 178:battery/compal_e88.c **** } 179:battery/compal_e88.c **** 180:battery/compal_e88.c **** printf("BCICTL2 is 0x%03x, CHGREG=%d\n", 115 .loc 1 180 2 view .LVU27 181:battery/compal_e88.c **** twl3025_reg_read(BCICTL2), 116 .loc 1 181 4 is_stmt 0 view .LVU28 117 0098 1D00A0E3 mov r0, #29 118 009c FEFFFFEB bl twl3025_reg_read 119 .LVL8: 120 00a0 0060A0E1 mov r6, r0 182:battery/compal_e88.c **** twl3025_reg_read(CHGREG)); 121 .loc 1 182 4 view .LVU29 122 00a4 1900A0E3 mov r0, #25 123 00a8 FEFFFFEB bl twl3025_reg_read 124 .LVL9: 180:battery/compal_e88.c **** twl3025_reg_read(BCICTL2), 125 .loc 1 180 2 view .LVU30 126 00ac 0610A0E1 mov r1, r6 127 .loc 1 182 4 view .LVU31 128 00b0 0020A0E1 mov r2, r0 180:battery/compal_e88.c **** twl3025_reg_read(BCICTL2), 129 .loc 1 180 2 view .LVU32 130 00b4 50009FE5 ldr r0, .L10+12 131 00b8 FEFFFFEB bl printf 132 .LVL10: 183:battery/compal_e88.c **** 184:battery/compal_e88.c **** bat_compal_e88_chg_state = newstate; 133 .loc 1 184 2 is_stmt 1 view .LVU33 134 .loc 1 184 27 is_stmt 0 view .LVU34 135 00bc 0040C5E5 strb r4, [r5] 136 .L1: 185:battery/compal_e88.c **** } 137 .loc 1 185 1 view .LVU35 138 00c0 7040BDE8 pop {r4, r5, r6, lr} 139 .LCFI1: 140 .cfi_remember_state 141 .cfi_restore 14 142 .cfi_restore 6 143 .cfi_restore 5 144 .cfi_restore 4 145 .cfi_def_cfa_offset 0 146 00c4 1EFF2FE1 bx lr 147 .L4: 148 .LCFI2: 149 .cfi_restore_state 161:battery/compal_e88.c **** BATTERY_FAILURE ); 150 .loc 1 161 3 is_stmt 1 view .LVU36 163:battery/compal_e88.c **** twl3025_reg_write(BCICTL2,0); 151 .loc 1 163 3 view .LVU37 161:battery/compal_e88.c **** BATTERY_FAILURE ); 152 .loc 1 161 22 is_stmt 0 view .LVU38 153 00c8 0C30C3E3 bic r3, r3, #12 163:battery/compal_e88.c **** twl3025_reg_write(BCICTL2,0); 154 .loc 1 163 22 view .LVU39 155 00cc 023083E3 orr r3, r3, #2 164:battery/compal_e88.c **** twl3025_reg_write(CHGREG,0); 156 .loc 1 164 3 view .LVU40 157 00d0 0010A0E3 mov r1, #0 158 00d4 1D00A0E3 mov r0, #29 163:battery/compal_e88.c **** twl3025_reg_write(BCICTL2,0); 159 .loc 1 163 22 view .LVU41 160 00d8 0430C5E5 strb r3, [r5, #4] 164:battery/compal_e88.c **** twl3025_reg_write(CHGREG,0); 161 .loc 1 164 3 is_stmt 1 view .LVU42 162 00dc FEFFFFEB bl twl3025_reg_write 163 .LVL11: 165:battery/compal_e88.c **** twl3025_reg_write(BCICTL2,CHEN|LEDC); 164 .loc 1 165 3 view .LVU43 165 00e0 0010A0E3 mov r1, #0 166 00e4 1900A0E3 mov r0, #25 167 00e8 FEFFFFEB bl twl3025_reg_write 168 .LVL12: 166:battery/compal_e88.c **** twl3025_reg_write(CHGREG,VCHG_set); 169 .loc 1 166 3 view .LVU44 170 00ec 2110A0E3 mov r1, #33 171 00f0 1D00A0E3 mov r0, #29 172 00f4 FEFFFFEB bl twl3025_reg_write 173 .LVL13: 167:battery/compal_e88.c **** break; 174 .loc 1 167 3 view .LVU45 175 00f8 10109FE5 ldr r1, .L10+16 176 00fc E3FFFFEA b .L9 177 .L11: 178 .align 2 179 .L10: 180 0100 00000000 .word .LANCHOR0 181 0104 00000000 .word .LANCHOR1 182 0108 00000000 .word .LC0 183 010c 20000000 .word .LC1 184 0110 42020000 .word 578 185 .cfi_endproc 186 .LFE35: 188 .global __aeabi_uidiv 189 .global __aeabi_idiv 190 .section .rodata.str1.1 191 .LC2: 192 003e 4241542D .ascii "BAT-ADC: \000" 192 4144433A 192 2000 193 .LC3: 194 0048 25336420 .ascii "%3d \000" 194 00 195 .LC4: 196 004d 25630A00 .ascii "%c\012\000" 197 .LC5: 198 0051 09436861 .ascii "\011Charger at %u mV.\012\000" 198 72676572 198 20617420 198 2575206D 198 562E0A00 199 .LC6: 200 0065 09426174 .ascii "\011Battery at %u mV.\012\000" 200 74657279 200 20617420 200 2575206D 200 562E0A00 201 .LC7: 202 0079 09436861 .ascii "\011Charging at %u mA.\012\000" 202 7267696E 202 67206174 202 20257520 202 6D412E0A 203 .LC8: 204 008e 09426174 .ascii "\011Battery capacity is %u%%.\012\000" 204 74657279 204 20636170 204 61636974 204 79206973 205 .LC9: 206 00aa 09426174 .ascii "\011Battery range is %d..%d mV.\012\000" 206 74657279 206 2072616E 206 67652069 206 73202564 207 .LC10: 208 00c8 09426174 .ascii "\011Battery full at %d LSB .. full at %d LSB\012\000" 208 74657279 208 2066756C 208 6C206174 208 20256420 209 .LC11: 210 00f3 09436861 .ascii "\011Charging at %d LSB (%d mA).\012\000" 210 7267696E 210 67206174 210 20256420 210 4C534220 211 .LC12: 212 0111 09424349 .ascii "\011BCICTL2=0x%03x\012\000" 212 43544C32 212 3D307825 212 3033780A 212 00 213 .LC13: 214 0122 09626174 .ascii "\011battery-info.flags=0x%08x\012\000" 214 74657279 214 2D696E66 214 6F2E666C 214 6167733D 215 .LC14: 216 013e 09626174 .ascii "\011bat_compal_e88_chg_state=%d\012\000" 216 5F636F6D 216 70616C5F 216 6538385F 216 6368675F 217 .LC15: 218 015c 1B5B3334 .ascii "\033[34;1mCHARGER: external voltage connected!\033[" 218 3B316D43 218 48415247 218 45523A20 218 65787465 219 0189 306D0A00 .ascii "0m\012\000" 220 .LC16: 221 018d 1B5B3334 .ascii "\033[34;1mCHARGER: external voltage disconnected!\033" 221 3B316D43 221 48415247 221 45523A20 221 65787465 222 01bc 5B306D0A .ascii "[0m\012\000" 222 00 223 .section .text.battery_compal_e88_timer_cb,"ax",%progbits 224 .align 2 225 .syntax unified 226 .arm 228 battery_compal_e88_timer_cb: 229 .LVL14: 230 .LFB40: 186:battery/compal_e88.c **** 187:battery/compal_e88.c **** static void 188:battery/compal_e88.c **** bat_compal_e88_chg_control(){ 189:battery/compal_e88.c **** /* with AC power disconnected, always go to off state */ 190:battery/compal_e88.c **** if(!(battery_info.flags & BATTERY_CHG_CONNECTED)){ 191:battery/compal_e88.c **** bat_compal_e88_goto_state(CHARG_OFF); 192:battery/compal_e88.c **** return; 193:battery/compal_e88.c **** } 194:battery/compal_e88.c **** 195:battery/compal_e88.c **** /* if failure condition is detected, always goto failure state */ 196:battery/compal_e88.c **** if(bat_compal_e88_madc[MADC_VBAT] > VBAT_fail){ 197:battery/compal_e88.c **** bat_compal_e88_goto_state(CHARG_FAIL); 198:battery/compal_e88.c **** return; 199:battery/compal_e88.c **** } 200:battery/compal_e88.c **** 201:battery/compal_e88.c **** /* now AC power is present and battery is not over failure 202:battery/compal_e88.c **** thresholds */ 203:battery/compal_e88.c **** switch(bat_compal_e88_chg_state){ 204:battery/compal_e88.c **** case CHARG_OFF: 205:battery/compal_e88.c **** if(bat_compal_e88_madc[MADC_VBAT] >= VBAT_full) 206:battery/compal_e88.c **** bat_compal_e88_goto_state(CHARG_CONST_VOLT); 207:battery/compal_e88.c **** else 208:battery/compal_e88.c **** bat_compal_e88_goto_state(CHARG_CONST_CURR); 209:battery/compal_e88.c **** break; 210:battery/compal_e88.c **** case CHARG_CONST_CURR: 211:battery/compal_e88.c **** if(bat_compal_e88_madc[MADC_VBAT] >= VBAT_full) 212:battery/compal_e88.c **** bat_compal_e88_goto_state(CHARG_CONST_VOLT); 213:battery/compal_e88.c **** break; 214:battery/compal_e88.c **** case CHARG_CONST_VOLT: 215:battery/compal_e88.c **** break; 216:battery/compal_e88.c **** default: 217:battery/compal_e88.c **** case CHARG_FAIL: 218:battery/compal_e88.c **** if(bat_compal_e88_madc[MADC_VBAT] < VBAT_full) 219:battery/compal_e88.c **** bat_compal_e88_goto_state(CHARG_CONST_CURR); 220:battery/compal_e88.c **** break; 221:battery/compal_e88.c **** } 222:battery/compal_e88.c **** } 223:battery/compal_e88.c **** 224:battery/compal_e88.c **** /* 225:battery/compal_e88.c **** * Charging voltage connection - state machine, remembers 226:battery/compal_e88.c **** * state in battery_info.flags. 227:battery/compal_e88.c **** * 228:battery/compal_e88.c **** * VCHG > VCHG_thr_on 229:battery/compal_e88.c **** * +-----------------+ ------------------> +---------------+ 230:battery/compal_e88.c **** * | ! CHG_CONNECTED | | CHG_CONNECTED | 231:battery/compal_e88.c **** * +-----------------+ <------------------ +---------------+ 232:battery/compal_e88.c **** * VCHG < VCHG_thr_off 233:battery/compal_e88.c **** */ 234:battery/compal_e88.c **** static void 235:battery/compal_e88.c **** bat_compal_e88_chk_ac_presence(){ 236:battery/compal_e88.c **** int vrpcsts = twl3025_reg_read(VRPCSTS); 237:battery/compal_e88.c **** 238:battery/compal_e88.c **** /* check for presence of charging voltage */ 239:battery/compal_e88.c **** if(!(battery_info.flags & BATTERY_CHG_CONNECTED)){ 240:battery/compal_e88.c **** if(vrpcsts & CHGPRES){ 241:battery/compal_e88.c **** puts("\033[34;1mCHARGER: external voltage connected!\033[0m\n"); 242:battery/compal_e88.c **** battery_info.flags |= BATTERY_CHG_CONNECTED; 243:battery/compal_e88.c **** 244:battery/compal_e88.c **** /* always keep ADC, voltage dividers and bias voltages on */ 245:battery/compal_e88.c **** twl3025_unit_enable(TWL3025_UNIT_MAD,1); 246:battery/compal_e88.c **** twl3025_reg_write(BCICTL1,BATTERY_ALL_SENSE); 247:battery/compal_e88.c **** } 248:battery/compal_e88.c **** } else { 249:battery/compal_e88.c **** if(!(vrpcsts & CHGPRES)){ 250:battery/compal_e88.c **** /* we'll only run ADC on demand */ 251:battery/compal_e88.c **** twl3025_unit_enable(TWL3025_UNIT_MAD,0); 252:battery/compal_e88.c **** twl3025_reg_write(BCICTL1,0); 253:battery/compal_e88.c **** 254:battery/compal_e88.c **** battery_info.flags &= ~ BATTERY_CHG_CONNECTED; 255:battery/compal_e88.c **** puts("\033[34;1mCHARGER: external voltage disconnected!\033[0m\n"); 256:battery/compal_e88.c **** } 257:battery/compal_e88.c **** } 258:battery/compal_e88.c **** } 259:battery/compal_e88.c **** 260:battery/compal_e88.c **** /* ---- update voltages visible to the user ---- */ 261:battery/compal_e88.c **** static void 262:battery/compal_e88.c **** bat_compal_e88_upd_measurements(){ 263:battery/compal_e88.c **** int adc,i; 264:battery/compal_e88.c **** 265:battery/compal_e88.c **** battery_info.charger_volt_mV= 266:battery/compal_e88.c **** ADC_TO_PHYSICAL(bat_compal_e88_madc[MADC_VCHG],VCHG_LSB_uV); 267:battery/compal_e88.c **** battery_info.bat_volt_mV= 268:battery/compal_e88.c **** ADC_TO_PHYSICAL(bat_compal_e88_madc[MADC_VBAT],VBAT_LSB_uV); 269:battery/compal_e88.c **** battery_info.bat_chg_curr_mA= 270:battery/compal_e88.c **** ADC_TO_PHYSICAL(bat_compal_e88_madc[MADC_ICHG],ICHG_LSB_uA); 271:battery/compal_e88.c **** 272:battery/compal_e88.c **** adc = bat_compal_e88_madc[MADC_VBAT]; 273:battery/compal_e88.c **** if(adc <= VBAT_empty){ /* battery 0..100% */ 274:battery/compal_e88.c **** battery_info.battery_percent = 0; 275:battery/compal_e88.c **** } else if (adc >= VBAT_full){ 276:battery/compal_e88.c **** battery_info.battery_percent = 100; 277:battery/compal_e88.c **** } else { 278:battery/compal_e88.c **** battery_info.battery_percent = 279:battery/compal_e88.c **** (50+100*(adc-VBAT_empty))/(VBAT_full-VBAT_empty); 280:battery/compal_e88.c **** } 281:battery/compal_e88.c **** 282:battery/compal_e88.c **** /* DEBUG */ 283:battery/compal_e88.c **** printf("BAT-ADC: "); 284:battery/compal_e88.c **** for(i=0;i= VBAT_full){ 393 .loc 1 274 32 view .LVU99 394 0100 140084E5 str r0, [r4, #20] 283:battery/compal_e88.c **** for(i=0;i