Add support for MAX1721x fuel gauge chips
Subsystems (2)
cover Add support for MAX1721x fuel gauge chips
Maxim Semiconductor MAX17211/MAX17215 is M5 Fuel Gauge Monitor with OneWire (W1) interface.
This patch provide W1 family, MAX17211x slave device and MAX17211x battery power_supply class device.
Alex A. Mihaylov (2):
Add support for OneWire (W1) devices family 0x26 (MAX17211/MAX17215) Add driver for MAX17211/MAX17215 fuel gauge
drivers/power/supply/Kconfig | 8 + drivers/power/supply/Makefile | 1 + drivers/power/supply/max1721x_battery.c | 303 ++++++++++++++++++++++++++++++++ drivers/w1/slaves/Kconfig | 12 ++ drivers/w1/slaves/Makefile | 1 + drivers/w1/slaves/w1_max1721x.c | 121 +++++++++++++ drivers/w1/slaves/w1_max1721x.h | 101 +++++++++++ drivers/w1/w1_family.h | 1 + 8 files changed, 548 insertions(+) create mode 100644 drivers/power/supply/max1721x_battery.c create mode 100644 drivers/w1/slaves/w1_max1721x.c create mode 100644 drivers/w1/slaves/w1_max1721x.h
Signature · 1 line
2.8.4 (Apple Git-73)
PATCH 1/2 Add support for OneWire (W1) devices family 0x26 (MAX17211/MAX17215)
Maxim Semiconductor MAX17211/MAX17215 single/multi-cell fuel gauge monitor with M5 Fuel Gauge algorithm
Slave device provide software layer for access to internal registers MAX17211/MAX17215 chip.
--- drivers/w1/slaves/Kconfig | 12 ++++ drivers/w1/slaves/Makefile | 1 + drivers/w1/slaves/w1_max1721x.c | 121 ++++++++++++++++++++++++++++++++++++++++ drivers/w1/slaves/w1_max1721x.h | 101 +++++++++++++++++++++++++++++++++ drivers/w1/w1_family.h | 1 + 5 files changed, 236 insertions(+) create mode 100644 drivers/w1/slaves/w1_max1721x.c create mode 100644 drivers/w1/slaves/w1_max1721x.h
drivers/w1/slaves/Kconfig +12 -0
@@ -78,6 +78,18 @@ config W1_SLAVE_DS2433_CRC Each block has 30 bytes of data and a two byte CRC16. Full block writes are only allowed if the CRC is valid. +config W1_SLAVE_MAX1721X + tristate "Maxim MAX17211/MAX17215 battery monitor chip" + help + If you enable this you will have the MAX17211/MAX17215 battery + monitor chip support. + + The battery monitor chip is used in many batteries/devices + as the one who is responsible for charging/discharging/monitoring + Li+ batteries. + + If you are unsure, say N. + config W1_SLAVE_DS2760 tristate "Dallas 2760 battery monitor chip (HP iPAQ & others)" help
drivers/w1/slaves/Makefile +1 -0
@@ -10,6 +10,7 @@ obj-$(CONFIG_W1_SLAVE_DS2406) += w1_ds2406.o obj-$(CONFIG_W1_SLAVE_DS2423) += w1_ds2423.o obj-$(CONFIG_W1_SLAVE_DS2431) += w1_ds2431.o obj-$(CONFIG_W1_SLAVE_DS2433) += w1_ds2433.o +obj-$(CONFIG_W1_SLAVE_MAX1721X) += w1_max1721x.o obj-$(CONFIG_W1_SLAVE_DS2760) += w1_ds2760.o obj-$(CONFIG_W1_SLAVE_DS2780) += w1_ds2780.o obj-$(CONFIG_W1_SLAVE_DS2781) += w1_ds2781.o
drivers/w1/slaves/w1_max1721x.c new file +121 -0
121 lines not on this page · raw message
drivers/w1/slaves/w1_max1721x.h new file +101 -0
101 lines not on this page · raw message
drivers/w1/w1_family.h +1 -0
@@ -35,6 +35,7 @@#define W1_COUNTER_DS2423 0x1D#define W1_THERM_DS1822 0x22#define W1_EEPROM_DS2433 0x23 +#define W1_FAMILY_MAX17211 0x26#define W1_THERM_DS18B20 0x28#define W1_FAMILY_DS2408 0x29#define W1_EEPROM_DS2431 0x2D
Signature · 1 line
2.8.4 (Apple Git-73)
PATCH 2/2 Add driver for MAX17211/MAX17215 fuel gauge
In reply to Alex A. MihaylovMaxim Semiconductor MAX17211/MAX17215 single/multi-cell fuel gauge monitor with M5 Fuel Gauge algorithm
This driver provide userspace access to MAX17211/MAX17215 data with power_supply class drivers.
--- drivers/power/supply/Kconfig | 8 + drivers/power/supply/Makefile | 1 + drivers/power/supply/max1721x_battery.c | 303 ++++++++++++++++++++++++++++++++ 3 files changed, 312 insertions(+) create mode 100644 drivers/power/supply/max1721x_battery.c
drivers/power/supply/Kconfig +8 -0
@@ -117,6 +117,14 @@ config BATTERY_DS2782 Say Y here to enable support for the DS2782/DS2786 standalone battery gas-gauge. +config BATTERY_MAX1721X + tristate "MAX17211/MAX17215 standalone gas-gauge" + depends on W1 + select W1_SLAVE_MAX1721X + help + Say Y here to enable support for the MAX17211/MAX17215 standalone + battery gas-gauge. + config BATTERY_PMU tristate "Apple PMU battery" depends on PPC32 && ADB_PMU
drivers/power/supply/Makefile +1 -0
@@ -22,6 +22,7 @@ obj-$(CONFIG_BATTERY_DS2760) += ds2760_battery.o obj-$(CONFIG_BATTERY_DS2780) += ds2780_battery.o obj-$(CONFIG_BATTERY_DS2781) += ds2781_battery.o obj-$(CONFIG_BATTERY_DS2782) += ds2782_battery.o +obj-$(CONFIG_BATTERY_MAX1721X) += max1721x_battery.o obj-$(CONFIG_BATTERY_GAUGE_LTC2941) += ltc2941-battery-gauge.o obj-$(CONFIG_BATTERY_GOLDFISH) += goldfish_battery.o obj-$(CONFIG_BATTERY_PMU) += pmu_battery.o
drivers/power/supply/max1721x_battery.c new file +303 -0
303 lines not on this page · raw message
Signature · 1 line
2.8.4 (Apple Git-73)
Sebastian Reichel
maintainerRe: [PATCH 1/2] Add support for OneWire (W1) devices family 0x26 (MAX17211/MAX17215)
In reply to Alex A. MihaylovHi,
Quoted 5 lines · Alex A. Mihaylov
Maxim Semiconductor MAX17211/MAX17215 single/multi-cell fuel gauge monitor with M5 Fuel Gauge algorithm
Slave device provide software layer for access to internal registers MAX17211/MAX17215 chip.
Please convert this to regmap. There should be lots of docs and examples around, for example:
http://elinux.org/images/a/a3/Regmap-_The_Power_of_Subsystems_and_Abstractions.pdf
There is no generic w1 handler, but you can provide custom read/write functions. Also it would be nice to have this based on https://lkml.org/lkml/2017/3/16/604. Then everything could go into the power-supply driver.
-- Sebastian
Sebastian Reichel
maintainerRe: [PATCH 2/2] Add driver for MAX17211/MAX17215 fuel gauge
In reply to Alex A. MihaylovHi,
Please make sure you Cc the relevant people / mailing lists. You can use ./scripts/get_maintainer.pl to find out who should receive the patches.
Quoted 9 lines · Alex A. Mihaylov
Maxim Semiconductor MAX17211/MAX17215 single/multi-cell fuel gauge monitor with M5 Fuel Gauge algorithm
This driver provide userspace access to MAX17211/MAX17215 data with
power_supplyclass drivers.--- drivers/power/supply/Kconfig | 8 + drivers/power/supply/Makefile | 1 +
Please move the entries in both files before CONFIG_BATTERY_MAX17040.
drivers/power/supply/max1721x_battery.c line 214
Quoted 8 lines
[...]
drivers/power/supply/max1721x_battery.c new file +6
-0+* FixMe: +* Device without no_thermal = true not register (err -22) +* Len of platform device name "max17211-battery.X.auto" +* more than 20 chars limit in THERMAL_NAME_LENGTH from +* include/uapi/linux/thermal.h +*/
IIRC we already had problems with small THERMAL_NAME_LENGTH before. I suggest to add another patch, that increases THERMAL_NAME_LENGTH (don't forget to Cc/To the thermal subsystem people).
Quoted 53 lines
drivers/power/supply/max1721x_battery.c new file +53
-0+ info->bat_desc.no_thermal = true; + psy_cfg.drv_data = info; + +if (w1_max1721x_reg_get (info->w1_dev, +MAX1721X_REG_NRSENSE , &info->rsense)) +return -ENODEV ; + +if (!info->rsense) { +dev_warn (info->dev,"RSenese not calibrated, set 10 mOhms!\n" ); + info->rsense =1000 ;/* in regs in 10^-5 */ + } +dev_dbg (info->dev,"RSense: %d mOhms.\n" , info->rsense /100 ); + +if (get_string (info->w1_dev,MAX1721X_REG_MFG_STR , +MAX1721X_REG_MFG_NUMB , info->ManufacturerName)) { +dev_err (info->dev,"Can't read manufacturer. Hardware error.\n" ); +return -ENODEV ; + } + +if (!info->ManufacturerName[0 ]) +strncpy (info->ManufacturerName,DEF_MFG_NAME , +2 *MAX1721X_REG_MFG_NUMB ); + +if (get_string (info->w1_dev,MAX1721X_REG_DEV_STR , +MAX1721X_REG_DEV_NUMB , info->DeviceName)) { +dev_err (info->dev,"Can't read device. Hardware error.\n" ); +return -ENODEV ; + } +if (!info->DeviceName[0 ]) { +uint16_t dev_name; + +if (w1_max1721x_reg_get (info->w1_dev, +MAX172XX_REG_DEVNAME , &dev_name)) { +dev_err (info->w1_dev,"Can't read device name reg.\n" ); +return -ENODEV ; + } + +switch (dev_name &MAX172XX_DEV_MASK ) { +case MAX172X1_DEV : +strncpy (info->DeviceName,DEF_DEV_NAME_MAX17211 , +2 *MAX1721X_REG_DEV_NUMB ); +break ; +case MAX172X5_DEV : +strncpy (info->DeviceName,DEF_DEV_NAME_MAX17215 , +2 *MAX1721X_REG_DEV_NUMB ); +break ; +default : +strncpy (info->DeviceName,DEF_DEV_NAME_UNKNOWN , +2 *MAX1721X_REG_DEV_NUMB ); + } + } + +if (get_sn_string (info->w1_dev, info->SerialNumber)) {
drivers/power/supply/max1721x_battery.c line 277
Quoted 10 lines
drivers/power/supply/max1721x_battery.c new file +10
-0+dev_err (info->dev,"Can't read serial. Hardware error.\n" ); +return -ENODEV ; + } + + info->bat =power_supply_register (&pdev->dev, &info->bat_desc, + &psy_cfg); +if (IS_ERR (info->bat)) { +dev_err (info->dev,"failed to register battery\n" ); +return PTR_ERR (info->bat); + }
Please use devm_power_supply_register() and drop the remove function.
Quoted 15 lines
drivers/power/supply/max1721x_battery.c new file +15
-0+return 0 ; +} + +static int max1721x_battery_remove (struct platform_device *pdev) +{ +struct max17211_device_info *info =platform_get_drvdata (pdev); + +power_supply_unregister (info->bat); + +return 0 ; +} + +static struct platform_driver max1721x_battery_driver = { + .driver = { + .name ="max1721x-battery" ,
drivers/power/supply/max1721x_battery.c line 303
Quoted 10 lines
drivers/power/supply/max1721x_battery.c new file +10
-0+ }, + .probe = max1721x_battery_probe, + .remove = max1721x_battery_remove, +}; +module_platform_driver (max1721x_battery_driver); + +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Alex A. Mihaylov <[email protected]>" ); +MODULE_DESCRIPTION ("Maxim MAX17211/MAX17215 Fuel Gauage IC driver" ); +MODULE_ALIAS ("platform:max1721x-battery" );
-- Sebastian
Re: [PATCH 1/2] Add support for OneWire (W1) devices family 0x26 (MAX17211/MAX17215)
In reply to Sebastian ReichelHi,
Quoted 4 lines
Quoted 2 lines
Slave device provide software layer for access to internal registers MAX17211/MAX17215 chip.
Please convert this to regmap.There is no generic w1 handler, but you can provide custom read/write functions.
I think regmap be overkill for this driver. Here we need access to a small number of registers. Registers are extremely simple on the internal device. As a result, the software layer of regmap will only complicate the readability and understanding of the code. And also increase the size and time of code execution, and even complicate the perception.
Quoted 4 lines
Also it would be nice to have this
based on https://lkml.org/lkml/2017/3/16/604. Then everything could go into the power-supply driver.
No problems. Once this set of patches will be accepted in the mainline.
Alex.
Re: [PATCH 2/2] Add driver for MAX17211/MAX17215 fuel gauge
In reply to Sebastian ReichelHi!
Quoted 11 lines
drivers/power/supply/max1721x_battery.c line 214
Quoted 8 lines
[...]
drivers/power/supply/max1721x_battery.c new file +6
-0+* FixMe: +* Device without no_thermal = true not register (err -22) +* Len of platform device name "max17211-battery.X.auto" +* more than 20 chars limit in THERMAL_NAME_LENGTH from +* include/uapi/linux/thermal.h +*/ IIRC we already had problems with small
THERMAL_NAME_LENGTHbefore. I suggest to add another patch, that increasesTHERMAL_NAME_LENGTH(don't forget to Cc/To the thermal subsystem people).
May be rename "max17211-battery" to "max17211" and remove no_thermal = true? This case thermal zone will work again. In current (mainline) kernel all drivers "xxxxxx-battery" (like ds2780-battery or ds2760-battery) compiled, but not working (not registered). They can start working again without thermal zone by adding no_thermal = true or by remove "-battery" from platform device name. Alternative limit on THERMAL_NAME_LENGTH may be extended.
Quoted 8 lines
drivers/power/supply/max1721x_battery.c line 277
Quoted 6 lines
drivers/power/supply/max1721x_battery.c new file +6
-0+ info->bat =power_supply_register (&pdev->dev, &info->bat_desc, + &psy_cfg); +if (IS_ERR (info->bat)) { +dev_err (info->dev,"failed to register battery\n" ); +return PTR_ERR (info->bat); + }Please use
devm_power_supply_register()and drop the remove function.
Khm... probe/remove paired functions. I can use devm_power_supply_register in my code. But all other fuel gauge drivers use classic probe/remove pair. Which decision will be more correct?
Sebastian Reichel
maintainerRe: [PATCH 2/2] Add driver for MAX17211/MAX17215 fuel gauge
Hi,
Quoted 10 lines · Михайлов Алексей Анатольевич
Quoted 3 lines
IIRC we already had problems with small
THERMAL_NAME_LENGTHbefore. I suggest to add another patch, that increasesTHERMAL_NAME_LENGTH(don't forget to Cc/To the thermal subsystem people).May be rename "max17211-battery" to "max17211" and remove
no_thermal= true? This case thermal zone will work again. In current (mainline) kernel all drivers "xxxxxx-battery" (like ds2780-battery or ds2760-battery) compiled, but not working (not registered). They can start working again without thermal zone by addingno_thermal= true or by remove "-battery" from platform device name. Alternative limit onTHERMAL_NAME_LENGTHmay be extended.
I think increasing THERMAL_NAME_LENGTH is the right way.
Quoted 11 lines
Quoted 8 lines
drivers/power/supply/max1721x_battery.c line 277
Quoted 6 lines
drivers/power/supply/max1721x_battery.c new file +6
-0+ info->bat =power_supply_register (&pdev->dev, &info->bat_desc, + &psy_cfg); +if (IS_ERR (info->bat)) { +dev_err (info->dev,"failed to register battery\n" ); +return PTR_ERR (info->bat); + }Please use
devm_power_supply_register()and drop the remove function.Khm... probe/remove paired functions. I can use
devm_power_supply_registerin my code. But all other fuel gauge drivers use classic probe/remove pair. Which decision will be more correct?
Most drivers are older than devm_power_supply_register. We already have a few fuel gauge drivers, which use it, though:
$ git grep devm_power_supply_register | grep "battery" 88pm860x_battery.c: info->battery = devm_power_supply_register(&pdev->dev, da9150-fg.c: fg->battery = devm_power_supply_register(dev, &fg_desc, NULL); max17042_battery.c: chip->battery = devm_power_supply_register(&client->dev, max17042_desc, max8997_charger.c: charger->battery = devm_power_supply_register(&pdev->dev, max8998_charger.c: max8998->battery = devm_power_supply_register(max8998->dev, sbs-battery.c: chip->power_supply = devm_power_supply_register(&client->dev, sbs_desc,
-- Sebastian
Sebastian Reichel
maintainerRe: [PATCH 1/2] Add support for OneWire (W1) devices family 0x26 (MAX17211/MAX17215)
In reply to Alex A. MihaylovHi,
Quoted 9 lines · Alex A. Mihaylov
Quoted 4 lines
Quoted 2 lines
Slave device provide software layer for access to internal registers MAX17211/MAX17215 chip.
Please convert this to regmap.There is no generic w1 handler, but you can provide custom read/write functions.
I think regmap be overkill for this driver. Here we need access to a small number of registers. Registers are extremely simple on the internal device. As a result, the software layer of regmap will only complicate the readability and understanding of the code. And also increase the size and time of code execution, and even complicate the perception.
I did not ask for full usage of all regmap features. Just register the read/write handler as regmap handler and use regmap_read/write to get values.
-- Sebastian
Re: [PATCH 1/2] Add support for OneWire (W1) devices family 0x26 (MAX17211/MAX17215)
Hi!
30.04.17 23:53, Sebastian Reichel wrote::
Quoted 9 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines
Slave device provide software layer for access to internal registers MAX17211/MAX17215 chip.
Please convert this to regmap.There is no generic w1 handler, but you can provide custom read/write functions.
I think regmap be overkill for this driver. the perception.
I did not ask for full usage of all regmap features. Just register the read/write handler as regmap handler and use regmap_read/write to get values.
OK, I think about this. But max17211-battery use ONLY w1_max12711x_reg_get(). This is very simple function.
Second function w1_max1721x_reg_set() writen for extend feature list (factory calibrating and init battery). I think, this code must _NOT_ be writen, and must _NOT_ be accessible for end user. Change calibration values potentially can damage battery or device. Theory, I can unexport this function and remove them from drivers code.
So output registers of Maxim M5 Fuel Gauge algorithm very simple: one register - one value. In driver I have two points with bitfield. First - battery connected from power supply props. Second: very optional device type from probe. This value _NOT_ used from driver - just write device type, if manufacturer not fill this data in chip nvram.
This moment driver use 14 registers. Ok, let's some time above will be 14*3=42 registers accessible with w1_max1721x_reg_get(). This value is greatly overestimated - so many properties are not in the class POWER_SUPPLY. But register range in MAX1721X is 0x1F0 (496 words or 992 bytes) of RAM for cache registers. As embedded system developer I dislike so ram management.
As result I repeat: regmap will be overkill for this driver. But OK, I try to write this code. Just for fun.