Maxim Semiconductor MAX1721x power_supply driver
PATCH 3/4 Introduce Maxim Semiconductor MAX17211/MAX17215 Standalone Fuel Gauge IC support for 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 | 357 ++++++++++++++++++++++++++++++++ 3 files changed, 372 insertions(+) create mode 100644 drivers/power/supply/max1721x_battery.c
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 +357 -0
357 lines not on this page · raw message
Signature · 1 line
2.8.4 (Apple Git-73)
cover Maxim Semiconductor MAX1721x power_supply driver
Maxim Semiconductor MAX1721x series chip is standalone fuel gauge for singlecell (MAX17211) or multicell (MAX17215) batteries. This device use OneWire (W1) interface with W1-Family code 0x26
PATCHES:
1. Introduce regmap infrastructure over Maxim/Dalas OneWire (W1) bus
2. Introduce new OneWire (W1) family 0x26 with slave device Maxim Semconductor MAX17211/MAX17215 Fuel Gauge IC
3.Introduce Maxim Semiconductor MAX17211/MAX17215 Standalone Fuel Gauge
IC support for power_supply class driver
4. Fix W1 slave exchange with second device on probe step
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 | 357 ++++++++++++++++++++++++++++++++ drivers/w1/slaves/Kconfig | 12 ++ drivers/w1/slaves/Makefile | 1 + drivers/w1/slaves/w1_max1721x.c | 73 +++++++ drivers/w1/slaves/w1_max1721x.h | 102 +++++++++ drivers/w1/w1.c | 4 +- drivers/w1/w1_family.h | 1 + include/linux/regmap.h | 34 +++ 13 files changed, 844 insertions(+), 3 deletions(-) create mode 100644 drivers/base/regmap/regmap-w1.c 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/4 Introduce regmap infrastructure over Maxim/Dalas OneWire (W1) 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)
PATCH 2/4 Introduce new OneWire (W1) family 0x26 with slave device Maxim Semconductor MAX17211/MAX17215 Fuel Gauge IC
In reply to Alex A. Mihaylov--- drivers/w1/slaves/Kconfig | 12 +++++ drivers/w1/slaves/Makefile | 1 + drivers/w1/slaves/w1_max1721x.c | 73 ++++++++++++++++++++++++++++ drivers/w1/slaves/w1_max1721x.h | 102 ++++++++++++++++++++++++++++++++++++++++ drivers/w1/w1_family.h | 1 + 5 files changed, 189 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
@@ -86,6 +86,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
@@ -11,6 +11,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 +73 -0
73 lines not on this page · raw message
drivers/w1/slaves/w1_max1721x.h new file +102 -0
102 lines not on this page · raw message
drivers/w1/w1_family.h +1 -0
@@ -29,6 +29,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 4/4 Fix W1 slave exchange with second device on probe step
In reply to Alex A. Mihaylov--- drivers/w1/w1.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/w1/w1.c +2 -2
@@ -731,6 +731,7 @@ int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn)memcpy (&sl->reg_num, rn,sizeof (sl->reg_num));atomic_set (&sl->refcnt,1 );atomic_inc (&sl->master->refcnt); + dev->slave_count++;/* slave modules need to be loaded in a context with unlocked mutex */ mutex_unlock (&dev->mutex);
@@ -750,11 +751,11 @@ int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn) sl->family = f; - err =__w1_attach_slave_device (sl);if (err <0 ) {dev_err (&dev->dev,"%s: Attaching %s failed.\n" , __func__, sl->name); + dev->slave_count--;w1_family_put (sl->family);atomic_dec (&sl->master->refcnt);kfree (sl);
@@ -762,7 +763,6 @@ int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn) } sl->ttl = dev->slave_ttl; - dev->slave_count++;memcpy (msg.id.id, rn,sizeof (msg.id)); msg.type =W1_SLAVE_ADD ;
Signature · 1 line
2.8.4 (Apple Git-73)
Greg Kroah-Hartman
maintainerRe: [PATCH 1/4] Introduce regmap infrastructure over Maxim/Dalas OneWire (W1) bus
In reply to Alex A. MihaylovQuoted 1 line · Alex A. Mihaylov
Signed-off-by Alex A. Mihaylov <[email protected]>
I just said I can ont take patches without any changelog text. Why did you resend these without fixing that up?
greg k-h
Mark Brown
maintainerRe: [PATCH 1/4] Introduce regmap infrastructure over Maxim/Dalas OneWire (W1) bus
Quoted 6 lines · Greg Kroah-Hartman
Quoted 1 line · Alex A. Mihaylov
Signed-off-by Alex A. Mihaylov <[email protected]>I just said I can ont take patches without any changelog text. Why did you resend these without fixing that up?
Please don't take regmap patches without my review! Though that's going to be a lot faster if the subject line matches the style for the subsystem...
Mark Brown
maintainerRe: [PATCH 1/4] Introduce regmap infrastructure over Maxim/Dalas OneWire (W1) bus
In reply to Alex A. MihaylovOn Thu, May 25, 2017 at 08:46:36PM +0300, Alex A. Mihaylov wrote:
This looks mostly fine, a couple of small things and like I said in reply to Greg please use subject lines matching the style for the subsystem - this makes it a lot easier for people to identify relevant patches.
Quoted 4 lines
drivers/base/regmap/regmap-w1.c new file +4
-0+int ret = -ENODEV ; + + +if (reg >255 )
drivers/base/regmap/regmap-w1.c line 42
Quoted 10 lines
drivers/base/regmap/regmap-w1.c new file +10
-0+return -EINVAL ; + +mutex_lock (&sl->master->bus_mutex); +if (!w1_reset_select_slave (sl)) { +w1_write_8 (sl->master,W1_CMD_READ_DATA ); +w1_write_8 (sl->master, reg); + *val =w1_read_8 (sl->master); + ret =0 ; + } +mutex_unlock (&sl->master->bus_mutex);
This is a bit confusing with how -ENODEV is generated - move the assignment into the if statement so it doesn't look like we're silently ignoring errors unless you look back to the top of the function.
drivers/base/regmap/regmap-w1.c line 129
Quoted 4 lines
drivers/base/regmap/regmap-w1.c new file +4
-0+static struct regmap_bus regmap_w1_bus_a8_v16 = { + .reg_read = w1_reg_a8_v16_read, + .reg_write = w1_reg_a8_v16_write, +};
It'd be clearer to just have all all these structs at the end of the set of functions rather than scattered about randomly.
Mark Brown
maintainerRe: [PATCH 1/4] Introduce regmap infrastructure over Maxim/Dalas OneWire (W1) bus
In reply to a message not in the archiveQuoted 6 lines · Evgeniy Polyakov
Frankly saying, your non-regmap version was so much simpler, smaller and cleaner. I wonder why did people force you to use regmap.
Guys, please speak up, if you want driver authors to use THIS, it is really flawed.
Sebastien, iirc it was your idea to use regmaps, what was the reason for this?
So, this is the first I've seen of this series but in general the main reason for using regmap is that it allows best practice to be factored out into common code both in terms of the I/O itself and also in terms of framework code being able to provide regmap based helpers for common operations so drivers need less code. The cache code is also really useful for a lot of devices, it's a performance boost for reads and is well optimized for restoring device state if you don't care about sequencing (this is where some of the MMIO users come from). You also get a bunch of debug support for free, things like the tracepoints and debugfs files (those do work better if you describe the register map).
Looking at the code in the regmap patch I have to say I'm very surprised if this is adding much complexity, usually moving to regmap is basically a sed.
Re: [PATCH 1/4] Introduce regmap infrastructure over Maxim/Dalas OneWire (W1) bus
In reply to Mark BrownQuoted 15 lines
This looks mostly fine, a couple of small things and like I said in reply to Greg please use subject lines matching the style for the subsystem - this makes it a lot easier for people to identify relevant patches.
Quoted 9 lines
drivers/base/regmap/regmap-w1.c new file +9
-0+int ret = -ENODEV ; + + +if (reg >255 ) +return -EINVAL ; + +mutex_lock (&sl->master->bus_mutex); +if (!w1_reset_select_slave (sl)) { +w1_write_8 (sl->master,W1_CMD_READ_DATA );
Quoted 8 lines
drivers/base/regmap/regmap-w1.c line 42
Quoted 5 lines
drivers/base/regmap/regmap-w1.c new file +5
-0+w1_write_8 (sl->master, reg); + *val =w1_read_8 (sl->master); + ret =0 ; + } +mutex_unlock (&sl->master->bus_mutex);This is a bit confusing with how
-ENODEVis generated - move the assignment into the if statement so it doesn't look like we're silently ignoring errors unless you look back to the top of the function.
Ok. I set default return value to -ENODEV. W1 (OneWire) Bus periodically scan for connected devices. Typical time between scans about 60 sec. This period W1 slave device can present in kernel device list, but will physically disconnected.
Only w1_reset_select_slave(sl) can say me about device still physically accessible. Only on success w1_reset_select_slave return zero. I think code, like
if (!w1_reset_select_slave(sl)) {
[...]
ret =0;
} else
ret = -ENODEV;
not good.
Quoted 6 lines
drivers/base/regmap/regmap-w1.c line 129
Quoted 4 lines
drivers/base/regmap/regmap-w1.c new file +4
-0+static struct regmap_bus regmap_w1_bus_a8_v16 = { + .reg_read = w1_reg_a8_v16_read, + .reg_write = w1_reg_a8_v16_write, +};It'd be clearer to just have all all these structs at the end of the set of functions rather than scattered about randomly.
Ok. I move this structs down in next version of patches.
I hope that the next edition will not contain such a large number of registration errors. Sorry for all.
Re: [PATCH 1/4] Introduce regmap infrastructure over Maxim/Dalas OneWire (W1) bus
In reply to a message not in the archiveQuoted 3 lines
Alex, it is up to you to decide whether you want to push your regmap version or not, I will not object against, but in my personal opinion your first version version was much cleaner.
I don't know. First edition (without regmap) was very simple. I think anyone could understand how this code works.
On the other hand, there is already a lot of duplicate code in the kernel, which is responsible for accessing device registers on the bus. In this sense, using the regmap infrastructure should help. As for the complex description of registers of a simple device, I consciously went into this complication by describing all the holes in the register map. Since this driver is a pioneer, he must use the maximum of infrastructure capabilities.
But I somehow do not really believe in the correctness of the realisation of regmap for W1. I have too few devices working with this bus. Theory, they all can work with my implementation of regmap. But not the fact that there will not be those who can not.
Mark Brown
maintainerRe: [PATCH 1/4] Introduce regmap infrastructure over Maxim/Dalas OneWire (W1) bus
In reply to a message not in the archiveOn Fri, May 26, 2017 at 04:45:12PM +0300, Evgeniy Polyakov wrote:
Please fix your mail client to word wrap within paragraphs at something substantially less than 80 columns. Doing this makes your messages much easier to read and reply to.
Quoted 5 lines
I wonder what is 'cache' argument about? If I know that some read can be cached, since underlying hardware never changes these values, I can store it into local variable and use it. If I do not know in advance whether given register can be cached, how can regmap determine it for me? How to debug cases when register
was erroneously considered to be cached?
regmap will only cache registers if it was explicitly told to cache, if the driver gets that wrong it's just your bog standard bug that can be debugged in the usual ways one might debug things. By default nothing will be cached.
Quoted 1 line
What is the reason to use regmap besides caching?
There's the other reasons I mentioned in the message you're replying to for a start...
Mark Brown
maintainerRe: [PATCH 1/4] Introduce regmap infrastructure over Maxim/Dalas OneWire (W1) bus
In reply to a message not in the archiveQuoted 9 lines · Evgeniy Polyakov
26.05.2017, 20:18, "Mark Brown" <[email protected]>:
Quoted 5 lines · Evgeniy Polyakov
Please fix your mail client to word wrap within paragraphs at something substantially less than 80 columns. Doing this makes your messages much easier to read and reply to.
What part of the message spans behind this limit? Did you handwrap paragraph below or it looked like a single line?
Essentially every line of your mail is overly long, including the first line of the above paragraph. I've not reflowed anything. I'd guess your client is doing the wrapping (this is fairly standard for GUI clients).
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
What is the reason to use regmap besides caching?
There's the other reasons I mentioned in the message you're replying to for a start...
That didn't show how it helps w1, so was the question.
I'm not clear why any of these benefits would be less applicable to w1 than to other buses.
Mark Brown
maintainerRe: [PATCH 1/4] Introduce regmap infrastructure over Maxim/Dalas OneWire (W1) bus
In reply to a message not in the archiveQuoted 4 lines · Evgeniy Polyakov
In fact, regmap-w1 brings virtually nothing to w1 from regmap point fo view - code is more complex and even a bit more error prone, but we found a nice feature, that we do not have to export IO functions anymore, they will be hidden behind regmap wrappers.
It's not for the benefit of the bus, it's for the benefit of the devices on the bus and their subsystems. From the point of view of the subsystem it shouldn't have any impact at all, it's a helper library for the layers above.