[PATCH v1 02/22] backlight: Add DECLARE_* macro for device registration

Sam Ravnborg sam at ravnborg.org
Sun Aug 2 11:06:16 UTC 2020


Device registration almost always uses a struct backlight_properties
variable to pass config info. Make it simpler and less error prone
by the introduction of a number of macros.

There is one macro for each type of backlight {firmware, platform, raw}.
All members in struct backlight_properties are initialized.

Signed-off-by: Sam Ravnborg <sam at ravnborg.org>
Cc: Lee Jones <lee.jones at linaro.org>
Cc: Daniel Thompson <daniel.thompson at linaro.org>
Cc: Jingoo Han <jingoohan1 at gmail.com>
---
 include/linux/backlight.h | 45 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/include/linux/backlight.h b/include/linux/backlight.h
index 190963ffb7fc..d683c053ec09 100644
--- a/include/linux/backlight.h
+++ b/include/linux/backlight.h
@@ -272,6 +272,51 @@ struct backlight_properties {
 	enum backlight_scale scale;
 };
 
+#define BACKLIGHT_PROPS(_brightness, _max_brightness, _type)	\
+	.brightness = _brightness,				\
+	.max_brightness = _max_brightness,			\
+	.power = FB_BLANK_POWERDOWN,				\
+	.type = _type,						\
+	.fb_blank = 0,						\
+	.state = 0,						\
+	.scale = BACKLIGHT_SCALE_UNKNOWN,
+
+/**
+ * DECLARE_BACKLIGHT_INIT_RAW - backlight_properties to init a raw
+ *                              backlight device
+ *
+ * This macro is used to initialize backlight_properties that is used when
+ * registering a raw backlight device.
+ */
+#define DECLARE_BACKLIGHT_INIT_RAW(name, _brightness, _max_brightness)		\
+	const struct backlight_properties name = {				\
+		BACKLIGHT_PROPS(_brightness, _max_brightness, BACKLIGHT_RAW)	\
+	}
+
+/**
+ * DECLARE_BACKLIGHT_INIT_PLATFORM - backlight_properties to init a platform
+ *                                   backlight device
+ *
+ * This macro is used to initialize backlight_properties that is used when
+ * registering a platform backlight device.
+ */
+#define DECLARE_BACKLIGHT_INIT_PLATFORM(name, _brightness, _max_brightness)		\
+	const struct backlight_properties name = {					\
+		BACKLIGHT_PROPS(_brightness, _max_brightness, BACKLIGHT_PLATFORM)	\
+	}
+
+/**
+ * DECLARE_BACKLIGHT_INIT_FIRMWARE - backlight_properties to init a firmware
+ *                                   backlight device
+ *
+ * This macro is used to initialize backlight_properties that is used when
+ * registering a firmware backlight device.
+ */
+#define DECLARE_BACKLIGHT_INIT_FIRMWARE(name, _brightness, _max_brightness)		\
+	const struct backlight_properties name = {					\
+		BACKLIGHT_PROPS(_brightness, _max_brightness, BACKLIGHT_FIRMWARE)	\
+	}
+
 /**
  * struct backlight_device - backlight device data
  *
-- 
2.25.1



More information about the dri-devel mailing list