Bjorn Helgaas | 8cfab3c | 2018-01-26 12:50:27 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Driver for the Aardvark PCIe controller, used on Marvell Armada |
| 4 | * 3700. |
| 5 | * |
| 6 | * Copyright (C) 2016 Marvell |
| 7 | * |
Bjorn Helgaas | a04bee8 | 2016-08-01 12:32:13 -0500 | [diff] [blame] | 8 | * Author: Hezi Shahmoon <hezi.shahmoon@marvell.com> |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <linux/delay.h> |
Pali Rohár | b32c012 | 2020-09-07 13:10:34 +0200 | [diff] [blame] | 12 | #include <linux/gpio/consumer.h> |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 13 | #include <linux/interrupt.h> |
| 14 | #include <linux/irq.h> |
| 15 | #include <linux/irqdomain.h> |
| 16 | #include <linux/kernel.h> |
Pali Rohár | 526a769 | 2020-09-07 13:10:37 +0200 | [diff] [blame] | 17 | #include <linux/module.h> |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 18 | #include <linux/pci.h> |
Krzysztof Wilczyński | e7708f5 | 2020-11-29 23:07:39 +0000 | [diff] [blame] | 19 | #include <linux/pci-ecam.h> |
Bjorn Helgaas | a04bee8 | 2016-08-01 12:32:13 -0500 | [diff] [blame] | 20 | #include <linux/init.h> |
Marek Behún | 3666970 | 2020-04-30 10:06:20 +0200 | [diff] [blame] | 21 | #include <linux/phy/phy.h> |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 22 | #include <linux/platform_device.h> |
Krzysztof Wilczynski | bbd8810d | 2019-09-03 13:30:59 +0200 | [diff] [blame] | 23 | #include <linux/msi.h> |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 24 | #include <linux/of_address.h> |
Pali Rohár | 5169a98 | 2020-04-30 10:06:18 +0200 | [diff] [blame] | 25 | #include <linux/of_gpio.h> |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 26 | #include <linux/of_pci.h> |
| 27 | |
Rob Herring | 9e2aee8 | 2018-05-11 12:15:30 -0500 | [diff] [blame] | 28 | #include "../pci.h" |
Zachary Zhang | 8a3ebd8 | 2018-10-18 17:37:19 +0200 | [diff] [blame] | 29 | #include "../pci-bridge-emul.h" |
Rob Herring | 9e2aee8 | 2018-05-11 12:15:30 -0500 | [diff] [blame] | 30 | |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 31 | /* PCIe core registers */ |
Zachary Zhang | 8a3ebd8 | 2018-10-18 17:37:19 +0200 | [diff] [blame] | 32 | #define PCIE_CORE_DEV_ID_REG 0x0 |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 33 | #define PCIE_CORE_CMD_STATUS_REG 0x4 |
| 34 | #define PCIE_CORE_CMD_IO_ACCESS_EN BIT(0) |
| 35 | #define PCIE_CORE_CMD_MEM_ACCESS_EN BIT(1) |
| 36 | #define PCIE_CORE_CMD_MEM_IO_REQ_EN BIT(2) |
Zachary Zhang | 8a3ebd8 | 2018-10-18 17:37:19 +0200 | [diff] [blame] | 37 | #define PCIE_CORE_DEV_REV_REG 0x8 |
| 38 | #define PCIE_CORE_PCIEXP_CAP 0xc0 |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 39 | #define PCIE_CORE_ERR_CAPCTL_REG 0x118 |
| 40 | #define PCIE_CORE_ERR_CAPCTL_ECRC_CHK_TX BIT(5) |
| 41 | #define PCIE_CORE_ERR_CAPCTL_ECRC_CHK_TX_EN BIT(6) |
| 42 | #define PCIE_CORE_ERR_CAPCTL_ECRC_CHCK BIT(7) |
| 43 | #define PCIE_CORE_ERR_CAPCTL_ECRC_CHCK_RCV BIT(8) |
Zachary Zhang | 8a3ebd8 | 2018-10-18 17:37:19 +0200 | [diff] [blame] | 44 | #define PCIE_CORE_INT_A_ASSERT_ENABLE 1 |
| 45 | #define PCIE_CORE_INT_B_ASSERT_ENABLE 2 |
| 46 | #define PCIE_CORE_INT_C_ASSERT_ENABLE 3 |
| 47 | #define PCIE_CORE_INT_D_ASSERT_ENABLE 4 |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 48 | /* PIO registers base address and register offsets */ |
| 49 | #define PIO_BASE_ADDR 0x4000 |
| 50 | #define PIO_CTRL (PIO_BASE_ADDR + 0x0) |
| 51 | #define PIO_CTRL_TYPE_MASK GENMASK(3, 0) |
| 52 | #define PIO_CTRL_ADDR_WIN_DISABLE BIT(24) |
| 53 | #define PIO_STAT (PIO_BASE_ADDR + 0x4) |
| 54 | #define PIO_COMPLETION_STATUS_SHIFT 7 |
| 55 | #define PIO_COMPLETION_STATUS_MASK GENMASK(9, 7) |
| 56 | #define PIO_COMPLETION_STATUS_OK 0 |
| 57 | #define PIO_COMPLETION_STATUS_UR 1 |
| 58 | #define PIO_COMPLETION_STATUS_CRS 2 |
| 59 | #define PIO_COMPLETION_STATUS_CA 4 |
Pali Rohár | 8ceeac3 | 2021-06-24 23:33:43 +0200 | [diff] [blame] | 60 | #define PIO_NON_POSTED_REQ BIT(10) |
Evan Wang | fcb461e | 2021-07-22 16:40:38 +0200 | [diff] [blame] | 61 | #define PIO_ERR_STATUS BIT(11) |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 62 | #define PIO_ADDR_LS (PIO_BASE_ADDR + 0x8) |
| 63 | #define PIO_ADDR_MS (PIO_BASE_ADDR + 0xc) |
| 64 | #define PIO_WR_DATA (PIO_BASE_ADDR + 0x10) |
| 65 | #define PIO_WR_DATA_STRB (PIO_BASE_ADDR + 0x14) |
| 66 | #define PIO_RD_DATA (PIO_BASE_ADDR + 0x18) |
| 67 | #define PIO_START (PIO_BASE_ADDR + 0x1c) |
| 68 | #define PIO_ISR (PIO_BASE_ADDR + 0x20) |
| 69 | #define PIO_ISRM (PIO_BASE_ADDR + 0x24) |
| 70 | |
| 71 | /* Aardvark Control registers */ |
| 72 | #define CONTROL_BASE_ADDR 0x4800 |
| 73 | #define PCIE_CORE_CTRL0_REG (CONTROL_BASE_ADDR + 0x0) |
| 74 | #define PCIE_GEN_SEL_MSK 0x3 |
| 75 | #define PCIE_GEN_SEL_SHIFT 0x0 |
| 76 | #define SPEED_GEN_1 0 |
| 77 | #define SPEED_GEN_2 1 |
| 78 | #define SPEED_GEN_3 2 |
| 79 | #define IS_RC_MSK 1 |
| 80 | #define IS_RC_SHIFT 2 |
| 81 | #define LANE_CNT_MSK 0x18 |
| 82 | #define LANE_CNT_SHIFT 0x3 |
| 83 | #define LANE_COUNT_1 (0 << LANE_CNT_SHIFT) |
| 84 | #define LANE_COUNT_2 (1 << LANE_CNT_SHIFT) |
| 85 | #define LANE_COUNT_4 (2 << LANE_CNT_SHIFT) |
| 86 | #define LANE_COUNT_8 (3 << LANE_CNT_SHIFT) |
| 87 | #define LINK_TRAINING_EN BIT(6) |
| 88 | #define LEGACY_INTA BIT(28) |
| 89 | #define LEGACY_INTB BIT(29) |
| 90 | #define LEGACY_INTC BIT(30) |
| 91 | #define LEGACY_INTD BIT(31) |
| 92 | #define PCIE_CORE_CTRL1_REG (CONTROL_BASE_ADDR + 0x4) |
| 93 | #define HOT_RESET_GEN BIT(0) |
| 94 | #define PCIE_CORE_CTRL2_REG (CONTROL_BASE_ADDR + 0x8) |
| 95 | #define PCIE_CORE_CTRL2_RESERVED 0x7 |
| 96 | #define PCIE_CORE_CTRL2_TD_ENABLE BIT(4) |
| 97 | #define PCIE_CORE_CTRL2_STRICT_ORDER_ENABLE BIT(5) |
| 98 | #define PCIE_CORE_CTRL2_OB_WIN_ENABLE BIT(6) |
| 99 | #define PCIE_CORE_CTRL2_MSI_ENABLE BIT(10) |
Marek Behún | 3666970 | 2020-04-30 10:06:20 +0200 | [diff] [blame] | 100 | #define PCIE_CORE_REF_CLK_REG (CONTROL_BASE_ADDR + 0x14) |
| 101 | #define PCIE_CORE_REF_CLK_TX_ENABLE BIT(1) |
Pali Rohár | 46ef609 | 2021-10-05 20:09:44 +0200 | [diff] [blame^] | 102 | #define PCIE_CORE_REF_CLK_RX_ENABLE BIT(2) |
Zachary Zhang | 8a3ebd8 | 2018-10-18 17:37:19 +0200 | [diff] [blame] | 103 | #define PCIE_MSG_LOG_REG (CONTROL_BASE_ADDR + 0x30) |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 104 | #define PCIE_ISR0_REG (CONTROL_BASE_ADDR + 0x40) |
Zachary Zhang | 8a3ebd8 | 2018-10-18 17:37:19 +0200 | [diff] [blame] | 105 | #define PCIE_MSG_PM_PME_MASK BIT(7) |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 106 | #define PCIE_ISR0_MASK_REG (CONTROL_BASE_ADDR + 0x44) |
| 107 | #define PCIE_ISR0_MSI_INT_PENDING BIT(24) |
| 108 | #define PCIE_ISR0_INTX_ASSERT(val) BIT(16 + (val)) |
| 109 | #define PCIE_ISR0_INTX_DEASSERT(val) BIT(20 + (val)) |
| 110 | #define PCIE_ISR0_ALL_MASK GENMASK(26, 0) |
| 111 | #define PCIE_ISR1_REG (CONTROL_BASE_ADDR + 0x48) |
| 112 | #define PCIE_ISR1_MASK_REG (CONTROL_BASE_ADDR + 0x4C) |
| 113 | #define PCIE_ISR1_POWER_STATE_CHANGE BIT(4) |
| 114 | #define PCIE_ISR1_FLUSH BIT(5) |
Victor Gu | 3430f92 | 2018-04-06 16:55:33 +0200 | [diff] [blame] | 115 | #define PCIE_ISR1_INTX_ASSERT(val) BIT(8 + (val)) |
| 116 | #define PCIE_ISR1_ALL_MASK GENMASK(11, 4) |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 117 | #define PCIE_MSI_ADDR_LOW_REG (CONTROL_BASE_ADDR + 0x50) |
| 118 | #define PCIE_MSI_ADDR_HIGH_REG (CONTROL_BASE_ADDR + 0x54) |
| 119 | #define PCIE_MSI_STATUS_REG (CONTROL_BASE_ADDR + 0x58) |
| 120 | #define PCIE_MSI_MASK_REG (CONTROL_BASE_ADDR + 0x5C) |
| 121 | #define PCIE_MSI_PAYLOAD_REG (CONTROL_BASE_ADDR + 0x9C) |
| 122 | |
Pali Rohár | 64f160e | 2021-06-24 23:55:45 +0200 | [diff] [blame] | 123 | /* PCIe window configuration */ |
| 124 | #define OB_WIN_BASE_ADDR 0x4c00 |
| 125 | #define OB_WIN_BLOCK_SIZE 0x20 |
| 126 | #define OB_WIN_COUNT 8 |
| 127 | #define OB_WIN_REG_ADDR(win, offset) (OB_WIN_BASE_ADDR + \ |
| 128 | OB_WIN_BLOCK_SIZE * (win) + \ |
| 129 | (offset)) |
| 130 | #define OB_WIN_MATCH_LS(win) OB_WIN_REG_ADDR(win, 0x00) |
| 131 | #define OB_WIN_ENABLE BIT(0) |
| 132 | #define OB_WIN_MATCH_MS(win) OB_WIN_REG_ADDR(win, 0x04) |
| 133 | #define OB_WIN_REMAP_LS(win) OB_WIN_REG_ADDR(win, 0x08) |
| 134 | #define OB_WIN_REMAP_MS(win) OB_WIN_REG_ADDR(win, 0x0c) |
| 135 | #define OB_WIN_MASK_LS(win) OB_WIN_REG_ADDR(win, 0x10) |
| 136 | #define OB_WIN_MASK_MS(win) OB_WIN_REG_ADDR(win, 0x14) |
| 137 | #define OB_WIN_ACTIONS(win) OB_WIN_REG_ADDR(win, 0x18) |
| 138 | #define OB_WIN_DEFAULT_ACTIONS (OB_WIN_ACTIONS(OB_WIN_COUNT-1) + 0x4) |
| 139 | #define OB_WIN_FUNC_NUM_MASK GENMASK(31, 24) |
| 140 | #define OB_WIN_FUNC_NUM_SHIFT 24 |
| 141 | #define OB_WIN_FUNC_NUM_ENABLE BIT(23) |
| 142 | #define OB_WIN_BUS_NUM_BITS_MASK GENMASK(22, 20) |
| 143 | #define OB_WIN_BUS_NUM_BITS_SHIFT 20 |
| 144 | #define OB_WIN_MSG_CODE_ENABLE BIT(22) |
| 145 | #define OB_WIN_MSG_CODE_MASK GENMASK(21, 14) |
| 146 | #define OB_WIN_MSG_CODE_SHIFT 14 |
| 147 | #define OB_WIN_MSG_PAYLOAD_LEN BIT(12) |
| 148 | #define OB_WIN_ATTR_ENABLE BIT(11) |
| 149 | #define OB_WIN_ATTR_TC_MASK GENMASK(10, 8) |
| 150 | #define OB_WIN_ATTR_TC_SHIFT 8 |
| 151 | #define OB_WIN_ATTR_RELAXED BIT(7) |
| 152 | #define OB_WIN_ATTR_NOSNOOP BIT(6) |
| 153 | #define OB_WIN_ATTR_POISON BIT(5) |
| 154 | #define OB_WIN_ATTR_IDO BIT(4) |
| 155 | #define OB_WIN_TYPE_MASK GENMASK(3, 0) |
| 156 | #define OB_WIN_TYPE_SHIFT 0 |
| 157 | #define OB_WIN_TYPE_MEM 0x0 |
| 158 | #define OB_WIN_TYPE_IO 0x4 |
| 159 | #define OB_WIN_TYPE_CONFIG_TYPE0 0x8 |
| 160 | #define OB_WIN_TYPE_CONFIG_TYPE1 0x9 |
| 161 | #define OB_WIN_TYPE_MSG 0xc |
| 162 | |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 163 | /* LMI registers base address and register offsets */ |
| 164 | #define LMI_BASE_ADDR 0x6000 |
| 165 | #define CFG_REG (LMI_BASE_ADDR + 0x0) |
| 166 | #define LTSSM_SHIFT 24 |
| 167 | #define LTSSM_MASK 0x3f |
| 168 | #define LTSSM_L0 0x10 |
| 169 | #define RC_BAR_CONFIG 0x300 |
Pali Rohár | 7f71a40 | 2021-06-25 00:26:20 +0200 | [diff] [blame] | 170 | #define VENDOR_ID_REG (LMI_BASE_ADDR + 0x44) |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 171 | |
| 172 | /* PCIe core controller registers */ |
| 173 | #define CTRL_CORE_BASE_ADDR 0x18000 |
| 174 | #define CTRL_CONFIG_REG (CTRL_CORE_BASE_ADDR + 0x0) |
| 175 | #define CTRL_MODE_SHIFT 0x0 |
| 176 | #define CTRL_MODE_MASK 0x1 |
| 177 | #define PCIE_CORE_MODE_DIRECT 0x0 |
| 178 | #define PCIE_CORE_MODE_COMMAND 0x1 |
| 179 | |
| 180 | /* PCIe Central Interrupts Registers */ |
| 181 | #define CENTRAL_INT_BASE_ADDR 0x1b000 |
| 182 | #define HOST_CTRL_INT_STATUS_REG (CENTRAL_INT_BASE_ADDR + 0x0) |
| 183 | #define HOST_CTRL_INT_MASK_REG (CENTRAL_INT_BASE_ADDR + 0x4) |
| 184 | #define PCIE_IRQ_CMDQ_INT BIT(0) |
| 185 | #define PCIE_IRQ_MSI_STATUS_INT BIT(1) |
| 186 | #define PCIE_IRQ_CMD_SENT_DONE BIT(3) |
| 187 | #define PCIE_IRQ_DMA_INT BIT(4) |
| 188 | #define PCIE_IRQ_IB_DXFERDONE BIT(5) |
| 189 | #define PCIE_IRQ_OB_DXFERDONE BIT(6) |
| 190 | #define PCIE_IRQ_OB_RXFERDONE BIT(7) |
| 191 | #define PCIE_IRQ_COMPQ_INT BIT(12) |
| 192 | #define PCIE_IRQ_DIR_RD_DDR_DET BIT(13) |
| 193 | #define PCIE_IRQ_DIR_WR_DDR_DET BIT(14) |
| 194 | #define PCIE_IRQ_CORE_INT BIT(16) |
| 195 | #define PCIE_IRQ_CORE_INT_PIO BIT(17) |
| 196 | #define PCIE_IRQ_DPMU_INT BIT(18) |
| 197 | #define PCIE_IRQ_PCIE_MIS_INT BIT(19) |
| 198 | #define PCIE_IRQ_MSI_INT1_DET BIT(20) |
| 199 | #define PCIE_IRQ_MSI_INT2_DET BIT(21) |
| 200 | #define PCIE_IRQ_RC_DBELL_DET BIT(22) |
| 201 | #define PCIE_IRQ_EP_STATUS BIT(23) |
| 202 | #define PCIE_IRQ_ALL_MASK 0xfff0fb |
| 203 | #define PCIE_IRQ_ENABLE_INTS_MASK PCIE_IRQ_CORE_INT |
| 204 | |
| 205 | /* Transaction types */ |
| 206 | #define PCIE_CONFIG_RD_TYPE0 0x8 |
| 207 | #define PCIE_CONFIG_RD_TYPE1 0x9 |
| 208 | #define PCIE_CONFIG_WR_TYPE0 0xa |
| 209 | #define PCIE_CONFIG_WR_TYPE1 0xb |
| 210 | |
Pali Rohár | 02bcec3 | 2021-07-22 16:40:39 +0200 | [diff] [blame] | 211 | #define PIO_RETRY_CNT 750000 /* 1.5 s */ |
Remi Pommarel | 7fbcb5d | 2019-09-27 10:55:02 +0200 | [diff] [blame] | 212 | #define PIO_RETRY_DELAY 2 /* 2 us*/ |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 213 | |
| 214 | #define LINK_WAIT_MAX_RETRIES 10 |
| 215 | #define LINK_WAIT_USLEEP_MIN 90000 |
| 216 | #define LINK_WAIT_USLEEP_MAX 100000 |
Remi Pommarel | 364b3f1 | 2019-05-22 23:33:51 +0200 | [diff] [blame] | 217 | #define RETRAIN_WAIT_MAX_RETRIES 10 |
| 218 | #define RETRAIN_WAIT_USLEEP_US 2000 |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 219 | |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 220 | #define MSI_IRQ_NUM 32 |
| 221 | |
Pali Rohár | 43f5c77 | 2021-07-22 16:40:41 +0200 | [diff] [blame] | 222 | #define CFG_RD_CRS_VAL 0xffff0001 |
| 223 | |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 224 | struct advk_pcie { |
| 225 | struct platform_device *pdev; |
| 226 | void __iomem *base; |
Pali Rohár | 64f160e | 2021-06-24 23:55:45 +0200 | [diff] [blame] | 227 | struct { |
| 228 | phys_addr_t match; |
| 229 | phys_addr_t remap; |
| 230 | phys_addr_t mask; |
| 231 | u32 actions; |
| 232 | } wins[OB_WIN_COUNT]; |
| 233 | u8 wins_count; |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 234 | struct irq_domain *irq_domain; |
| 235 | struct irq_chip irq_chip; |
Pali Rohár | d212dce | 2021-08-20 17:50:20 +0200 | [diff] [blame] | 236 | raw_spinlock_t irq_lock; |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 237 | struct irq_domain *msi_domain; |
Thomas Petazzoni | f21a8b1 | 2017-02-28 15:31:14 +0100 | [diff] [blame] | 238 | struct irq_domain *msi_inner_domain; |
| 239 | struct irq_chip msi_bottom_irq_chip; |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 240 | struct irq_chip msi_irq_chip; |
Thomas Petazzoni | f21a8b1 | 2017-02-28 15:31:14 +0100 | [diff] [blame] | 241 | struct msi_domain_info msi_domain_info; |
| 242 | DECLARE_BITMAP(msi_used, MSI_IRQ_NUM); |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 243 | struct mutex msi_used_lock; |
| 244 | u16 msi_msg; |
Marek Behún | 43fc679 | 2020-04-30 10:06:17 +0200 | [diff] [blame] | 245 | int link_gen; |
Zachary Zhang | 8a3ebd8 | 2018-10-18 17:37:19 +0200 | [diff] [blame] | 246 | struct pci_bridge_emul bridge; |
Pali Rohár | 5169a98 | 2020-04-30 10:06:18 +0200 | [diff] [blame] | 247 | struct gpio_desc *reset_gpio; |
Marek Behún | 3666970 | 2020-04-30 10:06:20 +0200 | [diff] [blame] | 248 | struct phy *phy; |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 249 | }; |
| 250 | |
| 251 | static inline void advk_writel(struct advk_pcie *pcie, u32 val, u64 reg) |
| 252 | { |
| 253 | writel(val, pcie->base + reg); |
| 254 | } |
| 255 | |
| 256 | static inline u32 advk_readl(struct advk_pcie *pcie, u64 reg) |
| 257 | { |
| 258 | return readl(pcie->base + reg); |
| 259 | } |
| 260 | |
Pali Rohár | 96be36d | 2020-04-30 10:06:21 +0200 | [diff] [blame] | 261 | static inline u16 advk_read16(struct advk_pcie *pcie, u64 reg) |
| 262 | { |
| 263 | return advk_readl(pcie, (reg & ~0x3)) >> ((reg & 0x3) * 8); |
| 264 | } |
| 265 | |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 266 | static int advk_pcie_link_up(struct advk_pcie *pcie) |
| 267 | { |
| 268 | u32 val, ltssm_state; |
| 269 | |
| 270 | val = advk_readl(pcie, CFG_REG); |
| 271 | ltssm_state = (val >> LTSSM_SHIFT) & LTSSM_MASK; |
| 272 | return ltssm_state >= LTSSM_L0; |
| 273 | } |
| 274 | |
| 275 | static int advk_pcie_wait_for_link(struct advk_pcie *pcie) |
| 276 | { |
| 277 | int retries; |
| 278 | |
| 279 | /* check if the link is up or not */ |
| 280 | for (retries = 0; retries < LINK_WAIT_MAX_RETRIES; retries++) { |
Marek Behún | 43fc679 | 2020-04-30 10:06:17 +0200 | [diff] [blame] | 281 | if (advk_pcie_link_up(pcie)) |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 282 | return 0; |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 283 | |
| 284 | usleep_range(LINK_WAIT_USLEEP_MIN, LINK_WAIT_USLEEP_MAX); |
| 285 | } |
| 286 | |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 287 | return -ETIMEDOUT; |
| 288 | } |
| 289 | |
Remi Pommarel | 364b3f1 | 2019-05-22 23:33:51 +0200 | [diff] [blame] | 290 | static void advk_pcie_wait_for_retrain(struct advk_pcie *pcie) |
| 291 | { |
| 292 | size_t retries; |
| 293 | |
| 294 | for (retries = 0; retries < RETRAIN_WAIT_MAX_RETRIES; ++retries) { |
| 295 | if (!advk_pcie_link_up(pcie)) |
| 296 | break; |
| 297 | udelay(RETRAIN_WAIT_USLEEP_US); |
| 298 | } |
| 299 | } |
| 300 | |
Pali Rohár | d0c6a34 | 2020-09-07 13:10:38 +0200 | [diff] [blame] | 301 | static void advk_pcie_issue_perst(struct advk_pcie *pcie) |
| 302 | { |
| 303 | u32 reg; |
| 304 | |
| 305 | if (!pcie->reset_gpio) |
| 306 | return; |
| 307 | |
Pali Rohár | 1d1cd16 | 2020-12-02 19:46:59 +0100 | [diff] [blame] | 308 | /* |
| 309 | * As required by PCI Express spec (PCI Express Base Specification, REV. |
| 310 | * 4.0 PCI Express, February 19 2014, 6.6.1 Conventional Reset) a delay |
| 311 | * for at least 100ms after de-asserting PERST# signal is needed before |
| 312 | * link training is enabled. So ensure that link training is disabled |
| 313 | * prior de-asserting PERST# signal to fulfill that PCI Express spec |
| 314 | * requirement. |
| 315 | */ |
Pali Rohár | d0c6a34 | 2020-09-07 13:10:38 +0200 | [diff] [blame] | 316 | reg = advk_readl(pcie, PCIE_CORE_CTRL0_REG); |
| 317 | reg &= ~LINK_TRAINING_EN; |
| 318 | advk_writel(pcie, reg, PCIE_CORE_CTRL0_REG); |
| 319 | |
| 320 | /* 10ms delay is needed for some cards */ |
| 321 | dev_info(&pcie->pdev->dev, "issuing PERST via reset GPIO for 10ms\n"); |
| 322 | gpiod_set_value_cansleep(pcie->reset_gpio, 1); |
| 323 | usleep_range(10000, 11000); |
| 324 | gpiod_set_value_cansleep(pcie->reset_gpio, 0); |
| 325 | } |
| 326 | |
Marek Behún | 43fc679 | 2020-04-30 10:06:17 +0200 | [diff] [blame] | 327 | static int advk_pcie_train_at_gen(struct advk_pcie *pcie, int gen) |
| 328 | { |
| 329 | int ret, neg_gen; |
| 330 | u32 reg; |
| 331 | |
| 332 | /* Setup link speed */ |
| 333 | reg = advk_readl(pcie, PCIE_CORE_CTRL0_REG); |
| 334 | reg &= ~PCIE_GEN_SEL_MSK; |
| 335 | if (gen == 3) |
| 336 | reg |= SPEED_GEN_3; |
| 337 | else if (gen == 2) |
| 338 | reg |= SPEED_GEN_2; |
| 339 | else |
| 340 | reg |= SPEED_GEN_1; |
| 341 | advk_writel(pcie, reg, PCIE_CORE_CTRL0_REG); |
| 342 | |
| 343 | /* |
| 344 | * Enable link training. This is not needed in every call to this |
| 345 | * function, just once suffices, but it does not break anything either. |
| 346 | */ |
| 347 | reg = advk_readl(pcie, PCIE_CORE_CTRL0_REG); |
| 348 | reg |= LINK_TRAINING_EN; |
| 349 | advk_writel(pcie, reg, PCIE_CORE_CTRL0_REG); |
| 350 | |
| 351 | /* |
| 352 | * Start link training immediately after enabling it. |
| 353 | * This solves problems for some buggy cards. |
| 354 | */ |
Pali Rohár | 96be36d | 2020-04-30 10:06:21 +0200 | [diff] [blame] | 355 | reg = advk_readl(pcie, PCIE_CORE_PCIEXP_CAP + PCI_EXP_LNKCTL); |
| 356 | reg |= PCI_EXP_LNKCTL_RL; |
| 357 | advk_writel(pcie, reg, PCIE_CORE_PCIEXP_CAP + PCI_EXP_LNKCTL); |
Marek Behún | 43fc679 | 2020-04-30 10:06:17 +0200 | [diff] [blame] | 358 | |
| 359 | ret = advk_pcie_wait_for_link(pcie); |
| 360 | if (ret) |
| 361 | return ret; |
| 362 | |
Pali Rohár | 96be36d | 2020-04-30 10:06:21 +0200 | [diff] [blame] | 363 | reg = advk_read16(pcie, PCIE_CORE_PCIEXP_CAP + PCI_EXP_LNKSTA); |
| 364 | neg_gen = reg & PCI_EXP_LNKSTA_CLS; |
Marek Behún | 43fc679 | 2020-04-30 10:06:17 +0200 | [diff] [blame] | 365 | |
| 366 | return neg_gen; |
| 367 | } |
| 368 | |
| 369 | static void advk_pcie_train_link(struct advk_pcie *pcie) |
| 370 | { |
| 371 | struct device *dev = &pcie->pdev->dev; |
| 372 | int neg_gen = -1, gen; |
| 373 | |
| 374 | /* |
Pali Rohár | d0c6a34 | 2020-09-07 13:10:38 +0200 | [diff] [blame] | 375 | * Reset PCIe card via PERST# signal. Some cards are not detected |
| 376 | * during link training when they are in some non-initial state. |
| 377 | */ |
| 378 | advk_pcie_issue_perst(pcie); |
| 379 | |
| 380 | /* |
| 381 | * PERST# signal could have been asserted by pinctrl subsystem before |
| 382 | * probe() callback has been called or issued explicitly by reset gpio |
| 383 | * function advk_pcie_issue_perst(), making the endpoint going into |
| 384 | * fundamental reset. As required by PCI Express spec a delay for at |
| 385 | * least 100ms after such a reset before link training is needed. |
| 386 | */ |
| 387 | msleep(PCI_PM_D3COLD_WAIT); |
| 388 | |
| 389 | /* |
Marek Behún | 43fc679 | 2020-04-30 10:06:17 +0200 | [diff] [blame] | 390 | * Try link training at link gen specified by device tree property |
| 391 | * 'max-link-speed'. If this fails, iteratively train at lower gen. |
| 392 | */ |
| 393 | for (gen = pcie->link_gen; gen > 0; --gen) { |
| 394 | neg_gen = advk_pcie_train_at_gen(pcie, gen); |
| 395 | if (neg_gen > 0) |
| 396 | break; |
| 397 | } |
| 398 | |
| 399 | if (neg_gen < 0) |
| 400 | goto err; |
| 401 | |
| 402 | /* |
| 403 | * After successful training if negotiated gen is lower than requested, |
| 404 | * train again on negotiated gen. This solves some stability issues for |
| 405 | * some buggy gen1 cards. |
| 406 | */ |
| 407 | if (neg_gen < gen) { |
| 408 | gen = neg_gen; |
| 409 | neg_gen = advk_pcie_train_at_gen(pcie, gen); |
| 410 | } |
| 411 | |
| 412 | if (neg_gen == gen) { |
| 413 | dev_info(dev, "link up at gen %i\n", gen); |
| 414 | return; |
| 415 | } |
| 416 | |
| 417 | err: |
| 418 | dev_err(dev, "link never came up\n"); |
| 419 | } |
| 420 | |
Pali Rohár | 64f160e | 2021-06-24 23:55:45 +0200 | [diff] [blame] | 421 | /* |
| 422 | * Set PCIe address window register which could be used for memory |
| 423 | * mapping. |
| 424 | */ |
| 425 | static void advk_pcie_set_ob_win(struct advk_pcie *pcie, u8 win_num, |
| 426 | phys_addr_t match, phys_addr_t remap, |
| 427 | phys_addr_t mask, u32 actions) |
| 428 | { |
| 429 | advk_writel(pcie, OB_WIN_ENABLE | |
| 430 | lower_32_bits(match), OB_WIN_MATCH_LS(win_num)); |
| 431 | advk_writel(pcie, upper_32_bits(match), OB_WIN_MATCH_MS(win_num)); |
| 432 | advk_writel(pcie, lower_32_bits(remap), OB_WIN_REMAP_LS(win_num)); |
| 433 | advk_writel(pcie, upper_32_bits(remap), OB_WIN_REMAP_MS(win_num)); |
| 434 | advk_writel(pcie, lower_32_bits(mask), OB_WIN_MASK_LS(win_num)); |
| 435 | advk_writel(pcie, upper_32_bits(mask), OB_WIN_MASK_MS(win_num)); |
| 436 | advk_writel(pcie, actions, OB_WIN_ACTIONS(win_num)); |
| 437 | } |
| 438 | |
| 439 | static void advk_pcie_disable_ob_win(struct advk_pcie *pcie, u8 win_num) |
| 440 | { |
| 441 | advk_writel(pcie, 0, OB_WIN_MATCH_LS(win_num)); |
| 442 | advk_writel(pcie, 0, OB_WIN_MATCH_MS(win_num)); |
| 443 | advk_writel(pcie, 0, OB_WIN_REMAP_LS(win_num)); |
| 444 | advk_writel(pcie, 0, OB_WIN_REMAP_MS(win_num)); |
| 445 | advk_writel(pcie, 0, OB_WIN_MASK_LS(win_num)); |
| 446 | advk_writel(pcie, 0, OB_WIN_MASK_MS(win_num)); |
| 447 | advk_writel(pcie, 0, OB_WIN_ACTIONS(win_num)); |
| 448 | } |
| 449 | |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 450 | static void advk_pcie_setup_hw(struct advk_pcie *pcie) |
| 451 | { |
| 452 | u32 reg; |
Pali Rohár | 64f160e | 2021-06-24 23:55:45 +0200 | [diff] [blame] | 453 | int i; |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 454 | |
Pali Rohár | 46ef609 | 2021-10-05 20:09:44 +0200 | [diff] [blame^] | 455 | /* |
| 456 | * Configure PCIe Reference clock. Direction is from the PCIe |
| 457 | * controller to the endpoint card, so enable transmitting of |
| 458 | * Reference clock differential signal off-chip and disable |
| 459 | * receiving off-chip differential signal. |
| 460 | */ |
Marek Behún | 3666970 | 2020-04-30 10:06:20 +0200 | [diff] [blame] | 461 | reg = advk_readl(pcie, PCIE_CORE_REF_CLK_REG); |
| 462 | reg |= PCIE_CORE_REF_CLK_TX_ENABLE; |
Pali Rohár | 46ef609 | 2021-10-05 20:09:44 +0200 | [diff] [blame^] | 463 | reg &= ~PCIE_CORE_REF_CLK_RX_ENABLE; |
Marek Behún | 3666970 | 2020-04-30 10:06:20 +0200 | [diff] [blame] | 464 | advk_writel(pcie, reg, PCIE_CORE_REF_CLK_REG); |
| 465 | |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 466 | /* Set to Direct mode */ |
| 467 | reg = advk_readl(pcie, CTRL_CONFIG_REG); |
| 468 | reg &= ~(CTRL_MODE_MASK << CTRL_MODE_SHIFT); |
| 469 | reg |= ((PCIE_CORE_MODE_DIRECT & CTRL_MODE_MASK) << CTRL_MODE_SHIFT); |
| 470 | advk_writel(pcie, reg, CTRL_CONFIG_REG); |
| 471 | |
| 472 | /* Set PCI global control register to RC mode */ |
| 473 | reg = advk_readl(pcie, PCIE_CORE_CTRL0_REG); |
| 474 | reg |= (IS_RC_MSK << IS_RC_SHIFT); |
| 475 | advk_writel(pcie, reg, PCIE_CORE_CTRL0_REG); |
| 476 | |
Pali Rohár | 7f71a40 | 2021-06-25 00:26:20 +0200 | [diff] [blame] | 477 | /* |
| 478 | * Replace incorrect PCI vendor id value 0x1b4b by correct value 0x11ab. |
| 479 | * VENDOR_ID_REG contains vendor id in low 16 bits and subsystem vendor |
| 480 | * id in high 16 bits. Updating this register changes readback value of |
| 481 | * read-only vendor id bits in PCIE_CORE_DEV_ID_REG register. Workaround |
| 482 | * for erratum 4.1: "The value of device and vendor ID is incorrect". |
| 483 | */ |
| 484 | reg = (PCI_VENDOR_ID_MARVELL << 16) | PCI_VENDOR_ID_MARVELL; |
| 485 | advk_writel(pcie, reg, VENDOR_ID_REG); |
| 486 | |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 487 | /* Set Advanced Error Capabilities and Control PF0 register */ |
| 488 | reg = PCIE_CORE_ERR_CAPCTL_ECRC_CHK_TX | |
| 489 | PCIE_CORE_ERR_CAPCTL_ECRC_CHK_TX_EN | |
| 490 | PCIE_CORE_ERR_CAPCTL_ECRC_CHCK | |
| 491 | PCIE_CORE_ERR_CAPCTL_ECRC_CHCK_RCV; |
| 492 | advk_writel(pcie, reg, PCIE_CORE_ERR_CAPCTL_REG); |
| 493 | |
Pali Rohár | 96be36d | 2020-04-30 10:06:21 +0200 | [diff] [blame] | 494 | /* Set PCIe Device Control register */ |
| 495 | reg = advk_readl(pcie, PCIE_CORE_PCIEXP_CAP + PCI_EXP_DEVCTL); |
| 496 | reg &= ~PCI_EXP_DEVCTL_RELAX_EN; |
| 497 | reg &= ~PCI_EXP_DEVCTL_NOSNOOP_EN; |
Pali Rohár | a4e17d6 | 2021-10-05 20:09:41 +0200 | [diff] [blame] | 498 | reg &= ~PCI_EXP_DEVCTL_PAYLOAD; |
Pali Rohár | 96be36d | 2020-04-30 10:06:21 +0200 | [diff] [blame] | 499 | reg &= ~PCI_EXP_DEVCTL_READRQ; |
Pali Rohár | a4e17d6 | 2021-10-05 20:09:41 +0200 | [diff] [blame] | 500 | reg |= PCI_EXP_DEVCTL_PAYLOAD_512B; |
Pali Rohár | 96be36d | 2020-04-30 10:06:21 +0200 | [diff] [blame] | 501 | reg |= PCI_EXP_DEVCTL_READRQ_512B; |
| 502 | advk_writel(pcie, reg, PCIE_CORE_PCIEXP_CAP + PCI_EXP_DEVCTL); |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 503 | |
| 504 | /* Program PCIe Control 2 to disable strict ordering */ |
| 505 | reg = PCIE_CORE_CTRL2_RESERVED | |
| 506 | PCIE_CORE_CTRL2_TD_ENABLE; |
| 507 | advk_writel(pcie, reg, PCIE_CORE_CTRL2_REG); |
| 508 | |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 509 | /* Set lane X1 */ |
| 510 | reg = advk_readl(pcie, PCIE_CORE_CTRL0_REG); |
| 511 | reg &= ~LANE_CNT_MSK; |
| 512 | reg |= LANE_COUNT_1; |
| 513 | advk_writel(pcie, reg, PCIE_CORE_CTRL0_REG); |
| 514 | |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 515 | /* Enable MSI */ |
| 516 | reg = advk_readl(pcie, PCIE_CORE_CTRL2_REG); |
| 517 | reg |= PCIE_CORE_CTRL2_MSI_ENABLE; |
| 518 | advk_writel(pcie, reg, PCIE_CORE_CTRL2_REG); |
| 519 | |
| 520 | /* Clear all interrupts */ |
| 521 | advk_writel(pcie, PCIE_ISR0_ALL_MASK, PCIE_ISR0_REG); |
| 522 | advk_writel(pcie, PCIE_ISR1_ALL_MASK, PCIE_ISR1_REG); |
| 523 | advk_writel(pcie, PCIE_IRQ_ALL_MASK, HOST_CTRL_INT_STATUS_REG); |
| 524 | |
| 525 | /* Disable All ISR0/1 Sources */ |
| 526 | reg = PCIE_ISR0_ALL_MASK; |
| 527 | reg &= ~PCIE_ISR0_MSI_INT_PENDING; |
| 528 | advk_writel(pcie, reg, PCIE_ISR0_MASK_REG); |
| 529 | |
| 530 | advk_writel(pcie, PCIE_ISR1_ALL_MASK, PCIE_ISR1_MASK_REG); |
| 531 | |
Bjorn Helgaas | f6b6aef | 2019-05-30 08:05:58 -0500 | [diff] [blame] | 532 | /* Unmask all MSIs */ |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 533 | advk_writel(pcie, 0, PCIE_MSI_MASK_REG); |
| 534 | |
| 535 | /* Enable summary interrupt for GIC SPI source */ |
| 536 | reg = PCIE_IRQ_ALL_MASK & (~PCIE_IRQ_ENABLE_INTS_MASK); |
| 537 | advk_writel(pcie, reg, HOST_CTRL_INT_MASK_REG); |
| 538 | |
Pali Rohár | 64f160e | 2021-06-24 23:55:45 +0200 | [diff] [blame] | 539 | /* |
| 540 | * Enable AXI address window location generation: |
| 541 | * When it is enabled, the default outbound window |
| 542 | * configurations (Default User Field: 0xD0074CFC) |
| 543 | * are used to transparent address translation for |
| 544 | * the outbound transactions. Thus, PCIe address |
| 545 | * windows are not required for transparent memory |
| 546 | * access when default outbound window configuration |
| 547 | * is set for memory access. |
| 548 | */ |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 549 | reg = advk_readl(pcie, PCIE_CORE_CTRL2_REG); |
| 550 | reg |= PCIE_CORE_CTRL2_OB_WIN_ENABLE; |
| 551 | advk_writel(pcie, reg, PCIE_CORE_CTRL2_REG); |
| 552 | |
Pali Rohár | 64f160e | 2021-06-24 23:55:45 +0200 | [diff] [blame] | 553 | /* |
| 554 | * Set memory access in Default User Field so it |
| 555 | * is not required to configure PCIe address for |
| 556 | * transparent memory access. |
| 557 | */ |
| 558 | advk_writel(pcie, OB_WIN_TYPE_MEM, OB_WIN_DEFAULT_ACTIONS); |
| 559 | |
| 560 | /* |
| 561 | * Bypass the address window mapping for PIO: |
| 562 | * Since PIO access already contains all required |
| 563 | * info over AXI interface by PIO registers, the |
| 564 | * address window is not required. |
| 565 | */ |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 566 | reg = advk_readl(pcie, PIO_CTRL); |
| 567 | reg |= PIO_CTRL_ADDR_WIN_DISABLE; |
| 568 | advk_writel(pcie, reg, PIO_CTRL); |
| 569 | |
Pali Rohár | 64f160e | 2021-06-24 23:55:45 +0200 | [diff] [blame] | 570 | /* |
| 571 | * Configure PCIe address windows for non-memory or |
| 572 | * non-transparent access as by default PCIe uses |
| 573 | * transparent memory access. |
| 574 | */ |
| 575 | for (i = 0; i < pcie->wins_count; i++) |
| 576 | advk_pcie_set_ob_win(pcie, i, |
| 577 | pcie->wins[i].match, pcie->wins[i].remap, |
| 578 | pcie->wins[i].mask, pcie->wins[i].actions); |
| 579 | |
| 580 | /* Disable remaining PCIe outbound windows */ |
| 581 | for (i = pcie->wins_count; i < OB_WIN_COUNT; i++) |
| 582 | advk_pcie_disable_ob_win(pcie, i); |
| 583 | |
Marek Behún | 43fc679 | 2020-04-30 10:06:17 +0200 | [diff] [blame] | 584 | advk_pcie_train_link(pcie); |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 585 | |
Pali Rohár | b2a5646 | 2020-04-30 10:06:19 +0200 | [diff] [blame] | 586 | /* |
| 587 | * FIXME: The following register update is suspicious. This register is |
| 588 | * applicable only when the PCI controller is configured for Endpoint |
| 589 | * mode, not as a Root Complex. But apparently when this code is |
| 590 | * removed, some cards stop working. This should be investigated and |
| 591 | * a comment explaining this should be put here. |
| 592 | */ |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 593 | reg = advk_readl(pcie, PCIE_CORE_CMD_STATUS_REG); |
| 594 | reg |= PCIE_CORE_CMD_MEM_ACCESS_EN | |
| 595 | PCIE_CORE_CMD_IO_ACCESS_EN | |
| 596 | PCIE_CORE_CMD_MEM_IO_REQ_EN; |
| 597 | advk_writel(pcie, reg, PCIE_CORE_CMD_STATUS_REG); |
| 598 | } |
| 599 | |
Pali Rohár | 43f5c77 | 2021-07-22 16:40:41 +0200 | [diff] [blame] | 600 | static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_crs, u32 *val) |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 601 | { |
Bjorn Helgaas | 9aec2fe | 2016-10-06 13:27:46 -0500 | [diff] [blame] | 602 | struct device *dev = &pcie->pdev->dev; |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 603 | u32 reg; |
| 604 | unsigned int status; |
| 605 | char *strcomp_status, *str_posted; |
| 606 | |
| 607 | reg = advk_readl(pcie, PIO_STAT); |
| 608 | status = (reg & PIO_COMPLETION_STATUS_MASK) >> |
| 609 | PIO_COMPLETION_STATUS_SHIFT; |
| 610 | |
Evan Wang | fcb461e | 2021-07-22 16:40:38 +0200 | [diff] [blame] | 611 | /* |
| 612 | * According to HW spec, the PIO status check sequence as below: |
| 613 | * 1) even if COMPLETION_STATUS(bit9:7) indicates successful, |
| 614 | * it still needs to check Error Status(bit11), only when this bit |
| 615 | * indicates no error happen, the operation is successful. |
| 616 | * 2) value Unsupported Request(1) of COMPLETION_STATUS(bit9:7) only |
| 617 | * means a PIO write error, and for PIO read it is successful with |
| 618 | * a read value of 0xFFFFFFFF. |
| 619 | * 3) value Completion Retry Status(CRS) of COMPLETION_STATUS(bit9:7) |
| 620 | * only means a PIO write error, and for PIO read it is successful |
| 621 | * with a read value of 0xFFFF0001. |
| 622 | * 4) value Completer Abort (CA) of COMPLETION_STATUS(bit9:7) means |
| 623 | * error for both PIO read and PIO write operation. |
| 624 | * 5) other errors are indicated as 'unknown'. |
| 625 | */ |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 626 | switch (status) { |
Evan Wang | fcb461e | 2021-07-22 16:40:38 +0200 | [diff] [blame] | 627 | case PIO_COMPLETION_STATUS_OK: |
| 628 | if (reg & PIO_ERR_STATUS) { |
| 629 | strcomp_status = "COMP_ERR"; |
| 630 | break; |
| 631 | } |
| 632 | /* Get the read result */ |
| 633 | if (val) |
| 634 | *val = advk_readl(pcie, PIO_RD_DATA); |
| 635 | /* No error */ |
| 636 | strcomp_status = NULL; |
| 637 | break; |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 638 | case PIO_COMPLETION_STATUS_UR: |
| 639 | strcomp_status = "UR"; |
| 640 | break; |
| 641 | case PIO_COMPLETION_STATUS_CRS: |
Pali Rohár | 43f5c77 | 2021-07-22 16:40:41 +0200 | [diff] [blame] | 642 | if (allow_crs && val) { |
| 643 | /* PCIe r4.0, sec 2.3.2, says: |
| 644 | * If CRS Software Visibility is enabled: |
| 645 | * For a Configuration Read Request that includes both |
| 646 | * bytes of the Vendor ID field of a device Function's |
| 647 | * Configuration Space Header, the Root Complex must |
| 648 | * complete the Request to the host by returning a |
| 649 | * read-data value of 0001h for the Vendor ID field and |
| 650 | * all '1's for any additional bytes included in the |
| 651 | * request. |
| 652 | * |
| 653 | * So CRS in this case is not an error status. |
| 654 | */ |
| 655 | *val = CFG_RD_CRS_VAL; |
| 656 | strcomp_status = NULL; |
| 657 | break; |
| 658 | } |
Evan Wang | fcb461e | 2021-07-22 16:40:38 +0200 | [diff] [blame] | 659 | /* PCIe r4.0, sec 2.3.2, says: |
| 660 | * If CRS Software Visibility is not enabled, the Root Complex |
| 661 | * must re-issue the Configuration Request as a new Request. |
Pali Rohár | 43f5c77 | 2021-07-22 16:40:41 +0200 | [diff] [blame] | 662 | * If CRS Software Visibility is enabled: For a Configuration |
| 663 | * Write Request or for any other Configuration Read Request, |
| 664 | * the Root Complex must re-issue the Configuration Request as |
| 665 | * a new Request. |
Evan Wang | fcb461e | 2021-07-22 16:40:38 +0200 | [diff] [blame] | 666 | * A Root Complex implementation may choose to limit the number |
| 667 | * of Configuration Request/CRS Completion Status loops before |
| 668 | * determining that something is wrong with the target of the |
| 669 | * Request and taking appropriate action, e.g., complete the |
| 670 | * Request to the host as a failed transaction. |
| 671 | * |
| 672 | * To simplify implementation do not re-issue the Configuration |
| 673 | * Request and complete the Request as a failed transaction. |
| 674 | */ |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 675 | strcomp_status = "CRS"; |
| 676 | break; |
| 677 | case PIO_COMPLETION_STATUS_CA: |
| 678 | strcomp_status = "CA"; |
| 679 | break; |
| 680 | default: |
| 681 | strcomp_status = "Unknown"; |
| 682 | break; |
| 683 | } |
| 684 | |
Evan Wang | fcb461e | 2021-07-22 16:40:38 +0200 | [diff] [blame] | 685 | if (!strcomp_status) |
| 686 | return 0; |
| 687 | |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 688 | if (reg & PIO_NON_POSTED_REQ) |
| 689 | str_posted = "Non-posted"; |
| 690 | else |
| 691 | str_posted = "Posted"; |
| 692 | |
Marek Behún | 464de7e | 2021-10-05 20:09:42 +0200 | [diff] [blame] | 693 | dev_dbg(dev, "%s PIO Response Status: %s, %#x @ %#x\n", |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 694 | str_posted, strcomp_status, reg, advk_readl(pcie, PIO_ADDR_LS)); |
Evan Wang | fcb461e | 2021-07-22 16:40:38 +0200 | [diff] [blame] | 695 | |
| 696 | return -EFAULT; |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | static int advk_pcie_wait_pio(struct advk_pcie *pcie) |
| 700 | { |
Bjorn Helgaas | 9aec2fe | 2016-10-06 13:27:46 -0500 | [diff] [blame] | 701 | struct device *dev = &pcie->pdev->dev; |
Remi Pommarel | 7fbcb5d | 2019-09-27 10:55:02 +0200 | [diff] [blame] | 702 | int i; |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 703 | |
Remi Pommarel | 7fbcb5d | 2019-09-27 10:55:02 +0200 | [diff] [blame] | 704 | for (i = 0; i < PIO_RETRY_CNT; i++) { |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 705 | u32 start, isr; |
| 706 | |
| 707 | start = advk_readl(pcie, PIO_START); |
| 708 | isr = advk_readl(pcie, PIO_ISR); |
| 709 | if (!start && isr) |
| 710 | return 0; |
Remi Pommarel | 7fbcb5d | 2019-09-27 10:55:02 +0200 | [diff] [blame] | 711 | udelay(PIO_RETRY_DELAY); |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 712 | } |
| 713 | |
Pali Rohár | f181399 | 2021-06-08 22:36:55 +0200 | [diff] [blame] | 714 | dev_err(dev, "PIO read/write transfer time out\n"); |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 715 | return -ETIMEDOUT; |
| 716 | } |
| 717 | |
Zachary Zhang | 8a3ebd8 | 2018-10-18 17:37:19 +0200 | [diff] [blame] | 718 | |
| 719 | static pci_bridge_emul_read_status_t |
| 720 | advk_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge, |
| 721 | int reg, u32 *value) |
| 722 | { |
| 723 | struct advk_pcie *pcie = bridge->data; |
| 724 | |
| 725 | |
| 726 | switch (reg) { |
| 727 | case PCI_EXP_SLTCTL: |
| 728 | *value = PCI_EXP_SLTSTA_PDS << 16; |
| 729 | return PCI_BRIDGE_EMUL_HANDLED; |
| 730 | |
| 731 | case PCI_EXP_RTCTL: { |
| 732 | u32 val = advk_readl(pcie, PCIE_ISR0_MASK_REG); |
Remi Pommarel | c0f05a6 | 2019-06-14 12:10:59 +0200 | [diff] [blame] | 733 | *value = (val & PCIE_MSG_PM_PME_MASK) ? 0 : PCI_EXP_RTCTL_PMEIE; |
Pali Rohár | d419052 | 2021-10-05 20:09:43 +0200 | [diff] [blame] | 734 | *value |= le16_to_cpu(bridge->pcie_conf.rootctl) & PCI_EXP_RTCTL_CRSSVE; |
Pali Rohár | 43f5c77 | 2021-07-22 16:40:41 +0200 | [diff] [blame] | 735 | *value |= PCI_EXP_RTCAP_CRSVIS << 16; |
Zachary Zhang | 8a3ebd8 | 2018-10-18 17:37:19 +0200 | [diff] [blame] | 736 | return PCI_BRIDGE_EMUL_HANDLED; |
| 737 | } |
| 738 | |
| 739 | case PCI_EXP_RTSTA: { |
| 740 | u32 isr0 = advk_readl(pcie, PCIE_ISR0_REG); |
| 741 | u32 msglog = advk_readl(pcie, PCIE_MSG_LOG_REG); |
| 742 | *value = (isr0 & PCIE_MSG_PM_PME_MASK) << 16 | (msglog >> 16); |
| 743 | return PCI_BRIDGE_EMUL_HANDLED; |
| 744 | } |
| 745 | |
Remi Pommarel | 364b3f1 | 2019-05-22 23:33:51 +0200 | [diff] [blame] | 746 | case PCI_EXP_LNKCTL: { |
| 747 | /* u32 contains both PCI_EXP_LNKCTL and PCI_EXP_LNKSTA */ |
| 748 | u32 val = advk_readl(pcie, PCIE_CORE_PCIEXP_CAP + reg) & |
| 749 | ~(PCI_EXP_LNKSTA_LT << 16); |
| 750 | if (!advk_pcie_link_up(pcie)) |
| 751 | val |= (PCI_EXP_LNKSTA_LT << 16); |
| 752 | *value = val; |
| 753 | return PCI_BRIDGE_EMUL_HANDLED; |
| 754 | } |
| 755 | |
Zachary Zhang | 8a3ebd8 | 2018-10-18 17:37:19 +0200 | [diff] [blame] | 756 | case PCI_CAP_LIST_ID: |
| 757 | case PCI_EXP_DEVCAP: |
| 758 | case PCI_EXP_DEVCTL: |
| 759 | case PCI_EXP_LNKCAP: |
Zachary Zhang | 8a3ebd8 | 2018-10-18 17:37:19 +0200 | [diff] [blame] | 760 | *value = advk_readl(pcie, PCIE_CORE_PCIEXP_CAP + reg); |
| 761 | return PCI_BRIDGE_EMUL_HANDLED; |
| 762 | default: |
| 763 | return PCI_BRIDGE_EMUL_NOT_HANDLED; |
| 764 | } |
| 765 | |
| 766 | } |
| 767 | |
| 768 | static void |
| 769 | advk_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge, |
| 770 | int reg, u32 old, u32 new, u32 mask) |
| 771 | { |
| 772 | struct advk_pcie *pcie = bridge->data; |
| 773 | |
| 774 | switch (reg) { |
| 775 | case PCI_EXP_DEVCTL: |
Zachary Zhang | 8a3ebd8 | 2018-10-18 17:37:19 +0200 | [diff] [blame] | 776 | advk_writel(pcie, new, PCIE_CORE_PCIEXP_CAP + reg); |
| 777 | break; |
| 778 | |
Zachary Zhang | 8a3ebd8 | 2018-10-18 17:37:19 +0200 | [diff] [blame] | 779 | case PCI_EXP_LNKCTL: |
| 780 | advk_writel(pcie, new, PCIE_CORE_PCIEXP_CAP + reg); |
Remi Pommarel | 364b3f1 | 2019-05-22 23:33:51 +0200 | [diff] [blame] | 781 | if (new & PCI_EXP_LNKCTL_RL) |
| 782 | advk_pcie_wait_for_retrain(pcie); |
Zachary Zhang | 8a3ebd8 | 2018-10-18 17:37:19 +0200 | [diff] [blame] | 783 | break; |
| 784 | |
Remi Pommarel | c0f05a6 | 2019-06-14 12:10:59 +0200 | [diff] [blame] | 785 | case PCI_EXP_RTCTL: { |
| 786 | /* Only mask/unmask PME interrupt */ |
| 787 | u32 val = advk_readl(pcie, PCIE_ISR0_MASK_REG) & |
| 788 | ~PCIE_MSG_PM_PME_MASK; |
| 789 | if ((new & PCI_EXP_RTCTL_PMEIE) == 0) |
| 790 | val |= PCIE_MSG_PM_PME_MASK; |
| 791 | advk_writel(pcie, val, PCIE_ISR0_MASK_REG); |
Zachary Zhang | 8a3ebd8 | 2018-10-18 17:37:19 +0200 | [diff] [blame] | 792 | break; |
Remi Pommarel | c0f05a6 | 2019-06-14 12:10:59 +0200 | [diff] [blame] | 793 | } |
Zachary Zhang | 8a3ebd8 | 2018-10-18 17:37:19 +0200 | [diff] [blame] | 794 | |
| 795 | case PCI_EXP_RTSTA: |
| 796 | new = (new & PCI_EXP_RTSTA_PME) >> 9; |
| 797 | advk_writel(pcie, new, PCIE_ISR0_REG); |
| 798 | break; |
| 799 | |
| 800 | default: |
| 801 | break; |
| 802 | } |
| 803 | } |
| 804 | |
Wei Yongjun | d3b34d04 | 2019-03-01 06:58:09 +0000 | [diff] [blame] | 805 | static struct pci_bridge_emul_ops advk_pci_bridge_emul_ops = { |
Zachary Zhang | 8a3ebd8 | 2018-10-18 17:37:19 +0200 | [diff] [blame] | 806 | .read_pcie = advk_pci_bridge_emul_pcie_conf_read, |
| 807 | .write_pcie = advk_pci_bridge_emul_pcie_conf_write, |
| 808 | }; |
| 809 | |
| 810 | /* |
| 811 | * Initialize the configuration space of the PCI-to-PCI bridge |
| 812 | * associated with the given PCIe interface. |
| 813 | */ |
Pali Rohár | 7862a61 | 2020-09-07 13:10:35 +0200 | [diff] [blame] | 814 | static int advk_sw_pci_bridge_init(struct advk_pcie *pcie) |
Zachary Zhang | 8a3ebd8 | 2018-10-18 17:37:19 +0200 | [diff] [blame] | 815 | { |
| 816 | struct pci_bridge_emul *bridge = &pcie->bridge; |
Pali Rohár | 43f5c77 | 2021-07-22 16:40:41 +0200 | [diff] [blame] | 817 | int ret; |
Zachary Zhang | 8a3ebd8 | 2018-10-18 17:37:19 +0200 | [diff] [blame] | 818 | |
Grzegorz Jaszczyk | e078723 | 2019-07-16 14:12:07 +0200 | [diff] [blame] | 819 | bridge->conf.vendor = |
| 820 | cpu_to_le16(advk_readl(pcie, PCIE_CORE_DEV_ID_REG) & 0xffff); |
| 821 | bridge->conf.device = |
| 822 | cpu_to_le16(advk_readl(pcie, PCIE_CORE_DEV_ID_REG) >> 16); |
Zachary Zhang | 8a3ebd8 | 2018-10-18 17:37:19 +0200 | [diff] [blame] | 823 | bridge->conf.class_revision = |
Grzegorz Jaszczyk | e078723 | 2019-07-16 14:12:07 +0200 | [diff] [blame] | 824 | cpu_to_le32(advk_readl(pcie, PCIE_CORE_DEV_REV_REG) & 0xff); |
Zachary Zhang | 8a3ebd8 | 2018-10-18 17:37:19 +0200 | [diff] [blame] | 825 | |
| 826 | /* Support 32 bits I/O addressing */ |
| 827 | bridge->conf.iobase = PCI_IO_RANGE_TYPE_32; |
| 828 | bridge->conf.iolimit = PCI_IO_RANGE_TYPE_32; |
| 829 | |
| 830 | /* Support 64 bits memory pref */ |
Grzegorz Jaszczyk | e078723 | 2019-07-16 14:12:07 +0200 | [diff] [blame] | 831 | bridge->conf.pref_mem_base = cpu_to_le16(PCI_PREF_RANGE_TYPE_64); |
| 832 | bridge->conf.pref_mem_limit = cpu_to_le16(PCI_PREF_RANGE_TYPE_64); |
Zachary Zhang | 8a3ebd8 | 2018-10-18 17:37:19 +0200 | [diff] [blame] | 833 | |
| 834 | /* Support interrupt A for MSI feature */ |
| 835 | bridge->conf.intpin = PCIE_CORE_INT_A_ASSERT_ENABLE; |
| 836 | |
| 837 | bridge->has_pcie = true; |
| 838 | bridge->data = pcie; |
| 839 | bridge->ops = &advk_pci_bridge_emul_ops; |
| 840 | |
Pali Rohár | 43f5c77 | 2021-07-22 16:40:41 +0200 | [diff] [blame] | 841 | /* PCIe config space can be initialized after pci_bridge_emul_init() */ |
| 842 | ret = pci_bridge_emul_init(bridge, 0); |
| 843 | if (ret < 0) |
| 844 | return ret; |
| 845 | |
| 846 | /* Indicates supports for Completion Retry Status */ |
| 847 | bridge->pcie_conf.rootcap = cpu_to_le16(PCI_EXP_RTCAP_CRSVIS); |
| 848 | |
| 849 | return 0; |
Zachary Zhang | 8a3ebd8 | 2018-10-18 17:37:19 +0200 | [diff] [blame] | 850 | } |
| 851 | |
Thomas Petazzoni | 248d4e5 | 2018-04-06 16:55:35 +0200 | [diff] [blame] | 852 | static bool advk_pcie_valid_device(struct advk_pcie *pcie, struct pci_bus *bus, |
| 853 | int devfn) |
| 854 | { |
Rob Herring | 11e9797 | 2020-07-21 20:24:59 -0600 | [diff] [blame] | 855 | if (pci_is_root_bus(bus) && PCI_SLOT(devfn) != 0) |
Thomas Petazzoni | 248d4e5 | 2018-04-06 16:55:35 +0200 | [diff] [blame] | 856 | return false; |
| 857 | |
Pali Rohár | 70e3802 | 2020-07-02 10:30:36 +0200 | [diff] [blame] | 858 | /* |
| 859 | * If the link goes down after we check for link-up, nothing bad |
| 860 | * happens but the config access times out. |
| 861 | */ |
Bjorn Helgaas | 49e427e | 2020-08-05 18:24:21 -0500 | [diff] [blame] | 862 | if (!pci_is_root_bus(bus) && !advk_pcie_link_up(pcie)) |
Pali Rohár | 70e3802 | 2020-07-02 10:30:36 +0200 | [diff] [blame] | 863 | return false; |
| 864 | |
Thomas Petazzoni | 248d4e5 | 2018-04-06 16:55:35 +0200 | [diff] [blame] | 865 | return true; |
| 866 | } |
| 867 | |
Pali Rohár | f181399 | 2021-06-08 22:36:55 +0200 | [diff] [blame] | 868 | static bool advk_pcie_pio_is_running(struct advk_pcie *pcie) |
| 869 | { |
| 870 | struct device *dev = &pcie->pdev->dev; |
| 871 | |
| 872 | /* |
| 873 | * Trying to start a new PIO transfer when previous has not completed |
| 874 | * cause External Abort on CPU which results in kernel panic: |
| 875 | * |
| 876 | * SError Interrupt on CPU0, code 0xbf000002 -- SError |
| 877 | * Kernel panic - not syncing: Asynchronous SError Interrupt |
| 878 | * |
| 879 | * Functions advk_pcie_rd_conf() and advk_pcie_wr_conf() are protected |
| 880 | * by raw_spin_lock_irqsave() at pci_lock_config() level to prevent |
| 881 | * concurrent calls at the same time. But because PIO transfer may take |
| 882 | * about 1.5s when link is down or card is disconnected, it means that |
| 883 | * advk_pcie_wait_pio() does not always have to wait for completion. |
| 884 | * |
| 885 | * Some versions of ARM Trusted Firmware handles this External Abort at |
| 886 | * EL3 level and mask it to prevent kernel panic. Relevant TF-A commit: |
| 887 | * https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/commit/?id=3c7dcdac5c50 |
| 888 | */ |
| 889 | if (advk_readl(pcie, PIO_START)) { |
| 890 | dev_err(dev, "Previous PIO read/write transfer is still running\n"); |
| 891 | return true; |
| 892 | } |
| 893 | |
| 894 | return false; |
| 895 | } |
| 896 | |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 897 | static int advk_pcie_rd_conf(struct pci_bus *bus, u32 devfn, |
| 898 | int where, int size, u32 *val) |
| 899 | { |
| 900 | struct advk_pcie *pcie = bus->sysdata; |
Pali Rohár | 43f5c77 | 2021-07-22 16:40:41 +0200 | [diff] [blame] | 901 | bool allow_crs; |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 902 | u32 reg; |
| 903 | int ret; |
| 904 | |
Thomas Petazzoni | 248d4e5 | 2018-04-06 16:55:35 +0200 | [diff] [blame] | 905 | if (!advk_pcie_valid_device(pcie, bus, devfn)) { |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 906 | *val = 0xffffffff; |
| 907 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 908 | } |
| 909 | |
Rob Herring | 11e9797 | 2020-07-21 20:24:59 -0600 | [diff] [blame] | 910 | if (pci_is_root_bus(bus)) |
Zachary Zhang | 8a3ebd8 | 2018-10-18 17:37:19 +0200 | [diff] [blame] | 911 | return pci_bridge_emul_conf_read(&pcie->bridge, where, |
| 912 | size, val); |
| 913 | |
Pali Rohár | 43f5c77 | 2021-07-22 16:40:41 +0200 | [diff] [blame] | 914 | /* |
| 915 | * Completion Retry Status is possible to return only when reading all |
| 916 | * 4 bytes from PCI_VENDOR_ID and PCI_DEVICE_ID registers at once and |
| 917 | * CRSSVE flag on Root Bridge is enabled. |
| 918 | */ |
| 919 | allow_crs = (where == PCI_VENDOR_ID) && (size == 4) && |
| 920 | (le16_to_cpu(pcie->bridge.pcie_conf.rootctl) & |
| 921 | PCI_EXP_RTCTL_CRSSVE); |
| 922 | |
Pali Rohár | f181399 | 2021-06-08 22:36:55 +0200 | [diff] [blame] | 923 | if (advk_pcie_pio_is_running(pcie)) { |
Pali Rohár | 43f5c77 | 2021-07-22 16:40:41 +0200 | [diff] [blame] | 924 | /* |
| 925 | * If it is possible return Completion Retry Status so caller |
| 926 | * tries to issue the request again instead of failing. |
| 927 | */ |
| 928 | if (allow_crs) { |
| 929 | *val = CFG_RD_CRS_VAL; |
| 930 | return PCIBIOS_SUCCESSFUL; |
| 931 | } |
Pali Rohár | f181399 | 2021-06-08 22:36:55 +0200 | [diff] [blame] | 932 | *val = 0xffffffff; |
| 933 | return PCIBIOS_SET_FAILED; |
| 934 | } |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 935 | |
| 936 | /* Program the control register */ |
| 937 | reg = advk_readl(pcie, PIO_CTRL); |
| 938 | reg &= ~PIO_CTRL_TYPE_MASK; |
Rob Herring | 11e9797 | 2020-07-21 20:24:59 -0600 | [diff] [blame] | 939 | if (pci_is_root_bus(bus->parent)) |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 940 | reg |= PCIE_CONFIG_RD_TYPE0; |
| 941 | else |
| 942 | reg |= PCIE_CONFIG_RD_TYPE1; |
| 943 | advk_writel(pcie, reg, PIO_CTRL); |
| 944 | |
| 945 | /* Program the address registers */ |
Krzysztof Wilczyński | e7708f5 | 2020-11-29 23:07:39 +0000 | [diff] [blame] | 946 | reg = ALIGN_DOWN(PCIE_ECAM_OFFSET(bus->number, devfn, where), 4); |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 947 | advk_writel(pcie, reg, PIO_ADDR_LS); |
| 948 | advk_writel(pcie, 0, PIO_ADDR_MS); |
| 949 | |
| 950 | /* Program the data strobe */ |
| 951 | advk_writel(pcie, 0xf, PIO_WR_DATA_STRB); |
| 952 | |
Pali Rohár | f181399 | 2021-06-08 22:36:55 +0200 | [diff] [blame] | 953 | /* Clear PIO DONE ISR and start the transfer */ |
| 954 | advk_writel(pcie, 1, PIO_ISR); |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 955 | advk_writel(pcie, 1, PIO_START); |
| 956 | |
| 957 | ret = advk_pcie_wait_pio(pcie); |
Pali Rohár | b1bd571 | 2020-06-01 15:03:15 +0200 | [diff] [blame] | 958 | if (ret < 0) { |
Pali Rohár | 43f5c77 | 2021-07-22 16:40:41 +0200 | [diff] [blame] | 959 | /* |
| 960 | * If it is possible return Completion Retry Status so caller |
| 961 | * tries to issue the request again instead of failing. |
| 962 | */ |
| 963 | if (allow_crs) { |
| 964 | *val = CFG_RD_CRS_VAL; |
| 965 | return PCIBIOS_SUCCESSFUL; |
| 966 | } |
Pali Rohár | b1bd571 | 2020-06-01 15:03:15 +0200 | [diff] [blame] | 967 | *val = 0xffffffff; |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 968 | return PCIBIOS_SET_FAILED; |
Pali Rohár | b1bd571 | 2020-06-01 15:03:15 +0200 | [diff] [blame] | 969 | } |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 970 | |
Evan Wang | fcb461e | 2021-07-22 16:40:38 +0200 | [diff] [blame] | 971 | /* Check PIO status and get the read result */ |
Pali Rohár | 43f5c77 | 2021-07-22 16:40:41 +0200 | [diff] [blame] | 972 | ret = advk_pcie_check_pio_status(pcie, allow_crs, val); |
Evan Wang | fcb461e | 2021-07-22 16:40:38 +0200 | [diff] [blame] | 973 | if (ret < 0) { |
| 974 | *val = 0xffffffff; |
| 975 | return PCIBIOS_SET_FAILED; |
| 976 | } |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 977 | |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 978 | if (size == 1) |
| 979 | *val = (*val >> (8 * (where & 3))) & 0xff; |
| 980 | else if (size == 2) |
| 981 | *val = (*val >> (8 * (where & 3))) & 0xffff; |
| 982 | |
| 983 | return PCIBIOS_SUCCESSFUL; |
| 984 | } |
| 985 | |
| 986 | static int advk_pcie_wr_conf(struct pci_bus *bus, u32 devfn, |
| 987 | int where, int size, u32 val) |
| 988 | { |
| 989 | struct advk_pcie *pcie = bus->sysdata; |
| 990 | u32 reg; |
| 991 | u32 data_strobe = 0x0; |
| 992 | int offset; |
| 993 | int ret; |
| 994 | |
Thomas Petazzoni | 248d4e5 | 2018-04-06 16:55:35 +0200 | [diff] [blame] | 995 | if (!advk_pcie_valid_device(pcie, bus, devfn)) |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 996 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 997 | |
Rob Herring | 11e9797 | 2020-07-21 20:24:59 -0600 | [diff] [blame] | 998 | if (pci_is_root_bus(bus)) |
Zachary Zhang | 8a3ebd8 | 2018-10-18 17:37:19 +0200 | [diff] [blame] | 999 | return pci_bridge_emul_conf_write(&pcie->bridge, where, |
| 1000 | size, val); |
| 1001 | |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1002 | if (where % size) |
| 1003 | return PCIBIOS_SET_FAILED; |
| 1004 | |
Pali Rohár | f181399 | 2021-06-08 22:36:55 +0200 | [diff] [blame] | 1005 | if (advk_pcie_pio_is_running(pcie)) |
| 1006 | return PCIBIOS_SET_FAILED; |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1007 | |
| 1008 | /* Program the control register */ |
| 1009 | reg = advk_readl(pcie, PIO_CTRL); |
| 1010 | reg &= ~PIO_CTRL_TYPE_MASK; |
Rob Herring | 11e9797 | 2020-07-21 20:24:59 -0600 | [diff] [blame] | 1011 | if (pci_is_root_bus(bus->parent)) |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1012 | reg |= PCIE_CONFIG_WR_TYPE0; |
| 1013 | else |
| 1014 | reg |= PCIE_CONFIG_WR_TYPE1; |
| 1015 | advk_writel(pcie, reg, PIO_CTRL); |
| 1016 | |
| 1017 | /* Program the address registers */ |
Krzysztof Wilczyński | e7708f5 | 2020-11-29 23:07:39 +0000 | [diff] [blame] | 1018 | reg = ALIGN_DOWN(PCIE_ECAM_OFFSET(bus->number, devfn, where), 4); |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1019 | advk_writel(pcie, reg, PIO_ADDR_LS); |
| 1020 | advk_writel(pcie, 0, PIO_ADDR_MS); |
| 1021 | |
| 1022 | /* Calculate the write strobe */ |
| 1023 | offset = where & 0x3; |
| 1024 | reg = val << (8 * offset); |
| 1025 | data_strobe = GENMASK(size - 1, 0) << offset; |
| 1026 | |
| 1027 | /* Program the data register */ |
| 1028 | advk_writel(pcie, reg, PIO_WR_DATA); |
| 1029 | |
| 1030 | /* Program the data strobe */ |
| 1031 | advk_writel(pcie, data_strobe, PIO_WR_DATA_STRB); |
| 1032 | |
Pali Rohár | f181399 | 2021-06-08 22:36:55 +0200 | [diff] [blame] | 1033 | /* Clear PIO DONE ISR and start the transfer */ |
| 1034 | advk_writel(pcie, 1, PIO_ISR); |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1035 | advk_writel(pcie, 1, PIO_START); |
| 1036 | |
| 1037 | ret = advk_pcie_wait_pio(pcie); |
| 1038 | if (ret < 0) |
| 1039 | return PCIBIOS_SET_FAILED; |
| 1040 | |
Pali Rohár | 43f5c77 | 2021-07-22 16:40:41 +0200 | [diff] [blame] | 1041 | ret = advk_pcie_check_pio_status(pcie, false, NULL); |
Evan Wang | fcb461e | 2021-07-22 16:40:38 +0200 | [diff] [blame] | 1042 | if (ret < 0) |
| 1043 | return PCIBIOS_SET_FAILED; |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1044 | |
| 1045 | return PCIBIOS_SUCCESSFUL; |
| 1046 | } |
| 1047 | |
| 1048 | static struct pci_ops advk_pcie_ops = { |
| 1049 | .read = advk_pcie_rd_conf, |
| 1050 | .write = advk_pcie_wr_conf, |
| 1051 | }; |
| 1052 | |
Thomas Petazzoni | f21a8b1 | 2017-02-28 15:31:14 +0100 | [diff] [blame] | 1053 | static void advk_msi_irq_compose_msi_msg(struct irq_data *data, |
| 1054 | struct msi_msg *msg) |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1055 | { |
Thomas Petazzoni | f21a8b1 | 2017-02-28 15:31:14 +0100 | [diff] [blame] | 1056 | struct advk_pcie *pcie = irq_data_get_irq_chip_data(data); |
| 1057 | phys_addr_t msi_msg = virt_to_phys(&pcie->msi_msg); |
| 1058 | |
| 1059 | msg->address_lo = lower_32_bits(msi_msg); |
| 1060 | msg->address_hi = upper_32_bits(msi_msg); |
| 1061 | msg->data = data->irq; |
| 1062 | } |
| 1063 | |
| 1064 | static int advk_msi_set_affinity(struct irq_data *irq_data, |
| 1065 | const struct cpumask *mask, bool force) |
| 1066 | { |
| 1067 | return -EINVAL; |
| 1068 | } |
| 1069 | |
| 1070 | static int advk_msi_irq_domain_alloc(struct irq_domain *domain, |
| 1071 | unsigned int virq, |
| 1072 | unsigned int nr_irqs, void *args) |
| 1073 | { |
| 1074 | struct advk_pcie *pcie = domain->host_data; |
| 1075 | int hwirq, i; |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1076 | |
| 1077 | mutex_lock(&pcie->msi_used_lock); |
Thomas Petazzoni | f21a8b1 | 2017-02-28 15:31:14 +0100 | [diff] [blame] | 1078 | hwirq = bitmap_find_next_zero_area(pcie->msi_used, MSI_IRQ_NUM, |
| 1079 | 0, nr_irqs, 0); |
| 1080 | if (hwirq >= MSI_IRQ_NUM) { |
| 1081 | mutex_unlock(&pcie->msi_used_lock); |
| 1082 | return -ENOSPC; |
| 1083 | } |
| 1084 | |
| 1085 | bitmap_set(pcie->msi_used, hwirq, nr_irqs); |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1086 | mutex_unlock(&pcie->msi_used_lock); |
| 1087 | |
Thomas Petazzoni | f21a8b1 | 2017-02-28 15:31:14 +0100 | [diff] [blame] | 1088 | for (i = 0; i < nr_irqs; i++) |
| 1089 | irq_domain_set_info(domain, virq + i, hwirq + i, |
| 1090 | &pcie->msi_bottom_irq_chip, |
| 1091 | domain->host_data, handle_simple_irq, |
| 1092 | NULL, NULL); |
| 1093 | |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1094 | return hwirq; |
| 1095 | } |
| 1096 | |
Thomas Petazzoni | f21a8b1 | 2017-02-28 15:31:14 +0100 | [diff] [blame] | 1097 | static void advk_msi_irq_domain_free(struct irq_domain *domain, |
| 1098 | unsigned int virq, unsigned int nr_irqs) |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1099 | { |
Thomas Petazzoni | f21a8b1 | 2017-02-28 15:31:14 +0100 | [diff] [blame] | 1100 | struct irq_data *d = irq_domain_get_irq_data(domain, virq); |
| 1101 | struct advk_pcie *pcie = domain->host_data; |
Bjorn Helgaas | 9aec2fe | 2016-10-06 13:27:46 -0500 | [diff] [blame] | 1102 | |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1103 | mutex_lock(&pcie->msi_used_lock); |
Thomas Petazzoni | f21a8b1 | 2017-02-28 15:31:14 +0100 | [diff] [blame] | 1104 | bitmap_clear(pcie->msi_used, d->hwirq, nr_irqs); |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1105 | mutex_unlock(&pcie->msi_used_lock); |
| 1106 | } |
| 1107 | |
Thomas Petazzoni | f21a8b1 | 2017-02-28 15:31:14 +0100 | [diff] [blame] | 1108 | static const struct irq_domain_ops advk_msi_domain_ops = { |
| 1109 | .alloc = advk_msi_irq_domain_alloc, |
| 1110 | .free = advk_msi_irq_domain_free, |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1111 | }; |
| 1112 | |
| 1113 | static void advk_pcie_irq_mask(struct irq_data *d) |
| 1114 | { |
| 1115 | struct advk_pcie *pcie = d->domain->host_data; |
| 1116 | irq_hw_number_t hwirq = irqd_to_hwirq(d); |
Pali Rohár | d212dce | 2021-08-20 17:50:20 +0200 | [diff] [blame] | 1117 | unsigned long flags; |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1118 | u32 mask; |
| 1119 | |
Pali Rohár | d212dce | 2021-08-20 17:50:20 +0200 | [diff] [blame] | 1120 | raw_spin_lock_irqsave(&pcie->irq_lock, flags); |
Victor Gu | 3430f92 | 2018-04-06 16:55:33 +0200 | [diff] [blame] | 1121 | mask = advk_readl(pcie, PCIE_ISR1_MASK_REG); |
| 1122 | mask |= PCIE_ISR1_INTX_ASSERT(hwirq); |
| 1123 | advk_writel(pcie, mask, PCIE_ISR1_MASK_REG); |
Pali Rohár | d212dce | 2021-08-20 17:50:20 +0200 | [diff] [blame] | 1124 | raw_spin_unlock_irqrestore(&pcie->irq_lock, flags); |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | static void advk_pcie_irq_unmask(struct irq_data *d) |
| 1128 | { |
| 1129 | struct advk_pcie *pcie = d->domain->host_data; |
| 1130 | irq_hw_number_t hwirq = irqd_to_hwirq(d); |
Pali Rohár | d212dce | 2021-08-20 17:50:20 +0200 | [diff] [blame] | 1131 | unsigned long flags; |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1132 | u32 mask; |
| 1133 | |
Pali Rohár | d212dce | 2021-08-20 17:50:20 +0200 | [diff] [blame] | 1134 | raw_spin_lock_irqsave(&pcie->irq_lock, flags); |
Victor Gu | 3430f92 | 2018-04-06 16:55:33 +0200 | [diff] [blame] | 1135 | mask = advk_readl(pcie, PCIE_ISR1_MASK_REG); |
| 1136 | mask &= ~PCIE_ISR1_INTX_ASSERT(hwirq); |
| 1137 | advk_writel(pcie, mask, PCIE_ISR1_MASK_REG); |
Pali Rohár | d212dce | 2021-08-20 17:50:20 +0200 | [diff] [blame] | 1138 | raw_spin_unlock_irqrestore(&pcie->irq_lock, flags); |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | static int advk_pcie_irq_map(struct irq_domain *h, |
| 1142 | unsigned int virq, irq_hw_number_t hwirq) |
| 1143 | { |
| 1144 | struct advk_pcie *pcie = h->host_data; |
| 1145 | |
| 1146 | advk_pcie_irq_mask(irq_get_irq_data(virq)); |
| 1147 | irq_set_status_flags(virq, IRQ_LEVEL); |
| 1148 | irq_set_chip_and_handler(virq, &pcie->irq_chip, |
| 1149 | handle_level_irq); |
| 1150 | irq_set_chip_data(virq, pcie); |
| 1151 | |
| 1152 | return 0; |
| 1153 | } |
| 1154 | |
| 1155 | static const struct irq_domain_ops advk_pcie_irq_domain_ops = { |
| 1156 | .map = advk_pcie_irq_map, |
| 1157 | .xlate = irq_domain_xlate_onecell, |
| 1158 | }; |
| 1159 | |
| 1160 | static int advk_pcie_init_msi_irq_domain(struct advk_pcie *pcie) |
| 1161 | { |
| 1162 | struct device *dev = &pcie->pdev->dev; |
| 1163 | struct device_node *node = dev->of_node; |
Thomas Petazzoni | f21a8b1 | 2017-02-28 15:31:14 +0100 | [diff] [blame] | 1164 | struct irq_chip *bottom_ic, *msi_ic; |
| 1165 | struct msi_domain_info *msi_di; |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1166 | phys_addr_t msi_msg_phys; |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1167 | |
| 1168 | mutex_init(&pcie->msi_used_lock); |
| 1169 | |
Thomas Petazzoni | f21a8b1 | 2017-02-28 15:31:14 +0100 | [diff] [blame] | 1170 | bottom_ic = &pcie->msi_bottom_irq_chip; |
| 1171 | |
| 1172 | bottom_ic->name = "MSI"; |
| 1173 | bottom_ic->irq_compose_msi_msg = advk_msi_irq_compose_msi_msg; |
| 1174 | bottom_ic->irq_set_affinity = advk_msi_set_affinity; |
| 1175 | |
| 1176 | msi_ic = &pcie->msi_irq_chip; |
| 1177 | msi_ic->name = "advk-MSI"; |
| 1178 | |
| 1179 | msi_di = &pcie->msi_domain_info; |
| 1180 | msi_di->flags = MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS | |
| 1181 | MSI_FLAG_MULTI_PCI_MSI; |
| 1182 | msi_di->chip = msi_ic; |
| 1183 | |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1184 | msi_msg_phys = virt_to_phys(&pcie->msi_msg); |
| 1185 | |
| 1186 | advk_writel(pcie, lower_32_bits(msi_msg_phys), |
| 1187 | PCIE_MSI_ADDR_LOW_REG); |
| 1188 | advk_writel(pcie, upper_32_bits(msi_msg_phys), |
| 1189 | PCIE_MSI_ADDR_HIGH_REG); |
| 1190 | |
Thomas Petazzoni | f21a8b1 | 2017-02-28 15:31:14 +0100 | [diff] [blame] | 1191 | pcie->msi_inner_domain = |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1192 | irq_domain_add_linear(NULL, MSI_IRQ_NUM, |
Thomas Petazzoni | f21a8b1 | 2017-02-28 15:31:14 +0100 | [diff] [blame] | 1193 | &advk_msi_domain_ops, pcie); |
| 1194 | if (!pcie->msi_inner_domain) |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1195 | return -ENOMEM; |
| 1196 | |
Thomas Petazzoni | f21a8b1 | 2017-02-28 15:31:14 +0100 | [diff] [blame] | 1197 | pcie->msi_domain = |
| 1198 | pci_msi_create_irq_domain(of_node_to_fwnode(node), |
| 1199 | msi_di, pcie->msi_inner_domain); |
| 1200 | if (!pcie->msi_domain) { |
| 1201 | irq_domain_remove(pcie->msi_inner_domain); |
| 1202 | return -ENOMEM; |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | return 0; |
| 1206 | } |
| 1207 | |
| 1208 | static void advk_pcie_remove_msi_irq_domain(struct advk_pcie *pcie) |
| 1209 | { |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1210 | irq_domain_remove(pcie->msi_domain); |
Thomas Petazzoni | f21a8b1 | 2017-02-28 15:31:14 +0100 | [diff] [blame] | 1211 | irq_domain_remove(pcie->msi_inner_domain); |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1212 | } |
| 1213 | |
| 1214 | static int advk_pcie_init_irq_domain(struct advk_pcie *pcie) |
| 1215 | { |
| 1216 | struct device *dev = &pcie->pdev->dev; |
| 1217 | struct device_node *node = dev->of_node; |
| 1218 | struct device_node *pcie_intc_node; |
| 1219 | struct irq_chip *irq_chip; |
Wen Yang | 3842f51 | 2019-02-27 12:40:40 +0800 | [diff] [blame] | 1220 | int ret = 0; |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1221 | |
Pali Rohár | d212dce | 2021-08-20 17:50:20 +0200 | [diff] [blame] | 1222 | raw_spin_lock_init(&pcie->irq_lock); |
| 1223 | |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1224 | pcie_intc_node = of_get_next_child(node, NULL); |
| 1225 | if (!pcie_intc_node) { |
| 1226 | dev_err(dev, "No PCIe Intc node found\n"); |
| 1227 | return -ENODEV; |
| 1228 | } |
| 1229 | |
| 1230 | irq_chip = &pcie->irq_chip; |
| 1231 | |
| 1232 | irq_chip->name = devm_kasprintf(dev, GFP_KERNEL, "%s-irq", |
| 1233 | dev_name(dev)); |
| 1234 | if (!irq_chip->name) { |
Wen Yang | 3842f51 | 2019-02-27 12:40:40 +0800 | [diff] [blame] | 1235 | ret = -ENOMEM; |
| 1236 | goto out_put_node; |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1237 | } |
| 1238 | |
| 1239 | irq_chip->irq_mask = advk_pcie_irq_mask; |
| 1240 | irq_chip->irq_mask_ack = advk_pcie_irq_mask; |
| 1241 | irq_chip->irq_unmask = advk_pcie_irq_unmask; |
| 1242 | |
| 1243 | pcie->irq_domain = |
Paul Burton | 0d2977a | 2017-08-15 16:26:03 -0500 | [diff] [blame] | 1244 | irq_domain_add_linear(pcie_intc_node, PCI_NUM_INTX, |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1245 | &advk_pcie_irq_domain_ops, pcie); |
| 1246 | if (!pcie->irq_domain) { |
| 1247 | dev_err(dev, "Failed to get a INTx IRQ domain\n"); |
Wen Yang | 3842f51 | 2019-02-27 12:40:40 +0800 | [diff] [blame] | 1248 | ret = -ENOMEM; |
| 1249 | goto out_put_node; |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1250 | } |
| 1251 | |
Wen Yang | 3842f51 | 2019-02-27 12:40:40 +0800 | [diff] [blame] | 1252 | out_put_node: |
| 1253 | of_node_put(pcie_intc_node); |
| 1254 | return ret; |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | static void advk_pcie_remove_irq_domain(struct advk_pcie *pcie) |
| 1258 | { |
| 1259 | irq_domain_remove(pcie->irq_domain); |
| 1260 | } |
| 1261 | |
| 1262 | static void advk_pcie_handle_msi(struct advk_pcie *pcie) |
| 1263 | { |
| 1264 | u32 msi_val, msi_mask, msi_status, msi_idx; |
| 1265 | u16 msi_data; |
| 1266 | |
| 1267 | msi_mask = advk_readl(pcie, PCIE_MSI_MASK_REG); |
| 1268 | msi_val = advk_readl(pcie, PCIE_MSI_STATUS_REG); |
| 1269 | msi_status = msi_val & ~msi_mask; |
| 1270 | |
| 1271 | for (msi_idx = 0; msi_idx < MSI_IRQ_NUM; msi_idx++) { |
| 1272 | if (!(BIT(msi_idx) & msi_status)) |
| 1273 | continue; |
| 1274 | |
| 1275 | advk_writel(pcie, BIT(msi_idx), PCIE_MSI_STATUS_REG); |
| 1276 | msi_data = advk_readl(pcie, PCIE_MSI_PAYLOAD_REG) & 0xFF; |
| 1277 | generic_handle_irq(msi_data); |
| 1278 | } |
| 1279 | |
| 1280 | advk_writel(pcie, PCIE_ISR0_MSI_INT_PENDING, |
| 1281 | PCIE_ISR0_REG); |
| 1282 | } |
| 1283 | |
| 1284 | static void advk_pcie_handle_int(struct advk_pcie *pcie) |
| 1285 | { |
Victor Gu | 3430f92 | 2018-04-06 16:55:33 +0200 | [diff] [blame] | 1286 | u32 isr0_val, isr0_mask, isr0_status; |
| 1287 | u32 isr1_val, isr1_mask, isr1_status; |
Marc Zyngier | d21faba1 | 2021-08-02 17:26:19 +0100 | [diff] [blame] | 1288 | int i; |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1289 | |
Victor Gu | 3430f92 | 2018-04-06 16:55:33 +0200 | [diff] [blame] | 1290 | isr0_val = advk_readl(pcie, PCIE_ISR0_REG); |
| 1291 | isr0_mask = advk_readl(pcie, PCIE_ISR0_MASK_REG); |
| 1292 | isr0_status = isr0_val & ((~isr0_mask) & PCIE_ISR0_ALL_MASK); |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1293 | |
Victor Gu | 3430f92 | 2018-04-06 16:55:33 +0200 | [diff] [blame] | 1294 | isr1_val = advk_readl(pcie, PCIE_ISR1_REG); |
| 1295 | isr1_mask = advk_readl(pcie, PCIE_ISR1_MASK_REG); |
| 1296 | isr1_status = isr1_val & ((~isr1_mask) & PCIE_ISR1_ALL_MASK); |
| 1297 | |
| 1298 | if (!isr0_status && !isr1_status) { |
| 1299 | advk_writel(pcie, isr0_val, PCIE_ISR0_REG); |
| 1300 | advk_writel(pcie, isr1_val, PCIE_ISR1_REG); |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1301 | return; |
| 1302 | } |
| 1303 | |
| 1304 | /* Process MSI interrupts */ |
Victor Gu | 3430f92 | 2018-04-06 16:55:33 +0200 | [diff] [blame] | 1305 | if (isr0_status & PCIE_ISR0_MSI_INT_PENDING) |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1306 | advk_pcie_handle_msi(pcie); |
| 1307 | |
| 1308 | /* Process legacy interrupts */ |
Paul Burton | 0d2977a | 2017-08-15 16:26:03 -0500 | [diff] [blame] | 1309 | for (i = 0; i < PCI_NUM_INTX; i++) { |
Victor Gu | 3430f92 | 2018-04-06 16:55:33 +0200 | [diff] [blame] | 1310 | if (!(isr1_status & PCIE_ISR1_INTX_ASSERT(i))) |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1311 | continue; |
| 1312 | |
Victor Gu | 3430f92 | 2018-04-06 16:55:33 +0200 | [diff] [blame] | 1313 | advk_writel(pcie, PCIE_ISR1_INTX_ASSERT(i), |
| 1314 | PCIE_ISR1_REG); |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1315 | |
Marc Zyngier | d21faba1 | 2021-08-02 17:26:19 +0100 | [diff] [blame] | 1316 | generic_handle_domain_irq(pcie->irq_domain, i); |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1317 | } |
| 1318 | } |
| 1319 | |
| 1320 | static irqreturn_t advk_pcie_irq_handler(int irq, void *arg) |
| 1321 | { |
| 1322 | struct advk_pcie *pcie = arg; |
| 1323 | u32 status; |
| 1324 | |
| 1325 | status = advk_readl(pcie, HOST_CTRL_INT_STATUS_REG); |
| 1326 | if (!(status & PCIE_IRQ_CORE_INT)) |
| 1327 | return IRQ_NONE; |
| 1328 | |
| 1329 | advk_pcie_handle_int(pcie); |
| 1330 | |
| 1331 | /* Clear interrupt */ |
| 1332 | advk_writel(pcie, PCIE_IRQ_CORE_INT, HOST_CTRL_INT_STATUS_REG); |
| 1333 | |
| 1334 | return IRQ_HANDLED; |
| 1335 | } |
| 1336 | |
Marek Behún | 3666970 | 2020-04-30 10:06:20 +0200 | [diff] [blame] | 1337 | static void __maybe_unused advk_pcie_disable_phy(struct advk_pcie *pcie) |
| 1338 | { |
| 1339 | phy_power_off(pcie->phy); |
| 1340 | phy_exit(pcie->phy); |
| 1341 | } |
| 1342 | |
| 1343 | static int advk_pcie_enable_phy(struct advk_pcie *pcie) |
| 1344 | { |
| 1345 | int ret; |
| 1346 | |
| 1347 | if (!pcie->phy) |
| 1348 | return 0; |
| 1349 | |
| 1350 | ret = phy_init(pcie->phy); |
| 1351 | if (ret) |
| 1352 | return ret; |
| 1353 | |
| 1354 | ret = phy_set_mode(pcie->phy, PHY_MODE_PCIE); |
| 1355 | if (ret) { |
| 1356 | phy_exit(pcie->phy); |
| 1357 | return ret; |
| 1358 | } |
| 1359 | |
| 1360 | ret = phy_power_on(pcie->phy); |
Pali Rohár | b0c6ae0 | 2020-09-02 16:43:44 +0200 | [diff] [blame] | 1361 | if (ret == -EOPNOTSUPP) { |
| 1362 | dev_warn(&pcie->pdev->dev, "PHY unsupported by firmware\n"); |
| 1363 | } else if (ret) { |
Marek Behún | 3666970 | 2020-04-30 10:06:20 +0200 | [diff] [blame] | 1364 | phy_exit(pcie->phy); |
| 1365 | return ret; |
| 1366 | } |
| 1367 | |
| 1368 | return 0; |
| 1369 | } |
| 1370 | |
| 1371 | static int advk_pcie_setup_phy(struct advk_pcie *pcie) |
| 1372 | { |
| 1373 | struct device *dev = &pcie->pdev->dev; |
| 1374 | struct device_node *node = dev->of_node; |
| 1375 | int ret = 0; |
| 1376 | |
| 1377 | pcie->phy = devm_of_phy_get(dev, node, NULL); |
| 1378 | if (IS_ERR(pcie->phy) && (PTR_ERR(pcie->phy) == -EPROBE_DEFER)) |
| 1379 | return PTR_ERR(pcie->phy); |
| 1380 | |
| 1381 | /* Old bindings miss the PHY handle */ |
| 1382 | if (IS_ERR(pcie->phy)) { |
| 1383 | dev_warn(dev, "PHY unavailable (%ld)\n", PTR_ERR(pcie->phy)); |
| 1384 | pcie->phy = NULL; |
| 1385 | return 0; |
| 1386 | } |
| 1387 | |
| 1388 | ret = advk_pcie_enable_phy(pcie); |
| 1389 | if (ret) |
| 1390 | dev_err(dev, "Failed to initialize PHY (%d)\n", ret); |
| 1391 | |
| 1392 | return ret; |
| 1393 | } |
| 1394 | |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1395 | static int advk_pcie_probe(struct platform_device *pdev) |
| 1396 | { |
Bjorn Helgaas | 9aec2fe | 2016-10-06 13:27:46 -0500 | [diff] [blame] | 1397 | struct device *dev = &pdev->dev; |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1398 | struct advk_pcie *pcie; |
Lorenzo Pieralisi | 6b6de6a | 2017-06-28 15:13:56 -0500 | [diff] [blame] | 1399 | struct pci_host_bridge *bridge; |
Pali Rohár | 64f160e | 2021-06-24 23:55:45 +0200 | [diff] [blame] | 1400 | struct resource_entry *entry; |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1401 | int ret, irq; |
| 1402 | |
Lorenzo Pieralisi | 6b6de6a | 2017-06-28 15:13:56 -0500 | [diff] [blame] | 1403 | bridge = devm_pci_alloc_host_bridge(dev, sizeof(struct advk_pcie)); |
| 1404 | if (!bridge) |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1405 | return -ENOMEM; |
| 1406 | |
Lorenzo Pieralisi | 6b6de6a | 2017-06-28 15:13:56 -0500 | [diff] [blame] | 1407 | pcie = pci_host_bridge_priv(bridge); |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1408 | pcie->pdev = pdev; |
Pali Rohár | 526a769 | 2020-09-07 13:10:37 +0200 | [diff] [blame] | 1409 | platform_set_drvdata(pdev, pcie); |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1410 | |
Pali Rohár | 64f160e | 2021-06-24 23:55:45 +0200 | [diff] [blame] | 1411 | resource_list_for_each_entry(entry, &bridge->windows) { |
| 1412 | resource_size_t start = entry->res->start; |
| 1413 | resource_size_t size = resource_size(entry->res); |
| 1414 | unsigned long type = resource_type(entry->res); |
| 1415 | u64 win_size; |
| 1416 | |
| 1417 | /* |
| 1418 | * Aardvark hardware allows to configure also PCIe window |
| 1419 | * for config type 0 and type 1 mapping, but driver uses |
| 1420 | * only PIO for issuing configuration transfers which does |
| 1421 | * not use PCIe window configuration. |
| 1422 | */ |
| 1423 | if (type != IORESOURCE_MEM && type != IORESOURCE_MEM_64 && |
| 1424 | type != IORESOURCE_IO) |
| 1425 | continue; |
| 1426 | |
| 1427 | /* |
| 1428 | * Skip transparent memory resources. Default outbound access |
| 1429 | * configuration is set to transparent memory access so it |
| 1430 | * does not need window configuration. |
| 1431 | */ |
| 1432 | if ((type == IORESOURCE_MEM || type == IORESOURCE_MEM_64) && |
| 1433 | entry->offset == 0) |
| 1434 | continue; |
| 1435 | |
| 1436 | /* |
| 1437 | * The n-th PCIe window is configured by tuple (match, remap, mask) |
| 1438 | * and an access to address A uses this window if A matches the |
| 1439 | * match with given mask. |
| 1440 | * So every PCIe window size must be a power of two and every start |
| 1441 | * address must be aligned to window size. Minimal size is 64 KiB |
| 1442 | * because lower 16 bits of mask must be zero. Remapped address |
| 1443 | * may have set only bits from the mask. |
| 1444 | */ |
| 1445 | while (pcie->wins_count < OB_WIN_COUNT && size > 0) { |
| 1446 | /* Calculate the largest aligned window size */ |
| 1447 | win_size = (1ULL << (fls64(size)-1)) | |
| 1448 | (start ? (1ULL << __ffs64(start)) : 0); |
| 1449 | win_size = 1ULL << __ffs64(win_size); |
| 1450 | if (win_size < 0x10000) |
| 1451 | break; |
| 1452 | |
| 1453 | dev_dbg(dev, |
| 1454 | "Configuring PCIe window %d: [0x%llx-0x%llx] as %lu\n", |
| 1455 | pcie->wins_count, (unsigned long long)start, |
| 1456 | (unsigned long long)start + win_size, type); |
| 1457 | |
| 1458 | if (type == IORESOURCE_IO) { |
| 1459 | pcie->wins[pcie->wins_count].actions = OB_WIN_TYPE_IO; |
| 1460 | pcie->wins[pcie->wins_count].match = pci_pio_to_address(start); |
| 1461 | } else { |
| 1462 | pcie->wins[pcie->wins_count].actions = OB_WIN_TYPE_MEM; |
| 1463 | pcie->wins[pcie->wins_count].match = start; |
| 1464 | } |
| 1465 | pcie->wins[pcie->wins_count].remap = start - entry->offset; |
| 1466 | pcie->wins[pcie->wins_count].mask = ~(win_size - 1); |
| 1467 | |
| 1468 | if (pcie->wins[pcie->wins_count].remap & (win_size - 1)) |
| 1469 | break; |
| 1470 | |
| 1471 | start += win_size; |
| 1472 | size -= win_size; |
| 1473 | pcie->wins_count++; |
| 1474 | } |
| 1475 | |
| 1476 | if (size > 0) { |
| 1477 | dev_err(&pcie->pdev->dev, |
| 1478 | "Invalid PCIe region [0x%llx-0x%llx]\n", |
| 1479 | (unsigned long long)entry->res->start, |
| 1480 | (unsigned long long)entry->res->end + 1); |
| 1481 | return -EINVAL; |
| 1482 | } |
| 1483 | } |
| 1484 | |
Dejin Zheng | 3cf0eea | 2020-07-08 23:56:14 +0800 | [diff] [blame] | 1485 | pcie->base = devm_platform_ioremap_resource(pdev, 0); |
Wei Yongjun | 8b22335 | 2016-07-28 16:17:14 +0000 | [diff] [blame] | 1486 | if (IS_ERR(pcie->base)) |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1487 | return PTR_ERR(pcie->base); |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1488 | |
| 1489 | irq = platform_get_irq(pdev, 0); |
Aman Sharma | 0584bff | 2020-03-12 00:49:02 +0530 | [diff] [blame] | 1490 | if (irq < 0) |
| 1491 | return irq; |
| 1492 | |
Bjorn Helgaas | 9aec2fe | 2016-10-06 13:27:46 -0500 | [diff] [blame] | 1493 | ret = devm_request_irq(dev, irq, advk_pcie_irq_handler, |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1494 | IRQF_SHARED | IRQF_NO_THREAD, "advk-pcie", |
| 1495 | pcie); |
| 1496 | if (ret) { |
Bjorn Helgaas | 9aec2fe | 2016-10-06 13:27:46 -0500 | [diff] [blame] | 1497 | dev_err(dev, "Failed to register interrupt\n"); |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1498 | return ret; |
| 1499 | } |
| 1500 | |
Pali Rohár | 5169a98 | 2020-04-30 10:06:18 +0200 | [diff] [blame] | 1501 | pcie->reset_gpio = devm_gpiod_get_from_of_node(dev, dev->of_node, |
| 1502 | "reset-gpios", 0, |
| 1503 | GPIOD_OUT_LOW, |
| 1504 | "pcie1-reset"); |
| 1505 | ret = PTR_ERR_OR_ZERO(pcie->reset_gpio); |
| 1506 | if (ret) { |
| 1507 | if (ret == -ENOENT) { |
| 1508 | pcie->reset_gpio = NULL; |
| 1509 | } else { |
| 1510 | if (ret != -EPROBE_DEFER) |
| 1511 | dev_err(dev, "Failed to get reset-gpio: %i\n", |
| 1512 | ret); |
| 1513 | return ret; |
| 1514 | } |
| 1515 | } |
| 1516 | |
Marek Behún | 43fc679 | 2020-04-30 10:06:17 +0200 | [diff] [blame] | 1517 | ret = of_pci_get_max_link_speed(dev->of_node); |
| 1518 | if (ret <= 0 || ret > 3) |
| 1519 | pcie->link_gen = 3; |
| 1520 | else |
| 1521 | pcie->link_gen = ret; |
| 1522 | |
Marek Behún | 3666970 | 2020-04-30 10:06:20 +0200 | [diff] [blame] | 1523 | ret = advk_pcie_setup_phy(pcie); |
| 1524 | if (ret) |
| 1525 | return ret; |
| 1526 | |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1527 | advk_pcie_setup_hw(pcie); |
| 1528 | |
Pali Rohár | 7862a61 | 2020-09-07 13:10:35 +0200 | [diff] [blame] | 1529 | ret = advk_sw_pci_bridge_init(pcie); |
| 1530 | if (ret) { |
| 1531 | dev_err(dev, "Failed to register emulated root PCI bridge\n"); |
| 1532 | return ret; |
| 1533 | } |
Zachary Zhang | 8a3ebd8 | 2018-10-18 17:37:19 +0200 | [diff] [blame] | 1534 | |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1535 | ret = advk_pcie_init_irq_domain(pcie); |
| 1536 | if (ret) { |
Bjorn Helgaas | 9aec2fe | 2016-10-06 13:27:46 -0500 | [diff] [blame] | 1537 | dev_err(dev, "Failed to initialize irq\n"); |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1538 | return ret; |
| 1539 | } |
| 1540 | |
| 1541 | ret = advk_pcie_init_msi_irq_domain(pcie); |
| 1542 | if (ret) { |
Bjorn Helgaas | 9aec2fe | 2016-10-06 13:27:46 -0500 | [diff] [blame] | 1543 | dev_err(dev, "Failed to initialize irq\n"); |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1544 | advk_pcie_remove_irq_domain(pcie); |
| 1545 | return ret; |
| 1546 | } |
| 1547 | |
Lorenzo Pieralisi | 6b6de6a | 2017-06-28 15:13:56 -0500 | [diff] [blame] | 1548 | bridge->sysdata = pcie; |
Lorenzo Pieralisi | 6b6de6a | 2017-06-28 15:13:56 -0500 | [diff] [blame] | 1549 | bridge->ops = &advk_pcie_ops; |
| 1550 | |
Thomas Petazzoni | c8e144f | 2018-06-29 11:16:20 +0200 | [diff] [blame] | 1551 | ret = pci_host_probe(bridge); |
Lorenzo Pieralisi | 6b6de6a | 2017-06-28 15:13:56 -0500 | [diff] [blame] | 1552 | if (ret < 0) { |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1553 | advk_pcie_remove_msi_irq_domain(pcie); |
| 1554 | advk_pcie_remove_irq_domain(pcie); |
Lorenzo Pieralisi | 6b6de6a | 2017-06-28 15:13:56 -0500 | [diff] [blame] | 1555 | return ret; |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1556 | } |
| 1557 | |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1558 | return 0; |
| 1559 | } |
| 1560 | |
Pali Rohár | 526a769 | 2020-09-07 13:10:37 +0200 | [diff] [blame] | 1561 | static int advk_pcie_remove(struct platform_device *pdev) |
| 1562 | { |
| 1563 | struct advk_pcie *pcie = platform_get_drvdata(pdev); |
| 1564 | struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie); |
Pali Rohár | 64f160e | 2021-06-24 23:55:45 +0200 | [diff] [blame] | 1565 | int i; |
Pali Rohár | 526a769 | 2020-09-07 13:10:37 +0200 | [diff] [blame] | 1566 | |
| 1567 | pci_lock_rescan_remove(); |
| 1568 | pci_stop_root_bus(bridge->bus); |
| 1569 | pci_remove_root_bus(bridge->bus); |
| 1570 | pci_unlock_rescan_remove(); |
| 1571 | |
| 1572 | advk_pcie_remove_msi_irq_domain(pcie); |
| 1573 | advk_pcie_remove_irq_domain(pcie); |
| 1574 | |
Pali Rohár | 64f160e | 2021-06-24 23:55:45 +0200 | [diff] [blame] | 1575 | /* Disable outbound address windows mapping */ |
| 1576 | for (i = 0; i < OB_WIN_COUNT; i++) |
| 1577 | advk_pcie_disable_ob_win(pcie, i); |
| 1578 | |
Pali Rohár | 526a769 | 2020-09-07 13:10:37 +0200 | [diff] [blame] | 1579 | return 0; |
| 1580 | } |
| 1581 | |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1582 | static const struct of_device_id advk_pcie_of_match_table[] = { |
| 1583 | { .compatible = "marvell,armada-3700-pcie", }, |
| 1584 | {}, |
| 1585 | }; |
Pali Rohár | 526a769 | 2020-09-07 13:10:37 +0200 | [diff] [blame] | 1586 | MODULE_DEVICE_TABLE(of, advk_pcie_of_match_table); |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1587 | |
| 1588 | static struct platform_driver advk_pcie_driver = { |
| 1589 | .driver = { |
| 1590 | .name = "advk-pcie", |
| 1591 | .of_match_table = advk_pcie_of_match_table, |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1592 | }, |
| 1593 | .probe = advk_pcie_probe, |
Pali Rohár | 526a769 | 2020-09-07 13:10:37 +0200 | [diff] [blame] | 1594 | .remove = advk_pcie_remove, |
Thomas Petazzoni | 8c39d71 | 2016-06-30 11:32:31 +0200 | [diff] [blame] | 1595 | }; |
Pali Rohár | 526a769 | 2020-09-07 13:10:37 +0200 | [diff] [blame] | 1596 | module_platform_driver(advk_pcie_driver); |
| 1597 | |
| 1598 | MODULE_DESCRIPTION("Aardvark PCIe controller"); |
| 1599 | MODULE_LICENSE("GPL v2"); |