intel_bxtwc_tmu.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Intel BXT Whiskey Cove PMIC TMU driver
  4. *
  5. * Copyright (C) 2016 Intel Corporation. All rights reserved.
  6. *
  7. * This driver adds TMU (Time Management Unit) support for Intel BXT platform.
  8. * It enables the alarm wake-up functionality in the TMU unit of Whiskey Cove
  9. * PMIC.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/mod_devicetable.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/mfd/intel_soc_pmic.h>
  16. #define BXTWC_TMUIRQ 0x4fb6
  17. #define BXTWC_MIRQLVL1 0x4e0e
  18. #define BXTWC_MTMUIRQ_REG 0x4fb7
  19. #define BXTWC_MIRQLVL1_MTMU BIT(1)
  20. #define BXTWC_TMU_WK_ALRM BIT(1)
  21. #define BXTWC_TMU_SYS_ALRM BIT(2)
  22. #define BXTWC_TMU_ALRM_MASK (BXTWC_TMU_WK_ALRM | BXTWC_TMU_SYS_ALRM)
  23. #define BXTWC_TMU_ALRM_IRQ (BXTWC_TMU_WK_ALRM | BXTWC_TMU_SYS_ALRM)
  24. struct wcove_tmu {
  25. int irq;
  26. struct device *dev;
  27. struct regmap *regmap;
  28. };
  29. static irqreturn_t bxt_wcove_tmu_irq_handler(int irq, void *data)
  30. {
  31. struct wcove_tmu *wctmu = data;
  32. unsigned int tmu_irq;
  33. /* Read TMU interrupt reg */
  34. regmap_read(wctmu->regmap, BXTWC_TMUIRQ, &tmu_irq);
  35. if (tmu_irq & BXTWC_TMU_ALRM_IRQ) {
  36. /* clear TMU irq */
  37. regmap_write(wctmu->regmap, BXTWC_TMUIRQ, tmu_irq);
  38. return IRQ_HANDLED;
  39. }
  40. return IRQ_NONE;
  41. }
  42. static int bxt_wcove_tmu_probe(struct platform_device *pdev)
  43. {
  44. struct intel_soc_pmic *pmic = dev_get_drvdata(pdev->dev.parent);
  45. struct regmap_irq_chip_data *regmap_irq_chip;
  46. struct wcove_tmu *wctmu;
  47. int ret, virq, irq;
  48. wctmu = devm_kzalloc(&pdev->dev, sizeof(*wctmu), GFP_KERNEL);
  49. if (!wctmu)
  50. return -ENOMEM;
  51. wctmu->dev = &pdev->dev;
  52. wctmu->regmap = pmic->regmap;
  53. irq = platform_get_irq(pdev, 0);
  54. if (irq < 0)
  55. return irq;
  56. regmap_irq_chip = pmic->irq_chip_data_tmu;
  57. virq = regmap_irq_get_virq(regmap_irq_chip, irq);
  58. if (virq < 0) {
  59. dev_err(&pdev->dev,
  60. "failed to get virtual interrupt=%d\n", irq);
  61. return virq;
  62. }
  63. ret = devm_request_threaded_irq(&pdev->dev, virq,
  64. NULL, bxt_wcove_tmu_irq_handler,
  65. IRQF_ONESHOT, "bxt_wcove_tmu", wctmu);
  66. if (ret) {
  67. dev_err(&pdev->dev, "request irq failed: %d,virq: %d\n",
  68. ret, virq);
  69. return ret;
  70. }
  71. wctmu->irq = virq;
  72. /* Unmask TMU second level Wake & System alarm */
  73. regmap_update_bits(wctmu->regmap, BXTWC_MTMUIRQ_REG,
  74. BXTWC_TMU_ALRM_MASK, 0);
  75. platform_set_drvdata(pdev, wctmu);
  76. return 0;
  77. }
  78. static int bxt_wcove_tmu_remove(struct platform_device *pdev)
  79. {
  80. struct wcove_tmu *wctmu = platform_get_drvdata(pdev);
  81. unsigned int val;
  82. /* Mask TMU interrupts */
  83. regmap_read(wctmu->regmap, BXTWC_MIRQLVL1, &val);
  84. regmap_write(wctmu->regmap, BXTWC_MIRQLVL1,
  85. val | BXTWC_MIRQLVL1_MTMU);
  86. regmap_read(wctmu->regmap, BXTWC_MTMUIRQ_REG, &val);
  87. regmap_write(wctmu->regmap, BXTWC_MTMUIRQ_REG,
  88. val | BXTWC_TMU_ALRM_MASK);
  89. return 0;
  90. }
  91. #ifdef CONFIG_PM_SLEEP
  92. static int bxtwc_tmu_suspend(struct device *dev)
  93. {
  94. struct wcove_tmu *wctmu = dev_get_drvdata(dev);
  95. enable_irq_wake(wctmu->irq);
  96. return 0;
  97. }
  98. static int bxtwc_tmu_resume(struct device *dev)
  99. {
  100. struct wcove_tmu *wctmu = dev_get_drvdata(dev);
  101. disable_irq_wake(wctmu->irq);
  102. return 0;
  103. }
  104. #endif
  105. static SIMPLE_DEV_PM_OPS(bxtwc_tmu_pm_ops, bxtwc_tmu_suspend, bxtwc_tmu_resume);
  106. static const struct platform_device_id bxt_wcove_tmu_id_table[] = {
  107. { .name = "bxt_wcove_tmu" },
  108. {},
  109. };
  110. MODULE_DEVICE_TABLE(platform, bxt_wcove_tmu_id_table);
  111. static struct platform_driver bxt_wcove_tmu_driver = {
  112. .probe = bxt_wcove_tmu_probe,
  113. .remove = bxt_wcove_tmu_remove,
  114. .driver = {
  115. .name = "bxt_wcove_tmu",
  116. .pm = &bxtwc_tmu_pm_ops,
  117. },
  118. .id_table = bxt_wcove_tmu_id_table,
  119. };
  120. module_platform_driver(bxt_wcove_tmu_driver);
  121. MODULE_LICENSE("GPL v2");
  122. MODULE_AUTHOR("Nilesh Bacchewar <nilesh.bacchewar@intel.com>");
  123. MODULE_DESCRIPTION("BXT Whiskey Cove TMU Driver");