Skip to contentSkip to conversation

DS2781 Maxim Stand-Alone Fuel Gauge battery and w1 slave drivers

PATCH New Renata Sayakhova 2 participants 4 messages Feb 29, 2012 1 message not in the archive W1 dallas's 1-wire bus

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 DS2781 Maxim Stand-Alone Fuel Gauge battery and w1 slave drivers

FROM: Renata Sayakhova <[email protected]>

Implementation of DS2781 Maxim Stand-Alone Fuel Gauge battery and w1 slave drivers.

Renata Sayakhova (1):
DS2781 Maxim Stand-Alone Fuel Gauge battery and w1 slave drivers

 drivers/power/Kconfig          |   14 +
 drivers/power/Makefile         |    1 +
 drivers/power/ds2781_battery.c |  874 ++++++++++++++++++++++++++++++++++++++++
 drivers/w1/slaves/Kconfig      |   13 +
 drivers/w1/slaves/Makefile     |    1 +
 drivers/w1/slaves/w1_ds2781.c  |  201 +++++++++
 drivers/w1/slaves/w1_ds2781.h  |  136 +++++++
 drivers/w1/w1_family.h         |    1 +
 8 files changed, 1241 insertions(+), 0 deletions(-)
 create mode 100644 drivers/power/ds2781_battery.c
 create mode 100644 drivers/w1/slaves/w1_ds2781.c
 create mode 100644 drivers/w1/slaves/w1_ds2781.h
Signature · 1 line
1.7.6.3
#1 lore raw

PATCH 1/1 DS2781 Maxim Stand-Alone Fuel Gauge battery and w1 slave drivers

---
 drivers/power/Kconfig          |   14 +
 drivers/power/Makefile         |    1 +
 drivers/power/ds2781_battery.c |  874 ++++++++++++++++++++++++++++++++++++++++
 drivers/w1/slaves/Kconfig      |   13 +
 drivers/w1/slaves/Makefile     |    1 +
 drivers/w1/slaves/w1_ds2781.c  |  201 +++++++++
 drivers/w1/slaves/w1_ds2781.h  |  136 +++++++
 drivers/w1/w1_family.h         |    1 +
 8 files changed, 1241 insertions(+), 0 deletions(-)
 create mode 100644 drivers/power/ds2781_battery.c
 create mode 100644 drivers/w1/slaves/w1_ds2781.c
 create mode 100644 drivers/w1/slaves/w1_ds2781.h
drivers/power/Kconfig +14 -0
index 3a8daf8..459f664 100644
@@ -76,6 +76,20 @@ config BATTERY_DS2780
 	help
 	  Say Y here to enable support for batteries with ds2780 chip.
 
+config BATTERY_DS2781
+	tristate "2781 battery driver"
+	depends on HAS_IOMEM
+	select W1
+	select W1_SLAVE_DS2781
+	help
+	  If you enable this you will have the DS2781 battery driver 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 BATTERY_DS2782
 	tristate "DS2782/DS2786 standalone gas-gauge"
 	depends on I2C
drivers/power/Makefile +1 -0
index e429008..c590fa5 100644
@@ -16,6 +16,7 @@ obj-$(CONFIG_TEST_POWER)	+= test_power.o
 
 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_PMU)	+= pmu_battery.o
 obj-$(CONFIG_BATTERY_OLPC)	+= olpc_battery.o
drivers/power/ds2781_battery.c new file +874 -0

874 lines not on this page · raw message

drivers/w1/slaves/Kconfig +13 -0
index d0cb01b..eb9e376 100644
@@ -81,6 +81,19 @@ config W1_SLAVE_DS2780
 
 	  If you are unsure, say N.
 
+config W1_SLAVE_DS2781
+	tristate "Dallas 2781 battery monitor chip"
+	depends on W1
+	help
+	  If you enable this you will have the DS2781 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_BQ27000
 	tristate "BQ27000 slave support"
 	depends on W1
drivers/w1/slaves/Makefile +1 -0
index 1f31e9f..c4f1859 100644
@@ -10,4 +10,5 @@ obj-$(CONFIG_W1_SLAVE_DS2431)	+= w1_ds2431.o
 obj-$(CONFIG_W1_SLAVE_DS2433)	+= w1_ds2433.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
 obj-$(CONFIG_W1_SLAVE_BQ27000)	+= w1_bq27000.o
drivers/w1/slaves/w1_ds2781.c new file +201 -0

201 lines not on this page · raw message

drivers/w1/slaves/w1_ds2781.h new file +136 -0

136 lines not on this page · raw message

drivers/w1/w1_family.h +1 -0
index 490cda2..874aeb0 100644
@@ -38,6 +38,7 @@
 #define W1_EEPROM_DS2431	0x2D
 #define W1_FAMILY_DS2760	0x30
 #define W1_FAMILY_DS2780	0x32
+#define W1_FAMILY_DS2781	0x3D
 #define W1_THERM_DS28EA00	0x42
 
 #define MAXNAMELEN		32
Signature · 1 line
1.7.6.3
#2 lore raw

Hi Renata

Quoted 2 lines · Renata Sayakhova

Patch looks good except this weird function

drivers/power/ds2781_battery.c line 70

Quoted 9 lines
drivers/power/ds2781_battery.c new file +9 -0
+static inline int ds2781_battery_io(struct ds2781_device_info *dev_info,
+	char *buf, int addr, size_t count, int io)
+{
+	if (dev_info->mutex_holder == current)
+		return w1_ds2781_io_nolock(dev_info->w1_dev, buf, addr,
+				count, io);
+	else
+		return w1_ds2781_io(dev_info->w1_dev, buf, addr, count, io);
+}

Who in the stack can run away holding mutex?

Signature · 1 line
	Evgeniy Polyakov

A message that is not in the archive (sent off-list or not yet received): CAO0_4pY_MXgx1gFRK9ino0P9RAO3e3E00PFCJvjpq2A-6Oz=1Q@mail.gmail.com

#4 lore raw
Quoted 8 lines · Renata Sayakhova

w1_process (w1.c line 982) holds mutex. If during w1_search_process (w1.c line 983) slave is found and battery initcall is already done at this moment than battery probe() is called. This call leads to power_supply_register() and device_add() which does among other things call battery properties. battery_get_property() should normally results in w1_ds2781_read() and w1_ds2781_io(), but w1_ds2781_io() calls itself mutex_lock.

Quoted 7 lines

So this weird function is a workaround to avoid a second mutex_lock during battery probe(). mutex_holder is set before power_supply_register() and unset when probe is done.

This is very brief, if it's not clear I'll try to explain in more details. I found this workaround in implementation of ds2780 battery and w1 slave drivers.

So basically IO routins caled from ->probe() are already locked so we protect against deadlock. Ok, I see.

I have no objections, patch looks good
Greg, please pull it into your tree
Thank you

Signature · 1 line
	Evgeniy Polyakov