From patchwork Sun Aug 30 18:53:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 255439 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7ABC7C433E2 for ; Sun, 30 Aug 2020 18:55:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4D8AC206CD for ; Sun, 30 Aug 2020 18:55:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PPJEEYyR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726515AbgH3SzO (ORCPT ); Sun, 30 Aug 2020 14:55:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726485AbgH3SzI (ORCPT ); Sun, 30 Aug 2020 14:55:08 -0400 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33601C061575; Sun, 30 Aug 2020 11:55:07 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id c2so156291ljj.12; Sun, 30 Aug 2020 11:55:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=L7rw93hhaf9uOHs3cGyY1kzgSun5Ciow1DW5ZdMuif0=; b=PPJEEYyRhUNt3ZqTR4234D0FB37mqxaZbKxnwDv4ZQAZfC6uwZpU22Mbtk0fau9JVt CSI5Uv97tE0MsP9TgcQH01ojbgIx7TmgEX0UohbxT/4BQ0Njl+eDaD537qSY7n03V+kU TYEKBPp83EJt/bhyrWT/HnoUGnz00WkXw4lTOxZw7tojF4w4qAwMWiG0TZ/GGAZZHfe9 QJCbGppfYS+VB47FMBcqYvd7CD+KGj05Inc7wpTUUDcXdqVlFUyyzT98bVP2TTNneIlc aXglX60rk3JRB5ZyrTBSavHfrMfvJXo5XIXnjAZXMMN/VBRR7wq2qjvPCLp6ytOF/brN MqSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=L7rw93hhaf9uOHs3cGyY1kzgSun5Ciow1DW5ZdMuif0=; b=syCiVDFAm1l1tEQhLCovuHn8AbX9ocedjZhf1VFwqeMEUFkiHbXxuZWRbFvCIFBrko mCUS26LtUQYca0UU2DRz5jslUt2pIPTi64thzntsiZrn8RF6y5CxxIzm+Y5+JFOAsQic GgPJOdFGZXkMOF859ZYB8cgxhNctYmjapGJtSfXmIY71R7sbBeSMRcfEKhu6W1DCCaH/ L2RsB23S7B2vF3bsQUEP+JrBHPbsV0D942OTPI2w2I63KBCOzvbK4SqvwRdLzL8lfmvB aAmiaewGYLZMfjF3Aj3pUhrVsJ+XkgFwGoknUohcrrr60Qp1jNU5A5gq+4pj/NnTIqa/ v1FA== X-Gm-Message-State: AOAM533SFelBrIyEFpqNBd3ZIV+8y0gmybZNlpc3W/Ds/X/+ZT+6X+1B SicQ9CtHujaGn/TwNIJ18kY= X-Google-Smtp-Source: ABdhPJyKSJlL7/Ku2+I/3RK7/bmANJhmytCHcV2rJbOAlR7UcMUA7bJJCI4q+f5qkbVJgTG6Kg/SoA== X-Received: by 2002:a2e:985a:: with SMTP id e26mr2431462ljj.320.1598813705546; Sun, 30 Aug 2020 11:55:05 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id n21sm21630ljc.89.2020.08.30.11.55.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Aug 2020 11:55:05 -0700 (PDT) From: Dmitry Osipenko To: Lee Jones , Rob Herring , Thierry Reding , Jonathan Hunter , Pavel Machek , Dan Murphy , Sebastian Reichel , Lubomir Rintel , Mark Brown Cc: devicetree@vger.kernel.org, linux-tegra@vger.kernel.org, linux-leds@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/6] mfd: Add driver for Embedded Controller found on Acer Iconia Tab A500 Date: Sun, 30 Aug 2020 21:53:53 +0300 Message-Id: <20200830185356.5365-4-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200830185356.5365-1-digetx@gmail.com> References: <20200830185356.5365-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-leds-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Acer Iconia Tab A500 is an Android tablet device, it has ENE KB930 Embedded Controller which provides battery-gauge, LED, GPIO and some other functions. The EC uses firmware that is specifically customized for Acer A500. This patch adds MFD driver for the Embedded Controller which allows to power-off / reboot the A500 device, it also provides a common register read/write API that will be used by the sub-devices. Signed-off-by: Dmitry Osipenko --- drivers/mfd/Kconfig | 12 +++ drivers/mfd/Makefile | 1 + drivers/mfd/acer-ec-a500.c | 203 +++++++++++++++++++++++++++++++++++++ 3 files changed, 216 insertions(+) create mode 100644 drivers/mfd/acer-ec-a500.c diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index ecd791ad5e8f..7a0f4952c76e 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -2062,6 +2062,18 @@ config MFD_KHADAS_MCU additional drivers must be enabled in order to use the functionality of the device. +config MFD_ACER_A500_EC + tristate "Embedded Controller driver for Acer Iconia Tab A500" + depends on I2C + depends on ARCH_TEGRA_2x_SOC || COMPILE_TEST + select MFD_CORE + select REGMAP + help + Support for Acer Iconia Tab A500 Embedded Controller. + + The controller itself is ENE KB930, it is running firmware + customized for the specific needs of the Acer A500 hardware. + menu "Multimedia Capabilities Port drivers" depends on ARCH_SA1100 diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index dd2cc7be7eaa..f6652fb33b7a 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -262,6 +262,7 @@ obj-$(CONFIG_MFD_ROHM_BD71828) += rohm-bd71828.o obj-$(CONFIG_MFD_ROHM_BD718XX) += rohm-bd718x7.o obj-$(CONFIG_MFD_STMFX) += stmfx.o obj-$(CONFIG_MFD_KHADAS_MCU) += khadas-mcu.o +obj-$(CONFIG_MFD_ACER_A500_EC) += acer-ec-a500.o obj-$(CONFIG_SGI_MFD_IOC3) += ioc3.o diff --git a/drivers/mfd/acer-ec-a500.c b/drivers/mfd/acer-ec-a500.c new file mode 100644 index 000000000000..2785a6d9bcc4 --- /dev/null +++ b/drivers/mfd/acer-ec-a500.c @@ -0,0 +1,203 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * MFD driver for Acer Iconia Tab A500 Embedded Controller. + * + * Copyright 2020 GRATE-driver project. + * + * Based on downstream driver from Acer Inc. + */ + +#include +#include +#include +#include +#include +#include +#include + +#define A500_EC_I2C_ERR_TIMEOUT 500 +#define A500_EC_POWER_CMD_TIMEOUT 1000 + +enum { + REG_CURRENT_NOW = 0x03, + REG_SHUTDOWN = 0x52, + REG_WARM_REBOOT = 0x54, + REG_COLD_REBOOT = 0x55, +}; + +static struct i2c_client *a500_ec_client_pm_off; + +static int a500_ec_read(void *context, const void *reg_buf, size_t reg_size, + void *val_buf, size_t val_sizel) +{ + struct i2c_client *client = context; + unsigned int reg, retries = 5; + u16 *ret_val = val_buf; + s32 ret = 0; + + if (reg_size != 1 || val_sizel != 2) + return -EOPNOTSUPP; + + reg = *(u8 *)reg_buf; + + while (retries-- > 0) { + ret = i2c_smbus_read_word_data(client, reg); + if (ret >= 0) + break; + + msleep(A500_EC_I2C_ERR_TIMEOUT); + } + + if (ret < 0) { + dev_err(&client->dev, "read 0x%x failed: %d\n", reg, ret); + return ret; + } + + *ret_val = ret; + + if (reg == REG_CURRENT_NOW) + fsleep(10000); + + return 0; +} + +static int a500_ec_write(void *context, const void *data, size_t count) +{ + struct i2c_client *client = context; + unsigned int reg, val, retries = 5; + s32 ret = 0; + + if (count != 3) + return -EOPNOTSUPP; + + reg = *(u8 *)(data + 0); + val = *(u16 *)(data + 1); + + while (retries-- > 0) { + ret = i2c_smbus_write_word_data(client, reg, val); + if (ret >= 0) + break; + + msleep(A500_EC_I2C_ERR_TIMEOUT); + } + + if (ret < 0) { + dev_err(&client->dev, "write 0x%x failed: %d\n", reg, ret); + return ret; + } + + return 0; +} + +static const struct regmap_config a500_ec_regmap_config = { + .name = "KB930", + .reg_bits = 8, + .val_bits = 16, + .max_register = 0xff, +}; + +static const struct regmap_bus a500_ec_regmap_bus = { + .reg_format_endian_default = REGMAP_ENDIAN_NATIVE, + .val_format_endian_default = REGMAP_ENDIAN_LITTLE, + .write = a500_ec_write, + .read = a500_ec_read, + .max_raw_read = 2, +}; + +static void a500_ec_poweroff(void) +{ + i2c_smbus_write_word_data(a500_ec_client_pm_off, REG_SHUTDOWN, 0); + + mdelay(A500_EC_POWER_CMD_TIMEOUT); +} + +static int a500_ec_restart_notify(struct notifier_block *this, + unsigned long reboot_mode, void *data) +{ + if (reboot_mode == REBOOT_WARM) + i2c_smbus_write_word_data(a500_ec_client_pm_off, + REG_WARM_REBOOT, 0); + else + i2c_smbus_write_word_data(a500_ec_client_pm_off, + REG_COLD_REBOOT, 1); + + mdelay(A500_EC_POWER_CMD_TIMEOUT); + + return NOTIFY_DONE; +} + +static struct notifier_block a500_ec_restart_handler = { + .notifier_call = a500_ec_restart_notify, + .priority = 200, +}; + +static const struct mfd_cell a500_ec_cells[] = { + { .name = "acer-a500-iconia-battery", }, + { .name = "acer-a500-iconia-leds", }, +}; + +static int a500_ec_probe(struct i2c_client *client) +{ + struct regmap *rmap; + int err; + + rmap = devm_regmap_init(&client->dev, &a500_ec_regmap_bus, + client, &a500_ec_regmap_config); + if (IS_ERR(rmap)) + return PTR_ERR(rmap); + + /* register battery and LED sub-devices */ + err = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_AUTO, + a500_ec_cells, ARRAY_SIZE(a500_ec_cells), + NULL, 0, NULL); + if (err) { + dev_err(&client->dev, "failed to add sub-devices: %d\n", err); + return err; + } + + /* set up power management functions */ + if (of_device_is_system_power_controller(client->dev.of_node)) { + a500_ec_client_pm_off = client; + + err = register_restart_handler(&a500_ec_restart_handler); + if (err) + return err; + + if (!pm_power_off) + pm_power_off = a500_ec_poweroff; + } + + return 0; +} + +static int a500_ec_remove(struct i2c_client *client) +{ + if (of_device_is_system_power_controller(client->dev.of_node)) { + if (pm_power_off == a500_ec_poweroff) + pm_power_off = NULL; + + unregister_restart_handler(&a500_ec_restart_handler); + } + + return 0; +} + +static const struct of_device_id a500_ec_match[] = { + { .compatible = "acer,a500-iconia-ec" }, + { } +}; +MODULE_DEVICE_TABLE(of, a500_ec_match); + +static struct i2c_driver a500_ec_driver = { + .driver = { + .name = "acer-a500-embedded-controller", + .of_match_table = a500_ec_match, + }, + .probe_new = a500_ec_probe, + .remove = a500_ec_remove, +}; +module_i2c_driver(a500_ec_driver); + +MODULE_DESCRIPTION("Acer Iconia Tab A500 Embedded Controller driver"); +MODULE_AUTHOR("Dmitry Osipenko "); +MODULE_LICENSE("GPL"); From patchwork Sun Aug 30 18:53:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 255438 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5834C2BBD0 for ; Sun, 30 Aug 2020 18:55:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A09352071B for ; Sun, 30 Aug 2020 18:55:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Afwk3TSy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726722AbgH3Szp (ORCPT ); Sun, 30 Aug 2020 14:55:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726489AbgH3SzK (ORCPT ); Sun, 30 Aug 2020 14:55:10 -0400 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 422FCC061239; Sun, 30 Aug 2020 11:55:09 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id w14so4272983ljj.4; Sun, 30 Aug 2020 11:55:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oLLo2YzfCJjR+A6TXZa0FxvLUMyx5MYAmbSNQ7sUe68=; b=Afwk3TSy4sfLwMLjGO+EDRVsjqOvPM9pk89DxOyzW7fXmZpzkXduUllrxVHQ35pxjK Tv4jKMJT4Iys13a5mQkuQYd8XAAqlQpAXs/E/MDlaGf73MSZ8qxNLLEWa+Al4grVEFFg vwTw9ZU/HOUv/OoO0RRu+2s92mrnxH1Qghji0W/NNJSOeJYnF0UKpwi5FJT2MRywmdpj 3WArW6qM4b4TUF9DTuZydI4JCI2Vwl7w551W/P0HJGEG5ztcY5d1kKff9Y6mCFf/lxLR pnZwAa3DObosJPswSmZDBjthlhx7QdOzC7B8ReruuRUu90WrjyYlG5fjZ22ghHELo0kz 4APQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oLLo2YzfCJjR+A6TXZa0FxvLUMyx5MYAmbSNQ7sUe68=; b=sWPmXuYQdqh51sxiMLDDJFH2RAzOlAH0pusXTSXRsjoKoblPeT0lp+A2BxF9WE5bAU coiJ1sTgCsP/YWt355LBndvZyPf5JPldgqDubkiz+Qnm+di9oCeZE1ZUcgjkkb4ZNvFk L2HCDAFOxKpiq1o3HYvcmwo4o1jEcPhilV+ETUbb68XpwRTyvgk72k7FQJ2suK+pVscU inzZ3HCtka2W5Hpm33kPsBI1md1cf/GH6pgc4BI3P80uqgUnDnrkCRGPusnXrgHe1/BQ lBsDEX4pP0H8FjUzfGU5rCwZk5X57ZH/Db2DT+I18Nfj2mUjYkBOQGOy9IzRvlYvZnWB 6spw== X-Gm-Message-State: AOAM531ZDCfr1R6byV04u7HxHzEuNNet6p6euSz8QsZD5Q2xwXGWLRrQ gwkzjAe4u0WMcPBchdKrbnI= X-Google-Smtp-Source: ABdhPJzURtHEnjnqDQ4crPdSoGwkqybZp8NvhdCp7iCjxQziqlSIqzy1nwrl3buNCRoylZUvMrUCwA== X-Received: by 2002:a2e:910d:: with SMTP id m13mr4046237ljg.240.1598813707670; Sun, 30 Aug 2020 11:55:07 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id n21sm21630ljc.89.2020.08.30.11.55.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Aug 2020 11:55:07 -0700 (PDT) From: Dmitry Osipenko To: Lee Jones , Rob Herring , Thierry Reding , Jonathan Hunter , Pavel Machek , Dan Murphy , Sebastian Reichel , Lubomir Rintel , Mark Brown Cc: devicetree@vger.kernel.org, linux-tegra@vger.kernel.org, linux-leds@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/6] leds: Add driver for Acer Iconia Tab A500 Date: Sun, 30 Aug 2020 21:53:55 +0300 Message-Id: <20200830185356.5365-6-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200830185356.5365-1-digetx@gmail.com> References: <20200830185356.5365-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-leds-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Acer Iconia Tab A500 is an Android tablet device which has two LEDs embedded into the Power Button. Orange LED indicates "battery charging" status and white LED indicates "wake-up/charge-done" status. The new LED driver provides control over both LEDs to userspace. Signed-off-by: Dmitry Osipenko --- drivers/leds/Kconfig | 7 ++ drivers/leds/Makefile | 1 + drivers/leds/leds-acer-a500.c | 130 ++++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 drivers/leds/leds-acer-a500.c diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 4f6464a169d5..4c39b53bcf1f 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -921,6 +921,13 @@ config LEDS_SGM3140 This option enables support for the SGM3140 500mA Buck/Boost Charge Pump LED Driver. +config LEDS_ACER_A500 + tristate "Power button LED support for Acer Iconia Tab A500" + depends on LEDS_CLASS && MFD_ACER_A500_EC + help + This option enables support for the Power Button LED of + Acer Iconia Tab A500. + comment "LED Triggers" source "drivers/leds/trigger/Kconfig" diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index 778cb4bb8c52..73e603e1727e 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -10,6 +10,7 @@ obj-$(CONFIG_LEDS_TRIGGERS) += led-triggers.o # LED Platform Drivers (keep this sorted, M-| sort) obj-$(CONFIG_LEDS_88PM860X) += leds-88pm860x.o obj-$(CONFIG_LEDS_AAT1290) += leds-aat1290.o +obj-$(CONFIG_LEDS_ACER_A500) += leds-acer-a500.o obj-$(CONFIG_LEDS_ADP5520) += leds-adp5520.o obj-$(CONFIG_LEDS_AN30259A) += leds-an30259a.o obj-$(CONFIG_LEDS_APU) += leds-apu.o diff --git a/drivers/leds/leds-acer-a500.c b/drivers/leds/leds-acer-a500.c new file mode 100644 index 000000000000..790238cebfb5 --- /dev/null +++ b/drivers/leds/leds-acer-a500.c @@ -0,0 +1,130 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include +#include +#include +#include + +#define A500_EC_LED_DELAY_USEC (100 * 1000) + +enum { + REG_RESET_LEDS = 0x40, + REG_POWER_LED_ON = 0x42, + REG_CHARGE_LED_ON = 0x43, + REG_ANDROID_LEDS_OFF = 0x5a, +}; + +struct a500_ec_led { + struct led_classdev cdev; + struct a500_ec_led *other; + const struct reg_sequence *enable_seq; + struct regmap *rmap; +}; + +static const struct reg_sequence a500_ec_leds_reset_seq[] = { + REG_SEQ(REG_RESET_LEDS, 0x0, A500_EC_LED_DELAY_USEC), + REG_SEQ(REG_ANDROID_LEDS_OFF, 0x0, A500_EC_LED_DELAY_USEC), +}; + +static const struct reg_sequence a500_ec_white_led_enable_seq[] = { + REG_SEQ(REG_POWER_LED_ON, 0x0, A500_EC_LED_DELAY_USEC), +}; + +static const struct reg_sequence a500_ec_orange_led_enable_seq[] = { + REG_SEQ(REG_CHARGE_LED_ON, 0x0, A500_EC_LED_DELAY_USEC), +}; + +static int a500_ec_led_brightness_set(struct led_classdev *led_cdev, + enum led_brightness value) +{ + struct a500_ec_led *led = container_of(led_cdev, struct a500_ec_led, + cdev); + struct reg_sequence control_seq[2]; + unsigned int num_regs = 1; + + if (value) { + control_seq[0] = led->enable_seq[0]; + } else { + /* + * There is no separate controls which can disable LEDs + * individually, there is only RESET_LEDS command that turns + * off both LEDs. + * + * RESET_LEDS turns off both LEDs, thus restore other LED if + * it's turned ON. + */ + if (led->other->cdev.brightness) + num_regs = 2; + + control_seq[0] = a500_ec_leds_reset_seq[0]; + control_seq[1] = led->other->enable_seq[0]; + } + + return regmap_multi_reg_write(led->rmap, control_seq, num_regs); +} + +static int a500_ec_leds_probe(struct platform_device *pdev) +{ + struct a500_ec_led *white_led, *orange_led; + struct regmap *rmap; + int err; + + rmap = dev_get_regmap(pdev->dev.parent, "KB930"); + if (!rmap) + return -EINVAL; + + /* reset and turn off LEDs */ + regmap_multi_reg_write(rmap, a500_ec_leds_reset_seq, 2); + + white_led = devm_kzalloc(&pdev->dev, sizeof(*white_led), GFP_KERNEL); + if (!white_led) + return -ENOMEM; + + white_led->cdev.name = "power:white"; + white_led->cdev.brightness_set_blocking = a500_ec_led_brightness_set; + white_led->cdev.flags = LED_CORE_SUSPENDRESUME; + white_led->cdev.max_brightness = 1; + white_led->enable_seq = a500_ec_white_led_enable_seq; + white_led->rmap = rmap; + + orange_led = devm_kzalloc(&pdev->dev, sizeof(*orange_led), GFP_KERNEL); + if (!orange_led) + return -ENOMEM; + + orange_led->cdev.name = "power:orange"; + orange_led->cdev.brightness_set_blocking = a500_ec_led_brightness_set; + orange_led->cdev.flags = LED_CORE_SUSPENDRESUME; + orange_led->cdev.max_brightness = 1; + orange_led->enable_seq = a500_ec_orange_led_enable_seq; + orange_led->rmap = rmap; + + white_led->other = orange_led; + orange_led->other = white_led; + + err = devm_led_classdev_register(&pdev->dev, &white_led->cdev); + if (err) { + dev_err(&pdev->dev, "failed to register white LED\n"); + return err; + } + + err = devm_led_classdev_register(&pdev->dev, &orange_led->cdev); + if (err) { + dev_err(&pdev->dev, "failed to register orange LED\n"); + return err; + } + + return 0; +} + +static struct platform_driver a500_ec_leds_driver = { + .driver = { + .name = "acer-a500-iconia-leds", + }, + .probe = a500_ec_leds_probe, +}; +module_platform_driver(a500_ec_leds_driver); + +MODULE_DESCRIPTION("LED driver for Acer Iconia Tab A500 Power Button"); +MODULE_AUTHOR("Dmitry Osipenko "); +MODULE_ALIAS("platform:acer-a500-iconia-leds"); +MODULE_LICENSE("GPL"); From patchwork Sun Aug 30 18:53:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 255437 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66C5AC2BBD0 for ; Sun, 30 Aug 2020 18:56:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 476F321527 for ; Sun, 30 Aug 2020 18:56:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uhimOhHN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726601AbgH3Szp (ORCPT ); Sun, 30 Aug 2020 14:55:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726492AbgH3SzL (ORCPT ); Sun, 30 Aug 2020 14:55:11 -0400 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D187C06123A; Sun, 30 Aug 2020 11:55:10 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id r13so4297888ljm.0; Sun, 30 Aug 2020 11:55:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=35wLUHHiL0jcYl7dr+ydbL6W/M+IENF1DgF9AQYM8t8=; b=uhimOhHNcVOop7DdL+0642zRtqUW3EjZYZ87OCM4VJnKnP2te6EhR+DxcP+EcdN34A Lcz++9haTnvEtJqJzHCsDt3XFecw2X6iOen/xKTWsHySnYpSNJ0a9Km44cg9zb2S7oyo QZcgxgYF4bEpZYp6xNwe+RjEq2p5iRN6eFxptoYVp4TEqXy/8BJx3Qr0RYp2YrJBNIgY AqqsVwyk78Zhynvb3hsUsg0UpmHWdXHgp6Rjp+WGKAXK9YkYnkmYnkirGvTa15l3uYXO bHswcbkZzCMoTIWDCE4PzeXv/Jfwt19sFvMB1tkoOSjyrEzxNkwtfUBb6P1fZFExaVjp Gcqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=35wLUHHiL0jcYl7dr+ydbL6W/M+IENF1DgF9AQYM8t8=; b=ddRhFAchFJxqSpkfAo+OaXoQopqQGKDQ2zXavacgz0kpAeZlarcPoxKvt6EeDvpDM7 DfjGs8Ai05AI/QnjCkaZi0RBKydd1VfTs2fxPF17XjLk5FqBgvbrJmX7WL6T4YGANBo2 OpjslSSu7mCJj1/HLgVRgfWi2eKee2ARFHSFW7+MGe63CQSCZo4OmQJpHNUvSUFM7jah rGo7UAlzzGIpG58Ha2mUGU6YPMsdSaEuZh7Ou/qkC+UIuphFMgGNOF1zxW7rke0wIJQG DUUqNqxNUOR8a6PIApEVmOV/IDfyiiMp6/b3IxctuIi/VELi1m4w1k5NOwrdvIpKSbrk M6cQ== X-Gm-Message-State: AOAM533tWsOQSgpxFpQ0szujf5AiXaHsqH2LALdGRZwm0as58cE15lW5 CvZdNM3LOD6lsiwapVXGF0o= X-Google-Smtp-Source: ABdhPJw+xY56U8MvvQE71DOroKATcepLQ64qhNh+AUcrFIbij52qmH2rMpKZ3ooqNrrNB0swam8nRQ== X-Received: by 2002:a2e:8046:: with SMTP id p6mr2514730ljg.372.1598813708857; Sun, 30 Aug 2020 11:55:08 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id n21sm21630ljc.89.2020.08.30.11.55.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Aug 2020 11:55:08 -0700 (PDT) From: Dmitry Osipenko To: Lee Jones , Rob Herring , Thierry Reding , Jonathan Hunter , Pavel Machek , Dan Murphy , Sebastian Reichel , Lubomir Rintel , Mark Brown Cc: devicetree@vger.kernel.org, linux-tegra@vger.kernel.org, linux-leds@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 6/6] ARM: tegra: acer-a500: Add Embedded Controller Date: Sun, 30 Aug 2020 21:53:56 +0300 Message-Id: <20200830185356.5365-7-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200830185356.5365-1-digetx@gmail.com> References: <20200830185356.5365-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-leds-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org This patch adds device-tree node for the Embedded Controller which is found on the Picasso board. The Embedded Controller itself is ENE KB930, it provides functions like battery-gauge/LED/GPIO/etc and it uses firmware that is specifically customized for the Acer A500 device. Signed-off-by: Dmitry Osipenko --- arch/arm/boot/dts/tegra20-acer-a500-picasso.dts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/arch/arm/boot/dts/tegra20-acer-a500-picasso.dts b/arch/arm/boot/dts/tegra20-acer-a500-picasso.dts index 2d683c9a1a5d..f92712e4bd34 100644 --- a/arch/arm/boot/dts/tegra20-acer-a500-picasso.dts +++ b/arch/arm/boot/dts/tegra20-acer-a500-picasso.dts @@ -502,6 +502,16 @@ panel_ddc: i2c@1 { reg = <1>; #address-cells = <1>; #size-cells = <0>; + + embedded-controller@58 { + compatible = "acer,a500-iconia-ec", "ene,kb930"; + reg = <0x58>; + + system-power-controller; + + monitored-battery = <&bat1010>; + power-supplies = <&mains>; + }; }; }; @@ -780,6 +790,13 @@ backlight: backlight { default-brightness-level = <20>; }; + bat1010: battery-2s1p { + compatible = "simple-battery"; + charge-full-design-microamp-hours = <3260000>; + energy-full-design-microwatt-hours = <24000000>; + operating-range-celsius = <0 40>; + }; + /* PMIC has a built-in 32KHz oscillator which is used by PMC */ clk32k_in: clock@0 { compatible = "fixed-clock";