linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/6] Add initial support for ATC260x PMICs
@ 2020-08-21 22:19 Cristian Ciocaltea
  2020-08-21 22:19 ` [PATCH v2 1/6] dt-bindings: mfd: Add Actions Semi ATC260x PMIC binding Cristian Ciocaltea
                   ` (6 more replies)
  0 siblings, 7 replies; 23+ messages in thread
From: Cristian Ciocaltea @ 2020-08-21 22:19 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Dmitry Torokhov, Sebastian Reichel,
	Liam Girdwood, Mark Brown
  Cc: Manivannan Sadhasivam, Andreas Färber, linux-actions,
	devicetree, linux-kernel, linux-input, linux-pm

This is re-spin of the patch series submitted some time ago by Mani,
who added initial support (MFD core and regulators) for the Actions
Semi ATC260x PMICs:
https://lore.kernel.org/lkml/20190617155011.15376-1-manivannan.sadhasivam@linaro.org/

The ATC260x family of PMICs integrates Audio Codec, Power management,
Clock generation and GPIO controller blocks. There are currently 3
variants: ATC2603A, ATC2603C and ATC2609A.

In addition to the ATC2609A regulator functionality provided that time,
this patchset adds support for the ATC2603C variant, together with some
new functionalities for both chips: power controller and onkey input.
The ATC2603A variant remains unsupported for the moment.

This has been tested on RoseapplePi, a SBC based on the Action Semi S500
SoC, which integrates ATC2603C PMIC. An initial support for this board
has been already submitted:
https://lore.kernel.org/lkml/cover.1592123160.git.cristian.ciocaltea@gmail.com/

Please note that enabling the ATC260x PMICs on the compatible Actions
Semi Owl SoC based boards depends on the following:

* Actions Semi SIRQ driver (for PMIC DTS setup):
  https://lore.kernel.org/lkml/cover.1597852360.git.cristian.ciocaltea@gmail.com/

* I2C Atomic transfers in Actions Semi Owl driver (for proper operation
  of the power controller driver):
  https://lore.kernel.org/lkml/b086ef6d355d9730c839359e15eb06175283e323.1596485741.git.cristian.ciocaltea@gmail.com/
  
Thanks,
Cristi

Cristian Ciocaltea (6):
  dt-bindings: mfd: Add Actions Semi ATC260x PMIC binding
  mfd: Add MFD driver for ATC260x PMICs
  regulator: Add regulator driver for ATC260x PMICs
  power: reset: Add poweroff driver for ATC260x PMICs
  input: atc260x: Add onkey driver for ATC260x PMICs
  MAINTAINERS: Add entry for ATC260x PMIC

 .../bindings/mfd/actions,atc260x.yaml         | 221 ++++++++
 MAINTAINERS                                   |  12 +
 drivers/input/misc/Kconfig                    |  11 +
 drivers/input/misc/Makefile                   |   2 +-
 drivers/input/misc/atc260x-onkey.c            | 304 +++++++++++
 drivers/mfd/Kconfig                           |  18 +
 drivers/mfd/Makefile                          |   3 +
 drivers/mfd/atc260x-core.c                    | 290 ++++++++++
 drivers/mfd/atc260x-i2c.c                     |  73 +++
 drivers/power/reset/Kconfig                   |   8 +-
 drivers/power/reset/Makefile                  |   1 +
 drivers/power/reset/atc260x-poweroff.c        | 274 ++++++++++
 drivers/regulator/Kconfig                     |   8 +
 drivers/regulator/Makefile                    |   1 +
 drivers/regulator/atc260x-regulator.c         | 511 ++++++++++++++++++
 include/linux/mfd/atc260x/atc2603c.h          | 281 ++++++++++
 include/linux/mfd/atc260x/atc2609a.h          | 308 +++++++++++
 include/linux/mfd/atc260x/core.h              |  86 +++
 18 files changed, 2410 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mfd/actions,atc260x.yaml
 create mode 100644 drivers/input/misc/atc260x-onkey.c
 create mode 100644 drivers/mfd/atc260x-core.c
 create mode 100644 drivers/mfd/atc260x-i2c.c
 create mode 100644 drivers/power/reset/atc260x-poweroff.c
 create mode 100644 drivers/regulator/atc260x-regulator.c
 create mode 100644 include/linux/mfd/atc260x/atc2603c.h
 create mode 100644 include/linux/mfd/atc260x/atc2609a.h
 create mode 100644 include/linux/mfd/atc260x/core.h

-- 
2.28.0


^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH v2 1/6] dt-bindings: mfd: Add Actions Semi ATC260x PMIC binding
  2020-08-21 22:19 [PATCH v2 0/6] Add initial support for ATC260x PMICs Cristian Ciocaltea
@ 2020-08-21 22:19 ` Cristian Ciocaltea
  2020-09-08 21:47   ` Rob Herring
  2020-08-21 22:19 ` [PATCH v2 2/6] mfd: Add MFD driver for ATC260x PMICs Cristian Ciocaltea
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 23+ messages in thread
From: Cristian Ciocaltea @ 2020-08-21 22:19 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Dmitry Torokhov, Sebastian Reichel,
	Liam Girdwood, Mark Brown
  Cc: Manivannan Sadhasivam, Andreas Färber, linux-actions,
	devicetree, linux-kernel, linux-input, linux-pm

Add devicetree binding for Actions Semi ATC260x PMICs.

Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
---
 .../bindings/mfd/actions,atc260x.yaml         | 221 ++++++++++++++++++
 1 file changed, 221 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/actions,atc260x.yaml

diff --git a/Documentation/devicetree/bindings/mfd/actions,atc260x.yaml b/Documentation/devicetree/bindings/mfd/actions,atc260x.yaml
new file mode 100644
index 000000000000..4a55bbe1306e
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/actions,atc260x.yaml
@@ -0,0 +1,221 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/actions,atc260x.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Actions Semi ATC260x Power Management IC bindings
+
+maintainers:
+  - Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
+  - Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
+
+description: |
+  ATC260x series PMICs integrates Audio Codec, Power Management, RTC, IR
+  and GPIO controller blocks. Currently only the PM related functionalities
+  (i.e. regulators and system power-off/reboot) for the ATC2603C and ATC2609A
+  chip variants are supported.
+  ATC2603C includes 3 programmable DC-DC converters and 9 LDO regulators.
+  ATC2609A includes 5 programmable DC-DC converters and 10 LDO regulators.
+
+properties:
+  compatible:
+    enum:
+      - actions,atc2603c
+      - actions,atc2609a
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  pwrc:
+    type: object
+    description: |
+      The power controller integrated in ATC260x provides system power-off
+      and reboot operations.
+
+    properties:
+      compatible:
+        enum:
+          - actions,atc2603c-pwrc
+          - actions,atc2609a-pwrc
+
+    required:
+      - compatible
+
+    additionalProperties: false
+
+  onkey:
+    type: object
+    description: |
+      Use the ONKEY built into ATC260x PMICs as an input device reporting
+      power button status. ONKEY can be used to wakeup from low power
+      modes and force a reset on long press.
+
+    properties:
+      compatible:
+        enum:
+          - actions,atc2603c-onkey
+          - actions,atc2609a-onkey
+
+      actions,reset-time-sec:
+        description: |
+          Duration in seconds which the key should be kept pressed for device
+          to reset automatically. The hardware default is 8. Use 0 to disable
+          this functionality.
+        enum: [0, 6, 8, 10, 12]
+
+    required:
+      - compatible
+
+    additionalProperties: false
+
+  regulators:
+    type: object
+    description: |
+      List of child nodes specifying the regulators, depending on chip variant:
+      * ATC2603C: dcdc[1-3], ldo[1-3,5-8,11], switchldo1
+      * ATC2609A: dcdc[0-4], ldo[0-9]
+
+    properties:
+      compatible:
+        enum:
+          - actions,atc2603c-regulator
+          - actions,atc2609a-regulator
+
+      switchldo1:
+        type: object
+        $ref: ../regulator/regulator.yaml
+
+        properties:
+          regulator-name: true
+          regulator-boot-on: true
+          regulator-always-on: true
+          regulator-min-microvolt: true
+          regulator-max-microvolt: true
+          regulator-allow-bypass: true
+          regulator-active-discharge: true
+
+        additionalProperties: false
+
+    patternProperties:
+      "^(dcdc[0-4]|ldo[0-9]|ldo11|switchldo1)-supply$":
+        description: ATC260x voltage regulators supplies
+
+      "^(dcdc[0-4]|ldo[0-9]|ldo11)$":
+        type: object
+        $ref: ../regulator/regulator.yaml
+
+        properties:
+          regulator-name: true
+          regulator-boot-on: true
+          regulator-always-on: true
+          regulator-min-microvolt: true
+          regulator-max-microvolt: true
+          regulator-allow-bypass: true
+
+        additionalProperties: false
+
+    allOf:
+      - if:
+          properties:
+            compatible:
+              contains:
+                const: actions,atc2603c-regulator
+        then:
+          patternProperties:
+            "^(dcdc[0,4]|ldo[0,4,9])(-supply)?$": false
+
+            "^(ldo|dcdc)":
+              properties:
+                regulator-allow-bypass: false
+      - if:
+          properties:
+            compatible:
+              contains:
+                const: actions,atc2609a-regulator
+        then:
+          patternProperties:
+            "^(ldo11|switchldo1)(-supply)?$": false
+
+            "^(dcdc|ldo[3-9])":
+              properties:
+                regulator-allow-bypass: false
+
+    required:
+      - compatible
+
+    additionalProperties: false
+
+additionalProperties: false
+
+required:
+  - compatible
+  - reg
+  - interrupts
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+    i2c0 {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      pmic@65 {
+        compatible = "actions,atc2603c";
+        reg = <0x65>;
+        interrupt-parent = <&sirq>;
+        interrupts = <2 IRQ_TYPE_LEVEL_HIGH>;
+
+        pwrc {
+          compatible = "actions,atc2603c-pwrc";
+        };
+
+        onkey {
+          compatible = "actions,atc2603c-onkey";
+          actions,reset-time-sec = <6>;
+        };
+
+        regulators {
+          compatible = "actions,atc2603c-regulator";
+
+          dcdc1-supply = <&reg_5v0>;
+          dcdc3-supply = <&reg_5v0>;
+          ldo5-supply = <&reg_5v0>;
+          switchldo1-supply = <&vcc>;
+
+          vdd_cpu: dcdc1 {
+            regulator-name = "VDD_CPU";
+            regulator-min-microvolt = <700000>;
+            regulator-max-microvolt = <1400000>;
+            regulator-always-on;
+          };
+
+          vcc: dcdc3 {
+            regulator-name = "VCC";
+            regulator-min-microvolt = <2600000>;
+            regulator-max-microvolt = <3300000>;
+            regulator-always-on;
+          };
+
+          vcc_3v1: ldo5 {
+            regulator-name = "VCC_3V1";
+            regulator-min-microvolt = <2600000>;
+            regulator-max-microvolt = <3300000>;
+          };
+
+          sd_vcc: switchldo1 {
+            regulator-name = "SD_VCC";
+            regulator-min-microvolt = <3000000>;
+            regulator-max-microvolt = <3300000>;
+            regulator-always-on;
+            regulator-boot-on;
+          };
+        };
+      };
+    };
+
+...
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v2 2/6] mfd: Add MFD driver for ATC260x PMICs
  2020-08-21 22:19 [PATCH v2 0/6] Add initial support for ATC260x PMICs Cristian Ciocaltea
  2020-08-21 22:19 ` [PATCH v2 1/6] dt-bindings: mfd: Add Actions Semi ATC260x PMIC binding Cristian Ciocaltea
@ 2020-08-21 22:19 ` Cristian Ciocaltea
  2020-08-21 22:19 ` [PATCH v2 3/6] regulator: Add regulator " Cristian Ciocaltea
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 23+ messages in thread
From: Cristian Ciocaltea @ 2020-08-21 22:19 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Dmitry Torokhov, Sebastian Reichel,
	Liam Girdwood, Mark Brown
  Cc: Manivannan Sadhasivam, Andreas Färber, linux-actions,
	devicetree, linux-kernel, linux-input, linux-pm

Add initial MFD driver for Actions Semi ATC260x PMICs. ATC260x series
PMICs integrates Audio Codec, Power management, Clock generation and
GPIO controller blocks.

For the moment this driver only supports Regulator, Poweroff and Onkey
functionalities for the ATC2603C and ATC2609A chip variants.

Since the PMICs can be accessed using both I2C and SPI buses, the
following driver structure has been adopted:

           -----> atc260x-core.c (Implements core functionalities)
          /
ATC260x --------> atc260x-i2c.c (Implements I2C interface)
          \
           -----> atc260x-spi.c (Implements SPI interface - TODO)

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
[cristian: add ATC2603C variant, poweroff and onkey features, rework]
Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
---
 drivers/mfd/Kconfig                  |  18 ++
 drivers/mfd/Makefile                 |   3 +
 drivers/mfd/atc260x-core.c           | 290 +++++++++++++++++++++++++
 drivers/mfd/atc260x-i2c.c            |  73 +++++++
 include/linux/mfd/atc260x/atc2603c.h | 281 ++++++++++++++++++++++++
 include/linux/mfd/atc260x/atc2609a.h | 308 +++++++++++++++++++++++++++
 include/linux/mfd/atc260x/core.h     |  86 ++++++++
 7 files changed, 1059 insertions(+)
 create mode 100644 drivers/mfd/atc260x-core.c
 create mode 100644 drivers/mfd/atc260x-i2c.c
 create mode 100644 include/linux/mfd/atc260x/atc2603c.h
 create mode 100644 include/linux/mfd/atc260x/atc2609a.h
 create mode 100644 include/linux/mfd/atc260x/core.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 33df0837ab41..49cc3c2b46ad 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -2041,6 +2041,24 @@ config MFD_WCD934X
 	  This driver provides common support WCD934x audio codec and its
 	  associated Pin Controller, Soundwire Controller and Audio codec.
 
+config MFD_ATC260X
+	tristate
+	select MFD_CORE
+	select REGMAP
+	select REGMAP_IRQ
+
+config MFD_ATC260X_I2C
+	tristate "Actions Semi ATC260x PMICs with I2C"
+	select MFD_ATC260X
+	select REGMAP_I2C
+	depends on I2C
+	help
+	  Support for the Actions Semi ATC260x PMICs controlled via I2C.
+
+	  This driver provides common support for accessing the ATC2603C
+	  and ATC2609A chip variants, additional drivers must be enabled
+	  in order to use the functionality of the device.
+
 config MFD_KHADAS_MCU
 	tristate "Support for Khadas System control Microcontroller"
 	depends on I2C
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index a60e5f835283..508e104b6393 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -264,3 +264,6 @@ obj-$(CONFIG_MFD_STMFX) 	+= stmfx.o
 obj-$(CONFIG_MFD_KHADAS_MCU) 	+= khadas-mcu.o
 
 obj-$(CONFIG_SGI_MFD_IOC3)	+= ioc3.o
+
+obj-$(CONFIG_MFD_ATC260X)	+= atc260x-core.o
+obj-$(CONFIG_MFD_ATC260X_I2C)	+= atc260x-i2c.o
diff --git a/drivers/mfd/atc260x-core.c b/drivers/mfd/atc260x-core.c
new file mode 100644
index 000000000000..1c63beda64cd
--- /dev/null
+++ b/drivers/mfd/atc260x-core.c
@@ -0,0 +1,290 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Core MFD support for ATC260x PMICs
+ *
+ * Copyright (C) 2019 Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
+ * Copyright (C) 2020 Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
+ */
+
+#include <linux/interrupt.h>
+#include <linux/mfd/atc260x/core.h>
+#include <linux/mfd/core.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/regmap.h>
+
+static void regmap_lock_mutex(void *__mutex)
+{
+	struct mutex *mutex = __mutex;
+
+	/*
+	 * Using regmap within an atomic context (e.g. accessing a PMIC when
+	 * powering system down) is normally allowed only if the regmap type
+	 * is MMIO and the regcache type is either REGCACHE_NONE or
+	 * REGCACHE_FLAT. For slow buses like I2C and SPI, the regmap is
+	 * internally protected by a mutex which is acquired non-atomically.
+	 *
+	 * Let's improve this by using a customized locking scheme inspired
+	 * from I2C atomic transfer. See i2c_in_atomic_xfer_mode() for a
+	 * starting point.
+	 */
+	if (system_state > SYSTEM_RUNNING && irqs_disabled())
+		mutex_trylock(mutex);
+	else
+		mutex_lock(mutex);
+}
+
+static void regmap_unlock_mutex(void *__mutex)
+{
+	struct mutex *mutex = __mutex;
+
+	mutex_unlock(mutex);
+}
+
+static const struct regmap_config atc2603c_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 16,
+	.max_register = ATC2603C_SADDR,
+	.cache_type = REGCACHE_NONE,
+};
+
+static const struct regmap_config atc2609a_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 16,
+	.max_register = ATC2609A_SADDR,
+	.cache_type = REGCACHE_NONE,
+};
+
+static const struct regmap_irq atc2603c_regmap_irqs[] = {
+	REGMAP_IRQ_REG(ATC2603C_IRQ_AUDIO,	0, ATC2603C_INTS_MSK_AUDIO),
+	REGMAP_IRQ_REG(ATC2603C_IRQ_OV,		0, ATC2603C_INTS_MSK_OV),
+	REGMAP_IRQ_REG(ATC2603C_IRQ_OC,		0, ATC2603C_INTS_MSK_OC),
+	REGMAP_IRQ_REG(ATC2603C_IRQ_OT,		0, ATC2603C_INTS_MSK_OT),
+	REGMAP_IRQ_REG(ATC2603C_IRQ_UV,		0, ATC2603C_INTS_MSK_UV),
+	REGMAP_IRQ_REG(ATC2603C_IRQ_ALARM,	0, ATC2603C_INTS_MSK_ALARM),
+	REGMAP_IRQ_REG(ATC2603C_IRQ_ONOFF,	0, ATC2603C_INTS_MSK_ONOFF),
+	REGMAP_IRQ_REG(ATC2603C_IRQ_SGPIO,	0, ATC2603C_INTS_MSK_SGPIO),
+	REGMAP_IRQ_REG(ATC2603C_IRQ_IR,		0, ATC2603C_INTS_MSK_IR),
+	REGMAP_IRQ_REG(ATC2603C_IRQ_REMCON,	0, ATC2603C_INTS_MSK_REMCON),
+	REGMAP_IRQ_REG(ATC2603C_IRQ_POWER_IN,	0, ATC2603C_INTS_MSK_POWERIN),
+};
+
+static const struct regmap_irq atc2609a_regmap_irqs[] = {
+	REGMAP_IRQ_REG(ATC2609A_IRQ_AUDIO,	0, ATC2609A_INTS_MSK_AUDIO),
+	REGMAP_IRQ_REG(ATC2609A_IRQ_OV,		0, ATC2609A_INTS_MSK_OV),
+	REGMAP_IRQ_REG(ATC2609A_IRQ_OC,		0, ATC2609A_INTS_MSK_OC),
+	REGMAP_IRQ_REG(ATC2609A_IRQ_OT,		0, ATC2609A_INTS_MSK_OT),
+	REGMAP_IRQ_REG(ATC2609A_IRQ_UV,		0, ATC2609A_INTS_MSK_UV),
+	REGMAP_IRQ_REG(ATC2609A_IRQ_ALARM,	0, ATC2609A_INTS_MSK_ALARM),
+	REGMAP_IRQ_REG(ATC2609A_IRQ_ONOFF,	0, ATC2609A_INTS_MSK_ONOFF),
+	REGMAP_IRQ_REG(ATC2609A_IRQ_WKUP,	0, ATC2609A_INTS_MSK_WKUP),
+	REGMAP_IRQ_REG(ATC2609A_IRQ_IR,		0, ATC2609A_INTS_MSK_IR),
+	REGMAP_IRQ_REG(ATC2609A_IRQ_REMCON,	0, ATC2609A_INTS_MSK_REMCON),
+	REGMAP_IRQ_REG(ATC2609A_IRQ_POWER_IN,	0, ATC2609A_INTS_MSK_POWERIN),
+};
+
+static const struct regmap_irq_chip atc2603c_regmap_irq_chip = {
+	.name = "atc2603c",
+	.irqs = atc2603c_regmap_irqs,
+	.num_irqs = ARRAY_SIZE(atc2603c_regmap_irqs),
+	.num_regs = 1,
+	.status_base = ATC2603C_INTS_PD,
+	.mask_base = ATC2603C_INTS_MSK,
+	.mask_invert = true,
+};
+
+static const struct regmap_irq_chip atc2609a_regmap_irq_chip = {
+	.name = "atc2609a",
+	.irqs = atc2609a_regmap_irqs,
+	.num_irqs = ARRAY_SIZE(atc2609a_regmap_irqs),
+	.num_regs = 1,
+	.status_base = ATC2609A_INTS_PD,
+	.mask_base = ATC2609A_INTS_MSK,
+	.mask_invert = true,
+};
+
+static const struct resource atc2603c_onkey_resources[] = {
+	DEFINE_RES_IRQ(ATC2603C_IRQ_ONOFF),
+};
+
+static const struct resource atc2609a_onkey_resources[] = {
+	DEFINE_RES_IRQ(ATC2609A_IRQ_ONOFF),
+};
+
+static const struct mfd_cell atc2603c_mfd_cells[] = {
+	{
+		.name = "atc260x-regulator",
+		.of_compatible = "actions,atc2603c-regulator"
+	}, {
+		.name = "atc260x-pwrc",
+		.of_compatible = "actions,atc2603c-pwrc"
+	}, {
+		.name = "atc260x-onkey",
+		.of_compatible = "actions,atc2603c-onkey",
+		.num_resources = ARRAY_SIZE(atc2603c_onkey_resources),
+		.resources = atc2603c_onkey_resources,
+	},
+};
+
+static const struct mfd_cell atc2609a_mfd_cells[] = {
+	{
+		.name = "atc260x-regulator",
+		.of_compatible = "actions,atc2609a-regulator"
+	}, {
+		.name = "atc260x-pwrc",
+		.of_compatible = "actions,atc2609a-pwrc"
+	}, {
+		.name = "atc260x-onkey",
+		.of_compatible = "actions,atc2609a-onkey",
+		.num_resources = ARRAY_SIZE(atc2609a_onkey_resources),
+		.resources = atc2609a_onkey_resources,
+	},
+};
+
+static void atc260x_cmu_reset(struct atc260x *atc260x, u32 reg, u8 mask, u32 bit)
+{
+	/* Assert reset */
+	regmap_update_bits(atc260x->regmap, reg, mask, ~bit);
+
+	/* De-assert reset */
+	regmap_update_bits(atc260x->regmap, reg, mask, bit);
+}
+
+static int atc2603c_dev_init(struct atc260x *atc260x)
+{
+	/* Initialize interrupt block */
+	atc260x_cmu_reset(atc260x, ATC2603C_CMU_DEVRST,
+			  ATC2603C_CMU_DEVRST_INTS, ATC2603C_CMU_DEVRST_INTS);
+
+	/* Disable all interrupt sources */
+	regmap_write(atc260x->regmap, ATC2603C_INTS_MSK, 0);
+
+	/* Enable EXTIRQ pad */
+	return regmap_update_bits(atc260x->regmap, ATC2603C_PAD_EN,
+				  ATC2603C_PAD_EN_EXTIRQ, ATC2603C_PAD_EN_EXTIRQ);
+}
+
+static int atc2609a_dev_init(struct atc260x *atc260x)
+{
+	/* Initialize interrupt block */
+	atc260x_cmu_reset(atc260x, ATC2609A_CMU_DEVRST,
+			  ATC2609A_CMU_DEVRST_INTS, ATC2609A_CMU_DEVRST_INTS);
+
+	/* Disable all interrupt sources */
+	regmap_write(atc260x->regmap, ATC2609A_INTS_MSK, 0);
+
+	/* Enable EXTIRQ pad */
+	return regmap_update_bits(atc260x->regmap, ATC2609A_PAD_EN,
+				  ATC2609A_PAD_EN_EXTIRQ, ATC2609A_PAD_EN_EXTIRQ);
+}
+
+int atc260x_match_device(struct atc260x *atc260x, struct regmap_config *regmap_cfg)
+{
+	struct device *dev = atc260x->dev;
+	const void *of_data;
+
+	of_data = of_device_get_match_data(dev);
+	if (!of_data)
+		return -ENODEV;
+
+	atc260x->ic_type = (unsigned long)of_data;
+
+	switch (atc260x->ic_type) {
+	case ATC2603C:
+		*regmap_cfg = atc2603c_regmap_config;
+		atc260x->regmap_irq_chip = &atc2603c_regmap_irq_chip;
+		atc260x->cells = atc2603c_mfd_cells;
+		atc260x->nr_cells = ARRAY_SIZE(atc2603c_mfd_cells);
+		atc260x->type_name = "atc2603c";
+		atc260x->rev_reg = ATC2603C_CHIP_VER;
+		atc260x->dev_init = atc2603c_dev_init;
+		break;
+	case ATC2609A:
+		*regmap_cfg = atc2609a_regmap_config;
+		atc260x->regmap_irq_chip = &atc2609a_regmap_irq_chip;
+		atc260x->cells = atc2609a_mfd_cells;
+		atc260x->nr_cells = ARRAY_SIZE(atc2609a_mfd_cells);
+		atc260x->type_name = "atc2609a";
+		atc260x->rev_reg = ATC2609A_CHIP_VER;
+		atc260x->dev_init = atc2609a_dev_init;
+		break;
+	default:
+		dev_err(dev, "Unsupported ATC260x device type: %u\n",
+			atc260x->ic_type);
+		return -EINVAL;
+	}
+
+	atc260x->regmap_mutex = devm_kzalloc(dev, sizeof(*atc260x->regmap_mutex),
+					     GFP_KERNEL);
+	if (!atc260x->regmap_mutex)
+		return -ENOMEM;
+
+	mutex_init(atc260x->regmap_mutex);
+
+	regmap_cfg->lock = regmap_lock_mutex,
+	regmap_cfg->unlock = regmap_unlock_mutex,
+	regmap_cfg->lock_arg = atc260x->regmap_mutex;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(atc260x_match_device);
+
+int atc260x_device_probe(struct atc260x *atc260x)
+{
+	struct device *dev = atc260x->dev;
+	unsigned int chip_rev;
+	int ret;
+
+	if (!atc260x->irq) {
+		dev_err(dev, "No interrupt support\n");
+		return -EINVAL;
+	}
+
+	/* Initialize the hardware */
+	if (atc260x->dev_init)
+		atc260x->dev_init(atc260x);
+
+	ret = regmap_read(atc260x->regmap, atc260x->rev_reg, &chip_rev);
+	if (ret) {
+		dev_err(dev, "Failed to get chip revision\n");
+		return ret;
+	}
+
+	if (chip_rev < 0 || chip_rev > 31) {
+		dev_err(dev, "Unknown chip revision: %d\n", ret);
+		return -EINVAL;
+	}
+
+	atc260x->ic_ver = __ffs(chip_rev + 1U);
+
+	dev_info(dev, "Detected chip type %s rev.%c\n",
+		 atc260x->type_name, 'A' + atc260x->ic_ver);
+
+	ret = regmap_add_irq_chip(atc260x->regmap, atc260x->irq, IRQF_ONESHOT, -1,
+				  atc260x->regmap_irq_chip, &atc260x->irq_data);
+	if (ret) {
+		dev_err(dev, "Failed to add IRQ chip: %d\n", ret);
+		return ret;
+	}
+
+	ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE,
+				   atc260x->cells, atc260x->nr_cells, NULL, 0,
+				   regmap_irq_get_domain(atc260x->irq_data));
+	if (ret) {
+		dev_err(dev, "Failed to add child devices: %d\n", ret);
+		regmap_del_irq_chip(atc260x->irq, atc260x->irq_data);
+		return ret;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(atc260x_device_probe);
+
+int atc260x_device_remove(struct atc260x *atc260x)
+{
+	mfd_remove_devices(atc260x->dev);
+	regmap_del_irq_chip(atc260x->irq, atc260x->irq_data);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(atc260x_device_remove);
diff --git a/drivers/mfd/atc260x-i2c.c b/drivers/mfd/atc260x-i2c.c
new file mode 100644
index 000000000000..9795be35dc22
--- /dev/null
+++ b/drivers/mfd/atc260x-i2c.c
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * I2C bus interface for ATC260x PMICs
+ *
+ * Copyright (C) 2019 Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
+ * Copyright (C) 2020 Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
+ */
+
+#include <linux/i2c.h>
+#include <linux/mfd/atc260x/core.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/regmap.h>
+
+static int atc260x_i2c_probe(struct i2c_client *client,
+			     const struct i2c_device_id *id)
+{
+	struct atc260x *atc260x;
+	struct regmap_config regmap_cfg;
+	int ret;
+
+	atc260x = devm_kzalloc(&client->dev, sizeof(*atc260x), GFP_KERNEL);
+	if (!atc260x)
+		return -ENOMEM;
+
+	atc260x->dev = &client->dev;
+	atc260x->irq = client->irq;
+
+	ret = atc260x_match_device(atc260x, &regmap_cfg);
+	if (ret)
+		return ret;
+
+	i2c_set_clientdata(client, atc260x);
+
+	atc260x->regmap = devm_regmap_init_i2c(client, &regmap_cfg);
+	if (IS_ERR(atc260x->regmap)) {
+		ret = PTR_ERR(atc260x->regmap);
+		dev_err(&client->dev, "failed to init regmap: %d\n", ret);
+		return ret;
+	}
+
+	return atc260x_device_probe(atc260x);
+}
+
+static int atc260x_i2c_remove(struct i2c_client *client)
+{
+	struct atc260x *atc260x = i2c_get_clientdata(client);
+
+	return atc260x_device_remove(atc260x);
+}
+
+const struct of_device_id atc260x_i2c_of_match[] = {
+	{ .compatible = "actions,atc2603c", .data = (void *)ATC2603C },
+	{ .compatible = "actions,atc2609a", .data = (void *)ATC2609A },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(i2c, atc260x_i2c_of_match);
+
+static struct i2c_driver atc260x_i2c_driver = {
+	.driver = {
+		.name	= "atc260x",
+		.of_match_table	= of_match_ptr(atc260x_i2c_of_match),
+	},
+	.probe		= atc260x_i2c_probe,
+	.remove		= atc260x_i2c_remove,
+};
+
+module_i2c_driver(atc260x_i2c_driver);
+
+MODULE_DESCRIPTION("ATC260x PMICs I2C bus interface");
+MODULE_AUTHOR("Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>");
+MODULE_AUTHOR("Cristian Ciocaltea <cristian.ciocaltea@gmail.com>");
+MODULE_LICENSE("GPL v2");
diff --git a/include/linux/mfd/atc260x/atc2603c.h b/include/linux/mfd/atc260x/atc2603c.h
new file mode 100644
index 000000000000..07ac640ef3e1
--- /dev/null
+++ b/include/linux/mfd/atc260x/atc2603c.h
@@ -0,0 +1,281 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * ATC2603C PMIC register definitions
+ *
+ * Copyright (C) 2020 Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
+ */
+
+#ifndef __LINUX_MFD_ATC260X_ATC2603C_H
+#define __LINUX_MFD_ATC260X_ATC2603C_H
+
+enum atc2603c_irq_def {
+	ATC2603C_IRQ_AUDIO = 0,
+	ATC2603C_IRQ_OV,
+	ATC2603C_IRQ_OC,
+	ATC2603C_IRQ_OT,
+	ATC2603C_IRQ_UV,
+	ATC2603C_IRQ_ALARM,
+	ATC2603C_IRQ_ONOFF,
+	ATC2603C_IRQ_SGPIO,
+	ATC2603C_IRQ_IR,
+	ATC2603C_IRQ_REMCON,
+	ATC2603C_IRQ_POWER_IN,
+};
+
+/* PMU Registers */
+#define ATC2603C_PMU_SYS_CTL0			0x00
+#define ATC2603C_PMU_SYS_CTL1			0x01
+#define ATC2603C_PMU_SYS_CTL2			0x02
+#define ATC2603C_PMU_SYS_CTL3			0x03
+#define ATC2603C_PMU_SYS_CTL4			0x04
+#define ATC2603C_PMU_SYS_CTL5			0x05
+#define ATC2603C_PMU_SYS_CTL6			0x06
+#define ATC2603C_PMU_SYS_CTL7			0x07
+#define ATC2603C_PMU_SYS_CTL8			0x08
+#define ATC2603C_PMU_SYS_CTL9			0x09
+#define ATC2603C_PMU_BAT_CTL0			0x0A
+#define ATC2603C_PMU_BAT_CTL1			0x0B
+#define ATC2603C_PMU_VBUS_CTL0			0x0C
+#define ATC2603C_PMU_VBUS_CTL1			0x0D
+#define ATC2603C_PMU_WALL_CTL0			0x0E
+#define ATC2603C_PMU_WALL_CTL1			0x0F
+#define ATC2603C_PMU_SYS_PENDING		0x10
+#define ATC2603C_PMU_DC1_CTL0			0x11
+#define ATC2603C_PMU_DC1_CTL1			0x12 // Undocumented
+#define ATC2603C_PMU_DC1_CTL2			0x13 // Undocumented
+#define ATC2603C_PMU_DC2_CTL0			0x14
+#define ATC2603C_PMU_DC2_CTL1			0x15 // Undocumented
+#define ATC2603C_PMU_DC2_CTL2			0x16 // Undocumented
+#define ATC2603C_PMU_DC3_CTL0			0x17
+#define ATC2603C_PMU_DC3_CTL1			0x18 // Undocumented
+#define ATC2603C_PMU_DC3_CTL2			0x19 // Undocumented
+#define ATC2603C_PMU_DC4_CTL0			0x1A // Undocumented
+#define ATC2603C_PMU_DC4_CTL1			0x1B // Undocumented
+#define ATC2603C_PMU_DC5_CTL0			0x1C // Undocumented
+#define ATC2603C_PMU_DC5_CTL1			0x1D // Undocumented
+#define ATC2603C_PMU_LDO1_CTL			0x1E
+#define ATC2603C_PMU_LDO2_CTL			0x1F
+#define ATC2603C_PMU_LDO3_CTL			0x20
+#define ATC2603C_PMU_LDO4_CTL			0x21 // Undocumented
+#define ATC2603C_PMU_LDO5_CTL			0x22
+#define ATC2603C_PMU_LDO6_CTL			0x23
+#define ATC2603C_PMU_LDO7_CTL			0x24
+#define ATC2603C_PMU_LDO8_CTL			0x25 // Undocumented
+#define ATC2603C_PMU_LDO9_CTL			0x26 // Undocumented
+#define ATC2603C_PMU_LDO10_CTL			0x27 // Undocumented
+#define ATC2603C_PMU_LDO11_CTL			0x28
+#define ATC2603C_PMU_SWITCH_CTL			0x29
+#define ATC2603C_PMU_OV_CTL0			0x2A
+#define ATC2603C_PMU_OV_CTL1			0x2B
+#define ATC2603C_PMU_OV_STATUS			0x2C
+#define ATC2603C_PMU_OV_EN			0x2D
+#define ATC2603C_PMU_OV_INT_EN			0x2E
+#define ATC2603C_PMU_OC_CTL			0x2F
+#define ATC2603C_PMU_OC_STATUS			0x30
+#define ATC2603C_PMU_OC_EN			0x31
+#define ATC2603C_PMU_OC_INT_EN			0x32
+#define ATC2603C_PMU_UV_CTL0			0x33
+#define ATC2603C_PMU_UV_CTL1			0x34
+#define ATC2603C_PMU_UV_STATUS			0x35
+#define ATC2603C_PMU_UV_EN			0x36
+#define ATC2603C_PMU_UV_INT_EN			0x37
+#define ATC2603C_PMU_OT_CTL			0x38
+#define ATC2603C_PMU_CHARGER_CTL0		0x39
+#define ATC2603C_PMU_CHARGER_CTL1		0x3A
+#define ATC2603C_PMU_CHARGER_CTL2		0x3B
+#define ATC2603C_PMU_BAKCHARGER_CTL		0x3C // Undocumented
+#define ATC2603C_PMU_APDS_CTL			0x3D
+#define ATC2603C_PMU_AUXADC_CTL0		0x3E
+#define ATC2603C_PMU_AUXADC_CTL1		0x3F
+#define ATC2603C_PMU_BATVADC			0x40
+#define ATC2603C_PMU_BATIADC			0x41
+#define ATC2603C_PMU_WALLVADC			0x42
+#define ATC2603C_PMU_WALLIADC			0x43
+#define ATC2603C_PMU_VBUSVADC			0x44
+#define ATC2603C_PMU_VBUSIADC			0x45
+#define ATC2603C_PMU_SYSPWRADC			0x46
+#define ATC2603C_PMU_REMCONADC			0x47
+#define ATC2603C_PMU_SVCCADC			0x48
+#define ATC2603C_PMU_CHGIADC			0x49
+#define ATC2603C_PMU_IREFADC			0x4A
+#define ATC2603C_PMU_BAKBATADC			0x4B
+#define ATC2603C_PMU_ICTEMPADC			0x4C
+#define ATC2603C_PMU_AUXADC0			0x4D
+#define ATC2603C_PMU_AUXADC1			0x4E
+#define ATC2603C_PMU_AUXADC2			0x4F
+#define	ATC2603C_PMU_ICMADC			0x50
+#define ATC2603C_PMU_BDG_CTL			0x51 // Undocumented
+#define ATC2603C_RTC_CTL			0x52
+#define ATC2603C_RTC_MSALM			0x53
+#define ATC2603C_RTC_HALM			0x54
+#define ATC2603C_RTC_YMDALM			0x55
+#define ATC2603C_RTC_MS				0x56
+#define ATC2603C_RTC_H				0x57
+#define ATC2603C_RTC_DC				0x58
+#define ATC2603C_RTC_YMD			0x59
+#define ATC2603C_EFUSE_DAT			0x5A // Undocumented
+#define ATC2603C_EFUSECRTL1			0x5B // Undocumented
+#define ATC2603C_EFUSECRTL2			0x5C // Undocumented
+#define ATC2603C_PMU_FW_USE0			0x5D // Undocumented
+#define ATC2603C_PMU_FW_USE1			0x5E // Undocumented
+#define ATC2603C_PMU_FW_USE2			0x5F // Undocumented
+#define ATC2603C_PMU_FW_USE3			0x60 // Undocumented
+#define ATC2603C_PMU_FW_USE4			0x61 // Undocumented
+#define ATC2603C_PMU_ABNORMAL_STATUS		0x62
+#define ATC2603C_PMU_WALL_APDS_CTL		0x63
+#define ATC2603C_PMU_REMCON_CTL0		0x64
+#define ATC2603C_PMU_REMCON_CTL1		0x65
+#define ATC2603C_PMU_MUX_CTL0			0x66
+#define ATC2603C_PMU_SGPIO_CTL0			0x67
+#define ATC2603C_PMU_SGPIO_CTL1			0x68
+#define ATC2603C_PMU_SGPIO_CTL2			0x69
+#define ATC2603C_PMU_SGPIO_CTL3			0x6A
+#define ATC2603C_PMU_SGPIO_CTL4			0x6B
+#define ATC2603C_PWMCLK_CTL			0x6C
+#define ATC2603C_PWM0_CTL			0x6D
+#define ATC2603C_PWM1_CTL			0x6E
+#define ATC2603C_PMU_ADC_DBG0			0x70
+#define ATC2603C_PMU_ADC_DBG1			0x71
+#define ATC2603C_PMU_ADC_DBG2			0x72
+#define ATC2603C_PMU_ADC_DBG3			0x73
+#define ATC2603C_PMU_ADC_DBG4			0x74
+#define ATC2603C_IRC_CTL			0x80
+#define ATC2603C_IRC_STAT			0x81
+#define ATC2603C_IRC_CC				0x82
+#define ATC2603C_IRC_KDC			0x83
+#define ATC2603C_IRC_WK				0x84
+#define ATC2603C_IRC_RCC			0x85
+#define ATC2603C_IRC_FILTER			0x86
+
+/* AUDIO_OUT Registers */
+#define ATC2603C_AUDIOINOUT_CTL			0xA0
+#define ATC2603C_AUDIO_DEBUGOUTCTL		0xA1
+#define ATC2603C_DAC_DIGITALCTL			0xA2
+#define ATC2603C_DAC_VOLUMECTL0			0xA3
+#define ATC2603C_DAC_ANALOG0			0xA4
+#define ATC2603C_DAC_ANALOG1			0xA5
+#define ATC2603C_DAC_ANALOG2			0xA6
+#define ATC2603C_DAC_ANALOG3			0xA7
+
+/* AUDIO_IN Registers */
+#define ATC2603C_ADC_DIGITALCTL			0xA8
+#define ATC2603C_ADC_HPFCTL			0xA9
+#define ATC2603C_ADC_CTL			0xAA
+#define ATC2603C_AGC_CTL0			0xAB
+#define ATC2603C_AGC_CTL1			0xAC // Undocumented
+#define ATC2603C_AGC_CTL2			0xAD
+#define ATC2603C_ADC_ANALOG0			0xAE
+#define ATC2603C_ADC_ANALOG1			0xAF
+
+/* PCM_IF Registers */
+#define ATC2603C_PCM0_CTL			0xB0 // Undocumented
+#define ATC2603C_PCM1_CTL			0xB1 // Undocumented
+#define ATC2603C_PCM2_CTL			0xB2 // Undocumented
+#define ATC2603C_PCMIF_CTL			0xB3 // Undocumented
+
+/* CMU_CONTROL Registers */
+#define ATC2603C_CMU_DEVRST			0xC1 // Undocumented
+
+/* INTS Registers */
+#define ATC2603C_INTS_PD			0xC8
+#define ATC2603C_INTS_MSK			0xC9
+
+/* MFP Registers */
+#define ATC2603C_MFP_CTL			0xD0
+#define ATC2603C_PAD_VSEL			0xD1 // Undocumented
+#define ATC2603C_GPIO_OUTEN			0xD2
+#define ATC2603C_GPIO_INEN			0xD3
+#define ATC2603C_GPIO_DAT			0xD4
+#define ATC2603C_PAD_DRV			0xD5
+#define ATC2603C_PAD_EN				0xD6
+#define ATC2603C_DEBUG_SEL			0xD7 // Undocumented
+#define ATC2603C_DEBUG_IE			0xD8 // Undocumented
+#define ATC2603C_DEBUG_OE			0xD9 // Undocumented
+#define ATC2603C_BIST_START			0x0A // Undocumented
+#define ATC2603C_BIST_RESULT			0x0B // Undocumented
+#define ATC2603C_CHIP_VER			0xDC
+
+/* TWSI Registers */
+#define ATC2603C_SADDR				0xFF
+
+/* PMU_SYS_CTL0 Register Mask Bits */
+#define ATC2603C_PMU_SYS_CTL0_IR_WK_EN			BIT(5)
+#define ATC2603C_PMU_SYS_CTL0_RESET_WK_EN		BIT(6)
+#define ATC2603C_PMU_SYS_CTL0_HDSW_WK_EN		BIT(7)
+#define ATC2603C_PMU_SYS_CTL0_ALARM_WK_EN		BIT(8)
+#define ATC2603C_PMU_SYS_CTL0_REM_CON_WK_EN		BIT(9)
+#define ATC2603C_PMU_SYS_CTL0_RESTART_EN		BIT(10)
+#define ATC2603C_PMU_SYS_CTL0_SGPIOIRQ_WK_EN		BIT(11)
+#define ATC2603C_PMU_SYS_CTL0_ONOFF_SHORT_WK_EN		BIT(12)
+#define ATC2603C_PMU_SYS_CTL0_ONOFF_LONG_WK_EN		BIT(13)
+#define ATC2603C_PMU_SYS_CTL0_WALL_WK_EN		BIT(14)
+#define ATC2603C_PMU_SYS_CTL0_USB_WK_EN			BIT(15)
+#define ATC2603C_PMU_SYS_CTL0_WK_ALL			(GENMASK(15, 5) & (~BIT(10)))
+
+/* PMU_SYS_CTL1 Register Mask Bits */
+#define ATC2603C_PMU_SYS_CTL1_EN_S1			BIT(0)
+#define ATC2603C_PMU_SYS_CTL1_LB_S4_EN			BIT(2)
+#define ATC2603C_PMU_SYS_CTL1_LB_S4			GENMASK(4, 3)
+#define ATC2603C_PMU_SYS_CTL1_LB_S4_3_1V		BIT(4)
+#define ATC2603C_PMU_SYS_CTL1_IR_WK_FLAG		BIT(5)
+#define ATC2603C_PMU_SYS_CTL1_RESET_WK_FLAG		BIT(6)
+#define ATC2603C_PMU_SYS_CTL1_HDSW_WK_FLAG		BIT(7)
+#define ATC2603C_PMU_SYS_CTL1_ALARM_WK_FLAG		BIT(8)
+#define ATC2603C_PMU_SYS_CTL1_REM_CON_WK_FLAG		BIT(9)
+#define ATC2603C_PMU_SYS_CTL1_ONOFF_PRESS_RESET_IRQ_PD	BIT(10)
+#define ATC2603C_PMU_SYS_CTL1_SGPIOIRQ_WK_FLAG		BIT(11)
+#define ATC2603C_PMU_SYS_CTL1_ONOFF_SHORT_WK_FLAG	BIT(12)
+#define ATC2603C_PMU_SYS_CTL1_ONOFF_LONG_WK_FLAG	BIT(13)
+#define ATC2603C_PMU_SYS_CTL1_WALL_WK_FLAG		BIT(14)
+#define ATC2603C_PMU_SYS_CTL1_USB_WK_FLAG		BIT(15)
+
+/* PMU_SYS_CTL2 Register Mask Bits */
+#define ATC2603C_PMU_SYS_CTL2_PMU_A_EN			BIT(0)
+#define ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS_INT_EN	BIT(1)
+#define ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS_PD		BIT(2)
+#define ATC2603C_PMU_SYS_CTL2_S2TIMER			GENMASK(5, 3)
+#define ATC2603C_PMU_SYS_CTL2_S2_TIMER_EN		BIT(6)
+#define ATC2603C_PMU_SYS_CTL2_ONOFF_RESET_TIME_SEL	GENMASK(8, 7)
+#define ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS_RESET_EN	BIT(9)
+#define ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS_TIME		GENMASK(11, 10)
+#define ATC2603C_PMU_SYS_CTL2_ONOFF_INT_EN		BIT(12)
+#define ATC2603C_PMU_SYS_CTL2_ONOFF_LONG_PRESS		BIT(13)
+#define ATC2603C_PMU_SYS_CTL2_ONOFF_SHORT_PRESS		BIT(14)
+#define ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS		BIT(15)
+
+/* PMU_SYS_CTL3 Register Mask Bits */
+#define ATC2603C_PMU_SYS_CTL3_S2S3TOS1_TIMER		GENMASK(8, 7)
+#define ATC2603C_PMU_SYS_CTL3_S2S3TOS1_TIMER_EN		BIT(9)
+#define ATC2603C_PMU_SYS_CTL3_S3_TIMER			GENMASK(12, 10)
+#define ATC2603C_PMU_SYS_CTL3_S3_TIMER_EN		BIT(13)
+#define ATC2603C_PMU_SYS_CTL3_EN_S3			BIT(14)
+#define ATC2603C_PMU_SYS_CTL3_EN_S2			BIT(15)
+
+/* PMU_SYS_CTL5 Register Mask Bits */
+#define ATC2603C_PMU_SYS_CTL5_WALLWKDTEN		BIT(7)
+#define ATC2603C_PMU_SYS_CTL5_VBUSWKDTEN		BIT(8)
+#define ATC2603C_PMU_SYS_CTL5_REMCON_DECT_EN		BIT(9)
+#define ATC2603C_PMU_SYS_CTL5_ONOFF_8S_SEL		BIT(10)
+
+/* INTS_MSK Register Mask Bits */
+#define ATC2603C_INTS_MSK_AUDIO				BIT(0)
+#define ATC2603C_INTS_MSK_OV				BIT(1)
+#define ATC2603C_INTS_MSK_OC				BIT(2)
+#define ATC2603C_INTS_MSK_OT				BIT(3)
+#define ATC2603C_INTS_MSK_UV				BIT(4)
+#define ATC2603C_INTS_MSK_ALARM				BIT(5)
+#define ATC2603C_INTS_MSK_ONOFF				BIT(6)
+#define ATC2603C_INTS_MSK_SGPIO				BIT(7)
+#define ATC2603C_INTS_MSK_IR				BIT(8)
+#define ATC2603C_INTS_MSK_REMCON			BIT(9)
+#define ATC2603C_INTS_MSK_POWERIN			BIT(10)
+
+/* CMU_DEVRST Register Mask Bits */
+#define ATC2603C_CMU_DEVRST_MFP				BIT(1)
+#define ATC2603C_CMU_DEVRST_INTS			BIT(2)
+#define ATC2603C_CMU_DEVRST_AUDIO			BIT(4)
+
+/* PAD_EN Register Mask Bits */
+#define ATC2603C_PAD_EN_EXTIRQ				BIT(0)
+
+#endif /* __LINUX_MFD_ATC260X_ATC2603C_H */
diff --git a/include/linux/mfd/atc260x/atc2609a.h b/include/linux/mfd/atc260x/atc2609a.h
new file mode 100644
index 000000000000..b957d7bd73e9
--- /dev/null
+++ b/include/linux/mfd/atc260x/atc2609a.h
@@ -0,0 +1,308 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * ATC2609A PMIC register definitions
+ *
+ * Copyright (C) 2019 Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
+ */
+
+#ifndef __LINUX_MFD_ATC260X_ATC2609A_H
+#define __LINUX_MFD_ATC260X_ATC2609A_H
+
+enum atc2609a_irq_def {
+	ATC2609A_IRQ_AUDIO = 0,
+	ATC2609A_IRQ_OV,
+	ATC2609A_IRQ_OC,
+	ATC2609A_IRQ_OT,
+	ATC2609A_IRQ_UV,
+	ATC2609A_IRQ_ALARM,
+	ATC2609A_IRQ_ONOFF,
+	ATC2609A_IRQ_WKUP,
+	ATC2609A_IRQ_IR,
+	ATC2609A_IRQ_REMCON,
+	ATC2609A_IRQ_POWER_IN,
+};
+
+/* PMU Registers */
+#define ATC2609A_PMU_SYS_CTL0			0x00
+#define ATC2609A_PMU_SYS_CTL1			0x01
+#define ATC2609A_PMU_SYS_CTL2			0x02
+#define ATC2609A_PMU_SYS_CTL3			0x03
+#define ATC2609A_PMU_SYS_CTL4			0x04
+#define ATC2609A_PMU_SYS_CTL5			0x05
+#define ATC2609A_PMU_SYS_CTL6			0x06
+#define ATC2609A_PMU_SYS_CTL7			0x07
+#define ATC2609A_PMU_SYS_CTL8			0x08
+#define ATC2609A_PMU_SYS_CTL9			0x09
+#define ATC2609A_PMU_BAT_CTL0			0x0A
+#define ATC2609A_PMU_BAT_CTL1			0x0B
+#define ATC2609A_PMU_VBUS_CTL0			0x0C
+#define ATC2609A_PMU_VBUS_CTL1			0x0D
+#define ATC2609A_PMU_WALL_CTL0			0x0E
+#define ATC2609A_PMU_WALL_CTL1			0x0F
+#define ATC2609A_PMU_SYS_PENDING		0x10
+#define ATC2609A_PMU_APDS_CTL0			0x11
+#define ATC2609A_PMU_APDS_CTL1			0x12
+#define ATC2609A_PMU_APDS_CTL2			0x13
+#define ATC2609A_PMU_CHARGER_CTL		0x14
+#define ATC2609A_PMU_BAKCHARGER_CTL		0x15
+#define ATC2609A_PMU_SWCHG_CTL0			0x16
+#define ATC2609A_PMU_SWCHG_CTL1			0x17
+#define ATC2609A_PMU_SWCHG_CTL2			0x18
+#define ATC2609A_PMU_SWCHG_CTL3			0x19
+#define ATC2609A_PMU_SWCHG_CTL4			0x1A
+#define ATC2609A_PMU_DC_OSC			0x1B
+#define ATC2609A_PMU_DC0_CTL0			0x1C
+#define ATC2609A_PMU_DC0_CTL1			0x1D
+#define ATC2609A_PMU_DC0_CTL2			0x1E
+#define ATC2609A_PMU_DC0_CTL3			0x1F
+#define ATC2609A_PMU_DC0_CTL4			0x20
+#define ATC2609A_PMU_DC0_CTL5			0x21
+#define ATC2609A_PMU_DC0_CTL6			0x22
+#define ATC2609A_PMU_DC1_CTL0			0x23
+#define ATC2609A_PMU_DC1_CTL1			0x24
+#define ATC2609A_PMU_DC1_CTL2			0x25
+#define ATC2609A_PMU_DC1_CTL3			0x26
+#define ATC2609A_PMU_DC1_CTL4			0x27
+#define ATC2609A_PMU_DC1_CTL5			0x28
+#define ATC2609A_PMU_DC1_CTL6			0x29
+#define ATC2609A_PMU_DC2_CTL0			0x2A
+#define ATC2609A_PMU_DC2_CTL1			0x2B
+#define ATC2609A_PMU_DC2_CTL2			0x2C
+#define ATC2609A_PMU_DC2_CTL3			0x2D
+#define ATC2609A_PMU_DC2_CTL4			0x2E
+#define ATC2609A_PMU_DC2_CTL5			0x2F
+#define ATC2609A_PMU_DC2_CTL6			0x30
+#define ATC2609A_PMU_DC3_CTL0			0x31
+#define ATC2609A_PMU_DC3_CTL1			0x32
+#define ATC2609A_PMU_DC3_CTL2			0x33
+#define ATC2609A_PMU_DC3_CTL3			0x34
+#define ATC2609A_PMU_DC3_CTL4			0x35
+#define ATC2609A_PMU_DC3_CTL5			0x36
+#define ATC2609A_PMU_DC3_CTL6			0x37
+#define ATC2609A_PMU_DC_ZR			0x38
+#define ATC2609A_PMU_LDO0_CTL0			0x39
+#define ATC2609A_PMU_LDO0_CTL1			0x3A
+#define ATC2609A_PMU_LDO1_CTL0			0x3B
+#define ATC2609A_PMU_LDO1_CTL1			0x3C
+#define ATC2609A_PMU_LDO2_CTL0			0x3D
+#define ATC2609A_PMU_LDO2_CTL1			0x3E
+#define ATC2609A_PMU_LDO3_CTL0			0x3F
+#define ATC2609A_PMU_LDO3_CTL1			0x40
+#define ATC2609A_PMU_LDO4_CTL0			0x41
+#define ATC2609A_PMU_LDO4_CTL1			0x42
+#define ATC2609A_PMU_LDO5_CTL0			0x43
+#define ATC2609A_PMU_LDO5_CTL1			0x44
+#define ATC2609A_PMU_LDO6_CTL0			0x45
+#define ATC2609A_PMU_LDO6_CTL1			0x46
+#define ATC2609A_PMU_LDO7_CTL0			0x47
+#define ATC2609A_PMU_LDO7_CTL1			0x48
+#define ATC2609A_PMU_LDO8_CTL0			0x49
+#define ATC2609A_PMU_LDO8_CTL1			0x4A
+#define ATC2609A_PMU_LDO9_CTL			0x4B
+#define ATC2609A_PMU_OV_INT_EN			0x4C
+#define ATC2609A_PMU_OV_STATUS			0x4D
+#define ATC2609A_PMU_UV_INT_EN			0x4E
+#define ATC2609A_PMU_UV_STATUS			0x4F
+#define ATC2609A_PMU_OC_INT_EN			0x50
+#define ATC2609A_PMU_OC_STATUS			0x51
+#define ATC2609A_PMU_OT_CTL			0x52
+#define ATC2609A_PMU_CM_CTL0			0x53
+#define ATC2609A_PMU_FW_USE0			0x54
+#define ATC2609A_PMU_FW_USE1			0x55
+#define ATC2609A_PMU_ADC12B_I			0x56
+#define ATC2609A_PMU_ADC12B_V			0x57
+#define ATC2609A_PMU_ADC12B_DUMMY		0x58
+#define ATC2609A_PMU_AUXADC_CTL0		0x59
+#define ATC2609A_PMU_AUXADC_CTL1		0x5A
+#define ATC2609A_PMU_BATVADC			0x5B
+#define ATC2609A_PMU_BATIADC			0x5C
+#define ATC2609A_PMU_WALLVADC			0x5D
+#define ATC2609A_PMU_WALLIADC			0x5E
+#define ATC2609A_PMU_VBUSVADC			0x5F
+#define ATC2609A_PMU_VBUSIADC			0x60
+#define ATC2609A_PMU_SYSPWRADC			0x61
+#define ATC2609A_PMU_REMCONADC			0x62
+#define ATC2609A_PMU_SVCCADC			0x63
+#define ATC2609A_PMU_CHGIADC			0x64
+#define ATC2609A_PMU_IREFADC			0x65
+#define ATC2609A_PMU_BAKBATADC			0x66
+#define ATC2609A_PMU_ICTEMPADC			0x67
+#define ATC2609A_PMU_AUXADC0			0x68
+#define ATC2609A_PMU_AUXADC1			0x69
+#define ATC2609A_PMU_AUXADC2			0x6A
+#define ATC2609A_PMU_AUXADC3			0x6B
+#define ATC2609A_PMU_ICTEMPADC_ADJ		0x6C
+#define ATC2609A_PMU_BDG_CTL			0x6D
+#define ATC2609A_RTC_CTL			0x6E
+#define ATC2609A_RTC_MSALM			0x6F
+#define ATC2609A_RTC_HALM			0x70
+#define ATC2609A_RTC_YMDALM			0x71
+#define ATC2609A_RTC_MS				0x72
+#define ATC2609A_RTC_H				0x73
+#define ATC2609A_RTC_DC				0x74
+#define ATC2609A_RTC_YMD			0x75
+#define ATC2609A_EFUSE_DAT			0x76
+#define ATC2609A_EFUSECRTL1			0x77
+#define ATC2609A_EFUSECRTL2			0x78
+#define ATC2609A_PMU_DC4_CTL0			0x79
+#define ATC2609A_PMU_DC4_CTL1			0x7A
+#define ATC2609A_PMU_DC4_CTL2			0x7B
+#define ATC2609A_PMU_DC4_CTL3			0x7C
+#define ATC2609A_PMU_DC4_CTL4			0x7D
+#define ATC2609A_PMU_DC4_CTL5			0x7E
+#define ATC2609A_PMU_DC4_CTL6			0x7F
+#define ATC2609A_PMU_PWR_STATUS			0x80
+#define ATC2609A_PMU_S2_PWR			0x81
+#define ATC2609A_CLMT_CTL0			0x82
+#define ATC2609A_CLMT_DATA0			0x83
+#define ATC2609A_CLMT_DATA1			0x84
+#define ATC2609A_CLMT_DATA2			0x85
+#define ATC2609A_CLMT_DATA3			0x86
+#define ATC2609A_CLMT_ADD0			0x87
+#define ATC2609A_CLMT_ADD1			0x88
+#define ATC2609A_CLMT_OCV_TABLE			0x89
+#define ATC2609A_CLMT_R_TABLE			0x8A
+#define ATC2609A_PMU_PWRON_CTL0			0x8D
+#define ATC2609A_PMU_PWRON_CTL1			0x8E
+#define ATC2609A_PMU_PWRON_CTL2			0x8F
+#define ATC2609A_IRC_CTL			0x90
+#define ATC2609A_IRC_STAT			0x91
+#define ATC2609A_IRC_CC				0x92
+#define ATC2609A_IRC_KDC			0x93
+#define ATC2609A_IRC_WK				0x94
+#define ATC2609A_IRC_RCC			0x95
+
+/* AUDIO_OUT Registers */
+#define ATC2609A_AUDIOINOUT_CTL			0xA0
+#define ATC2609A_AUDIO_DEBUGOUTCTL		0xA1
+#define ATC2609A_DAC_DIGITALCTL			0xA2
+#define ATC2609A_DAC_VOLUMECTL0			0xA3
+#define ATC2609A_DAC_ANALOG0			0xA4
+#define ATC2609A_DAC_ANALOG1			0xA5
+#define ATC2609A_DAC_ANALOG2			0xA6
+#define ATC2609A_DAC_ANALOG3			0xA7
+
+/* AUDIO_IN Registers */
+#define ATC2609A_ADC_DIGITALCTL			0xA8
+#define ATC2609A_ADC_HPFCTL			0xA9
+#define ATC2609A_ADC_CTL			0xAA
+#define ATC2609A_AGC_CTL0			0xAB
+#define ATC2609A_AGC_CTL1			0xAC
+#define ATC2609A_AGC_CTL2			0xAD
+#define ATC2609A_ADC_ANALOG0			0xAE
+#define ATC2609A_ADC_ANALOG1			0xAF
+
+/* PCM_IF Registers */
+#define ATC2609A_PCM0_CTL			0xB0
+#define ATC2609A_PCM1_CTL			0xB1
+#define ATC2609A_PCM2_CTL			0xB2
+#define ATC2609A_PCMIF_CTL			0xB3
+
+/* CMU_CONTROL Registers */
+#define ATC2609A_CMU_DEVRST			0xC1
+
+/* INTS Registers */
+#define ATC2609A_INTS_PD			0xC8
+#define ATC2609A_INTS_MSK			0xC9
+
+/* MFP Registers */
+#define ATC2609A_MFP_CTL			0xD0
+#define ATC2609A_PAD_VSEL			0xD1
+#define ATC2609A_GPIO_OUTEN			0xD2
+#define ATC2609A_GPIO_INEN			0xD3
+#define ATC2609A_GPIO_DAT			0xD4
+#define ATC2609A_PAD_DRV			0xD5
+#define ATC2609A_PAD_EN				0xD6
+#define ATC2609A_DEBUG_SEL			0xD7
+#define ATC2609A_DEBUG_IE			0xD8
+#define ATC2609A_DEBUG_OE			0xD9
+#define ATC2609A_CHIP_VER			0xDC
+
+/* PWSI Registers */
+#define ATC2609A_PWSI_CTL			0xF0
+#define ATC2609A_PWSI_STATUS			0xF1
+
+/* TWSI Registers */
+#define ATC2609A_SADDR				0xFF
+
+/* PMU_SYS_CTL0 Register Mask Bits */
+#define ATC2609A_PMU_SYS_CTL0_IR_WK_EN			BIT(5)
+#define ATC2609A_PMU_SYS_CTL0_RESET_WK_EN		BIT(6)
+#define ATC2609A_PMU_SYS_CTL0_HDSW_WK_EN		BIT(7)
+#define ATC2609A_PMU_SYS_CTL0_ALARM_WK_EN		BIT(8)
+#define ATC2609A_PMU_SYS_CTL0_REM_CON_WK_EN		BIT(9)
+#define ATC2609A_PMU_SYS_CTL0_RESTART_EN		BIT(10)
+#define ATC2609A_PMU_SYS_CTL0_WKIRQ_WK_EN		BIT(11)
+#define ATC2609A_PMU_SYS_CTL0_ONOFF_SHORT_WK_EN		BIT(12)
+#define ATC2609A_PMU_SYS_CTL0_ONOFF_LONG_WK_EN		BIT(13)
+#define ATC2609A_PMU_SYS_CTL0_WALL_WK_EN		BIT(14)
+#define ATC2609A_PMU_SYS_CTL0_USB_WK_EN			BIT(15)
+#define ATC2609A_PMU_SYS_CTL0_WK_ALL			(GENMASK(15, 5) & (~BIT(10)))
+
+/* PMU_SYS_CTL1 Register Mask Bits */
+#define ATC2609A_PMU_SYS_CTL1_EN_S1			BIT(0)
+#define ATC2609A_PMU_SYS_CTL1_LB_S4_EN			BIT(2)
+#define ATC2609A_PMU_SYS_CTL1_LB_S4			GENMASK(4, 3)
+#define ATC2609A_PMU_SYS_CTL1_LB_S4_3_1V		BIT(4)
+#define ATC2609A_PMU_SYS_CTL1_IR_WK_FLAG		BIT(5)
+#define ATC2609A_PMU_SYS_CTL1_RESET_WK_FLAG		BIT(6)
+#define ATC2609A_PMU_SYS_CTL1_HDSW_WK_FLAG		BIT(7)
+#define ATC2609A_PMU_SYS_CTL1_ALARM_WK_FLAG		BIT(8)
+#define ATC2609A_PMU_SYS_CTL1_REM_CON_WK_FLAG		BIT(9)
+#define ATC2609A_PMU_SYS_CTL1_RESTART_WK_FLAG		BIT(10)
+#define ATC2609A_PMU_SYS_CTL1_WKIRQ_WK_FLAG		BIT(11)
+#define ATC2609A_PMU_SYS_CTL1_ONOFF_SHORT_WK_FLAG	BIT(12)
+#define ATC2609A_PMU_SYS_CTL1_ONOFF_LONG_WK_FLAG	BIT(13)
+#define ATC2609A_PMU_SYS_CTL1_WALL_WK_FLAG		BIT(14)
+#define ATC2609A_PMU_SYS_CTL1_USB_WK_FLAG		BIT(15)
+
+/* PMU_SYS_CTL2 Register Mask Bits */
+#define ATC2609A_PMU_SYS_CTL2_PMU_A_EN			BIT(0)
+#define ATC2609A_PMU_SYS_CTL2_ONOFF_PRESS_INT_EN	BIT(1)
+#define ATC2609A_PMU_SYS_CTL2_ONOFF_PRESS_PD		BIT(2)
+#define ATC2609A_PMU_SYS_CTL2_S2TIMER			GENMASK(5, 3)
+#define ATC2609A_PMU_SYS_CTL2_S2_TIMER_EN		BIT(6)
+#define ATC2609A_PMU_SYS_CTL2_ONOFF_RESET_TIME_SEL	GENMASK(8, 7)
+#define ATC2609A_PMU_SYS_CTL2_ONOFF_RESET_EN		BIT(9)
+#define ATC2609A_PMU_SYS_CTL2_ONOFF_PRESS_TIME		GENMASK(11, 10)
+#define ATC2609A_PMU_SYS_CTL2_ONOFF_LSP_INT_EN		BIT(12)
+#define ATC2609A_PMU_SYS_CTL2_ONOFF_LONG_PRESS		BIT(13)
+#define ATC2609A_PMU_SYS_CTL2_ONOFF_SHORT_PRESS		BIT(14)
+#define ATC2609A_PMU_SYS_CTL2_ONOFF_PRESS		BIT(15)
+
+/* PMU_SYS_CTL3 Register Mask Bits */
+#define ATC2609A_PMU_SYS_CTL3_S2S3TOS1_TIMER		GENMASK(8, 7)
+#define ATC2609A_PMU_SYS_CTL3_S2S3TOS1_TIMER_EN		BIT(9)
+#define ATC2609A_PMU_SYS_CTL3_S3_TIMER			GENMASK(12, 10)
+#define ATC2609A_PMU_SYS_CTL3_S3_TIMER_EN		BIT(13)
+#define ATC2609A_PMU_SYS_CTL3_EN_S3			BIT(14)
+#define ATC2609A_PMU_SYS_CTL3_EN_S2			BIT(15)
+
+/* PMU_SYS_CTL5 Register Mask Bits */
+#define ATC2609A_PMU_SYS_CTL5_WALLWKDTEN		BIT(7)
+#define ATC2609A_PMU_SYS_CTL5_VBUSWKDTEN		BIT(8)
+#define ATC2609A_PMU_SYS_CTL5_REMCON_DECT_EN		BIT(9)
+#define ATC2609A_PMU_SYS_CTL5_ONOFF_8S_SEL		BIT(10)
+
+/* INTS_MSK Register Mask Bits */
+#define ATC2609A_INTS_MSK_AUDIO				BIT(0)
+#define ATC2609A_INTS_MSK_OV				BIT(1)
+#define ATC2609A_INTS_MSK_OC				BIT(2)
+#define ATC2609A_INTS_MSK_OT				BIT(3)
+#define ATC2609A_INTS_MSK_UV				BIT(4)
+#define ATC2609A_INTS_MSK_ALARM				BIT(5)
+#define ATC2609A_INTS_MSK_ONOFF				BIT(6)
+#define ATC2609A_INTS_MSK_WKUP				BIT(7)
+#define ATC2609A_INTS_MSK_IR				BIT(8)
+#define ATC2609A_INTS_MSK_REMCON			BIT(9)
+#define ATC2609A_INTS_MSK_POWERIN			BIT(10)
+
+/* CMU_DEVRST Register Mask Bits */
+#define ATC2609A_CMU_DEVRST_AUDIO			BIT(0)
+#define ATC2609A_CMU_DEVRST_MFP				BIT(1)
+#define ATC2609A_CMU_DEVRST_INTS			BIT(2)
+
+/* PAD_EN Register Mask Bits */
+#define ATC2609A_PAD_EN_EXTIRQ				BIT(0)
+
+#endif /* __LINUX_MFD_ATC260X_ATC2609A_H */
diff --git a/include/linux/mfd/atc260x/core.h b/include/linux/mfd/atc260x/core.h
new file mode 100644
index 000000000000..a87b976f48e3
--- /dev/null
+++ b/include/linux/mfd/atc260x/core.h
@@ -0,0 +1,86 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Core MFD defines for ATC260x PMICs
+ *
+ * Copyright (C) 2019 Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
+ * Copyright (C) 2020 Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
+ */
+
+#ifndef __LINUX_MFD_ATC260X_CORE_H
+#define __LINUX_MFD_ATC260X_CORE_H
+
+#include <linux/mfd/atc260x/atc2603c.h>
+#include <linux/mfd/atc260x/atc2609a.h>
+
+enum atc260x_type {
+	ATC2603A = 0,
+	ATC2603C,
+	ATC2609A,
+};
+
+enum atc260x_ver {
+	ATC260X_A = 0,
+	ATC260X_B,
+	ATC260X_C,
+	ATC260X_D,
+	ATC260X_E,
+	ATC260X_F,
+	ATC260X_G,
+	ATC260X_H,
+};
+
+struct atc260x {
+	struct device *dev;
+
+	struct regmap *regmap;
+	const struct regmap_irq_chip *regmap_irq_chip;
+	struct regmap_irq_chip_data *irq_data;
+
+	struct mutex *regmap_mutex;	/* mutex for custom regmap locking */
+
+	const struct mfd_cell *cells;
+	int nr_cells;
+	int irq;
+
+	enum atc260x_type ic_type;
+	enum atc260x_ver ic_ver;
+	const char *type_name;
+	unsigned int rev_reg;
+
+	int (*dev_init)(struct atc260x *atc260x);
+};
+
+struct regmap_config;
+
+/**
+ * atc260x_match_device(): Setup atc260x variant related fields
+ *
+ * @atc260x: atc260x device to setup (.dev field must be set)
+ * @regmap_cfg: regmap config associated with this atc260x device
+ *
+ * This lets the atc260x core configure the mfd cells and register maps
+ * for later use.
+ */
+int atc260x_match_device(struct atc260x *atc260x, struct regmap_config *regmap_cfg);
+
+/**
+ * atc260x_device_probe(): Probe a configured atc260x device
+ *
+ * @atc260x: atc260x device to probe (must be configured)
+ *
+ * This function lets the atc260x core register the atc260x mfd devices
+ * and irqchip. The atc260x device passed in must be fully configured
+ * with atc260x_match_device, its irq set, and regmap created.
+ */
+int atc260x_device_probe(struct atc260x *atc260x);
+
+/**
+ * atc260x_device_remove(): Remove a atc260x device
+ *
+ * @atc260x: atc260x device to remove
+ *
+ * This tells the atc260x core to remove the associated mfd devices
+ */
+int atc260x_device_remove(struct atc260x *atc260x);
+
+#endif /* __LINUX_MFD_ATC260X_CORE_H */
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v2 3/6] regulator: Add regulator driver for ATC260x PMICs
  2020-08-21 22:19 [PATCH v2 0/6] Add initial support for ATC260x PMICs Cristian Ciocaltea
  2020-08-21 22:19 ` [PATCH v2 1/6] dt-bindings: mfd: Add Actions Semi ATC260x PMIC binding Cristian Ciocaltea
  2020-08-21 22:19 ` [PATCH v2 2/6] mfd: Add MFD driver for ATC260x PMICs Cristian Ciocaltea
@ 2020-08-21 22:19 ` Cristian Ciocaltea
  2020-08-24 11:00   ` Mark Brown
  2020-08-21 22:19 ` [PATCH v2 4/6] power: reset: Add poweroff " Cristian Ciocaltea
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 23+ messages in thread
From: Cristian Ciocaltea @ 2020-08-21 22:19 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Dmitry Torokhov, Sebastian Reichel,
	Liam Girdwood, Mark Brown
  Cc: Manivannan Sadhasivam, Andreas Färber, linux-actions,
	devicetree, linux-kernel, linux-input, linux-pm

This driver supports the DC-DC converters and LDO regulators found in
the ATC2603C and ATC2609A chip variants of the Actions Semi ATC260x
family of PMICs.

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
[cristian: add ATC2603C variant, more regulator capabilities, cleanups]
Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
---
 drivers/regulator/Kconfig             |   8 +
 drivers/regulator/Makefile            |   1 +
 drivers/regulator/atc260x-regulator.c | 511 ++++++++++++++++++++++++++
 3 files changed, 520 insertions(+)
 create mode 100644 drivers/regulator/atc260x-regulator.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index de17ef7e18f0..860e46798503 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -170,6 +170,14 @@ config REGULATOR_AS3722
 	  AS3722 PMIC. This will enable support for all the software
 	  controllable DCDC/LDO regulators.
 
+config REGULATOR_ATC260X
+	tristate "Actions Semi ATC260x PMIC Regulators"
+	depends on MFD_ATC260X
+	help
+	  This driver provides support for the voltage regulators on the
+	  ATC260x PMICs. This will enable support for all the software
+	  controllable DCDC/LDO regulators.
+
 config REGULATOR_AXP20X
 	tristate "X-POWERS AXP20X PMIC Regulators"
 	depends on MFD_AXP20X
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index d8d3ecf526a8..181ff77ee23c 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -26,6 +26,7 @@ obj-$(CONFIG_REGULATOR_ARIZONA_LDO1) += arizona-ldo1.o
 obj-$(CONFIG_REGULATOR_ARIZONA_MICSUPP) += arizona-micsupp.o
 obj-$(CONFIG_REGULATOR_AS3711) += as3711-regulator.o
 obj-$(CONFIG_REGULATOR_AS3722) += as3722-regulator.o
+obj-$(CONFIG_REGULATOR_ATC260X) += atc260x-regulator.o
 obj-$(CONFIG_REGULATOR_AXP20X) += axp20x-regulator.o
 obj-$(CONFIG_REGULATOR_BCM590XX) += bcm590xx-regulator.o
 obj-$(CONFIG_REGULATOR_BD70528) += bd70528-regulator.o
diff --git a/drivers/regulator/atc260x-regulator.c b/drivers/regulator/atc260x-regulator.c
new file mode 100644
index 000000000000..7fab56cb80df
--- /dev/null
+++ b/drivers/regulator/atc260x-regulator.c
@@ -0,0 +1,511 @@
+// SPDX-License-Identifier: GPL-2.0+
+//
+// Regulator driver for ATC260x PMICs
+//
+// Copyright (C) 2019 Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
+// Copyright (C) 2020 Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
+
+#include <linux/mfd/atc260x/core.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/regmap.h>
+#include <linux/regulator/driver.h>
+
+struct atc260x_regulator_data {
+	int last_dcdc_reg_id;
+	int voltage_time_dcdc;
+	int voltage_time_ldo;
+};
+
+static const struct linear_range atc2603c_dcdc_voltage_ranges[] = {
+	REGULATOR_LINEAR_RANGE(1300000, 0, 13, 50000),
+	REGULATOR_LINEAR_RANGE(1950000, 14, 15, 100000),
+};
+
+static const struct linear_range atc2609a_dcdc_voltage_ranges[] = {
+	REGULATOR_LINEAR_RANGE(600000, 0, 127, 6250),
+	REGULATOR_LINEAR_RANGE(1400000, 128, 232, 25000),
+};
+
+static const struct linear_range atc2609a_ldo_voltage_ranges0[] = {
+	REGULATOR_LINEAR_RANGE(700000, 0, 15, 100000),
+	REGULATOR_LINEAR_RANGE(2100000, 16, 28, 100000),
+};
+
+static const struct linear_range atc2609a_ldo_voltage_ranges1[] = {
+	REGULATOR_LINEAR_RANGE(850000, 0, 15, 100000),
+	REGULATOR_LINEAR_RANGE(2100000, 16, 27, 100000),
+};
+
+static const unsigned int atc260x_ldo_voltage_range_sel[] = {
+	0x0, 0x1,
+};
+
+static int atc260x_set_voltage_time_sel(struct regulator_dev *rdev,
+					unsigned int old_selector,
+					unsigned int new_selector)
+{
+	struct atc260x_regulator_data *data = rdev_get_drvdata(rdev);
+	int id = rdev_get_id(rdev);
+
+	if (new_selector > old_selector)
+		return id > data->last_dcdc_reg_id ? data->voltage_time_ldo
+						   : data->voltage_time_dcdc;
+
+	return 0;
+}
+
+static const struct regulator_ops atc260x_reg_ops = {
+	.enable	= regulator_enable_regmap,
+	.disable = regulator_disable_regmap,
+	.is_enabled = regulator_is_enabled_regmap,
+	.list_voltage = regulator_list_voltage_linear,
+	.set_voltage_sel = regulator_set_voltage_sel_regmap,
+	.get_voltage_sel = regulator_get_voltage_sel_regmap,
+	.set_voltage_time_sel = atc260x_set_voltage_time_sel,
+};
+
+static const struct regulator_ops atc260x_reg_bypass_ops = {
+	.enable	= regulator_enable_regmap,
+	.disable = regulator_disable_regmap,
+	.is_enabled = regulator_is_enabled_regmap,
+	.list_voltage = regulator_list_voltage_linear,
+	.set_voltage_sel = regulator_set_voltage_sel_regmap,
+	.get_voltage_sel = regulator_get_voltage_sel_regmap,
+	.set_voltage_time_sel = atc260x_set_voltage_time_sel,
+	.set_bypass = regulator_set_bypass_regmap,
+	.get_bypass = regulator_get_bypass_regmap,
+};
+
+static const struct regulator_ops atc260x_reg_bypass_discharge_ops = {
+	.enable	= regulator_enable_regmap,
+	.disable = regulator_disable_regmap,
+	.is_enabled = regulator_is_enabled_regmap,
+	.list_voltage = regulator_list_voltage_linear,
+	.set_voltage_sel = regulator_set_voltage_sel_regmap,
+	.get_voltage_sel = regulator_get_voltage_sel_regmap,
+	.set_voltage_time_sel = atc260x_set_voltage_time_sel,
+	.set_bypass = regulator_set_bypass_regmap,
+	.get_bypass = regulator_get_bypass_regmap,
+	.set_active_discharge = regulator_set_active_discharge_regmap,
+};
+
+static const struct regulator_ops atc260x_reg_range_ops = {
+	.enable	= regulator_enable_regmap,
+	.disable = regulator_disable_regmap,
+	.is_enabled = regulator_is_enabled_regmap,
+	.list_voltage = regulator_list_voltage_linear_range,
+	.set_voltage_sel = regulator_set_voltage_sel_regmap,
+	.get_voltage_sel = regulator_get_voltage_sel_regmap,
+	.set_voltage_time_sel = atc260x_set_voltage_time_sel,
+};
+
+static const struct regulator_ops atc260x_reg_range_pick_ops = {
+	.enable	= regulator_enable_regmap,
+	.disable = regulator_disable_regmap,
+	.is_enabled = regulator_is_enabled_regmap,
+	.list_voltage = regulator_list_voltage_pickable_linear_range,
+	.set_voltage_sel = regulator_set_voltage_sel_pickable_regmap,
+	.get_voltage_sel = regulator_get_voltage_sel_pickable_regmap,
+	.set_voltage_time_sel = atc260x_set_voltage_time_sel,
+};
+
+static const struct regulator_ops atc260x_reg_fixed_ops = {
+	.list_voltage = regulator_list_voltage_linear,
+	.set_voltage_sel = regulator_set_voltage_sel_regmap,
+	.get_voltage_sel = regulator_get_voltage_sel_regmap,
+	.set_voltage_time_sel = atc260x_set_voltage_time_sel,
+};
+
+/*
+ * ATC2603C notes:
+ * - LDO8 is not documented in datasheet (v2.4), but supported
+ *   in the vendor's driver implementation (xapp-le-kernel).
+ * - LDO12 mentioned in datasheet is not programmable, hence not
+ *   handled in this driver.
+ */
+enum atc2603c_reg_ids {
+	ATC2603C_ID_DCDC1,
+	ATC2603C_ID_DCDC2,
+	ATC2603C_ID_DCDC3,
+	ATC2603C_ID_LDO1,
+	ATC2603C_ID_LDO2,
+	ATC2603C_ID_LDO3,
+	ATC2603C_ID_LDO5,
+	ATC2603C_ID_LDO6,
+	ATC2603C_ID_LDO7,
+	ATC2603C_ID_LDO8,
+	ATC2603C_ID_LDO11,
+	ATC2603C_ID_SWITCHLDO1,
+	ATC2603C_ID_MAX,
+};
+
+#define atc2603c_reg_desc_dcdc(num, min, step, n_volt, vsel_h, vsel_l) { \
+	.name = "DCDC"#num, \
+	.supply_name = "dcdc"#num, \
+	.of_match = of_match_ptr("dcdc"#num), \
+	.regulators_node = of_match_ptr("regulators"), \
+	.id = ATC2603C_ID_DCDC##num, \
+	.ops = &atc260x_reg_ops, \
+	.type = REGULATOR_VOLTAGE, \
+	.min_uV = min, \
+	.uV_step = step, \
+	.n_voltages = n_volt, \
+	.vsel_reg = ATC2603C_PMU_DC##num##_CTL0, \
+	.vsel_mask = GENMASK(vsel_h, vsel_l), \
+	.enable_reg = ATC2603C_PMU_DC##num##_CTL0, \
+	.enable_mask = BIT(15), \
+	.enable_time = 800, \
+	.owner = THIS_MODULE, \
+}
+
+#define atc2603c_reg_desc_dcdc_range(num, vsel_h, vsel_l) { \
+	.name = "DCDC"#num, \
+	.supply_name = "dcdc"#num, \
+	.of_match = of_match_ptr("dcdc"#num), \
+	.regulators_node = of_match_ptr("regulators"), \
+	.id = ATC2603C_ID_DCDC##num, \
+	.ops = &atc260x_reg_range_ops, \
+	.type = REGULATOR_VOLTAGE, \
+	.n_voltages = 16, \
+	.linear_ranges = atc2603c_dcdc_voltage_ranges, \
+	.n_linear_ranges = ARRAY_SIZE(atc2603c_dcdc_voltage_ranges), \
+	.vsel_reg = ATC2603C_PMU_DC##num##_CTL0, \
+	.vsel_mask = GENMASK(vsel_h, vsel_l), \
+	.enable_reg = ATC2603C_PMU_DC##num##_CTL0, \
+	.enable_mask = BIT(15), \
+	.enable_time = 800, \
+	.owner = THIS_MODULE, \
+}
+
+#define atc2603c_reg_desc_dcdc_fixed(num, min, step, n_volt, vsel_h, vsel_l) { \
+	.name = "DCDC"#num, \
+	.supply_name = "dcdc"#num, \
+	.of_match = of_match_ptr("dcdc"#num), \
+	.regulators_node = of_match_ptr("regulators"), \
+	.id = ATC2603C_ID_DCDC##num, \
+	.ops = &atc260x_reg_fixed_ops, \
+	.type = REGULATOR_VOLTAGE, \
+	.min_uV = min, \
+	.uV_step = step, \
+	.n_voltages = n_volt, \
+	.vsel_reg = ATC2603C_PMU_DC##num##_CTL0, \
+	.vsel_mask = GENMASK(vsel_h, vsel_l), \
+	.enable_time = 800, \
+	.owner = THIS_MODULE, \
+}
+
+#define atc2603c_reg_desc_ldo(num, min, step, n_volt, vsel_h, vsel_l) { \
+	.name = "LDO"#num, \
+	.supply_name = "ldo"#num, \
+	.of_match = of_match_ptr("ldo"#num), \
+	.regulators_node = of_match_ptr("regulators"), \
+	.id = ATC2603C_ID_LDO##num, \
+	.ops = &atc260x_reg_ops, \
+	.type = REGULATOR_VOLTAGE, \
+	.min_uV = min, \
+	.uV_step = step, \
+	.n_voltages = n_volt, \
+	.vsel_reg = ATC2603C_PMU_LDO##num##_CTL, \
+	.vsel_mask = GENMASK(vsel_h, vsel_l), \
+	.enable_reg = ATC2603C_PMU_LDO##num##_CTL, \
+	.enable_mask = BIT(0), \
+	.enable_time = 2000, \
+	.owner = THIS_MODULE, \
+}
+
+#define atc2603c_reg_desc_ldo_fixed(num, min, step, n_volt, vsel_h, vsel_l) { \
+	.name = "LDO"#num, \
+	.supply_name = "ldo"#num, \
+	.of_match = of_match_ptr("ldo"#num), \
+	.regulators_node = of_match_ptr("regulators"), \
+	.id = ATC2603C_ID_LDO##num, \
+	.ops = &atc260x_reg_fixed_ops, \
+	.type = REGULATOR_VOLTAGE, \
+	.min_uV = min, \
+	.uV_step = step, \
+	.n_voltages = n_volt, \
+	.vsel_reg = ATC2603C_PMU_LDO##num##_CTL, \
+	.vsel_mask = GENMASK(vsel_h, vsel_l), \
+	.enable_time = 2000, \
+	.owner = THIS_MODULE, \
+}
+
+#define atc2603c_reg_desc_ldo_switch(num, min, step, n_volt, vsel_h, vsel_l) { \
+	.name = "SWITCHLDO"#num, \
+	.supply_name = "switchldo"#num, \
+	.of_match = of_match_ptr("switchldo"#num), \
+	.regulators_node = of_match_ptr("regulators"), \
+	.id = ATC2603C_ID_SWITCHLDO##num, \
+	.ops = &atc260x_reg_bypass_discharge_ops, \
+	.type = REGULATOR_VOLTAGE, \
+	.min_uV = min, \
+	.uV_step = step, \
+	.n_voltages = n_volt, \
+	.vsel_reg = ATC2603C_PMU_SWITCH_CTL, \
+	.vsel_mask = GENMASK(vsel_h, vsel_l), \
+	.enable_reg = ATC2603C_PMU_SWITCH_CTL, \
+	.enable_mask = BIT(15), \
+	.enable_is_inverted = true, \
+	.enable_time = 2000, \
+	.bypass_reg = ATC2603C_PMU_SWITCH_CTL, \
+	.bypass_mask = BIT(5), \
+	.active_discharge_reg = ATC2603C_PMU_SWITCH_CTL, \
+	.active_discharge_mask = BIT(1), \
+	.owner = THIS_MODULE, \
+}
+
+static const struct regulator_desc atc2603c_reg[] = {
+	atc2603c_reg_desc_dcdc_fixed(1, 700000, 25000, 29, 11, 7),
+	atc2603c_reg_desc_dcdc_range(2, 12, 8),
+	atc2603c_reg_desc_dcdc_fixed(3, 2600000, 100000, 8, 11, 9),
+	atc2603c_reg_desc_ldo_fixed(1, 2600000, 100000, 8, 15, 13),
+	atc2603c_reg_desc_ldo_fixed(2, 2600000, 100000, 8, 15, 13),
+	atc2603c_reg_desc_ldo_fixed(3, 1500000, 100000, 6, 15, 13),
+	atc2603c_reg_desc_ldo(5, 2600000, 100000, 8, 15, 13),
+	atc2603c_reg_desc_ldo_fixed(6, 700000, 25000, 29, 15, 11),
+	atc2603c_reg_desc_ldo(7, 1500000, 100000, 6, 15, 13),
+	atc2603c_reg_desc_ldo(8, 2300000, 100000, 11, 15, 12),
+	atc2603c_reg_desc_ldo_fixed(11, 2600000, 100000, 8, 15, 13),
+	atc2603c_reg_desc_ldo_switch(1, 3000000, 100000, 4, 4, 3),
+};
+
+static const struct regulator_desc atc2603c_reg_dcdc2_ver_b =
+	atc2603c_reg_desc_dcdc(2, 1000000, 50000, 18, 12, 8);
+
+enum atc2609a_reg_ids {
+	ATC2609A_ID_DCDC0,
+	ATC2609A_ID_DCDC1,
+	ATC2609A_ID_DCDC2,
+	ATC2609A_ID_DCDC3,
+	ATC2609A_ID_DCDC4,
+	ATC2609A_ID_LDO0,
+	ATC2609A_ID_LDO1,
+	ATC2609A_ID_LDO2,
+	ATC2609A_ID_LDO3,
+	ATC2609A_ID_LDO4,
+	ATC2609A_ID_LDO5,
+	ATC2609A_ID_LDO6,
+	ATC2609A_ID_LDO7,
+	ATC2609A_ID_LDO8,
+	ATC2609A_ID_LDO9,
+	ATC2609A_ID_MAX,
+};
+
+#define atc2609a_reg_desc_dcdc(num, en_bit) { \
+	.name = "DCDC"#num, \
+	.supply_name = "dcdc"#num, \
+	.of_match = of_match_ptr("dcdc"#num), \
+	.regulators_node = of_match_ptr("regulators"), \
+	.id = ATC2609A_ID_DCDC##num, \
+	.ops = &atc260x_reg_ops, \
+	.type = REGULATOR_VOLTAGE, \
+	.min_uV = 600000, \
+	.uV_step = 6250, \
+	.n_voltages = 256, \
+	.vsel_reg = ATC2609A_PMU_DC##num##_CTL0, \
+	.vsel_mask = GENMASK(15, 8), \
+	.enable_reg = ATC2609A_PMU_DC_OSC, \
+	.enable_mask = BIT(en_bit), \
+	.enable_time = 800, \
+	.owner = THIS_MODULE, \
+}
+
+#define atc2609a_reg_desc_dcdc_range(num, en_bit) { \
+	.name = "DCDC"#num, \
+	.supply_name = "dcdc"#num, \
+	.of_match = of_match_ptr("dcdc"#num), \
+	.regulators_node = of_match_ptr("regulators"), \
+	.id = ATC2609A_ID_DCDC##num, \
+	.ops = &atc260x_reg_range_ops, \
+	.type = REGULATOR_VOLTAGE, \
+	.n_voltages = 233, \
+	.linear_ranges = atc2609a_dcdc_voltage_ranges, \
+	.n_linear_ranges = ARRAY_SIZE(atc2609a_dcdc_voltage_ranges), \
+	.vsel_reg = ATC2609A_PMU_DC##num##_CTL0, \
+	.vsel_mask = GENMASK(15, 8), \
+	.enable_reg = ATC2609A_PMU_DC_OSC, \
+	.enable_mask = BIT(en_bit), \
+	.enable_time = 800, \
+	.owner = THIS_MODULE, \
+}
+
+#define atc2609a_reg_desc_ldo(num) { \
+	.name = "LDO"#num, \
+	.supply_name = "ldo"#num, \
+	.of_match = of_match_ptr("ldo"#num), \
+	.regulators_node = of_match_ptr("regulators"), \
+	.id = ATC2609A_ID_LDO##num, \
+	.ops = &atc260x_reg_ops, \
+	.type = REGULATOR_VOLTAGE, \
+	.min_uV = 700000, \
+	.uV_step = 100000, \
+	.n_voltages = 16, \
+	.vsel_reg = ATC2609A_PMU_LDO##num##_CTL0, \
+	.vsel_mask = GENMASK(4, 1), \
+	.enable_reg = ATC2609A_PMU_LDO##num##_CTL0, \
+	.enable_mask = BIT(0), \
+	.enable_time = 2000, \
+	.owner = THIS_MODULE, \
+}
+
+#define atc2609a_reg_desc_ldo_bypass(num) { \
+	.name = "LDO"#num, \
+	.supply_name = "ldo"#num, \
+	.of_match = of_match_ptr("ldo"#num), \
+	.regulators_node = of_match_ptr("regulators"), \
+	.id = ATC2609A_ID_LDO##num, \
+	.ops = &atc260x_reg_bypass_ops, \
+	.type = REGULATOR_VOLTAGE, \
+	.min_uV = 2300000, \
+	.uV_step = 100000, \
+	.n_voltages = 12, \
+	.vsel_reg = ATC2609A_PMU_LDO##num##_CTL0, \
+	.vsel_mask = GENMASK(5, 2), \
+	.enable_reg = ATC2609A_PMU_LDO##num##_CTL0, \
+	.enable_mask = BIT(0), \
+	.enable_time = 2000, \
+	.bypass_reg = ATC2609A_PMU_LDO##num##_CTL0, \
+	.bypass_mask = BIT(1), \
+	.owner = THIS_MODULE, \
+}
+
+#define atc2609a_reg_desc_ldo_range_pick(num, n_range) { \
+	.name = "LDO"#num, \
+	.supply_name = "ldo"#num, \
+	.of_match = of_match_ptr("ldo"#num), \
+	.regulators_node = of_match_ptr("regulators"), \
+	.id = ATC2609A_ID_LDO##num, \
+	.ops = &atc260x_reg_range_pick_ops, \
+	.type = REGULATOR_VOLTAGE, \
+	.linear_ranges = atc2609a_ldo_voltage_ranges##n_range, \
+	.n_linear_ranges = ARRAY_SIZE(atc2609a_ldo_voltage_ranges##n_range), \
+	.vsel_reg = ATC2609A_PMU_LDO##num##_CTL0, \
+	.vsel_mask = GENMASK(4, 1), \
+	.vsel_range_reg = ATC2609A_PMU_LDO##num##_CTL0, \
+	.vsel_range_mask = BIT(5), \
+	.linear_range_selectors = atc260x_ldo_voltage_range_sel, \
+	.enable_reg = ATC2609A_PMU_LDO##num##_CTL0, \
+	.enable_mask = BIT(0), \
+	.enable_time = 2000, \
+	.owner = THIS_MODULE, \
+}
+
+#define atc2609a_reg_desc_ldo_fixed(num) { \
+	.name = "LDO"#num, \
+	.supply_name = "ldo"#num, \
+	.of_match = of_match_ptr("ldo"#num), \
+	.regulators_node = of_match_ptr("regulators"), \
+	.id = ATC2609A_ID_LDO##num, \
+	.ops = &atc260x_reg_fixed_ops, \
+	.type = REGULATOR_VOLTAGE, \
+	.min_uV = 2600000, \
+	.uV_step = 100000, \
+	.n_voltages = 8, \
+	.vsel_reg = ATC2609A_PMU_LDO##num##_CTL, \
+	.vsel_mask = GENMASK(15, 13), \
+	.enable_time = 2000, \
+	.owner = THIS_MODULE, \
+}
+
+static const struct regulator_desc atc2609a_reg[] = {
+	atc2609a_reg_desc_dcdc(0, 4),
+	atc2609a_reg_desc_dcdc(1, 5),
+	atc2609a_reg_desc_dcdc(2, 6),
+	atc2609a_reg_desc_dcdc_range(3, 7),
+	atc2609a_reg_desc_dcdc(4, 8),
+	atc2609a_reg_desc_ldo_bypass(0),
+	atc2609a_reg_desc_ldo_bypass(1),
+	atc2609a_reg_desc_ldo_bypass(2),
+	atc2609a_reg_desc_ldo_range_pick(3, 0),
+	atc2609a_reg_desc_ldo_range_pick(4, 0),
+	atc2609a_reg_desc_ldo(5),
+	atc2609a_reg_desc_ldo_range_pick(6, 1),
+	atc2609a_reg_desc_ldo_range_pick(7, 0),
+	atc2609a_reg_desc_ldo_range_pick(8, 0),
+	atc2609a_reg_desc_ldo_fixed(9),
+};
+
+static int atc260x_regulator_probe(struct platform_device *pdev)
+{
+	struct atc260x *atc260x = dev_get_drvdata(pdev->dev.parent);
+	struct device *dev = atc260x->dev;
+	struct atc260x_regulator_data *atc260x_data;
+	struct regulator_config config = {};
+	struct regulator_dev *atc260x_rdev;
+	const struct regulator_desc *regulators;
+	bool atc2603c_ver_b = false;
+	int i, nregulators;
+
+	if (!pdev->dev.of_node)
+		return -ENXIO;
+
+	atc260x_data = devm_kzalloc(&pdev->dev, sizeof(*atc260x_data), GFP_KERNEL);
+	if (!atc260x_data)
+		return -ENOMEM;
+
+	atc260x_data->voltage_time_dcdc = 350;
+	atc260x_data->voltage_time_ldo = 800;
+
+	switch (atc260x->ic_type) {
+	case ATC2603C:
+		atc260x_data->last_dcdc_reg_id = ATC2603C_ID_DCDC3;
+		regulators = atc2603c_reg;
+		nregulators = ATC2603C_ID_MAX;
+		atc2603c_ver_b = atc260x->ic_ver == ATC260X_B;
+		break;
+	case ATC2609A:
+		atc260x_data->last_dcdc_reg_id = ATC2609A_ID_DCDC4;
+		atc260x_data->voltage_time_dcdc = 250;
+		regulators = atc2609a_reg;
+		nregulators = ATC2609A_ID_MAX;
+		break;
+	default:
+		dev_err(dev, "unsupported ATC260X ID %d\n", atc260x->ic_type);
+		return -EINVAL;
+	}
+
+	config.dev = dev;
+	config.regmap = atc260x->regmap;
+	config.driver_data = atc260x_data;
+
+	/* Instantiate the regulators */
+	for (i = 0; i < nregulators; i++) {
+		if (atc2603c_ver_b && regulators[i].id == ATC2603C_ID_DCDC2)
+			atc260x_rdev = devm_regulator_register(&pdev->dev,
+							       &atc2603c_reg_dcdc2_ver_b,
+							       &config);
+		else
+			atc260x_rdev = devm_regulator_register(&pdev->dev,
+							       &regulators[i],
+							       &config);
+		if (IS_ERR(atc260x_rdev)) {
+			dev_err(dev, "failed to register regulator: %d\n", i);
+			return PTR_ERR(atc260x_rdev);
+		}
+	}
+
+	return 0;
+}
+
+static const struct of_device_id atc260x_regulator_of_match[] = {
+	{ .compatible = "actions,atc2603c-regulator" },
+	{ .compatible = "actions,atc2609a-regulator" },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, atc260x_regulator_of_match);
+
+static struct platform_driver atc260x_regulator_driver = {
+	.probe = atc260x_regulator_probe,
+	.driver = {
+		.name = "atc260x-regulator",
+		.of_match_table = of_match_ptr(atc260x_regulator_of_match),
+	},
+};
+
+module_platform_driver(atc260x_regulator_driver);
+
+MODULE_DESCRIPTION("Regulator driver for ATC260x PMICs");
+MODULE_AUTHOR("Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>");
+MODULE_AUTHOR("Cristian Ciocaltea <cristian.ciocaltea@gmail.com>");
+MODULE_LICENSE("GPL");
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v2 4/6] power: reset: Add poweroff driver for ATC260x PMICs
  2020-08-21 22:19 [PATCH v2 0/6] Add initial support for ATC260x PMICs Cristian Ciocaltea
                   ` (2 preceding siblings ...)
  2020-08-21 22:19 ` [PATCH v2 3/6] regulator: Add regulator " Cristian Ciocaltea
@ 2020-08-21 22:19 ` Cristian Ciocaltea
  2020-08-24 14:41   ` Sebastian Reichel
  2020-08-21 22:19 ` [PATCH v2 5/6] input: atc260x: Add onkey " Cristian Ciocaltea
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 23+ messages in thread
From: Cristian Ciocaltea @ 2020-08-21 22:19 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Dmitry Torokhov, Sebastian Reichel,
	Liam Girdwood, Mark Brown
  Cc: Manivannan Sadhasivam, Andreas Färber, linux-actions,
	devicetree, linux-kernel, linux-input, linux-pm

This driver provides poweroff and reboot support for a system through
the ATC2603C and ATC2609A chip variants of the Actions Semi ATC260x
family of PMICs.

Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
---
 drivers/power/reset/Kconfig            |   8 +-
 drivers/power/reset/Makefile           |   1 +
 drivers/power/reset/atc260x-poweroff.c | 274 +++++++++++++++++++++++++
 3 files changed, 282 insertions(+), 1 deletion(-)
 create mode 100644 drivers/power/reset/atc260x-poweroff.c

diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
index 0a1fb5c74f83..df6c3676b892 100644
--- a/drivers/power/reset/Kconfig
+++ b/drivers/power/reset/Kconfig
@@ -39,6 +39,13 @@ config POWER_RESET_AT91_SAMA5D2_SHDWC
 	  This driver supports the alternate shutdown controller for some Atmel
 	  SAMA5 SoCs. It is present for example on SAMA5D2 SoC.
 
+config POWER_RESET_ATC260X
+	tristate "Actions Semi ATC260x PMIC power-off driver"
+	depends on MFD_ATC260X
+	help
+	  This driver provides power-off and restart support for a system
+	  through Actions Semi ATC260x series PMICs.
+
 config POWER_RESET_AXXIA
 	bool "LSI Axxia reset driver"
 	depends on ARCH_AXXIA
@@ -285,4 +292,3 @@ config NVMEM_REBOOT_MODE
 	  action according to the mode.
 
 endif
-
diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile
index c51eceba9ea3..829df1157540 100644
--- a/drivers/power/reset/Makefile
+++ b/drivers/power/reset/Makefile
@@ -3,6 +3,7 @@ obj-$(CONFIG_POWER_RESET_AS3722) += as3722-poweroff.o
 obj-$(CONFIG_POWER_RESET_AT91_POWEROFF) += at91-poweroff.o
 obj-$(CONFIG_POWER_RESET_AT91_RESET) += at91-reset.o
 obj-$(CONFIG_POWER_RESET_AT91_SAMA5D2_SHDWC) += at91-sama5d2_shdwc.o
+obj-$(CONFIG_POWER_RESET_ATC260X) += atc260x-poweroff.o
 obj-$(CONFIG_POWER_RESET_AXXIA) += axxia-reset.o
 obj-$(CONFIG_POWER_RESET_BRCMKONA) += brcm-kona-reset.o
 obj-$(CONFIG_POWER_RESET_BRCMSTB) += brcmstb-reboot.o
diff --git a/drivers/power/reset/atc260x-poweroff.c b/drivers/power/reset/atc260x-poweroff.c
new file mode 100644
index 000000000000..81a99e7e4a91
--- /dev/null
+++ b/drivers/power/reset/atc260x-poweroff.c
@@ -0,0 +1,274 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Poweroff & reset driver for Actions Semi ATC260x PMICs
+ *
+ * Copyright (c) 2020 Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
+ */
+
+#include <linux/delay.h>
+#include <linux/mfd/atc260x/core.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/power_supply.h>
+#include <linux/reboot.h>
+#include <linux/regmap.h>
+
+struct atc260x_pwrc {
+	struct device *dev;
+	struct regmap *regmap;
+	struct notifier_block restart_nb;
+	int (*do_poweroff)(const struct atc260x_pwrc *pwrc, bool restart);
+};
+
+/* Global variable needed only for pm_power_off */
+static struct atc260x_pwrc *atc260x_pwrc_data;
+
+static int atc2603c_do_poweroff(const struct atc260x_pwrc *pwrc, bool restart)
+{
+	int ret, deep_sleep = 0;
+	uint reg_mask, reg_val;
+
+	/* S4-Deep Sleep Mode is NOT available for WALL/USB power */
+	if (!restart && !power_supply_is_system_supplied()) {
+		deep_sleep = 1;
+		dev_info(pwrc->dev, "Enabling S4-Deep Sleep Mode");
+	}
+
+	/* Update wakeup sources */
+	reg_val = ATC2603C_PMU_SYS_CTL0_ONOFF_LONG_WK_EN |
+		  (restart ? ATC2603C_PMU_SYS_CTL0_RESET_WK_EN
+			   : ATC2603C_PMU_SYS_CTL0_ONOFF_SHORT_WK_EN);
+
+	ret = regmap_update_bits(pwrc->regmap, ATC2603C_PMU_SYS_CTL0,
+				 ATC2603C_PMU_SYS_CTL0_WK_ALL, reg_val);
+	if (ret)
+		dev_warn(pwrc->dev, "failed to write SYS_CTL0: %d\n", ret);
+
+	/* Update power mode */
+	reg_mask = ATC2603C_PMU_SYS_CTL3_EN_S2 | ATC2603C_PMU_SYS_CTL3_EN_S3;
+
+	ret = regmap_update_bits(pwrc->regmap, ATC2603C_PMU_SYS_CTL3, reg_mask,
+				 deep_sleep ? 0 : ATC2603C_PMU_SYS_CTL3_EN_S3);
+	if (ret) {
+		dev_err(pwrc->dev, "failed to write SYS_CTL3: %d\n", ret);
+		return ret;
+	}
+
+	/* Trigger poweroff / restart sequence */
+	reg_mask = restart ? ATC2603C_PMU_SYS_CTL0_RESTART_EN
+			   : ATC2603C_PMU_SYS_CTL1_EN_S1;
+	reg_val = restart ? ATC2603C_PMU_SYS_CTL0_RESTART_EN : 0;
+
+	ret = regmap_update_bits(pwrc->regmap,
+				 restart ? ATC2603C_PMU_SYS_CTL0 : ATC2603C_PMU_SYS_CTL1,
+				 reg_mask, reg_val);
+	if (ret) {
+		dev_err(pwrc->dev, "failed to write SYS_CTL%d: %d\n",
+			restart ? 0 : 1, ret);
+		return ret;
+	}
+
+	/* Wait for trigger completion */
+	mdelay(200);
+
+	return 0;
+}
+
+static int atc2609a_do_poweroff(const struct atc260x_pwrc *pwrc, bool restart)
+{
+	int ret, deep_sleep = 0;
+	uint reg_mask, reg_val;
+
+	/* S4-Deep Sleep Mode is NOT available for WALL/USB power */
+	if (!restart && !power_supply_is_system_supplied()) {
+		deep_sleep = 1;
+		dev_info(pwrc->dev, "Enabling S4-Deep Sleep Mode");
+	}
+
+	/* Update wakeup sources */
+	reg_val = ATC2609A_PMU_SYS_CTL0_ONOFF_LONG_WK_EN |
+		  (restart ? ATC2609A_PMU_SYS_CTL0_RESET_WK_EN
+			   : ATC2609A_PMU_SYS_CTL0_ONOFF_SHORT_WK_EN);
+
+	ret = regmap_update_bits(pwrc->regmap, ATC2609A_PMU_SYS_CTL0,
+				 ATC2609A_PMU_SYS_CTL0_WK_ALL, reg_val);
+	if (ret)
+		dev_warn(pwrc->dev, "failed to write SYS_CTL0: %d\n", ret);
+
+	/* Update power mode */
+	reg_mask = ATC2609A_PMU_SYS_CTL3_EN_S2 | ATC2609A_PMU_SYS_CTL3_EN_S3;
+
+	ret = regmap_update_bits(pwrc->regmap, ATC2609A_PMU_SYS_CTL3, reg_mask,
+				 deep_sleep ? 0 : ATC2609A_PMU_SYS_CTL3_EN_S3);
+	if (ret) {
+		dev_err(pwrc->dev, "failed to write SYS_CTL3: %d\n", ret);
+		return ret;
+	}
+
+	/* Trigger poweroff / restart sequence */
+	reg_mask = restart ? ATC2609A_PMU_SYS_CTL0_RESTART_EN
+			   : ATC2609A_PMU_SYS_CTL1_EN_S1;
+	reg_val = restart ? ATC2609A_PMU_SYS_CTL0_RESTART_EN : 0;
+
+	ret = regmap_update_bits(pwrc->regmap,
+				 restart ? ATC2609A_PMU_SYS_CTL0 : ATC2609A_PMU_SYS_CTL1,
+				 reg_mask, reg_val);
+	if (ret) {
+		dev_err(pwrc->dev, "failed to write SYS_CTL%d: %d\n",
+			restart ? 0 : 1, ret);
+		return ret;
+	}
+
+	/* Wait for trigger completion */
+	mdelay(200);
+
+	return 0;
+}
+
+static int atc2603c_init(const struct atc260x_pwrc *pwrc)
+{
+	int ret;
+
+	/*
+	 * Delay transition from S2/S3 to S1 in order to avoid
+	 * DDR init failure in Bootloader.
+	 */
+	ret = regmap_update_bits(pwrc->regmap, ATC2603C_PMU_SYS_CTL3,
+				 ATC2603C_PMU_SYS_CTL3_S2S3TOS1_TIMER_EN,
+				 ATC2603C_PMU_SYS_CTL3_S2S3TOS1_TIMER_EN);
+	if (ret)
+		dev_warn(pwrc->dev, "failed to write SYS_CTL3: %d\n", ret);
+
+	/* Set wakeup sources */
+	ret = regmap_update_bits(pwrc->regmap, ATC2603C_PMU_SYS_CTL0,
+				 ATC2603C_PMU_SYS_CTL0_WK_ALL,
+				 ATC2603C_PMU_SYS_CTL0_HDSW_WK_EN |
+				 ATC2603C_PMU_SYS_CTL0_ONOFF_LONG_WK_EN);
+	if (ret)
+		dev_warn(pwrc->dev, "failed to write SYS_CTL0: %d\n", ret);
+
+	return ret;
+}
+
+static int atc2609a_init(const struct atc260x_pwrc *pwrc)
+{
+	int ret;
+
+	/* Set wakeup sources */
+	ret = regmap_update_bits(pwrc->regmap, ATC2609A_PMU_SYS_CTL0,
+				 ATC2609A_PMU_SYS_CTL0_WK_ALL,
+				 ATC2609A_PMU_SYS_CTL0_HDSW_WK_EN |
+				 ATC2609A_PMU_SYS_CTL0_ONOFF_LONG_WK_EN);
+	if (ret)
+		dev_warn(pwrc->dev, "failed to write SYS_CTL0: %d\n", ret);
+
+	return ret;
+}
+
+static void atc260x_pwrc_pm_handler(void)
+{
+	atc260x_pwrc_data->do_poweroff(atc260x_pwrc_data, false);
+
+	WARN_ONCE(1, "Unable to power off system\n");
+}
+
+static int atc260x_pwrc_restart_handler(struct notifier_block *nb,
+					unsigned long mode, void *cmd)
+{
+	struct atc260x_pwrc *pwrc = container_of(nb, struct atc260x_pwrc,
+						 restart_nb);
+	pwrc->do_poweroff(pwrc, true);
+
+	return NOTIFY_DONE;
+}
+
+static int atc260x_pwrc_probe(struct platform_device *pdev)
+{
+	struct atc260x *atc260x = dev_get_drvdata(pdev->dev.parent);
+	struct atc260x_pwrc *priv;
+	int ret;
+
+	if (!pdev->dev.of_node)
+		return -ENXIO;
+
+	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->dev = &pdev->dev;
+	priv->regmap = atc260x->regmap;
+	priv->restart_nb.notifier_call = atc260x_pwrc_restart_handler;
+	priv->restart_nb.priority = 192;
+
+	switch (atc260x->ic_type) {
+	case ATC2603C:
+		priv->do_poweroff = atc2603c_do_poweroff;
+		ret = atc2603c_init(priv);
+		break;
+	case ATC2609A:
+		priv->do_poweroff = atc2609a_do_poweroff;
+		ret = atc2609a_init(priv);
+		break;
+	default:
+		dev_err(priv->dev,
+			"Poweroff not supported for ATC260x PMIC type: %u\n",
+			atc260x->ic_type);
+		return -EINVAL;
+	}
+
+	if (ret)
+		return ret;
+
+	platform_set_drvdata(pdev, priv);
+
+	if (!pm_power_off) {
+		atc260x_pwrc_data = priv;
+		pm_power_off = atc260x_pwrc_pm_handler;
+	} else {
+		dev_warn(priv->dev, "Poweroff callback already assigned\n");
+	}
+
+	ret = register_restart_handler(&priv->restart_nb);
+	if (ret)
+		dev_err(priv->dev, "failed to register restart handler: %d\n",
+			ret);
+
+	return ret;
+}
+
+static int atc260x_pwrc_remove(struct platform_device *pdev)
+{
+	struct atc260x_pwrc *priv = platform_get_drvdata(pdev);
+
+	if (atc260x_pwrc_data == priv) {
+		pm_power_off = NULL;
+		atc260x_pwrc_data = NULL;
+	}
+
+	unregister_restart_handler(&priv->restart_nb);
+
+	return 0;
+}
+
+static const struct of_device_id atc260x_pwrc_of_match[] = {
+	{ .compatible = "actions,atc2603c-pwrc" },
+	{ .compatible = "actions,atc2609a-pwrc" },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, atc260x_pwrc_of_match);
+
+static struct platform_driver atc260x_pwrc_driver = {
+	.probe = atc260x_pwrc_probe,
+	.remove = atc260x_pwrc_remove,
+	.driver = {
+		.name = "atc260x-pwrc",
+		.of_match_table = of_match_ptr(atc260x_pwrc_of_match),
+	},
+};
+
+module_platform_driver(atc260x_pwrc_driver);
+
+MODULE_DESCRIPTION("Poweroff & reset driver for ATC260x PMICs");
+MODULE_AUTHOR("Cristian Ciocaltea <cristian.ciocaltea@gmail.com>");
+MODULE_LICENSE("GPL");
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v2 5/6] input: atc260x: Add onkey driver for ATC260x PMICs
  2020-08-21 22:19 [PATCH v2 0/6] Add initial support for ATC260x PMICs Cristian Ciocaltea
                   ` (3 preceding siblings ...)
  2020-08-21 22:19 ` [PATCH v2 4/6] power: reset: Add poweroff " Cristian Ciocaltea
@ 2020-08-21 22:19 ` Cristian Ciocaltea
  2020-09-14 21:09   ` Dmitry Torokhov
  2020-08-21 22:19 ` [PATCH v2 6/6] MAINTAINERS: Add entry for ATC260x PMIC Cristian Ciocaltea
  2020-08-21 22:26 ` [PATCH v2 0/6] Add initial support for ATC260x PMICs Cristian Ciocaltea
  6 siblings, 1 reply; 23+ messages in thread
From: Cristian Ciocaltea @ 2020-08-21 22:19 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Dmitry Torokhov, Sebastian Reichel,
	Liam Girdwood, Mark Brown
  Cc: Manivannan Sadhasivam, Andreas Färber, linux-actions,
	devicetree, linux-kernel, linux-input, linux-pm

The Actions Semi ATC260x PMICs are able to manage an onkey button.
This driver exposes the ATC260x onkey as an input device. It can also
be configured to force a system reset on a long key-press with an
adjustable duration.

The currently supported chip variants are ATC2603C and ATC2609A.

Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
---
 drivers/input/misc/Kconfig         |  11 ++
 drivers/input/misc/Makefile        |   2 +-
 drivers/input/misc/atc260x-onkey.c | 304 +++++++++++++++++++++++++++++
 3 files changed, 316 insertions(+), 1 deletion(-)
 create mode 100644 drivers/input/misc/atc260x-onkey.c

diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 362e8a01980c..9e297ebdea57 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -83,6 +83,17 @@ config INPUT_ARIZONA_HAPTICS
 	  To compile this driver as a module, choose M here: the
 	  module will be called arizona-haptics.
 
+config INPUT_ATC260X_ONKEY
+	tristate "Actions Semi ATC260x PMIC ONKEY"
+	depends on MFD_ATC260X
+	help
+	  Support the ONKEY of ATC260x PMICs as an input device reporting
+	  power button status. ONKEY can be used to wakeup from low power
+	  modes and force a reset on long press.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called atc260x-onkey.
+
 config INPUT_ATMEL_CAPTOUCH
 	tristate "Atmel Capacitive Touch Button Driver"
 	depends on OF || COMPILE_TEST
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index a48e5f2d859d..7f854c6ecefa 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -16,6 +16,7 @@ obj-$(CONFIG_INPUT_ADXL34X_I2C)		+= adxl34x-i2c.o
 obj-$(CONFIG_INPUT_ADXL34X_SPI)		+= adxl34x-spi.o
 obj-$(CONFIG_INPUT_APANEL)		+= apanel.o
 obj-$(CONFIG_INPUT_ARIZONA_HAPTICS)	+= arizona-haptics.o
+obj-$(CONFIG_INPUT_ATC260X_ONKEY)	+= atc260x-onkey.o
 obj-$(CONFIG_INPUT_ATI_REMOTE2)		+= ati_remote2.o
 obj-$(CONFIG_INPUT_ATLAS_BTNS)		+= atlas_btns.o
 obj-$(CONFIG_INPUT_ATMEL_CAPTOUCH)	+= atmel_captouch.o
@@ -84,4 +85,3 @@ obj-$(CONFIG_INPUT_WM831X_ON)		+= wm831x-on.o
 obj-$(CONFIG_INPUT_XEN_KBDDEV_FRONTEND)	+= xen-kbdfront.o
 obj-$(CONFIG_INPUT_YEALINK)		+= yealink.o
 obj-$(CONFIG_INPUT_IDEAPAD_SLIDEBAR)	+= ideapad_slidebar.o
-
diff --git a/drivers/input/misc/atc260x-onkey.c b/drivers/input/misc/atc260x-onkey.c
new file mode 100644
index 000000000000..7caec7d6f9ac
--- /dev/null
+++ b/drivers/input/misc/atc260x-onkey.c
@@ -0,0 +1,304 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Onkey driver for Actions Semi ATC260x PMICs.
+ *
+ * Copyright (c) 2020 Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
+ */
+
+#include <linux/bitfield.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
+#include <linux/mfd/atc260x/core.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+
+/* <2s for short press, >2s for long press */
+#define KEY_PRESS_TIME_SEC	2
+
+/* Driver internals */
+enum atc260x_onkey_reset_status {
+	KEY_RESET_HW_DEFAULT,
+	KEY_RESET_DISABLED,
+	KEY_RESET_USER_SEL,
+};
+
+struct atc260x_onkey_params {
+	u32 reg_int_ctl;
+	u32 kdwn_state_bm;
+	u32 long_int_pnd_bm;
+	u32 short_int_pnd_bm;
+	u32 kdwn_int_pnd_bm;
+	u32 press_int_en_bm;
+	u32 kdwn_int_en_bm;
+	u32 press_time_bm;
+	u32 reset_en_bm;
+	u32 reset_time_bm;
+};
+
+struct atc260x_onkey {
+	struct atc260x *atc260x;
+	const struct atc260x_onkey_params *params;
+	struct input_dev *input_dev;
+	struct delayed_work work;
+};
+
+static const struct atc260x_onkey_params atc2603c_onkey_params = {
+	.reg_int_ctl		= ATC2603C_PMU_SYS_CTL2,
+	.long_int_pnd_bm	= ATC2603C_PMU_SYS_CTL2_ONOFF_LONG_PRESS,
+	.short_int_pnd_bm	= ATC2603C_PMU_SYS_CTL2_ONOFF_SHORT_PRESS,
+	.kdwn_int_pnd_bm	= ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS_PD,
+	.press_int_en_bm	= ATC2603C_PMU_SYS_CTL2_ONOFF_INT_EN,
+	.kdwn_int_en_bm		= ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS_INT_EN,
+	.kdwn_state_bm		= ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS,
+	.press_time_bm		= ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS_TIME,
+	.reset_en_bm		= ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS_RESET_EN,
+	.reset_time_bm		= ATC2603C_PMU_SYS_CTL2_ONOFF_RESET_TIME_SEL,
+};
+
+static const struct atc260x_onkey_params atc2609a_onkey_params = {
+	.reg_int_ctl		= ATC2609A_PMU_SYS_CTL2,
+	.long_int_pnd_bm	= ATC2609A_PMU_SYS_CTL2_ONOFF_LONG_PRESS,
+	.short_int_pnd_bm	= ATC2609A_PMU_SYS_CTL2_ONOFF_SHORT_PRESS,
+	.kdwn_int_pnd_bm	= ATC2609A_PMU_SYS_CTL2_ONOFF_PRESS_PD,
+	.press_int_en_bm	= ATC2609A_PMU_SYS_CTL2_ONOFF_LSP_INT_EN,
+	.kdwn_int_en_bm		= ATC2609A_PMU_SYS_CTL2_ONOFF_PRESS_INT_EN,
+	.kdwn_state_bm		= ATC2609A_PMU_SYS_CTL2_ONOFF_PRESS,
+	.press_time_bm		= ATC2609A_PMU_SYS_CTL2_ONOFF_PRESS_TIME,
+	.reset_en_bm		= ATC2609A_PMU_SYS_CTL2_ONOFF_RESET_EN,
+	.reset_time_bm		= ATC2609A_PMU_SYS_CTL2_ONOFF_RESET_TIME_SEL,
+};
+
+static int atc2603x_onkey_hw_init(struct atc260x_onkey *onkey,
+				  enum atc260x_onkey_reset_status reset_status,
+				  u32 reset_time, u32 press_time)
+{
+	u32 reg_bm, reg_val;
+
+	reg_bm = onkey->params->long_int_pnd_bm |
+		 onkey->params->short_int_pnd_bm |
+		 onkey->params->kdwn_int_pnd_bm |
+		 onkey->params->press_int_en_bm |
+		 onkey->params->kdwn_int_en_bm;
+
+	reg_val = reg_bm | press_time;
+	reg_bm |= onkey->params->press_time_bm;
+
+	if (reset_status == KEY_RESET_DISABLED) {
+		reg_bm |= onkey->params->reset_en_bm;
+	} else if (reset_status == KEY_RESET_USER_SEL) {
+		reg_bm |= onkey->params->reset_en_bm |
+			  onkey->params->reset_time_bm;
+		reg_val |= onkey->params->reset_en_bm | reset_time;
+	}
+
+	return regmap_update_bits(onkey->atc260x->regmap,
+				  onkey->params->reg_int_ctl, reg_bm, reg_val);
+}
+
+static void atc260x_onkey_query(struct atc260x_onkey *onkey)
+{
+	u32 reg_bits;
+	int ret, key_down;
+
+	ret = regmap_read(onkey->atc260x->regmap,
+			  onkey->params->reg_int_ctl, &key_down);
+	if (ret) {
+		key_down = 1;
+		dev_err(onkey->atc260x->dev,
+			"Failed to read onkey status: %d\n", ret);
+	} else {
+		key_down &= onkey->params->kdwn_state_bm;
+	}
+
+	/*
+	 * The hardware generates interrupt only when the onkey pin is
+	 * asserted. Hence, the deassertion of the pin is simulated through
+	 * work queue.
+	 */
+	if (key_down) {
+		schedule_delayed_work(&onkey->work, msecs_to_jiffies(200));
+		return;
+	}
+
+	/*
+	 * The key-down status bit is cleared when the On/Off button
+	 * is released.
+	 */
+	input_report_key(onkey->input_dev, KEY_POWER, 0);
+	input_sync(onkey->input_dev);
+
+	reg_bits = onkey->params->long_int_pnd_bm |
+		   onkey->params->short_int_pnd_bm |
+		   onkey->params->kdwn_int_pnd_bm |
+		   onkey->params->press_int_en_bm |
+		   onkey->params->kdwn_int_en_bm;
+
+	/* Clear key press pending events and enable key press interrupts. */
+	regmap_update_bits(onkey->atc260x->regmap, onkey->params->reg_int_ctl,
+			   reg_bits, reg_bits);
+}
+
+static void atc260x_onkey_work(struct work_struct *work)
+{
+	struct atc260x_onkey *onkey = container_of(work, struct atc260x_onkey,
+						   work.work);
+	atc260x_onkey_query(onkey);
+}
+
+static irqreturn_t atc260x_onkey_irq(int irq, void *data)
+{
+	struct atc260x_onkey *onkey = data;
+	int ret;
+
+	/* Disable key press interrupts. */
+	ret = regmap_update_bits(onkey->atc260x->regmap,
+				 onkey->params->reg_int_ctl,
+				 onkey->params->press_int_en_bm |
+				 onkey->params->kdwn_int_en_bm, 0);
+	if (ret)
+		dev_err(onkey->atc260x->dev,
+			"Failed to disable interrupts: %d\n", ret);
+
+	input_report_key(onkey->input_dev, KEY_POWER, 1);
+	input_sync(onkey->input_dev);
+
+	atc260x_onkey_query(onkey);
+
+	return IRQ_HANDLED;
+}
+
+static int atc260x_onkey_probe(struct platform_device *pdev)
+{
+	struct atc260x *atc260x = dev_get_drvdata(pdev->dev.parent);
+	struct atc260x_onkey *onkey;
+	struct input_dev *input_dev;
+	enum atc260x_onkey_reset_status reset_status;
+	u32 press_time = KEY_PRESS_TIME_SEC, reset_time = 0;
+	int val, irq, ret;
+
+	if (!pdev->dev.of_node)
+		return -ENXIO;
+
+	onkey = devm_kzalloc(&pdev->dev, sizeof(*onkey), GFP_KERNEL);
+	if (!onkey)
+		return -ENOMEM;
+
+	ret = device_property_read_u32(&pdev->dev,
+				       "actions,reset-time-sec", &val);
+	if (ret) {
+		reset_status = KEY_RESET_HW_DEFAULT;
+	} else if (val) {
+		if (val < 6 || val > 12) {
+			dev_err(&pdev->dev, "actions,reset-time-sec out of range\n");
+			return -EINVAL;
+		}
+
+		reset_status = KEY_RESET_USER_SEL;
+		reset_time = (val - 6) / 2;
+	} else {
+		reset_status = KEY_RESET_DISABLED;
+		dev_info(&pdev->dev, "Disabled reset on long-press\n");
+	}
+
+	switch (atc260x->ic_type) {
+	case ATC2603C:
+		onkey->params = &atc2603c_onkey_params;
+		press_time = FIELD_PREP(ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS_TIME,
+					press_time);
+		reset_time = FIELD_PREP(ATC2603C_PMU_SYS_CTL2_ONOFF_RESET_TIME_SEL,
+					reset_time);
+		break;
+	case ATC2609A:
+		onkey->params = &atc2609a_onkey_params;
+		press_time = FIELD_PREP(ATC2609A_PMU_SYS_CTL2_ONOFF_PRESS_TIME,
+					press_time);
+		reset_time = FIELD_PREP(ATC2609A_PMU_SYS_CTL2_ONOFF_RESET_TIME_SEL,
+					reset_time);
+		break;
+	default:
+		dev_err(&pdev->dev,
+			"OnKey not supported for ATC260x PMIC type: %u\n",
+			atc260x->ic_type);
+		return -EINVAL;
+	}
+
+	input_dev = devm_input_allocate_device(&pdev->dev);
+	if (!input_dev) {
+		dev_err(&pdev->dev, "Failed to allocate input device\n");
+		return -ENOMEM;
+	}
+
+	onkey->input_dev = input_dev;
+	onkey->atc260x = atc260x;
+
+	input_dev->name = "atc260x-onkey";
+	input_dev->phys = "atc260x-onkey/input0";
+	input_dev->evbit[0] = BIT_MASK(EV_KEY);
+	input_set_capability(input_dev, EV_KEY, KEY_POWER);
+
+	INIT_DELAYED_WORK(&onkey->work, atc260x_onkey_work);
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0)
+		return irq;
+
+	ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
+					atc260x_onkey_irq,
+					IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
+					dev_name(&pdev->dev), onkey);
+	if (ret) {
+		dev_err(&pdev->dev,
+			"Failed to register IRQ %d: %d\n", irq, ret);
+		return ret;
+	}
+
+	ret = input_register_device(input_dev);
+	if (ret) {
+		dev_err(&pdev->dev,
+			"Failed to register input device: %d\n", ret);
+		return ret;
+	}
+
+	ret = atc2603x_onkey_hw_init(onkey, reset_status,
+				     reset_time, press_time);
+	if (ret)
+		return ret;
+
+	platform_set_drvdata(pdev, onkey);
+	device_init_wakeup(&pdev->dev, true);
+
+	return 0;
+}
+
+static int atc260x_onkey_remove(struct platform_device *pdev)
+{
+	struct atc260x_onkey *onkey = platform_get_drvdata(pdev);
+
+	cancel_delayed_work_sync(&onkey->work);
+
+	return 0;
+}
+
+static const struct of_device_id atc260x_onkey_of_match[] = {
+	{ .compatible = "actions,atc2603c-onkey" },
+	{ .compatible = "actions,atc2609a-onkey" },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, atc260x_onkey_of_match);
+
+static struct platform_driver atc260x_onkey_driver = {
+	.probe	= atc260x_onkey_probe,
+	.remove	= atc260x_onkey_remove,
+	.driver	= {
+		.name = "atc260x-onkey",
+		.of_match_table = of_match_ptr(atc260x_onkey_of_match),
+	},
+};
+
+module_platform_driver(atc260x_onkey_driver);
+
+MODULE_DESCRIPTION("Onkey driver for ATC260x PMICs");
+MODULE_AUTHOR("Cristian Ciocaltea <cristian.ciocaltea@gmail.com>");
+MODULE_LICENSE("GPL");
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v2 6/6] MAINTAINERS: Add entry for ATC260x PMIC
  2020-08-21 22:19 [PATCH v2 0/6] Add initial support for ATC260x PMICs Cristian Ciocaltea
                   ` (4 preceding siblings ...)
  2020-08-21 22:19 ` [PATCH v2 5/6] input: atc260x: Add onkey " Cristian Ciocaltea
@ 2020-08-21 22:19 ` Cristian Ciocaltea
  2020-08-21 22:26 ` [PATCH v2 0/6] Add initial support for ATC260x PMICs Cristian Ciocaltea
  6 siblings, 0 replies; 23+ messages in thread
From: Cristian Ciocaltea @ 2020-08-21 22:19 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Dmitry Torokhov, Sebastian Reichel,
	Liam Girdwood, Mark Brown
  Cc: Manivannan Sadhasivam, Andreas Färber, linux-actions,
	devicetree, linux-kernel, linux-input, linux-pm

Add MAINTAINERS entry for ATC260x PMIC.

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
[cristian: change binding doc file path, add file patterns for onkey and
           poweroff drivers, fix ordering, add myself as co-maintainer]
Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
---
 MAINTAINERS | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index e28d8ad47d03..b57ac4e9aa11 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2899,6 +2899,18 @@ W:	http://www.openaoe.org/
 F:	Documentation/admin-guide/aoe/
 F:	drivers/block/aoe/
 
+ATC260X PMIC MFD DRIVER
+M:	Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
+M:	Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
+L:	linux-actions@lists.infradead.org
+S:	Maintained
+F:	Documentation/devicetree/bindings/mfd/actions,atc260x.yaml
+F:	drivers/input/misc/atc260x-onkey.c
+F:	drivers/mfd/atc260*
+F:	drivers/power/reset/atc260x-poweroff.c
+F:	drivers/regulator/atc260x-regulator.c
+F:	include/linux/mfd/atc260x/*
+
 ATHEROS 71XX/9XXX GPIO DRIVER
 M:	Alban Bedel <albeu@free.fr>
 S:	Maintained
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 0/6] Add initial support for ATC260x PMICs
  2020-08-21 22:19 [PATCH v2 0/6] Add initial support for ATC260x PMICs Cristian Ciocaltea
                   ` (5 preceding siblings ...)
  2020-08-21 22:19 ` [PATCH v2 6/6] MAINTAINERS: Add entry for ATC260x PMIC Cristian Ciocaltea
@ 2020-08-21 22:26 ` Cristian Ciocaltea
  2020-08-22 13:13   ` Manivannan Sadhasivam
  6 siblings, 1 reply; 23+ messages in thread
From: Cristian Ciocaltea @ 2020-08-21 22:26 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Dmitry Torokhov, Sebastian Reichel,
	Liam Girdwood, Mark Brown
  Cc: Manivannan Sadhasivam, Andreas Färber, linux-actions,
	devicetree, linux-kernel, linux-input, linux-pm

I have just realized I had omitted the changelog - sorry:

Changes in v2:
- Reworked MFD core & I2C driver
  * Integrated Lee's feedback
  * Added support for using the regmap within atomic contexts
  * Added support for ATC2603C chip variant
  * Reorganized KConfig entries
- Improved regulator driver
  * Added support for ATC2603C variant
  * Used helper macros for more compact specification of regulator_desc items
  * Added more regulator capabilities
- Added power controller driver
  * Provides system poweroff/reboot functionalities
  * Requires support for I2C Atomic transfers in the Owl driver (already submitted)
- Added onkey driver: exposes the power button as an input device
- Added yaml binding doc
- Rebased patchset on kernel v5.9-rc1

Kind regards,
Cristi

On Sat, Aug 22, 2020 at 01:19:46AM +0300, Cristian Ciocaltea wrote:
> This is re-spin of the patch series submitted some time ago by Mani,
> who added initial support (MFD core and regulators) for the Actions
> Semi ATC260x PMICs:
> https://lore.kernel.org/lkml/20190617155011.15376-1-manivannan.sadhasivam@linaro.org/
> 
> The ATC260x family of PMICs integrates Audio Codec, Power management,
> Clock generation and GPIO controller blocks. There are currently 3
> variants: ATC2603A, ATC2603C and ATC2609A.
> 
> In addition to the ATC2609A regulator functionality provided that time,
> this patchset adds support for the ATC2603C variant, together with some
> new functionalities for both chips: power controller and onkey input.
> The ATC2603A variant remains unsupported for the moment.
> 
> This has been tested on RoseapplePi, a SBC based on the Action Semi S500
> SoC, which integrates ATC2603C PMIC. An initial support for this board
> has been already submitted:
> https://lore.kernel.org/lkml/cover.1592123160.git.cristian.ciocaltea@gmail.com/
> 
> Please note that enabling the ATC260x PMICs on the compatible Actions
> Semi Owl SoC based boards depends on the following:
> 
> * Actions Semi SIRQ driver (for PMIC DTS setup):
>   https://lore.kernel.org/lkml/cover.1597852360.git.cristian.ciocaltea@gmail.com/
> 
> * I2C Atomic transfers in Actions Semi Owl driver (for proper operation
>   of the power controller driver):
>   https://lore.kernel.org/lkml/b086ef6d355d9730c839359e15eb06175283e323.1596485741.git.cristian.ciocaltea@gmail.com/
>   
> Thanks,
> Cristi
> 
> Cristian Ciocaltea (6):
>   dt-bindings: mfd: Add Actions Semi ATC260x PMIC binding
>   mfd: Add MFD driver for ATC260x PMICs
>   regulator: Add regulator driver for ATC260x PMICs
>   power: reset: Add poweroff driver for ATC260x PMICs
>   input: atc260x: Add onkey driver for ATC260x PMICs
>   MAINTAINERS: Add entry for ATC260x PMIC
> 
>  .../bindings/mfd/actions,atc260x.yaml         | 221 ++++++++
>  MAINTAINERS                                   |  12 +
>  drivers/input/misc/Kconfig                    |  11 +
>  drivers/input/misc/Makefile                   |   2 +-
>  drivers/input/misc/atc260x-onkey.c            | 304 +++++++++++
>  drivers/mfd/Kconfig                           |  18 +
>  drivers/mfd/Makefile                          |   3 +
>  drivers/mfd/atc260x-core.c                    | 290 ++++++++++
>  drivers/mfd/atc260x-i2c.c                     |  73 +++
>  drivers/power/reset/Kconfig                   |   8 +-
>  drivers/power/reset/Makefile                  |   1 +
>  drivers/power/reset/atc260x-poweroff.c        | 274 ++++++++++
>  drivers/regulator/Kconfig                     |   8 +
>  drivers/regulator/Makefile                    |   1 +
>  drivers/regulator/atc260x-regulator.c         | 511 ++++++++++++++++++
>  include/linux/mfd/atc260x/atc2603c.h          | 281 ++++++++++
>  include/linux/mfd/atc260x/atc2609a.h          | 308 +++++++++++
>  include/linux/mfd/atc260x/core.h              |  86 +++
>  18 files changed, 2410 insertions(+), 2 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/mfd/actions,atc260x.yaml
>  create mode 100644 drivers/input/misc/atc260x-onkey.c
>  create mode 100644 drivers/mfd/atc260x-core.c
>  create mode 100644 drivers/mfd/atc260x-i2c.c
>  create mode 100644 drivers/power/reset/atc260x-poweroff.c
>  create mode 100644 drivers/regulator/atc260x-regulator.c
>  create mode 100644 include/linux/mfd/atc260x/atc2603c.h
>  create mode 100644 include/linux/mfd/atc260x/atc2609a.h
>  create mode 100644 include/linux/mfd/atc260x/core.h
> 
> -- 
> 2.28.0
> 

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 0/6] Add initial support for ATC260x PMICs
  2020-08-21 22:26 ` [PATCH v2 0/6] Add initial support for ATC260x PMICs Cristian Ciocaltea
@ 2020-08-22 13:13   ` Manivannan Sadhasivam
  2020-08-22 23:24     ` Cristian Ciocaltea
  0 siblings, 1 reply; 23+ messages in thread
From: Manivannan Sadhasivam @ 2020-08-22 13:13 UTC (permalink / raw)
  To: Cristian Ciocaltea
  Cc: Lee Jones, Rob Herring, Dmitry Torokhov, Sebastian Reichel,
	Liam Girdwood, Mark Brown, Andreas Färber, linux-actions,
	devicetree, linux-kernel, linux-input, linux-pm

Hi Cristi,

Thanks for the series! I'll take a look soon but there is a quick comment
below.

On Sat, Aug 22, 2020 at 01:26:53AM +0300, Cristian Ciocaltea wrote:
> I have just realized I had omitted the changelog - sorry:
> 
> Changes in v2:
> - Reworked MFD core & I2C driver
>   * Integrated Lee's feedback
>   * Added support for using the regmap within atomic contexts
>   * Added support for ATC2603C chip variant
>   * Reorganized KConfig entries
> - Improved regulator driver
>   * Added support for ATC2603C variant
>   * Used helper macros for more compact specification of regulator_desc items
>   * Added more regulator capabilities
> - Added power controller driver
>   * Provides system poweroff/reboot functionalities
>   * Requires support for I2C Atomic transfers in the Owl driver (already submitted)
> - Added onkey driver: exposes the power button as an input device
> - Added yaml binding doc
> - Rebased patchset on kernel v5.9-rc1
> 
> Kind regards,
> Cristi
> 
> On Sat, Aug 22, 2020 at 01:19:46AM +0300, Cristian Ciocaltea wrote:
> > This is re-spin of the patch series submitted some time ago by Mani,
> > who added initial support (MFD core and regulators) for the Actions
> > Semi ATC260x PMICs:
> > https://lore.kernel.org/lkml/20190617155011.15376-1-manivannan.sadhasivam@linaro.org/
> > 
> > The ATC260x family of PMICs integrates Audio Codec, Power management,
> > Clock generation and GPIO controller blocks. There are currently 3
> > variants: ATC2603A, ATC2603C and ATC2609A.
> > 
> > In addition to the ATC2609A regulator functionality provided that time,
> > this patchset adds support for the ATC2603C variant, together with some
> > new functionalities for both chips: power controller and onkey input.
> > The ATC2603A variant remains unsupported for the moment.
> > 
> > This has been tested on RoseapplePi, a SBC based on the Action Semi S500
> > SoC, which integrates ATC2603C PMIC. An initial support for this board
> > has been already submitted:
> > https://lore.kernel.org/lkml/cover.1592123160.git.cristian.ciocaltea@gmail.com/
> > 
> > Please note that enabling the ATC260x PMICs on the compatible Actions
> > Semi Owl SoC based boards depends on the following:
> > 
> > * Actions Semi SIRQ driver (for PMIC DTS setup):
> >   https://lore.kernel.org/lkml/cover.1597852360.git.cristian.ciocaltea@gmail.com/
> > 
> > * I2C Atomic transfers in Actions Semi Owl driver (for proper operation
> >   of the power controller driver):
> >   https://lore.kernel.org/lkml/b086ef6d355d9730c839359e15eb06175283e323.1596485741.git.cristian.ciocaltea@gmail.com/
> >   
> > Thanks,
> > Cristi
> > 
> > Cristian Ciocaltea (6):
> >   dt-bindings: mfd: Add Actions Semi ATC260x PMIC binding
> >   mfd: Add MFD driver for ATC260x PMICs
> >   regulator: Add regulator driver for ATC260x PMICs

You need to preserve my authorship for above two patches. Adding the signed-off-by
is not enough.

> >   power: reset: Add poweroff driver for ATC260x PMICs
> >   input: atc260x: Add onkey driver for ATC260x PMICs
> >   MAINTAINERS: Add entry for ATC260x PMIC

I think this one too.

Thanks,
Mani

> > 
> >  .../bindings/mfd/actions,atc260x.yaml         | 221 ++++++++
> >  MAINTAINERS                                   |  12 +
> >  drivers/input/misc/Kconfig                    |  11 +
> >  drivers/input/misc/Makefile                   |   2 +-
> >  drivers/input/misc/atc260x-onkey.c            | 304 +++++++++++
> >  drivers/mfd/Kconfig                           |  18 +
> >  drivers/mfd/Makefile                          |   3 +
> >  drivers/mfd/atc260x-core.c                    | 290 ++++++++++
> >  drivers/mfd/atc260x-i2c.c                     |  73 +++
> >  drivers/power/reset/Kconfig                   |   8 +-
> >  drivers/power/reset/Makefile                  |   1 +
> >  drivers/power/reset/atc260x-poweroff.c        | 274 ++++++++++
> >  drivers/regulator/Kconfig                     |   8 +
> >  drivers/regulator/Makefile                    |   1 +
> >  drivers/regulator/atc260x-regulator.c         | 511 ++++++++++++++++++
> >  include/linux/mfd/atc260x/atc2603c.h          | 281 ++++++++++
> >  include/linux/mfd/atc260x/atc2609a.h          | 308 +++++++++++
> >  include/linux/mfd/atc260x/core.h              |  86 +++
> >  18 files changed, 2410 insertions(+), 2 deletions(-)
> >  create mode 100644 Documentation/devicetree/bindings/mfd/actions,atc260x.yaml
> >  create mode 100644 drivers/input/misc/atc260x-onkey.c
> >  create mode 100644 drivers/mfd/atc260x-core.c
> >  create mode 100644 drivers/mfd/atc260x-i2c.c
> >  create mode 100644 drivers/power/reset/atc260x-poweroff.c
> >  create mode 100644 drivers/regulator/atc260x-regulator.c
> >  create mode 100644 include/linux/mfd/atc260x/atc2603c.h
> >  create mode 100644 include/linux/mfd/atc260x/atc2609a.h
> >  create mode 100644 include/linux/mfd/atc260x/core.h
> > 
> > -- 
> > 2.28.0
> > 

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 0/6] Add initial support for ATC260x PMICs
  2020-08-22 13:13   ` Manivannan Sadhasivam
@ 2020-08-22 23:24     ` Cristian Ciocaltea
  2020-08-25  3:48       ` Manivannan Sadhasivam
  0 siblings, 1 reply; 23+ messages in thread
From: Cristian Ciocaltea @ 2020-08-22 23:24 UTC (permalink / raw)
  To: Manivannan Sadhasivam
  Cc: Lee Jones, Rob Herring, Dmitry Torokhov, Sebastian Reichel,
	Liam Girdwood, Mark Brown, Andreas Färber, linux-actions,
	devicetree, linux-kernel, linux-input, linux-pm

Hi Mani,

On Sat, Aug 22, 2020 at 06:43:43PM +0530, Manivannan Sadhasivam wrote:
> Hi Cristi,
> 
> Thanks for the series! I'll take a look soon but there is a quick comment
> below.
> 
> On Sat, Aug 22, 2020 at 01:26:53AM +0300, Cristian Ciocaltea wrote:
> > I have just realized I had omitted the changelog - sorry:
> > 
> > Changes in v2:
> > - Reworked MFD core & I2C driver
> >   * Integrated Lee's feedback
> >   * Added support for using the regmap within atomic contexts
> >   * Added support for ATC2603C chip variant
> >   * Reorganized KConfig entries
> > - Improved regulator driver
> >   * Added support for ATC2603C variant
> >   * Used helper macros for more compact specification of regulator_desc items
> >   * Added more regulator capabilities
> > - Added power controller driver
> >   * Provides system poweroff/reboot functionalities
> >   * Requires support for I2C Atomic transfers in the Owl driver (already submitted)
> > - Added onkey driver: exposes the power button as an input device
> > - Added yaml binding doc
> > - Rebased patchset on kernel v5.9-rc1
> > 
> > Kind regards,
> > Cristi
> > 
> > On Sat, Aug 22, 2020 at 01:19:46AM +0300, Cristian Ciocaltea wrote:
> > > This is re-spin of the patch series submitted some time ago by Mani,
> > > who added initial support (MFD core and regulators) for the Actions
> > > Semi ATC260x PMICs:
> > > https://lore.kernel.org/lkml/20190617155011.15376-1-manivannan.sadhasivam@linaro.org/
> > > 
> > > The ATC260x family of PMICs integrates Audio Codec, Power management,
> > > Clock generation and GPIO controller blocks. There are currently 3
> > > variants: ATC2603A, ATC2603C and ATC2609A.
> > > 
> > > In addition to the ATC2609A regulator functionality provided that time,
> > > this patchset adds support for the ATC2603C variant, together with some
> > > new functionalities for both chips: power controller and onkey input.
> > > The ATC2603A variant remains unsupported for the moment.
> > > 
> > > This has been tested on RoseapplePi, a SBC based on the Action Semi S500
> > > SoC, which integrates ATC2603C PMIC. An initial support for this board
> > > has been already submitted:
> > > https://lore.kernel.org/lkml/cover.1592123160.git.cristian.ciocaltea@gmail.com/
> > > 
> > > Please note that enabling the ATC260x PMICs on the compatible Actions
> > > Semi Owl SoC based boards depends on the following:
> > > 
> > > * Actions Semi SIRQ driver (for PMIC DTS setup):
> > >   https://lore.kernel.org/lkml/cover.1597852360.git.cristian.ciocaltea@gmail.com/
> > > 
> > > * I2C Atomic transfers in Actions Semi Owl driver (for proper operation
> > >   of the power controller driver):
> > >   https://lore.kernel.org/lkml/b086ef6d355d9730c839359e15eb06175283e323.1596485741.git.cristian.ciocaltea@gmail.com/
> > >   
> > > Thanks,
> > > Cristi
> > > 
> > > Cristian Ciocaltea (6):
> > >   dt-bindings: mfd: Add Actions Semi ATC260x PMIC binding
> > >   mfd: Add MFD driver for ATC260x PMICs
> > >   regulator: Add regulator driver for ATC260x PMICs
> 
> You need to preserve my authorship for above two patches. Adding the signed-off-by
> is not enough.

I'm very sorry for the mistake, I was not aware of the correct reposting
procedure. Should I resend the series now or could we handle a first round
of review before?

Thanks,
Cristi

> > >   power: reset: Add poweroff driver for ATC260x PMICs
> > >   input: atc260x: Add onkey driver for ATC260x PMICs
> > >   MAINTAINERS: Add entry for ATC260x PMIC
> 
> I think this one too.
> 
> Thanks,
> Mani
> 
> > > 
> > >  .../bindings/mfd/actions,atc260x.yaml         | 221 ++++++++
> > >  MAINTAINERS                                   |  12 +
> > >  drivers/input/misc/Kconfig                    |  11 +
> > >  drivers/input/misc/Makefile                   |   2 +-
> > >  drivers/input/misc/atc260x-onkey.c            | 304 +++++++++++
> > >  drivers/mfd/Kconfig                           |  18 +
> > >  drivers/mfd/Makefile                          |   3 +
> > >  drivers/mfd/atc260x-core.c                    | 290 ++++++++++
> > >  drivers/mfd/atc260x-i2c.c                     |  73 +++
> > >  drivers/power/reset/Kconfig                   |   8 +-
> > >  drivers/power/reset/Makefile                  |   1 +
> > >  drivers/power/reset/atc260x-poweroff.c        | 274 ++++++++++
> > >  drivers/regulator/Kconfig                     |   8 +
> > >  drivers/regulator/Makefile                    |   1 +
> > >  drivers/regulator/atc260x-regulator.c         | 511 ++++++++++++++++++
> > >  include/linux/mfd/atc260x/atc2603c.h          | 281 ++++++++++
> > >  include/linux/mfd/atc260x/atc2609a.h          | 308 +++++++++++
> > >  include/linux/mfd/atc260x/core.h              |  86 +++
> > >  18 files changed, 2410 insertions(+), 2 deletions(-)
> > >  create mode 100644 Documentation/devicetree/bindings/mfd/actions,atc260x.yaml
> > >  create mode 100644 drivers/input/misc/atc260x-onkey.c
> > >  create mode 100644 drivers/mfd/atc260x-core.c
> > >  create mode 100644 drivers/mfd/atc260x-i2c.c
> > >  create mode 100644 drivers/power/reset/atc260x-poweroff.c
> > >  create mode 100644 drivers/regulator/atc260x-regulator.c
> > >  create mode 100644 include/linux/mfd/atc260x/atc2603c.h
> > >  create mode 100644 include/linux/mfd/atc260x/atc2609a.h
> > >  create mode 100644 include/linux/mfd/atc260x/core.h
> > > 
> > > -- 
> > > 2.28.0
> > > 

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 3/6] regulator: Add regulator driver for ATC260x PMICs
  2020-08-21 22:19 ` [PATCH v2 3/6] regulator: Add regulator " Cristian Ciocaltea
@ 2020-08-24 11:00   ` Mark Brown
  2020-08-24 23:23     ` Cristian Ciocaltea
  0 siblings, 1 reply; 23+ messages in thread
From: Mark Brown @ 2020-08-24 11:00 UTC (permalink / raw)
  To: Cristian Ciocaltea
  Cc: Lee Jones, Rob Herring, Dmitry Torokhov, Sebastian Reichel,
	Liam Girdwood, Manivannan Sadhasivam, Andreas Färber,
	linux-actions, devicetree, linux-kernel, linux-input, linux-pm

[-- Attachment #1: Type: text/plain, Size: 1247 bytes --]

On Sat, Aug 22, 2020 at 01:19:49AM +0300, Cristian Ciocaltea wrote:

> +static int atc260x_set_voltage_time_sel(struct regulator_dev *rdev,
> +					unsigned int old_selector,
> +					unsigned int new_selector)
> +{
> +	struct atc260x_regulator_data *data = rdev_get_drvdata(rdev);
> +	int id = rdev_get_id(rdev);
> +
> +	if (new_selector > old_selector)
> +		return id > data->last_dcdc_reg_id ? data->voltage_time_ldo
> +						   : data->voltage_time_dcdc;

Please write normal conditional statements to make things easier to
read.  It also looks like this would be more robustly written by just
having separate ops for DCDCs and LDOs, this could easily break if
another device is supported in the driver.

> +static const struct of_device_id atc260x_regulator_of_match[] = {
> +	{ .compatible = "actions,atc2603c-regulator" },
> +	{ .compatible = "actions,atc2609a-regulator" },
> +	{ /* sentinel */ }
> +};
> +MODULE_DEVICE_TABLE(of, atc260x_regulator_of_match);

We don't need compatibles here, this is just reflecting the current
Linux device model into the OS neutral DT bindings.  Another OS may
choose to split regulators up differently.  We should just instantiate
the regulator device from the MFD based on identifying the chip overall.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 4/6] power: reset: Add poweroff driver for ATC260x PMICs
  2020-08-21 22:19 ` [PATCH v2 4/6] power: reset: Add poweroff " Cristian Ciocaltea
@ 2020-08-24 14:41   ` Sebastian Reichel
  2020-08-24 23:31     ` Cristian Ciocaltea
  0 siblings, 1 reply; 23+ messages in thread
From: Sebastian Reichel @ 2020-08-24 14:41 UTC (permalink / raw)
  To: Cristian Ciocaltea
  Cc: Lee Jones, Rob Herring, Dmitry Torokhov, Liam Girdwood,
	Mark Brown, Manivannan Sadhasivam, Andreas Färber,
	linux-actions, devicetree, linux-kernel, linux-input, linux-pm

[-- Attachment #1: Type: text/plain, Size: 10942 bytes --]

Hi,

On Sat, Aug 22, 2020 at 01:19:50AM +0300, Cristian Ciocaltea wrote:
> This driver provides poweroff and reboot support for a system through
> the ATC2603C and ATC2609A chip variants of the Actions Semi ATC260x
> family of PMICs.
> 
> Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
> ---
>  drivers/power/reset/Kconfig            |   8 +-
>  drivers/power/reset/Makefile           |   1 +
>  drivers/power/reset/atc260x-poweroff.c | 274 +++++++++++++++++++++++++
>  3 files changed, 282 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/power/reset/atc260x-poweroff.c
> 
> diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
> index 0a1fb5c74f83..df6c3676b892 100644
> --- a/drivers/power/reset/Kconfig
> +++ b/drivers/power/reset/Kconfig
> @@ -39,6 +39,13 @@ config POWER_RESET_AT91_SAMA5D2_SHDWC
>  	  This driver supports the alternate shutdown controller for some Atmel
>  	  SAMA5 SoCs. It is present for example on SAMA5D2 SoC.
>  
> +config POWER_RESET_ATC260X
> +	tristate "Actions Semi ATC260x PMIC power-off driver"
> +	depends on MFD_ATC260X
> +	help
> +	  This driver provides power-off and restart support for a system
> +	  through Actions Semi ATC260x series PMICs.
> +
>  config POWER_RESET_AXXIA
>  	bool "LSI Axxia reset driver"
>  	depends on ARCH_AXXIA
> @@ -285,4 +292,3 @@ config NVMEM_REBOOT_MODE
>  	  action according to the mode.
>  
>  endif
> -
> diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile
> index c51eceba9ea3..829df1157540 100644
> --- a/drivers/power/reset/Makefile
> +++ b/drivers/power/reset/Makefile
> @@ -3,6 +3,7 @@ obj-$(CONFIG_POWER_RESET_AS3722) += as3722-poweroff.o
>  obj-$(CONFIG_POWER_RESET_AT91_POWEROFF) += at91-poweroff.o
>  obj-$(CONFIG_POWER_RESET_AT91_RESET) += at91-reset.o
>  obj-$(CONFIG_POWER_RESET_AT91_SAMA5D2_SHDWC) += at91-sama5d2_shdwc.o
> +obj-$(CONFIG_POWER_RESET_ATC260X) += atc260x-poweroff.o
>  obj-$(CONFIG_POWER_RESET_AXXIA) += axxia-reset.o
>  obj-$(CONFIG_POWER_RESET_BRCMKONA) += brcm-kona-reset.o
>  obj-$(CONFIG_POWER_RESET_BRCMSTB) += brcmstb-reboot.o
> diff --git a/drivers/power/reset/atc260x-poweroff.c b/drivers/power/reset/atc260x-poweroff.c
> new file mode 100644
> index 000000000000..81a99e7e4a91
> --- /dev/null
> +++ b/drivers/power/reset/atc260x-poweroff.c
> @@ -0,0 +1,274 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Poweroff & reset driver for Actions Semi ATC260x PMICs
> + *
> + * Copyright (c) 2020 Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
> + */
> +
> +#include <linux/delay.h>
> +#include <linux/mfd/atc260x/core.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +#include <linux/power_supply.h>
> +#include <linux/reboot.h>
> +#include <linux/regmap.h>
> +
> +struct atc260x_pwrc {
> +	struct device *dev;
> +	struct regmap *regmap;
> +	struct notifier_block restart_nb;
> +	int (*do_poweroff)(const struct atc260x_pwrc *pwrc, bool restart);
> +};
> +
> +/* Global variable needed only for pm_power_off */
> +static struct atc260x_pwrc *atc260x_pwrc_data;
> +
> +static int atc2603c_do_poweroff(const struct atc260x_pwrc *pwrc, bool restart)
> +{
> +	int ret, deep_sleep = 0;
> +	uint reg_mask, reg_val;
> +
> +	/* S4-Deep Sleep Mode is NOT available for WALL/USB power */
> +	if (!restart && !power_supply_is_system_supplied()) {
> +		deep_sleep = 1;
> +		dev_info(pwrc->dev, "Enabling S4-Deep Sleep Mode");
> +	}
> +
> +	/* Update wakeup sources */
> +	reg_val = ATC2603C_PMU_SYS_CTL0_ONOFF_LONG_WK_EN |
> +		  (restart ? ATC2603C_PMU_SYS_CTL0_RESET_WK_EN
> +			   : ATC2603C_PMU_SYS_CTL0_ONOFF_SHORT_WK_EN);
> +
> +	ret = regmap_update_bits(pwrc->regmap, ATC2603C_PMU_SYS_CTL0,
> +				 ATC2603C_PMU_SYS_CTL0_WK_ALL, reg_val);
> +	if (ret)
> +		dev_warn(pwrc->dev, "failed to write SYS_CTL0: %d\n", ret);
> +
> +	/* Update power mode */
> +	reg_mask = ATC2603C_PMU_SYS_CTL3_EN_S2 | ATC2603C_PMU_SYS_CTL3_EN_S3;
> +
> +	ret = regmap_update_bits(pwrc->regmap, ATC2603C_PMU_SYS_CTL3, reg_mask,
> +				 deep_sleep ? 0 : ATC2603C_PMU_SYS_CTL3_EN_S3);
> +	if (ret) {
> +		dev_err(pwrc->dev, "failed to write SYS_CTL3: %d\n", ret);
> +		return ret;
> +	}
> +
> +	/* Trigger poweroff / restart sequence */
> +	reg_mask = restart ? ATC2603C_PMU_SYS_CTL0_RESTART_EN
> +			   : ATC2603C_PMU_SYS_CTL1_EN_S1;
> +	reg_val = restart ? ATC2603C_PMU_SYS_CTL0_RESTART_EN : 0;
> +
> +	ret = regmap_update_bits(pwrc->regmap,
> +				 restart ? ATC2603C_PMU_SYS_CTL0 : ATC2603C_PMU_SYS_CTL1,
> +				 reg_mask, reg_val);
> +	if (ret) {
> +		dev_err(pwrc->dev, "failed to write SYS_CTL%d: %d\n",
> +			restart ? 0 : 1, ret);
> +		return ret;
> +	}
> +
> +	/* Wait for trigger completion */
> +	mdelay(200);
> +
> +	return 0;
> +}
> +
> +static int atc2609a_do_poweroff(const struct atc260x_pwrc *pwrc, bool restart)
> +{
> +	int ret, deep_sleep = 0;
> +	uint reg_mask, reg_val;
> +
> +	/* S4-Deep Sleep Mode is NOT available for WALL/USB power */
> +	if (!restart && !power_supply_is_system_supplied()) {
> +		deep_sleep = 1;
> +		dev_info(pwrc->dev, "Enabling S4-Deep Sleep Mode");
> +	}
> +
> +	/* Update wakeup sources */
> +	reg_val = ATC2609A_PMU_SYS_CTL0_ONOFF_LONG_WK_EN |
> +		  (restart ? ATC2609A_PMU_SYS_CTL0_RESET_WK_EN
> +			   : ATC2609A_PMU_SYS_CTL0_ONOFF_SHORT_WK_EN);
> +
> +	ret = regmap_update_bits(pwrc->regmap, ATC2609A_PMU_SYS_CTL0,
> +				 ATC2609A_PMU_SYS_CTL0_WK_ALL, reg_val);
> +	if (ret)
> +		dev_warn(pwrc->dev, "failed to write SYS_CTL0: %d\n", ret);
> +
> +	/* Update power mode */
> +	reg_mask = ATC2609A_PMU_SYS_CTL3_EN_S2 | ATC2609A_PMU_SYS_CTL3_EN_S3;
> +
> +	ret = regmap_update_bits(pwrc->regmap, ATC2609A_PMU_SYS_CTL3, reg_mask,
> +				 deep_sleep ? 0 : ATC2609A_PMU_SYS_CTL3_EN_S3);
> +	if (ret) {
> +		dev_err(pwrc->dev, "failed to write SYS_CTL3: %d\n", ret);
> +		return ret;
> +	}
> +
> +	/* Trigger poweroff / restart sequence */
> +	reg_mask = restart ? ATC2609A_PMU_SYS_CTL0_RESTART_EN
> +			   : ATC2609A_PMU_SYS_CTL1_EN_S1;
> +	reg_val = restart ? ATC2609A_PMU_SYS_CTL0_RESTART_EN : 0;
> +
> +	ret = regmap_update_bits(pwrc->regmap,
> +				 restart ? ATC2609A_PMU_SYS_CTL0 : ATC2609A_PMU_SYS_CTL1,
> +				 reg_mask, reg_val);
> +	if (ret) {
> +		dev_err(pwrc->dev, "failed to write SYS_CTL%d: %d\n",
> +			restart ? 0 : 1, ret);
> +		return ret;
> +	}
> +
> +	/* Wait for trigger completion */
> +	mdelay(200);
> +
> +	return 0;
> +}
> +
> +static int atc2603c_init(const struct atc260x_pwrc *pwrc)
> +{
> +	int ret;
> +
> +	/*
> +	 * Delay transition from S2/S3 to S1 in order to avoid
> +	 * DDR init failure in Bootloader.
> +	 */
> +	ret = regmap_update_bits(pwrc->regmap, ATC2603C_PMU_SYS_CTL3,
> +				 ATC2603C_PMU_SYS_CTL3_S2S3TOS1_TIMER_EN,
> +				 ATC2603C_PMU_SYS_CTL3_S2S3TOS1_TIMER_EN);
> +	if (ret)
> +		dev_warn(pwrc->dev, "failed to write SYS_CTL3: %d\n", ret);
> +
> +	/* Set wakeup sources */
> +	ret = regmap_update_bits(pwrc->regmap, ATC2603C_PMU_SYS_CTL0,
> +				 ATC2603C_PMU_SYS_CTL0_WK_ALL,
> +				 ATC2603C_PMU_SYS_CTL0_HDSW_WK_EN |
> +				 ATC2603C_PMU_SYS_CTL0_ONOFF_LONG_WK_EN);
> +	if (ret)
> +		dev_warn(pwrc->dev, "failed to write SYS_CTL0: %d\n", ret);
> +
> +	return ret;
> +}
> +
> +static int atc2609a_init(const struct atc260x_pwrc *pwrc)
> +{
> +	int ret;
> +
> +	/* Set wakeup sources */
> +	ret = regmap_update_bits(pwrc->regmap, ATC2609A_PMU_SYS_CTL0,
> +				 ATC2609A_PMU_SYS_CTL0_WK_ALL,
> +				 ATC2609A_PMU_SYS_CTL0_HDSW_WK_EN |
> +				 ATC2609A_PMU_SYS_CTL0_ONOFF_LONG_WK_EN);
> +	if (ret)
> +		dev_warn(pwrc->dev, "failed to write SYS_CTL0: %d\n", ret);
> +
> +	return ret;
> +}
> +
> +static void atc260x_pwrc_pm_handler(void)
> +{
> +	atc260x_pwrc_data->do_poweroff(atc260x_pwrc_data, false);
> +
> +	WARN_ONCE(1, "Unable to power off system\n");
> +}
> +
> +static int atc260x_pwrc_restart_handler(struct notifier_block *nb,
> +					unsigned long mode, void *cmd)
> +{
> +	struct atc260x_pwrc *pwrc = container_of(nb, struct atc260x_pwrc,
> +						 restart_nb);
> +	pwrc->do_poweroff(pwrc, true);
> +
> +	return NOTIFY_DONE;
> +}
> +
> +static int atc260x_pwrc_probe(struct platform_device *pdev)
> +{
> +	struct atc260x *atc260x = dev_get_drvdata(pdev->dev.parent);
> +	struct atc260x_pwrc *priv;
> +	int ret;
> +
> +	if (!pdev->dev.of_node)
> +		return -ENXIO;
> +
> +	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
> +	if (!priv)
> +		return -ENOMEM;
> +
> +	priv->dev = &pdev->dev;
> +	priv->regmap = atc260x->regmap;
> +	priv->restart_nb.notifier_call = atc260x_pwrc_restart_handler;
> +	priv->restart_nb.priority = 192;
> +
> +	switch (atc260x->ic_type) {
> +	case ATC2603C:
> +		priv->do_poweroff = atc2603c_do_poweroff;
> +		ret = atc2603c_init(priv);
> +		break;
> +	case ATC2609A:
> +		priv->do_poweroff = atc2609a_do_poweroff;
> +		ret = atc2609a_init(priv);
> +		break;
> +	default:
> +		dev_err(priv->dev,
> +			"Poweroff not supported for ATC260x PMIC type: %u\n",
> +			atc260x->ic_type);
> +		return -EINVAL;
> +	}
> +
> +	if (ret)
> +		return ret;
> +
> +	platform_set_drvdata(pdev, priv);
> +
> +	if (!pm_power_off) {
> +		atc260x_pwrc_data = priv;
> +		pm_power_off = atc260x_pwrc_pm_handler;
> +	} else {
> +		dev_warn(priv->dev, "Poweroff callback already assigned\n");
> +	}
> +
> +	ret = register_restart_handler(&priv->restart_nb);
> +	if (ret)
> +		dev_err(priv->dev, "failed to register restart handler: %d\n",
> +			ret);
> +
> +	return ret;
> +}
> +
> +static int atc260x_pwrc_remove(struct platform_device *pdev)
> +{
> +	struct atc260x_pwrc *priv = platform_get_drvdata(pdev);
> +
> +	if (atc260x_pwrc_data == priv) {
> +		pm_power_off = NULL;
> +		atc260x_pwrc_data = NULL;
> +	}
> +
> +	unregister_restart_handler(&priv->restart_nb);
> +
> +	return 0;
> +}
> +
> +static const struct of_device_id atc260x_pwrc_of_match[] = {
> +	{ .compatible = "actions,atc2603c-pwrc" },
> +	{ .compatible = "actions,atc2609a-pwrc" },
> +	{ /* sentinel */ }
> +};
> +MODULE_DEVICE_TABLE(of, atc260x_pwrc_of_match);
> +
> +static struct platform_driver atc260x_pwrc_driver = {
> +	.probe = atc260x_pwrc_probe,
> +	.remove = atc260x_pwrc_remove,
> +	.driver = {
> +		.name = "atc260x-pwrc",
> +		.of_match_table = of_match_ptr(atc260x_pwrc_of_match),

drop of_match_ptr() and directly use atc260x_pwrc_of_match. Current
code would throw unused warning for atc260x_pwrc_of_match when OF is
disabled.

> +	},
> +};
> +
> +module_platform_driver(atc260x_pwrc_driver);
> +
> +MODULE_DESCRIPTION("Poweroff & reset driver for ATC260x PMICs");
> +MODULE_AUTHOR("Cristian Ciocaltea <cristian.ciocaltea@gmail.com>");
> +MODULE_LICENSE("GPL");

Otherwise LGTM,

-- Sebastian

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 3/6] regulator: Add regulator driver for ATC260x PMICs
  2020-08-24 11:00   ` Mark Brown
@ 2020-08-24 23:23     ` Cristian Ciocaltea
  2020-08-25 10:55       ` Mark Brown
  0 siblings, 1 reply; 23+ messages in thread
From: Cristian Ciocaltea @ 2020-08-24 23:23 UTC (permalink / raw)
  To: Mark Brown
  Cc: Lee Jones, Rob Herring, Dmitry Torokhov, Sebastian Reichel,
	Liam Girdwood, Manivannan Sadhasivam, Andreas Färber,
	linux-actions, devicetree, linux-kernel, linux-input, linux-pm

Hi Mark,

Thanks for reviewing!

On Mon, Aug 24, 2020 at 12:00:45PM +0100, Mark Brown wrote:
> On Sat, Aug 22, 2020 at 01:19:49AM +0300, Cristian Ciocaltea wrote:
> 
> > +static int atc260x_set_voltage_time_sel(struct regulator_dev *rdev,
> > +					unsigned int old_selector,
> > +					unsigned int new_selector)
> > +{
> > +	struct atc260x_regulator_data *data = rdev_get_drvdata(rdev);
> > +	int id = rdev_get_id(rdev);
> > +
> > +	if (new_selector > old_selector)
> > +		return id > data->last_dcdc_reg_id ? data->voltage_time_ldo
> > +						   : data->voltage_time_dcdc;
> 
> Please write normal conditional statements to make things easier to
> read.  It also looks like this would be more robustly written by just
> having separate ops for DCDCs and LDOs, this could easily break if
> another device is supported in the driver.

Sure, I can provide separate ops, but in this case we duplicate almost
all of them. If this is not acceptable, then I will just rewrite the
conditional statement.

> > +static const struct of_device_id atc260x_regulator_of_match[] = {
> > +	{ .compatible = "actions,atc2603c-regulator" },
> > +	{ .compatible = "actions,atc2609a-regulator" },
> > +	{ /* sentinel */ }
> > +};
> > +MODULE_DEVICE_TABLE(of, atc260x_regulator_of_match);
> 
> We don't need compatibles here, this is just reflecting the current
> Linux device model into the OS neutral DT bindings.  Another OS may
> choose to split regulators up differently.  We should just instantiate
> the regulator device from the MFD based on identifying the chip overall.

I have actually seen this in some MFD drivers I had been studying before
starting this work. I wasn't sure what is the rationale behind, I
assumed they have just an informative purpose.

So, if I understand correctly, this approach is deprecated now and I
should remove the compatibles from both the function driver and the
corresponding mfd_cell in the core implementation. And not only for
regulators, but for all the other functions of the MFD device.

Regards,
Cristi

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 4/6] power: reset: Add poweroff driver for ATC260x PMICs
  2020-08-24 14:41   ` Sebastian Reichel
@ 2020-08-24 23:31     ` Cristian Ciocaltea
  0 siblings, 0 replies; 23+ messages in thread
From: Cristian Ciocaltea @ 2020-08-24 23:31 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Lee Jones, Rob Herring, Dmitry Torokhov, Liam Girdwood,
	Mark Brown, Manivannan Sadhasivam, Andreas Färber,
	linux-actions, devicetree, linux-kernel, linux-input, linux-pm

Hi Sebastian,

Thanks for the review!

On Mon, Aug 24, 2020 at 04:41:13PM +0200, Sebastian Reichel wrote:
> Hi,
> 
> On Sat, Aug 22, 2020 at 01:19:50AM +0300, Cristian Ciocaltea wrote:
> > This driver provides poweroff and reboot support for a system through
> > the ATC2603C and ATC2609A chip variants of the Actions Semi ATC260x
> > family of PMICs.
> > 
> > Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
> > ---
> >  drivers/power/reset/Kconfig            |   8 +-
> >  drivers/power/reset/Makefile           |   1 +
> >  drivers/power/reset/atc260x-poweroff.c | 274 +++++++++++++++++++++++++
> >  3 files changed, 282 insertions(+), 1 deletion(-)
> >  create mode 100644 drivers/power/reset/atc260x-poweroff.c
> > 
> > diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
> > index 0a1fb5c74f83..df6c3676b892 100644
> > --- a/drivers/power/reset/Kconfig
> > +++ b/drivers/power/reset/Kconfig
> > @@ -39,6 +39,13 @@ config POWER_RESET_AT91_SAMA5D2_SHDWC
> >  	  This driver supports the alternate shutdown controller for some Atmel
> >  	  SAMA5 SoCs. It is present for example on SAMA5D2 SoC.
> >  
> > +config POWER_RESET_ATC260X
> > +	tristate "Actions Semi ATC260x PMIC power-off driver"
> > +	depends on MFD_ATC260X
> > +	help
> > +	  This driver provides power-off and restart support for a system
> > +	  through Actions Semi ATC260x series PMICs.
> > +
> >  config POWER_RESET_AXXIA
> >  	bool "LSI Axxia reset driver"
> >  	depends on ARCH_AXXIA
> > @@ -285,4 +292,3 @@ config NVMEM_REBOOT_MODE
> >  	  action according to the mode.
> >  
> >  endif
> > -
> > diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile
> > index c51eceba9ea3..829df1157540 100644
> > --- a/drivers/power/reset/Makefile
> > +++ b/drivers/power/reset/Makefile
> > @@ -3,6 +3,7 @@ obj-$(CONFIG_POWER_RESET_AS3722) += as3722-poweroff.o
> >  obj-$(CONFIG_POWER_RESET_AT91_POWEROFF) += at91-poweroff.o
> >  obj-$(CONFIG_POWER_RESET_AT91_RESET) += at91-reset.o
> >  obj-$(CONFIG_POWER_RESET_AT91_SAMA5D2_SHDWC) += at91-sama5d2_shdwc.o
> > +obj-$(CONFIG_POWER_RESET_ATC260X) += atc260x-poweroff.o
> >  obj-$(CONFIG_POWER_RESET_AXXIA) += axxia-reset.o
> >  obj-$(CONFIG_POWER_RESET_BRCMKONA) += brcm-kona-reset.o
> >  obj-$(CONFIG_POWER_RESET_BRCMSTB) += brcmstb-reboot.o
> > diff --git a/drivers/power/reset/atc260x-poweroff.c b/drivers/power/reset/atc260x-poweroff.c
> > new file mode 100644
> > index 000000000000..81a99e7e4a91
> > --- /dev/null
> > +++ b/drivers/power/reset/atc260x-poweroff.c
> > @@ -0,0 +1,274 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * Poweroff & reset driver for Actions Semi ATC260x PMICs
> > + *
> > + * Copyright (c) 2020 Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
> > + */
> > +
> > +#include <linux/delay.h>
> > +#include <linux/mfd/atc260x/core.h>
> > +#include <linux/module.h>
> > +#include <linux/of.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/power_supply.h>
> > +#include <linux/reboot.h>
> > +#include <linux/regmap.h>
> > +
> > +struct atc260x_pwrc {
> > +	struct device *dev;
> > +	struct regmap *regmap;
> > +	struct notifier_block restart_nb;
> > +	int (*do_poweroff)(const struct atc260x_pwrc *pwrc, bool restart);
> > +};
> > +
> > +/* Global variable needed only for pm_power_off */
> > +static struct atc260x_pwrc *atc260x_pwrc_data;
> > +
> > +static int atc2603c_do_poweroff(const struct atc260x_pwrc *pwrc, bool restart)
> > +{
> > +	int ret, deep_sleep = 0;
> > +	uint reg_mask, reg_val;
> > +
> > +	/* S4-Deep Sleep Mode is NOT available for WALL/USB power */
> > +	if (!restart && !power_supply_is_system_supplied()) {
> > +		deep_sleep = 1;
> > +		dev_info(pwrc->dev, "Enabling S4-Deep Sleep Mode");
> > +	}
> > +
> > +	/* Update wakeup sources */
> > +	reg_val = ATC2603C_PMU_SYS_CTL0_ONOFF_LONG_WK_EN |
> > +		  (restart ? ATC2603C_PMU_SYS_CTL0_RESET_WK_EN
> > +			   : ATC2603C_PMU_SYS_CTL0_ONOFF_SHORT_WK_EN);
> > +
> > +	ret = regmap_update_bits(pwrc->regmap, ATC2603C_PMU_SYS_CTL0,
> > +				 ATC2603C_PMU_SYS_CTL0_WK_ALL, reg_val);
> > +	if (ret)
> > +		dev_warn(pwrc->dev, "failed to write SYS_CTL0: %d\n", ret);
> > +
> > +	/* Update power mode */
> > +	reg_mask = ATC2603C_PMU_SYS_CTL3_EN_S2 | ATC2603C_PMU_SYS_CTL3_EN_S3;
> > +
> > +	ret = regmap_update_bits(pwrc->regmap, ATC2603C_PMU_SYS_CTL3, reg_mask,
> > +				 deep_sleep ? 0 : ATC2603C_PMU_SYS_CTL3_EN_S3);
> > +	if (ret) {
> > +		dev_err(pwrc->dev, "failed to write SYS_CTL3: %d\n", ret);
> > +		return ret;
> > +	}
> > +
> > +	/* Trigger poweroff / restart sequence */
> > +	reg_mask = restart ? ATC2603C_PMU_SYS_CTL0_RESTART_EN
> > +			   : ATC2603C_PMU_SYS_CTL1_EN_S1;
> > +	reg_val = restart ? ATC2603C_PMU_SYS_CTL0_RESTART_EN : 0;
> > +
> > +	ret = regmap_update_bits(pwrc->regmap,
> > +				 restart ? ATC2603C_PMU_SYS_CTL0 : ATC2603C_PMU_SYS_CTL1,
> > +				 reg_mask, reg_val);
> > +	if (ret) {
> > +		dev_err(pwrc->dev, "failed to write SYS_CTL%d: %d\n",
> > +			restart ? 0 : 1, ret);
> > +		return ret;
> > +	}
> > +
> > +	/* Wait for trigger completion */
> > +	mdelay(200);
> > +
> > +	return 0;
> > +}
> > +
> > +static int atc2609a_do_poweroff(const struct atc260x_pwrc *pwrc, bool restart)
> > +{
> > +	int ret, deep_sleep = 0;
> > +	uint reg_mask, reg_val;
> > +
> > +	/* S4-Deep Sleep Mode is NOT available for WALL/USB power */
> > +	if (!restart && !power_supply_is_system_supplied()) {
> > +		deep_sleep = 1;
> > +		dev_info(pwrc->dev, "Enabling S4-Deep Sleep Mode");
> > +	}
> > +
> > +	/* Update wakeup sources */
> > +	reg_val = ATC2609A_PMU_SYS_CTL0_ONOFF_LONG_WK_EN |
> > +		  (restart ? ATC2609A_PMU_SYS_CTL0_RESET_WK_EN
> > +			   : ATC2609A_PMU_SYS_CTL0_ONOFF_SHORT_WK_EN);
> > +
> > +	ret = regmap_update_bits(pwrc->regmap, ATC2609A_PMU_SYS_CTL0,
> > +				 ATC2609A_PMU_SYS_CTL0_WK_ALL, reg_val);
> > +	if (ret)
> > +		dev_warn(pwrc->dev, "failed to write SYS_CTL0: %d\n", ret);
> > +
> > +	/* Update power mode */
> > +	reg_mask = ATC2609A_PMU_SYS_CTL3_EN_S2 | ATC2609A_PMU_SYS_CTL3_EN_S3;
> > +
> > +	ret = regmap_update_bits(pwrc->regmap, ATC2609A_PMU_SYS_CTL3, reg_mask,
> > +				 deep_sleep ? 0 : ATC2609A_PMU_SYS_CTL3_EN_S3);
> > +	if (ret) {
> > +		dev_err(pwrc->dev, "failed to write SYS_CTL3: %d\n", ret);
> > +		return ret;
> > +	}
> > +
> > +	/* Trigger poweroff / restart sequence */
> > +	reg_mask = restart ? ATC2609A_PMU_SYS_CTL0_RESTART_EN
> > +			   : ATC2609A_PMU_SYS_CTL1_EN_S1;
> > +	reg_val = restart ? ATC2609A_PMU_SYS_CTL0_RESTART_EN : 0;
> > +
> > +	ret = regmap_update_bits(pwrc->regmap,
> > +				 restart ? ATC2609A_PMU_SYS_CTL0 : ATC2609A_PMU_SYS_CTL1,
> > +				 reg_mask, reg_val);
> > +	if (ret) {
> > +		dev_err(pwrc->dev, "failed to write SYS_CTL%d: %d\n",
> > +			restart ? 0 : 1, ret);
> > +		return ret;
> > +	}
> > +
> > +	/* Wait for trigger completion */
> > +	mdelay(200);
> > +
> > +	return 0;
> > +}
> > +
> > +static int atc2603c_init(const struct atc260x_pwrc *pwrc)
> > +{
> > +	int ret;
> > +
> > +	/*
> > +	 * Delay transition from S2/S3 to S1 in order to avoid
> > +	 * DDR init failure in Bootloader.
> > +	 */
> > +	ret = regmap_update_bits(pwrc->regmap, ATC2603C_PMU_SYS_CTL3,
> > +				 ATC2603C_PMU_SYS_CTL3_S2S3TOS1_TIMER_EN,
> > +				 ATC2603C_PMU_SYS_CTL3_S2S3TOS1_TIMER_EN);
> > +	if (ret)
> > +		dev_warn(pwrc->dev, "failed to write SYS_CTL3: %d\n", ret);
> > +
> > +	/* Set wakeup sources */
> > +	ret = regmap_update_bits(pwrc->regmap, ATC2603C_PMU_SYS_CTL0,
> > +				 ATC2603C_PMU_SYS_CTL0_WK_ALL,
> > +				 ATC2603C_PMU_SYS_CTL0_HDSW_WK_EN |
> > +				 ATC2603C_PMU_SYS_CTL0_ONOFF_LONG_WK_EN);
> > +	if (ret)
> > +		dev_warn(pwrc->dev, "failed to write SYS_CTL0: %d\n", ret);
> > +
> > +	return ret;
> > +}
> > +
> > +static int atc2609a_init(const struct atc260x_pwrc *pwrc)
> > +{
> > +	int ret;
> > +
> > +	/* Set wakeup sources */
> > +	ret = regmap_update_bits(pwrc->regmap, ATC2609A_PMU_SYS_CTL0,
> > +				 ATC2609A_PMU_SYS_CTL0_WK_ALL,
> > +				 ATC2609A_PMU_SYS_CTL0_HDSW_WK_EN |
> > +				 ATC2609A_PMU_SYS_CTL0_ONOFF_LONG_WK_EN);
> > +	if (ret)
> > +		dev_warn(pwrc->dev, "failed to write SYS_CTL0: %d\n", ret);
> > +
> > +	return ret;
> > +}
> > +
> > +static void atc260x_pwrc_pm_handler(void)
> > +{
> > +	atc260x_pwrc_data->do_poweroff(atc260x_pwrc_data, false);
> > +
> > +	WARN_ONCE(1, "Unable to power off system\n");
> > +}
> > +
> > +static int atc260x_pwrc_restart_handler(struct notifier_block *nb,
> > +					unsigned long mode, void *cmd)
> > +{
> > +	struct atc260x_pwrc *pwrc = container_of(nb, struct atc260x_pwrc,
> > +						 restart_nb);
> > +	pwrc->do_poweroff(pwrc, true);
> > +
> > +	return NOTIFY_DONE;
> > +}
> > +
> > +static int atc260x_pwrc_probe(struct platform_device *pdev)
> > +{
> > +	struct atc260x *atc260x = dev_get_drvdata(pdev->dev.parent);
> > +	struct atc260x_pwrc *priv;
> > +	int ret;
> > +
> > +	if (!pdev->dev.of_node)
> > +		return -ENXIO;
> > +
> > +	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
> > +	if (!priv)
> > +		return -ENOMEM;
> > +
> > +	priv->dev = &pdev->dev;
> > +	priv->regmap = atc260x->regmap;
> > +	priv->restart_nb.notifier_call = atc260x_pwrc_restart_handler;
> > +	priv->restart_nb.priority = 192;
> > +
> > +	switch (atc260x->ic_type) {
> > +	case ATC2603C:
> > +		priv->do_poweroff = atc2603c_do_poweroff;
> > +		ret = atc2603c_init(priv);
> > +		break;
> > +	case ATC2609A:
> > +		priv->do_poweroff = atc2609a_do_poweroff;
> > +		ret = atc2609a_init(priv);
> > +		break;
> > +	default:
> > +		dev_err(priv->dev,
> > +			"Poweroff not supported for ATC260x PMIC type: %u\n",
> > +			atc260x->ic_type);
> > +		return -EINVAL;
> > +	}
> > +
> > +	if (ret)
> > +		return ret;
> > +
> > +	platform_set_drvdata(pdev, priv);
> > +
> > +	if (!pm_power_off) {
> > +		atc260x_pwrc_data = priv;
> > +		pm_power_off = atc260x_pwrc_pm_handler;
> > +	} else {
> > +		dev_warn(priv->dev, "Poweroff callback already assigned\n");
> > +	}
> > +
> > +	ret = register_restart_handler(&priv->restart_nb);
> > +	if (ret)
> > +		dev_err(priv->dev, "failed to register restart handler: %d\n",
> > +			ret);
> > +
> > +	return ret;
> > +}
> > +
> > +static int atc260x_pwrc_remove(struct platform_device *pdev)
> > +{
> > +	struct atc260x_pwrc *priv = platform_get_drvdata(pdev);
> > +
> > +	if (atc260x_pwrc_data == priv) {
> > +		pm_power_off = NULL;
> > +		atc260x_pwrc_data = NULL;
> > +	}
> > +
> > +	unregister_restart_handler(&priv->restart_nb);
> > +
> > +	return 0;
> > +}
> > +
> > +static const struct of_device_id atc260x_pwrc_of_match[] = {
> > +	{ .compatible = "actions,atc2603c-pwrc" },
> > +	{ .compatible = "actions,atc2609a-pwrc" },
> > +	{ /* sentinel */ }
> > +};
> > +MODULE_DEVICE_TABLE(of, atc260x_pwrc_of_match);
> > +
> > +static struct platform_driver atc260x_pwrc_driver = {
> > +	.probe = atc260x_pwrc_probe,
> > +	.remove = atc260x_pwrc_remove,
> > +	.driver = {
> > +		.name = "atc260x-pwrc",
> > +		.of_match_table = of_match_ptr(atc260x_pwrc_of_match),
> 
> drop of_match_ptr() and directly use atc260x_pwrc_of_match. Current
> code would throw unused warning for atc260x_pwrc_of_match when OF is
> disabled.

Done.

> > +	},
> > +};
> > +
> > +module_platform_driver(atc260x_pwrc_driver);
> > +
> > +MODULE_DESCRIPTION("Poweroff & reset driver for ATC260x PMICs");
> > +MODULE_AUTHOR("Cristian Ciocaltea <cristian.ciocaltea@gmail.com>");
> > +MODULE_LICENSE("GPL");
> 
> Otherwise LGTM,
> 
> -- Sebastian

Regards,
Cristi

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 0/6] Add initial support for ATC260x PMICs
  2020-08-22 23:24     ` Cristian Ciocaltea
@ 2020-08-25  3:48       ` Manivannan Sadhasivam
  0 siblings, 0 replies; 23+ messages in thread
From: Manivannan Sadhasivam @ 2020-08-25  3:48 UTC (permalink / raw)
  To: Cristian Ciocaltea
  Cc: Lee Jones, Rob Herring, Dmitry Torokhov, Sebastian Reichel,
	Liam Girdwood, Mark Brown, Andreas Färber, linux-actions,
	devicetree, linux-kernel, linux-input, linux-pm



On 23 August 2020 4:54:05 AM IST, Cristian Ciocaltea <cristian.ciocaltea@gmail.com> wrote:
>Hi Mani,
>
>On Sat, Aug 22, 2020 at 06:43:43PM +0530, Manivannan Sadhasivam wrote:
>> Hi Cristi,
>> 
>> Thanks for the series! I'll take a look soon but there is a quick
>comment
>> below.
>> 
>> On Sat, Aug 22, 2020 at 01:26:53AM +0300, Cristian Ciocaltea wrote:
>> > I have just realized I had omitted the changelog - sorry:
>> > 
>> > Changes in v2:
>> > - Reworked MFD core & I2C driver
>> >   * Integrated Lee's feedback
>> >   * Added support for using the regmap within atomic contexts
>> >   * Added support for ATC2603C chip variant
>> >   * Reorganized KConfig entries
>> > - Improved regulator driver
>> >   * Added support for ATC2603C variant
>> >   * Used helper macros for more compact specification of
>regulator_desc items
>> >   * Added more regulator capabilities
>> > - Added power controller driver
>> >   * Provides system poweroff/reboot functionalities
>> >   * Requires support for I2C Atomic transfers in the Owl driver
>(already submitted)
>> > - Added onkey driver: exposes the power button as an input device
>> > - Added yaml binding doc
>> > - Rebased patchset on kernel v5.9-rc1
>> > 
>> > Kind regards,
>> > Cristi
>> > 
>> > On Sat, Aug 22, 2020 at 01:19:46AM +0300, Cristian Ciocaltea wrote:
>> > > This is re-spin of the patch series submitted some time ago by
>Mani,
>> > > who added initial support (MFD core and regulators) for the
>Actions
>> > > Semi ATC260x PMICs:
>> > >
>https://lore.kernel.org/lkml/20190617155011.15376-1-manivannan.sadhasivam@linaro.org/
>> > > 
>> > > The ATC260x family of PMICs integrates Audio Codec, Power
>management,
>> > > Clock generation and GPIO controller blocks. There are currently
>3
>> > > variants: ATC2603A, ATC2603C and ATC2609A.
>> > > 
>> > > In addition to the ATC2609A regulator functionality provided that
>time,
>> > > this patchset adds support for the ATC2603C variant, together
>with some
>> > > new functionalities for both chips: power controller and onkey
>input.
>> > > The ATC2603A variant remains unsupported for the moment.
>> > > 
>> > > This has been tested on RoseapplePi, a SBC based on the Action
>Semi S500
>> > > SoC, which integrates ATC2603C PMIC. An initial support for this
>board
>> > > has been already submitted:
>> > >
>https://lore.kernel.org/lkml/cover.1592123160.git.cristian.ciocaltea@gmail.com/
>> > > 
>> > > Please note that enabling the ATC260x PMICs on the compatible
>Actions
>> > > Semi Owl SoC based boards depends on the following:
>> > > 
>> > > * Actions Semi SIRQ driver (for PMIC DTS setup):
>> > >  
>https://lore.kernel.org/lkml/cover.1597852360.git.cristian.ciocaltea@gmail.com/
>> > > 
>> > > * I2C Atomic transfers in Actions Semi Owl driver (for proper
>operation
>> > >   of the power controller driver):
>> > >  
>https://lore.kernel.org/lkml/b086ef6d355d9730c839359e15eb06175283e323.1596485741.git.cristian.ciocaltea@gmail.com/
>> > >   
>> > > Thanks,
>> > > Cristi
>> > > 
>> > > Cristian Ciocaltea (6):
>> > >   dt-bindings: mfd: Add Actions Semi ATC260x PMIC binding
>> > >   mfd: Add MFD driver for ATC260x PMICs
>> > >   regulator: Add regulator driver for ATC260x PMICs
>> 
>> You need to preserve my authorship for above two patches. Adding the
>signed-off-by
>> is not enough.
>
>I'm very sorry for the mistake, I was not aware of the correct
>reposting
>procedure. Should I resend the series now or could we handle a first
>round
>of review before?
>

You can wait to get review comments. 

Thanks, 
Mani 

>Thanks,
>Cristi
>
>> > >   power: reset: Add poweroff driver for ATC260x PMICs
>> > >   input: atc260x: Add onkey driver for ATC260x PMICs
>> > >   MAINTAINERS: Add entry for ATC260x PMIC
>> 
>> I think this one too.
>> 
>> Thanks,
>> Mani
>> 
>> > > 
>> > >  .../bindings/mfd/actions,atc260x.yaml         | 221 ++++++++
>> > >  MAINTAINERS                                   |  12 +
>> > >  drivers/input/misc/Kconfig                    |  11 +
>> > >  drivers/input/misc/Makefile                   |   2 +-
>> > >  drivers/input/misc/atc260x-onkey.c            | 304 +++++++++++
>> > >  drivers/mfd/Kconfig                           |  18 +
>> > >  drivers/mfd/Makefile                          |   3 +
>> > >  drivers/mfd/atc260x-core.c                    | 290 ++++++++++
>> > >  drivers/mfd/atc260x-i2c.c                     |  73 +++
>> > >  drivers/power/reset/Kconfig                   |   8 +-
>> > >  drivers/power/reset/Makefile                  |   1 +
>> > >  drivers/power/reset/atc260x-poweroff.c        | 274 ++++++++++
>> > >  drivers/regulator/Kconfig                     |   8 +
>> > >  drivers/regulator/Makefile                    |   1 +
>> > >  drivers/regulator/atc260x-regulator.c         | 511
>++++++++++++++++++
>> > >  include/linux/mfd/atc260x/atc2603c.h          | 281 ++++++++++
>> > >  include/linux/mfd/atc260x/atc2609a.h          | 308 +++++++++++
>> > >  include/linux/mfd/atc260x/core.h              |  86 +++
>> > >  18 files changed, 2410 insertions(+), 2 deletions(-)
>> > >  create mode 100644
>Documentation/devicetree/bindings/mfd/actions,atc260x.yaml
>> > >  create mode 100644 drivers/input/misc/atc260x-onkey.c
>> > >  create mode 100644 drivers/mfd/atc260x-core.c
>> > >  create mode 100644 drivers/mfd/atc260x-i2c.c
>> > >  create mode 100644 drivers/power/reset/atc260x-poweroff.c
>> > >  create mode 100644 drivers/regulator/atc260x-regulator.c
>> > >  create mode 100644 include/linux/mfd/atc260x/atc2603c.h
>> > >  create mode 100644 include/linux/mfd/atc260x/atc2609a.h
>> > >  create mode 100644 include/linux/mfd/atc260x/core.h
>> > > 
>> > > -- 
>> > > 2.28.0
>> > > 

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 3/6] regulator: Add regulator driver for ATC260x PMICs
  2020-08-24 23:23     ` Cristian Ciocaltea
@ 2020-08-25 10:55       ` Mark Brown
  0 siblings, 0 replies; 23+ messages in thread
From: Mark Brown @ 2020-08-25 10:55 UTC (permalink / raw)
  To: Cristian Ciocaltea
  Cc: Lee Jones, Rob Herring, Dmitry Torokhov, Sebastian Reichel,
	Liam Girdwood, Manivannan Sadhasivam, Andreas Färber,
	linux-actions, devicetree, linux-kernel, linux-input, linux-pm

[-- Attachment #1: Type: text/plain, Size: 645 bytes --]

On Tue, Aug 25, 2020 at 02:23:10AM +0300, Cristian Ciocaltea wrote:
> On Mon, Aug 24, 2020 at 12:00:45PM +0100, Mark Brown wrote:

> > Please write normal conditional statements to make things easier to
> > read.  It also looks like this would be more robustly written by just
> > having separate ops for DCDCs and LDOs, this could easily break if
> > another device is supported in the driver.

> Sure, I can provide separate ops, but in this case we duplicate almost
> all of them. If this is not acceptable, then I will just rewrite the
> conditional statement.

That's fine, it's just a fairly small struct that's being duplicated not
code.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 1/6] dt-bindings: mfd: Add Actions Semi ATC260x PMIC binding
  2020-08-21 22:19 ` [PATCH v2 1/6] dt-bindings: mfd: Add Actions Semi ATC260x PMIC binding Cristian Ciocaltea
@ 2020-09-08 21:47   ` Rob Herring
  2020-09-09 16:03     ` Cristian Ciocaltea
  0 siblings, 1 reply; 23+ messages in thread
From: Rob Herring @ 2020-09-08 21:47 UTC (permalink / raw)
  To: Cristian Ciocaltea
  Cc: Lee Jones, Dmitry Torokhov, Sebastian Reichel, Liam Girdwood,
	Mark Brown, Manivannan Sadhasivam, Andreas Färber,
	linux-actions, devicetree, linux-kernel, linux-input, linux-pm

On Sat, Aug 22, 2020 at 01:19:47AM +0300, Cristian Ciocaltea wrote:
> Add devicetree binding for Actions Semi ATC260x PMICs.
> 
> Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
> ---
>  .../bindings/mfd/actions,atc260x.yaml         | 221 ++++++++++++++++++
>  1 file changed, 221 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/mfd/actions,atc260x.yaml
> 
> diff --git a/Documentation/devicetree/bindings/mfd/actions,atc260x.yaml b/Documentation/devicetree/bindings/mfd/actions,atc260x.yaml
> new file mode 100644
> index 000000000000..4a55bbe1306e
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/mfd/actions,atc260x.yaml
> @@ -0,0 +1,221 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/mfd/actions,atc260x.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Actions Semi ATC260x Power Management IC bindings
> +
> +maintainers:
> +  - Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> +  - Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
> +
> +description: |
> +  ATC260x series PMICs integrates Audio Codec, Power Management, RTC, IR
> +  and GPIO controller blocks. Currently only the PM related functionalities
> +  (i.e. regulators and system power-off/reboot) for the ATC2603C and ATC2609A
> +  chip variants are supported.
> +  ATC2603C includes 3 programmable DC-DC converters and 9 LDO regulators.
> +  ATC2609A includes 5 programmable DC-DC converters and 10 LDO regulators.
> +
> +properties:
> +  compatible:
> +    enum:
> +      - actions,atc2603c
> +      - actions,atc2609a
> +
> +  reg:
> +    maxItems: 1
> +
> +  interrupts:
> +    maxItems: 1
> +
> +  pwrc:
> +    type: object
> +    description: |
> +      The power controller integrated in ATC260x provides system power-off
> +      and reboot operations.

No need for this node as there are no properties, just instantiate 
what's needed in the MFD driver.

> +
> +    properties:
> +      compatible:
> +        enum:
> +          - actions,atc2603c-pwrc
> +          - actions,atc2609a-pwrc
> +
> +    required:
> +      - compatible
> +
> +    additionalProperties: false
> +
> +  onkey:
> +    type: object
> +    description: |
> +      Use the ONKEY built into ATC260x PMICs as an input device reporting
> +      power button status. ONKEY can be used to wakeup from low power
> +      modes and force a reset on long press.
> +
> +    properties:
> +      compatible:
> +        enum:
> +          - actions,atc2603c-onkey
> +          - actions,atc2609a-onkey
> +
> +      actions,reset-time-sec:
> +        description: |
> +          Duration in seconds which the key should be kept pressed for device
> +          to reset automatically. The hardware default is 8. Use 0 to disable
> +          this functionality.
> +        enum: [0, 6, 8, 10, 12]

We already have 'power-off-time-sec' in input.yaml. How about adding 
'reset-time-sec' there.

This could really just be a property in the parent node.

> +
> +    required:
> +      - compatible
> +
> +    additionalProperties: false
> +
> +  regulators:
> +    type: object
> +    description: |
> +      List of child nodes specifying the regulators, depending on chip variant:
> +      * ATC2603C: dcdc[1-3], ldo[1-3,5-8,11], switchldo1
> +      * ATC2609A: dcdc[0-4], ldo[0-9]
> +
> +    properties:
> +      compatible:
> +        enum:
> +          - actions,atc2603c-regulator
> +          - actions,atc2609a-regulator
> +
> +      switchldo1:
> +        type: object
> +        $ref: ../regulator/regulator.yaml
> +
> +        properties:
> +          regulator-name: true
> +          regulator-boot-on: true
> +          regulator-always-on: true
> +          regulator-min-microvolt: true
> +          regulator-max-microvolt: true
> +          regulator-allow-bypass: true
> +          regulator-active-discharge: true
> +
> +        additionalProperties: false
> +
> +    patternProperties:
> +      "^(dcdc[0-4]|ldo[0-9]|ldo11|switchldo1)-supply$":
> +        description: ATC260x voltage regulators supplies
> +
> +      "^(dcdc[0-4]|ldo[0-9]|ldo11)$":
> +        type: object
> +        $ref: ../regulator/regulator.yaml
> +
> +        properties:
> +          regulator-name: true
> +          regulator-boot-on: true
> +          regulator-always-on: true
> +          regulator-min-microvolt: true
> +          regulator-max-microvolt: true
> +          regulator-allow-bypass: true
> +
> +        additionalProperties: false
> +
> +    allOf:
> +      - if:
> +          properties:
> +            compatible:
> +              contains:
> +                const: actions,atc2603c-regulator
> +        then:
> +          patternProperties:
> +            "^(dcdc[0,4]|ldo[0,4,9])(-supply)?$": false
> +
> +            "^(ldo|dcdc)":
> +              properties:
> +                regulator-allow-bypass: false
> +      - if:
> +          properties:
> +            compatible:
> +              contains:
> +                const: actions,atc2609a-regulator
> +        then:
> +          patternProperties:
> +            "^(ldo11|switchldo1)(-supply)?$": false
> +
> +            "^(dcdc|ldo[3-9])":
> +              properties:
> +                regulator-allow-bypass: false
> +
> +    required:
> +      - compatible
> +
> +    additionalProperties: false
> +
> +additionalProperties: false
> +
> +required:
> +  - compatible
> +  - reg
> +  - interrupts
> +
> +examples:
> +  - |
> +    #include <dt-bindings/interrupt-controller/arm-gic.h>
> +
> +    i2c0 {
> +      #address-cells = <1>;
> +      #size-cells = <0>;
> +
> +      pmic@65 {
> +        compatible = "actions,atc2603c";
> +        reg = <0x65>;
> +        interrupt-parent = <&sirq>;
> +        interrupts = <2 IRQ_TYPE_LEVEL_HIGH>;
> +
> +        pwrc {
> +          compatible = "actions,atc2603c-pwrc";
> +        };
> +
> +        onkey {
> +          compatible = "actions,atc2603c-onkey";
> +          actions,reset-time-sec = <6>;
> +        };
> +
> +        regulators {
> +          compatible = "actions,atc2603c-regulator";
> +
> +          dcdc1-supply = <&reg_5v0>;
> +          dcdc3-supply = <&reg_5v0>;
> +          ldo5-supply = <&reg_5v0>;
> +          switchldo1-supply = <&vcc>;
> +
> +          vdd_cpu: dcdc1 {
> +            regulator-name = "VDD_CPU";
> +            regulator-min-microvolt = <700000>;
> +            regulator-max-microvolt = <1400000>;
> +            regulator-always-on;
> +          };
> +
> +          vcc: dcdc3 {
> +            regulator-name = "VCC";
> +            regulator-min-microvolt = <2600000>;
> +            regulator-max-microvolt = <3300000>;
> +            regulator-always-on;
> +          };
> +
> +          vcc_3v1: ldo5 {
> +            regulator-name = "VCC_3V1";
> +            regulator-min-microvolt = <2600000>;
> +            regulator-max-microvolt = <3300000>;
> +          };
> +
> +          sd_vcc: switchldo1 {
> +            regulator-name = "SD_VCC";
> +            regulator-min-microvolt = <3000000>;
> +            regulator-max-microvolt = <3300000>;
> +            regulator-always-on;
> +            regulator-boot-on;
> +          };
> +        };
> +      };
> +    };
> +
> +...
> -- 
> 2.28.0
> 

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 1/6] dt-bindings: mfd: Add Actions Semi ATC260x PMIC binding
  2020-09-08 21:47   ` Rob Herring
@ 2020-09-09 16:03     ` Cristian Ciocaltea
  2020-09-09 17:22       ` Rob Herring
  0 siblings, 1 reply; 23+ messages in thread
From: Cristian Ciocaltea @ 2020-09-09 16:03 UTC (permalink / raw)
  To: Rob Herring
  Cc: Lee Jones, Dmitry Torokhov, Sebastian Reichel, Liam Girdwood,
	Mark Brown, Manivannan Sadhasivam, Andreas Färber,
	linux-actions, devicetree, linux-kernel, linux-input, linux-pm

Hi Rob,

Thanks for reviewing!

On Tue, Sep 08, 2020 at 03:47:24PM -0600, Rob Herring wrote:
> On Sat, Aug 22, 2020 at 01:19:47AM +0300, Cristian Ciocaltea wrote:
> > Add devicetree binding for Actions Semi ATC260x PMICs.
> > 
> > Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
> > ---
> >  .../bindings/mfd/actions,atc260x.yaml         | 221 ++++++++++++++++++
> >  1 file changed, 221 insertions(+)
> >  create mode 100644 Documentation/devicetree/bindings/mfd/actions,atc260x.yaml
> > 
> > diff --git a/Documentation/devicetree/bindings/mfd/actions,atc260x.yaml b/Documentation/devicetree/bindings/mfd/actions,atc260x.yaml
> > new file mode 100644
> > index 000000000000..4a55bbe1306e
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/mfd/actions,atc260x.yaml
> > @@ -0,0 +1,221 @@
> > +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> > +%YAML 1.2
> > +---
> > +$id: http://devicetree.org/schemas/mfd/actions,atc260x.yaml#
> > +$schema: http://devicetree.org/meta-schemas/core.yaml#
> > +
> > +title: Actions Semi ATC260x Power Management IC bindings
> > +
> > +maintainers:
> > +  - Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> > +  - Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
> > +
> > +description: |
> > +  ATC260x series PMICs integrates Audio Codec, Power Management, RTC, IR
> > +  and GPIO controller blocks. Currently only the PM related functionalities
> > +  (i.e. regulators and system power-off/reboot) for the ATC2603C and ATC2609A
> > +  chip variants are supported.
> > +  ATC2603C includes 3 programmable DC-DC converters and 9 LDO regulators.
> > +  ATC2609A includes 5 programmable DC-DC converters and 10 LDO regulators.
> > +
> > +properties:
> > +  compatible:
> > +    enum:
> > +      - actions,atc2603c
> > +      - actions,atc2609a
> > +
> > +  reg:
> > +    maxItems: 1
> > +
> > +  interrupts:
> > +    maxItems: 1
> > +
> > +  pwrc:
> > +    type: object
> > +    description: |
> > +      The power controller integrated in ATC260x provides system power-off
> > +      and reboot operations.
> 
> No need for this node as there are no properties, just instantiate 
> what's needed in the MFD driver.

My intention was to allow the user specify what functionality in the MFD
shall be enabled. For this particular case, if the 'pwrc' node is not
provided, the power-off/reboot functions will be disabled.

> > +
> > +    properties:
> > +      compatible:
> > +        enum:
> > +          - actions,atc2603c-pwrc
> > +          - actions,atc2609a-pwrc
> > +
> > +    required:
> > +      - compatible
> > +
> > +    additionalProperties: false
> > +
> > +  onkey:
> > +    type: object
> > +    description: |
> > +      Use the ONKEY built into ATC260x PMICs as an input device reporting
> > +      power button status. ONKEY can be used to wakeup from low power
> > +      modes and force a reset on long press.
> > +
> > +    properties:
> > +      compatible:
> > +        enum:
> > +          - actions,atc2603c-onkey
> > +          - actions,atc2609a-onkey
> > +
> > +      actions,reset-time-sec:
> > +        description: |
> > +          Duration in seconds which the key should be kept pressed for device
> > +          to reset automatically. The hardware default is 8. Use 0 to disable
> > +          this functionality.
> > +        enum: [0, 6, 8, 10, 12]
> 
> We already have 'power-off-time-sec' in input.yaml. How about adding 
> 'reset-time-sec' there.

Thanks for the suggestion, I was actually looking for this before
choosing the custom property and just assumed this was not added for
a particular reason.

So I'm going to handle it. Would you like me to send a separate patch
(not part of this series)?

> This could really just be a property in the parent node.

This is similar with 'pwrc': if 'onkey' node is not present, the ONKEY
functionality will not be enabled.

Is there a better/recommended approach to manage this MFD feature
selection?

> > +
> > +    required:
> > +      - compatible
> > +
> > +    additionalProperties: false
> > +
> > +  regulators:
> > +    type: object
> > +    description: |
> > +      List of child nodes specifying the regulators, depending on chip variant:
> > +      * ATC2603C: dcdc[1-3], ldo[1-3,5-8,11], switchldo1
> > +      * ATC2609A: dcdc[0-4], ldo[0-9]
> > +
> > +    properties:
> > +      compatible:
> > +        enum:
> > +          - actions,atc2603c-regulator
> > +          - actions,atc2609a-regulator
> > +
> > +      switchldo1:
> > +        type: object
> > +        $ref: ../regulator/regulator.yaml
> > +
> > +        properties:
> > +          regulator-name: true
> > +          regulator-boot-on: true
> > +          regulator-always-on: true
> > +          regulator-min-microvolt: true
> > +          regulator-max-microvolt: true
> > +          regulator-allow-bypass: true
> > +          regulator-active-discharge: true
> > +
> > +        additionalProperties: false
> > +
> > +    patternProperties:
> > +      "^(dcdc[0-4]|ldo[0-9]|ldo11|switchldo1)-supply$":
> > +        description: ATC260x voltage regulators supplies
> > +
> > +      "^(dcdc[0-4]|ldo[0-9]|ldo11)$":
> > +        type: object
> > +        $ref: ../regulator/regulator.yaml
> > +
> > +        properties:
> > +          regulator-name: true
> > +          regulator-boot-on: true
> > +          regulator-always-on: true
> > +          regulator-min-microvolt: true
> > +          regulator-max-microvolt: true
> > +          regulator-allow-bypass: true
> > +
> > +        additionalProperties: false
> > +
> > +    allOf:
> > +      - if:
> > +          properties:
> > +            compatible:
> > +              contains:
> > +                const: actions,atc2603c-regulator
> > +        then:
> > +          patternProperties:
> > +            "^(dcdc[0,4]|ldo[0,4,9])(-supply)?$": false
> > +
> > +            "^(ldo|dcdc)":
> > +              properties:
> > +                regulator-allow-bypass: false
> > +      - if:
> > +          properties:
> > +            compatible:
> > +              contains:
> > +                const: actions,atc2609a-regulator
> > +        then:
> > +          patternProperties:
> > +            "^(ldo11|switchldo1)(-supply)?$": false
> > +
> > +            "^(dcdc|ldo[3-9])":
> > +              properties:
> > +                regulator-allow-bypass: false
> > +
> > +    required:
> > +      - compatible
> > +
> > +    additionalProperties: false
> > +
> > +additionalProperties: false
> > +
> > +required:
> > +  - compatible
> > +  - reg
> > +  - interrupts
> > +
> > +examples:
> > +  - |
> > +    #include <dt-bindings/interrupt-controller/arm-gic.h>
> > +
> > +    i2c0 {
> > +      #address-cells = <1>;
> > +      #size-cells = <0>;
> > +
> > +      pmic@65 {
> > +        compatible = "actions,atc2603c";
> > +        reg = <0x65>;
> > +        interrupt-parent = <&sirq>;
> > +        interrupts = <2 IRQ_TYPE_LEVEL_HIGH>;
> > +
> > +        pwrc {
> > +          compatible = "actions,atc2603c-pwrc";
> > +        };
> > +
> > +        onkey {
> > +          compatible = "actions,atc2603c-onkey";
> > +          actions,reset-time-sec = <6>;
> > +        };
> > +
> > +        regulators {
> > +          compatible = "actions,atc2603c-regulator";
> > +
> > +          dcdc1-supply = <&reg_5v0>;
> > +          dcdc3-supply = <&reg_5v0>;
> > +          ldo5-supply = <&reg_5v0>;
> > +          switchldo1-supply = <&vcc>;
> > +
> > +          vdd_cpu: dcdc1 {
> > +            regulator-name = "VDD_CPU";
> > +            regulator-min-microvolt = <700000>;
> > +            regulator-max-microvolt = <1400000>;
> > +            regulator-always-on;
> > +          };
> > +
> > +          vcc: dcdc3 {
> > +            regulator-name = "VCC";
> > +            regulator-min-microvolt = <2600000>;
> > +            regulator-max-microvolt = <3300000>;
> > +            regulator-always-on;
> > +          };
> > +
> > +          vcc_3v1: ldo5 {
> > +            regulator-name = "VCC_3V1";
> > +            regulator-min-microvolt = <2600000>;
> > +            regulator-max-microvolt = <3300000>;
> > +          };
> > +
> > +          sd_vcc: switchldo1 {
> > +            regulator-name = "SD_VCC";
> > +            regulator-min-microvolt = <3000000>;
> > +            regulator-max-microvolt = <3300000>;
> > +            regulator-always-on;
> > +            regulator-boot-on;
> > +          };
> > +        };
> > +      };
> > +    };
> > +
> > +...
> > -- 
> > 2.28.0
> > 

Kind regards,
Cristi

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 1/6] dt-bindings: mfd: Add Actions Semi ATC260x PMIC binding
  2020-09-09 16:03     ` Cristian Ciocaltea
@ 2020-09-09 17:22       ` Rob Herring
  0 siblings, 0 replies; 23+ messages in thread
From: Rob Herring @ 2020-09-09 17:22 UTC (permalink / raw)
  To: Cristian Ciocaltea
  Cc: Lee Jones, Dmitry Torokhov, Sebastian Reichel, Liam Girdwood,
	Mark Brown, Manivannan Sadhasivam, Andreas Färber,
	linux-actions, devicetree, linux-kernel, Linux Input,
	open list:THERMAL

On Wed, Sep 9, 2020 at 10:03 AM Cristian Ciocaltea
<cristian.ciocaltea@gmail.com> wrote:
>
> Hi Rob,
>
> Thanks for reviewing!
>
> On Tue, Sep 08, 2020 at 03:47:24PM -0600, Rob Herring wrote:
> > On Sat, Aug 22, 2020 at 01:19:47AM +0300, Cristian Ciocaltea wrote:
> > > Add devicetree binding for Actions Semi ATC260x PMICs.
> > >
> > > Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
> > > ---
> > >  .../bindings/mfd/actions,atc260x.yaml         | 221 ++++++++++++++++++
> > >  1 file changed, 221 insertions(+)
> > >  create mode 100644 Documentation/devicetree/bindings/mfd/actions,atc260x.yaml
> > >
> > > diff --git a/Documentation/devicetree/bindings/mfd/actions,atc260x.yaml b/Documentation/devicetree/bindings/mfd/actions,atc260x.yaml
> > > new file mode 100644
> > > index 000000000000..4a55bbe1306e
> > > --- /dev/null
> > > +++ b/Documentation/devicetree/bindings/mfd/actions,atc260x.yaml
> > > @@ -0,0 +1,221 @@
> > > +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> > > +%YAML 1.2
> > > +---
> > > +$id: http://devicetree.org/schemas/mfd/actions,atc260x.yaml#
> > > +$schema: http://devicetree.org/meta-schemas/core.yaml#
> > > +
> > > +title: Actions Semi ATC260x Power Management IC bindings
> > > +
> > > +maintainers:
> > > +  - Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> > > +  - Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
> > > +
> > > +description: |
> > > +  ATC260x series PMICs integrates Audio Codec, Power Management, RTC, IR
> > > +  and GPIO controller blocks. Currently only the PM related functionalities
> > > +  (i.e. regulators and system power-off/reboot) for the ATC2603C and ATC2609A
> > > +  chip variants are supported.
> > > +  ATC2603C includes 3 programmable DC-DC converters and 9 LDO regulators.
> > > +  ATC2609A includes 5 programmable DC-DC converters and 10 LDO regulators.
> > > +
> > > +properties:
> > > +  compatible:
> > > +    enum:
> > > +      - actions,atc2603c
> > > +      - actions,atc2609a
> > > +
> > > +  reg:
> > > +    maxItems: 1
> > > +
> > > +  interrupts:
> > > +    maxItems: 1
> > > +
> > > +  pwrc:
> > > +    type: object
> > > +    description: |
> > > +      The power controller integrated in ATC260x provides system power-off
> > > +      and reboot operations.
> >
> > No need for this node as there are no properties, just instantiate
> > what's needed in the MFD driver.
>
> My intention was to allow the user specify what functionality in the MFD
> shall be enabled. For this particular case, if the 'pwrc' node is not
> provided, the power-off/reboot functions will be disabled.

IIRC, there's a flag property for this already.

>
> > > +
> > > +    properties:
> > > +      compatible:
> > > +        enum:
> > > +          - actions,atc2603c-pwrc
> > > +          - actions,atc2609a-pwrc
> > > +
> > > +    required:
> > > +      - compatible
> > > +
> > > +    additionalProperties: false
> > > +
> > > +  onkey:
> > > +    type: object
> > > +    description: |
> > > +      Use the ONKEY built into ATC260x PMICs as an input device reporting
> > > +      power button status. ONKEY can be used to wakeup from low power
> > > +      modes and force a reset on long press.
> > > +
> > > +    properties:
> > > +      compatible:
> > > +        enum:
> > > +          - actions,atc2603c-onkey
> > > +          - actions,atc2609a-onkey
> > > +
> > > +      actions,reset-time-sec:
> > > +        description: |
> > > +          Duration in seconds which the key should be kept pressed for device
> > > +          to reset automatically. The hardware default is 8. Use 0 to disable
> > > +          this functionality.
> > > +        enum: [0, 6, 8, 10, 12]
> >
> > We already have 'power-off-time-sec' in input.yaml. How about adding
> > 'reset-time-sec' there.
>
> Thanks for the suggestion, I was actually looking for this before
> choosing the custom property and just assumed this was not added for
> a particular reason.

Probably just because the usual behavior of holding the power button
is to power off rather than reset.

> So I'm going to handle it. Would you like me to send a separate patch
> (not part of this series)?

Separate patch yes, but it can be part of the series.

> > This could really just be a property in the parent node.
>
> This is similar with 'pwrc': if 'onkey' node is not present, the ONKEY
> functionality will not be enabled.

Would you really want/need to support wakeup, but disable long press
feature? Seems like a single property would be sufficient.

> Is there a better/recommended approach to manage this MFD feature
> selection?

But we have child nodes for this in other cases, so I guess it is fine.

Rob

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 5/6] input: atc260x: Add onkey driver for ATC260x PMICs
  2020-08-21 22:19 ` [PATCH v2 5/6] input: atc260x: Add onkey " Cristian Ciocaltea
@ 2020-09-14 21:09   ` Dmitry Torokhov
  2020-09-18 10:35     ` Cristian Ciocaltea
  0 siblings, 1 reply; 23+ messages in thread
From: Dmitry Torokhov @ 2020-09-14 21:09 UTC (permalink / raw)
  To: Cristian Ciocaltea
  Cc: Lee Jones, Rob Herring, Sebastian Reichel, Liam Girdwood,
	Mark Brown, Manivannan Sadhasivam, Andreas Färber,
	linux-actions, devicetree, linux-kernel, linux-input, linux-pm

Hi Cristian,

On Sat, Aug 22, 2020 at 01:19:51AM +0300, Cristian Ciocaltea wrote:
> The Actions Semi ATC260x PMICs are able to manage an onkey button.
> This driver exposes the ATC260x onkey as an input device. It can also
> be configured to force a system reset on a long key-press with an
> adjustable duration.
> 
> The currently supported chip variants are ATC2603C and ATC2609A.
> 
> Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
> ---
>  drivers/input/misc/Kconfig         |  11 ++
>  drivers/input/misc/Makefile        |   2 +-
>  drivers/input/misc/atc260x-onkey.c | 304 +++++++++++++++++++++++++++++
>  3 files changed, 316 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/input/misc/atc260x-onkey.c
> 
> diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
> index 362e8a01980c..9e297ebdea57 100644
> --- a/drivers/input/misc/Kconfig
> +++ b/drivers/input/misc/Kconfig
> @@ -83,6 +83,17 @@ config INPUT_ARIZONA_HAPTICS
>  	  To compile this driver as a module, choose M here: the
>  	  module will be called arizona-haptics.
>  
> +config INPUT_ATC260X_ONKEY
> +	tristate "Actions Semi ATC260x PMIC ONKEY"
> +	depends on MFD_ATC260X
> +	help
> +	  Support the ONKEY of ATC260x PMICs as an input device reporting
> +	  power button status. ONKEY can be used to wakeup from low power
> +	  modes and force a reset on long press.
> +
> +	  To compile this driver as a module, choose M here: the
> +	  module will be called atc260x-onkey.
> +
>  config INPUT_ATMEL_CAPTOUCH
>  	tristate "Atmel Capacitive Touch Button Driver"
>  	depends on OF || COMPILE_TEST
> diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
> index a48e5f2d859d..7f854c6ecefa 100644
> --- a/drivers/input/misc/Makefile
> +++ b/drivers/input/misc/Makefile
> @@ -16,6 +16,7 @@ obj-$(CONFIG_INPUT_ADXL34X_I2C)		+= adxl34x-i2c.o
>  obj-$(CONFIG_INPUT_ADXL34X_SPI)		+= adxl34x-spi.o
>  obj-$(CONFIG_INPUT_APANEL)		+= apanel.o
>  obj-$(CONFIG_INPUT_ARIZONA_HAPTICS)	+= arizona-haptics.o
> +obj-$(CONFIG_INPUT_ATC260X_ONKEY)	+= atc260x-onkey.o
>  obj-$(CONFIG_INPUT_ATI_REMOTE2)		+= ati_remote2.o
>  obj-$(CONFIG_INPUT_ATLAS_BTNS)		+= atlas_btns.o
>  obj-$(CONFIG_INPUT_ATMEL_CAPTOUCH)	+= atmel_captouch.o
> @@ -84,4 +85,3 @@ obj-$(CONFIG_INPUT_WM831X_ON)		+= wm831x-on.o
>  obj-$(CONFIG_INPUT_XEN_KBDDEV_FRONTEND)	+= xen-kbdfront.o
>  obj-$(CONFIG_INPUT_YEALINK)		+= yealink.o
>  obj-$(CONFIG_INPUT_IDEAPAD_SLIDEBAR)	+= ideapad_slidebar.o
> -
> diff --git a/drivers/input/misc/atc260x-onkey.c b/drivers/input/misc/atc260x-onkey.c
> new file mode 100644
> index 000000000000..7caec7d6f9ac
> --- /dev/null
> +++ b/drivers/input/misc/atc260x-onkey.c
> @@ -0,0 +1,304 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Onkey driver for Actions Semi ATC260x PMICs.
> + *
> + * Copyright (c) 2020 Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
> + */
> +
> +#include <linux/bitfield.h>
> +#include <linux/input.h>
> +#include <linux/interrupt.h>
> +#include <linux/mfd/atc260x/core.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +#include <linux/regmap.h>
> +
> +/* <2s for short press, >2s for long press */
> +#define KEY_PRESS_TIME_SEC	2
> +
> +/* Driver internals */
> +enum atc260x_onkey_reset_status {
> +	KEY_RESET_HW_DEFAULT,
> +	KEY_RESET_DISABLED,
> +	KEY_RESET_USER_SEL,
> +};
> +
> +struct atc260x_onkey_params {
> +	u32 reg_int_ctl;
> +	u32 kdwn_state_bm;
> +	u32 long_int_pnd_bm;
> +	u32 short_int_pnd_bm;
> +	u32 kdwn_int_pnd_bm;
> +	u32 press_int_en_bm;
> +	u32 kdwn_int_en_bm;
> +	u32 press_time_bm;
> +	u32 reset_en_bm;
> +	u32 reset_time_bm;
> +};
> +
> +struct atc260x_onkey {
> +	struct atc260x *atc260x;
> +	const struct atc260x_onkey_params *params;
> +	struct input_dev *input_dev;
> +	struct delayed_work work;
> +};
> +
> +static const struct atc260x_onkey_params atc2603c_onkey_params = {
> +	.reg_int_ctl		= ATC2603C_PMU_SYS_CTL2,
> +	.long_int_pnd_bm	= ATC2603C_PMU_SYS_CTL2_ONOFF_LONG_PRESS,
> +	.short_int_pnd_bm	= ATC2603C_PMU_SYS_CTL2_ONOFF_SHORT_PRESS,
> +	.kdwn_int_pnd_bm	= ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS_PD,
> +	.press_int_en_bm	= ATC2603C_PMU_SYS_CTL2_ONOFF_INT_EN,
> +	.kdwn_int_en_bm		= ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS_INT_EN,
> +	.kdwn_state_bm		= ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS,
> +	.press_time_bm		= ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS_TIME,
> +	.reset_en_bm		= ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS_RESET_EN,
> +	.reset_time_bm		= ATC2603C_PMU_SYS_CTL2_ONOFF_RESET_TIME_SEL,
> +};
> +
> +static const struct atc260x_onkey_params atc2609a_onkey_params = {
> +	.reg_int_ctl		= ATC2609A_PMU_SYS_CTL2,
> +	.long_int_pnd_bm	= ATC2609A_PMU_SYS_CTL2_ONOFF_LONG_PRESS,
> +	.short_int_pnd_bm	= ATC2609A_PMU_SYS_CTL2_ONOFF_SHORT_PRESS,
> +	.kdwn_int_pnd_bm	= ATC2609A_PMU_SYS_CTL2_ONOFF_PRESS_PD,
> +	.press_int_en_bm	= ATC2609A_PMU_SYS_CTL2_ONOFF_LSP_INT_EN,
> +	.kdwn_int_en_bm		= ATC2609A_PMU_SYS_CTL2_ONOFF_PRESS_INT_EN,
> +	.kdwn_state_bm		= ATC2609A_PMU_SYS_CTL2_ONOFF_PRESS,
> +	.press_time_bm		= ATC2609A_PMU_SYS_CTL2_ONOFF_PRESS_TIME,
> +	.reset_en_bm		= ATC2609A_PMU_SYS_CTL2_ONOFF_RESET_EN,
> +	.reset_time_bm		= ATC2609A_PMU_SYS_CTL2_ONOFF_RESET_TIME_SEL,
> +};
> +
> +static int atc2603x_onkey_hw_init(struct atc260x_onkey *onkey,
> +				  enum atc260x_onkey_reset_status reset_status,
> +				  u32 reset_time, u32 press_time)
> +{
> +	u32 reg_bm, reg_val;
> +
> +	reg_bm = onkey->params->long_int_pnd_bm |
> +		 onkey->params->short_int_pnd_bm |
> +		 onkey->params->kdwn_int_pnd_bm |
> +		 onkey->params->press_int_en_bm |
> +		 onkey->params->kdwn_int_en_bm;
> +
> +	reg_val = reg_bm | press_time;
> +	reg_bm |= onkey->params->press_time_bm;
> +
> +	if (reset_status == KEY_RESET_DISABLED) {
> +		reg_bm |= onkey->params->reset_en_bm;
> +	} else if (reset_status == KEY_RESET_USER_SEL) {
> +		reg_bm |= onkey->params->reset_en_bm |
> +			  onkey->params->reset_time_bm;
> +		reg_val |= onkey->params->reset_en_bm | reset_time;
> +	}
> +
> +	return regmap_update_bits(onkey->atc260x->regmap,
> +				  onkey->params->reg_int_ctl, reg_bm, reg_val);
> +}
> +
> +static void atc260x_onkey_query(struct atc260x_onkey *onkey)
> +{
> +	u32 reg_bits;
> +	int ret, key_down;
> +
> +	ret = regmap_read(onkey->atc260x->regmap,
> +			  onkey->params->reg_int_ctl, &key_down);
> +	if (ret) {
> +		key_down = 1;
> +		dev_err(onkey->atc260x->dev,
> +			"Failed to read onkey status: %d\n", ret);
> +	} else {
> +		key_down &= onkey->params->kdwn_state_bm;
> +	}
> +
> +	/*
> +	 * The hardware generates interrupt only when the onkey pin is
> +	 * asserted. Hence, the deassertion of the pin is simulated through
> +	 * work queue.
> +	 */
> +	if (key_down) {
> +		schedule_delayed_work(&onkey->work, msecs_to_jiffies(200));
> +		return;
> +	}
> +
> +	/*
> +	 * The key-down status bit is cleared when the On/Off button
> +	 * is released.
> +	 */
> +	input_report_key(onkey->input_dev, KEY_POWER, 0);
> +	input_sync(onkey->input_dev);
> +
> +	reg_bits = onkey->params->long_int_pnd_bm |
> +		   onkey->params->short_int_pnd_bm |
> +		   onkey->params->kdwn_int_pnd_bm |
> +		   onkey->params->press_int_en_bm |
> +		   onkey->params->kdwn_int_en_bm;
> +
> +	/* Clear key press pending events and enable key press interrupts. */
> +	regmap_update_bits(onkey->atc260x->regmap, onkey->params->reg_int_ctl,
> +			   reg_bits, reg_bits);
> +}
> +
> +static void atc260x_onkey_work(struct work_struct *work)
> +{
> +	struct atc260x_onkey *onkey = container_of(work, struct atc260x_onkey,
> +						   work.work);
> +	atc260x_onkey_query(onkey);
> +}
> +
> +static irqreturn_t atc260x_onkey_irq(int irq, void *data)
> +{
> +	struct atc260x_onkey *onkey = data;
> +	int ret;
> +
> +	/* Disable key press interrupts. */
> +	ret = regmap_update_bits(onkey->atc260x->regmap,
> +				 onkey->params->reg_int_ctl,
> +				 onkey->params->press_int_en_bm |
> +				 onkey->params->kdwn_int_en_bm, 0);
> +	if (ret)
> +		dev_err(onkey->atc260x->dev,
> +			"Failed to disable interrupts: %d\n", ret);
> +
> +	input_report_key(onkey->input_dev, KEY_POWER, 1);
> +	input_sync(onkey->input_dev);
> +
> +	atc260x_onkey_query(onkey);
> +
> +	return IRQ_HANDLED;
> +}
> +
> +static int atc260x_onkey_probe(struct platform_device *pdev)
> +{
> +	struct atc260x *atc260x = dev_get_drvdata(pdev->dev.parent);
> +	struct atc260x_onkey *onkey;
> +	struct input_dev *input_dev;
> +	enum atc260x_onkey_reset_status reset_status;
> +	u32 press_time = KEY_PRESS_TIME_SEC, reset_time = 0;
> +	int val, irq, ret;
> +
> +	if (!pdev->dev.of_node)
> +		return -ENXIO;

Why is this needed?

> +
> +	onkey = devm_kzalloc(&pdev->dev, sizeof(*onkey), GFP_KERNEL);
> +	if (!onkey)
> +		return -ENOMEM;
> +
> +	ret = device_property_read_u32(&pdev->dev,
> +				       "actions,reset-time-sec", &val);

Call this "error" please.

> +	if (ret) {
> +		reset_status = KEY_RESET_HW_DEFAULT;
> +	} else if (val) {
> +		if (val < 6 || val > 12) {
> +			dev_err(&pdev->dev, "actions,reset-time-sec out of range\n");
> +			return -EINVAL;
> +		}
> +
> +		reset_status = KEY_RESET_USER_SEL;
> +		reset_time = (val - 6) / 2;
> +	} else {
> +		reset_status = KEY_RESET_DISABLED;
> +		dev_info(&pdev->dev, "Disabled reset on long-press\n");
> +	}
> +
> +	switch (atc260x->ic_type) {
> +	case ATC2603C:
> +		onkey->params = &atc2603c_onkey_params;
> +		press_time = FIELD_PREP(ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS_TIME,
> +					press_time);
> +		reset_time = FIELD_PREP(ATC2603C_PMU_SYS_CTL2_ONOFF_RESET_TIME_SEL,
> +					reset_time);
> +		break;
> +	case ATC2609A:
> +		onkey->params = &atc2609a_onkey_params;
> +		press_time = FIELD_PREP(ATC2609A_PMU_SYS_CTL2_ONOFF_PRESS_TIME,
> +					press_time);
> +		reset_time = FIELD_PREP(ATC2609A_PMU_SYS_CTL2_ONOFF_RESET_TIME_SEL,
> +					reset_time);
> +		break;
> +	default:
> +		dev_err(&pdev->dev,
> +			"OnKey not supported for ATC260x PMIC type: %u\n",
> +			atc260x->ic_type);
> +		return -EINVAL;
> +	}
> +
> +	input_dev = devm_input_allocate_device(&pdev->dev);
> +	if (!input_dev) {
> +		dev_err(&pdev->dev, "Failed to allocate input device\n");
> +		return -ENOMEM;
> +	}
> +
> +	onkey->input_dev = input_dev;
> +	onkey->atc260x = atc260x;
> +
> +	input_dev->name = "atc260x-onkey";
> +	input_dev->phys = "atc260x-onkey/input0";
> +	input_dev->evbit[0] = BIT_MASK(EV_KEY);

Not needed.

> +	input_set_capability(input_dev, EV_KEY, KEY_POWER);
> +
> +	INIT_DELAYED_WORK(&onkey->work, atc260x_onkey_work);
> +
> +	irq = platform_get_irq(pdev, 0);
> +	if (irq < 0)
> +		return irq;
> +
> +	ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
> +					atc260x_onkey_irq,
> +					IRQF_TRIGGER_HIGH | IRQF_ONESHOT,

Do we need to force the trigger type? Can we rely on the parent to
configure it as needed?

> +					dev_name(&pdev->dev), onkey);
> +	if (ret) {
> +		dev_err(&pdev->dev,
> +			"Failed to register IRQ %d: %d\n", irq, ret);
> +		return ret;
> +	}
> +
> +	ret = input_register_device(input_dev);
> +	if (ret) {
> +		dev_err(&pdev->dev,
> +			"Failed to register input device: %d\n", ret);
> +		return ret;
> +	}
> +
> +	ret = atc2603x_onkey_hw_init(onkey, reset_status,
> +				     reset_time, press_time);
> +	if (ret)
> +		return ret;
> +
> +	platform_set_drvdata(pdev, onkey);
> +	device_init_wakeup(&pdev->dev, true);
> +
> +	return 0;
> +}
> +
> +static int atc260x_onkey_remove(struct platform_device *pdev)
> +{
> +	struct atc260x_onkey *onkey = platform_get_drvdata(pdev);
> +
> +	cancel_delayed_work_sync(&onkey->work);

This is racy. Past this point the interrupts are not disabled, so if key
happens to be pressed you will re-schedule the work and it will go BOOM.

You are using threaded interrupt. Maybe consider sleeping and
re-checking the key status right there.

> +
> +	return 0;
> +}
> +
> +static const struct of_device_id atc260x_onkey_of_match[] = {
> +	{ .compatible = "actions,atc2603c-onkey" },
> +	{ .compatible = "actions,atc2609a-onkey" },
> +	{ /* sentinel */ }
> +};
> +MODULE_DEVICE_TABLE(of, atc260x_onkey_of_match);
> +
> +static struct platform_driver atc260x_onkey_driver = {
> +	.probe	= atc260x_onkey_probe,
> +	.remove	= atc260x_onkey_remove,
> +	.driver	= {
> +		.name = "atc260x-onkey",
> +		.of_match_table = of_match_ptr(atc260x_onkey_of_match),
> +	},
> +};
> +
> +module_platform_driver(atc260x_onkey_driver);
> +
> +MODULE_DESCRIPTION("Onkey driver for ATC260x PMICs");
> +MODULE_AUTHOR("Cristian Ciocaltea <cristian.ciocaltea@gmail.com>");
> +MODULE_LICENSE("GPL");
> -- 
> 2.28.0
> 

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 5/6] input: atc260x: Add onkey driver for ATC260x PMICs
  2020-09-14 21:09   ` Dmitry Torokhov
@ 2020-09-18 10:35     ` Cristian Ciocaltea
  2020-09-29 20:35       ` Dmitry Torokhov
  0 siblings, 1 reply; 23+ messages in thread
From: Cristian Ciocaltea @ 2020-09-18 10:35 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Lee Jones, Rob Herring, Sebastian Reichel, Liam Girdwood,
	Mark Brown, Manivannan Sadhasivam, Andreas Färber,
	linux-actions, devicetree, linux-kernel, linux-input, linux-pm

Hi Dmitry,

Thanks for the review!

On Mon, Sep 14, 2020 at 02:09:41PM -0700, Dmitry Torokhov wrote:
> Hi Cristian,
> 
> On Sat, Aug 22, 2020 at 01:19:51AM +0300, Cristian Ciocaltea wrote:
> > The Actions Semi ATC260x PMICs are able to manage an onkey button.
> > This driver exposes the ATC260x onkey as an input device. It can also
> > be configured to force a system reset on a long key-press with an
> > adjustable duration.
> > 
> > The currently supported chip variants are ATC2603C and ATC2609A.
> > 
> > Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
> > ---
> >  drivers/input/misc/Kconfig         |  11 ++
> >  drivers/input/misc/Makefile        |   2 +-
> >  drivers/input/misc/atc260x-onkey.c | 304 +++++++++++++++++++++++++++++
> >  3 files changed, 316 insertions(+), 1 deletion(-)
> >  create mode 100644 drivers/input/misc/atc260x-onkey.c
> > 
> > diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
> > index 362e8a01980c..9e297ebdea57 100644
> > --- a/drivers/input/misc/Kconfig
> > +++ b/drivers/input/misc/Kconfig
> > @@ -83,6 +83,17 @@ config INPUT_ARIZONA_HAPTICS
> >  	  To compile this driver as a module, choose M here: the
> >  	  module will be called arizona-haptics.
> >  
> > +config INPUT_ATC260X_ONKEY
> > +	tristate "Actions Semi ATC260x PMIC ONKEY"
> > +	depends on MFD_ATC260X
> > +	help
> > +	  Support the ONKEY of ATC260x PMICs as an input device reporting
> > +	  power button status. ONKEY can be used to wakeup from low power
> > +	  modes and force a reset on long press.
> > +
> > +	  To compile this driver as a module, choose M here: the
> > +	  module will be called atc260x-onkey.
> > +
> >  config INPUT_ATMEL_CAPTOUCH
> >  	tristate "Atmel Capacitive Touch Button Driver"
> >  	depends on OF || COMPILE_TEST
> > diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
> > index a48e5f2d859d..7f854c6ecefa 100644
> > --- a/drivers/input/misc/Makefile
> > +++ b/drivers/input/misc/Makefile
> > @@ -16,6 +16,7 @@ obj-$(CONFIG_INPUT_ADXL34X_I2C)		+= adxl34x-i2c.o
> >  obj-$(CONFIG_INPUT_ADXL34X_SPI)		+= adxl34x-spi.o
> >  obj-$(CONFIG_INPUT_APANEL)		+= apanel.o
> >  obj-$(CONFIG_INPUT_ARIZONA_HAPTICS)	+= arizona-haptics.o
> > +obj-$(CONFIG_INPUT_ATC260X_ONKEY)	+= atc260x-onkey.o
> >  obj-$(CONFIG_INPUT_ATI_REMOTE2)		+= ati_remote2.o
> >  obj-$(CONFIG_INPUT_ATLAS_BTNS)		+= atlas_btns.o
> >  obj-$(CONFIG_INPUT_ATMEL_CAPTOUCH)	+= atmel_captouch.o
> > @@ -84,4 +85,3 @@ obj-$(CONFIG_INPUT_WM831X_ON)		+= wm831x-on.o
> >  obj-$(CONFIG_INPUT_XEN_KBDDEV_FRONTEND)	+= xen-kbdfront.o
> >  obj-$(CONFIG_INPUT_YEALINK)		+= yealink.o
> >  obj-$(CONFIG_INPUT_IDEAPAD_SLIDEBAR)	+= ideapad_slidebar.o
> > -
> > diff --git a/drivers/input/misc/atc260x-onkey.c b/drivers/input/misc/atc260x-onkey.c
> > new file mode 100644
> > index 000000000000..7caec7d6f9ac
> > --- /dev/null
> > +++ b/drivers/input/misc/atc260x-onkey.c
> > @@ -0,0 +1,304 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * Onkey driver for Actions Semi ATC260x PMICs.
> > + *
> > + * Copyright (c) 2020 Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
> > + */
> > +
> > +#include <linux/bitfield.h>
> > +#include <linux/input.h>
> > +#include <linux/interrupt.h>
> > +#include <linux/mfd/atc260x/core.h>
> > +#include <linux/module.h>
> > +#include <linux/of.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/regmap.h>
> > +
> > +/* <2s for short press, >2s for long press */
> > +#define KEY_PRESS_TIME_SEC	2
> > +
> > +/* Driver internals */
> > +enum atc260x_onkey_reset_status {
> > +	KEY_RESET_HW_DEFAULT,
> > +	KEY_RESET_DISABLED,
> > +	KEY_RESET_USER_SEL,
> > +};
> > +
> > +struct atc260x_onkey_params {
> > +	u32 reg_int_ctl;
> > +	u32 kdwn_state_bm;
> > +	u32 long_int_pnd_bm;
> > +	u32 short_int_pnd_bm;
> > +	u32 kdwn_int_pnd_bm;
> > +	u32 press_int_en_bm;
> > +	u32 kdwn_int_en_bm;
> > +	u32 press_time_bm;
> > +	u32 reset_en_bm;
> > +	u32 reset_time_bm;
> > +};
> > +
> > +struct atc260x_onkey {
> > +	struct atc260x *atc260x;
> > +	const struct atc260x_onkey_params *params;
> > +	struct input_dev *input_dev;
> > +	struct delayed_work work;
> > +};
> > +
> > +static const struct atc260x_onkey_params atc2603c_onkey_params = {
> > +	.reg_int_ctl		= ATC2603C_PMU_SYS_CTL2,
> > +	.long_int_pnd_bm	= ATC2603C_PMU_SYS_CTL2_ONOFF_LONG_PRESS,
> > +	.short_int_pnd_bm	= ATC2603C_PMU_SYS_CTL2_ONOFF_SHORT_PRESS,
> > +	.kdwn_int_pnd_bm	= ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS_PD,
> > +	.press_int_en_bm	= ATC2603C_PMU_SYS_CTL2_ONOFF_INT_EN,
> > +	.kdwn_int_en_bm		= ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS_INT_EN,
> > +	.kdwn_state_bm		= ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS,
> > +	.press_time_bm		= ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS_TIME,
> > +	.reset_en_bm		= ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS_RESET_EN,
> > +	.reset_time_bm		= ATC2603C_PMU_SYS_CTL2_ONOFF_RESET_TIME_SEL,
> > +};
> > +
> > +static const struct atc260x_onkey_params atc2609a_onkey_params = {
> > +	.reg_int_ctl		= ATC2609A_PMU_SYS_CTL2,
> > +	.long_int_pnd_bm	= ATC2609A_PMU_SYS_CTL2_ONOFF_LONG_PRESS,
> > +	.short_int_pnd_bm	= ATC2609A_PMU_SYS_CTL2_ONOFF_SHORT_PRESS,
> > +	.kdwn_int_pnd_bm	= ATC2609A_PMU_SYS_CTL2_ONOFF_PRESS_PD,
> > +	.press_int_en_bm	= ATC2609A_PMU_SYS_CTL2_ONOFF_LSP_INT_EN,
> > +	.kdwn_int_en_bm		= ATC2609A_PMU_SYS_CTL2_ONOFF_PRESS_INT_EN,
> > +	.kdwn_state_bm		= ATC2609A_PMU_SYS_CTL2_ONOFF_PRESS,
> > +	.press_time_bm		= ATC2609A_PMU_SYS_CTL2_ONOFF_PRESS_TIME,
> > +	.reset_en_bm		= ATC2609A_PMU_SYS_CTL2_ONOFF_RESET_EN,
> > +	.reset_time_bm		= ATC2609A_PMU_SYS_CTL2_ONOFF_RESET_TIME_SEL,
> > +};
> > +
> > +static int atc2603x_onkey_hw_init(struct atc260x_onkey *onkey,
> > +				  enum atc260x_onkey_reset_status reset_status,
> > +				  u32 reset_time, u32 press_time)
> > +{
> > +	u32 reg_bm, reg_val;
> > +
> > +	reg_bm = onkey->params->long_int_pnd_bm |
> > +		 onkey->params->short_int_pnd_bm |
> > +		 onkey->params->kdwn_int_pnd_bm |
> > +		 onkey->params->press_int_en_bm |
> > +		 onkey->params->kdwn_int_en_bm;
> > +
> > +	reg_val = reg_bm | press_time;
> > +	reg_bm |= onkey->params->press_time_bm;
> > +
> > +	if (reset_status == KEY_RESET_DISABLED) {
> > +		reg_bm |= onkey->params->reset_en_bm;
> > +	} else if (reset_status == KEY_RESET_USER_SEL) {
> > +		reg_bm |= onkey->params->reset_en_bm |
> > +			  onkey->params->reset_time_bm;
> > +		reg_val |= onkey->params->reset_en_bm | reset_time;
> > +	}
> > +
> > +	return regmap_update_bits(onkey->atc260x->regmap,
> > +				  onkey->params->reg_int_ctl, reg_bm, reg_val);
> > +}
> > +
> > +static void atc260x_onkey_query(struct atc260x_onkey *onkey)
> > +{
> > +	u32 reg_bits;
> > +	int ret, key_down;
> > +
> > +	ret = regmap_read(onkey->atc260x->regmap,
> > +			  onkey->params->reg_int_ctl, &key_down);
> > +	if (ret) {
> > +		key_down = 1;
> > +		dev_err(onkey->atc260x->dev,
> > +			"Failed to read onkey status: %d\n", ret);
> > +	} else {
> > +		key_down &= onkey->params->kdwn_state_bm;
> > +	}
> > +
> > +	/*
> > +	 * The hardware generates interrupt only when the onkey pin is
> > +	 * asserted. Hence, the deassertion of the pin is simulated through
> > +	 * work queue.
> > +	 */
> > +	if (key_down) {
> > +		schedule_delayed_work(&onkey->work, msecs_to_jiffies(200));
> > +		return;
> > +	}
> > +
> > +	/*
> > +	 * The key-down status bit is cleared when the On/Off button
> > +	 * is released.
> > +	 */
> > +	input_report_key(onkey->input_dev, KEY_POWER, 0);
> > +	input_sync(onkey->input_dev);
> > +
> > +	reg_bits = onkey->params->long_int_pnd_bm |
> > +		   onkey->params->short_int_pnd_bm |
> > +		   onkey->params->kdwn_int_pnd_bm |
> > +		   onkey->params->press_int_en_bm |
> > +		   onkey->params->kdwn_int_en_bm;
> > +
> > +	/* Clear key press pending events and enable key press interrupts. */
> > +	regmap_update_bits(onkey->atc260x->regmap, onkey->params->reg_int_ctl,
> > +			   reg_bits, reg_bits);
> > +}
> > +
> > +static void atc260x_onkey_work(struct work_struct *work)
> > +{
> > +	struct atc260x_onkey *onkey = container_of(work, struct atc260x_onkey,
> > +						   work.work);
> > +	atc260x_onkey_query(onkey);
> > +}
> > +
> > +static irqreturn_t atc260x_onkey_irq(int irq, void *data)
> > +{
> > +	struct atc260x_onkey *onkey = data;
> > +	int ret;
> > +
> > +	/* Disable key press interrupts. */
> > +	ret = regmap_update_bits(onkey->atc260x->regmap,
> > +				 onkey->params->reg_int_ctl,
> > +				 onkey->params->press_int_en_bm |
> > +				 onkey->params->kdwn_int_en_bm, 0);
> > +	if (ret)
> > +		dev_err(onkey->atc260x->dev,
> > +			"Failed to disable interrupts: %d\n", ret);
> > +
> > +	input_report_key(onkey->input_dev, KEY_POWER, 1);
> > +	input_sync(onkey->input_dev);
> > +
> > +	atc260x_onkey_query(onkey);
> > +
> > +	return IRQ_HANDLED;
> > +}
> > +
> > +static int atc260x_onkey_probe(struct platform_device *pdev)
> > +{
> > +	struct atc260x *atc260x = dev_get_drvdata(pdev->dev.parent);
> > +	struct atc260x_onkey *onkey;
> > +	struct input_dev *input_dev;
> > +	enum atc260x_onkey_reset_status reset_status;
> > +	u32 press_time = KEY_PRESS_TIME_SEC, reset_time = 0;
> > +	int val, irq, ret;
> > +
> > +	if (!pdev->dev.of_node)
> > +		return -ENXIO;
> 
> Why is this needed?

The idea was to allow the user enable/disable the ONKEY functionality
of the MFD device via the 'onkey' DTS node. So if this node is not
present, the driver will not be loaded.

Is there a better/recommended way to handle this scenario?

> > +
> > +	onkey = devm_kzalloc(&pdev->dev, sizeof(*onkey), GFP_KERNEL);
> > +	if (!onkey)
> > +		return -ENOMEM;
> > +
> > +	ret = device_property_read_u32(&pdev->dev,
> > +				       "actions,reset-time-sec", &val);
> 
> Call this "error" please.

Would something like bellow suffice?

	if (ret) {
		dev_err(&pdev->dev, "Failed to read actions,reset-time-sec\n");
		return ret;
	}

> > +	if (ret) {
> > +		reset_status = KEY_RESET_HW_DEFAULT;
> > +	} else if (val) {
> > +		if (val < 6 || val > 12) {
> > +			dev_err(&pdev->dev, "actions,reset-time-sec out of range\n");
> > +			return -EINVAL;
> > +		}
> > +
> > +		reset_status = KEY_RESET_USER_SEL;
> > +		reset_time = (val - 6) / 2;
> > +	} else {
> > +		reset_status = KEY_RESET_DISABLED;
> > +		dev_info(&pdev->dev, "Disabled reset on long-press\n");
> > +	}
> > +
> > +	switch (atc260x->ic_type) {
> > +	case ATC2603C:
> > +		onkey->params = &atc2603c_onkey_params;
> > +		press_time = FIELD_PREP(ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS_TIME,
> > +					press_time);
> > +		reset_time = FIELD_PREP(ATC2603C_PMU_SYS_CTL2_ONOFF_RESET_TIME_SEL,
> > +					reset_time);
> > +		break;
> > +	case ATC2609A:
> > +		onkey->params = &atc2609a_onkey_params;
> > +		press_time = FIELD_PREP(ATC2609A_PMU_SYS_CTL2_ONOFF_PRESS_TIME,
> > +					press_time);
> > +		reset_time = FIELD_PREP(ATC2609A_PMU_SYS_CTL2_ONOFF_RESET_TIME_SEL,
> > +					reset_time);
> > +		break;
> > +	default:
> > +		dev_err(&pdev->dev,
> > +			"OnKey not supported for ATC260x PMIC type: %u\n",
> > +			atc260x->ic_type);
> > +		return -EINVAL;
> > +	}
> > +
> > +	input_dev = devm_input_allocate_device(&pdev->dev);
> > +	if (!input_dev) {
> > +		dev_err(&pdev->dev, "Failed to allocate input device\n");
> > +		return -ENOMEM;
> > +	}
> > +
> > +	onkey->input_dev = input_dev;
> > +	onkey->atc260x = atc260x;
> > +
> > +	input_dev->name = "atc260x-onkey";
> > +	input_dev->phys = "atc260x-onkey/input0";
> > +	input_dev->evbit[0] = BIT_MASK(EV_KEY);
> 
> Not needed.

Done.

> > +	input_set_capability(input_dev, EV_KEY, KEY_POWER);
> > +
> > +	INIT_DELAYED_WORK(&onkey->work, atc260x_onkey_work);
> > +
> > +	irq = platform_get_irq(pdev, 0);
> > +	if (irq < 0)
> > +		return irq;
> > +
> > +	ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
> > +					atc260x_onkey_irq,
> > +					IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
> 
> Do we need to force the trigger type? Can we rely on the parent to
> configure it as needed?

Done, I removed the trigger type enforcement.

> > +					dev_name(&pdev->dev), onkey);
> > +	if (ret) {
> > +		dev_err(&pdev->dev,
> > +			"Failed to register IRQ %d: %d\n", irq, ret);
> > +		return ret;
> > +	}
> > +
> > +	ret = input_register_device(input_dev);
> > +	if (ret) {
> > +		dev_err(&pdev->dev,
> > +			"Failed to register input device: %d\n", ret);
> > +		return ret;
> > +	}
> > +
> > +	ret = atc2603x_onkey_hw_init(onkey, reset_status,
> > +				     reset_time, press_time);
> > +	if (ret)
> > +		return ret;
> > +
> > +	platform_set_drvdata(pdev, onkey);
> > +	device_init_wakeup(&pdev->dev, true);
> > +
> > +	return 0;
> > +}
> > +
> > +static int atc260x_onkey_remove(struct platform_device *pdev)
> > +{
> > +	struct atc260x_onkey *onkey = platform_get_drvdata(pdev);
> > +
> > +	cancel_delayed_work_sync(&onkey->work);
> 
> This is racy. Past this point the interrupts are not disabled, so if key
> happens to be pressed you will re-schedule the work and it will go BOOM.
> 
> You are using threaded interrupt. Maybe consider sleeping and
> re-checking the key status right there.

I've seen this approach in a few drivers: da9055_onkey.c,
palmas-pwrbutton.c, wm831x-on.c

I noticed they also call 'free_irq()' right before
'cancel_delayed_work_sync()'. Would this help mitigate the racing issue?

> > +
> > +	return 0;
> > +}
> > +
> > +static const struct of_device_id atc260x_onkey_of_match[] = {
> > +	{ .compatible = "actions,atc2603c-onkey" },
> > +	{ .compatible = "actions,atc2609a-onkey" },
> > +	{ /* sentinel */ }
> > +};
> > +MODULE_DEVICE_TABLE(of, atc260x_onkey_of_match);
> > +
> > +static struct platform_driver atc260x_onkey_driver = {
> > +	.probe	= atc260x_onkey_probe,
> > +	.remove	= atc260x_onkey_remove,
> > +	.driver	= {
> > +		.name = "atc260x-onkey",
> > +		.of_match_table = of_match_ptr(atc260x_onkey_of_match),
> > +	},
> > +};
> > +
> > +module_platform_driver(atc260x_onkey_driver);
> > +
> > +MODULE_DESCRIPTION("Onkey driver for ATC260x PMICs");
> > +MODULE_AUTHOR("Cristian Ciocaltea <cristian.ciocaltea@gmail.com>");
> > +MODULE_LICENSE("GPL");
> > -- 
> > 2.28.0
> > 
> 
> Thanks.
> 
> -- 
> Dmitry

Kind regards,
Cristi

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 5/6] input: atc260x: Add onkey driver for ATC260x PMICs
  2020-09-18 10:35     ` Cristian Ciocaltea
@ 2020-09-29 20:35       ` Dmitry Torokhov
  2020-09-29 21:46         ` Cristian Ciocaltea
  0 siblings, 1 reply; 23+ messages in thread
From: Dmitry Torokhov @ 2020-09-29 20:35 UTC (permalink / raw)
  To: Cristian Ciocaltea
  Cc: Lee Jones, Rob Herring, Sebastian Reichel, Liam Girdwood,
	Mark Brown, Manivannan Sadhasivam, Andreas Färber,
	linux-actions, devicetree, linux-kernel, linux-input, linux-pm

Hi Cristian,

On Fri, Sep 18, 2020 at 01:35:03PM +0300, Cristian Ciocaltea wrote:
> Hi Dmitry,
> 
> Thanks for the review!
> 
> On Mon, Sep 14, 2020 at 02:09:41PM -0700, Dmitry Torokhov wrote:
> > Hi Cristian,
> > 
> > On Sat, Aug 22, 2020 at 01:19:51AM +0300, Cristian Ciocaltea wrote:
> > > The Actions Semi ATC260x PMICs are able to manage an onkey button.
> > > This driver exposes the ATC260x onkey as an input device. It can also
> > > be configured to force a system reset on a long key-press with an
> > > adjustable duration.
> > > 
> > > The currently supported chip variants are ATC2603C and ATC2609A.
> > > 
> > > Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
> > > ---
> > >  drivers/input/misc/Kconfig         |  11 ++
> > >  drivers/input/misc/Makefile        |   2 +-
> > >  drivers/input/misc/atc260x-onkey.c | 304 +++++++++++++++++++++++++++++
> > >  3 files changed, 316 insertions(+), 1 deletion(-)
> > >  create mode 100644 drivers/input/misc/atc260x-onkey.c
> > > 
> > > diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
> > > index 362e8a01980c..9e297ebdea57 100644
> > > --- a/drivers/input/misc/Kconfig
> > > +++ b/drivers/input/misc/Kconfig
> > > @@ -83,6 +83,17 @@ config INPUT_ARIZONA_HAPTICS
> > >  	  To compile this driver as a module, choose M here: the
> > >  	  module will be called arizona-haptics.
> > >  
> > > +config INPUT_ATC260X_ONKEY
> > > +	tristate "Actions Semi ATC260x PMIC ONKEY"
> > > +	depends on MFD_ATC260X
> > > +	help
> > > +	  Support the ONKEY of ATC260x PMICs as an input device reporting
> > > +	  power button status. ONKEY can be used to wakeup from low power
> > > +	  modes and force a reset on long press.
> > > +
> > > +	  To compile this driver as a module, choose M here: the
> > > +	  module will be called atc260x-onkey.
> > > +
> > >  config INPUT_ATMEL_CAPTOUCH
> > >  	tristate "Atmel Capacitive Touch Button Driver"
> > >  	depends on OF || COMPILE_TEST
> > > diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
> > > index a48e5f2d859d..7f854c6ecefa 100644
> > > --- a/drivers/input/misc/Makefile
> > > +++ b/drivers/input/misc/Makefile
> > > @@ -16,6 +16,7 @@ obj-$(CONFIG_INPUT_ADXL34X_I2C)		+= adxl34x-i2c.o
> > >  obj-$(CONFIG_INPUT_ADXL34X_SPI)		+= adxl34x-spi.o
> > >  obj-$(CONFIG_INPUT_APANEL)		+= apanel.o
> > >  obj-$(CONFIG_INPUT_ARIZONA_HAPTICS)	+= arizona-haptics.o
> > > +obj-$(CONFIG_INPUT_ATC260X_ONKEY)	+= atc260x-onkey.o
> > >  obj-$(CONFIG_INPUT_ATI_REMOTE2)		+= ati_remote2.o
> > >  obj-$(CONFIG_INPUT_ATLAS_BTNS)		+= atlas_btns.o
> > >  obj-$(CONFIG_INPUT_ATMEL_CAPTOUCH)	+= atmel_captouch.o
> > > @@ -84,4 +85,3 @@ obj-$(CONFIG_INPUT_WM831X_ON)		+= wm831x-on.o
> > >  obj-$(CONFIG_INPUT_XEN_KBDDEV_FRONTEND)	+= xen-kbdfront.o
> > >  obj-$(CONFIG_INPUT_YEALINK)		+= yealink.o
> > >  obj-$(CONFIG_INPUT_IDEAPAD_SLIDEBAR)	+= ideapad_slidebar.o
> > > -
> > > diff --git a/drivers/input/misc/atc260x-onkey.c b/drivers/input/misc/atc260x-onkey.c
> > > new file mode 100644
> > > index 000000000000..7caec7d6f9ac
> > > --- /dev/null
> > > +++ b/drivers/input/misc/atc260x-onkey.c
> > > @@ -0,0 +1,304 @@
> > > +// SPDX-License-Identifier: GPL-2.0+
> > > +/*
> > > + * Onkey driver for Actions Semi ATC260x PMICs.
> > > + *
> > > + * Copyright (c) 2020 Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
> > > + */
> > > +
> > > +#include <linux/bitfield.h>
> > > +#include <linux/input.h>
> > > +#include <linux/interrupt.h>
> > > +#include <linux/mfd/atc260x/core.h>
> > > +#include <linux/module.h>
> > > +#include <linux/of.h>
> > > +#include <linux/platform_device.h>
> > > +#include <linux/regmap.h>
> > > +
> > > +/* <2s for short press, >2s for long press */
> > > +#define KEY_PRESS_TIME_SEC	2
> > > +
> > > +/* Driver internals */
> > > +enum atc260x_onkey_reset_status {
> > > +	KEY_RESET_HW_DEFAULT,
> > > +	KEY_RESET_DISABLED,
> > > +	KEY_RESET_USER_SEL,
> > > +};
> > > +
> > > +struct atc260x_onkey_params {
> > > +	u32 reg_int_ctl;
> > > +	u32 kdwn_state_bm;
> > > +	u32 long_int_pnd_bm;
> > > +	u32 short_int_pnd_bm;
> > > +	u32 kdwn_int_pnd_bm;
> > > +	u32 press_int_en_bm;
> > > +	u32 kdwn_int_en_bm;
> > > +	u32 press_time_bm;
> > > +	u32 reset_en_bm;
> > > +	u32 reset_time_bm;
> > > +};
> > > +
> > > +struct atc260x_onkey {
> > > +	struct atc260x *atc260x;
> > > +	const struct atc260x_onkey_params *params;
> > > +	struct input_dev *input_dev;
> > > +	struct delayed_work work;
> > > +};
> > > +
> > > +static const struct atc260x_onkey_params atc2603c_onkey_params = {
> > > +	.reg_int_ctl		= ATC2603C_PMU_SYS_CTL2,
> > > +	.long_int_pnd_bm	= ATC2603C_PMU_SYS_CTL2_ONOFF_LONG_PRESS,
> > > +	.short_int_pnd_bm	= ATC2603C_PMU_SYS_CTL2_ONOFF_SHORT_PRESS,
> > > +	.kdwn_int_pnd_bm	= ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS_PD,
> > > +	.press_int_en_bm	= ATC2603C_PMU_SYS_CTL2_ONOFF_INT_EN,
> > > +	.kdwn_int_en_bm		= ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS_INT_EN,
> > > +	.kdwn_state_bm		= ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS,
> > > +	.press_time_bm		= ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS_TIME,
> > > +	.reset_en_bm		= ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS_RESET_EN,
> > > +	.reset_time_bm		= ATC2603C_PMU_SYS_CTL2_ONOFF_RESET_TIME_SEL,
> > > +};
> > > +
> > > +static const struct atc260x_onkey_params atc2609a_onkey_params = {
> > > +	.reg_int_ctl		= ATC2609A_PMU_SYS_CTL2,
> > > +	.long_int_pnd_bm	= ATC2609A_PMU_SYS_CTL2_ONOFF_LONG_PRESS,
> > > +	.short_int_pnd_bm	= ATC2609A_PMU_SYS_CTL2_ONOFF_SHORT_PRESS,
> > > +	.kdwn_int_pnd_bm	= ATC2609A_PMU_SYS_CTL2_ONOFF_PRESS_PD,
> > > +	.press_int_en_bm	= ATC2609A_PMU_SYS_CTL2_ONOFF_LSP_INT_EN,
> > > +	.kdwn_int_en_bm		= ATC2609A_PMU_SYS_CTL2_ONOFF_PRESS_INT_EN,
> > > +	.kdwn_state_bm		= ATC2609A_PMU_SYS_CTL2_ONOFF_PRESS,
> > > +	.press_time_bm		= ATC2609A_PMU_SYS_CTL2_ONOFF_PRESS_TIME,
> > > +	.reset_en_bm		= ATC2609A_PMU_SYS_CTL2_ONOFF_RESET_EN,
> > > +	.reset_time_bm		= ATC2609A_PMU_SYS_CTL2_ONOFF_RESET_TIME_SEL,
> > > +};
> > > +
> > > +static int atc2603x_onkey_hw_init(struct atc260x_onkey *onkey,
> > > +				  enum atc260x_onkey_reset_status reset_status,
> > > +				  u32 reset_time, u32 press_time)
> > > +{
> > > +	u32 reg_bm, reg_val;
> > > +
> > > +	reg_bm = onkey->params->long_int_pnd_bm |
> > > +		 onkey->params->short_int_pnd_bm |
> > > +		 onkey->params->kdwn_int_pnd_bm |
> > > +		 onkey->params->press_int_en_bm |
> > > +		 onkey->params->kdwn_int_en_bm;
> > > +
> > > +	reg_val = reg_bm | press_time;
> > > +	reg_bm |= onkey->params->press_time_bm;
> > > +
> > > +	if (reset_status == KEY_RESET_DISABLED) {
> > > +		reg_bm |= onkey->params->reset_en_bm;
> > > +	} else if (reset_status == KEY_RESET_USER_SEL) {
> > > +		reg_bm |= onkey->params->reset_en_bm |
> > > +			  onkey->params->reset_time_bm;
> > > +		reg_val |= onkey->params->reset_en_bm | reset_time;
> > > +	}
> > > +
> > > +	return regmap_update_bits(onkey->atc260x->regmap,
> > > +				  onkey->params->reg_int_ctl, reg_bm, reg_val);
> > > +}
> > > +
> > > +static void atc260x_onkey_query(struct atc260x_onkey *onkey)
> > > +{
> > > +	u32 reg_bits;
> > > +	int ret, key_down;
> > > +
> > > +	ret = regmap_read(onkey->atc260x->regmap,
> > > +			  onkey->params->reg_int_ctl, &key_down);
> > > +	if (ret) {
> > > +		key_down = 1;
> > > +		dev_err(onkey->atc260x->dev,
> > > +			"Failed to read onkey status: %d\n", ret);
> > > +	} else {
> > > +		key_down &= onkey->params->kdwn_state_bm;
> > > +	}
> > > +
> > > +	/*
> > > +	 * The hardware generates interrupt only when the onkey pin is
> > > +	 * asserted. Hence, the deassertion of the pin is simulated through
> > > +	 * work queue.
> > > +	 */
> > > +	if (key_down) {
> > > +		schedule_delayed_work(&onkey->work, msecs_to_jiffies(200));
> > > +		return;
> > > +	}
> > > +
> > > +	/*
> > > +	 * The key-down status bit is cleared when the On/Off button
> > > +	 * is released.
> > > +	 */
> > > +	input_report_key(onkey->input_dev, KEY_POWER, 0);
> > > +	input_sync(onkey->input_dev);
> > > +
> > > +	reg_bits = onkey->params->long_int_pnd_bm |
> > > +		   onkey->params->short_int_pnd_bm |
> > > +		   onkey->params->kdwn_int_pnd_bm |
> > > +		   onkey->params->press_int_en_bm |
> > > +		   onkey->params->kdwn_int_en_bm;
> > > +
> > > +	/* Clear key press pending events and enable key press interrupts. */
> > > +	regmap_update_bits(onkey->atc260x->regmap, onkey->params->reg_int_ctl,
> > > +			   reg_bits, reg_bits);
> > > +}
> > > +
> > > +static void atc260x_onkey_work(struct work_struct *work)
> > > +{
> > > +	struct atc260x_onkey *onkey = container_of(work, struct atc260x_onkey,
> > > +						   work.work);
> > > +	atc260x_onkey_query(onkey);
> > > +}
> > > +
> > > +static irqreturn_t atc260x_onkey_irq(int irq, void *data)
> > > +{
> > > +	struct atc260x_onkey *onkey = data;
> > > +	int ret;
> > > +
> > > +	/* Disable key press interrupts. */
> > > +	ret = regmap_update_bits(onkey->atc260x->regmap,
> > > +				 onkey->params->reg_int_ctl,
> > > +				 onkey->params->press_int_en_bm |
> > > +				 onkey->params->kdwn_int_en_bm, 0);
> > > +	if (ret)
> > > +		dev_err(onkey->atc260x->dev,
> > > +			"Failed to disable interrupts: %d\n", ret);
> > > +
> > > +	input_report_key(onkey->input_dev, KEY_POWER, 1);
> > > +	input_sync(onkey->input_dev);
> > > +
> > > +	atc260x_onkey_query(onkey);
> > > +
> > > +	return IRQ_HANDLED;
> > > +}
> > > +
> > > +static int atc260x_onkey_probe(struct platform_device *pdev)
> > > +{
> > > +	struct atc260x *atc260x = dev_get_drvdata(pdev->dev.parent);
> > > +	struct atc260x_onkey *onkey;
> > > +	struct input_dev *input_dev;
> > > +	enum atc260x_onkey_reset_status reset_status;
> > > +	u32 press_time = KEY_PRESS_TIME_SEC, reset_time = 0;
> > > +	int val, irq, ret;
> > > +
> > > +	if (!pdev->dev.of_node)
> > > +		return -ENXIO;
> > 
> > Why is this needed?
> 
> The idea was to allow the user enable/disable the ONKEY functionality
> of the MFD device via the 'onkey' DTS node. So if this node is not
> present, the driver will not be loaded.
> 
> Is there a better/recommended way to handle this scenario?

I believe the best way is not to create correspnding platform device if
functionality is disabled. So the logic shoudl go into MFD piece.

> 
> > > +
> > > +	onkey = devm_kzalloc(&pdev->dev, sizeof(*onkey), GFP_KERNEL);
> > > +	if (!onkey)
> > > +		return -ENOMEM;
> > > +
> > > +	ret = device_property_read_u32(&pdev->dev,
> > > +				       "actions,reset-time-sec", &val);
> > 
> > Call this "error" please.
> 
> Would something like bellow suffice?
> 
> 	if (ret) {
> 		dev_err(&pdev->dev, "Failed to read actions,reset-time-sec\n");
> 		return ret;
> 	}


I meant

	error = device_property_read_u32(&pdev->dev,
					 "actions,reset-time-sec", &val);
	if (error) {
		reset_status = KEY_RESET_HW_DEFAULT;
	}


> 
> > > +	if (ret) {
> > > +		reset_status = KEY_RESET_HW_DEFAULT;
> > > +	} else if (val) {
> > > +		if (val < 6 || val > 12) {
> > > +			dev_err(&pdev->dev, "actions,reset-time-sec out of range\n");
> > > +			return -EINVAL;
> > > +		}
> > > +
> > > +		reset_status = KEY_RESET_USER_SEL;
> > > +		reset_time = (val - 6) / 2;
> > > +	} else {
> > > +		reset_status = KEY_RESET_DISABLED;
> > > +		dev_info(&pdev->dev, "Disabled reset on long-press\n");

dev_dbg();

> > > +	}
> > > +
> > > +	switch (atc260x->ic_type) {
> > > +	case ATC2603C:
> > > +		onkey->params = &atc2603c_onkey_params;
> > > +		press_time = FIELD_PREP(ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS_TIME,
> > > +					press_time);
> > > +		reset_time = FIELD_PREP(ATC2603C_PMU_SYS_CTL2_ONOFF_RESET_TIME_SEL,
> > > +					reset_time);
> > > +		break;
> > > +	case ATC2609A:
> > > +		onkey->params = &atc2609a_onkey_params;
> > > +		press_time = FIELD_PREP(ATC2609A_PMU_SYS_CTL2_ONOFF_PRESS_TIME,
> > > +					press_time);
> > > +		reset_time = FIELD_PREP(ATC2609A_PMU_SYS_CTL2_ONOFF_RESET_TIME_SEL,
> > > +					reset_time);
> > > +		break;
> > > +	default:
> > > +		dev_err(&pdev->dev,
> > > +			"OnKey not supported for ATC260x PMIC type: %u\n",
> > > +			atc260x->ic_type);
> > > +		return -EINVAL;
> > > +	}
> > > +
> > > +	input_dev = devm_input_allocate_device(&pdev->dev);
> > > +	if (!input_dev) {
> > > +		dev_err(&pdev->dev, "Failed to allocate input device\n");
> > > +		return -ENOMEM;
> > > +	}
> > > +
> > > +	onkey->input_dev = input_dev;
> > > +	onkey->atc260x = atc260x;
> > > +
> > > +	input_dev->name = "atc260x-onkey";
> > > +	input_dev->phys = "atc260x-onkey/input0";
> > > +	input_dev->evbit[0] = BIT_MASK(EV_KEY);
> > 
> > Not needed.
> 
> Done.
> 
> > > +	input_set_capability(input_dev, EV_KEY, KEY_POWER);
> > > +
> > > +	INIT_DELAYED_WORK(&onkey->work, atc260x_onkey_work);
> > > +
> > > +	irq = platform_get_irq(pdev, 0);
> > > +	if (irq < 0)
> > > +		return irq;
> > > +
> > > +	ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
> > > +					atc260x_onkey_irq,
> > > +					IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
> > 
> > Do we need to force the trigger type? Can we rely on the parent to
> > configure it as needed?
> 
> Done, I removed the trigger type enforcement.
> 
> > > +					dev_name(&pdev->dev), onkey);
> > > +	if (ret) {
> > > +		dev_err(&pdev->dev,
> > > +			"Failed to register IRQ %d: %d\n", irq, ret);
> > > +		return ret;
> > > +	}
> > > +
> > > +	ret = input_register_device(input_dev);
> > > +	if (ret) {
> > > +		dev_err(&pdev->dev,
> > > +			"Failed to register input device: %d\n", ret);
> > > +		return ret;
> > > +	}
> > > +
> > > +	ret = atc2603x_onkey_hw_init(onkey, reset_status,
> > > +				     reset_time, press_time);
> > > +	if (ret)
> > > +		return ret;
> > > +
> > > +	platform_set_drvdata(pdev, onkey);
> > > +	device_init_wakeup(&pdev->dev, true);
> > > +
> > > +	return 0;
> > > +}
> > > +
> > > +static int atc260x_onkey_remove(struct platform_device *pdev)
> > > +{
> > > +	struct atc260x_onkey *onkey = platform_get_drvdata(pdev);
> > > +
> > > +	cancel_delayed_work_sync(&onkey->work);
> > 
> > This is racy. Past this point the interrupts are not disabled, so if key
> > happens to be pressed you will re-schedule the work and it will go BOOM.
> > 
> > You are using threaded interrupt. Maybe consider sleeping and
> > re-checking the key status right there.
> 
> I've seen this approach in a few drivers: da9055_onkey.c,
> palmas-pwrbutton.c, wm831x-on.c
> 
> I noticed they also call 'free_irq()' right before
> 'cancel_delayed_work_sync()'. Would this help mitigate the racing issue?

Yes, but this messes up with devm releasing resources.

Another option is to implement open/close and call enable_irq() in open
and disable_irq/cancel_work_sync in close.

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 5/6] input: atc260x: Add onkey driver for ATC260x PMICs
  2020-09-29 20:35       ` Dmitry Torokhov
@ 2020-09-29 21:46         ` Cristian Ciocaltea
  0 siblings, 0 replies; 23+ messages in thread
From: Cristian Ciocaltea @ 2020-09-29 21:46 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Lee Jones, Rob Herring, Sebastian Reichel, Liam Girdwood,
	Mark Brown, Manivannan Sadhasivam, Andreas Färber,
	linux-actions, devicetree, linux-kernel, linux-input, linux-pm

Hi Dmitry,

On Tue, Sep 29, 2020 at 01:35:54PM -0700, Dmitry Torokhov wrote:
> Hi Cristian,
> 
> On Fri, Sep 18, 2020 at 01:35:03PM +0300, Cristian Ciocaltea wrote:
> > Hi Dmitry,
> > 
> > Thanks for the review!
> > 
> > On Mon, Sep 14, 2020 at 02:09:41PM -0700, Dmitry Torokhov wrote:
> > > Hi Cristian,
> > > 
> > > On Sat, Aug 22, 2020 at 01:19:51AM +0300, Cristian Ciocaltea wrote:
> > > > The Actions Semi ATC260x PMICs are able to manage an onkey button.
> > > > This driver exposes the ATC260x onkey as an input device. It can also
> > > > be configured to force a system reset on a long key-press with an
> > > > adjustable duration.
> > > > 
> > > > The currently supported chip variants are ATC2603C and ATC2609A.
> > > > 
> > > > Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
> > > > ---
> > > >  drivers/input/misc/Kconfig         |  11 ++
> > > >  drivers/input/misc/Makefile        |   2 +-
> > > >  drivers/input/misc/atc260x-onkey.c | 304 +++++++++++++++++++++++++++++
> > > >  3 files changed, 316 insertions(+), 1 deletion(-)
> > > >  create mode 100644 drivers/input/misc/atc260x-onkey.c
> > > > 
> > > > diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
> > > > index 362e8a01980c..9e297ebdea57 100644
> > > > --- a/drivers/input/misc/Kconfig
> > > > +++ b/drivers/input/misc/Kconfig
> > > > @@ -83,6 +83,17 @@ config INPUT_ARIZONA_HAPTICS
> > > >  	  To compile this driver as a module, choose M here: the
> > > >  	  module will be called arizona-haptics.
> > > >  
> > > > +config INPUT_ATC260X_ONKEY
> > > > +	tristate "Actions Semi ATC260x PMIC ONKEY"
> > > > +	depends on MFD_ATC260X
> > > > +	help
> > > > +	  Support the ONKEY of ATC260x PMICs as an input device reporting
> > > > +	  power button status. ONKEY can be used to wakeup from low power
> > > > +	  modes and force a reset on long press.
> > > > +
> > > > +	  To compile this driver as a module, choose M here: the
> > > > +	  module will be called atc260x-onkey.
> > > > +
> > > >  config INPUT_ATMEL_CAPTOUCH
> > > >  	tristate "Atmel Capacitive Touch Button Driver"
> > > >  	depends on OF || COMPILE_TEST
> > > > diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
> > > > index a48e5f2d859d..7f854c6ecefa 100644
> > > > --- a/drivers/input/misc/Makefile
> > > > +++ b/drivers/input/misc/Makefile
> > > > @@ -16,6 +16,7 @@ obj-$(CONFIG_INPUT_ADXL34X_I2C)		+= adxl34x-i2c.o
> > > >  obj-$(CONFIG_INPUT_ADXL34X_SPI)		+= adxl34x-spi.o
> > > >  obj-$(CONFIG_INPUT_APANEL)		+= apanel.o
> > > >  obj-$(CONFIG_INPUT_ARIZONA_HAPTICS)	+= arizona-haptics.o
> > > > +obj-$(CONFIG_INPUT_ATC260X_ONKEY)	+= atc260x-onkey.o
> > > >  obj-$(CONFIG_INPUT_ATI_REMOTE2)		+= ati_remote2.o
> > > >  obj-$(CONFIG_INPUT_ATLAS_BTNS)		+= atlas_btns.o
> > > >  obj-$(CONFIG_INPUT_ATMEL_CAPTOUCH)	+= atmel_captouch.o
> > > > @@ -84,4 +85,3 @@ obj-$(CONFIG_INPUT_WM831X_ON)		+= wm831x-on.o
> > > >  obj-$(CONFIG_INPUT_XEN_KBDDEV_FRONTEND)	+= xen-kbdfront.o
> > > >  obj-$(CONFIG_INPUT_YEALINK)		+= yealink.o
> > > >  obj-$(CONFIG_INPUT_IDEAPAD_SLIDEBAR)	+= ideapad_slidebar.o
> > > > -
> > > > diff --git a/drivers/input/misc/atc260x-onkey.c b/drivers/input/misc/atc260x-onkey.c
> > > > new file mode 100644
> > > > index 000000000000..7caec7d6f9ac
> > > > --- /dev/null
> > > > +++ b/drivers/input/misc/atc260x-onkey.c
> > > > @@ -0,0 +1,304 @@
> > > > +// SPDX-License-Identifier: GPL-2.0+
> > > > +/*
> > > > + * Onkey driver for Actions Semi ATC260x PMICs.
> > > > + *
> > > > + * Copyright (c) 2020 Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
> > > > + */
> > > > +
> > > > +#include <linux/bitfield.h>
> > > > +#include <linux/input.h>
> > > > +#include <linux/interrupt.h>
> > > > +#include <linux/mfd/atc260x/core.h>
> > > > +#include <linux/module.h>
> > > > +#include <linux/of.h>
> > > > +#include <linux/platform_device.h>
> > > > +#include <linux/regmap.h>
> > > > +
> > > > +/* <2s for short press, >2s for long press */
> > > > +#define KEY_PRESS_TIME_SEC	2
> > > > +
> > > > +/* Driver internals */
> > > > +enum atc260x_onkey_reset_status {
> > > > +	KEY_RESET_HW_DEFAULT,
> > > > +	KEY_RESET_DISABLED,
> > > > +	KEY_RESET_USER_SEL,
> > > > +};
> > > > +
> > > > +struct atc260x_onkey_params {
> > > > +	u32 reg_int_ctl;
> > > > +	u32 kdwn_state_bm;
> > > > +	u32 long_int_pnd_bm;
> > > > +	u32 short_int_pnd_bm;
> > > > +	u32 kdwn_int_pnd_bm;
> > > > +	u32 press_int_en_bm;
> > > > +	u32 kdwn_int_en_bm;
> > > > +	u32 press_time_bm;
> > > > +	u32 reset_en_bm;
> > > > +	u32 reset_time_bm;
> > > > +};
> > > > +
> > > > +struct atc260x_onkey {
> > > > +	struct atc260x *atc260x;
> > > > +	const struct atc260x_onkey_params *params;
> > > > +	struct input_dev *input_dev;
> > > > +	struct delayed_work work;
> > > > +};
> > > > +
> > > > +static const struct atc260x_onkey_params atc2603c_onkey_params = {
> > > > +	.reg_int_ctl		= ATC2603C_PMU_SYS_CTL2,
> > > > +	.long_int_pnd_bm	= ATC2603C_PMU_SYS_CTL2_ONOFF_LONG_PRESS,
> > > > +	.short_int_pnd_bm	= ATC2603C_PMU_SYS_CTL2_ONOFF_SHORT_PRESS,
> > > > +	.kdwn_int_pnd_bm	= ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS_PD,
> > > > +	.press_int_en_bm	= ATC2603C_PMU_SYS_CTL2_ONOFF_INT_EN,
> > > > +	.kdwn_int_en_bm		= ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS_INT_EN,
> > > > +	.kdwn_state_bm		= ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS,
> > > > +	.press_time_bm		= ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS_TIME,
> > > > +	.reset_en_bm		= ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS_RESET_EN,
> > > > +	.reset_time_bm		= ATC2603C_PMU_SYS_CTL2_ONOFF_RESET_TIME_SEL,
> > > > +};
> > > > +
> > > > +static const struct atc260x_onkey_params atc2609a_onkey_params = {
> > > > +	.reg_int_ctl		= ATC2609A_PMU_SYS_CTL2,
> > > > +	.long_int_pnd_bm	= ATC2609A_PMU_SYS_CTL2_ONOFF_LONG_PRESS,
> > > > +	.short_int_pnd_bm	= ATC2609A_PMU_SYS_CTL2_ONOFF_SHORT_PRESS,
> > > > +	.kdwn_int_pnd_bm	= ATC2609A_PMU_SYS_CTL2_ONOFF_PRESS_PD,
> > > > +	.press_int_en_bm	= ATC2609A_PMU_SYS_CTL2_ONOFF_LSP_INT_EN,
> > > > +	.kdwn_int_en_bm		= ATC2609A_PMU_SYS_CTL2_ONOFF_PRESS_INT_EN,
> > > > +	.kdwn_state_bm		= ATC2609A_PMU_SYS_CTL2_ONOFF_PRESS,
> > > > +	.press_time_bm		= ATC2609A_PMU_SYS_CTL2_ONOFF_PRESS_TIME,
> > > > +	.reset_en_bm		= ATC2609A_PMU_SYS_CTL2_ONOFF_RESET_EN,
> > > > +	.reset_time_bm		= ATC2609A_PMU_SYS_CTL2_ONOFF_RESET_TIME_SEL,
> > > > +};
> > > > +
> > > > +static int atc2603x_onkey_hw_init(struct atc260x_onkey *onkey,
> > > > +				  enum atc260x_onkey_reset_status reset_status,
> > > > +				  u32 reset_time, u32 press_time)
> > > > +{
> > > > +	u32 reg_bm, reg_val;
> > > > +
> > > > +	reg_bm = onkey->params->long_int_pnd_bm |
> > > > +		 onkey->params->short_int_pnd_bm |
> > > > +		 onkey->params->kdwn_int_pnd_bm |
> > > > +		 onkey->params->press_int_en_bm |
> > > > +		 onkey->params->kdwn_int_en_bm;
> > > > +
> > > > +	reg_val = reg_bm | press_time;
> > > > +	reg_bm |= onkey->params->press_time_bm;
> > > > +
> > > > +	if (reset_status == KEY_RESET_DISABLED) {
> > > > +		reg_bm |= onkey->params->reset_en_bm;
> > > > +	} else if (reset_status == KEY_RESET_USER_SEL) {
> > > > +		reg_bm |= onkey->params->reset_en_bm |
> > > > +			  onkey->params->reset_time_bm;
> > > > +		reg_val |= onkey->params->reset_en_bm | reset_time;
> > > > +	}
> > > > +
> > > > +	return regmap_update_bits(onkey->atc260x->regmap,
> > > > +				  onkey->params->reg_int_ctl, reg_bm, reg_val);
> > > > +}
> > > > +
> > > > +static void atc260x_onkey_query(struct atc260x_onkey *onkey)
> > > > +{
> > > > +	u32 reg_bits;
> > > > +	int ret, key_down;
> > > > +
> > > > +	ret = regmap_read(onkey->atc260x->regmap,
> > > > +			  onkey->params->reg_int_ctl, &key_down);
> > > > +	if (ret) {
> > > > +		key_down = 1;
> > > > +		dev_err(onkey->atc260x->dev,
> > > > +			"Failed to read onkey status: %d\n", ret);
> > > > +	} else {
> > > > +		key_down &= onkey->params->kdwn_state_bm;
> > > > +	}
> > > > +
> > > > +	/*
> > > > +	 * The hardware generates interrupt only when the onkey pin is
> > > > +	 * asserted. Hence, the deassertion of the pin is simulated through
> > > > +	 * work queue.
> > > > +	 */
> > > > +	if (key_down) {
> > > > +		schedule_delayed_work(&onkey->work, msecs_to_jiffies(200));
> > > > +		return;
> > > > +	}
> > > > +
> > > > +	/*
> > > > +	 * The key-down status bit is cleared when the On/Off button
> > > > +	 * is released.
> > > > +	 */
> > > > +	input_report_key(onkey->input_dev, KEY_POWER, 0);
> > > > +	input_sync(onkey->input_dev);
> > > > +
> > > > +	reg_bits = onkey->params->long_int_pnd_bm |
> > > > +		   onkey->params->short_int_pnd_bm |
> > > > +		   onkey->params->kdwn_int_pnd_bm |
> > > > +		   onkey->params->press_int_en_bm |
> > > > +		   onkey->params->kdwn_int_en_bm;
> > > > +
> > > > +	/* Clear key press pending events and enable key press interrupts. */
> > > > +	regmap_update_bits(onkey->atc260x->regmap, onkey->params->reg_int_ctl,
> > > > +			   reg_bits, reg_bits);
> > > > +}
> > > > +
> > > > +static void atc260x_onkey_work(struct work_struct *work)
> > > > +{
> > > > +	struct atc260x_onkey *onkey = container_of(work, struct atc260x_onkey,
> > > > +						   work.work);
> > > > +	atc260x_onkey_query(onkey);
> > > > +}
> > > > +
> > > > +static irqreturn_t atc260x_onkey_irq(int irq, void *data)
> > > > +{
> > > > +	struct atc260x_onkey *onkey = data;
> > > > +	int ret;
> > > > +
> > > > +	/* Disable key press interrupts. */
> > > > +	ret = regmap_update_bits(onkey->atc260x->regmap,
> > > > +				 onkey->params->reg_int_ctl,
> > > > +				 onkey->params->press_int_en_bm |
> > > > +				 onkey->params->kdwn_int_en_bm, 0);
> > > > +	if (ret)
> > > > +		dev_err(onkey->atc260x->dev,
> > > > +			"Failed to disable interrupts: %d\n", ret);
> > > > +
> > > > +	input_report_key(onkey->input_dev, KEY_POWER, 1);
> > > > +	input_sync(onkey->input_dev);
> > > > +
> > > > +	atc260x_onkey_query(onkey);
> > > > +
> > > > +	return IRQ_HANDLED;
> > > > +}
> > > > +
> > > > +static int atc260x_onkey_probe(struct platform_device *pdev)
> > > > +{
> > > > +	struct atc260x *atc260x = dev_get_drvdata(pdev->dev.parent);
> > > > +	struct atc260x_onkey *onkey;
> > > > +	struct input_dev *input_dev;
> > > > +	enum atc260x_onkey_reset_status reset_status;
> > > > +	u32 press_time = KEY_PRESS_TIME_SEC, reset_time = 0;
> > > > +	int val, irq, ret;
> > > > +
> > > > +	if (!pdev->dev.of_node)
> > > > +		return -ENXIO;
> > > 
> > > Why is this needed?
> > 
> > The idea was to allow the user enable/disable the ONKEY functionality
> > of the MFD device via the 'onkey' DTS node. So if this node is not
> > present, the driver will not be loaded.
> > 
> > Is there a better/recommended way to handle this scenario?
> 
> I believe the best way is not to create correspnding platform device if
> functionality is disabled. So the logic shoudl go into MFD piece.

Thanks for the suggestion, I will move the logic to MFD core.

> > 
> > > > +
> > > > +	onkey = devm_kzalloc(&pdev->dev, sizeof(*onkey), GFP_KERNEL);
> > > > +	if (!onkey)
> > > > +		return -ENOMEM;
> > > > +
> > > > +	ret = device_property_read_u32(&pdev->dev,
> > > > +				       "actions,reset-time-sec", &val);
> > > 
> > > Call this "error" please.
> > 
> > Would something like bellow suffice?
> > 
> > 	if (ret) {
> > 		dev_err(&pdev->dev, "Failed to read actions,reset-time-sec\n");
> > 		return ret;
> > 	}
> 
> 
> I meant
> 
> 	error = device_property_read_u32(&pdev->dev,
> 					 "actions,reset-time-sec", &val);
> 	if (error) {
> 		reset_status = KEY_RESET_HW_DEFAULT;
> 	}

Got it now.
 
> > 
> > > > +	if (ret) {
> > > > +		reset_status = KEY_RESET_HW_DEFAULT;
> > > > +	} else if (val) {
> > > > +		if (val < 6 || val > 12) {
> > > > +			dev_err(&pdev->dev, "actions,reset-time-sec out of range\n");
> > > > +			return -EINVAL;
> > > > +		}
> > > > +
> > > > +		reset_status = KEY_RESET_USER_SEL;
> > > > +		reset_time = (val - 6) / 2;
> > > > +	} else {
> > > > +		reset_status = KEY_RESET_DISABLED;
> > > > +		dev_info(&pdev->dev, "Disabled reset on long-press\n");
> 
> dev_dbg();

Acknowledged.

> > > > +	}
> > > > +
> > > > +	switch (atc260x->ic_type) {
> > > > +	case ATC2603C:
> > > > +		onkey->params = &atc2603c_onkey_params;
> > > > +		press_time = FIELD_PREP(ATC2603C_PMU_SYS_CTL2_ONOFF_PRESS_TIME,
> > > > +					press_time);
> > > > +		reset_time = FIELD_PREP(ATC2603C_PMU_SYS_CTL2_ONOFF_RESET_TIME_SEL,
> > > > +					reset_time);
> > > > +		break;
> > > > +	case ATC2609A:
> > > > +		onkey->params = &atc2609a_onkey_params;
> > > > +		press_time = FIELD_PREP(ATC2609A_PMU_SYS_CTL2_ONOFF_PRESS_TIME,
> > > > +					press_time);
> > > > +		reset_time = FIELD_PREP(ATC2609A_PMU_SYS_CTL2_ONOFF_RESET_TIME_SEL,
> > > > +					reset_time);
> > > > +		break;
> > > > +	default:
> > > > +		dev_err(&pdev->dev,
> > > > +			"OnKey not supported for ATC260x PMIC type: %u\n",
> > > > +			atc260x->ic_type);
> > > > +		return -EINVAL;
> > > > +	}
> > > > +
> > > > +	input_dev = devm_input_allocate_device(&pdev->dev);
> > > > +	if (!input_dev) {
> > > > +		dev_err(&pdev->dev, "Failed to allocate input device\n");
> > > > +		return -ENOMEM;
> > > > +	}
> > > > +
> > > > +	onkey->input_dev = input_dev;
> > > > +	onkey->atc260x = atc260x;
> > > > +
> > > > +	input_dev->name = "atc260x-onkey";
> > > > +	input_dev->phys = "atc260x-onkey/input0";
> > > > +	input_dev->evbit[0] = BIT_MASK(EV_KEY);
> > > 
> > > Not needed.
> > 
> > Done.
> > 
> > > > +	input_set_capability(input_dev, EV_KEY, KEY_POWER);
> > > > +
> > > > +	INIT_DELAYED_WORK(&onkey->work, atc260x_onkey_work);
> > > > +
> > > > +	irq = platform_get_irq(pdev, 0);
> > > > +	if (irq < 0)
> > > > +		return irq;
> > > > +
> > > > +	ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
> > > > +					atc260x_onkey_irq,
> > > > +					IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
> > > 
> > > Do we need to force the trigger type? Can we rely on the parent to
> > > configure it as needed?
> > 
> > Done, I removed the trigger type enforcement.
> > 
> > > > +					dev_name(&pdev->dev), onkey);
> > > > +	if (ret) {
> > > > +		dev_err(&pdev->dev,
> > > > +			"Failed to register IRQ %d: %d\n", irq, ret);
> > > > +		return ret;
> > > > +	}
> > > > +
> > > > +	ret = input_register_device(input_dev);
> > > > +	if (ret) {
> > > > +		dev_err(&pdev->dev,
> > > > +			"Failed to register input device: %d\n", ret);
> > > > +		return ret;
> > > > +	}
> > > > +
> > > > +	ret = atc2603x_onkey_hw_init(onkey, reset_status,
> > > > +				     reset_time, press_time);
> > > > +	if (ret)
> > > > +		return ret;
> > > > +
> > > > +	platform_set_drvdata(pdev, onkey);
> > > > +	device_init_wakeup(&pdev->dev, true);
> > > > +
> > > > +	return 0;
> > > > +}
> > > > +
> > > > +static int atc260x_onkey_remove(struct platform_device *pdev)
> > > > +{
> > > > +	struct atc260x_onkey *onkey = platform_get_drvdata(pdev);
> > > > +
> > > > +	cancel_delayed_work_sync(&onkey->work);
> > > 
> > > This is racy. Past this point the interrupts are not disabled, so if key
> > > happens to be pressed you will re-schedule the work and it will go BOOM.
> > > 
> > > You are using threaded interrupt. Maybe consider sleeping and
> > > re-checking the key status right there.
> > 
> > I've seen this approach in a few drivers: da9055_onkey.c,
> > palmas-pwrbutton.c, wm831x-on.c
> > 
> > I noticed they also call 'free_irq()' right before
> > 'cancel_delayed_work_sync()'. Would this help mitigate the racing issue?
> 
> Yes, but this messes up with devm releasing resources.

Indeed, I missed that.

> Another option is to implement open/close and call enable_irq() in open
> and disable_irq/cancel_work_sync in close.

I'm going to try this, thanks for the suggestion!

> Thanks.
> 
> -- 
> Dmitry

Kind regards,
Cristi

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2020-09-29 21:46 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-21 22:19 [PATCH v2 0/6] Add initial support for ATC260x PMICs Cristian Ciocaltea
2020-08-21 22:19 ` [PATCH v2 1/6] dt-bindings: mfd: Add Actions Semi ATC260x PMIC binding Cristian Ciocaltea
2020-09-08 21:47   ` Rob Herring
2020-09-09 16:03     ` Cristian Ciocaltea
2020-09-09 17:22       ` Rob Herring
2020-08-21 22:19 ` [PATCH v2 2/6] mfd: Add MFD driver for ATC260x PMICs Cristian Ciocaltea
2020-08-21 22:19 ` [PATCH v2 3/6] regulator: Add regulator " Cristian Ciocaltea
2020-08-24 11:00   ` Mark Brown
2020-08-24 23:23     ` Cristian Ciocaltea
2020-08-25 10:55       ` Mark Brown
2020-08-21 22:19 ` [PATCH v2 4/6] power: reset: Add poweroff " Cristian Ciocaltea
2020-08-24 14:41   ` Sebastian Reichel
2020-08-24 23:31     ` Cristian Ciocaltea
2020-08-21 22:19 ` [PATCH v2 5/6] input: atc260x: Add onkey " Cristian Ciocaltea
2020-09-14 21:09   ` Dmitry Torokhov
2020-09-18 10:35     ` Cristian Ciocaltea
2020-09-29 20:35       ` Dmitry Torokhov
2020-09-29 21:46         ` Cristian Ciocaltea
2020-08-21 22:19 ` [PATCH v2 6/6] MAINTAINERS: Add entry for ATC260x PMIC Cristian Ciocaltea
2020-08-21 22:26 ` [PATCH v2 0/6] Add initial support for ATC260x PMICs Cristian Ciocaltea
2020-08-22 13:13   ` Manivannan Sadhasivam
2020-08-22 23:24     ` Cristian Ciocaltea
2020-08-25  3:48       ` Manivannan Sadhasivam

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).