[PATCH 4/6] acpi/cppc: Add macros to define a R/W sysfs entry for CPPC registers
From: Natarajan, Janakarajan
Date: Fri Mar 22 2019 - 16:26:36 EST
From: Yazen Ghannam <Yazen.Ghannam@xxxxxxx>
Some CPPC registers can be used to configure the platform. To enable this,
create macros to define the show, store routines and create sysfs entries
with R/W permission.
Signed-off-by: Yazen Ghannam <Yazen.Ghannam@xxxxxxx>
[ carved into a patch, cleaned up, productized ]
Signed-off-by: Janakarajan Natarajan <Janakarajan.Natarajan@xxxxxxx>
---
drivers/acpi/cppc_acpi.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
index e81c19316628..7cb23b369fc7 100644
--- a/drivers/acpi/cppc_acpi.c
+++ b/drivers/acpi/cppc_acpi.c
@@ -134,6 +134,10 @@ struct cppc_attr {
static struct cppc_attr _name = \
__ATTR(_name, 0444, show_##_name, NULL)
+#define define_one_cppc_rw(_name) \
+static struct cppc_attr _name = \
+__ATTR(_name, 0644, show_##_name, store_##_name)
+
#define to_cpc_desc(a) container_of(a, struct cpc_desc, kobj)
#define show_cppc_data(access_fn, struct_name, member_name) \
@@ -156,6 +160,33 @@ __ATTR(_name, 0444, show_##_name, NULL)
show_cppc_data(access_fn, struct_name, member_name) \
define_one_cppc_ro(member_name)
+#define store_cppc_data(struct_name, member_name, reg_idx) \
+ static ssize_t store_##member_name(struct kobject *kobj, \
+ struct attribute *attr, \
+ const char *c, ssize_t count)\
+ { \
+ struct cpc_desc *cpc_ptr = to_cpc_desc(kobj); \
+ struct struct_name st_name = {0}; \
+ u32 val; \
+ int ret; \
+ \
+ ret = kstrtou32(c, 0, &val); \
+ if (ret) \
+ return ret; \
+ \
+ st_name.member_name = val; \
+ \
+ ret = cppc_set_reg(cpc_ptr->cpu_id, &st_name, reg_idx); \
+ if (ret) \
+ return ret; \
+ \
+ return count; \
+ } \
+
+#define store_cppc_data_rw(struct_name, member_name, reg_idx) \
+ store_cppc_data(struct_name, member_name, reg_idx) \
+ define_one_cppc_rw(member_name)
+
show_cppc_data_ro(cppc_get_perf_caps, cppc_perf_caps, highest_perf);
show_cppc_data_ro(cppc_get_perf_caps, cppc_perf_caps, lowest_perf);
show_cppc_data_ro(cppc_get_perf_caps, cppc_perf_caps, nominal_perf);
--
2.17.1