pwm-lpss-pci.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Intel Low Power Subsystem PWM controller PCI driver
  4. *
  5. * Copyright (C) 2014, Intel Corporation
  6. *
  7. * Derived from the original pwm-lpss.c
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/module.h>
  11. #include <linux/pci.h>
  12. #include <linux/pm_runtime.h>
  13. #include "pwm-lpss.h"
  14. static int pwm_lpss_probe_pci(struct pci_dev *pdev,
  15. const struct pci_device_id *id)
  16. {
  17. const struct pwm_lpss_boardinfo *info;
  18. struct pwm_lpss_chip *lpwm;
  19. int err;
  20. err = pcim_enable_device(pdev);
  21. if (err < 0)
  22. return err;
  23. err = pcim_iomap_regions(pdev, BIT(0), pci_name(pdev));
  24. if (err)
  25. return err;
  26. info = (struct pwm_lpss_boardinfo *)id->driver_data;
  27. lpwm = pwm_lpss_probe(&pdev->dev, pcim_iomap_table(pdev)[0], info);
  28. if (IS_ERR(lpwm))
  29. return PTR_ERR(lpwm);
  30. pci_set_drvdata(pdev, lpwm);
  31. pm_runtime_put(&pdev->dev);
  32. pm_runtime_allow(&pdev->dev);
  33. return 0;
  34. }
  35. static void pwm_lpss_remove_pci(struct pci_dev *pdev)
  36. {
  37. pm_runtime_forbid(&pdev->dev);
  38. pm_runtime_get_sync(&pdev->dev);
  39. }
  40. static int pwm_lpss_runtime_suspend_pci(struct device *dev)
  41. {
  42. /*
  43. * The PCI core will handle transition to D3 automatically. We only
  44. * need to provide runtime PM hooks for that to happen.
  45. */
  46. return 0;
  47. }
  48. static int pwm_lpss_runtime_resume_pci(struct device *dev)
  49. {
  50. return 0;
  51. }
  52. static DEFINE_RUNTIME_DEV_PM_OPS(pwm_lpss_pci_pm,
  53. pwm_lpss_runtime_suspend_pci,
  54. pwm_lpss_runtime_resume_pci,
  55. NULL);
  56. static const struct pci_device_id pwm_lpss_pci_ids[] = {
  57. { PCI_VDEVICE(INTEL, 0x0ac8), (unsigned long)&pwm_lpss_bxt_info},
  58. { PCI_VDEVICE(INTEL, 0x0f08), (unsigned long)&pwm_lpss_byt_info},
  59. { PCI_VDEVICE(INTEL, 0x0f09), (unsigned long)&pwm_lpss_byt_info},
  60. { PCI_VDEVICE(INTEL, 0x11a5), (unsigned long)&pwm_lpss_tng_info},
  61. { PCI_VDEVICE(INTEL, 0x1ac8), (unsigned long)&pwm_lpss_bxt_info},
  62. { PCI_VDEVICE(INTEL, 0x2288), (unsigned long)&pwm_lpss_bsw_info},
  63. { PCI_VDEVICE(INTEL, 0x2289), (unsigned long)&pwm_lpss_bsw_info},
  64. { PCI_VDEVICE(INTEL, 0x31c8), (unsigned long)&pwm_lpss_bxt_info},
  65. { PCI_VDEVICE(INTEL, 0x5ac8), (unsigned long)&pwm_lpss_bxt_info},
  66. { },
  67. };
  68. MODULE_DEVICE_TABLE(pci, pwm_lpss_pci_ids);
  69. static struct pci_driver pwm_lpss_driver_pci = {
  70. .name = "pwm-lpss",
  71. .id_table = pwm_lpss_pci_ids,
  72. .probe = pwm_lpss_probe_pci,
  73. .remove = pwm_lpss_remove_pci,
  74. .driver = {
  75. .pm = pm_ptr(&pwm_lpss_pci_pm),
  76. },
  77. };
  78. module_pci_driver(pwm_lpss_driver_pci);
  79. MODULE_DESCRIPTION("PWM PCI driver for Intel LPSS");
  80. MODULE_LICENSE("GPL v2");
  81. MODULE_IMPORT_NS(PWM_LPSS);