intel_pmc_core_pltdrv.c 2.4 KB

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