[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250517-fw-attrs-api-v2-3-fa1ab045a01c@gmail.com>
Date: Sat, 17 May 2025 05:51:38 -0300
From: Kurt Borja <kuurtb@...il.com>
To: Hans de Goede <hdegoede@...hat.com>,
Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>,
Thomas Weißschuh <linux@...ssschuh.net>,
Joshua Grisham <josh@...huagrisham.com>,
Mark Pearson <mpearson-lenovo@...ebb.ca>, Armin Wolf <W_Armin@....de>,
Mario Limonciello <mario.limonciello@....com>
Cc: Antheas Kapenekakis <lkml@...heas.dev>,
"Derek J. Clark" <derekjohn.clark@...il.com>,
Prasanth Ksr <prasanth.ksr@...l.com>, Jorge Lopez <jorge.lopez2@...com>,
platform-driver-x86@...r.kernel.org, linux-kernel@...r.kernel.org,
Dell.Client.Kernel@...l.com, Kurt Borja <kuurtb@...il.com>
Subject: [PATCH v2 3/5] platform/x86: firmware_attributes_class: Add a
boolean type
Add a `boolean` attribute type to prevent the use of the `enumeration`
type for this simple specification.
Signed-off-by: Kurt Borja <kuurtb@...il.com>
---
.../ABI/testing/sysfs-class-firmware-attributes | 1 +
drivers/platform/x86/firmware_attributes_class.c | 19 +++++++++++++++++++
drivers/platform/x86/firmware_attributes_class.h | 8 ++++++++
3 files changed, 28 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-class-firmware-attributes b/Documentation/ABI/testing/sysfs-class-firmware-attributes
index 2713efa509b465a39bf014180794bf487e5b42d6..dc117e694416aed3f1f7ba0ebb1d0c23337b2298 100644
--- a/Documentation/ABI/testing/sysfs-class-firmware-attributes
+++ b/Documentation/ABI/testing/sysfs-class-firmware-attributes
@@ -21,6 +21,7 @@ Description:
- enumeration: a set of pre-defined valid values
- integer: a range of numerical values
- string
+ - bool
HP specific types
-----------------
diff --git a/drivers/platform/x86/firmware_attributes_class.c b/drivers/platform/x86/firmware_attributes_class.c
index 29401b81b25b9bb1332dbe56eadf96ff81e91c2f..6ff38b3be98bc8705ac29ce0afc11d5a4604dc8e 100644
--- a/drivers/platform/x86/firmware_attributes_class.c
+++ b/drivers/platform/x86/firmware_attributes_class.c
@@ -27,6 +27,7 @@ EXPORT_SYMBOL_GPL(firmware_attributes_class);
static const char * const fwat_type_labels[] = {
[fwat_type_integer] = "integer",
+ [fwat_type_boolean] = "boolean",
[fwat_type_string] = "string",
[fwat_type_enumeration] = "enumeration",
};
@@ -74,6 +75,7 @@ fwat_current_value_show(struct device *dev, const struct fwat_attribute *attr, c
const struct fwat_attr_config *config = ext->config;
const struct fwat_attr_ops *ops = config->ops;
const char *str;
+ bool bool_val;
long int_val;
int ret;
@@ -87,6 +89,12 @@ fwat_current_value_show(struct device *dev, const struct fwat_attribute *attr, c
return ret;
return sysfs_emit(buf, "%ld\n", int_val);
+ case fwat_type_boolean:
+ ret = config->ops->boolean.read(dev, config->aux, &bool_val);
+ if (ret)
+ return ret;
+
+ return sysfs_emit(buf, "%u\n", bool_val);
case fwat_type_string:
if (!ops->string.read)
return -EOPNOTSUPP;
@@ -117,6 +125,7 @@ fwat_current_value_store(struct device *dev, const struct fwat_attribute *attr,
const struct fwat_attribute_ext *ext = to_fwat_attribute_ext(attr);
const struct fwat_attr_config *config = ext->config;
const struct fwat_attr_ops *ops = config->ops;
+ bool bool_val;
long int_val;
int ret;
@@ -131,6 +140,16 @@ fwat_current_value_store(struct device *dev, const struct fwat_attribute *attr,
ret = ops->integer.write(dev, config->aux, int_val);
break;
+ case fwat_type_boolean:
+ if (!ops->boolean.write)
+ return -EOPNOTSUPP;
+
+ ret = kstrtobool(buf, &bool_val);
+ if (ret)
+ return ret;
+
+ ret = ops->boolean.write(dev, config->aux, bool_val);
+ break;
case fwat_type_string:
if (!ops->string.write)
return -EOPNOTSUPP;
diff --git a/drivers/platform/x86/firmware_attributes_class.h b/drivers/platform/x86/firmware_attributes_class.h
index 3a13c69ca6a0f993cf7c6bfae6e43f1eeaa002ab..b823d05d76e91efa40cd3623687b57c664176073 100644
--- a/drivers/platform/x86/firmware_attributes_class.h
+++ b/drivers/platform/x86/firmware_attributes_class.h
@@ -49,6 +49,7 @@ struct fwat_attribute {
enum fwat_attr_type {
fwat_type_integer,
+ fwat_type_boolean,
fwat_type_string,
fwat_type_enumeration,
};
@@ -80,11 +81,17 @@ struct str_ops {
int (*write)(struct device *dev, long aux, const char *str, size_t count);
};
+struct bool_ops {
+ int (*read)(struct device *dev, long aux, bool *val);
+ int (*write)(struct device *dev, long aux, bool val);
+};
+
/**
* struct fwat_attr_ops - Operations for a firmware *attribute*
* @type: Type of callbacks.
* @prop_read: Callback for retrieving each configured property of an attribute.
* @integer: Integer type callbacks.
+ * @boolean: Boolean type callbacks.
* @string: String type callbacks.
* @enumeration: Enumeration type callbacks.
*/
@@ -94,6 +101,7 @@ struct fwat_attr_ops {
enum fwat_property prop, char *buf);
union {
struct long_ops integer;
+ struct bool_ops boolean;
struct str_ops string;
struct str_ops enumeration;
};
--
2.49.0
Powered by blists - more mailing lists