Lines Matching refs:chip

156 static int max17040_reset(struct max17040_chip *chip)
158 return regmap_write(chip->regmap, MAX17040_CMD, chip->data.reset_val);
161 static int max17040_set_low_soc_alert(struct max17040_chip *chip, u32 level)
163 level = 32 - level * (chip->quirk_double_soc ? 2 : 1);
164 return regmap_update_bits(chip->regmap, MAX17040_CONFIG,
168 static int max17040_set_soc_alert(struct max17040_chip *chip, bool enable)
170 return regmap_update_bits(chip->regmap, MAX17040_CONFIG,
174 static int max17040_set_rcomp(struct max17040_chip *chip, u16 rcomp)
176 u16 mask = chip->data.rcomp_bytes == 2 ?
179 return regmap_update_bits(chip->regmap, MAX17040_CONFIG, mask, rcomp);
182 static int max17040_raw_vcell_to_uvolts(struct max17040_chip *chip, u16 vcell)
184 struct chip_data *d = &chip->data;
190 static int max17040_get_vcell(struct max17040_chip *chip)
194 regmap_read(chip->regmap, MAX17040_VCELL, &vcell);
196 return max17040_raw_vcell_to_uvolts(chip, vcell);
199 static int max17040_get_soc(struct max17040_chip *chip)
203 regmap_read(chip->regmap, MAX17040_SOC, &soc);
205 return soc >> (chip->quirk_double_soc ? 9 : 8);
208 static int max17040_get_version(struct max17040_chip *chip)
213 ret = regmap_read(chip->regmap, MAX17040_VER, &version);
218 static int max17040_get_online(struct max17040_chip *chip)
223 static int max17040_get_of_data(struct max17040_chip *chip)
225 struct device *dev = &chip->client->dev;
231 chip->quirk_double_soc = device_property_read_bool(dev,
234 chip->low_soc_alert = MAX17040_ATHD_DEFAULT_POWER_UP;
237 &chip->low_soc_alert);
239 if (chip->low_soc_alert <= 0 ||
240 chip->low_soc_alert > (chip->quirk_double_soc ? 16 : 32)) {
246 chip->rcomp = MAX17040_RCOMP_DEFAULT;
250 chip->rcomp = rcomp_len == 2 ? rcomp[0] << 8 | rcomp[1] :
260 static void max17040_check_changes(struct max17040_chip *chip)
262 chip->soc = max17040_get_soc(chip);
265 static void max17040_queue_work(struct max17040_chip *chip)
267 queue_delayed_work(system_power_efficient_wq, &chip->work,
273 struct max17040_chip *chip = data;
275 cancel_delayed_work_sync(&chip->work);
280 struct max17040_chip *chip;
283 chip = container_of(work, struct max17040_chip, work.work);
286 last_soc = chip->soc;
287 max17040_check_changes(chip);
290 if (last_soc != chip->soc)
291 power_supply_changed(chip->battery);
293 max17040_queue_work(chip);
297 static bool max17040_handle_soc_alert(struct max17040_chip *chip)
302 regmap_read(chip->regmap, MAX17040_STATUS, &data);
310 regmap_write(chip->regmap, MAX17040_STATUS,
319 struct max17040_chip *chip = dev;
321 if (!(chip->data.has_soc_alert && max17040_handle_soc_alert(chip)))
322 dev_warn(&chip->client->dev, "IRQ: Alert battery low level\n");
325 max17040_check_changes(chip);
328 power_supply_changed(chip->battery);
331 max17040_set_low_soc_alert(chip, chip->low_soc_alert);
336 static int max17040_enable_alert_irq(struct max17040_chip *chip)
338 struct i2c_client *client = chip->client;
343 chip->battery->desc->name, chip);
363 struct max17040_chip *chip = power_supply_get_drvdata(psy);
370 (val->intval > (chip->quirk_double_soc ? 16 : 32))) {
374 ret = max17040_set_low_soc_alert(chip, val->intval);
375 chip->low_soc_alert = val->intval;
388 struct max17040_chip *chip = power_supply_get_drvdata(psy);
392 val->intval = max17040_get_online(chip);
395 val->intval = max17040_get_vcell(chip);
398 val->intval = max17040_get_soc(chip);
401 val->intval = chip->low_soc_alert;
438 struct max17040_chip *chip;
446 chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
447 if (!chip)
450 chip->client = client;
451 chip->regmap = devm_regmap_init_i2c(client, &max17040_regmap);
452 if (IS_ERR(chip->regmap))
453 return PTR_ERR(chip->regmap);
456 ret = max17040_get_of_data(chip);
461 chip->data = max17040_family[chip_id];
463 i2c_set_clientdata(client, chip);
464 psy_cfg.drv_data = chip;
466 chip->battery = devm_power_supply_register(&client->dev,
468 if (IS_ERR(chip->battery)) {
470 return PTR_ERR(chip->battery);
473 ret = max17040_get_version(chip);
476 dev_dbg(&chip->client->dev, "MAX17040 Fuel-Gauge Ver 0x%x\n", ret);
479 max17040_reset(chip);
481 max17040_set_rcomp(chip, chip->rcomp);
484 if (client->irq && chip->data.has_low_soc_alert) {
485 ret = max17040_set_low_soc_alert(chip, chip->low_soc_alert);
495 if (client->irq && chip->data.has_soc_alert) {
496 ret = max17040_set_soc_alert(chip, 1);
505 INIT_DEFERRABLE_WORK(&chip->work, max17040_work);
506 ret = devm_add_action(&client->dev, max17040_stop_work, chip);
509 max17040_queue_work(chip);
513 ret = max17040_enable_alert_irq(chip);
529 struct max17040_chip *chip = i2c_get_clientdata(client);
531 if (client->irq && chip->data.has_soc_alert)
533 max17040_set_soc_alert(chip, 0);
535 cancel_delayed_work(&chip->work);
546 struct max17040_chip *chip = i2c_get_clientdata(client);
551 if (client->irq && chip->data.has_soc_alert)
552 max17040_set_soc_alert(chip, 1);
554 max17040_queue_work(chip);