Again w1-regman and power_supply MAX1721x
Subsystems (3)
cover Again w1-regman and power_supply MAX1721x
Hi!
I wrote driver for Maxim MAX17211/MAX17215 standalone fuel gauge IC.
Earlier I post preliminary versions of this driver and got recommendations to translate it into the infrastructure of regmap. Accordingly, it was necessary to implement at least basic support of regmap for the OneWire bus. Which was done. There was a criticism about the use of an intermediate platform_device. In this edition, this is also fixed.
I would like to hear not only criticism, but also constructive proposals for the implementation or correction of this code.
Known issuie/troubles:
~~~~~~~~~~~~~~~~~~~~~~
1. Endian for W1-regmap
Code writen for use nativ endian for host (master) device. But waiting for little-endian slave divice. I don't know W1 slave device with big-endian addrees or data format. May be regmap_bus or regmap_config will be checked for host/device endian requirements?
2. W1 Family/device infrastructure
All present power_supply class drivers in vanilla kernel use w1-slave devices. All of them create platform_device with name "chip-battery.X.auto", and power_supply class driver use this platform device. Why used this way? I write code, allocated power_supply at W1 slave (family) device register. This work as expected.
3. Device names
All W1 device have unical 64 bit ID (8-bit family, 48-bit serial number, 8 bit CRC). W1 infrastructure show 56 bits (family-serial_nimber) as w1 slave device name. I use this (unical) device name as power_supply battery name. This work. But in /sys/class/power_supply is placed machine readabe subdir "26-HexDigString", instead of human-readable "chip-battery.X.auto". But in /sys/class/power_supply/26-HexDigString/type file still content human-readable type "Battery".
Thermal zone working, but in /sys/class/thermal/thermal_zoneX/type also placed "26-HexDigString", instead of "chip-battery.X.auto".
I can rename "26-HexDigString" to "battery-26-HexDigString" or "26-HexDigString-battery", but this exceeded 20 chars thermal zone device name. So, thermal zone will have to be disabled.
Alex A. Mihaylov (2):
Basic support for regmap ifrastucture over Maxim/Dalas OneWire Bus MAX1721x Standalone Fuel Gauge IC power_supply class driver
drivers/base/regmap/Kconfig | 6 +- drivers/base/regmap/Makefile | 1 + drivers/base/regmap/regmap-w1.c | 241 +++++++++++++++++++++ drivers/power/supply/Kconfig | 14 ++ drivers/power/supply/Makefile | 1 + drivers/power/supply/max1721x_battery.c | 361 ++++++++++++++++++++++++++++++++ include/linux/power/max172xx-battery.h | 100 +++++++++ include/linux/regmap.h | 34 +++ 8 files changed, 757 insertions(+), 1 deletion(-) create mode 100644 drivers/base/regmap/regmap-w1.c create mode 100644 drivers/power/supply/max1721x_battery.c create mode 100644 include/linux/power/max172xx-battery.h
Signature · 1 line
2.8.4 (Apple Git-73)
RFC 1/2 Basic support for regmap ifrastucture over Maxim/Dalas OneWire Bus
--- drivers/base/regmap/Kconfig | 6 +- drivers/base/regmap/Makefile | 1 + drivers/base/regmap/regmap-w1.c | 241 ++++++++++++++++++++++++++++++++++++++++ include/linux/regmap.h | 34 ++++++ 4 files changed, 281 insertions(+), 1 deletion(-) create mode 100644 drivers/base/regmap/regmap-w1.c
drivers/base/regmap/Kconfig +5 -1
@@ -3,7 +3,7 @@ # subsystems should select the appropriate symbols. config REGMAP - default y if (REGMAP_I2C || REGMAP_SPI || REGMAP_SPMI || REGMAP_AC97 || REGMAP_MMIO || REGMAP_IRQ) + default y if (REGMAP_I2C || REGMAP_SPI || REGMAP_SPMI || REGMAP_W1 || REGMAP_AC97 || REGMAP_MMIO || REGMAP_IRQ) select LZO_COMPRESS select LZO_DECOMPRESS select IRQ_DOMAIN if REGMAP_IRQ
@@ -24,6 +24,10 @@ config REGMAP_SPMI tristate depends on SPMI +config REGMAP_W1 + tristate + depends on W1 + config REGMAP_MMIO tristate
drivers/base/regmap/Makefile +1 -0
@@ -10,3 +10,4 @@ obj-$(CONFIG_REGMAP_SPI) += regmap-spi.o obj-$(CONFIG_REGMAP_SPMI) += regmap-spmi.o obj-$(CONFIG_REGMAP_MMIO) += regmap-mmio.o obj-$(CONFIG_REGMAP_IRQ) += regmap-irq.o +obj-$(CONFIG_REGMAP_W1) += regmap-w1.o
drivers/base/regmap/regmap-w1.c new file +241 -0
241 lines not on this page · raw message
include/linux/regmap.h +34 -0
@@ -461,6 +461,10 @@ struct regmap *__regmap_init_spmi_ext(struct spmi_device *dev,const struct regmap_config *config, struct lock_class_key *lock_key, const char *lock_name); +struct regmap *__regmap_init_w1 (struct device *w1_dev, +const struct regmap_config *config, +struct lock_class_key *lock_key, +const char *lock_name); struct regmap *__regmap_init_mmio_clk(struct device *dev, const char *clk_id, void __iomem *regs, const struct regmap_config *config,
@@ -493,6 +497,10 @@ struct regmap *__devm_regmap_init_spmi_ext(struct spmi_device *dev,const struct regmap_config *config, struct lock_class_key *lock_key, const char *lock_name); +struct regmap *__devm_regmap_init_w1 (struct device *w1_dev, +const struct regmap_config *config, +struct lock_class_key *lock_key, +const char *lock_name); struct regmap *__devm_regmap_init_mmio_clk(struct device *dev, const char *clk_id, void __iomem *regs,
@@ -597,6 +605,19 @@ int regmap_attach_dev(struct device *dev, struct regmap *map, dev, config)/** +* regmap_init_w1() - Initialise register map +* +* @w1_dev: Device that will be interacted with +* @config: Configuration for register map +* +* The return value will be an ERR_PTR() on error or a valid pointer to +* a struct regmap. +*/ +#define regmap_init_w1 (w1_dev, config) \ + __regmap_lockdep_wrapper(__regmap_init_w1, #config, \ + w1_dev, config) + +/** * regmap_init_mmio_clk() - Initialise register map with register clock * * @dev: Device that will be interacted with
@@ -712,6 +733,19 @@ bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg); dev, config)/** +* devm_regmap_init_w1() - Initialise managed register map +* +* @w1_dev: Device that will be interacted with +* @config: Configuration for register map +* +* The return value will be an ERR_PTR() on error or a valid pointer +* to a struct regmap. The regmap will be automatically freed by the +* device management code. +*/ +#define devm_regmap_init_w1 (w1_dev, config) \ + __regmap_lockdep_wrapper(__devm_regmap_init_w1, #config, \ + w1_dev, config) +/** * devm_regmap_init_mmio_clk() - Initialise managed register map with clock * * @dev: Device that will be interacted with
Signature · 1 line
2.8.4 (Apple Git-73)
RFC 2/2 MAX1721x Standalone Fuel Gauge IC power_supply class driver
In reply to Alex A. Mihaylov--- drivers/power/supply/Kconfig | 14 ++ drivers/power/supply/Makefile | 1 + drivers/power/supply/max1721x_battery.c | 361 ++++++++++++++++++++++++++++++++ include/linux/power/max172xx-battery.h | 100 +++++++++ 4 files changed, 476 insertions(+) create mode 100644 drivers/power/supply/max1721x_battery.c create mode 100644 include/linux/power/max172xx-battery.h
drivers/power/supply/Kconfig +14 -0
@@ -268,6 +268,20 @@ config BATTERY_MAX17042 with MAX17042. This driver also supports max17047/50 chips which are improved version of max17042. +config BATTERY_MAX1721X + tristate "MAX17211/MAX17215 standalone gas-gauge" + depends on W1 + select W1_SLAVE_MAX1721X + select REGMAP_W1 + help + MAX1721x is fuel-gauge systems for lithium-ion (Li+) batteries + in handheld and portable equipment. MAX17211 used with single cell + battery. MAX17215 designed for muticell battery. Both them have + OneWire (W1) host interface. + + Say Y here to enable support for the MAX17211/MAX17215 standalone + battery gas-gauge. + config BATTERY_Z2 tristate "Z2 battery driver" depends on I2C && MACH_ZIPIT2
drivers/power/supply/Makefile +1 -0
@@ -41,6 +41,7 @@ obj-$(CONFIG_CHARGER_DA9150) += da9150-charger.o obj-$(CONFIG_BATTERY_DA9150) += da9150-fg.o obj-$(CONFIG_BATTERY_MAX17040) += max17040_battery.o obj-$(CONFIG_BATTERY_MAX17042) += max17042_battery.o +obj-$(CONFIG_BATTERY_MAX1721X) += max1721x_battery.o obj-$(CONFIG_BATTERY_Z2) += z2_battery.o obj-$(CONFIG_BATTERY_RT5033) += rt5033_battery.o obj-$(CONFIG_CHARGER_RT9455) += rt9455_charger.o
drivers/power/supply/max1721x_battery.c new file +361 -0
361 lines not on this page · raw message
include/linux/power/max172xx-battery.h new file +100 -0
100 lines not on this page · raw message
Signature · 1 line
2.8.4 (Apple Git-73)