mfd: Add support for Asus Transformer embedded controller
Subsystems (6)
v7 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
Changes in v3:
- dropped DockRAM commits (both schema and driver)
- integrated DockRAM functionality directly into the controller driver
- EC schema moved to embedded controllers folder
- removed all cell descriptions from the schema
- removed all compatibles from the cell drivers
- adjusted naming conventions to better align with the ASUS Transformers
- defined EC variant sets to provide coverage for all known devices
Changes in v4:
- grouped known programming models of EC chronologically (both schema and driver)
- call debugfs init only if CONFIG_DEBUG_FS is enabled
Changes in v5:
- added asus,tf600t-ec-dock compatible to schema
- rebased on top of v7.0
- kzalloc > kzalloc_obj in keys and kbc
Changes in v6:
- removed asus_ec_handle_smi casting
- asus_dockram_access_ctl > asus_ec_get_ctl in control_reg_*
- fixed battery Kconfig description
Changes in v7:
- added status check of devm_kasprintf where missing
- devm_asus_ec_register_notifier dropped, added .remove where it was used
- removed cell_to_ec, asus_dockram_read, asus_dockram_write, asus_ec_* public API asus_ec_i2c_command, devm_asus_ec_register_notifier, asus_ec_read, asus_ec_write
- renamed asusec_info > asusec_core
- ec-kbc: added packed size check
ret > error
improved key remap logic
- ec-keys: improve formatting and comments
ret > error
switched to dev_err_probe
- ec-leds: reworked to register both leds via loop
- ec-mfd: adjusted Kconfig description
fixed smbus operation sizes
fixed saving of EC fw model
adjusted IRQ flags
converted to use definer for set cell composition
added factory mode states enum and handling
defined some "magic" values
self > client, info > ec, ecreq > ecreq_gpio, priv > ddata asus_ec_chip_data data > asus_ec_chip_info info
ec_data > ec_buf, ctl_data > ctl_buf
added and improved comments, added structure descriptions asus_ec_magic_debug > asus_ec_susb_on_status
removed all dev_dbg and most of dev_info
pronts with model, fw behavior, factory and susb state preserved switched to MFD_CELL_* macros
removed debugfs
- ec-battery: swithced to BIT macro
lock usage moved to asus_ec_battery_get_value
in asus_ec_battery_poll_work fixed possible rescheduling fail in asus_ec_battery_poll_work fixed missing not charging
- ec-charger: POWER_SUPPLY_PROP_MODEL_NAME set as the first check
---
Michał Mirosław (6):
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 (1):
dt-bindings: embedded-controller: document ASUS Transformer EC
.../asus,tf201-ec-pad.yaml | 119 ++++ drivers/input/keyboard/Kconfig | 10 + drivers/input/keyboard/Makefile | 1 + .../input/keyboard/asus-transformer-ec-keys.c | 281 +++++++++ drivers/input/serio/Kconfig | 15 + drivers/input/serio/Makefile | 1 + drivers/input/serio/asus-transformer-ec-kbc.c | 157 +++++ drivers/leds/Kconfig | 11 + drivers/leds/Makefile | 1 + drivers/leds/leds-asus-transformer-ec.c | 109 ++++ drivers/mfd/Kconfig | 16 + drivers/mfd/Makefile | 1 + drivers/mfd/asus-transformer-ec.c | 534 ++++++++++++++++++ drivers/power/supply/Kconfig | 22 + drivers/power/supply/Makefile | 2 + .../supply/asus-transformer-ec-battery.c | 286 ++++++++++ .../supply/asus-transformer-ec-charger.c | 207 +++++++ include/linux/mfd/asus-transformer-ec.h | 92 +++ 18 files changed, 1865 insertions(+) create mode 100644 Documentation/devicetree/bindings/embedded-controller/asus,tf201-ec-pad.yaml create mode 100644 drivers/input/keyboard/asus-transformer-ec-keys.c create mode 100644 drivers/input/serio/asus-transformer-ec-kbc.c create mode 100644 drivers/leds/leds-asus-transformer-ec.c create mode 100644 drivers/mfd/asus-transformer-ec.c create mode 100644 drivers/power/supply/asus-transformer-ec-battery.c create mode 100644 drivers/power/supply/asus-transformer-ec-charger.c create mode 100644 include/linux/mfd/asus-transformer-ec.h
Signature · 1 line
2.51.0
PATCH v7 1/7 dt-bindings: embedded-controller: document ASUS Transformer EC
Document embedded controller used in ASUS Transformer device series.
--- .../asus,tf201-ec-pad.yaml | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 Documentation/devicetree/bindings/embedded-controller/asus,tf201-ec-pad.yaml
Documentation/devicetree/bindings/embedded-controller/asus,tf201-ec-pad.yaml new file +119 -0
@@ -0,0 +1,119 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/embedded-controller/asus,tf201-ec-pad.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: ASUS Transformer's Embedded Controller + +description: + Several Nuvoton based Embedded Controllers attached to an I2C bus, + running a custom ASUS firmware, specific to the ASUS Transformer + device series. + +maintainers: + - Svyatoslav Ryhel <[email protected]> + +properties: + compatible: + description: + The 'pad' suffix is used for the controller within the tablet, while + the 'dock' suffix refers to the controller in the mobile dock keyboard. + oneOf: + - enum: + - asus,sl101-ec-dock + - asus,tf101-ec-dock + - asus,tf201-ec-pad + - asus,tf600t-ec-dock + - asus,tf600t-ec-pad + + - items: + - enum: + - asus,tf101g-ec-dock + - asus,tf201-ec-dock + - asus,tf300t-ec-dock + - asus,tf300tg-ec-dock + - asus,tf300tl-ec-dock + - asus,tf700t-ec-dock + - const: asus,tf101-ec-dock + + - items: + - enum: + - asus,tf300t-ec-pad + - asus,tf300tg-ec-pad + - asus,tf300tl-ec-pad + - asus,tf700t-ec-pad + - const: asus,tf201-ec-pad + + - items: + - enum: + - asus,tf701t-ec-dock + - const: asus,tf600t-ec-dock + + - items: + - enum: + - asus,p1801-t-ec-pad + - asus,tf701t-ec-pad + - const: asus,tf600t-ec-pad + + 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 + + interrupts: + maxItems: 1 + + request-gpios: + maxItems: 1 + +required: + - compatible + - reg + - reg-names + +allOf: + - $ref: /schemas/power/supply/power-supply.yaml + - if: + properties: + compatible: + not: + contains: + const: asus,tf600t-ec-dock + then: + required: + - interrupts + - request-gpios + +unevaluatedProperties: 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,tf201-ec-dock", "asus,tf101-ec-dock"; + reg = <0x19>, <0x1b>; + reg-names = "ec", "dockram"; + + interrupt-parent = <&gpio>; + interrupts = <151 IRQ_TYPE_LEVEL_LOW>; + + request-gpios = <&gpio 134 GPIO_ACTIVE_LOW>; + + monitored-battery = <&dock_battery>; + }; + }; +...
Signature · 1 line
2.51.0
[email protected]
AI reviewRe: [PATCH v7 1/7] dt-bindings: embedded-controller: document ASUS Transformer EC
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The `reg` property specifies `minItems: 2` but is missing an explicit `maxItems: 2` constraint or…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The reg property specifies minItems: 2 but is missing an explicit maxItems: 2 constraint or an items array definition. --
commit 1a4f9a19859ef3d1429d7fbcebe0842f0c3684af
Author: Svyatoslav Ryhel <[email protected]>
dt-bindings: embedded-controller: document ASUS Transformer EC
This commit adds device tree binding documentation for the embedded controller used in the ASUS Transformer device series. The controllers are attached to an I2C bus and run custom ASUS firmware.
Quoted 5 lines
Documentation/devicetree/bindings/embedded-controller/asus,tf201-ec-pad.yaml new file +0
-0
[ ... ]
Documentation/devicetree/bindings/embedded-controller/asus,tf201-ec-pad.yaml line 64
Quoted 6 lines
Documentation/devicetree/bindings/embedded-controller/asus,tf201-ec-pad.yaml new file +6
-0+ 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
Does this property need an explicit maxItems: 2 constraint or an items array definition to properly bound the schema?
Documentation/devicetree/bindings/embedded-controller/asus,tf201-ec-pad.yaml line 69
Quoted 5 lines
Documentation/devicetree/bindings/embedded-controller/asus,tf201-ec-pad.yaml new file +5
-0+ + reg-names: + items: + - const: ec + - const: dockram
While the reg-names property correctly defines exactly two expected names, without an explicit upper bound or items array, the reg property definition might be incomplete according to standard dt-binding conventions.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v7 2/7 mfd: Add driver for ASUS Transformer embedded controller
In reply to Svyatoslav RyhelFrom: 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 | 16 + drivers/mfd/Makefile | 1 + drivers/mfd/asus-transformer-ec.c | 534 ++++++++++++++++++++++++ include/linux/mfd/asus-transformer-ec.h | 92 ++++ 4 files changed, 643 insertions(+) create mode 100644 drivers/mfd/asus-transformer-ec.c create mode 100644 include/linux/mfd/asus-transformer-ec.h
drivers/mfd/Kconfig +16 -0
@@ -137,6 +137,22 @@ config MFD_AAT2870_CORE additional drivers must be enabled in order to use the functionality of the device. +config MFD_ASUS_TRANSFORMER_EC + tristate "ASUS Transformer's embedded controller" + select MFD_CORE + depends on I2C && OF + help + Select this to enable support for the Embedded Controller (EC) + found in Tegra based ASUS Transformer series tablets and mobile + docks. + + This driver handles the core I2C communication with the EC and + provides support for its sub-devices, including battery management, + charger detection, LEDs and keyboard dock functions support. + + This driver can also be built as a module. If so, the module + will be called asus-transformer-ec. + config MFD_AT91_USART tristate "AT91 USART Driver" select MFD_CORE
drivers/mfd/Makefile +1 -0
@@ -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_ASUS_TRANSFORMER_EC) += asus-transformer-ec.o obj-$(CONFIG_ARCH_BCM2835) += bcm2835-pm.o obj-$(CONFIG_MFD_BCM590XX) += bcm590xx.o obj-$(CONFIG_MFD_BD9571MWV) += bd9571mwv.o
drivers/mfd/asus-transformer-ec.c new file +534 -0
534 lines not on this page · raw message
include/linux/mfd/asus-transformer-ec.h new file +92 -0
92 lines not on this page · raw message
Signature · 1 line
2.51.0
[email protected]
AI reviewRe: [PATCH v7 2/7] mfd: Add driver for ASUS Transformer embedded controller
Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider: - [High] Unsynchronized reallocation of `ddata->ec.model` causes Use-After-Free during interrupts. - [High]…
Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider:
- [High] Unsynchronized reallocation of ddata->ec.model causes Use-After-Free during interrupts.
- [High] Stale and uninitialized data is accessed on short I2C reads.
- [Medium] asus_dockram_access_ctl() silently ignores I2C write errors.
- [Medium] Memory leak of ddata->ec.model upon driver unbind or probe failure.
- [Medium] The original IRQ event payload is corrupted before being passed to child notifiers.
- [Medium] Subsystem Guideline Violation: Mixing goto error handling with __free() cleanup.
- [Medium] Missing error check for kstrndup() allocation failure in asus_ec_log_info().
- [Low] Incorrect length check causes string truncation in asus_ec_log_info(). --
commit d95a94a77b9b37ec021eabccb7ff81e4dd52730e
Author: Michał Mirosław <[email protected]>
mfd: Add driver for ASUS Transformer embedded controller
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.
Quoted 5 lines
drivers/mfd/asus-transformer-ec.c new file +0
-0
[ ... ]
drivers/mfd/asus-transformer-ec.c line 139
Quoted 9 lines
drivers/mfd/asus-transformer-ec.c new file +9
-0+if (mask || xor) { +put_unaligned_le64 ((val & ~mask) ^ xor, buf +1 ); + ret =i2c_smbus_write_i2c_block_data (client, +ASUSEC_DOCKRAM_CONTROL , +DOCKRAM_ENTRY_SIZE , buf); + } + +return 0 ; +}
Does this accidentally hide hardware write failures? Since ret is ignored, callers might falsely assume the I2C block write succeeded.
[ ... ]
Quoted 7 lines
drivers/mfd/asus-transformer-ec.c new file +7
-0+static void asus_ec_clear_buffer (struct asus_ec_data *ddata) +{ +int ret, retry =ASUSEC_RSP_BUFFER_SIZE ; + +/* +* Read the buffer till we get valid data by checking ASUSEC_OBF_MASK +* of the status byte or till we reach end of the 256 byte buffer.
drivers/mfd/asus-transformer-ec.c line 171
Quoted 10 lines
drivers/mfd/asus-transformer-ec.c new file +10
-0+*/ +while (retry--) { + ret =i2c_smbus_read_i2c_block_data (ddata->client,ASUSEC_READ_BUF , +sizeof (ddata->ec_buf), + ddata->ec_buf); +if (ret <0 ) +continue ; + +if (ddata->ec_buf[ASUSEC_IRQ_STATUS ] &ASUSEC_OBF_MASK ) +continue ;
Can a short read leave stale data in ddata->ec_buf? The function i2c_smbus_read_i2c_block_data() returns the actual number of bytes read. If it returns a positive value less than ASUSEC_IRQ_STATUS + 1, the buffer will retain data from previous iterations.
[ ... ]
Quoted 8 lines
drivers/mfd/asus-transformer-ec.c new file +8
-0+static int asus_ec_log_info (struct asus_ec_data *ddata,unsigned int reg, +const char *name,char **out) +{ +struct device *dev = &ddata->client->dev; +u8 buf[DOCKRAM_ENTRY_BUFSIZE ]; +int ret; + +memset (buf,0 ,DOCKRAM_ENTRY_BUFSIZE );
drivers/mfd/asus-transformer-ec.c line 194
Quoted 10 lines
drivers/mfd/asus-transformer-ec.c new file +10
-0+ ret =i2c_smbus_read_i2c_block_data (ddata->ec.dockram, reg, +DOCKRAM_ENTRY_SIZE , buf); +if (ret <0 ) +return ret; + +if (buf[0 ] >DOCKRAM_ENTRY_SIZE ) { +dev_err (dev,"bad data len; buffer: %*ph; ret: %d\n" , +DOCKRAM_ENTRY_BUFSIZE , buf, ret); +return -EPROTO ; + }
Is there a risk of an out-of-bounds read here? The I2C read fills up to 32 bytes (DOCKRAM_ENTRY_SIZE), meaning buf[0] to buf[31] are valid. If buf[0] equals 32, the kstrndup() below will attempt to copy 32 bytes starting from buf + 1, reading up to buf[32].
drivers/mfd/asus-transformer-ec.c line 203
Quoted 9 lines
drivers/mfd/asus-transformer-ec.c new file +9
-0+ +if (!ddata->logging_disabled) +dev_info (dev,"%-14s: %.*s\n" , name, buf[0 ], buf +1 ); + +if (out) + *out =kstrndup (buf +1 , buf[0 ],GFP_KERNEL ); + +return 0 ; +}
If kstrndup() fails and returns NULL, asus_ec_detect() will unknowingly assign NULL to ddata->ec.model. Should this return -ENOMEM on allocation failure?
[ ... ]
drivers/mfd/asus-transformer-ec.c line 259
Quoted 8 lines
drivers/mfd/asus-transformer-ec.c new file +8
-0+static int asus_ec_detect (struct asus_ec_data *ddata) +{ + char *model __free(kfree) = NULL; +int ret; + + ret =asus_ec_reset (ddata); +if (ret) + goto err_exit;
This isn't a bug, but mixing goto error handling with __free() cleanup in the same function violates the subsystem guidelines. Functions are expected to use either scope-based cleanup or goto-based cleanup exclusively to prevent confusing ownership semantics.
[ ... ]
drivers/mfd/asus-transformer-ec.c line 289
Quoted 8 lines
drivers/mfd/asus-transformer-ec.c new file +8
-0+/* Check and inform about EC firmware behavior */ + ret =asus_ec_susb_on_status (ddata); +if (ret) + goto err_exit; + +kfree (ddata->ec.model); + + ddata->ec.model =no_free_ptr (model);
Could this cause a use-after-free or a memory leak?
Since asus_ec_detect() can be called from the threaded interrupt handler at runtime, ddata->ec.model might be freed and replaced without synchronization while child drivers or sysfs attributes are concurrently accessing it.
Additionally, ddata->ec.model is never freed on driver unbind or probe failure, causing a memory leak.
[ ... ]
drivers/mfd/asus-transformer-ec.c line 322
Quoted 10 lines
drivers/mfd/asus-transformer-ec.c new file +10
-0+static irqreturn_t asus_ec_interrupt (int irq,void *dev_id) +{ +struct asus_ec_data *ddata = dev_id; +unsigned long notify_action; +int ret; + + ret =i2c_smbus_read_i2c_block_data (ddata->client,ASUSEC_READ_BUF , +sizeof (ddata->ec_buf), ddata->ec_buf); +if (ret <=0 || !(ddata->ec_buf[ASUSEC_IRQ_STATUS ] &ASUSEC_OBF_MASK )) +return IRQ_NONE ;
Similar to asus_ec_clear_buffer(), if ret is a positive value smaller than the required length, this could process stale data from previous interrupt events.
Quoted 5 lines
drivers/mfd/asus-transformer-ec.c new file +5
-0+ + notify_action = ddata->ec_buf[ASUSEC_IRQ_STATUS ]; +if (notify_action &ASUSEC_SMI_MASK ) { +unsigned int code = ddata->ec_buf[ASUSEC_SMI_CODE ]; +
drivers/mfd/asus-transformer-ec.c line 337
Quoted 10 lines
drivers/mfd/asus-transformer-ec.c new file +10
-0+asus_ec_handle_smi (ddata, code); + + notify_action |= code <<8 ; + } + +blocking_notifier_call_chain (&ddata->ec.notify_list, + notify_action, ddata->ec_buf); + +return IRQ_HANDLED ; +}
Does asus_ec_handle_smi() corrupt the event payload before it is passed to child notifiers?
If asus_ec_handle_smi() triggers a reset, it eventually calls asus_ec_clear_buffer(), which performs new I2C reads directly into ddata->ec_buf. This overwrites the original event data, meaning blocking_notifier_call_chain() will pass a clobbered buffer to child devices.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH v7 3/7 input: serio: Add driver for ASUS Transformer dock keyboard and touchpad
In reply to Svyatoslav RyhelFrom: 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-transformer-ec-kbc.c | 157 ++++++++++++++++++ 3 files changed, 173 insertions(+) create mode 100644 drivers/input/serio/asus-transformer-ec-kbc.c
drivers/input/serio/Kconfig +15 -0
@@ -84,6 +84,21 @@ config SERIO_RPCKBD To compile this driver as a module, choose M here: the module will be called rpckbd. +config SERIO_ASUS_TRANSFORMER_EC + tristate "Asus Transformer's Dock keyboard and touchpad controller" + depends on MFD_ASUS_TRANSFORMER_EC + 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-transformer-ec-kbc. + config SERIO_AMBAKMI tristate "AMBA KMI keyboard controller" depends on ARM_AMBA
drivers/input/serio/Makefile +1 -0
@@ -12,6 +12,7 @@ obj-$(CONFIG_SERIO_SERPORT) += serport.o obj-$(CONFIG_SERIO_RPCKBD) += rpckbd.o obj-$(CONFIG_SERIO_SA1111) += sa1111ps2.o obj-$(CONFIG_SERIO_AMBAKMI) += ambakmi.o +obj-$(CONFIG_SERIO_ASUS_TRANSFORMER_EC) += asus-transformer-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-transformer-ec-kbc.c new file +157 -0
157 lines not on this page · raw message
Signature · 1 line
2.51.0
[email protected]
AI reviewRe: [PATCH v7 3/7] input: serio: Add driver for ASUS Transformer dock keyboard and touchpad
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] Sleeping in atomic context due to synchronous I2C transfer in serio->write callback. - [High]…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Sleeping in atomic context due to synchronous I2C transfer in serio->write callback.
- [High] Off-by-one error in packet length calculation causes a buffer over-read and breaks keycode remapping.
- [Medium] In-place modification of a shared notifier data buffer.
--
commit 3c9b2bf0acd20a594f17d65b0d6fd9762329b3bc
Author: Michał Mirosław <[email protected]>
input: serio: Add driver for ASUS Transformer dock keyboard and touchpad
This commit adds a serio input driver for the ASUS Transformer dock keyboard and touchpad. It registers serio ports that act as a bridge over I2C and remaps specific keycodes according to their position.
Quoted 5 lines
drivers/input/serio/asus-transformer-ec-kbc.c new file +0
-0
[ ... ]
Quoted 16 lines
drivers/input/serio/asus-transformer-ec-kbc.c new file +16
-0+static int asus_ec_kbc_notify (struct notifier_block *nb, +unsigned long action,void *data_) +{ + struct asus_ec_kbc_data *priv = container_of(nb, struct asus_ec_kbc_data, nb); +unsigned int port_idx, n; +u8 *data = data_; + +if (action & (ASUSEC_SMI_MASK |ASUSEC_SCI_MASK )) +return NOTIFY_DONE ; +else if (action &ASUSEC_AUX_MASK ) + port_idx =1 ; +else if (action & (ASUSEC_KBC_MASK |ASUSEC_KEY_MASK )) + port_idx =0 ; +else +return NOTIFY_DONE ; +
drivers/input/serio/asus-transformer-ec-kbc.c line 43
Quoted 10 lines
drivers/input/serio/asus-transformer-ec-kbc.c new file +10
-0+/* +* The data[0] is the length of the packet including itself. It has to +* be at least 2 bytes (length + 1 data byte) and must not exceed +* the EC buffer size. +*/ +if (data[0 ] <2 || data[0 ] >DOCKRAM_ENTRY_BUFSIZE ) +return NOTIFY_BAD ; + + n = data[0 ] -1 ; + data +=2 ;
Is the payload length calculation off by one?
The comment states data[0] is the length of the packet including itself. The code then skips two bytes (data += 2), which suggests the payload starts at offset 2. If the payload length is data[0] - 2, will setting n = data[0] - 1 cause the loop at the end of the function to read one byte past the actual payload and inject garbage data into the serio port?
If an external device sends a packet with data[0] == DOCKRAM_ENTRY_BUFSIZE, could this off-by-one error cause an out-of-bounds read past the end of the EC buffer array?
Additionally, will this artificially inflated n cause the exact-length validation in the key remapping logic (if (n == 2 ...) and if (n == 3 ...)) to always fail for valid payload sequences, breaking the layout translation?
drivers/input/serio/asus-transformer-ec-kbc.c line 56
Quoted 13 lines
drivers/input/serio/asus-transformer-ec-kbc.c new file +13
-0+ +if (port_idx ==0 ) { +/* +* Remap keyboard key codes to match AT layout: +* SEARCH: RIGHT-META [E0 27] -> LEFT-ALT [11] +* MENU: COMPOSE [E0 2F] -> RIGHT-META [E0 27] +*/ +if ((n ==2 || (n ==3 && data[1 ] ==0xF0 )) && data[0 ] ==0xE0 ) { +u8 *keycode = &data[n -1 ]; + +switch (*keycode) { +case 0x27 : + *keycode =0x11 ;
Is it safe to modify the data_ buffer in place?
Since data_ is passed to this function via the notifier chain, it points to a shared event buffer that is broadcast to all registered listeners. Will modifying this payload permanently corrupt the event data for any downstream notifiers that might inspect the packet subsequently?
Quoted 12 lines
drivers/input/serio/asus-transformer-ec-kbc.c new file +12
-0+ ++data; + --n; +break ; +case 0x2F : + *keycode =0x27 ; +break ; + } + } + } + +while (n--) +serio_interrupt (priv->sdev[port_idx], *data++,0 );
drivers/input/serio/asus-transformer-ec-kbc.c line 78
Quoted 10 lines
drivers/input/serio/asus-transformer-ec-kbc.c new file +10
-0+ +return NOTIFY_OK ; +} + +static int asus_ec_serio_write (struct serio *port,unsigned char data) +{ +struct asus_ec_kbc_data *priv = port->port_data; + +return i2c_smbus_write_word_data (priv->parent,ASUSEC_WRITE_BUF , + (data <<8 ) | port->id.extra);
Can this sleep while in an atomic context?
i2c_smbus_write_word_data() performs a synchronous I2C transaction which acquires mutexes and can sleep. However, serio->write callbacks can be invoked from atomic contexts.
For example, asus_ec_kbc_notify() calls serio_interrupt() which acquires a spinlock and disables interrupts:
serio_interrupt()
spin_lock_irqsave(&serio->lock, flags);
serio->drv->interrupt()
serio_write()
asus_ec_serio_write()
i2c_smbus_write_word_data()Will this trigger a scheduling-while-atomic panic if the input driver issues a command back to the port while the spinlock is held?
Quoted 1 line
+}
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
PATCH v7 4/7 input: keyboard: Add driver for ASUS Transformer dock multimedia keys
In reply to Svyatoslav RyhelFrom: 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 + .../input/keyboard/asus-transformer-ec-keys.c | 281 ++++++++++++++++++ 3 files changed, 292 insertions(+) create mode 100644 drivers/input/keyboard/asus-transformer-ec-keys.c
drivers/input/keyboard/Kconfig +10 -0
@@ -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_ASUS_TRANSFORMER_EC + tristate "Asus Transformer's Mobile Dock multimedia keys" + depends on MFD_ASUS_TRANSFORMER_EC + 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-transformer-ec-keys. + config KEYBOARD_ATARI tristate "Atari keyboard" depends on ATARI
drivers/input/keyboard/Makefile +1 -0
@@ -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_ASUS_TRANSFORMER_EC) += asus-transformer-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-transformer-ec-keys.c new file +281 -0
281 lines not on this page · raw message
Signature · 1 line
2.51.0
[email protected]
AI reviewRe: [PATCH v7 4/7] input: keyboard: Add driver for ASUS Transformer dock multimedia keys
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Registering a statically allocated `struct input_handler` in the per-device probe function…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Registering a statically allocated struct input_handler in the per-device probe function violates the driver model and causes list corruption.
- [High] The input handler permanently opens all EV_KEY input devices in the system without declaring itself as a passive observer, preventing runtime suspend. --
commit 3ac5537da45198a85ba82452de2c64484baeac36
Author: Michał Mirosław <[email protected]>
input: keyboard: Add driver for ASUS Transformer dock multimedia keys
This adds support for the multimedia top button row of the ASUS Transformer Mobile Dock keyboard. It defaults to function keys (F1-F12) and uses an input handler to monitor system-wide key events to switch to multimedia keys when ScreenLock + AltGr are pressed.
Quoted 5 lines
drivers/input/keyboard/asus-transformer-ec-keys.c new file +0
-0
[ ... ]
Quoted 6 lines
drivers/input/keyboard/asus-transformer-ec-keys.c new file +6
-0+static int asus_ec_input_connect (struct input_handler *handler, +struct input_dev *dev, +const struct input_device_id *id) +{ +struct input_handle *handle; +int error;
[ ... ]
Quoted 5 lines
drivers/input/keyboard/asus-transformer-ec-keys.c new file +5
-0+ error =input_open_device (handle); +if (error) + goto err_unregister_handle; + +return 0 ;
[ ... ]
drivers/input/keyboard/asus-transformer-ec-keys.c line 88
Quoted 7 lines
drivers/input/keyboard/asus-transformer-ec-keys.c new file +7
-0+static struct input_handler asus_ec_input_handler = { + .name ="asusec-media-handler" , + .event = asus_ec_input_event, + .connect = asus_ec_input_connect, + .disconnect = asus_ec_input_disconnect, + .id_table = asus_ec_input_ids, +};
Because this handler connects to all EV_KEY devices and calls input_open_device() without setting .passive_observer = true, will this increment the dev->users count for every matching input device in the system?
Could this force all EV_KEY input devices to remain open and active permanently, preventing them from entering runtime suspend?
[ ... ]
Quoted 2 lines
drivers/input/keyboard/asus-transformer-ec-keys.c new file +2
-0+static int asus_ec_keys_probe (struct platform_device *pdev) +{
[ ... ]
drivers/input/keyboard/asus-transformer-ec-keys.c line 250
Quoted 4 lines
drivers/input/keyboard/asus-transformer-ec-keys.c new file +4
-0+ asus_ec_input_handler.private = priv; + error =input_register_handler (&asus_ec_input_handler); +if (error) +return error;
Since asus_ec_input_handler is a static global structure, what happens if this driver is probed multiple times (for instance, via sysfs bind/unbind or multiple ECs)?
If input_register_handler() is called a second time, it will re-initialize the list head and add an already linked node. Could this corrupt the input_handler_list?
Should the input_handler be dynamically allocated per-device or embedded within struct asus_ec_keys_data?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
PATCH v7 5/7 leds: Add driver for ASUS Transformer LEDs
In reply to Svyatoslav RyhelFrom: 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-transformer-ec.c | 109 ++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 drivers/leds/leds-asus-transformer-ec.c
drivers/leds/Kconfig +11 -0
@@ -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_ASUS_TRANSFORMER_EC + tristate "LED Support for Asus Transformer charging LED" + depends on LEDS_CLASS + depends on MFD_ASUS_TRANSFORMER_EC + 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-transformer-ec. + config LEDS_AW200XX tristate "LED support for Awinic AW20036/AW20054/AW20072/AW20108" depends on LEDS_CLASS
drivers/leds/Makefile +1 -0
@@ -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_ASUS_TRANSFORMER_EC) += leds-asus-transformer-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-transformer-ec.c new file +109 -0
109 lines not on this page · raw message
Signature · 1 line
2.51.0
[email protected]
AI reviewRe: [PATCH v7 5/7] leds: Add driver for ASUS Transformer LEDs
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] Incorrect use of `LED_CORE_SUSPENDRESUME` for charging indicators. - [Medium] Lack of hardware…
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] Incorrect use of LED_CORE_SUSPENDRESUME for charging indicators.
- [Medium] Lack of hardware state synchronization (brightness_get) at initialization.
- [Medium] Missing MODULE_ALIAS prevents automatic module loading.
- [Low] The driver exposes a physical bi-color LED as two independent single-color LED devices instead of utilizing the LED Multicolor class. --
commit f02de4369b03c2d6785dea5fb4edfab53036130d
Author: Michał Mirosław <[email protected]>
leds: Add driver for ASUS Transformer LEDs
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.
Quoted 3 lines
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.
Since this describes a physically multi-color LED, shouldn't the driver use the LED Multicolor class API (CONFIG_LEDS_CLASS_MULTICOLOR) instead of exposing them as two separate single-color LED devices?
Quoted 5 lines
drivers/leds/leds-asus-transformer-ec.c new file +0
-0
[ ... ]
drivers/leds/leds-asus-transformer-ec.c line 84
Quoted 12 lines
drivers/leds/leds-asus-transformer-ec.c new file +12
-0+for (i =0 ; i <ASUSEC_LED_MAX ; i++) { +const struct asus_ec_led_config *cfg = &asus_ec_leds[i]; +struct asus_ec_led *led = &ddata->leds[i]; + + led->cdev.name =devm_kasprintf (dev,GFP_KERNEL ,"%s::%s" , + ddata->ec->name, cfg->name); +if (!led->cdev.name) +return -ENOMEM ; + + led->cdev.max_brightness =1 ; + led->cdev.color = cfg->color; + led->cdev.flags =LED_CORE_SUSPENDRESUME |LED_RETAIN_AT_SHUTDOWN ;
Does LED_CORE_SUSPENDRESUME make sense for a charging indicator?
This flag instructs the LED core to explicitly turn off the LED during suspend, which turns off the charging indicator while the device is sleeping.
Also, could the Embedded Controller have already turned the LED on before the driver probes?
Since there is no brightness_get callback to synchronize the initial hardware state, the LED core will initialize the software brightness to 0. If the device resumes from suspend, the LED core will restore this saved brightness of 0, permanently turning off the LED even if it was physically on before.
[ ... ]
drivers/leds/leds-asus-transformer-ec.c line 109
Quoted 10 lines
drivers/leds/leds-asus-transformer-ec.c new file +10
-0+static struct platform_driver asus_ec_led_driver = { + .driver.name ="asus-transformer-ec-led" , + .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" );
Will this module load automatically when the platform device is registered?
Since there is no MODULE_ALIAS("platform:asus-transformer-ec-led") declaration, udev might not be able to automatically load the module during boot when the MFD core registers the corresponding platform device.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
PATCH v7 6/7 power: supply: Add driver for ASUS Transformer battery
In reply to Svyatoslav RyhelFrom: 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 + .../supply/asus-transformer-ec-battery.c | 286 ++++++++++++++++++ 3 files changed, 298 insertions(+) create mode 100644 drivers/power/supply/asus-transformer-ec-battery.c
drivers/power/supply/Kconfig +11 -0
@@ -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_ASUS_TRANSFORMER_EC + tristate "Asus Transformer's battery driver" + depends on MFD_ASUS_TRANSFORMER_EC + help + Say Y to enable support for battery status access on Tegra based + ASUS Transformer devices. + + This sub-driver supports battery cells found in Asus Transformer + tablets and mobile docks and controlled by a special embedded + controller. + config BATTERY_CPCAP tristate "Motorola CPCAP PMIC battery driver" depends on MFD_CPCAP && IIO
drivers/power/supply/Makefile +1 -0
@@ -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_ASUS_TRANSFORMER_EC) += asus-transformer-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-transformer-ec-battery.c new file +286 -0
286 lines not on this page · raw message
Signature · 1 line
2.51.0
[email protected]
AI reviewRe: [PATCH v7 6/7] power: supply: Add driver for ASUS Transformer battery
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] The driver lacks a MODULE_ALIAS declaration, which breaks module autoloading. - [Low] Missing…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The driver lacks a MODULE_ALIAS declaration, which breaks module autoloading.
- [Low] Missing NULL check for the devm_kasprintf allocation of the power supply name. --
commit ccc69cbdb16bd3e704318f7d07abbad8dc370844
Author: Michał Mirosław <[email protected]>
power: supply: Add driver for ASUS Transformer battery
This commit introduces a new power supply driver for the ASUS Transformer battery. It communicates with the embedded controller via I2C to read battery status for both the tablet and mobile dock.
Quoted 5 lines
drivers/power/supply/asus-transformer-ec-battery.c new file +0
-0
[ ... ]
Quoted 2 lines
drivers/power/supply/asus-transformer-ec-battery.c new file +2
-0+static int asus_ec_battery_probe (struct platform_device *pdev) +{
[ ... ]
drivers/power/supply/asus-transformer-ec-battery.c line 239
Quoted 11 lines
drivers/power/supply/asus-transformer-ec-battery.c new file +11
-0+ cfg.fwnode =dev_fwnode (dev->parent); + cfg.drv_data = priv; + +memcpy (&priv->psy_desc, &asus_ec_battery_desc,sizeof (priv->psy_desc)); + priv->psy_desc.name =devm_kasprintf (dev,GFP_KERNEL ,"%s-battery" , + priv->ec->name); + + priv->battery =devm_power_supply_register (dev, &priv->psy_desc, &cfg); +if (IS_ERR (priv->battery)) +return dev_err_probe (dev,PTR_ERR (priv->battery), +"Failed to register power supply\n" );
Is it possible for devm_kasprintf() to fail and return NULL under memory pressure?
If so, priv->psy_desc.name would become NULL, and devm_power_supply_register() would return ERR_PTR(-EINVAL) because it checks for !desc->name. This relies on downstream validation and results in an incorrect error code being propagated for a memory allocation failure instead of -ENOMEM.
Should there be an explicit NULL check here?
[ ... ]
drivers/power/supply/asus-transformer-ec-battery.c line 286
Quoted 13 lines
drivers/power/supply/asus-transformer-ec-battery.c new file +13
-0+static struct platform_driver asus_ec_battery_driver = { + .driver = { + .name ="asus-transformer-ec-battery" , + .pm = &asus_ec_battery_pm_ops, + }, + .probe = asus_ec_battery_probe, +}; +module_platform_driver (asus_ec_battery_driver); + +MODULE_AUTHOR ("Michał Mirosław <[email protected]>" ); +MODULE_AUTHOR ("Svyatoslav Ryhel <[email protected]>" ); +MODULE_DESCRIPTION ("ASUS Transformer's battery driver" ); +MODULE_LICENSE ("GPL" );
Since this platform driver matches devices purely by name ("asus-transformer-ec-battery") and lacks an id_table or of_match_table, will userspace tools like udev be able to automatically load this driver when it is compiled as a module?
Should a MODULE_ALIAS("platform:asus-transformer-ec-battery"); declaration be added to ensure module autoloading works correctly?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
PATCH v7 7/7 power: supply: Add charger driver for Asus Transformers
In reply to Svyatoslav RyhelFrom: 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 + .../supply/asus-transformer-ec-charger.c | 207 ++++++++++++++++++ 3 files changed, 219 insertions(+) create mode 100644 drivers/power/supply/asus-transformer-ec-charger.c
drivers/power/supply/Kconfig +11 -0
@@ -508,6 +508,17 @@ config CHARGER_88PM860X help Say Y here to enable charger for Marvell 88PM860x chip. +config CHARGER_ASUS_TRANSFORMER_EC + tristate "Asus Transformer's charger driver" + depends on MFD_ASUS_TRANSFORMER_EC + 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
@@ -69,6 +69,7 @@ obj-$(CONFIG_CHARGER_RT9471) += rt9471.o obj-$(CONFIG_CHARGER_RT9756) += rt9756.o obj-$(CONFIG_BATTERY_TWL4030_MADC) += twl4030_madc_battery.o obj-$(CONFIG_CHARGER_88PM860X) += 88pm860x_charger.o +obj-$(CONFIG_CHARGER_ASUS_TRANSFORMER_EC) += asus-transformer-ec-charger.o obj-$(CONFIG_CHARGER_PF1550) += pf1550-charger.o obj-$(CONFIG_BATTERY_RX51) += rx51_battery.o obj-$(CONFIG_AB8500_BM) += ab8500_bmdata.o ab8500_charger.o ab8500_fg.o ab8500_btemp.o ab8500_chargalg.o
drivers/power/supply/asus-transformer-ec-charger.c new file +207 -0
207 lines not on this page · raw message
Signature · 1 line
2.51.0
Lee Jones
maintainerQuoted 2 lines · Svyatoslav Ryhel
Add support for embedded controller used in Asus Transformers for managing power and input functions.
Once you have your Input Acks, I'll merge everything through MFD.
Signature · 1 line
Lee Jones
ср, 27 трав. 2026 р. о 17:46 Lee Jones <[email protected]> пише:
Quoted 8 lines · Svyatoslav Ryhel
Quoted 3 lines
Add support for embedded controller used in Asus Transformers for managing power and input functions.
Once you have your Input Acks, I'll merge everything through MFD.
That is awesome news! I have a few minor adjustments to add including input adjustments Dmitry might require.
Quoted 2 lines
--
Lee Jones