Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp803389lqh; Sun, 5 May 2024 02:43:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWgecoh3AFjMjsQO4mRZqZHHBswGX0dFP5fmJerKMDtbPOq5BTbcOvQyiWmRaAsXjKUuKlzpCYJVY9uEFUqY7HHbhz9E6BjohwM9b22Qw== X-Google-Smtp-Source: AGHT+IFFMLW+1Dpp895hWDzSgtwdHihdr8mVP++8Dbt1dma97BM0wUZJlk9IT77VbaQKiNS6pIcM X-Received: by 2002:a05:620a:2703:b0:790:686f:f683 with SMTP id b3-20020a05620a270300b00790686ff683mr9984085qkp.58.1714902234260; Sun, 05 May 2024 02:43:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714902234; cv=pass; d=google.com; s=arc-20160816; b=H0KkOaqoG/YMtjn/nC9QyoXbnUjrr1RVJeJ2Hevf+LFEHXYcFDfEkgHOuMM89HuLkg k/G5k5CLh8gROnSMPSus1kppzCt8HwDcGnmmOqK9D7k8qyrF/0aGdkBRgr1mLEHh+1SZ UxorcdQ3/kF8kwE6A8CWX12MVCa+YUKSIHKURENjrExw6wdSrvLjIVvxaK1ddB66G7lu 7XSrpBdT/848h1siQDh5TCQPKDiA3hnyjfT79LRkhdQBt+iKhNdvgus0j/KSusOB9+wO y4t2ZyVrp+ALniFSWGC0fMMXKyuAAlRLg623ZHDHsLsYP4Hzzw7mA0TdTMzGwUV8F5C+ rIWw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:message-id:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:subject:date :from:dkim-signature; bh=29SIiz8XNPsH6TRjUyFAQ8DdIpGKr/zbAMKrlLsqShM=; fh=vAGlr30tiBxGPEhMMptB4MccNgOqlXs4d+HZRjv78hI=; b=bLpL85MpEo5E9rIPV/KhA9tjGoB3BQV8an/qvsI5BYCK4Y3aKaXe+8CjXbROWkbbo5 bvIeQuafcWk2b7i7GJ6Q6s3+Yc81N3OeF12RRlYZbdNUzfvub+0e/ZPdK/J3fp1E9n/T FibA1I5ZnvpSMhFRfxXSdi0PWOfbkDj0tdq/VSNq94NmYNbG3WlMIfpC7ZVKlpa/jfyN kRkCFcaaJSNOQFQQnn222iJyJufBRyiZ0YH3N9r/dTmYrJaoyhNjRcD9eJsmF7io3M/3 tTJ9j+ABEQ3ii5NTgSv5kXMZ6chiEllYDXH+0md13nVNyXcW7VHlWmlzrWmlgsCDUw30 ACMg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=Ov8EUCRI; arc=pass (i=1 spf=pass spfdomain=weissschuh.net dkim=pass dkdomain=weissschuh.net); spf=pass (google.com: domain of linux-kernel+bounces-168935-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168935-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id dv15-20020a05620a1b8f00b007928c802725si2569547qkb.409.2024.05.05.02.43.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 May 2024 02:43:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-168935-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=Ov8EUCRI; arc=pass (i=1 spf=pass spfdomain=weissschuh.net dkim=pass dkdomain=weissschuh.net); spf=pass (google.com: domain of linux-kernel+bounces-168935-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168935-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 041341C20C25 for ; Sun, 5 May 2024 09:43:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 003A479D8; Sun, 5 May 2024 09:43:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="Ov8EUCRI" Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (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 2B512747F for ; Sun, 5 May 2024 09:43:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714902226; cv=none; b=YxDbfOlv4W38gwNYpnMqdNeSGU4oD053jzg/18OmXsdynk46u1tpYpdyKjk1eSE+5MhQ0bwsqclm7Px/kmsuq8HSiyADt+yTbi6xZtUjiEH8N1wXvs2Tsz5GzePPVpG/53fIEX4HjV5wqdO3OT7gOmejRpTcsaFosZjVbXGOW/A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714902226; c=relaxed/simple; bh=69zuOGDVoiA8YolUWTMHMK/ue23v46ozm7Zzhb88fmY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=ocdeA9eH1wQn4KOLPd+hc86bC3vmsKw0LzKcrsVwY5y/YN/8SjR0JBy2VY4cP7sRE+c88ItLuS8wnNILUx075vL7ZBuBT5LK4mK6djFEHxd77yD+gpkx41jRFemtqAKX9Bhg82z8kqXsigtthJeLMEsxg4e/gIkZUiyOC98mxYE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=Ov8EUCRI; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1714902214; bh=69zuOGDVoiA8YolUWTMHMK/ue23v46ozm7Zzhb88fmY=; h=From:Date:Subject:To:Cc:From; b=Ov8EUCRIUEwsCYlWlwhRXyRpDsev8MnJ/KWJl7xN4ZmK2DpjFdYKJzrUjAyXqTW4c f4V9/xaX400fApwybWtB079lEZhSem/amg2SgY2X7m6Q13NrkcfVC3VaXK9qMnOPok Aqy90ivgKlk7d5Bza5EdVkmMjSFfk4edev0aMxuk= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sun, 05 May 2024 11:41:13 +0200 Subject: [PATCH] platform/chrome: cros_kbd_led_backlight: enable probing through EC_FEATURE_PWM_KEYB Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20240505-cros_ec-kbd-led-framework-v1-1-bfcca69013d2@weissschuh.net> X-B4-Tracking: v=1; b=H4sIADhUN2YC/x3MWwqDMBBG4a3IPHcgphWrWyml6OS3HbxEJlAFc e8NffwezjkowRSJ2uIgw1eTxiWjvBQkn255gzVkk3f+5ipXsVhMLwiPfeAJgQfrZmzRRq7hcb+ WvdSNUO5Xw6D7//14nucPDPQ5wWsAAAA= To: Lee Jones , Benson Leung , Guenter Roeck , Tzung-Bi Shih Cc: chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org, Dustin Howett , Mario Limonciello , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1714902214; l=4055; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=69zuOGDVoiA8YolUWTMHMK/ue23v46ozm7Zzhb88fmY=; b=aOJ2dfaKSQlwO0RyMYkOmQsSBkyJsuBdOIG6zUFNlS7rYBQ3L4lz/G0pbGrmTgMHrFXv3B0cZ L4dNXdcWQM5D0iLxJdpEYkkho8vbx0+Bx1ZTYc7bQ7oALLiiYrwikkr X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The ChromeOS EC used in Framework laptops supports the standard cros keyboard backlight protocol. However the firmware on these laptops don't implement the ACPI ID GOOG0002 that is recognized by cros_kbd_led_backlight and they also don't use device tree. Extend the cros_ec MFD device to also load cros_kbd_led_backlight when the EC reports EC_FEATURE_PWM_KEYB. Tested on a Framework 13 AMD, Bios 3.05. Signed-off-by: Thomas Weißschuh --- This is based on https://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux.git for-next The helper keyboard_led_is_mfd_device is a bit iffy, but I couldn't find a nicer way. * driver_data from platform_device_id is overwritten by the mfd platform data * Setting the driver_data in drivers/mfd/cros_ec_dev.c would expose the internals of cros_kbd_led_backlight --- drivers/mfd/cros_ec_dev.c | 9 ++++++ drivers/platform/chrome/cros_kbd_led_backlight.c | 41 +++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/drivers/mfd/cros_ec_dev.c b/drivers/mfd/cros_ec_dev.c index a52d59cc2b1e..4444b361aeae 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_keyboard_leds_cells[] = { + { .name = "cros-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_keyboard_leds_cells, + .num_cells = ARRAY_SIZE(cros_ec_keyboard_leds_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 b83e4f328620..88dd3848e5da 100644 --- a/drivers/platform/chrome/cros_kbd_led_backlight.c +++ b/drivers/platform/chrome/cros_kbd_led_backlight.c @@ -194,13 +194,52 @@ static const __maybe_unused struct keyboard_led_drvdata keyboard_led_drvdata_ec_ #endif /* IS_ENABLED(CONFIG_CROS_EC) */ +#if IS_ENABLED(CONFIG_MFD_CROS_EC_DEV) +static int keyboard_led_init_ec_pwm_mfd(struct platform_device *pdev) +{ + struct cros_ec_dev *ec_dev = dev_get_drvdata(pdev->dev.parent); + struct cros_ec_device *cros_ec = ec_dev->ec_dev; + struct keyboard_led *keyboard_led = platform_get_drvdata(pdev); + + keyboard_led->ec = cros_ec; + + return 0; +} + +static const struct keyboard_led_drvdata keyboard_led_drvdata_ec_pwm_mfd = { + .init = keyboard_led_init_ec_pwm_mfd, + .brightness_set_blocking = keyboard_led_set_brightness_ec_pwm, + .brightness_get = keyboard_led_get_brightness_ec_pwm, + .max_brightness = KEYBOARD_BACKLIGHT_MAX, +}; + +#else /* IS_ENABLED(CONFIG_MFD_CROS_EC_DEV) */ + +static const struct keyboard_led_drvdata keyboard_led_drvdata_ec_pwm = {}; + +#endif /* IS_ENABLED(CONFIG_MFD_CROS_EC_DEV) */ + +static int keyboard_led_is_mfd_device(struct platform_device *pdev) +{ + if (!IS_ENABLED(CONFIG_MFD_CROS_EC_DEV)) + return 0; + + if (!pdev->dev.parent) + return 0; + + return strcmp(pdev->dev.parent->driver->name, "cros-ec-dev") == 0; +} + static int keyboard_led_probe(struct platform_device *pdev) { const struct keyboard_led_drvdata *drvdata; struct keyboard_led *keyboard_led; int error; - drvdata = device_get_match_data(&pdev->dev); + if (keyboard_led_is_mfd_device(pdev)) + drvdata = &keyboard_led_drvdata_ec_pwm_mfd; + else + drvdata = device_get_match_data(&pdev->dev); if (!drvdata) return -EINVAL; --- base-commit: 2fbe479c0024e1c6b992184a799055e19932aa48 change-id: 20240505-cros_ec-kbd-led-framework-7e2e831bc79c Best regards, -- Thomas Weißschuh