mfd: Add support for Asus Transformer embedded controller
Subsystems (6)
v8 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
Changes in v8:
- added MODULE_ALIAS
- renamed DOCKRAM_* to ASUSEC_*
- ec-keys: input_handler moved into private structure
- ec-leds: added brightness_get
- ec-mdf: fixed i2c_smbus_* return checks () improved model storing
- ec-batt: added status check of devm_kasprintf
---
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 | 286 +++++++++ drivers/input/serio/Kconfig | 15 + drivers/input/serio/Makefile | 1 + drivers/input/serio/asus-transformer-ec-kbc.c | 158 +++++ drivers/leds/Kconfig | 11 + drivers/leds/Makefile | 1 + drivers/leds/leds-asus-transformer-ec.c | 125 ++++ drivers/mfd/Kconfig | 16 + drivers/mfd/Makefile | 1 + drivers/mfd/asus-transformer-ec.c | 542 ++++++++++++++++++ drivers/power/supply/Kconfig | 22 + drivers/power/supply/Makefile | 2 + .../supply/asus-transformer-ec-battery.c | 289 ++++++++++ .../supply/asus-transformer-ec-charger.c | 208 +++++++ include/linux/mfd/asus-transformer-ec.h | 92 +++ 18 files changed, 1899 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 v8 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 v8 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 array lacks an explicit upper bound ('maxItems' or 'items' list). --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The 'reg' property array lacks an explicit upper bound ('maxItems' or 'items' list). --
commit 51056b233d45625f7f08ea91a021eae296836600
Author: Svyatoslav Ryhel <[email protected]>
dt-bindings: embedded-controller: document ASUS Transformer EC
This commit documents the embedded controllers used in the ASUS Transformer device series, adding a new YAML binding for the Nuvoton-based controllers found in these tablets and docks.
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
[Severity: Low]
Should this reg property also specify maxItems: 2 or an explicit items array?
While reg-names restricts the size indirectly, standard dt-schema meta-schema rules generally require array properties like reg to define strict upper bounds explicitly to pass make dt_binding_check without warnings.
Quoted 5 lines
Documentation/devicetree/bindings/embedded-controller/asus,tf201-ec-pad.yaml new file +5
-0+ + reg-names: + items: + - const: ec + - const: dockram
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v8 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 | 542 ++++++++++++++++++++++++ include/linux/mfd/asus-transformer-ec.h | 92 ++++ 4 files changed, 651 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 +542 -0
542 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 v8 2/7] mfd: Add driver for ASUS Transformer embedded controller
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Short I2C block reads return positive values or zero, violating API contract and causing false…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Short I2C block reads return positive values or zero, violating API contract and causing false probe success or uninitialized variable usage. --
commit 66708f4a4bcbbc5908e6fc11660dc174e28d7ee4
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 2 lines
drivers/mfd/asus-transformer-ec.c new file +0
-0
[ ... ]
Quoted 7 lines
drivers/mfd/asus-transformer-ec.c new file +7
-0+int asus_dockram_access_ctl (struct i2c_client *client,u64 *out,u64 mask, +u64 xor) +{ +struct dockram_ec_data *ddata =i2c_get_clientdata (client); +u8 *buf = ddata->ctl_buf; +u64 val; +int ret =0 ;
drivers/mfd/asus-transformer-ec.c line 117
Quoted 10 lines
drivers/mfd/asus-transformer-ec.c new file +10
-0+ +guard (mutex)(&ddata->ctl_lock); + +memset (buf,0 ,ASUSEC_ENTRY_BUFSIZE ); + ret =i2c_smbus_read_i2c_block_data (client,ASUSEC_DOCKRAM_CONTROL , +ASUSEC_ENTRY_SIZE , buf); +if (ret <ASUSEC_ENTRY_SIZE ) { +dev_err (&client->dev,"failed to access control buffer: %d\n" , + ret); +return ret;
[Severity: High]
If i2c_smbus_read_i2c_block_data() returns a positive short read, will this return a positive error code?
This positive value could propagate up to asus_ec_probe(). Returning a positive value from probe causes __device_attach_driver() to interpret it as a successful match and probe, leaving the device in an unbound, broken state without a proper failure log.
Additionally, if it returns 0, the function will return success (0) without populating output variables, potentially leading to uninitialized memory usage in callers like asus_ec_susb_on_status().
Quoted 3 lines
drivers/mfd/asus-transformer-ec.c new file +3
-0+ } + +if (buf[0 ] !=ASUSEC_CTL_SIZE ) {
[ ... ]
drivers/mfd/asus-transformer-ec.c line 190
Quoted 12 lines
drivers/mfd/asus-transformer-ec.c new file +12
-0+static int asus_ec_log_info (struct asus_ec_data *ddata,unsigned int reg, +const char *name,const char **out) +{ +struct device *dev = &ddata->client->dev; +u8 buf[ASUSEC_ENTRY_BUFSIZE ]; +int ret; + +memset (buf,0 ,ASUSEC_ENTRY_BUFSIZE ); + ret =i2c_smbus_read_i2c_block_data (ddata->ec.dockram, reg, +ASUSEC_ENTRY_SIZE , buf); +if (ret <ASUSEC_ENTRY_SIZE ) +return ret;
[Severity: High]
Could this also return a positive short read or 0 to the caller?
Similar to asus_dockram_access_ctl(), this might propagate positive values to the probe function or mask zero-byte read failures.
Quoted 2 lines
drivers/mfd/asus-transformer-ec.c new file +2
-0+ +if (buf[0 ] >ASUSEC_ENTRY_SIZE ) {
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Lee Jones
maintainerRe: [PATCH v8 2/7] mfd: Add driver for ASUS Transformer embedded controller
In reply to Svyatoslav RyhelQuoted 171 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.
Co-developed-by Svyatoslav Ryhel <[email protected]>Signed-off-by Svyatoslav Ryhel <[email protected]>Signed-off-by Michał Mirosław <[email protected]>--- drivers/mfd/Kconfig | 16 + drivers/mfd/Makefile | 1 + drivers/mfd/asus-transformer-ec.c | 542 ++++++++++++++++++++++++ include/linux/mfd/asus-transformer-ec.h | 92 ++++ 4 files changed, 651 insertions(+) create mode 100644 drivers/mfd/asus-transformer-ec.c create mode 100644 include/linux/mfd/asus-transformer-ec.hdrivers/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_COREdrivers/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.odrivers/mfd/asus-transformer-ec.c new file +107
-0@@ -0,0 +1,542 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <linux/array_size.h> +#include <linux/debugfs.h> +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/err.h> +#include <linux/gpio/consumer.h> +#include <linux/i2c.h> +#include <linux/interrupt.h> +#include <linux/mfd/asus-transformer-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/slab.h> +#include <linux/string.h> +#include <linux/types.h> +#include <linux/unaligned.h> + +#define ASUSEC_RSP_BUFFER_SIZE (ASUSEC_ENTRIES / ASUSEC_ENTRY_SIZE) + +#define ASUSEC_RESET 0 +#define ASUSEC_RETRY_MAX 3 +#define ASUSEC_ACCESS_TIMEOUT 300 + +enum asusec_variant { +ASUSEC_SL101_DOCK =1 , +ASUSEC_TF101_DOCK , +ASUSEC_TF201_PAD , +ASUSEC_TF600T_PAD , +ASUSEC_MAX +}; + +enum asusec_mode { +ASUSEC_MODE_NONE , +ASUSEC_MODE_NORMAL , +ASUSEC_MODE_FACTORY , +ASUSEC_MODE_MAX +}; + +/** +* struct asus_ec_chip_info +* +* @name: prefix associated with the EC +* @variant: id of programming model of EC +* @mode: state of Factory Mode bit in EC control register +*/ +struct asus_ec_chip_info { +const char *name; +enum asusec_variant variant; +enum asusec_mode fmode; +}; + +/** +* struct asus_ec_data +* +* @ec: public part shared with all cells (must be first) +* @ecreq_lock: prevents simultaneous access to EC +* @ecreq_gpio: EC request GPIO +* @client: pointer to EC's i2c_client +* @info: pointer to EC's version description +* @ec_buf: buffer for EC read +* @logging_disabled: flag disabling logging on reset events +*/ +struct asus_ec_data { +struct asusec_core ec; +struct mutex ecreq_lock; +struct gpio_desc *ecreq_gpio; +struct i2c_client *client; +const struct asus_ec_chip_info *info; +u8 ec_buf[ASUSEC_ENTRY_BUFSIZE ]; +bool logging_disabled; +}; + +/** +* struct dockram_ec_data +* +* @ctl_lock: prevent simultaneous access to Dockram +* @ctl_buf: buffer for Dockram read +*/ +struct dockram_ec_data { +struct mutex ctl_lock; +u8 ctl_buf[ASUSEC_ENTRY_BUFSIZE ]; +}; + +/** +* asus_dockram_access_ctl - Read from or write to the DockRAM control register. +* @client: Handle to the DockRAM device. +* @out: Pointer to a variable where the register value will be stored. +* @mask: Bitmask of bits to be cleared. +* @xor: Bitmask of bits to be set (via XOR). +* +* This performs a control register read if @out is provided and both @mask +* and @xor are zero. Otherwise, it performs a control register update if +* @mask and @xor are provided. +* +* Returns a negative errno code else zero on success. +*/ +int asus_dockram_access_ctl (struct i2c_client *client,u64 *out,u64 mask, +u64 xor) +{ +struct dockram_ec_data *ddata =i2c_get_clientdata (client); +u8 *buf = ddata->ctl_buf; +u64 val; +int ret =0 ;
drivers/mfd/asus-transformer-ec.c line 117
Quoted 10 lines
drivers/mfd/asus-transformer-ec.c new file +10
-0+ +guard (mutex)(&ddata->ctl_lock); + +memset (buf,0 ,ASUSEC_ENTRY_BUFSIZE ); + ret =i2c_smbus_read_i2c_block_data (client,ASUSEC_DOCKRAM_CONTROL , +ASUSEC_ENTRY_SIZE , buf); +if (ret <ASUSEC_ENTRY_SIZE ) { +dev_err (&client->dev,"failed to access control buffer: %d\n" , + ret); +return ret;
Should we return a negative error code here if the read is shorter than expected, rather than propagating the positive byte count?
Quoted 25 lines
drivers/mfd/asus-transformer-ec.c new file +25
-0+ } + +if (buf[0 ] !=ASUSEC_CTL_SIZE ) { +dev_err (&client->dev,"buffer size exceeds %d: %d\n" , +ASUSEC_CTL_SIZE , buf[0 ]); +return -EPROTO ; + } + + val =get_unaligned_le64 (buf +1 ); + +if (out) + *out = val; + +if (mask || xor) { +put_unaligned_le64 ((val & ~mask) ^ xor, buf +1 ); + ret =i2c_smbus_write_i2c_block_data (client, +ASUSEC_DOCKRAM_CONTROL , +ASUSEC_ENTRY_SIZE , buf); +if (ret) +return ret; + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (asus_dockram_access_ctl);
drivers/mfd/asus-transformer-ec.c line 152
Quoted 10 lines
drivers/mfd/asus-transformer-ec.c new file +10
-0+ +static int asus_ec_signal_request (struct asus_ec_data *ddata) +{ +guard (mutex)(&ddata->ecreq_lock); + +gpiod_set_value_cansleep (ddata->ecreq_gpio,1 ); +msleep (50 ); + +gpiod_set_value_cansleep (ddata->ecreq_gpio,0 ); +msleep (200 );
Do these numbers come from the datasheet or were they arbitrarily chosen?
Quoted 28 lines
drivers/mfd/asus-transformer-ec.c new file +28
-0+ +return 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. +*/ +while (retry--) { + ret =i2c_smbus_read_i2c_block_data (ddata->client,ASUSEC_READ_BUF , +ASUSEC_ENTRY_SIZE , + ddata->ec_buf); +if (ret <ASUSEC_ENTRY_SIZE ) +continue ; + +if (ddata->ec_buf[ASUSEC_IRQ_STATUS ] &ASUSEC_OBF_MASK ) +continue ; + +break ; + } +} + +static int asus_ec_log_info (struct asus_ec_data *ddata,unsigned int reg, +const char *name,const char **out)
drivers/mfd/asus-transformer-ec.c line 190
Quoted 10 lines
drivers/mfd/asus-transformer-ec.c new file +10
-0+{ +struct device *dev = &ddata->client->dev; +u8 buf[ASUSEC_ENTRY_BUFSIZE ]; +int ret; + +memset (buf,0 ,ASUSEC_ENTRY_BUFSIZE ); + ret =i2c_smbus_read_i2c_block_data (ddata->ec.dockram, reg, +ASUSEC_ENTRY_SIZE , buf); +if (ret <ASUSEC_ENTRY_SIZE ) +return ret;
Same here. These should be negative.
Quoted 7 lines
drivers/mfd/asus-transformer-ec.c new file +7
-0+ +if (buf[0 ] >ASUSEC_ENTRY_SIZE ) { +dev_err (dev,"bad data len; buffer: %*ph; ret: %d\n" , +ASUSEC_ENTRY_BUFSIZE , buf, ret); +return -EPROTO ; + } +
drivers/mfd/asus-transformer-ec.c line 207
Quoted 10 lines
drivers/mfd/asus-transformer-ec.c new file +10
-0+if (!ddata->logging_disabled) { +dev_info (dev,"%-14s: %.*s\n" , name, buf[0 ], buf +1 ); + +if (out) { + *out =devm_kasprintf (dev,GFP_KERNEL ,"%.*s" , + buf[0 ], buf +1 ); +if (!*out) +return -ENOMEM ; + } + }
FWIW, I hate this! What does it give you now that development is done?
drivers/mfd/asus-transformer-ec.c line 218
Quoted 10 lines
drivers/mfd/asus-transformer-ec.c new file +10
-0+return 0 ; +} + +static int asus_ec_reset (struct asus_ec_data *ddata) +{ +int retry, ret; + +guard (mutex)(&ddata->ecreq_lock); + +for (retry =0 ; retry <ASUSEC_RETRY_MAX ; retry++) {
for (int return = ... is generally preferred for throwaway variables.
drivers/mfd/asus-transformer-ec.c line 224
Quoted 6 lines
drivers/mfd/asus-transformer-ec.c new file +6
-0+ ret =i2c_smbus_write_word_data (ddata->client,ASUSEC_WRITE_BUF , +ASUSEC_RESET ); +if (!ret) +return 0 ; + +msleep (ASUSEC_ACCESS_TIMEOUT );
I like that this is defined, can we do that with the others please?
Quoted 22 lines
drivers/mfd/asus-transformer-ec.c new file +22
-0+ } + +return ret; +} + +static int asus_ec_susb_on_status (struct asus_ec_data *ddata) +{ +u64 flag; +int ret; + + ret =asus_dockram_access_ctl (ddata->ec.dockram, &flag,0 ,0 ); +if (ret) +return ret; + + flag &=ASUSEC_CTL_SUSB_MODE ; +dev_info (&ddata->client->dev,"EC FW behaviour: %s\n" , + flag ?"susb on when receive ec_req" : +"susb on when system wakeup" ); + +return 0 ; +} +
drivers/mfd/asus-transformer-ec.c line 256
Quoted 10 lines
drivers/mfd/asus-transformer-ec.c new file +10
-0+static int asus_ec_set_factory_mode (struct asus_ec_data *ddata, +enum asusec_mode fmode) +{ +dev_info (&ddata->client->dev,"Entering %s mode.\n" , + fmode ==ASUSEC_MODE_FACTORY ?"factory" :"normal" ); + +return asus_dockram_access_ctl (ddata->ec.dockram,NULL , +ASUSEC_CTL_FACTORY_MODE , + fmode ==ASUSEC_MODE_FACTORY ? +ASUSEC_CTL_FACTORY_MODE :0 );
Why not create make:
ASUSEC_MODE_FACTORY == ASUSEC_CTL_FACTORY_MODE
What happens to NORMAL?
Quoted 4 lines
drivers/mfd/asus-transformer-ec.c new file +4
-0+} + +static int asus_ec_detect (struct asus_ec_data *ddata) +{
drivers/mfd/asus-transformer-ec.c line 270
Quoted 10 lines
drivers/mfd/asus-transformer-ec.c new file +10
-0+int ret; + + ret =asus_ec_reset (ddata); +if (ret) + goto err_exit; + +asus_ec_clear_buffer (ddata); + + ret =asus_ec_log_info (ddata,ASUSEC_DOCKRAM_INFO_MODEL ,"Model" , + &ddata->ec.model);
You can use 100-chars and make the code look beautiful! :)
Quoted 9 lines
drivers/mfd/asus-transformer-ec.c new file +9
-0+if (ret) + goto err_exit; + + ret =asus_ec_log_info (ddata,ASUSEC_DOCKRAM_INFO_FW ,"FW version" , +NULL ); +if (ret) + goto err_exit; + + ret = asus_ec_log_info(ddata, ASUSEC_DOCKRAM_INFO_CFGFMT, "Config format",
drivers/mfd/asus-transformer-ec.c line 289
Quoted 10 lines
drivers/mfd/asus-transformer-ec.c new file +10
-0+ NULL); +if (ret) + goto err_exit; + + ret =asus_ec_log_info (ddata,ASUSEC_DOCKRAM_INFO_HW ,"HW version" , +NULL ); +if (ret) + goto err_exit; + +/* Disable logging on next EC request */
Why, but why?
Quoted 30 lines
drivers/mfd/asus-transformer-ec.c new file +30
-0+ ddata->logging_disabled = true; + +/* Check and inform about EC firmware behavior */ + ret =asus_ec_susb_on_status (ddata); +if (ret) + goto err_exit; + + ddata->ec.name = ddata->info->name; + +/* Some EC require factory mode to be set normal on each request */ +if (ddata->info->fmode) + ret =asus_ec_set_factory_mode (ddata, ddata->info->fmode); + +err_exit: +if (ret) +dev_err (&ddata->client->dev,"failed to access EC: %d\n" , ret); + +return ret; +} + +static void asus_ec_handle_smi (struct asus_ec_data *ddata,unsigned int code) +{ +switch (code) { +case ASUSEC_SMI_HANDSHAKE : +case ASUSEC_SMI_RESET : +asus_ec_detect (ddata); +break ; + } +} +
drivers/mfd/asus-transformer-ec.c line 329
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 , +ASUSEC_ENTRY_SIZE , ddata->ec_buf); +if (ret <ASUSEC_ENTRY_SIZE || + !(ddata->ec_buf[ASUSEC_IRQ_STATUS ] &ASUSEC_OBF_MASK ))
Unwrap for readability.
Also, I think a comment would be helpful.
Quoted 21 lines
drivers/mfd/asus-transformer-ec.c new file +21
-0+return IRQ_NONE ; + + notify_action = ddata->ec_buf[ASUSEC_IRQ_STATUS ]; +if (notify_action &ASUSEC_SMI_MASK ) { +unsigned int code = ddata->ec_buf[ASUSEC_SMI_CODE ]; + +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 ; +} + +static void asus_ec_release_dockram_dev (void *client) +{ +i2c_unregister_device (client); +}
drivers/mfd/asus-transformer-ec.c line 360
Quoted 10 lines
drivers/mfd/asus-transformer-ec.c new file +10
-0+ +static struct i2c_client *devm_asus_dockram_get (struct device *dev) +{ +struct i2c_client *parent =to_i2c_client (dev); +struct i2c_client *dockram; +struct dockram_ec_data *ddata; +int ret; + + dockram =i2c_new_ancillary_device (parent,"dockram" , + parent->addr +2 );
Could we define a macro for the address offset '2' here to avoid using a magic number?
Quoted 140 lines
drivers/mfd/asus-transformer-ec.c new file +140
-0+if (IS_ERR (dockram)) +return dockram; + + ret =devm_add_action_or_reset (dev, asus_ec_release_dockram_dev, + dockram); +if (ret) +return ERR_PTR (ret); + + ddata =devm_kzalloc (&dockram->dev,sizeof (*ddata),GFP_KERNEL ); +if (!ddata) +return ERR_PTR (-ENOMEM ); + +i2c_set_clientdata (dockram, ddata); +mutex_init (&ddata->ctl_lock); + +return dockram; +} + +static const struct mfd_cell asus_ec_sl101_dock_mfd_devices[] = { +MFD_CELL_NAME ("asus-transformer-ec-kbc" ), +}; + +static const struct mfd_cell asus_ec_tf101_dock_mfd_devices[] = { +MFD_CELL_BASIC ("asus-transformer-ec-battery" ,NULL ,NULL ,0 ,1 ), +MFD_CELL_BASIC ("asus-transformer-ec-charger" ,NULL ,NULL ,0 ,1 ), +MFD_CELL_BASIC ("asus-transformer-ec-led" ,NULL ,NULL ,0 ,1 ), +MFD_CELL_NAME ("asus-transformer-ec-keys" ), +MFD_CELL_NAME ("asus-transformer-ec-kbc" ), +}; + +static const struct mfd_cell asus_ec_tf201_pad_mfd_devices[] = { +MFD_CELL_NAME ("asus-transformer-ec-battery" ), +MFD_CELL_NAME ("asus-transformer-ec-led" ), +}; + +static const struct mfd_cell asus_ec_tf600t_pad_mfd_devices[] = { +MFD_CELL_NAME ("asus-transformer-ec-battery" ), +MFD_CELL_NAME ("asus-transformer-ec-charger" ), +MFD_CELL_NAME ("asus-transformer-ec-led" ), +}; + +static int asus_ec_probe (struct i2c_client *client) +{ +struct device *dev = &client->dev; +struct asus_ec_data *ddata; +const struct mfd_cell *cells; +unsigned int num_cells; +unsigned long irqflags; +int ret; + +if (!i2c_check_functionality (client->adapter,I2C_FUNC_SMBUS_I2C_BLOCK )) +return dev_err_probe (dev, -ENXIO , +"I2C bus is missing required SMBus block mode support\n" ); + + ddata =devm_kzalloc (dev,sizeof (*ddata),GFP_KERNEL ); +if (!ddata) +return -ENOMEM ; + + ddata->info =device_get_match_data (dev); +if (!ddata->info) +return -ENODEV ; + +switch (ddata->info->variant) { +case ASUSEC_SL101_DOCK : + cells = asus_ec_sl101_dock_mfd_devices; + num_cells =ARRAY_SIZE (asus_ec_sl101_dock_mfd_devices); +break ; +case ASUSEC_TF101_DOCK : + cells = asus_ec_tf101_dock_mfd_devices; + num_cells =ARRAY_SIZE (asus_ec_tf101_dock_mfd_devices); +break ; +case ASUSEC_TF201_PAD : + cells = asus_ec_tf201_pad_mfd_devices; + num_cells =ARRAY_SIZE (asus_ec_tf201_pad_mfd_devices); +break ; +case ASUSEC_TF600T_PAD : + cells = asus_ec_tf600t_pad_mfd_devices; + num_cells =ARRAY_SIZE (asus_ec_tf600t_pad_mfd_devices); +break ; +default : +return dev_err_probe (dev, -EINVAL , +"unknown device variant %d\n" , + ddata->info->variant); + } + +i2c_set_clientdata (client, ddata); + ddata->client = client; + + ddata->ec.dockram =devm_asus_dockram_get (dev); +if (IS_ERR (ddata->ec.dockram)) +return dev_err_probe (dev,PTR_ERR (ddata->ec.dockram), +"failed to get dockram\n" ); + + ddata->ecreq_gpio =devm_gpiod_get (dev,"request" ,GPIOD_OUT_LOW ); +if (IS_ERR (ddata->ecreq_gpio)) +return dev_err_probe (dev,PTR_ERR (ddata->ecreq_gpio), +"failed to get EC request GPIO\n" ); + +BLOCKING_INIT_NOTIFIER_HEAD (&ddata->ec.notify_list); +mutex_init (&ddata->ecreq_lock); + +asus_ec_signal_request (ddata); + + ret =asus_ec_detect (ddata); +if (ret) +return dev_err_probe (dev, ret,"failed to detect EC version\n" ); + +/* +* Systems using device tree should set up interrupt via DTS, +* the rest will use the default low interrupt. +*/ + irqflags = dev->of_node ?0 :IRQF_TRIGGER_LOW ; + + ret =devm_request_threaded_irq (dev, client->irq,NULL , + &asus_ec_interrupt, +IRQF_ONESHOT | irqflags, + client->name, ddata); +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; + +return devm_mfd_add_devices (dev,0 , cells, num_cells,NULL ,0 ,NULL ); +} + +static const struct asus_ec_chip_info asus_ec_sl101_dock_data = { + .name ="dock" , + .variant =ASUSEC_SL101_DOCK , + .fmode =ASUSEC_MODE_NONE , +}; + +static const struct asus_ec_chip_info asus_ec_tf101_dock_data = { + .name ="dock" , + .variant =ASUSEC_TF101_DOCK , + .fmode =ASUSEC_MODE_NONE , +}; + +static const struct asus_ec_chip_info asus_ec_tf201_pad_data = {
drivers/mfd/asus-transformer-ec.c line 510
Quoted 10 lines
drivers/mfd/asus-transformer-ec.c new file +10
-0+ .name = "pad", + .variant = ASUSEC_TF201_PAD, + .fmode = ASUSEC_MODE_NORMAL, +}; + +static const struct asus_ec_chip_info asus_ec_tf600t_pad_data = { + .name ="pad" , + .variant =ASUSEC_TF600T_PAD , + .fmode =ASUSEC_MODE_NORMAL , +};
Any reason not to just pass the identifier (variant) and add the name and fmode attribues to the switch() above?
Quoted 133 lines
drivers/mfd/asus-transformer-ec.c new file +32
-0+ +static const struct of_device_id asus_ec_match[] = { + { + .compatible ="asus,sl101-ec-dock" , + .data = &asus_ec_sl101_dock_data + }, { + .compatible ="asus,tf101-ec-dock" , + .data = &asus_ec_tf101_dock_data + }, { + .compatible ="asus,tf201-ec-pad" , + .data = &asus_ec_tf201_pad_data + }, { + .compatible ="asus,tf600t-ec-pad" , + .data = &asus_ec_tf600t_pad_data + }, + {/* sentinel */ } +}; +MODULE_DEVICE_TABLE (of, asus_ec_match); + +static struct i2c_driver asus_ec_driver = { + .driver = { + .name ="asus-transformer-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-transformer-ec.h new file +92
-0@@ -0,0 +1,92 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __MFD_ASUS_TRANSFORMER_EC_H +#define __MFD_ASUS_TRANSFORMER_EC_H + +#include <linux/notifier.h> +#include <linux/platform_device.h> + +struct i2c_client ; + +/** +* struct asusec_core - public part shared with all cells +* +* @model: firmware version running on the EC +* @name: prefix associated with the EC +* @dockram: pointer to Dockram's i2c_client +* @notify_list: notify list used by cells +*/ +struct asusec_core { +const char *model; +const char *name; +struct i2c_client *dockram; +struct blocking_notifier_head notify_list; +}; + +#define ASUSEC_ENTRIES 0x100 +#define ASUSEC_ENTRY_SIZE 32 +#define ASUSEC_ENTRY_BUFSIZE (ASUSEC_ENTRY_SIZE + 1) + +/* interrupt sources */ +#define ASUSEC_IRQ_STATUS 1 +#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_CODE 2 +#define ASUSEC_SMI_POWER_NOTIFY 0x31/* USB cable plug event */ +#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/* charger to dock plug event */ +#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(9) +#define ASUSEC_CMD_SUSPEND_S3 BIT_ULL(33) +#define ASUSEC_CTL_TEST_DISCHARGE BIT_ULL(35) +#define ASUSEC_CMD_SUSPEND_INHIBIT BIT_ULL(37) +#define ASUSEC_CTL_FACTORY_MODE BIT_ULL(38) +#define ASUSEC_CTL_KEEP_AWAKE BIT_ULL(39) +#define ASUSEC_CTL_USB_CHARGE BIT_ULL(40) +#define ASUSEC_CTL_LED_BLINK BIT_ULL(40) +#define ASUSEC_CTL_LED_AMBER BIT_ULL(41) +#define ASUSEC_CTL_LED_GREEN BIT_ULL(42) +#define ASUSEC_CMD_SWITCH_HDMI BIT_ULL(56) +#define ASUSEC_CMD_WIN_SHUTDOWN BIT_ULL(62) + +#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 + +int asus_dockram_access_ctl (struct i2c_client *client, +u64 *out,u64 mask,u64 xor); + +#endif /* __MFD_ASUS_TRANSFORMER_EC_H */ Signature · 1 line
2.51.0
Signature · 1 line
Lee Jones
Re: [PATCH v8 2/7] mfd: Add driver for ASUS Transformer embedded controller
чт, 11 черв. 2026 р. о 14:17 Lee Jones <[email protected]> пише:
Quoted 21 lines · Svyatoslav Ryhel
Quoted 19 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.
Co-developed-by Svyatoslav Ryhel <[email protected]>Signed-off-by Svyatoslav Ryhel <[email protected]>Signed-off-by Michał Mirosław <[email protected]>--- drivers/mfd/Kconfig | 16 + drivers/mfd/Makefile | 1 + drivers/mfd/asus-transformer-ec.c | 542 ++++++++++++++++++++++++ include/linux/mfd/asus-transformer-ec.h | 92 ++++ 4 files changed, 651 insertions(+) create mode 100644 drivers/mfd/asus-transformer-ec.c create mode 100644 include/linux/mfd/asus-transformer-ec.h
...
Quoted 9 lines
drivers/mfd/asus-transformer-ec.c line 117
Quoted 8 lines
drivers/mfd/asus-transformer-ec.c new file +8
-0+ +memset (buf,0 ,ASUSEC_ENTRY_BUFSIZE ); + ret =i2c_smbus_read_i2c_block_data (client,ASUSEC_DOCKRAM_CONTROL , +ASUSEC_ENTRY_SIZE , buf); +if (ret <ASUSEC_ENTRY_SIZE ) { +dev_err (&client->dev,"failed to access control buffer: %d\n" , + ret); +return ret;
Quoted 3 lines
Should we return a negative error code here if the read is shorter than expected, rather than propagating the positive byte count?
Yes, I have adjusted it already locally for the next iteration. It will return ret if negative and -EIO if ret is pos but less then ASUSEC_ENTRY_SIZE (return ret < 0 ? ret : -EIO)
Quoted 29 lines
Quoted 29 lines
drivers/mfd/asus-transformer-ec.c new file +29
-0+ } + +if (buf[0 ] !=ASUSEC_CTL_SIZE ) { +dev_err (&client->dev,"buffer size exceeds %d: %d\n" , +ASUSEC_CTL_SIZE , buf[0 ]); +return -EPROTO ; + } + + val =get_unaligned_le64 (buf +1 ); + +if (out) + *out = val; + +if (mask || xor) { +put_unaligned_le64 ((val & ~mask) ^ xor, buf +1 ); + ret =i2c_smbus_write_i2c_block_data (client, +ASUSEC_DOCKRAM_CONTROL , +ASUSEC_ENTRY_SIZE , buf); +if (ret) +return ret; + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (asus_dockram_access_ctl); + +static int asus_ec_signal_request (struct asus_ec_data *ddata) +{ +guard (mutex)(&ddata->ecreq_lock);
Quoted 9 lines
drivers/mfd/asus-transformer-ec.c line 152
Quoted 6 lines
drivers/mfd/asus-transformer-ec.c new file +6
-0+ +gpiod_set_value_cansleep (ddata->ecreq_gpio,1 ); +msleep (50 ); + +gpiod_set_value_cansleep (ddata->ecreq_gpio,0 ); +msleep (200 );Do these numbers come from the datasheet or were they arbitrarily chosen?
There is no datasheet. These delays come from downstream driver and with lower values or removed delays request fails.
Quoted 32 lines
Quoted 32 lines
drivers/mfd/asus-transformer-ec.c new file +32
-0+ +return 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. +*/ +while (retry--) { + ret =i2c_smbus_read_i2c_block_data (ddata->client,ASUSEC_READ_BUF , +ASUSEC_ENTRY_SIZE , + ddata->ec_buf); +if (ret <ASUSEC_ENTRY_SIZE ) +continue ; + +if (ddata->ec_buf[ASUSEC_IRQ_STATUS ] &ASUSEC_OBF_MASK ) +continue ; + +break ; + } +} + +static int asus_ec_log_info (struct asus_ec_data *ddata,unsigned int reg, +const char *name,const char **out) +{ +struct device *dev = &ddata->client->dev; +u8 buf[ASUSEC_ENTRY_BUFSIZE ]; +int ret;
Quoted 9 lines
drivers/mfd/asus-transformer-ec.c line 190
Quoted 6 lines
drivers/mfd/asus-transformer-ec.c new file +6
-0+ +memset (buf,0 ,ASUSEC_ENTRY_BUFSIZE ); + ret =i2c_smbus_read_i2c_block_data (ddata->ec.dockram, reg, +ASUSEC_ENTRY_SIZE , buf); +if (ret <ASUSEC_ENTRY_SIZE ) +return ret;Same here. These should be negative.
return ret < 0 ? ret : -EIO same as above
Quoted 11 lines
Quoted 11 lines
drivers/mfd/asus-transformer-ec.c new file +11
-0+ +if (buf[0 ] >ASUSEC_ENTRY_SIZE ) { +dev_err (dev,"bad data len; buffer: %*ph; ret: %d\n" , +ASUSEC_ENTRY_BUFSIZE , buf, ret); +return -EPROTO ; + } + +if (!ddata->logging_disabled) { +dev_info (dev,"%-14s: %.*s\n" , name, buf[0 ], buf +1 ); + +if (out) {
Quoted 9 lines
drivers/mfd/asus-transformer-ec.c line 207
Quoted 6 lines
drivers/mfd/asus-transformer-ec.c new file +6
-0+ *out =devm_kasprintf (dev,GFP_KERNEL ,"%.*s" , + buf[0 ], buf +1 ); +if (!*out) +return -ENOMEM ; + } + }FWIW, I hate this! What does it give you now that development is done?
We have already discussed this, and you agreed that EC and firmware prints may stay! This prints EC model and firmware info as well as EC firmware behavior. It allows identify possible new revisions of EC - Firmware combo and address possible regressions (check if it is chip malfunction or firmware needs a new programming model) without rebuilding kernel and digging downstream kernel for needed bits of code.
Quoted 4 lines
Quoted 4 lines
drivers/mfd/asus-transformer-ec.c new file +4
-0+return 0 ; +} + +static int asus_ec_reset (struct asus_ec_data *ddata)
Quoted 9 lines
drivers/mfd/asus-transformer-ec.c line 218
Quoted 6 lines
drivers/mfd/asus-transformer-ec.c new file +6
-0+{ +int retry, ret; + +guard (mutex)(&ddata->ecreq_lock); + +for (retry =0 ; retry <ASUSEC_RETRY_MAX ; retry++) {for (int return = ... is generally preferred for throwaway variables.
Not that I care too much, but I am defining ret anyway, why not add retry too there?
Quoted 10 lines
drivers/mfd/asus-transformer-ec.c line 224
Quoted 7 lines
drivers/mfd/asus-transformer-ec.c new file +6
-0+ ret =i2c_smbus_write_word_data (ddata->client,ASUSEC_WRITE_BUF , +ASUSEC_RESET ); +if (!ret) +return 0 ; + +msleep (ASUSEC_ACCESS_TIMEOUT );I like that this is defined, can we do that with the others please?
I don't see any benefits of defining delays, they are all arbitrary and derive from downstream kernel, removing or altering them caused malfunction.
Quoted 35 lines
Quoted 22 lines
drivers/mfd/asus-transformer-ec.c new file +22
-0+ } + +return ret; +} + +static int asus_ec_susb_on_status (struct asus_ec_data *ddata) +{ +u64 flag; +int ret; + + ret =asus_dockram_access_ctl (ddata->ec.dockram, &flag,0 ,0 ); +if (ret) +return ret; + + flag &=ASUSEC_CTL_SUSB_MODE ; +dev_info (&ddata->client->dev,"EC FW behaviour: %s\n" , + flag ?"susb on when receive ec_req" : +"susb on when system wakeup" ); + +return 0 ; +} +drivers/mfd/asus-transformer-ec.c line 256
Quoted 10 lines
drivers/mfd/asus-transformer-ec.c new file +10
-0+static int asus_ec_set_factory_mode (struct asus_ec_data *ddata, +enum asusec_mode fmode) +{ +dev_info (&ddata->client->dev,"Entering %s mode.\n" , + fmode ==ASUSEC_MODE_FACTORY ?"factory" :"normal" ); + +return asus_dockram_access_ctl (ddata->ec.dockram,NULL , +ASUSEC_CTL_FACTORY_MODE , + fmode ==ASUSEC_MODE_FACTORY ? +ASUSEC_CTL_FACTORY_MODE :0 );Why not create make:
Quoted 4 lines
ASUSEC_MODE_FACTORY==ASUSEC_CTL_FACTORY_MODEWhat happens to NORMAL?
ASUSEC_CTL_FACTORY_MODE is a bit in the ctl register. For NORMAL mode bit is cleared,
for FACTORY bit it set, for NONE bit is ignored.
Quoted 8 lines
Quoted 8 lines
drivers/mfd/asus-transformer-ec.c new file +8
-0+} + +static int asus_ec_detect (struct asus_ec_data *ddata) +{ +int ret; + + ret =asus_ec_reset (ddata); +if (ret)
Quoted 9 lines
drivers/mfd/asus-transformer-ec.c line 270
Quoted 6 lines
drivers/mfd/asus-transformer-ec.c new file +6
-0+ goto err_exit; + +asus_ec_clear_buffer (ddata); + + ret =asus_ec_log_info (ddata,ASUSEC_DOCKRAM_INFO_MODEL ,"Model" , + &ddata->ec.model);You can use 100-chars and make the code look beautiful! :)
Not every subsystem permits 100 chars, some stick to 80 as a strict rule, so it is better be safe.
Quoted 13 lines
Quoted 13 lines
drivers/mfd/asus-transformer-ec.c new file +13
-0+if (ret) + goto err_exit; + + ret =asus_ec_log_info (ddata,ASUSEC_DOCKRAM_INFO_FW ,"FW version" , +NULL ); +if (ret) + goto err_exit; + + ret =asus_ec_log_info (ddata,ASUSEC_DOCKRAM_INFO_CFGFMT ,"Config format" , +NULL ); +if (ret) + goto err_exit; +
Quoted 9 lines
drivers/mfd/asus-transformer-ec.c line 289
Quoted 6 lines
drivers/mfd/asus-transformer-ec.c new file +6
-0+ ret =asus_ec_log_info (ddata,ASUSEC_DOCKRAM_INFO_HW ,"HW version" , +NULL ); +if (ret) + goto err_exit; + +/* Disable logging on next EC request */ Why, but why?
Cause EC requests are frequent (handshake/reset) and constant logging same data is not acceptable.
Quoted 43 lines
Quoted 30 lines
drivers/mfd/asus-transformer-ec.c new file +30
-0+ ddata->logging_disabled = true; + +/* Check and inform about EC firmware behavior */ + ret =asus_ec_susb_on_status (ddata); +if (ret) + goto err_exit; + + ddata->ec.name = ddata->info->name; + +/* Some EC require factory mode to be set normal on each request */ +if (ddata->info->fmode) + ret =asus_ec_set_factory_mode (ddata, ddata->info->fmode); + +err_exit: +if (ret) +dev_err (&ddata->client->dev,"failed to access EC: %d\n" , ret); + +return ret; +} + +static void asus_ec_handle_smi (struct asus_ec_data *ddata,unsigned int code) +{ +switch (code) { +case ASUSEC_SMI_HANDSHAKE : +case ASUSEC_SMI_RESET : +asus_ec_detect (ddata); +break ; + } +} +drivers/mfd/asus-transformer-ec.c line 329
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 , +ASUSEC_ENTRY_SIZE , ddata->ec_buf); +if (ret <ASUSEC_ENTRY_SIZE || + !(ddata->ec_buf[ASUSEC_IRQ_STATUS ] &ASUSEC_OBF_MASK ))Unwrap for readability.
Quoted 2 lines
Also, I think a comment would be helpful.
if (ret < ASUSEC_ENTRY_SIZE)
return IRQ_NONE;
ret = ddata->ec_buf[ASUSEC_IRQ_STATUS] & ASUSEC_OBF_MASK; if (!ret)
return IRQ_NONE;
This would be acceptable? (I will add comments later on)
Quoted 26 lines
Quoted 26 lines
drivers/mfd/asus-transformer-ec.c new file +26
-0+return IRQ_NONE ; + + notify_action = ddata->ec_buf[ASUSEC_IRQ_STATUS ]; +if (notify_action &ASUSEC_SMI_MASK ) { +unsigned int code = ddata->ec_buf[ASUSEC_SMI_CODE ]; + +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 ; +} + +static void asus_ec_release_dockram_dev (void *client) +{ +i2c_unregister_device (client); +} + +static struct i2c_client *devm_asus_dockram_get (struct device *dev) +{ +struct i2c_client *parent =to_i2c_client (dev); +struct i2c_client *dockram;
Quoted 9 lines
drivers/mfd/asus-transformer-ec.c line 360
Quoted 5 lines
drivers/mfd/asus-transformer-ec.c new file +5
-0+struct dockram_ec_data *ddata; +int ret; + + dockram =i2c_new_ancillary_device (parent,"dockram" , + parent->addr +2 );Could we define a macro for the address offset '2' here to avoid using a magic number?
It seems that you are excessively concerned with "magic numbers".
Quoted 145 lines
Quoted 145 lines
drivers/mfd/asus-transformer-ec.c new file +145
-0+if (IS_ERR (dockram)) +return dockram; + + ret =devm_add_action_or_reset (dev, asus_ec_release_dockram_dev, + dockram); +if (ret) +return ERR_PTR (ret); + + ddata =devm_kzalloc (&dockram->dev,sizeof (*ddata),GFP_KERNEL ); +if (!ddata) +return ERR_PTR (-ENOMEM ); + +i2c_set_clientdata (dockram, ddata); +mutex_init (&ddata->ctl_lock); + +return dockram; +} + +static const struct mfd_cell asus_ec_sl101_dock_mfd_devices[] = { +MFD_CELL_NAME ("asus-transformer-ec-kbc" ), +}; + +static const struct mfd_cell asus_ec_tf101_dock_mfd_devices[] = { +MFD_CELL_BASIC ("asus-transformer-ec-battery" ,NULL ,NULL ,0 ,1 ), +MFD_CELL_BASIC ("asus-transformer-ec-charger" ,NULL ,NULL ,0 ,1 ), +MFD_CELL_BASIC ("asus-transformer-ec-led" ,NULL ,NULL ,0 ,1 ), +MFD_CELL_NAME ("asus-transformer-ec-keys" ), +MFD_CELL_NAME ("asus-transformer-ec-kbc" ), +}; + +static const struct mfd_cell asus_ec_tf201_pad_mfd_devices[] = { +MFD_CELL_NAME ("asus-transformer-ec-battery" ), +MFD_CELL_NAME ("asus-transformer-ec-led" ), +}; + +static const struct mfd_cell asus_ec_tf600t_pad_mfd_devices[] = { +MFD_CELL_NAME ("asus-transformer-ec-battery" ), +MFD_CELL_NAME ("asus-transformer-ec-charger" ), +MFD_CELL_NAME ("asus-transformer-ec-led" ), +}; + +static int asus_ec_probe (struct i2c_client *client) +{ +struct device *dev = &client->dev; +struct asus_ec_data *ddata; +const struct mfd_cell *cells; +unsigned int num_cells; +unsigned long irqflags; +int ret; + +if (!i2c_check_functionality (client->adapter,I2C_FUNC_SMBUS_I2C_BLOCK )) +return dev_err_probe (dev, -ENXIO , +"I2C bus is missing required SMBus block mode support\n" ); + + ddata =devm_kzalloc (dev,sizeof (*ddata),GFP_KERNEL ); +if (!ddata) +return -ENOMEM ; + + ddata->info =device_get_match_data (dev); +if (!ddata->info) +return -ENODEV ; + +switch (ddata->info->variant) { +case ASUSEC_SL101_DOCK : + cells = asus_ec_sl101_dock_mfd_devices; + num_cells =ARRAY_SIZE (asus_ec_sl101_dock_mfd_devices); +break ; +case ASUSEC_TF101_DOCK : + cells = asus_ec_tf101_dock_mfd_devices; + num_cells =ARRAY_SIZE (asus_ec_tf101_dock_mfd_devices); +break ; +case ASUSEC_TF201_PAD : + cells = asus_ec_tf201_pad_mfd_devices; + num_cells =ARRAY_SIZE (asus_ec_tf201_pad_mfd_devices); +break ; +case ASUSEC_TF600T_PAD : + cells = asus_ec_tf600t_pad_mfd_devices; + num_cells =ARRAY_SIZE (asus_ec_tf600t_pad_mfd_devices); +break ; +default : +return dev_err_probe (dev, -EINVAL , +"unknown device variant %d\n" , + ddata->info->variant); + } + +i2c_set_clientdata (client, ddata); + ddata->client = client; + + ddata->ec.dockram =devm_asus_dockram_get (dev); +if (IS_ERR (ddata->ec.dockram)) +return dev_err_probe (dev,PTR_ERR (ddata->ec.dockram), +"failed to get dockram\n" ); + + ddata->ecreq_gpio =devm_gpiod_get (dev,"request" ,GPIOD_OUT_LOW ); +if (IS_ERR (ddata->ecreq_gpio)) +return dev_err_probe (dev,PTR_ERR (ddata->ecreq_gpio), +"failed to get EC request GPIO\n" ); + +BLOCKING_INIT_NOTIFIER_HEAD (&ddata->ec.notify_list); +mutex_init (&ddata->ecreq_lock); + +asus_ec_signal_request (ddata); + + ret =asus_ec_detect (ddata); +if (ret) +return dev_err_probe (dev, ret,"failed to detect EC version\n" ); + +/* +* Systems using device tree should set up interrupt via DTS, +* the rest will use the default low interrupt. +*/ + irqflags = dev->of_node ?0 :IRQF_TRIGGER_LOW ; + + ret =devm_request_threaded_irq (dev, client->irq,NULL , + &asus_ec_interrupt, +IRQF_ONESHOT | irqflags, + client->name, ddata); +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; + +return devm_mfd_add_devices (dev,0 , cells, num_cells,NULL ,0 ,NULL ); +} + +static const struct asus_ec_chip_info asus_ec_sl101_dock_data = { + .name ="dock" , + .variant =ASUSEC_SL101_DOCK , + .fmode =ASUSEC_MODE_NONE , +}; + +static const struct asus_ec_chip_info asus_ec_tf101_dock_data = { + .name ="dock" , + .variant =ASUSEC_TF101_DOCK , + .fmode =ASUSEC_MODE_NONE , +}; + +static const struct asus_ec_chip_info asus_ec_tf201_pad_data = { + .name ="pad" , + .variant =ASUSEC_TF201_PAD , + .fmode =ASUSEC_MODE_NORMAL , +}; +
Quoted 8 lines
drivers/mfd/asus-transformer-ec.c line 510
Quoted 5 lines
drivers/mfd/asus-transformer-ec.c new file +5
-0+static const struct asus_ec_chip_info asus_ec_tf600t_pad_data = { + .name ="pad" , + .variant =ASUSEC_TF600T_PAD , + .fmode =ASUSEC_MODE_NORMAL , +};Any reason not to just pass the identifier (variant) and add the name and fmode attribues to the
switch()above?
Why not set it here, I am not passing any mfd or any other API via of data.
Quoted 136 lines
Quoted 131 lines
drivers/mfd/asus-transformer-ec.c new file +32
-0+ +static const struct of_device_id asus_ec_match[] = { + { + .compatible ="asus,sl101-ec-dock" , + .data = &asus_ec_sl101_dock_data + }, { + .compatible ="asus,tf101-ec-dock" , + .data = &asus_ec_tf101_dock_data + }, { + .compatible ="asus,tf201-ec-pad" , + .data = &asus_ec_tf201_pad_data + }, { + .compatible ="asus,tf600t-ec-pad" , + .data = &asus_ec_tf600t_pad_data + }, + {/* sentinel */ } +}; +MODULE_DEVICE_TABLE (of, asus_ec_match); + +static struct i2c_driver asus_ec_driver = { + .driver = { + .name ="asus-transformer-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-transformer-ec.h new file +92
-1@@ -0,0 +1,92 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __MFD_ASUS_TRANSFORMER_EC_H +#define __MFD_ASUS_TRANSFORMER_EC_H + +#include <linux/notifier.h> +#include <linux/platform_device.h> + +struct i2c_client ; + +/** +* struct asusec_core - public part shared with all cells +* +* @model: firmware version running on the EC +* @name: prefix associated with the EC +* @dockram: pointer to Dockram's i2c_client +* @notify_list: notify list used by cells +*/ +struct asusec_core { +const char *model; +const char *name; +struct i2c_client *dockram; +struct blocking_notifier_head notify_list; +}; + +#define ASUSEC_ENTRIES 0x100 +#define ASUSEC_ENTRY_SIZE 32 +#define ASUSEC_ENTRY_BUFSIZE (ASUSEC_ENTRY_SIZE + 1) + +/* interrupt sources */ +#define ASUSEC_IRQ_STATUS 1 +#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_CODE 2 +#define ASUSEC_SMI_POWER_NOTIFY 0x31/* USB cable plug event */ +#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/* charger to dock plug event */ +#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(9) +#define ASUSEC_CMD_SUSPEND_S3 BIT_ULL(33) +#define ASUSEC_CTL_TEST_DISCHARGE BIT_ULL(35) +#define ASUSEC_CMD_SUSPEND_INHIBIT BIT_ULL(37) +#define ASUSEC_CTL_FACTORY_MODE BIT_ULL(38) +#define ASUSEC_CTL_KEEP_AWAKE BIT_ULL(39) +#define ASUSEC_CTL_USB_CHARGE BIT_ULL(40) +#define ASUSEC_CTL_LED_BLINK BIT_ULL(40) +#define ASUSEC_CTL_LED_AMBER BIT_ULL(41) +#define ASUSEC_CTL_LED_GREEN BIT_ULL(42) +#define ASUSEC_CMD_SWITCH_HDMI BIT_ULL(56) +#define ASUSEC_CMD_WIN_SHUTDOWN BIT_ULL(62) + +#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 + +int asus_dockram_access_ctl (struct i2c_client *client, +u64 *out,u64 mask,u64 xor); + +#endif /* __MFD_ASUS_TRANSFORMER_EC_H */ --Quoted 2 lines
2.51.0
--
Lee Jones
Lee Jones
maintainerRe: [PATCH v8 2/7] mfd: Add driver for ASUS Transformer embedded controller
Quoted 21 lines · Svyatoslav Ryhel
чт, 11 черв. 2026 р. о 14:17 Lee Jones <[email protected]> пише:
Quoted 20 lines · Svyatoslav Ryhel
Quoted 18 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.
Co-developed-by Svyatoslav Ryhel <[email protected]>Signed-off-by Svyatoslav Ryhel <[email protected]>Signed-off-by Michał Mirosław <[email protected]>--- drivers/mfd/Kconfig | 16 + drivers/mfd/Makefile | 1 + drivers/mfd/asus-transformer-ec.c | 542 ++++++++++++++++++++++++ include/linux/mfd/asus-transformer-ec.h | 92 ++++ 4 files changed, 651 insertions(+) create mode 100644 drivers/mfd/asus-transformer-ec.c create mode 100644 include/linux/mfd/asus-transformer-ec.h
[...]
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
drivers/mfd/asus-transformer-ec.c new file +16
-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. +*/ +while (retry--) { + ret =i2c_smbus_read_i2c_block_data (ddata->client,ASUSEC_READ_BUF , +ASUSEC_ENTRY_SIZE , + ddata->ec_buf); +if (ret <ASUSEC_ENTRY_SIZE ) +continue ; + +if (ddata->ec_buf[ASUSEC_IRQ_STATUS ] &ASUSEC_OBF_MASK )
Quoted 8 lines
Quoted 8 lines
drivers/mfd/asus-transformer-ec.c line 180
Quoted 8 lines
drivers/mfd/asus-transformer-ec.c new file +8
-0+continue ; + +break ; + } +} + +static int asus_ec_log_info (struct asus_ec_data *ddata,unsigned int reg, +const char *name,const char **out)
If we can avoid points to pointers, then please do.
We already have ddata, so we can just set the name?
It will remove a lot of the following complexity / ugliness.
Quoted 37 lines
Quoted 4 lines
Quoted 4 lines
drivers/mfd/asus-transformer-ec.c new file +4
-0+{ +struct device *dev = &ddata->client->dev; +u8 buf[ASUSEC_ENTRY_BUFSIZE ]; +int ret;Quoted 9 lines
drivers/mfd/asus-transformer-ec.c line 190
Quoted 6 lines
drivers/mfd/asus-transformer-ec.c new file +6
-0+ +memset (buf,0 ,ASUSEC_ENTRY_BUFSIZE ); + ret =i2c_smbus_read_i2c_block_data (ddata->ec.dockram, reg, +ASUSEC_ENTRY_SIZE , buf); +if (ret <ASUSEC_ENTRY_SIZE ) +return ret;Same here. These should be negative.
return ret < 0 ? ret :
-EIOsame as aboveQuoted 11 lines
Quoted 11 lines
drivers/mfd/asus-transformer-ec.c new file +11
-0+ +if (buf[0 ] >ASUSEC_ENTRY_SIZE ) { +dev_err (dev,"bad data len; buffer: %*ph; ret: %d\n" , +ASUSEC_ENTRY_BUFSIZE , buf, ret); +return -EPROTO ; + } + +if (!ddata->logging_disabled) { +dev_info (dev,"%-14s: %.*s\n" , name, buf[0 ], buf +1 ); + +if (out) {Quoted 9 lines
drivers/mfd/asus-transformer-ec.c line 207
Quoted 6 lines
drivers/mfd/asus-transformer-ec.c new file +6
-0+ *out =devm_kasprintf (dev,GFP_KERNEL ,"%.*s" , + buf[0 ], buf +1 ); +if (!*out) +return -ENOMEM ; + } + }FWIW, I hate this! What does it give you now that development is done?
Quoted 7 lines
We have already discussed this, and you agreed that EC and firmware prints may stay! This prints EC model and firmware info as well as EC firmware behavior. It allows identify possible new revisions of EC - Firmware combo and address possible regressions (check if it is chip malfunction or firmware needs a new programming model) without rebuilding kernel and digging downstream kernel for needed bits of code.
Right, so just print it out and remove all of the 'logging_disabled' and 'out' nonsense.
Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
drivers/mfd/asus-transformer-ec.c new file +4
-0+return 0 ; +} + +static int asus_ec_reset (struct asus_ec_data *ddata)Quoted 9 lines
drivers/mfd/asus-transformer-ec.c line 218
Quoted 6 lines
drivers/mfd/asus-transformer-ec.c new file +6
-0+{ +int retry, ret; + +guard (mutex)(&ddata->ecreq_lock); + +for (retry =0 ; retry <ASUSEC_RETRY_MAX ; retry++) {for (int retry = ... is generally preferred for throwaway variables.
Quoted 2 lines
Not that I care too much, but I am defining ret anyway, why not add retry too there?
This is the new and preferred way to use throw-away variables.
ret is not a throw-away variable.
[...]
Quoted 13 lines
Quoted 13 lines
drivers/mfd/asus-transformer-ec.c line 256
Quoted 10 lines
drivers/mfd/asus-transformer-ec.c new file +10
-0+static int asus_ec_set_factory_mode (struct asus_ec_data *ddata, +enum asusec_mode fmode) +{ +dev_info (&ddata->client->dev,"Entering %s mode.\n" , + fmode ==ASUSEC_MODE_FACTORY ?"factory" :"normal" ); + +return asus_dockram_access_ctl (ddata->ec.dockram,NULL , +ASUSEC_CTL_FACTORY_MODE , + fmode ==ASUSEC_MODE_FACTORY ? +ASUSEC_CTL_FACTORY_MODE :0 );Why not create make:
Quoted 6 lines
Quoted 4 lines
ASUSEC_MODE_FACTORY==ASUSEC_CTL_FACTORY_MODEWhat happens to NORMAL?
ASUSEC_CTL_FACTORY_MODEis a bit in the ctl register. For NORMAL mode
I get that, but if the values can be shared, it make the code simpler.
Quoted 17 lines
bit is cleared,
for FACTORY bit it set, for NONE bit is ignored.Quoted 6 lines
Quoted 6 lines
drivers/mfd/asus-transformer-ec.c new file +6
-0+} + +static int asus_ec_detect (struct asus_ec_data *ddata) +{ +int ret; +Quoted 8 lines
drivers/mfd/asus-transformer-ec.c line 270
Quoted 8 lines
drivers/mfd/asus-transformer-ec.c new file +8
-0+ ret =asus_ec_reset (ddata); +if (ret) + goto err_exit; + +asus_ec_clear_buffer (ddata); + + ret =asus_ec_log_info (ddata,ASUSEC_DOCKRAM_INFO_MODEL ,"Model" , + &ddata->ec.model);
Where is this model used?
Quoted 5 lines
Quoted 2 lines
You can use 100-chars and make the code look beautiful! :)
Not every subsystem permits 100 chars, some stick to 80 as a strict rule, so it is better be safe.
Right, but we are forward thinking here.
You can and should use 100-chars in this subsystem.
Quoted 23 lines
Quoted 13 lines
Quoted 13 lines
drivers/mfd/asus-transformer-ec.c new file +13
-0+if (ret) + goto err_exit; + + ret =asus_ec_log_info (ddata,ASUSEC_DOCKRAM_INFO_FW ,"FW version" , +NULL ); +if (ret) + goto err_exit; + + ret =asus_ec_log_info (ddata,ASUSEC_DOCKRAM_INFO_CFGFMT ,"Config format" , +NULL ); +if (ret) + goto err_exit; +Quoted 9 lines
drivers/mfd/asus-transformer-ec.c line 289
Quoted 6 lines
drivers/mfd/asus-transformer-ec.c new file +6
-0+ ret =asus_ec_log_info (ddata,ASUSEC_DOCKRAM_INFO_HW ,"HW version" , +NULL ); +if (ret) + goto err_exit; + +/* Disable logging on next EC request */ Why, but why?
Quoted 2 lines
Cause EC requests are frequent (handshake/reset) and constant logging same data is not acceptable.
Then rid the prints entirely or do them at a more appropriate point like during probe?
Or maybe consider dev_info_once() and friends.
Quoted 46 lines
Quoted 43 lines
Quoted 30 lines
drivers/mfd/asus-transformer-ec.c new file +30
-0+ ddata->logging_disabled = true; + +/* Check and inform about EC firmware behavior */ + ret =asus_ec_susb_on_status (ddata); +if (ret) + goto err_exit; + + ddata->ec.name = ddata->info->name; + +/* Some EC require factory mode to be set normal on each request */ +if (ddata->info->fmode) + ret =asus_ec_set_factory_mode (ddata, ddata->info->fmode); + +err_exit: +if (ret) +dev_err (&ddata->client->dev,"failed to access EC: %d\n" , ret); + +return ret; +} + +static void asus_ec_handle_smi (struct asus_ec_data *ddata,unsigned int code) +{ +switch (code) { +case ASUSEC_SMI_HANDSHAKE : +case ASUSEC_SMI_RESET : +asus_ec_detect (ddata); +break ; + } +} +drivers/mfd/asus-transformer-ec.c line 329
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 , +ASUSEC_ENTRY_SIZE , ddata->ec_buf); +if (ret <ASUSEC_ENTRY_SIZE || + !(ddata->ec_buf[ASUSEC_IRQ_STATUS ] &ASUSEC_OBF_MASK ))Unwrap for readability.
Quoted 2 lines
Also, I think a comment would be helpful.
Quoted 8 lines
if (ret <
ASUSEC_ENTRY_SIZE)return IRQ_NONE;ret = ddata->ec_buf[ASUSEC_IRQ_STATUS] &
ASUSEC_OBF_MASK; if (!ret)return IRQ_NONE;This would be acceptable? (I will add comments later on)
Yes, better.
If you're not using ret again, you could just put 'ddata.." inside the if().
Quoted 36 lines
Quoted 26 lines
Quoted 26 lines
drivers/mfd/asus-transformer-ec.c new file +26
-0+return IRQ_NONE ; + + notify_action = ddata->ec_buf[ASUSEC_IRQ_STATUS ]; +if (notify_action &ASUSEC_SMI_MASK ) { +unsigned int code = ddata->ec_buf[ASUSEC_SMI_CODE ]; + +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 ; +} + +static void asus_ec_release_dockram_dev (void *client) +{ +i2c_unregister_device (client); +} + +static struct i2c_client *devm_asus_dockram_get (struct device *dev) +{ +struct i2c_client *parent =to_i2c_client (dev); +struct i2c_client *dockram;Quoted 9 lines
drivers/mfd/asus-transformer-ec.c line 360
Quoted 5 lines
drivers/mfd/asus-transformer-ec.c new file +5
-0+struct dockram_ec_data *ddata; +int ret; + + dockram =i2c_new_ancillary_device (parent,"dockram" , + parent->addr +2 );Could we define a macro for the address offset '2' here to avoid using a magic number?
Quoted 1 line
It seems that you are excessively concerned with "magic numbers".
Bingo! I HATE magic numbers.
https://lore.kernel.org/all/?q=%22Lee+Jones%22+magic
~900 messages! =:-D
[...]
Quoted 10 lines
Quoted 8 lines
drivers/mfd/asus-transformer-ec.c line 510
Quoted 5 lines
drivers/mfd/asus-transformer-ec.c new file +5
-0+static const struct asus_ec_chip_info asus_ec_tf600t_pad_data = { + .name ="pad" , + .variant =ASUSEC_TF600T_PAD , + .fmode =ASUSEC_MODE_NORMAL , +};Any reason not to just pass the identifier (variant) and add the name and fmode attribues to the
switch()above?Why not set it here, I am not passing any mfd or any other API via of data.
I get that, and you're not breaking any of my golden rules.
However, I just think doing everything in one place, usually a which based off of the 'variant' which you pass as a single value, is a nicer, more consolidated way of doing things.
Signature · 1 line
Lee Jones
Re: [PATCH v8 2/7] mfd: Add driver for ASUS Transformer embedded controller
чт, 18 черв. 2026 р. о 15:26 Lee Jones <[email protected]> пише:
Quoted 154 lines · Svyatoslav Ryhel
Quoted 22 lines
чт, 11 черв. 2026 р. о 14:17 Lee Jones <[email protected]> пише:
Quoted 20 lines · Svyatoslav Ryhel
Quoted 18 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.
Co-developed-by Svyatoslav Ryhel <[email protected]>Signed-off-by Svyatoslav Ryhel <[email protected]>Signed-off-by Michał Mirosław <[email protected]>--- drivers/mfd/Kconfig | 16 + drivers/mfd/Makefile | 1 + drivers/mfd/asus-transformer-ec.c | 542 ++++++++++++++++++++++++ include/linux/mfd/asus-transformer-ec.h | 92 ++++ 4 files changed, 651 insertions(+) create mode 100644 drivers/mfd/asus-transformer-ec.c create mode 100644 include/linux/mfd/asus-transformer-ec.h[...]
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
drivers/mfd/asus-transformer-ec.c new file +16
-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. +*/ +while (retry--) { + ret =i2c_smbus_read_i2c_block_data (ddata->client,ASUSEC_READ_BUF , +ASUSEC_ENTRY_SIZE , + ddata->ec_buf); +if (ret <ASUSEC_ENTRY_SIZE ) +continue ; + +if (ddata->ec_buf[ASUSEC_IRQ_STATUS ] &ASUSEC_OBF_MASK )Quoted 8 lines
Quoted 8 lines
drivers/mfd/asus-transformer-ec.c line 180
Quoted 8 lines
drivers/mfd/asus-transformer-ec.c new file +8
-0+continue ; + +break ; + } +} + +static int asus_ec_log_info (struct asus_ec_data *ddata,unsigned int reg, +const char *name,const char **out)If we can avoid points to pointers, then please do.
We already have ddata, so we can just set the name?
It will remove a lot of the following complexity / ugliness.
Quoted 37 lines
Quoted 4 lines
Quoted 4 lines
drivers/mfd/asus-transformer-ec.c new file +4
-0+{ +struct device *dev = &ddata->client->dev; +u8 buf[ASUSEC_ENTRY_BUFSIZE ]; +int ret;Quoted 9 lines
drivers/mfd/asus-transformer-ec.c line 190
Quoted 6 lines
drivers/mfd/asus-transformer-ec.c new file +6
-0+ +memset (buf,0 ,ASUSEC_ENTRY_BUFSIZE ); + ret =i2c_smbus_read_i2c_block_data (ddata->ec.dockram, reg, +ASUSEC_ENTRY_SIZE , buf); +if (ret <ASUSEC_ENTRY_SIZE ) +return ret;Same here. These should be negative.
return ret < 0 ? ret :
-EIOsame as aboveQuoted 11 lines
Quoted 11 lines
drivers/mfd/asus-transformer-ec.c new file +11
-0+ +if (buf[0 ] >ASUSEC_ENTRY_SIZE ) { +dev_err (dev,"bad data len; buffer: %*ph; ret: %d\n" , +ASUSEC_ENTRY_BUFSIZE , buf, ret); +return -EPROTO ; + } + +if (!ddata->logging_disabled) { +dev_info (dev,"%-14s: %.*s\n" , name, buf[0 ], buf +1 ); + +if (out) {Quoted 9 lines
drivers/mfd/asus-transformer-ec.c line 207
Quoted 6 lines
drivers/mfd/asus-transformer-ec.c new file +6
-0+ *out =devm_kasprintf (dev,GFP_KERNEL ,"%.*s" , + buf[0 ], buf +1 ); +if (!*out) +return -ENOMEM ; + } + }FWIW, I hate this! What does it give you now that development is done?
Quoted 7 lines
We have already discussed this, and you agreed that EC and firmware prints may stay! This prints EC model and firmware info as well as EC firmware behavior. It allows identify possible new revisions of EC - Firmware combo and address possible regressions (check if it is chip malfunction or firmware needs a new programming model) without rebuilding kernel and digging downstream kernel for needed bits of code.
Right, so just print it out and remove all of the '
logging_disabled' and 'out' nonsense.Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
drivers/mfd/asus-transformer-ec.c new file +4
-0+return 0 ; +} + +static int asus_ec_reset (struct asus_ec_data *ddata)Quoted 9 lines
drivers/mfd/asus-transformer-ec.c line 218
Quoted 6 lines
drivers/mfd/asus-transformer-ec.c new file +6
-0+{ +int retry, ret; + +guard (mutex)(&ddata->ecreq_lock); + +for (retry =0 ; retry <ASUSEC_RETRY_MAX ; retry++) {for (int retry = ... is generally preferred for throwaway variables.
Quoted 2 lines
Not that I care too much, but I am defining ret anyway, why not add retry too there?
This is the new and preferred way to use throw-away variables.
ret is not a throw-away variable.
[...]
Quoted 13 lines
Quoted 13 lines
drivers/mfd/asus-transformer-ec.c line 256
Quoted 10 lines
drivers/mfd/asus-transformer-ec.c new file +10
-0+static int asus_ec_set_factory_mode (struct asus_ec_data *ddata, +enum asusec_mode fmode) +{ +dev_info (&ddata->client->dev,"Entering %s mode.\n" , + fmode ==ASUSEC_MODE_FACTORY ?"factory" :"normal" ); + +return asus_dockram_access_ctl (ddata->ec.dockram,NULL , +ASUSEC_CTL_FACTORY_MODE , + fmode ==ASUSEC_MODE_FACTORY ? +ASUSEC_CTL_FACTORY_MODE :0 );Why not create make:
Quoted 6 lines
Quoted 4 lines
ASUSEC_MODE_FACTORY==ASUSEC_CTL_FACTORY_MODEWhat happens to NORMAL?
ASUSEC_CTL_FACTORY_MODEis a bit in the ctl register. For NORMAL modeI get that, but if the values can be shared, it make the code simpler.
Quoted 3 lines
bit is cleared,
for FACTORY bit it set, for NONE bit is ignored.
Quoted 17 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/mfd/asus-transformer-ec.c new file +6
-0+} + +static int asus_ec_detect (struct asus_ec_data *ddata) +{ +int ret; +Quoted 8 lines
Quoted 8 lines
drivers/mfd/asus-transformer-ec.c line 270
Quoted 8 lines
drivers/mfd/asus-transformer-ec.c new file +8
-0+ ret =asus_ec_reset (ddata); +if (ret) + goto err_exit; + +asus_ec_clear_buffer (ddata); + + ret =asus_ec_log_info (ddata,ASUSEC_DOCKRAM_INFO_MODEL ,"Model" , + &ddata->ec.model);Where is this model used?
Model is passed to cells to form names, particularly input device names.
Quoted 33 lines
Quoted 5 lines
Quoted 2 lines
You can use 100-chars and make the code look beautiful! :)
Not every subsystem permits 100 chars, some stick to 80 as a strict rule, so it is better be safe.
Right, but we are forward thinking here.
You can and should use 100-chars in this subsystem.
Quoted 23 lines
Quoted 22 lines
Quoted 9 lines
drivers/mfd/asus-transformer-ec.c new file +9
-0+if (ret) + goto err_exit; + + ret =asus_ec_log_info (ddata,ASUSEC_DOCKRAM_INFO_FW ,"FW version" , +NULL ); +if (ret) + goto err_exit; + + ret = asus_ec_log_info(ddata, ASUSEC_DOCKRAM_INFO_CFGFMT, "Config format",drivers/mfd/asus-transformer-ec.c line 289
Quoted 10 lines
drivers/mfd/asus-transformer-ec.c new file +10
-0+ NULL); +if (ret) + goto err_exit; + + ret =asus_ec_log_info (ddata,ASUSEC_DOCKRAM_INFO_HW ,"HW version" , +NULL ); +if (ret) + goto err_exit; + +/* Disable logging on next EC request */ Why, but why?
Quoted 8 lines
Quoted 2 lines
Cause EC requests are frequent (handshake/reset) and constant logging same data is not acceptable.
Then rid the prints entirely or do them at a more appropriate point like during probe?
Or maybe consider
dev_info_once()and friends.
I totally forgot about dev_info_once(), thank you.
Quoted 53 lines
Quoted 53 lines
Quoted 43 lines
Quoted 30 lines
drivers/mfd/asus-transformer-ec.c new file +30
-0+ ddata->logging_disabled = true; + +/* Check and inform about EC firmware behavior */ + ret =asus_ec_susb_on_status (ddata); +if (ret) + goto err_exit; + + ddata->ec.name = ddata->info->name; + +/* Some EC require factory mode to be set normal on each request */ +if (ddata->info->fmode) + ret =asus_ec_set_factory_mode (ddata, ddata->info->fmode); + +err_exit: +if (ret) +dev_err (&ddata->client->dev,"failed to access EC: %d\n" , ret); + +return ret; +} + +static void asus_ec_handle_smi (struct asus_ec_data *ddata,unsigned int code) +{ +switch (code) { +case ASUSEC_SMI_HANDSHAKE : +case ASUSEC_SMI_RESET : +asus_ec_detect (ddata); +break ; + } +} +drivers/mfd/asus-transformer-ec.c line 329
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 , +ASUSEC_ENTRY_SIZE , ddata->ec_buf); +if (ret <ASUSEC_ENTRY_SIZE || + !(ddata->ec_buf[ASUSEC_IRQ_STATUS ] &ASUSEC_OBF_MASK ))Unwrap for readability.
Quoted 2 lines
Also, I think a comment would be helpful.
if (ret <
ASUSEC_ENTRY_SIZE)return IRQ_NONE;ret = ddata->ec_buf[ASUSEC_IRQ_STATUS] &
ASUSEC_OBF_MASK; if (!ret)return IRQ_NONE;
Quoted 6 lines
Quoted 1 line
This would be acceptable? (I will add comments later on)
Yes, better.
If you're not using ret again, you could just put 'ddata.." inside the
if().
I thought about this, but that would require combining it with (!) which will not help with readabilty.
Quoted 36 lines
Quoted 36 lines
Quoted 35 lines
Quoted 21 lines
drivers/mfd/asus-transformer-ec.c new file +21
-0+return IRQ_NONE ; + + notify_action = ddata->ec_buf[ASUSEC_IRQ_STATUS ]; +if (notify_action &ASUSEC_SMI_MASK ) { +unsigned int code = ddata->ec_buf[ASUSEC_SMI_CODE ]; + +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 ; +} + +static void asus_ec_release_dockram_dev (void *client) +{ +i2c_unregister_device (client); +}drivers/mfd/asus-transformer-ec.c line 360
Quoted 10 lines
drivers/mfd/asus-transformer-ec.c new file +10
-0+ +static struct i2c_client *devm_asus_dockram_get (struct device *dev) +{ +struct i2c_client *parent =to_i2c_client (dev); +struct i2c_client *dockram; +struct dockram_ec_data *ddata; +int ret; + + dockram =i2c_new_ancillary_device (parent,"dockram" , + parent->addr +2 );Could we define a macro for the address offset '2' here to avoid using a magic number?
Quoted 8 lines
Quoted 1 line
It seems that you are excessively concerned with "magic numbers".
Bingo! I HATE magic numbers.
https://lore.kernel.org/all/?q=%22Lee+Jones%22+magic
~900 messages! =:-D
AHAHAH, ok, this makes things clearer. Lemmy have a note about this quirk.
Quoted 11 lines
[...]
Quoted 9 lines
Quoted 8 lines
drivers/mfd/asus-transformer-ec.c line 510
Quoted 5 lines
drivers/mfd/asus-transformer-ec.c new file +5
-0+static const struct asus_ec_chip_info asus_ec_tf600t_pad_data = { + .name ="pad" , + .variant =ASUSEC_TF600T_PAD , + .fmode =ASUSEC_MODE_NORMAL , +};Any reason not to just pass the identifier (variant) and add the name and fmode attribues to the
switch()above?
Quoted 8 lines
Quoted 1 line
Why not set it here, I am not passing any mfd or any other API via of data.
I get that, and you're not breaking any of my golden rules.
However, I just think doing everything in one place, usually a which based off of the 'variant' which you pass as a single value, is a nicer, more consolidated way of doing things.
Well, I would need to pass OF data regardless, so why not bundle it with all required info and leave probes switch for strictly mfd cell assignment. I suppose this is more a personal preference issue. I hope you will not mind if I leave this as it is?
All other comments you have left and I did not answer directly were read and acknowledged. Thank you!
Quoted 2 lines
--
Lee Jones
PATCH v8 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 | 158 ++++++++++++++++++ 3 files changed, 174 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 +158 -0
158 lines not on this page · raw message
Signature · 1 line
2.51.0
[email protected]
AI reviewRe: [PATCH v8 3/7] input: serio: Add driver for ASUS Transformer dock keyboard and touchpad
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] The serio->write callback calls a sleeping I2C API, violating the atomic context requirements of…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The serio->write callback calls a sleeping I2C API, violating the atomic context requirements of the serio subsystem.
- [High] Serio ports are registered before the EC notifier is active, which can lead to dropped hardware ACKs and driver probe timeouts. --
commit c384b4357257c7b443531cb85e3b65aa83067d31
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 handles incoming scancodes, remaps specific keys to match the standard AT layout, and forwards the data to the serio subsystem.
[ ... ]
Quoted 6 lines
drivers/input/serio/asus-transformer-ec-kbc.c new file +0
-0@@ -0,0 +1,158 @@
[ ... ]
drivers/input/serio/asus-transformer-ec-kbc.c line 79
Quoted 7 lines
drivers/input/serio/asus-transformer-ec-kbc.c new file +7
-0+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); +}
[Severity: High]
Does this code sleep in an atomic context?
The i2c_smbus_write_word_data() function takes the I2C adapter's mutex and sleeps while waiting for the synchronous transaction to complete.
However, the serio core and keyboard/mouse drivers frequently call serio_write() from atomic contexts. For example, the core serio_interrupt() function holds the port's spinlock with interrupts disabled:
serio_interrupt() {
guard(spinlock_irqsave)(&serio->lock);
...
serio->drv->interrupt(...) // calls driver interrupt which may write
}If a driver like atkbd needs to resend a command or respond to a hardware NAK, it calls serio_write() directly from this interrupt handler.
Executing a sleeping I2C write while holding a spinlock with interrupts disabled will trigger a "scheduling while atomic" bug or cause a system deadlock.
[ ... ]
Quoted 17 lines
drivers/input/serio/asus-transformer-ec-kbc.c new file +17
-0+static int asus_ec_kbc_probe (struct platform_device *pdev) +{ +struct asusec_core *ec =dev_get_drvdata (pdev->dev.parent); +struct asus_ec_kbc_data *priv; +int error; + + priv =devm_kzalloc (&pdev->dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + +platform_set_drvdata (pdev, priv); + + priv->ec = ec; + priv->parent =to_i2c_client (pdev->dev.parent); + + error =asus_ec_register_serio (pdev,0 ,"Keyboard" ,0 ); +if (error)
drivers/input/serio/asus-transformer-ec-kbc.c line 138
Quoted 10 lines
drivers/input/serio/asus-transformer-ec-kbc.c new file +10
-0+return error; + + error =asus_ec_register_serio (pdev,1 ,"Touchpad" ,I8042_CMD_AUX_SEND ); +if (error) +return error; + + priv->nb.notifier_call = asus_ec_kbc_notify; + +return blocking_notifier_chain_register (&ec->notify_list, &priv->nb); +}
[Severity: High]
Can this cause driver probe timeouts by dropping hardware ACKs?
The asus_ec_register_serio() calls are exposing the keyboard and touchpad to the serio subsystem before the EC notifier is attached. The serio port registration asynchronously queues work on the kseriod workqueue, which finds and binds drivers.
Since the kseriod workqueue can run concurrently on another CPU, it may send initialization commands and the hardware may respond before this probe function reaches blocking_notifier_chain_register().
Because the notifier is not yet attached to receive and forward these ACKs, the events will be dropped. This causes the bound driver's probe to time out and fail, leaving the input devices non-functional.
Should the notifier be fully registered before the serio ports are exposed?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH v8 3/7] input: serio: Add driver for ASUS Transformer dock keyboard and touchpad
In reply to Svyatoslav Ryhelчт, 28 трав. 2026 р. о 08:32 Svyatoslav Ryhel <[email protected]> пише:
Quoted 13 lines
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.
Co-developed-by Ion Agorria <[email protected]>Signed-off-by Ion Agorria <[email protected]>Signed-off-by Michał Mirosław <[email protected]>Signed-off-by Svyatoslav Ryhel <[email protected]>
Quoted 6 lines
--- drivers/input/serio/Kconfig | 15 ++ drivers/input/serio/Makefile | 1 + drivers/input/serio/asus-transformer-ec-kbc.c | 158 ++++++++++++++++++ 3 files changed, 174 insertions(+) create mode 100644 drivers/input/serio/asus-transformer-ec-kbc.c
Hello Dmitry! May you please take a look and Ack it if you are fine this this driver or tell what I should adjust? That would be very helpful. Thank you.
PATCH v8 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 | 286 ++++++++++++++++++ 3 files changed, 297 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 +286 -0
286 lines not on this page · raw message
Signature · 1 line
2.51.0
[email protected]
AI reviewRe: [PATCH v8 4/7] input: keyboard: Add driver for ASUS Transformer dock multimedia keys
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] The driver registers a global input handler to snoop keystrokes from all input devices in the…
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] The driver registers a global input handler to snoop keystrokes from all input devices in the system, violating driver boundaries.
- [High] The input_dev's name, phys, and keycode fields point to devres-managed memory that is freed when the driver unbinds, causing a Use-After-Free if userspace holds the input device open.
- [Medium] The state flags special_key_pressed and special_key_mode are accessed and modified concurrently from multiple contexts without any locking or synchronization.
- [Low] The driver unregisters the input handler before unregistering the hardware event notifier in the remove function, violating the reverse-order teardown principle. --
commit ed5ee673506765c49f751d4f9cce6ec50eda686c
Author: Michał Mirosław <[email protected]>
Subject: input: keyboard: Add driver for ASUS Transformer dock multimedia keys
This commit adds support for the multimedia top button row of the ASUS Transformer's Mobile Dock keyboard. It switches to multimedia keys when ScreenLock + AltGr are pressed.
Quoted 6 lines
drivers/input/keyboard/asus-transformer-ec-keys.c new file +0
-0@@ -0,0 +1,286 @@
[ ... ]
drivers/input/keyboard/asus-transformer-ec-keys.c line 32
Quoted 9 lines
drivers/input/keyboard/asus-transformer-ec-keys.c new file +9
-0+static void asus_ec_input_event (struct input_handle *handle, +unsigned int event_type, +unsigned int event_code,int value) +{ +struct asus_ec_keys_data *priv = handle->handler->private; + +/* Store special key state */ +if (event_type ==EV_KEY && event_code ==KEY_RIGHTALT ) + priv->special_key_pressed = !!value;
[Severity: Medium]
Can this result in a data race on special_key_pressed?
The asus_ec_input_event() function writes to special_key_pressed from the input event delivery context, which often runs in hardirq or softirq.
Concurrently, asus_ec_keys_process_key() reads this flag and modifies special_key_mode from a process context via the blocking notifier chain.
Could concurrent execution lead to missed key modifiers or lost mode updates without synchronization primitives or READ_ONCE() annotations?
Quoted 1 line
+}
[ ... ]
drivers/input/keyboard/asus-transformer-ec-keys.c line 81
Quoted 7 lines
drivers/input/keyboard/asus-transformer-ec-keys.c new file +7
-0+static const struct input_device_id asus_ec_input_ids[] = { + { + .flags =INPUT_DEVICE_ID_MATCH_EVBIT , + .evbit = {BIT_MASK (EV_KEY ) }, + }, + { } +};
[Severity: High]
Does this input_device_id match any device with EV_KEY capabilities, causing the driver to intercept key events globally?
If a user unplugs an unrelated external USB keyboard while the RIGHTALT key is currently held down, could the special_key_pressed state remain permanently stuck?
[ ... ]
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) +{
[ ... ]
Quoted 1 line
drivers/input/keyboard/asus-transformer-ec-keys.c new file +1
-0+ priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL );
[ ... ]
drivers/input/keyboard/asus-transformer-ec-keys.c line 228
Quoted 9 lines
drivers/input/keyboard/asus-transformer-ec-keys.c new file +9
-0+ priv->xidev =devm_input_allocate_device (dev); +if (!priv->xidev) +return -ENOMEM ; + + priv->xidev->name =devm_kasprintf (dev,GFP_KERNEL ,"%s Keyboard Ext" , + ec->model); + priv->xidev->phys =devm_kasprintf (dev,GFP_KERNEL ,"i2c-%u-%04x" , +i2c_adapter_id (parent->adapter), + parent->addr);
[Severity: High]
Does this code introduce a use-after-free regression if userspace holds the input device open during an unbind?
The priv->xidev->name and priv->xidev->phys strings, as well as the priv->keymap array assigned to dev->keycode, are managed by devres and will be freed when the driver unbinds.
However, if a userspace process holds a file descriptor to the evdev node, the input_dev object is kept alive via reference counting.
Could a subsequent ioctl from userspace, such as EVIOCGNAME, attempt to read from these already-freed pointers?
[ ... ]
drivers/input/keyboard/asus-transformer-ec-keys.c line 273
Quoted 7 lines
drivers/input/keyboard/asus-transformer-ec-keys.c new file +7
-0+static void asus_ec_keys_remove (struct platform_device *pdev) +{ +struct asus_ec_keys_data *priv =platform_get_drvdata (pdev); +struct asusec_core *ec = priv->ec; + +input_unregister_handler (&priv->input_handler); +blocking_notifier_chain_unregister (&ec->notify_list, &priv->nb);
[Severity: Low]
Does this remove sequence violate the reverse-order teardown principle?
In asus_ec_keys_probe(), the driver registers the input handler first, followed by the EC notifier chain.
Unregistering the handler first opens a race window where the software tracking is disconnected but the driver is still registered to receive hardware events from the EC.
Can the driver still process events in a partially dismantled state?
Quoted 1 line
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [PATCH v8 4/7] input: keyboard: Add driver for ASUS Transformer dock multimedia keys
In reply to Svyatoslav Ryhelчт, 28 трав. 2026 р. о 08:32 Svyatoslav Ryhel <[email protected]> пише:
Quoted 14 lines
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.
Co-developed-by Ion Agorria <[email protected]>Signed-off-by Ion Agorria <[email protected]>Signed-off-by Michał Mirosław <[email protected]>Signed-off-by Svyatoslav Ryhel <[email protected]>
Quoted 7 lines
--- drivers/input/keyboard/Kconfig | 10 + drivers/input/keyboard/Makefile | 1 + .../input/keyboard/asus-transformer-ec-keys.c | 286 ++++++++++++++++++ 3 files changed, 297 insertions(+) create mode 100644 drivers/input/keyboard/asus-transformer-ec-keys.c
Hello Dmitry! May you please take a look and Ack it if you are fine this this driver or tell what I should adjust? That would be very helpful. Thank you.
Dmitry Torokhov
maintainerRe: [PATCH v8 4/7] input: keyboard: Add driver for ASUS Transformer dock multimedia keys
In reply to Svyatoslav RyhelHi Svyatoslav,
Quoted 8 lines · 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.
I think using input handler to intercept ScreenLock + AltGr is quite awkward. I think this also passes the original key events (unless you make it a filter not a regular handler).
I do not see benefit for reacting to AltGr+ScreenLock on other keyboards to activate the special mode on this one. So given the fact that you already mange the data stream when you split it into "serio" ports, maybe just intercept this key combo right there and create the input device and signal input events right there?
Thanks.
Signature · 1 line
Dmitry
Re: [PATCH v8 4/7] input: keyboard: Add driver for ASUS Transformer dock multimedia keys
вт, 16 черв. 2026 р. о 07:26 Dmitry Torokhov <[email protected]> пише:
Quoted 17 lines
Hi Svyatoslav,
Quoted 8 lines · 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.
I think using input handler to intercept ScreenLock + AltGr is quite awkward. I think this also passes the original key events (unless you make it a filter not a regular handler).
Quoted 6 lines
I do not see benefit for reacting to AltGr+ScreenLock on other keyboards to activate the special mode on this one. So given the fact that you already mange the data stream when you split it into "serio" ports, maybe just intercept this key combo right there and create the input device and signal input events right there?
Though it seems awkward at a first glance, media keys are integrated with a standard keyboard in a detachable dock. It is highly unlikely that media keys will be used with a different keyboard then the one that is integrated with dock. Additionally, the ScreenLock key has a code specific to this driver and is not in general use, so even if any standard keyboard has AltGr but none has ScreenLock specific to this driver except the dock itself. Handler is also set as observer so it should not interfere with work of other input devices.
Quoted 4 lines
Thanks.
--
Dmitry
Dmitry Torokhov
maintainerRe: [PATCH v8 4/7] input: keyboard: Add driver for ASUS Transformer dock multimedia keys
Quoted 25 lines · Svyatoslav Ryhel
вт, 16 черв. 2026 р. о 07:26 Dmitry Torokhov <[email protected]> пише:
Quoted 17 lines
Hi Svyatoslav,
Quoted 8 lines · 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.
I think using input handler to intercept ScreenLock + AltGr is quite awkward. I think this also passes the original key events (unless you make it a filter not a regular handler).
Quoted 6 lines
I do not see benefit for reacting to AltGr+ScreenLock on other keyboards to activate the special mode on this one. So given the fact that you already mange the data stream when you split it into "serio" ports, maybe just intercept this key combo right there and create the input device and signal input events right there?
Quoted 8 lines
Though it seems awkward at a first glance, media keys are integrated with a standard keyboard in a detachable dock. It is highly unlikely that media keys will be used with a different keyboard then the one that is integrated with dock. Additionally, the ScreenLock key has a code specific to this driver and is not in general use, so even if any standard keyboard has AltGr but none has ScreenLock specific to this driver except the dock itself. Handler is also set as observer so it should not interfere with work of other input devices.
I am not concerned about it interfering with other drivers, I am concerned about it unnecessarily connecting to unrelated devices (anything that declares EV_KEY).
Again, I think having input handler is not appropriate here. I would fold this patch into the patch that introduces the 2 serio ports, enhanced the data stream analysis to detect your key combo, and then report through this new input device. You do not need to have the round trip through atkbd and the new input handler for this.
Thanks.
Signature · 1 line
Dmitry
Re: [PATCH v8 4/7] input: keyboard: Add driver for ASUS Transformer dock multimedia keys
ср, 17 черв. 2026 р. о 00:23 Dmitry Torokhov <[email protected]> пише:
Quoted 40 lines · Svyatoslav Ryhel
Quoted 25 lines
вт, 16 черв. 2026 р. о 07:26 Dmitry Torokhov <[email protected]> пише:
Quoted 17 lines
Hi Svyatoslav,
Quoted 8 lines · 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.
I think using input handler to intercept ScreenLock + AltGr is quite awkward. I think this also passes the original key events (unless you make it a filter not a regular handler).
Quoted 6 lines
I do not see benefit for reacting to AltGr+ScreenLock on other keyboards to activate the special mode on this one. So given the fact that you already mange the data stream when you split it into "serio" ports, maybe just intercept this key combo right there and create the input device and signal input events right there?
Quoted 8 lines
Though it seems awkward at a first glance, media keys are integrated with a standard keyboard in a detachable dock. It is highly unlikely that media keys will be used with a different keyboard then the one that is integrated with dock. Additionally, the ScreenLock key has a code specific to this driver and is not in general use, so even if any standard keyboard has AltGr but none has ScreenLock specific to this driver except the dock itself. Handler is also set as observer so it should not interfere with work of other input devices.
I am not concerned about it interfering with other drivers, I am concerned about it unnecessarily connecting to unrelated devices (anything that declares
EV_KEY).
Quoted 6 lines
Again, I think having input handler is not appropriate here. I would fold this patch into the patch that introduces the 2 serio ports, enhanced the data stream analysis to detect your key combo, and then report through this new input device. You do not need to have the round trip through atkbd and the new input handler for this.
I will try with filtering first if you don't mind. If that will not work I'll consider folding. Do you have any good examples of handler with filter to use as an inspiration? Thank you.
Quoted 4 lines
Thanks.
--
Dmitry
Re: [PATCH v8 4/7] input: keyboard: Add driver for ASUS Transformer dock multimedia keys
чт, 18 черв. 2026 р. о 12:18 Svyatoslav Ryhel <[email protected]> пише:
Quoted 42 lines
ср, 17 черв. 2026 р. о 00:23 Dmitry Torokhov <[email protected]> пише:
Quoted 40 lines · Svyatoslav Ryhel
Quoted 25 lines
вт, 16 черв. 2026 р. о 07:26 Dmitry Torokhov <[email protected]> пише:
Quoted 17 lines
Hi Svyatoslav,
Quoted 8 lines · 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.
I think using input handler to intercept ScreenLock + AltGr is quite awkward. I think this also passes the original key events (unless you make it a filter not a regular handler).
Quoted 6 lines
I do not see benefit for reacting to AltGr+ScreenLock on other keyboards to activate the special mode on this one. So given the fact that you already mange the data stream when you split it into "serio" ports, maybe just intercept this key combo right there and create the input device and signal input events right there?
Quoted 8 lines
Though it seems awkward at a first glance, media keys are integrated with a standard keyboard in a detachable dock. It is highly unlikely that media keys will be used with a different keyboard then the one that is integrated with dock. Additionally, the ScreenLock key has a code specific to this driver and is not in general use, so even if any standard keyboard has AltGr but none has ScreenLock specific to this driver except the dock itself. Handler is also set as observer so it should not interfere with work of other input devices.
I am not concerned about it interfering with other drivers, I am concerned about it unnecessarily connecting to unrelated devices (anything that declares
EV_KEY).
I can add check in asus_ec_input_connect() to strictly connect only to dock keyboard, will this be sufficient?
Quoted 5 lines
Quoted 5 lines
Again, I think having input handler is not appropriate here. I would fold this patch into the patch that introduces the 2 serio ports, enhanced the data stream analysis to detect your key combo, and then report through this new input device. You do not need to have the round trip through atkbd and the new input handler for this.
This sounds like a load of additional work, I would rather remove layout swapping entirely (even though it is a useful feature) then rewrite everything from scratch.
Quoted 10 lines
Quoted 1 line
I will try with filtering first if you don't mind. If that will not work I'll consider folding. Do you have any good examples of handler with filter to use as an inspiration? Thank you.
Quoted 4 lines
Thanks.
--
Dmitry
PATCH v8 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 | 125 ++++++++++++++++++++++++ 3 files changed, 137 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 +125 -0
125 lines not on this page · raw message
Signature · 1 line
2.51.0
Lee Jones
maintainerRe: [PATCH v8 5/7] leds: Add driver for ASUS Transformer LEDs
Quoted 65 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.
Co-developed-by Svyatoslav Ryhel <[email protected]>Signed-off-by Svyatoslav Ryhel <[email protected]>Signed-off-by Michał Mirosław <[email protected]>--- drivers/leds/Kconfig | 11 +++ drivers/leds/Makefile | 1 + drivers/leds/leds-asus-transformer-ec.c | 125 ++++++++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 drivers/leds/leds-asus-transformer-ec.cdrivers/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_CLASSdrivers/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.odrivers/leds/leds-asus-transformer-ec.c new file +9
-0@@ -0,0 +1,125 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include <linux/err.h> +#include <linux/leds.h> +#include <linux/mfd/asus-transformer-ec.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/slab.h> +
drivers/leds/leds-asus-transformer-ec.c line 19
Quoted 10 lines
drivers/leds/leds-asus-transformer-ec.c new file +10
-0+enum { +ASUSEC_LED_AMBER , +ASUSEC_LED_GREEN , +ASUSEC_LED_MAX +}; + +struct asus_ec_led_config { +const char *name; +unsigned int color; +unsigned long long ctrl_bit;
Should we use 'u64' here instead of 'unsigned long long' to align with standard kernel integer types?
drivers/leds/leds-asus-transformer-ec.c line 25
Quoted 6 lines
drivers/leds/leds-asus-transformer-ec.c new file +6
-0+}; + +struct asus_ec_led { +struct asus_ec_leds_data *ddata; +struct led_classdev cdev; +unsigned long long ctrl_bit;
Should we use 'u64' here as well to keep it consistent?
Quoted 14 lines
drivers/leds/leds-asus-transformer-ec.c new file +14
-0+}; + +struct asus_ec_leds_data { +const struct asusec_core *ec; +struct asus_ec_led leds[ASUSEC_LED_MAX ]; +}; + +static const struct asus_ec_led_config asus_ec_leds[] = { + [ASUSEC_LED_AMBER ] = { + .name ="amber" , + .color =LED_COLOR_ID_AMBER , + .ctrl_bit =ASUSEC_CTL_LED_AMBER , + }, + [ASUSEC_LED_GREEN ] = {
drivers/leds/leds-asus-transformer-ec.c line 49
Quoted 10 lines
drivers/leds/leds-asus-transformer-ec.c new file +10
-0+ .name = "green", + .color = LED_COLOR_ID_GREEN, + .ctrl_bit = ASUSEC_CTL_LED_GREEN, + }, +}; + +static enum led_brightness asus_ec_led_get_brightness (struct led_classdev *cdev) +{ + struct asus_ec_led *led = container_of(cdev, struct asus_ec_led, cdev); +const struct asusec_core *ec = led->ddata->ec;
I'm getting confused here.
ddata is what I'd be calling the device data struct passed by the parent?
In fact, ddata is a little known concept in Leds. Any reason to go for this over the standard nomenclature?
drivers/leds/leds-asus-transformer-ec.c line 53
Quoted 4 lines
drivers/leds/leds-asus-transformer-ec.c new file +4
-0+u64 ctl; +int ret; + + ret =asus_dockram_access_ctl (ec->dockram, &ctl,0 ,0 );
Did we discuss preferring regmap already?
Quoted 15 lines
drivers/leds/leds-asus-transformer-ec.c new file +15
-0+if (ret) +return LED_OFF ; + +return ctl & led->ctrl_bit ?LED_ON :LED_OFF ; +} + +static int asus_ec_led_set_brightness (struct led_classdev *cdev, +enum led_brightness brightness) +{ + struct asus_ec_led *led = container_of(cdev, struct asus_ec_led, cdev); +const struct asusec_core *ec = led->ddata->ec; + +if (brightness) +return asus_dockram_access_ctl (ec->dockram,NULL , + led->ctrl_bit, led->ctrl_bit);
drivers/leds/leds-asus-transformer-ec.c line 78
Quoted 10 lines
drivers/leds/leds-asus-transformer-ec.c new file +10
-0+ +return asus_dockram_access_ctl (ec->dockram,NULL , led->ctrl_bit,0 ); +} + +static int asus_ec_led_probe (struct platform_device *pdev) +{ +const struct asusec_core *ec =dev_get_drvdata (pdev->dev.parent); +struct asus_ec_leds_data *ddata; +struct device *dev = &pdev->dev; +int i, ret;
Could we declare the loop counter 'i' directly within the 'for' statement's scope to keep its scope limited? For example, 'for (int i = 0; ...)'.
drivers/leds/leds-asus-transformer-ec.c line 87
Quoted 9 lines
drivers/leds/leds-asus-transformer-ec.c new file +9
-0+ + ddata =devm_kzalloc (dev,sizeof (*ddata),GFP_KERNEL ); +if (!ddata) +return -ENOMEM ; + +platform_set_drvdata (pdev, ddata); + ddata->ec = ec; + +for (i =0 ; i <ASUSEC_LED_MAX ; i++) {
Nit: for (int i = ...
Quoted 12 lines
drivers/leds/leds-asus-transformer-ec.c new file +12
-0+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 ; + led->cdev.brightness_get = asus_ec_led_get_brightness;
drivers/leds/leds-asus-transformer-ec.c line 109
Quoted 10 lines
drivers/leds/leds-asus-transformer-ec.c new file +10
-0+ led->cdev.brightness_set_blocking = asus_ec_led_set_brightness; + + led->ddata = ddata; + led->ctrl_bit = cfg->ctrl_bit; + + ret =devm_led_classdev_register (dev, &led->cdev); +if (ret) +return dev_err_probe (dev, ret, +"failed to register %s LED\n" , + cfg->name);
Should we capitalise the error message here to match our style guidelines (e.g. 'Failed to register...')?
Quoted 20 lines
drivers/leds/leds-asus-transformer-ec.c new file +16
-0+ } + +return 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_ALIAS ("platform:asus-transformer-ec-led" ); +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
Re: [PATCH v8 5/7] leds: Add driver for ASUS Transformer LEDs
чт, 11 черв. 2026 р. о 14:30 Lee Jones <[email protected]> пише:
Quoted 73 lines · Svyatoslav Ryhel
Quoted 71 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.
Co-developed-by Svyatoslav Ryhel <[email protected]>Signed-off-by Svyatoslav Ryhel <[email protected]>Signed-off-by Michał Mirosław <[email protected]>--- drivers/leds/Kconfig | 11 +++ drivers/leds/Makefile | 1 + drivers/leds/leds-asus-transformer-ec.c | 125 ++++++++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 drivers/leds/leds-asus-transformer-ec.cdrivers/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_CLASSdrivers/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.odrivers/leds/leds-asus-transformer-ec.c new file +14
-0@@ -0,0 +1,125 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include <linux/err.h> +#include <linux/leds.h> +#include <linux/mfd/asus-transformer-ec.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/slab.h> + +enum { +ASUSEC_LED_AMBER , +ASUSEC_LED_GREEN , +ASUSEC_LED_MAX +};
Quoted 9 lines
drivers/leds/leds-asus-transformer-ec.c line 19
Quoted 5 lines
drivers/leds/leds-asus-transformer-ec.c new file +5
-0+ +struct asus_ec_led_config { +const char *name; +unsigned int color; +unsigned long long ctrl_bit;Should we use 'u64' here instead of 'unsigned long long' to align with standard kernel integer types?
sure
Quoted 9 lines
drivers/leds/leds-asus-transformer-ec.c line 25
Quoted 6 lines
drivers/leds/leds-asus-transformer-ec.c new file +6
-0+}; + +struct asus_ec_led { +struct asus_ec_leds_data *ddata; +struct led_classdev cdev; +unsigned long long ctrl_bit;Should we use 'u64' here as well to keep it consistent?
sure
Quoted 27 lines
Quoted 14 lines
drivers/leds/leds-asus-transformer-ec.c new file +14
-0+}; + +struct asus_ec_leds_data { +const struct asusec_core *ec; +struct asus_ec_led leds[ASUSEC_LED_MAX ]; +}; + +static const struct asus_ec_led_config asus_ec_leds[] = { + [ASUSEC_LED_AMBER ] = { + .name ="amber" , + .color =LED_COLOR_ID_AMBER , + .ctrl_bit =ASUSEC_CTL_LED_AMBER , + }, + [ASUSEC_LED_GREEN ] = {drivers/leds/leds-asus-transformer-ec.c line 49
Quoted 10 lines
drivers/leds/leds-asus-transformer-ec.c new file +10
-0+ .name = "green", + .color = LED_COLOR_ID_GREEN, + .ctrl_bit = ASUSEC_CTL_LED_GREEN, + }, +}; + +static enum led_brightness asus_ec_led_get_brightness (struct led_classdev *cdev) +{ + struct asus_ec_led *led = container_of(cdev, struct asus_ec_led, cdev); +const struct asusec_core *ec = led->ddata->ec;I'm getting confused here.
Quoted 5 lines
ddata is what I'd be calling the device data struct passed by the parent?
In fact, ddata is a little known concept in Leds. Any reason to go for this over the standard nomenclature?
How then it should be named? It holds each LED's control bit.
Quoted 7 lines
drivers/leds/leds-asus-transformer-ec.c line 53
Quoted 4 lines
drivers/leds/leds-asus-transformer-ec.c new file +4
-0+u64 ctl; +int ret; + + ret =asus_dockram_access_ctl (ec->dockram, &ctl,0 ,0 );Did we discuss preferring regmap already?
Yes, you were fine with all and even said that you will merge everything with Dmitry Ack for input
HERE https://lore.kernel.org/lkml/[email protected]/
Yet now I get a new pile of complaints and nits.
Quoted 58 lines
Quoted 15 lines
drivers/leds/leds-asus-transformer-ec.c new file +15
-0+if (ret) +return LED_OFF ; + +return ctl & led->ctrl_bit ?LED_ON :LED_OFF ; +} + +static int asus_ec_led_set_brightness (struct led_classdev *cdev, +enum led_brightness brightness) +{ + struct asus_ec_led *led = container_of(cdev, struct asus_ec_led, cdev); +const struct asusec_core *ec = led->ddata->ec; + +if (brightness) +return asus_dockram_access_ctl (ec->dockram,NULL , + led->ctrl_bit, led->ctrl_bit);drivers/leds/leds-asus-transformer-ec.c line 78
Quoted 10 lines
drivers/leds/leds-asus-transformer-ec.c new file +10
-0+ +return asus_dockram_access_ctl (ec->dockram,NULL , led->ctrl_bit,0 ); +} + +static int asus_ec_led_probe (struct platform_device *pdev) +{ +const struct asusec_core *ec =dev_get_drvdata (pdev->dev.parent); +struct asus_ec_leds_data *ddata; +struct device *dev = &pdev->dev; +int i, ret;Could we declare the loop counter 'i' directly within the 'for' statement's scope to keep its scope limited? For example, 'for (int i = 0; ...)'.
drivers/leds/leds-asus-transformer-ec.c line 87
Quoted 9 lines
drivers/leds/leds-asus-transformer-ec.c new file +9
-0+ + ddata =devm_kzalloc (dev,sizeof (*ddata),GFP_KERNEL ); +if (!ddata) +return -ENOMEM ; + +platform_set_drvdata (pdev, ddata); + ddata->ec = ec; + +for (i =0 ; i <ASUSEC_LED_MAX ; i++) {Nit: for (int i = ...
Quoted 17 lines
drivers/leds/leds-asus-transformer-ec.c new file +17
-0+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 ; + led->cdev.brightness_get = asus_ec_led_get_brightness; + led->cdev.brightness_set_blocking = asus_ec_led_set_brightness; + + led->ddata = ddata; + led->ctrl_bit = cfg->ctrl_bit; +
Quoted 9 lines
drivers/leds/leds-asus-transformer-ec.c line 109
Quoted 5 lines
drivers/leds/leds-asus-transformer-ec.c new file +5
-0+ ret =devm_led_classdev_register (dev, &led->cdev); +if (ret) +return dev_err_probe (dev, ret, +"failed to register %s LED\n" , + cfg->name);Should we capitalise the error message here to match our style guidelines (e.g. 'Failed to register...')?
dev messages end with ":" so it should continue with lower case. You want cap, I don't mind
Quoted 23 lines
Quoted 17 lines
drivers/leds/leds-asus-transformer-ec.c new file +16
-1+ } + +return 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_ALIAS ("platform:asus-transformer-ec-led" ); +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
PATCH v8 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 | 289 ++++++++++++++++++ 3 files changed, 301 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 +289 -0
289 lines not on this page · raw message
Signature · 1 line
2.51.0
[email protected]
AI reviewRe: [PATCH v8 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] Short I2C reads return a positive value that bypasses the caller's error check, leading to…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Short I2C reads return a positive value that bypasses the caller's error check, leading to uninitialized data access and cache bypass.
- [Medium] Off-by-one error in length bounds check allows reading outside the valid EC payload.
--
commit 04954fc98984d98f0039fee1c123ecdf16dc2ff7
Author: Michał Mirosław <[email protected]>
power: supply: Add driver for ASUS Transformer battery
This commit adds a new driver for ASUS Transformer batteries, which implements one battery cell per EC controller and supports reading battery status for the pad and mobile dock.
Quoted 5 lines
drivers/power/supply/asus-transformer-ec-battery.c new file +0
-0
[ ... ]
Quoted 4 lines
drivers/power/supply/asus-transformer-ec-battery.c new file +4
-0+static int asus_ec_battery_refresh (struct asus_ec_battery_data *priv) +{ +struct i2c_client *client = priv->ec->dockram; +struct device *dev = &client->dev;
drivers/power/supply/asus-transformer-ec-battery.c line 47
Quoted 10 lines
drivers/power/supply/asus-transformer-ec-battery.c new file +10
-0+int ret =0 ; + +if (time_before (jiffies, priv->batt_data_ts)) +return ret; + +memset (priv->batt_data,0 ,ASUSEC_ENTRY_BUFSIZE ); + ret =i2c_smbus_read_i2c_block_data (client,ASUSEC_DOCKRAM_BATT_CTL , +ASUSEC_ENTRY_SIZE , priv->batt_data); +if (ret <ASUSEC_ENTRY_SIZE ) +return ret;
[Severity: Medium]
Since i2c_smbus_read_i2c_block_data() returns the number of bytes read on success, could this return a positive value on a short read?
If this returns a positive value less than ASUSEC_ENTRY_SIZE, it bypasses updating the batt_data_ts timestamp, which breaks the 5-second caching mechanism and triggers an I2C transaction on every subsequent property read.
Additionally, asus_ec_battery_get_value() below only checks for errors with if (ret < 0), which would fail to catch this positive short read value as an error, potentially leading to the use of uninitialized data.
[ ... ]
Quoted 13 lines
drivers/power/supply/asus-transformer-ec-battery.c new file +13
-0+static int asus_ec_battery_get_value (struct asus_ec_battery_data *priv, +enum power_supply_property psp) +{ +int ret, offs; + +guard (mutex)(&priv->battery_lock); + +if (psp >=ARRAY_SIZE (asus_ec_battery_prop_offs)) +return -EINVAL ; + + offs = asus_ec_battery_prop_offs[psp]; +if (!offs) +return -EINVAL ;
drivers/power/supply/asus-transformer-ec-battery.c line 110
Quoted 10 lines
drivers/power/supply/asus-transformer-ec-battery.c new file +10
-0+ + ret =asus_ec_battery_refresh (priv); +if (ret <0 ) +return ret; + +if (offs >= priv->batt_data[0 ]) +return -ENODATA ; + +return get_unaligned_le16 (priv->batt_data + offs); +}
[Severity: Medium]
Does this bounds check properly account for the 16-bit read?
Since get_unaligned_le16() reads two bytes, if offs exactly equals priv->batt_data[0] - 1, the bounds check passes. However, the second byte read (offs + 1) would fall outside the valid payload length.
Could this silently combine one byte of valid data with a zero-padded byte from the buffer, returning a corrupted value?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
PATCH v8 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 | 208 ++++++++++++++++++ 3 files changed, 220 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 +208 -0
208 lines not on this page · raw message
Signature · 1 line
2.51.0
[email protected]
AI reviewRe: [PATCH v8 7/7] power: supply: Add charger driver for Asus Transformers
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Strict equality check on `action` bitmask may cause dropped events. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Strict equality check on action bitmask may cause dropped events. --
commit 55ed27a4bfa91a64727ac41721ebdb9163ebef2a
Author: Michał Mirosław <[email protected]>
power: supply: Add charger driver for Asus Transformers
This commit adds a new driver to support charger detection capabilities provided by the embedded controller on ASUS Transformer devices. It reports properties like USB type, charging behaviour, and online status.
Quoted 5 lines
drivers/power/supply/asus-transformer-ec-charger.c new file +0
-0
[ ... ]
drivers/power/supply/asus-transformer-ec-charger.c line 149
Quoted 9 lines
drivers/power/supply/asus-transformer-ec-charger.c new file +9
-0+static int asus_ec_charger_notify (struct notifier_block *nb, +unsigned long action,void *data) +{ +struct asus_ec_charger_data *priv = + container_of(nb, struct asus_ec_charger_data, nb); + +switch (action) { +case ASUSEC_SMI_ACTION (POWER_NOTIFY ): +case ASUSEC_SMI_ACTION (ADAPTER_EVENT ):
[Severity: Medium]
Will this strict equality check cause charger events to be dropped if multiple interrupt flags are set simultaneously?
The action parameter appears to be constructed by the parent MFD driver by taking the raw ASUSEC_IRQ_STATUS byte and OR'ing it with the SMI code shifted by 8 bits. Since ASUSEC_IRQ_STATUS is a bitmask, if an SMI event occurs concurrently with another event (such as a keyboard press), the action bitmask will contain additional bits.
Could this strict switch check be replaced by checking the ASUSEC_SMI_MASK with a bitwise AND operation, and then evaluating the SMI code separately?
Quoted 6 lines
drivers/power/supply/asus-transformer-ec-charger.c new file +6
-0+power_supply_changed (priv->psy); +break ; + } + +return NOTIFY_DONE ; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7