18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Support for V3 Semiconductor PCI Local Bus to PCI Bridge 48c2ecf20Sopenharmony_ci * Copyright (C) 2017 Linus Walleij <linus.walleij@linaro.org> 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Based on the code from arch/arm/mach-integrator/pci_v3.c 78c2ecf20Sopenharmony_ci * Copyright (C) 1999 ARM Limited 88c2ecf20Sopenharmony_ci * Copyright (C) 2000-2001 Deep Blue Solutions Ltd 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * Contributors to the old driver include: 118c2ecf20Sopenharmony_ci * Russell King <linux@armlinux.org.uk> 128c2ecf20Sopenharmony_ci * David A. Rusling <david.rusling@linaro.org> (uHAL, ARM Firmware suite) 138c2ecf20Sopenharmony_ci * Rob Herring <robh@kernel.org> 148c2ecf20Sopenharmony_ci * Liviu Dudau <Liviu.Dudau@arm.com> 158c2ecf20Sopenharmony_ci * Grant Likely <grant.likely@secretlab.ca> 168c2ecf20Sopenharmony_ci * Arnd Bergmann <arnd@arndb.de> 178c2ecf20Sopenharmony_ci * Bjorn Helgaas <bhelgaas@google.com> 188c2ecf20Sopenharmony_ci */ 198c2ecf20Sopenharmony_ci#include <linux/init.h> 208c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 218c2ecf20Sopenharmony_ci#include <linux/io.h> 228c2ecf20Sopenharmony_ci#include <linux/kernel.h> 238c2ecf20Sopenharmony_ci#include <linux/of_address.h> 248c2ecf20Sopenharmony_ci#include <linux/of_device.h> 258c2ecf20Sopenharmony_ci#include <linux/of_irq.h> 268c2ecf20Sopenharmony_ci#include <linux/of_pci.h> 278c2ecf20Sopenharmony_ci#include <linux/pci.h> 288c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 298c2ecf20Sopenharmony_ci#include <linux/slab.h> 308c2ecf20Sopenharmony_ci#include <linux/bitops.h> 318c2ecf20Sopenharmony_ci#include <linux/irq.h> 328c2ecf20Sopenharmony_ci#include <linux/mfd/syscon.h> 338c2ecf20Sopenharmony_ci#include <linux/regmap.h> 348c2ecf20Sopenharmony_ci#include <linux/clk.h> 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#include "../pci.h" 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#define V3_PCI_VENDOR 0x00000000 398c2ecf20Sopenharmony_ci#define V3_PCI_DEVICE 0x00000002 408c2ecf20Sopenharmony_ci#define V3_PCI_CMD 0x00000004 418c2ecf20Sopenharmony_ci#define V3_PCI_STAT 0x00000006 428c2ecf20Sopenharmony_ci#define V3_PCI_CC_REV 0x00000008 438c2ecf20Sopenharmony_ci#define V3_PCI_HDR_CFG 0x0000000C 448c2ecf20Sopenharmony_ci#define V3_PCI_IO_BASE 0x00000010 458c2ecf20Sopenharmony_ci#define V3_PCI_BASE0 0x00000014 468c2ecf20Sopenharmony_ci#define V3_PCI_BASE1 0x00000018 478c2ecf20Sopenharmony_ci#define V3_PCI_SUB_VENDOR 0x0000002C 488c2ecf20Sopenharmony_ci#define V3_PCI_SUB_ID 0x0000002E 498c2ecf20Sopenharmony_ci#define V3_PCI_ROM 0x00000030 508c2ecf20Sopenharmony_ci#define V3_PCI_BPARAM 0x0000003C 518c2ecf20Sopenharmony_ci#define V3_PCI_MAP0 0x00000040 528c2ecf20Sopenharmony_ci#define V3_PCI_MAP1 0x00000044 538c2ecf20Sopenharmony_ci#define V3_PCI_INT_STAT 0x00000048 548c2ecf20Sopenharmony_ci#define V3_PCI_INT_CFG 0x0000004C 558c2ecf20Sopenharmony_ci#define V3_LB_BASE0 0x00000054 568c2ecf20Sopenharmony_ci#define V3_LB_BASE1 0x00000058 578c2ecf20Sopenharmony_ci#define V3_LB_MAP0 0x0000005E 588c2ecf20Sopenharmony_ci#define V3_LB_MAP1 0x00000062 598c2ecf20Sopenharmony_ci#define V3_LB_BASE2 0x00000064 608c2ecf20Sopenharmony_ci#define V3_LB_MAP2 0x00000066 618c2ecf20Sopenharmony_ci#define V3_LB_SIZE 0x00000068 628c2ecf20Sopenharmony_ci#define V3_LB_IO_BASE 0x0000006E 638c2ecf20Sopenharmony_ci#define V3_FIFO_CFG 0x00000070 648c2ecf20Sopenharmony_ci#define V3_FIFO_PRIORITY 0x00000072 658c2ecf20Sopenharmony_ci#define V3_FIFO_STAT 0x00000074 668c2ecf20Sopenharmony_ci#define V3_LB_ISTAT 0x00000076 678c2ecf20Sopenharmony_ci#define V3_LB_IMASK 0x00000077 688c2ecf20Sopenharmony_ci#define V3_SYSTEM 0x00000078 698c2ecf20Sopenharmony_ci#define V3_LB_CFG 0x0000007A 708c2ecf20Sopenharmony_ci#define V3_PCI_CFG 0x0000007C 718c2ecf20Sopenharmony_ci#define V3_DMA_PCI_ADR0 0x00000080 728c2ecf20Sopenharmony_ci#define V3_DMA_PCI_ADR1 0x00000090 738c2ecf20Sopenharmony_ci#define V3_DMA_LOCAL_ADR0 0x00000084 748c2ecf20Sopenharmony_ci#define V3_DMA_LOCAL_ADR1 0x00000094 758c2ecf20Sopenharmony_ci#define V3_DMA_LENGTH0 0x00000088 768c2ecf20Sopenharmony_ci#define V3_DMA_LENGTH1 0x00000098 778c2ecf20Sopenharmony_ci#define V3_DMA_CSR0 0x0000008B 788c2ecf20Sopenharmony_ci#define V3_DMA_CSR1 0x0000009B 798c2ecf20Sopenharmony_ci#define V3_DMA_CTLB_ADR0 0x0000008C 808c2ecf20Sopenharmony_ci#define V3_DMA_CTLB_ADR1 0x0000009C 818c2ecf20Sopenharmony_ci#define V3_DMA_DELAY 0x000000E0 828c2ecf20Sopenharmony_ci#define V3_MAIL_DATA 0x000000C0 838c2ecf20Sopenharmony_ci#define V3_PCI_MAIL_IEWR 0x000000D0 848c2ecf20Sopenharmony_ci#define V3_PCI_MAIL_IERD 0x000000D2 858c2ecf20Sopenharmony_ci#define V3_LB_MAIL_IEWR 0x000000D4 868c2ecf20Sopenharmony_ci#define V3_LB_MAIL_IERD 0x000000D6 878c2ecf20Sopenharmony_ci#define V3_MAIL_WR_STAT 0x000000D8 888c2ecf20Sopenharmony_ci#define V3_MAIL_RD_STAT 0x000000DA 898c2ecf20Sopenharmony_ci#define V3_QBA_MAP 0x000000DC 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci/* PCI STATUS bits */ 928c2ecf20Sopenharmony_ci#define V3_PCI_STAT_PAR_ERR BIT(15) 938c2ecf20Sopenharmony_ci#define V3_PCI_STAT_SYS_ERR BIT(14) 948c2ecf20Sopenharmony_ci#define V3_PCI_STAT_M_ABORT_ERR BIT(13) 958c2ecf20Sopenharmony_ci#define V3_PCI_STAT_T_ABORT_ERR BIT(12) 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci/* LB ISTAT bits */ 988c2ecf20Sopenharmony_ci#define V3_LB_ISTAT_MAILBOX BIT(7) 998c2ecf20Sopenharmony_ci#define V3_LB_ISTAT_PCI_RD BIT(6) 1008c2ecf20Sopenharmony_ci#define V3_LB_ISTAT_PCI_WR BIT(5) 1018c2ecf20Sopenharmony_ci#define V3_LB_ISTAT_PCI_INT BIT(4) 1028c2ecf20Sopenharmony_ci#define V3_LB_ISTAT_PCI_PERR BIT(3) 1038c2ecf20Sopenharmony_ci#define V3_LB_ISTAT_I2O_QWR BIT(2) 1048c2ecf20Sopenharmony_ci#define V3_LB_ISTAT_DMA1 BIT(1) 1058c2ecf20Sopenharmony_ci#define V3_LB_ISTAT_DMA0 BIT(0) 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci/* PCI COMMAND bits */ 1088c2ecf20Sopenharmony_ci#define V3_COMMAND_M_FBB_EN BIT(9) 1098c2ecf20Sopenharmony_ci#define V3_COMMAND_M_SERR_EN BIT(8) 1108c2ecf20Sopenharmony_ci#define V3_COMMAND_M_PAR_EN BIT(6) 1118c2ecf20Sopenharmony_ci#define V3_COMMAND_M_MASTER_EN BIT(2) 1128c2ecf20Sopenharmony_ci#define V3_COMMAND_M_MEM_EN BIT(1) 1138c2ecf20Sopenharmony_ci#define V3_COMMAND_M_IO_EN BIT(0) 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci/* SYSTEM bits */ 1168c2ecf20Sopenharmony_ci#define V3_SYSTEM_M_RST_OUT BIT(15) 1178c2ecf20Sopenharmony_ci#define V3_SYSTEM_M_LOCK BIT(14) 1188c2ecf20Sopenharmony_ci#define V3_SYSTEM_UNLOCK 0xa05f 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci/* PCI CFG bits */ 1218c2ecf20Sopenharmony_ci#define V3_PCI_CFG_M_I2O_EN BIT(15) 1228c2ecf20Sopenharmony_ci#define V3_PCI_CFG_M_IO_REG_DIS BIT(14) 1238c2ecf20Sopenharmony_ci#define V3_PCI_CFG_M_IO_DIS BIT(13) 1248c2ecf20Sopenharmony_ci#define V3_PCI_CFG_M_EN3V BIT(12) 1258c2ecf20Sopenharmony_ci#define V3_PCI_CFG_M_RETRY_EN BIT(10) 1268c2ecf20Sopenharmony_ci#define V3_PCI_CFG_M_AD_LOW1 BIT(9) 1278c2ecf20Sopenharmony_ci#define V3_PCI_CFG_M_AD_LOW0 BIT(8) 1288c2ecf20Sopenharmony_ci/* 1298c2ecf20Sopenharmony_ci * This is the value applied to C/BE[3:1], with bit 0 always held 0 1308c2ecf20Sopenharmony_ci * during DMA access. 1318c2ecf20Sopenharmony_ci */ 1328c2ecf20Sopenharmony_ci#define V3_PCI_CFG_M_RTYPE_SHIFT 5 1338c2ecf20Sopenharmony_ci#define V3_PCI_CFG_M_WTYPE_SHIFT 1 1348c2ecf20Sopenharmony_ci#define V3_PCI_CFG_TYPE_DEFAULT 0x3 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci/* PCI BASE bits (PCI -> Local Bus) */ 1378c2ecf20Sopenharmony_ci#define V3_PCI_BASE_M_ADR_BASE 0xFFF00000U 1388c2ecf20Sopenharmony_ci#define V3_PCI_BASE_M_ADR_BASEL 0x000FFF00U 1398c2ecf20Sopenharmony_ci#define V3_PCI_BASE_M_PREFETCH BIT(3) 1408c2ecf20Sopenharmony_ci#define V3_PCI_BASE_M_TYPE (3 << 1) 1418c2ecf20Sopenharmony_ci#define V3_PCI_BASE_M_IO BIT(0) 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci/* PCI MAP bits (PCI -> Local bus) */ 1448c2ecf20Sopenharmony_ci#define V3_PCI_MAP_M_MAP_ADR 0xFFF00000U 1458c2ecf20Sopenharmony_ci#define V3_PCI_MAP_M_RD_POST_INH BIT(15) 1468c2ecf20Sopenharmony_ci#define V3_PCI_MAP_M_ROM_SIZE (3 << 10) 1478c2ecf20Sopenharmony_ci#define V3_PCI_MAP_M_SWAP (3 << 8) 1488c2ecf20Sopenharmony_ci#define V3_PCI_MAP_M_ADR_SIZE 0x000000F0U 1498c2ecf20Sopenharmony_ci#define V3_PCI_MAP_M_REG_EN BIT(1) 1508c2ecf20Sopenharmony_ci#define V3_PCI_MAP_M_ENABLE BIT(0) 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci/* LB_BASE0,1 bits (Local bus -> PCI) */ 1538c2ecf20Sopenharmony_ci#define V3_LB_BASE_ADR_BASE 0xfff00000U 1548c2ecf20Sopenharmony_ci#define V3_LB_BASE_SWAP (3 << 8) 1558c2ecf20Sopenharmony_ci#define V3_LB_BASE_ADR_SIZE (15 << 4) 1568c2ecf20Sopenharmony_ci#define V3_LB_BASE_PREFETCH BIT(3) 1578c2ecf20Sopenharmony_ci#define V3_LB_BASE_ENABLE BIT(0) 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci#define V3_LB_BASE_ADR_SIZE_1MB (0 << 4) 1608c2ecf20Sopenharmony_ci#define V3_LB_BASE_ADR_SIZE_2MB (1 << 4) 1618c2ecf20Sopenharmony_ci#define V3_LB_BASE_ADR_SIZE_4MB (2 << 4) 1628c2ecf20Sopenharmony_ci#define V3_LB_BASE_ADR_SIZE_8MB (3 << 4) 1638c2ecf20Sopenharmony_ci#define V3_LB_BASE_ADR_SIZE_16MB (4 << 4) 1648c2ecf20Sopenharmony_ci#define V3_LB_BASE_ADR_SIZE_32MB (5 << 4) 1658c2ecf20Sopenharmony_ci#define V3_LB_BASE_ADR_SIZE_64MB (6 << 4) 1668c2ecf20Sopenharmony_ci#define V3_LB_BASE_ADR_SIZE_128MB (7 << 4) 1678c2ecf20Sopenharmony_ci#define V3_LB_BASE_ADR_SIZE_256MB (8 << 4) 1688c2ecf20Sopenharmony_ci#define V3_LB_BASE_ADR_SIZE_512MB (9 << 4) 1698c2ecf20Sopenharmony_ci#define V3_LB_BASE_ADR_SIZE_1GB (10 << 4) 1708c2ecf20Sopenharmony_ci#define V3_LB_BASE_ADR_SIZE_2GB (11 << 4) 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci#define v3_addr_to_lb_base(a) ((a) & V3_LB_BASE_ADR_BASE) 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci/* LB_MAP0,1 bits (Local bus -> PCI) */ 1758c2ecf20Sopenharmony_ci#define V3_LB_MAP_MAP_ADR 0xfff0U 1768c2ecf20Sopenharmony_ci#define V3_LB_MAP_TYPE (7 << 1) 1778c2ecf20Sopenharmony_ci#define V3_LB_MAP_AD_LOW_EN BIT(0) 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci#define V3_LB_MAP_TYPE_IACK (0 << 1) 1808c2ecf20Sopenharmony_ci#define V3_LB_MAP_TYPE_IO (1 << 1) 1818c2ecf20Sopenharmony_ci#define V3_LB_MAP_TYPE_MEM (3 << 1) 1828c2ecf20Sopenharmony_ci#define V3_LB_MAP_TYPE_CONFIG (5 << 1) 1838c2ecf20Sopenharmony_ci#define V3_LB_MAP_TYPE_MEM_MULTIPLE (6 << 1) 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ci#define v3_addr_to_lb_map(a) (((a) >> 16) & V3_LB_MAP_MAP_ADR) 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci/* LB_BASE2 bits (Local bus -> PCI IO) */ 1888c2ecf20Sopenharmony_ci#define V3_LB_BASE2_ADR_BASE 0xff00U 1898c2ecf20Sopenharmony_ci#define V3_LB_BASE2_SWAP_AUTO (3 << 6) 1908c2ecf20Sopenharmony_ci#define V3_LB_BASE2_ENABLE BIT(0) 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci#define v3_addr_to_lb_base2(a) (((a) >> 16) & V3_LB_BASE2_ADR_BASE) 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci/* LB_MAP2 bits (Local bus -> PCI IO) */ 1958c2ecf20Sopenharmony_ci#define V3_LB_MAP2_MAP_ADR 0xff00U 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci#define v3_addr_to_lb_map2(a) (((a) >> 16) & V3_LB_MAP2_MAP_ADR) 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci/* FIFO priority bits */ 2008c2ecf20Sopenharmony_ci#define V3_FIFO_PRIO_LOCAL BIT(12) 2018c2ecf20Sopenharmony_ci#define V3_FIFO_PRIO_LB_RD1_FLUSH_EOB BIT(10) 2028c2ecf20Sopenharmony_ci#define V3_FIFO_PRIO_LB_RD1_FLUSH_AP1 BIT(11) 2038c2ecf20Sopenharmony_ci#define V3_FIFO_PRIO_LB_RD1_FLUSH_ANY (BIT(10)|BIT(11)) 2048c2ecf20Sopenharmony_ci#define V3_FIFO_PRIO_LB_RD0_FLUSH_EOB BIT(8) 2058c2ecf20Sopenharmony_ci#define V3_FIFO_PRIO_LB_RD0_FLUSH_AP1 BIT(9) 2068c2ecf20Sopenharmony_ci#define V3_FIFO_PRIO_LB_RD0_FLUSH_ANY (BIT(8)|BIT(9)) 2078c2ecf20Sopenharmony_ci#define V3_FIFO_PRIO_PCI BIT(4) 2088c2ecf20Sopenharmony_ci#define V3_FIFO_PRIO_PCI_RD1_FLUSH_EOB BIT(2) 2098c2ecf20Sopenharmony_ci#define V3_FIFO_PRIO_PCI_RD1_FLUSH_AP1 BIT(3) 2108c2ecf20Sopenharmony_ci#define V3_FIFO_PRIO_PCI_RD1_FLUSH_ANY (BIT(2)|BIT(3)) 2118c2ecf20Sopenharmony_ci#define V3_FIFO_PRIO_PCI_RD0_FLUSH_EOB BIT(0) 2128c2ecf20Sopenharmony_ci#define V3_FIFO_PRIO_PCI_RD0_FLUSH_AP1 BIT(1) 2138c2ecf20Sopenharmony_ci#define V3_FIFO_PRIO_PCI_RD0_FLUSH_ANY (BIT(0)|BIT(1)) 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci/* Local bus configuration bits */ 2168c2ecf20Sopenharmony_ci#define V3_LB_CFG_LB_TO_64_CYCLES 0x0000 2178c2ecf20Sopenharmony_ci#define V3_LB_CFG_LB_TO_256_CYCLES BIT(13) 2188c2ecf20Sopenharmony_ci#define V3_LB_CFG_LB_TO_512_CYCLES BIT(14) 2198c2ecf20Sopenharmony_ci#define V3_LB_CFG_LB_TO_1024_CYCLES (BIT(13)|BIT(14)) 2208c2ecf20Sopenharmony_ci#define V3_LB_CFG_LB_RST BIT(12) 2218c2ecf20Sopenharmony_ci#define V3_LB_CFG_LB_PPC_RDY BIT(11) 2228c2ecf20Sopenharmony_ci#define V3_LB_CFG_LB_LB_INT BIT(10) 2238c2ecf20Sopenharmony_ci#define V3_LB_CFG_LB_ERR_EN BIT(9) 2248c2ecf20Sopenharmony_ci#define V3_LB_CFG_LB_RDY_EN BIT(8) 2258c2ecf20Sopenharmony_ci#define V3_LB_CFG_LB_BE_IMODE BIT(7) 2268c2ecf20Sopenharmony_ci#define V3_LB_CFG_LB_BE_OMODE BIT(6) 2278c2ecf20Sopenharmony_ci#define V3_LB_CFG_LB_ENDIAN BIT(5) 2288c2ecf20Sopenharmony_ci#define V3_LB_CFG_LB_PARK_EN BIT(4) 2298c2ecf20Sopenharmony_ci#define V3_LB_CFG_LB_FBB_DIS BIT(2) 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_ci/* ARM Integrator-specific extended control registers */ 2328c2ecf20Sopenharmony_ci#define INTEGRATOR_SC_PCI_OFFSET 0x18 2338c2ecf20Sopenharmony_ci#define INTEGRATOR_SC_PCI_ENABLE BIT(0) 2348c2ecf20Sopenharmony_ci#define INTEGRATOR_SC_PCI_INTCLR BIT(1) 2358c2ecf20Sopenharmony_ci#define INTEGRATOR_SC_LBFADDR_OFFSET 0x20 2368c2ecf20Sopenharmony_ci#define INTEGRATOR_SC_LBFCODE_OFFSET 0x24 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_cistruct v3_pci { 2398c2ecf20Sopenharmony_ci struct device *dev; 2408c2ecf20Sopenharmony_ci void __iomem *base; 2418c2ecf20Sopenharmony_ci void __iomem *config_base; 2428c2ecf20Sopenharmony_ci u32 config_mem; 2438c2ecf20Sopenharmony_ci u32 non_pre_mem; 2448c2ecf20Sopenharmony_ci u32 pre_mem; 2458c2ecf20Sopenharmony_ci phys_addr_t non_pre_bus_addr; 2468c2ecf20Sopenharmony_ci phys_addr_t pre_bus_addr; 2478c2ecf20Sopenharmony_ci struct regmap *map; 2488c2ecf20Sopenharmony_ci}; 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci/* 2518c2ecf20Sopenharmony_ci * The V3 PCI interface chip in Integrator provides several windows from 2528c2ecf20Sopenharmony_ci * local bus memory into the PCI memory areas. Unfortunately, there 2538c2ecf20Sopenharmony_ci * are not really enough windows for our usage, therefore we reuse 2548c2ecf20Sopenharmony_ci * one of the windows for access to PCI configuration space. On the 2558c2ecf20Sopenharmony_ci * Integrator/AP, the memory map is as follows: 2568c2ecf20Sopenharmony_ci * 2578c2ecf20Sopenharmony_ci * Local Bus Memory Usage 2588c2ecf20Sopenharmony_ci * 2598c2ecf20Sopenharmony_ci * 40000000 - 4FFFFFFF PCI memory. 256M non-prefetchable 2608c2ecf20Sopenharmony_ci * 50000000 - 5FFFFFFF PCI memory. 256M prefetchable 2618c2ecf20Sopenharmony_ci * 60000000 - 60FFFFFF PCI IO. 16M 2628c2ecf20Sopenharmony_ci * 61000000 - 61FFFFFF PCI Configuration. 16M 2638c2ecf20Sopenharmony_ci * 2648c2ecf20Sopenharmony_ci * There are three V3 windows, each described by a pair of V3 registers. 2658c2ecf20Sopenharmony_ci * These are LB_BASE0/LB_MAP0, LB_BASE1/LB_MAP1 and LB_BASE2/LB_MAP2. 2668c2ecf20Sopenharmony_ci * Base0 and Base1 can be used for any type of PCI memory access. Base2 2678c2ecf20Sopenharmony_ci * can be used either for PCI I/O or for I20 accesses. By default, uHAL 2688c2ecf20Sopenharmony_ci * uses this only for PCI IO space. 2698c2ecf20Sopenharmony_ci * 2708c2ecf20Sopenharmony_ci * Normally these spaces are mapped using the following base registers: 2718c2ecf20Sopenharmony_ci * 2728c2ecf20Sopenharmony_ci * Usage Local Bus Memory Base/Map registers used 2738c2ecf20Sopenharmony_ci * 2748c2ecf20Sopenharmony_ci * Mem 40000000 - 4FFFFFFF LB_BASE0/LB_MAP0 2758c2ecf20Sopenharmony_ci * Mem 50000000 - 5FFFFFFF LB_BASE1/LB_MAP1 2768c2ecf20Sopenharmony_ci * IO 60000000 - 60FFFFFF LB_BASE2/LB_MAP2 2778c2ecf20Sopenharmony_ci * Cfg 61000000 - 61FFFFFF 2788c2ecf20Sopenharmony_ci * 2798c2ecf20Sopenharmony_ci * This means that I20 and PCI configuration space accesses will fail. 2808c2ecf20Sopenharmony_ci * When PCI configuration accesses are needed (via the uHAL PCI 2818c2ecf20Sopenharmony_ci * configuration space primitives) we must remap the spaces as follows: 2828c2ecf20Sopenharmony_ci * 2838c2ecf20Sopenharmony_ci * Usage Local Bus Memory Base/Map registers used 2848c2ecf20Sopenharmony_ci * 2858c2ecf20Sopenharmony_ci * Mem 40000000 - 4FFFFFFF LB_BASE0/LB_MAP0 2868c2ecf20Sopenharmony_ci * Mem 50000000 - 5FFFFFFF LB_BASE0/LB_MAP0 2878c2ecf20Sopenharmony_ci * IO 60000000 - 60FFFFFF LB_BASE2/LB_MAP2 2888c2ecf20Sopenharmony_ci * Cfg 61000000 - 61FFFFFF LB_BASE1/LB_MAP1 2898c2ecf20Sopenharmony_ci * 2908c2ecf20Sopenharmony_ci * To make this work, the code depends on overlapping windows working. 2918c2ecf20Sopenharmony_ci * The V3 chip translates an address by checking its range within 2928c2ecf20Sopenharmony_ci * each of the BASE/MAP pairs in turn (in ascending register number 2938c2ecf20Sopenharmony_ci * order). It will use the first matching pair. So, for example, 2948c2ecf20Sopenharmony_ci * if the same address is mapped by both LB_BASE0/LB_MAP0 and 2958c2ecf20Sopenharmony_ci * LB_BASE1/LB_MAP1, the V3 will use the translation from 2968c2ecf20Sopenharmony_ci * LB_BASE0/LB_MAP0. 2978c2ecf20Sopenharmony_ci * 2988c2ecf20Sopenharmony_ci * To allow PCI Configuration space access, the code enlarges the 2998c2ecf20Sopenharmony_ci * window mapped by LB_BASE0/LB_MAP0 from 256M to 512M. This occludes 3008c2ecf20Sopenharmony_ci * the windows currently mapped by LB_BASE1/LB_MAP1 so that it can 3018c2ecf20Sopenharmony_ci * be remapped for use by configuration cycles. 3028c2ecf20Sopenharmony_ci * 3038c2ecf20Sopenharmony_ci * At the end of the PCI Configuration space accesses, 3048c2ecf20Sopenharmony_ci * LB_BASE1/LB_MAP1 is reset to map PCI Memory. Finally the window 3058c2ecf20Sopenharmony_ci * mapped by LB_BASE0/LB_MAP0 is reduced in size from 512M to 256M to 3068c2ecf20Sopenharmony_ci * reveal the now restored LB_BASE1/LB_MAP1 window. 3078c2ecf20Sopenharmony_ci * 3088c2ecf20Sopenharmony_ci * NOTE: We do not set up I2O mapping. I suspect that this is only 3098c2ecf20Sopenharmony_ci * for an intelligent (target) device. Using I2O disables most of 3108c2ecf20Sopenharmony_ci * the mappings into PCI memory. 3118c2ecf20Sopenharmony_ci */ 3128c2ecf20Sopenharmony_cistatic void __iomem *v3_map_bus(struct pci_bus *bus, 3138c2ecf20Sopenharmony_ci unsigned int devfn, int offset) 3148c2ecf20Sopenharmony_ci{ 3158c2ecf20Sopenharmony_ci struct v3_pci *v3 = bus->sysdata; 3168c2ecf20Sopenharmony_ci unsigned int address, mapaddress, busnr; 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_ci busnr = bus->number; 3198c2ecf20Sopenharmony_ci if (busnr == 0) { 3208c2ecf20Sopenharmony_ci int slot = PCI_SLOT(devfn); 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_ci /* 3238c2ecf20Sopenharmony_ci * local bus segment so need a type 0 config cycle 3248c2ecf20Sopenharmony_ci * 3258c2ecf20Sopenharmony_ci * build the PCI configuration "address" with one-hot in 3268c2ecf20Sopenharmony_ci * A31-A11 3278c2ecf20Sopenharmony_ci * 3288c2ecf20Sopenharmony_ci * mapaddress: 3298c2ecf20Sopenharmony_ci * 3:1 = config cycle (101) 3308c2ecf20Sopenharmony_ci * 0 = PCI A1 & A0 are 0 (0) 3318c2ecf20Sopenharmony_ci */ 3328c2ecf20Sopenharmony_ci address = PCI_FUNC(devfn) << 8; 3338c2ecf20Sopenharmony_ci mapaddress = V3_LB_MAP_TYPE_CONFIG; 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci if (slot > 12) 3368c2ecf20Sopenharmony_ci /* 3378c2ecf20Sopenharmony_ci * high order bits are handled by the MAP register 3388c2ecf20Sopenharmony_ci */ 3398c2ecf20Sopenharmony_ci mapaddress |= BIT(slot - 5); 3408c2ecf20Sopenharmony_ci else 3418c2ecf20Sopenharmony_ci /* 3428c2ecf20Sopenharmony_ci * low order bits handled directly in the address 3438c2ecf20Sopenharmony_ci */ 3448c2ecf20Sopenharmony_ci address |= BIT(slot + 11); 3458c2ecf20Sopenharmony_ci } else { 3468c2ecf20Sopenharmony_ci /* 3478c2ecf20Sopenharmony_ci * not the local bus segment so need a type 1 config cycle 3488c2ecf20Sopenharmony_ci * 3498c2ecf20Sopenharmony_ci * address: 3508c2ecf20Sopenharmony_ci * 23:16 = bus number 3518c2ecf20Sopenharmony_ci * 15:11 = slot number (7:3 of devfn) 3528c2ecf20Sopenharmony_ci * 10:8 = func number (2:0 of devfn) 3538c2ecf20Sopenharmony_ci * 3548c2ecf20Sopenharmony_ci * mapaddress: 3558c2ecf20Sopenharmony_ci * 3:1 = config cycle (101) 3568c2ecf20Sopenharmony_ci * 0 = PCI A1 & A0 from host bus (1) 3578c2ecf20Sopenharmony_ci */ 3588c2ecf20Sopenharmony_ci mapaddress = V3_LB_MAP_TYPE_CONFIG | V3_LB_MAP_AD_LOW_EN; 3598c2ecf20Sopenharmony_ci address = (busnr << 16) | (devfn << 8); 3608c2ecf20Sopenharmony_ci } 3618c2ecf20Sopenharmony_ci 3628c2ecf20Sopenharmony_ci /* 3638c2ecf20Sopenharmony_ci * Set up base0 to see all 512Mbytes of memory space (not 3648c2ecf20Sopenharmony_ci * prefetchable), this frees up base1 for re-use by 3658c2ecf20Sopenharmony_ci * configuration memory 3668c2ecf20Sopenharmony_ci */ 3678c2ecf20Sopenharmony_ci writel(v3_addr_to_lb_base(v3->non_pre_mem) | 3688c2ecf20Sopenharmony_ci V3_LB_BASE_ADR_SIZE_512MB | V3_LB_BASE_ENABLE, 3698c2ecf20Sopenharmony_ci v3->base + V3_LB_BASE0); 3708c2ecf20Sopenharmony_ci 3718c2ecf20Sopenharmony_ci /* 3728c2ecf20Sopenharmony_ci * Set up base1/map1 to point into configuration space. 3738c2ecf20Sopenharmony_ci * The config mem is always 16MB. 3748c2ecf20Sopenharmony_ci */ 3758c2ecf20Sopenharmony_ci writel(v3_addr_to_lb_base(v3->config_mem) | 3768c2ecf20Sopenharmony_ci V3_LB_BASE_ADR_SIZE_16MB | V3_LB_BASE_ENABLE, 3778c2ecf20Sopenharmony_ci v3->base + V3_LB_BASE1); 3788c2ecf20Sopenharmony_ci writew(mapaddress, v3->base + V3_LB_MAP1); 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_ci return v3->config_base + address + offset; 3818c2ecf20Sopenharmony_ci} 3828c2ecf20Sopenharmony_ci 3838c2ecf20Sopenharmony_cistatic void v3_unmap_bus(struct v3_pci *v3) 3848c2ecf20Sopenharmony_ci{ 3858c2ecf20Sopenharmony_ci /* 3868c2ecf20Sopenharmony_ci * Reassign base1 for use by prefetchable PCI memory 3878c2ecf20Sopenharmony_ci */ 3888c2ecf20Sopenharmony_ci writel(v3_addr_to_lb_base(v3->pre_mem) | 3898c2ecf20Sopenharmony_ci V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_PREFETCH | 3908c2ecf20Sopenharmony_ci V3_LB_BASE_ENABLE, 3918c2ecf20Sopenharmony_ci v3->base + V3_LB_BASE1); 3928c2ecf20Sopenharmony_ci writew(v3_addr_to_lb_map(v3->pre_bus_addr) | 3938c2ecf20Sopenharmony_ci V3_LB_MAP_TYPE_MEM, /* was V3_LB_MAP_TYPE_MEM_MULTIPLE */ 3948c2ecf20Sopenharmony_ci v3->base + V3_LB_MAP1); 3958c2ecf20Sopenharmony_ci 3968c2ecf20Sopenharmony_ci /* 3978c2ecf20Sopenharmony_ci * And shrink base0 back to a 256M window (NOTE: MAP0 already correct) 3988c2ecf20Sopenharmony_ci */ 3998c2ecf20Sopenharmony_ci writel(v3_addr_to_lb_base(v3->non_pre_mem) | 4008c2ecf20Sopenharmony_ci V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_ENABLE, 4018c2ecf20Sopenharmony_ci v3->base + V3_LB_BASE0); 4028c2ecf20Sopenharmony_ci} 4038c2ecf20Sopenharmony_ci 4048c2ecf20Sopenharmony_cistatic int v3_pci_read_config(struct pci_bus *bus, unsigned int fn, 4058c2ecf20Sopenharmony_ci int config, int size, u32 *value) 4068c2ecf20Sopenharmony_ci{ 4078c2ecf20Sopenharmony_ci struct v3_pci *v3 = bus->sysdata; 4088c2ecf20Sopenharmony_ci int ret; 4098c2ecf20Sopenharmony_ci 4108c2ecf20Sopenharmony_ci dev_dbg(&bus->dev, 4118c2ecf20Sopenharmony_ci "[read] slt: %.2d, fnc: %d, cnf: 0x%.2X, val (%d bytes): 0x%.8X\n", 4128c2ecf20Sopenharmony_ci PCI_SLOT(fn), PCI_FUNC(fn), config, size, *value); 4138c2ecf20Sopenharmony_ci ret = pci_generic_config_read(bus, fn, config, size, value); 4148c2ecf20Sopenharmony_ci v3_unmap_bus(v3); 4158c2ecf20Sopenharmony_ci return ret; 4168c2ecf20Sopenharmony_ci} 4178c2ecf20Sopenharmony_ci 4188c2ecf20Sopenharmony_cistatic int v3_pci_write_config(struct pci_bus *bus, unsigned int fn, 4198c2ecf20Sopenharmony_ci int config, int size, u32 value) 4208c2ecf20Sopenharmony_ci{ 4218c2ecf20Sopenharmony_ci struct v3_pci *v3 = bus->sysdata; 4228c2ecf20Sopenharmony_ci int ret; 4238c2ecf20Sopenharmony_ci 4248c2ecf20Sopenharmony_ci dev_dbg(&bus->dev, 4258c2ecf20Sopenharmony_ci "[write] slt: %.2d, fnc: %d, cnf: 0x%.2X, val (%d bytes): 0x%.8X\n", 4268c2ecf20Sopenharmony_ci PCI_SLOT(fn), PCI_FUNC(fn), config, size, value); 4278c2ecf20Sopenharmony_ci ret = pci_generic_config_write(bus, fn, config, size, value); 4288c2ecf20Sopenharmony_ci v3_unmap_bus(v3); 4298c2ecf20Sopenharmony_ci return ret; 4308c2ecf20Sopenharmony_ci} 4318c2ecf20Sopenharmony_ci 4328c2ecf20Sopenharmony_cistatic struct pci_ops v3_pci_ops = { 4338c2ecf20Sopenharmony_ci .map_bus = v3_map_bus, 4348c2ecf20Sopenharmony_ci .read = v3_pci_read_config, 4358c2ecf20Sopenharmony_ci .write = v3_pci_write_config, 4368c2ecf20Sopenharmony_ci}; 4378c2ecf20Sopenharmony_ci 4388c2ecf20Sopenharmony_cistatic irqreturn_t v3_irq(int irq, void *data) 4398c2ecf20Sopenharmony_ci{ 4408c2ecf20Sopenharmony_ci struct v3_pci *v3 = data; 4418c2ecf20Sopenharmony_ci struct device *dev = v3->dev; 4428c2ecf20Sopenharmony_ci u32 status; 4438c2ecf20Sopenharmony_ci 4448c2ecf20Sopenharmony_ci status = readw(v3->base + V3_PCI_STAT); 4458c2ecf20Sopenharmony_ci if (status & V3_PCI_STAT_PAR_ERR) 4468c2ecf20Sopenharmony_ci dev_err(dev, "parity error interrupt\n"); 4478c2ecf20Sopenharmony_ci if (status & V3_PCI_STAT_SYS_ERR) 4488c2ecf20Sopenharmony_ci dev_err(dev, "system error interrupt\n"); 4498c2ecf20Sopenharmony_ci if (status & V3_PCI_STAT_M_ABORT_ERR) 4508c2ecf20Sopenharmony_ci dev_err(dev, "master abort error interrupt\n"); 4518c2ecf20Sopenharmony_ci if (status & V3_PCI_STAT_T_ABORT_ERR) 4528c2ecf20Sopenharmony_ci dev_err(dev, "target abort error interrupt\n"); 4538c2ecf20Sopenharmony_ci writew(status, v3->base + V3_PCI_STAT); 4548c2ecf20Sopenharmony_ci 4558c2ecf20Sopenharmony_ci status = readb(v3->base + V3_LB_ISTAT); 4568c2ecf20Sopenharmony_ci if (status & V3_LB_ISTAT_MAILBOX) 4578c2ecf20Sopenharmony_ci dev_info(dev, "PCI mailbox interrupt\n"); 4588c2ecf20Sopenharmony_ci if (status & V3_LB_ISTAT_PCI_RD) 4598c2ecf20Sopenharmony_ci dev_err(dev, "PCI target LB->PCI READ abort interrupt\n"); 4608c2ecf20Sopenharmony_ci if (status & V3_LB_ISTAT_PCI_WR) 4618c2ecf20Sopenharmony_ci dev_err(dev, "PCI target LB->PCI WRITE abort interrupt\n"); 4628c2ecf20Sopenharmony_ci if (status & V3_LB_ISTAT_PCI_INT) 4638c2ecf20Sopenharmony_ci dev_info(dev, "PCI pin interrupt\n"); 4648c2ecf20Sopenharmony_ci if (status & V3_LB_ISTAT_PCI_PERR) 4658c2ecf20Sopenharmony_ci dev_err(dev, "PCI parity error interrupt\n"); 4668c2ecf20Sopenharmony_ci if (status & V3_LB_ISTAT_I2O_QWR) 4678c2ecf20Sopenharmony_ci dev_info(dev, "I2O inbound post queue interrupt\n"); 4688c2ecf20Sopenharmony_ci if (status & V3_LB_ISTAT_DMA1) 4698c2ecf20Sopenharmony_ci dev_info(dev, "DMA channel 1 interrupt\n"); 4708c2ecf20Sopenharmony_ci if (status & V3_LB_ISTAT_DMA0) 4718c2ecf20Sopenharmony_ci dev_info(dev, "DMA channel 0 interrupt\n"); 4728c2ecf20Sopenharmony_ci /* Clear all possible interrupts on the local bus */ 4738c2ecf20Sopenharmony_ci writeb(0, v3->base + V3_LB_ISTAT); 4748c2ecf20Sopenharmony_ci if (v3->map) 4758c2ecf20Sopenharmony_ci regmap_write(v3->map, INTEGRATOR_SC_PCI_OFFSET, 4768c2ecf20Sopenharmony_ci INTEGRATOR_SC_PCI_ENABLE | 4778c2ecf20Sopenharmony_ci INTEGRATOR_SC_PCI_INTCLR); 4788c2ecf20Sopenharmony_ci 4798c2ecf20Sopenharmony_ci return IRQ_HANDLED; 4808c2ecf20Sopenharmony_ci} 4818c2ecf20Sopenharmony_ci 4828c2ecf20Sopenharmony_cistatic int v3_integrator_init(struct v3_pci *v3) 4838c2ecf20Sopenharmony_ci{ 4848c2ecf20Sopenharmony_ci unsigned int val; 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_ci v3->map = 4878c2ecf20Sopenharmony_ci syscon_regmap_lookup_by_compatible("arm,integrator-ap-syscon"); 4888c2ecf20Sopenharmony_ci if (IS_ERR(v3->map)) { 4898c2ecf20Sopenharmony_ci dev_err(v3->dev, "no syscon\n"); 4908c2ecf20Sopenharmony_ci return -ENODEV; 4918c2ecf20Sopenharmony_ci } 4928c2ecf20Sopenharmony_ci 4938c2ecf20Sopenharmony_ci regmap_read(v3->map, INTEGRATOR_SC_PCI_OFFSET, &val); 4948c2ecf20Sopenharmony_ci /* Take the PCI bridge out of reset, clear IRQs */ 4958c2ecf20Sopenharmony_ci regmap_write(v3->map, INTEGRATOR_SC_PCI_OFFSET, 4968c2ecf20Sopenharmony_ci INTEGRATOR_SC_PCI_ENABLE | 4978c2ecf20Sopenharmony_ci INTEGRATOR_SC_PCI_INTCLR); 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ci if (!(val & INTEGRATOR_SC_PCI_ENABLE)) { 5008c2ecf20Sopenharmony_ci /* If we were in reset we need to sleep a bit */ 5018c2ecf20Sopenharmony_ci msleep(230); 5028c2ecf20Sopenharmony_ci 5038c2ecf20Sopenharmony_ci /* Set the physical base for the controller itself */ 5048c2ecf20Sopenharmony_ci writel(0x6200, v3->base + V3_LB_IO_BASE); 5058c2ecf20Sopenharmony_ci 5068c2ecf20Sopenharmony_ci /* Wait for the mailbox to settle after reset */ 5078c2ecf20Sopenharmony_ci do { 5088c2ecf20Sopenharmony_ci writeb(0xaa, v3->base + V3_MAIL_DATA); 5098c2ecf20Sopenharmony_ci writeb(0x55, v3->base + V3_MAIL_DATA + 4); 5108c2ecf20Sopenharmony_ci } while (readb(v3->base + V3_MAIL_DATA) != 0xaa && 5118c2ecf20Sopenharmony_ci readb(v3->base + V3_MAIL_DATA) != 0x55); 5128c2ecf20Sopenharmony_ci } 5138c2ecf20Sopenharmony_ci 5148c2ecf20Sopenharmony_ci dev_info(v3->dev, "initialized PCI V3 Integrator/AP integration\n"); 5158c2ecf20Sopenharmony_ci 5168c2ecf20Sopenharmony_ci return 0; 5178c2ecf20Sopenharmony_ci} 5188c2ecf20Sopenharmony_ci 5198c2ecf20Sopenharmony_cistatic int v3_pci_setup_resource(struct v3_pci *v3, 5208c2ecf20Sopenharmony_ci struct pci_host_bridge *host, 5218c2ecf20Sopenharmony_ci struct resource_entry *win) 5228c2ecf20Sopenharmony_ci{ 5238c2ecf20Sopenharmony_ci struct device *dev = v3->dev; 5248c2ecf20Sopenharmony_ci struct resource *mem; 5258c2ecf20Sopenharmony_ci struct resource *io; 5268c2ecf20Sopenharmony_ci 5278c2ecf20Sopenharmony_ci switch (resource_type(win->res)) { 5288c2ecf20Sopenharmony_ci case IORESOURCE_IO: 5298c2ecf20Sopenharmony_ci io = win->res; 5308c2ecf20Sopenharmony_ci 5318c2ecf20Sopenharmony_ci /* Setup window 2 - PCI I/O */ 5328c2ecf20Sopenharmony_ci writel(v3_addr_to_lb_base2(pci_pio_to_address(io->start)) | 5338c2ecf20Sopenharmony_ci V3_LB_BASE2_ENABLE, 5348c2ecf20Sopenharmony_ci v3->base + V3_LB_BASE2); 5358c2ecf20Sopenharmony_ci writew(v3_addr_to_lb_map2(io->start - win->offset), 5368c2ecf20Sopenharmony_ci v3->base + V3_LB_MAP2); 5378c2ecf20Sopenharmony_ci break; 5388c2ecf20Sopenharmony_ci case IORESOURCE_MEM: 5398c2ecf20Sopenharmony_ci mem = win->res; 5408c2ecf20Sopenharmony_ci if (mem->flags & IORESOURCE_PREFETCH) { 5418c2ecf20Sopenharmony_ci mem->name = "V3 PCI PRE-MEM"; 5428c2ecf20Sopenharmony_ci v3->pre_mem = mem->start; 5438c2ecf20Sopenharmony_ci v3->pre_bus_addr = mem->start - win->offset; 5448c2ecf20Sopenharmony_ci dev_dbg(dev, "PREFETCHABLE MEM window %pR, bus addr %pap\n", 5458c2ecf20Sopenharmony_ci mem, &v3->pre_bus_addr); 5468c2ecf20Sopenharmony_ci if (resource_size(mem) != SZ_256M) { 5478c2ecf20Sopenharmony_ci dev_err(dev, "prefetchable memory range is not 256MB\n"); 5488c2ecf20Sopenharmony_ci return -EINVAL; 5498c2ecf20Sopenharmony_ci } 5508c2ecf20Sopenharmony_ci if (v3->non_pre_mem && 5518c2ecf20Sopenharmony_ci (mem->start != v3->non_pre_mem + SZ_256M)) { 5528c2ecf20Sopenharmony_ci dev_err(dev, 5538c2ecf20Sopenharmony_ci "prefetchable memory is not adjacent to non-prefetchable memory\n"); 5548c2ecf20Sopenharmony_ci return -EINVAL; 5558c2ecf20Sopenharmony_ci } 5568c2ecf20Sopenharmony_ci /* Setup window 1 - PCI prefetchable memory */ 5578c2ecf20Sopenharmony_ci writel(v3_addr_to_lb_base(v3->pre_mem) | 5588c2ecf20Sopenharmony_ci V3_LB_BASE_ADR_SIZE_256MB | 5598c2ecf20Sopenharmony_ci V3_LB_BASE_PREFETCH | 5608c2ecf20Sopenharmony_ci V3_LB_BASE_ENABLE, 5618c2ecf20Sopenharmony_ci v3->base + V3_LB_BASE1); 5628c2ecf20Sopenharmony_ci writew(v3_addr_to_lb_map(v3->pre_bus_addr) | 5638c2ecf20Sopenharmony_ci V3_LB_MAP_TYPE_MEM, /* Was V3_LB_MAP_TYPE_MEM_MULTIPLE */ 5648c2ecf20Sopenharmony_ci v3->base + V3_LB_MAP1); 5658c2ecf20Sopenharmony_ci } else { 5668c2ecf20Sopenharmony_ci mem->name = "V3 PCI NON-PRE-MEM"; 5678c2ecf20Sopenharmony_ci v3->non_pre_mem = mem->start; 5688c2ecf20Sopenharmony_ci v3->non_pre_bus_addr = mem->start - win->offset; 5698c2ecf20Sopenharmony_ci dev_dbg(dev, "NON-PREFETCHABLE MEM window %pR, bus addr %pap\n", 5708c2ecf20Sopenharmony_ci mem, &v3->non_pre_bus_addr); 5718c2ecf20Sopenharmony_ci if (resource_size(mem) != SZ_256M) { 5728c2ecf20Sopenharmony_ci dev_err(dev, 5738c2ecf20Sopenharmony_ci "non-prefetchable memory range is not 256MB\n"); 5748c2ecf20Sopenharmony_ci return -EINVAL; 5758c2ecf20Sopenharmony_ci } 5768c2ecf20Sopenharmony_ci /* Setup window 0 - PCI non-prefetchable memory */ 5778c2ecf20Sopenharmony_ci writel(v3_addr_to_lb_base(v3->non_pre_mem) | 5788c2ecf20Sopenharmony_ci V3_LB_BASE_ADR_SIZE_256MB | 5798c2ecf20Sopenharmony_ci V3_LB_BASE_ENABLE, 5808c2ecf20Sopenharmony_ci v3->base + V3_LB_BASE0); 5818c2ecf20Sopenharmony_ci writew(v3_addr_to_lb_map(v3->non_pre_bus_addr) | 5828c2ecf20Sopenharmony_ci V3_LB_MAP_TYPE_MEM, 5838c2ecf20Sopenharmony_ci v3->base + V3_LB_MAP0); 5848c2ecf20Sopenharmony_ci } 5858c2ecf20Sopenharmony_ci break; 5868c2ecf20Sopenharmony_ci case IORESOURCE_BUS: 5878c2ecf20Sopenharmony_ci break; 5888c2ecf20Sopenharmony_ci default: 5898c2ecf20Sopenharmony_ci dev_info(dev, "Unknown resource type %lu\n", 5908c2ecf20Sopenharmony_ci resource_type(win->res)); 5918c2ecf20Sopenharmony_ci break; 5928c2ecf20Sopenharmony_ci } 5938c2ecf20Sopenharmony_ci 5948c2ecf20Sopenharmony_ci return 0; 5958c2ecf20Sopenharmony_ci} 5968c2ecf20Sopenharmony_ci 5978c2ecf20Sopenharmony_cistatic int v3_get_dma_range_config(struct v3_pci *v3, 5988c2ecf20Sopenharmony_ci struct resource_entry *entry, 5998c2ecf20Sopenharmony_ci u32 *pci_base, u32 *pci_map) 6008c2ecf20Sopenharmony_ci{ 6018c2ecf20Sopenharmony_ci struct device *dev = v3->dev; 6028c2ecf20Sopenharmony_ci u64 cpu_addr = entry->res->start; 6038c2ecf20Sopenharmony_ci u64 cpu_end = entry->res->end; 6048c2ecf20Sopenharmony_ci u64 pci_end = cpu_end - entry->offset; 6058c2ecf20Sopenharmony_ci u64 pci_addr = entry->res->start - entry->offset; 6068c2ecf20Sopenharmony_ci u32 val; 6078c2ecf20Sopenharmony_ci 6088c2ecf20Sopenharmony_ci if (pci_addr & ~V3_PCI_BASE_M_ADR_BASE) { 6098c2ecf20Sopenharmony_ci dev_err(dev, "illegal range, only PCI bits 31..20 allowed\n"); 6108c2ecf20Sopenharmony_ci return -EINVAL; 6118c2ecf20Sopenharmony_ci } 6128c2ecf20Sopenharmony_ci val = ((u32)pci_addr) & V3_PCI_BASE_M_ADR_BASE; 6138c2ecf20Sopenharmony_ci *pci_base = val; 6148c2ecf20Sopenharmony_ci 6158c2ecf20Sopenharmony_ci if (cpu_addr & ~V3_PCI_MAP_M_MAP_ADR) { 6168c2ecf20Sopenharmony_ci dev_err(dev, "illegal range, only CPU bits 31..20 allowed\n"); 6178c2ecf20Sopenharmony_ci return -EINVAL; 6188c2ecf20Sopenharmony_ci } 6198c2ecf20Sopenharmony_ci val = ((u32)cpu_addr) & V3_PCI_MAP_M_MAP_ADR; 6208c2ecf20Sopenharmony_ci 6218c2ecf20Sopenharmony_ci switch (resource_size(entry->res)) { 6228c2ecf20Sopenharmony_ci case SZ_1M: 6238c2ecf20Sopenharmony_ci val |= V3_LB_BASE_ADR_SIZE_1MB; 6248c2ecf20Sopenharmony_ci break; 6258c2ecf20Sopenharmony_ci case SZ_2M: 6268c2ecf20Sopenharmony_ci val |= V3_LB_BASE_ADR_SIZE_2MB; 6278c2ecf20Sopenharmony_ci break; 6288c2ecf20Sopenharmony_ci case SZ_4M: 6298c2ecf20Sopenharmony_ci val |= V3_LB_BASE_ADR_SIZE_4MB; 6308c2ecf20Sopenharmony_ci break; 6318c2ecf20Sopenharmony_ci case SZ_8M: 6328c2ecf20Sopenharmony_ci val |= V3_LB_BASE_ADR_SIZE_8MB; 6338c2ecf20Sopenharmony_ci break; 6348c2ecf20Sopenharmony_ci case SZ_16M: 6358c2ecf20Sopenharmony_ci val |= V3_LB_BASE_ADR_SIZE_16MB; 6368c2ecf20Sopenharmony_ci break; 6378c2ecf20Sopenharmony_ci case SZ_32M: 6388c2ecf20Sopenharmony_ci val |= V3_LB_BASE_ADR_SIZE_32MB; 6398c2ecf20Sopenharmony_ci break; 6408c2ecf20Sopenharmony_ci case SZ_64M: 6418c2ecf20Sopenharmony_ci val |= V3_LB_BASE_ADR_SIZE_64MB; 6428c2ecf20Sopenharmony_ci break; 6438c2ecf20Sopenharmony_ci case SZ_128M: 6448c2ecf20Sopenharmony_ci val |= V3_LB_BASE_ADR_SIZE_128MB; 6458c2ecf20Sopenharmony_ci break; 6468c2ecf20Sopenharmony_ci case SZ_256M: 6478c2ecf20Sopenharmony_ci val |= V3_LB_BASE_ADR_SIZE_256MB; 6488c2ecf20Sopenharmony_ci break; 6498c2ecf20Sopenharmony_ci case SZ_512M: 6508c2ecf20Sopenharmony_ci val |= V3_LB_BASE_ADR_SIZE_512MB; 6518c2ecf20Sopenharmony_ci break; 6528c2ecf20Sopenharmony_ci case SZ_1G: 6538c2ecf20Sopenharmony_ci val |= V3_LB_BASE_ADR_SIZE_1GB; 6548c2ecf20Sopenharmony_ci break; 6558c2ecf20Sopenharmony_ci case SZ_2G: 6568c2ecf20Sopenharmony_ci val |= V3_LB_BASE_ADR_SIZE_2GB; 6578c2ecf20Sopenharmony_ci break; 6588c2ecf20Sopenharmony_ci default: 6598c2ecf20Sopenharmony_ci dev_err(v3->dev, "illegal dma memory chunk size\n"); 6608c2ecf20Sopenharmony_ci return -EINVAL; 6618c2ecf20Sopenharmony_ci } 6628c2ecf20Sopenharmony_ci val |= V3_PCI_MAP_M_REG_EN | V3_PCI_MAP_M_ENABLE; 6638c2ecf20Sopenharmony_ci *pci_map = val; 6648c2ecf20Sopenharmony_ci 6658c2ecf20Sopenharmony_ci dev_dbg(dev, 6668c2ecf20Sopenharmony_ci "DMA MEM CPU: 0x%016llx -> 0x%016llx => " 6678c2ecf20Sopenharmony_ci "PCI: 0x%016llx -> 0x%016llx base %08x map %08x\n", 6688c2ecf20Sopenharmony_ci cpu_addr, cpu_end, 6698c2ecf20Sopenharmony_ci pci_addr, pci_end, 6708c2ecf20Sopenharmony_ci *pci_base, *pci_map); 6718c2ecf20Sopenharmony_ci 6728c2ecf20Sopenharmony_ci return 0; 6738c2ecf20Sopenharmony_ci} 6748c2ecf20Sopenharmony_ci 6758c2ecf20Sopenharmony_cistatic int v3_pci_parse_map_dma_ranges(struct v3_pci *v3, 6768c2ecf20Sopenharmony_ci struct device_node *np) 6778c2ecf20Sopenharmony_ci{ 6788c2ecf20Sopenharmony_ci struct pci_host_bridge *bridge = pci_host_bridge_from_priv(v3); 6798c2ecf20Sopenharmony_ci struct device *dev = v3->dev; 6808c2ecf20Sopenharmony_ci struct resource_entry *entry; 6818c2ecf20Sopenharmony_ci int i = 0; 6828c2ecf20Sopenharmony_ci 6838c2ecf20Sopenharmony_ci resource_list_for_each_entry(entry, &bridge->dma_ranges) { 6848c2ecf20Sopenharmony_ci int ret; 6858c2ecf20Sopenharmony_ci u32 pci_base, pci_map; 6868c2ecf20Sopenharmony_ci 6878c2ecf20Sopenharmony_ci ret = v3_get_dma_range_config(v3, entry, &pci_base, &pci_map); 6888c2ecf20Sopenharmony_ci if (ret) 6898c2ecf20Sopenharmony_ci return ret; 6908c2ecf20Sopenharmony_ci 6918c2ecf20Sopenharmony_ci if (i == 0) { 6928c2ecf20Sopenharmony_ci writel(pci_base, v3->base + V3_PCI_BASE0); 6938c2ecf20Sopenharmony_ci writel(pci_map, v3->base + V3_PCI_MAP0); 6948c2ecf20Sopenharmony_ci } else if (i == 1) { 6958c2ecf20Sopenharmony_ci writel(pci_base, v3->base + V3_PCI_BASE1); 6968c2ecf20Sopenharmony_ci writel(pci_map, v3->base + V3_PCI_MAP1); 6978c2ecf20Sopenharmony_ci } else { 6988c2ecf20Sopenharmony_ci dev_err(dev, "too many ranges, only two supported\n"); 6998c2ecf20Sopenharmony_ci dev_err(dev, "range %d ignored\n", i); 7008c2ecf20Sopenharmony_ci } 7018c2ecf20Sopenharmony_ci i++; 7028c2ecf20Sopenharmony_ci } 7038c2ecf20Sopenharmony_ci return 0; 7048c2ecf20Sopenharmony_ci} 7058c2ecf20Sopenharmony_ci 7068c2ecf20Sopenharmony_cistatic int v3_pci_probe(struct platform_device *pdev) 7078c2ecf20Sopenharmony_ci{ 7088c2ecf20Sopenharmony_ci struct device *dev = &pdev->dev; 7098c2ecf20Sopenharmony_ci struct device_node *np = dev->of_node; 7108c2ecf20Sopenharmony_ci struct resource *regs; 7118c2ecf20Sopenharmony_ci struct resource_entry *win; 7128c2ecf20Sopenharmony_ci struct v3_pci *v3; 7138c2ecf20Sopenharmony_ci struct pci_host_bridge *host; 7148c2ecf20Sopenharmony_ci struct clk *clk; 7158c2ecf20Sopenharmony_ci u16 val; 7168c2ecf20Sopenharmony_ci int irq; 7178c2ecf20Sopenharmony_ci int ret; 7188c2ecf20Sopenharmony_ci 7198c2ecf20Sopenharmony_ci host = devm_pci_alloc_host_bridge(dev, sizeof(*v3)); 7208c2ecf20Sopenharmony_ci if (!host) 7218c2ecf20Sopenharmony_ci return -ENOMEM; 7228c2ecf20Sopenharmony_ci 7238c2ecf20Sopenharmony_ci host->ops = &v3_pci_ops; 7248c2ecf20Sopenharmony_ci v3 = pci_host_bridge_priv(host); 7258c2ecf20Sopenharmony_ci host->sysdata = v3; 7268c2ecf20Sopenharmony_ci v3->dev = dev; 7278c2ecf20Sopenharmony_ci 7288c2ecf20Sopenharmony_ci /* Get and enable host clock */ 7298c2ecf20Sopenharmony_ci clk = devm_clk_get(dev, NULL); 7308c2ecf20Sopenharmony_ci if (IS_ERR(clk)) { 7318c2ecf20Sopenharmony_ci dev_err(dev, "clock not found\n"); 7328c2ecf20Sopenharmony_ci return PTR_ERR(clk); 7338c2ecf20Sopenharmony_ci } 7348c2ecf20Sopenharmony_ci ret = clk_prepare_enable(clk); 7358c2ecf20Sopenharmony_ci if (ret) { 7368c2ecf20Sopenharmony_ci dev_err(dev, "unable to enable clock\n"); 7378c2ecf20Sopenharmony_ci return ret; 7388c2ecf20Sopenharmony_ci } 7398c2ecf20Sopenharmony_ci 7408c2ecf20Sopenharmony_ci regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 7418c2ecf20Sopenharmony_ci v3->base = devm_ioremap_resource(dev, regs); 7428c2ecf20Sopenharmony_ci if (IS_ERR(v3->base)) 7438c2ecf20Sopenharmony_ci return PTR_ERR(v3->base); 7448c2ecf20Sopenharmony_ci /* 7458c2ecf20Sopenharmony_ci * The hardware has a register with the physical base address 7468c2ecf20Sopenharmony_ci * of the V3 controller itself, verify that this is the same 7478c2ecf20Sopenharmony_ci * as the physical memory we've remapped it from. 7488c2ecf20Sopenharmony_ci */ 7498c2ecf20Sopenharmony_ci if (readl(v3->base + V3_LB_IO_BASE) != (regs->start >> 16)) 7508c2ecf20Sopenharmony_ci dev_err(dev, "V3_LB_IO_BASE = %08x but device is @%pR\n", 7518c2ecf20Sopenharmony_ci readl(v3->base + V3_LB_IO_BASE), regs); 7528c2ecf20Sopenharmony_ci 7538c2ecf20Sopenharmony_ci /* Configuration space is 16MB directly mapped */ 7548c2ecf20Sopenharmony_ci regs = platform_get_resource(pdev, IORESOURCE_MEM, 1); 7558c2ecf20Sopenharmony_ci if (resource_size(regs) != SZ_16M) { 7568c2ecf20Sopenharmony_ci dev_err(dev, "config mem is not 16MB!\n"); 7578c2ecf20Sopenharmony_ci return -EINVAL; 7588c2ecf20Sopenharmony_ci } 7598c2ecf20Sopenharmony_ci v3->config_mem = regs->start; 7608c2ecf20Sopenharmony_ci v3->config_base = devm_ioremap_resource(dev, regs); 7618c2ecf20Sopenharmony_ci if (IS_ERR(v3->config_base)) 7628c2ecf20Sopenharmony_ci return PTR_ERR(v3->config_base); 7638c2ecf20Sopenharmony_ci 7648c2ecf20Sopenharmony_ci /* Get and request error IRQ resource */ 7658c2ecf20Sopenharmony_ci irq = platform_get_irq(pdev, 0); 7668c2ecf20Sopenharmony_ci if (irq < 0) 7678c2ecf20Sopenharmony_ci return irq; 7688c2ecf20Sopenharmony_ci 7698c2ecf20Sopenharmony_ci ret = devm_request_irq(dev, irq, v3_irq, 0, 7708c2ecf20Sopenharmony_ci "PCIv3 error", v3); 7718c2ecf20Sopenharmony_ci if (ret < 0) { 7728c2ecf20Sopenharmony_ci dev_err(dev, 7738c2ecf20Sopenharmony_ci "unable to request PCIv3 error IRQ %d (%d)\n", 7748c2ecf20Sopenharmony_ci irq, ret); 7758c2ecf20Sopenharmony_ci return ret; 7768c2ecf20Sopenharmony_ci } 7778c2ecf20Sopenharmony_ci 7788c2ecf20Sopenharmony_ci /* 7798c2ecf20Sopenharmony_ci * Unlock V3 registers, but only if they were previously locked. 7808c2ecf20Sopenharmony_ci */ 7818c2ecf20Sopenharmony_ci if (readw(v3->base + V3_SYSTEM) & V3_SYSTEM_M_LOCK) 7828c2ecf20Sopenharmony_ci writew(V3_SYSTEM_UNLOCK, v3->base + V3_SYSTEM); 7838c2ecf20Sopenharmony_ci 7848c2ecf20Sopenharmony_ci /* Disable all slave access while we set up the windows */ 7858c2ecf20Sopenharmony_ci val = readw(v3->base + V3_PCI_CMD); 7868c2ecf20Sopenharmony_ci val &= ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER); 7878c2ecf20Sopenharmony_ci writew(val, v3->base + V3_PCI_CMD); 7888c2ecf20Sopenharmony_ci 7898c2ecf20Sopenharmony_ci /* Put the PCI bus into reset */ 7908c2ecf20Sopenharmony_ci val = readw(v3->base + V3_SYSTEM); 7918c2ecf20Sopenharmony_ci val &= ~V3_SYSTEM_M_RST_OUT; 7928c2ecf20Sopenharmony_ci writew(val, v3->base + V3_SYSTEM); 7938c2ecf20Sopenharmony_ci 7948c2ecf20Sopenharmony_ci /* Retry until we're ready */ 7958c2ecf20Sopenharmony_ci val = readw(v3->base + V3_PCI_CFG); 7968c2ecf20Sopenharmony_ci val |= V3_PCI_CFG_M_RETRY_EN; 7978c2ecf20Sopenharmony_ci writew(val, v3->base + V3_PCI_CFG); 7988c2ecf20Sopenharmony_ci 7998c2ecf20Sopenharmony_ci /* Set up the local bus protocol */ 8008c2ecf20Sopenharmony_ci val = readw(v3->base + V3_LB_CFG); 8018c2ecf20Sopenharmony_ci val |= V3_LB_CFG_LB_BE_IMODE; /* Byte enable input */ 8028c2ecf20Sopenharmony_ci val |= V3_LB_CFG_LB_BE_OMODE; /* Byte enable output */ 8038c2ecf20Sopenharmony_ci val &= ~V3_LB_CFG_LB_ENDIAN; /* Little endian */ 8048c2ecf20Sopenharmony_ci val &= ~V3_LB_CFG_LB_PPC_RDY; /* TODO: when using on PPC403Gx, set to 1 */ 8058c2ecf20Sopenharmony_ci writew(val, v3->base + V3_LB_CFG); 8068c2ecf20Sopenharmony_ci 8078c2ecf20Sopenharmony_ci /* Enable the PCI bus master */ 8088c2ecf20Sopenharmony_ci val = readw(v3->base + V3_PCI_CMD); 8098c2ecf20Sopenharmony_ci val |= PCI_COMMAND_MASTER; 8108c2ecf20Sopenharmony_ci writew(val, v3->base + V3_PCI_CMD); 8118c2ecf20Sopenharmony_ci 8128c2ecf20Sopenharmony_ci /* Get the I/O and memory ranges from DT */ 8138c2ecf20Sopenharmony_ci resource_list_for_each_entry(win, &host->windows) { 8148c2ecf20Sopenharmony_ci ret = v3_pci_setup_resource(v3, host, win); 8158c2ecf20Sopenharmony_ci if (ret) { 8168c2ecf20Sopenharmony_ci dev_err(dev, "error setting up resources\n"); 8178c2ecf20Sopenharmony_ci return ret; 8188c2ecf20Sopenharmony_ci } 8198c2ecf20Sopenharmony_ci } 8208c2ecf20Sopenharmony_ci ret = v3_pci_parse_map_dma_ranges(v3, np); 8218c2ecf20Sopenharmony_ci if (ret) 8228c2ecf20Sopenharmony_ci return ret; 8238c2ecf20Sopenharmony_ci 8248c2ecf20Sopenharmony_ci /* 8258c2ecf20Sopenharmony_ci * Disable PCI to host IO cycles, enable I/O buffers @3.3V, 8268c2ecf20Sopenharmony_ci * set AD_LOW0 to 1 if one of the LB_MAP registers choose 8278c2ecf20Sopenharmony_ci * to use this (should be unused). 8288c2ecf20Sopenharmony_ci */ 8298c2ecf20Sopenharmony_ci writel(0x00000000, v3->base + V3_PCI_IO_BASE); 8308c2ecf20Sopenharmony_ci val = V3_PCI_CFG_M_IO_REG_DIS | V3_PCI_CFG_M_IO_DIS | 8318c2ecf20Sopenharmony_ci V3_PCI_CFG_M_EN3V | V3_PCI_CFG_M_AD_LOW0; 8328c2ecf20Sopenharmony_ci /* 8338c2ecf20Sopenharmony_ci * DMA read and write from PCI bus commands types 8348c2ecf20Sopenharmony_ci */ 8358c2ecf20Sopenharmony_ci val |= V3_PCI_CFG_TYPE_DEFAULT << V3_PCI_CFG_M_RTYPE_SHIFT; 8368c2ecf20Sopenharmony_ci val |= V3_PCI_CFG_TYPE_DEFAULT << V3_PCI_CFG_M_WTYPE_SHIFT; 8378c2ecf20Sopenharmony_ci writew(val, v3->base + V3_PCI_CFG); 8388c2ecf20Sopenharmony_ci 8398c2ecf20Sopenharmony_ci /* 8408c2ecf20Sopenharmony_ci * Set the V3 FIFO such that writes have higher priority than 8418c2ecf20Sopenharmony_ci * reads, and local bus write causes local bus read fifo flush 8428c2ecf20Sopenharmony_ci * on aperture 1. Same for PCI. 8438c2ecf20Sopenharmony_ci */ 8448c2ecf20Sopenharmony_ci writew(V3_FIFO_PRIO_LB_RD1_FLUSH_AP1 | 8458c2ecf20Sopenharmony_ci V3_FIFO_PRIO_LB_RD0_FLUSH_AP1 | 8468c2ecf20Sopenharmony_ci V3_FIFO_PRIO_PCI_RD1_FLUSH_AP1 | 8478c2ecf20Sopenharmony_ci V3_FIFO_PRIO_PCI_RD0_FLUSH_AP1, 8488c2ecf20Sopenharmony_ci v3->base + V3_FIFO_PRIORITY); 8498c2ecf20Sopenharmony_ci 8508c2ecf20Sopenharmony_ci 8518c2ecf20Sopenharmony_ci /* 8528c2ecf20Sopenharmony_ci * Clear any error interrupts, and enable parity and write error 8538c2ecf20Sopenharmony_ci * interrupts 8548c2ecf20Sopenharmony_ci */ 8558c2ecf20Sopenharmony_ci writeb(0, v3->base + V3_LB_ISTAT); 8568c2ecf20Sopenharmony_ci val = readw(v3->base + V3_LB_CFG); 8578c2ecf20Sopenharmony_ci val |= V3_LB_CFG_LB_LB_INT; 8588c2ecf20Sopenharmony_ci writew(val, v3->base + V3_LB_CFG); 8598c2ecf20Sopenharmony_ci writeb(V3_LB_ISTAT_PCI_WR | V3_LB_ISTAT_PCI_PERR, 8608c2ecf20Sopenharmony_ci v3->base + V3_LB_IMASK); 8618c2ecf20Sopenharmony_ci 8628c2ecf20Sopenharmony_ci /* Special Integrator initialization */ 8638c2ecf20Sopenharmony_ci if (of_device_is_compatible(np, "arm,integrator-ap-pci")) { 8648c2ecf20Sopenharmony_ci ret = v3_integrator_init(v3); 8658c2ecf20Sopenharmony_ci if (ret) 8668c2ecf20Sopenharmony_ci return ret; 8678c2ecf20Sopenharmony_ci } 8688c2ecf20Sopenharmony_ci 8698c2ecf20Sopenharmony_ci /* Post-init: enable PCI memory and invalidate (master already on) */ 8708c2ecf20Sopenharmony_ci val = readw(v3->base + V3_PCI_CMD); 8718c2ecf20Sopenharmony_ci val |= PCI_COMMAND_MEMORY | PCI_COMMAND_INVALIDATE; 8728c2ecf20Sopenharmony_ci writew(val, v3->base + V3_PCI_CMD); 8738c2ecf20Sopenharmony_ci 8748c2ecf20Sopenharmony_ci /* Clear pending interrupts */ 8758c2ecf20Sopenharmony_ci writeb(0, v3->base + V3_LB_ISTAT); 8768c2ecf20Sopenharmony_ci /* Read or write errors and parity errors cause interrupts */ 8778c2ecf20Sopenharmony_ci writeb(V3_LB_ISTAT_PCI_RD | V3_LB_ISTAT_PCI_WR | V3_LB_ISTAT_PCI_PERR, 8788c2ecf20Sopenharmony_ci v3->base + V3_LB_IMASK); 8798c2ecf20Sopenharmony_ci 8808c2ecf20Sopenharmony_ci /* Take the PCI bus out of reset so devices can initialize */ 8818c2ecf20Sopenharmony_ci val = readw(v3->base + V3_SYSTEM); 8828c2ecf20Sopenharmony_ci val |= V3_SYSTEM_M_RST_OUT; 8838c2ecf20Sopenharmony_ci writew(val, v3->base + V3_SYSTEM); 8848c2ecf20Sopenharmony_ci 8858c2ecf20Sopenharmony_ci /* 8868c2ecf20Sopenharmony_ci * Re-lock the system register. 8878c2ecf20Sopenharmony_ci */ 8888c2ecf20Sopenharmony_ci val = readw(v3->base + V3_SYSTEM); 8898c2ecf20Sopenharmony_ci val |= V3_SYSTEM_M_LOCK; 8908c2ecf20Sopenharmony_ci writew(val, v3->base + V3_SYSTEM); 8918c2ecf20Sopenharmony_ci 8928c2ecf20Sopenharmony_ci return pci_host_probe(host); 8938c2ecf20Sopenharmony_ci} 8948c2ecf20Sopenharmony_ci 8958c2ecf20Sopenharmony_cistatic const struct of_device_id v3_pci_of_match[] = { 8968c2ecf20Sopenharmony_ci { 8978c2ecf20Sopenharmony_ci .compatible = "v3,v360epc-pci", 8988c2ecf20Sopenharmony_ci }, 8998c2ecf20Sopenharmony_ci {}, 9008c2ecf20Sopenharmony_ci}; 9018c2ecf20Sopenharmony_ci 9028c2ecf20Sopenharmony_cistatic struct platform_driver v3_pci_driver = { 9038c2ecf20Sopenharmony_ci .driver = { 9048c2ecf20Sopenharmony_ci .name = "pci-v3-semi", 9058c2ecf20Sopenharmony_ci .of_match_table = of_match_ptr(v3_pci_of_match), 9068c2ecf20Sopenharmony_ci .suppress_bind_attrs = true, 9078c2ecf20Sopenharmony_ci }, 9088c2ecf20Sopenharmony_ci .probe = v3_pci_probe, 9098c2ecf20Sopenharmony_ci}; 9108c2ecf20Sopenharmony_cibuiltin_platform_driver(v3_pci_driver); 911