Skip to contentSkip to conversation

Add battery charger driver support for MP2629

PATCH Superseded Saravanan Sekar 5 participants 33 messages Mar 22, 2020 – Apr 8, 2020

Subsystems (5)

v4 of 12 Superseded Latest is v12 →

lore
Share & tools
lore

Saravanan Sekar

author maintainer
#0 lore raw

v4 cover Add battery charger driver support for MP2629

changes in v4:
- fixed capitalization in mfg Kconfig and documentation

changes in v3:
- regmap for children passed using platform data and remove mfd driver info access directly from children

changes in v2:
- removed EXPORT_SYMBOL of register set/get helper
- regmap bit filed used, fixed other review comments

This patch series add support for Battery charger control driver for Monolithic Power System's MP2629 chipset, includes MFD driver for ADC battery & input power supply measurement and battery charger control driver.

Thanks,
Saravanan

Saravanan Sekar (5):
dt-bindings: mfd: add document bindings for mp2629
mfd: mp2629: Add support for mps battery charger
iio: adc: mp2629: Add support for mp2629 ADC driver
power: supply: Add support for mps mp2629 battery charger
MAINTAINERS: Add entry for mp2629 Battery Charger driver

 .../devicetree/bindings/mfd/mps,mp2629.yaml   |  60 ++
 MAINTAINERS                                   |   5 +
 drivers/iio/adc/Kconfig                       |  10 +
 drivers/iio/adc/Makefile                      |   1 +
 drivers/iio/adc/mp2629_adc.c                  | 214 ++++++
 drivers/mfd/Kconfig                           |   9 +
 drivers/mfd/Makefile                          |   2 +
 drivers/mfd/mp2629.c                          | 116 +++
 drivers/power/supply/Kconfig                  |  10 +
 drivers/power/supply/Makefile                 |   1 +
 drivers/power/supply/mp2629_charger.c         | 697 ++++++++++++++++++
 include/linux/mfd/mp2629.h                    |  31 +
 12 files changed, 1156 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/mps,mp2629.yaml
 create mode 100644 drivers/iio/adc/mp2629_adc.c
 create mode 100644 drivers/mfd/mp2629.c
 create mode 100644 drivers/power/supply/mp2629_charger.c
 create mode 100644 include/linux/mfd/mp2629.h
Signature · 1 line
2.17.1
author maintainer
#1 lore raw

PATCH v4 1/5 dt-bindings: mfd: add document bindings for mp2629

Add device tree binding information for mp2629 mfd driver.

---
 .../devicetree/bindings/mfd/mps,mp2629.yaml   | 60 +++++++++++++++++++
 1 file changed, 60 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/mps,mp2629.yaml
Documentation/devicetree/bindings/mfd/mps,mp2629.yaml new file +60 -0
new file mode 100644
index 000000000000..314309ea91ac
@@ -0,0 +1,60 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/mps,mp2629.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: MP2629 Battery Charger PMIC from Monolithic Power System.
+
+maintainers:
+  - Saravanan Sekar <[email protected]>
+
+description: |
+  MP2629 is an PMIC providing battery charging and power supply for smartphones,
+  wireless camera and portable devices. Chip is contrlled over I2C.
+
+  The MFD device handles battery charger controller and ADC IIO device for
+  battery, system voltage
+
+properties:
+  compatible:
+    const: mps,mp2629
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  interrupt-controller: true
+
+  "#interrupt-cells":
+    const: 2
+    description:
+      The first cell is the IRQ number, the second cell is the trigger type.
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - interrupt-controller
+  - "#interrupt-cells"
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/input/linux-event-codes.h>
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        pmic@4b {
+            compatible = "mps,mp2629";
+            reg = <0x4b>;
+
+            interrupt-controller;
+            interrupt-parent = <&gpio2>;
+            #interrupt-cells = <2>;
+            interrupts = <3 IRQ_TYPE_LEVEL_HIGH>;
+        };
+    };
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH v4 1/5] dt-bindings: mfd: add document bindings for mp2629

Quoted 14 lines · Saravanan Sekar

Add device tree binding information for mp2629 mfd driver.

---
 .../devicetree/bindings/mfd/mps,mp2629.yaml   | 60 +++++++++++++++++++
 1 file changed, 60 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/mps,mp2629.yaml
Documentation/devicetree/bindings/mfd/mps,mp2629.yaml new file +0 -0
new file mode 100644
index 000000000000..314309ea91ac

Documentation/devicetree/bindings/mfd/mps,mp2629.yaml line 5

Quoted 5 lines
Documentation/devicetree/bindings/mfd/mps,mp2629.yaml new file +5 -0
@@ -0,0 +1,60 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/mps,mp2629.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#

Are these links supposed to work?

Documentation/devicetree/bindings/mfd/mps,mp2629.yaml line 13

Quoted 7 lines
Documentation/devicetree/bindings/mfd/mps,mp2629.yaml new file +7 -0
+title: MP2629 Battery Charger PMIC from Monolithic Power System.
+
+maintainers:
+  - Saravanan Sekar <[email protected]>
+
+description: |
+  MP2629 is an PMIC providing battery charging and power supply for smartphones,

s/an/a/

Documentation/devicetree/bindings/mfd/mps,mp2629.yaml line 14

Quoted 1 line
Documentation/devicetree/bindings/mfd/mps,mp2629.yaml new file +1 -0
+  wireless camera and portable devices. Chip is contrlled over I2C.

Spell check!

Documentation/devicetree/bindings/mfd/mps,mp2629.yaml line 17

Quoted 2 lines
Documentation/devicetree/bindings/mfd/mps,mp2629.yaml new file +2 -0
+  The MFD device handles battery charger controller and ADC IIO device for
+  battery, system voltage

MFD isn't a thing. We made it up. Please describe it as it is in the datasheet.

Quoted 19 lines
Documentation/devicetree/bindings/mfd/mps,mp2629.yaml new file +19 -0
+properties:
+  compatible:
+    const: mps,mp2629
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  interrupt-controller: true
+
+  "#interrupt-cells":
+    const: 2
+    description:
+      The first cell is the IRQ number, the second cell is the trigger type.
+
+required:
+  - compatible

Documentation/devicetree/bindings/mfd/mps,mp2629.yaml line 47

Quoted 10 lines
Documentation/devicetree/bindings/mfd/mps,mp2629.yaml new file +10 -0
+  - reg
+  - interrupts
+  - interrupt-controller
+  - "#interrupt-cells"
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/input/linux-event-codes.h>
+    i2c {

i2c@0x????????

Quoted 13 lines
Documentation/devicetree/bindings/mfd/mps,mp2629.yaml new file +13 -0
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        pmic@4b {
+            compatible = "mps,mp2629";
+            reg = <0x4b>;
+
+            interrupt-controller;
+            interrupt-parent = <&gpio2>;
+            #interrupt-cells = <2>;
+            interrupts = <3 IRQ_TYPE_LEVEL_HIGH>;
+        };
+    };
Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
author maintainer
#3 lore raw

Re: [PATCH v4 1/5] dt-bindings: mfd: add document bindings for mp2629

Hi Lee,

Quoted 10 lines · Lee Jones
Quoted 8 lines · Saravanan Sekar

Add device tree binding information for mp2629 mfd driver.

---
  .../devicetree/bindings/mfd/mps,mp2629.yaml   | 60 +++++++++++++++++++
  1 file changed, 60 insertions(+)

create mode 100644 Documentation/devicetree/bindings/mfd/mps,mp2629.yaml

Quoted 12 lines

Documentation/devicetree/bindings/mfd/mps,mp2629.yaml line 5

Quoted 11 lines
Documentation/devicetree/bindings/mfd/mps,mp2629.yaml new file +5 -0
new file mode 100644
index 000000000000..314309ea91ac
@@ -0,0 +1,60 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/mps,mp2629.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#

Are these links supposed to work?

Not really, but as far my understanding needed for dt-bindings check

Quoted 38 lines

Documentation/devicetree/bindings/mfd/mps,mp2629.yaml line 13

Quoted 7 lines
Documentation/devicetree/bindings/mfd/mps,mp2629.yaml new file +7 -0
+title: MP2629 Battery Charger PMIC from Monolithic Power System.
+
+maintainers:
+  - Saravanan Sekar <[email protected]>
+
+description: |
+  MP2629 is an PMIC providing battery charging and power supply for smartphones,

s/an/a/

Documentation/devicetree/bindings/mfd/mps,mp2629.yaml line 14

Quoted 1 line
Documentation/devicetree/bindings/mfd/mps,mp2629.yaml new file +1 -0
+  wireless camera and portable devices. Chip is contrlled over I2C.

Spell check!

Documentation/devicetree/bindings/mfd/mps,mp2629.yaml line 17

Quoted 2 lines
Documentation/devicetree/bindings/mfd/mps,mp2629.yaml new file +2 -0
+  The MFD device handles battery charger controller and ADC IIO device for
+  battery, system voltage

MFD isn't a thing. We made it up. Please describe it as it is in the datasheet.

Quoted 22 lines
Documentation/devicetree/bindings/mfd/mps,mp2629.yaml new file +22 -0
+properties:
+  compatible:
+    const: mps,mp2629
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  interrupt-controller: true
+
+  "#interrupt-cells":
+    const: 2
+    description:
+      The first cell is the IRQ number, the second cell is the trigger type.
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - interrupt-controller
Quoted 8 lines

Documentation/devicetree/bindings/mfd/mps,mp2629.yaml line 47

Quoted 7 lines
Documentation/devicetree/bindings/mfd/mps,mp2629.yaml new file +7 -0
+  - "#interrupt-cells"
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/input/linux-event-codes.h>
+    i2c {

i2c@0x????????

Its a I2C controller node, I don't think address is needed. Mention like this my previous other driver patches,

dt_binding_check is also passed

Quoted 13 lines
Quoted 13 lines
Documentation/devicetree/bindings/mfd/mps,mp2629.yaml new file +13 -0
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        pmic@4b {
+            compatible = "mps,mp2629";
+            reg = <0x4b>;
+
+            interrupt-controller;
+            interrupt-parent = <&gpio2>;
+            #interrupt-cells = <2>;
+            interrupts = <3 IRQ_TYPE_LEVEL_HIGH>;
+        };
+    };
#4 lore raw

Re: [PATCH v4 1/5] dt-bindings: mfd: add document bindings for mp2629

Quoted 23 lines · saravanan sekar
Quoted 10 lines · Lee Jones
Quoted 8 lines · Saravanan Sekar

Add device tree binding information for mp2629 mfd driver.

---
  .../devicetree/bindings/mfd/mps,mp2629.yaml   | 60 +++++++++++++++++++
  1 file changed, 60 insertions(+)

create mode 100644 Documentation/devicetree/bindings/mfd/mps,mp2629.yaml

Quoted 12 lines

Documentation/devicetree/bindings/mfd/mps,mp2629.yaml line 5

Quoted 11 lines
Documentation/devicetree/bindings/mfd/mps,mp2629.yaml new file +5 -0
new file mode 100644
index 000000000000..314309ea91ac
@@ -0,0 +1,60 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/mps,mp2629.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#

Are these links supposed to work?

Quoted 1 line

Not really, but as far my understanding needed for dt-bindings check

Rob, why are these here if they just result in 404s?

Quoted 9 lines
Quoted 6 lines

Documentation/devicetree/bindings/mfd/mps,mp2629.yaml line 47

Quoted 5 lines
Documentation/devicetree/bindings/mfd/mps,mp2629.yaml new file +5 -0
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/input/linux-event-codes.h>
+    i2c {

i2c@0x????????

Its a I2C controller node, I don't think address is needed. Mention like this my previous other driver patches,

This doesn't sound right.

How do you control/operate the controller?

Surely you read/write from/to registers?

Quoted 15 lines

dt_binding_check is also passed

Quoted 13 lines
Quoted 13 lines
Documentation/devicetree/bindings/mfd/mps,mp2629.yaml new file +13 -0
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        pmic@4b {
+            compatible = "mps,mp2629";
+            reg = <0x4b>;
+
+            interrupt-controller;
+            interrupt-parent = <&gpio2>;
+            #interrupt-cells = <2>;
+            interrupts = <3 IRQ_TYPE_LEVEL_HIGH>;
+        };
+    };
Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
author maintainer
#5 lore raw

Re: [PATCH v4 1/5] dt-bindings: mfd: add document bindings for mp2629

Hi Lee,

Quoted 32 lines · Lee Jones
Quoted 23 lines · saravanan sekar
Quoted 10 lines · Lee Jones
Quoted 8 lines · Saravanan Sekar

Add device tree binding information for mp2629 mfd driver.

---
   .../devicetree/bindings/mfd/mps,mp2629.yaml   | 60 +++++++++++++++++++
   1 file changed, 60 insertions(+)

create mode 100644 Documentation/devicetree/bindings/mfd/mps,mp2629.yaml

Quoted 12 lines

Documentation/devicetree/bindings/mfd/mps,mp2629.yaml line 5

Quoted 11 lines
Documentation/devicetree/bindings/mfd/mps,mp2629.yaml new file +5 -0
new file mode 100644
index 000000000000..314309ea91ac
@@ -0,0 +1,60 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/mps,mp2629.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#

Are these links supposed to work?

Quoted 1 line

Not really, but as far my understanding needed for dt-bindings check

Rob, why are these here if they just result in 404s?

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Documentation/devicetree/bindings/mfd/mps,mp2629.yaml new file +5 -0
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/input/linux-event-codes.h>
+    i2c {
Quoted 8 lines
Quoted 3 lines
Quoted 1 line

i2c@0x????????

Its a I2C controller node, I don't think address is needed. Mention like this my previous other driver patches,

This doesn't sound right.

How do you control/operate the controller?

Surely you read/write from/to registers?

Indeed, but each SoC will have different address so which address to mention here.
For me it should be like &i2c {}, anyhow I respect maintainers review (I can give RPi I2c bus address used for testing) and wait for Rob's reply

Quoted 16 lines
Quoted 16 lines

dt_binding_check is also passed

Quoted 13 lines
Quoted 13 lines
Documentation/devicetree/bindings/mfd/mps,mp2629.yaml new file +13 -0
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        pmic@4b {
+            compatible = "mps,mp2629";
+            reg = <0x4b>;
+
+            interrupt-controller;
+            interrupt-parent = <&gpio2>;
+            #interrupt-cells = <2>;
+            interrupts = <3 IRQ_TYPE_LEVEL_HIGH>;
+        };
+    };
#6 lore raw

Re: [PATCH v4 1/5] dt-bindings: mfd: add document bindings for mp2629

Quoted 42 lines · saravanan sekar

Hi Lee,

Quoted 39 lines · Lee Jones
Quoted 23 lines · saravanan sekar
Quoted 10 lines · Lee Jones
Quoted 8 lines · Saravanan Sekar

Add device tree binding information for mp2629 mfd driver.

---
   .../devicetree/bindings/mfd/mps,mp2629.yaml   | 60 +++++++++++++++++++
   1 file changed, 60 insertions(+)

create mode 100644 Documentation/devicetree/bindings/mfd/mps,mp2629.yaml

Quoted 12 lines

Documentation/devicetree/bindings/mfd/mps,mp2629.yaml line 5

Quoted 11 lines
Documentation/devicetree/bindings/mfd/mps,mp2629.yaml new file +5 -0
new file mode 100644
index 000000000000..314309ea91ac
@@ -0,0 +1,60 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/mps,mp2629.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#

Are these links supposed to work?

Quoted 1 line

Not really, but as far my understanding needed for dt-bindings check

Rob, why are these here if they just result in 404s?

Quoted 8 lines
Quoted 6 lines

Documentation/devicetree/bindings/mfd/mps,mp2629.yaml line 47

Quoted 5 lines
Documentation/devicetree/bindings/mfd/mps,mp2629.yaml new file +5 -0
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/input/linux-event-codes.h>
+    i2c {

i2c@0x????????

Its a I2C controller node, I don't think address is needed. Mention like this my previous other driver patches,

This doesn't sound right.

How do you control/operate the controller?

Quoted 8 lines
Quoted 1 line

Surely you read/write from/to registers?

Indeed, but each SoC will have different address so which address to mention here.
For me it should be like &i2c {}, anyhow I respect maintainers review (I can give RPi I2c bus address used for testing)
and wait for Rob's reply

It's only an example. It doesn't have to match any real H/W.

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines

dt_binding_check is also passed

Quoted 13 lines
Quoted 13 lines
Documentation/devicetree/bindings/mfd/mps,mp2629.yaml new file +13 -0
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        pmic@4b {
+            compatible = "mps,mp2629";
+            reg = <0x4b>;
+
+            interrupt-controller;
+            interrupt-parent = <&gpio2>;
+            #interrupt-cells = <2>;
+            interrupts = <3 IRQ_TYPE_LEVEL_HIGH>;
+        };
+    };
Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
author maintainer
#7 lore raw

PATCH v4 2/5 mfd: mp2629: Add support for mps battery charger

In reply to Saravanan Sekar

mp2629 is a highly-integrated switching-mode battery charge management device for single-cell Li-ion or Li-polymer battery.

Add MFD core enables chip access for ADC driver for battery readings, and a power supply battery-charger driver

---
 drivers/mfd/Kconfig        |   9 +++
 drivers/mfd/Makefile       |   2 +
 drivers/mfd/mp2629.c       | 116 +++++++++++++++++++++++++++++++++++++
 include/linux/mfd/mp2629.h |  22 +++++++
 4 files changed, 149 insertions(+)
 create mode 100644 drivers/mfd/mp2629.c
 create mode 100644 include/linux/mfd/mp2629.h
drivers/mfd/Kconfig +9 -0
index 3c547ed575e6..6614e5cff881 100644
@@ -434,6 +434,15 @@ config MFD_MC13XXX_I2C
 	help
 	  Select this if your MC13xxx is connected via an I2C bus.
 
+config MFD_MP2629
+	bool "Monolithic power system MP2629 ADC and Battery charger"
+	depends on I2C
+	select REGMAP_I2C
+	help
+	  Select this option to enable support for monolithic power system
+	  battery charger. This provides ADC, thermal, battery charger power
+	  management functions on the systems.
+
 config MFD_MXS_LRADC
 	tristate "Freescale i.MX23/i.MX28 LRADC"
 	depends on ARCH_MXS || COMPILE_TEST
drivers/mfd/Makefile +2 -0
index f935d10cbf0f..d6c210f96d02 100644
@@ -170,6 +170,8 @@ obj-$(CONFIG_MFD_MAX8925)	+= max8925.o
 obj-$(CONFIG_MFD_MAX8997)	+= max8997.o max8997-irq.o
 obj-$(CONFIG_MFD_MAX8998)	+= max8998.o max8998-irq.o
 
+obj-$(CONFIG_MFD_MP2629)	+= mp2629.o
+
 pcf50633-objs			:= pcf50633-core.o pcf50633-irq.o
 obj-$(CONFIG_MFD_PCF50633)	+= pcf50633.o
 obj-$(CONFIG_PCF50633_ADC)	+= pcf50633-adc.o
drivers/mfd/mp2629.c new file +116 -0

116 lines not on this page · raw message

include/linux/mfd/mp2629.h new file +22 -0
new file mode 100644
index 000000000000..371e44330ba8
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * mp2629.h  - register definitions for mp2629 charger
+ *
+ * Copyright 2020 Monolithic Power Systems, Inc
+ *
+ */
+
+#ifndef __MP2629_H__
+#define __MP2629_H__
+
+#include <linux/types.h>
+
+struct device;
+struct regmap;
+
+struct mp2629_info {
+	struct device *dev;
+	struct regmap *regmap;
+};
+
+#endif
Signature · 1 line
2.17.1
#8 lore raw

Re: [PATCH v4 2/5] mfd: mp2629: Add support for mps battery charger

I love your patch! Yet something to improve:

Hi Saravanan,

I love your patch! Yet something to improve:

[auto build test ERROR on next-20200320]
[also build test ERROR on v5.6-rc7]
[cannot apply to ljones-mfd/for-mfd-next iio/togreg power-supply/for-next v5.6-rc6 v5.6-rc5 v5.6-rc4] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Saravanan-Sekar/Add-battery-charger-driver-support-for-MP2629/20200323-064940
base:    d8f289c16fbb72e17b783175c1fb0942816264fd
config: sh-allmodconfig (attached as .config)
compiler: sh4-linux-gcc (GCC) 9.2.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=9.2.0 make.cross ARCH=sh

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

sh4-linux-ld: drivers/mfd/mp2629.o: in function `mp2629_probe':
mp2629.c:(.text+0xdc): undefined reference to `__devm_regmap_init_i2c'
sh4-linux-ld: drivers/mfd/mp2629.o: in function `mp2629_driver_init':
mp2629.c:(.init.text+0x28): undefined reference to `i2c_register_driver'
sh4-linux-ld: drivers/mfd/mp2629.o: in function `mp2629_driver_exit':

>> mp2629.c:(.exit.text+0x18): undefined reference to `i2c_del_driver'

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#9 lore raw

Re: [PATCH v4 2/5] mfd: mp2629: Add support for mps battery charger

In reply to Saravanan Sekar
I love your patch! Yet something to improve:

Hi Saravanan,

I love your patch! Yet something to improve:

[auto build test ERROR on next-20200320]
[also build test ERROR on v5.6-rc7]
[cannot apply to ljones-mfd/for-mfd-next iio/togreg power-supply/for-next v5.6-rc6 v5.6-rc5 v5.6-rc4] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Saravanan-Sekar/Add-battery-charger-driver-support-for-MP2629/20200323-064940
base:    d8f289c16fbb72e17b783175c1fb0942816264fd
config: m68k-allmodconfig (attached as .config)
compiler: m68k-linux-gcc (GCC) 9.2.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=9.2.0 make.cross ARCH=m68k

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

m68k-linux-ld: drivers/mfd/mp2629.o: in function `mp2629_probe':

>> mp2629.c:(.text+0x40): undefined reference to `__devm_regmap_init_i2c'
   m68k-linux-ld: drivers/mfd/mp2629.o: in function `mp2629_driver_init':
>> mp2629.c:(.init.text+0xe): undefined reference to `i2c_register_driver'

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#10 lore raw

Re: [PATCH v4 2/5] mfd: mp2629: Add support for mps battery charger

In reply to Saravanan Sekar
Quoted 55 lines · Saravanan Sekar

mp2629 is a highly-integrated switching-mode battery charge management device for single-cell Li-ion or Li-polymer battery.

Add MFD core enables chip access for ADC driver for battery readings, and a power supply battery-charger driver

---
 drivers/mfd/Kconfig        |   9 +++
 drivers/mfd/Makefile       |   2 +
 drivers/mfd/mp2629.c       | 116 +++++++++++++++++++++++++++++++++++++
 include/linux/mfd/mp2629.h |  22 +++++++
 4 files changed, 149 insertions(+)
 create mode 100644 drivers/mfd/mp2629.c
 create mode 100644 include/linux/mfd/mp2629.h
drivers/mfd/Kconfig +9 -0
index 3c547ed575e6..6614e5cff881 100644
@@ -434,6 +434,15 @@ config MFD_MC13XXX_I2C
 	help
 	  Select this if your MC13xxx is connected via an I2C bus.
 
+config MFD_MP2629
+	bool "Monolithic power system MP2629 ADC and Battery charger"
+	depends on I2C
+	select REGMAP_I2C
+	help
+	  Select this option to enable support for monolithic power system
+	  battery charger. This provides ADC, thermal, battery charger power
+	  management functions on the systems.
+
 config MFD_MXS_LRADC
 	tristate "Freescale i.MX23/i.MX28 LRADC"
 	depends on ARCH_MXS || COMPILE_TEST
drivers/mfd/Makefile +2 -0
index f935d10cbf0f..d6c210f96d02 100644
@@ -170,6 +170,8 @@ obj-$(CONFIG_MFD_MAX8925)	+= max8925.o
 obj-$(CONFIG_MFD_MAX8997)	+= max8997.o max8997-irq.o
 obj-$(CONFIG_MFD_MAX8998)	+= max8998.o max8998-irq.o
 
+obj-$(CONFIG_MFD_MP2629)	+= mp2629.o
+
 pcf50633-objs			:= pcf50633-core.o pcf50633-irq.o
 obj-$(CONFIG_MFD_PCF50633)	+= pcf50633.o
 obj-$(CONFIG_PCF50633_ADC)	+= pcf50633-adc.o
drivers/mfd/mp2629.c new file +0 -0
new file mode 100644
index 000000000000..41a4082387ce

drivers/mfd/mp2629.c line 3

Quoted 3 lines
drivers/mfd/mp2629.c new file +3 -0
@@ -0,0 +1,116 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * MP2629 MFD Driver for ADC and battery charger

s/MFD Driver/parent driver/

Quoted 5 lines
drivers/mfd/mp2629.c new file +5 -0
+ * Copyright 2020 Monolithic Power Systems, Inc
+ *
+ * Author: Saravanan Sekar <[email protected]>
+ */
+

drivers/mfd/mp2629.c line 19

Quoted 10 lines
drivers/mfd/mp2629.c new file +10 -0
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/i2c.h>
+#include <linux/regmap.h>
+#include <linux/slab.h>
+#include <linux/irq.h>
+#include <linux/interrupt.h>
+#include <linux/mfd/core.h>
+#include <linux/mfd/mp2629.h>

Alphabetical please.

Quoted 24 lines
drivers/mfd/mp2629.c new file +24 -0
+enum {
+	MP2629_MFD_ADC,
+	MP2629_MFD_CHARGER,
+	MP2629_MFD_MAX
+};
+
+static struct resource mp2629_irq_rsrc[] = {
+	{
+		.flags = IORESOURCE_IRQ,
+	},
+};
+
+static struct mfd_cell mp2629mfd[] = {
+	[MP2629_MFD_ADC] = {
+		.name = "mp2629_adc",
+		.of_compatible = "mps,mp2629_adc",
+	},
+	[MP2629_MFD_CHARGER] = {
+		.name = "mp2629_charger",
+		.of_compatible = "mps,mp2629_charger",
+		.resources = mp2629_irq_rsrc,
+		.num_resources = ARRAY_SIZE(mp2629_irq_rsrc),
+	}
+};

drivers/mfd/mp2629.c line 54

Quoted 10 lines
drivers/mfd/mp2629.c new file +10 -0
+
+static const struct regmap_config mp2629_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.max_register = 0x17,
+};
+
+static int mp2629_probe(struct i2c_client *client)
+{
+	struct mp2629_info *info;

All this ddata instead of info.

Quoted 10 lines
drivers/mfd/mp2629.c new file +10 -0
+	struct resource	*resources;
+	int ret;
+	int i;
+
+	info = devm_kzalloc(&client->dev, sizeof(*info), GFP_KERNEL);
+	if (!info)
+		return -ENOMEM;
+
+	info->dev = &client->dev;
+	i2c_set_clientdata(client, info);

drivers/mfd/mp2629.c line 74

Quoted 10 lines
drivers/mfd/mp2629.c new file +10 -0
+
+	info->regmap = devm_regmap_init_i2c(client, &mp2629_regmap_config);
+	if (IS_ERR(info->regmap)) {
+		dev_err(info->dev, "Failed to allocate regmap!\n");
+		return PTR_ERR(info->regmap);
+	}
+
+	for (i = 0; i < MP2629_MFD_MAX; i++) {
+		mp2629mfd[i].platform_data = &info->regmap;
+		mp2629mfd[i].pdata_size = sizeof(info->regmap);

You don't need to store this in platform data as well.

You already have it in device data (ddata [currently 'info']).

drivers/mfd/mp2629.c line 80

Quoted 5 lines
drivers/mfd/mp2629.c new file +5 -0
+		resources = (struct resource *)mp2629mfd[i].resources;
+		if (resources) {
+			resources[0].start = client->irq;
+			resources[0].end = client->irq;
+		}

You don't need to store this separately either.

Just fetch it from the parent in the child device driver.

It will look something like (untested, off the top of my head):

  platform_get_irq(to_platform_device(pdev->dev.parent), 0);

drivers/mfd/mp2629.c line 87

Quoted 7 lines
drivers/mfd/mp2629.c new file +7 -0
+	}
+
+	ret = devm_mfd_add_devices(info->dev, PLATFORM_DEVID_NONE, mp2629mfd,
+				ARRAY_SIZE(mp2629mfd), NULL,
+				0, NULL);
+	if (ret)
+		dev_err(info->dev, "Failed to add mfd %d\n", ret);

"Failed to register sub-devices"

Quoted 4 lines
drivers/mfd/mp2629.c new file +4 -0
+	return ret;
+}
+
+static const struct of_device_id mp2629_of_match[] = {

drivers/mfd/mp2629.c line 102

Quoted 10 lines
drivers/mfd/mp2629.c new file +10 -0
+	{ .compatible = "mps,mp2629"},
+	{ }
+};
+MODULE_DEVICE_TABLE(of, mp2629_of_match);
+
+static const struct i2c_device_id mp2629_id[] = {
+	{ "mp2629", },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, mp2629_id);

You're already using .probe_new - this can be removed.

drivers/mfd/mp2629.c line 115

Quoted 12 lines
drivers/mfd/mp2629.c new file +12 -0
+static struct i2c_driver mp2629_driver = {
+	.driver = {
+		.name = "mp2629",
+		.of_match_table = mp2629_of_match,
+	},
+	.probe_new	= mp2629_probe,
+	.id_table	= mp2629_id,
+};
+module_i2c_driver(mp2629_driver);
+
+MODULE_AUTHOR("Saravanan Sekar <[email protected]>");
+MODULE_DESCRIPTION("MP2629 Battery charger mfd driver");

"parent driver"

include/linux/mfd/mp2629.h line 3

Quoted 10 lines
drivers/mfd/mp2629.c new file +1 -0
+MODULE_LICENSE("GPL");
include/linux/mfd/mp2629.h new file +3 -0
new file mode 100644
index 000000000000..371e44330ba8
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * mp2629.h  - register definitions for mp2629 charger

Remove the filename.

s/mp2629/MP2629/

include/linux/mfd/mp2629.h line 5

Quoted 2 lines
include/linux/mfd/mp2629.h new file +2 -0
+ * Copyright 2020 Monolithic Power Systems, Inc
+ *

Superfluous '\n'.

include/linux/mfd/mp2629.h line 15

Quoted 9 lines
include/linux/mfd/mp2629.h new file +9 -0
+ */
+
+#ifndef __MP2629_H__
+#define __MP2629_H__
+
+#include <linux/types.h>
+
+struct device;
+struct regmap;

Why not just add the includes?

Quoted 6 lines
include/linux/mfd/mp2629.h new file +6 -0
+struct mp2629_info {
+	struct device *dev;
+	struct regmap *regmap;
+};
+
+#endif
Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
author maintainer
#11 lore raw

Re: [PATCH v4 2/5] mfd: mp2629: Add support for mps battery charger

Hi Lee,

Quoted 106 lines · Lee Jones
Quoted 55 lines · Saravanan Sekar

mp2629 is a highly-integrated switching-mode battery charge management device for single-cell Li-ion or Li-polymer battery.

Add MFD core enables chip access for ADC driver for battery readings, and a power supply battery-charger driver

---
  drivers/mfd/Kconfig        |   9 +++
  drivers/mfd/Makefile       |   2 +
  drivers/mfd/mp2629.c       | 116 +++++++++++++++++++++++++++++++++++++
  include/linux/mfd/mp2629.h |  22 +++++++
  4 files changed, 149 insertions(+)

create mode 100644 drivers/mfd/mp2629.c
create mode 100644 include/linux/mfd/mp2629.h

drivers/mfd/Kconfig +9 -0
index 3c547ed575e6..6614e5cff881 100644
@@ -434,6 +434,15 @@ config MFD_MC13XXX_I2C
  	help
  	  Select this if your MC13xxx is connected via an I2C bus.
 
+config MFD_MP2629
+	bool "Monolithic power system MP2629 ADC and Battery charger"
+	depends on I2C
+	select REGMAP_I2C
+	help
+	  Select this option to enable support for monolithic power system
+	  battery charger. This provides ADC, thermal, battery charger power
+	  management functions on the systems.
+
  config MFD_MXS_LRADC
  	tristate "Freescale i.MX23/i.MX28 LRADC"
  	depends on ARCH_MXS || COMPILE_TEST
drivers/mfd/Makefile +2 -0
index f935d10cbf0f..d6c210f96d02 100644
@@ -170,6 +170,8 @@ obj-$(CONFIG_MFD_MAX8925)	+= max8925.o
  obj-$(CONFIG_MFD_MAX8997)	+= max8997.o max8997-irq.o
  obj-$(CONFIG_MFD_MAX8998)	+= max8998.o max8998-irq.o
 
+obj-$(CONFIG_MFD_MP2629)	+= mp2629.o
+
  pcf50633-objs			:= pcf50633-core.o pcf50633-irq.o
  obj-$(CONFIG_MFD_PCF50633)	+= pcf50633.o
  obj-$(CONFIG_PCF50633_ADC)	+= pcf50633-adc.o
drivers/mfd/mp2629.c new file +0 -0
new file mode 100644
index 000000000000..41a4082387ce

drivers/mfd/mp2629.c line 3

Quoted 3 lines
drivers/mfd/mp2629.c new file +3 -0
@@ -0,0 +1,116 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * MP2629 MFD Driver for ADC and battery charger

s/MFD Driver/parent driver/

Quoted 5 lines
drivers/mfd/mp2629.c new file +5 -0
+ * Copyright 2020 Monolithic Power Systems, Inc
+ *
+ * Author: Saravanan Sekar <[email protected]>
+ */
+

drivers/mfd/mp2629.c line 19

Quoted 10 lines
drivers/mfd/mp2629.c new file +10 -0
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/i2c.h>
+#include <linux/regmap.h>
+#include <linux/slab.h>
+#include <linux/irq.h>
+#include <linux/interrupt.h>
+#include <linux/mfd/core.h>
+#include <linux/mfd/mp2629.h>

Alphabetical please.

Quoted 27 lines
drivers/mfd/mp2629.c new file +27 -0
+enum {
+	MP2629_MFD_ADC,
+	MP2629_MFD_CHARGER,
+	MP2629_MFD_MAX
+};
+
+static struct resource mp2629_irq_rsrc[] = {
+	{
+		.flags = IORESOURCE_IRQ,
+	},
+};
+
+static struct mfd_cell mp2629mfd[] = {
+	[MP2629_MFD_ADC] = {
+		.name = "mp2629_adc",
+		.of_compatible = "mps,mp2629_adc",
+	},
+	[MP2629_MFD_CHARGER] = {
+		.name = "mp2629_charger",
+		.of_compatible = "mps,mp2629_charger",
+		.resources = mp2629_irq_rsrc,
+		.num_resources = ARRAY_SIZE(mp2629_irq_rsrc),
+	}
+};
+
+static const struct regmap_config mp2629_regmap_config = {
+	.reg_bits = 8,
Quoted 8 lines

drivers/mfd/mp2629.c line 54

Quoted 7 lines
drivers/mfd/mp2629.c new file +7 -0
+	.val_bits = 8,
+	.max_register = 0x17,
+};
+
+static int mp2629_probe(struct i2c_client *client)
+{
+	struct mp2629_info *info;

All this ddata instead of info.

Not sure the reason, I will do.

Quoted 23 lines
Quoted 11 lines
drivers/mfd/mp2629.c new file +10 -0
+	struct resource	*resources;
+	int ret;
+	int i;
+
+	info = devm_kzalloc(&client->dev, sizeof(*info), GFP_KERNEL);
+	if (!info)
+		return -ENOMEM;
+
+	info->dev = &client->dev;
+	i2c_set_clientdata(client, info);

drivers/mfd/mp2629.c line 74

Quoted 10 lines
drivers/mfd/mp2629.c new file +10 -0
+
+	info->regmap = devm_regmap_init_i2c(client, &mp2629_regmap_config);
+	if (IS_ERR(info->regmap)) {
+		dev_err(info->dev, "Failed to allocate regmap!\n");
+		return PTR_ERR(info->regmap);
+	}
+
+	for (i = 0; i < MP2629_MFD_MAX; i++) {
+		mp2629mfd[i].platform_data = &info->regmap;
+		mp2629mfd[i].pdata_size = sizeof(info->regmap);

You don't need to store this in platform data as well.

Quoted 1 line

You already have it in device data (ddata [currently 'info']).

"The IIO parts seems fine (minor comments inline) but I'm not keep on directly accessing the internals of the mfd device info structure. To my mind that should be opaque to the child drivers so as to provide clear structure to any such accesses.

This mess in layering with the children directly using the parents regmap is a little concerning. It means that the 3 drivers really aren't very well separated and can't really be reviewed independently (not a good thing)."

This is the review comments form Jonathan on V2, not to access parent data structure directly. Am I misunderstood his review comments? please suggest the better option to follow as like in V2 or V2 + some improvements or V4 + improvements?

Quoted 7 lines

drivers/mfd/mp2629.c line 80

Quoted 5 lines
drivers/mfd/mp2629.c new file +5 -0
+		resources = (struct resource *)mp2629mfd[i].resources;
+		if (resources) {
+			resources[0].start = client->irq;
+			resources[0].end = client->irq;
+		}

You don't need to store this separately either.

Quoted 5 lines

Just fetch it from the parent in the child device driver.

It will look something like (untested, off the top of my head):

   platform_get_irq(to_platform_device(pdev->dev.parent), 0);

I have tested child got irq number correctly. Ok I will change it

Quoted 58 lines

drivers/mfd/mp2629.c line 87

Quoted 8 lines
drivers/mfd/mp2629.c new file +7 -0
+	}
+
+	ret = devm_mfd_add_devices(info->dev, PLATFORM_DEVID_NONE, mp2629mfd,
+				ARRAY_SIZE(mp2629mfd), NULL,
+				0, NULL);
+	if (ret)
+		dev_err(info->dev, "Failed to add mfd %d\n", ret);

"Failed to register sub-devices"

Quoted 4 lines
drivers/mfd/mp2629.c new file +4 -0
+	return ret;
+}
+
+static const struct of_device_id mp2629_of_match[] = {

drivers/mfd/mp2629.c line 102

Quoted 10 lines
drivers/mfd/mp2629.c new file +10 -0
+	{ .compatible = "mps,mp2629"},
+	{ }
+};
+MODULE_DEVICE_TABLE(of, mp2629_of_match);
+
+static const struct i2c_device_id mp2629_id[] = {
+	{ "mp2629", },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, mp2629_id);

You're already using .probe_new - this can be removed.

drivers/mfd/mp2629.c line 115

Quoted 12 lines
drivers/mfd/mp2629.c new file +12 -0
+static struct i2c_driver mp2629_driver = {
+	.driver = {
+		.name = "mp2629",
+		.of_match_table = mp2629_of_match,
+	},
+	.probe_new	= mp2629_probe,
+	.id_table	= mp2629_id,
+};
+module_i2c_driver(mp2629_driver);
+
+MODULE_AUTHOR("Saravanan Sekar <[email protected]>");
+MODULE_DESCRIPTION("MP2629 Battery charger mfd driver");

"parent driver"

include/linux/mfd/mp2629.h line 3

Quoted 10 lines
drivers/mfd/mp2629.c new file +1 -0
+MODULE_LICENSE("GPL");
include/linux/mfd/mp2629.h new file +3 -0
new file mode 100644
index 000000000000..371e44330ba8
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * mp2629.h  - register definitions for mp2629 charger

Remove the filename.

s/mp2629/MP2629/

include/linux/mfd/mp2629.h line 5

Quoted 2 lines
include/linux/mfd/mp2629.h new file +2 -0
+ * Copyright 2020 Monolithic Power Systems, Inc
+ *

Superfluous '\n'.

Quoted 10 lines

include/linux/mfd/mp2629.h line 15

Quoted 9 lines
include/linux/mfd/mp2629.h new file +9 -0
+ */
+
+#ifndef __MP2629_H__
+#define __MP2629_H__
+
+#include <linux/types.h>
+
+struct device;
+struct regmap;

Why not just add the includes?

Some more shared enum added in ADC driver

Quoted 6 lines

include/linux/mfd/mp2629.h line 22

Quoted 6 lines
include/linux/mfd/mp2629.h new file +6 -0
+struct mp2629_info {
+	struct device *dev;
+	struct regmap *regmap;
+};
+
+#endif

Thanks,
Saravanan

#12 lore raw

Re: [PATCH v4 2/5] mfd: mp2629: Add support for mps battery charger

Saravanan, Jonathan,

Quoted 18 lines · saravanan sekar
Quoted 17 lines · Lee Jones
Quoted 15 lines · Saravanan Sekar

mp2629 is a highly-integrated switching-mode battery charge management device for single-cell Li-ion or Li-polymer battery.

Add MFD core enables chip access for ADC driver for battery readings, and a power supply battery-charger driver

---
  drivers/mfd/Kconfig        |   9 +++
  drivers/mfd/Makefile       |   2 +
  drivers/mfd/mp2629.c       | 116 +++++++++++++++++++++++++++++++++++++
  include/linux/mfd/mp2629.h |  22 +++++++
  4 files changed, 149 insertions(+)

create mode 100644 drivers/mfd/mp2629.c
create mode 100644 include/linux/mfd/mp2629.h

[...]

Quoted 5 lines
Quoted 4 lines

drivers/mfd/mp2629.c line 54

Quoted 3 lines
drivers/mfd/mp2629.c new file +3 -0
+static int mp2629_probe(struct i2c_client *client)
+{
+	struct mp2629_info *info;

Call this ddata instead of info.

Not sure the reason, I will do.

Because this is device data. Info is too loose of a definition.

Quoted 34 lines
Quoted 22 lines
Quoted 10 lines
drivers/mfd/mp2629.c new file +10 -0
+	struct resource	*resources;
+	int ret;
+	int i;
+
+	info = devm_kzalloc(&client->dev, sizeof(*info), GFP_KERNEL);
+	if (!info)
+		return -ENOMEM;
+
+	info->dev = &client->dev;
+	i2c_set_clientdata(client, info);

drivers/mfd/mp2629.c line 74

Quoted 10 lines
drivers/mfd/mp2629.c new file +10 -0
+
+	info->regmap = devm_regmap_init_i2c(client, &mp2629_regmap_config);
+	if (IS_ERR(info->regmap)) {
+		dev_err(info->dev, "Failed to allocate regmap!\n");
+		return PTR_ERR(info->regmap);
+	}
+
+	for (i = 0; i < MP2629_MFD_MAX; i++) {
+		mp2629mfd[i].platform_data = &info->regmap;
+		mp2629mfd[i].pdata_size = sizeof(info->regmap);

You don't need to store this in platform data as well.

Quoted 1 line

You already have it in device data (ddata [currently 'info']).

"The IIO parts seems fine (minor comments inline) but I'm not keep on directly accessing the internals of the mfd device info structure. To my mind that should be opaque to the child drivers so as to provide clear structure to any such accesses.

This mess in layering with the children directly using the parents regmap is a little concerning. It means that the 3 drivers really aren't very well separated and can't really be reviewed independently (not a good thing)."

Quoted 5 lines

This is the review comments form Jonathan on V2, not to access parent data structure directly.
Am I misunderstood his review comments? please suggest the better option to follow as like in V2
or V2 + some improvements or V4 + improvements?

I will take this up with Jonathan separately if necessary.

For your FYI (and Jonathan if he's Cc'ed), it's very common for a child of an MFD to acquire resources from their parent. That is the point of a lot of MFDs, to obtain and register shared resources and pass them onto their offspring. There are 10's of examples of this.

Things like Regmaps aren't platform data, they are device/driver data, which is usually passed though platform_set_drvdata().

[...]

Quoted 11 lines
Quoted 10 lines

include/linux/mfd/mp2629.h line 15

Quoted 9 lines

+ */

include/linux/mfd/mp2629.h new file +8 -0
+
+#ifndef __MP2629_H__
+#define __MP2629_H__
+
+#include <linux/types.h>
+
+struct device;
+struct regmap;

Why not just add the includes?

Some more shared enum added in ADC driver

Sorry?

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
include/linux/mfd/mp2629.h new file +6 -0
+struct mp2629_info {
+	struct device *dev;
+	struct regmap *regmap;
+};
+
+#endif
Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
author maintainer
#13 lore raw

Re: [PATCH v4 2/5] mfd: mp2629: Add support for mps battery charger

Hi Lee,

Quoted 21 lines · Lee Jones

Saravanan, Jonathan,

Quoted 9 lines · saravanan sekar
Quoted 8 lines · Lee Jones
Quoted 6 lines · Saravanan Sekar

mp2629 is a highly-integrated switching-mode battery charge management device for single-cell Li-ion or Li-polymer battery.

Add MFD core enables chip access for ADC driver for battery readings, and a power supply battery-charger driver

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
---
   drivers/mfd/Kconfig        |   9 +++
   drivers/mfd/Makefile       |   2 +
   drivers/mfd/mp2629.c       | 116 +++++++++++++++++++++++++++++++++++++
   include/linux/mfd/mp2629.h |  22 +++++++
   4 files changed, 149 insertions(+)

create mode 100644 drivers/mfd/mp2629.c
create mode 100644 include/linux/mfd/mp2629.h

Quoted 8 lines

[...]

Quoted 5 lines
Quoted 4 lines

drivers/mfd/mp2629.c line 54

Quoted 3 lines
drivers/mfd/mp2629.c new file +3 -0
+static int mp2629_probe(struct i2c_client *client)
+{
+	struct mp2629_info *info;

Call this ddata instead of info.

Not sure the reason, I will do.

Because this is device data. Info is too loose of a definition.

Ok, noted

Quoted 40 lines
Quoted 33 lines
Quoted 22 lines
Quoted 10 lines
drivers/mfd/mp2629.c new file +10 -0
+	struct resource	*resources;
+	int ret;
+	int i;
+
+	info = devm_kzalloc(&client->dev, sizeof(*info), GFP_KERNEL);
+	if (!info)
+		return -ENOMEM;
+
+	info->dev = &client->dev;
+	i2c_set_clientdata(client, info);

drivers/mfd/mp2629.c line 74

Quoted 10 lines
drivers/mfd/mp2629.c new file +10 -0
+
+	info->regmap = devm_regmap_init_i2c(client, &mp2629_regmap_config);
+	if (IS_ERR(info->regmap)) {
+		dev_err(info->dev, "Failed to allocate regmap!\n");
+		return PTR_ERR(info->regmap);
+	}
+
+	for (i = 0; i < MP2629_MFD_MAX; i++) {
+		mp2629mfd[i].platform_data = &info->regmap;
+		mp2629mfd[i].pdata_size = sizeof(info->regmap);

You don't need to store this in platform data as well.

Quoted 1 line

You already have it in device data (ddata [currently 'info']).

"The IIO parts seems fine (minor comments inline) but I'm not keep on directly accessing the internals of the mfd device info structure. To my mind that should be opaque to the child drivers so as to provide clear structure to any such accesses.

This mess in layering with the children directly using the parents regmap is a little concerning. It means that the 3 drivers really aren't very well separated and can't really be reviewed independently (not a good thing)."

Quoted 5 lines

This is the review comments form Jonathan on V2, not to access parent data structure directly.
Am I misunderstood his review comments? please suggest the better option to follow as like in V2
or V2 + some improvements or V4 + improvements?

I will take this up with Jonathan separately if necessary.

Quoted 7 lines

For your FYI (and Jonathan if he's Cc'ed), it's very common for a child of an MFD to acquire resources from their parent. That is the point of a lot of MFDs, to obtain and register shared resources and pass them onto their offspring. There are 10's of examples of this.

Things like Regmaps aren't platform data, they are device/driver data, which is usually passed though platform_set_drvdata().

Thanks for clarification, I will go as like in V2 sharing mfd struct to the childs.

Quoted 12 lines

[...]

Quoted 10 lines
Quoted 10 lines

include/linux/mfd/mp2629.h line 15

Quoted 9 lines

+ */

include/linux/mfd/mp2629.h new file +8 -0
+
+#ifndef __MP2629_H__
+#define __MP2629_H__
+
+#include <linux/types.h>
+
+struct device;
+struct regmap;

Why not just add the includes?

Quoted 2 lines
Quoted 1 line

Some more shared enum added in ADC driver

Sorry?

I misunderstood your previous question that you are asking to remove this mp2629.h file

"No user here. (Hint: Use forward declaration of struct device instead)" - review comments on V1 from Andy Shevchenko. So remove the includes

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

include/linux/mfd/mp2629.h line 22

Quoted 6 lines
include/linux/mfd/mp2629.h new file +6 -0
+struct mp2629_info {
+	struct device *dev;
+	struct regmap *regmap;
+};
+
+#endif

Thanks,

Saravanan

#14 lore raw

Re: [PATCH v4 2/5] mfd: mp2629: Add support for mps battery charger

Quoted 22 lines · saravanan sekar
Quoted 21 lines · Lee Jones

Saravanan, Jonathan,

Quoted 18 lines · saravanan sekar
Quoted 17 lines · Lee Jones
Quoted 15 lines · Saravanan Sekar

mp2629 is a highly-integrated switching-mode battery charge management device for single-cell Li-ion or Li-polymer battery.

Add MFD core enables chip access for ADC driver for battery readings, and a power supply battery-charger driver

---
   drivers/mfd/Kconfig        |   9 +++
   drivers/mfd/Makefile       |   2 +
   drivers/mfd/mp2629.c       | 116 +++++++++++++++++++++++++++++++++++++
   include/linux/mfd/mp2629.h |  22 +++++++
   4 files changed, 149 insertions(+)

create mode 100644 drivers/mfd/mp2629.c
create mode 100644 include/linux/mfd/mp2629.h

[...]

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

include/linux/mfd/mp2629.h line 15

Quoted 7 lines
include/linux/mfd/mp2629.h new file +7 -0
+#ifndef __MP2629_H__
+#define __MP2629_H__
+
+#include <linux/types.h>
+
+struct device;
+struct regmap;

Why not just add the includes?

Some more shared enum added in ADC driver

Quoted 8 lines
Quoted 1 line

Sorry?

I misunderstood your previous question that you are asking to remove this mp2629.h file

"No user here. (Hint: Use forward declaration of struct device instead)" - review comments on V1 from Andy Shevchenko.
So remove the includes

So Andy has reviewed, but you still don't have him on Cc?

How are we meant to continue the discussion?

As a general rule I'm not a fan of forward declarations.

I think they should be avoided if at all possible.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
include/linux/mfd/mp2629.h new file +6 -0
+struct mp2629_info {
+	struct device *dev;
+	struct regmap *regmap;
+};
+
+#endif
Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
author maintainer
#15 lore raw

Re: [PATCH v4 2/5] mfd: mp2629: Add support for mps battery charger

Hi Lee, Andy

Quoted 34 lines · Lee Jones
Quoted 22 lines · saravanan sekar
Quoted 21 lines · Lee Jones

Saravanan, Jonathan,

Quoted 18 lines · saravanan sekar
Quoted 17 lines · Lee Jones
Quoted 15 lines · Saravanan Sekar

mp2629 is a highly-integrated switching-mode battery charge management device for single-cell Li-ion or Li-polymer battery.

Add MFD core enables chip access for ADC driver for battery readings, and a power supply battery-charger driver

---
    drivers/mfd/Kconfig        |   9 +++
    drivers/mfd/Makefile       |   2 +
    drivers/mfd/mp2629.c       | 116 +++++++++++++++++++++++++++++++++++++
    include/linux/mfd/mp2629.h |  22 +++++++
    4 files changed, 149 insertions(+)
    create mode 100644 drivers/mfd/mp2629.c
    create mode 100644 include/linux/mfd/mp2629.h

[...]

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

include/linux/mfd/mp2629.h line 15

Quoted 7 lines
include/linux/mfd/mp2629.h new file +7 -0
+#ifndef __MP2629_H__
+#define __MP2629_H__
+
+#include <linux/types.h>
+
+struct device;
+struct regmap;

Why not just add the includes?

Some more shared enum added in ADC driver

Quoted 8 lines
Quoted 7 lines
Quoted 1 line

Sorry?

I misunderstood your previous question that you are asking to remove this mp2629.h file

"No user here. (Hint: Use forward declaration of struct device instead)" - review comments on V1 from Andy Shevchenko.
So remove the includes

So Andy has reviewed, but you still don't have him on Cc?

Sorry one of his hint made me removed him in CC unknowingly.

"For the future, hint:
        scripts/get_maintainer.pl --git --git-min-percent=67 ..."

My fault, added him in CC

Quoted 5 lines

How are we meant to continue the discussion?

As a general rule I'm not a fan of forward declarations.

I think they should be avoided if at all possible.

Ok will add includes

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
include/linux/mfd/mp2629.h new file +6 -0
+struct mp2629_info {
+	struct device *dev;
+	struct regmap *regmap;
+};
+
+#endif
#16 lore raw

Re: [PATCH v4 2/5] mfd: mp2629: Add support for mps battery charger

Quoted 10 lines · saravanan sekar
Quoted 4 lines · Lee Jones
Quoted 1 line · saravanan sekar

On 27/03/20 11:22 am, Lee Jones wrote:

So Andy has reviewed, but you still don't have him on Cc?

Sorry one of his hint made me removed him in CC unknowingly.

"For the future, hint:

         scripts/get_maintainer.pl --git --git-min-percent=67 ..."

Perhaps I have to elaborate. The above hint for the initial submit. Then the rule of thumb: Include reviewers into Cc (to the patches they have reviewed), because you can't know their intention and maybe they want to follow a development.

Quoted 1 line

My fault, added him in CC

No problem.

--
With Best Regards,
Andy Shevchenko

author maintainer
#17 lore raw

Re: [PATCH v4 2/5] mfd: mp2629: Add support for mps battery charger

Hi Andy,

Quoted 7 lines · Andy Shevchenko
Quoted 6 lines · saravanan sekar
Quoted 3 lines · Lee Jones
Quoted 1 line · saravanan sekar

On 27/03/20 11:22 am, Lee Jones wrote:

So Andy has reviewed, but you still don't have him on Cc?

Sorry one of his hint made me removed him in CC unknowingly.

Quoted 7 lines
Quoted 3 lines

"For the future, hint:

          scripts/get_maintainer.pl --git --git-min-percent=67 ..."

Perhaps I have to elaborate. The above hint for the initial submit. Then the rule of thumb: Include reviewers into Cc (to the patches they have reviewed), because you can't know their intention and maybe they want to follow a development.

Thanks for more details. Between Lee has not recommended "forward declarations", the review comment you gave on my V1 patch (more info on previous email). Hope you agree with the same.

Quoted 6 lines
Quoted 1 line

My fault, added him in CC

No problem.

--
With Best Regards,
Andy Shevchenko

#18 lore raw

Re: [PATCH v4 2/5] mfd: mp2629: Add support for mps battery charger

Quoted 11 lines · saravanan sekar
Quoted 10 lines · Andy Shevchenko
Quoted 9 lines · saravanan sekar
Quoted 3 lines · Lee Jones
Quoted 1 line · saravanan sekar

On 27/03/20 11:22 am, Lee Jones wrote:

So Andy has reviewed, but you still don't have him on Cc?

Sorry one of his hint made me removed him in CC unknowingly.

"For the future, hint:

          scripts/get_maintainer.pl --git --git-min-percent=67 ..."
Quoted 8 lines
Quoted 4 lines

Perhaps I have to elaborate. The above hint for the initial submit. Then the rule of thumb: Include reviewers into Cc (to the patches they have reviewed), because you can't know their intention and maybe they want to follow a development.

Thanks for more details. Between Lee has not recommended "forward declarations", the review comment
you gave on my V1 patch (more info on previous email). Hope you agree with the same.

I think so.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#19 lore raw

Re: [PATCH v4 2/5] mfd: mp2629: Add support for mps battery charger

In reply to Lee Jones
Quoted 74 lines · On Fri, 27 Mar 2020 10:22:21 +0000 Lee Jones <[email protected]> wrote:

Saravanan, Jonathan,

Quoted 18 lines · saravanan sekar
Quoted 17 lines · Lee Jones
Quoted 15 lines · Saravanan Sekar

mp2629 is a highly-integrated switching-mode battery charge management device for single-cell Li-ion or Li-polymer battery.

Add MFD core enables chip access for ADC driver for battery readings, and a power supply battery-charger driver

---
  drivers/mfd/Kconfig        |   9 +++
  drivers/mfd/Makefile       |   2 +
  drivers/mfd/mp2629.c       | 116 +++++++++++++++++++++++++++++++++++++
  include/linux/mfd/mp2629.h |  22 +++++++
  4 files changed, 149 insertions(+)

create mode 100644 drivers/mfd/mp2629.c
create mode 100644 include/linux/mfd/mp2629.h

[...]

Quoted 5 lines
Quoted 4 lines

drivers/mfd/mp2629.c line 54

Quoted 3 lines
drivers/mfd/mp2629.c new file +3 -0
+static int mp2629_probe(struct i2c_client *client)
+{
+	struct mp2629_info *info;  

Call this ddata instead of info.

Not sure the reason, I will do.

Because this is device data. Info is too loose of a definition.

Quoted 34 lines
Quoted 22 lines
Quoted 10 lines
drivers/mfd/mp2629.c new file +10 -0
+	struct resource	*resources;
+	int ret;
+	int i;
+
+	info = devm_kzalloc(&client->dev, sizeof(*info), GFP_KERNEL);
+	if (!info)
+		return -ENOMEM;
+
+	info->dev = &client->dev;
+	i2c_set_clientdata(client, info);

drivers/mfd/mp2629.c line 74

Quoted 10 lines
drivers/mfd/mp2629.c new file +10 -0
+
+	info->regmap = devm_regmap_init_i2c(client, &mp2629_regmap_config);
+	if (IS_ERR(info->regmap)) {
+		dev_err(info->dev, "Failed to allocate regmap!\n");
+		return PTR_ERR(info->regmap);
+	}
+
+	for (i = 0; i < MP2629_MFD_MAX; i++) {
+		mp2629mfd[i].platform_data = &info->regmap;
+		mp2629mfd[i].pdata_size = sizeof(info->regmap);  

You don't need to store this in platform data as well.

Quoted 1 line

You already have it in device data (ddata [currently 'info']).

"The IIO parts seems fine (minor comments inline) but I'm not keep on directly accessing the internals of the mfd device info structure. To my mind that should be opaque to the child drivers so as to provide clear structure to any such accesses.

This mess in layering with the children directly using the parents regmap is a little concerning. It means that the 3 drivers really aren't very well separated and can't really be reviewed independently (not a good thing)."

Quoted 5 lines

This is the review comments form Jonathan on V2, not to access parent data structure directly.
Am I misunderstood his review comments? please suggest the better option to follow as like in V2
or V2 + some improvements or V4 + improvements?

I will take this up with Jonathan separately if necessary.

Quoted 8 lines

For your FYI (and Jonathan if he's Cc'ed), it's very common for a child of an MFD to acquire resources from their parent. That is the point of a lot of MFDs, to obtain and register shared resources and pass them onto their offspring. There are 10's of examples of this.

Things like Regmaps aren't platform data, they are device/driver data, which is usually passed though platform_set_drvdata().

Fair enough. It seemed a bit messy to have full visibility of the parent driver structures just to access one element.

What I was actually meaning to suggest was a couple of wrapper functions, not passing the regmap separately, but I guess that doesn't really make any difference.

So a read / write wrapper that just takes an abstract ddata pointer.

Fair enough if you think that's an unnecessary bit of abstraction.

Jonathan

Quoted 23 lines

[...]

Quoted 11 lines
Quoted 10 lines

include/linux/mfd/mp2629.h line 15

Quoted 9 lines

+ */

include/linux/mfd/mp2629.h new file +8 -0
+
+#ifndef __MP2629_H__
+#define __MP2629_H__
+
+#include <linux/types.h>
+
+struct device;
+struct regmap;  

Why not just add the includes?

Some more shared enum added in ADC driver

Sorry?

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
include/linux/mfd/mp2629.h new file +6 -0
+struct mp2629_info {
+	struct device *dev;
+	struct regmap *regmap;
+};
+
+#endif  
author maintainer
#20 lore raw

PATCH v4 3/5 iio: adc: mp2629: Add support for mp2629 ADC driver

In reply to Saravanan Sekar

Add support for 8-bit resolution ADC readings for input power supply and battery charging measurement. Provides voltage, current readings to mp2629 power supply driver.

---
 drivers/iio/adc/Kconfig      |  10 ++
 drivers/iio/adc/Makefile     |   1 +
 drivers/iio/adc/mp2629_adc.c | 214 +++++++++++++++++++++++++++++++++++
 include/linux/mfd/mp2629.h   |   9 ++
 4 files changed, 234 insertions(+)
 create mode 100644 drivers/iio/adc/mp2629_adc.c
drivers/iio/adc/Kconfig +10 -0
index 82e33082958c..ef0c0cd31855 100644
@@ -680,6 +680,16 @@ config MESON_SARADC
 	  To compile this driver as a module, choose M here: the
 	  module will be called meson_saradc.
 
+config MP2629_ADC
+	tristate "Monolithic MP2629 ADC driver"
+	depends on MFD_MP2629
+	help
+	  Say yes to have support for battery charger IC MP2629 ADC device
+	  accessed over I2C.
+
+	  This driver provides ADC conversion of system, input power supply
+	  and battery voltage & current information.
+
 config NAU7802
 	tristate "Nuvoton NAU7802 ADC driver"
 	depends on I2C
drivers/iio/adc/Makefile +1 -0
index 919228900df9..f14416c245a6 100644
@@ -64,6 +64,7 @@ obj-$(CONFIG_MCP3911) += mcp3911.o
 obj-$(CONFIG_MEDIATEK_MT6577_AUXADC) += mt6577_auxadc.o
 obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o
 obj-$(CONFIG_MESON_SARADC) += meson_saradc.o
+obj-$(CONFIG_MP2629_ADC) += mp2629_adc.o
 obj-$(CONFIG_MXS_LRADC_ADC) += mxs-lradc-adc.o
 obj-$(CONFIG_NAU7802) += nau7802.o
 obj-$(CONFIG_NPCM_ADC) += npcm_adc.o
drivers/iio/adc/mp2629_adc.c new file +214 -0

214 lines not on this page · raw message

include/linux/mfd/mp2629.h +9 -0
index 371e44330ba8..8b9c717e1fb0 100644
@@ -19,4 +19,13 @@ struct mp2629_info {
 	struct regmap *regmap;
 };
 
+enum mp2629_adc_chan {
+	MP2629_BATT_VOLT,
+	MP2629_SYSTEM_VOLT,
+	MP2629_INPUT_VOLT,
+	MP2629_BATT_CURRENT,
+	MP2629_INPUT_CURRENT,
+	MP2629_ADC_CHAN_END
+};
+
 #endif
Signature · 1 line
2.17.1
#21 lore raw

Re: [PATCH v4 3/5] iio: adc: mp2629: Add support for mp2629 ADC driver

Quoted 4 lines · Saravanan Sekar

Add support for 8-bit resolution ADC readings for input power supply and battery charging measurement. Provides voltage, current readings to mp2629 power supply driver.

...

drivers/iio/adc/mp2629_adc.c line 11

Quoted 3 lines
drivers/iio/adc/mp2629_adc.c new file +2 -0
+#include <linux/platform_device.h>
 
+#include <linux/of_device.h>

Don't see users of it.

drivers/iio/adc/mp2629_adc.c line 15

Quoted 5 lines
drivers/iio/adc/mp2629_adc.c new file +4 -0
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/regulator/consumer.h>
 
+#include <linux/sysfs.h>

Any users?

Quoted 1 line

+#include <linux/regmap.h>

Perhaps ordered?

drivers/iio/adc/mp2629_adc.c line 20

Quoted 3 lines
drivers/iio/adc/mp2629_adc.c new file +3 -0
+#include <linux/iio/iio.h>
+#include <linux/iio/machine.h>
+#include <linux/iio/driver.h>

+ blank line?

Quoted 1 line

+#include <linux/mfd/mp2629.h>

...

Quoted 7 lines
drivers/iio/adc/mp2629_adc.c new file +7 -0
+static int mp2629_read_raw(struct iio_dev *indio_dev,
+                       struct iio_chan_spec const *chan,
+                       int *val, int *val2, long mask)
+{
+       struct mp2629_adc *info = iio_priv(indio_dev);
+       unsigned int rval;
+       int ret;

drivers/iio/adc/mp2629_adc.c line 81

Quoted 10 lines
drivers/iio/adc/mp2629_adc.c new file +9 -0
+
+       switch (mask) {
+       case IIO_CHAN_INFO_RAW:
+               ret = regmap_read(info->regmap, chan->address, &rval);
+               if (ret < 0)
+                       return ret;
+
+               if (chan->address == MP2629_INPUT_VOLT)
 
+                       rval &= 0x7f;

GENMASK() ?

Quoted 5 lines
drivers/iio/adc/mp2629_adc.c new file +4 -0
+               *val = rval;
+               return IIO_VAL_INT;
 
+       return 0;
+}

...

Quoted 1 line

+ void **pdata = pdev->dev.platform_data;

Same Qs as per other patch.

...

Quoted 1 line

+ indio_dev->dev.of_node = pdev->dev.of_node;

Jonathan, doesn't IIO core do this for all?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#22 lore raw

Re: [PATCH v4 3/5] iio: adc: mp2629: Add support for mp2629 ADC driver

Quoted 66 lines · On Mon, 23 Mar 2020 01:32:34 +0200 Andy Shevchenko <[email protected]>…
Quoted 4 lines · Saravanan Sekar

Add support for 8-bit resolution ADC readings for input power supply and battery charging measurement. Provides voltage, current readings to mp2629 power supply driver.

...

drivers/iio/adc/mp2629_adc.c line 11

Quoted 3 lines
drivers/iio/adc/mp2629_adc.c new file +2 -0
+#include <linux/platform_device.h>  
 
+#include <linux/of_device.h>  

Don't see users of it.

drivers/iio/adc/mp2629_adc.c line 15

Quoted 5 lines
drivers/iio/adc/mp2629_adc.c new file +4 -0
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/regulator/consumer.h>  
 
+#include <linux/sysfs.h>  

Any users?

Quoted 1 line

+#include <linux/regmap.h>

Perhaps ordered?

drivers/iio/adc/mp2629_adc.c line 20

Quoted 3 lines
drivers/iio/adc/mp2629_adc.c new file +3 -0
+#include <linux/iio/iio.h>
+#include <linux/iio/machine.h>
+#include <linux/iio/driver.h>  

+ blank line?

Quoted 1 line

+#include <linux/mfd/mp2629.h>

...

Quoted 7 lines
drivers/iio/adc/mp2629_adc.c new file +7 -0
+static int mp2629_read_raw(struct iio_dev *indio_dev,
+                       struct iio_chan_spec const *chan,
+                       int *val, int *val2, long mask)
+{
+       struct mp2629_adc *info = iio_priv(indio_dev);
+       unsigned int rval;
+       int ret;

drivers/iio/adc/mp2629_adc.c line 81

Quoted 10 lines
drivers/iio/adc/mp2629_adc.c new file +9 -0
+
+       switch (mask) {
+       case IIO_CHAN_INFO_RAW:
+               ret = regmap_read(info->regmap, chan->address, &rval);
+               if (ret < 0)
+                       return ret;
+
+               if (chan->address == MP2629_INPUT_VOLT)  
 
+                       rval &= 0x7f;  

GENMASK() ?

Quoted 5 lines
drivers/iio/adc/mp2629_adc.c new file +4 -0
+               *val = rval;
+               return IIO_VAL_INT;  
 
+       return 0;
+}  

...

Quoted 1 line

+ void **pdata = pdev->dev.platform_data;

Quoted 8 lines

Same Qs as per other patch.

...

Quoted 1 line

+ indio_dev->dev.of_node = pdev->dev.of_node;

Jonathan, doesn't IIO core do this for all?

Nope. I'm not totally sure it's always safe to do so as we have some weird parent structures in some cases. A quick grep suggests that we may be fine though, or alternatively be able to get away with a set it if not already set approach.

I'll take a look when I get some time. It would be nice to clean this up.

Jonathan

#23 lore raw

Re: [PATCH v4 3/5] iio: adc: mp2629: Add support for mp2629 ADC driver

Quoted 3 lines · Jonathan Cameron
Quoted 1 line · On Mon, 23 Mar 2020 01:32:34 +0200 Andy Shevchenko <[email protected]>…

On Mon, Mar 23, 2020 at 12:47 AM Saravanan Sekar <[email protected]> wrote:

...

Quoted 5 lines
Quoted 4 lines
Quoted 1 line

+ indio_dev->dev.of_node = pdev->dev.of_node;

Jonathan, doesn't IIO core do this for all?

Quoted 8 lines

Nope. I'm not totally sure it's always safe to do so as we have some weird parent structures in some cases. A quick grep suggests that we may be fine though, or alternatively be able to get away with a set it if not already set approach.

I'll take a look when I get some time. It would be nice to clean this up.

We may follow the GPIO subsystem's approach, i.e. if there is no node provided take the one from the supplied struct device. But it may have side effects. So, it's completely up to you.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#24 lore raw

Re: [PATCH v4 3/5] iio: adc: mp2629: Add support for mp2629 ADC driver

In reply to Jonathan Cameron

Hi Andy,

Quoted 4 lines · Jonathan Cameron
Quoted 1 line · On Mon, 23 Mar 2020 01:32:34 +0200 Andy Shevchenko <[email protected]>…

On Mon, Mar 23, 2020 at 12:47 AM Saravanan Sekar <[email protected]> wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

Add support for 8-bit resolution ADC readings for input power supply and battery charging measurement. Provides voltage, current readings to mp2629 power supply driver.

...

drivers/iio/adc/mp2629_adc.c line 11

Quoted 2 lines
drivers/iio/adc/mp2629_adc.c new file +2 -0
+#include <linux/platform_device.h>
+#include <linux/of_device.h>

Don't see users of it.

Forgot to reply, its needed since I used struct of_device "error: field name not in record or union initializer { .compatible = "mps,mp2629_charger"},"

Quoted 63 lines
Quoted 41 lines

drivers/iio/adc/mp2629_adc.c line 15

Quoted 4 lines
drivers/iio/adc/mp2629_adc.c new file +4 -0
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/regulator/consumer.h>
+#include <linux/sysfs.h>

Any users?

Quoted 1 line

+#include <linux/regmap.h>

Perhaps ordered?

drivers/iio/adc/mp2629_adc.c line 20

Quoted 3 lines
drivers/iio/adc/mp2629_adc.c new file +3 -0
+#include <linux/iio/iio.h>
+#include <linux/iio/machine.h>
+#include <linux/iio/driver.h>

+ blank line?

Quoted 1 line

+#include <linux/mfd/mp2629.h>

...

Quoted 6 lines
drivers/iio/adc/mp2629_adc.c new file +6 -0
+static int mp2629_read_raw(struct iio_dev *indio_dev,
+                       struct iio_chan_spec const *chan,
+                       int *val, int *val2, long mask)
+{
+       struct mp2629_adc *info = iio_priv(indio_dev);
+       unsigned int rval;

drivers/iio/adc/mp2629_adc.c line 81

Quoted 10 lines
drivers/iio/adc/mp2629_adc.c new file +10 -0
+       int ret;
+
+       switch (mask) {
+       case IIO_CHAN_INFO_RAW:
+               ret = regmap_read(info->regmap, chan->address, &rval);
+               if (ret < 0)
+                       return ret;
+
+               if (chan->address == MP2629_INPUT_VOLT)
+                       rval &= 0x7f;

GENMASK() ?

Quoted 4 lines
drivers/iio/adc/mp2629_adc.c new file +4 -0
+               *val = rval;
+               return IIO_VAL_INT;
+       return 0;
+}

...

Quoted 8 lines
Quoted 1 line

+ void **pdata = pdev->dev.platform_data;

Same Qs as per other patch.

...

Quoted 1 line

+ indio_dev->dev.of_node = pdev->dev.of_node;

Jonathan, doesn't IIO core do this for all?

Nope. I'm not totally sure it's always safe to do so as we have some weird parent structures in some cases. A quick grep suggests that we may be fine though, or alternatively be able to get away with a set it if not already set approach.

I'll take a look when I get some time. It would be nice to clean this up.

Jonathan

#25 lore raw

Re: [PATCH v4 3/5] iio: adc: mp2629: Add support for mp2629 ADC driver

Quoted 4 lines · saravanan sekar
Quoted 3 lines · Jonathan Cameron
Quoted 1 line · On Mon, 23 Mar 2020 01:32:34 +0200 Andy Shevchenko <[email protected]>…

On Mon, Mar 23, 2020 at 12:47 AM Saravanan Sekar <[email protected]> wrote:

...

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line

+#include <linux/of_device.h>

Don't see users of it.

Forgot to reply, its needed since I used struct of_device "error: field name not in record or union initializer
{ .compatible = "mps,mp2629_charger"},"

Yes, and my comment still stays. The error you get due to lack of proper header, i.e. mod_devicetable.h.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#26 lore raw

PATCH v4 4/5 power: supply: Add support for mps mp2629 battery charger

In reply to Saravanan Sekar

The mp2629 provides switching-mode battery charge management for single-cell Li-ion or Li-polymer battery. Driver supports the access/control input source and battery charging parameters.

---
 drivers/power/supply/Kconfig          |  10 +
 drivers/power/supply/Makefile         |   1 +
 drivers/power/supply/mp2629_charger.c | 697 ++++++++++++++++++++++++++
 3 files changed, 708 insertions(+)
 create mode 100644 drivers/power/supply/mp2629_charger.c
drivers/power/supply/Kconfig +10 -0
index f3424fdce341..f45409d26d54 100644
@@ -541,6 +541,16 @@ config CHARGER_MAX8998
 	  Say Y to enable support for the battery charger control sysfs and
 	  platform data of MAX8998/LP3974 PMICs.
 
+config CHARGER_MP2629
+	bool "Monolithic power system MP2629 Battery charger"
+	depends on MFD_MP2629
+	depends on MP2629_ADC
+	depends on IIO
+	help
+	  Select this option to enable support for Monolithic power system
+	  Battery charger. This driver provies Battery charger power management
+	  functions on the systems.
+
 config CHARGER_QCOM_SMBB
 	tristate "Qualcomm Switch-Mode Battery Charger and Boost"
 	depends on MFD_SPMI_PMIC || COMPILE_TEST
drivers/power/supply/Makefile +1 -0
index 6c7da920ea83..41cb64f09e49 100644
@@ -75,6 +75,7 @@ obj-$(CONFIG_CHARGER_MAX77650)	+= max77650-charger.o
 obj-$(CONFIG_CHARGER_MAX77693)	+= max77693_charger.o
 obj-$(CONFIG_CHARGER_MAX8997)	+= max8997_charger.o
 obj-$(CONFIG_CHARGER_MAX8998)	+= max8998_charger.o
+obj-$(CONFIG_CHARGER_MP2629)	+= mp2629_charger.o
 obj-$(CONFIG_CHARGER_QCOM_SMBB)	+= qcom_smbb.o
 obj-$(CONFIG_CHARGER_BQ2415X)	+= bq2415x_charger.o
 obj-$(CONFIG_CHARGER_BQ24190)	+= bq24190_charger.o
drivers/power/supply/mp2629_charger.c new file +697 -0

697 lines not on this page · raw message

Signature · 1 line
2.17.1
#27 lore raw

Re: [PATCH v4 4/5] power: supply: Add support for mps mp2629 battery charger

Quoted 4 lines · Saravanan Sekar

The mp2629 provides switching-mode battery charge management for single-cell Li-ion or Li-polymer battery. Driver supports the access/control input source and battery charging parameters.

...

drivers/power/supply/mp2629_charger.c line 12

Quoted 4 lines
drivers/power/supply/mp2629_charger.c new file +3 -0
+#include <linux/module.h>
+#include <linux/platform_device.h>
 
+#include <linux/of_device.h>

Do you need this one?

drivers/power/supply/mp2629_charger.c line 18

Quoted 6 lines
drivers/power/supply/mp2629_charger.c new file +6 -0
+#include <linux/interrupt.h>
+#include <linux/iio/consumer.h>
+#include <linux/iio/types.h>
+#include <linux/power_supply.h>
+#include <linux/workqueue.h>
+#include <linux/regmap.h>

Perhaps put them in order?

Quoted 1 line

+#include <linux/mfd/core.h>

How this is being used?

Quoted 1 line

+#include <linux/mfd/mp2629.h>

...

drivers/power/supply/mp2629_charger.c line 40

Quoted 5 lines
drivers/power/supply/mp2629_charger.c new file +5 -0
+#define MP2629_MASK_INPUT_TYPE         0xe0
+#define MP2629_MASK_CHARGE_TYPE                0x18
+#define MP2629_MASK_CHARGE_CTRL                0x30
+#define MP2629_MASK_WDOG_CTRL          0x30
+#define MP2629_MASK_IMPEDANCE          0xf0

GENMASK()?

...

Quoted 1 line

+ struct regmap_field *regmap_fields[TERM_CURRENT + 1];

Hmm... Why not to have a definition to cover + 1?

...

drivers/power/supply/mp2629_charger.c line 185

Quoted 13 lines
drivers/power/supply/mp2629_charger.c new file +12 -0
+static int mp2629_get_prop(struct mp2629_charger *charger,
+                          enum mp2629_field fld,
+                          union power_supply_propval *val)
+{
+       int ret;
+       unsigned int rval;
+
 
+       ret = regmap_field_read(charger->regmap_fields[fld], &rval);
+       if (!ret)
+               val->intval = (rval * props[fld].step) + props[fld].min;
+
+       return ret;

Why not to use standard pattern, i.e.

if (ret)

    return ret;

...
return 0;

?

Quoted 1 line

+}

...

drivers/power/supply/mp2629_charger.c line 329

Quoted 7 lines
drivers/power/supply/mp2629_charger.c new file +6 -0
+static int mp2629_charger_battery_set_prop(struct power_supply *psy,
+                                       enum power_supply_property psp,
+                                       const union power_supply_propval *val)
+{
+       struct mp2629_charger *charger = dev_get_drvdata(psy->dev.parent);
 
+       int ret;

You may replace it with in-place return statements.

Quoted 14 lines
drivers/power/supply/mp2629_charger.c new file +14 -0
+
+       switch (psp) {
+       case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
+               ret = mp2629_set_prop(charger, TERM_CURRENT, val);
+               break;
+
+       case POWER_SUPPLY_PROP_PRECHARGE_CURRENT:
+               ret = mp2629_set_prop(charger, PRECHARGE, val);
+               break;
+
+       case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:
+               ret = mp2629_set_prop(charger, CHARGE_VLIM, val);
+               break;
+

drivers/power/supply/mp2629_charger.c line 352

Quoted 10 lines
drivers/power/supply/mp2629_charger.c new file +9 -0
+       case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
+               ret = mp2629_set_prop(charger, CHARGE_ILIM, val);
+               break;
+
+       default:
+               return -EINVAL;
+       }
 
+
+       return ret;

...and drop this completely.

Quoted 1 line

+}

...

drivers/power/supply/mp2629_charger.c line 368

Quoted 5 lines
drivers/power/supply/mp2629_charger.c new file +5 -0
+       case POWER_SUPPLY_PROP_ONLINE:
+               ret = regmap_read(charger->regmap, MP2629_REG_STATUS, &rval);
+               if (!ret)
+                       val->intval = !!(rval & MP2629_MASK_INPUT_TYPE);
+               break;

Traditional pattern?

...

drivers/power/supply/mp2629_charger.c line 423

Quoted 7 lines
drivers/power/supply/mp2629_charger.c new file +6 -0
+static int mp2629_charger_usb_set_prop(struct power_supply *psy,
+                               enum power_supply_property psp,
+                               const union power_supply_propval *val)
+{
+       struct mp2629_charger *charger = dev_get_drvdata(psy->dev.parent);
 
+       int ret;

No need to have it.

Quoted 15 lines
drivers/power/supply/mp2629_charger.c new file +15 -0
+       switch (psp) {
+       case POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT:
+               ret = mp2629_set_prop(charger, INPUT_VLIM, val);
+               break;
+
+       case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
+               ret = mp2629_set_prop(charger, INPUT_ILIM, val);
+               break;
+
+       default:
+               return -EINVAL;
+       }
+
+       return ret;
+}

...

drivers/power/supply/mp2629_charger.c line 447

Quoted 4 lines
drivers/power/supply/mp2629_charger.c new file +4 -0
+       return (psp == POWER_SUPPLY_PROP_PRECHARGE_CURRENT ||
+               psp == POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT ||
+               psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT ||
+               psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE);

Redundant parentheses.
Ditto for similar cases in the driver.

...

drivers/power/supply/mp2629_charger.c line 537

Quoted 11 lines
drivers/power/supply/mp2629_charger.c new file +10 -0
+static ssize_t batt_impedance_compensation_show(struct device *dev,
+                                          struct device_attribute *attr,
+                                          char *buf)
+{
+       struct mp2629_charger *charger = dev_get_drvdata(dev->parent);
+       unsigned int rval;
+       int ret;
+
+       ret = regmap_read(charger->regmap, MP2629_REG_IMPEDANCE_COMP, &rval);
 
+       if (ret < 0)

' < 0' is not needed.
Ditto for other cases.

drivers/power/supply/mp2629_charger.c line 542

Quoted 6 lines
drivers/power/supply/mp2629_charger.c new file +5 -0
+               return ret;
+
+       rval = (rval >> 4) * 10;
+
 
+       return scnprintf(buf, PAGE_SIZE, "%d mohm\n", rval);

Simple sprintf().

Quoted 1 line

+}

...

drivers/power/supply/mp2629_charger.c line 555

Quoted 12 lines
drivers/power/supply/mp2629_charger.c new file +11 -0
+static ssize_t batt_impedance_compensation_store(struct device *dev,
+                                           struct device_attribute *attr,
+                                           const char *buf,
+                                           size_t count)
+{
+       struct mp2629_charger *charger = dev_get_drvdata(dev->parent);
+       long val;
+       int ret;
+
+       ret = kstrtol(buf, 10, &val);
 
+       if (ret < 0)

No need to check for negative only.

drivers/power/supply/mp2629_charger.c line 559

Quoted 4 lines
drivers/power/supply/mp2629_charger.c new file +4 -0
+               return ret;
+
+       if (val < 0 && val > 140)
+               return -ERANGE;

And what the point then to use l instead of ul or even uint variant of the conversion above?

Quoted 9 lines
drivers/power/supply/mp2629_charger.c new file +9 -0
+       /* multiples of 10 mohm so round off */
+       val = val / 10;
+       ret = regmap_update_bits(charger->regmap, MP2629_REG_IMPEDANCE_COMP,
+                                       MP2629_MASK_IMPEDANCE, val << 4);
+       if (ret < 0)
+               return ret;
+
+       return count;
+}

...

drivers/power/supply/mp2629_charger.c line 582

Quoted 5 lines
drivers/power/supply/mp2629_charger.c new file +4 -0
+static int mp2629_charger_probe(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
 
+       void **pdata = pdev->dev.platform_data;

Why void?
Why **?
Why not to use dev_get_platdata()?
Why do we need platform data at all?

drivers/power/supply/mp2629_charger.c line 652

Quoted 8 lines
drivers/power/supply/mp2629_charger.c new file +6 -0
+       struct mp2629_charger *charger;
+       struct power_supply_config psy_cfg = {0};
+       int ret, i;
 
+       charger->regmap = *pdata;
 
+       regmap_update_bits(charger->regmap, MP2629_REG_INTERRUPT,
+                               GENMASK(6, 5), (BIT(6) | BIT(5)));

Too many parentheses.

Quoted 1 line

+}

--
With Best Regards,
Andy Shevchenko

author maintainer
#28 lore raw

Re: [PATCH v4 4/5] power: supply: Add support for mps mp2629 battery charger

Hi Andy,

Quoted 196 lines · Andy Shevchenko
Quoted 3 lines · Saravanan Sekar

The mp2629 provides switching-mode battery charge management for single-cell Li-ion or Li-polymer battery. Driver supports the access/control input source and battery charging parameters.

...

drivers/power/supply/mp2629_charger.c line 12

Quoted 3 lines
drivers/power/supply/mp2629_charger.c new file +3 -0
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/of_device.h>

Do you need this one?

drivers/power/supply/mp2629_charger.c line 18

Quoted 6 lines
drivers/power/supply/mp2629_charger.c new file +6 -0
+#include <linux/interrupt.h>
+#include <linux/iio/consumer.h>
+#include <linux/iio/types.h>
+#include <linux/power_supply.h>
+#include <linux/workqueue.h>
+#include <linux/regmap.h>

Perhaps put them in order?

Quoted 1 line

+#include <linux/mfd/core.h>

How this is being used?

Quoted 1 line

+#include <linux/mfd/mp2629.h>

...

drivers/power/supply/mp2629_charger.c line 40

Quoted 5 lines
drivers/power/supply/mp2629_charger.c new file +5 -0
+#define MP2629_MASK_INPUT_TYPE         0xe0
+#define MP2629_MASK_CHARGE_TYPE                0x18
+#define MP2629_MASK_CHARGE_CTRL                0x30
+#define MP2629_MASK_WDOG_CTRL          0x30
+#define MP2629_MASK_IMPEDANCE          0xf0

GENMASK()?

...

Quoted 1 line

+ struct regmap_field *regmap_fields[TERM_CURRENT + 1];

Hmm... Why not to have a definition to cover + 1?

...

drivers/power/supply/mp2629_charger.c line 185

Quoted 12 lines
drivers/power/supply/mp2629_charger.c new file +12 -0
+static int mp2629_get_prop(struct mp2629_charger *charger,
+                          enum mp2629_field fld,
+                          union power_supply_propval *val)
+{
+       int ret;
+       unsigned int rval;
+
+       ret = regmap_field_read(charger->regmap_fields[fld], &rval);
+       if (!ret)
+               val->intval = (rval * props[fld].step) + props[fld].min;
+
+       return ret;

Why not to use standard pattern, i.e.

   if (ret)
     return ret;
   ...
   return 0;

?

Quoted 1 line

+}

...

drivers/power/supply/mp2629_charger.c line 329

Quoted 6 lines
drivers/power/supply/mp2629_charger.c new file +6 -0
+static int mp2629_charger_battery_set_prop(struct power_supply *psy,
+                                       enum power_supply_property psp,
+                                       const union power_supply_propval *val)
+{
+       struct mp2629_charger *charger = dev_get_drvdata(psy->dev.parent);
+       int ret;

You may replace it with in-place return statements.

Quoted 13 lines
drivers/power/supply/mp2629_charger.c new file +13 -0
+
+       switch (psp) {
+       case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
+               ret = mp2629_set_prop(charger, TERM_CURRENT, val);
+               break;
+
+       case POWER_SUPPLY_PROP_PRECHARGE_CURRENT:
+               ret = mp2629_set_prop(charger, PRECHARGE, val);
+               break;
+
+       case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:
+               ret = mp2629_set_prop(charger, CHARGE_VLIM, val);
+               break;

drivers/power/supply/mp2629_charger.c line 352

Quoted 10 lines
drivers/power/supply/mp2629_charger.c new file +10 -0
+
+       case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
+               ret = mp2629_set_prop(charger, CHARGE_ILIM, val);
+               break;
+
+       default:
+               return -EINVAL;
+       }
+
+       return ret;

...and drop this completely.

Quoted 1 line

+}

...

drivers/power/supply/mp2629_charger.c line 368

Quoted 5 lines
drivers/power/supply/mp2629_charger.c new file +5 -0
+       case POWER_SUPPLY_PROP_ONLINE:
+               ret = regmap_read(charger->regmap, MP2629_REG_STATUS, &rval);
+               if (!ret)
+                       val->intval = !!(rval & MP2629_MASK_INPUT_TYPE);
+               break;

Traditional pattern?

...

drivers/power/supply/mp2629_charger.c line 423

Quoted 6 lines
drivers/power/supply/mp2629_charger.c new file +6 -0
+static int mp2629_charger_usb_set_prop(struct power_supply *psy,
+                               enum power_supply_property psp,
+                               const union power_supply_propval *val)
+{
+       struct mp2629_charger *charger = dev_get_drvdata(psy->dev.parent);
+       int ret;

No need to have it.

Quoted 15 lines
drivers/power/supply/mp2629_charger.c new file +15 -0
+       switch (psp) {
+       case POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT:
+               ret = mp2629_set_prop(charger, INPUT_VLIM, val);
+               break;
+
+       case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
+               ret = mp2629_set_prop(charger, INPUT_ILIM, val);
+               break;
+
+       default:
+               return -EINVAL;
+       }
+
+       return ret;
+}

...

drivers/power/supply/mp2629_charger.c line 447

Quoted 4 lines
drivers/power/supply/mp2629_charger.c new file +4 -0
+       return (psp == POWER_SUPPLY_PROP_PRECHARGE_CURRENT ||
+               psp == POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT ||
+               psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT ||
+               psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE);

Redundant parentheses.
Ditto for similar cases in the driver.

...

drivers/power/supply/mp2629_charger.c line 537

Quoted 10 lines
drivers/power/supply/mp2629_charger.c new file +10 -0
+static ssize_t batt_impedance_compensation_show(struct device *dev,
+                                          struct device_attribute *attr,
+                                          char *buf)
+{
+       struct mp2629_charger *charger = dev_get_drvdata(dev->parent);
+       unsigned int rval;
+       int ret;
+
+       ret = regmap_read(charger->regmap, MP2629_REG_IMPEDANCE_COMP, &rval);
+       if (ret < 0)

' < 0' is not needed.
Ditto for other cases.

drivers/power/supply/mp2629_charger.c line 542

Quoted 5 lines
drivers/power/supply/mp2629_charger.c new file +5 -0
+               return ret;
+
+       rval = (rval >> 4) * 10;
+
+       return scnprintf(buf, PAGE_SIZE, "%d mohm\n", rval);

Simple sprintf().

Quoted 1 line

+}

...

drivers/power/supply/mp2629_charger.c line 555

Quoted 11 lines
drivers/power/supply/mp2629_charger.c new file +11 -0
+static ssize_t batt_impedance_compensation_store(struct device *dev,
+                                           struct device_attribute *attr,
+                                           const char *buf,
+                                           size_t count)
+{
+       struct mp2629_charger *charger = dev_get_drvdata(dev->parent);
+       long val;
+       int ret;
+
+       ret = kstrtol(buf, 10, &val);
+       if (ret < 0)

No need to check for negative only.

drivers/power/supply/mp2629_charger.c line 559

Quoted 4 lines
drivers/power/supply/mp2629_charger.c new file +4 -0
+               return ret;
+
+       if (val < 0 && val > 140)
+               return -ERANGE;

And what the point then to use l instead of ul or even uint variant of the conversion above?

Quoted 9 lines
drivers/power/supply/mp2629_charger.c new file +9 -0
+       /* multiples of 10 mohm so round off */
+       val = val / 10;
+       ret = regmap_update_bits(charger->regmap, MP2629_REG_IMPEDANCE_COMP,
+                                       MP2629_MASK_IMPEDANCE, val << 4);
+       if (ret < 0)
+               return ret;
+
+       return count;
+}

...

Quoted 8 lines

drivers/power/supply/mp2629_charger.c line 582

Quoted 4 lines
drivers/power/supply/mp2629_charger.c new file +4 -0
+static int mp2629_charger_probe(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
+       void **pdata = pdev->dev.platform_data;

Why void?
Why **?
Why not to use dev_get_platdata()?
Why do we need platform data at all?

I have to pass regmap (address) from mfd driver to its children, as per review comment previous patch, mfd driver structure should not be directly accessed in children. Please suggest if any other better way

Quoted 6 lines

drivers/power/supply/mp2629_charger.c line 652

Quoted 6 lines
drivers/power/supply/mp2629_charger.c new file +6 -0
+       struct mp2629_charger *charger;
+       struct power_supply_config psy_cfg = {0};
+       int ret, i;
+       charger->regmap = *pdata;
+       regmap_update_bits(charger->regmap, MP2629_REG_INTERRUPT,
+                               GENMASK(6, 5), (BIT(6) | BIT(5)));
Quoted 6 lines

Too many parentheses.

Quoted 1 line

+}

--
With Best Regards,
Andy Shevchenko

Thanks,
Saravanan

#29 lore raw

Re: [PATCH v4 4/5] power: supply: Add support for mps mp2629 battery charger

In reply to Saravanan Sekar
I love your patch! Yet something to improve:

Hi Saravanan,

I love your patch! Yet something to improve:

[auto build test ERROR on next-20200320]
[also build test ERROR on v5.6-rc7]
[cannot apply to ljones-mfd/for-mfd-next iio/togreg power-supply/for-next v5.6-rc6 v5.6-rc5 v5.6-rc4] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Saravanan-Sekar/Add-battery-charger-driver-support-for-MP2629/20200323-064940
base:    d8f289c16fbb72e17b783175c1fb0942816264fd
config: sh-allmodconfig (attached as .config)
compiler: sh4-linux-gcc (GCC) 9.2.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=9.2.0 make.cross ARCH=sh

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

sh4-linux-ld: drivers/mfd/mp2629.o: in function `mp2629_probe':
mp2629.c:(.text+0xdc): undefined reference to `__devm_regmap_init_i2c'
sh4-linux-ld: drivers/mfd/mp2629.o: in function `mp2629_driver_init':
mp2629.c:(.init.text+0x28): undefined reference to `i2c_register_driver'
sh4-linux-ld: drivers/mfd/mp2629.o: in function `mp2629_driver_exit':
mp2629.c:(.exit.text+0x18): undefined reference to `i2c_del_driver'
sh4-linux-ld: drivers/power/supply/mp2629_charger.o: in function `mp2629_charger_remove':
mp2629_charger.c:(.text+0xcc): undefined reference to `iio_channel_release'
sh4-linux-ld: drivers/power/supply/mp2629_charger.o: in function `mp2629_charger_usb_get_prop':
mp2629_charger.c:(.text+0x3dc): undefined reference to `iio_read_channel_processed'
sh4-linux-ld: drivers/power/supply/mp2629_charger.o: in function `mp2629_charger_probe':
mp2629_charger.c:(.text+0x6d4): undefined reference to `iio_channel_get'

>> sh4-linux-ld: mp2629_charger.c:(.text+0x7f8): undefined reference to `iio_channel_release'

sh4-linux-ld: drivers/power/supply/mp2629_charger.o: in function `mp2629_charger_battery_get_prop':
mp2629_charger.c:(.text+0xb9c): undefined reference to `iio_read_channel_processed'

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#30 lore raw

Re: [PATCH v4 4/5] power: supply: Add support for mps mp2629 battery charger

In reply to Saravanan Sekar
I love your patch! Yet something to improve:

Hi Saravanan,

I love your patch! Yet something to improve:

[auto build test ERROR on next-20200320]
[also build test ERROR on v5.6-rc7]
[cannot apply to ljones-mfd/for-mfd-next iio/togreg power-supply/for-next v5.6-rc6 v5.6-rc5 v5.6-rc4] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Saravanan-Sekar/Add-battery-charger-driver-support-for-MP2629/20200323-064940
base:    d8f289c16fbb72e17b783175c1fb0942816264fd
config: s390-allmodconfig (attached as .config)
compiler: s390-linux-gcc (GCC) 9.2.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=9.2.0 make.cross ARCH=s390

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

s390-linux-ld: drivers/mfd/mp2629.o: in function `mp2629_probe':
mp2629.c:(.text+0x86): undefined reference to `__devm_regmap_init_i2c'
s390-linux-ld: drivers/mfd/mp2629.o: in function `mp2629_driver_init':
mp2629.c:(.init.text+0x64): undefined reference to `i2c_register_driver'
s390-linux-ld: drivers/mfd/mp2629.o: in function `mp2629_driver_exit':
mp2629.c:(.exit.text+0x2a): undefined reference to `i2c_del_driver'
s390-linux-ld: drivers/power/supply/mp2629_charger.o: in function `mp2629_charger_remove':
mp2629_charger.c:(.text+0x154): undefined reference to `iio_channel_release'
s390-linux-ld: drivers/power/supply/mp2629_charger.o: in function `mp2629_charger_usb_get_prop':
mp2629_charger.c:(.text+0x810): undefined reference to `iio_read_channel_processed'
s390-linux-ld: drivers/power/supply/mp2629_charger.o: in function `mp2629_charger_probe':
mp2629_charger.c:(.text+0xee4): undefined reference to `iio_channel_get'

>> s390-linux-ld: mp2629_charger.c:(.text+0x1270): undefined reference to `iio_channel_release'
   s390-linux-ld: drivers/power/supply/mp2629_charger.o: in function `mp2629_charger_battery_get_prop':
   mp2629_charger.c:(.text+0x179e): undefined reference to `iio_read_channel_processed'
>> s390-linux-ld: mp2629_charger.c:(.text+0x1844): undefined reference to `iio_read_channel_processed'

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#31 lore raw

Re: [PATCH v4 4/5] power: supply: Add support for mps mp2629 battery charger

In reply to Saravanan Sekar
I love your patch! Perhaps something to improve:

Hi Saravanan,

I love your patch! Perhaps something to improve:

[auto build test WARNING on next-20200320]
[also build test WARNING on v5.6-rc7]
[cannot apply to ljones-mfd/for-mfd-next iio/togreg power-supply/for-next v5.6-rc6 v5.6-rc5 v5.6-rc4] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Saravanan-Sekar/Add-battery-charger-driver-support-for-MP2629/20200323-064940
base:    d8f289c16fbb72e17b783175c1fb0942816264fd
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.1-187-gbff9b106-dirty
        make ARCH=x86_64 allmodconfig
        make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

If you fix the issue, kindly add following tag

sparse warnings: (new ones prefixed by >>)

>> drivers/power/supply/mp2629_charger.c:584:47: sparse: sparse: Using plain integer as NULL pointer

vim +584 drivers/power/supply/mp2629_charger.c

578
579 static int mp2629_charger_probe(struct platform_device *pdev)
580 {
581 struct device *dev = &pdev->dev;
582 void **pdata = pdev->dev.platform_data;
583 struct mp2629_charger *charger;

 > 584		struct power_supply_config psy_cfg = {0};

585 int ret, i;
586
587 charger = devm_kzalloc(dev, sizeof(*charger), GFP_KERNEL);
588 if (!charger)
589 return -ENOMEM;
590
591 charger->regmap = *pdata;
592 charger->dev = dev;
593 charger->irq = platform_get_irq(pdev, 0);
594 platform_set_drvdata(pdev, charger);
595
596 for (i = 0; i <= TERM_CURRENT; i++) {
597 charger->regmap_fields[i] = devm_regmap_field_alloc(dev,
598 charger->regmap, mp2629_reg_fields[i]);
599 if (IS_ERR(charger->regmap_fields[i])) {
600 dev_err(dev, "regmap field alloc fail %d\n", i);
601 return PTR_ERR(charger->regmap_fields[i]);
602 }
603 }
604
605 for (i = 0; i < MP2629_ADC_CHAN_END; i++) {
606 charger->iiochan[i] = iio_channel_get(dev, adc_chan_name[i]);
607 if (IS_ERR(charger->iiochan[i])) {
608 ret = PTR_ERR(charger->iiochan[i]);
609 goto iio_fail;
610 }
611 }
612
613 charger->usb = devm_power_supply_register(dev, &mp2629_usb_desc, NULL);
614 if (IS_ERR(charger->usb)) {
615 ret = PTR_ERR(charger->usb);
616 goto iio_fail;
617 }
618
619 psy_cfg.drv_data = charger;
620 psy_cfg.attr_grp = mp2629_charger_sysfs_groups;
621 charger->battery = devm_power_supply_register(dev,
622 &mp2629_battery_desc, &psy_cfg);
623 if (IS_ERR(charger->battery)) {
624 ret = PTR_ERR(charger->battery);
625 goto iio_fail;
626 }
627
628 ret = regmap_update_bits(charger->regmap, MP2629_REG_CHARGE_CTRL,
629 MP2629_MASK_CHARGE_CTRL, BIT(4));
630 if (ret) {
631 dev_err(dev, "enable charge fail: %d\n", ret);
632 goto iio_fail;
633 }
634
635 regmap_update_bits(charger->regmap, MP2629_REG_TIMER_CTRL,
636 MP2629_MASK_WDOG_CTRL, 0);
637
638 INIT_WORK(&charger->charger_work, mp2629_charger_work);
639 mutex_init(&charger->lock);
640
641 if (charger->irq) {
642 ret = devm_request_irq(dev, charger->irq, mp2629_irq_handler,
643 IRQF_TRIGGER_RISING, "mp2629-charger",
644 charger);
645 if (ret) {
646 dev_err(dev, "failed to request gpio IRQ\n");
647 goto iio_fail;
648 }
649 }
650
651 regmap_update_bits(charger->regmap, MP2629_REG_INTERRUPT,
652 GENMASK(6, 5), (BIT(6) | BIT(5)));
653
654 return 0;
655
656 iio_fail:
657 while (i--)
658 iio_channel_release(charger->iiochan[i]);
659
660 dev_err(dev, "driver register fail: %d\n", ret);
661 return ret;
662 }
663

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

author maintainer
#32 lore raw

PATCH v4 5/5 MAINTAINERS: Add entry for mp2629 Battery Charger driver

In reply to Saravanan Sekar

Add MAINTAINERS entry for Monolithic Power Systems mp2629 Charger driver.

---
 MAINTAINERS | 5 +++++
 1 file changed, 5 insertions(+)
MAINTAINERS +5 -0
index 32a95d162f06..0f82d5a7a614 100644
@@ -11358,10 +11358,15 @@ F:	drivers/tty/mxser.*
 MONOLITHIC POWER SYSTEM PMIC DRIVER
 M:	Saravanan Sekar <[email protected]>
 S:	Maintained
+F:	Documentation/devicetree/bindings/mfd/mps,mp2629.yaml
 F:	Documentation/devicetree/bindings/regulator/mps,mp*.yaml
+F:	drivers/iio/adc/mp2629_adc.c
+F:	drivers/mfd/mp2629.c
+F:	drivers/power/supply/mp2629_charger.c
 F:	drivers/regulator/mp5416.c
 F:	drivers/regulator/mpq7920.c
 F:	drivers/regulator/mpq7920.h
+F:	include/linux/mfd/mp2629.h
 
 MR800 AVERMEDIA USB FM RADIO DRIVER
 M:	Alexey Klimov <[email protected]>
Signature · 1 line
2.17.1