Skip to contentSkip to conversation

Add initial support for ATC260x PMICs

PATCH Superseded Cristian Ciocaltea 8 participants 26 messages Aug 21, 2020 – Sep 29, 2020

Subsystems (7)

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Cristian Ciocaltea

author maintainer
#0 lore raw

v2 cover Add initial support for ATC260x PMICs

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/[email protected]/

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/[email protected]/

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/[email protected]/

* 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
Signature · 1 line
2.28.0
author maintainer
#1 lore raw

PATCH v2 1/6 dt-bindings: mfd: Add Actions Semi ATC260x PMIC binding

Add devicetree binding for Actions Semi ATC260x PMICs.

---
 .../bindings/mfd/actions,atc260x.yaml         | 221 ++++++++++++++++++
 1 file changed, 221 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/actions,atc260x.yaml
Documentation/devicetree/bindings/mfd/actions,atc260x.yaml new file +221 -0
new file mode 100644
index 000000000000..4a55bbe1306e
@@ -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 <[email protected]>
+  - Cristian Ciocaltea <[email protected]>
+
+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;
+          };
+        };
+      };
+    };
+
+...
Signature · 1 line
2.28.0
author maintainer
#9 lore raw

PATCH v2 3/6 regulator: Add regulator driver for ATC260x PMICs

In reply to Cristian Ciocaltea

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.

[cristian: add ATC2603C variant, more regulator capabilities, cleanups]
---
 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
drivers/regulator/Kconfig +8 -0
index de17ef7e18f0..860e46798503 100644
@@ -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
drivers/regulator/Makefile +1 -0
index d8d3ecf526a8..181ff77ee23c 100644
@@ -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
drivers/regulator/atc260x-regulator.c new file +511 -0

511 lines not on this page · raw message

Signature · 1 line
2.28.0
author maintainer
#13 lore raw

PATCH v2 4/6 power: reset: Add poweroff driver for ATC260x PMICs

In reply to Cristian Ciocaltea

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.

---
 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
drivers/power/reset/Kconfig +7 -1
index 0a1fb5c74f83..df6c3676b892 100644
@@ -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
-
drivers/power/reset/Makefile +1 -0
index c51eceba9ea3..829df1157540 100644
@@ -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
drivers/power/reset/atc260x-poweroff.c new file +274 -0

274 lines not on this page · raw message

Signature · 1 line
2.28.0
author maintainer
#21 lore raw

PATCH v2 6/6 MAINTAINERS: Add entry for ATC260x PMIC

In reply to Cristian Ciocaltea

Add MAINTAINERS entry for ATC260x PMIC.

[cristian: change binding doc file path, add file patterns for onkey and
poweroff drivers, fix ordering, add myself as co-maintainer]

---
 MAINTAINERS | 12 ++++++++++++
 1 file changed, 12 insertions(+)
MAINTAINERS +12 -0
index e28d8ad47d03..b57ac4e9aa11 100644
@@ -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 <[email protected]>
+M:	Cristian Ciocaltea <[email protected]>
+L:	[email protected]
+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 <[email protected]>
 S:	Maintained
Signature · 1 line
2.28.0
author maintainer
#5 lore raw

PATCH v2 2/6 mfd: Add MFD driver for ATC260x PMICs

In reply to Cristian Ciocaltea

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)
[cristian: add ATC2603C variant, poweroff and onkey features, rework]
---
 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
drivers/mfd/Kconfig +18 -0
index 33df0837ab41..49cc3c2b46ad 100644
@@ -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
drivers/mfd/Makefile +3 -0
index a60e5f835283..508e104b6393 100644
@@ -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
drivers/mfd/atc260x-core.c new file +290 -0

290 lines not on this page · raw message

drivers/mfd/atc260x-i2c.c new file +73 -0

73 lines not on this page · raw message

include/linux/mfd/atc260x/atc2603c.h new file +281 -0

281 lines not on this page · raw message

include/linux/mfd/atc260x/atc2609a.h new file +308 -0

308 lines not on this page · raw message

include/linux/mfd/atc260x/core.h new file +86 -0

86 lines not on this page · raw message

Signature · 1 line
2.28.0
author maintainer
#16 lore raw

PATCH v2 5/6 input: atc260x: Add onkey driver for ATC260x PMICs

In reply to Cristian Ciocaltea

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.

---
 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
drivers/input/misc/Kconfig +11 -0
index 362e8a01980c..9e297ebdea57 100644
@@ -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
drivers/input/misc/Makefile +1 -1
index a48e5f2d859d..7f854c6ecefa 100644
@@ -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
-
drivers/input/misc/atc260x-onkey.c new file +304 -0

304 lines not on this page · raw message

Signature · 1 line
2.28.0
author maintainer
#22 lore raw
In reply to Cristian Ciocaltea

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

Quoted 72 lines · Cristian Ciocaltea

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/[email protected]/

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/[email protected]/

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/[email protected]/

* 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
Signature · 1 line
2.28.0
#6 lore raw

Re: [PATCH v2 2/6] mfd: Add MFD driver for ATC260x PMICs

In reply to Cristian Ciocaltea
Thank you for the patch! Yet something to improve:

Hi Cristian,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on lee-mfd/for-mfd-next]
[also build test ERROR on regulator/for-next v5.9-rc1 next-20200821] [cannot apply to input/next power-supply/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Cristian-Ciocaltea/Add-initial-support-for-ATC260x-PMICs/20200822-062126
base:   https://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git for-mfd-next
config: sh-allmodconfig (attached as .config)
compiler: sh4-linux-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=sh

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>, old ones prefixed by <<):

WARNING: modpost: missing MODULE_LICENSE() in drivers/mfd/atc260x-core.o

>> FATAL: modpost: drivers/mfd/atc260x-i2c: sizeof(struct i2c_device_id)=24 is not a modulo of the size of section __mod_i2c__<identifier>_device_table=588.
>> Fix definition of struct i2c_device_id in mod_devicetable.h

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

#23 lore raw
In reply to Cristian Ciocaltea

Hi Cristi,

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

Quoted 19 lines · Cristian Ciocaltea

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

Quoted 40 lines

Kind regards,
Cristi

Quoted 36 lines · Cristian Ciocaltea

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/[email protected]/

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/[email protected]/

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/[email protected]/

* 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.

Quoted 3 lines
Quoted 3 lines

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

Quoted 33 lines
Quoted 33 lines
 .../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
Signature · 1 line
2.28.0
author maintainer
#24 lore raw

Hi Mani,

Quoted 61 lines · Manivannan Sadhasivam

Hi Cristi,

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

Quoted 55 lines · Cristian Ciocaltea

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

Quoted 32 lines · Cristian Ciocaltea

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/[email protected]/

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/[email protected]/

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/[email protected]/

* 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

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

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

Quoted 42 lines
Quoted 3 lines
Quoted 3 lines

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

Quoted 33 lines
Quoted 33 lines
 .../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
Signature · 1 line
2.28.0
maintainer
#10 lore raw

Re: [PATCH v2 3/6] regulator: Add regulator driver for ATC260x PMICs

In reply to Cristian Ciocaltea

drivers/regulator/atc260x-regulator.c line 53

Quoted 10 lines · Cristian Ciocaltea
drivers/regulator/atc260x-regulator.c new file +10 -0
+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.

drivers/regulator/atc260x-regulator.c line 496

Quoted 6 lines
drivers/regulator/atc260x-regulator.c new file +6 -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);

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.

#14 lore raw

Re: [PATCH v2 4/6] power: reset: Add poweroff driver for ATC260x PMICs

In reply to Cristian Ciocaltea

Hi,

Quoted 309 lines · Cristian Ciocaltea

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.

---
 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
drivers/power/reset/Kconfig +7 -1
index 0a1fb5c74f83..df6c3676b892 100644
@@ -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
-
drivers/power/reset/Makefile +1 -0
index c51eceba9ea3..829df1157540 100644
@@ -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
drivers/power/reset/atc260x-poweroff.c new file +256 -0
new file mode 100644
index 000000000000..81a99e7e4a91
@@ -0,0 +1,274 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Poweroff & reset driver for Actions Semi ATC260x PMICs
+ *
+ * Copyright (c) 2020 Cristian Ciocaltea <[email protected]>
+ */
+
+#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" },

drivers/power/reset/atc260x-poweroff.c line 266

Quoted 10 lines
drivers/power/reset/atc260x-poweroff.c new file +10 -0
+	{ /* 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.

drivers/power/reset/atc260x-poweroff.c line 274

Quoted 8 lines
drivers/power/reset/atc260x-poweroff.c new file +8 -0
+	},
+};
+
+module_platform_driver(atc260x_pwrc_driver);
+
+MODULE_DESCRIPTION("Poweroff & reset driver for ATC260x PMICs");
+MODULE_AUTHOR("Cristian Ciocaltea <[email protected]>");
+MODULE_LICENSE("GPL");

Otherwise LGTM,

-- Sebastian

author maintainer
#11 lore raw

Re: [PATCH v2 3/6] regulator: Add regulator driver for ATC260x PMICs

In reply to Mark Brown

Hi Mark,

Thanks for reviewing!

Quoted 17 lines · Mark Brown

drivers/regulator/atc260x-regulator.c line 53

Quoted 10 lines · Cristian Ciocaltea
drivers/regulator/atc260x-regulator.c new file +10 -0
+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.

Quoted 11 lines

drivers/regulator/atc260x-regulator.c line 496

Quoted 6 lines
drivers/regulator/atc260x-regulator.c new file +6 -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);

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

author maintainer
#15 lore raw

Re: [PATCH v2 4/6] power: reset: Add poweroff driver for ATC260x PMICs

In reply to Sebastian Reichel

Hi Sebastian,

Thanks for the review!

Quoted 318 lines · Sebastian Reichel

Hi,

Quoted 315 lines · Cristian Ciocaltea

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.

---
 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
drivers/power/reset/Kconfig +7 -1
index 0a1fb5c74f83..df6c3676b892 100644
@@ -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
-
drivers/power/reset/Makefile +1 -0
index c51eceba9ea3..829df1157540 100644
@@ -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
drivers/power/reset/atc260x-poweroff.c new file +262 -0
new file mode 100644
index 000000000000..81a99e7e4a91
@@ -0,0 +1,274 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Poweroff & reset driver for Actions Semi ATC260x PMICs
+ *
+ * Copyright (c) 2020 Cristian Ciocaltea <[email protected]>
+ */
+
+#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,
Quoted 8 lines

drivers/power/reset/atc260x-poweroff.c line 266

Quoted 4 lines
drivers/power/reset/atc260x-poweroff.c new file +4 -0
+	.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.

Quoted 11 lines

drivers/power/reset/atc260x-poweroff.c line 274

Quoted 8 lines
drivers/power/reset/atc260x-poweroff.c new file +8 -0
+	},
+};
+
+module_platform_driver(atc260x_pwrc_driver);
+
+MODULE_DESCRIPTION("Poweroff & reset driver for ATC260x PMICs");
+MODULE_AUTHOR("Cristian Ciocaltea <[email protected]>");
+MODULE_LICENSE("GPL");

Otherwise LGTM,

Quoted 1 line

-- Sebastian

Regards,
Cristi

#25 lore raw
In reply to Cristian Ciocaltea
Quoted 88 lines · Cristian Ciocaltea

Hi Mani,

Quoted 3 lines · Manivannan Sadhasivam

Hi Cristi,

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

comment

Quoted 14 lines

below.

Quoted 11 lines · Cristian Ciocaltea

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

Quoted 4 lines
Quoted 4 lines

* 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)

Quoted 9 lines
Quoted 9 lines

- 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

Quoted 1 line · Cristian Ciocaltea

This is re-spin of the patch series submitted some time ago by

Mani,

Quoted 1 line
Quoted 1 line
Quoted 1 line

who added initial support (MFD core and regulators) for the

Actions

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Semi ATC260x PMICs:

https://lore.kernel.org/lkml/[email protected]/

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

The ATC260x family of PMICs integrates Audio Codec, Power

management,

Quoted 1 line
Quoted 1 line
Quoted 1 line

Clock generation and GPIO controller blocks. There are currently

3

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

variants: ATC2603A, ATC2603C and ATC2609A.

In addition to the ATC2609A regulator functionality provided that

time,

Quoted 1 line
Quoted 1 line
Quoted 1 line

this patchset adds support for the ATC2603C variant, together

with some

Quoted 1 line
Quoted 1 line
Quoted 1 line

new functionalities for both chips: power controller and onkey

input.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

The ATC2603A variant remains unsupported for the moment.

This has been tested on RoseapplePi, a SBC based on the Action

Semi S500

Quoted 1 line
Quoted 1 line
Quoted 1 line

SoC, which integrates ATC2603C PMIC. An initial support for this

board

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

has been already submitted:

https://lore.kernel.org/lkml/[email protected]/

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Please note that enabling the ATC260x PMICs on the compatible

Actions

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Semi Owl SoC based boards depends on the following:

* Actions Semi SIRQ driver (for PMIC DTS setup):

https://lore.kernel.org/lkml/[email protected]/

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

* I2C Atomic transfers in Actions Semi Owl driver (for proper

operation

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

of the power controller driver):

https://lore.kernel.org/lkml/b086ef6d355d9730c839359e15eb06175283e323.1596485741.git.cristian.ciocaltea@gmail.com/

Quoted 10 lines
Quoted 8 lines
Quoted 8 lines

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

Quoted 9 lines

signed-off-by

Quoted 1 line

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

Quoted 47 lines

Thanks,
Cristi

Quoted 4 lines
Quoted 3 lines
Quoted 3 lines

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

Quoted 21 lines

I think this one too.

Thanks,
Mani

Quoted 16 lines
Quoted 16 lines
 .../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

++++++++++++++++++

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
 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

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
 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
Signature · 1 line
2.28.0
Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse my brevity.
maintainer
#12 lore raw

Re: [PATCH v2 3/6] regulator: Add regulator driver for ATC260x PMICs

In reply to Cristian Ciocaltea
Quoted 10 lines · Cristian Ciocaltea
Quoted 4 lines · Mark Brown

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.

maintainer
#2 lore raw

Re: [PATCH v2 1/6] dt-bindings: mfd: Add Actions Semi ATC260x PMIC binding

In reply to Cristian Ciocaltea
Quoted 41 lines · Cristian Ciocaltea

Add devicetree binding for Actions Semi ATC260x PMICs.

---
 .../bindings/mfd/actions,atc260x.yaml         | 221 ++++++++++++++++++
 1 file changed, 221 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/actions,atc260x.yaml
Documentation/devicetree/bindings/mfd/actions,atc260x.yaml new file +27 -0
new file mode 100644
index 000000000000..4a55bbe1306e
@@ -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 <[email protected]>
+  - Cristian Ciocaltea <[email protected]>
+
+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:

Documentation/devicetree/bindings/mfd/actions,atc260x.yaml line 37

Quoted 10 lines
Documentation/devicetree/bindings/mfd/actions,atc260x.yaml new file +10 -0
+    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.

Quoted 21 lines
Documentation/devicetree/bindings/mfd/actions,atc260x.yaml new file +21 -0
+
+    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:

Documentation/devicetree/bindings/mfd/actions,atc260x.yaml line 68

Quoted 10 lines
Documentation/devicetree/bindings/mfd/actions,atc260x.yaml new file +10 -0
+        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.

Quoted 156 lines
Documentation/devicetree/bindings/mfd/actions,atc260x.yaml new file +153 -0
+
+    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;
+          };
+        };
+      };
+    };
+
+...
Signature · 1 line
2.28.0
author maintainer
#3 lore raw

Re: [PATCH v2 1/6] dt-bindings: mfd: Add Actions Semi ATC260x PMIC binding

Hi Rob,

Thanks for reviewing!

Quoted 47 lines · Rob Herring
Quoted 46 lines · Cristian Ciocaltea

Add devicetree binding for Actions Semi ATC260x PMICs.

---
 .../bindings/mfd/actions,atc260x.yaml         | 221 ++++++++++++++++++
 1 file changed, 221 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/actions,atc260x.yaml
Documentation/devicetree/bindings/mfd/actions,atc260x.yaml new file +32 -0
new file mode 100644
index 000000000000..4a55bbe1306e
@@ -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 <[email protected]>
+  - Cristian Ciocaltea <[email protected]>
+
+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
+
Quoted 8 lines

Documentation/devicetree/bindings/mfd/actions,atc260x.yaml line 37

Quoted 5 lines
Documentation/devicetree/bindings/mfd/actions,atc260x.yaml new file +5 -0
+  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.

Quoted 26 lines
Quoted 26 lines
Documentation/devicetree/bindings/mfd/actions,atc260x.yaml new file +26 -0
+
+    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:
Quoted 8 lines

Documentation/devicetree/bindings/mfd/actions,atc260x.yaml line 68

Quoted 5 lines
Documentation/devicetree/bindings/mfd/actions,atc260x.yaml new file +5 -0
+        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)?

Quoted 1 line

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?

Quoted 148 lines
Quoted 148 lines
Documentation/devicetree/bindings/mfd/actions,atc260x.yaml new file +148 -0
+
+    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;
+          };
Quoted 8 lines
Quoted 8 lines
Documentation/devicetree/bindings/mfd/actions,atc260x.yaml new file +5 -0
+        };
+      };
+    };
+
+...
Signature · 1 line
2.28.0

Kind regards,
Cristi

maintainer
#4 lore raw

Re: [PATCH v2 1/6] dt-bindings: mfd: Add Actions Semi ATC260x PMIC binding

Quoted 62 lines · Cristian Ciocaltea

Hi Rob,

Thanks for reviewing!

Quoted 47 lines · Rob Herring
Quoted 46 lines · Cristian Ciocaltea

Add devicetree binding for Actions Semi ATC260x PMICs.

---
 .../bindings/mfd/actions,atc260x.yaml         | 221 ++++++++++++++++++
 1 file changed, 221 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/actions,atc260x.yaml
Documentation/devicetree/bindings/mfd/actions,atc260x.yaml new file +32 -0
new file mode 100644
index 000000000000..4a55bbe1306e
@@ -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 <[email protected]>
+  - Cristian Ciocaltea <[email protected]>
+
+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
+
Quoted 8 lines

Documentation/devicetree/bindings/mfd/actions,atc260x.yaml line 37

Quoted 5 lines
Documentation/devicetree/bindings/mfd/actions,atc260x.yaml new file +5 -0
+  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.

Quoted 3 lines

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.

Quoted 36 lines
Quoted 27 lines
Quoted 27 lines
Documentation/devicetree/bindings/mfd/actions,atc260x.yaml new file +26 -0
+
+    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:
Quoted 8 lines

Documentation/devicetree/bindings/mfd/actions,atc260x.yaml line 68

Quoted 5 lines
Documentation/devicetree/bindings/mfd/actions,atc260x.yaml new file +5 -0
+        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.

Quoted 3 lines

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.

Quoted 2 lines

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.

Quoted 4 lines
Quoted 1 line

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.

Quoted 2 lines

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

maintainer
#17 lore raw

Re: [PATCH v2 5/6] input: atc260x: Add onkey driver for ATC260x PMICs

In reply to Cristian Ciocaltea

Hi Cristian,

Quoted 232 lines · Cristian Ciocaltea

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.

---
 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
drivers/input/misc/Kconfig +11 -0
index 362e8a01980c..9e297ebdea57 100644
@@ -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
drivers/input/misc/Makefile +1 -1
index a48e5f2d859d..7f854c6ecefa 100644
@@ -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
-
drivers/input/misc/atc260x-onkey.c new file +172 -0
new file mode 100644
index 000000000000..7caec7d6f9ac
@@ -0,0 +1,304 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Onkey driver for Actions Semi ATC260x PMICs.
+ *
+ * Copyright (c) 2020 Cristian Ciocaltea <[email protected]>
+ */
+
+#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)

drivers/input/misc/atc260x-onkey.c line 182

Quoted 10 lines
drivers/input/misc/atc260x-onkey.c new file +10 -0
+{
+	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?

drivers/input/misc/atc260x-onkey.c line 189

Quoted 7 lines
drivers/input/misc/atc260x-onkey.c new file +7 -0
+
+	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.

Quoted 39 lines
drivers/input/misc/atc260x-onkey.c new file +39 -0
+	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) {

drivers/input/misc/atc260x-onkey.c line 238

Quoted 10 lines
drivers/input/misc/atc260x-onkey.c new file +10 -0
+		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.

drivers/input/misc/atc260x-onkey.c line 249

Quoted 11 lines
drivers/input/misc/atc260x-onkey.c new file +11 -0
+	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?

Quoted 20 lines
drivers/input/misc/atc260x-onkey.c new file +20 -0
+					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);

drivers/input/misc/atc260x-onkey.c line 279

Quoted 10 lines
drivers/input/misc/atc260x-onkey.c new file +10 -0
+	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.

Quoted 28 lines
drivers/input/misc/atc260x-onkey.c new file +25 -0
+
+	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 <[email protected]>");
+MODULE_LICENSE("GPL");
Signature · 1 line
2.28.0

Thanks.

Signature · 1 line
Dmitry
author maintainer
#18 lore raw

Re: [PATCH v2 5/6] input: atc260x: Add onkey driver for ATC260x PMICs

Hi Dmitry,

Thanks for the review!

Quoted 239 lines · Dmitry Torokhov

Hi Cristian,

Quoted 236 lines · Cristian Ciocaltea

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.

---
 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
drivers/input/misc/Kconfig +11 -0
index 362e8a01980c..9e297ebdea57 100644
@@ -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
drivers/input/misc/Makefile +1 -1
index a48e5f2d859d..7f854c6ecefa 100644
@@ -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
-
drivers/input/misc/atc260x-onkey.c new file +176 -0
new file mode 100644
index 000000000000..7caec7d6f9ac
@@ -0,0 +1,304 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Onkey driver for Actions Semi ATC260x PMICs.
+ *
+ * Copyright (c) 2020 Cristian Ciocaltea <[email protected]>
+ */
+
+#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;
Quoted 8 lines

drivers/input/misc/atc260x-onkey.c line 182

Quoted 6 lines
drivers/input/misc/atc260x-onkey.c new file +6 -0
+	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?

Quoted 9 lines

drivers/input/misc/atc260x-onkey.c line 189

Quoted 7 lines
drivers/input/misc/atc260x-onkey.c new file +7 -0
+
+	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;
	}
Quoted 43 lines
Quoted 43 lines
drivers/input/misc/atc260x-onkey.c new file +43 -0
+	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;
+	}
+
Quoted 8 lines

drivers/input/misc/atc260x-onkey.c line 238

Quoted 6 lines
drivers/input/misc/atc260x-onkey.c new file +6 -0
+	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.

Quoted 6 lines
Quoted 6 lines
drivers/input/misc/atc260x-onkey.c new file +6 -0
+	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)
Quoted 8 lines

drivers/input/misc/atc260x-onkey.c line 249

Quoted 5 lines
drivers/input/misc/atc260x-onkey.c new file +5 -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.

Quoted 34 lines
Quoted 20 lines
drivers/input/misc/atc260x-onkey.c new file +20 -0
+					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);

drivers/input/misc/atc260x-onkey.c line 279

Quoted 10 lines
drivers/input/misc/atc260x-onkey.c new file +10 -0
+	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.

Quoted 2 lines

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?

Quoted 22 lines
Quoted 22 lines
drivers/input/misc/atc260x-onkey.c new file +22 -0
+
+	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);
+
Quoted 11 lines
Quoted 6 lines
drivers/input/misc/atc260x-onkey.c new file +3 -0
+MODULE_DESCRIPTION("Onkey driver for ATC260x PMICs");
+MODULE_AUTHOR("Cristian Ciocaltea <[email protected]>");
+MODULE_LICENSE("GPL");
Signature · 1 line
2.28.0

Thanks.

Signature · 1 line
Dmitry

Kind regards,
Cristi

#7 lore raw

Re: [PATCH v2 2/6] mfd: Add MFD driver for ATC260x PMICs

In reply to kernel test robot
Quoted 26 lines · kernel test robot

Hi Cristian,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on lee-mfd/for-mfd-next]
[also build test ERROR on regulator/for-next v5.9-rc1 next-20200821] [cannot apply to input/next power-supply/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Cristian-Ciocaltea/Add-initial-support-for-ATC260x-PMICs/20200822-062126
base:   https://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git for-mfd-next
config: sh-allmodconfig (attached as .config)
compiler: sh4-linux-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=sh

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>, old ones prefixed by <<):

Quoted 7 lines

WARNING: modpost: missing MODULE_LICENSE() in drivers/mfd/atc260x-core.o

Quoted 2 lines
Quoted 2 lines

FATAL: modpost: drivers/mfd/atc260x-i2c: sizeof(struct i2c_device_id)=24 is not a modulo of the size of section __mod_i2c__<identifier>_device_table=588. Fix definition of struct i2c_device_id in mod_devicetable.h

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

Is this something you plan to fix?

Signature · 4 lines
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog
maintainer
#19 lore raw

Re: [PATCH v2 5/6] input: atc260x: Add onkey driver for ATC260x PMICs

In reply to Cristian Ciocaltea

Hi Cristian,

Quoted 253 lines · Cristian Ciocaltea

Hi Dmitry,

Thanks for the review!

Quoted 239 lines · Dmitry Torokhov

Hi Cristian,

Quoted 236 lines · Cristian Ciocaltea

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.

---
 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
drivers/input/misc/Kconfig +11 -0
index 362e8a01980c..9e297ebdea57 100644
@@ -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
drivers/input/misc/Makefile +1 -1
index a48e5f2d859d..7f854c6ecefa 100644
@@ -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
-
drivers/input/misc/atc260x-onkey.c new file +176 -0
new file mode 100644
index 000000000000..7caec7d6f9ac
@@ -0,0 +1,304 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Onkey driver for Actions Semi ATC260x PMICs.
+ *
+ * Copyright (c) 2020 Cristian Ciocaltea <[email protected]>
+ */
+
+#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;
Quoted 8 lines

drivers/input/misc/atc260x-onkey.c line 182

Quoted 6 lines
drivers/input/misc/atc260x-onkey.c new file +6 -0
+	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?

Quoted 5 lines

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.

Quoted 11 lines
Quoted 10 lines

drivers/input/misc/atc260x-onkey.c line 189

Quoted 8 lines
drivers/input/misc/atc260x-onkey.c new file +7 -0
+
+	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.

Quoted 6 lines

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;
	}
Quoted 14 lines
Quoted 14 lines
Quoted 4 lines
drivers/input/misc/atc260x-onkey.c new file +3 -0
+	if (ret) {
+		reset_status = KEY_RESET_HW_DEFAULT;
+	} else if (val) {

drivers/input/misc/atc260x-onkey.c line 202

Quoted 10 lines
drivers/input/misc/atc260x-onkey.c new file +10 -0
+		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();

Quoted 92 lines
Quoted 30 lines
Quoted 30 lines
drivers/input/misc/atc260x-onkey.c new file +30 -0
+	}
+
+	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;
+	}
+
Quoted 8 lines

drivers/input/misc/atc260x-onkey.c line 238

Quoted 6 lines
drivers/input/misc/atc260x-onkey.c new file +6 -0
+	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.

Quoted 6 lines
Quoted 6 lines
drivers/input/misc/atc260x-onkey.c new file +6 -0
+	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)
Quoted 8 lines

drivers/input/misc/atc260x-onkey.c line 249

Quoted 5 lines
drivers/input/misc/atc260x-onkey.c new file +5 -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.

Quoted 34 lines
Quoted 20 lines
drivers/input/misc/atc260x-onkey.c new file +20 -0
+					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);

drivers/input/misc/atc260x-onkey.c line 279

Quoted 10 lines
drivers/input/misc/atc260x-onkey.c new file +10 -0
+	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.

Quoted 8 lines
Quoted 2 lines

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.

Signature · 1 line
Dmitry
author maintainer
#8 lore raw

Re: [PATCH v2 2/6] mfd: Add MFD driver for ATC260x PMICs

In reply to Lee Jones

Hi Lee,

Quoted 29 lines · Lee Jones
Quoted 27 lines · kernel test robot

Hi Cristian,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on lee-mfd/for-mfd-next]
[also build test ERROR on regulator/for-next v5.9-rc1 next-20200821] [cannot apply to input/next power-supply/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Cristian-Ciocaltea/Add-initial-support-for-ATC260x-PMICs/20200822-062126
base:   https://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git for-mfd-next
config: sh-allmodconfig (attached as .config)
compiler: sh4-linux-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=sh

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>, old ones prefixed by <<):

WARNING: modpost: missing MODULE_LICENSE() in drivers/mfd/atc260x-core.o

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

FATAL: modpost: drivers/mfd/atc260x-i2c: sizeof(struct i2c_device_id)=24 is not a modulo of the size of section __mod_i2c__<identifier>_device_table=588. Fix definition of struct i2c_device_id in mod_devicetable.h

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]

Is this something you plan to fix?

Yes, I was just waiting to get some initial feedback for the drivers code before submitting a new revision. Except for the MFD core, I think this is almost completed.

Quoted 5 lines
Signature · 4 lines
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog

Kind regards,
Cristi

author maintainer
#20 lore raw

Re: [PATCH v2 5/6] input: atc260x: Add onkey driver for ATC260x PMICs

In reply to Dmitry Torokhov

Hi Dmitry,

Quoted 256 lines · Dmitry Torokhov

Hi Cristian,

Quoted 253 lines · Cristian Ciocaltea

Hi Dmitry,

Thanks for the review!

Quoted 247 lines · Dmitry Torokhov

Hi Cristian,

Quoted 232 lines · Cristian Ciocaltea

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.

---
 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
drivers/input/misc/Kconfig +11 -0
index 362e8a01980c..9e297ebdea57 100644
@@ -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
drivers/input/misc/Makefile +1 -1
index a48e5f2d859d..7f854c6ecefa 100644
@@ -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
-
drivers/input/misc/atc260x-onkey.c new file +172 -0
new file mode 100644
index 000000000000..7caec7d6f9ac
@@ -0,0 +1,304 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Onkey driver for Actions Semi ATC260x PMICs.
+ *
+ * Copyright (c) 2020 Cristian Ciocaltea <[email protected]>
+ */
+
+#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)

drivers/input/misc/atc260x-onkey.c line 182

Quoted 10 lines
drivers/input/misc/atc260x-onkey.c new file +10 -0
+{
+	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?

Quoted 8 lines
Quoted 5 lines

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.

Quoted 19 lines
Quoted 11 lines
Quoted 10 lines

drivers/input/misc/atc260x-onkey.c line 189

Quoted 8 lines
drivers/input/misc/atc260x-onkey.c new file +7 -0
+
+	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.

Quoted 6 lines

Would something like bellow suffice?

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

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.

Quoted 16 lines
Quoted 14 lines
Quoted 14 lines
Quoted 4 lines
drivers/input/misc/atc260x-onkey.c new file +3 -0
+	if (ret) {
+		reset_status = KEY_RESET_HW_DEFAULT;
+	} else if (val) {

drivers/input/misc/atc260x-onkey.c line 202

Quoted 10 lines
drivers/input/misc/atc260x-onkey.c new file +10 -0
+		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.

Quoted 95 lines
Quoted 95 lines
Quoted 30 lines
Quoted 30 lines
drivers/input/misc/atc260x-onkey.c new file +30 -0
+	}
+
+	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;
+	}
+
Quoted 8 lines

drivers/input/misc/atc260x-onkey.c line 238

Quoted 6 lines
drivers/input/misc/atc260x-onkey.c new file +6 -0
+	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.

Quoted 6 lines
Quoted 6 lines
drivers/input/misc/atc260x-onkey.c new file +6 -0
+	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)
Quoted 8 lines

drivers/input/misc/atc260x-onkey.c line 249

Quoted 5 lines
drivers/input/misc/atc260x-onkey.c new file +5 -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.

Quoted 36 lines
Quoted 20 lines
drivers/input/misc/atc260x-onkey.c new file +20 -0
+					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);

drivers/input/misc/atc260x-onkey.c line 279

Quoted 10 lines
drivers/input/misc/atc260x-onkey.c new file +10 -0
+	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.

Quoted 7 lines
Quoted 5 lines

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.

Quoted 2 lines

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!

Quoted 4 lines

Thanks.

Signature · 1 line
Dmitry

Kind regards,
Cristi