Skip to contentSkip to conversation

Add AMS AS3722 mfd, GPIO, regulator and RTC driver

PATCH Superseded Laxman Dewangan 4 participants 15 messages Sep 17, 2013 – Sep 23, 2013

Subsystems (5)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover Add AMS AS3722 mfd, GPIO, regulator and RTC driver

This series add the driver support for AMS AS3722 PMIC. The driver includes mfd, gpio, regulator and rtc.

Laxman Dewangan (4):
mfd: add support for AMS AS3722 PMIC
gpio: add support for AMS AS3722 gpio driver
regulator: as3722: add regulator driver for AMS AS3722 drivers/rtc/rtc-as3722: add RTC driver

 .../devicetree/bindings/gpio/gpio-as3722.txt       |   63 ++
 Documentation/devicetree/bindings/mfd/as3722.txt   |   69 ++
 .../bindings/regulator/as3722-reguator.txt         |  103 +++
 .../devicetree/bindings/rtc/rtc-as3722.txt         |   21 +
 drivers/gpio/Kconfig                               |    6 +
 drivers/gpio/Makefile                              |    1 +
 drivers/gpio/gpio-as3722.c                         |  444 ++++++++++
 drivers/mfd/Kconfig                                |   12 +
 drivers/mfd/Makefile                               |    1 +
 drivers/mfd/as3722.c                               |  463 ++++++++++
 drivers/regulator/Kconfig                          |    8 +
 drivers/regulator/Makefile                         |    1 +
 drivers/regulator/as3722-regulator.c               |  883 ++++++++++++++++++++
 drivers/rtc/Kconfig                                |   10 +
 drivers/rtc/Makefile                               |    1 +
 drivers/rtc/rtc-as3722.c                           |  315 +++++++
 include/linux/mfd/as3722.h                         |  425 ++++++++++
 17 files changed, 2826 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-as3722.txt
 create mode 100644 Documentation/devicetree/bindings/mfd/as3722.txt
 create mode 100644 Documentation/devicetree/bindings/regulator/as3722-reguator.txt
 create mode 100644 Documentation/devicetree/bindings/rtc/rtc-as3722.txt
 create mode 100644 drivers/gpio/gpio-as3722.c
 create mode 100644 drivers/mfd/as3722.c
 create mode 100644 drivers/regulator/as3722-regulator.c
 create mode 100644 drivers/rtc/rtc-as3722.c
 create mode 100644 include/linux/mfd/as3722.h
#7 lore raw

PATCH 2/4 gpio: add support for AMS AS3722 gpio driver

The AS3722 is a compact system PMU suitable for Mobile Phones, Tablet etc.

Add a driver to support accessing the 8 GPIOs found on the AMS AS3722 PMIC using gpiolib.

---
 .../devicetree/bindings/gpio/gpio-as3722.txt       |   63 +++
 drivers/gpio/Kconfig                               |    6 +
 drivers/gpio/Makefile                              |    1 +
 drivers/gpio/gpio-as3722.c                         |  444 ++++++++++++++++++++
 4 files changed, 514 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-as3722.txt
 create mode 100644 drivers/gpio/gpio-as3722.c
Documentation/devicetree/bindings/gpio/gpio-as3722.txt new file +63 -0
new file mode 100644
index 0000000..c94ca59
@@ -0,0 +1,63 @@
+AMS AS3722 GPIO bindings.
+This describe the properties of the gpio sub-node of the AMS AS3722 device tree.
+
+Required properties:
+--------------------
+- compatible: Must be "ams,as3722-gpio".
+- #address-cells: Number of address of the sub node of this node. Must be 1.
+- #size-cells: Size of addess cells. Must be 1.
+
+Sub node:
+--------
+The sub nodes provides the configuration of each gpio pins. The properties of the
+nodes are as follows:
+Required subnode properties:
+---------------------------
+reg: The GPIO number on which the properties need to be applied.
+
+Optional subnode properties:
+---------------------------
+bias-pull-up: The Pull-up for the pin to be enable.
+bias-pull-down: Pull down of the pins to be enable.
+bias-high-impedance: High impedance of the pin to be enable.
+open-drain: Pin is Open drain type.
+function: IO functionality of the pins. The valid options are:
+	gpio, intrrupt-output, vsup-vbat-low-undeb, interrupt-input,
+	pwm-input, voltage-stby, oc-powergood-sd0, powergood-output,
+	clk32k-output, watchdog-input, soft-reset-input, pwm-output,
+	vsup-vbat-low-deb, oc-powergood-sd6
+    Missing the function property will set the pin in GPIO mode.
+
+ams,enable-gpio-invert: Enable invert of the signal on GPIO pin.
+
+Example:
+	ams3722:: ams3722 {
+		compatible = "ams,as3722";
+		...
+		gpio-controller;
+		#gpio-cells = <2>;
+
+		gpio {
+			compatible = "ams,as3722-gpio";
+			#address-cells = <1>;
+			#size-cells = <0>;
+			gpio@0 {
+				reg = <0>;
+				bias-pull-down;
+			};
+
+			gpio@1 {
+				reg = <1>;
+				bias-pull-up;
+				ams,enable-gpio-invert;
+			};
+
+			...
+			gpio@5 {
+				reg = <5>;
+				unction  = "clk32k-output";
+			};
+			...
+		};
+		...
+	};
drivers/gpio/Kconfig +6 -0
index 5cb2181..e1f3ead 100644
@@ -368,6 +368,12 @@ config GPIO_ARIZONA
 	help
 	  Support for GPIOs on Wolfson Arizona class devices.
 
+config GPIO_AS3722
+	bool "AMS AS3722 PMICs GPIO"
+	depends on MFD_AS3722
+	help
+	  Select this option to enable GPIO driver for the AMS AS3722 PMIC.
+
 config GPIO_MAX7300
 	tristate "Maxim MAX7300 GPIO expander"
 	depends on I2C
drivers/gpio/Makefile +1 -0
index 98e23eb..d1715a0 100644
@@ -16,6 +16,7 @@ obj-$(CONFIG_GPIO_ADP5520)	+= gpio-adp5520.o
 obj-$(CONFIG_GPIO_ADP5588)	+= gpio-adp5588.o
 obj-$(CONFIG_GPIO_AMD8111)	+= gpio-amd8111.o
 obj-$(CONFIG_GPIO_ARIZONA)	+= gpio-arizona.o
+obj-$(CONFIG_GPIO_AS3722)	+= gpio-as3722.o
 obj-$(CONFIG_GPIO_BT8XX)	+= gpio-bt8xx.o
 obj-$(CONFIG_GPIO_CLPS711X)	+= gpio-clps711x.o
 obj-$(CONFIG_GPIO_CS5535)	+= gpio-cs5535.o
drivers/gpio/gpio-as3722.c new file +444 -0

444 lines not on this page · raw message

Signature · 1 line
1.7.1.1
#1 lore raw

PATCH 1/4 mfd: add support for AMS AS3722 PMIC

In reply to Laxman Dewangan

The AMS AS3722 is a compact system PMU suitable for mobile phones, tablets etc. It has 4 DC/DC step-down regulators, 3 DC/DC step-down controller, 11 LDOs, RTC, automatic battery, temperature and over-current monitoring, 8 GPIOs, ADC and wathdog.

Add mfd core driver for the AS3722 to support core functionality.

---
 Documentation/devicetree/bindings/mfd/as3722.txt |   69 ++++
 drivers/mfd/Kconfig                              |   12 +
 drivers/mfd/Makefile                             |    1 +
 drivers/mfd/as3722.c                             |  463 ++++++++++++++++++++++
 include/linux/mfd/as3722.h                       |  425 ++++++++++++++++++++
 5 files changed, 970 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mfd/as3722.txt
 create mode 100644 drivers/mfd/as3722.c
 create mode 100644 include/linux/mfd/as3722.h
Documentation/devicetree/bindings/mfd/as3722.txt new file +69 -0
new file mode 100644
index 0000000..d6bfd00
@@ -0,0 +1,69 @@
+* AMS AS3722 device tree bindings
+
+Required properties:
+-------------------
+- compatible : Must be "ams,as3722".
+- interrupt-controller : AS3722 has its own internal IRQs
+- #interrupt-cells : should be set to 2 for IRQ number and flags
+  The first cell is the IRQ number.
+  The second cell is the flags, encoded as the trigger masks from
+	  Documentation/devicetree/bindings/interrupts.txt
+- interrupt-parent : The parent interrupt controller.
+
+Optional properties:
+-------------------
+- gpio-controller: Marks the device node as a GPIO controller.
+- #gpio-cells: Number of GPIO cells. Should be two.
+	- first cell is the gpio pin number.
+	- second cell is used to specify the gpio polarity:
+		0 = active high
+		1 = active low
+
+Note: This gpio properties will be in the as3722 node.
+
+Sub-node compatible:
+-------------------
+The of_node of its all child node will have compatible so that it can
+get the child node handle and pass as the dev->of_node when registering
+mfd devices.
+MFD driver adds following mfd devices with their compatible values:
+as3722-gpio: The compatible value of this as3722 gpio driver is
+	     "ams,as3722-gpio";
+as3722-regulator: The compatible value of this as3722 regulator driver is
+	     "ams,as3722-regulator";
+as3722-rtc: The compatible value of this as3722 rtc driver is
+	     "ams,as3722-rtc";
+as3722-adc: The compatible value of this as3722 adc driver is
+	     "ams,as3722-adc";
+as3722-power-off: he compatible value of this as3722 power off driver is
+	     "ams,as3722-power-off".
+
+Example:
+--------
+ams3722 {
+	compatible = "ams,as3722";
+	reg = <0x48>
+
+	interrupt-parent = <&intc>;
+	interrupt-controller;
+	#interrupt-cells = <2>;
+
+	gpio-controller;
+	#gpio-cells = <2>;
+
+	gpio {
+		compatible = "ams,as3722-gpio";
+		...
+	};
+
+	rtc {
+		compatible = "ams,as3722-rtc";
+		...
+	};
+
+	regulators {
+		compatible = "ams,as3722-regulator";
+		...
+	};
+	...
+};
drivers/mfd/Kconfig +12 -0
index e0e46f5..251d451 100644
@@ -27,6 +27,18 @@ config MFD_AS3711
 	help
 	  Support for the AS3711 PMIC from AMS
 
+config MFD_AS3722
+	bool "AMS AS3722 Power Management IC"
+	select MFD_CORE
+	select REGMAP_I2C
+	select REGMAP_IRQ
+	depends on I2C=y && OF
+	help
+	  The AMS AS3722 is a compact system PMU suitable for mobile phones,
+	  tablet etc. It has 4 DC/DC step-down regulators, 3 DC/DC step-down
+	  controller, 11 LDOs, RTC, automatic battery, temperature and
+	  over current monitoring, GPIOs, ADC, watchdog.
+
 config PMIC_ADP5520
 	bool "Analog Devices ADP5520/01 MFD PMIC Core Support"
 	depends on I2C=y
drivers/mfd/Makefile +1 -0
index 15b905c..d8c2ba1 100644
@@ -162,3 +162,4 @@ obj-$(CONFIG_MFD_LM3533)	+= lm3533-core.o lm3533-ctrlbank.o
 obj-$(CONFIG_VEXPRESS_CONFIG)	+= vexpress-config.o vexpress-sysreg.o
 obj-$(CONFIG_MFD_RETU)		+= retu-mfd.o
 obj-$(CONFIG_MFD_AS3711)	+= as3711.o
+obj-$(CONFIG_MFD_AS3722)	+= as3722.o
drivers/mfd/as3722.c new file +463 -0

463 lines not on this page · raw message

include/linux/mfd/as3722.h new file +425 -0

425 lines not on this page · raw message

Signature · 1 line
1.7.1.1
#9 lore raw

PATCH 3/4 regulator: as3722: add regulator driver for AMS AS3722

In reply to Laxman Dewangan

The AS3722 is a compact system PMU suitable for Mobile Phones, Tablet etc. It has 4 DCDC step down regulators, 3 DCDC step down controller, 11 LDOs.

Add a driver to support accessing the DCDC/LDOs found on the AMS AS3722 PMIC using regulators.

---
 .../bindings/regulator/as3722-reguator.txt         |  103 +++
 drivers/regulator/Kconfig                          |    8 +
 drivers/regulator/Makefile                         |    1 +
 drivers/regulator/as3722-regulator.c               |  883 ++++++++++++++++++++
 4 files changed, 995 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/regulator/as3722-reguator.txt
 create mode 100644 drivers/regulator/as3722-regulator.c
Documentation/devicetree/bindings/regulator/as3722-reguator.txt new file +103 -0
new file mode 100644
index 0000000..414eda2
@@ -0,0 +1,103 @@
+AMS AS3722 regulator devicetree bindings.
+The regulator node is sub node of the AS3722 node.
+
+Required properties:
+- compatible : Must be ams,as3722-regulator.
+
+Optional properties:
+The input supply of regulators are the optional properties on the
+regulator node. The AS3722 is having 7 DCDC step-down regulators as
+sd[0-6], 10 LDOs as ldo[0-7], ldo[9-11]. The input supply of these
+regulators are provided through following properties:
+vsup-sd2-supply: Input supply for SD2.
+vsup-sd3-supply: Input supply for SD3.
+vsup-sd4-supply: Input supply for SD4.
+vsup-sd5-supply: Input supply for SD5.
+vin-ldo0-supply: Input supply for LDO0.
+vin-ldo1-6-supply: Input supply for LDO1 and LDO6.
+vin-ldo2-5-7-supply: Input supply for LDO2, LDO5 and LDO7.
+vin-ldo3-4-supply: Input supply for LDO3 and LDO4.
+vin-ldo9-10-supply: Input supply for LDO9 and LDO10.
+vin-ldo11-supply: Input supply for LDO11.
+
+Optional nodes:
+- regulators : Must contain a sub-node per regulator from the list below.
+	       Each sub-node should contain the constraints and initialization
+	       information for that regulator. See regulator.txt for a
+	       description of standard properties for these sub-nodes.
+	       Additional custom properties  are listed below.
+	       sd[0-6], ldo[0-7], ldo[9-11].
+
+	       Optional sub-node properties:
+		ams,ext-control: External control of the rail. The option of
+			this properties will tell which external input is
+			controlling this rail. Valid values are 0, 1, 2 ad 3.
+			0: There is no external control of this rail.
+			1: Rail is controlled by ENABLE1 input pin.
+			2: Rail is controlled by ENABLE1 input pin.
+			3: Rail is controlled by ENABLE1 input pin.
+		ams,enable-oc-config: Enable overcurrent configuration of the
+			rails. This is applicable for SD0, SD1 and SD6 only.
+			Other rails do not support this configuration.
+		ams,oc-trip-threshold-perphase: Overcurrent trip threshold
+			per phase. This is in milliAmp. The valid values are:
+			2500, 3000 and 3500. Please refer datasheet for more
+			detail.
+		ams,oc-alarm-threshold-perphase: Overcurrent alarm threshold
+			per phase. This is in milliAmp. The valid values are:
+			1600, 1800, 2000, 2200, 2400, 2600, 2800. This is only
+			supported for SD0.
+		ams,enable-tracking: Enable tracking with SD1, only supported
+			by LDO3.
+
+Example:
+	ams3722: ams3722 {
+		compatible = "ams,as3722";
+		reg = <0x40>;
+		...
+
+		regulators {
+			compatible = "ams,as3722-regulator";
+			vsup-sd2-supply = <...>;
+			sd0 {
+				regulator-name = "vdd_cpu";
+				regulator-min-microvolt = <700000>;
+				regulator-max-microvolt = <1400000>;
+				regulator-always-on;
+				ams,ext-control = <2>;
+				ams,enable-oc-config;
+				ams,oc-trip-threshold-perphase = <3500>;
+				ams,oc-alarm-threshold-perphase = <0>;
+			};
+
+			sd1 {
+				regulator-name = "vdd_core";
+				regulator-min-microvolt = <700000>;
+				regulator-max-microvolt = <1400000>;
+				regulator-always-on;
+				ams,ext-control = <1>;
+				ams,enable-oc-config;
+				ams,oc-trip-threshold-perphase = <2500>;
+				ams,oc-alarm-threshold-perphase = <0>;
+			};
+			sd2 {
+				regulator-name = "vddio_ddr";
+				regulator-min-microvolt = <1350000>;
+				regulator-max-microvolt = <1350000>;
+				regulator-always-on;
+			};
+			sd4 {
+				regulator-name = "avdd-hdmi-pex";
+				regulator-min-microvolt = <1050000>;
+				regulator-max-microvolt = <1050000>;
+				regulator-always-on;
+			};
+			sd5 {
+				regulator-name = "vdd-1v8";
+				regulator-min-microvolt = <1800000>;
+				regulator-max-microvolt = <1800000>;
+				regulator-always-on;
+			};
+				....
+		};
+	};
drivers/regulator/Kconfig +8 -0
index dfe5809..9869064 100644
@@ -133,6 +133,14 @@ config REGULATOR_AS3711
 	  This driver provides support for the voltage regulators on the
 	  AS3711 PMIC
 
+config REGULATOR_AS3722
+	tristate "AMS AS3722 PMIC Regulators"
+	depends on MFD_AS3722
+	help
+	  This driver provides support for the voltage regulators on the
+	  AS3722 PMIC. This will enable support for all the software
+	  controllable DCDC/LDO regulators.
+
 config REGULATOR_DA903X
 	tristate "Dialog Semiconductor DA9030/DA9034 regulators"
 	depends on PMIC_DA903X
drivers/regulator/Makefile +1 -0
index 185cce2..0b233bb 100644
@@ -18,6 +18,7 @@ obj-$(CONFIG_REGULATOR_AD5398) += ad5398.o
 obj-$(CONFIG_REGULATOR_ANATOP) += anatop-regulator.o
 obj-$(CONFIG_REGULATOR_ARIZONA) += arizona-micsupp.o arizona-ldo1.o
 obj-$(CONFIG_REGULATOR_AS3711) += as3711-regulator.o
+obj-$(CONFIG_REGULATOR_AS3722) += as3722-regulator.o
 obj-$(CONFIG_REGULATOR_DA903X)	+= da903x.o
 obj-$(CONFIG_REGULATOR_DA9052)	+= da9052-regulator.o
 obj-$(CONFIG_REGULATOR_DA9055)	+= da9055-regulator.o
drivers/regulator/as3722-regulator.c new file +883 -0

883 lines not on this page · raw message

Signature · 1 line
1.7.1.1
#13 lore raw

PATCH 4/4 drivers/rtc/rtc-as3722: add RTC driver

In reply to Laxman Dewangan

The AS3722 is a compact system PMU suitable for Mobile Phones, Tablet etc.

Add a driver to support accessing the RTC found on the AMS AS3722 PMIC using RTC framework.

---
 .../devicetree/bindings/rtc/rtc-as3722.txt         |   21 ++
 drivers/rtc/Kconfig                                |   10 +
 drivers/rtc/Makefile                               |    1 +
 drivers/rtc/rtc-as3722.c                           |  315 ++++++++++++++++++++
 4 files changed, 347 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/rtc/rtc-as3722.txt
 create mode 100644 drivers/rtc/rtc-as3722.c
Documentation/devicetree/bindings/rtc/rtc-as3722.txt new file +21 -0
new file mode 100644
index 0000000..17a9671
@@ -0,0 +1,21 @@
+AMS AS3722 RTC bindings.
+This describe the properties of the rtc sub-node of the AMS AS3722 device tree.
+
+Required properties:
+--------------------
+- compatible: Must be "ams,as3722-rtc".
+
+Optional properties:
+-------------------
+ams,enable_clk32k_out: Enable CLK32K output.
+
+Example:
+	ams3722:: ams3722 {
+		compatible = "ams,as3722";
+		...
+		rtc {
+			compatible = "ams,as3722-rtc";
+			ams,enable_clk32k_out;
+		};
+		...
+	};
drivers/rtc/Kconfig +10 -0
index 9654aa3..3a17788 100644
@@ -153,6 +153,16 @@ config RTC_DRV_88PM80X
 	  This driver can also be built as a module. If so, the module
 	  will be called rtc-88pm80x.
 
+config RTC_DRV_AS3722
+	tristate "AMS AS3722 RTC driver"
+	depends on MFD_AS3722
+	help
+	  If you say yes here you get support for the RTC of AMS AS3722 PMIC
+	  chips.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called rtc-as3722.
+
 config RTC_DRV_DS1307
 	tristate "Dallas/Maxim DS1307/37/38/39/40, ST M41T00, EPSON RX-8025"
 	help
drivers/rtc/Makefile +1 -0
index 2dff3d2..fdb5764 100644
@@ -20,6 +20,7 @@ obj-$(CONFIG_RTC_DRV_88PM860X)  += rtc-88pm860x.o
 obj-$(CONFIG_RTC_DRV_88PM80X)	+= rtc-88pm80x.o
 obj-$(CONFIG_RTC_DRV_AB3100)	+= rtc-ab3100.o
 obj-$(CONFIG_RTC_DRV_AB8500)	+= rtc-ab8500.o
+obj-$(CONFIG_RTC_DRV_AS3722)	+= rtc-as3722.o
 obj-$(CONFIG_RTC_DRV_AT32AP700X)+= rtc-at32ap700x.o
 obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o
 obj-$(CONFIG_RTC_DRV_AT91SAM9)	+= rtc-at91sam9.o
drivers/rtc/rtc-as3722.c new file +315 -0

315 lines not on this page · raw message

Signature · 1 line
1.7.1.1
#2 lore raw

Re: [PATCH 1/4] mfd: add support for AMS AS3722 PMIC

In reply to Laxman Dewangan
Quoted 26 lines · Laxman Dewangan

The AMS AS3722 is a compact system PMU suitable for mobile phones, tablets etc. It has 4 DC/DC step-down regulators, 3 DC/DC step-down controller, 11 LDOs, RTC, automatic battery, temperature and over-current monitoring, 8 GPIOs, ADC and wathdog.

Add mfd core driver for the AS3722 to support core functionality.

---
 Documentation/devicetree/bindings/mfd/as3722.txt |   69 ++++
 drivers/mfd/Kconfig                              |   12 +
 drivers/mfd/Makefile                             |    1 +
 drivers/mfd/as3722.c                             |  463 ++++++++++++++++++++++
 include/linux/mfd/as3722.h                       |  425 ++++++++++++++++++++
 5 files changed, 970 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mfd/as3722.txt
 create mode 100644 drivers/mfd/as3722.c
 create mode 100644 include/linux/mfd/as3722.h
Documentation/devicetree/bindings/mfd/as3722.txt new file +0 -0
new file mode 100644
index 0000000..d6bfd00

Documentation/devicetree/bindings/mfd/as3722.txt line 1

Quoted 1 line
Documentation/devicetree/bindings/mfd/as3722.txt new file +1 -0
@@ -0,0 +1,69 @@
+* AMS AS3722 device tree bindings

We know they're DT bindings, that's why they're here. How about swapping that out for the type of device we're supplying them for?

Documentation/devicetree/bindings/mfd/as3722.txt line 5

Quoted 3 lines
Documentation/devicetree/bindings/mfd/as3722.txt new file +3 -0
+Required properties:
+-------------------
+- compatible : Must be "ams,as3722".

- reg: <blah>

Documentation/devicetree/bindings/mfd/as3722.txt line 10

Quoted 5 lines
Documentation/devicetree/bindings/mfd/as3722.txt new file +5 -0
+- interrupt-controller : AS3722 has its own internal IRQs
+- #interrupt-cells : should be set to 2 for IRQ number and flags
+  The first cell is the IRQ number.
+  The second cell is the flags, encoded as the trigger masks from
+	  Documentation/devicetree/bindings/interrupts.txt

... using the #defines found in dt-bindings/irq.

Documentation/devicetree/bindings/mfd/as3722.txt line 20

Quoted 10 lines
Documentation/devicetree/bindings/mfd/as3722.txt new file +10 -0
+- interrupt-parent : The parent interrupt controller.
+
+Optional properties:
+-------------------
+- gpio-controller: Marks the device node as a GPIO controller.
+- #gpio-cells: Number of GPIO cells. Should be two.
+	- first cell is the gpio pin number.
+	- second cell is used to specify the gpio polarity:
+		0 = active high
+		1 = active low

Use the #includes in dt-bindings/gpio instead.

Documentation/devicetree/bindings/mfd/as3722.txt line 30

Quoted 9 lines
Documentation/devicetree/bindings/mfd/as3722.txt new file +9 -0
+Note: This gpio properties will be in the as3722 node.
+
+Sub-node compatible:
+-------------------
+The of_node of its all child node will have compatible so that it can
+get the child node handle and pass as the dev->of_node when registering
+mfd devices.
+MFD driver adds following mfd devices with their compatible values:
+as3722-gpio: The compatible value of this as3722 gpio driver is

Consider using uppercase device types: s/gpio/GPIO etc.

Documentation/devicetree/bindings/mfd/as3722.txt line 38

Quoted 8 lines
Documentation/devicetree/bindings/mfd/as3722.txt new file +8 -0
+	     "ams,as3722-gpio";
+as3722-regulator: The compatible value of this as3722 regulator driver is
+	     "ams,as3722-regulator";
+as3722-rtc: The compatible value of this as3722 rtc driver is
+	     "ams,as3722-rtc";
+as3722-adc: The compatible value of this as3722 adc driver is
+	     "ams,as3722-adc";
+as3722-power-off: he compatible value of this as3722 power off driver is

s/he/The

Documentation/devicetree/bindings/mfd/as3722.txt line 39

Quoted 1 line
Documentation/devicetree/bindings/mfd/as3722.txt new file +1 -0
+	     "ams,as3722-power-off".

I don't think there's any need to repleat these values. Just do:

ams,as3722-power-off: The compatible value of this as3722 power off driver.

Quoted 34 lines
Documentation/devicetree/bindings/mfd/as3722.txt new file +29 -0
+Example:
+--------
+ams3722 {
+	compatible = "ams,as3722";
+	reg = <0x48>
+
+	interrupt-parent = <&intc>;
+	interrupt-controller;
+	#interrupt-cells = <2>;
+
+	gpio-controller;
+	#gpio-cells = <2>;
+
+	gpio {
+		compatible = "ams,as3722-gpio";
+		...
+	};
+
+	rtc {
+		compatible = "ams,as3722-rtc";
+		...
+	};
+
+	regulators {
+		compatible = "ams,as3722-regulator";
+		...
+	};
+	...
+};
drivers/mfd/Kconfig +0 -0
index e0e46f5..251d451 100644

drivers/mfd/Kconfig config MFD_AS3711 · line 35

Quoted 9 lines
drivers/mfd/Kconfig +6 -0
@@ -27,6 +27,18 @@ config MFD_AS3711
 	help
 	  Support for the AS3711 PMIC from AMS
 
+config MFD_AS3722
+	bool "AMS AS3722 Power Management IC"
+	select MFD_CORE
+	select REGMAP_I2C
+	select REGMAP_IRQ
+	depends on I2C=y && OF

Do you need the "=y" here?

Quoted 48 lines
drivers/mfd/Kconfig +6 -0
+	help
+	  The AMS AS3722 is a compact system PMU suitable for mobile phones,
+	  tablet etc. It has 4 DC/DC step-down regulators, 3 DC/DC step-down
+	  controller, 11 LDOs, RTC, automatic battery, temperature and
+	  over current monitoring, GPIOs, ADC, watchdog.
+
 config PMIC_ADP5520
 	bool "Analog Devices ADP5520/01 MFD PMIC Core Support"
 	depends on I2C=y
drivers/mfd/Makefile +1 -0
index 15b905c..d8c2ba1 100644
@@ -162,3 +162,4 @@ obj-$(CONFIG_MFD_LM3533)	+= lm3533-core.o lm3533-ctrlbank.o
 obj-$(CONFIG_VEXPRESS_CONFIG)	+= vexpress-config.o vexpress-sysreg.o
 obj-$(CONFIG_MFD_RETU)		+= retu-mfd.o
 obj-$(CONFIG_MFD_AS3711)	+= as3711.o
+obj-$(CONFIG_MFD_AS3722)	+= as3722.o
drivers/mfd/as3722.c new file +24 -0
new file mode 100644
index 0000000..4f6c5c6
@@ -0,0 +1,463 @@
+/*
+ * Core driver for AMS AS3722 PMICs
+ *
+ * Copyright (C) 2013 ams AG
+ * Copyright (c) 2013, NVIDIA Corporation. All rights reserved.
+ *
+ * Author: Florian Lobmaier <[email protected]>
+ * Author: Laxman Dewangan <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ */
+

drivers/mfd/as3722.c line 34

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

Are we inherently including linux/of.h here, or is it genuinely not required?

Quoted 191 lines
drivers/mfd/as3722.c new file +191 -0
+#define AS3722_DEVICE_ID	0x0C
+
+static const struct resource as3722_rtc_resource[] = {
+	{
+		.name = "as3722-rtc-alarm",
+		.start = AS3722_IRQ_RTC_ALARM,
+		.end = AS3722_IRQ_RTC_ALARM,
+		.flags = IORESOURCE_IRQ,
+	},
+};
+
+static const struct resource as3722_adc_resource[] = {
+	{
+		.name = "as3722-adc",
+		.start = AS3722_IRQ_ADC,
+		.end = AS3722_IRQ_ADC,
+		.flags = IORESOURCE_IRQ,
+	},
+};
+
+static struct mfd_cell as3722_devs[] = {
+	{
+		.name = "as3722-gpio",
+		.of_compatible = "ams,as3722-gpio",
+	},
+	{
+		.name = "as3722-regulator",
+		.of_compatible = "ams,as3722-regulator",
+	},
+	{
+		.name = "as3722-rtc",
+		.of_compatible = "ams,as3722-rtc",
+		.num_resources = ARRAY_SIZE(as3722_rtc_resource),
+		.resources = as3722_rtc_resource,
+	},
+	{
+		.name = "as3722-adc",
+		.of_compatible = "ams,as3722-adc",
+		.num_resources = ARRAY_SIZE(as3722_adc_resource),
+		.resources = as3722_adc_resource,
+	},
+	{
+		.name = "as3722-power-off",
+		.of_compatible = "ams,as3722-power-off",
+	},
+};
+
+static const struct regmap_irq as3722_irqs[] = {
+	/* INT1 IRQs */
+	[AS3722_IRQ_LID] = {
+		.mask = AS3722_INTERRUPT_MASK1_LID,
+	},
+	[AS3722_IRQ_ACOK] = {
+		.mask = AS3722_INTERRUPT_MASK1_ACOK,
+	},
+	[AS3722_IRQ_ENABLE1] = {
+		.mask = AS3722_INTERRUPT_MASK1_ENABLE1,
+	},
+	[AS3722_IRQ_OCCUR_ALARM_SD0] = {
+		.mask = AS3722_INTERRUPT_MASK1_OCURR_ALARM_SD0,
+	},
+	[AS3722_IRQ_ONKEY_LONG_PRESS] = {
+		.mask = AS3722_INTERRUPT_MASK1_ONKEY_LONG,
+	},
+	[AS3722_IRQ_ONKEY] = {
+		.mask = AS3722_INTERRUPT_MASK1_ONKEY,
+	},
+	[AS3722_IRQ_OVTMP] = {
+		.mask = AS3722_INTERRUPT_MASK1_OVTMP,
+	},
+	[AS3722_IRQ_LOWBAT] = {
+		.mask = AS3722_INTERRUPT_MASK1_LOWBAT,
+	},
+
+	/* INT2 IRQs */
+	[AS3722_IRQ_SD0_LV] = {
+		.mask = AS3722_INTERRUPT_MASK2_SD0_LV,
+		.reg_offset = 1,
+	},
+	[AS3722_IRQ_SD1_LV] = {
+		.mask = AS3722_INTERRUPT_MASK2_SD1_LV,
+		.reg_offset = 1,
+	},
+	[AS3722_IRQ_SD2_LV] = {
+		.mask = AS3722_INTERRUPT_MASK2_SD2345_LV,
+		.reg_offset = 1,
+	},
+	[AS3722_IRQ_PWM1_OV_PROT] = {
+		.mask = AS3722_INTERRUPT_MASK2_PWM1_OV_PROT,
+		.reg_offset = 1,
+	},
+	[AS3722_IRQ_PWM2_OV_PROT] = {
+		.mask = AS3722_INTERRUPT_MASK2_PWM2_OV_PROT,
+		.reg_offset = 1,
+	},
+	[AS3722_IRQ_ENABLE2] = {
+		.mask = AS3722_INTERRUPT_MASK2_ENABLE2,
+		.reg_offset = 1,
+	},
+	[AS3722_IRQ_SD6_LV] = {
+		.mask = AS3722_INTERRUPT_MASK2_SD6_LV,
+		.reg_offset = 1,
+	},
+	[AS3722_IRQ_RTC_REP] = {
+		.mask = AS3722_INTERRUPT_MASK2_RTC_REP,
+		.reg_offset = 1,
+	},
+
+	/* INT3 IRQs */
+	[AS3722_IRQ_RTC_ALARM] = {
+		.mask = AS3722_INTERRUPT_MASK3_RTC_ALARM,
+		.reg_offset = 2,
+	},
+	[AS3722_IRQ_GPIO1] = {
+		.mask = AS3722_INTERRUPT_MASK3_GPIO1,
+		.reg_offset = 2,
+	},
+	[AS3722_IRQ_GPIO2] = {
+		.mask = AS3722_INTERRUPT_MASK3_GPIO2,
+		.reg_offset = 2,
+	},
+	[AS3722_IRQ_GPIO3] = {
+		.mask = AS3722_INTERRUPT_MASK3_GPIO3,
+		.reg_offset = 2,
+	},
+	[AS3722_IRQ_GPIO4] = {
+		.mask = AS3722_INTERRUPT_MASK3_GPIO4,
+		.reg_offset = 2,
+	},
+	[AS3722_IRQ_GPIO5] = {
+		.mask = AS3722_INTERRUPT_MASK3_GPIO5,
+		.reg_offset = 2,
+	},
+	[AS3722_IRQ_WATCHDOG] = {
+		.mask = AS3722_INTERRUPT_MASK3_WATCHDOG,
+		.reg_offset = 2,
+	},
+	[AS3722_IRQ_ENABLE3] = {
+		.mask = AS3722_INTERRUPT_MASK3_ENABLE3,
+		.reg_offset = 2,
+	},
+
+	/* INT4 IRQs */
+	[AS3722_IRQ_TEMP_SD0_SHUTDOWN] = {
+		.mask = AS3722_INTERRUPT_MASK4_TEMP_SD0_SHUTDOWN,
+		.reg_offset = 3,
+	},
+	[AS3722_IRQ_TEMP_SD1_SHUTDOWN] = {
+		.mask = AS3722_INTERRUPT_MASK4_TEMP_SD1_SHUTDOWN,
+		.reg_offset = 3,
+	},
+	[AS3722_IRQ_TEMP_SD2_SHUTDOWN] = {
+		.mask = AS3722_INTERRUPT_MASK4_TEMP_SD6_SHUTDOWN,
+		.reg_offset = 3,
+	},
+	[AS3722_IRQ_TEMP_SD0_ALARM] = {
+		.mask = AS3722_INTERRUPT_MASK4_TEMP_SD0_ALARM,
+		.reg_offset = 3,
+	},
+	[AS3722_IRQ_TEMP_SD1_ALARM] = {
+		.mask = AS3722_INTERRUPT_MASK4_TEMP_SD1_ALARM,
+		.reg_offset = 3,
+	},
+	[AS3722_IRQ_TEMP_SD6_ALARM] = {
+		.mask = AS3722_INTERRUPT_MASK4_TEMP_SD6_ALARM,
+		.reg_offset = 3,
+	},
+	[AS3722_IRQ_OCCUR_ALARM_SD6] = {
+		.mask = AS3722_INTERRUPT_MASK4_OCCUR_ALARM_SD6,
+		.reg_offset = 3,
+	},
+	[AS3722_IRQ_ADC] = {
+		.mask = AS3722_INTERRUPT_MASK4_ADC,
+		.reg_offset = 3,
+	},
+};
+
+static const struct regmap_irq_chip as3722_irq_chip = {
+	.name = "as3722",
+	.irqs = as3722_irqs,
+	.num_irqs = ARRAY_SIZE(as3722_irqs),
+	.num_regs = 4,
+	.status_base = AS3722_INTERRUPT_STATUS1_REG,
+	.mask_base = AS3722_INTERRUPT_MASK1_REG,
+};
+
+static int as3722_check_device_id(struct as3722 *as3722)
+{
+	u32 val;
+	int ret;
+

drivers/mfd/as3722.c line 236

Quoted 10 lines
drivers/mfd/as3722.c new file +10 -0
+	/* Check that this is actually a AS3722 */
+	ret = as3722_read(as3722, AS3722_ASIC_ID1_REG, &val);
+	if (ret < 0) {
+		dev_err(as3722->dev, "ASIC_ID1 read failed: %d\n", ret);
+		return ret;
+	}
+
+	if (val != AS3722_DEVICE_ID) {
+		dev_err(as3722->dev, "Device is not AS3722, ID is 0x%x\n", val);
+		return -ENOTSUPP;

Not an expert, but I think this is the wrong error to use.

I would consider using something like -ENODEV instead.

Quoted 20 lines
drivers/mfd/as3722.c new file +20 -0
+	}
+
+	ret = as3722_read(as3722, AS3722_ASIC_ID2_REG, &val);
+	if (ret < 0) {
+		dev_err(as3722->dev, "ASIC_ID2 read failed: %d\n", ret);
+		return ret;
+	}
+
+	dev_info(as3722->dev, "AS3722 with revision 0x%x found\n", val);
+	return 0;
+}
+
+static int as3722_configure_pullups(struct as3722 *as3722)
+{
+	int ret;
+	u32 val = 0;
+
+	if (as3722->enable_internal_int_pullup)
+		val |= AS3722_INT_PULL_UP;
+	if (as3722->enable_internal_i2c_pullup)

drivers/mfd/as3722.c line 266

Quoted 10 lines
drivers/mfd/as3722.c new file +10 -0
+		val |= AS3722_I2C_PULL_UP;
+
+	ret = as3722_update_bits(as3722, AS3722_IOVOLTAGE_REG,
+			AS3722_INT_PULL_UP | AS3722_I2C_PULL_UP, val);
+	if (ret < 0)
+		dev_err(as3722->dev, "IOVOLTAGE_REG update failed: %d\n", ret);
+	return ret;
+}
+
+#define reg_range(min, max)	{.range_min = min, .range_max = max,}

I was a little confused that it didn't finish with a ',' or ';', but I now see it in the struct below.

Can you put a new line separator here please?

Quoted 64 lines
drivers/mfd/as3722.c new file +64 -0
+static const struct regmap_range as3722_readable_ranges[] = {
+	reg_range(AS3722_SD0_VOLTAGE_REG, AS3722_SD6_VOLTAGE_REG),
+	reg_range(AS3722_GPIO0_CONTROL_REG, AS3722_LDO7_VOLTAGE_REG),
+	reg_range(AS3722_LDO9_VOLTAGE_REG, AS3722_REG_SEQU_MOD3_REG),
+	reg_range(AS3722_SD_PHSW_CTRL_REG, AS3722_PWM_CONTROL_H_REG),
+	reg_range(AS3722_WATCHDOG_TIMER_REG, AS3722_WATCHDOG_TIMER_REG),
+	reg_range(AS3722_WATCHDOG_SOFTWARE_SIGNAL_REG,
+				AS3722_BATTERY_VOLTAGE_MONITOR2_REG),
+	reg_range(AS3722_SD_CONTROL_REG, AS3722_PWM_VCONTROL4_REG),
+	reg_range(AS3722_BB_CHARGER_REG, AS3722_SRAM_REG),
+	reg_range(AS3722_RTC_ACCESS_REG, AS3722_RTC_ACCESS_REG),
+	reg_range(AS3722_RTC_STATUS_REG, AS3722_TEMP_STATUS_REG),
+	reg_range(AS3722_ADC0_CONTROL_REG, AS3722_ADC_CONFIGURATION_REG),
+	reg_range(AS3722_ASIC_ID1_REG, AS3722_ASIC_ID2_REG),
+	reg_range(AS3722_LOCK_REG, AS3722_LOCK_REG),
+};
+
+static const struct regmap_access_table as3722_readable_table = {
+	.yes_ranges = as3722_readable_ranges,
+	.n_yes_ranges = ARRAY_SIZE(as3722_readable_ranges),
+};
+
+static const struct regmap_range as3722_writable_ranges[] = {
+	reg_range(AS3722_SD0_VOLTAGE_REG, AS3722_SD6_VOLTAGE_REG),
+	reg_range(AS3722_GPIO0_CONTROL_REG, AS3722_LDO7_VOLTAGE_REG),
+	reg_range(AS3722_LDO9_VOLTAGE_REG, AS3722_GPIO_SIGNAL_OUT_REG),
+	reg_range(AS3722_REG_SEQU_MOD1_REG, AS3722_REG_SEQU_MOD3_REG),
+	reg_range(AS3722_SD_PHSW_CTRL_REG, AS3722_PWM_CONTROL_H_REG),
+	reg_range(AS3722_WATCHDOG_TIMER_REG, AS3722_WATCHDOG_TIMER_REG),
+	reg_range(AS3722_WATCHDOG_SOFTWARE_SIGNAL_REG,
+				AS3722_BATTERY_VOLTAGE_MONITOR2_REG),
+	reg_range(AS3722_SD_CONTROL_REG, AS3722_PWM_VCONTROL4_REG),
+	reg_range(AS3722_BB_CHARGER_REG, AS3722_SRAM_REG),
+	reg_range(AS3722_INTERRUPT_MASK1_REG, AS3722_TEMP_STATUS_REG),
+	reg_range(AS3722_ADC0_CONTROL_REG, AS3722_ADC1_CONTROL_REG),
+	reg_range(AS3722_ADC1_THRESHOLD_HI_MSB_REG,
+				AS3722_ADC_CONFIGURATION_REG),
+	reg_range(AS3722_LOCK_REG, AS3722_LOCK_REG),
+};
+
+static const struct regmap_access_table as3722_writable_table = {
+	.yes_ranges = as3722_writable_ranges,
+	.n_yes_ranges = ARRAY_SIZE(as3722_writable_ranges),
+};
+
+static const struct regmap_range as3722_voltaile_ranges[] = {
+	reg_range(AS3722_SD0_VOLTAGE_REG, AS3722_LDO11_VOLTAGE_REG),
+	reg_range(AS3722_SD_CONTROL_REG, AS3722_LDOCONTROL1_REG),
+};
+
+static const struct regmap_access_table as3722_volatile_table = {
+	.no_ranges = as3722_voltaile_ranges,
+	.n_no_ranges = ARRAY_SIZE(as3722_voltaile_ranges),
+};
+
+const struct regmap_config as3722_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.max_register = AS3722_MAX_REGISTER,
+	.cache_type = REGCACHE_RBTREE,
+	.rd_table = &as3722_readable_table,
+	.wr_table = &as3722_writable_table,
+	.volatile_table = &as3722_volatile_table,
+};

drivers/mfd/as3722.c line 340

Quoted 10 lines
drivers/mfd/as3722.c new file +10 -0
+
+static int as3722_get_core_dt_data(struct i2c_client *i2c,
+			struct as3722 *as3722)
+{
+	struct device_node *np = i2c->dev.of_node;
+	struct irq_data *irq_data;
+
+	if (!np) {
+		dev_err(&i2c->dev, "Device does not have of_node\n");
+		return -ENODEV;

I usually use -EINVAL for lack of pdata or np.

Perhaps this is suitable too.

Second opinion please?

Quoted 23 lines
drivers/mfd/as3722.c new file +23 -0
+	}
+
+	irq_data = irq_get_irq_data(i2c->irq);
+	if (!irq_data) {
+		dev_err(&i2c->dev, "Invalid IRQ: %d\n", i2c->irq);
+		return -EINVAL;
+	}
+
+	as3722->enable_internal_int_pullup = of_property_read_bool(np,
+					"ams,enable-internal-int-pullup");
+	as3722->enable_internal_i2c_pullup = of_property_read_bool(np,
+					"ams,enable-internal-i2c-pullup");
+	as3722->irq_flags = irqd_get_trigger_type(irq_data);
+	dev_dbg(&i2c->dev, "Irq flag is 0x%08lx\n", as3722->irq_flags);
+	return 0;
+}
+
+static int as3722_i2c_probe(struct i2c_client *i2c,
+			const struct i2c_device_id *id)
+{
+	struct as3722 *as3722;
+	unsigned long irq_flags;
+	int ret;

drivers/mfd/as3722.c line 373

Quoted 10 lines
drivers/mfd/as3722.c new file +10 -0
+
+	as3722 = devm_kzalloc(&i2c->dev, sizeof(struct as3722), GFP_KERNEL);
+	if (!as3722)
+		return -ENOMEM;
+
+	as3722->dev = &i2c->dev;
+	as3722->chip_irq = i2c->irq;
+	i2c_set_clientdata(i2c, as3722);
+
+	ret = as3722_get_core_dt_data(i2c, as3722);

How about "as3722_i2c_of_probe()" instead?

Quoted 51 lines
drivers/mfd/as3722.c new file +49 -0
+	if (ret < 0)
+		return ret;
+
+	as3722->regmap = devm_regmap_init_i2c(i2c, &as3722_regmap_config);
+	if (IS_ERR(as3722->regmap)) {
+		ret = PTR_ERR(as3722->regmap);
+		dev_err(&i2c->dev, "regmap_init failed with err: %d\n", ret);
 
 
+		return ret;
+	}
+
+	ret = as3722_check_device_id(as3722);
+	if (ret < 0)
+		return ret;
+
+	irq_flags = as3722->irq_flags | IRQF_ONESHOT;
+	ret = regmap_add_irq_chip(as3722->regmap, as3722->chip_irq,
+			irq_flags, -1, &as3722_irq_chip,
+			&as3722->irq_data);
+	if (ret < 0) {
+		dev_err(as3722->dev, "regmap_add_irq failed: %d\n", ret);
+		return ret;
+	}
+
+	ret = as3722_configure_pullups(as3722);
+	if (ret < 0)
+		goto scrub;
+
+	ret = mfd_add_devices(&i2c->dev, -1, as3722_devs,
+			ARRAY_SIZE(as3722_devs), NULL, 0,
+			regmap_irq_get_domain(as3722->irq_data));
+	if (ret) {
+		dev_err(as3722->dev, "mfd_add_devices() failed: %d\n", ret);
+		goto scrub;
+	}
+
+	dev_dbg(as3722->dev, "AS3722 core driver initialized successfully\n");
+	return 0;
+scrub:
+	regmap_del_irq_chip(as3722->chip_irq, as3722->irq_data);
+	return ret;
+}
+
+static int as3722_i2c_remove(struct i2c_client *i2c)
+{
+	struct as3722 *as3722 = i2c_get_clientdata(i2c);
+
+	mfd_remove_devices(as3722->dev);
+	regmap_del_irq_chip(as3722->chip_irq, as3722->irq_data);
+	return 0;

drivers/mfd/as3722.c line 432

Quoted 10 lines
drivers/mfd/as3722.c new file +10 -0
+}
+
+static const struct of_device_id as3722_of_match[] = {
+	{ .compatible = "ams,as3722", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, as3722_of_match);
+
+static const struct i2c_device_id as3722_i2c_id[] = {
+	{"as3722", 0},

Most likely a personal preference and certainly a nit, but I prefer:

	{ "as3722", 0 },
Quoted 4 lines
drivers/mfd/as3722.c new file +4 -0
+	{}
+};
+MODULE_DEVICE_TABLE(i2c, as3722_i2c_id);
+

drivers/mfd/as3722.c line 446

Quoted 10 lines
drivers/mfd/as3722.c new file +10 -0
+static struct i2c_driver as3722_i2c_driver = {
+	.driver = {
+		.name = "as3722",
+		.owner = THIS_MODULE,
+		.of_match_table = as3722_of_match,
+	},
+	.probe = as3722_i2c_probe,
+	.remove = as3722_i2c_remove,
+	.id_table = as3722_i2c_id,
+};

<----- From here ----->

drivers/mfd/as3722.c line 458

Quoted 11 lines
drivers/mfd/as3722.c new file +11 -0
+static int __init as3722_i2c_init(void)
+{
+	return i2c_add_driver(&as3722_i2c_driver);
+}
+subsys_initcall(as3722_i2c_init);
+
+static void __exit as3722_i2c_exit(void)
+{
+	i2c_del_driver(&as3722_i2c_driver);
+}
+module_exit(as3722_i2c_exit);

Boiler plate. Replace with module_i2c_driver(as3722_i2c_driver)

Quoted 389 lines
drivers/mfd/as3722.c new file +4 -0
+MODULE_DESCRIPTION("I2C support for AS3722 PMICs");
+MODULE_AUTHOR("Florian Lobmaier <[email protected]>");
+MODULE_AUTHOR("Laxman Dewangan <[email protected]>");
+MODULE_LICENSE("GPL");
include/linux/mfd/as3722.h new file +379 -0
new file mode 100644
index 0000000..ba99567
@@ -0,0 +1,425 @@
+/*
+ * as3722 definitions
+ *
+ * Copyright (C) 2013 ams
+ * Copyright (c) 2013, NVIDIA Corporation. All rights reserved.
+ *
+ * Author: Florian Lobmaier <[email protected]>
+ * Author: Laxman Dewangan <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ *
+ */
+
+#ifndef __LINUX_MFD_AS3722_H__
+#define __LINUX_MFD_AS3722_H__
+
+#include <linux/regmap.h>
+
+/* AS3722 registers */
+#define AS3722_SD0_VOLTAGE_REG				0x00
+#define AS3722_SD1_VOLTAGE_REG				0x01
+#define AS3722_SD2_VOLTAGE_REG				0x02
+#define AS3722_SD3_VOLTAGE_REG				0x03
+#define AS3722_SD4_VOLTAGE_REG				0x04
+#define AS3722_SD5_VOLTAGE_REG				0x05
+#define AS3722_SD6_VOLTAGE_REG				0x06
+#define AS3722_GPIO0_CONTROL_REG			0x08
+#define AS3722_GPIO1_CONTROL_REG			0x09
+#define AS3722_GPIO2_CONTROL_REG			0x0A
+#define AS3722_GPIO3_CONTROL_REG			0x0B
+#define AS3722_GPIO4_CONTROL_REG			0x0C
+#define AS3722_GPIO5_CONTROL_REG			0x0D
+#define AS3722_GPIO6_CONTROL_REG			0x0E
+#define AS3722_GPIO7_CONTROL_REG			0x0F
+#define AS3722_LDO0_VOLTAGE_REG				0x10
+#define AS3722_LDO1_VOLTAGE_REG				0x11
+#define AS3722_LDO2_VOLTAGE_REG				0x12
+#define AS3722_LDO3_VOLTAGE_REG				0x13
+#define AS3722_LDO4_VOLTAGE_REG				0x14
+#define AS3722_LDO5_VOLTAGE_REG				0x15
+#define AS3722_LDO6_VOLTAGE_REG				0x16
+#define AS3722_LDO7_VOLTAGE_REG				0x17
+#define AS3722_LDO9_VOLTAGE_REG				0x19
+#define AS3722_LDO10_VOLTAGE_REG			0x1A
+#define AS3722_LDO11_VOLTAGE_REG			0x1B
+#define AS3722_GPIO_DEB1_REG				0x1E
+#define AS3722_GPIO_DEB2_REG				0x1F
+#define AS3722_GPIO_SIGNAL_OUT_REG			0x20
+#define AS3722_GPIO_SIGNAL_IN_REG			0x21
+#define AS3722_REG_SEQU_MOD1_REG			0x22
+#define AS3722_REG_SEQU_MOD2_REG			0x23
+#define AS3722_REG_SEQU_MOD3_REG			0x24
+#define AS3722_SD_PHSW_CTRL_REG				0x27
+#define AS3722_SD_PHSW_STATUS				0x28
+#define AS3722_SD0_CONTROL_REG				0x29
+#define AS3722_SD1_CONTROL_REG				0x2A
+#define AS3722_SDmph_CONTROL_REG			0x2B
+#define AS3722_SD23_CONTROL_REG				0x2C
+#define AS3722_SD4_CONTROL_REG				0x2D
+#define AS3722_SD5_CONTROL_REG				0x2E
+#define AS3722_SD6_CONTROL_REG				0x2F
+#define AS3722_SD_DVM_REG				0x30
+#define AS3722_RESET_REASON_REG				0x31
+#define AS3722_BATTERY_VOLTAGE_MONITOR_REG		0x32
+#define AS3722_STARTUP_CONTROL_REG			0x33
+#define AS3722_RESET_TIMER_REG				0x34
+#define AS3722_REFERENCE_CONTROL_REG			0x35
+#define AS3722_RESET_CONTROL_REG			0x36
+#define AS3722_OVER_TEMP_CONTROL_REG			0x37
+#define AS3722_WATCHDOG_CONTROL_REG			0x38
+#define AS3722_REG_STANDBY_MOD1_REG			0x39
+#define AS3722_REG_STANDBY_MOD2_REG			0x3A
+#define AS3722_REG_STANDBY_MOD3_REG			0x3B
+#define AS3722_ENABLE_CTRL1_REG				0x3C
+#define AS3722_ENABLE_CTRL2_REG				0x3D
+#define AS3722_ENABLE_CTRL3_REG				0x3E
+#define AS3722_ENABLE_CTRL4_REG				0x3F
+#define AS3722_ENABLE_CTRL5_REG				0x40
+#define AS3722_PWM_CONTROL_L_REG			0x41
+#define AS3722_PWM_CONTROL_H_REG			0x42
+#define AS3722_WATCHDOG_TIMER_REG			0x46
+#define AS3722_WATCHDOG_SOFTWARE_SIGNAL_REG		0x48
+#define AS3722_IOVOLTAGE_REG				0x49
+#define AS3722_BATTERY_VOLTAGE_MONITOR2_REG		0x4A
+#define AS3722_SD_CONTROL_REG				0x4D
+#define AS3722_LDOCONTROL0_REG				0x4E
+#define AS3722_LDOCONTROL1_REG				0x4F
+#define AS3722_SD0_PROTECT_REG				0x50
+#define AS3722_SD6_PROTECT_REG				0x51
+#define AS3722_PWM_VCONTROL1_REG			0x52
+#define AS3722_PWM_VCONTROL2_REG			0x53
+#define AS3722_PWM_VCONTROL3_REG			0x54
+#define AS3722_PWM_VCONTROL4_REG			0x55
+#define AS3722_BB_CHARGER_REG				0x57
+#define AS3722_CTRL_SEQU1_REG				0x58
+#define AS3722_CTRL_SEQU2_REG				0x59
+#define AS3722_OVCURRENT_REG				0x5A
+#define AS3722_OVCURRENT_DEB_REG			0x5B
+#define AS3722_SDLV_DEB_REG				0x5C
+#define AS3722_OC_PG_CTRL_REG				0x5D
+#define AS3722_OC_PG_CTRL2_REG				0x5E
+#define AS3722_CTRL_STATUS				0x5F
+#define AS3722_RTC_CONTROL_REG				0x60
+#define AS3722_RTC_SECOND_REG				0x61
+#define AS3722_RTC_MINUTE_REG				0x62
+#define AS3722_RTC_HOUR_REG				0x63
+#define AS3722_RTC_DAY_REG				0x64
+#define AS3722_RTC_MONTH_REG				0x65
+#define AS3722_RTC_YEAR_REG				0x66
+#define AS3722_RTC_ALARM_SECOND_REG			0x67
+#define AS3722_RTC_ALARM_MINUTE_REG			0x68
+#define AS3722_RTC_ALARM_HOUR_REG			0x69
+#define AS3722_RTC_ALARM_DAY_REG			0x6A
+#define AS3722_RTC_ALARM_MONTH_REG			0x6B
+#define AS3722_RTC_ALARM_YEAR_REG			0x6C
+#define AS3722_SRAM_REG					0x6D
+#define AS3722_RTC_ACCESS_REG				0x6F
+#define AS3722_RTC_STATUS_REG				0x73
+#define AS3722_INTERRUPT_MASK1_REG			0x74
+#define AS3722_INTERRUPT_MASK2_REG			0x75
+#define AS3722_INTERRUPT_MASK3_REG			0x76
+#define AS3722_INTERRUPT_MASK4_REG			0x77
+#define AS3722_INTERRUPT_STATUS1_REG			0x78
+#define AS3722_INTERRUPT_STATUS2_REG			0x79
+#define AS3722_INTERRUPT_STATUS3_REG			0x7A
+#define AS3722_INTERRUPT_STATUS4_REG			0x7B
+#define AS3722_TEMP_STATUS_REG				0x7D
+#define AS3722_ADC0_CONTROL_REG				0x80
+#define AS3722_ADC1_CONTROL_REG				0x81
+#define AS3722_ADC0_MSB_RESULT_REG			0x82
+#define AS3722_ADC0_LSB_RESULT_REG			0x83
+#define AS3722_ADC1_MSB_RESULT_REG			0x84
+#define AS3722_ADC1_LSB_RESULT_REG			0x85
+#define AS3722_ADC1_THRESHOLD_HI_MSB_REG		0x86
+#define AS3722_ADC1_THRESHOLD_HI_LSB_REG		0x87
+#define AS3722_ADC1_THRESHOLD_LO_MSB_REG		0x88
+#define AS3722_ADC1_THRESHOLD_LO_LSB_REG		0x89
+#define AS3722_ADC_CONFIGURATION_REG			0x8A
+#define AS3722_ASIC_ID1_REG				0x90
+#define AS3722_ASIC_ID2_REG				0x91
+#define AS3722_LOCK_REG					0x9E
+#define AS3722_MAX_REGISTER				0xF4
+
+#define AS3722_SD0_EXT_ENABLE_MASK			0x03
+#define AS3722_SD1_EXT_ENABLE_MASK			0x0C
+#define AS3722_SD2_EXT_ENABLE_MASK			0x30
+#define AS3722_SD3_EXT_ENABLE_MASK			0xC0
+#define AS3722_SD4_EXT_ENABLE_MASK			0x03
+#define AS3722_SD5_EXT_ENABLE_MASK			0x0C
+#define AS3722_SD6_EXT_ENABLE_MASK			0x30
+#define AS3722_LDO0_EXT_ENABLE_MASK			0x03
+#define AS3722_LDO1_EXT_ENABLE_MASK			0x0C
+#define AS3722_LDO2_EXT_ENABLE_MASK			0x30
+#define AS3722_LDO3_EXT_ENABLE_MASK			0xC0
+#define AS3722_LDO4_EXT_ENABLE_MASK			0x03
+#define AS3722_LDO5_EXT_ENABLE_MASK			0x0C
+#define AS3722_LDO6_EXT_ENABLE_MASK			0x30
+#define AS3722_LDO7_EXT_ENABLE_MASK			0xC0
+#define AS3722_LDO9_EXT_ENABLE_MASK			0x0C
+#define AS3722_LDO10_EXT_ENABLE_MASK			0x30
+#define AS3722_LDO11_EXT_ENABLE_MASK			0xC0
+
+#define AS3722_OVCURRENT_SD0_ALARM_MASK			0x07
+#define AS3722_OVCURRENT_SD0_ALARM_SHIFT		0x01
+#define AS3722_OVCURRENT_SD0_TRIP_MASK			0x18
+#define AS3722_OVCURRENT_SD0_TRIP_SHIFT			0x03
+#define AS3722_OVCURRENT_SD1_TRIP_MASK			0x60
+#define AS3722_OVCURRENT_SD1_TRIP_SHIFT			0x05
+
+#define AS3722_OVCURRENT_SD6_ALARM_MASK			0x07
+#define AS3722_OVCURRENT_SD6_ALARM_SHIFT		0x01
+#define AS3722_OVCURRENT_SD6_TRIP_MASK			0x18
+#define AS3722_OVCURRENT_SD6_TRIP_SHIFT			0x03
+
+/* AS3722 register bits and bit masks */
+#define AS3722_LDO_ILIMIT_MASK				BIT(7)
+#define AS3722_LDO_ILIMIT_BIT				BIT(7)
+#define AS3722_LDO0_VSEL_MASK				0x1F
+#define AS3722_LDO0_VSEL_MIN				0x01
+#define AS3722_LDO0_VSEL_MAX				0x12
+#define AS3722_LDO0_NUM_VOLT				0x12
+#define AS3722_LDO3_VSEL_MASK				0x3F
+#define AS3722_LDO3_VSEL_MIN				0x01
+#define AS3722_LDO3_VSEL_MAX				0x2D
+#define AS3722_LDO3_NUM_VOLT				0x2D
+#define AS3722_LDO_VSEL_MASK				0x7F
+#define AS3722_LDO_VSEL_MIN				0x01
+#define AS3722_LDO_VSEL_MAX				0x7F
+#define AS3722_LDO_VSEL_DNU_MIN				0x25
+#define AS3722_LDO_VSEL_DNU_MAX				0x3F
+#define AS3722_LDO_NUM_VOLT				0x80
+
+#define AS3722_LDO0_CTRL				BIT(0)
+#define AS3722_LDO1_CTRL				BIT(1)
+#define AS3722_LDO2_CTRL				BIT(2)
+#define AS3722_LDO3_CTRL				BIT(3)
+#define AS3722_LDO4_CTRL				BIT(4)
+#define AS3722_LDO5_CTRL				BIT(5)
+#define AS3722_LDO6_CTRL				BIT(6)
+#define AS3722_LDO7_CTRL				BIT(7)
+#define AS3722_LDO9_CTRL				BIT(1)
+#define AS3722_LDO10_CTRL				BIT(2)
+#define AS3722_LDO11_CTRL				BIT(3)
+
+#define AS3722_LDO3_MODE_MASK				(3 << 6)
+#define AS3722_LDO3_MODE_VAL(n)				(((n) & 0x3) << 6)
+#define AS3722_LDO3_MODE_PMOS				AS3722_LDO3_MODE_VAL(0)
+#define AS3722_LDO3_MODE_PMOS_TRACKING			AS3722_LDO3_MODE_VAL(1)
+#define AS3722_LDO3_MODE_NMOS				AS3722_LDO3_MODE_VAL(2)
+#define AS3722_LDO3_MODE_SWITCH				AS3722_LDO3_MODE_VAL(3)
+
+#define AS3722_SD_VSEL_MASK				0x7F
+#define AS3722_SD0_VSEL_MIN				0x01
+#define AS3722_SD0_VSEL_MAX				0x5A
+#define AS3722_SD2_VSEL_MIN				0x01
+#define AS3722_SD2_VSEL_MAX				0x7F
+
+#define AS3722_SDn_CTRL(n)				BIT(n)
+
+#define AS3722_SD0_MODE_FAST				BIT(4)
+#define AS3722_SD1_MODE_FAST				BIT(4)
+#define AS3722_SD2_MODE_FAST				BIT(2)
+#define AS3722_SD3_MODE_FAST				BIT(6)
+#define AS3722_SD4_MODE_FAST				BIT(2)
+#define AS3722_SD5_MODE_FAST				BIT(2)
+#define AS3722_SD6_MODE_FAST				BIT(4)
+
+#define AS3722_POWER_OFF				BIT(1)
+
+#define AS3722_INTERRUPT_MASK1_LID			BIT(0)
+#define AS3722_INTERRUPT_MASK1_ACOK			BIT(1)
+#define AS3722_INTERRUPT_MASK1_ENABLE1			BIT(2)
+#define AS3722_INTERRUPT_MASK1_OCURR_ALARM_SD0		BIT(3)
+#define AS3722_INTERRUPT_MASK1_ONKEY_LONG		BIT(4)
+#define AS3722_INTERRUPT_MASK1_ONKEY			BIT(5)
+#define AS3722_INTERRUPT_MASK1_OVTMP			BIT(6)
+#define AS3722_INTERRUPT_MASK1_LOWBAT			BIT(7)
+
+#define AS3722_INTERRUPT_MASK2_SD0_LV			BIT(0)
+#define AS3722_INTERRUPT_MASK2_SD1_LV			BIT(1)
+#define AS3722_INTERRUPT_MASK2_SD2345_LV		BIT(2)
+#define AS3722_INTERRUPT_MASK2_PWM1_OV_PROT		BIT(3)
+#define AS3722_INTERRUPT_MASK2_PWM2_OV_PROT		BIT(4)
+#define AS3722_INTERRUPT_MASK2_ENABLE2			BIT(5)
+#define AS3722_INTERRUPT_MASK2_SD6_LV			BIT(6)
+#define AS3722_INTERRUPT_MASK2_RTC_REP			BIT(7)
+
+#define AS3722_INTERRUPT_MASK3_RTC_ALARM		BIT(0)
+#define AS3722_INTERRUPT_MASK3_GPIO1			BIT(1)
+#define AS3722_INTERRUPT_MASK3_GPIO2			BIT(2)
+#define AS3722_INTERRUPT_MASK3_GPIO3			BIT(3)
+#define AS3722_INTERRUPT_MASK3_GPIO4			BIT(4)
+#define AS3722_INTERRUPT_MASK3_GPIO5			BIT(5)
+#define AS3722_INTERRUPT_MASK3_WATCHDOG			BIT(6)
+#define AS3722_INTERRUPT_MASK3_ENABLE3			BIT(7)
+
+#define AS3722_INTERRUPT_MASK4_TEMP_SD0_SHUTDOWN	BIT(0)
+#define AS3722_INTERRUPT_MASK4_TEMP_SD1_SHUTDOWN	BIT(1)
+#define AS3722_INTERRUPT_MASK4_TEMP_SD6_SHUTDOWN	BIT(2)
+#define AS3722_INTERRUPT_MASK4_TEMP_SD0_ALARM		BIT(3)
+#define AS3722_INTERRUPT_MASK4_TEMP_SD1_ALARM		BIT(4)
+#define AS3722_INTERRUPT_MASK4_TEMP_SD6_ALARM		BIT(5)
+#define AS3722_INTERRUPT_MASK4_OCCUR_ALARM_SD6		BIT(6)
+#define AS3722_INTERRUPT_MASK4_ADC			BIT(7)
+
+#define AS3722_ADC1_INTERVAL_TIME			BIT(0)
+#define AS3722_ADC1_INT_MODE_ON				BIT(1)
+#define AS3722_ADC_BUF_ON				BIT(2)
+#define AS3722_ADC1_LOW_VOLTAGE_RANGE			BIT(5)
+#define AS3722_ADC1_INTEVAL_SCAN			BIT(6)
+#define AS3722_ADC1_INT_MASK				BIT(7)
+
+#define AS3722_ADC_MSB_VAL_MASK				0x7F
+#define AS3722_ADC_LSB_VAL_MASK				0x07
+
+#define AS3722_ADC0_CONV_START				BIT(7)
+#define AS3722_ADC0_CONV_NOTREADY			BIT(7)
+#define AS3722_ADC0_SOURCE_SELECT_MASK			0x1F
+
+#define AS3722_ADC1_CONV_START				BIT(7)
+#define AS3722_ADC1_CONV_NOTREADY			BIT(7)
+#define AS3722_ADC1_SOURCE_SELECT_MASK			0x1F
+
+/* GPIO modes */
+#define AS3722_GPIO_MODE_MASK				0x07
+#define AS3722_GPIO_MODE_INPUT				0x00
+#define AS3722_GPIO_MODE_OUTPUT_VDDH			0x01
+#define AS3722_GPIO_MODE_IO_OPEN_DRAIN			0x02
+#define AS3722_GPIO_MODE_ADC_IN				0x03
+#define AS3722_GPIO_MODE_INPUT_PULL_UP			0x04
+#define AS3722_GPIO_MODE_INPUT_PULL_DOWN		0x05
+#define AS3722_GPIO_MODE_IO_OPEN_DRAIN_PULL_UP		0x06
+#define AS3722_GPIO_MODE_OUTPUT_VDDL			0x07
+#define AS3722_GPIO_MODE_VAL(n)	\
+		((n) & AS3722_GPIO_MODE_MASK)
+
+#define AS3722_GPIO_INV					BIT(7)
+#define AS3722_GPIO_IOSF_MASK				0x78
+#define AS3722_GPIO_IOSF_VAL(n)				(((n) & 0xF) << 3)
+#define AS3722_GPIO_IOSF_NORMAL				AS3722_GPIO_IOSF_VAL(0)
+#define AS3722_GPIO_IOSF_INTERRUPT_OUT			AS3722_GPIO_IOSF_VAL(1)
+#define AS3722_GPIO_IOSF_VSUP_LOW_OUT			AS3722_GPIO_IOSF_VAL(2)
+#define AS3722_GPIO_IOSF_GPIO_INTERRUPT_IN		AS3722_GPIO_IOSF_VAL(3)
+#define AS3722_GPIO_IOSF_ISINK_PWM_IN			AS3722_GPIO_IOSF_VAL(4)
+#define AS3722_GPIO_IOSF_VOLTAGE_STBY			AS3722_GPIO_IOSF_VAL(5)
+#define AS3722_GPIO_IOSF_PWR_GOOD_OUT			AS3722_GPIO_IOSF_VAL(7)
+#define AS3722_GPIO_IOSF_Q32K_OUT			AS3722_GPIO_IOSF_VAL(8)
+#define AS3722_GPIO_IOSF_WATCHDOG_IN			AS3722_GPIO_IOSF_VAL(9)
+#define AS3722_GPIO_IOSF_SOFT_RESET_IN			AS3722_GPIO_IOSF_VAL(11)
+#define AS3722_GPIO_IOSF_PWM_OUT			AS3722_GPIO_IOSF_VAL(12)
+#define AS3722_GPIO_IOSF_VSUP_LOW_DEB_OUT		AS3722_GPIO_IOSF_VAL(13)
+#define AS3722_GPIO_IOSF_SD6_LOW_VOLT_LOW		AS3722_GPIO_IOSF_VAL(14)
+
+#define AS3722_GPIOn_SIGNAL(n)				BIT(n)
+#define AS3722_GPIOn_CONTROL_REG(n) \
+			(AS3722_GPIO0_CONTROL_REG + n)
+#define AS3722_I2C_PULL_UP				BIT(4)
+#define AS3722_INT_PULL_UP				BIT(5)
+
+#define AS3722_RTC_REP_WAKEUP_EN			BIT(0)
+#define AS3722_RTC_ALARM_WAKEUP_EN			BIT(1)
+#define AS3722_RTC_ON					BIT(2)
+#define AS3722_RTC_IRQMODE				BIT(3)
+#define AS3722_RTC_CLK32K_OUT_EN			BIT(5)
+
+#define AS3722_WATCHDOG_TIMER_MAX			0x7F
+#define AS3722_WATCHDOG_ON				BIT(0)
+#define AS3722_WATCHDOG_SW_SIG				BIT(0)
+
+#define AS3722_EXT_CONTROL_ENABLE1			0x1
+#define AS3722_EXT_CONTROL_ENABLE2			0x2
+#define AS3722_EXT_CONTROL_ENABLE3			0x3
+
+/* Interrupt IDs */
+enum as3722_irq {
+	AS3722_IRQ_LID,
+	AS3722_IRQ_ACOK,
+	AS3722_IRQ_ENABLE1,
+	AS3722_IRQ_OCCUR_ALARM_SD0,
+	AS3722_IRQ_ONKEY_LONG_PRESS,
+	AS3722_IRQ_ONKEY,
+	AS3722_IRQ_OVTMP,
+	AS3722_IRQ_LOWBAT,
+	AS3722_IRQ_SD0_LV,
+	AS3722_IRQ_SD1_LV,
+	AS3722_IRQ_SD2_LV,
+	AS3722_IRQ_PWM1_OV_PROT,
+	AS3722_IRQ_PWM2_OV_PROT,
+	AS3722_IRQ_ENABLE2,
+	AS3722_IRQ_SD6_LV,
+	AS3722_IRQ_RTC_REP,
+	AS3722_IRQ_RTC_ALARM,
+	AS3722_IRQ_GPIO1,
+	AS3722_IRQ_GPIO2,
+	AS3722_IRQ_GPIO3,
+	AS3722_IRQ_GPIO4,
+	AS3722_IRQ_GPIO5,
+	AS3722_IRQ_WATCHDOG,
+	AS3722_IRQ_ENABLE3,
+	AS3722_IRQ_TEMP_SD0_SHUTDOWN,
+	AS3722_IRQ_TEMP_SD1_SHUTDOWN,
+	AS3722_IRQ_TEMP_SD2_SHUTDOWN,
+	AS3722_IRQ_TEMP_SD0_ALARM,
+	AS3722_IRQ_TEMP_SD1_ALARM,
+	AS3722_IRQ_TEMP_SD6_ALARM,
+	AS3722_IRQ_OCCUR_ALARM_SD6,
+	AS3722_IRQ_ADC,

include/linux/mfd/as3722.h line 389

Quoted 10 lines
include/linux/mfd/as3722.h new file +10 -0
+	AS3722_IRQ_MAX,
+};
+
+struct as3722 {
+	struct device *dev;
+	struct regmap *regmap;
+	int chip_irq;
+	unsigned long irq_flags;
+	bool enable_internal_int_pullup;
+	bool enable_internal_i2c_pullup;

Just a nit:

Any way we can shorten these even a little? en_intern_int_pullup?

Quoted 36 lines
include/linux/mfd/as3722.h new file +36 -0
+	struct regmap_irq_chip_data *irq_data;
+};
+
+static inline int as3722_read(struct as3722 *as3722, u32 reg, u32 *dest)
+{
+	return regmap_read(as3722->regmap, reg, dest);
+}
+
+static inline int as3722_write(struct as3722 *as3722, u32 reg, u32 value)
+{
+	return regmap_write(as3722->regmap, reg, value);
+}
+
+static inline int as3722_block_read(struct as3722 *as3722, u32 reg,
+		int count, u8 *buf)
+{
+	return regmap_bulk_read(as3722->regmap, reg, buf, count);
+}
+
+static inline int as3722_block_write(struct as3722 *as3722, u32 reg,
+		int count, u8 *data)
+{
+	return regmap_bulk_write(as3722->regmap, reg, data, count);
+}
+
+static inline int as3722_update_bits(struct as3722 *as3722, u32 reg,
+		u32 mask, u8 val)
+{
+	return regmap_update_bits(as3722->regmap, reg, mask, val);
+}
+
+static inline int as3722_irq_get_virq(struct as3722 *as3722, int irq)
+{
+	return regmap_irq_get_virq(as3722->irq_data, irq);
+}
+#endif /* __LINUX_MFD_AS3722_H__ */
Signature · 8 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
maintainer
#3 lore raw

Re: [PATCH 1/4] mfd: add support for AMS AS3722 PMIC

In reply to Laxman Dewangan

Documentation/devicetree/bindings/mfd/as3722.txt line 39

Quoted 11 lines · Laxman Dewangan
Documentation/devicetree/bindings/mfd/as3722.txt new file +11 -0
+MFD driver adds following mfd devices with their compatible values:
+as3722-gpio: The compatible value of this as3722 gpio driver is
+	     "ams,as3722-gpio";
+as3722-regulator: The compatible value of this as3722 regulator driver is
+	     "ams,as3722-regulator";
+as3722-rtc: The compatible value of this as3722 rtc driver is
+	     "ams,as3722-rtc";
+as3722-adc: The compatible value of this as3722 adc driver is
+	     "ams,as3722-adc";
+as3722-power-off: he compatible value of this as3722 power off driver is
+	     "ams,as3722-power-off".

Personally I find this to be exposing implementation details of Linux - unless there is something reusable about the binding that'd allow it to be used to describe the contents of the chip the subnodes really aren't adding any information that wasn't present from just knowing the parent chip. If there were relocatable IPs it'd be a bit different.

drivers/mfd/as3722.c line 269

Quoted 4 lines
drivers/mfd/as3722.c new file +4 -0
+#define reg_range(min, max)	{.range_min = min, .range_max = max,}
+static const struct regmap_range as3722_readable_ranges[] = {
+	reg_range(AS3722_SD0_VOLTAGE_REG, AS3722_SD6_VOLTAGE_REG),
+	reg_range(AS3722_GPIO0_CONTROL_REG, AS3722_LDO7_VOLTAGE_REG),

If this macro is useful it should be a generic thing in the header, not done driver local.

drivers/mfd/as3722.c line 320

Quoted 4 lines
drivers/mfd/as3722.c new file +4 -0
+static const struct regmap_access_table as3722_volatile_table = {
+	.no_ranges = as3722_voltaile_ranges,
+	.n_no_ranges = ARRAY_SIZE(as3722_voltaile_ranges),
+};

This looks wrong - the registers listed in _volatile_ranges are in fact the ones that are not volatile. I'd rename _volatile_ranges to something like _cacheable_ranges.

drivers/mfd/as3722.c line 458

Quoted 11 lines
drivers/mfd/as3722.c new file +11 -0
+static int __init as3722_i2c_init(void)
+{
+	return i2c_add_driver(&as3722_i2c_driver);
+}
+subsys_initcall(as3722_i2c_init);
+
+static void __exit as3722_i2c_exit(void)
+{
+	i2c_del_driver(&as3722_i2c_driver);
+}
+module_exit(as3722_i2c_exit);

Modern systems should be able to use module_i2c_driver() and deferred probing - is this not working well?

maintainer
#10 lore raw

Re: [PATCH 3/4] regulator: as3722: add regulator driver for AMS AS3722

In reply to Laxman Dewangan

Documentation/devicetree/bindings/regulator/as3722-reguator.txt line 46

Quoted 3 lines · Laxman Dewangan
Documentation/devicetree/bindings/regulator/as3722-reguator.txt new file +3 -0
+               ams,enable-oc-config: Enable overcurrent configuration of the
+               ams,oc-trip-threshold-perphase: Overcurrent trip threshold
+               ams,oc-alarm-threshold-perphase: Overcurrent alarm threshold

These look like you should be implementing the current setting operations in the framework, probably mapping to the alarm limit if nothing else.

drivers/regulator/as3722-regulator.c line 384

Quoted 9 lines
drivers/regulator/as3722-regulator.c new file +9 -0
+static int as3722_ldo_get_voltage_sel(struct regulator_dev *rdev)
+{
+	int ret;
+
+	ret = regulator_get_voltage_sel_regmap(rdev);
+	if (ret >= 0x40)
+		ret -= 0x1B;
+	return ret;
+}

This looks very strange. What's going on here? A gap in the selectors? If that's the case you probably want to be using linear ranges.

drivers/regulator/as3722-regulator.c line 409

Quoted 5 lines
drivers/regulator/as3722-regulator.c new file +5 -0
+static struct regulator_ops as3722_ldo_extcntrl_ops = {
+	.get_voltage_sel = as3722_ldo_get_voltage_sel,
+	.set_voltage_sel = as3722_ldo_set_voltage_sel,
+	.list_voltage = regulator_list_voltage_linear,
+};

You ought to be providing map_voltage() too, same for some if not all of the other regulators.

drivers/regulator/as3722-regulator.c line 420

Quoted 10 lines
drivers/regulator/as3722-regulator.c new file +10 -0
+static unsigned int as3722_sd_get_mode(struct regulator_dev *dev)
+{
+	struct as3722_regulators *as3722_regs = rdev_get_drvdata(dev);
+	struct as3722 *as3722 = as3722_regs->as3722;
+	int id = rdev_get_id(dev);
+	u32 val;
+	int ret;
+
+	if (!as3722_reg_lookup[id].control_reg)
+		return -ERANGE;

That seems a bit of a random error code. -ENOTSUPP?

Quoted 4 lines
drivers/regulator/as3722-regulator.c new file +4 -0
+static int as3722_sd_list_voltage(struct regulator_dev *rdev, unsigned selector)
+{
+	if (selector >= AS3722_SD2_VSEL_MAX)
+		return -EINVAL;

drivers/regulator/as3722-regulator.c line 479

Quoted 10 lines
drivers/regulator/as3722-regulator.c new file +10 -0
+
+	selector++;
+	if (selector <= 0x40)
+		return 600000 + selector * 12500;
+	if (selector <= 0x70)
+		return 1400000 + (selector - 0x40) * 25000;
+	if (selector <= 0x7F)
+		return 2600000 + (selector - 0x70) * 50000;
+	return -EINVAL;
+}

Use linear ranges.

drivers/regulator/as3722-regulator.c line 602

Quoted 2 lines
drivers/regulator/as3722-regulator.c new file +2 -0
+static struct of_regulator_match as3722_regulator_matches[] = {
+	{.name = "sd0", },
	{ .name = "sd0", },

drivers/regulator/as3722-regulator.c line 806

Quoted 3 lines
drivers/regulator/as3722-regulator.c new file +3 -0
+		config.of_node = as3722_regulator_matches[id].of_node;
+		rdev = regulator_register(&as3722_regs->desc[id], &config);
+		if (IS_ERR(rdev)) {

devm_regualtor_register().

drivers/regulator/as3722-regulator.c line 821

Quoted 8 lines
drivers/regulator/as3722-regulator.c new file +8 -0
+		if (reg_config->ext_control) {
+			ret = regulator_enable_regmap(rdev);
+			if (ret < 0) {
+				dev_err(&pdev->dev,
+					"Regulator %d enable failed: %d\n",
+					id, ret);
+				goto scrub;
+			}

This looks wrong... why is the regualtor being enabled by something other than the core?

drivers/regulator/as3722-regulator.c line 877

Quoted 11 lines
drivers/regulator/as3722-regulator.c new file +11 -0
+static int __init as3722_regulator_init(void)
+{
+	return platform_driver_register(&as3722_regulator_driver);
+}
+subsys_initcall(as3722_regulator_init);
+
+static void __exit as3722_regulator_exit(void)
+{
+	platform_driver_unregister(&as3722_regulator_driver);
+}
+module_exit(as3722_regulator_exit);

module_platform_driver().

#4 lore raw

Re: [PATCH 1/4] mfd: add support for AMS AS3722 PMIC

In reply to Mark Brown
Quoted 4 lines · Mark Brown

* PGP Signed by an unknown key

On Tue, Sep 17, 2013 at 12:15:35PM +0530, Laxman Dewangan wrote:

Quoted 16 lines

Documentation/devicetree/bindings/mfd/as3722.txt line 39

Quoted 11 lines
Documentation/devicetree/bindings/mfd/as3722.txt new file +11 -0
+MFD driver adds following mfd devices with their compatible values:
+as3722-gpio: The compatible value of this as3722 gpio driver is
+	     "ams,as3722-gpio";
+as3722-regulator: The compatible value of this as3722 regulator driver is
+	     "ams,as3722-regulator";
+as3722-rtc: The compatible value of this as3722 rtc driver is
+	     "ams,as3722-rtc";
+as3722-adc: The compatible value of this as3722 adc driver is
+	     "ams,as3722-adc";
+as3722-power-off: he compatible value of this as3722 power off driver is
+	     "ams,as3722-power-off".

Personally I find this to be exposing implementation details of Linux - unless there is something reusable about the binding that'd allow it to be used to describe the contents of the chip the subnodes really aren't adding any information that wasn't present from just knowing the parent chip. If there were relocatable IPs it'd be a bit different.

Ok, then can we fix the the sub node name and parse these when adding mfd devices and set the pdev->dev.of_node of child devices. Like

parent_node {
    ...
    child1_node {
        ...
    };

    child1_node {
        ...
    };
};

and fix the node name of child1 and child2 and have this as part of mfd-cell's of_node_name.
So when we add the mfd devices, we look for these fixed name and if matches then set the dev->of_node for that child sub device.

This will avoid the code for getting child node pointer from parent node in each driver. We fix the child node name in any case.

maintainer
#14 lore raw

Re: [PATCH 4/4] drivers/rtc/rtc-as3722: add RTC driver

In reply to Laxman Dewangan

Documentation/devicetree/bindings/rtc/rtc-as3722.txt line 10

Quoted 3 lines · Laxman Dewangan
Documentation/devicetree/bindings/rtc/rtc-as3722.txt new file +3 -0
+Optional properties:
+-------------------
+ams,enable_clk32k_out: Enable CLK32K output.

This looks like it should be being supported via the clock API? This sort of thing is one of the reasons why I'm not too keen on representing the MFD structure directly in the DT.

#11 lore raw

Re: [PATCH 3/4] regulator: as3722: add regulator driver for AMS AS3722

In reply to Mark Brown
Quoted 12 lines

drivers/regulator/as3722-regulator.c line 384

Quoted 10 lines
drivers/regulator/as3722-regulator.c new file +9 -0
+static int as3722_ldo_get_voltage_sel(struct regulator_dev *rdev)
+{
+	int ret;
+
+	ret = regulator_get_voltage_sel_regmap(rdev);
+	if (ret >= 0x40)
+		ret -= 0x1B;
+	return ret;
+}

This looks very strange. What's going on here? A gap in the selectors? If that's the case you probably want to be using linear ranges.

Yes device does not want to be configure the vsel to 0x25 to 0x3F

01h-24h : V_LDO1=0.8V+ldo1_vsel*25mV
25h-3Fh : do not use
40h-7Fh : V_LDO1=1.725V+(ldo1_vsel-40h)*25mV

Let me use linear range.

Quoted 10 lines

drivers/regulator/as3722-regulator.c line 821

Quoted 8 lines
drivers/regulator/as3722-regulator.c new file +8 -0
+		if (reg_config->ext_control) {
+			ret = regulator_enable_regmap(rdev);
+			if (ret < 0) {
+				dev_err(&pdev->dev,
+					"Regulator %d enable failed: %d\n",
+					id, ret);
+				goto scrub;
+			}

This looks wrong... why is the regualtor being enabled by something other than the core?

When the rail is configured externally controlled then we are not providing the enable/disable callback to enable through register access. So core will not be able to enable it. Here, we are making sure that it is enabled through register write.
After that enable/disable can be done by device-input pin toggeling.

#5 lore raw

Re: [PATCH 1/4] mfd: add support for AMS AS3722 PMIC

In reply to Laxman Dewangan
Quoted 26 lines · Laxman Dewangan
Quoted 14 lines · Mark Brown

* PGP Signed by an unknown key

Quoted 10 lines · Laxman Dewangan
Documentation/devicetree/bindings/mfd/as3722.txt new file +4 -0
+MFD driver adds following mfd devices with their compatible values:
+as3722-gpio: The compatible value of this as3722 gpio driver is
+         "ams,as3722-gpio";
+as3722-regulator: The compatible value of this as3722 regulator 

driver is

Documentation/devicetree/bindings/mfd/as3722.txt new file +5 -0
+         "ams,as3722-regulator";
+as3722-rtc: The compatible value of this as3722 rtc driver is
+         "ams,as3722-rtc";
+as3722-adc: The compatible value of this as3722 adc driver is
+         "ams,as3722-adc";
Quoted 8 lines
Quoted 3 lines

+as3722-power-off: he compatible value of this as3722 power off driver is
+ "ams,as3722-power-off".

Personally I find this to be exposing implementation details of Linux - unless there is something reusable about the binding that'd allow it to be used to describe the contents of the chip the subnodes really aren't adding any information that wasn't present from just knowing the parent chip. If there were relocatable IPs it'd be a bit different.

Ok, then can we fix the the sub node name and parse these when adding mfd devices and set the pdev->dev.of_node of child devices. Like

Quoted 7 lines
parent_node {
    ...
    child1_node {
        ...
    };

    child1_node {

Sorry, just wanted to say child2_node here.

Quoted 11 lines

...

    };
};

and fix the node name of child1 and child2 and have this as part of mfd-cell's of_node_name.
So when we add the mfd devices, we look for these fixed name and if matches then set the dev->of_node for that child sub device.

This will avoid the code for getting child node pointer from parent node in each driver. We fix the child node name in any case.

#6 lore raw

Re: [PATCH 1/4] mfd: add support for AMS AS3722 PMIC

In reply to Laxman Dewangan
Quoted 6 lines · Laxman Dewangan

The AMS AS3722 is a compact system PMU suitable for mobile phones, tablets etc. It has 4 DC/DC step-down regulators, 3 DC/DC step-down controller, 11 LDOs, RTC, automatic battery, temperature and over-current monitoring, 8 GPIOs, ADC and wathdog.

Add mfd core driver for the AS3722 to support core functionality.

Nice patch description.

(although a couple typos: s/wathdog/watchdog/, s/mfd/MFD/)

Quoted 1 line

+Note: This gpio properties will be in the as3722 node.

Why? If there's a GPIO sub-node, why wouldn't all the GPIO properties appear there?

Documentation/devicetree/bindings/mfd/as3722.txt line 28

Quoted 5 lines
Documentation/devicetree/bindings/mfd/as3722.txt new file +5 -0
+Sub-node compatible:
+-------------------
+The of_node of its all child node will have compatible so that it can
+get the child node handle and pass as the dev->of_node when registering
+mfd devices.

That's very much Linux-specific details. Re-phrasing it as follows would make more sense:

==========
Each HW module within the PMIC is represented as a separate child node within the PMIC's main node. These nodes are described below:

GPIO controller
-------------------

Required properties:
compatible: Must be "ams,as3722-gpio"
...

Regulator
-------------------

...
==========

That also has the benefit of fully describing the content of all the child nodes in the binding, rather than only mentioning what the compatible values should be, and saying nothing else about the nodes.

But, as Mark asked, why are any child nodes needed at all? If e.g. an identical/re-usable GPIO HW block appears in many AMS PMICs, it possibly makes sense, but otherwise it doesn't.

#8 lore raw

Re: [PATCH 2/4] gpio: add support for AMS AS3722 gpio driver

In reply to Laxman Dewangan

Documentation/devicetree/bindings/gpio/gpio-as3722.txt line 2

Quoted 9 lines · Laxman Dewangan

The AS3722 is a compact system PMU suitable for Mobile Phones, Tablet etc.

Add a driver to support accessing the 8 GPIOs found on the AMS AS3722 PMIC using gpiolib.

Documentation/devicetree/bindings/gpio/gpio-as3722.txt +2 -0
 
+AMS AS3722 GPIO bindings.
+This describe the properties of the gpio sub-node of the AMS AS3722 device tree.

Oh, I see that you document each of the PMIC's sub-nodes separately. That's something you should explicitly mention in the top-level PMIC binding document. You should probably also mention the filenames of the binding documents for the child nodes.

Quoted 4 lines

+Required properties:

+--------------------
+- compatible: Must be "ams,as3722-gpio".
+- #address-cells: Number of address of the sub node of this node. Must be 1.

This isn't the number of addresses in the child node, but rather the number of cells in an (a single) address.

Quoted 1 line

+- #size-cells: Size of addess cells. Must be 1.

Similarly, this is the number of cells in a size specifier, nothing to do with address, and not the size of a cell.

You should put the GPIO properties (gpio-controller, perhaps interrupt-controller?) here instead of at the top level, since this HW block is what implements the GPIO controller, and perhaps a GPIO-interrupt controller.

Documentation/devicetree/bindings/gpio/gpio-as3722.txt line 14

Quoted 5 lines
Documentation/devicetree/bindings/gpio/gpio-as3722.txt +5 -0
+Sub node:
+--------
+The sub nodes provides the configuration of each gpio pins. The properties of the
+nodes are as follows:
+Required subnode properties:

You need a blank line there.

Documentation/devicetree/bindings/gpio/gpio-as3722.txt line 25

Quoted 11 lines

+---------------------------

Documentation/devicetree/bindings/gpio/gpio-as3722.txt +10 -0
+reg: The GPIO number on which the properties need to be applied.
+
+Optional subnode properties:
+---------------------------
+bias-pull-up: The Pull-up for the pin to be enable.
+bias-pull-down: Pull down of the pins to be enable.
+bias-high-impedance: High impedance of the pin to be enable.
+open-drain: Pin is Open drain type.
+function: IO functionality of the pins. The valid options are:
+	gpio, intrrupt-output, vsup-vbat-low-undeb, interrupt-input,

intrrupt? undeb?

Documentation/devicetree/bindings/gpio/gpio-as3722.txt line 26

Quoted 1 line
Documentation/devicetree/bindings/gpio/gpio-as3722.txt +1 -0
+	pwm-input, voltage-stby, oc-powergood-sd0, powergood-output,

stby might be better written out in full as standby.

Documentation/devicetree/bindings/gpio/gpio-as3722.txt line 28

Quoted 2 lines
Documentation/devicetree/bindings/gpio/gpio-as3722.txt +2 -0
+	clk32k-output, watchdog-input, soft-reset-input, pwm-output,
+	vsup-vbat-low-deb, oc-powergood-sd6

deb?

Documentation/devicetree/bindings/gpio/gpio-as3722.txt line 31

Quoted 3 lines
Documentation/devicetree/bindings/gpio/gpio-as3722.txt +3 -0
+    Missing the function property will set the pin in GPIO mode.
+
+ams,enable-gpio-invert: Enable invert of the signal on GPIO pin.

This looks very much like pinctrl. If there's a real need to be as verbose as pinctrl, perhaps this binding should actually be a full pinctrl binding? If not, perhaps you can just use the raw HW register values (with appropriate #defines to simplify setting up the properties). Something like:

pin-configuration = <0xf7348 0x5783 0x92348 ...>;

or:

pin-configruation = <

    AMS3722_PULL_UP | AMS_GPIO_INVERT ...,
    ...
    >;
#12 lore raw

Re: [PATCH 3/4] regulator: as3722: add regulator driver for AMS AS3722

In reply to Laxman Dewangan

Documentation/devicetree/bindings/regulator/as3722-reguator.txt

Quoted 8 lines · Laxman Dewangan

The AS3722 is a compact system PMU suitable for Mobile Phones, Tablet etc. It has 4 DCDC step down regulators, 3 DCDC step down controller, 11 LDOs.

Add a driver to support accessing the DCDC/LDOs found on the AMS AS3722 PMIC using regulators.

Documentation/devicetree/bindings/regulator/as3722-reguator.txt +0 -0

The filename is typo'd

Documentation/devicetree/bindings/regulator/as3722-reguator.txt line 2

Quoted 2 lines
Documentation/devicetree/bindings/regulator/as3722-reguator.txt +2 -0
+AMS AS3722 regulator devicetree bindings.
+The regulator node is sub node of the AS3722 node.

You probably want a blank line to separate the document title from the body text.

Documentation/devicetree/bindings/regulator/as3722-reguator.txt line 29

Quoted 7 lines
Documentation/devicetree/bindings/regulator/as3722-reguator.txt +7 -0
+Optional nodes:
+- regulators : Must contain a sub-node per regulator from the list below.
+	       Each sub-node should contain the constraints and initialization
+	       information for that regulator. See regulator.txt for a
+	       description of standard properties for these sub-nodes.
+	       Additional custom properties  are listed below.
+	       sd[0-6], ldo[0-7], ldo[9-11].

I think you want to prefix that last line with something like: "Valid regulator names are: ".

Documentation/devicetree/bindings/regulator/as3722-reguator.txt line 38

Quoted 7 lines
Documentation/devicetree/bindings/regulator/as3722-reguator.txt +7 -0
+		ams,ext-control: External control of the rail. The option of
+			this properties will tell which external input is
+			controlling this rail. Valid values are 0, 1, 2 ad 3.
+			0: There is no external control of this rail.
+			1: Rail is controlled by ENABLE1 input pin.
+			2: Rail is controlled by ENABLE1 input pin.
+			3: Rail is controlled by ENABLE1 input pin.

Those last 3 lines all say the same thing.