Skip to content

Commit

Permalink
leds: steamdeck: Add support for Steam Deck LED
Browse files Browse the repository at this point in the history
(cherry picked from commit 85a86d19aa7022ff0555023d53aef78323a42d0c)
Signed-off-by: Cristian Ciocaltea <[email protected]>
Signed-off-by: Alexandre Frade <[email protected]>
  • Loading branch information
ndreys authored and xanmod committed Sep 16, 2024
1 parent 30b84b2 commit 1baead0
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
7 changes: 7 additions & 0 deletions drivers/leds/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,13 @@ config LEDS_ACER_A500
This option enables support for the Power Button LED of
Acer Iconia Tab A500.

config LEDS_STEAMDECK
tristate "LED support for Steam Deck"
depends on LEDS_CLASS && MFD_STEAMDECK
help
This option enabled support for the status LED (next to the
power button) on Steam Deck

source "drivers/leds/blink/Kconfig"

comment "Flash and Torch LED drivers"
Expand Down
1 change: 1 addition & 0 deletions drivers/leds/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ obj-$(CONFIG_LEDS_POWERNV) += leds-powernv.o
obj-$(CONFIG_LEDS_PWM) += leds-pwm.o
obj-$(CONFIG_LEDS_REGULATOR) += leds-regulator.o
obj-$(CONFIG_LEDS_SC27XX_BLTC) += leds-sc27xx-bltc.o
obj-$(CONFIG_LEDS_STEAMDECK) += leds-steamdeck.o
obj-$(CONFIG_LEDS_SUN50I_A100) += leds-sun50i-a100.o
obj-$(CONFIG_LEDS_SUNFIRE) += leds-sunfire.o
obj-$(CONFIG_LEDS_SYSCON) += leds-syscon.o
Expand Down
74 changes: 74 additions & 0 deletions drivers/leds/leds-steamdeck.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// SPDX-License-Identifier: GPL-2.0+

/*
* Steam Deck EC MFD LED cell driver
*
* Copyright (C) 2021-2022 Valve Corporation
*
*/

#include <linux/acpi.h>
#include <linux/leds.h>
#include <linux/platform_device.h>

struct steamdeck_led {
struct acpi_device *adev;
struct led_classdev cdev;
};

static int steamdeck_leds_brightness_set(struct led_classdev *cdev,
enum led_brightness value)
{
struct steamdeck_led *sd = container_of(cdev, struct steamdeck_led,
cdev);

if (ACPI_FAILURE(acpi_execute_simple_method(sd->adev->handle,
"CHBV", value)))
return -EIO;

return 0;
}

static int steamdeck_leds_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct steamdeck_led *sd;
int ret;

sd = devm_kzalloc(dev, sizeof(*sd), GFP_KERNEL);
if (!sd)
return -ENOMEM;

sd->adev = ACPI_COMPANION(dev->parent);

sd->cdev.name = "status:white";
sd->cdev.brightness_set_blocking = steamdeck_leds_brightness_set;
sd->cdev.max_brightness = 100;

ret = devm_led_classdev_register(dev, &sd->cdev);
if (ret) {
dev_err(dev, "Failed to register LEDs device: %d\n", ret);
return ret;
}

return 0;
}

static const struct platform_device_id steamdeck_leds_id_table[] = {
{ .name = "steamdeck-leds" },
{}
};
MODULE_DEVICE_TABLE(platform, steamdeck_leds_id_table);

static struct platform_driver steamdeck_leds_driver = {
.probe = steamdeck_leds_probe,
.driver = {
.name = "steamdeck-leds",
},
.id_table = steamdeck_leds_id_table,
};
module_platform_driver(steamdeck_leds_driver);

MODULE_AUTHOR("Andrey Smirnov <[email protected]>");
MODULE_DESCRIPTION("Steam Deck LEDs driver");
MODULE_LICENSE("GPL");

0 comments on commit 1baead0

Please sign in to comment.