mfd: Add support for Asus Transformer embedded controller
Subsystems (6)
v5 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
---
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 | 272 +++++++ drivers/input/serio/Kconfig | 15 + drivers/input/serio/Makefile | 1 + drivers/input/serio/asus-transformer-ec-kbc.c | 147 ++++ drivers/leds/Kconfig | 11 + drivers/leds/Makefile | 1 + drivers/leds/leds-asus-transformer-ec.c | 79 ++ drivers/mfd/Kconfig | 14 + drivers/mfd/Makefile | 1 + drivers/mfd/asus-transformer-ec.c | 762 ++++++++++++++++++ drivers/power/supply/Kconfig | 22 + drivers/power/supply/Makefile | 2 + .../supply/asus-transformer-ec-battery.c | 272 +++++++ .../supply/asus-transformer-ec-charger.c | 193 +++++ include/linux/mfd/asus-transformer-ec.h | 162 ++++ 18 files changed, 2084 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 v5 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
Re: [PATCH v5 1/7] dt-bindings: embedded-controller: document ASUS Transformer EC
Quoted 8 lines · Svyatoslav Ryhel
Document embedded controller used in ASUS Transformer device series.
Signed-off-by Svyatoslav Ryhel <[email protected]>--- .../asus,tf201-ec-pad.yaml | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 Documentation/devicetree/bindings/embedded-controller/asus,tf201-ec-pad.yaml
PATCH v5 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 | 14 + drivers/mfd/Makefile | 1 + drivers/mfd/asus-transformer-ec.c | 762 ++++++++++++++++++++++++ include/linux/mfd/asus-transformer-ec.h | 162 +++++ 4 files changed, 939 insertions(+) create mode 100644 drivers/mfd/asus-transformer-ec.c create mode 100644 include/linux/mfd/asus-transformer-ec.h
drivers/mfd/Kconfig +14 -0
@@ -137,6 +137,20 @@ 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" + depends on I2C && OF + help + Support ECs found in ASUS Transformer's Pad and Mobile Dock. + + This provides shared glue for functional part drivers: + asus-transformer-ec-kbc, asus-transformer-ec-keys, + leds-asus-transformer-ec, asus-transformer-ec-battery + and asus-transformer-ec-charger. + + 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 +762 -0
762 lines not on this page · raw message
include/linux/mfd/asus-transformer-ec.h new file +162 -0
162 lines not on this page · raw message
Signature · 1 line
2.51.0
kernel test robot
build botRe: [PATCH v5 2/7] mfd: Add driver for ASUS Transformer embedded controller
kernel test robot noticed the following build warnings:
Hi Svyatoslav,
kernel test robot noticed the following build warnings:
[auto build test WARNING on sre-power-supply/for-next]
[also build test WARNING on robh/for-next linus/master v7.0-rc2 next-20260305] [cannot apply to dtor-input/next dtor-input/for-linus]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Svyatoslav-Ryhel/dt-bindings-embedded-controller-document-ASUS-Transformer-EC/20260305-030907 base: https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git for-next patch link: https://lore.kernel.org/r/20260304185751.83494-3-clamor95%40gmail.com patch subject: [PATCH v5 2/7] mfd: Add driver for ASUS Transformer embedded controller config: powerpc64-randconfig-r133-20260305 (https://download.01.org/0day-ci/archive/20260307/[email protected]/config) compiler: clang version 23.0.0git (https://github.com/llvm/llvm-project 9a109fbb6e184ec9bcce10615949f598f4c974a9) sparse: v0.6.5-rc1 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260307/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
sparse warnings: (new ones prefixed by >>)
>> drivers/mfd/asus-transformer-ec.c:482:9: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected void const * @@ got char const [noderef] __user *buf @@ drivers/mfd/asus-transformer-ec.c:482:9: sparse: expected void const * drivers/mfd/asus-transformer-ec.c:482:9: sparse: got char const [noderef] __user *buf >> drivers/mfd/asus-transformer-ec.c:482:9: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected void const * @@ got char const [noderef] __user *buf @@
drivers/mfd/asus-transformer-ec.c:482:9: sparse: expected void const *
drivers/mfd/asus-transformer-ec.c:482:9: sparse: got char const [noderef] __user *buf
drivers/mfd/asus-transformer-ec.c:482:9: sparse: sparse: incorrect type in argument 2 (different address spaces) @@ expected void const * @@ got char const [noderef] __user *buf @@
drivers/mfd/asus-transformer-ec.c:482:9: sparse: expected void const *
drivers/mfd/asus-transformer-ec.c:482:9: sparse: got char const [noderef] __user *buf
drivers/mfd/asus-transformer-ec.c:476:16: sparse: sparse: dereference of noderef expression
vim +482 drivers/mfd/asus-transformer-ec.c
467
468 static int dockram_write_one(struct i2c_client *client, int reg,
469 const char __user *buf, size_t count)
470 {
471 struct dockram_ec_data *priv = i2c_get_clientdata(client);
472 int ret;
473
474 if (!count || count > DOCKRAM_ENTRY_SIZE)
475 return -EINVAL;
476 if (buf[0] != count - 1)
477 return -EINVAL;
478
479 guard(mutex)(&priv->ctl_lock);
480
481 priv->ctl_data[0] = (u8)count;
> 482 memcpy(priv->ctl_data + 1, buf, count);
483 ret = asus_dockram_write(client, reg, priv->ctl_data);
484
485 return ret;
486 }
487
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH v5 2/7] mfd: Add driver for ASUS Transformer embedded controller
In reply to Svyatoslav Ryhelkernel test robot noticed the following build warnings:
Hi Svyatoslav,
kernel test robot noticed the following build warnings:
[auto build test WARNING on sre-power-supply/for-next]
[also build test WARNING on robh/for-next linus/master v7.0-rc2 next-20260305] [cannot apply to dtor-input/next dtor-input/for-linus]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Svyatoslav-Ryhel/dt-bindings-embedded-controller-document-ASUS-Transformer-EC/20260305-030907 base: https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git for-next patch link: https://lore.kernel.org/r/20260304185751.83494-3-clamor95%40gmail.com patch subject: [PATCH v5 2/7] mfd: Add driver for ASUS Transformer embedded controller config: openrisc-randconfig-r134-20260305 (https://download.01.org/0day-ci/archive/20260307/[email protected]/config) compiler: or1k-linux-gcc (GCC) 12.5.0 sparse: v0.6.5-rc1 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260307/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
sparse warnings: (new ones prefixed by >>)
>> drivers/mfd/asus-transformer-ec.c:482:36: sparse: sparse: incorrect type in argument 2 (different address spaces) @@ expected void const *src @@ got char const [noderef] __user *buf @@ drivers/mfd/asus-transformer-ec.c:482:36: sparse: expected void const *src drivers/mfd/asus-transformer-ec.c:482:36: sparse: got char const [noderef] __user *buf >> drivers/mfd/asus-transformer-ec.c:476:16: sparse: sparse: dereference of noderef expression
vim +482 drivers/mfd/asus-transformer-ec.c
467
468 static int dockram_write_one(struct i2c_client *client, int reg,
469 const char __user *buf, size_t count)
470 {
471 struct dockram_ec_data *priv = i2c_get_clientdata(client);
472 int ret;
473
474 if (!count || count > DOCKRAM_ENTRY_SIZE)
475 return -EINVAL;
> 476 if (buf[0] != count - 1) 477 return -EINVAL; 478 479 guard(mutex)(&priv->ctl_lock); 480 481 priv->ctl_data[0] = (u8)count; > 482 memcpy(priv->ctl_data + 1, buf, count);
483 ret = asus_dockram_write(client, reg, priv->ctl_data);
484
485 return ret;
486 }
487
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH v5 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 | 147 ++++++++++++++++++ 3 files changed, 163 insertions(+) create mode 100644 drivers/input/serio/asus-transformer-ec-kbc.c
drivers/input/serio/Kconfig +15 -0
@@ -97,6 +97,21 @@ config SERIO_RPCKBD To compile this driver as a module, choose M here: the module will be called rpckbd. +config SERIO_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
@@ -13,6 +13,7 @@ obj-$(CONFIG_SERIO_CT82C710) += ct82c710.o obj-$(CONFIG_SERIO_RPCKBD) += rpckbd.o obj-$(CONFIG_SERIO_SA1111) += sa1111ps2.o obj-$(CONFIG_SERIO_AMBAKMI) += ambakmi.o +obj-$(CONFIG_SERIO_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 +147 -0
147 lines not on this page · raw message
Signature · 1 line
2.51.0
PATCH v5 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 | 272 ++++++++++++++++++ 3 files changed, 283 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 +272 -0
272 lines not on this page · raw message
Signature · 1 line
2.51.0
PATCH v5 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 | 79 +++++++++++++++++++++++++ 3 files changed, 91 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 +79 -0
79 lines not on this page · raw message
Signature · 1 line
2.51.0
PATCH v5 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 | 272 ++++++++++++++++++ 3 files changed, 284 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 here to enable support APM status emulation using + battery class devices. + + This sub-driver supports battery cells found in Asus Transformer + tablets and mobile docks and controlled by special embedded + controller. + config BATTERY_CPCAP tristate "Motorola CPCAP PMIC battery driver" depends on MFD_CPCAP && IIO
drivers/power/supply/Makefile +1 -0
@@ -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 +272 -0
272 lines not on this page · raw message
Signature · 1 line
2.51.0
Re: [PATCH v5 6/7] power: supply: Add driver for ASUS Transformer battery
Hi,
Quoted 20 lines · Svyatoslav Ryhel
From: Michał Mirosław <[email protected]>
Driver implements one battery cell per EC controller and supports reading of battery status for ASUS Transformer's pad and mobile dock.
Co-developed-by Svyatoslav Ryhel <[email protected]>Signed-off-by Svyatoslav Ryhel <[email protected]>Signed-off-by Michał Mirosław <[email protected]>--- drivers/power/supply/Kconfig | 11 + drivers/power/supply/Makefile | 1 + .../supply/asus-transformer-ec-battery.c | 272 ++++++++++++++++++ 3 files changed, 284 insertions(+) create mode 100644 drivers/power/supply/asus-transformer-ec-battery.cdrivers/power/supply/Kconfig +0
-0
drivers/power/supply/Kconfig config BATTERY_CHAGALL · line 130
Quoted 9 lines
drivers/power/supply/Kconfig +6
-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 here to enable support APM status emulation using + battery class devices.
^^^
You forgot to drop that when you used the APM_POWER config entry as template. Otherwise the driver LGTM:
Greetings,
-- Sebastian
Quoted 301 lines
drivers/power/supply/Kconfig +4
-0+ This sub-driver supports battery cells found in Asus Transformer + tablets and mobile docks and controlled by special embedded + controller. + config BATTERY_CPCAP tristate "Motorola CPCAP PMIC battery driver" depends on MFD_CPCAP && IIOdrivers/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.odrivers/power/supply/asus-transformer-ec-battery.c new file +272
-0@@ -0,0 +1,272 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <linux/array_size.h> +#include <linux/devm-helpers.h> +#include <linux/err.h> +#include <linux/mfd/asus-transformer-ec.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/platform_device.h> +#include <linux/power_supply.h> +#include <linux/property.h> +#include <linux/unaligned.h> + +#define ASUSEC_BATTERY_DATA_FRESH_MSEC 5000 + +#define ASUSEC_BATTERY_DISCHARGING 0x40 +#define ASUSEC_BATTERY_FULL_CHARGED 0x20 +#define ASUSEC_BATTERY_NOT_CHARGING 0x10 + +#define TEMP_CELSIUS_OFFSET 2731 + +struct asus_ec_battery_data { +const struct asusec_info *ec; +struct power_supply *battery; +struct power_supply_desc psy_desc; +struct delayed_work poll_work; +struct mutex battery_lock;/* for data refresh */ +unsigned long batt_data_ts; +int last_state; +u8 batt_data[DOCKRAM_ENTRY_BUFSIZE ]; +}; + +static int asus_ec_battery_refresh (struct asus_ec_battery_data *priv) +{ +int ret =0 ; + +guard (mutex)(&priv->battery_lock); + +if (time_before (jiffies, priv->batt_data_ts)) +return ret; + + ret =asus_dockram_read (priv->ec->dockram,ASUSEC_DOCKRAM_BATT_CTL , + priv->batt_data); +if (ret <0 ) +return ret; + + priv->batt_data_ts = jiffies + +msecs_to_jiffies (ASUSEC_BATTERY_DATA_FRESH_MSEC ); + +return ret; +} + +static enum power_supply_property asus_ec_battery_properties[] = { +POWER_SUPPLY_PROP_STATUS , +POWER_SUPPLY_PROP_VOLTAGE_MAX , +POWER_SUPPLY_PROP_CURRENT_MAX , +POWER_SUPPLY_PROP_TEMP , +POWER_SUPPLY_PROP_VOLTAGE_NOW , +POWER_SUPPLY_PROP_CURRENT_NOW , +POWER_SUPPLY_PROP_CAPACITY , +POWER_SUPPLY_PROP_CHARGE_NOW , +POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW , +POWER_SUPPLY_PROP_TIME_TO_FULL_NOW , +POWER_SUPPLY_PROP_PRESENT , +}; + +static const unsigned int asus_ec_battery_prop_offs[] = { + [POWER_SUPPLY_PROP_STATUS ] =1 , + [POWER_SUPPLY_PROP_VOLTAGE_MAX ] =3 , + [POWER_SUPPLY_PROP_CURRENT_MAX ] =5 , + [POWER_SUPPLY_PROP_TEMP ] =7 , + [POWER_SUPPLY_PROP_VOLTAGE_NOW ] =9 , + [POWER_SUPPLY_PROP_CURRENT_NOW ] =11 , + [POWER_SUPPLY_PROP_CAPACITY ] =13 , + [POWER_SUPPLY_PROP_CHARGE_NOW ] =15 , + [POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW ] =17 , + [POWER_SUPPLY_PROP_TIME_TO_FULL_NOW ] =19 , +}; + +static int asus_ec_battery_get_value (struct asus_ec_battery_data *priv, +enum power_supply_property psp) +{ +int ret, offs; + +if (psp >=ARRAY_SIZE (asus_ec_battery_prop_offs)) +return -EINVAL ; + + offs = asus_ec_battery_prop_offs[psp]; +if (!offs) +return -EINVAL ; + + 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); +} + +static int asus_ec_battery_get_property (struct power_supply *psy, +enum power_supply_property psp, +union power_supply_propval *val) +{ +struct asus_ec_battery_data *priv =power_supply_get_drvdata (psy); +int ret; + +switch (psp) { +case POWER_SUPPLY_PROP_PRESENT : + val->intval =1 ; +break ; + +default : + ret =asus_ec_battery_get_value (priv, psp); +if (ret <0 ) +return ret; + + val->intval = (s16 )ret; + +switch (psp) { +case POWER_SUPPLY_PROP_STATUS : +if (ret &ASUSEC_BATTERY_FULL_CHARGED ) + val->intval =POWER_SUPPLY_STATUS_FULL ; +else if (ret &ASUSEC_BATTERY_NOT_CHARGING ) + val->intval =POWER_SUPPLY_STATUS_NOT_CHARGING ; +else if (ret &ASUSEC_BATTERY_DISCHARGING ) + val->intval =POWER_SUPPLY_STATUS_DISCHARGING ; +else + val->intval =POWER_SUPPLY_STATUS_CHARGING ; +break ; + +case POWER_SUPPLY_PROP_TEMP : + val->intval -=TEMP_CELSIUS_OFFSET ; +break ; + +case POWER_SUPPLY_PROP_CHARGE_NOW : +case POWER_SUPPLY_PROP_CURRENT_NOW : +case POWER_SUPPLY_PROP_CURRENT_MAX : +case POWER_SUPPLY_PROP_VOLTAGE_NOW : +case POWER_SUPPLY_PROP_VOLTAGE_MAX : + val->intval *=1000 ; +break ; + +case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW : +case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW : + val->intval *=60 ; +break ; + +default : +break ; + } + +break ; + } + +return 0 ; +} + +static void asus_ec_battery_poll_work (struct work_struct *work) +{ +struct asus_ec_battery_data *priv = + container_of(work, struct asus_ec_battery_data, poll_work.work); +int state; + + state =asus_ec_battery_get_value (priv,POWER_SUPPLY_PROP_STATUS ); +if (state <0 ) +return ; + +if (state &ASUSEC_BATTERY_FULL_CHARGED ) + state =POWER_SUPPLY_STATUS_FULL ; +else if (state &ASUSEC_BATTERY_DISCHARGING ) + state =POWER_SUPPLY_STATUS_DISCHARGING ; +else + state =POWER_SUPPLY_STATUS_CHARGING ; + +if (priv->last_state != state) { + priv->last_state = state; +power_supply_changed (priv->battery); + } + +/* continuously send uevent notification */ +schedule_delayed_work (&priv->poll_work, +msecs_to_jiffies (ASUSEC_BATTERY_DATA_FRESH_MSEC )); +} + +static const struct power_supply_desc asus_ec_battery_desc = { + .name ="asus-ec-battery" , + .type =POWER_SUPPLY_TYPE_BATTERY , + .properties = asus_ec_battery_properties, + .num_properties =ARRAY_SIZE (asus_ec_battery_properties), + .get_property = asus_ec_battery_get_property, + .external_power_changed = power_supply_changed, +}; + +static int asus_ec_battery_probe (struct platform_device *pdev) +{ +struct asus_ec_battery_data *priv; +struct device *dev = &pdev->dev; +struct power_supply_config cfg = { }; +int ret; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + +platform_set_drvdata (pdev, priv); + +mutex_init (&priv->battery_lock); + + priv->ec =cell_to_ec (pdev); + priv->batt_data_ts = jiffies -1 ; + priv->last_state =POWER_SUPPLY_STATUS_UNKNOWN ; + + cfg.fwnode =dev_fwnode (dev->parent); + cfg.drv_data = priv; + +memcpy (&priv->psy_desc, &asus_ec_battery_desc,sizeof (priv->psy_desc)); + priv->psy_desc.name =devm_kasprintf (dev,GFP_KERNEL ,"%s-battery" , + priv->ec->name); + + priv->battery =devm_power_supply_register (dev, &priv->psy_desc, &cfg); +if (IS_ERR (priv->battery)) +return dev_err_probe (dev,PTR_ERR (priv->battery), +"Failed to register power supply\n" ); + + ret =devm_delayed_work_autocancel (dev, &priv->poll_work, + asus_ec_battery_poll_work); +if (ret) +return ret; + +schedule_delayed_work (&priv->poll_work, +msecs_to_jiffies (ASUSEC_BATTERY_DATA_FRESH_MSEC )); + +return 0 ; +} + +static int __maybe_unused asus_ec_battery_suspend (struct device *dev) +{ +struct asus_ec_battery_data *priv =dev_get_drvdata (dev); + +cancel_delayed_work_sync (&priv->poll_work); + +return 0 ; +} + +static int __maybe_unused asus_ec_battery_resume (struct device *dev) +{ +struct asus_ec_battery_data *priv =dev_get_drvdata (dev); + +schedule_delayed_work (&priv->poll_work, +msecs_to_jiffies (ASUSEC_BATTERY_DATA_FRESH_MSEC )); + +return 0 ; +} + +static SIMPLE_DEV_PM_OPS(asus_ec_battery_pm_ops, + asus_ec_battery_suspend, asus_ec_battery_resume); + +static struct platform_driver asus_ec_battery_driver = { + .driver = { + .name ="asus-transformer-ec-battery" , + .pm = &asus_ec_battery_pm_ops, + }, + .probe = asus_ec_battery_probe, +}; +module_platform_driver (asus_ec_battery_driver); + +MODULE_AUTHOR ("Michał Mirosław <[email protected]>" ); +MODULE_AUTHOR ("Svyatoslav Ryhel <[email protected]>" ); +MODULE_DESCRIPTION ("ASUS Transformer's battery driver" ); +MODULE_LICENSE ("GPL" );Signature · 1 line
2.51.0
Re: [PATCH v5 6/7] power: supply: Add driver for ASUS Transformer battery
ср, 11 бер. 2026 р. о 08:31 Sebastian Reichel
<[email protected]> пише:
Quoted 36 lines
Hi,
Quoted 20 lines · Svyatoslav Ryhel
From: Michał Mirosław <[email protected]>
Driver implements one battery cell per EC controller and supports reading of battery status for ASUS Transformer's pad and mobile dock.
Co-developed-by Svyatoslav Ryhel <[email protected]>Signed-off-by Svyatoslav Ryhel <[email protected]>Signed-off-by Michał Mirosław <[email protected]>--- drivers/power/supply/Kconfig | 11 + drivers/power/supply/Makefile | 1 + .../supply/asus-transformer-ec-battery.c | 272 ++++++++++++++++++ 3 files changed, 284 insertions(+) create mode 100644 drivers/power/supply/asus-transformer-ec-battery.cdrivers/power/supply/Kconfig +0
-0drivers/power/supply/Kconfig config BATTERY_CHAGALL · line 130
Quoted 9 lines
drivers/power/supply/Kconfig +6
-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 here to enable support APM status emulation using + battery class devices.^^^
Quoted 3 lines
You forgot to drop that when you used the
APM_POWERconfig entry as template. Otherwise the driver LGTM:
Oh, my bad. I will adjust in the next iteration. Thank you catching this.
Quoted 307 lines
Reviewed-by Sebastian Reichel <[email protected]>Greetings,
-- Sebastian
Quoted 301 lines
drivers/power/supply/Kconfig +4
-0+ This sub-driver supports battery cells found in Asus Transformer + tablets and mobile docks and controlled by special embedded + controller. + config BATTERY_CPCAP tristate "Motorola CPCAP PMIC battery driver" depends on MFD_CPCAP && IIOdrivers/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.odrivers/power/supply/asus-transformer-ec-battery.c new file +272
-1@@ -0,0 +1,272 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <linux/array_size.h> +#include <linux/devm-helpers.h> +#include <linux/err.h> +#include <linux/mfd/asus-transformer-ec.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/platform_device.h> +#include <linux/power_supply.h> +#include <linux/property.h> +#include <linux/unaligned.h> + +#define ASUSEC_BATTERY_DATA_FRESH_MSEC 5000 + +#define ASUSEC_BATTERY_DISCHARGING 0x40 +#define ASUSEC_BATTERY_FULL_CHARGED 0x20 +#define ASUSEC_BATTERY_NOT_CHARGING 0x10 + +#define TEMP_CELSIUS_OFFSET 2731 + +struct asus_ec_battery_data { +const struct asusec_info *ec; +struct power_supply *battery; +struct power_supply_desc psy_desc; +struct delayed_work poll_work; +struct mutex battery_lock;/* for data refresh */ +unsigned long batt_data_ts; +int last_state; +u8 batt_data[DOCKRAM_ENTRY_BUFSIZE ]; +}; + +static int asus_ec_battery_refresh (struct asus_ec_battery_data *priv) +{ +int ret =0 ; + +guard (mutex)(&priv->battery_lock); + +if (time_before (jiffies, priv->batt_data_ts)) +return ret; + + ret =asus_dockram_read (priv->ec->dockram,ASUSEC_DOCKRAM_BATT_CTL , + priv->batt_data); +if (ret <0 ) +return ret; + + priv->batt_data_ts = jiffies + +msecs_to_jiffies (ASUSEC_BATTERY_DATA_FRESH_MSEC ); + +return ret; +} + +static enum power_supply_property asus_ec_battery_properties[] = { +POWER_SUPPLY_PROP_STATUS , +POWER_SUPPLY_PROP_VOLTAGE_MAX , +POWER_SUPPLY_PROP_CURRENT_MAX , +POWER_SUPPLY_PROP_TEMP , +POWER_SUPPLY_PROP_VOLTAGE_NOW , +POWER_SUPPLY_PROP_CURRENT_NOW , +POWER_SUPPLY_PROP_CAPACITY , +POWER_SUPPLY_PROP_CHARGE_NOW , +POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW , +POWER_SUPPLY_PROP_TIME_TO_FULL_NOW , +POWER_SUPPLY_PROP_PRESENT , +}; + +static const unsigned int asus_ec_battery_prop_offs[] = { + [POWER_SUPPLY_PROP_STATUS ] =1 , + [POWER_SUPPLY_PROP_VOLTAGE_MAX ] =3 , + [POWER_SUPPLY_PROP_CURRENT_MAX ] =5 , + [POWER_SUPPLY_PROP_TEMP ] =7 , + [POWER_SUPPLY_PROP_VOLTAGE_NOW ] =9 , + [POWER_SUPPLY_PROP_CURRENT_NOW ] =11 , + [POWER_SUPPLY_PROP_CAPACITY ] =13 , + [POWER_SUPPLY_PROP_CHARGE_NOW ] =15 , + [POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW ] =17 , + [POWER_SUPPLY_PROP_TIME_TO_FULL_NOW ] =19 , +}; + +static int asus_ec_battery_get_value (struct asus_ec_battery_data *priv, +enum power_supply_property psp) +{ +int ret, offs; + +if (psp >=ARRAY_SIZE (asus_ec_battery_prop_offs)) +return -EINVAL ; + + offs = asus_ec_battery_prop_offs[psp]; +if (!offs) +return -EINVAL ; + + 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); +} + +static int asus_ec_battery_get_property (struct power_supply *psy, +enum power_supply_property psp, +union power_supply_propval *val) +{ +struct asus_ec_battery_data *priv =power_supply_get_drvdata (psy); +int ret; + +switch (psp) { +case POWER_SUPPLY_PROP_PRESENT : + val->intval =1 ; +break ; + +default : + ret =asus_ec_battery_get_value (priv, psp); +if (ret <0 ) +return ret; + + val->intval = (s16 )ret; + +switch (psp) { +case POWER_SUPPLY_PROP_STATUS : +if (ret &ASUSEC_BATTERY_FULL_CHARGED ) + val->intval =POWER_SUPPLY_STATUS_FULL ; +else if (ret &ASUSEC_BATTERY_NOT_CHARGING ) + val->intval =POWER_SUPPLY_STATUS_NOT_CHARGING ; +else if (ret &ASUSEC_BATTERY_DISCHARGING ) + val->intval =POWER_SUPPLY_STATUS_DISCHARGING ; +else + val->intval =POWER_SUPPLY_STATUS_CHARGING ; +break ; + +case POWER_SUPPLY_PROP_TEMP : + val->intval -=TEMP_CELSIUS_OFFSET ; +break ; + +case POWER_SUPPLY_PROP_CHARGE_NOW : +case POWER_SUPPLY_PROP_CURRENT_NOW : +case POWER_SUPPLY_PROP_CURRENT_MAX : +case POWER_SUPPLY_PROP_VOLTAGE_NOW : +case POWER_SUPPLY_PROP_VOLTAGE_MAX : + val->intval *=1000 ; +break ; + +case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW : +case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW : + val->intval *=60 ; +break ; + +default : +break ; + } + +break ; + } + +return 0 ; +} + +static void asus_ec_battery_poll_work (struct work_struct *work) +{ +struct asus_ec_battery_data *priv = + container_of(work, struct asus_ec_battery_data, poll_work.work); +int state; + + state =asus_ec_battery_get_value (priv,POWER_SUPPLY_PROP_STATUS ); +if (state <0 ) +return ; + +if (state &ASUSEC_BATTERY_FULL_CHARGED ) + state =POWER_SUPPLY_STATUS_FULL ; +else if (state &ASUSEC_BATTERY_DISCHARGING ) + state =POWER_SUPPLY_STATUS_DISCHARGING ; +else + state =POWER_SUPPLY_STATUS_CHARGING ; + +if (priv->last_state != state) { + priv->last_state = state; +power_supply_changed (priv->battery); + } + +/* continuously send uevent notification */ +schedule_delayed_work (&priv->poll_work, +msecs_to_jiffies (ASUSEC_BATTERY_DATA_FRESH_MSEC )); +} + +static const struct power_supply_desc asus_ec_battery_desc = { + .name ="asus-ec-battery" , + .type =POWER_SUPPLY_TYPE_BATTERY , + .properties = asus_ec_battery_properties, + .num_properties =ARRAY_SIZE (asus_ec_battery_properties), + .get_property = asus_ec_battery_get_property, + .external_power_changed = power_supply_changed, +}; + +static int asus_ec_battery_probe (struct platform_device *pdev) +{ +struct asus_ec_battery_data *priv; +struct device *dev = &pdev->dev; +struct power_supply_config cfg = { }; +int ret; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + +platform_set_drvdata (pdev, priv); + +mutex_init (&priv->battery_lock); + + priv->ec =cell_to_ec (pdev); + priv->batt_data_ts = jiffies -1 ; + priv->last_state =POWER_SUPPLY_STATUS_UNKNOWN ; + + cfg.fwnode =dev_fwnode (dev->parent); + cfg.drv_data = priv; + +memcpy (&priv->psy_desc, &asus_ec_battery_desc,sizeof (priv->psy_desc)); + priv->psy_desc.name =devm_kasprintf (dev,GFP_KERNEL ,"%s-battery" , + priv->ec->name); + + priv->battery =devm_power_supply_register (dev, &priv->psy_desc, &cfg); +if (IS_ERR (priv->battery)) +return dev_err_probe (dev,PTR_ERR (priv->battery), +"Failed to register power supply\n" ); + + ret =devm_delayed_work_autocancel (dev, &priv->poll_work, + asus_ec_battery_poll_work); +if (ret) +return ret; + +schedule_delayed_work (&priv->poll_work, +msecs_to_jiffies (ASUSEC_BATTERY_DATA_FRESH_MSEC )); + +return 0 ; +} + +static int __maybe_unused asus_ec_battery_suspend (struct device *dev) +{ +struct asus_ec_battery_data *priv =dev_get_drvdata (dev); + +cancel_delayed_work_sync (&priv->poll_work); + +return 0 ; +} + +static int __maybe_unused asus_ec_battery_resume (struct device *dev) +{ +struct asus_ec_battery_data *priv =dev_get_drvdata (dev); + +schedule_delayed_work (&priv->poll_work, +msecs_to_jiffies (ASUSEC_BATTERY_DATA_FRESH_MSEC )); + +return 0 ; +} + +static SIMPLE_DEV_PM_OPS(asus_ec_battery_pm_ops, + asus_ec_battery_suspend, asus_ec_battery_resume); + +static struct platform_driver asus_ec_battery_driver = { + .driver = { + .name ="asus-transformer-ec-battery" , + .pm = &asus_ec_battery_pm_ops, + }, + .probe = asus_ec_battery_probe, +}; +module_platform_driver (asus_ec_battery_driver); + +MODULE_AUTHOR ("Michał Mirosław <[email protected]>" ); +MODULE_AUTHOR ("Svyatoslav Ryhel <[email protected]>" ); +MODULE_DESCRIPTION ("ASUS Transformer's battery driver" ); +MODULE_LICENSE ("GPL" ); --2.51.0
PATCH v5 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 | 193 ++++++++++++++++++ 3 files changed, 205 insertions(+) create mode 100644 drivers/power/supply/asus-transformer-ec-charger.c
drivers/power/supply/Kconfig +11 -0
@@ -497,6 +497,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
@@ -68,6 +68,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 +193 -0
193 lines not on this page · raw message
Signature · 1 line
2.51.0
Re: [PATCH v5 7/7] power: supply: Add charger driver for Asus Transformers
Hi,
Quoted 10 lines · Svyatoslav Ryhel
From: Michał Mirosław <[email protected]>
Add support for charger detection capabilities found in the embedded controller of ASUS Transformer devices.
Suggested-by Maxim Schwalm <[email protected]>Suggested-by Svyatoslav Ryhel <[email protected]>Signed-off-by Michał Mirosław <[email protected]>Signed-off-by Svyatoslav Ryhel <[email protected]>---
-- Sebastian
Quoted 243 lines
drivers/power/supply/Kconfig | 11 + drivers/power/supply/Makefile | 1 + .../supply/asus-transformer-ec-charger.c | 193 ++++++++++++++++++ 3 files changed, 205 insertions(+) create mode 100644 drivers/power/supply/asus-transformer-ec-charger.cdrivers/power/supply/Kconfig +11
-0@@ -497,6 +497,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_PF1550drivers/power/supply/Makefile +1
-0@@ -68,6 +68,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.odrivers/power/supply/asus-transformer-ec-charger.c new file +193
-0@@ -0,0 +1,193 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <linux/err.h> +#include <linux/mfd/asus-transformer-ec.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/power_supply.h> +#include <linux/property.h> + +struct asus_ec_charger_data { +struct notifier_block nb; +const struct asusec_info *ec; +struct power_supply *psy; +struct power_supply_desc psy_desc; +}; + +static enum power_supply_property asus_ec_charger_properties[] = { +POWER_SUPPLY_PROP_USB_TYPE , +POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR , +POWER_SUPPLY_PROP_ONLINE , +POWER_SUPPLY_PROP_MODEL_NAME , +}; + +static int asus_ec_charger_get_property (struct power_supply *psy, +enum power_supply_property psp, +union power_supply_propval *val) +{ +struct asus_ec_charger_data *priv =power_supply_get_drvdata (psy); +enum power_supply_usb_type psu; +int ret; +u64 ctl; + + ret =asus_ec_get_ctl (priv->ec, &ctl); +if (ret) +return ret; + +switch (ctl & (ASUSEC_CTL_FULL_POWER_SOURCE |ASUSEC_CTL_DIRECT_POWER_SOURCE )) { +case ASUSEC_CTL_FULL_POWER_SOURCE : + psu =POWER_SUPPLY_USB_TYPE_CDP ;/* DOCK */ +break ; +case ASUSEC_CTL_DIRECT_POWER_SOURCE : + psu =POWER_SUPPLY_USB_TYPE_SDP ;/* USB */ +break ; +case 0 : + psu =POWER_SUPPLY_USB_TYPE_UNKNOWN ;/* no power source connected */ +break ; +default : + psu =POWER_SUPPLY_USB_TYPE_ACA ;/* power adapter */ +break ; + } + +switch (psp) { +case POWER_SUPPLY_PROP_ONLINE : + val->intval = psu !=POWER_SUPPLY_USB_TYPE_UNKNOWN ; +return 0 ; + +case POWER_SUPPLY_PROP_USB_TYPE : + val->intval = psu; +return 0 ; + +case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR : +if (ctl &ASUSEC_CTL_TEST_DISCHARGE ) + val->intval =POWER_SUPPLY_CHARGE_BEHAVIOUR_FORCE_DISCHARGE ; +else if (ctl &ASUSEC_CTL_USB_CHARGE ) + val->intval =POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO ; +else + val->intval =POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE ; +return 0 ; + +case POWER_SUPPLY_PROP_MODEL_NAME : + val->strval = priv->ec->model; +return 0 ; + +default : +return -EINVAL ; + } +} + +static int asus_ec_charger_set_property (struct power_supply *psy, +enum power_supply_property psp, +const union power_supply_propval *val) +{ +struct asus_ec_charger_data *priv =power_supply_get_drvdata (psy); + +switch (psp) { +case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR : +switch ((enum power_supply_charge_behaviour )val->intval) { +case POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO : +return asus_ec_update_ctl (priv->ec, +ASUSEC_CTL_TEST_DISCHARGE |ASUSEC_CTL_USB_CHARGE , +ASUSEC_CTL_USB_CHARGE ); + +case POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE : +return asus_ec_clear_ctl_bits (priv->ec, +ASUSEC_CTL_TEST_DISCHARGE |ASUSEC_CTL_USB_CHARGE ); + +case POWER_SUPPLY_CHARGE_BEHAVIOUR_FORCE_DISCHARGE : +return asus_ec_update_ctl (priv->ec, +ASUSEC_CTL_TEST_DISCHARGE |ASUSEC_CTL_USB_CHARGE , +ASUSEC_CTL_TEST_DISCHARGE ); +default : +return -EINVAL ; + } + +default : +return -EINVAL ; + } +} + +static int asus_ec_charger_property_is_writeable (struct power_supply *psy, +enum power_supply_property psp) +{ +switch (psp) { +case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR : +return true; +default : +return false; + } +} + +static const struct power_supply_desc asus_ec_charger_desc = { + .name ="asus-ec-charger" , + .type =POWER_SUPPLY_TYPE_USB , + .charge_behaviours =BIT (POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO ) | +BIT (POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE ) | +BIT (POWER_SUPPLY_CHARGE_BEHAVIOUR_FORCE_DISCHARGE ), + .usb_types =BIT (POWER_SUPPLY_USB_TYPE_UNKNOWN ) | +BIT (POWER_SUPPLY_USB_TYPE_SDP ) | +BIT (POWER_SUPPLY_USB_TYPE_CDP ) | +BIT (POWER_SUPPLY_USB_TYPE_ACA ), + .properties = asus_ec_charger_properties, + .num_properties =ARRAY_SIZE (asus_ec_charger_properties), + .get_property = asus_ec_charger_get_property, + .set_property = asus_ec_charger_set_property, + .property_is_writeable = asus_ec_charger_property_is_writeable, + .no_thermal = true, +}; + +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 ): +power_supply_changed (priv->psy); +break ; + } + +return NOTIFY_DONE ; +} + +static int asus_ec_charger_probe (struct platform_device *pdev) +{ +struct asus_ec_charger_data *priv; +struct device *dev = &pdev->dev; +struct power_supply_config cfg = { }; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + +platform_set_drvdata (pdev, priv); + priv->ec =cell_to_ec (pdev); + + cfg.fwnode =dev_fwnode (dev->parent); + cfg.drv_data = priv; + +memcpy (&priv->psy_desc, &asus_ec_charger_desc,sizeof (priv->psy_desc)); + priv->psy_desc.name =devm_kasprintf (dev,GFP_KERNEL ,"%s-charger" , + priv->ec->name); + + priv->psy =devm_power_supply_register (dev, &priv->psy_desc, &cfg); +if (IS_ERR (priv->psy)) +return dev_err_probe (dev,PTR_ERR (priv->psy), +"Failed to register power supply\n" ); + + priv->nb.notifier_call = asus_ec_charger_notify; + +return devm_asus_ec_register_notifier (pdev, &priv->nb); +} + +static struct platform_driver asus_ec_charger_driver = { + .driver.name ="asus-transformer-ec-charger" , + .probe = asus_ec_charger_probe, +}; +module_platform_driver (asus_ec_charger_driver); + +MODULE_AUTHOR ("Michał Mirosław <[email protected]>" ); +MODULE_DESCRIPTION ("ASUS Transformer Pad battery charger driver" ); +MODULE_LICENSE ("GPL" );Signature · 1 line
2.51.0