Lines Matching +full:alert +full:- +full:celsius
1 // SPDX-License-Identifier: GPL-2.0+
97 struct regmap *map = chip->regmap; in max17042_get_temperature()
104 /* The value is converted into deci-centigrade scale */ in max17042_get_temperature()
105 /* Units of LSB = 1 / 256 degree Celsius */ in max17042_get_temperature()
116 ret = power_supply_am_i_supplied(chip->battery); in max17042_get_status()
127 * The MAX170xx has builtin end-of-charge detection and will update in max17042_get_status()
132 * contineously once end-of-charge detection kicks in, so allow the in max17042_get_status()
136 ret = regmap_read(chip->regmap, MAX17042_FullCAP, &charge_full); in max17042_get_status()
140 ret = regmap_read(chip->regmap, MAX17042_RepCap, &charge_now); in max17042_get_status()
144 if ((charge_full - charge_now) <= MAX17042_FULL_THRESHOLD) { in max17042_get_status()
153 if (!chip->pdata->enable_current_sense) { in max17042_get_status()
158 ret = regmap_read(chip->regmap, MAX17042_AvgCurrent, &data); in max17042_get_status()
163 avg_current *= 1562500 / chip->pdata->r_sns; in max17042_get_status()
178 ret = regmap_read(chip->regmap, MAX17042_AvgVCELL, &val); in max17042_get_battery_health()
182 /* bits [0-3] unused */ in max17042_get_battery_health()
187 ret = regmap_read(chip->regmap, MAX17042_VCELL, &val); in max17042_get_battery_health()
191 /* bits [0-3] unused */ in max17042_get_battery_health()
196 if (vavg < chip->pdata->vmin) { in max17042_get_battery_health()
201 if (vbatt > chip->pdata->vmax + MAX17042_VMAX_TOLERANCE) { in max17042_get_battery_health()
210 if (temp < chip->pdata->temp_min) { in max17042_get_battery_health()
215 if (temp > chip->pdata->temp_max) { in max17042_get_battery_health()
234 struct regmap *map = chip->regmap; in max17042_get_property()
239 if (!chip->init_complete) in max17042_get_property()
240 return -EAGAIN; in max17042_get_property()
244 ret = max17042_get_status(chip, &val->intval); in max17042_get_property()
254 val->intval = 0; in max17042_get_property()
256 val->intval = 1; in max17042_get_property()
259 val->intval = POWER_SUPPLY_TECHNOLOGY_LION; in max17042_get_property()
266 val->intval = data; in max17042_get_property()
273 val->intval = data >> 8; in max17042_get_property()
274 val->intval *= 20000; /* Units of LSB = 20mV */ in max17042_get_property()
281 val->intval = (data & 0xff) * 20000; /* Units of 20mV */ in max17042_get_property()
284 if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17042) in max17042_get_property()
286 else if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17055) in max17042_get_property()
293 val->intval = data >> 7; in max17042_get_property()
294 val->intval *= 10000; /* Units of LSB = 10mV */ in max17042_get_property()
301 val->intval = data * 625 / 8; in max17042_get_property()
308 val->intval = data * 625 / 8; in max17042_get_property()
315 val->intval = data * 625 / 8; in max17042_get_property()
322 val->intval = data >> 8; in max17042_get_property()
330 do_div(data64, chip->pdata->r_sns); in max17042_get_property()
331 val->intval = data64; in max17042_get_property()
339 do_div(data64, chip->pdata->r_sns); in max17042_get_property()
340 val->intval = data64; in max17042_get_property()
348 do_div(data64, chip->pdata->r_sns); in max17042_get_property()
349 val->intval = data64; in max17042_get_property()
356 val->intval = data * 1000 / 2; in max17042_get_property()
359 ret = max17042_get_temperature(chip, &val->intval); in max17042_get_property()
367 /* LSB is Alert Minimum. In deci-centigrade */ in max17042_get_property()
368 val->intval = sign_extend32(data & 0xff, 7) * 10; in max17042_get_property()
374 /* MSB is Alert Maximum. In deci-centigrade */ in max17042_get_property()
375 val->intval = sign_extend32(data >> 8, 7) * 10; in max17042_get_property()
378 val->intval = chip->pdata->temp_min; in max17042_get_property()
381 val->intval = chip->pdata->temp_max; in max17042_get_property()
384 ret = max17042_get_battery_health(chip, &val->intval); in max17042_get_property()
389 val->intval = POWER_SUPPLY_SCOPE_SYSTEM; in max17042_get_property()
392 if (chip->pdata->enable_current_sense) { in max17042_get_property()
397 val->intval = sign_extend32(data, 15); in max17042_get_property()
398 val->intval *= 1562500 / chip->pdata->r_sns; in max17042_get_property()
400 return -EINVAL; in max17042_get_property()
404 if (chip->pdata->enable_current_sense) { in max17042_get_property()
409 val->intval = sign_extend32(data, 15); in max17042_get_property()
410 val->intval *= 1562500 / chip->pdata->r_sns; in max17042_get_property()
412 return -EINVAL; in max17042_get_property()
420 val->intval = data * 5625 / 1000; in max17042_get_property()
423 return -EINVAL; in max17042_get_property()
433 struct regmap *map = chip->regmap; in max17042_set_property()
444 /* Input in deci-centigrade, convert to centigrade */ in max17042_set_property()
445 temp = val->intval / 10; in max17042_set_property()
448 temp = (int8_t)(data >> 8) - 1; in max17042_set_property()
449 /* Write both MAX and MIN ALERT */ in max17042_set_property()
458 /* Input in Deci-Centigrade, convert to centigrade */ in max17042_set_property()
459 temp = val->intval / 10; in max17042_set_property()
463 /* Write both MAX and MIN ALERT */ in max17042_set_property()
468 ret = -EINVAL; in max17042_set_property()
506 ret = -EIO; in max17042_write_verify_reg()
507 retries--; in max17042_write_verify_reg()
526 struct regmap *map = chip->regmap; in max17042_unlock_model()
534 struct regmap *map = chip->regmap; in max17042_lock_model()
543 struct regmap *map = chip->regmap; in max17042_write_model_data()
548 chip->pdata->config_data->cell_char_tbl[i]); in max17042_write_model_data()
554 struct regmap *map = chip->regmap; in max17042_read_model_data()
570 dev_err(&chip->client->dev, "%s compare failed\n", __func__); in max17042_model_data_compare()
572 dev_info(&chip->client->dev, "0x%x, 0x%x", in max17042_model_data_compare()
574 dev_info(&chip->client->dev, "\n"); in max17042_model_data_compare()
575 return -EINVAL; in max17042_model_data_compare()
583 int table_size = ARRAY_SIZE(chip->pdata->config_data->cell_char_tbl); in max17042_init_model()
588 return -ENOMEM; in max17042_init_model()
598 chip->pdata->config_data->cell_char_tbl, in max17042_init_model()
611 int table_size = ARRAY_SIZE(chip->pdata->config_data->cell_char_tbl); in max17042_verify_model_lock()
617 return -ENOMEM; in max17042_verify_model_lock()
623 ret = -EINVAL; in max17042_verify_model_lock()
631 struct max17042_config_data *config = chip->pdata->config_data; in max17042_write_config_regs()
632 struct regmap *map = chip->regmap; in max17042_write_config_regs()
634 regmap_write(map, MAX17042_CONFIG, config->config); in max17042_write_config_regs()
635 regmap_write(map, MAX17042_LearnCFG, config->learn_cfg); in max17042_write_config_regs()
637 config->filter_cfg); in max17042_write_config_regs()
638 regmap_write(map, MAX17042_RelaxCFG, config->relax_cfg); in max17042_write_config_regs()
639 if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17047 || in max17042_write_config_regs()
640 chip->chip_type == MAXIM_DEVICE_TYPE_MAX17050 || in max17042_write_config_regs()
641 chip->chip_type == MAXIM_DEVICE_TYPE_MAX17055) in max17042_write_config_regs()
643 config->full_soc_thresh); in max17042_write_config_regs()
648 struct max17042_config_data *config = chip->pdata->config_data; in max17042_write_custom_regs()
649 struct regmap *map = chip->regmap; in max17042_write_custom_regs()
651 max17042_write_verify_reg(map, MAX17042_RCOMP0, config->rcomp0); in max17042_write_custom_regs()
652 max17042_write_verify_reg(map, MAX17042_TempCo, config->tcompc0); in max17042_write_custom_regs()
653 max17042_write_verify_reg(map, MAX17042_ICHGTerm, config->ichgt_term); in max17042_write_custom_regs()
654 if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17042) { in max17042_write_custom_regs()
655 regmap_write(map, MAX17042_EmptyTempCo, config->empty_tempco); in max17042_write_custom_regs()
657 config->kempty0); in max17042_write_custom_regs()
660 config->qrtbl00); in max17042_write_custom_regs()
662 config->qrtbl10); in max17042_write_custom_regs()
664 config->qrtbl20); in max17042_write_custom_regs()
666 config->qrtbl30); in max17042_write_custom_regs()
672 struct max17042_config_data *config = chip->pdata->config_data; in max17042_update_capacity_regs()
673 struct regmap *map = chip->regmap; in max17042_update_capacity_regs()
676 config->fullcap); in max17042_update_capacity_regs()
677 regmap_write(map, MAX17042_DesignCap, config->design_cap); in max17042_update_capacity_regs()
679 config->fullcapnom); in max17042_update_capacity_regs()
685 struct regmap *map = chip->regmap; in max17042_reset_vfsoc0_reg()
698 struct max17042_config_data *config = chip->pdata->config_data; in max17042_load_new_capacity_params()
699 struct regmap *map = chip->regmap; in max17042_load_new_capacity_params()
715 dq_acc = config->fullcap / dQ_ACC_DIV; in max17042_load_new_capacity_params()
720 config->fullcap); in max17042_load_new_capacity_params()
722 config->design_cap); in max17042_load_new_capacity_params()
724 config->fullcapnom); in max17042_load_new_capacity_params()
736 struct regmap *map = chip->regmap; in max17042_override_por_values()
737 struct max17042_config_data *config = chip->pdata->config_data; in max17042_override_por_values()
739 max17042_override_por(map, MAX17042_TGAIN, config->tgain); in max17042_override_por_values()
740 max17042_override_por(map, MAx17042_TOFF, config->toff); in max17042_override_por_values()
741 max17042_override_por(map, MAX17042_CGAIN, config->cgain); in max17042_override_por_values()
742 max17042_override_por(map, MAX17042_COFF, config->coff); in max17042_override_por_values()
744 max17042_override_por(map, MAX17042_VALRT_Th, config->valrt_thresh); in max17042_override_por_values()
745 max17042_override_por(map, MAX17042_TALRT_Th, config->talrt_thresh); in max17042_override_por_values()
747 config->soc_alrt_thresh); in max17042_override_por_values()
748 max17042_override_por(map, MAX17042_CONFIG, config->config); in max17042_override_por_values()
749 max17042_override_por(map, MAX17042_SHDNTIMER, config->shdntimer); in max17042_override_por_values()
751 max17042_override_por(map, MAX17042_DesignCap, config->design_cap); in max17042_override_por_values()
752 max17042_override_por(map, MAX17042_ICHGTerm, config->ichgt_term); in max17042_override_por_values()
754 max17042_override_por(map, MAX17042_AtRate, config->at_rate); in max17042_override_por_values()
755 max17042_override_por(map, MAX17042_LearnCFG, config->learn_cfg); in max17042_override_por_values()
756 max17042_override_por(map, MAX17042_FilterCFG, config->filter_cfg); in max17042_override_por_values()
757 max17042_override_por(map, MAX17042_RelaxCFG, config->relax_cfg); in max17042_override_por_values()
758 max17042_override_por(map, MAX17042_MiscCFG, config->misc_cfg); in max17042_override_por_values()
759 max17042_override_por(map, MAX17042_MaskSOC, config->masksoc); in max17042_override_por_values()
761 max17042_override_por(map, MAX17042_FullCAP, config->fullcap); in max17042_override_por_values()
762 max17042_override_por(map, MAX17042_FullCAPNom, config->fullcapnom); in max17042_override_por_values()
763 if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17042) in max17042_override_por_values()
765 config->socempty); in max17042_override_por_values()
766 max17042_override_por(map, MAX17042_LAvg_empty, config->lavg_empty); in max17042_override_por_values()
767 max17042_override_por(map, MAX17042_dQacc, config->dqacc); in max17042_override_por_values()
768 max17042_override_por(map, MAX17042_dPacc, config->dpacc); in max17042_override_por_values()
770 if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17042) in max17042_override_por_values()
771 max17042_override_por(map, MAX17042_V_empty, config->vempty); in max17042_override_por_values()
772 if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17055) in max17042_override_por_values()
773 max17042_override_por(map, MAX17055_V_empty, config->vempty); in max17042_override_por_values()
775 max17042_override_por(map, MAX17047_V_empty, config->vempty); in max17042_override_por_values()
776 max17042_override_por(map, MAX17042_TempNom, config->temp_nom); in max17042_override_por_values()
777 max17042_override_por(map, MAX17042_TempLim, config->temp_lim); in max17042_override_por_values()
778 max17042_override_por(map, MAX17042_FCTC, config->fctc); in max17042_override_por_values()
779 max17042_override_por(map, MAX17042_RCOMP0, config->rcomp0); in max17042_override_por_values()
780 max17042_override_por(map, MAX17042_TempCo, config->tcompc0); in max17042_override_por_values()
781 if (chip->chip_type && in max17042_override_por_values()
782 ((chip->chip_type == MAXIM_DEVICE_TYPE_MAX17042) || in max17042_override_por_values()
783 (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17047) || in max17042_override_por_values()
784 (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17050))) { in max17042_override_por_values()
786 config->empty_tempco); in max17042_override_por_values()
788 config->kempty0); in max17042_override_por_values()
794 struct regmap *map = chip->regmap; in max17042_init_chip()
809 dev_err(&chip->client->dev, "%s init failed\n", in max17042_init_chip()
811 return -EIO; in max17042_init_chip()
816 dev_err(&chip->client->dev, "%s lock verify failed\n", in max17042_init_chip()
818 return -EIO; in max17042_init_chip()
844 struct regmap *map = chip->regmap; in max17042_set_soc_threshold()
853 soc_tr |= (soc - off); in max17042_set_soc_threshold()
862 regmap_read(chip->regmap, MAX17042_STATUS, &val); in max17042_thread_handler()
865 dev_info(&chip->client->dev, "SOC threshold INTR\n"); in max17042_thread_handler()
869 power_supply_changed(chip->battery); in max17042_thread_handler()
880 if (chip->pdata->enable_por_init && chip->pdata->config_data) { in max17042_init_worker()
886 chip->init_complete = 1; in max17042_init_worker()
893 struct device *dev = &chip->client->dev; in max17042_get_of_pdata()
894 struct device_node *np = dev->of_node; in max17042_get_of_pdata()
904 * current-sense functionality to be enabled at all. in max17042_get_of_pdata()
906 if (of_property_read_u32(np, "maxim,rsns-microohm", &prop) == 0) { in max17042_get_of_pdata()
907 pdata->r_sns = prop; in max17042_get_of_pdata()
908 pdata->enable_current_sense = true; in max17042_get_of_pdata()
911 if (of_property_read_s32(np, "maxim,cold-temp", &pdata->temp_min)) in max17042_get_of_pdata()
912 pdata->temp_min = INT_MIN; in max17042_get_of_pdata()
913 if (of_property_read_s32(np, "maxim,over-heat-temp", &pdata->temp_max)) in max17042_get_of_pdata()
914 pdata->temp_max = INT_MAX; in max17042_get_of_pdata()
915 if (of_property_read_s32(np, "maxim,dead-volt", &pdata->vmin)) in max17042_get_of_pdata()
916 pdata->vmin = INT_MIN; in max17042_get_of_pdata()
917 if (of_property_read_s32(np, "maxim,over-volt", &pdata->vmax)) in max17042_get_of_pdata()
918 pdata->vmax = INT_MAX; in max17042_get_of_pdata()
926 * Some firmwares do not set FullSOCThr, Enable End-of-Charge Detection
935 struct device *dev = &chip->client->dev; in max17042_get_default_pdata()
941 * the firmware will already have initialized the fuel-gauge and provide in max17042_get_default_pdata()
948 if ((chip->chip_type == MAXIM_DEVICE_TYPE_MAX17047) || in max17042_get_default_pdata()
949 (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17050)) { in max17042_get_default_pdata()
950 pdata->init_data = max17047_default_pdata_init_regs; in max17042_get_default_pdata()
951 pdata->num_init_data = in max17042_get_default_pdata()
955 ret = regmap_read(chip->regmap, MAX17042_MiscCFG, &misc_cfg); in max17042_get_default_pdata()
959 /* If bits 0-1 are set to 3 then only Voltage readings are used */ in max17042_get_default_pdata()
961 pdata->enable_current_sense = false; in max17042_get_default_pdata()
963 pdata->enable_current_sense = true; in max17042_get_default_pdata()
965 pdata->vmin = MAX17042_DEFAULT_VMIN; in max17042_get_default_pdata()
966 pdata->vmax = MAX17042_DEFAULT_VMAX; in max17042_get_default_pdata()
967 pdata->temp_min = MAX17042_DEFAULT_TEMP_MIN; in max17042_get_default_pdata()
968 pdata->temp_max = MAX17042_DEFAULT_TEMP_MAX; in max17042_get_default_pdata()
976 struct device *dev = &chip->client->dev; in max17042_get_pdata()
979 if (dev->of_node) in max17042_get_pdata()
982 if (dev->platform_data) in max17042_get_pdata()
983 return dev->platform_data; in max17042_get_pdata()
1012 .num_properties = ARRAY_SIZE(max17042_battery_props) - 2,
1019 cancel_work_sync(&chip->work); in max17042_stop_work()
1025 struct i2c_adapter *adapter = client->adapter; in max17042_probe()
1029 struct device *dev = &client->dev; in max17042_probe()
1036 return -EIO; in max17042_probe()
1038 chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); in max17042_probe()
1040 return -ENOMEM; in max17042_probe()
1042 chip->client = client; in max17042_probe()
1044 chip->chip_type = id->driver_data; in max17042_probe()
1046 acpi_id = acpi_match_device(dev->driver->acpi_match_table, dev); in max17042_probe()
1048 return -ENODEV; in max17042_probe()
1050 chip->chip_type = acpi_id->driver_data; in max17042_probe()
1052 chip->regmap = devm_regmap_init_i2c(client, &max17042_regmap_config); in max17042_probe()
1053 if (IS_ERR(chip->regmap)) { in max17042_probe()
1054 dev_err(&client->dev, "Failed to initialize regmap\n"); in max17042_probe()
1055 return -EINVAL; in max17042_probe()
1058 chip->pdata = max17042_get_pdata(chip); in max17042_probe()
1059 if (!chip->pdata) { in max17042_probe()
1060 dev_err(&client->dev, "no platform data provided\n"); in max17042_probe()
1061 return -EINVAL; in max17042_probe()
1066 psy_cfg.of_node = dev->of_node; in max17042_probe()
1070 if (!chip->pdata->enable_current_sense) in max17042_probe()
1073 if (chip->pdata->r_sns == 0) in max17042_probe()
1074 chip->pdata->r_sns = MAX17042_DEFAULT_SNS_RESISTOR; in max17042_probe()
1076 if (chip->pdata->init_data) in max17042_probe()
1077 for (i = 0; i < chip->pdata->num_init_data; i++) in max17042_probe()
1078 regmap_write(chip->regmap, in max17042_probe()
1079 chip->pdata->init_data[i].addr, in max17042_probe()
1080 chip->pdata->init_data[i].data); in max17042_probe()
1082 if (!chip->pdata->enable_current_sense) { in max17042_probe()
1083 regmap_write(chip->regmap, MAX17042_CGAIN, 0x0000); in max17042_probe()
1084 regmap_write(chip->regmap, MAX17042_MiscCFG, 0x0003); in max17042_probe()
1085 regmap_write(chip->regmap, MAX17042_LearnCFG, 0x0007); in max17042_probe()
1088 chip->battery = devm_power_supply_register(&client->dev, max17042_desc, in max17042_probe()
1090 if (IS_ERR(chip->battery)) { in max17042_probe()
1091 dev_err(&client->dev, "failed: power supply register\n"); in max17042_probe()
1092 return PTR_ERR(chip->battery); in max17042_probe()
1095 if (client->irq) { in max17042_probe()
1099 * On ACPI systems the IRQ may be handled by ACPI-event code, in max17042_probe()
1105 ret = devm_request_threaded_irq(&client->dev, client->irq, in max17042_probe()
1108 chip->battery->desc->name, in max17042_probe()
1111 regmap_update_bits(chip->regmap, MAX17042_CONFIG, in max17042_probe()
1116 client->irq = 0; in max17042_probe()
1117 if (ret != -EBUSY) in max17042_probe()
1118 dev_err(&client->dev, "Failed to get IRQ\n"); in max17042_probe()
1121 /* Not able to update the charge threshold when exceeded? -> disable */ in max17042_probe()
1122 if (!client->irq) in max17042_probe()
1123 regmap_write(chip->regmap, MAX17042_SALRT_Th, 0xff00); in max17042_probe()
1125 regmap_read(chip->regmap, MAX17042_STATUS, &val); in max17042_probe()
1127 INIT_WORK(&chip->work, max17042_init_worker); in max17042_probe()
1128 ret = devm_add_action(&client->dev, max17042_stop_work, chip); in max17042_probe()
1131 schedule_work(&chip->work); in max17042_probe()
1133 chip->init_complete = 1; in max17042_probe()
1148 if (chip->client->irq) { in max17042_suspend()
1149 disable_irq(chip->client->irq); in max17042_suspend()
1150 enable_irq_wake(chip->client->irq); in max17042_suspend()
1160 if (chip->client->irq) { in max17042_resume()
1161 disable_irq_wake(chip->client->irq); in max17042_resume()
1162 enable_irq(chip->client->irq); in max17042_resume()
1163 /* re-program the SOC thresholds to 1% change */ in max17042_resume()