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 */ 6 7 #include <linux/acpi.h> 8 #include <linux/kernel.h> 9 #include <linux/module.h> 10 #include <linux/platform_device.h> 11 12 /* 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 19 */ 20 #define PCH_FIVR_SHOW(name, method) \ 21 static ssize_t name##_show(struct device *dev,\ 22 struct device_attribute *attr,\ 23 char *buf)\ 24 {\ 25 struct acpi_device *acpi_dev = dev_get_drvdata(dev);\ 26 unsigned long long val;\ 27 acpi_status status;\ 28 \ 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;\ 35 } 36 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)\ 41 {\ 42 struct acpi_device *acpi_dev = dev_get_drvdata(dev);\ 43 acpi_status status;\ 44 u32 val;\ 45 \ 46 if (kstrtouint(buf, 0, &val) < 0)\ 47 return -EINVAL;\ 48 \ 49 status = acpi_execute_simple_method(acpi_dev->handle, #method, val);\ 50 if (ACPI_SUCCESS(status))\ 51 return count;\ 52 \ 53 return -EINVAL;\ 54 } 55 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) 60 61 static DEVICE_ATTR_RW(freq_mhz_low_clock); 62 static DEVICE_ATTR_RW(freq_mhz_high_clock); 63 64 static struct attribute *fivr_attrs[] = { 65 &dev_attr_freq_mhz_low_clock.attr, 66 &dev_attr_freq_mhz_high_clock.attr, 67 NULL 68 }; 69 70 static const struct attribute_group pch_fivr_attribute_group = { 71 .attrs = fivr_attrs, 72 .name = "pch_fivr_switch_frequency" 73 }; 74 75 static int pch_fivr_add(struct platform_device *pdev) 76 { 77 struct acpi_device *acpi_dev; 78 unsigned long long ptype; 79 acpi_status status; 80 int result; 81 82 acpi_dev = ACPI_COMPANION(&(pdev->dev)); 83 if (!acpi_dev) 84 return -ENODEV; 85 86 status = acpi_evaluate_integer(acpi_dev->handle, "PTYP", NULL, &ptype); 87 if (ACPI_FAILURE(status) || ptype != 0x05) 88 return -ENODEV; 89 90 result = sysfs_create_group(&pdev->dev.kobj, 91 &pch_fivr_attribute_group); 92 if (result) 93 return result; 94 95 platform_set_drvdata(pdev, acpi_dev); 96 97 return 0; 98 } 99 100 static int pch_fivr_remove(struct platform_device *pdev) 101 { 102 sysfs_remove_group(&pdev->dev.kobj, &pch_fivr_attribute_group); 103 104 return 0; 105 } 106 107 static const struct acpi_device_id pch_fivr_device_ids[] = { 108 {"INTC1045", 0}, 109 {"INTC1049", 0}, 110 {"", 0}, 111 }; 112 MODULE_DEVICE_TABLE(acpi, pch_fivr_device_ids); 113 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, 120 }, 121 }; 122 123 module_platform_driver(pch_fivr_driver); 124 125 MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>"); 126 MODULE_LICENSE("GPL v2"); 127 MODULE_DESCRIPTION("ACPI DPTF PCH FIVR driver"); 128