From patchwork Mon Feb 14 05:36:42 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: 12744902 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E728F7E4 for ; Mon, 14 Feb 2022 05:37:29 +0000 (UTC) Received: by mail-yb1-f201.google.com with SMTP id i205-20020a2522d6000000b00622c778ac7cso4357346ybi.3 for ; Sun, 13 Feb 2022 21:37:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=RM7B/VP3RiMIbRxHXAkoswg4A5f1B95tqoOVGTsgT8Q=; b=TTbMKvwz6PseJb5lRAXLQiBv75QGAS10Z9JTQyCyZ32BBng4ecFDNGi05LGrA57+Fv +cgxTg66+Ae6IeLW50dDVi+h2CZqYrwt9erF1a+Qa3ZqUuQnXUpkEhOLGdZEDsmEtlOD aa4oKgzbTO7qdsYuMM9iefxLmoVMihDg2tb+VlAp/Hdb2c5gQwONJz1XJ01Jl5Ln9xl7 jq4QV7B/naowDN69QoT8aNjnfHnCL5sbZxKazEBN2lAJpA8RKeNzdRDr0T2UqrxznoZr FC8aW/1Lq/VsZWV1tzNCy/EIcMbu6uaLKupmhBW6xUQeT0FcH85gsLXHR3nPNvCTJQ4R vDbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=RM7B/VP3RiMIbRxHXAkoswg4A5f1B95tqoOVGTsgT8Q=; b=katf43X9YcYjfmQbMEq21JuF90QlTQS5vlM7emwUfguAsxwgER2sfu4eY3hUYVazQW D2h8f5rTiGh6mn32CgxY1M/WcLvR+tyD4+pezpNWw7ISl9/HyzHUyVUZ2mAgJSplczIa 76nv5IhdW19QDeCa2Ui1YJKwiKv3k2L6GYkMTA/O0zidOYqKiPDEuzskqXpG49HBkd0A AyD473GtstEVADVwXHnbmzw5w/BH6e/iw16ZpB3WpcVCSlK71VesQ2GvPTSGz4dihpKB z6YfbAg+sYw4nSGWvE/d+fXpfUqhq3C0rRvoocJeXFKmRC6m7hDb79QMRAqldBOLiNZ/ j2Lw== X-Gm-Message-State: AOAM531CSNKwmHtsUFihjHNsX0pk6mSu6PDoq/1WR5A2ePiHlMaynp5j RkcW+jwsbMC5i29QO+Fi2HFm2uJZVCuB X-Google-Smtp-Source: ABdhPJx+13Gw/OOKY8khKfw7V8FFpvA8xTR4gZkToZpRpsfvFKIV+UFm7cr8RGYsxDkI86AyD9bMelqUh6+q X-Received: from tzungbi-z840.tpe.corp.google.com ([2401:fa00:1:10:f315:f92d:e3d3:2539]) (user=tzungbi job=sendgmr) by 2002:a25:e705:: with SMTP id e5mr786251ybh.216.1644817049075; Sun, 13 Feb 2022 21:37:29 -0800 (PST) Date: Mon, 14 Feb 2022 13:36:42 +0800 In-Reply-To: <20220214053646.3088298-1-tzungbi@google.com> Message-Id: <20220214053646.3088298-2-tzungbi@google.com> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20220214053646.3088298-1-tzungbi@google.com> X-Mailer: git-send-email 2.35.1.265.g69c8d7142f-goog Subject: [PATCH 1/5] platform/chrome: cros_kbd_led_backlight: sort headers alphabetically From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org, robh+dt@kernel.org Cc: chrome-platform@lists.linux.dev, tzungbi@google.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Signed-off-by: Tzung-Bi Shih --- 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 Feb 14 05:36: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: 12744903 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E56F7E4 for ; Mon, 14 Feb 2022 05:37:34 +0000 (UTC) Received: by mail-yb1-f202.google.com with SMTP id b187-20020a251bc4000000b0061e15c5024fso31638876ybb.4 for ; Sun, 13 Feb 2022 21:37:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=mvUncpaYliSmeR41+C/l/4otzikQqLf0u/Gn7UTF124=; b=CgnY/Etxq1CyrqQlo1UL4rL1ybmB5rCQ+6pY/MvGGHYyeaRQsk2wYMLegZQZEcwZsJ NyGIccHYFaOnm98G3N7N85lg3DLRQ7xGG5rxkwVD7W95E1+D1weAeD1yk3Q10IZ6Amt0 Hw8qX+xAGOHGlE0R+X5VypIs+M8lpKY2gB5VlccfDK524l+q/KlnvnXOk3phmLmmhOdC TWGytAKQp4Gjxj/7h2Ud6bRoDWdzV9b0SiI//E+GziCKNvcwaptlfJuY47cilCo+nf3/ m9Jx0k1qUxPpzzVO1nVgKvVuUO5dymF7qS3N42RoXWnbLGLQh/LgCxMxVBKPecZ3yFY9 XkXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=mvUncpaYliSmeR41+C/l/4otzikQqLf0u/Gn7UTF124=; b=yOni6zCMRAdhPzHA1i4i1UpI00mLQU8AzBx0kATpSlm+iugEKNSeY+VB2x+yO3F7Wa /6+Wn/o8E3eHOepDEC69AxvokCH0WxFCpO9esEmXS+d8orF6qax2yVCMCHDQnAkXepDZ ReqBJQSXQ9fdKcLaODzJ0jcz5bAm76be6zrzecadFdb1gUFQ7n+0ZVx22SZGG/+C8AVK t6K1GsOGU3bj/E48R2a9ID5S5jzh9X7uKOYrwOj04AdQeocxVvSpxQWhnEj/aCtH/t1+ f+HtbupFRcGTamllw1rn4dDUJqbR+C5D9dHGaFJngBoHFK2tLNOydyOFYv+04K01H8eb CdKw== X-Gm-Message-State: AOAM531mOn1ooBY/AsULdljEUGLrhiW7wPhNMKjJOL52xUpVndGRVIx3 DqnkI2NLYU3kEb4Oc9HfJguZiFM8z8l4 X-Google-Smtp-Source: ABdhPJyvjfHE/YYj+ehvCI5kt0131cYqhmHlQgRbK0thqB8SDSpmLWhwKARAD9ExhYgg6qDWIzUjIoLS8icM X-Received: from tzungbi-z840.tpe.corp.google.com ([2401:fa00:1:10:f315:f92d:e3d3:2539]) (user=tzungbi job=sendgmr) by 2002:a25:d9ce:: with SMTP id q197mr10879482ybg.739.1644817053360; Sun, 13 Feb 2022 21:37:33 -0800 (PST) Date: Mon, 14 Feb 2022 13:36:43 +0800 In-Reply-To: <20220214053646.3088298-1-tzungbi@google.com> Message-Id: <20220214053646.3088298-3-tzungbi@google.com> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20220214053646.3088298-1-tzungbi@google.com> X-Mailer: git-send-email 2.35.1.265.g69c8d7142f-goog Subject: [PATCH 2/5] platform/chrome: cros_kbd_led_backlight: separate ACPI backend From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org, robh+dt@kernel.org Cc: chrome-platform@lists.linux.dev, tzungbi@google.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org 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 --- drivers/platform/chrome/Kconfig | 8 +- .../platform/chrome/cros_kbd_led_backlight.c | 91 ++++++++++++++++--- 2 files changed, 85 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..814f2b74c602 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; +}; + +#if IS_ENABLED(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 /* IS_ENABLED(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 /* IS_ENABLED(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,16 @@ static int keyboard_led_probe(struct platform_device *pdev) return 0; } -static const struct acpi_device_id keyboard_led_id[] = { - { "GOOG0002", 0 }, +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); 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 Feb 14 05:36: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: 12744904 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A37577E4 for ; Mon, 14 Feb 2022 05:37:38 +0000 (UTC) Received: by mail-yb1-f201.google.com with SMTP id q11-20020a252a0b000000b0061e240c8fb3so28231042ybq.22 for ; Sun, 13 Feb 2022 21:37:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=DQT1njARcAhQIihUotwILwK0baqFsKzs/qdOQYfjv+Y=; b=oMvKMnKWvbRtr0l3jGrkdm9p29tjSHtw95L8IvCbwaufLdZ58bkWoR/MIAGbmxIDNO 74swf8EoSGgOIV9tdjWYPg8p+3lenYCFrs0vZKplemvO4UvcORH+n7Mhy+auqOZ2vd+q otqKjMDl2eS/6jYwLKo+yju3h1BsAX6WnMrB5qCjKGSBqKss8Kmt66ve3GtbSFvd/EQx 4PRLsvvjRxehPpufJfqfekjZmzEU4ob0pYTOPHlv1OZFMkkIq+tJA534UOpV769Gbzt3 NRdZv8XhxXniBv858yKjIfAMxqOwVLivC2/NjUtdoi88OfxIBEXVGAUKzLRru1X+KCHg OQxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=DQT1njARcAhQIihUotwILwK0baqFsKzs/qdOQYfjv+Y=; b=SpOxag6WQr+aysogRyw7S3FbOoegHqINE+SANtE5kbxorsaOrIYcHPMouOviqXqix6 Mmhj3hUtdoHI1oh0LKYPMsmC+JOJh7Gf0GjQvCNfjc1uHyO6iv7/nAW3TdDRVz6YXNnF ySk0dwJ4S8b1Z69fyNYpbv7fof0YUoIhRXLRUF8TGl04/LsseZmXU42ktMMnhq9HJ/ui mcoJhKRW2eLZgtj9xjhUpL0N8es55t5sDi52e8/GgDsyRK2ltjORrrP6aLLh/GMgI+hc X+yFCUfyLqzA3IKsUqmiauv3Rm2GfdTMSDRoZjtF2nW4/wfdA3BVKxly4A/344Iw3KnQ SJRg== X-Gm-Message-State: AOAM5337AGGv6CBllPa0VEz49zBwjww6PKRdtJdTC3NjdTu9+H/KWBkr MNoMq+r/iSU7hUBxMRJQoZUrilzbbjrQ X-Google-Smtp-Source: ABdhPJxOzKq6UNR5brAsM1MXIf51Dq60vdHRApus/HRyC/6Y4e0TFqZsk5zbI7Qfdjv+7pQmG53gsfD841a+ X-Received: from tzungbi-z840.tpe.corp.google.com ([2401:fa00:1:10:f315:f92d:e3d3:2539]) (user=tzungbi job=sendgmr) by 2002:a81:a391:: with SMTP id a139mr12318940ywh.432.1644817057814; Sun, 13 Feb 2022 21:37:37 -0800 (PST) Date: Mon, 14 Feb 2022 13:36:44 +0800 In-Reply-To: <20220214053646.3088298-1-tzungbi@google.com> Message-Id: <20220214053646.3088298-4-tzungbi@google.com> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20220214053646.3088298-1-tzungbi@google.com> X-Mailer: git-send-email 2.35.1.265.g69c8d7142f-goog Subject: [PATCH 3/5] dt-bindings: add google,cros-kbd-led-backlight From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org, robh+dt@kernel.org Cc: chrome-platform@lists.linux.dev, tzungbi@google.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Signed-off-by: Tzung-Bi Shih Acked-by: Rob Herring --- .../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..104299e09cbb --- /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 Feb 14 05:36: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: 12744905 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4F397E4 for ; Mon, 14 Feb 2022 05:37:42 +0000 (UTC) Received: by mail-yb1-f201.google.com with SMTP id b64-20020a256743000000b0061e169a5f19so31453970ybc.11 for ; Sun, 13 Feb 2022 21:37:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=VQ0fcrLFQa5SytEe7w/qOoQOsJ7lIVCuuogL1feOzv4=; b=jALbtnI4xhmtv743R1KcTnGNyCR/hveB1agW+EITuGYYJjN7VjULLeZUpg1jpOa+do KRXfiDuV651LoMpFUBBLV/zeK8X2XWUJ/ELowaltEMBWhIN7n4bPNHlzrXe+OkD1oWqP gxnoayl1wJdVDryxOF/6X366MTp57R+/sdu/hri/7v0/pNMNQANSN3weCfwaxvyX82nT esiQTwWunoufA1dWXVdQsue/AV3qEc1DcxLFzDu5Lf/kNmiYYpKKcTCh3wcMKeVSPCKf trUt8WyUNoT3bT4CPlw1ssBdYB7X34gQnrZ0YoGtOnQ56HWce0GRObKu4l8u2y2wRu1J YOEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=VQ0fcrLFQa5SytEe7w/qOoQOsJ7lIVCuuogL1feOzv4=; b=iqzSin9fO0cT/eo+r6KaMnkwzInJcTaElG8JmIRj8yGq3OVVJLU4T2y3ShjOkt/6xx +UxNjQGaffJePhpKHa1o+lphxXXkPLbbyDZyDztpgqvhu5HuhJBVjtES6ZDa2f4h/ZKP IXjPLLgPK26D6Zl1q0YGkGLWHNlJ3sQiJQ/gjt/MOKugLV4ATlbjpn454OzMe6utXMpP c6Na0nZtZR67GTrjFnpKA04Eu6/yEDGeZLjibSfC0FI/SWfwDVlgc6v7YfGakgnL4qkl P5+OtXBcSDpbYXg8W6idkLgA1yC2P7qeQkFS18L7g8ZaCIx9mMUcM5CGMKBcEsvxb0Ie pcCQ== X-Gm-Message-State: AOAM533SznhI5wFxkHtaji0HbEk4Ky4RMJOW2kXvxD/+JwqYFk3uzFQy rPtno8xNhag4woB3Kg7d3fw3hyCR6I4t X-Google-Smtp-Source: ABdhPJyOH81PjOmuwdU6s3uLtdosLovDzjzTPjpE/E0VxwmsccbFz1wTIadjdqBnfoDQauwB5X/1krvPmrru X-Received: from tzungbi-z840.tpe.corp.google.com ([2401:fa00:1:10:f315:f92d:e3d3:2539]) (user=tzungbi job=sendgmr) by 2002:a25:5185:: with SMTP id f127mr10214317ybb.396.1644817062104; Sun, 13 Feb 2022 21:37:42 -0800 (PST) Date: Mon, 14 Feb 2022 13:36:45 +0800 In-Reply-To: <20220214053646.3088298-1-tzungbi@google.com> Message-Id: <20220214053646.3088298-5-tzungbi@google.com> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20220214053646.3088298-1-tzungbi@google.com> X-Mailer: git-send-email 2.35.1.265.g69c8d7142f-goog Subject: [PATCH 4/5] platform/chrome: cros_kbd_led_backlight: support OF match From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org, robh+dt@kernel.org Cc: chrome-platform@lists.linux.dev, tzungbi@google.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Signed-off-by: Tzung-Bi Shih --- .../platform/chrome/cros_kbd_led_backlight.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/platform/chrome/cros_kbd_led_backlight.c b/drivers/platform/chrome/cros_kbd_led_backlight.c index 814f2b74c602..ba853e55d29a 100644 --- a/drivers/platform/chrome/cros_kbd_led_backlight.c +++ b/drivers/platform/chrome/cros_kbd_led_backlight.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -128,8 +129,11 @@ static int keyboard_led_probe(struct platform_device *pdev) int error; drvdata = acpi_device_get_match_data(&pdev->dev); - if (!drvdata) - return -EINVAL; + if (!drvdata) { + drvdata = of_device_get_match_data(&pdev->dev); + if (!drvdata) + return -EINVAL; + } if (drvdata->init) { error = drvdata->init(pdev); @@ -161,10 +165,19 @@ static const struct acpi_device_id keyboard_led_acpi_match[] = { }; MODULE_DEVICE_TABLE(acpi, keyboard_led_acpi_match); +static const struct of_device_id keyboard_led_of_match[] = { + { + .compatible = "google,cros-kbd-led-backlight", + }, + {} +}; +MODULE_DEVICE_TABLE(of, keyboard_led_of_match); + 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 Feb 14 05:36: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: 12744906 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE2BA7E4 for ; Mon, 14 Feb 2022 05:37:46 +0000 (UTC) Received: by mail-pj1-f74.google.com with SMTP id a15-20020a17090ad80f00b001b8a1e1da50so11344689pjv.6 for ; Sun, 13 Feb 2022 21:37:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=29uHVdHAQSqiT8vvfXqlsD57wZoWh7bXiS10RQ7W7Qg=; b=Pr0sIocwVERST9JG5yNYFzh4bfH0oj29aF92lMVCUeQOm5sHkFEyreYdobAZHbm+fl yoZIypGvnAv5RfDCLvM/pLGbDC4x0obhy9+lnxLPI5zUEzjeypIr9E28KbcI4AeFqjJu ZeWzJay7J/rvPFUygr8T5Jl+7ceUQ7RCI3sZJK1Vqi2yfFkBynrs9FPgUcW3KegJdiPg ESxlTYktuJa4Gwj08a7M7G61QWkd6KA6+UCFSEMm6Ox+k6MmkjO8CFPRxQ8xtb5ldNAr g6r6P4K5nvWlvrYrCJBurEVE4CIehOCiipVhujNJzPHQzoUwAUPSxafHl7bZMF/mcdX2 SLHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=29uHVdHAQSqiT8vvfXqlsD57wZoWh7bXiS10RQ7W7Qg=; b=s4doXSzJNSTjfZkXzm7zCT6hmDHvguf/mePXR22U8ArgE1dFUCJF7WN2VGuZ6odAKr tGsG+/up3Zkb8SRVDOIX61lVm6QOoRM9M/Ehx7xwO/TGhqujNqr2GVMe6cqHlFuO3hbx yA4l4lhXbiNJavhkCgilIpuYAhE8/ufaScQO+qr1LjOe4BtzrbY8JyTdJkNWch8PYECy EV+m8m2SFy9MGPykMcUpmxR9tF97NUoORgqo5KMt9LeySYHDKoH6HnhaLyCn/Rtp7ahn waftGFV+YIz7aBJS0OqZaMgYEgm1Rkn+IqGN6wKMFH0qSvGBM0iuEefb/aKzpp9Rsbb/ 1u9A== X-Gm-Message-State: AOAM53326GREFPB50wyS475mXXdpiwDb+yMF9kNAw1kmgjqupNsS4AKu HrDyMxw4f37/WYi61NIprXZbBoyWdOl/ X-Google-Smtp-Source: ABdhPJxKNKGdvDYl8ykS+dHO1ASu06EfmVMuaH4MZLhystWtVyLkcNMLBCQkNjLLUXLqBRdA9t3NMsHsmNHz X-Received: from tzungbi-z840.tpe.corp.google.com ([2401:fa00:1:10:f315:f92d:e3d3:2539]) (user=tzungbi job=sendgmr) by 2002:a62:ce06:: with SMTP id y6mr1345902pfg.85.1644817066460; Sun, 13 Feb 2022 21:37:46 -0800 (PST) Date: Mon, 14 Feb 2022 13:36:46 +0800 In-Reply-To: <20220214053646.3088298-1-tzungbi@google.com> Message-Id: <20220214053646.3088298-6-tzungbi@google.com> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20220214053646.3088298-1-tzungbi@google.com> X-Mailer: git-send-email 2.35.1.265.g69c8d7142f-goog Subject: [PATCH 5/5] platform/chrome: cros_kbd_led_backlight: support EC PWM backend From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org, robh+dt@kernel.org Cc: chrome-platform@lists.linux.dev, tzungbi@google.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org 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 --- 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..298a49550857 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 + tristate "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 ba853e55d29a..d655cf5bc960 100644 --- a/drivers/platform/chrome/cros_kbd_led_backlight.c +++ b/drivers/platform/chrome/cros_kbd_led_backlight.c @@ -11,9 +11,16 @@ #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. @@ -39,6 +46,8 @@ struct keyboard_led_drvdata { enum led_brightness max_brightness; }; +#define KEYBOARD_BACKLIGHT_MAX 100 + #if IS_ENABLED(CONFIG_CROS_KBD_LED_BACKLIGHT_ACPI) /* Keyboard LED ACPI Device must be defined in firmware */ @@ -46,8 +55,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) { @@ -106,7 +113,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 /* IS_ENABLED(CONFIG_CROS_KBD_LED_BACKLIGHT_ACPI) */ @@ -122,10 +129,97 @@ static const struct keyboard_led_drvdata keyboard_led_drvdata_acpi = { #endif /* IS_ENABLED(CONFIG_CROS_KBD_LED_BACKLIGHT_ACPI) */ +#if IS_ENABLED(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 /* IS_ENABLED(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 /* IS_ENABLED(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 = acpi_device_get_match_data(&pdev->dev); @@ -135,24 +229,25 @@ static int keyboard_led_probe(struct platform_device *pdev) 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; @@ -168,6 +263,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, }, {} };