1 // SPDX-License-Identifier: GPL-2.0-only
3 * dptf_pch_fivr: DPTF PCH FIVR Participant driver
4 * Copyright (c) 2020, Intel Corporation.
7 #include <linux/acpi.h>
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/platform_device.h>
12 struct pch_fivr_resp
{
17 static int pch_fivr_read(acpi_handle handle
, char *method
, struct pch_fivr_resp
*fivr_resp
)
19 struct acpi_buffer resp
= { sizeof(struct pch_fivr_resp
), fivr_resp
};
20 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
21 struct acpi_buffer format
= { sizeof("NN"), "NN" };
22 union acpi_object
*obj
;
26 status
= acpi_evaluate_object(handle
, method
, NULL
, &buffer
);
27 if (ACPI_FAILURE(status
))
31 if (!obj
|| obj
->type
!= ACPI_TYPE_PACKAGE
)
34 status
= acpi_extract_package(obj
, &format
, &resp
);
35 if (ACPI_FAILURE(status
))
38 if (fivr_resp
->status
)
44 kfree(buffer
.pointer
);
49 * Presentation of attributes which are defined for INTC10xx
51 * freq_mhz_low_clock : Set PCH FIVR switching freq for
52 * FIVR clock 19.2MHz and 24MHz
53 * freq_mhz_high_clock : Set PCH FIVR switching freq for
56 #define PCH_FIVR_SHOW(name, method) \
57 static ssize_t name##_show(struct device *dev,\
58 struct device_attribute *attr,\
61 struct acpi_device *acpi_dev = dev_get_drvdata(dev);\
62 struct pch_fivr_resp fivr_resp;\
65 status = pch_fivr_read(acpi_dev->handle, #method, &fivr_resp);\
69 return sprintf(buf, "%llu\n", fivr_resp.result);\
72 #define PCH_FIVR_STORE(name, method) \
73 static ssize_t name##_store(struct device *dev,\
74 struct device_attribute *attr,\
75 const char *buf, size_t count)\
77 struct acpi_device *acpi_dev = dev_get_drvdata(dev);\
81 if (kstrtouint(buf, 0, &val) < 0)\
84 status = acpi_execute_simple_method(acpi_dev->handle, #method, val);\
85 if (ACPI_SUCCESS(status))\
91 PCH_FIVR_SHOW(freq_mhz_low_clock
, GFC0
)
92 PCH_FIVR_SHOW(freq_mhz_high_clock
, GFC1
)
93 PCH_FIVR_SHOW(ssc_clock_info
, GEMI
)
94 PCH_FIVR_SHOW(fivr_switching_freq_mhz
, GFCS
)
95 PCH_FIVR_SHOW(fivr_switching_fault_status
, GFFS
)
96 PCH_FIVR_STORE(freq_mhz_low_clock
, RFC0
)
97 PCH_FIVR_STORE(freq_mhz_high_clock
, RFC1
)
99 static DEVICE_ATTR_RW(freq_mhz_low_clock
);
100 static DEVICE_ATTR_RW(freq_mhz_high_clock
);
101 static DEVICE_ATTR_RO(ssc_clock_info
);
102 static DEVICE_ATTR_RO(fivr_switching_freq_mhz
);
103 static DEVICE_ATTR_RO(fivr_switching_fault_status
);
105 static struct attribute
*fivr_attrs
[] = {
106 &dev_attr_freq_mhz_low_clock
.attr
,
107 &dev_attr_freq_mhz_high_clock
.attr
,
108 &dev_attr_ssc_clock_info
.attr
,
109 &dev_attr_fivr_switching_freq_mhz
.attr
,
110 &dev_attr_fivr_switching_fault_status
.attr
,
114 static const struct attribute_group pch_fivr_attribute_group
= {
116 .name
= "pch_fivr_switch_frequency"
119 static int pch_fivr_add(struct platform_device
*pdev
)
121 struct acpi_device
*acpi_dev
;
122 unsigned long long ptype
;
126 acpi_dev
= ACPI_COMPANION(&(pdev
->dev
));
130 status
= acpi_evaluate_integer(acpi_dev
->handle
, "PTYP", NULL
, &ptype
);
131 if (ACPI_FAILURE(status
) || ptype
!= 0x05)
134 result
= sysfs_create_group(&pdev
->dev
.kobj
,
135 &pch_fivr_attribute_group
);
139 platform_set_drvdata(pdev
, acpi_dev
);
144 static void pch_fivr_remove(struct platform_device
*pdev
)
146 sysfs_remove_group(&pdev
->dev
.kobj
, &pch_fivr_attribute_group
);
149 static const struct acpi_device_id pch_fivr_device_ids
[] = {
157 MODULE_DEVICE_TABLE(acpi
, pch_fivr_device_ids
);
159 static struct platform_driver pch_fivr_driver
= {
160 .probe
= pch_fivr_add
,
161 .remove_new
= pch_fivr_remove
,
163 .name
= "dptf_pch_fivr",
164 .acpi_match_table
= pch_fivr_device_ids
,
168 module_platform_driver(pch_fivr_driver
);
170 MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
171 MODULE_LICENSE("GPL v2");
172 MODULE_DESCRIPTION("ACPI DPTF PCH FIVR driver");