From patchwork Mon Mar 21 08:55:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 12786987 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0BB687B for ; Mon, 21 Mar 2022 08:56:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62FF8C340F3; Mon, 21 Mar 2022 08:56:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647852981; bh=M2Gy8FiVTRYpGNe6BMtTfeY32cNOQh7iPVRsDN8x8+U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NNRcCs1SuofokOveoJ8pC12tqUZ3DbIUmh4vdoHVI3RDRv0EDrYdLdajojfhincll BXCW99MX9K2Lko2aZavQqbx3D0xcfvN917+gwLYTS52UYVOamkPJ/cR53UF2VFevLP /sLQO0ba1Y4C2zqTaUmCXwtGqghTD/twVisDVY8SPpSXFgW9ykaHHDHGyru54i83yy AlF066hfU4Z+K4ewcwKIzICt2hIbHlpHtmn7Xek6pUesbFaL/9kxq1qbWa4jVN1YCV vx1i/W6DxuCR5QX/0o9kswOcJwyZmxbSYJ0LeF4evUMxe3U4az/204M1EZoRV87Pca H3NlKWWOWw62A== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org, robh+dt@kernel.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Guenter Roeck Subject: [PATCH v3 1/5] platform/chrome: cros_kbd_led_backlight: sort headers alphabetically Date: Mon, 21 Mar 2022 16:55:43 +0800 Message-Id: <20220321085547.1162312-2-tzungbi@kernel.org> X-Mailer: git-send-email 2.35.1.894.gb6a874cedc-goog In-Reply-To: <20220321085547.1162312-1-tzungbi@kernel.org> References: <20220321085547.1162312-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To be neat and reduce conflict possibility, sort the headers alphabetically. Reviewed-by: Guenter Roeck Signed-off-by: Tzung-Bi Shih --- Changes from v2: - Add commit message. - Add R-b tag. Changes from v1: - Update email address accordingly. drivers/platform/chrome/cros_kbd_led_backlight.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/platform/chrome/cros_kbd_led_backlight.c b/drivers/platform/chrome/cros_kbd_led_backlight.c index aa409f0201fb..f9587a562bb7 100644 --- a/drivers/platform/chrome/cros_kbd_led_backlight.c +++ b/drivers/platform/chrome/cros_kbd_led_backlight.c @@ -4,12 +4,12 @@ // Copyright (C) 2012 Google, Inc. #include -#include #include #include -#include #include #include +#include +#include #include #include From patchwork Mon Mar 21 08:55:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 12786988 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D790D7B for ; Mon, 21 Mar 2022 08:56:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42515C340ED; Mon, 21 Mar 2022 08:56:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647852983; bh=bYn8GCOS4FzVyko3kVP3w9AziCglz52+xbgyJ5twDxc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ODnQvKChuT4AvZtyDFoo3l7Pk/6hRt0OVLvDV4SC6H8Xhj/dvwKb541nZuiluJUQ2 7sWxey8fEsm4icDslXgiEiwtKiYz0pI8iwVX3Q4OvhOgUbQJC45boYXdaWKdTZE28P emedXXAjKlCp80LYwytgIwe6HiXfgM9LpJXjt7LGE8hfHejDssnDgyqSUCrj/flu+a ioxkKvqLfbxvLA+xKQkxzwSH7yy2r/KYwHt307O/cLYH1sMRbZNUaVwg65AbKC9FVo axZRrx53JqTIfz0SkGFihKY7hZ+bNZNbf83lFPKsqnyW0avW+CSFd2v44K2em5BRRl I1Q29Vwvjf0lg== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org, robh+dt@kernel.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/5] platform/chrome: cros_kbd_led_backlight: separate ACPI backend Date: Mon, 21 Mar 2022 16:55:44 +0800 Message-Id: <20220321085547.1162312-3-tzungbi@kernel.org> X-Mailer: git-send-email 2.35.1.894.gb6a874cedc-goog In-Reply-To: <20220321085547.1162312-1-tzungbi@kernel.org> References: <20220321085547.1162312-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 cros_kbd_led_backlight uses ACPI_KEYBOARD_BACKLIGHT_WRITE and ACPI_KEYBOARD_BACKLIGHT_READ for setting and getting the brightness respectively. Separate ACPI operations as an independent option for preparing the driver to support other backends. Signed-off-by: Tzung-Bi Shih --- Changes from v2: - Use #ifdef for boolean CONFIG_CROS_KBD_LED_BACKLIGHT_ACPI. Changes from v1: - Update email address accordingly. - Use CONFIG_ACPI guard per "kernel test robot " reported an unused variable issue. drivers/platform/chrome/Kconfig | 8 +- .../platform/chrome/cros_kbd_led_backlight.c | 93 ++++++++++++++++--- 2 files changed, 87 insertions(+), 14 deletions(-) diff --git a/drivers/platform/chrome/Kconfig b/drivers/platform/chrome/Kconfig index ccc23d8686e8..3f74679a556c 100644 --- a/drivers/platform/chrome/Kconfig +++ b/drivers/platform/chrome/Kconfig @@ -128,7 +128,7 @@ config CROS_EC_PROTO config CROS_KBD_LED_BACKLIGHT tristate "Backlight LED support for Chrome OS keyboards" - depends on LEDS_CLASS && ACPI + depends on LEDS_CLASS help This option enables support for the keyboard backlight LEDs on select Chrome OS systems. @@ -136,6 +136,12 @@ config CROS_KBD_LED_BACKLIGHT To compile this driver as a module, choose M here: the module will be called cros_kbd_led_backlight. +config CROS_KBD_LED_BACKLIGHT_ACPI + bool "ChromeOS keyboard backlight ACPI backend" + depends on ACPI && CROS_KBD_LED_BACKLIGHT + help + ChromeOS keyboard backlight ACPI backend. + config CROS_EC_CHARDEV tristate "ChromeOS EC miscdevice" depends on MFD_CROS_EC_DEV diff --git a/drivers/platform/chrome/cros_kbd_led_backlight.c b/drivers/platform/chrome/cros_kbd_led_backlight.c index f9587a562bb7..05b4f274086b 100644 --- a/drivers/platform/chrome/cros_kbd_led_backlight.c +++ b/drivers/platform/chrome/cros_kbd_led_backlight.c @@ -13,6 +13,33 @@ #include #include +/** + * struct keyboard_led_drvdata - keyboard LED driver data. + * @init: Init function. + * @brightness_get: Get LED brightness level. + * @brightness_set: Set LED brightness level. Must not sleep. + * @brightness_set_blocking: Set LED brightness level. It can block the + * caller for the time required for accessing a + * LED device register + * @max_brightness: Maximum brightness. + * + * See struct led_classdev in include/linux/leds.h for more details. + */ +struct keyboard_led_drvdata { + int (*init)(struct platform_device *pdev); + + enum led_brightness (*brightness_get)(struct led_classdev *led_cdev); + + void (*brightness_set)(struct led_classdev *led_cdev, + enum led_brightness brightness); + int (*brightness_set_blocking)(struct led_classdev *led_cdev, + enum led_brightness brightness); + + enum led_brightness max_brightness; +}; + +#ifdef CONFIG_CROS_KBD_LED_BACKLIGHT_ACPI + /* Keyboard LED ACPI Device must be defined in firmware */ #define ACPI_KEYBOARD_BACKLIGHT_DEVICE "\\_SB.KBLT" #define ACPI_KEYBOARD_BACKLIGHT_READ ACPI_KEYBOARD_BACKLIGHT_DEVICE ".KBQC" @@ -20,8 +47,8 @@ #define ACPI_KEYBOARD_BACKLIGHT_MAX 100 -static void keyboard_led_set_brightness(struct led_classdev *cdev, - enum led_brightness brightness) +static void keyboard_led_set_brightness_acpi(struct led_classdev *cdev, + enum led_brightness brightness) { union acpi_object param; struct acpi_object_list input; @@ -40,7 +67,7 @@ static void keyboard_led_set_brightness(struct led_classdev *cdev, } static enum led_brightness -keyboard_led_get_brightness(struct led_classdev *cdev) +keyboard_led_get_brightness_acpi(struct led_classdev *cdev) { unsigned long long brightness; acpi_status status; @@ -56,12 +83,10 @@ keyboard_led_get_brightness(struct led_classdev *cdev) return brightness; } -static int keyboard_led_probe(struct platform_device *pdev) +static int keyboard_led_init_acpi(struct platform_device *pdev) { - struct led_classdev *cdev; acpi_handle handle; acpi_status status; - int error; /* Look for the keyboard LED ACPI Device */ status = acpi_get_handle(ACPI_ROOT_OBJECT, @@ -73,15 +98,55 @@ static int keyboard_led_probe(struct platform_device *pdev) return -ENXIO; } + return 0; +} + +static const struct keyboard_led_drvdata keyboard_led_drvdata_acpi = { + .init = keyboard_led_init_acpi, + .brightness_set = keyboard_led_set_brightness_acpi, + .brightness_get = keyboard_led_get_brightness_acpi, + .max_brightness = ACPI_KEYBOARD_BACKLIGHT_MAX, +}; + +#else /* CONFIG_CROS_KBD_LED_BACKLIGHT_ACPI */ + +static int keyboard_led_init_acpi_null(struct platform_device *pdev) +{ + return -EOPNOTSUPP; +} + +static const struct keyboard_led_drvdata keyboard_led_drvdata_acpi = { + .init = keyboard_led_init_acpi_null, +}; + +#endif /* CONFIG_CROS_KBD_LED_BACKLIGHT_ACPI */ + +static int keyboard_led_probe(struct platform_device *pdev) +{ + struct led_classdev *cdev; + const struct keyboard_led_drvdata *drvdata; + int error; + + drvdata = acpi_device_get_match_data(&pdev->dev); + if (!drvdata) + return -EINVAL; + + if (drvdata->init) { + error = drvdata->init(pdev); + if (error) + return error; + } + cdev = devm_kzalloc(&pdev->dev, sizeof(*cdev), GFP_KERNEL); if (!cdev) return -ENOMEM; cdev->name = "chromeos::kbd_backlight"; - cdev->max_brightness = ACPI_KEYBOARD_BACKLIGHT_MAX; cdev->flags |= LED_CORE_SUSPENDRESUME; - cdev->brightness_set = keyboard_led_set_brightness; - cdev->brightness_get = keyboard_led_get_brightness; + cdev->max_brightness = drvdata->max_brightness; + cdev->brightness_set = drvdata->brightness_set; + cdev->brightness_set_blocking = drvdata->brightness_set_blocking; + cdev->brightness_get = drvdata->brightness_get; error = devm_led_classdev_register(&pdev->dev, cdev); if (error) @@ -90,16 +155,18 @@ static int keyboard_led_probe(struct platform_device *pdev) return 0; } -static const struct acpi_device_id keyboard_led_id[] = { - { "GOOG0002", 0 }, +#ifdef CONFIG_ACPI +static const struct acpi_device_id keyboard_led_acpi_match[] = { + { "GOOG0002", (kernel_ulong_t)&keyboard_led_drvdata_acpi }, { } }; -MODULE_DEVICE_TABLE(acpi, keyboard_led_id); +MODULE_DEVICE_TABLE(acpi, keyboard_led_acpi_match); +#endif static struct platform_driver keyboard_led_driver = { .driver = { .name = "chromeos-keyboard-leds", - .acpi_match_table = ACPI_PTR(keyboard_led_id), + .acpi_match_table = ACPI_PTR(keyboard_led_acpi_match), }, .probe = keyboard_led_probe, }; From patchwork Mon Mar 21 08:55:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 12786989 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A4FF7B for ; Mon, 21 Mar 2022 08:56:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0C9DC340E8; Mon, 21 Mar 2022 08:56:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647852985; bh=6lvD4As1wyNt6hgqRzKbcQR73uSqjdjkadOyY4gAMe8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EEgt3+1vucLMwZM6kfXoKAd8O1Ci4FG/O3UCFATYey1FL2W9BnwwESoAzZJrZJE9m /QjrbqMoIg4aX/42MUUv4kGQg4/yBXI1yMEpJXjAZ/BonSJIVJ4rp1ZNNstr1HB+4N 6EJfEeZW2dnCbY0zTFlYYKySQrWciTuFhg+o03a2LBjW3wz7kZQBs+zk+Njx3t8HiZ sBMBDT4gCfVKYj5dX9ue2dpIzyXFiLI+oVfeocaqvSnQug43CqtK4/7/GwWgWK7uUc YyCkwT3B2sCpbcdbqkQjyVyrSk1NaGbssf7LyrmK9oEWFL0zHopxGY3E2kSuXAyR7m Q+YUee+nJ/PFg== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org, robh+dt@kernel.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Rob Herring Subject: [PATCH v3 3/5] dt-bindings: add google,cros-kbd-led-backlight Date: Mon, 21 Mar 2022 16:55:45 +0800 Message-Id: <20220321085547.1162312-4-tzungbi@kernel.org> X-Mailer: git-send-email 2.35.1.894.gb6a874cedc-goog In-Reply-To: <20220321085547.1162312-1-tzungbi@kernel.org> References: <20220321085547.1162312-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Acked-by: Rob Herring Signed-off-by: Tzung-Bi Shih --- No changes from v2. Changes from v1: (https://patchwork.kernel.org/project/chrome-platform/patch/20220214053646.3088298-4-tzungbi@google.com/) - Update email address accordingly. - Add A-b tag. .../chrome/google,cros-kbd-led-backlight.yaml | 35 +++++++++++++++++++ .../bindings/mfd/google,cros-ec.yaml | 3 ++ 2 files changed, 38 insertions(+) create mode 100644 Documentation/devicetree/bindings/chrome/google,cros-kbd-led-backlight.yaml diff --git a/Documentation/devicetree/bindings/chrome/google,cros-kbd-led-backlight.yaml b/Documentation/devicetree/bindings/chrome/google,cros-kbd-led-backlight.yaml new file mode 100644 index 000000000000..5b875af6a95a --- /dev/null +++ b/Documentation/devicetree/bindings/chrome/google,cros-kbd-led-backlight.yaml @@ -0,0 +1,35 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/chrome/google,cros-kbd-led-backlight.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: ChromeOS keyboard backlight LED driver. + +maintainers: + - Tzung-Bi Shih + +properties: + compatible: + const: google,cros-kbd-led-backlight + +required: + - compatible + +additionalProperties: false + +examples: + - | + spi0 { + #address-cells = <1>; + #size-cells = <0>; + + cros_ec: ec@0 { + compatible = "google,cros-ec-spi"; + reg = <0>; + + kbd-led-backlight { + compatible = "google,cros-kbd-led-backlight"; + }; + }; + }; diff --git a/Documentation/devicetree/bindings/mfd/google,cros-ec.yaml b/Documentation/devicetree/bindings/mfd/google,cros-ec.yaml index d1f53bd449f7..1815ca0e8ebc 100644 --- a/Documentation/devicetree/bindings/mfd/google,cros-ec.yaml +++ b/Documentation/devicetree/bindings/mfd/google,cros-ec.yaml @@ -90,6 +90,9 @@ properties: ec-pwm: $ref: "/schemas/pwm/google,cros-ec-pwm.yaml#" + kbd-led-backlight: + $ref: "/schemas/chrome/google,cros-kbd-led-backlight.yaml#" + keyboard-controller: $ref: "/schemas/input/google,cros-ec-keyb.yaml#" From patchwork Mon Mar 21 08:55:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 12786990 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E2702C9E for ; Mon, 21 Mar 2022 08:56:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D10B0C340F4; Mon, 21 Mar 2022 08:56:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647852987; bh=JOxBbU85PIDh5q8fQ7u3tZbk+aC74evCjtf8jSmnQJ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GVj31NNC9haN0oT/wmRNbhOtPiJ0MDU/rdmyt/JATCvhKxY1s6cQ3O11/rYyv1yVi FArp0kGbpUUiM4f9yBCwJHMSFDJHtWHszg5j+nlDhfrPTMP3VROV78EOW0IsoHkmtA QYUDy0fIjj96CN6llz9TcOTlJwuDmmfLz5CmHXfBWnSy7ZGVS2F4is4dKJO+LLnDd+ TevaFSnZJQ5Ho4S5BR/QfAdSzmXbGIUQdQU0KPjhs2lnQ01vEs59vFuqICI78mnPGP ea+LVSV/njiHxnysuZOPpWuc/ygDGDzRIvT1Z7AnZ+U0GoGURe73xP7Z0PR1UXlL0l 1H7hNNFl5kfXw== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org, robh+dt@kernel.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Guenter Roeck Subject: [PATCH v3 4/5] platform/chrome: cros_kbd_led_backlight: support OF match Date: Mon, 21 Mar 2022 16:55:46 +0800 Message-Id: <20220321085547.1162312-5-tzungbi@kernel.org> X-Mailer: git-send-email 2.35.1.894.gb6a874cedc-goog In-Reply-To: <20220321085547.1162312-1-tzungbi@kernel.org> References: <20220321085547.1162312-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 For letting device tree based machines to use the driver, support OF match. Reviewed-by: Guenter Roeck Signed-off-by: Tzung-Bi Shih --- Changes from v2: - Add commit message. - Add R-b tag. Changes from v1: (https://patchwork.kernel.org/project/chrome-platform/patch/20220214053646.3088298-5-tzungbi@google.com/) - Update email address accordingly. - Use device_get_match_data() per review comment in v1. drivers/platform/chrome/cros_kbd_led_backlight.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/platform/chrome/cros_kbd_led_backlight.c b/drivers/platform/chrome/cros_kbd_led_backlight.c index 05b4f274086b..5cbe27cb4610 100644 --- a/drivers/platform/chrome/cros_kbd_led_backlight.c +++ b/drivers/platform/chrome/cros_kbd_led_backlight.c @@ -10,7 +10,9 @@ #include #include #include +#include #include +#include #include /** @@ -127,7 +129,7 @@ static int keyboard_led_probe(struct platform_device *pdev) const struct keyboard_led_drvdata *drvdata; int error; - drvdata = acpi_device_get_match_data(&pdev->dev); + drvdata = device_get_match_data(&pdev->dev); if (!drvdata) return -EINVAL; @@ -163,10 +165,21 @@ static const struct acpi_device_id keyboard_led_acpi_match[] = { MODULE_DEVICE_TABLE(acpi, keyboard_led_acpi_match); #endif +#ifdef CONFIG_OF +static const struct of_device_id keyboard_led_of_match[] = { + { + .compatible = "google,cros-kbd-led-backlight", + }, + {} +}; +MODULE_DEVICE_TABLE(of, keyboard_led_of_match); +#endif + static struct platform_driver keyboard_led_driver = { .driver = { .name = "chromeos-keyboard-leds", .acpi_match_table = ACPI_PTR(keyboard_led_acpi_match), + .of_match_table = of_match_ptr(keyboard_led_of_match), }, .probe = keyboard_led_probe, }; From patchwork Mon Mar 21 08:55:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 12786991 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33B2D2C9E for ; Mon, 21 Mar 2022 08:56:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF7FDC36AE2; Mon, 21 Mar 2022 08:56:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647852989; bh=5b71O0M4hOE8WRFTD/qF2V3yAPLXWyKIX8OtNTzalko=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ABCTfHx2+Kdv7Zb8U/CBtl2L25DF34cgdE731d3KkXmBpCZFJlRFQyvzSjfT1Nw2S W0qk09Bs8SFZgIddMe/IEBzZJ1vxhsgyMH6+1ldRGTUfjvJHj+zssNyR4YHXpE2xwq 9s+9TYrYY1QxZZtd2vp4rjIH8EN0s4v6FXIr4LaiYRyPmqyiKmlflMZbN2TWeoi0gS a2nQg3nfSrkGtrPXYOb92qQb0gj7Hi1ieGnPhUHGNPBS5cOqP8nCEXc8iMz+W2e6Zj CVG2cCx+u25nPHYKs7k22/hQv5GpUhOXdqk0nMoHolON0/mwrS+iq9HCkJYeOg+Sbq dCY9shF7BNAag== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org, robh+dt@kernel.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 5/5] platform/chrome: cros_kbd_led_backlight: support EC PWM backend Date: Mon, 21 Mar 2022 16:55:47 +0800 Message-Id: <20220321085547.1162312-6-tzungbi@kernel.org> X-Mailer: git-send-email 2.35.1.894.gb6a874cedc-goog In-Reply-To: <20220321085547.1162312-1-tzungbi@kernel.org> References: <20220321085547.1162312-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 EC PWM backend uses EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT and EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT for setting and getting the brightness respectively. Signed-off-by: Tzung-Bi Shih --- Changes from v2: - Turn CROS_KBD_LED_BACKLIGHT_EC_PWM to boolean. - Use #ifdef for boolean CROS_KBD_LED_BACKLIGHT_EC_PWM. Changes from v1: - Update email address accordingly. drivers/platform/chrome/Kconfig | 6 + .../platform/chrome/cros_kbd_led_backlight.c | 126 +++++++++++++++--- 2 files changed, 117 insertions(+), 15 deletions(-) diff --git a/drivers/platform/chrome/Kconfig b/drivers/platform/chrome/Kconfig index 3f74679a556c..e02789d7c0d4 100644 --- a/drivers/platform/chrome/Kconfig +++ b/drivers/platform/chrome/Kconfig @@ -142,6 +142,12 @@ config CROS_KBD_LED_BACKLIGHT_ACPI help ChromeOS keyboard backlight ACPI backend. +config CROS_KBD_LED_BACKLIGHT_EC_PWM + bool "ChromeOS keyboard backlight EC PWM backend" + depends on CROS_EC && CROS_KBD_LED_BACKLIGHT + help + ChromeOS keyboard backlight EC PWM backend. + config CROS_EC_CHARDEV tristate "ChromeOS EC miscdevice" depends on MFD_CROS_EC_DEV diff --git a/drivers/platform/chrome/cros_kbd_led_backlight.c b/drivers/platform/chrome/cros_kbd_led_backlight.c index 5cbe27cb4610..8c35dd2fa607 100644 --- a/drivers/platform/chrome/cros_kbd_led_backlight.c +++ b/drivers/platform/chrome/cros_kbd_led_backlight.c @@ -11,10 +11,17 @@ #include #include #include +#include +#include #include #include #include +struct keyboard_led_private { + struct led_classdev cdev; + struct cros_ec_device *ec; +}; + /** * struct keyboard_led_drvdata - keyboard LED driver data. * @init: Init function. @@ -40,6 +47,8 @@ struct keyboard_led_drvdata { enum led_brightness max_brightness; }; +#define KEYBOARD_BACKLIGHT_MAX 100 + #ifdef CONFIG_CROS_KBD_LED_BACKLIGHT_ACPI /* Keyboard LED ACPI Device must be defined in firmware */ @@ -47,8 +56,6 @@ struct keyboard_led_drvdata { #define ACPI_KEYBOARD_BACKLIGHT_READ ACPI_KEYBOARD_BACKLIGHT_DEVICE ".KBQC" #define ACPI_KEYBOARD_BACKLIGHT_WRITE ACPI_KEYBOARD_BACKLIGHT_DEVICE ".KBCM" -#define ACPI_KEYBOARD_BACKLIGHT_MAX 100 - static void keyboard_led_set_brightness_acpi(struct led_classdev *cdev, enum led_brightness brightness) { @@ -107,7 +114,7 @@ static const struct keyboard_led_drvdata keyboard_led_drvdata_acpi = { .init = keyboard_led_init_acpi, .brightness_set = keyboard_led_set_brightness_acpi, .brightness_get = keyboard_led_get_brightness_acpi, - .max_brightness = ACPI_KEYBOARD_BACKLIGHT_MAX, + .max_brightness = KEYBOARD_BACKLIGHT_MAX, }; #else /* CONFIG_CROS_KBD_LED_BACKLIGHT_ACPI */ @@ -123,34 +130,122 @@ static const struct keyboard_led_drvdata keyboard_led_drvdata_acpi = { #endif /* CONFIG_CROS_KBD_LED_BACKLIGHT_ACPI */ +#ifdef CONFIG_CROS_KBD_LED_BACKLIGHT_EC_PWM + +static int +keyboard_led_set_brightness_blocking_ec_pwm(struct led_classdev *cdev, + enum led_brightness brightness) +{ + struct { + struct cros_ec_command msg; + struct ec_params_pwm_set_keyboard_backlight params; + } __packed buf; + struct ec_params_pwm_set_keyboard_backlight *params = &buf.params; + struct cros_ec_command *msg = &buf.msg; + struct keyboard_led_private *private = + container_of(cdev, struct keyboard_led_private, cdev); + + memset(&buf, 0, sizeof(buf)); + + msg->version = 0; + msg->command = EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT; + msg->insize = 0; + msg->outsize = sizeof(*params); + + params->percent = brightness; + + return cros_ec_cmd_xfer_status(private->ec, msg); +} + +static enum led_brightness +keyboard_led_get_brightness_ec_pwm(struct led_classdev *cdev) +{ + struct { + struct cros_ec_command msg; + struct ec_response_pwm_get_keyboard_backlight resp; + } __packed buf; + struct ec_response_pwm_get_keyboard_backlight *resp = &buf.resp; + struct cros_ec_command *msg = &buf.msg; + struct keyboard_led_private *private = + container_of(cdev, struct keyboard_led_private, cdev); + int ret; + + memset(&buf, 0, sizeof(buf)); + + msg->version = 0; + msg->command = EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT; + msg->insize = sizeof(*resp); + msg->outsize = 0; + + ret = cros_ec_cmd_xfer_status(private->ec, msg); + if (ret < 0) + return ret; + + return resp->percent; +} + +static int keyboard_led_init_ec_pwm(struct platform_device *pdev) +{ + struct keyboard_led_private *private = platform_get_drvdata(pdev); + + private->ec = dev_get_drvdata(pdev->dev.parent); + if (!private->ec) { + dev_err(&pdev->dev, "no parent EC device\n"); + return -EINVAL; + } + + return 0; +} + +static const struct keyboard_led_drvdata keyboard_led_drvdata_ec_pwm = { + .init = keyboard_led_init_ec_pwm, + .brightness_set_blocking = keyboard_led_set_brightness_blocking_ec_pwm, + .brightness_get = keyboard_led_get_brightness_ec_pwm, + .max_brightness = KEYBOARD_BACKLIGHT_MAX, +}; + +#else /* CONFIG_CROS_KBD_LED_BACKLIGHT_EC_PWM */ + +static int keyboard_led_init_ec_pwm_null(struct platform_device *pdev) +{ + return -EOPNOTSUPP; +} + +static const struct keyboard_led_drvdata keyboard_led_drvdata_ec_pwm = { + .init = keyboard_led_init_ec_pwm_null, +}; + +#endif /* CONFIG_CROS_KBD_LED_BACKLIGHT_EC_PWM */ + static int keyboard_led_probe(struct platform_device *pdev) { - struct led_classdev *cdev; const struct keyboard_led_drvdata *drvdata; + struct keyboard_led_private *private; int error; drvdata = device_get_match_data(&pdev->dev); if (!drvdata) return -EINVAL; + private = devm_kzalloc(&pdev->dev, sizeof(*private), GFP_KERNEL); + if (!private) + return -ENOMEM; + platform_set_drvdata(pdev, private); + if (drvdata->init) { error = drvdata->init(pdev); if (error) return error; } - cdev = devm_kzalloc(&pdev->dev, sizeof(*cdev), GFP_KERNEL); - if (!cdev) - return -ENOMEM; - - cdev->name = "chromeos::kbd_backlight"; - cdev->flags |= LED_CORE_SUSPENDRESUME; - cdev->max_brightness = drvdata->max_brightness; - cdev->brightness_set = drvdata->brightness_set; - cdev->brightness_set_blocking = drvdata->brightness_set_blocking; - cdev->brightness_get = drvdata->brightness_get; + private->cdev.name = "chromeos::kbd_backlight"; + private->cdev.flags |= LED_CORE_SUSPENDRESUME; + private->cdev.max_brightness = drvdata->max_brightness; + private->cdev.brightness_set = drvdata->brightness_set; + private->cdev.brightness_set_blocking = drvdata->brightness_set_blocking; + private->cdev.brightness_get = drvdata->brightness_get; - error = devm_led_classdev_register(&pdev->dev, cdev); + error = devm_led_classdev_register(&pdev->dev, &private->cdev); if (error) return error; @@ -169,6 +264,7 @@ MODULE_DEVICE_TABLE(acpi, keyboard_led_acpi_match); static const struct of_device_id keyboard_led_of_match[] = { { .compatible = "google,cros-kbd-led-backlight", + .data = &keyboard_led_drvdata_ec_pwm, }, {} };