^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * 1-Wire implementation for Maxim Semiconductor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * MAX7211/MAX17215 stanalone fuel gauge chip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2017 Radioavionica Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Author: Alex A. Mihaylov <minimumlaw@rambler.ru>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Use consistent with the GNU GPL is permitted,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * provided that this copyright notice is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * preserved in its entirety in all copies and derived works.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/w1.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/power_supply.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define W1_MAX1721X_FAMILY_ID 0x26
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define DEF_DEV_NAME_MAX17211 "MAX17211"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define DEF_DEV_NAME_MAX17215 "MAX17215"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define DEF_DEV_NAME_UNKNOWN "UNKNOWN"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define DEF_MFG_NAME "MAXIM"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define PSY_MAX_NAME_LEN 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) /* Number of valid register addresses in W1 mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define MAX1721X_MAX_REG_NR 0x1EF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) /* Factory settings (nonvilatile registers) (W1 specific) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define MAX1721X_REG_NRSENSE 0x1CF /* RSense in 10^-5 Ohm */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /* Strings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define MAX1721X_REG_MFG_STR 0x1CC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define MAX1721X_REG_MFG_NUMB 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define MAX1721X_REG_DEV_STR 0x1DB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define MAX1721X_REG_DEV_NUMB 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) /* HEX Strings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define MAX1721X_REG_SER_HEX 0x1D8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /* MAX172XX Output Registers for W1 chips */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define MAX172XX_REG_STATUS 0x000 /* status reg */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define MAX172XX_BAT_PRESENT (1<<4) /* battery connected bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define MAX172XX_REG_DEVNAME 0x021 /* chip config */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define MAX172XX_DEV_MASK 0x000F /* chip type mask */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define MAX172X1_DEV 0x0001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define MAX172X5_DEV 0x0005
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define MAX172XX_REG_TEMP 0x008 /* Temperature */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define MAX172XX_REG_BATT 0x0DA /* Battery voltage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define MAX172XX_REG_CURRENT 0x00A /* Actual current */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define MAX172XX_REG_AVGCURRENT 0x00B /* Average current */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define MAX172XX_REG_REPSOC 0x006 /* Percentage of charge */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define MAX172XX_REG_DESIGNCAP 0x018 /* Design capacity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define MAX172XX_REG_REPCAP 0x005 /* Average capacity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define MAX172XX_REG_TTE 0x011 /* Time to empty */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define MAX172XX_REG_TTF 0x020 /* Time to full */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct max17211_device_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) char name[PSY_MAX_NAME_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct power_supply *bat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct power_supply_desc bat_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct device *w1_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct regmap *regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /* battery design format */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) unsigned int rsense; /* in tenths uOhm */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) char DeviceName[2 * MAX1721X_REG_DEV_NUMB + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) char ManufacturerName[2 * MAX1721X_REG_MFG_NUMB + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) char SerialNumber[13]; /* see get_sn_str() later for comment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) /* Convert regs value to power_supply units */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static inline int max172xx_time_to_ps(unsigned int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return reg * 5625 / 1000; /* in sec. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) static inline int max172xx_percent_to_ps(unsigned int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return reg / 256; /* in percent from 0 to 100 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) static inline int max172xx_voltage_to_ps(unsigned int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return reg * 1250; /* in uV */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static inline int max172xx_capacity_to_ps(unsigned int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return reg * 500; /* in uAh */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * Current and temperature is signed values, so unsigned regs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * value must be converted to signed type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) static inline int max172xx_temperature_to_ps(unsigned int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) int val = (int16_t)(reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) return val * 10 / 256; /* in tenths of deg. C */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * Calculating current registers resolution:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * RSense stored in 10^-5 Ohm, so mesaurment voltage must be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * in 10^-11 Volts for get current in uA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * 16 bit current reg fullscale +/-51.2mV is 102400 uV.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * So: 102400 / 65535 * 10^5 = 156252
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static inline int max172xx_current_to_voltage(unsigned int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) int val = (int16_t)(reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) return val * 156252;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static inline struct max17211_device_info *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) to_device_info(struct power_supply *psy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return power_supply_get_drvdata(psy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static int max1721x_battery_get_property(struct power_supply *psy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) enum power_supply_property psp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) union power_supply_propval *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct max17211_device_info *info = to_device_info(psy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) unsigned int reg = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) switch (psp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) case POWER_SUPPLY_PROP_PRESENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * POWER_SUPPLY_PROP_PRESENT will always readable via
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * sysfs interface. Value return 0 if battery not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * present or unaccesable via W1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) val->intval =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) regmap_read(info->regmap, MAX172XX_REG_STATUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) ®) ? 0 : !(reg & MAX172XX_BAT_PRESENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) case POWER_SUPPLY_PROP_CAPACITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) ret = regmap_read(info->regmap, MAX172XX_REG_REPSOC, ®);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) val->intval = max172xx_percent_to_ps(reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) case POWER_SUPPLY_PROP_VOLTAGE_NOW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) ret = regmap_read(info->regmap, MAX172XX_REG_BATT, ®);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) val->intval = max172xx_voltage_to_ps(reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) ret = regmap_read(info->regmap, MAX172XX_REG_DESIGNCAP, ®);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) val->intval = max172xx_capacity_to_ps(reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) case POWER_SUPPLY_PROP_CHARGE_AVG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) ret = regmap_read(info->regmap, MAX172XX_REG_REPCAP, ®);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) val->intval = max172xx_capacity_to_ps(reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) ret = regmap_read(info->regmap, MAX172XX_REG_TTE, ®);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) val->intval = max172xx_time_to_ps(reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) case POWER_SUPPLY_PROP_TIME_TO_FULL_AVG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) ret = regmap_read(info->regmap, MAX172XX_REG_TTF, ®);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) val->intval = max172xx_time_to_ps(reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) case POWER_SUPPLY_PROP_TEMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) ret = regmap_read(info->regmap, MAX172XX_REG_TEMP, ®);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) val->intval = max172xx_temperature_to_ps(reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) /* We need signed current, so must cast info->rsense to signed type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) case POWER_SUPPLY_PROP_CURRENT_NOW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) ret = regmap_read(info->regmap, MAX172XX_REG_CURRENT, ®);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) val->intval =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) max172xx_current_to_voltage(reg) / (int)info->rsense;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) case POWER_SUPPLY_PROP_CURRENT_AVG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) ret = regmap_read(info->regmap, MAX172XX_REG_AVGCURRENT, ®);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) val->intval =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) max172xx_current_to_voltage(reg) / (int)info->rsense;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * Strings already received and inited by probe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) * We do dummy read for check battery still available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) case POWER_SUPPLY_PROP_MODEL_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) ret = regmap_read(info->regmap, MAX1721X_REG_DEV_STR, ®);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) val->strval = info->DeviceName;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) case POWER_SUPPLY_PROP_MANUFACTURER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) ret = regmap_read(info->regmap, MAX1721X_REG_MFG_STR, ®);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) val->strval = info->ManufacturerName;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) case POWER_SUPPLY_PROP_SERIAL_NUMBER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) ret = regmap_read(info->regmap, MAX1721X_REG_SER_HEX, ®);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) val->strval = info->SerialNumber;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static enum power_supply_property max1721x_battery_props[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /* int */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) POWER_SUPPLY_PROP_PRESENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) POWER_SUPPLY_PROP_CAPACITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) POWER_SUPPLY_PROP_VOLTAGE_NOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) POWER_SUPPLY_PROP_CHARGE_AVG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) POWER_SUPPLY_PROP_TIME_TO_FULL_AVG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) POWER_SUPPLY_PROP_TEMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) POWER_SUPPLY_PROP_CURRENT_NOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) POWER_SUPPLY_PROP_CURRENT_AVG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) /* strings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) POWER_SUPPLY_PROP_MODEL_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) POWER_SUPPLY_PROP_MANUFACTURER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) POWER_SUPPLY_PROP_SERIAL_NUMBER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static int get_string(struct max17211_device_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) uint16_t reg, uint8_t nr, char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (!str || !(reg == MAX1721X_REG_MFG_STR ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) reg == MAX1721X_REG_DEV_STR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) while (nr--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (regmap_read(info->regmap, reg++, &val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) *str++ = val>>8 & 0x00FF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) *str++ = val & 0x00FF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) /* Maxim say: Serial number is a hex string up to 12 hex characters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) static int get_sn_string(struct max17211_device_info *info, char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) unsigned int val[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (!str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) if (regmap_read(info->regmap, MAX1721X_REG_SER_HEX, &val[0]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (regmap_read(info->regmap, MAX1721X_REG_SER_HEX + 1, &val[1]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) if (regmap_read(info->regmap, MAX1721X_REG_SER_HEX + 2, &val[2]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) snprintf(str, 13, "%04X%04X%04X", val[0], val[1], val[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) * MAX1721x registers description for w1-regmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static const struct regmap_range max1721x_allow_range[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) regmap_reg_range(0, 0xDF), /* volatile data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) regmap_reg_range(0x180, 0x1DF), /* non-volatile memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) regmap_reg_range(0x1E0, 0x1EF), /* non-volatile history (unused) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static const struct regmap_range max1721x_deny_range[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) /* volatile data unused registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) regmap_reg_range(0x24, 0x26),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) regmap_reg_range(0x30, 0x31),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) regmap_reg_range(0x33, 0x34),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) regmap_reg_range(0x37, 0x37),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) regmap_reg_range(0x3B, 0x3C),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) regmap_reg_range(0x40, 0x41),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) regmap_reg_range(0x43, 0x44),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) regmap_reg_range(0x47, 0x49),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) regmap_reg_range(0x4B, 0x4C),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) regmap_reg_range(0x4E, 0xAF),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) regmap_reg_range(0xB1, 0xB3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) regmap_reg_range(0xB5, 0xB7),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) regmap_reg_range(0xBF, 0xD0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) regmap_reg_range(0xDB, 0xDB),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) /* hole between volatile and non-volatile registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) regmap_reg_range(0xE0, 0x17F),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static const struct regmap_access_table max1721x_regs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) .yes_ranges = max1721x_allow_range,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) .n_yes_ranges = ARRAY_SIZE(max1721x_allow_range),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) .no_ranges = max1721x_deny_range,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) .n_no_ranges = ARRAY_SIZE(max1721x_deny_range),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) * Model Gauge M5 Algorithm output register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) * Volatile data (must not be cached)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) static const struct regmap_range max1721x_volatile_allow[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) regmap_reg_range(0, 0xDF),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) static const struct regmap_access_table max1721x_volatile_regs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) .yes_ranges = max1721x_volatile_allow,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) .n_yes_ranges = ARRAY_SIZE(max1721x_volatile_allow),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) * W1-regmap config
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) static const struct regmap_config max1721x_regmap_w1_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) .reg_bits = 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) .val_bits = 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) .rd_table = &max1721x_regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) .volatile_table = &max1721x_volatile_regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) .max_register = MAX1721X_MAX_REG_NR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) static int devm_w1_max1721x_add_device(struct w1_slave *sl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) struct power_supply_config psy_cfg = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) struct max17211_device_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) info = devm_kzalloc(&sl->dev, sizeof(*info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) sl->family_data = (void *)info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) info->w1_dev = &sl->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) * power_supply class battery name translated from W1 slave device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) * unical ID (look like 26-0123456789AB) to "max1721x-0123456789AB\0"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) * so, 26 (device family) correcpondent to max1721x devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) * Device name still unical for any numbers connected devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) snprintf(info->name, sizeof(info->name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) "max1721x-%012X", (unsigned int)sl->reg_num.id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) info->bat_desc.name = info->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) * FixMe: battery device name exceed max len for thermal_zone device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) * name and translation to thermal_zone must be disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) info->bat_desc.no_thermal = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) info->bat_desc.type = POWER_SUPPLY_TYPE_BATTERY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) info->bat_desc.properties = max1721x_battery_props;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) info->bat_desc.num_properties = ARRAY_SIZE(max1721x_battery_props);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) info->bat_desc.get_property = max1721x_battery_get_property;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) psy_cfg.drv_data = info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) /* regmap init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) info->regmap = devm_regmap_init_w1(info->w1_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) &max1721x_regmap_w1_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) if (IS_ERR(info->regmap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) int err = PTR_ERR(info->regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) dev_err(info->w1_dev, "Failed to allocate register map: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) /* rsense init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) info->rsense = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) if (regmap_read(info->regmap, MAX1721X_REG_NRSENSE, &info->rsense)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) dev_err(info->w1_dev, "Can't read RSense. Hardware error.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) if (!info->rsense) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) dev_warn(info->w1_dev, "RSense not calibrated, set 10 mOhms!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) info->rsense = 1000; /* in regs in 10^-5 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) dev_info(info->w1_dev, "RSense: %d mOhms.\n", info->rsense / 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) if (get_string(info, MAX1721X_REG_MFG_STR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) MAX1721X_REG_MFG_NUMB, info->ManufacturerName)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) dev_err(info->w1_dev, "Can't read manufacturer. Hardware error.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) if (!info->ManufacturerName[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) strncpy(info->ManufacturerName, DEF_MFG_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 2 * MAX1721X_REG_MFG_NUMB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) if (get_string(info, MAX1721X_REG_DEV_STR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) MAX1721X_REG_DEV_NUMB, info->DeviceName)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) dev_err(info->w1_dev, "Can't read device. Hardware error.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) if (!info->DeviceName[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) unsigned int dev_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) if (regmap_read(info->regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) MAX172XX_REG_DEVNAME, &dev_name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) dev_err(info->w1_dev, "Can't read device name reg.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) switch (dev_name & MAX172XX_DEV_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) case MAX172X1_DEV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) strncpy(info->DeviceName, DEF_DEV_NAME_MAX17211,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 2 * MAX1721X_REG_DEV_NUMB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) case MAX172X5_DEV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) strncpy(info->DeviceName, DEF_DEV_NAME_MAX17215,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 2 * MAX1721X_REG_DEV_NUMB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) strncpy(info->DeviceName, DEF_DEV_NAME_UNKNOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 2 * MAX1721X_REG_DEV_NUMB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) if (get_sn_string(info, info->SerialNumber)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) dev_err(info->w1_dev, "Can't read serial. Hardware error.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) info->bat = devm_power_supply_register(&sl->dev, &info->bat_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) &psy_cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) if (IS_ERR(info->bat)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) dev_err(info->w1_dev, "failed to register battery\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) return PTR_ERR(info->bat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) static const struct w1_family_ops w1_max1721x_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) .add_slave = devm_w1_max1721x_add_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) static struct w1_family w1_max1721x_family = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) .fid = W1_MAX1721X_FAMILY_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) .fops = &w1_max1721x_fops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) module_w1_family(w1_max1721x_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) MODULE_AUTHOR("Alex A. Mihaylov <minimumlaw@rambler.ru>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) MODULE_DESCRIPTION("Maxim MAX17211/MAX17215 Fuel Gauage IC driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) MODULE_ALIAS("w1-family-" __stringify(W1_MAX1721X_FAMILY_ID));