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.
This commit is contained in:
Niklas Cathor 2020-04-12 20:46:22 +02:00 committed by Alexey Min
parent ef7f4514a7
commit 5acf41a60e
No known key found for this signature in database
GPG key ID: 0B19D2A65870B448
4 changed files with 123 additions and 6 deletions

View file

@ -0,0 +1,26 @@
From 847af15f6683de0f131924555eb2ca1ac05527ac Mon Sep 17 00:00:00 2001
From: Niklas Cathor <niklas.cathor@gmx.de>
Date: Sun, 12 Apr 2020 15:56:54 +0200
Subject: [PATCH 1/2] drivers/leds/rt5033_fled: fix use of 'usleep'
Symbol seems to be deprecated, and replaced by usleep_range
---
drivers/leds/rt5033_fled.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/leds/rt5033_fled.c b/drivers/leds/rt5033_fled.c
index da0d2fc6be8..97e76c5acde 100644
--- a/drivers/leds/rt5033_fled.c
+++ b/drivers/leds/rt5033_fled.c
@@ -531,7 +531,7 @@ int32_t rt5033_charger_notification(struct rt_fled_info *fled_info,
* we will check torch had already been on or not
*/
if (mode == FLASHLIGHT_MODE_TORCH || mode == FLASHLIGHT_MODE_MIXED) {
- usleep(2500);
+ usleep_range(2500, 2500);
rt5033_clr_bits(info->i2c_client, 0x1a, 0x80);
}
}
--
2.20.1

View file

@ -0,0 +1,68 @@
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

View file

@ -2,7 +2,7 @@
pkgname="linux-samsung-kminilte"
pkgver=3.4.113
pkgrel=4
pkgrel=5
pkgdesc="Samsung Galaxy S5 Mini kernel fork"
arch="armv7"
_carch="arm"
@ -29,7 +29,9 @@ source="
$pkgname-$_commit.tar.gz::https://github.com/cm-3470/$_repository/archive/$_commit.tar.gz
$_config
compiler-gcc6.h
"
0001-drivers-leds-rt5033_fled-fix-use-of-usleep.patch
0002-drivers-leds-flashlight-add-support-for-setting-mode.patch
"
builddir="$srcdir/$_repository-$_commit"
prepare() {
@ -48,5 +50,7 @@ package() {
}
sha512sums="351b043822d9fc25a002f07a490422341fd03671d661bb949085ef8d69042f1ae528f80ade7076aba3eaffec80f65c09fdbb600ffe04063c69d876c22a53709b linux-samsung-kminilte-7a8c010f226189116dcf2301d338555ae0d270c3.tar.gz
0279b76e569da5042178c78b1781ce85ef65f60ef402655953996ca737cbc2a2b2bea44ac290540ab7fcf70c11434bf375f18dec21d2d84a050d0c7d6373496f config-samsung-kminilte.armv7
d80980e9474c82ba0ef1a6903b434d8bd1b092c40367ba543e72d2c119301c8b2d05265740e4104ca1ac5d15f6c4aa49e8776cb44264a9a28dc551e0d1850dcc compiler-gcc6.h"
f48cb3b5952f489758d01ec91ce7c3a8d67093be1fb9afebee6b519dd3d05b076fb0e299378323347e3e86cd138fe9e798378c96159acf4a97d7a6da9df2ca5b config-samsung-kminilte.armv7
d80980e9474c82ba0ef1a6903b434d8bd1b092c40367ba543e72d2c119301c8b2d05265740e4104ca1ac5d15f6c4aa49e8776cb44264a9a28dc551e0d1850dcc compiler-gcc6.h
873e4ff64521f685b7948e7a55aba4a95e3c0086b54c8e1440f67630c49a6b17b10c71837ba44d0bdb9afb05ff3ee8c0c890f0053fb79cd733aa76aed53579c2 0001-drivers-leds-rt5033_fled-fix-use-of-usleep.patch
fb30ea67620fc0dae62943b512662e0f3a49b7509d5f3cddda4c1552fe365535ac414f4ae960356f18228ce49d5c362c512cec7a9b671ffe96408f91b1b9fdee 0002-drivers-leds-flashlight-add-support-for-setting-mode.patch"

View file

@ -2244,6 +2244,7 @@ CONFIG_VIDEO_S5P_FIMC=y
# CONFIG_VIDEO_EXYNOS4_FIMC_IS is not set
# CONFIG_VIDEO_SAMSUNG_S5P_TV is not set
CONFIG_VIDEO_EXYNOS=y
CONFIG_EXYNOS_MEDIA_DEVICE=y
# CONFIG_VIDEO_EXYNOS_FIMC_LITE is not set
# CONFIG_VIDEO_EXYNOS_GSCALER is not set
CONFIG_VIDEO_EXYNOS_JPEG=y
@ -2258,9 +2259,25 @@ CONFIG_EXYNOS_MFC_V5=y
#
# CONFIG_VIDEO_EXYNOS_TV is not set
# CONFIG_VIDEO_EXYNOS_ROTATOR is not set
# CONFIG_VIDEO_EXYNOS_FIMC_IS is not set
CONFIG_VIDEO_EXYNOS_FIMC_IS=y
# CONFIG_CAMERA_EEPROM_SUPPORT is not set
CONFIG_USE_VENDER_FEATURE=y
# CONFIG_CAMERA_SENSOR_8B1_OBJ is not set
# CONFIG_CAMERA_SENSOR_6B2_OBJ is not set
# CONFIG_CAMERA_SENSOR_6A3_OBJ is not set
# CONFIG_CAMERA_SENSOR_IMX135_OBJ is not set
# CONFIG_CAMERA_SENSOR_3L2_OBJ is not set
# CONFIG_CAMERA_SENSOR_2P2_OBJ is not set
# CONFIG_CAMERA_SENSOR_2P2_12M_OBJ is not set
# CONFIG_CAMERA_SENSOR_3H5_OBJ is not set
# CONFIG_CAMERA_SENSOR_3H7_OBJ is not set
# CONFIG_CAMERA_SENSOR_3H7_SUNNY_OBJ is not set
# CONFIG_CAMERA_SENSOR_4E5_OBJ is not set
# CONFIG_CAMERA_SENSOR_IMX175_OBJ is not set
# CONFIG_CAMERA_SENSOR_4H5_OBJ is not set
# CONFIG_CAMERA_SENSOR_SR261_OBJ is not set
# CONFIG_VIDEO_EXYNOS5_FIMC_IS_SENSOR is not set
CONFIG_MEDIA_EXYNOS=y
# CONFIG_V4L_MEM2MEM_DRIVERS is not set
CONFIG_RADIO_ADAPTERS=y
# CONFIG_RADIO_SI470X is not set
@ -2812,7 +2829,9 @@ CONFIG_LEDS_KTD2026=y
# CONFIG_LEDS_TRIGGERS is not set
CONFIG_FLASHLIGHT=y
CONFIG_RT_FLASH_LED=y
# CONFIG_FLED_RT5033 is not set
CONFIG_FLED_RT5033=y
CONFIG_FLED_RT5033_I2C=y
# CONFIG_FLED_RT5033_EXT_GPIO is not set
#
# LED Triggers