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>
13 * Presentation of attributes which are defined for INT1045
15 * freq_mhz_low_clock : Set PCH FIVR switching freq for
16 * FIVR clock 19.2MHz and 24MHz
17 * freq_mhz_high_clock : Set PCH FIVR switching freq for
20 #define PCH_FIVR_SHOW(name, method) \
21 static ssize_t name##_show(struct device *dev,\
22 struct device_attribute *attr,\
25 struct acpi_device *acpi_dev = dev_get_drvdata(dev);\
26 unsigned long long val;\
29 status = acpi_evaluate_integer(acpi_dev->handle, #method,\
31 if (ACPI_SUCCESS(status))\
32 return sprintf(buf, "%d\n", (int)val);\
37 #define PCH_FIVR_STORE(name, method) \
38 static ssize_t name##_store(struct device *dev,\
39 struct device_attribute *attr,\
40 const char *buf, size_t count)\
42 struct acpi_device *acpi_dev = dev_get_drvdata(dev);\
46 if (kstrtouint(buf, 0, &val) < 0)\
49 status = acpi_execute_simple_method(acpi_dev->handle, #method, val);\
50 if (ACPI_SUCCESS(status))\
56 PCH_FIVR_SHOW(freq_mhz_low_clock
, GFC0
)
57 PCH_FIVR_SHOW(freq_mhz_high_clock
, GFC1
)
58 PCH_FIVR_STORE(freq_mhz_low_clock
, RFC0
)
59 PCH_FIVR_STORE(freq_mhz_high_clock
, RFC1
)
61 static DEVICE_ATTR_RW(freq_mhz_low_clock
);
62 static DEVICE_ATTR_RW(freq_mhz_high_clock
);
64 static struct attribute
*fivr_attrs
[] = {
65 &dev_attr_freq_mhz_low_clock
.attr
,
66 &dev_attr_freq_mhz_high_clock
.attr
,
70 static const struct attribute_group pch_fivr_attribute_group
= {
72 .name
= "pch_fivr_switch_frequency"
75 static int pch_fivr_add(struct platform_device
*pdev
)
77 struct acpi_device
*acpi_dev
;
78 unsigned long long ptype
;
82 acpi_dev
= ACPI_COMPANION(&(pdev
->dev
));
86 status
= acpi_evaluate_integer(acpi_dev
->handle
, "PTYP", NULL
, &ptype
);
87 if (ACPI_FAILURE(status
) || ptype
!= 0x05)
90 result
= sysfs_create_group(&pdev
->dev
.kobj
,
91 &pch_fivr_attribute_group
);
95 platform_set_drvdata(pdev
, acpi_dev
);
100 static int pch_fivr_remove(struct platform_device
*pdev
)
102 sysfs_remove_group(&pdev
->dev
.kobj
, &pch_fivr_attribute_group
);
107 static const struct acpi_device_id pch_fivr_device_ids
[] = {
112 MODULE_DEVICE_TABLE(acpi
, pch_fivr_device_ids
);
114 static struct platform_driver pch_fivr_driver
= {
115 .probe
= pch_fivr_add
,
116 .remove
= pch_fivr_remove
,
118 .name
= "dptf_pch_fivr",
119 .acpi_match_table
= pch_fivr_device_ids
,
123 module_platform_driver(pch_fivr_driver
);
125 MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
126 MODULE_LICENSE("GPL v2");
127 MODULE_DESCRIPTION("ACPI DPTF PCH FIVR driver");