18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * PCIe driver for Renesas R-Car SoCs 48c2ecf20Sopenharmony_ci * Copyright (C) 2014-2020 Renesas Electronics Europe Ltd 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Author: Phil Edworthy <phil.edworthy@renesas.com> 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#ifndef _PCIE_RCAR_H 108c2ecf20Sopenharmony_ci#define _PCIE_RCAR_H 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#define PCIECAR 0x000010 138c2ecf20Sopenharmony_ci#define PCIECCTLR 0x000018 148c2ecf20Sopenharmony_ci#define CONFIG_SEND_ENABLE BIT(31) 158c2ecf20Sopenharmony_ci#define TYPE0 (0 << 8) 168c2ecf20Sopenharmony_ci#define TYPE1 BIT(8) 178c2ecf20Sopenharmony_ci#define PCIECDR 0x000020 188c2ecf20Sopenharmony_ci#define PCIEMSR 0x000028 198c2ecf20Sopenharmony_ci#define PCIEINTXR 0x000400 208c2ecf20Sopenharmony_ci#define ASTINTX BIT(16) 218c2ecf20Sopenharmony_ci#define PCIEPHYSR 0x0007f0 228c2ecf20Sopenharmony_ci#define PHYRDY BIT(0) 238c2ecf20Sopenharmony_ci#define PCIEMSITXR 0x000840 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci/* Transfer control */ 268c2ecf20Sopenharmony_ci#define PCIETCTLR 0x02000 278c2ecf20Sopenharmony_ci#define DL_DOWN BIT(3) 288c2ecf20Sopenharmony_ci#define CFINIT BIT(0) 298c2ecf20Sopenharmony_ci#define PCIETSTR 0x02004 308c2ecf20Sopenharmony_ci#define DATA_LINK_ACTIVE BIT(0) 318c2ecf20Sopenharmony_ci#define PCIEERRFR 0x02020 328c2ecf20Sopenharmony_ci#define UNSUPPORTED_REQUEST BIT(4) 338c2ecf20Sopenharmony_ci#define PCIEMSIFR 0x02044 348c2ecf20Sopenharmony_ci#define PCIEMSIALR 0x02048 358c2ecf20Sopenharmony_ci#define MSIFE BIT(0) 368c2ecf20Sopenharmony_ci#define PCIEMSIAUR 0x0204c 378c2ecf20Sopenharmony_ci#define PCIEMSIIER 0x02050 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci/* root port address */ 408c2ecf20Sopenharmony_ci#define PCIEPRAR(x) (0x02080 + ((x) * 0x4)) 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci/* local address reg & mask */ 438c2ecf20Sopenharmony_ci#define PCIELAR(x) (0x02200 + ((x) * 0x20)) 448c2ecf20Sopenharmony_ci#define PCIELAMR(x) (0x02208 + ((x) * 0x20)) 458c2ecf20Sopenharmony_ci#define LAM_PREFETCH BIT(3) 468c2ecf20Sopenharmony_ci#define LAM_64BIT BIT(2) 478c2ecf20Sopenharmony_ci#define LAR_ENABLE BIT(1) 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci/* PCIe address reg & mask */ 508c2ecf20Sopenharmony_ci#define PCIEPALR(x) (0x03400 + ((x) * 0x20)) 518c2ecf20Sopenharmony_ci#define PCIEPAUR(x) (0x03404 + ((x) * 0x20)) 528c2ecf20Sopenharmony_ci#define PCIEPAMR(x) (0x03408 + ((x) * 0x20)) 538c2ecf20Sopenharmony_ci#define PCIEPTCTLR(x) (0x0340c + ((x) * 0x20)) 548c2ecf20Sopenharmony_ci#define PAR_ENABLE BIT(31) 558c2ecf20Sopenharmony_ci#define IO_SPACE BIT(8) 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci/* Configuration */ 588c2ecf20Sopenharmony_ci#define PCICONF(x) (0x010000 + ((x) * 0x4)) 598c2ecf20Sopenharmony_ci#define INTDIS BIT(10) 608c2ecf20Sopenharmony_ci#define PMCAP(x) (0x010040 + ((x) * 0x4)) 618c2ecf20Sopenharmony_ci#define MSICAP(x) (0x010050 + ((x) * 0x4)) 628c2ecf20Sopenharmony_ci#define MSICAP0_MSIE BIT(16) 638c2ecf20Sopenharmony_ci#define MSICAP0_MMESCAP_OFFSET 17 648c2ecf20Sopenharmony_ci#define MSICAP0_MMESE_OFFSET 20 658c2ecf20Sopenharmony_ci#define MSICAP0_MMESE_MASK GENMASK(22, 20) 668c2ecf20Sopenharmony_ci#define EXPCAP(x) (0x010070 + ((x) * 0x4)) 678c2ecf20Sopenharmony_ci#define VCCAP(x) (0x010100 + ((x) * 0x4)) 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci/* link layer */ 708c2ecf20Sopenharmony_ci#define IDSETR0 0x011000 718c2ecf20Sopenharmony_ci#define IDSETR1 0x011004 728c2ecf20Sopenharmony_ci#define SUBIDSETR 0x011024 738c2ecf20Sopenharmony_ci#define TLCTLR 0x011048 748c2ecf20Sopenharmony_ci#define MACSR 0x011054 758c2ecf20Sopenharmony_ci#define SPCHGFIN BIT(4) 768c2ecf20Sopenharmony_ci#define SPCHGFAIL BIT(6) 778c2ecf20Sopenharmony_ci#define SPCHGSUC BIT(7) 788c2ecf20Sopenharmony_ci#define LINK_SPEED (0xf << 16) 798c2ecf20Sopenharmony_ci#define LINK_SPEED_2_5GTS (1 << 16) 808c2ecf20Sopenharmony_ci#define LINK_SPEED_5_0GTS (2 << 16) 818c2ecf20Sopenharmony_ci#define MACCTLR 0x011058 828c2ecf20Sopenharmony_ci#define MACCTLR_NFTS_MASK GENMASK(23, 16) /* The name is from SH7786 */ 838c2ecf20Sopenharmony_ci#define SPEED_CHANGE BIT(24) 848c2ecf20Sopenharmony_ci#define SCRAMBLE_DISABLE BIT(27) 858c2ecf20Sopenharmony_ci#define LTSMDIS BIT(31) 868c2ecf20Sopenharmony_ci#define MACCTLR_INIT_VAL (LTSMDIS | MACCTLR_NFTS_MASK) 878c2ecf20Sopenharmony_ci#define PMSR 0x01105c 888c2ecf20Sopenharmony_ci#define MACS2R 0x011078 898c2ecf20Sopenharmony_ci#define MACCGSPSETR 0x011084 908c2ecf20Sopenharmony_ci#define SPCNGRSN BIT(31) 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci/* R-Car H1 PHY */ 938c2ecf20Sopenharmony_ci#define H1_PCIEPHYADRR 0x04000c 948c2ecf20Sopenharmony_ci#define WRITE_CMD BIT(16) 958c2ecf20Sopenharmony_ci#define PHY_ACK BIT(24) 968c2ecf20Sopenharmony_ci#define RATE_POS 12 978c2ecf20Sopenharmony_ci#define LANE_POS 8 988c2ecf20Sopenharmony_ci#define ADR_POS 0 998c2ecf20Sopenharmony_ci#define H1_PCIEPHYDOUTR 0x040014 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci/* R-Car Gen2 PHY */ 1028c2ecf20Sopenharmony_ci#define GEN2_PCIEPHYADDR 0x780 1038c2ecf20Sopenharmony_ci#define GEN2_PCIEPHYDATA 0x784 1048c2ecf20Sopenharmony_ci#define GEN2_PCIEPHYCTRL 0x78c 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci#define INT_PCI_MSI_NR 32 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci#define RCONF(x) (PCICONF(0) + (x)) 1098c2ecf20Sopenharmony_ci#define RPMCAP(x) (PMCAP(0) + (x)) 1108c2ecf20Sopenharmony_ci#define REXPCAP(x) (EXPCAP(0) + (x)) 1118c2ecf20Sopenharmony_ci#define RVCCAP(x) (VCCAP(0) + (x)) 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci#define PCIE_CONF_BUS(b) (((b) & 0xff) << 24) 1148c2ecf20Sopenharmony_ci#define PCIE_CONF_DEV(d) (((d) & 0x1f) << 19) 1158c2ecf20Sopenharmony_ci#define PCIE_CONF_FUNC(f) (((f) & 0x7) << 16) 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci#define RCAR_PCI_MAX_RESOURCES 4 1188c2ecf20Sopenharmony_ci#define MAX_NR_INBOUND_MAPS 6 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_cistruct rcar_pcie { 1218c2ecf20Sopenharmony_ci struct device *dev; 1228c2ecf20Sopenharmony_ci void __iomem *base; 1238c2ecf20Sopenharmony_ci}; 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_cienum { 1268c2ecf20Sopenharmony_ci RCAR_PCI_ACCESS_READ, 1278c2ecf20Sopenharmony_ci RCAR_PCI_ACCESS_WRITE, 1288c2ecf20Sopenharmony_ci}; 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_civoid rcar_pci_write_reg(struct rcar_pcie *pcie, u32 val, unsigned int reg); 1318c2ecf20Sopenharmony_ciu32 rcar_pci_read_reg(struct rcar_pcie *pcie, unsigned int reg); 1328c2ecf20Sopenharmony_civoid rcar_rmw32(struct rcar_pcie *pcie, int where, u32 mask, u32 data); 1338c2ecf20Sopenharmony_ciint rcar_pcie_wait_for_phyrdy(struct rcar_pcie *pcie); 1348c2ecf20Sopenharmony_ciint rcar_pcie_wait_for_dl(struct rcar_pcie *pcie); 1358c2ecf20Sopenharmony_civoid rcar_pcie_set_outbound(struct rcar_pcie *pcie, int win, 1368c2ecf20Sopenharmony_ci struct resource_entry *window); 1378c2ecf20Sopenharmony_civoid rcar_pcie_set_inbound(struct rcar_pcie *pcie, u64 cpu_addr, 1388c2ecf20Sopenharmony_ci u64 pci_addr, u64 flags, int idx, bool host); 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci#endif 141