Skip to content

Commit 39b91eb

Browse files
mindachen1987bjorn-helgaas
authored andcommitted
PCI: starfive: Add JH7110 PCIe controller
Add StarFive JH7110 SoC PCIe controller platform driver code, JH7110 with PLDA host PCIe core. Link: https://lore.kernel.org/linux-pci/[email protected] Co-developed-by: Kevin Xie <[email protected]> Signed-off-by: Minda Chen <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Mason Huo <[email protected]>
1 parent 22fe322 commit 39b91eb

File tree

5 files changed

+572
-1
lines changed

5 files changed

+572
-1
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17492,6 +17492,7 @@ M: Kevin Xie <[email protected]>
1749217492
1749317493
S: Maintained
1749417494
F: Documentation/devicetree/bindings/pci/starfive,jh7110-pcie.yaml
17495+
F: drivers/pci/controller/plda/pcie-starfive.c
1749517496

1749617497
PCIE ENDPOINT DRIVER FOR QUALCOMM
1749717498
M: Manivannan Sadhasivam <[email protected]>

drivers/pci/controller/plda/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,16 @@ config PCIE_MICROCHIP_HOST
1515
Say Y here if you want kernel to support the Microchip AXI PCIe
1616
Host Bridge driver.
1717

18+
config PCIE_STARFIVE_HOST
19+
tristate "StarFive PCIe host controller"
20+
depends on PCI_MSI && OF
21+
depends on ARCH_STARFIVE || COMPILE_TEST
22+
select PCIE_PLDA_HOST
23+
help
24+
Say Y here if you want to support the StarFive PCIe controller in
25+
host mode. StarFive PCIe controller uses PLDA PCIe core.
26+
27+
If you choose to build this driver as module it will be dynamically
28+
linked and module will be called pcie-starfive.ko.
29+
1830
endmenu

drivers/pci/controller/plda/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# SPDX-License-Identifier: GPL-2.0
22
obj-$(CONFIG_PCIE_PLDA_HOST) += pcie-plda-host.o
33
obj-$(CONFIG_PCIE_MICROCHIP_HOST) += pcie-microchip-host.o
4+
obj-$(CONFIG_PCIE_STARFIVE_HOST) += pcie-starfive.o

drivers/pci/controller/plda/pcie-plda.h

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,20 @@
1010
#define PLDA_MAX_NUM_MSI_IRQS 32
1111

1212
/* PCIe Bridge Phy Regs */
13+
#define GEN_SETTINGS 0x80
14+
#define RP_ENABLE 1
15+
#define PCIE_PCI_IDS_DW1 0x9c
16+
#define IDS_CLASS_CODE_SHIFT 16
17+
#define REVISION_ID_MASK GENMASK(7, 0)
18+
#define CLASS_CODE_ID_MASK GENMASK(31, 8)
1319
#define PCIE_PCI_IRQ_DW0 0xa8
1420
#define MSIX_CAP_MASK BIT(31)
1521
#define NUM_MSI_MSGS_MASK GENMASK(6, 4)
1622
#define NUM_MSI_MSGS_SHIFT 4
23+
#define PCI_MISC 0xb4
24+
#define PHY_FUNCTION_DIS BIT(15)
25+
#define PCIE_WINROM 0xfc
26+
#define PREF_MEM_WIN_64_SUPPORT BIT(3)
1727

1828
#define IMASK_LOCAL 0x180
1929
#define DMA_END_ENGINE_0_MASK 0x00000000u
@@ -65,6 +75,8 @@
6575
#define ISTATUS_HOST 0x18c
6676
#define IMSI_ADDR 0x190
6777
#define ISTATUS_MSI 0x194
78+
#define PMSG_SUPPORT_RX 0x3f0
79+
#define PMSG_LTR_SUPPORT BIT(2)
6880

6981
/* PCIe Master table init defines */
7082
#define ATR0_PCIE_WIN0_SRCADDR_PARAM 0x600u
@@ -86,6 +98,8 @@
8698
#define PCIE_TX_RX_INTERFACE 0x00000000u
8799
#define PCIE_CONFIG_INTERFACE 0x00000001u
88100

101+
#define CONFIG_SPACE_ADDR_OFFSET 0x1000u
102+
89103
#define ATR_ENTRY_SIZE 32
90104

91105
enum plda_int_event {
@@ -201,4 +215,59 @@ static inline void plda_set_default_msi(struct plda_msi *msi)
201215
msi->vector_phy = IMSI_ADDR;
202216
msi->num_vectors = PLDA_MAX_NUM_MSI_IRQS;
203217
}
204-
#endif
218+
219+
static inline void plda_pcie_enable_root_port(struct plda_pcie_rp *plda)
220+
{
221+
u32 value;
222+
223+
value = readl_relaxed(plda->bridge_addr + GEN_SETTINGS);
224+
value |= RP_ENABLE;
225+
writel_relaxed(value, plda->bridge_addr + GEN_SETTINGS);
226+
}
227+
228+
static inline void plda_pcie_set_standard_class(struct plda_pcie_rp *plda)
229+
{
230+
u32 value;
231+
232+
/* set class code and reserve revision id */
233+
value = readl_relaxed(plda->bridge_addr + PCIE_PCI_IDS_DW1);
234+
value &= REVISION_ID_MASK;
235+
value |= (PCI_CLASS_BRIDGE_PCI << IDS_CLASS_CODE_SHIFT);
236+
writel_relaxed(value, plda->bridge_addr + PCIE_PCI_IDS_DW1);
237+
}
238+
239+
static inline void plda_pcie_set_pref_win_64bit(struct plda_pcie_rp *plda)
240+
{
241+
u32 value;
242+
243+
value = readl_relaxed(plda->bridge_addr + PCIE_WINROM);
244+
value |= PREF_MEM_WIN_64_SUPPORT;
245+
writel_relaxed(value, plda->bridge_addr + PCIE_WINROM);
246+
}
247+
248+
static inline void plda_pcie_disable_ltr(struct plda_pcie_rp *plda)
249+
{
250+
u32 value;
251+
252+
value = readl_relaxed(plda->bridge_addr + PMSG_SUPPORT_RX);
253+
value &= ~PMSG_LTR_SUPPORT;
254+
writel_relaxed(value, plda->bridge_addr + PMSG_SUPPORT_RX);
255+
}
256+
257+
static inline void plda_pcie_disable_func(struct plda_pcie_rp *plda)
258+
{
259+
u32 value;
260+
261+
value = readl_relaxed(plda->bridge_addr + PCI_MISC);
262+
value |= PHY_FUNCTION_DIS;
263+
writel_relaxed(value, plda->bridge_addr + PCI_MISC);
264+
}
265+
266+
static inline void plda_pcie_write_rc_bar(struct plda_pcie_rp *plda, u64 val)
267+
{
268+
void __iomem *addr = plda->bridge_addr + CONFIG_SPACE_ADDR_OFFSET;
269+
270+
writel_relaxed(lower_32_bits(val), addr + PCI_BASE_ADDRESS_0);
271+
writel_relaxed(upper_32_bits(val), addr + PCI_BASE_ADDRESS_1);
272+
}
273+
#endif /* _PCIE_PLDA_H */

0 commit comments

Comments
 (0)