|
| 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 | + |
| 8 | + * Sreehari Kancharla <[email protected]> |
| 9 | + * |
| 10 | + * Contributors: |
| 11 | + * Amir Hanania <[email protected]> |
| 12 | + * Ricardo Martinez <[email protected]> |
| 13 | + */ |
| 14 | + |
| 15 | +#include <linux/bits.h> |
| 16 | +#include <linux/completion.h> |
| 17 | +#include <linux/dev_printk.h> |
| 18 | +#include <linux/io.h> |
| 19 | +#include <linux/irqreturn.h> |
| 20 | + |
| 21 | +#include "t7xx_mhccif.h" |
| 22 | +#include "t7xx_modem_ops.h" |
| 23 | +#include "t7xx_pci.h" |
| 24 | +#include "t7xx_pcie_mac.h" |
| 25 | +#include "t7xx_reg.h" |
| 26 | + |
| 27 | +static void t7xx_mhccif_clear_interrupts(struct t7xx_pci_dev *t7xx_dev, u32 mask) |
| 28 | +{ |
| 29 | + void __iomem *mhccif_pbase = t7xx_dev->base_addr.mhccif_rc_base; |
| 30 | + |
| 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 | + |
| 39 | +static irqreturn_t t7xx_mhccif_isr_thread(int irq, void *data) |
| 40 | +{ |
| 41 | + struct t7xx_pci_dev *t7xx_dev = data; |
| 42 | + u32 int_status, val; |
| 43 | + |
| 44 | + val = T7XX_L1_1_BIT(1) | T7XX_L1_2_BIT(1); |
| 45 | + iowrite32(val, IREG_BASE(t7xx_dev) + DISABLE_ASPM_LOWPWR); |
| 46 | + |
| 47 | + int_status = t7xx_mhccif_read_sw_int_sts(t7xx_dev); |
| 48 | + if (int_status & D2H_SW_INT_MASK) { |
| 49 | + int ret = t7xx_pci_mhccif_isr(t7xx_dev); |
| 50 | + |
| 51 | + if (ret) |
| 52 | + dev_err(&t7xx_dev->pdev->dev, "PCI MHCCIF ISR failure: %d", ret); |
| 53 | + } |
| 54 | + |
| 55 | + t7xx_mhccif_clear_interrupts(t7xx_dev, int_status); |
| 56 | + t7xx_pcie_mac_set_int(t7xx_dev, MHCCIF_INT); |
| 57 | + return IRQ_HANDLED; |
| 58 | +} |
| 59 | + |
| 60 | +u32 t7xx_mhccif_read_sw_int_sts(struct t7xx_pci_dev *t7xx_dev) |
| 61 | +{ |
| 62 | + return ioread32(t7xx_dev->base_addr.mhccif_rc_base + REG_EP2RC_SW_INT_STS); |
| 63 | +} |
| 64 | + |
| 65 | +void t7xx_mhccif_mask_set(struct t7xx_pci_dev *t7xx_dev, u32 val) |
| 66 | +{ |
| 67 | + iowrite32(val, t7xx_dev->base_addr.mhccif_rc_base + REG_EP2RC_SW_INT_EAP_MASK_SET); |
| 68 | +} |
| 69 | + |
| 70 | +void t7xx_mhccif_mask_clr(struct t7xx_pci_dev *t7xx_dev, u32 val) |
| 71 | +{ |
| 72 | + iowrite32(val, t7xx_dev->base_addr.mhccif_rc_base + REG_EP2RC_SW_INT_EAP_MASK_CLR); |
| 73 | +} |
| 74 | + |
| 75 | +u32 t7xx_mhccif_mask_get(struct t7xx_pci_dev *t7xx_dev) |
| 76 | +{ |
| 77 | + return ioread32(t7xx_dev->base_addr.mhccif_rc_base + REG_EP2RC_SW_INT_EAP_MASK); |
| 78 | +} |
| 79 | + |
| 80 | +static irqreturn_t t7xx_mhccif_isr_handler(int irq, void *data) |
| 81 | +{ |
| 82 | + return IRQ_WAKE_THREAD; |
| 83 | +} |
| 84 | + |
| 85 | +void t7xx_mhccif_init(struct t7xx_pci_dev *t7xx_dev) |
| 86 | +{ |
| 87 | + t7xx_dev->base_addr.mhccif_rc_base = t7xx_dev->base_addr.pcie_ext_reg_base + |
| 88 | + MHCCIF_RC_DEV_BASE - |
| 89 | + t7xx_dev->base_addr.pcie_dev_reg_trsl_addr; |
| 90 | + |
| 91 | + t7xx_dev->intr_handler[MHCCIF_INT] = t7xx_mhccif_isr_handler; |
| 92 | + t7xx_dev->intr_thread[MHCCIF_INT] = t7xx_mhccif_isr_thread; |
| 93 | + t7xx_dev->callback_param[MHCCIF_INT] = t7xx_dev; |
| 94 | +} |
| 95 | + |
| 96 | +void t7xx_mhccif_h2d_swint_trigger(struct t7xx_pci_dev *t7xx_dev, u32 channel) |
| 97 | +{ |
| 98 | + void __iomem *mhccif_pbase = t7xx_dev->base_addr.mhccif_rc_base; |
| 99 | + |
| 100 | + iowrite32(BIT(channel), mhccif_pbase + REG_RC2EP_SW_BSY); |
| 101 | + iowrite32(channel, mhccif_pbase + REG_RC2EP_SW_TCHNUM); |
| 102 | +} |
0 commit comments