led: Add flash LED type
Camera flashes are also exported via the LED subsystem. We use a separate LED type so they're not picked by default. We don't use them as fallbacks either.
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The Phosh Developers
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0+
|
||||
* Author: Guido Günther <agx@sigxcpu.org>
|
||||
*
|
||||
* See Documentation/ABI/testing/sysfs-class-led-trigger-pattern
|
||||
*/
|
||||
|
||||
#define G_LOG_DOMAIN "fbd-dev-led-flash"
|
||||
|
||||
#include "fbd-dev-led-priv.h"
|
||||
#include "fbd-dev-led-flash.h"
|
||||
#include "fbd-enums.h"
|
||||
#include "fbd-udev.h"
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
/**
|
||||
* fbd-dev-led-flash:
|
||||
*
|
||||
* The LED of a camera flash
|
||||
*/
|
||||
typedef struct _FbdDevLedFlash {
|
||||
FbdDevLed parent;
|
||||
} FbdDevLedFlash;
|
||||
|
||||
|
||||
G_DEFINE_TYPE (FbdDevLedFlash, fbd_dev_led_flash, FBD_TYPE_DEV_LED)
|
||||
|
||||
|
||||
static gboolean
|
||||
fbd_dev_led_flash_probe (FbdDevLed *led, GError **error)
|
||||
{
|
||||
GUdevDevice *dev = fbd_dev_led_get_device (led);
|
||||
const gchar *name, *path;
|
||||
guint max_brightness;
|
||||
|
||||
name = g_udev_device_get_name (dev);
|
||||
if (!g_udev_device_get_sysfs_attr (dev, "flash_strobe") ||
|
||||
!g_udev_device_get_sysfs_attr (dev, "flash_brightness")) {
|
||||
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "%s is no flash LED", name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
max_brightness = g_udev_device_get_sysfs_attr_as_int (dev, LED_MAX_BRIGHTNESS_ATTR);
|
||||
if (!max_brightness) {
|
||||
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "%s has no max_brightness", name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fbd_dev_led_set_max_brightness (led, max_brightness);
|
||||
fbd_dev_led_set_supported_color (led, FBD_FEEDBACK_LED_COLOR_FLASH);
|
||||
|
||||
path = g_udev_device_get_sysfs_path (dev);
|
||||
g_debug ("LED at '%s' usable as flash", path);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
fbd_dev_led_flash_class_init (FbdDevLedFlashClass *klass)
|
||||
{
|
||||
FbdDevLedClass *fbd_dev_led_class = FBD_DEV_LED_CLASS (klass);
|
||||
|
||||
fbd_dev_led_class->probe = fbd_dev_led_flash_probe;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
fbd_dev_led_flash_init (FbdDevLedFlash *self)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FbdDevLed *
|
||||
fbd_dev_led_flash_new (GUdevDevice *dev, GError **err)
|
||||
{
|
||||
return g_initable_new (FBD_TYPE_DEV_LED_FLASH, NULL, err, "dev", dev, NULL);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The Phosh Developers
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0+
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "fbd-dev-led.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define FBD_TYPE_DEV_LED_FLASH fbd_dev_led_flash_get_type()
|
||||
|
||||
G_DECLARE_FINAL_TYPE (FbdDevLedFlash, fbd_dev_led_flash, FBD, DEV_LED_FLASH, FbdDevLed)
|
||||
|
||||
FbdDevLed *fbd_dev_led_flash_new (GUdevDevice *dev, GError **err);
|
||||
|
||||
G_END_DECLS
|
||||
+9
-2
@@ -53,8 +53,15 @@ find_led_by_color (FbdDevLeds *self, FbdFeedbackLedColor color)
|
||||
return led;
|
||||
}
|
||||
|
||||
/* If we did not match a color pick the first */
|
||||
return self->leds->data;
|
||||
/* If we did not match a color pick the first non flash LED */
|
||||
for (GSList *l = self->leds; l != NULL; l = l->next) {
|
||||
FbdDevLed *led = FBD_DEV_LED (l->data);
|
||||
|
||||
if (!fbd_dev_led_supports_color (led, FBD_FEEDBACK_LED_COLOR_FLASH))
|
||||
return led;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ G_BEGIN_DECLS
|
||||
* @FBD_FEEDBACK_LED_COLOR_GREEN: A green LED
|
||||
* @FBD_FEEDBACK_LED_COLOR_BLUE: A blue LED
|
||||
* @FBD_FEEDBACK_LED_COLOR_RGB: A multicolor LED that can display arbitrary RGB values
|
||||
* @FBD_FEEDBACK_LED_COLOR_FLASH: A flash (usually white)
|
||||
*
|
||||
* The color of a hardware LED.
|
||||
*/
|
||||
@@ -25,6 +26,8 @@ typedef enum _FbdFeedbackLedColor {
|
||||
FBD_FEEDBACK_LED_COLOR_GREEN = 2,
|
||||
FBD_FEEDBACK_LED_COLOR_BLUE = 3,
|
||||
FBD_FEEDBACK_LED_COLOR_RGB = 4,
|
||||
/* Keep this last in the list */
|
||||
FBD_FEEDBACK_LED_COLOR_FLASH = 5,
|
||||
} FbdFeedbackLedColor;
|
||||
|
||||
typedef struct {
|
||||
|
||||
@@ -16,6 +16,7 @@ sources = [
|
||||
'fbd-dev-vibra.c',
|
||||
'fbd-dev-sound.c',
|
||||
'fbd-dev-led.c',
|
||||
'fbd-dev-led-flash.c',
|
||||
'fbd-dev-led-multicolor.c',
|
||||
'fbd-dev-led-qcom.c',
|
||||
'fbd-dev-led-qcom-multicolor.c',
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
P: /devices/platform/soc@0/c440000.spmi/spmi-0/0-03/c440000.spmi:pmic@3:led-controller@d300/leds/white:flash
|
||||
E: FEEDBACKD_TYPE=led
|
||||
E: CURRENT_TAGS=:seat:
|
||||
E: ID_FOR_SEAT=leds-platform-c440000_spmi-platform-c440000_spmi_pmic_3_led-controller_d300
|
||||
E: ID_PATH=platform-c440000.spmi-platform-c440000.spmi:pmic@3:led-controller@d300
|
||||
E: ID_PATH_TAG=platform-c440000_spmi-platform-c440000_spmi_pmic_3_led-controller_d300
|
||||
E: OF_COMPATIBLE_N=0
|
||||
E: OF_FULLNAME=/soc@0/spmi@c440000/pmic@3/led-controller@d300/led-0
|
||||
E: OF_NAME=led-0
|
||||
E: SUBSYSTEM=leds
|
||||
E: TAGS=:seat:
|
||||
A: brightness=0\n
|
||||
L: device=../../../c440000.spmi:pmic@3:led-controller@d300
|
||||
A: flash_brightness=12500\n
|
||||
A: flash_fault=flash-timeout-exceeded \n
|
||||
A: flash_strobe=1\n
|
||||
A: flash_timeout=10000\n
|
||||
A: max_brightness=255\n
|
||||
A: max_flash_brightness=1500000\n
|
||||
A: max_flash_timeout=1280000\n
|
||||
A: pattern=
|
||||
A: power/control=auto\n
|
||||
A: power/runtime_active_time=0\n
|
||||
A: power/runtime_status=unsupported\n
|
||||
A: power/runtime_suspended_time=0\n
|
||||
A: repeat=-1\n
|
||||
A: trigger=none usb-gadget usb-host kbd-scrolllock kbd-numlock kbd-capslock kbd-kanalock kbd-shiftlock kbd-altgrlock kbd-ctrllock kbd-altlock kbd-shiftllock kbd-shiftrlock kbd-ctrlllock kbd-ctrlrlock usbport timer oneshot heartbeat backlight cpu cpu0 cpu1 cpu2 cpu3 cpu4 cpu5 cpu6 cpu7 activity default-on transient flash torch panic netdev [pattern] audio-mute audio-micmute rfkill-any rfkill-none bq27411-0-charging-or-full bq27411-0-charging bq27411-0-full bq27411-0-charging-blink-full-solid pmi8998-charger-online bluetooth-power hci0-power rfkill0 phy0rx phy0tx phy0assoc phy0radio rfkill1\n
|
||||
|
||||
P: /devices/platform/soc@0/c440000.spmi/spmi-0/0-03/c440000.spmi:pmic@3:led-controller@d300
|
||||
E: DRIVER=leds-qcom-flash
|
||||
E: ID_PATH=platform-c440000.spmi-platform-c440000.spmi:pmic@3:led-controller@d300
|
||||
E: ID_PATH_TAG=platform-c440000_spmi-platform-c440000_spmi_pmic_3_led-controller_d300
|
||||
E: MODALIAS=of:Nled-controllerT(null)Cqcom,pmi8998-flash-ledCqcom,spmi-flash-led
|
||||
E: OF_COMPATIBLE_0=qcom,pmi8998-flash-led
|
||||
E: OF_COMPATIBLE_1=qcom,spmi-flash-led
|
||||
E: OF_COMPATIBLE_N=2
|
||||
E: OF_FULLNAME=/soc@0/spmi@c440000/pmic@3/led-controller@d300
|
||||
E: OF_NAME=led-controller
|
||||
E: SUBSYSTEM=platform
|
||||
L: driver=../../../../../../../bus/platform/drivers/leds-qcom-flash
|
||||
A: driver_override=(null)\n
|
||||
A: modalias=of:Nled-controllerT(null)Cqcom,pmi8998-flash-ledCqcom,spmi-flash-led\n
|
||||
L: of_node=../../../../../../../firmware/devicetree/base/soc@0/spmi@c440000/pmic@3/led-controller@d300
|
||||
A: power/control=auto\n
|
||||
A: power/runtime_active_time=0\n
|
||||
A: power/runtime_status=unsupported\n
|
||||
A: power/runtime_suspended_time=0\n
|
||||
|
||||
P: /devices/platform/soc@0/c440000.spmi/spmi-0/0-03
|
||||
E: DRIVER=pmic-spmi
|
||||
E: MODALIAS=of:NpmicT(null)Cqcom,pmi8998Cqcom,spmi-pmic
|
||||
E: OF_COMPATIBLE_0=qcom,pmi8998
|
||||
E: OF_COMPATIBLE_1=qcom,spmi-pmic
|
||||
E: OF_COMPATIBLE_N=2
|
||||
E: OF_FULLNAME=/soc@0/spmi@c440000/pmic@3
|
||||
E: OF_NAME=pmic
|
||||
E: SUBSYSTEM=spmi
|
||||
L: driver=../../../../../../bus/spmi/drivers/pmic-spmi
|
||||
L: of_node=../../../../../../firmware/devicetree/base/soc@0/spmi@c440000/pmic@3
|
||||
A: power/control=auto\n
|
||||
A: power/runtime_active_time=132131678\n
|
||||
A: power/runtime_status=active\n
|
||||
A: power/runtime_suspended_time=0\n
|
||||
|
||||
P: /devices/platform/soc@0/c440000.spmi/spmi-0
|
||||
E: MODALIAS=of:NspmiT(null)Cqcom,spmi-pmic-arb
|
||||
E: OF_COMPATIBLE_0=qcom,spmi-pmic-arb
|
||||
E: OF_COMPATIBLE_N=1
|
||||
E: OF_FULLNAME=/soc@0/spmi@c440000
|
||||
E: OF_NAME=spmi
|
||||
E: SUBSYSTEM=spmi
|
||||
L: of_node=../../../../../firmware/devicetree/base/soc@0/spmi@c440000
|
||||
A: power/control=auto\n
|
||||
A: power/runtime_active_time=0\n
|
||||
A: power/runtime_status=unsupported\n
|
||||
A: power/runtime_suspended_time=0\n
|
||||
|
||||
P: /devices/platform/soc@0/c440000.spmi
|
||||
E: DRIVER=spmi_pmic_arb
|
||||
E: ID_PATH=platform-c440000.spmi
|
||||
E: ID_PATH_TAG=platform-c440000_spmi
|
||||
E: MODALIAS=of:NspmiT(null)Cqcom,spmi-pmic-arb
|
||||
E: OF_COMPATIBLE_0=qcom,spmi-pmic-arb
|
||||
E: OF_COMPATIBLE_N=1
|
||||
E: OF_FULLNAME=/soc@0/spmi@c440000
|
||||
E: OF_NAME=spmi
|
||||
E: SUBSYSTEM=platform
|
||||
L: consumer:platform:c440000.spmi:pmic@0:adc@3100=../../../virtual/devlink/platform:c440000.spmi--platform:c440000.spmi:pmic@0:adc@3100
|
||||
L: consumer:platform:c440000.spmi:pmic@0:pon@800:pwrkey=../../../virtual/devlink/platform:c440000.spmi--platform:c440000.spmi:pmic@0:pon@800:pwrkey
|
||||
L: consumer:platform:c440000.spmi:pmic@0:rtc@6000=../../../virtual/devlink/platform:c440000.spmi--platform:c440000.spmi:pmic@0:rtc@6000
|
||||
L: consumer:platform:c440000.spmi:pmic@0:temp-alarm@2400=../../../virtual/devlink/platform:c440000.spmi--platform:c440000.spmi:pmic@0:temp-alarm@2400
|
||||
L: consumer:platform:c440000.spmi:pmic@2:charger@1000=../../../virtual/devlink/platform:c440000.spmi--platform:c440000.spmi:pmic@2:charger@1000
|
||||
L: consumer:platform:c440000.spmi:pmic@3:haptics@c000=../../../virtual/devlink/platform:c440000.spmi--platform:c440000.spmi:pmic@3:haptics@c000
|
||||
L: driver=../../../../bus/platform/drivers/spmi_pmic_arb
|
||||
A: driver_override=(null)\n
|
||||
A: modalias=of:NspmiT(null)Cqcom,spmi-pmic-arb\n
|
||||
L: of_node=../../../../firmware/devicetree/base/soc@0/spmi@c440000
|
||||
A: power/control=auto\n
|
||||
A: power/runtime_active_time=0\n
|
||||
A: power/runtime_status=unsupported\n
|
||||
A: power/runtime_suspended_time=0\n
|
||||
|
||||
P: /devices/platform/soc@0
|
||||
E: DRIVER=simple-pm-bus
|
||||
E: ID_PATH=platform-soc@0
|
||||
E: ID_PATH_TAG=platform-soc_0
|
||||
E: MODALIAS=of:NsocT(null)Csimple-bus
|
||||
E: OF_COMPATIBLE_0=simple-bus
|
||||
E: OF_COMPATIBLE_N=1
|
||||
E: OF_FULLNAME=/soc@0
|
||||
E: OF_NAME=soc
|
||||
E: SUBSYSTEM=platform
|
||||
L: consumer:platform:17c90000.timer=../../virtual/devlink/platform:soc@0--platform:17c90000.timer
|
||||
L: consumer:platform:890000.i2c=../../virtual/devlink/platform:soc@0--platform:890000.i2c
|
||||
L: consumer:platform:898000.serial=../../virtual/devlink/platform:soc@0--platform:898000.serial
|
||||
L: consumer:platform:a600000.usb=../../virtual/devlink/platform:soc@0--platform:a600000.usb
|
||||
L: consumer:platform:a84000.serial=../../virtual/devlink/platform:soc@0--platform:a84000.serial
|
||||
L: consumer:platform:a88000.i2c=../../virtual/devlink/platform:soc@0--platform:a88000.i2c
|
||||
L: consumer:platform:a90000.i2c=../../virtual/devlink/platform:soc@0--platform:a90000.i2c
|
||||
L: driver=../../../bus/platform/drivers/simple-pm-bus
|
||||
A: driver_override=(null)\n
|
||||
A: modalias=of:NsocT(null)Csimple-bus\n
|
||||
L: of_node=../../../firmware/devicetree/base/soc@0
|
||||
A: power/control=auto\n
|
||||
A: power/runtime_active_time=0\n
|
||||
A: power/runtime_status=unsupported\n
|
||||
A: power/runtime_suspended_time=0\n
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "fbd-feedback-led.h"
|
||||
#include "fbd-dev-led.h"
|
||||
#include "fbd-dev-led-flash.h"
|
||||
#include "fbd-dev-led-multicolor.h"
|
||||
#include "fbd-dev-led-qcom.h"
|
||||
#include "fbd-dev-led-qcom-multicolor.h"
|
||||
@@ -69,6 +70,34 @@ test_fbd_dev_led_multicolor (FbdUmockdevFixture *fixture, gconstpointer unused)
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
test_fbd_dev_led_flash (FbdUmockdevFixture *fixture, gconstpointer unused)
|
||||
{
|
||||
GUdevClient *client;
|
||||
g_autolist (GUdevDevice) leds = NULL;
|
||||
FbdDevLed *led;
|
||||
g_autoptr (GError) err = NULL;
|
||||
GUdevDevice *dev;
|
||||
|
||||
client = g_udev_client_new ((const char *const []){ "leds", NULL});
|
||||
leds = g_udev_client_query_by_subsystem (client, "leds");
|
||||
|
||||
/* There should be a single device only */
|
||||
g_assert_cmpint (g_list_length (leds), ==, 1);
|
||||
dev = G_UDEV_DEVICE (leds->data);
|
||||
|
||||
g_assert_cmpstr (g_udev_device_get_property (dev, "FEEDBACKD_TYPE"), ==, "led");
|
||||
|
||||
led = fbd_dev_led_flash_new (dev, &err);
|
||||
g_assert_no_error (err);
|
||||
g_assert_cmpint (fbd_dev_led_get_max_brightness (led), ==, 255);
|
||||
g_assert_true (fbd_dev_led_supports_color (led, FBD_FEEDBACK_LED_COLOR_FLASH));
|
||||
g_assert_true (fbd_dev_led_start_periodic (led, 50, 50));
|
||||
|
||||
g_assert_finalize_object (led);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
test_fbd_dev_led_qcom_simple (FbdUmockdevFixture *fixture, gconstpointer unused)
|
||||
{
|
||||
@@ -135,6 +164,9 @@ main (gint argc, gchar *argv[])
|
||||
FBD_UMOCKDEV_TEST_ADD ("/feedbackd/fbd/dev/led/multicolor",
|
||||
test_fbd_dev_led_multicolor,
|
||||
"led-multicolor");
|
||||
FBD_UMOCKDEV_TEST_ADD ("/feedbackd/fbd/dev/led/flash",
|
||||
test_fbd_dev_led_flash,
|
||||
"led-flash");
|
||||
FBD_UMOCKDEV_TEST_ADD ("/feedbackd/fbd/dev/led/qcom/simple",
|
||||
test_fbd_dev_led_qcom_simple,
|
||||
"led-qcom-simple");
|
||||
|
||||
Reference in New Issue
Block a user