pmaports/device/testing/linux-samsung-kminilte/0002-drivers-leds-flashlight-add-support-for-setting-mode.patch
Niklas Cathor 5acf41a60e
linux-samsung-kminilte: add flashlight support (MR 1150)
These changes enable the flashlight LED driver (fled_rt5033), and add
support for switching the light on and off from userspace.

In more detail:

* CONFIG_FLED_RT5033 enables the flashlight driver
* CONFIG_VIDEO_EXYNOS_FIMC_IS is required for the flashlight driver to
  compile (there seems to be a lot of cross-dependency between the two
  drivers)
* patch 0001 fixes the use of usleep (which no longer exists), to make
  the kernel compile with those settings

With these changes, /sys/class/flashlight/rt-flash-led shows up in
sysfs, but it's only possible to control the brightness of the LED,
not to switch it on.

Patch 0002 is what actually makes the flashlight usable: it makes
the /sys/class/flashlight/rt-flash-led/mode file writable.

Writing "Torch" there enables the flashlight, writing "Off" disables
it again. "Mixed" mode works like "Torch" as well. I have not figured
out yet how to trigger the camera flash, so setting the mode to
"Flash" is possible, albeit pointless.
2020-04-13 19:08:19 +03:00

68 lines
2.4 KiB
Diff

From d6a4ef0853770f70b7930a2b4cb63cc3219c05a9 Mon Sep 17 00:00:00 2001
From: Niklas Cathor <niklas.cathor@gmx.de>
Date: Sun, 12 Apr 2020 16:01:13 +0200
Subject: [PATCH 2/2] drivers/leds/flashlight: add support for setting mode via
sysfs
The mode can be set by writing one of these strings:
- "Off"
- "Torch"
- "Flash"
- "Mixed"
to /sys/class/flashlight/<device>/mode.
---
drivers/leds/flashlight.c | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/drivers/leds/flashlight.c b/drivers/leds/flashlight.c
index f8fbfb84ca1..5f3510b4aee 100644
--- a/drivers/leds/flashlight.c
+++ b/drivers/leds/flashlight.c
@@ -56,6 +56,35 @@ static ssize_t flashlight_show_mode(struct device *dev,
flashlight_mode_string[flashlight_dev->props.mode]);
}
+static ssize_t flashlight_store_mode(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t count)
+{
+ int mode;
+ int n = buf[count - 1] == '\n' ? count - 1 : count;
+ struct flashlight_device *flashlight_dev = to_flashlight_device(dev);
+
+ if (!strncmp(buf, flashlight_mode_string[FLASHLIGHT_MODE_OFF], n)) {
+ mode = FLASHLIGHT_MODE_OFF;
+ } else if (!strncmp(buf, flashlight_mode_string[FLASHLIGHT_MODE_TORCH], n)) {
+ mode = FLASHLIGHT_MODE_TORCH;
+ } else if (!strncmp(buf, flashlight_mode_string[FLASHLIGHT_MODE_FLASH], n)) {
+ mode = FLASHLIGHT_MODE_FLASH;
+ } else if (!strncmp(buf, flashlight_mode_string[FLASHLIGHT_MODE_MIXED], n)) {
+ mode = FLASHLIGHT_MODE_MIXED;
+ } else {
+ pr_err("%s: invalid mode for flashlight.\n", __func__);
+ return -1;
+ }
+ if (flashlight_set_mode(flashlight_dev, mode) != 0) {
+ pr_err("%s: failed to set flashlight mode\n", __func__);
+ return -1;
+ }
+
+ pr_info("%s: set flashlight mode: %s\n",
+ __func__, flashlight_mode_string[mode]);
+ return count;
+}
+
static ssize_t flashlight_show_torch_max_brightness(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -229,7 +258,7 @@ static void flashlight_device_release(struct device *dev)
static struct device_attribute flashlight_device_attributes[] = {
__ATTR(name, 0444, flashlight_show_name, NULL),
__ATTR(type, 0444, flashlight_show_type, NULL),
- __ATTR(mode, 0444, flashlight_show_mode, NULL),
+ __ATTR(mode, 0644, flashlight_show_mode, flashlight_store_mode),
__ATTR(torch_max_brightness, 0444,
flashlight_show_torch_max_brightness, NULL),
__ATTR(strobe_max_brightness, 0444,
--
2.20.1