DS2781 Maxim Stand-Alone Fuel Gauge battery and w1 slave drivers
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
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Hi Renata
Quoted 2 lines · Renata Sayakhova
Signed-off-by Renata Sayakhova <[email protected]>
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
Evgeniy Polyakov
Acked-byQuoted 8 lines · Renata Sayakhova
w1_process(w1.cline 982) holds mutex. If duringw1_search_process(w1.cline 983) slave is found and battery initcall is already done at this moment than batteryprobe()is called. This call leads topower_supply_register()anddevice_add()which does among other things call battery properties.battery_get_property()should normally results inw1_ds2781_read()andw1_ds2781_io(), butw1_ds2781_io()calls itselfmutex_lock.
Quoted 7 lines
So this weird function is a workaround to avoid a second
mutex_lockduring batteryprobe().mutex_holderis set beforepower_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