chrome-platform.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Stephen Horvath <s.horvath@outlook.com.au>
To: Lee Jones <lee@kernel.org>, Benson Leung <bleung@chromium.org>,
	Guenter Roeck <groeck@chromium.org>,
	Tzung-Bi Shih <tzungbi@kernel.org>,
	chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org
Cc: Stephen Horvath <s.horvath@outlook.com.au>
Subject: [PATCH 1/2] platform/chrome: cros_kbd_led_backlight: Automatically enable keyboard backlight control if feature present in EC
Date: Fri, 22 Mar 2024 20:27:58 +1000	[thread overview]
Message-ID: <SY4P282MB306333469B31348E4A25A1A5C5312@SY4P282MB3063.AUSP282.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <20240322102800.1322022-1-s.horvath@outlook.com.au>

The keyboard backlight control is not enabled by default on all devices
with a Chromium EC, e.g. my Framework 13.
This patch adds a check for the feature and enables backlight control if
it is present.

I also fixed a bug that seemed like there was some confusion between
`cros_ec_dev` and `cros_ec_device`, so I'm not sure if this module even
worked until now.

Signed-off-by: Stephen Horvath <s.horvath@outlook.com.au>
---
 drivers/mfd/cros_ec_dev.c                     |  9 +++++++
 .../platform/chrome/cros_kbd_led_backlight.c  | 24 +++++++------------
 2 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/drivers/mfd/cros_ec_dev.c b/drivers/mfd/cros_ec_dev.c
index a52d59cc2b1e..29b85ed5fece 100644
--- a/drivers/mfd/cros_ec_dev.c
+++ b/drivers/mfd/cros_ec_dev.c
@@ -99,6 +99,10 @@ static const struct mfd_cell cros_ec_wdt_cells[] = {
 	{ .name = "cros-ec-wdt", }
 };
 
+static const struct mfd_cell cros_ec_pwm_kbd_cells[] = {
+	{ .name = "chromeos-keyboard-leds", }
+};
+
 static const struct cros_feature_to_cells cros_subdevices[] = {
 	{
 		.id		= EC_FEATURE_CEC,
@@ -125,6 +129,11 @@ static const struct cros_feature_to_cells cros_subdevices[] = {
 		.mfd_cells	= cros_ec_wdt_cells,
 		.num_cells	= ARRAY_SIZE(cros_ec_wdt_cells),
 	},
+	{
+		.id		= EC_FEATURE_PWM_KEYB,
+		.mfd_cells	= cros_ec_pwm_kbd_cells,
+		.num_cells	= ARRAY_SIZE(cros_ec_pwm_kbd_cells),
+	},
 };
 
 static const struct mfd_cell cros_ec_platform_cells[] = {
diff --git a/drivers/platform/chrome/cros_kbd_led_backlight.c b/drivers/platform/chrome/cros_kbd_led_backlight.c
index 793fd3f1015d..06e9a57536af 100644
--- a/drivers/platform/chrome/cros_kbd_led_backlight.c
+++ b/drivers/platform/chrome/cros_kbd_led_backlight.c
@@ -171,12 +171,15 @@ static int keyboard_led_init_ec_pwm(struct platform_device *pdev)
 {
 	struct keyboard_led *keyboard_led = platform_get_drvdata(pdev);
 
-	keyboard_led->ec = dev_get_drvdata(pdev->dev.parent);
-	if (!keyboard_led->ec) {
+	struct cros_ec_dev *parent_ec = dev_get_drvdata(pdev->dev.parent);
+
+	if (!parent_ec) {
 		dev_err(&pdev->dev, "no parent EC device\n");
 		return -EINVAL;
 	}
 
+	keyboard_led->ec = parent_ec->ec_dev;
+
 	return 0;
 }
 
@@ -200,8 +203,10 @@ static int keyboard_led_probe(struct platform_device *pdev)
 	int error;
 
 	drvdata = device_get_match_data(&pdev->dev);
-	if (!drvdata)
-		return -EINVAL;
+	if (!drvdata) {
+		/* Assume EC if no match data is provided */
+		drvdata = &keyboard_led_drvdata_ec_pwm;
+	}
 
 	keyboard_led = devm_kzalloc(&pdev->dev, sizeof(*keyboard_led), GFP_KERNEL);
 	if (!keyboard_led)
@@ -236,22 +241,10 @@ 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",
-		.data = &keyboard_led_drvdata_ec_pwm,
-	},
-	{}
-};
-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,
 };
-- 
2.43.0


       reply	other threads:[~2024-03-22 10:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20240322102800.1322022-1-s.horvath@outlook.com.au>
2024-03-22 10:27 ` Stephen Horvath [this message]
2024-03-25  3:24   ` [PATCH 1/2] platform/chrome: cros_kbd_led_backlight: Automatically enable keyboard backlight control if feature present in EC Tzung-Bi Shih
2024-03-25  4:27     ` Stephen Horvath
2024-03-22 10:27 ` [PATCH 2/2] platform/chrome: cros_kbd_led_backlight: Remove obsolete commands (EC_CMD_PWM_*_KEYBOARD_BACKLIGHT) Stephen Horvath
2024-03-25 18:45   ` Brian Norris
2024-03-26  0:30     ` Stephen Horvath
2024-03-26  0:39       ` Brian Norris

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=SY4P282MB306333469B31348E4A25A1A5C5312@SY4P282MB3063.AUSP282.PROD.OUTLOOK.COM \
    --to=s.horvath@outlook.com.au \
    --cc=bleung@chromium.org \
    --cc=chrome-platform@lists.linux.dev \
    --cc=groeck@chromium.org \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tzungbi@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).