t7xx_mhccif.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021, MediaTek Inc.
  4. * Copyright (c) 2021-2022, Intel Corporation.
  5. *
  6. * Authors:
  7. * Haijun Liu <[email protected]>
  8. * Sreehari Kancharla <[email protected]>
  9. *
  10. * Contributors:
  11. * Amir Hanania <[email protected]>
  12. * Ricardo Martinez <[email protected]>
  13. */
  14. #include <linux/bits.h>
  15. #include <linux/completion.h>
  16. #include <linux/dev_printk.h>
  17. #include <linux/io.h>
  18. #include <linux/irqreturn.h>
  19. #include "t7xx_mhccif.h"
  20. #include "t7xx_modem_ops.h"
  21. #include "t7xx_pci.h"
  22. #include "t7xx_pcie_mac.h"
  23. #include "t7xx_reg.h"
  24. #define D2H_INT_SR_ACK (D2H_INT_SUSPEND_ACK | \
  25. D2H_INT_RESUME_ACK | \
  26. D2H_INT_SUSPEND_ACK_AP | \
  27. D2H_INT_RESUME_ACK_AP)
  28. static void t7xx_mhccif_clear_interrupts(struct t7xx_pci_dev *t7xx_dev, u32 mask)
  29. {
  30. void __iomem *mhccif_pbase = t7xx_dev->base_addr.mhccif_rc_base;
  31. /* Clear level 2 interrupt */
  32. iowrite32(mask, mhccif_pbase + REG_EP2RC_SW_INT_ACK);
  33. /* Ensure write is complete */
  34. t7xx_mhccif_read_sw_int_sts(t7xx_dev);
  35. /* Clear level 1 interrupt */
  36. t7xx_pcie_mac_clear_int_status(t7xx_dev, MHCCIF_INT);
  37. }
  38. static irqreturn_t t7xx_mhccif_isr_thread(int irq, void *data)
  39. {
  40. struct t7xx_pci_dev *t7xx_dev = data;
  41. u32 int_status, val;
  42. val = T7XX_L1_1_BIT(1) | T7XX_L1_2_BIT(1);
  43. iowrite32(val, IREG_BASE(t7xx_dev) + DISABLE_ASPM_LOWPWR);
  44. int_status = t7xx_mhccif_read_sw_int_sts(t7xx_dev);
  45. if (int_status & D2H_SW_INT_MASK) {
  46. int ret = t7xx_pci_mhccif_isr(t7xx_dev);
  47. if (ret)
  48. dev_err(&t7xx_dev->pdev->dev, "PCI MHCCIF ISR failure: %d", ret);
  49. }
  50. t7xx_mhccif_clear_interrupts(t7xx_dev, int_status);
  51. if (int_status & D2H_INT_DS_LOCK_ACK)
  52. complete_all(&t7xx_dev->sleep_lock_acquire);
  53. if (int_status & D2H_INT_SR_ACK)
  54. complete(&t7xx_dev->pm_sr_ack);
  55. iowrite32(T7XX_L1_BIT(1), IREG_BASE(t7xx_dev) + ENABLE_ASPM_LOWPWR);
  56. int_status = t7xx_mhccif_read_sw_int_sts(t7xx_dev);
  57. if (!int_status) {
  58. val = T7XX_L1_1_BIT(1) | T7XX_L1_2_BIT(1);
  59. iowrite32(val, IREG_BASE(t7xx_dev) + ENABLE_ASPM_LOWPWR);
  60. }
  61. t7xx_pcie_mac_set_int(t7xx_dev, MHCCIF_INT);
  62. return IRQ_HANDLED;
  63. }
  64. u32 t7xx_mhccif_read_sw_int_sts(struct t7xx_pci_dev *t7xx_dev)
  65. {
  66. return ioread32(t7xx_dev->base_addr.mhccif_rc_base + REG_EP2RC_SW_INT_STS);
  67. }
  68. void t7xx_mhccif_mask_set(struct t7xx_pci_dev *t7xx_dev, u32 val)
  69. {
  70. iowrite32(val, t7xx_dev->base_addr.mhccif_rc_base + REG_EP2RC_SW_INT_EAP_MASK_SET);
  71. }
  72. void t7xx_mhccif_mask_clr(struct t7xx_pci_dev *t7xx_dev, u32 val)
  73. {
  74. iowrite32(val, t7xx_dev->base_addr.mhccif_rc_base + REG_EP2RC_SW_INT_EAP_MASK_CLR);
  75. }
  76. u32 t7xx_mhccif_mask_get(struct t7xx_pci_dev *t7xx_dev)
  77. {
  78. return ioread32(t7xx_dev->base_addr.mhccif_rc_base + REG_EP2RC_SW_INT_EAP_MASK);
  79. }
  80. static irqreturn_t t7xx_mhccif_isr_handler(int irq, void *data)
  81. {
  82. return IRQ_WAKE_THREAD;
  83. }
  84. void t7xx_mhccif_init(struct t7xx_pci_dev *t7xx_dev)
  85. {
  86. t7xx_dev->base_addr.mhccif_rc_base = t7xx_dev->base_addr.pcie_ext_reg_base +
  87. MHCCIF_RC_DEV_BASE -
  88. t7xx_dev->base_addr.pcie_dev_reg_trsl_addr;
  89. t7xx_dev->intr_handler[MHCCIF_INT] = t7xx_mhccif_isr_handler;
  90. t7xx_dev->intr_thread[MHCCIF_INT] = t7xx_mhccif_isr_thread;
  91. t7xx_dev->callback_param[MHCCIF_INT] = t7xx_dev;
  92. }
  93. void t7xx_mhccif_h2d_swint_trigger(struct t7xx_pci_dev *t7xx_dev, u32 channel)
  94. {
  95. void __iomem *mhccif_pbase = t7xx_dev->base_addr.mhccif_rc_base;
  96. iowrite32(BIT(channel), mhccif_pbase + REG_RC2EP_SW_BSY);
  97. iowrite32(channel, mhccif_pbase + REG_RC2EP_SW_TCHNUM);
  98. }