Linux-libre 5.3.12-gnu
[librecmc/linux-libre.git] / drivers / platform / x86 / intel_pmc_core_pltdrv.c
1 // SPDX-License-Identifier: GPL-2.0
2
3 /*
4  * Intel PMC Core platform init
5  * Copyright (c) 2019, Google Inc.
6  * Author - Rajat Jain
7  *
8  * This code instantiates platform devices for intel_pmc_core driver, only
9  * on supported platforms that may not have the ACPI devices in the ACPI tables.
10  * No new platforms should be added here, because we expect that new platforms
11  * should all have the ACPI device, which is the preferred way of enumeration.
12  */
13
14 #include <linux/acpi.h>
15 #include <linux/module.h>
16 #include <linux/platform_device.h>
17
18 #include <asm/cpu_device_id.h>
19 #include <asm/intel-family.h>
20
21 static void intel_pmc_core_release(struct device *dev)
22 {
23         /* Nothing to do. */
24 }
25
26 static struct platform_device pmc_core_device = {
27         .name = "intel_pmc_core",
28         .dev  = {
29                 .release = intel_pmc_core_release,
30         },
31 };
32
33 /*
34  * intel_pmc_core_platform_ids is the list of platforms where we want to
35  * instantiate the platform_device if not already instantiated. This is
36  * different than intel_pmc_core_ids in intel_pmc_core.c which is the
37  * list of platforms that the driver supports for pmc_core device. The
38  * other list may grow, but this list should not.
39  */
40 static const struct x86_cpu_id intel_pmc_core_platform_ids[] = {
41         INTEL_CPU_FAM6(SKYLAKE_MOBILE, pmc_core_device),
42         INTEL_CPU_FAM6(SKYLAKE_DESKTOP, pmc_core_device),
43         INTEL_CPU_FAM6(KABYLAKE_MOBILE, pmc_core_device),
44         INTEL_CPU_FAM6(KABYLAKE_DESKTOP, pmc_core_device),
45         INTEL_CPU_FAM6(CANNONLAKE_MOBILE, pmc_core_device),
46         INTEL_CPU_FAM6(ICELAKE_MOBILE, pmc_core_device),
47         {}
48 };
49 MODULE_DEVICE_TABLE(x86cpu, intel_pmc_core_platform_ids);
50
51 static int __init pmc_core_platform_init(void)
52 {
53         /* Skip creating the platform device if ACPI already has a device */
54         if (acpi_dev_present("INT33A1", NULL, -1))
55                 return -ENODEV;
56
57         if (!x86_match_cpu(intel_pmc_core_platform_ids))
58                 return -ENODEV;
59
60         return platform_device_register(&pmc_core_device);
61 }
62
63 static void __exit pmc_core_platform_exit(void)
64 {
65         platform_device_unregister(&pmc_core_device);
66 }
67
68 module_init(pmc_core_platform_init);
69 module_exit(pmc_core_platform_exit);
70 MODULE_LICENSE("GPL v2");