Re: [PATCH 2/2] Add driver for MAX17211/MAX17215 fuel gauge

2017-04-30 Thread Sebastian Reichel
Hi,

On Sun, Apr 30, 2017 at 08:32:10PM +0300, Михайлов Алексей Анатольевич wrote:
> > 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).
> 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 "xx-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.

I think increasing THERMAL_NAME_LENGTH is the right way.

> > > + info->bat = power_supply_register(>dev, >bat_desc,
> > > + _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?

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(>dev,
da9150-fg.c:fg->battery = devm_power_supply_register(dev, _desc, NULL);
max17042_battery.c: chip->battery = 
devm_power_supply_register(>dev, max17042_desc,
max8997_charger.c:  charger->battery = 
devm_power_supply_register(>dev,
max8998_charger.c:  max8998->battery = 
devm_power_supply_register(max8998->dev,
sbs-battery.c:  chip->power_supply = devm_power_supply_register(>dev, 
sbs_desc,

-- Sebastian


signature.asc
Description: PGP signature


Re: [PATCH 2/2] Add driver for MAX17211/MAX17215 fuel gauge

2017-04-30 Thread Sebastian Reichel
Hi,

On Sun, Apr 30, 2017 at 08:32:10PM +0300, Михайлов Алексей Анатольевич wrote:
> > 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).
> 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 "xx-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.

I think increasing THERMAL_NAME_LENGTH is the right way.

> > > + info->bat = power_supply_register(>dev, >bat_desc,
> > > + _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?

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(>dev,
da9150-fg.c:fg->battery = devm_power_supply_register(dev, _desc, NULL);
max17042_battery.c: chip->battery = 
devm_power_supply_register(>dev, max17042_desc,
max8997_charger.c:  charger->battery = 
devm_power_supply_register(>dev,
max8998_charger.c:  max8998->battery = 
devm_power_supply_register(max8998->dev,
sbs-battery.c:  chip->power_supply = devm_power_supply_register(>dev, 
sbs_desc,

-- Sebastian


signature.asc
Description: PGP signature


Re: [PATCH 2/2] Add driver for MAX17211/MAX17215 fuel gauge

2017-04-30 Thread Михайлов Алексей Анатольевич

Hi!



[...]

+* 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).
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 "xx-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.

+   info->bat = power_supply_register(>dev, >bat_desc,
+   _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?




Re: [PATCH 2/2] Add driver for MAX17211/MAX17215 fuel gauge

2017-04-30 Thread Михайлов Алексей Анатольевич

Hi!



[...]

+* 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).
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 "xx-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.

+   info->bat = power_supply_register(>dev, >bat_desc,
+   _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?




Re: [PATCH 2/2] Add driver for MAX17211/MAX17215 fuel gauge

2017-04-29 Thread Sebastian Reichel
Hi,

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.

On Sat, Apr 29, 2017 at 05:34:29PM +0300, Alex A. Mihaylov wrote:
> 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_supply class drivers.

> ---
>  drivers/power/supply/Kconfig|   8 +
>  drivers/power/supply/Makefile   |   1 +

Please move the entries in both files before CONFIG_BATTERY_MAX17040.

> [...]
>
> +  * 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).

> + info->bat_desc.no_thermal = true;
> + psy_cfg.drv_data = info;
> +
> + if (w1_max1721x_reg_get(info->w1_dev,
> + MAX1721X_REG_NRSENSE, >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, _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)) {
> + dev_err(info->dev, "Can't read serial. Hardware error.\n");
> + return -ENODEV;
> + }
> +
> + info->bat = power_supply_register(>dev, >bat_desc,
> + _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.

> + 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",
> + },
> + .probe= max1721x_battery_probe,
> + .remove   = max1721x_battery_remove,
> +};
> +module_platform_driver(max1721x_battery_driver);
> +
> +MODULE_LICENSE("GPL");
> +MODULE_AUTHOR("Alex A. Mihaylov ");
> +MODULE_DESCRIPTION("Maxim MAX17211/MAX17215 Fuel Gauage IC driver");
> +MODULE_ALIAS("platform:max1721x-battery");

-- Sebastian


signature.asc
Description: PGP signature


Re: [PATCH 2/2] Add driver for MAX17211/MAX17215 fuel gauge

2017-04-29 Thread Sebastian Reichel
Hi,

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.

On Sat, Apr 29, 2017 at 05:34:29PM +0300, Alex A. Mihaylov wrote:
> 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_supply class drivers.

> ---
>  drivers/power/supply/Kconfig|   8 +
>  drivers/power/supply/Makefile   |   1 +

Please move the entries in both files before CONFIG_BATTERY_MAX17040.

> [...]
>
> +  * 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).

> + info->bat_desc.no_thermal = true;
> + psy_cfg.drv_data = info;
> +
> + if (w1_max1721x_reg_get(info->w1_dev,
> + MAX1721X_REG_NRSENSE, >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, _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)) {
> + dev_err(info->dev, "Can't read serial. Hardware error.\n");
> + return -ENODEV;
> + }
> +
> + info->bat = power_supply_register(>dev, >bat_desc,
> + _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.

> + 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",
> + },
> + .probe= max1721x_battery_probe,
> + .remove   = max1721x_battery_remove,
> +};
> +module_platform_driver(max1721x_battery_driver);
> +
> +MODULE_LICENSE("GPL");
> +MODULE_AUTHOR("Alex A. Mihaylov ");
> +MODULE_DESCRIPTION("Maxim MAX17211/MAX17215 Fuel Gauage IC driver");
> +MODULE_ALIAS("platform:max1721x-battery");

-- Sebastian


signature.asc
Description: PGP signature


[PATCH 2/2] Add driver for MAX17211/MAX17215 fuel gauge

2017-04-29 Thread 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_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

diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig
index 76806a0..25fe441 100644
--- a/drivers/power/supply/Kconfig
+++ b/drivers/power/supply/Kconfig
@@ -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
diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile
index 36c599d..1e5546d 100644
--- a/drivers/power/supply/Makefile
+++ b/drivers/power/supply/Makefile
@@ -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
diff --git a/drivers/power/supply/max1721x_battery.c 
b/drivers/power/supply/max1721x_battery.c
new file mode 100644
index 000..ff77d3f
--- /dev/null
+++ b/drivers/power/supply/max1721x_battery.c
@@ -0,0 +1,303 @@
+/*
+ * 1-wire client/driver for the Maxim MAX17211/MAX17215 Fuel Gauge IC
+ *
+ * Author: Alex A. Mihaylov 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "../../w1/w1.h"
+#include "../../w1/slaves/w1_max1721x.h"
+
+#define DEF_DEV_NAME_MAX17211  "MAX17211"
+#define DEF_DEV_NAME_MAX17215  "MAX17215"
+#define DEF_DEV_NAME_UNKNOWN   "UNKNOWN"
+#define DEF_MFG_NAME   "MAXIM"
+
+struct max17211_device_info {
+   struct device *dev;
+   struct power_supply *bat;
+   struct power_supply_desc bat_desc;
+   struct device *w1_dev;
+   /* battery design format */
+   uint16_t rsense; /* in tenths uOhm */
+   char DeviceName[2 * MAX1721X_REG_DEV_NUMB + 1];
+   char ManufacturerName[2 * MAX1721X_REG_MFG_NUMB + 1];
+   char SerialNumber[13]; /* see get_sn_str() later for comment */
+};
+
+static inline struct max17211_device_info *
+to_device_info(struct power_supply *psy)
+{
+   return power_supply_get_drvdata(psy);
+}
+
+static int max1721x_battery_get_property(struct power_supply *psy,
+   enum power_supply_property psp,
+   union power_supply_propval *val)
+{
+   struct max17211_device_info *info = to_device_info(psy);
+   uint16_t reg;
+   int ret = 0;
+
+   switch (psp) {
+   case POWER_SUPPLY_PROP_PRESENT:
+   /*
+* POWER_SUPPLY_PROP_PRESENT will always readable via
+* sysfs interface. Value return 0 if battery not
+* present or unaccesable via W1.
+*/
+   val->intval =
+   w1_max1721x_reg_get(info->w1_dev, MAX172XX_REG_STATUS,
+   ) ? 0 : !(reg & MAX172XX_BAT_PRESENT);
+   break;
+   case POWER_SUPPLY_PROP_CAPACITY:
+   ret = w1_max1721x_reg_get(info->w1_dev,
+   MAX172XX_REG_REPSOC, );
+   val->intval = max172xx_percent_to_ps(reg);
+   break;
+   case POWER_SUPPLY_PROP_VOLTAGE_NOW:
+   ret = w1_max1721x_reg_get(info->w1_dev,
+   MAX172XX_REG_BATT, );
+   val->intval = max172xx_voltage_to_ps(reg);
+   break;
+   case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
+   ret = w1_max1721x_reg_get(info->w1_dev,
+   MAX172XX_REG_DESIGNCAP, );
+   val->intval = max172xx_capacity_to_ps(reg);
+   break;
+   case POWER_SUPPLY_PROP_CHARGE_AVG:
+   ret = w1_max1721x_reg_get(info->w1_dev,
+   MAX172XX_REG_REPCAP, );
+   val->intval = max172xx_capacity_to_ps(reg);
+   break;
+   case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG:
+   ret = 

[PATCH 2/2] Add driver for MAX17211/MAX17215 fuel gauge

2017-04-29 Thread 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_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

diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig
index 76806a0..25fe441 100644
--- a/drivers/power/supply/Kconfig
+++ b/drivers/power/supply/Kconfig
@@ -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
diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile
index 36c599d..1e5546d 100644
--- a/drivers/power/supply/Makefile
+++ b/drivers/power/supply/Makefile
@@ -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
diff --git a/drivers/power/supply/max1721x_battery.c 
b/drivers/power/supply/max1721x_battery.c
new file mode 100644
index 000..ff77d3f
--- /dev/null
+++ b/drivers/power/supply/max1721x_battery.c
@@ -0,0 +1,303 @@
+/*
+ * 1-wire client/driver for the Maxim MAX17211/MAX17215 Fuel Gauge IC
+ *
+ * Author: Alex A. Mihaylov 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "../../w1/w1.h"
+#include "../../w1/slaves/w1_max1721x.h"
+
+#define DEF_DEV_NAME_MAX17211  "MAX17211"
+#define DEF_DEV_NAME_MAX17215  "MAX17215"
+#define DEF_DEV_NAME_UNKNOWN   "UNKNOWN"
+#define DEF_MFG_NAME   "MAXIM"
+
+struct max17211_device_info {
+   struct device *dev;
+   struct power_supply *bat;
+   struct power_supply_desc bat_desc;
+   struct device *w1_dev;
+   /* battery design format */
+   uint16_t rsense; /* in tenths uOhm */
+   char DeviceName[2 * MAX1721X_REG_DEV_NUMB + 1];
+   char ManufacturerName[2 * MAX1721X_REG_MFG_NUMB + 1];
+   char SerialNumber[13]; /* see get_sn_str() later for comment */
+};
+
+static inline struct max17211_device_info *
+to_device_info(struct power_supply *psy)
+{
+   return power_supply_get_drvdata(psy);
+}
+
+static int max1721x_battery_get_property(struct power_supply *psy,
+   enum power_supply_property psp,
+   union power_supply_propval *val)
+{
+   struct max17211_device_info *info = to_device_info(psy);
+   uint16_t reg;
+   int ret = 0;
+
+   switch (psp) {
+   case POWER_SUPPLY_PROP_PRESENT:
+   /*
+* POWER_SUPPLY_PROP_PRESENT will always readable via
+* sysfs interface. Value return 0 if battery not
+* present or unaccesable via W1.
+*/
+   val->intval =
+   w1_max1721x_reg_get(info->w1_dev, MAX172XX_REG_STATUS,
+   ) ? 0 : !(reg & MAX172XX_BAT_PRESENT);
+   break;
+   case POWER_SUPPLY_PROP_CAPACITY:
+   ret = w1_max1721x_reg_get(info->w1_dev,
+   MAX172XX_REG_REPSOC, );
+   val->intval = max172xx_percent_to_ps(reg);
+   break;
+   case POWER_SUPPLY_PROP_VOLTAGE_NOW:
+   ret = w1_max1721x_reg_get(info->w1_dev,
+   MAX172XX_REG_BATT, );
+   val->intval = max172xx_voltage_to_ps(reg);
+   break;
+   case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
+   ret = w1_max1721x_reg_get(info->w1_dev,
+   MAX172XX_REG_DESIGNCAP, );
+   val->intval = max172xx_capacity_to_ps(reg);
+   break;
+   case POWER_SUPPLY_PROP_CHARGE_AVG:
+   ret = w1_max1721x_reg_get(info->w1_dev,
+   MAX172XX_REG_REPCAP, );
+   val->intval = max172xx_capacity_to_ps(reg);
+   break;
+   case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG:
+   ret = w1_max1721x_reg_get(info->w1_dev,
+