2626#define PARAM_CUT_OFF_LOW 0x10
2727#define PARAM_CUT_OFF_HIGH 0x00
2828
29+ enum battery_type {
30+ BATTERY_ADL ,
31+ BATTERY_RPL ,
32+ BATTERY_TYPE_COUNT ,
33+ };
34+
35+ struct board_batt_params {
36+ int design_voltage ;
37+ const char * batt_name ;
38+ const struct battery_info * batt_info ;
39+ };
40+
41+ /*
42+ * Set ADL Battery as default
43+ */
44+ #define DEFAULT_BATTERY_TYPE BATTERY_ADL
45+ static enum battery_type board_battery_type = BATTERY_TYPE_COUNT ;
46+
2947/* Battery info for BQ40Z50 4-cell */
30- static const struct battery_info info = {
48+ static const struct battery_info adl_info = {
3149 .voltage_max = 17600 , /* mV */
3250 .voltage_normal = 15400 ,
3351 .voltage_min = 12000 ,
@@ -40,15 +58,70 @@ static const struct battery_info info = {
4058 .discharging_max_c = 62 ,
4159};
4260
43- static enum battery_present batt_pres_prev = BP_NOT_SURE ;
44- static uint8_t charging_maximum_level = NEED_RESTORE ;
45- static int old_btp ;
61+ static const struct battery_info rpl_info = {
62+ .voltage_max = 17800 , /* mV */
63+ .voltage_normal = 15480 ,
64+ .voltage_min = 12000 ,
65+ .precharge_current = 80 , /* mA */
66+ .start_charging_min_c = 0 ,
67+ .start_charging_max_c = 47 ,
68+ .charging_min_c = 0 ,
69+ .charging_max_c = 52 ,
70+ .discharging_min_c = 0 ,
71+ .discharging_max_c = 62 ,
72+ };
73+
74+ static struct board_batt_params info [] = {
75+ [BATTERY_ADL ] = {
76+ .design_voltage = 15400 ,
77+ .batt_name = "ADL-55W" ,
78+ .batt_info = & adl_info ,
79+ },
80+
81+ [BATTERY_RPL ] = {
82+ .design_voltage = 15480 ,
83+ .batt_name = "RPL-61W" ,
84+ .batt_info = & rpl_info ,
85+ },
86+ };
87+ BUILD_ASSERT (ARRAY_SIZE (info ) == BATTERY_TYPE_COUNT );
88+
89+ /* Get type of the battery connected on the board */
90+ static int board_get_battery_type (void )
91+ {
92+ int i ;
93+ int vol ;
94+
95+ if (!battery_design_voltage (& vol )) {
96+ for (i = 0 ; i < BATTERY_TYPE_COUNT ; i ++ ) {
97+ if (vol == info [i ].design_voltage ) {
98+ board_battery_type = i ;
99+ break ;
100+ }
101+ }
102+ }
103+ return board_battery_type ;
104+ }
105+
106+ static void board_init_battery_type (void )
107+ {
108+ if (board_get_battery_type () != BATTERY_TYPE_COUNT )
109+ ccprintf ("found batt: %s\n" , info [board_battery_type ].batt_name );
110+ else
111+ ccprintf ("battery not found\n" );
112+ }
113+ DECLARE_HOOK (HOOK_INIT , board_init_battery_type , HOOK_PRIO_INIT_ADC + 1 );
46114
47115const struct battery_info * battery_get_info (void )
48116{
49- return & info ;
117+ return info [board_battery_type == BATTERY_TYPE_COUNT ?
118+ DEFAULT_BATTERY_TYPE : board_battery_type ].batt_info ;
50119}
51120
121+ static enum battery_present batt_pres_prev = BP_NOT_SURE ;
122+ static uint8_t charging_maximum_level = NEED_RESTORE ;
123+ static int old_btp ;
124+
52125int board_cut_off_battery (void )
53126{
54127 int rv ;
@@ -95,6 +168,8 @@ static int battery_check_disconnect(void)
95168 if (data [3 ] & BATTERY_DISCHARGING_DISABLED )
96169 return BATTERY_DISCONNECTED ;
97170
171+ /* reinit battery type */
172+ board_init_battery_type ();
98173
99174 return BATTERY_NOT_DISCONNECTED ;
100175}
0 commit comments