55#include <zephyr/drivers/gpio.h>
66
77#include "battery.h"
8+ #include "battery_smart.h"
9+ #include "battery_fuel_gauge.h"
810#include "board_charger.h"
911#include "charge_manager.h"
1012#include "charge_state.h"
@@ -33,10 +35,11 @@ static void charger_chips_init(void)
3335 * after ADC
3436 */
3537
36- int chip ;
38+ const int no_battery_current_limit_override_ma = 3000 ;
39+ const struct battery_info * bi = battery_get_info ();
3740 uint16_t val = 0x0000 ; /*default ac setting */
3841 uint32_t data = 0 ;
39-
42+ int value ;
4043
4144 /*
4245 * In our case the EC can boot before the charger has power so
@@ -50,18 +53,69 @@ static void charger_chips_init(void)
5053 return ;
5154 }
5255
53- for (chip = 0 ; chip < board_get_charger_chip_count (); chip ++ ) {
54- if (chg_chips [chip ].drv -> init )
55- chg_chips [chip ].drv -> init (chip );
56+ if (i2c_write16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
57+ ISL9241_REG_CONTROL4 , ISL9241_CONTROL4_WOCP_FUNCTION |
58+ ISL9241_CONTROL4_VSYS_SHORT_CHECK |
59+ ISL9241_CONTROL4_ACOK_BATGONE_DEBOUNCE_25US ))
60+ goto init_fail ;
61+
62+ /*
63+ * Set control3 register to
64+ * [14]: ACLIM Reload (Do not reload)
65+ */
66+ if (i2c_write16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
67+ ISL9241_REG_CONTROL3 ,
68+ (ISL9241_CONTROL3_ACLIM_RELOAD | ISL9241_CONTROL3_ENABLE_ADC )))
69+ goto init_fail ;
70+
71+ value = battery_is_charge_fet_disabled ();
72+ /* reverse the flag if no error */
73+ if (value != -1 )
74+ value = !value ;
75+ /*
76+ * When there is no battery, override charger current limit to
77+ * prevent brownout during boot.
78+ */
79+ if (value == -1 ) {
80+ ccprints ("No Battery Found - Override Current Limit to %dmA" ,
81+ no_battery_current_limit_override_ma );
82+ charger_set_input_current_limit (
83+ CHARGER_SOLO , no_battery_current_limit_override_ma );
5684 }
5785
86+ /* According to Power team suggest, Set ACOK reference to 4.544V */
5887 if (i2c_write16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
59- ISL9241_REG_CONTROL2 ,
60- ISL9241_CONTROL2_TRICKLE_CHG_CURR (128 ) |
61- ISL9241_CONTROL2_GENERAL_PURPOSE_COMPARATOR |
62- ISL9241_CONTROL2_PROCHOT_DEBOUNCE_100 ))
88+ ISL9241_REG_ACOK_REFERENCE , ISL9241_MV_TO_ACOK_REFERENCE (4207 )))
89+ goto init_fail ;
90+
91+
92+ /*
93+ * Set the MaxSystemVoltage to battery maximum,
94+ * 0x00=disables switching charger states
95+ */
96+ if (value == -1 ) {
97+ if (i2c_write16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
98+ ISL9241_REG_MAX_SYSTEM_VOLTAGE , 15400 ))
99+ goto init_fail ;
100+ } else {
101+ if (i2c_write16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
102+ ISL9241_REG_MAX_SYSTEM_VOLTAGE , bi -> voltage_max ))
103+ goto init_fail ;
104+ }
105+
106+ /*
107+ * Set the MinSystemVoltage to battery minimum,
108+ * 0x00=disables all battery charging
109+ */
110+ if (i2c_write16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
111+ ISL9241_REG_MIN_SYSTEM_VOLTAGE , bi -> voltage_min ))
63112 goto init_fail ;
64113
114+ if (i2c_write16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
115+ ISL9241_REG_CONTROL2 ,
116+ ISL9241_CONTROL2_TRICKLE_CHG_CURR (bi -> precharge_current ) |
117+ ISL9241_CONTROL2_PROCHOT_DEBOUNCE_1000 ))
118+ goto init_fail ;
65119
66120 if (i2c_write16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
67121 ISL9241_REG_CONTROL0 , 0x0000 ))
@@ -78,19 +132,8 @@ static void charger_chips_init(void)
78132 ISL9241_REG_CONTROL1 , val ))
79133 goto init_fail ;
80134
81- /* According to Power team suggest, Set ACOK reference to 4.544V */
82- if (i2c_write16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
83- ISL9241_REG_ACOK_REFERENCE , 0x0B00 ))
84- goto init_fail ;
85-
86- if (i2c_write16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
87- ISL9241_REG_CONTROL4 , ISL9241_CONTROL4_WOCP_FUNCTION |
88- ISL9241_CONTROL4_VSYS_SHORT_CHECK |
89- ISL9241_CONTROL4_ACOK_BATGONE_DEBOUNCE_25US ))
90- goto init_fail ;
91-
92135 /* TODO: should we need to talk to PD chip after initial complete ? */
93- CPRINTS ("ISL9241 customized initial complete!" );
136+ CPRINTS ("ISL9241 customized initial complete! 3F:%d" , value );
94137 return ;
95138
96139init_fail :
0 commit comments