Lines Matching full:cw201x

22 #define COMPAT_ROCKCHIP_CW201X "cw201x"
64 static u8 cw201x_read(struct cw201x_info *cw201x, u8 reg) in cw201x_read() argument
69 ret = dm_i2c_read(cw201x->dev, reg, &val, 1); in cw201x_read()
72 cw201x->dev, reg); in cw201x_read()
79 static int cw201x_write(struct cw201x_info *cw201x, u8 reg, u8 val) in cw201x_write() argument
83 ret = dm_i2c_write(cw201x->dev, reg, &val, 1); in cw201x_write()
86 cw201x->dev, reg); in cw201x_write()
93 static u16 cw201x_read_half_word(struct cw201x_info *cw201x, int reg) in cw201x_read_half_word() argument
98 valh = cw201x_read(cw201x, reg); in cw201x_read_half_word()
99 vall = cw201x_read(cw201x, reg + 1); in cw201x_read_half_word()
105 static int cw201x_parse_config_info(struct cw201x_info *cw201x) in cw201x_parse_config_info() argument
110 struct udevice *dev = cw201x->dev; in cw201x_parse_config_info()
114 size = sizeof(*cw201x->cw_bat_config_info) * len; in cw201x_parse_config_info()
115 cw201x->cw_bat_config_info = calloc(size, 1); in cw201x_parse_config_info()
116 if (!cw201x->cw_bat_config_info) { in cw201x_parse_config_info()
121 cw201x->cw_bat_config_info, len); in cw201x_parse_config_info()
133 size = sizeof(*cw201x->cw_bat_config_info) * len; in cw201x_parse_config_info()
134 cw201x->cw_bat_config_info = calloc(size, 1); in cw201x_parse_config_info()
135 if (!cw201x->cw_bat_config_info) { in cw201x_parse_config_info()
146 cw201x->cw_bat_config_info[i] = info[i]; in cw201x_parse_config_info()
147 debug("%#x ", cw201x->cw_bat_config_info[i]); in cw201x_parse_config_info()
157 struct cw201x_info *cw201x = dev_get_priv(dev); in cw201x_ofdata_to_platdata() local
161 cw201x->dev = dev; in cw201x_ofdata_to_platdata()
162 ret = cw201x_parse_config_info(cw201x); in cw201x_ofdata_to_platdata()
166 cw201x->dual_cell = dev_read_bool(dev, "cellwise,dual-cell"); in cw201x_ofdata_to_platdata()
168 0, &cw201x->dc_det_gpio, GPIOD_IS_IN); in cw201x_ofdata_to_platdata()
170 cw201x->support_dc_adp = 1; in cw201x_ofdata_to_platdata()
176 cw201x->hw_id_check = dev_read_u32_default(dev, "hw_id_check", 0); in cw201x_ofdata_to_platdata()
177 if (cw201x->hw_id_check) { in cw201x_ofdata_to_platdata()
180 &cw201x->hw_id0, GPIOD_IS_IN); in cw201x_ofdata_to_platdata()
183 hw_id0_val = dm_gpio_get_value(&cw201x->hw_id0); in cw201x_ofdata_to_platdata()
187 &cw201x->hw_id1, GPIOD_IS_IN); in cw201x_ofdata_to_platdata()
190 hw_id1_val = dm_gpio_get_value(&cw201x->hw_id1); in cw201x_ofdata_to_platdata()
197 cw201x->divider_res1 = dev_read_u32_default(dev, "divider_res1", 0); in cw201x_ofdata_to_platdata()
198 cw201x->divider_res2 = dev_read_u32_default(dev, "divider_res2", 0); in cw201x_ofdata_to_platdata()
203 static int cw201x_get_vol(struct cw201x_info *cw201x) in cw201x_get_vol() argument
211 value16 = cw201x_read_half_word(cw201x, REG_VCELL); in cw201x_get_vol()
215 value16_1 = cw201x_read_half_word(cw201x, REG_VCELL); in cw201x_get_vol()
219 value16_2 = cw201x_read_half_word(cw201x, REG_VCELL); in cw201x_get_vol()
248 if (cw201x->divider_res1 && in cw201x_get_vol()
249 cw201x->divider_res2) { in cw201x_get_vol()
250 res1 = cw201x->divider_res1; in cw201x_get_vol()
251 res2 = cw201x->divider_res2; in cw201x_get_vol()
255 if (cw201x->dual_cell) in cw201x_get_vol()
258 debug("the cw201x voltage=%d\n", voltage); in cw201x_get_vol()
272 static int cw201x_get_usb_state(struct cw201x_info *cw201x) in cw201x_get_usb_state() argument
295 static bool cw201x_get_dc_state(struct cw201x_info *cw201x) in cw201x_get_dc_state() argument
297 if (dm_gpio_get_value(&cw201x->dc_det_gpio)) in cw201x_get_dc_state()
303 static bool cw201x_check_charge(struct cw201x_info *cw201x) in cw201x_check_charge() argument
305 if (cw201x_get_usb_state(cw201x) != CHARGER_TYPE_NO) in cw201x_check_charge()
307 if (cw201x_get_dc_state(cw201x)) in cw201x_check_charge()
313 static int cw201x_get_soc(struct cw201x_info *cw201x) in cw201x_get_soc() argument
318 cap = cw201x_read(cw201x, REG_SOC); in cw201x_get_soc()
320 cap = cw201x->capacity; in cw201x_get_soc()
325 cw201x->capacity = cap; in cw201x_get_soc()
327 return cw201x->capacity; in cw201x_get_soc()
332 struct cw201x_info *cw201x = dev_get_priv(dev); in cw201x_update_get_soc() local
334 return cw201x_get_soc(cw201x); in cw201x_update_get_soc()
339 struct cw201x_info *cw201x = dev_get_priv(dev); in cw201x_update_get_voltage() local
341 return cw201x_get_vol(cw201x); in cw201x_update_get_voltage()
351 struct cw201x_info *cw201x = dev_get_priv(dev); in cw201x_update_get_chrg_online() local
353 return cw201x_check_charge(cw201x); in cw201x_update_get_chrg_online()
369 static int cw201x_fg_cfg(struct cw201x_info *cw201x) in cw201x_fg_cfg() argument
376 cw201x_write(cw201x, REG_MODE, val); in cw201x_fg_cfg()
380 cw201x_write(cw201x, REG_BATINFO + i, in cw201x_fg_cfg()
381 (u8)cw201x->cw_bat_config_info[i]); in cw201x_fg_cfg()
389 struct cw201x_info *cw201x = dev_get_priv(dev); in cw201x_fg_probe() local
391 cw201x->dev = dev; in cw201x_fg_probe()
392 cw201x_fg_cfg(cw201x); in cw201x_fg_probe()
395 cw201x_get_vol(cw201x), cw201x_get_soc(cw201x)); in cw201x_fg_probe()
401 { .compatible = "cw201x" },