Skip to contentSkip to conversation

mfd: Add support for Asus Transformer embedded controller

PATCH Superseded Svyatoslav Ryhel 3 participants 30 messages Feb 9 – Mar 9

Subsystems (7)

v2 of 13 Superseded Latest is v13 →

lore
Share & tools
lore
#0 lore raw

v2 cover mfd: Add support for Asus Transformer embedded controller

Add support for embedded controller used in Asus Transformers for managing power and input functions.

---
Changes in v2:
- converted sysfs debug exports into debugfs
- added kernel-doc comments for exposed functions
- fixed minor typos and inconsistencies
---

Michał Mirosław (7):
misc: Support Asus Transformer's EC access device
mfd: Add driver for Asus Transformer embedded controller
input: serio: Add driver for Asus Transformer dock keyboard and
touchpad
input: keyboard: Add driver for Asus Transformer dock multimedia keys
leds: Add driver for Asus Transformer LEDs
power: supply: Add driver for Asus Transformer battery
power: supply: Add charger driver for Asus Transformers

Svyatoslav Ryhel (2):
dt-bindings: misc: document ASUS Transformers EC DockRAM
dt-bindings: mfd: document ASUS Transformer EC

 .../devicetree/bindings/mfd/asus,ec.yaml      | 152 ++++++
 .../bindings/misc/asus,dockram.yaml           |  40 ++
 drivers/input/keyboard/Kconfig                |  10 +
 drivers/input/keyboard/Makefile               |   1 +
 drivers/input/keyboard/asus-ec-keys.c         | 285 +++++++++++
 drivers/input/serio/Kconfig                   |  15 +
 drivers/input/serio/Makefile                  |   1 +
 drivers/input/serio/asus-ec-kbc.c             | 160 ++++++
 drivers/leds/Kconfig                          |  11 +
 drivers/leds/Makefile                         |   1 +
 drivers/leds/leds-asus-ec.c                   | 104 ++++
 drivers/mfd/Kconfig                           |  15 +
 drivers/mfd/Makefile                          |   1 +
 drivers/mfd/asus-ec.c                         | 467 ++++++++++++++++++
 drivers/misc/Kconfig                          |   9 +
 drivers/misc/Makefile                         |   1 +
 drivers/misc/asus-dockram.c                   | 370 ++++++++++++++
 drivers/power/supply/Kconfig                  |  22 +
 drivers/power/supply/Makefile                 |   2 +
 drivers/power/supply/asus-ec-battery.c        | 283 +++++++++++
 drivers/power/supply/asus-ec-charger.c        | 206 ++++++++
 include/linux/mfd/asus-ec.h                   | 162 ++++++
 22 files changed, 2318 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/asus,ec.yaml
 create mode 100644 Documentation/devicetree/bindings/misc/asus,dockram.yaml
 create mode 100644 drivers/input/keyboard/asus-ec-keys.c
 create mode 100644 drivers/input/serio/asus-ec-kbc.c
 create mode 100644 drivers/leds/leds-asus-ec.c
 create mode 100644 drivers/mfd/asus-ec.c
 create mode 100644 drivers/misc/asus-dockram.c
 create mode 100644 drivers/power/supply/asus-ec-battery.c
 create mode 100644 drivers/power/supply/asus-ec-charger.c
 create mode 100644 include/linux/mfd/asus-ec.h
Signature · 1 line
2.51.0
#1 lore raw

PATCH v2 1/9 dt-bindings: misc: document ASUS Transformers EC DockRAM

Documenting an I2C device used in conjunction with the EC on ASUS Transformers. The main function of DockRAM (the name used by downstream ASUS sources) is to provide power-related functions, such as battery and charger communication. The device is exposed as an individual entity because multiple embedded controllers can utilize the same DockRAM instance.

---
 .../bindings/misc/asus,dockram.yaml           | 40 +++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/misc/asus,dockram.yaml
Documentation/devicetree/bindings/misc/asus,dockram.yaml new file +40 -0
new file mode 100644
index 000000000000..0cfde619ba01
@@ -0,0 +1,40 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/misc/asus,dockram.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Asus Transformer EC DockRAM
+
+maintainers:
+  - Svyatoslav Ryhel <[email protected]>
+
+description:
+  Dedicated i2c device used to provide power related functions of the
+  embedded controller used in ASUS Transformer device family.
+
+properties:
+  compatible:
+    const: asus,dockram
+
+  reg:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      dockram@17 {
+        compatible = "asus,dockram";
+        reg = <0x17>;
+      };
+    };
+...
Signature · 1 line
2.51.0
#2 lore raw

Re: [PATCH v2 1/9] dt-bindings: misc: document ASUS Transformers EC DockRAM

Documentation/devicetree/bindings/misc/asus,dockram.yaml

Quoted 18 lines · Svyatoslav Ryhel

Documenting an I2C device used in conjunction with the EC on ASUS Transformers. The main function of DockRAM (the name used by downstream ASUS sources) is to provide power-related functions, such as battery and charger communication. The device is exposed as an individual entity because multiple embedded controllers can utilize the same DockRAM instance.

---
 .../bindings/misc/asus,dockram.yaml           | 40 +++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/misc/asus,dockram.yaml
Documentation/devicetree/bindings/misc/asus,dockram.yaml new file +0 -0
new file mode 100644
index 000000000000..0cfde619ba01

Not a misc device. Find appropriate place, e.g. for EC or docking or laptop devices or power-related.

Quoted 9 lines
Documentation/devicetree/bindings/misc/asus,dockram.yaml new file +8 -0
@@ -0,0 +1,40 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/misc/asus,dockram.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Asus Transformer EC DockRAM
+

Documentation/devicetree/bindings/misc/asus,dockram.yaml line 18

Quoted 10 lines
Documentation/devicetree/bindings/misc/asus,dockram.yaml new file +10 -0
+maintainers:
+  - Svyatoslav Ryhel <[email protected]>
+
+description:
+  Dedicated i2c device used to provide power related functions of the
+  embedded controller used in ASUS Transformer device family.
+
+properties:
+  compatible:
+    const: asus,dockram

Way too generic compatible. You are not documenting here all ASUS laptops/devices dockram. For example this implies dockram is also on ASUS Vivobook... or on any other asus device.

Documentation/devicetree/bindings/misc/asus,dockram.yaml line 26

Quoted 8 lines
Documentation/devicetree/bindings/misc/asus,dockram.yaml new file +8 -0
+
+  reg:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+

Device looks weirdly empty. Probably you have it only to instantiate I2C handle, so what you really wanted is i2c-parent. This is not a real device.

Best regards,
Krzysztof

#3 lore raw

Re: [PATCH v2 1/9] dt-bindings: misc: document ASUS Transformers EC DockRAM

вт, 10 лют. 2026 р. о 11:25 Krzysztof Kozlowski <[email protected]> пише:

Quoted 15 lines · Svyatoslav Ryhel
Quoted 13 lines

Documenting an I2C device used in conjunction with the EC on ASUS Transformers. The main function of DockRAM (the name used by downstream ASUS sources) is to provide power-related functions, such as battery and charger communication. The device is exposed as an individual entity because multiple embedded controllers can utilize the same DockRAM instance.

---
 .../bindings/misc/asus,dockram.yaml           | 40 +++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/misc/asus,dockram.yaml
Quoted 9 lines

Documentation/devicetree/bindings/misc/asus,dockram.yaml

Quoted 5 lines
Documentation/devicetree/bindings/misc/asus,dockram.yaml new file +0 -0
new file mode 100644
index 000000000000..0cfde619ba01

Not a misc device. Find appropriate place, e.g. for EC or docking or laptop devices or power-related.

Why not misc? be more specific pls where you want it to be.

Quoted 15 lines
Quoted 15 lines
Documentation/devicetree/bindings/misc/asus,dockram.yaml new file +14 -0
@@ -0,0 +1,40 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/misc/asus,dockram.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Asus Transformer EC DockRAM
+
+maintainers:
+  - Svyatoslav Ryhel <[email protected]>
+
+description:
+  Dedicated i2c device used to provide power related functions of the
+  embedded controller used in ASUS Transformer device family.
Quoted 9 lines

Documentation/devicetree/bindings/misc/asus,dockram.yaml line 18

Quoted 4 lines
Documentation/devicetree/bindings/misc/asus,dockram.yaml new file +4 -0
+
+properties:
+  compatible:
+    const: asus,dockram

Way too generic compatible. You are not documenting here all ASUS laptops/devices dockram. For example this implies dockram is also on ASUS Vivobook... or on any other asus device.

Asus were not so generous to provide more specific data, they call this device dockram in their sources.

Quoted 4 lines
Quoted 4 lines
Documentation/devicetree/bindings/misc/asus,dockram.yaml new file +4 -0
+
+  reg:
+    maxItems: 1
+
Quoted 9 lines

Documentation/devicetree/bindings/misc/asus,dockram.yaml line 26

Quoted 4 lines
Documentation/devicetree/bindings/misc/asus,dockram.yaml new file +4 -0
+required:
+  - compatible
+  - reg
+

Device looks weirdly empty. Probably you have it only to instantiate I2C handle, so what you really wanted is i2c-parent. This is not a real device.

WDYM? it is a real physical i2c device located on a i2c bus and probed by i2c driver just fine. Maybe you will deny RTC being a real device like it was done for example for max77663 which now causes a massive issues since it can occupy different i2c addresses?

Quoted 3 lines

Best regards,
Krzysztof

#4 lore raw

Re: [PATCH v2 1/9] dt-bindings: misc: document ASUS Transformers EC DockRAM

Quoted 26 lines · Svyatoslav Ryhel

вт, 10 лют. 2026 р. о 11:25 Krzysztof Kozlowski <[email protected]> пише:

Quoted 15 lines · Svyatoslav Ryhel
Quoted 13 lines

Documenting an I2C device used in conjunction with the EC on ASUS Transformers. The main function of DockRAM (the name used by downstream ASUS sources) is to provide power-related functions, such as battery and charger communication. The device is exposed as an individual entity because multiple embedded controllers can utilize the same DockRAM instance.

---
 .../bindings/misc/asus,dockram.yaml           | 40 +++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/misc/asus,dockram.yaml
Quoted 9 lines

Documentation/devicetree/bindings/misc/asus,dockram.yaml

Quoted 5 lines
Documentation/devicetree/bindings/misc/asus,dockram.yaml new file +0 -0
new file mode 100644
index 000000000000..0cfde619ba01

Not a misc device. Find appropriate place, e.g. for EC or docking or laptop devices or power-related.

Quoted 1 line

Why not misc? be more specific pls where you want it to be.

Because there is no such device as "misc". Otherwise explain me what sort of device is "misc".

I already wrote where I want it to be placed. You keep bouncing questions pointlessly, even when given exact request.

Quoted 46 lines
Quoted 16 lines
Quoted 16 lines
Documentation/devicetree/bindings/misc/asus,dockram.yaml new file +14 -0
@@ -0,0 +1,40 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/misc/asus,dockram.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Asus Transformer EC DockRAM
+
+maintainers:
+  - Svyatoslav Ryhel <[email protected]>
+
+description:
+  Dedicated i2c device used to provide power related functions of the
+  embedded controller used in ASUS Transformer device family.
Quoted 9 lines

Documentation/devicetree/bindings/misc/asus,dockram.yaml line 18

Quoted 4 lines
Documentation/devicetree/bindings/misc/asus,dockram.yaml new file +4 -0
+
+properties:
+  compatible:
+    const: asus,dockram

Way too generic compatible. You are not documenting here all ASUS laptops/devices dockram. For example this implies dockram is also on ASUS Vivobook... or on any other asus device.

Asus were not so generous to provide more specific data, they call this device dockram in their sources.

Quoted 4 lines
Quoted 4 lines
Documentation/devicetree/bindings/misc/asus,dockram.yaml new file +4 -0
+
+  reg:
+    maxItems: 1
+
Quoted 9 lines

Documentation/devicetree/bindings/misc/asus,dockram.yaml line 26

Quoted 4 lines
Documentation/devicetree/bindings/misc/asus,dockram.yaml new file +4 -0
+required:
+  - compatible
+  - reg
+

Device looks weirdly empty. Probably you have it only to instantiate I2C handle, so what you really wanted is i2c-parent. This is not a real device.

Quoted 2 lines

WDYM? it is a real physical i2c device located on a i2c bus and probed by i2c driver just fine. Maybe you will deny RTC being a real device

Driver does not matter here.

Quoted 2 lines

like it was done for example for max77663 which now causes a massive issues since it can occupy different i2c addresses?

Then describe what is the device here. So far it looks exactly like "ec-dock" for which you already have a binding.

Best regards,
Krzysztof

#5 lore raw

Re: [PATCH v2 1/9] dt-bindings: misc: document ASUS Transformers EC DockRAM

вт, 10 лют. 2026 р. о 12:50 Krzysztof Kozlowski <[email protected]> пише:

Quoted 28 lines · Svyatoslav Ryhel
Quoted 26 lines

вт, 10 лют. 2026 р. о 11:25 Krzysztof Kozlowski <[email protected]> пише:

Quoted 24 lines · Svyatoslav Ryhel

Documentation/devicetree/bindings/misc/asus,dockram.yaml

Quoted 18 lines

Documenting an I2C device used in conjunction with the EC on ASUS Transformers. The main function of DockRAM (the name used by downstream ASUS sources) is to provide power-related functions, such as battery and charger communication. The device is exposed as an individual entity because multiple embedded controllers can utilize the same DockRAM instance.

---
 .../bindings/misc/asus,dockram.yaml           | 40 +++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/misc/asus,dockram.yaml
Documentation/devicetree/bindings/misc/asus,dockram.yaml new file +0 -0
new file mode 100644
index 000000000000..0cfde619ba01

Not a misc device. Find appropriate place, e.g. for EC or docking or laptop devices or power-related.

Quoted 8 lines
Quoted 1 line

Why not misc? be more specific pls where you want it to be.

Because there is no such device as "misc". Otherwise explain me what sort of device is "misc".

I already wrote where I want it to be placed. You keep bouncing questions pointlessly, even when given exact request.

Among your list only EC exists. There are no docking or laptop devices or power-related. Hence asking.

Quoted 47 lines
Quoted 47 lines
Quoted 17 lines
Quoted 17 lines
Documentation/devicetree/bindings/misc/asus,dockram.yaml new file +14 -0
@@ -0,0 +1,40 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/misc/asus,dockram.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Asus Transformer EC DockRAM
+
+maintainers:
+  - Svyatoslav Ryhel <[email protected]>
+
+description:
+  Dedicated i2c device used to provide power related functions of the
+  embedded controller used in ASUS Transformer device family.
Quoted 9 lines

Documentation/devicetree/bindings/misc/asus,dockram.yaml line 18

Quoted 4 lines
Documentation/devicetree/bindings/misc/asus,dockram.yaml new file +4 -0
+
+properties:
+  compatible:
+    const: asus,dockram

Way too generic compatible. You are not documenting here all ASUS laptops/devices dockram. For example this implies dockram is also on ASUS Vivobook... or on any other asus device.

Asus were not so generous to provide more specific data, they call this device dockram in their sources.

Quoted 13 lines

Documentation/devicetree/bindings/misc/asus,dockram.yaml line 26

Quoted 8 lines
Documentation/devicetree/bindings/misc/asus,dockram.yaml new file +8 -0
+
+  reg:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+

Device looks weirdly empty. Probably you have it only to instantiate I2C handle, so what you really wanted is i2c-parent. This is not a real device.

Quoted 5 lines
Quoted 2 lines

WDYM? it is a real physical i2c device located on a i2c bus and probed by i2c driver just fine. Maybe you will deny RTC being a real device

Driver does not matter here.

It seems that you see a "forbidden" word and tear it out of context.

Quoted 6 lines
Quoted 2 lines

like it was done for example for max77663 which now causes a massive issues since it can occupy different i2c addresses?

Then describe what is the device here. So far it looks exactly like "ec-dock" for which you already have a binding.

Wrong, it has nothing to do with "ec-dock" specifically. It is has a pretty discrete description. It used to provide power related functions of the embedded controller used in ASUS Transformer device family. To access to battery stats, charger status, leds control. Can be used by multiple controllers at once (like on TF701T or TF600T)

Quoted 2 lines

Best regards,
Krzysztof

#6 lore raw

PATCH v2 2/9 misc: Support Asus Transformer's EC access device

In reply to Svyatoslav Ryhel

From: Michał Mirosław <[email protected]>

Add support for accessing Embedded Controller of Asus Transformer devices. This will be used by the EC MFD drivers.

---
 drivers/misc/Kconfig        |   9 +
 drivers/misc/Makefile       |   1 +
 drivers/misc/asus-dockram.c | 370 ++++++++++++++++++++++++++++++++++++
 include/linux/mfd/asus-ec.h |  24 +++
 4 files changed, 404 insertions(+)
 create mode 100644 drivers/misc/asus-dockram.c
 create mode 100644 include/linux/mfd/asus-ec.h
drivers/misc/Kconfig +9 -0
index dd1ab7e445ac..e7faa7ab4199 100644
@@ -50,6 +50,15 @@ config AD525X_DPOT_SPI
 	  To compile this driver as a module, choose M here: the
 	  module will be called ad525x_dpot-spi.
 
+config ASUS_DOCKRAM
+	tristate "Asus Transformer's EC DockRAM"
+	depends on I2C
+	help
+	  Select this if you are building for Asus Transformer's.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called asus-dockram.
+
 config DUMMY_IRQ
 	tristate "Dummy IRQ handler"
 	help
drivers/misc/Makefile +1 -0
index bfad6982591c..d2287e912d59 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_IBMVMC)		+= ibmvmc.o
 obj-$(CONFIG_AD525X_DPOT)	+= ad525x_dpot.o
 obj-$(CONFIG_AD525X_DPOT_I2C)	+= ad525x_dpot-i2c.o
 obj-$(CONFIG_AD525X_DPOT_SPI)	+= ad525x_dpot-spi.o
+obj-$(CONFIG_ASUS_DOCKRAM)	+= asus-dockram.o
 obj-$(CONFIG_ATMEL_SSC)		+= atmel-ssc.o
 obj-$(CONFIG_DUMMY_IRQ)		+= dummy-irq.o
 obj-$(CONFIG_ICS932S401)	+= ics932s401.o
drivers/misc/asus-dockram.c new file +370 -0

370 lines not on this page · raw message

include/linux/mfd/asus-ec.h new file +24 -0
new file mode 100644
index 000000000000..6a36313b9ebd
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __MISC_ASUS_EC_H
+#define __MISC_ASUS_EC_H
+
+struct i2c_client;
+
+#define DOCKRAM_ENTRIES			0x100
+#define DOCKRAM_ENTRY_SIZE		32
+#define DOCKRAM_ENTRY_BUFSIZE		(DOCKRAM_ENTRY_SIZE + 1)
+
+/* control register [0x0A] layout */
+#define ASUSEC_CTL_SIZE			8
+
+#define ASUSEC_DOCKRAM_CONTROL		0x0a
+
+/* dockram comm */
+int asus_dockram_read(struct i2c_client *client, int reg, char *buf);
+int asus_dockram_write(struct i2c_client *client, int reg, const char *buf);
+int asus_dockram_access_ctl(struct i2c_client *client,
+			    u64 *out, u64 mask, u64 xor);
+struct i2c_client *devm_asus_dockram_get(struct device *parent);
+void asus_dockram_debugfs_init(struct i2c_client *client,
+			       struct dentry *debugfs_root);
+#endif /* __MISC_ASUS_EC_H */
Signature · 1 line
2.51.0
#7 lore raw

PATCH v2 3/9 dt-bindings: mfd: document ASUS Transformer EC

In reply to Svyatoslav Ryhel

Document embedded controller used in ASUS Transformer device series.

---
 .../devicetree/bindings/mfd/asus,ec.yaml      | 152 ++++++++++++++++++
 1 file changed, 152 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/asus,ec.yaml
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +152 -0
new file mode 100644
index 000000000000..1d1a62761b71
@@ -0,0 +1,152 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/asus,ec.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ASUS Transformer's Embedded Controller
+
+description:
+  Several Nuvoton based Embedded Controller attached to an I2C bus,
+  running a custom ASUS firmware, specific to the Asus Transformer
+  device series.
+
+maintainers:
+  - Svyatoslav Ryhel <[email protected]>
+
+properties:
+  compatible:
+    oneOf:
+      - enum:
+          - asus,ec-pad  # Pad part of Asus Transformer
+          - asus,ec-dock # Dock part of Asus Transformer
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  request-gpio:
+    maxItems: 1
+
+  asus,dockram:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description: I2C device used to access power related functions.
+
+  asus,clear-factory-mode:
+    type: boolean
+    description: clear Factory Mode bit in EC control register
+
+  battery:
+    type: object
+    $ref: /schemas/power/supply/power-supply.yaml
+    unevaluatedProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-battery
+
+    required:
+      - compatible
+
+  charger:
+    type: object
+    $ref: /schemas/power/supply/power-supply.yaml
+    additionalProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-charger
+
+      monitored-battery: true
+
+    required:
+      - compatible
+
+  keyboard-ext:
+    type: object
+    description: top row of multimedia keys
+    additionalProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-keys
+
+    required:
+      - compatible
+
+  led:
+    type: object
+    additionalProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-led
+
+    required:
+      - compatible
+
+  serio:
+    type: object
+    description: keyboard and touchpad
+    additionalProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-kbc
+
+    required:
+      - compatible
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - request-gpio
+  - asus,dockram
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      embedded-controller@19 {
+        compatible = "asus,ec-dock";
+        reg = <0x19>;
+
+        interrupt-parent = <&gpio>;
+        interrupts = <151 IRQ_TYPE_LEVEL_LOW>;
+
+        request-gpio = <&gpio 134 GPIO_ACTIVE_LOW>;
+        asus,dockram = <&dockram_ec>;
+
+        battery {
+          compatible = "asus,ec-battery";
+          monitored-battery = <&dock_battery>;
+        };
+
+        charger {
+          compatible = "asus,ec-charger";
+          monitored-battery = <&dock_battery>;
+        };
+
+        keyboard-ext {
+          compatible = "asus,ec-keys";
+        };
+
+        led {
+          compatible = "asus,ec-led";
+        };
+
+        serio {
+          compatible = "asus,ec-kbc";
+        };
+      };
+    };
+...
Signature · 1 line
2.51.0
#8 lore raw

Re: [PATCH v2 3/9] dt-bindings: mfd: document ASUS Transformer EC

Documentation/devicetree/bindings/mfd/asus,ec.yaml

Quoted 13 lines · Svyatoslav Ryhel

Document embedded controller used in ASUS Transformer device series.

---
 .../devicetree/bindings/mfd/asus,ec.yaml      | 152 ++++++++++++++++++
 1 file changed, 152 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/asus,ec.yaml
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +0 -0
new file mode 100644
index 000000000000..1d1a62761b71

EC do not go to MFD, but to dedicated directory (there is such).

Quoted 10 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +9 -0
@@ -0,0 +1,152 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/asus,ec.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ASUS Transformer's Embedded Controller
+
+description:

Documentation/devicetree/bindings/mfd/asus,ec.yaml line 19

Quoted 10 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +10 -0
+  Several Nuvoton based Embedded Controller attached to an I2C bus,
+  running a custom ASUS firmware, specific to the Asus Transformer
+  device series.
+
+maintainers:
+  - Svyatoslav Ryhel <[email protected]>
+
+properties:
+  compatible:
+    oneOf:

Drop oneOf

Documentation/devicetree/bindings/mfd/asus,ec.yaml line 22

Quoted 3 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +3 -0
+      - enum:
+          - asus,ec-pad  # Pad part of Asus Transformer
+          - asus,ec-dock # Dock part of Asus Transformer

Compatibles are way too generic. "ec" basically means you document all Asus EC, which is for sure not true. You need specific compatible for this specific model.

Missing blank line.

Documentation/devicetree/bindings/mfd/asus,ec.yaml line 29

Quoted 7 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +7 -0
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  request-gpio:

gpio is deprecated. gpios, look at any other binding.

Documentation/devicetree/bindings/mfd/asus,ec.yaml line 38

Quoted 9 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +9 -0
+    maxItems: 1
+
+  asus,dockram:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description: I2C device used to access power related functions.
+
+  asus,clear-factory-mode:
+    type: boolean
+    description: clear Factory Mode bit in EC control register

Why would this be a static/fixed property over lifecycle of all devices?

Quoted 41 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +41 -0
+
+  battery:
+    type: object
+    $ref: /schemas/power/supply/power-supply.yaml
+    unevaluatedProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-battery
+
+    required:
+      - compatible
+
+  charger:
+    type: object
+    $ref: /schemas/power/supply/power-supply.yaml
+    additionalProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-charger
+
+      monitored-battery: true
+
+    required:
+      - compatible
+
+  keyboard-ext:
+    type: object
+    description: top row of multimedia keys
+    additionalProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-keys
+
+    required:
+      - compatible
+
+  led:
+    type: object

Documentation/devicetree/bindings/mfd/asus,ec.yaml line 89

Quoted 10 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +10 -0
+    additionalProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-led
+
+    required:
+      - compatible
+
+  serio:

All of these children are pointless - no resources. Drop all of them, it's btw explicitly documented rule in writing bindings.

Best regards,
Krzysztof

#9 lore raw

Re: [PATCH v2 3/9] dt-bindings: mfd: document ASUS Transformer EC

вт, 10 лют. 2026 р. о 11:22 Krzysztof Kozlowski <[email protected]> пише:

Quoted 10 lines · Svyatoslav Ryhel
Quoted 8 lines

Document embedded controller used in ASUS Transformer device series.

---
 .../devicetree/bindings/mfd/asus,ec.yaml      | 152 ++++++++++++++++++
 1 file changed, 152 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/asus,ec.yaml
Quoted 8 lines

Documentation/devicetree/bindings/mfd/asus,ec.yaml

Quoted 5 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +0 -0
new file mode 100644
index 000000000000..1d1a62761b71

EC do not go to MFD, but to dedicated directory (there is such).

Noted

Quoted 14 lines
Quoted 14 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +13 -0
@@ -0,0 +1,152 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/asus,ec.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ASUS Transformer's Embedded Controller
+
+description:
+  Several Nuvoton based Embedded Controller attached to an I2C bus,
+  running a custom ASUS firmware, specific to the Asus Transformer
+  device series.
+
Quoted 9 lines

Documentation/devicetree/bindings/mfd/asus,ec.yaml line 19

Quoted 6 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +6 -0
+maintainers:
+  - Svyatoslav Ryhel <[email protected]>
+
+properties:
+  compatible:
+    oneOf:

Drop oneOf

Noted

Quoted 9 lines

Documentation/devicetree/bindings/mfd/asus,ec.yaml line 22

Quoted 3 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +3 -0
+      - enum:
+          - asus,ec-pad  # Pad part of Asus Transformer
+          - asus,ec-dock # Dock part of Asus Transformer

Compatibles are way too generic. "ec" basically means you document all Asus EC, which is for sure not true. You need specific compatible for this specific model.

Asus were not so generous to provide more specific data, they call there controllers asusdec and asusped in their sources.

Quoted 2 lines

Missing blank line.

noted

Quoted 10 lines

Documentation/devicetree/bindings/mfd/asus,ec.yaml line 29

Quoted 7 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +7 -0
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  request-gpio:

gpio is deprecated. gpios, look at any other binding.

noted

Quoted 12 lines

Documentation/devicetree/bindings/mfd/asus,ec.yaml line 38

Quoted 9 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +9 -0
+    maxItems: 1
+
+  asus,dockram:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description: I2C device used to access power related functions.
+
+  asus,clear-factory-mode:
+    type: boolean
+    description: clear Factory Mode bit in EC control register

Why would this be a static/fixed property over lifecycle of all devices?

Specify pls.

Quoted 46 lines
Quoted 46 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +46 -0
+
+  battery:
+    type: object
+    $ref: /schemas/power/supply/power-supply.yaml
+    unevaluatedProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-battery
+
+    required:
+      - compatible
+
+  charger:
+    type: object
+    $ref: /schemas/power/supply/power-supply.yaml
+    additionalProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-charger
+
+      monitored-battery: true
+
+    required:
+      - compatible
+
+  keyboard-ext:
+    type: object
+    description: top row of multimedia keys
+    additionalProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-keys
+
+    required:
+      - compatible
+
+  led:
+    type: object
+    additionalProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-led
Quoted 9 lines

Documentation/devicetree/bindings/mfd/asus,ec.yaml line 89

Quoted 5 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +5 -0
+
+    required:
+      - compatible
+
+  serio:

All of these children are pointless - no resources. Drop all of them, it's btw explicitly documented rule in writing bindings.

They are all needed to be able to disable them individually from the device tree if needed.

Quoted 3 lines

Best regards,
Krzysztof

#10 lore raw

Re: [PATCH v2 3/9] dt-bindings: mfd: document ASUS Transformer EC

Quoted 53 lines · Svyatoslav Ryhel

вт, 10 лют. 2026 р. о 11:22 Krzysztof Kozlowski <[email protected]> пише:

Quoted 10 lines · Svyatoslav Ryhel
Quoted 8 lines

Document embedded controller used in ASUS Transformer device series.

---
 .../devicetree/bindings/mfd/asus,ec.yaml      | 152 ++++++++++++++++++
 1 file changed, 152 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/asus,ec.yaml
Quoted 8 lines

Documentation/devicetree/bindings/mfd/asus,ec.yaml

Quoted 5 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +0 -0
new file mode 100644
index 000000000000..1d1a62761b71

EC do not go to MFD, but to dedicated directory (there is such).

Noted

Quoted 14 lines
Quoted 14 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +13 -0
@@ -0,0 +1,152 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/asus,ec.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ASUS Transformer's Embedded Controller
+
+description:
+  Several Nuvoton based Embedded Controller attached to an I2C bus,
+  running a custom ASUS firmware, specific to the Asus Transformer
+  device series.
+
Quoted 9 lines

Documentation/devicetree/bindings/mfd/asus,ec.yaml line 19

Quoted 6 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +6 -0
+maintainers:
+  - Svyatoslav Ryhel <[email protected]>
+
+properties:
+  compatible:
+    oneOf:

Drop oneOf

Noted

Quoted 5 lines
Quoted 3 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +3 -0
+      - enum:
+          - asus,ec-pad  # Pad part of Asus Transformer
+          - asus,ec-dock # Dock part of Asus Transformer
Quoted 7 lines
Quoted 4 lines

Compatibles are way too generic. "ec" basically means you document all Asus EC, which is for sure not true. You need specific compatible for this specific model.

Asus were not so generous to provide more specific data, they call there controllers asusdec and asusped in their sources.

Look how other ECs are called. Your device is not "", but e.g. "Transformer".

Quoted 32 lines
Quoted 3 lines

Missing blank line.

noted

Quoted 10 lines

Documentation/devicetree/bindings/mfd/asus,ec.yaml line 29

Quoted 7 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +7 -0
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  request-gpio:

gpio is deprecated. gpios, look at any other binding.

noted

Quoted 12 lines

Documentation/devicetree/bindings/mfd/asus,ec.yaml line 38

Quoted 9 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +9 -0
+    maxItems: 1
+
+  asus,dockram:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description: I2C device used to access power related functions.
+
+  asus,clear-factory-mode:
+    type: boolean
+    description: clear Factory Mode bit in EC control register

Why would this be a static/fixed property over lifecycle of all devices?

Quoted 1 line

Specify pls.

Provide rationale why we need to clear it every time, not once. Or any other rationale why we would accept that property.

Quoted 57 lines
Quoted 47 lines
Quoted 47 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +46 -0
+
+  battery:
+    type: object
+    $ref: /schemas/power/supply/power-supply.yaml
+    unevaluatedProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-battery
+
+    required:
+      - compatible
+
+  charger:
+    type: object
+    $ref: /schemas/power/supply/power-supply.yaml
+    additionalProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-charger
+
+      monitored-battery: true
+
+    required:
+      - compatible
+
+  keyboard-ext:
+    type: object
+    description: top row of multimedia keys
+    additionalProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-keys
+
+    required:
+      - compatible
+
+  led:
+    type: object
+    additionalProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-led
Quoted 9 lines

Documentation/devicetree/bindings/mfd/asus,ec.yaml line 89

Quoted 5 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +5 -0
+
+    required:
+      - compatible
+
+  serio:

All of these children are pointless - no resources. Drop all of them, it's btw explicitly documented rule in writing bindings.

Quoted 2 lines

They are all needed to be able to disable them individually from the device tree if needed.

They should not be disabled from DT, so they are not valid here. The given EC for given device is fixed/static. Does not change.

Best regards,
Krzysztof

#11 lore raw

Re: [PATCH v2 3/9] dt-bindings: mfd: document ASUS Transformer EC

вт, 10 лют. 2026 р. о 12:48 Krzysztof Kozlowski <[email protected]> пише:

Quoted 98 lines · Svyatoslav Ryhel
Quoted 53 lines

вт, 10 лют. 2026 р. о 11:22 Krzysztof Kozlowski <[email protected]> пише:

Quoted 10 lines · Svyatoslav Ryhel
Quoted 8 lines

Document embedded controller used in ASUS Transformer device series.

---
 .../devicetree/bindings/mfd/asus,ec.yaml      | 152 ++++++++++++++++++
 1 file changed, 152 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/asus,ec.yaml
Quoted 8 lines

Documentation/devicetree/bindings/mfd/asus,ec.yaml

Quoted 5 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +0 -0
new file mode 100644
index 000000000000..1d1a62761b71

EC do not go to MFD, but to dedicated directory (there is such).

Noted

Quoted 14 lines
Quoted 14 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +13 -0
@@ -0,0 +1,152 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/asus,ec.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ASUS Transformer's Embedded Controller
+
+description:
+  Several Nuvoton based Embedded Controller attached to an I2C bus,
+  running a custom ASUS firmware, specific to the Asus Transformer
+  device series.
+
Quoted 9 lines

Documentation/devicetree/bindings/mfd/asus,ec.yaml line 19

Quoted 6 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +6 -0
+maintainers:
+  - Svyatoslav Ryhel <[email protected]>
+
+properties:
+  compatible:
+    oneOf:

Drop oneOf

Noted

Quoted 5 lines
Quoted 3 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +3 -0
+      - enum:
+          - asus,ec-pad  # Pad part of Asus Transformer
+          - asus,ec-dock # Dock part of Asus Transformer
Quoted 7 lines
Quoted 4 lines

Compatibles are way too generic. "ec" basically means you document all Asus EC, which is for sure not true. You need specific compatible for this specific model.

Asus were not so generous to provide more specific data, they call there controllers asusdec and asusped in their sources.

Look how other ECs are called. Your device is not "", but e.g. "Transformer".

Quoted 32 lines
Quoted 3 lines

Missing blank line.

noted

Quoted 10 lines

Documentation/devicetree/bindings/mfd/asus,ec.yaml line 29

Quoted 7 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +7 -0
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  request-gpio:

gpio is deprecated. gpios, look at any other binding.

noted

Quoted 12 lines

Documentation/devicetree/bindings/mfd/asus,ec.yaml line 38

Quoted 9 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +9 -0
+    maxItems: 1
+
+  asus,dockram:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description: I2C device used to access power related functions.
+
+  asus,clear-factory-mode:
+    type: boolean
+    description: clear Factory Mode bit in EC control register

Why would this be a static/fixed property over lifecycle of all devices?

Quoted 5 lines
Quoted 1 line

Specify pls.

Provide rationale why we need to clear it every time, not once. Or any other rationale why we would accept that property.

Cause it is done by original Asus code and Asus did not provide schematic or any data apart from downstream source regarding this EC.

Quoted 57 lines
Quoted 57 lines
Quoted 56 lines
Quoted 42 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +41 -0
+
+  battery:
+    type: object
+    $ref: /schemas/power/supply/power-supply.yaml
+    unevaluatedProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-battery
+
+    required:
+      - compatible
+
+  charger:
+    type: object
+    $ref: /schemas/power/supply/power-supply.yaml
+    additionalProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-charger
+
+      monitored-battery: true
+
+    required:
+      - compatible
+
+  keyboard-ext:
+    type: object
+    description: top row of multimedia keys
+    additionalProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-keys
+
+    required:
+      - compatible
+
+  led:
+    type: object

Documentation/devicetree/bindings/mfd/asus,ec.yaml line 89

Quoted 10 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +10 -0
+    additionalProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-led
+
+    required:
+      - compatible
+
+  serio:

All of these children are pointless - no resources. Drop all of them, it's btw explicitly documented rule in writing bindings.

Quoted 6 lines
Quoted 2 lines

They are all needed to be able to disable them individually from the device tree if needed.

They should not be disabled from DT, so they are not valid here. The given EC for given device is fixed/static. Does not change.

Have you considered a possibility that function may be disabled/unrouted within the controller. By the vendor.

Quoted 3 lines

Best regards,
Krzysztof

#12 lore raw

Re: [PATCH v2 3/9] dt-bindings: mfd: document ASUS Transformer EC

Quoted 7 lines · Svyatoslav Ryhel
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

Documentation/devicetree/bindings/mfd/asus,ec.yaml line 38

Quoted 3 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +3 -0
+  asus,clear-factory-mode:
+    type: boolean
+    description: clear Factory Mode bit in EC control register

Why would this be a static/fixed property over lifecycle of all devices?

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Specify pls.

Provide rationale why we need to clear it every time, not once. Or any other rationale why we would accept that property.

Cause it is done by original Asus code and Asus did not provide schematic or any data apart from downstream source regarding this EC.

So that's a no. downstream code which is poor quality, not following DT rules at all, is never an argument for a DT property.

Quoted 61 lines
Quoted 61 lines
Quoted 60 lines
Quoted 48 lines
Quoted 48 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +46 -0
+
+  battery:
+    type: object
+    $ref: /schemas/power/supply/power-supply.yaml
+    unevaluatedProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-battery
+
+    required:
+      - compatible
+
+  charger:
+    type: object
+    $ref: /schemas/power/supply/power-supply.yaml
+    additionalProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-charger
+
+      monitored-battery: true
+
+    required:
+      - compatible
+
+  keyboard-ext:
+    type: object
+    description: top row of multimedia keys
+    additionalProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-keys
+
+    required:
+      - compatible
+
+  led:
+    type: object
+    additionalProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-led
Quoted 9 lines

Documentation/devicetree/bindings/mfd/asus,ec.yaml line 89

Quoted 5 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +5 -0
+
+    required:
+      - compatible
+
+  serio:

All of these children are pointless - no resources. Drop all of them, it's btw explicitly documented rule in writing bindings.

They are all needed to be able to disable them individually from the device tree if needed.

Quoted 6 lines
Quoted 3 lines

They should not be disabled from DT, so they are not valid here. The given EC for given device is fixed/static. Does not change.

Have you considered a possibility that function may be disabled/unrouted within the controller. By the vendor.

And then it is implied by the compatible, so no need for any of that. Otherwise, if it is not specific per device, then specifying it for DTS for all devices would make no sense.

Best regards,
Krzysztof

#13 lore raw

Re: [PATCH v2 3/9] dt-bindings: mfd: document ASUS Transformer EC

вт, 10 лют. 2026 р. о 13:04 Krzysztof Kozlowski <[email protected]> пише:

Quoted 15 lines · Svyatoslav Ryhel
Quoted 13 lines
Quoted 12 lines
Quoted 8 lines
Quoted 6 lines

Documentation/devicetree/bindings/mfd/asus,ec.yaml line 38

Quoted 3 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +3 -0
+  asus,clear-factory-mode:
+    type: boolean
+    description: clear Factory Mode bit in EC control register

Why would this be a static/fixed property over lifecycle of all devices?

Specify pls.

Provide rationale why we need to clear it every time, not once. Or any other rationale why we would accept that property.

Quoted 6 lines
Quoted 2 lines

Cause it is done by original Asus code and Asus did not provide schematic or any data apart from downstream source regarding this EC.

So that's a no. downstream code which is poor quality, not following DT rules at all, is never an argument for a DT property.

This property indicates that this controller on every reset restores factory bit hence it must be cleared. Bit is write only and cannot be detected. EC remains in factory mode which blocks its functions.

Quoted 65 lines
Quoted 65 lines
Quoted 64 lines
Quoted 58 lines
Quoted 48 lines
Quoted 48 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +46 -0
+
+  battery:
+    type: object
+    $ref: /schemas/power/supply/power-supply.yaml
+    unevaluatedProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-battery
+
+    required:
+      - compatible
+
+  charger:
+    type: object
+    $ref: /schemas/power/supply/power-supply.yaml
+    additionalProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-charger
+
+      monitored-battery: true
+
+    required:
+      - compatible
+
+  keyboard-ext:
+    type: object
+    description: top row of multimedia keys
+    additionalProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-keys
+
+    required:
+      - compatible
+
+  led:
+    type: object
+    additionalProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-led
Quoted 9 lines

Documentation/devicetree/bindings/mfd/asus,ec.yaml line 89

Quoted 5 lines
Documentation/devicetree/bindings/mfd/asus,ec.yaml new file +5 -0
+
+    required:
+      - compatible
+
+  serio:

All of these children are pointless - no resources. Drop all of them, it's btw explicitly documented rule in writing bindings.

Quoted 2 lines

They are all needed to be able to disable them individually from the device tree if needed.

They should not be disabled from DT, so they are not valid here. The given EC for given device is fixed/static. Does not change.

Quoted 7 lines
Quoted 2 lines

Have you considered a possibility that function may be disabled/unrouted within the controller. By the vendor.

And then it is implied by the compatible, so no need for any of that. Otherwise, if it is not specific per device, then specifying it for DTS for all devices would make no sense.

So you propose introduce a compatible for every single ec used in transformers instead of simply disable unpopulated functions? And how then battery and charger can reach monitored cell if they have no dedicated node?

Quoted 2 lines

Best regards,
Krzysztof

#14 lore raw

Re: [PATCH v2 3/9] dt-bindings: mfd: document ASUS Transformer EC

Quoted 16 lines · Svyatoslav Ryhel

вт, 10 лют. 2026 р. о 13:04 Krzysztof Kozlowski <[email protected]> пише:

Quoted 15 lines · Svyatoslav Ryhel
Quoted 13 lines
Quoted 12 lines
Quoted 8 lines
Quoted 6 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+  asus,clear-factory-mode:
+    type: boolean
+    description: clear Factory Mode bit in EC control register

Why would this be a static/fixed property over lifecycle of all devices?

Specify pls.

Provide rationale why we need to clear it every time, not once. Or any other rationale why we would accept that property.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Cause it is done by original Asus code and Asus did not provide schematic or any data apart from downstream source regarding this EC.

So that's a no. downstream code which is poor quality, not following DT rules at all, is never an argument for a DT property.

This property indicates that this controller on every reset restores

Implied by compatible then and you can drop the property.

Quoted 76 lines

factory bit hence it must be cleared. Bit is write only and cannot be detected. EC remains in factory mode which blocks its functions.

Quoted 65 lines
Quoted 65 lines
Quoted 64 lines
Quoted 58 lines
Quoted 48 lines
Quoted 48 lines
(quoted diff) +46 -0
+
+  battery:
+    type: object
+    $ref: /schemas/power/supply/power-supply.yaml
+    unevaluatedProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-battery
+
+    required:
+      - compatible
+
+  charger:
+    type: object
+    $ref: /schemas/power/supply/power-supply.yaml
+    additionalProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-charger
+
+      monitored-battery: true
+
+    required:
+      - compatible
+
+  keyboard-ext:
+    type: object
+    description: top row of multimedia keys
+    additionalProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-keys
+
+    required:
+      - compatible
+
+  led:
+    type: object
+    additionalProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-led
Quoted 9 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+
+    required:
+      - compatible
+
+  serio:

All of these children are pointless - no resources. Drop all of them, it's btw explicitly documented rule in writing bindings.

Quoted 2 lines

They are all needed to be able to disable them individually from the device tree if needed.

They should not be disabled from DT, so they are not valid here. The given EC for given device is fixed/static. Does not change.

Quoted 7 lines
Quoted 2 lines

Have you considered a possibility that function may be disabled/unrouted within the controller. By the vendor.

And then it is implied by the compatible, so no need for any of that. Otherwise, if it is not specific per device, then specifying it for DTS for all devices would make no sense.

Quoted 4 lines

So you propose introduce a compatible for every single ec used in transformers instead of simply disable unpopulated functions? And how then battery and charger can reach monitored cell if they have no dedicated node?

Just like for other bindings for nodes without resources, fold into parent. This is already explained in writing bindings, so you could have just read that. I will pass with answering more questions till you read that doc.

Best regards,
Krzysztof

#15 lore raw

Re: [PATCH v2 3/9] dt-bindings: mfd: document ASUS Transformer EC

вт, 10 лют. 2026 р. о 13:24 Krzysztof Kozlowski <[email protected]> пише:

Quoted 110 lines · Svyatoslav Ryhel
Quoted 16 lines

вт, 10 лют. 2026 р. о 13:04 Krzysztof Kozlowski <[email protected]> пише:

Quoted 15 lines · Svyatoslav Ryhel
Quoted 13 lines
Quoted 12 lines
Quoted 8 lines
Quoted 6 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+  asus,clear-factory-mode:
+    type: boolean
+    description: clear Factory Mode bit in EC control register

Why would this be a static/fixed property over lifecycle of all devices?

Specify pls.

Provide rationale why we need to clear it every time, not once. Or any other rationale why we would accept that property.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Cause it is done by original Asus code and Asus did not provide schematic or any data apart from downstream source regarding this EC.

So that's a no. downstream code which is poor quality, not following DT rules at all, is never an argument for a DT property.

This property indicates that this controller on every reset restores

Implied by compatible then and you can drop the property.

Quoted 76 lines

factory bit hence it must be cleared. Bit is write only and cannot be detected. EC remains in factory mode which blocks its functions.

Quoted 65 lines
Quoted 65 lines
Quoted 64 lines
Quoted 58 lines
Quoted 48 lines
Quoted 48 lines
(quoted diff) +46 -0
+
+  battery:
+    type: object
+    $ref: /schemas/power/supply/power-supply.yaml
+    unevaluatedProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-battery
+
+    required:
+      - compatible
+
+  charger:
+    type: object
+    $ref: /schemas/power/supply/power-supply.yaml
+    additionalProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-charger
+
+      monitored-battery: true
+
+    required:
+      - compatible
+
+  keyboard-ext:
+    type: object
+    description: top row of multimedia keys
+    additionalProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-keys
+
+    required:
+      - compatible
+
+  led:
+    type: object
+    additionalProperties: false
+
+    properties:
+      compatible:
+        const: asus,ec-led
Quoted 9 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+
+    required:
+      - compatible
+
+  serio:

All of these children are pointless - no resources. Drop all of them, it's btw explicitly documented rule in writing bindings.

Quoted 2 lines

They are all needed to be able to disable them individually from the device tree if needed.

They should not be disabled from DT, so they are not valid here. The given EC for given device is fixed/static. Does not change.

Quoted 7 lines
Quoted 2 lines

Have you considered a possibility that function may be disabled/unrouted within the controller. By the vendor.

And then it is implied by the compatible, so no need for any of that. Otherwise, if it is not specific per device, then specifying it for DTS for all devices would make no sense.

Quoted 4 lines

So you propose introduce a compatible for every single ec used in transformers instead of simply disable unpopulated functions? And how then battery and charger can reach monitored cell if they have no dedicated node?

Quoted 5 lines

Just like for other bindings for nodes without resources, fold into parent. This is already explained in writing bindings, so you could have just read that. I will pass with answering more questions till you read that doc.

Unfolding asus,ec-pad and asus,ec-dock will result in this list:

asus,tf101-dock-ec
asus,tf101g-dock-ec
asus,sl101-pad-ec
asus,tf201-pad-ec
asus,tf201-dock-ec
asus,tf300t-pad-ec
asus,tf300t-dock-ec
asus,tf300tg-pad-ec
asus,tf300tg-dock-ec
asus,tf300tl-pad-ec
asus,tf300tl-dock-ec
asus,tf600t-pad-ec
asus,tf700t-pad-ec
asus,tf700t-dock-ec
asus,tf701t-pad-ec
asus,p1801-t-pad-ec

with minor variations in populated cells. Is this acceptible?

Quoted 3 lines

Best regards,
Krzysztof

#16 lore raw

Re: [PATCH v2 3/9] dt-bindings: mfd: document ASUS Transformer EC

Quoted 31 lines · Svyatoslav Ryhel
Quoted 11 lines
Quoted 5 lines

So you propose introduce a compatible for every single ec used in transformers instead of simply disable unpopulated functions? And how then battery and charger can reach monitored cell if they have no dedicated node?

Just like for other bindings for nodes without resources, fold into parent. This is already explained in writing bindings, so you could have just read that. I will pass with answering more questions till you read that doc.

Unfolding asus,ec-pad and asus,ec-dock will result in this list:

asus,tf101-dock-ec
asus,tf101g-dock-ec
asus,sl101-pad-ec
asus,tf201-pad-ec
asus,tf201-dock-ec
asus,tf300t-pad-ec
asus,tf300t-dock-ec
asus,tf300tg-pad-ec
asus,tf300tg-dock-ec
asus,tf300tl-pad-ec
asus,tf300tl-dock-ec
asus,tf600t-pad-ec
asus,tf700t-pad-ec
asus,tf700t-dock-ec
asus,tf701t-pad-ec
asus,p1801-t-pad-ec

Quoted 1 line

with minor variations in populated cells. Is this acceptible?

Yes, this looks correct.

Best regards,
Krzysztof

#17 lore raw

Re: [PATCH v2 3/9] dt-bindings: mfd: document ASUS Transformer EC

Quoted 32 lines · Krzysztof Kozlowski
Quoted 31 lines · Svyatoslav Ryhel
Quoted 11 lines
Quoted 5 lines

So you propose introduce a compatible for every single ec used in transformers instead of simply disable unpopulated functions? And how then battery and charger can reach monitored cell if they have no dedicated node?

Just like for other bindings for nodes without resources, fold into parent. This is already explained in writing bindings, so you could have just read that. I will pass with answering more questions till you read that doc.

Unfolding asus,ec-pad and asus,ec-dock will result in this list:

asus,tf101-dock-ec
asus,tf101g-dock-ec
asus,sl101-pad-ec
asus,tf201-pad-ec
asus,tf201-dock-ec
asus,tf300t-pad-ec
asus,tf300t-dock-ec
asus,tf300tg-pad-ec
asus,tf300tg-dock-ec
asus,tf300tl-pad-ec
asus,tf300tl-dock-ec
asus,tf600t-pad-ec
asus,tf700t-pad-ec
asus,tf700t-dock-ec
asus,tf701t-pad-ec
asus,p1801-t-pad-ec

Quoted 4 lines
Quoted 1 line

with minor variations in populated cells. Is this acceptible?

Yes, this looks correct.

Update: with fallback-expressed compatibility when same interface and/or superset of features.

Best regards,
Krzysztof

#18 lore raw

Re: [PATCH v2 3/9] dt-bindings: mfd: document ASUS Transformer EC

вт, 10 лют. 2026 р. о 14:48 Krzysztof Kozlowski <[email protected]> пише:

Quoted 34 lines · Krzysztof Kozlowski
Quoted 32 lines · Svyatoslav Ryhel
Quoted 31 lines
Quoted 11 lines
Quoted 5 lines

So you propose introduce a compatible for every single ec used in transformers instead of simply disable unpopulated functions? And how then battery and charger can reach monitored cell if they have no dedicated node?

Just like for other bindings for nodes without resources, fold into parent. This is already explained in writing bindings, so you could have just read that. I will pass with answering more questions till you read that doc.

Unfolding asus,ec-pad and asus,ec-dock will result in this list:

asus,tf101-dock-ec
asus,tf101g-dock-ec
asus,sl101-pad-ec
asus,tf201-pad-ec
asus,tf201-dock-ec
asus,tf300t-pad-ec
asus,tf300t-dock-ec
asus,tf300tg-pad-ec
asus,tf300tg-dock-ec
asus,tf300tl-pad-ec
asus,tf300tl-dock-ec
asus,tf600t-pad-ec
asus,tf700t-pad-ec
asus,tf700t-dock-ec
asus,tf701t-pad-ec
asus,p1801-t-pad-ec

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

with minor variations in populated cells. Is this acceptible?

Yes, this looks correct.

Update: with fallback-expressed compatibility when same interface and/or superset of features.

I am removing separate DockRAM and merging it into this schema hence, it should look like this

reg:
description:
The ASUS Transformer EC has a main I2C address and an associated DockRAM device, which provides power-related functions for the embedded controller. Both addresses are required for operation.
minItems: 2

reg-names:
items:
- const: ec
- const: dockram

How should I organize amount of regs? Would this example be acceptable with minItems: 2 since EC requires both to work or should I set is as items list or minItems: 2 maxItems: 2? Thank you.

Quoted 2 lines

Best regards,
Krzysztof

#19 lore raw

PATCH v2 4/9 mfd: Add driver for Asus Transformer embedded controller

In reply to Svyatoslav Ryhel

From: Michał Mirosław <[email protected]>

Support Nuvoton NPCE795-based ECs as used in Asus Transformer TF201, TF300T, TF300TG, TF300TL and TF700T pad and dock, as well as TF101 dock and TF600T, P1801-T and TF701T pad. This is a glue driver handling detection and common operations for EC's functions.

---
 drivers/mfd/Kconfig         |  15 ++
 drivers/mfd/Makefile        |   1 +
 drivers/mfd/asus-ec.c       | 467 ++++++++++++++++++++++++++++++++++++
 include/linux/mfd/asus-ec.h | 138 +++++++++++
 4 files changed, 621 insertions(+)
 create mode 100644 drivers/mfd/asus-ec.c
drivers/mfd/Kconfig +15 -0
index 7192c9d1d268..312fd15eec6a 100644
@@ -137,6 +137,21 @@ config MFD_AAT2870_CORE
 	  additional drivers must be enabled in order to use the
 	  functionality of the device.
 
+config MFD_ASUSEC
+	tristate "ASUS Transformer's embedded controller"
+	depends on I2C && OF
+	select SYSFS
+	select ASUS_DOCKRAM
+	help
+	  Support ECs found in ASUS Transformer's Pad and Mobile Dock.
+
+	  This provides shared glue for functional part drivers:
+	    asus-ec-kbc, asus-ec-keys, leds-asus-ec, asus-ec-battery
+	    and asus-ec-charger.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called asus-ec.
+
 config MFD_AT91_USART
 	tristate "AT91 USART Driver"
 	select MFD_CORE
drivers/mfd/Makefile +1 -0
index e75e8045c28a..b676922601ba 100644
@@ -10,6 +10,7 @@ obj-$(CONFIG_MFD_88PM805)	+= 88pm805.o 88pm80x.o
 obj-$(CONFIG_MFD_88PM886_PMIC)	+= 88pm886.o
 obj-$(CONFIG_MFD_ACT8945A)	+= act8945a.o
 obj-$(CONFIG_MFD_SM501)		+= sm501.o
+obj-$(CONFIG_MFD_ASUSEC)	+= asus-ec.o
 obj-$(CONFIG_ARCH_BCM2835)	+= bcm2835-pm.o
 obj-$(CONFIG_MFD_BCM590XX)	+= bcm590xx.o
 obj-$(CONFIG_MFD_BD9571MWV)	+= bd9571mwv.o
drivers/mfd/asus-ec.c new file +467 -0

467 lines not on this page · raw message

include/linux/mfd/asus-ec.h +138 -0

158 lines not on this page · raw message

Signature · 1 line
2.51.0
maintainer
#20 lore raw

Re: [PATCH v2 4/9] mfd: Add driver for Asus Transformer embedded controller

Quoted 23 lines · Svyatoslav Ryhel

From: Michał Mirosław <[email protected]>

Support Nuvoton NPCE795-based ECs as used in Asus Transformer TF201, TF300T, TF300TG, TF300TL and TF700T pad and dock, as well as TF101 dock and TF600T, P1801-T and TF701T pad. This is a glue driver handling detection and common operations for EC's functions.

---
 drivers/mfd/Kconfig         |  15 ++
 drivers/mfd/Makefile        |   1 +
 drivers/mfd/asus-ec.c       | 467 ++++++++++++++++++++++++++++++++++++
 include/linux/mfd/asus-ec.h | 138 +++++++++++
 4 files changed, 621 insertions(+)
 create mode 100644 drivers/mfd/asus-ec.c
drivers/mfd/Kconfig +0 -0
index 7192c9d1d268..312fd15eec6a 100644

drivers/mfd/Kconfig config MFD_AAT2870_CORE · line 140

Quoted 4 lines
drivers/mfd/Kconfig +1 -0
@@ -137,6 +137,21 @@ config MFD_AAT2870_CORE
 	  additional drivers must be enabled in order to use the
 	  functionality of the device.
 
+config MFD_ASUSEC

MFD_ASUS_EC

drivers/mfd/Kconfig config MFD_AAT2870_CORE · line 150

Quoted 10 lines
drivers/mfd/Kconfig +10 -0
+	tristate "ASUS Transformer's embedded controller"
+	depends on I2C && OF
+	select SYSFS
+	select ASUS_DOCKRAM
+	help
+	  Support ECs found in ASUS Transformer's Pad and Mobile Dock.
+
+	  This provides shared glue for functional part drivers:
+	    asus-ec-kbc, asus-ec-keys, leds-asus-ec, asus-ec-battery
+	    and asus-ec-charger.

Why the additional tabbing? What example did you take that from?

Quoted 24 lines
drivers/mfd/Kconfig +3 -0
+	  This driver can also be built as a module. If so, the module
+	  will be called asus-ec.
+
 config MFD_AT91_USART
 	tristate "AT91 USART Driver"
 	select MFD_CORE
drivers/mfd/Makefile +1 -0
index e75e8045c28a..b676922601ba 100644
@@ -10,6 +10,7 @@ obj-$(CONFIG_MFD_88PM805)	+= 88pm805.o 88pm80x.o
 obj-$(CONFIG_MFD_88PM886_PMIC)	+= 88pm886.o
 obj-$(CONFIG_MFD_ACT8945A)	+= act8945a.o
 obj-$(CONFIG_MFD_SM501)		+= sm501.o
+obj-$(CONFIG_MFD_ASUSEC)	+= asus-ec.o
 obj-$(CONFIG_ARCH_BCM2835)	+= bcm2835-pm.o
 obj-$(CONFIG_MFD_BCM590XX)	+= bcm590xx.o
 obj-$(CONFIG_MFD_BD9571MWV)	+= bd9571mwv.o
drivers/mfd/asus-ec.c new file +0 -0
new file mode 100644
index 000000000000..e151c1506aa2

drivers/mfd/asus-ec.c line 3

Quoted 3 lines
drivers/mfd/asus-ec.c new file +3 -0
@@ -0,0 +1,467 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * ASUS EC driver

Copyright? Author?

Quoted 9 lines
drivers/mfd/asus-ec.c new file +9 -0
+ */
+
+#include <linux/array_size.h>
+#include <linux/debugfs.h>
+#include <linux/delay.h>
+#include <linux/gpio/consumer.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/i2c.h>

drivers/mfd/asus-ec.c line 22

Quoted 10 lines
drivers/mfd/asus-ec.c new file +10 -0
+#include <linux/interrupt.h>
+#include <linux/mfd/asus-ec.h>
+#include <linux/mfd/core.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/property.h>
+#include <linux/string.h>
+#include <linux/sysfs.h>
+#include <linux/types.h>

Alphabetical.

Are you sure all of these are in use?

drivers/mfd/asus-ec.c line 34

Quoted 11 lines
drivers/mfd/asus-ec.c new file +11 -0
+#define ASUSEC_RSP_BUFFER_SIZE		8
+
+struct asus_ec_chip_data {
+	const char *name;
+	const struct mfd_cell *mfd_devices;
+	unsigned int num_devices;
+};
+
+struct asus_ec_data {
+	struct asusec_info info;
+	struct mutex ecreq_lock; /* prevent simultaneous access */

We know what mutexes do.

If you're going to provide a comment, state WHAT is is protecting.

Or just omit the comment altogether.

drivers/mfd/asus-ec.c line 36

Quoted 2 lines
drivers/mfd/asus-ec.c new file +2 -0
+	struct gpio_desc *ecreq;
+	struct i2c_client *self;

"client"

Why are you storing this?

Quoted 79 lines
drivers/mfd/asus-ec.c new file +79 -0
+	const struct asus_ec_chip_data *data;
+	u8 ec_data[DOCKRAM_ENTRY_BUFSIZE];
+	bool clr_fmode;
+	bool logging_disabled;
+};
+
+#define to_ec_data(ec) \
+	container_of(ec, struct asus_ec_data, info)
+
+static void asus_ec_remove_notifier(struct device *dev, void *res)
+{
+	struct asusec_info *ec = dev_get_drvdata(dev->parent);
+	struct notifier_block **nb = res;
+
+	blocking_notifier_chain_unregister(&ec->notify_list, *nb);
+}
+
+/**
+ * devm_asus_ec_register_notifier - Managed registration of notifier to an
+ *				    ASUS EC blocking notifier chain.
+ * @pdev: Device requesting the notifier (used for resource management).
+ * @nb: Notifier block to be registered.
+ *
+ * Register a notifier to the ASUS EC blocking notifier chain. The notifier
+ * will be automatically unregistered when the requesting device is detached.
+ *
+ * Return: 0 on success or a negative error code on failure.
+ */
+int devm_asus_ec_register_notifier(struct platform_device *pdev,
+				   struct notifier_block *nb)
+{
+	struct asusec_info *ec = dev_get_drvdata(pdev->dev.parent);
+	struct notifier_block **res;
+	int ret;
+
+	res = devres_alloc(asus_ec_remove_notifier, sizeof(*res), GFP_KERNEL);
+	if (!res)
+		return -ENOMEM;
+
+	*res = nb;
+	ret = blocking_notifier_chain_register(&ec->notify_list, nb);
+	if (ret) {
+		devres_free(res);
+		return ret;
+	}
+
+	devres_add(&pdev->dev, res);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(devm_asus_ec_register_notifier);
+
+static int asus_ec_signal_request(const struct asusec_info *ec)
+{
+	struct asus_ec_data *priv = to_ec_data(ec);
+
+	guard(mutex)(&priv->ecreq_lock);
+
+	dev_dbg(&priv->self->dev, "EC request\n");
+
+	gpiod_set_value_cansleep(priv->ecreq, 1);
+	msleep(50);
+
+	gpiod_set_value_cansleep(priv->ecreq, 0);
+	msleep(200);
+
+	return 0;
+}
+
+static int asus_ec_write(struct asus_ec_data *priv, u16 data)
+{
+	int ret = i2c_smbus_write_word_data(priv->self, ASUSEC_WRITE_BUF, data);
+
+	dev_dbg(&priv->self->dev, "EC write: %04x, ret = %d\n", data, ret);
+	return ret;
+}
+
+static int asus_ec_read(struct asus_ec_data *priv, bool in_irq)
+{

drivers/mfd/asus-ec.c line 125

Quoted 10 lines
drivers/mfd/asus-ec.c new file +10 -0
+	int ret = i2c_smbus_read_i2c_block_data(priv->self, ASUSEC_READ_BUF,
+						sizeof(priv->ec_data),
+						priv->ec_data);
+
+	dev_dbg(&priv->self->dev, "EC read: %*ph, ret = %d%s\n",
+		sizeof(priv->ec_data), priv->ec_data,
+		ret, in_irq ? "; in irq" : "");
+
+	return ret;
+}

Remove both of these functions and use the i2c_smbus_*() API instead.

drivers/mfd/asus-ec.c line 138

Quoted 13 lines
drivers/mfd/asus-ec.c new file +13 -0
+
+/**
+ * asus_ec_i2c_command - Send a 16-bit command to the ASUS EC.
+ * @ec: Pointer to the shared ASUS EC structure.
+ * @data: The 16-bit command (word) to be sent.
+ *
+ * Return: 0 on success or a negative error code on failure.
+ */
+int asus_ec_i2c_command(const struct asusec_info *ec, u16 data)
+{
+	return asus_ec_write(to_ec_data(ec), data);
+}
+EXPORT_SYMBOL_GPL(asus_ec_i2c_command);

Why is this needed? Why not share 'client' with the leave drivers and let them make their own calls to i2c_smbus_write_word_data()?

drivers/mfd/asus-ec.c line 144

Quoted 5 lines
drivers/mfd/asus-ec.c new file +5 -0
+static void asus_ec_clear_buffer(struct asus_ec_data *priv)
+{
+	int retry = ASUSEC_RSP_BUFFER_SIZE;
+
+	while (retry--) {

Why is the amount of retries related to the buffer size?

drivers/mfd/asus-ec.c line 148

Quoted 4 lines
drivers/mfd/asus-ec.c new file +4 -0
+		if (asus_ec_read(priv, false) < 0)
+			continue;
+
+		if (priv->ec_data[1] & ASUSEC_OBF_MASK)

No magic numbers. Define the 1.

Quoted 14 lines
drivers/mfd/asus-ec.c new file +14 -0
+			continue;
+
+		break;
+	}
+}
+
+static int asus_ec_log_info(struct asus_ec_data *priv, unsigned int reg,
+			    const char *name, char **out)
+{
+	char buf[DOCKRAM_ENTRY_BUFSIZE];
+	int ret;
+
+	ret = asus_dockram_read(priv->info.dockram, reg, buf);
+	if (ret < 0)

drivers/mfd/asus-ec.c line 172

Quoted 10 lines
drivers/mfd/asus-ec.c new file +10 -0
+		return ret;
+
+	if (!priv->logging_disabled)
+		dev_info(&priv->self->dev, "%-14s: %.*s\n", name, buf[0], buf + 1);
+
+	if (out)
+		*out = kstrndup(buf + 1, buf[0], GFP_KERNEL);
+
+	return 0;
+}

The driver is written now. You can remove this over-engineered debugging facility.

drivers/mfd/asus-ec.c line 178

Quoted 5 lines
drivers/mfd/asus-ec.c new file +5 -0
+static int asus_ec_reset(struct asus_ec_data *priv)
+{
+	int retry, ret;
+
+	for (retry = 0; retry < 3; retry++) {

Why 3?

Why are you using for() here and while() above?

drivers/mfd/asus-ec.c line 179

Quoted 1 line
drivers/mfd/asus-ec.c new file +1 -0
+		ret = asus_ec_write(priv, 0);

Add a comment to explain how this works.

Or, better still, define the value.

drivers/mfd/asus-ec.c line 183

Quoted 4 lines
drivers/mfd/asus-ec.c new file +4 -0
+		if (!ret)
+			return 0;
+
+		msleep(300);

Why 300?

drivers/mfd/asus-ec.c line 189

Quoted 6 lines
drivers/mfd/asus-ec.c new file +6 -0
+	}
+
+	return ret;
+}
+
+static int asus_ec_magic_debug(struct asus_ec_data *priv)

What does this do? More comments throughout please.

Quoted 8 lines
drivers/mfd/asus-ec.c new file +8 -0
+{
+	u64 flag;
+	int ret;
+
+	ret = asus_ec_get_ctl(&priv->info, &flag);
+	if (ret < 0)
+		return ret;
+

drivers/mfd/asus-ec.c line 207

Quoted 10 lines
drivers/mfd/asus-ec.c new file +10 -0
+	flag &= ASUSEC_CTL_SUSB_MODE;
+	dev_info(&priv->self->dev, "EC FW behaviour: %s\n",
+		 flag ? "susb on when receive ec_req" : "susb on when system wakeup");
+
+	return 0;
+}
+
+static int asus_ec_set_factory_mode(struct asus_ec_data *priv, bool on)
+{
+	dev_info(&priv->self->dev, "Entering %s mode.\n", on ? "factory" : "normal");

Remove all of the debugging prints now.

drivers/mfd/asus-ec.c line 212

Quoted 5 lines
drivers/mfd/asus-ec.c new file +5 -0
+	return asus_ec_update_ctl(&priv->info, ASUSEC_CTL_FACTORY_MODE,
+				  on ? ASUSEC_CTL_FACTORY_MODE : 0);
+}
+
+static void asus_ec_handle_smi(struct asus_ec_data *priv, unsigned int code);

No forward declarations.

Quoted 95 lines
drivers/mfd/asus-ec.c new file +95 -0
+static irqreturn_t asus_ec_interrupt(int irq, void *dev_id)
+{
+	struct asus_ec_data *priv = dev_id;
+	unsigned long notify_action;
+	int ret;
+
+	ret = asus_ec_read(priv, true);
+	if (ret <= 0 || !(priv->ec_data[1] & ASUSEC_OBF_MASK))
+		return IRQ_NONE;
+
+	notify_action = priv->ec_data[1];
+	if (notify_action & ASUSEC_SMI_MASK) {
+		unsigned int code = priv->ec_data[2];
+
+		asus_ec_handle_smi(priv, code);
+
+		notify_action |= code << 8;
+		dev_dbg(&priv->self->dev, "SMI code: 0x%02x\n", code);
+	}
+
+	blocking_notifier_call_chain(&priv->info.notify_list,
+				     notify_action, priv->ec_data);
+
+	return IRQ_HANDLED;
+}
+
+static int asus_ec_detect(struct asus_ec_data *priv)
+{
+	char *model = NULL;
+	int ret;
+
+	ret = asus_ec_reset(priv);
+	if (ret)
+		goto err_exit;
+
+	asus_ec_clear_buffer(priv);
+
+	ret = asus_ec_log_info(priv, ASUSEC_DOCKRAM_INFO_MODEL, "model", &model);
+	if (ret)
+		goto err_exit;
+
+	ret = asus_ec_log_info(priv, ASUSEC_DOCKRAM_INFO_FW, "FW version", NULL);
+	if (ret)
+		goto err_exit;
+
+	ret = asus_ec_log_info(priv, ASUSEC_DOCKRAM_INFO_CFGFMT, "Config format", NULL);
+	if (ret)
+		goto err_exit;
+
+	ret = asus_ec_log_info(priv, ASUSEC_DOCKRAM_INFO_HW, "HW version", NULL);
+	if (ret)
+		goto err_exit;
+
+	priv->logging_disabled = true;
+
+	ret = asus_ec_magic_debug(priv);
+	if (ret)
+		goto err_exit;
+
+	priv->info.model = model;
+	priv->info.name = priv->data->name;
+
+	if (priv->clr_fmode)
+		asus_ec_set_factory_mode(priv, false);
+
+err_exit:
+	if (ret)
+		dev_err(&priv->self->dev, "failed to access EC: %d\n", ret);
+
+	return ret;
+}
+
+static void asus_ec_handle_smi(struct asus_ec_data *priv, unsigned int code)
+{
+	dev_dbg(&priv->self->dev, "SMI interrupt: 0x%02x\n", code);
+
+	switch (code) {
+	case ASUSEC_SMI_HANDSHAKE:
+	case ASUSEC_SMI_RESET:
+		asus_ec_detect(priv);
+		break;
+	}
+}
+
+static int ec_request_set(void *ec, u64 val)
+{
+	if (val)
+		asus_ec_signal_request(ec);
+
+	return 0;
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(ec_request_fops, NULL, ec_request_set, "%llu\n");
+
+static int ec_irq_set(void *ec, u64 val)

drivers/mfd/asus-ec.c line 318

Quoted 10 lines
drivers/mfd/asus-ec.c new file +10 -0
+{
+	struct asus_ec_data *priv = to_ec_data(ec);
+
+	if (val)
+		irq_wake_thread(priv->self->irq, priv);
+
+	return 0;
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(ec_irq_fops, NULL, ec_irq_set, "%llu\n");

Document these.

Quoted 17 lines
drivers/mfd/asus-ec.c new file +17 -0
+static void asus_ec_debugfs_remove(void *debugfs_root)
+{
+	debugfs_remove_recursive(debugfs_root);
+}
+
+static void devm_asus_ec_debugfs_init(struct device *dev)
+{
+	struct asusec_info *ec = dev_get_drvdata(dev);
+	struct asus_ec_data *priv = to_ec_data(ec);
+	struct dentry *debugfs_root;
+	char *name = devm_kasprintf(dev, GFP_KERNEL, "asus-ec-%s",
+				    priv->data->name);
+
+	debugfs_root = debugfs_create_dir(name, NULL);
+
+	debugfs_create_file("ec_irq", 0200, debugfs_root, ec, &ec_irq_fops);
+	debugfs_create_file("ec_request", 0200, debugfs_root, ec, &ec_request_fops);

drivers/mfd/asus-ec.c line 346

Quoted 10 lines
drivers/mfd/asus-ec.c new file +10 -0
+
+	asus_dockram_debugfs_init(priv->info.dockram, debugfs_root);
+
+	devm_add_action_or_reset(dev, asus_ec_debugfs_remove, debugfs_root);
+}
+
+static int asus_ec_probe(struct i2c_client *client)
+{
+	struct device *dev = &client->dev;
+	struct asus_ec_data *priv;

Call this "ddata".

Quoted 93 lines
drivers/mfd/asus-ec.c new file +93 -0
+	int ret;
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->data = device_get_match_data(dev);
+	if (!priv->data)
+		return -ENODEV;
+
+	i2c_set_clientdata(client, priv);
+	priv->self = client;
+
+	priv->info.dockram = devm_asus_dockram_get(dev);
+	if (IS_ERR(priv->info.dockram))
+		return dev_err_probe(dev, PTR_ERR(priv->info.dockram),
+				     "failed to get dockram\n");
+
+	priv->ecreq = devm_gpiod_get(dev, "request", GPIOD_OUT_LOW);
+	if (IS_ERR(priv->ecreq))
+		return dev_err_probe(dev, PTR_ERR(priv->ecreq),
+				     "failed to get request GPIO\n");
+
+	BLOCKING_INIT_NOTIFIER_HEAD(&priv->info.notify_list);
+	mutex_init(&priv->ecreq_lock);
+
+	priv->clr_fmode = device_property_read_bool(dev, "asus,clear-factory-mode");
+
+	asus_ec_signal_request(&priv->info);
+
+	ret = asus_ec_detect(priv);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to detect EC version\n");
+
+	ret = devm_request_threaded_irq(dev, client->irq, NULL,
+					&asus_ec_interrupt,
+					IRQF_ONESHOT | IRQF_SHARED,
+					client->name, priv);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to register IRQ\n");
+
+	/* Parent I2C controller uses DMA, ASUS EC and child devices do not */
+	client->dev.coherent_dma_mask = 0;
+	client->dev.dma_mask = &client->dev.coherent_dma_mask;
+
+	devm_asus_ec_debugfs_init(dev);
+
+	return devm_mfd_add_devices(dev, 0, priv->data->mfd_devices,
+				    priv->data->num_devices, NULL, 0, NULL);
+}
+
+static const struct mfd_cell asus_ec_pad_mfd_devices[] = {
+	{
+		.name = "asus-ec-battery",
+		.id = 0,
+		.of_compatible = "asus,ec-battery",
+	}, {
+		.name = "asus-ec-charger",
+		.id = 0,
+		.of_compatible = "asus,ec-charger",
+	}, {
+		.name = "asus-ec-led",
+		.id = 0,
+		.of_compatible = "asus,ec-led",
+	},
+};
+
+static const struct mfd_cell asus_ec_dock_mfd_devices[] = {
+	{
+		.name = "asus-ec-battery",
+		.id = 1,
+		.of_compatible = "asus,ec-battery",
+	}, {
+		.name = "asus-ec-charger",
+		.id = 1,
+		.of_compatible = "asus,ec-charger",
+	}, {
+		.name = "asus-ec-led",
+		.id = 1,
+		.of_compatible = "asus,ec-led",
+	}, {
+		.name = "asus-ec-keys",
+		.of_compatible = "asus,ec-keys",
+	}, {
+		.name = "asus-ec-kbc",
+		.of_compatible = "asus,ec-kbc",
+	},
+};
+
+static const struct asus_ec_chip_data asus_ec_pad_data = {
+	.name = "pad",
+	.mfd_devices = asus_ec_pad_mfd_devices,
+	.num_devices = ARRAY_SIZE(asus_ec_pad_mfd_devices),

drivers/mfd/asus-ec.c line 449

Quoted 10 lines
drivers/mfd/asus-ec.c new file +10 -0
+};
+
+static const struct asus_ec_chip_data asus_ec_dock_data = {
+	.name = "dock",
+	.mfd_devices = asus_ec_dock_mfd_devices,
+	.num_devices = ARRAY_SIZE(asus_ec_dock_mfd_devices),
+};
+
+static const struct of_device_id asus_ec_match[] = {
+	{ .compatible = "asus,ec-pad", .data = &asus_ec_pad_data },

Passing MFD data through a different registration mechanism is not allowed. Use identifiers to match in instead.

git grep "\.data =.*void" -- drivers/mfd

Quoted 167 lines
drivers/mfd/asus-ec.c new file +18 -0
+	{ .compatible = "asus,ec-dock", .data = &asus_ec_dock_data },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, asus_ec_match);
+
+static struct i2c_driver asus_ec_driver = {
+	.driver	= {
+		.name = "asus-ec",
+		.of_match_table = asus_ec_match,
+	},
+	.probe = asus_ec_probe,
+};
+module_i2c_driver(asus_ec_driver);
+
+MODULE_AUTHOR("Michał Mirosław <[email protected]>");
+MODULE_AUTHOR("Svyatoslav Ryhel <[email protected]>");
+MODULE_DESCRIPTION("ASUS Transformer's EC driver");
+MODULE_LICENSE("GPL");
include/linux/mfd/asus-ec.h +124 -0
index 6a36313b9ebd..6a06b125ba30 100644
@@ -2,16 +2,78 @@
 #ifndef __MISC_ASUS_EC_H
 #define __MISC_ASUS_EC_H
 
+#include <linux/notifier.h>
+#include <linux/platform_device.h>
+#include <linux/workqueue.h>
+
 struct i2c_client;
 
+struct asusec_info {
+	const char *model;
+	const char *name;
+	struct i2c_client *dockram;
+	struct workqueue_struct *wq;
+	struct blocking_notifier_head notify_list;
+};
+
 #define DOCKRAM_ENTRIES			0x100
 #define DOCKRAM_ENTRY_SIZE		32
 #define DOCKRAM_ENTRY_BUFSIZE		(DOCKRAM_ENTRY_SIZE + 1)
 
+/* interrupt sources */
+#define ASUSEC_OBF_MASK			BIT(0)
+#define ASUSEC_KEY_MASK			BIT(2)
+#define ASUSEC_KBC_MASK			BIT(3)
+#define ASUSEC_AUX_MASK			BIT(5)
+#define ASUSEC_SCI_MASK			BIT(6)
+#define ASUSEC_SMI_MASK			BIT(7)
+
+/* SMI notification codes */
+#define ASUSEC_SMI_POWER_NOTIFY		0x31	/* [un]plugging USB cable */
+#define ASUSEC_SMI_HANDSHAKE		0x50	/* response to ec_req edge */
+#define ASUSEC_SMI_WAKE			0x53
+#define ASUSEC_SMI_RESET		0x5f
+#define ASUSEC_SMI_ADAPTER_EVENT	0x60	/* [un]plugging charger to dock */
+#define ASUSEC_SMI_BACKLIGHT_ON		0x63
+#define ASUSEC_SMI_AUDIO_DOCK_IN	0x70
+
+#define ASUSEC_SMI_ACTION(code)		(ASUSEC_SMI_MASK | ASUSEC_OBF_MASK | \
+					(ASUSEC_SMI_##code << 8))
+
 /* control register [0x0A] layout */
 #define ASUSEC_CTL_SIZE			8
 
+/*
+ * EC reports power from 40-pin connector in the LSB of the control
+ * register.  The following values have been observed (xor 0x02):
+ *
+ * PAD-ec no-plug  0x40 / PAD-ec DOCK     0x20 / DOCK-ec no-plug 0x40
+ * PAD-ec AC       0x25 / PAD-ec DOCK+AC  0x24 / DOCK-ec AC      0x25
+ * PAD-ec USB      0x45 / PAD-ec DOCK+USB 0x24 / DOCK-ec USB     0x41
+ */
+
+#define ASUSEC_CTL_DIRECT_POWER_SOURCE	BIT_ULL(0)
+#define ASUSEC_STAT_CHARGING		BIT_ULL(2)
+#define ASUSEC_CTL_FULL_POWER_SOURCE	BIT_ULL(5)
+#define ASUSEC_CTL_SUSB_MODE		BIT_ULL(11)
+#define ASUSEC_CMD_SUSPEND_S3		BIT_ULL(41)
+#define ASUSEC_CTL_TEST_DISCHARGE	BIT_ULL(43)
+#define ASUSEC_CMD_SUSPEND_INHIBIT	BIT_ULL(45)
+#define ASUSEC_CTL_FACTORY_MODE		BIT_ULL(46)
+#define ASUSEC_CTL_KEEP_AWAKE		BIT_ULL(47)
+#define ASUSEC_CTL_USB_CHARGE		BIT_ULL(50)
+#define ASUSEC_CMD_SWITCH_HDMI		BIT_ULL(70)
+#define ASUSEC_CMD_WIN_SHUTDOWN		BIT_ULL(76)
+
+#define ASUSEC_DOCKRAM_INFO_MODEL	0x01
+#define ASUSEC_DOCKRAM_INFO_FW		0x02
+#define ASUSEC_DOCKRAM_INFO_CFGFMT	0x03
+#define ASUSEC_DOCKRAM_INFO_HW		0x04
 #define ASUSEC_DOCKRAM_CONTROL		0x0a
+#define ASUSEC_DOCKRAM_BATT_CTL		0x14
+
+#define ASUSEC_WRITE_BUF		0x64
+#define ASUSEC_READ_BUF			0x6A
 
 /* dockram comm */
 int asus_dockram_read(struct i2c_client *client, int reg, char *buf);
@@ -21,4 +83,80 @@ int asus_dockram_access_ctl(struct i2c_client *client,
 struct i2c_client *devm_asus_dockram_get(struct device *parent);
 void asus_dockram_debugfs_init(struct i2c_client *client,
 			       struct dentry *debugfs_root);
+
+/* EC public API */
+
+/**
+ * cell_to_ec - Request the shared ASUS EC structure via a subdevice's pdev.
+ * @pdev: EC subdevice pdev requesting access to the shared ASUS EC structure.
+ *
+ * Returns a pointer to the asusec_info structure.
+ */
+static inline struct asusec_info *cell_to_ec(struct platform_device *pdev)
+{
+	return dev_get_drvdata(pdev->dev.parent);
+}
+
+/**
+ * asus_ec_get_ctl - Read from the DockRAM control register.
+ * @ec:  Pointer to the shared ASUS EC structure.
+ * @out: Pointer to the variable where the register value will be stored.
+ *
+ * Performs a control register read and stores the value in @out.
+ *
+ * Return: 0 on success, or a negative errno code on failure.
+ */
+static inline int asus_ec_get_ctl(const struct asusec_info *ec, u64 *out)
+{
+	return asus_dockram_access_ctl(ec->dockram, out, 0, 0);
+}
+
+/**
+ * asus_ec_update_ctl - Update the DockRAM control register.
+ * @ec:   Pointer to the shared ASUS EC structure.
+ * @mask: Bitmask of bits to be cleared.
+ * @xor:  Bitmask of bits to be toggled or set (via XOR).
+ *
+ * Performs a read-modify-write update on the control register using
+ * the provided @mask and @xor values.
+ *
+ * Return: 0 on success, or a negative errno code on failure.
+ */
+static inline int asus_ec_update_ctl(const struct asusec_info *ec,
+				     u64 mask, u64 xor)
+{
+	return asus_dockram_access_ctl(ec->dockram, NULL, mask, xor);
+}
+
+/**
+ * asus_ec_set_ctl_bits - Sets bits of the DockRAM control register.
+ * @ec:   Pointer to the shared ASUS EC structure.
+ * @mask: Bitmask of bits to be set.
+ *
+ * Sets bits of the control register using the provided @mask value.
+ *
+ * Return: 0 on success, or a negative errno code on failure.
+ */
+static inline int asus_ec_set_ctl_bits(const struct asusec_info *ec, u64 mask)
+{
+	return asus_dockram_access_ctl(ec->dockram, NULL, mask, mask);
+}
+
+/**
+ * asus_ec_clear_ctl_bits - Clears bits of the DockRAM control register.
+ * @ec:   Pointer to the shared ASUS EC structure.

include/linux/mfd/asus-ec.h int asus_dockram_access_ctl(struct i2c_client *client, · line 157

Quoted 10 lines
include/linux/mfd/asus-ec.h +10 -0
+ * @mask: Bitmask of bits to be cleared.
+ *
+ * Clears bits of the control register using the provided @mask value.
+ *
+ * Return: 0 on success, or a negative errno code on failure.
+ */
+static inline int asus_ec_clear_ctl_bits(const struct asusec_info *ec, u64 mask)
+{
+	return asus_dockram_access_ctl(ec->dockram, NULL, mask, 0);
+}

This is all abstraction for he sake of abstraction.

Quoted 8 lines
include/linux/mfd/asus-ec.h +3 -0
+int asus_ec_i2c_command(const struct asusec_info *ec, u16 data);
+int devm_asus_ec_register_notifier(struct platform_device *dev,
+				   struct notifier_block *nb);
 #endif /* __MISC_ASUS_EC_H */
Signature · 1 line
2.51.0
Signature · 1 line
Lee Jones [李琼斯]
#21 lore raw

Re: [PATCH v2 4/9] mfd: Add driver for Asus Transformer embedded controller

пт, 6 бер. 2026 р. о 11:19 Lee Jones <[email protected]> пише:

Quoted 44 lines · Svyatoslav Ryhel
Quoted 24 lines

From: Michał Mirosław <[email protected]>

Support Nuvoton NPCE795-based ECs as used in Asus Transformer TF201, TF300T, TF300TG, TF300TL and TF700T pad and dock, as well as TF101 dock and TF600T, P1801-T and TF701T pad. This is a glue driver handling detection and common operations for EC's functions.

---
 drivers/mfd/Kconfig         |  15 ++
 drivers/mfd/Makefile        |   1 +
 drivers/mfd/asus-ec.c       | 467 ++++++++++++++++++++++++++++++++++++
 include/linux/mfd/asus-ec.h | 138 +++++++++++
 4 files changed, 621 insertions(+)
 create mode 100644 drivers/mfd/asus-ec.c
drivers/mfd/Kconfig +0 -0
index 7192c9d1d268..312fd15eec6a 100644

drivers/mfd/Kconfig config MFD_AAT2870_CORE · line 140

Quoted 4 lines
drivers/mfd/Kconfig +1 -0
@@ -137,6 +137,21 @@ config MFD_AAT2870_CORE
        additional drivers must be enabled in order to use the
        functionality of the device.
 
+config MFD_ASUSEC

MFD_ASUS_EC

drivers/mfd/Kconfig config MFD_AAT2870_CORE · line 150

Quoted 10 lines
drivers/mfd/Kconfig +10 -0
+     tristate "ASUS Transformer's embedded controller"
+     depends on I2C && OF
+     select SYSFS
+     select ASUS_DOCKRAM
+     help
+       Support ECs found in ASUS Transformer's Pad and Mobile Dock.
+
+       This provides shared glue for functional part drivers:
+         asus-ec-kbc, asus-ec-keys, leds-asus-ec, asus-ec-battery
+         and asus-ec-charger.
Quoted 2 lines

Why the additional tabbing? What example did you take that from?

MFD_MXS_LRADC
MFD_SL28CPLD
MFD_STMPE

They use 2 tabs, so I asume I have to switch to 2 tabs and a list too.

Quoted 52 lines
Quoted 24 lines
drivers/mfd/Kconfig +3 -0
+       This driver can also be built as a module. If so, the module
+       will be called asus-ec.
+
 config MFD_AT91_USART
      tristate "AT91 USART Driver"
      select MFD_CORE
drivers/mfd/Makefile +1 -0
index e75e8045c28a..b676922601ba 100644
@@ -10,6 +10,7 @@ obj-$(CONFIG_MFD_88PM805)   += 88pm805.o 88pm80x.o
 obj-$(CONFIG_MFD_88PM886_PMIC)       += 88pm886.o
 obj-$(CONFIG_MFD_ACT8945A)   += act8945a.o
 obj-$(CONFIG_MFD_SM501)              += sm501.o
+obj-$(CONFIG_MFD_ASUSEC)     += asus-ec.o
 obj-$(CONFIG_ARCH_BCM2835)   += bcm2835-pm.o
 obj-$(CONFIG_MFD_BCM590XX)   += bcm590xx.o
 obj-$(CONFIG_MFD_BD9571MWV)  += bd9571mwv.o
drivers/mfd/asus-ec.c new file +0 -0
new file mode 100644
index 000000000000..e151c1506aa2

drivers/mfd/asus-ec.c line 3

Quoted 3 lines
drivers/mfd/asus-ec.c new file +3 -0
@@ -0,0 +1,467 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * ASUS EC driver

Copyright? Author?

Quoted 9 lines
drivers/mfd/asus-ec.c new file +9 -0
+ */
+
+#include <linux/array_size.h>
+#include <linux/debugfs.h>
+#include <linux/delay.h>
+#include <linux/gpio/consumer.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/i2c.h>

drivers/mfd/asus-ec.c line 22

Quoted 10 lines
drivers/mfd/asus-ec.c new file +10 -0
+#include <linux/interrupt.h>
+#include <linux/mfd/asus-ec.h>
+#include <linux/mfd/core.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/property.h>
+#include <linux/string.h>
+#include <linux/sysfs.h>
+#include <linux/types.h>

Alphabetical.

Quoted 2 lines

Are you sure all of these are in use?

Yes, but if you are willing to double check I would be happy to include your findings.

Quoted 14 lines

drivers/mfd/asus-ec.c line 34

Quoted 11 lines
drivers/mfd/asus-ec.c new file +11 -0
+#define ASUSEC_RSP_BUFFER_SIZE               8
+
+struct asus_ec_chip_data {
+     const char *name;
+     const struct mfd_cell *mfd_devices;
+     unsigned int num_devices;
+};
+
+struct asus_ec_data {
+     struct asusec_info info;
+     struct mutex ecreq_lock; /* prevent simultaneous access */

We know what mutexes do.

Quoted 4 lines

If you're going to provide a comment, state WHAT is is protecting.

Or just omit the comment altogether.

checkpatch script requires a brief comment why mutex is used, I added a brief comment where it is used. If you don't like it, then propose a fix to checkpatch.

Quoted 5 lines

drivers/mfd/asus-ec.c line 36

Quoted 2 lines
drivers/mfd/asus-ec.c new file +2 -0
+     struct gpio_desc *ecreq;
+     struct i2c_client *self;

"client"

Is there any written convention that struct i2c_client pointer MUST be named "client"? "self" is pretty well fitting to. You are just nitpicking.

Quoted 2 lines

Why are you storing this?

To use later on to get device and irq.

Quoted 83 lines
Quoted 83 lines
drivers/mfd/asus-ec.c new file +83 -0
+     const struct asus_ec_chip_data *data;
+     u8 ec_data[DOCKRAM_ENTRY_BUFSIZE];
+     bool clr_fmode;
+     bool logging_disabled;
+};
+
+#define to_ec_data(ec) \
+     container_of(ec, struct asus_ec_data, info)
+
+static void asus_ec_remove_notifier(struct device *dev, void *res)
+{
+     struct asusec_info *ec = dev_get_drvdata(dev->parent);
+     struct notifier_block **nb = res;
+
+     blocking_notifier_chain_unregister(&ec->notify_list, *nb);
+}
+
+/**
+ * devm_asus_ec_register_notifier - Managed registration of notifier to an
+ *                               ASUS EC blocking notifier chain.
+ * @pdev: Device requesting the notifier (used for resource management).
+ * @nb: Notifier block to be registered.
+ *
+ * Register a notifier to the ASUS EC blocking notifier chain. The notifier
+ * will be automatically unregistered when the requesting device is detached.
+ *
+ * Return: 0 on success or a negative error code on failure.
+ */
+int devm_asus_ec_register_notifier(struct platform_device *pdev,
+                                struct notifier_block *nb)
+{
+     struct asusec_info *ec = dev_get_drvdata(pdev->dev.parent);
+     struct notifier_block **res;
+     int ret;
+
+     res = devres_alloc(asus_ec_remove_notifier, sizeof(*res), GFP_KERNEL);
+     if (!res)
+             return -ENOMEM;
+
+     *res = nb;
+     ret = blocking_notifier_chain_register(&ec->notify_list, nb);
+     if (ret) {
+             devres_free(res);
+             return ret;
+     }
+
+     devres_add(&pdev->dev, res);
+
+     return 0;
+}
+EXPORT_SYMBOL_GPL(devm_asus_ec_register_notifier);
+
+static int asus_ec_signal_request(const struct asusec_info *ec)
+{
+     struct asus_ec_data *priv = to_ec_data(ec);
+
+     guard(mutex)(&priv->ecreq_lock);
+
+     dev_dbg(&priv->self->dev, "EC request\n");
+
+     gpiod_set_value_cansleep(priv->ecreq, 1);
+     msleep(50);
+
+     gpiod_set_value_cansleep(priv->ecreq, 0);
+     msleep(200);
+
+     return 0;
+}
+
+static int asus_ec_write(struct asus_ec_data *priv, u16 data)
+{
+     int ret = i2c_smbus_write_word_data(priv->self, ASUSEC_WRITE_BUF, data);
+
+     dev_dbg(&priv->self->dev, "EC write: %04x, ret = %d\n", data, ret);
+     return ret;
+}
+
+static int asus_ec_read(struct asus_ec_data *priv, bool in_irq)
+{
+     int ret = i2c_smbus_read_i2c_block_data(priv->self, ASUSEC_READ_BUF,
+                                             sizeof(priv->ec_data),
+                                             priv->ec_data);
+
Quoted 9 lines

drivers/mfd/asus-ec.c line 125

Quoted 6 lines
drivers/mfd/asus-ec.c new file +6 -0
+     dev_dbg(&priv->self->dev, "EC read: %*ph, ret = %d%s\n",
+             sizeof(priv->ec_data), priv->ec_data,
+             ret, in_irq ? "; in irq" : "");
+
+     return ret;
+}

Remove both of these functions and use the i2c_smbus_*() API instead.

This would not reduce size much but it will reduce readability significantly since i2c_smbus_*() API have quite extended names.

Quoted 8 lines
Quoted 8 lines
drivers/mfd/asus-ec.c new file +8 -0
+
+/**
+ * asus_ec_i2c_command - Send a 16-bit command to the ASUS EC.
+ * @ec: Pointer to the shared ASUS EC structure.
+ * @data: The 16-bit command (word) to be sent.
+ *
+ * Return: 0 on success or a negative error code on failure.
+ */
Quoted 9 lines

drivers/mfd/asus-ec.c line 138

Quoted 5 lines
drivers/mfd/asus-ec.c new file +5 -0
+int asus_ec_i2c_command(const struct asusec_info *ec, u16 data)
+{
+     return asus_ec_write(to_ec_data(ec), data);
+}
+EXPORT_SYMBOL_GPL(asus_ec_i2c_command);

Why is this needed? Why not share 'client' with the leave drivers and let them make their own calls to i2c_smbus_write_word_data()?

Because parent should not share its internal stuff with subdevices.

Quoted 8 lines

drivers/mfd/asus-ec.c line 144

Quoted 5 lines
drivers/mfd/asus-ec.c new file +5 -0
+static void asus_ec_clear_buffer(struct asus_ec_data *priv)
+{
+     int retry = ASUSEC_RSP_BUFFER_SIZE;
+
+     while (retry--) {

Why is the amount of retries related to the buffer size?

Buffer size is 256 bytes, 1 read is 32 bytes. Calculate

Quoted 7 lines

drivers/mfd/asus-ec.c line 148

Quoted 4 lines
drivers/mfd/asus-ec.c new file +4 -0
+             if (asus_ec_read(priv, false) < 0)
+                     continue;
+
+             if (priv->ec_data[1] & ASUSEC_OBF_MASK)

No magic numbers. Define the 1.

#define ONE 1

Quoted 19 lines
Quoted 19 lines
drivers/mfd/asus-ec.c new file +19 -0
+                     continue;
+
+             break;
+     }
+}
+
+static int asus_ec_log_info(struct asus_ec_data *priv, unsigned int reg,
+                         const char *name, char **out)
+{
+     char buf[DOCKRAM_ENTRY_BUFSIZE];
+     int ret;
+
+     ret = asus_dockram_read(priv->info.dockram, reg, buf);
+     if (ret < 0)
+             return ret;
+
+     if (!priv->logging_disabled)
+             dev_info(&priv->self->dev, "%-14s: %.*s\n", name, buf[0], buf + 1);
+
Quoted 9 lines

drivers/mfd/asus-ec.c line 172

Quoted 5 lines
drivers/mfd/asus-ec.c new file +5 -0
+     if (out)
+             *out = kstrndup(buf + 1, buf[0], GFP_KERNEL);
+
+     return 0;
+}

The driver is written now. You can remove this over-engineered debugging facility.

No, this is logs EC firmware behaior. According to your logic kernel should have no logging whatsoever, and dmesg output is obviously redundant.

Quoted 10 lines

drivers/mfd/asus-ec.c line 178

Quoted 5 lines
drivers/mfd/asus-ec.c new file +5 -0
+static int asus_ec_reset(struct asus_ec_data *priv)
+{
+     int retry, ret;
+
+     for (retry = 0; retry < 3; retry++) {

Why 3?

Why are you using for() here and while() above?

Transferred from vendor source. No datasheet.

Quoted 6 lines

drivers/mfd/asus-ec.c line 179

Quoted 1 line
drivers/mfd/asus-ec.c new file +1 -0
+             ret = asus_ec_write(priv, 0);

Add a comment to explain how this works.

Or, better still, define the value.

#define ZERO 0

Quoted 7 lines

drivers/mfd/asus-ec.c line 183

Quoted 4 lines
drivers/mfd/asus-ec.c new file +4 -0
+             if (!ret)
+                     return 0;
+
+             msleep(300);

Why 300?

Transferred from vendor source. No datasheet.

Quoted 9 lines

drivers/mfd/asus-ec.c line 189

Quoted 6 lines
drivers/mfd/asus-ec.c new file +6 -0
+     }
+
+     return ret;
+}
+
+static int asus_ec_magic_debug(struct asus_ec_data *priv)

What does this do? More comments throughout please.

Checks firmware behavior. More is not known.

Quoted 12 lines
Quoted 12 lines
drivers/mfd/asus-ec.c new file +12 -0
+{
+     u64 flag;
+     int ret;
+
+     ret = asus_ec_get_ctl(&priv->info, &flag);
+     if (ret < 0)
+             return ret;
+
+     flag &= ASUSEC_CTL_SUSB_MODE;
+     dev_info(&priv->self->dev, "EC FW behaviour: %s\n",
+              flag ? "susb on when receive ec_req" : "susb on when system wakeup");
+
Quoted 9 lines

drivers/mfd/asus-ec.c line 207

Quoted 6 lines
drivers/mfd/asus-ec.c new file +6 -0
+     return 0;
+}
+
+static int asus_ec_set_factory_mode(struct asus_ec_data *priv, bool on)
+{
+     dev_info(&priv->self->dev, "Entering %s mode.\n", on ? "factory" : "normal");

Remove all of the debugging prints now.

No, this is logs EC firmware behavior.

Quoted 107 lines

drivers/mfd/asus-ec.c line 212

Quoted 5 lines
drivers/mfd/asus-ec.c new file +5 -0
+     return asus_ec_update_ctl(&priv->info, ASUSEC_CTL_FACTORY_MODE,
+                               on ? ASUSEC_CTL_FACTORY_MODE : 0);
+}
+
+static void asus_ec_handle_smi(struct asus_ec_data *priv, unsigned int code);

No forward declarations.

Quoted 99 lines
drivers/mfd/asus-ec.c new file +99 -0
+static irqreturn_t asus_ec_interrupt(int irq, void *dev_id)
+{
+     struct asus_ec_data *priv = dev_id;
+     unsigned long notify_action;
+     int ret;
+
+     ret = asus_ec_read(priv, true);
+     if (ret <= 0 || !(priv->ec_data[1] & ASUSEC_OBF_MASK))
+             return IRQ_NONE;
+
+     notify_action = priv->ec_data[1];
+     if (notify_action & ASUSEC_SMI_MASK) {
+             unsigned int code = priv->ec_data[2];
+
+             asus_ec_handle_smi(priv, code);
+
+             notify_action |= code << 8;
+             dev_dbg(&priv->self->dev, "SMI code: 0x%02x\n", code);
+     }
+
+     blocking_notifier_call_chain(&priv->info.notify_list,
+                                  notify_action, priv->ec_data);
+
+     return IRQ_HANDLED;
+}
+
+static int asus_ec_detect(struct asus_ec_data *priv)
+{
+     char *model = NULL;
+     int ret;
+
+     ret = asus_ec_reset(priv);
+     if (ret)
+             goto err_exit;
+
+     asus_ec_clear_buffer(priv);
+
+     ret = asus_ec_log_info(priv, ASUSEC_DOCKRAM_INFO_MODEL, "model", &model);
+     if (ret)
+             goto err_exit;
+
+     ret = asus_ec_log_info(priv, ASUSEC_DOCKRAM_INFO_FW, "FW version", NULL);
+     if (ret)
+             goto err_exit;
+
+     ret = asus_ec_log_info(priv, ASUSEC_DOCKRAM_INFO_CFGFMT, "Config format", NULL);
+     if (ret)
+             goto err_exit;
+
+     ret = asus_ec_log_info(priv, ASUSEC_DOCKRAM_INFO_HW, "HW version", NULL);
+     if (ret)
+             goto err_exit;
+
+     priv->logging_disabled = true;
+
+     ret = asus_ec_magic_debug(priv);
+     if (ret)
+             goto err_exit;
+
+     priv->info.model = model;
+     priv->info.name = priv->data->name;
+
+     if (priv->clr_fmode)
+             asus_ec_set_factory_mode(priv, false);
+
+err_exit:
+     if (ret)
+             dev_err(&priv->self->dev, "failed to access EC: %d\n", ret);
+
+     return ret;
+}
+
+static void asus_ec_handle_smi(struct asus_ec_data *priv, unsigned int code)
+{
+     dev_dbg(&priv->self->dev, "SMI interrupt: 0x%02x\n", code);
+
+     switch (code) {
+     case ASUSEC_SMI_HANDSHAKE:
+     case ASUSEC_SMI_RESET:
+             asus_ec_detect(priv);
+             break;
+     }
+}
+
+static int ec_request_set(void *ec, u64 val)
+{
+     if (val)
+             asus_ec_signal_request(ec);
+
+     return 0;
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(ec_request_fops, NULL, ec_request_set, "%llu\n");
+
+static int ec_irq_set(void *ec, u64 val)
+{
+     struct asus_ec_data *priv = to_ec_data(ec);
+
+     if (val)
Quoted 9 lines

drivers/mfd/asus-ec.c line 318

Quoted 6 lines
drivers/mfd/asus-ec.c new file +6 -0
+             irq_wake_thread(priv->self->irq, priv);
+
+     return 0;
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(ec_irq_fops, NULL, ec_irq_set, "%llu\n");

Document these.

Debugfs does not require any documentation.

Quoted 21 lines
Quoted 21 lines
drivers/mfd/asus-ec.c new file +21 -0
+static void asus_ec_debugfs_remove(void *debugfs_root)
+{
+     debugfs_remove_recursive(debugfs_root);
+}
+
+static void devm_asus_ec_debugfs_init(struct device *dev)
+{
+     struct asusec_info *ec = dev_get_drvdata(dev);
+     struct asus_ec_data *priv = to_ec_data(ec);
+     struct dentry *debugfs_root;
+     char *name = devm_kasprintf(dev, GFP_KERNEL, "asus-ec-%s",
+                                 priv->data->name);
+
+     debugfs_root = debugfs_create_dir(name, NULL);
+
+     debugfs_create_file("ec_irq", 0200, debugfs_root, ec, &ec_irq_fops);
+     debugfs_create_file("ec_request", 0200, debugfs_root, ec, &ec_request_fops);
+
+     asus_dockram_debugfs_init(priv->info.dockram, debugfs_root);
+
+     devm_add_action_or_reset(dev, asus_ec_debugfs_remove, debugfs_root);
Quoted 9 lines

drivers/mfd/asus-ec.c line 346

Quoted 6 lines
drivers/mfd/asus-ec.c new file +6 -0
+}
+
+static int asus_ec_probe(struct i2c_client *client)
+{
+     struct device *dev = &client->dev;
+     struct asus_ec_data *priv;

Call this "ddata".

Is there any written convention that driver private data pointer MUST be named "ddata"? "priv" is pretty well fitting to. You are just nitpicking.

Quoted 107 lines
Quoted 93 lines
drivers/mfd/asus-ec.c new file +93 -0
+     int ret;
+
+     priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+     if (!priv)
+             return -ENOMEM;
+
+     priv->data = device_get_match_data(dev);
+     if (!priv->data)
+             return -ENODEV;
+
+     i2c_set_clientdata(client, priv);
+     priv->self = client;
+
+     priv->info.dockram = devm_asus_dockram_get(dev);
+     if (IS_ERR(priv->info.dockram))
+             return dev_err_probe(dev, PTR_ERR(priv->info.dockram),
+                                  "failed to get dockram\n");
+
+     priv->ecreq = devm_gpiod_get(dev, "request", GPIOD_OUT_LOW);
+     if (IS_ERR(priv->ecreq))
+             return dev_err_probe(dev, PTR_ERR(priv->ecreq),
+                                  "failed to get request GPIO\n");
+
+     BLOCKING_INIT_NOTIFIER_HEAD(&priv->info.notify_list);
+     mutex_init(&priv->ecreq_lock);
+
+     priv->clr_fmode = device_property_read_bool(dev, "asus,clear-factory-mode");
+
+     asus_ec_signal_request(&priv->info);
+
+     ret = asus_ec_detect(priv);
+     if (ret)
+             return dev_err_probe(dev, ret, "failed to detect EC version\n");
+
+     ret = devm_request_threaded_irq(dev, client->irq, NULL,
+                                     &asus_ec_interrupt,
+                                     IRQF_ONESHOT | IRQF_SHARED,
+                                     client->name, priv);
+     if (ret)
+             return dev_err_probe(dev, ret, "failed to register IRQ\n");
+
+     /* Parent I2C controller uses DMA, ASUS EC and child devices do not */
+     client->dev.coherent_dma_mask = 0;
+     client->dev.dma_mask = &client->dev.coherent_dma_mask;
+
+     devm_asus_ec_debugfs_init(dev);
+
+     return devm_mfd_add_devices(dev, 0, priv->data->mfd_devices,
+                                 priv->data->num_devices, NULL, 0, NULL);
+}
+
+static const struct mfd_cell asus_ec_pad_mfd_devices[] = {
+     {
+             .name = "asus-ec-battery",
+             .id = 0,
+             .of_compatible = "asus,ec-battery",
+     }, {
+             .name = "asus-ec-charger",
+             .id = 0,
+             .of_compatible = "asus,ec-charger",
+     }, {
+             .name = "asus-ec-led",
+             .id = 0,
+             .of_compatible = "asus,ec-led",
+     },
+};
+
+static const struct mfd_cell asus_ec_dock_mfd_devices[] = {
+     {
+             .name = "asus-ec-battery",
+             .id = 1,
+             .of_compatible = "asus,ec-battery",
+     }, {
+             .name = "asus-ec-charger",
+             .id = 1,
+             .of_compatible = "asus,ec-charger",
+     }, {
+             .name = "asus-ec-led",
+             .id = 1,
+             .of_compatible = "asus,ec-led",
+     }, {
+             .name = "asus-ec-keys",
+             .of_compatible = "asus,ec-keys",
+     }, {
+             .name = "asus-ec-kbc",
+             .of_compatible = "asus,ec-kbc",
+     },
+};
+
+static const struct asus_ec_chip_data asus_ec_pad_data = {
+     .name = "pad",
+     .mfd_devices = asus_ec_pad_mfd_devices,
+     .num_devices = ARRAY_SIZE(asus_ec_pad_mfd_devices),

drivers/mfd/asus-ec.c line 449

Quoted 10 lines
drivers/mfd/asus-ec.c new file +10 -0
+};
+
+static const struct asus_ec_chip_data asus_ec_dock_data = {
+     .name = "dock",
+     .mfd_devices = asus_ec_dock_mfd_devices,
+     .num_devices = ARRAY_SIZE(asus_ec_dock_mfd_devices),
+};
+
+static const struct of_device_id asus_ec_match[] = {
+     { .compatible = "asus,ec-pad", .data = &asus_ec_pad_data },

Passing MFD data through a different registration mechanism is not allowed. Use identifiers to match in instead.

Quoted 2 lines

git grep "\.data =.*void" -- drivers/mfd

Why? So for overwhelming majority of the kernel drivers this is perfectly fine and ok, and for MFD this is no no? Point me please to any written convention why using OF match (which is a must for any new driver) is bad? Especially since this driver targets embedded devices which rely mostly on OF device trees.

Quoted 171 lines
Quoted 171 lines
drivers/mfd/asus-ec.c new file +18 -0
+     { .compatible = "asus,ec-dock", .data = &asus_ec_dock_data },
+     { }
+};
+MODULE_DEVICE_TABLE(of, asus_ec_match);
+
+static struct i2c_driver asus_ec_driver = {
+     .driver = {
+             .name = "asus-ec",
+             .of_match_table = asus_ec_match,
+     },
+     .probe = asus_ec_probe,
+};
+module_i2c_driver(asus_ec_driver);
+
+MODULE_AUTHOR("Michał Mirosław <[email protected]>");
+MODULE_AUTHOR("Svyatoslav Ryhel <[email protected]>");
+MODULE_DESCRIPTION("ASUS Transformer's EC driver");
+MODULE_LICENSE("GPL");
include/linux/mfd/asus-ec.h +128 -0
index 6a36313b9ebd..6a06b125ba30 100644
@@ -2,16 +2,78 @@
 #ifndef __MISC_ASUS_EC_H
 #define __MISC_ASUS_EC_H
 
+#include <linux/notifier.h>
+#include <linux/platform_device.h>
+#include <linux/workqueue.h>
+
 struct i2c_client;
 
+struct asusec_info {
+     const char *model;
+     const char *name;
+     struct i2c_client *dockram;
+     struct workqueue_struct *wq;
+     struct blocking_notifier_head notify_list;
+};
+
 #define DOCKRAM_ENTRIES                      0x100
 #define DOCKRAM_ENTRY_SIZE           32
 #define DOCKRAM_ENTRY_BUFSIZE                (DOCKRAM_ENTRY_SIZE + 1)
 
+/* interrupt sources */
+#define ASUSEC_OBF_MASK                      BIT(0)
+#define ASUSEC_KEY_MASK                      BIT(2)
+#define ASUSEC_KBC_MASK                      BIT(3)
+#define ASUSEC_AUX_MASK                      BIT(5)
+#define ASUSEC_SCI_MASK                      BIT(6)
+#define ASUSEC_SMI_MASK                      BIT(7)
+
+/* SMI notification codes */
+#define ASUSEC_SMI_POWER_NOTIFY              0x31    /* [un]plugging USB cable */
+#define ASUSEC_SMI_HANDSHAKE         0x50    /* response to ec_req edge */
+#define ASUSEC_SMI_WAKE                      0x53
+#define ASUSEC_SMI_RESET             0x5f
+#define ASUSEC_SMI_ADAPTER_EVENT     0x60    /* [un]plugging charger to dock */
+#define ASUSEC_SMI_BACKLIGHT_ON              0x63
+#define ASUSEC_SMI_AUDIO_DOCK_IN     0x70
+
+#define ASUSEC_SMI_ACTION(code)              (ASUSEC_SMI_MASK | ASUSEC_OBF_MASK | \
+                                     (ASUSEC_SMI_##code << 8))
+
 /* control register [0x0A] layout */
 #define ASUSEC_CTL_SIZE                      8
 
+/*
+ * EC reports power from 40-pin connector in the LSB of the control
+ * register.  The following values have been observed (xor 0x02):
+ *
+ * PAD-ec no-plug  0x40 / PAD-ec DOCK     0x20 / DOCK-ec no-plug 0x40
+ * PAD-ec AC       0x25 / PAD-ec DOCK+AC  0x24 / DOCK-ec AC      0x25
+ * PAD-ec USB      0x45 / PAD-ec DOCK+USB 0x24 / DOCK-ec USB     0x41
+ */
+
+#define ASUSEC_CTL_DIRECT_POWER_SOURCE       BIT_ULL(0)
+#define ASUSEC_STAT_CHARGING         BIT_ULL(2)
+#define ASUSEC_CTL_FULL_POWER_SOURCE BIT_ULL(5)
+#define ASUSEC_CTL_SUSB_MODE         BIT_ULL(11)
+#define ASUSEC_CMD_SUSPEND_S3                BIT_ULL(41)
+#define ASUSEC_CTL_TEST_DISCHARGE    BIT_ULL(43)
+#define ASUSEC_CMD_SUSPEND_INHIBIT   BIT_ULL(45)
+#define ASUSEC_CTL_FACTORY_MODE              BIT_ULL(46)
+#define ASUSEC_CTL_KEEP_AWAKE                BIT_ULL(47)
+#define ASUSEC_CTL_USB_CHARGE                BIT_ULL(50)
+#define ASUSEC_CMD_SWITCH_HDMI               BIT_ULL(70)
+#define ASUSEC_CMD_WIN_SHUTDOWN              BIT_ULL(76)
+
+#define ASUSEC_DOCKRAM_INFO_MODEL    0x01
+#define ASUSEC_DOCKRAM_INFO_FW               0x02
+#define ASUSEC_DOCKRAM_INFO_CFGFMT   0x03
+#define ASUSEC_DOCKRAM_INFO_HW               0x04
 #define ASUSEC_DOCKRAM_CONTROL               0x0a
+#define ASUSEC_DOCKRAM_BATT_CTL              0x14
+
+#define ASUSEC_WRITE_BUF             0x64
+#define ASUSEC_READ_BUF                      0x6A
 
 /* dockram comm */
 int asus_dockram_read(struct i2c_client *client, int reg, char *buf);
@@ -21,4 +83,80 @@ int asus_dockram_access_ctl(struct i2c_client *client,
 struct i2c_client *devm_asus_dockram_get(struct device *parent);
 void asus_dockram_debugfs_init(struct i2c_client *client,
                             struct dentry *debugfs_root);
+
+/* EC public API */
+
+/**
+ * cell_to_ec - Request the shared ASUS EC structure via a subdevice's pdev.
+ * @pdev: EC subdevice pdev requesting access to the shared ASUS EC structure.
+ *
+ * Returns a pointer to the asusec_info structure.
+ */
+static inline struct asusec_info *cell_to_ec(struct platform_device *pdev)
+{
+     return dev_get_drvdata(pdev->dev.parent);
+}
+
+/**
+ * asus_ec_get_ctl - Read from the DockRAM control register.
+ * @ec:  Pointer to the shared ASUS EC structure.
+ * @out: Pointer to the variable where the register value will be stored.
+ *
+ * Performs a control register read and stores the value in @out.
+ *
+ * Return: 0 on success, or a negative errno code on failure.
+ */
+static inline int asus_ec_get_ctl(const struct asusec_info *ec, u64 *out)
+{
+     return asus_dockram_access_ctl(ec->dockram, out, 0, 0);
+}
+
+/**
+ * asus_ec_update_ctl - Update the DockRAM control register.
+ * @ec:   Pointer to the shared ASUS EC structure.
+ * @mask: Bitmask of bits to be cleared.
+ * @xor:  Bitmask of bits to be toggled or set (via XOR).
+ *
+ * Performs a read-modify-write update on the control register using
+ * the provided @mask and @xor values.
+ *
+ * Return: 0 on success, or a negative errno code on failure.
+ */
+static inline int asus_ec_update_ctl(const struct asusec_info *ec,
+                                  u64 mask, u64 xor)
+{
+     return asus_dockram_access_ctl(ec->dockram, NULL, mask, xor);
+}
+
+/**
+ * asus_ec_set_ctl_bits - Sets bits of the DockRAM control register.
+ * @ec:   Pointer to the shared ASUS EC structure.
+ * @mask: Bitmask of bits to be set.
+ *
+ * Sets bits of the control register using the provided @mask value.
+ *
+ * Return: 0 on success, or a negative errno code on failure.
+ */
+static inline int asus_ec_set_ctl_bits(const struct asusec_info *ec, u64 mask)
+{
+     return asus_dockram_access_ctl(ec->dockram, NULL, mask, mask);
+}
+
+/**
+ * asus_ec_clear_ctl_bits - Clears bits of the DockRAM control register.
+ * @ec:   Pointer to the shared ASUS EC structure.
+ * @mask: Bitmask of bits to be cleared.
+ *
+ * Clears bits of the control register using the provided @mask value.
+ *
Quoted 9 lines

include/linux/mfd/asus-ec.h int asus_dockram_access_ctl(struct i2c_client *client, · line 157

Quoted 6 lines
include/linux/mfd/asus-ec.h +6 -0
+ * Return: 0 on success, or a negative errno code on failure.
+ */
+static inline int asus_ec_clear_ctl_bits(const struct asusec_info *ec, u64 mask)
+{
+     return asus_dockram_access_ctl(ec->dockram, NULL, mask, 0);
+}

This is all abstraction for he sake of abstraction.

Is this nitpicking for the sake of nitpicking? All 3 are used by subdevices and have proper descriptions. According to your logic maybe all clear, set and setclr wrappers should be removed across kernel as well. And all access functions can be dropped to xfer covers everything.

Quoted 11 lines
Quoted 8 lines
include/linux/mfd/asus-ec.h +3 -1
+int asus_ec_i2c_command(const struct asusec_info *ec, u16 data);
+int devm_asus_ec_register_notifier(struct platform_device *dev,
+                                struct notifier_block *nb);
 #endif /* __MISC_ASUS_EC_H */
--

2.51.0

--
Lee Jones [李琼斯]

#22 lore raw

PATCH v2 5/9 input: serio: Add driver for Asus Transformer dock keyboard and touchpad

In reply to Svyatoslav Ryhel

From: Michał Mirosław <[email protected]>

Add input driver for Asus Transformer dock keyboard and touchpad.

Some keys in Asus Dock report keycodes that don't make sense according to their position, this patch modifies the incoming data that is sent to serio to send proper scancodes.

---
 drivers/input/serio/Kconfig       |  15 +++
 drivers/input/serio/Makefile      |   1 +
 drivers/input/serio/asus-ec-kbc.c | 160 ++++++++++++++++++++++++++++++
 3 files changed, 176 insertions(+)
 create mode 100644 drivers/input/serio/asus-ec-kbc.c
drivers/input/serio/Kconfig +15 -0
index c7ef347a4dff..46c4286cd5f6 100644
@@ -97,6 +97,21 @@ config SERIO_RPCKBD
 	  To compile this driver as a module, choose M here: the
 	  module will be called rpckbd.
 
+config SERIO_ASUSEC
+	tristate "Asus Transformer's Dock keyboard and touchpad controller"
+	depends on MFD_ASUSEC
+	help
+	  Say Y here if you want to use the keyboard and/or touchpad on
+	  Asus Transformed's Mobile Dock.
+
+	  For keyboard support you also need atkbd driver.
+
+	  For touchpad support you also need psmouse driver with Elantech
+	  touchpad option enabled.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called asus-ec-kbc.
+
 config SERIO_AMBAKMI
 	tristate "AMBA KMI keyboard controller"
 	depends on ARM_AMBA
drivers/input/serio/Makefile +1 -0
index 6d97bad7b844..444e3ea70e37 100644
@@ -13,6 +13,7 @@ obj-$(CONFIG_SERIO_CT82C710)	+= ct82c710.o
 obj-$(CONFIG_SERIO_RPCKBD)	+= rpckbd.o
 obj-$(CONFIG_SERIO_SA1111)	+= sa1111ps2.o
 obj-$(CONFIG_SERIO_AMBAKMI)	+= ambakmi.o
+obj-$(CONFIG_SERIO_ASUSEC)	+= asus-ec-kbc.o
 obj-$(CONFIG_SERIO_Q40KBD)	+= q40kbd.o
 obj-$(CONFIG_SERIO_GSCPS2)	+= gscps2.o
 obj-$(CONFIG_HP_SDC)		+= hp_sdc.o
drivers/input/serio/asus-ec-kbc.c new file +160 -0

160 lines not on this page · raw message

Signature · 1 line
2.51.0
#23 lore raw

PATCH v2 6/9 input: keyboard: Add driver for Asus Transformer dock multimedia keys

In reply to Svyatoslav Ryhel

From: Michał Mirosław <[email protected]>

Add support for multimedia top button row of ASUS Transformer's Mobile Dock keyboard. Driver is made that function keys (F1-F12) are used by default which suits average Linux use better and with pressing ScreenLock + AltGr function keys layout is switched to multimedia keys. Since this only modifies codes sent by asus-ec-keys it doesn't affect normal keyboards at all.

---
 drivers/input/keyboard/Kconfig        |  10 +
 drivers/input/keyboard/Makefile       |   1 +
 drivers/input/keyboard/asus-ec-keys.c | 285 ++++++++++++++++++++++++++
 3 files changed, 296 insertions(+)
 create mode 100644 drivers/input/keyboard/asus-ec-keys.c
drivers/input/keyboard/Kconfig +10 -0
index 2ff4fef322c2..d23af13ab99a 100644
@@ -89,6 +89,16 @@ config KEYBOARD_APPLESPI
 	  To compile this driver as a module, choose M here: the
 	  module will be called applespi.
 
+config KEYBOARD_ASUSEC
+	tristate "Asus Transformer's Mobile Dock multimedia keys"
+	depends on MFD_ASUSEC
+	help
+	  Say Y here if you want to use multimedia keys present on Asus
+	  Transformer's Mobile Dock.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called asus-ec-keys.
+
 config KEYBOARD_ATARI
 	tristate "Atari keyboard"
 	depends on ATARI
drivers/input/keyboard/Makefile +1 -0
index 2d906e14f3e2..7226aafddf7a 100644
@@ -11,6 +11,7 @@ obj-$(CONFIG_KEYBOARD_ADP5585)		+= adp5585-keys.o
 obj-$(CONFIG_KEYBOARD_ADP5588)		+= adp5588-keys.o
 obj-$(CONFIG_KEYBOARD_AMIGA)		+= amikbd.o
 obj-$(CONFIG_KEYBOARD_APPLESPI)		+= applespi.o
+obj-$(CONFIG_KEYBOARD_ASUSEC)		+= asus-ec-keys.o
 obj-$(CONFIG_KEYBOARD_ATARI)		+= atakbd.o
 obj-$(CONFIG_KEYBOARD_ATKBD)		+= atkbd.o
 obj-$(CONFIG_KEYBOARD_BCM)		+= bcm-keypad.o
drivers/input/keyboard/asus-ec-keys.c new file +285 -0

285 lines not on this page · raw message

Signature · 1 line
2.51.0
#24 lore raw

PATCH v2 7/9 leds: Add driver for Asus Transformer LEDs

In reply to Svyatoslav Ryhel

From: Michał Mirosław <[email protected]>

Asus Transformer tablets have a green and an amber LED on both the Pad and the Dock. If both LEDs are enabled simultaneously, the emitted light will be yellow.

---
 drivers/leds/Kconfig        |  11 ++++
 drivers/leds/Makefile       |   1 +
 drivers/leds/leds-asus-ec.c | 104 ++++++++++++++++++++++++++++++++++++
 3 files changed, 116 insertions(+)
 create mode 100644 drivers/leds/leds-asus-ec.c
drivers/leds/Kconfig +11 -0
index 597d7a79c988..96dab210f6ca 100644
@@ -120,6 +120,17 @@ config LEDS_OSRAM_AMS_AS3668
 	  To compile this driver as a module, choose M here: the module
 	  will be called leds-as3668.
 
+config LEDS_ASUSEC
+	tristate "LED Support for Asus Transformer charging LED"
+	depends on LEDS_CLASS
+	depends on MFD_ASUSEC
+	help
+	  This option enables support for charging indicator on
+	  Asus Transformer's Pad and it's Dock.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called leds-asus-ec.
+
 config LEDS_AW200XX
 	tristate "LED support for Awinic AW20036/AW20054/AW20072/AW20108"
 	depends on LEDS_CLASS
drivers/leds/Makefile +1 -0
index 8fdb45d5b439..1117304dfdf4 100644
@@ -16,6 +16,7 @@ obj-$(CONFIG_LEDS_AN30259A)		+= leds-an30259a.o
 obj-$(CONFIG_LEDS_APU)			+= leds-apu.o
 obj-$(CONFIG_LEDS_ARIEL)		+= leds-ariel.o
 obj-$(CONFIG_LEDS_AS3668)		+= leds-as3668.o
+obj-$(CONFIG_LEDS_ASUSEC)		+= leds-asus-ec.o
 obj-$(CONFIG_LEDS_AW200XX)		+= leds-aw200xx.o
 obj-$(CONFIG_LEDS_AW2013)		+= leds-aw2013.o
 obj-$(CONFIG_LEDS_BCM6328)		+= leds-bcm6328.o
drivers/leds/leds-asus-ec.c new file +104 -0

104 lines not on this page · raw message

Signature · 1 line
2.51.0
maintainer
#25 lore raw

Re: [PATCH v2 7/9] leds: Add driver for Asus Transformer LEDs

Quoted 96 lines · Svyatoslav Ryhel

From: Michał Mirosław <[email protected]>

Asus Transformer tablets have a green and an amber LED on both the Pad and the Dock. If both LEDs are enabled simultaneously, the emitted light will be yellow.

---
 drivers/leds/Kconfig        |  11 ++++
 drivers/leds/Makefile       |   1 +
 drivers/leds/leds-asus-ec.c | 104 ++++++++++++++++++++++++++++++++++++
 3 files changed, 116 insertions(+)
 create mode 100644 drivers/leds/leds-asus-ec.c
drivers/leds/Kconfig +11 -0
index 597d7a79c988..96dab210f6ca 100644
@@ -120,6 +120,17 @@ config LEDS_OSRAM_AMS_AS3668
 	  To compile this driver as a module, choose M here: the module
 	  will be called leds-as3668.
 
+config LEDS_ASUSEC
+	tristate "LED Support for Asus Transformer charging LED"
+	depends on LEDS_CLASS
+	depends on MFD_ASUSEC
+	help
+	  This option enables support for charging indicator on
+	  Asus Transformer's Pad and it's Dock.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called leds-asus-ec.
+
 config LEDS_AW200XX
 	tristate "LED support for Awinic AW20036/AW20054/AW20072/AW20108"
 	depends on LEDS_CLASS
drivers/leds/Makefile +1 -0
index 8fdb45d5b439..1117304dfdf4 100644
@@ -16,6 +16,7 @@ obj-$(CONFIG_LEDS_AN30259A)		+= leds-an30259a.o
 obj-$(CONFIG_LEDS_APU)			+= leds-apu.o
 obj-$(CONFIG_LEDS_ARIEL)		+= leds-ariel.o
 obj-$(CONFIG_LEDS_AS3668)		+= leds-as3668.o
+obj-$(CONFIG_LEDS_ASUSEC)		+= leds-asus-ec.o
 obj-$(CONFIG_LEDS_AW200XX)		+= leds-aw200xx.o
 obj-$(CONFIG_LEDS_AW2013)		+= leds-aw2013.o
 obj-$(CONFIG_LEDS_BCM6328)		+= leds-bcm6328.o
drivers/leds/leds-asus-ec.c new file +40 -0
new file mode 100644
index 000000000000..5dd76c9247ee
@@ -0,0 +1,104 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ASUS EC driver - battery LED
+ */
+
+#include <linux/err.h>
+#include <linux/leds.h>
+#include <linux/mfd/asus-ec.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+/*
+ * F[5] & 0x07
+ *  auto: brightness == 0
+ *  bit 0: blink / charger on
+ *  bit 1: amber on
+ *  bit 2: green on
+ */
+
+#define ASUSEC_CTL_LED_BLINK		BIT_ULL(40)
+#define ASUSEC_CTL_LED_AMBER		BIT_ULL(41)
+#define ASUSEC_CTL_LED_GREEN		BIT_ULL(42)
+
+static void asus_ec_led_set_brightness_amber(struct led_classdev *led,
+					     enum led_brightness brightness)
+{
+	const struct asusec_info *ec = dev_get_drvdata(led->dev->parent);
+
+	if (brightness)
+		asus_ec_set_ctl_bits(ec, ASUSEC_CTL_LED_AMBER);
+	else
+		asus_ec_clear_ctl_bits(ec, ASUSEC_CTL_LED_AMBER);
+}
+
+static void asus_ec_led_set_brightness_green(struct led_classdev *led,
+					     enum led_brightness brightness)
+{
+	const struct asusec_info *ec = dev_get_drvdata(led->dev->parent);

drivers/leds/leds-asus-ec.c line 50

Quoted 10 lines
drivers/leds/leds-asus-ec.c new file +10 -0
+
+	if (brightness)
+		asus_ec_set_ctl_bits(ec, ASUSEC_CTL_LED_GREEN);
+	else
+		asus_ec_clear_ctl_bits(ec, ASUSEC_CTL_LED_GREEN);
+}
+
+static int asus_ec_led_probe(struct platform_device *pdev)
+{
+	struct asusec_info *ec = cell_to_ec(pdev);

Please remove all of your abstraction layers. They serve little purpose other than to complicate things. Just use dev_get_drvdata() here.

Remove the "_info" part and change "ec" to "ddata".

drivers/leds/leds-asus-ec.c line 55

Quoted 5 lines
drivers/leds/leds-asus-ec.c new file +5 -0
+	struct device *dev = &pdev->dev;
+	struct led_classdev *amber_led, *green_led;
+	int ret;
+
+	platform_set_drvdata(pdev, ec);

Wait, what?

Why are you doing that?

Quoted 15 lines
drivers/leds/leds-asus-ec.c new file +15 -0
+	amber_led = devm_kzalloc(dev, sizeof(*amber_led), GFP_KERNEL);
+	if (!amber_led)
+		return -ENOMEM;
+
+	amber_led->name = devm_kasprintf(dev, GFP_KERNEL, "%s::amber", ec->name);
+	amber_led->max_brightness = 1;
+	amber_led->flags = LED_CORE_SUSPENDRESUME | LED_RETAIN_AT_SHUTDOWN;
+	amber_led->brightness_set = asus_ec_led_set_brightness_amber;
+
+	ret = devm_led_classdev_register(dev, amber_led);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to register amber LED\n");
+
+	green_led = devm_kzalloc(dev, sizeof(*green_led), GFP_KERNEL);
+	if (!green_led)

drivers/leds/leds-asus-ec.c line 81

Quoted 10 lines
drivers/leds/leds-asus-ec.c new file +10 -0
+		return -ENOMEM;
+
+	green_led->name = devm_kasprintf(dev, GFP_KERNEL, "%s::green", ec->name);
+	green_led->max_brightness = 1;
+	green_led->flags = LED_CORE_SUSPENDRESUME | LED_RETAIN_AT_SHUTDOWN;
+	green_led->brightness_set = asus_ec_led_set_brightness_green;
+
+	ret = devm_led_classdev_register(dev, green_led);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to register green LED\n");

Lots of repetition here.

I'd make a sub-function that takes the differences.

Same with the set brightness functions.

Think to yourself - what if I had to support 16 different LEDs?

Quoted 27 lines
drivers/leds/leds-asus-ec.c new file +23 -0
+
+	return 0;
+}
+
+static const struct of_device_id asus_ec_led_match[] = {
+	{ .compatible = "asus,ec-led" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, asus_ec_led_match);
+
+static struct platform_driver asus_ec_led_driver = {
+	.driver = {
+		.name = "asus-ec-led",
+		.of_match_table = asus_ec_led_match,
+	},
+	.probe = asus_ec_led_probe,
+};
+module_platform_driver(asus_ec_led_driver);
+
+MODULE_AUTHOR("Michał Mirosław <[email protected]>");
+MODULE_AUTHOR("Svyatoslav Ryhel <[email protected]>");
+MODULE_DESCRIPTION("ASUS Transformer's charging LED driver");
+MODULE_LICENSE("GPL");
Signature · 1 line
2.51.0
Signature · 1 line
Lee Jones [李琼斯]
#26 lore raw

Re: [PATCH v2 7/9] leds: Add driver for Asus Transformer LEDs

пт, 6 бер. 2026 р. о 12:04 Lee Jones <[email protected]> пише:

Quoted 113 lines · Svyatoslav Ryhel
Quoted 97 lines

From: Michał Mirosław <[email protected]>

Asus Transformer tablets have a green and an amber LED on both the Pad and the Dock. If both LEDs are enabled simultaneously, the emitted light will be yellow.

---
 drivers/leds/Kconfig        |  11 ++++
 drivers/leds/Makefile       |   1 +
 drivers/leds/leds-asus-ec.c | 104 ++++++++++++++++++++++++++++++++++++
 3 files changed, 116 insertions(+)
 create mode 100644 drivers/leds/leds-asus-ec.c
drivers/leds/Kconfig +11 -0
index 597d7a79c988..96dab210f6ca 100644
@@ -120,6 +120,17 @@ config LEDS_OSRAM_AMS_AS3668
        To compile this driver as a module, choose M here: the module
        will be called leds-as3668.
 
+config LEDS_ASUSEC
+     tristate "LED Support for Asus Transformer charging LED"
+     depends on LEDS_CLASS
+     depends on MFD_ASUSEC
+     help
+       This option enables support for charging indicator on
+       Asus Transformer's Pad and it's Dock.
+
+       To compile this driver as a module, choose M here: the module
+       will be called leds-asus-ec.
+
 config LEDS_AW200XX
      tristate "LED support for Awinic AW20036/AW20054/AW20072/AW20108"
      depends on LEDS_CLASS
drivers/leds/Makefile +1 -0
index 8fdb45d5b439..1117304dfdf4 100644
@@ -16,6 +16,7 @@ obj-$(CONFIG_LEDS_AN30259A)         += leds-an30259a.o
 obj-$(CONFIG_LEDS_APU)                       += leds-apu.o
 obj-$(CONFIG_LEDS_ARIEL)             += leds-ariel.o
 obj-$(CONFIG_LEDS_AS3668)            += leds-as3668.o
+obj-$(CONFIG_LEDS_ASUSEC)            += leds-asus-ec.o
 obj-$(CONFIG_LEDS_AW200XX)           += leds-aw200xx.o
 obj-$(CONFIG_LEDS_AW2013)            += leds-aw2013.o
 obj-$(CONFIG_LEDS_BCM6328)           += leds-bcm6328.o
drivers/leds/leds-asus-ec.c new file +40 -0
new file mode 100644
index 000000000000..5dd76c9247ee
@@ -0,0 +1,104 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ASUS EC driver - battery LED
+ */
+
+#include <linux/err.h>
+#include <linux/leds.h>
+#include <linux/mfd/asus-ec.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+/*
+ * F[5] & 0x07
+ *  auto: brightness == 0
+ *  bit 0: blink / charger on
+ *  bit 1: amber on
+ *  bit 2: green on
+ */
+
+#define ASUSEC_CTL_LED_BLINK         BIT_ULL(40)
+#define ASUSEC_CTL_LED_AMBER         BIT_ULL(41)
+#define ASUSEC_CTL_LED_GREEN         BIT_ULL(42)
+
+static void asus_ec_led_set_brightness_amber(struct led_classdev *led,
+                                          enum led_brightness brightness)
+{
+     const struct asusec_info *ec = dev_get_drvdata(led->dev->parent);
+
+     if (brightness)
+             asus_ec_set_ctl_bits(ec, ASUSEC_CTL_LED_AMBER);
+     else
+             asus_ec_clear_ctl_bits(ec, ASUSEC_CTL_LED_AMBER);
+}
+
+static void asus_ec_led_set_brightness_green(struct led_classdev *led,
+                                          enum led_brightness brightness)
+{
+     const struct asusec_info *ec = dev_get_drvdata(led->dev->parent);

drivers/leds/leds-asus-ec.c line 50

Quoted 10 lines
drivers/leds/leds-asus-ec.c new file +10 -0
+
+     if (brightness)
+             asus_ec_set_ctl_bits(ec, ASUSEC_CTL_LED_GREEN);
+     else
+             asus_ec_clear_ctl_bits(ec, ASUSEC_CTL_LED_GREEN);
+}
+
+static int asus_ec_led_probe(struct platform_device *pdev)
+{
+     struct asusec_info *ec = cell_to_ec(pdev);

Please remove all of your abstraction layers. They serve little purpose other than to complicate things. Just use dev_get_drvdata() here.

Quoted 2 lines

Remove the "_info" part and change "ec" to "ddata".

Controller exposes only required stuff, exposing controllers internal parts is not desired. Is there any written convention that driver private data pointer MUST be named "ddata"? "priv" is pretty well fitting to. You are just nitpicking.

Quoted 10 lines

drivers/leds/leds-asus-ec.c line 55

Quoted 5 lines
drivers/leds/leds-asus-ec.c new file +5 -0
+     struct device *dev = &pdev->dev;
+     struct led_classdev *amber_led, *green_led;
+     int ret;
+
+     platform_set_drvdata(pdev, ec);

Wait, what?

Why are you doing that?

This is redundant, yes.

Quoted 28 lines
Quoted 15 lines
drivers/leds/leds-asus-ec.c new file +15 -0
+     amber_led = devm_kzalloc(dev, sizeof(*amber_led), GFP_KERNEL);
+     if (!amber_led)
+             return -ENOMEM;
+
+     amber_led->name = devm_kasprintf(dev, GFP_KERNEL, "%s::amber", ec->name);
+     amber_led->max_brightness = 1;
+     amber_led->flags = LED_CORE_SUSPENDRESUME | LED_RETAIN_AT_SHUTDOWN;
+     amber_led->brightness_set = asus_ec_led_set_brightness_amber;
+
+     ret = devm_led_classdev_register(dev, amber_led);
+     if (ret)
+             return dev_err_probe(dev, ret, "failed to register amber LED\n");
+
+     green_led = devm_kzalloc(dev, sizeof(*green_led), GFP_KERNEL);
+     if (!green_led)

drivers/leds/leds-asus-ec.c line 81

Quoted 10 lines
drivers/leds/leds-asus-ec.c new file +10 -0
+             return -ENOMEM;
+
+     green_led->name = devm_kasprintf(dev, GFP_KERNEL, "%s::green", ec->name);
+     green_led->max_brightness = 1;
+     green_led->flags = LED_CORE_SUSPENDRESUME | LED_RETAIN_AT_SHUTDOWN;
+     green_led->brightness_set = asus_ec_led_set_brightness_green;
+
+     ret = devm_led_classdev_register(dev, green_led);
+     if (ret)
+             return dev_err_probe(dev, ret, "failed to register green LED\n");

Lots of repetition here.

Quoted 6 lines

I'd make a sub-function that takes the differences.

Same with the set brightness functions.

Think to yourself - what if I had to support 16 different LEDs?

That is not of my concern what you would do. I have 2 LEDs and I see no point in "abstraction for he sake of abstraction".

Quoted 30 lines
Quoted 24 lines
drivers/leds/leds-asus-ec.c new file +23 -1
+
+     return 0;
+}
+
+static const struct of_device_id asus_ec_led_match[] = {
+     { .compatible = "asus,ec-led" },
+     { }
+};
+MODULE_DEVICE_TABLE(of, asus_ec_led_match);
+
+static struct platform_driver asus_ec_led_driver = {
+     .driver = {
+             .name = "asus-ec-led",
+             .of_match_table = asus_ec_led_match,
+     },
+     .probe = asus_ec_led_probe,
+};
+module_platform_driver(asus_ec_led_driver);
+
+MODULE_AUTHOR("Michał Mirosław <[email protected]>");
+MODULE_AUTHOR("Svyatoslav Ryhel <[email protected]>");
+MODULE_DESCRIPTION("ASUS Transformer's charging LED driver");
+MODULE_LICENSE("GPL");
--
Quoted 3 lines

2.51.0

--
Lee Jones [李琼斯]

maintainer
#27 lore raw

Re: [PATCH v2 7/9] leds: Add driver for Asus Transformer LEDs

Quoted 19 lines · Svyatoslav Ryhel

пт, 6 бер. 2026 р. о 12:04 Lee Jones <[email protected]> пише:

Quoted 18 lines · Svyatoslav Ryhel
Quoted 16 lines

From: Michał Mirosław <[email protected]>

Asus Transformer tablets have a green and an amber LED on both the Pad and the Dock. If both LEDs are enabled simultaneously, the emitted light will be yellow.

---
 drivers/leds/Kconfig        |  11 ++++
 drivers/leds/Makefile       |   1 +
 drivers/leds/leds-asus-ec.c | 104 ++++++++++++++++++++++++++++++++++++
 3 files changed, 116 insertions(+)
 create mode 100644 drivers/leds/leds-asus-ec.c

[
...]

Quoted 14 lines
Quoted 9 lines

drivers/leds/leds-asus-ec.c line 50

Quoted 3 lines
drivers/leds/leds-asus-ec.c new file +3 -0
+static int asus_ec_led_probe(struct platform_device *pdev)
+{
+     struct asusec_info *ec = cell_to_ec(pdev);

Please remove all of your abstraction layers. They serve little purpose other than to complicate things. Just use dev_get_drvdata() here.

Remove the "_info" part and change "ec" to "ddata".

Controller exposes only required stuff, exposing controllers internal parts is not desired. Is there any written convention that driver private data pointer MUST be named "ddata"? "priv" is pretty well fitting to. You are just nitpicking.

[...]

Quoted 11 lines
Quoted 8 lines

Lots of repetition here.

I'd make a sub-function that takes the differences.

Same with the set brightness functions.

Think to yourself - what if I had to support 16 different LEDs?

That is not of my concern what you would do. I have 2 LEDs and I see no point in "abstraction for he sake of abstraction".

Your attitude stinks!

All of your submissions are now on hold until I can be bothered to look at them again. In the mean time, I suggest you look inward and re-evaluate how you choose to communicate with others.

Signature · 1 line
Lee Jones [李琼斯]
#28 lore raw

PATCH v2 8/9 power: supply: Add driver for Asus Transformer battery

In reply to Svyatoslav Ryhel

From: Michał Mirosław <[email protected]>

Driver implements one battery cell per EC controller and supports reading of battery status for Asus Transformer's pad and mobile dock.

---
 drivers/power/supply/Kconfig           |  11 +
 drivers/power/supply/Makefile          |   1 +
 drivers/power/supply/asus-ec-battery.c | 283 +++++++++++++++++++++++++
 3 files changed, 295 insertions(+)
 create mode 100644 drivers/power/supply/asus-ec-battery.c
drivers/power/supply/Kconfig +11 -0
index 81fadb0695a9..bcf6a23858be 100644
@@ -122,6 +122,17 @@ config BATTERY_CHAGALL
 	  This driver can also be built as a module. If so, the module will be
 	  called chagall-battery.
 
+config BATTERY_ASUSEC
+	tristate "Asus Transformer's battery driver"
+	depends on MFD_ASUSEC
+	help
+	  Say Y here to enable support APM status emulation using
+	  battery class devices.
+
+	  This sub-driver supports battery cells found in Asus Transformer
+	  tablets and mobile docks and controlled by special embedded
+	  controller.
+
 config BATTERY_CPCAP
 	tristate "Motorola CPCAP PMIC battery driver"
 	depends on MFD_CPCAP && IIO
drivers/power/supply/Makefile +1 -0
index 41c400bbf022..0a2cbfa96ed9 100644
@@ -22,6 +22,7 @@ obj-$(CONFIG_TEST_POWER)	+= test_power.o
 obj-$(CONFIG_BATTERY_88PM860X)	+= 88pm860x_battery.o
 obj-$(CONFIG_CHARGER_ADP5061)	+= adp5061.o
 obj-$(CONFIG_BATTERY_ACT8945A)	+= act8945a_charger.o
+obj-$(CONFIG_BATTERY_ASUSEC)	+= asus-ec-battery.o
 obj-$(CONFIG_BATTERY_AXP20X)	+= axp20x_battery.o
 obj-$(CONFIG_CHARGER_AXP20X)	+= axp20x_ac_power.o
 obj-$(CONFIG_BATTERY_CHAGALL)	+= chagall-battery.o
drivers/power/supply/asus-ec-battery.c new file +283 -0

283 lines not on this page · raw message

Signature · 1 line
2.51.0
#29 lore raw

PATCH v2 9/9 power: supply: Add charger driver for Asus Transformers

In reply to Svyatoslav Ryhel

From: Michał Mirosław <[email protected]>

Add support for charger detection capabilities found in the embedded controller of ASUS Transformer devices.

---
 drivers/power/supply/Kconfig           |  11 ++
 drivers/power/supply/Makefile          |   1 +
 drivers/power/supply/asus-ec-charger.c | 206 +++++++++++++++++++++++++
 3 files changed, 218 insertions(+)
 create mode 100644 drivers/power/supply/asus-ec-charger.c
drivers/power/supply/Kconfig +11 -0
index bcf6a23858be..43b902a12795 100644
@@ -497,6 +497,17 @@ config CHARGER_88PM860X
 	help
 	  Say Y here to enable charger for Marvell 88PM860x chip.
 
+config CHARGER_ASUSEC
+	tristate "Asus Transformer's charger driver"
+	depends on MFD_ASUSEC
+	help
+	  Say Y here to enable support AC plug detection on Asus Transformer
+	  Dock.
+
+	  This sub-driver supports charger detection mechanism found in Asus
+	  Transformer tablets and mobile docks and controlled by special
+	  embedded controller.
+
 config CHARGER_PF1550
 	tristate "NXP PF1550 battery charger driver"
 	depends on MFD_PF1550
drivers/power/supply/Makefile +1 -0
index 0a2cbfa96ed9..b93848227f50 100644
@@ -23,6 +23,7 @@ obj-$(CONFIG_BATTERY_88PM860X)	+= 88pm860x_battery.o
 obj-$(CONFIG_CHARGER_ADP5061)	+= adp5061.o
 obj-$(CONFIG_BATTERY_ACT8945A)	+= act8945a_charger.o
 obj-$(CONFIG_BATTERY_ASUSEC)	+= asus-ec-battery.o
+obj-$(CONFIG_CHARGER_ASUSEC)	+= asus-ec-charger.o
 obj-$(CONFIG_BATTERY_AXP20X)	+= axp20x_battery.o
 obj-$(CONFIG_CHARGER_AXP20X)	+= axp20x_ac_power.o
 obj-$(CONFIG_BATTERY_CHAGALL)	+= chagall-battery.o
drivers/power/supply/asus-ec-charger.c new file +206 -0

206 lines not on this page · raw message

Signature · 1 line
2.51.0