hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/power/supply/max17042_battery.c
....@@ -1,26 +1,12 @@
1
-/*
2
- * Fuel gauge driver for Maxim 17042 / 8966 / 8997
3
- * Note that Maxim 8966 and 8997 are mfd and this is its subdevice.
4
- *
5
- * Copyright (C) 2011 Samsung Electronics
6
- * MyungJoo Ham <myungjoo.ham@samsung.com>
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- * GNU General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU General Public License
19
- * along with this program; if not, write to the Free Software
20
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
- *
22
- * This driver is based on max17040_battery.c
23
- */
1
+// SPDX-License-Identifier: GPL-2.0+
2
+//
3
+// Fuel gauge driver for Maxim 17042 / 8966 / 8997
4
+// Note that Maxim 8966 and 8997 are mfd and this is its subdevice.
5
+//
6
+// Copyright (C) 2011 Samsung Electronics
7
+// MyungJoo Ham <myungjoo.ham@samsung.com>
8
+//
9
+// This driver is based on max17040_battery.c
2410
2511 #include <linux/acpi.h>
2612 #include <linux/init.h>
....@@ -99,6 +85,8 @@
9985 POWER_SUPPLY_PROP_TEMP_MAX,
10086 POWER_SUPPLY_PROP_HEALTH,
10187 POWER_SUPPLY_PROP_SCOPE,
88
+ POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
89
+ // these two have to be at the end on the list
10290 POWER_SUPPLY_PROP_CURRENT_NOW,
10391 POWER_SUPPLY_PROP_CURRENT_AVG,
10492 };
....@@ -296,6 +284,8 @@
296284 case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
297285 if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17042)
298286 ret = regmap_read(map, MAX17042_V_empty, &data);
287
+ else if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17055)
288
+ ret = regmap_read(map, MAX17055_V_empty, &data);
299289 else
300290 ret = regmap_read(map, MAX17047_V_empty, &data);
301291 if (ret < 0)
....@@ -426,6 +416,13 @@
426416 return -EINVAL;
427417 }
428418 break;
419
+ case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW:
420
+ ret = regmap_read(map, MAX17042_TTE, &data);
421
+ if (ret < 0)
422
+ return ret;
423
+
424
+ val->intval = data * 5625 / 1000;
425
+ break;
429426 default:
430427 return -EINVAL;
431428 }
....@@ -528,7 +525,7 @@
528525 regmap_write(map, reg, value);
529526 }
530527
531
-static inline void max10742_unlock_model(struct max17042_chip *chip)
528
+static inline void max17042_unlock_model(struct max17042_chip *chip)
532529 {
533530 struct regmap *map = chip->regmap;
534531
....@@ -536,7 +533,7 @@
536533 regmap_write(map, MAX17042_MLOCKReg2, MODEL_UNLOCK2);
537534 }
538535
539
-static inline void max10742_lock_model(struct max17042_chip *chip)
536
+static inline void max17042_lock_model(struct max17042_chip *chip)
540537 {
541538 struct regmap *map = chip->regmap;
542539
....@@ -594,7 +591,7 @@
594591 if (!temp_data)
595592 return -ENOMEM;
596593
597
- max10742_unlock_model(chip);
594
+ max17042_unlock_model(chip);
598595 max17042_write_model_data(chip, MAX17042_MODELChrTbl,
599596 table_size);
600597 max17042_read_model_data(chip, MAX17042_MODELChrTbl, temp_data,
....@@ -606,7 +603,7 @@
606603 temp_data,
607604 table_size);
608605
609
- max10742_lock_model(chip);
606
+ max17042_lock_model(chip);
610607 kfree(temp_data);
611608
612609 return ret;
....@@ -644,7 +641,8 @@
644641 config->filter_cfg);
645642 regmap_write(map, MAX17042_RelaxCFG, config->relax_cfg);
646643 if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17047 ||
647
- chip->chip_type == MAXIM_DEVICE_TYPE_MAX17050)
644
+ chip->chip_type == MAXIM_DEVICE_TYPE_MAX17050 ||
645
+ chip->chip_type == MAXIM_DEVICE_TYPE_MAX17055)
648646 regmap_write(map, MAX17047_FullSOCThr,
649647 config->full_soc_thresh);
650648 }
....@@ -775,6 +773,8 @@
775773
776774 if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17042)
777775 max17042_override_por(map, MAX17042_V_empty, config->vempty);
776
+ if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17055)
777
+ max17042_override_por(map, MAX17055_V_empty, config->vempty);
778778 else
779779 max17042_override_por(map, MAX17047_V_empty, config->vempty);
780780 max17042_override_por(map, MAX17042_TempNom, config->temp_nom);
....@@ -782,7 +782,10 @@
782782 max17042_override_por(map, MAX17042_FCTC, config->fctc);
783783 max17042_override_por(map, MAX17042_RCOMP0, config->rcomp0);
784784 max17042_override_por(map, MAX17042_TempCo, config->tcompc0);
785
- if (chip->chip_type) {
785
+ if (chip->chip_type &&
786
+ ((chip->chip_type == MAXIM_DEVICE_TYPE_MAX17042) ||
787
+ (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17047) ||
788
+ (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17050))) {
786789 max17042_override_por(map, MAX17042_EmptyTempCo,
787790 config->empty_tempco);
788791 max17042_override_por(map, MAX17042_K_empty0,
....@@ -872,6 +875,10 @@
872875 max17042_set_soc_threshold(chip, 1);
873876 }
874877
878
+ /* we implicitly handle all alerts via power_supply_changed */
879
+ regmap_clear_bits(chip->regmap, MAX17042_STATUS,
880
+ 0xFFFF & ~(STATUS_POR_BIT | STATUS_BST_BIT));
881
+
875882 power_supply_changed(chip->battery);
876883 return IRQ_HANDLED;
877884 }
....@@ -951,7 +958,8 @@
951958 if (!pdata)
952959 return pdata;
953960
954
- if (chip->chip_type != MAXIM_DEVICE_TYPE_MAX17042) {
961
+ if ((chip->chip_type == MAXIM_DEVICE_TYPE_MAX17047) ||
962
+ (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17050)) {
955963 pdata->init_data = max17047_default_pdata_init_regs;
956964 pdata->num_init_data =
957965 ARRAY_SIZE(max17047_default_pdata_init_regs);
....@@ -1017,10 +1025,17 @@
10171025 .num_properties = ARRAY_SIZE(max17042_battery_props) - 2,
10181026 };
10191027
1028
+static void max17042_stop_work(void *data)
1029
+{
1030
+ struct max17042_chip *chip = data;
1031
+
1032
+ cancel_work_sync(&chip->work);
1033
+}
1034
+
10201035 static int max17042_probe(struct i2c_client *client,
10211036 const struct i2c_device_id *id)
10221037 {
1023
- struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
1038
+ struct i2c_adapter *adapter = client->adapter;
10241039 const struct power_supply_desc *max17042_desc = &max17042_psy_desc;
10251040 struct power_supply_config psy_cfg = {};
10261041 const struct acpi_device_id *acpi_id = NULL;
....@@ -1123,6 +1138,9 @@
11231138 regmap_read(chip->regmap, MAX17042_STATUS, &val);
11241139 if (val & STATUS_POR_BIT) {
11251140 INIT_WORK(&chip->work, max17042_init_worker);
1141
+ ret = devm_add_action(&client->dev, max17042_stop_work, chip);
1142
+ if (ret)
1143
+ return ret;
11261144 schedule_work(&chip->work);
11271145 } else {
11281146 chip->init_complete = 1;
....@@ -1179,6 +1197,7 @@
11791197 { .compatible = "maxim,max17042" },
11801198 { .compatible = "maxim,max17047" },
11811199 { .compatible = "maxim,max17050" },
1200
+ { .compatible = "maxim,max17055" },
11821201 { },
11831202 };
11841203 MODULE_DEVICE_TABLE(of, max17042_dt_match);
....@@ -1188,6 +1207,7 @@
11881207 { "max17042", MAXIM_DEVICE_TYPE_MAX17042 },
11891208 { "max17047", MAXIM_DEVICE_TYPE_MAX17047 },
11901209 { "max17050", MAXIM_DEVICE_TYPE_MAX17050 },
1210
+ { "max17055", MAXIM_DEVICE_TYPE_MAX17055 },
11911211 { }
11921212 };
11931213 MODULE_DEVICE_TABLE(i2c, max17042_id);