Merge tag 'trace-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
[linux/fpc-iii.git] / drivers / acpi / dptf / dptf_pch_fivr.c
blob5fca18296bf6801514c154dca99969f1049008a3
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * dptf_pch_fivr: DPTF PCH FIVR Participant driver
4 * Copyright (c) 2020, Intel Corporation.
5 */
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
14 * They are:
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
18 * FIVR clock 38.4MHz
20 #define PCH_FIVR_SHOW(name, method) \
21 static ssize_t name##_show(struct device *dev,\
22 struct device_attribute *attr,\
23 char *buf)\
25 struct acpi_device *acpi_dev = dev_get_drvdata(dev);\
26 unsigned long long val;\
27 acpi_status status;\
29 status = acpi_evaluate_integer(acpi_dev->handle, #method,\
30 NULL, &val);\
31 if (ACPI_SUCCESS(status))\
32 return sprintf(buf, "%d\n", (int)val);\
33 else\
34 return -EINVAL;\
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);\
43 acpi_status status;\
44 u32 val;\
46 if (kstrtouint(buf, 0, &val) < 0)\
47 return -EINVAL;\
49 status = acpi_execute_simple_method(acpi_dev->handle, #method, val);\
50 if (ACPI_SUCCESS(status))\
51 return count;\
53 return -EINVAL;\
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,
67 NULL
70 static const struct attribute_group pch_fivr_attribute_group = {
71 .attrs = fivr_attrs,
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;
79 acpi_status status;
80 int result;
82 acpi_dev = ACPI_COMPANION(&(pdev->dev));
83 if (!acpi_dev)
84 return -ENODEV;
86 status = acpi_evaluate_integer(acpi_dev->handle, "PTYP", NULL, &ptype);
87 if (ACPI_FAILURE(status) || ptype != 0x05)
88 return -ENODEV;
90 result = sysfs_create_group(&pdev->dev.kobj,
91 &pch_fivr_attribute_group);
92 if (result)
93 return result;
95 platform_set_drvdata(pdev, acpi_dev);
97 return 0;
100 static int pch_fivr_remove(struct platform_device *pdev)
102 sysfs_remove_group(&pdev->dev.kobj, &pch_fivr_attribute_group);
104 return 0;
107 static const struct acpi_device_id pch_fivr_device_ids[] = {
108 {"INTC1045", 0},
109 {"INTC1049", 0},
110 {"", 0},
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,
117 .driver = {
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");