[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250107-pdx86-firmware-attributes-v1-2-9d75c04a3b52@weissschuh.net>
Date: Tue, 07 Jan 2025 18:05:38 +0100
From: Thomas Weißschuh <linux@...ssschuh.net>
To: Hans de Goede <hdegoede@...hat.com>,
Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>,
Armin Wolf <W_Armin@....de>
Cc: platform-driver-x86@...r.kernel.org, linux-kernel@...r.kernel.org,
Joshua Grisham <josh@...huagrisham.com>,
Thomas Weißschuh <linux@...ssschuh.net>
Subject: [PATCH 2/2] platform/x86: firmware_attributes_class: Add test
driver
The driver showcases the use of the new subsystem API.
Signed-off-by: Thomas Weißschuh <linux@...ssschuh.net>
---
drivers/platform/x86/Kconfig | 12 ++++
drivers/platform/x86/Makefile | 1 +
drivers/platform/x86/firmware_attributes_test.c | 78 +++++++++++++++++++++++++
3 files changed, 91 insertions(+)
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 0258dd879d64be389f4dd9bc309fe089f23cc798..2a0e828657d2f07074944d6c42dc204fc8825a42 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -1065,6 +1065,18 @@ source "drivers/platform/x86/x86-android-tablets/Kconfig"
config FW_ATTR_CLASS
tristate
+config FW_ATTR_TEST
+ tristate "Firmware attribute test driver"
+ select FW_ATTR_CLASS
+ help
+ This driver provides a test user of the firmware attribute subsystem.
+
+ An instance is created at /sys/class/firmware-attributes/test/
+ container various example attributes.
+
+ To compile this driver as a module, choose M here: the module
+ will be called firmware_attributes_test.
+
config INTEL_IMR
bool "Intel Isolated Memory Region support"
depends on X86_INTEL_QUARK && IOSF_MBI
diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
index e1b142947067475ee5472400a5a1cd20d79e12bd..610a1ca850a4353fd490e43b214a9e5872d2d28d 100644
--- a/drivers/platform/x86/Makefile
+++ b/drivers/platform/x86/Makefile
@@ -121,6 +121,7 @@ obj-$(CONFIG_TOPSTAR_LAPTOP) += topstar-laptop.o
# Platform drivers
obj-$(CONFIG_FW_ATTR_CLASS) += firmware_attributes_class.o
+obj-$(CONFIG_FW_ATTR_TEST) += firmware_attributes_test.o
obj-$(CONFIG_SERIAL_MULTI_INSTANTIATE) += serial-multi-instantiate.o
obj-$(CONFIG_MLX_PLATFORM) += mlx-platform.o
obj-$(CONFIG_TOUCHSCREEN_DMI) += touchscreen_dmi.o
diff --git a/drivers/platform/x86/firmware_attributes_test.c b/drivers/platform/x86/firmware_attributes_test.c
new file mode 100644
index 0000000000000000000000000000000000000000..84f6a92e5163378c655f30ac022d513d7df5a18c
--- /dev/null
+++ b/drivers/platform/x86/firmware_attributes_test.c
@@ -0,0 +1,78 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/module.h>
+#include <linux/sysfs.h>
+#include "firmware_attributes_class.h"
+
+struct fw_attr_test_data {
+ char attr1_value[PAGE_SIZE];
+};
+
+static ssize_t test_attr1_default_value_show(struct firmware_attributes_device *fwadev,
+ const struct firmware_attribute *attr, char *buf)
+{
+ return sysfs_emit(buf, "default 1\n");
+}
+
+static struct firmware_attribute test_attr1_default_value = __ATTR(default_value, 0444,
+ test_attr1_default_value_show,
+ NULL);
+
+static ssize_t test_attr1_current_value_show(struct firmware_attributes_device *fwadev,
+ const struct firmware_attribute *attr, char *buf)
+{
+ struct fw_attr_test_data *data = fwadev->data;
+
+ return sysfs_emit(buf, "%s\n", data->attr1_value);
+}
+
+static ssize_t test_attr1_current_value_store(struct firmware_attributes_device *fwadev,
+ const struct firmware_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct fw_attr_test_data *data = fwadev->data;
+
+ return strscpy(data->attr1_value, buf);
+}
+
+static struct firmware_attribute test_attr1_current_value = __ATTR(current_value, 0644,
+ test_attr1_current_value_show,
+ test_attr1_current_value_store);
+
+static struct attribute *test_attr1_attrs[] = {
+ firmware_attribute_type_string,
+ &test_attr1_default_value.attr,
+ &test_attr1_current_value.attr,
+ NULL
+};
+
+static const struct attribute_group test_attr1_group = {
+ .name = "attr1",
+ .attrs = test_attr1_attrs,
+};
+
+static const struct attribute_group *test_attr_groups[] = {
+ &test_attr1_group,
+ NULL
+};
+
+static struct firmware_attributes_device *fwadev;
+
+static int __init fw_test_init(void)
+{
+ static struct fw_attr_test_data data = {
+ .attr1_value = "attr1",
+ };
+
+ fwadev = firmware_attributes_device_register(NULL, "test", test_attr_groups, &data);
+ return PTR_ERR_OR_ZERO(fwadev);
+}
+module_init(fw_test_init);
+
+static void __exit fw_test_exit(void)
+{
+ firmware_attributes_device_unregister(fwadev);
+}
+module_exit(fw_test_exit);
+
+MODULE_LICENSE("GPL");
--
2.47.1
Powered by blists - more mailing lists