pwm-lpss-pci.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Intel Low Power Subsystem PWM controller PCI driver
  3. *
  4. * Copyright (C) 2014, Intel Corporation
  5. *
  6. * Derived from the original pwm-lpss.c
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/module.h>
  14. #include <linux/pci.h>
  15. #include <linux/pm_runtime.h>
  16. #include "pwm-lpss.h"
  17. /* BayTrail */
  18. static const struct pwm_lpss_boardinfo pwm_lpss_byt_info = {
  19. .clk_rate = 25000000,
  20. .npwm = 1,
  21. .base_unit_bits = 16,
  22. };
  23. /* Braswell */
  24. static const struct pwm_lpss_boardinfo pwm_lpss_bsw_info = {
  25. .clk_rate = 19200000,
  26. .npwm = 1,
  27. .base_unit_bits = 16,
  28. };
  29. /* Broxton */
  30. static const struct pwm_lpss_boardinfo pwm_lpss_bxt_info = {
  31. .clk_rate = 19200000,
  32. .npwm = 4,
  33. .base_unit_bits = 22,
  34. .bypass = true,
  35. };
  36. /* Tangier */
  37. static const struct pwm_lpss_boardinfo pwm_lpss_tng_info = {
  38. .clk_rate = 19200000,
  39. .npwm = 4,
  40. .base_unit_bits = 22,
  41. };
  42. static int pwm_lpss_probe_pci(struct pci_dev *pdev,
  43. const struct pci_device_id *id)
  44. {
  45. const struct pwm_lpss_boardinfo *info;
  46. struct pwm_lpss_chip *lpwm;
  47. int err;
  48. err = pcim_enable_device(pdev);
  49. if (err < 0)
  50. return err;
  51. info = (struct pwm_lpss_boardinfo *)id->driver_data;
  52. lpwm = pwm_lpss_probe(&pdev->dev, &pdev->resource[0], info);
  53. if (IS_ERR(lpwm))
  54. return PTR_ERR(lpwm);
  55. pci_set_drvdata(pdev, lpwm);
  56. pm_runtime_put(&pdev->dev);
  57. pm_runtime_allow(&pdev->dev);
  58. return 0;
  59. }
  60. static void pwm_lpss_remove_pci(struct pci_dev *pdev)
  61. {
  62. struct pwm_lpss_chip *lpwm = pci_get_drvdata(pdev);
  63. pm_runtime_forbid(&pdev->dev);
  64. pm_runtime_get_sync(&pdev->dev);
  65. pwm_lpss_remove(lpwm);
  66. }
  67. #ifdef CONFIG_PM
  68. static int pwm_lpss_runtime_suspend_pci(struct device *dev)
  69. {
  70. /*
  71. * The PCI core will handle transition to D3 automatically. We only
  72. * need to provide runtime PM hooks for that to happen.
  73. */
  74. return 0;
  75. }
  76. static int pwm_lpss_runtime_resume_pci(struct device *dev)
  77. {
  78. return 0;
  79. }
  80. #endif
  81. static const struct dev_pm_ops pwm_lpss_pci_pm = {
  82. SET_RUNTIME_PM_OPS(pwm_lpss_runtime_suspend_pci,
  83. pwm_lpss_runtime_resume_pci, NULL)
  84. };
  85. static const struct pci_device_id pwm_lpss_pci_ids[] = {
  86. { PCI_VDEVICE(INTEL, 0x0ac8), (unsigned long)&pwm_lpss_bxt_info},
  87. { PCI_VDEVICE(INTEL, 0x0f08), (unsigned long)&pwm_lpss_byt_info},
  88. { PCI_VDEVICE(INTEL, 0x0f09), (unsigned long)&pwm_lpss_byt_info},
  89. { PCI_VDEVICE(INTEL, 0x11a5), (unsigned long)&pwm_lpss_tng_info},
  90. { PCI_VDEVICE(INTEL, 0x1ac8), (unsigned long)&pwm_lpss_bxt_info},
  91. { PCI_VDEVICE(INTEL, 0x2288), (unsigned long)&pwm_lpss_bsw_info},
  92. { PCI_VDEVICE(INTEL, 0x2289), (unsigned long)&pwm_lpss_bsw_info},
  93. { PCI_VDEVICE(INTEL, 0x31c8), (unsigned long)&pwm_lpss_bxt_info},
  94. { PCI_VDEVICE(INTEL, 0x5ac8), (unsigned long)&pwm_lpss_bxt_info},
  95. { },
  96. };
  97. MODULE_DEVICE_TABLE(pci, pwm_lpss_pci_ids);
  98. static struct pci_driver pwm_lpss_driver_pci = {
  99. .name = "pwm-lpss",
  100. .id_table = pwm_lpss_pci_ids,
  101. .probe = pwm_lpss_probe_pci,
  102. .remove = pwm_lpss_remove_pci,
  103. .driver = {
  104. .pm = &pwm_lpss_pci_pm,
  105. },
  106. };
  107. module_pci_driver(pwm_lpss_driver_pci);
  108. MODULE_DESCRIPTION("PWM PCI driver for Intel LPSS");
  109. MODULE_LICENSE("GPL v2");