Lines Matching refs:cw221x

124 static u8 cw221x_read(struct cw221x_info *cw221x, u8 reg, u8 *buffer)  in cw221x_read()  argument
129 ret = dm_i2c_read(cw221x->dev, reg, &val, 1); in cw221x_read()
139 static int cw221x_write(struct cw221x_info *cw221x, u8 reg, u8 val) in cw221x_write() argument
143 ret = dm_i2c_write(cw221x->dev, reg, &val, 1); in cw221x_write()
150 static int cw221x_read_half_word(struct cw221x_info *cw221x, in cw221x_read_half_word() argument
157 ret = cw221x_read(cw221x, reg, &valh); in cw221x_read_half_word()
161 ret = cw221x_read(cw221x, reg + 1, &vall); in cw221x_read_half_word()
172 struct cw221x_info *cw221x = dev_get_priv(dev); in cw221x_ofdata_to_platdata() local
178 cw221x->bat_profile = config_profile_info; in cw221x_ofdata_to_platdata()
183 size = sizeof(*cw221x->bat_profile) * len; in cw221x_ofdata_to_platdata()
184 cw221x->bat_profile = calloc(size, 1); in cw221x_ofdata_to_platdata()
185 if (!cw221x->bat_profile) { in cw221x_ofdata_to_platdata()
196 cw221x->bat_profile[i] = info[i]; in cw221x_ofdata_to_platdata()
197 CW_DBG("%#x ", cw221x->bat_profile[i]); in cw221x_ofdata_to_platdata()
205 static int cw221x_get_vol(struct cw221x_info *cw221x) in cw221x_get_vol() argument
210 cw221x_read_half_word(cw221x, REG_VCELL_H, &value16); in cw221x_get_vol()
213 cw221x_read_half_word(cw221x, REG_VCELL_H, &value16_1); in cw221x_get_vol()
217 cw221x_read_half_word(cw221x, REG_VCELL_H, &value16_2); in cw221x_get_vol()
241 static int cw221x_get_usb_state(struct cw221x_info *cw221x) in cw221x_get_usb_state() argument
264 static bool cw221x_check_charge(struct cw221x_info *cw221x) in cw221x_check_charge() argument
266 if (cw221x_get_usb_state(cw221x) != CHARGER_TYPE_NO) in cw221x_check_charge()
272 static int cw221x_get_soc(struct cw221x_info *cw221x) in cw221x_get_soc() argument
279 ret = cw221x_read_half_word(cw221x, REG_SOC_INT, &value16); in cw221x_get_soc()
286 ret = cw221x_read_half_word(cw221x, REG_SOC_INT, &value16_1); in cw221x_get_soc()
294 ret = cw221x_read_half_word(cw221x, REG_SOC_INT, &value16_2); in cw221x_get_soc()
317 struct cw221x_info *cw221x = dev_get_priv(dev); in cw221x_update_get_soc() local
319 return cw221x_get_soc(cw221x); in cw221x_update_get_soc()
326 static void cw221X_get_chip_id(struct cw221x_info *cw221x) in cw221X_get_chip_id() argument
331 ret = cw221x_read(cw221x, REG_CHIP_ID, &chip_id); in cw221X_get_chip_id()
337 cw221x->chip_id = chip_id; in cw221X_get_chip_id()
340 static int cw221X_active(struct cw221x_info *cw221x) in cw221X_active() argument
344 cw221x_write(cw221x, REG_MODE_CONFIG, reg_val); in cw221X_active()
347 cw221x_write(cw221x, REG_MODE_CONFIG, reg_val); in cw221X_active()
353 static int cw221X_sleep(struct cw221x_info *cw221x) in cw221X_sleep() argument
357 cw221x_write(cw221x, REG_MODE_CONFIG, reg_val); in cw221X_sleep()
360 cw221x_write(cw221x, REG_MODE_CONFIG, reg_val); in cw221X_sleep()
366 static int cw_write_profile(struct cw221x_info *cw221x, u8 buf[]) in cw_write_profile() argument
372 ret = cw221x_write(cw221x, REG_BAT_PROFILE + i, buf[i]); in cw_write_profile()
386 static int cw221X_get_state(struct cw221x_info *cw221x) in cw221X_get_state() argument
392 ret = cw221x_read(cw221x, REG_MODE_CONFIG, &reg_val); in cw221X_get_state()
401 ret = cw221x_read(cw221x, REG_SOC_ALERT, &reg_val); in cw221X_get_state()
411 ret = cw221x_read(cw221x, (REG_BAT_PROFILE + i), &reg_val); in cw221X_get_state()
417 if (cw221x->bat_profile[i] != reg_val) in cw221X_get_state()
427 static int cw_config_start_ic(struct cw221x_info *cw221x) in cw_config_start_ic() argument
433 cw221X_sleep(cw221x); in cw_config_start_ic()
434 cw_write_profile(cw221x, cw221x->bat_profile); in cw_config_start_ic()
435 cw221X_active(cw221x); in cw_config_start_ic()
439 ret = cw221x_write(cw221x, REG_SOC_ALERT, reg_val); in cw_config_start_ic()
445 ret = cw221x_write(cw221x, REG_GPIO_CONFIG, reg_val); in cw_config_start_ic()
451 ret = cw221x_read(cw221x, REG_IC_STATE, &reg_val); in cw_config_start_ic()
461 cw221X_sleep(cw221x); in cw_config_start_ic()
468 static int cw221X_init(struct cw221x_info *cw221x) in cw221X_init() argument
472 cw221X_get_chip_id(cw221x); in cw221X_init()
473 if (cw221x->chip_id != IC_VCHIP_ID) { in cw221X_init()
479 ret = cw221X_get_state(cw221x); in cw221X_init()
483 ret = cw_config_start_ic(cw221x); in cw221X_init()
513 static int cw221x_get_current(struct cw221x_info *cw221x) in cw221x_get_current() argument
519 ret = cw221x_read_half_word(cw221x, REG_CURRENT_H, &value16); in cw221x_get_current()
535 struct cw221x_info *cw221x = dev_get_priv(dev); in cw221x_update_get_current() local
537 return cw221x_get_current(cw221x); in cw221x_update_get_current()
542 struct cw221x_info *cw221x = dev_get_priv(dev); in cw221x_get_temperature() local
547 ret = cw221x_read(cw221x, REG_TEMP, &reg_val); in cw221x_get_temperature()
560 struct cw221x_info *cw221x = dev_get_priv(dev); in cw221x_update_get_chrg_online() local
562 return cw221x_check_charge(cw221x); in cw221x_update_get_chrg_online()
567 struct cw221x_info *cw221x = dev_get_priv(dev); in cw221x_update_get_voltage() local
570 cw221x_get_current(cw221x); in cw221x_update_get_voltage()
573 return cw221x_get_vol(cw221x); in cw221x_update_get_voltage()
592 struct cw221x_info *cw221x = dev_get_priv(dev); in cw221x_fg_probe() local
594 cw221x->dev = dev; in cw221x_fg_probe()
596 cw221X_init(cw221x); in cw221x_fg_probe()
598 cw221x_get_vol(cw221x), cw221x_get_soc(cw221x)); in cw221x_fg_probe()