From: Yazen Ghannam <yazen.ghan...@amd.com> 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.ghan...@amd.com> [ carved into a patch, cleaned up, productized ] Signed-off-by: Janakarajan Natarajan <janakarajan.natara...@amd.com> --- 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 1cce231b8501..1e862415faf0 100644 --- a/drivers/acpi/cppc_acpi.c +++ b/drivers/acpi/cppc_acpi.c @@ -142,6 +142,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) \ @@ -164,6 +168,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