18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci#include <linux/kernel.h> 38c2ecf20Sopenharmony_ci#include <linux/types.h> 48c2ecf20Sopenharmony_ci#include <linux/init.h> 58c2ecf20Sopenharmony_ci#include <linux/delay.h> 68c2ecf20Sopenharmony_ci#include <linux/pci.h> 78c2ecf20Sopenharmony_ci#include <linux/io.h> 88c2ecf20Sopenharmony_ci#include <linux/sh_intc.h> 98c2ecf20Sopenharmony_ci#include "pci-sh4.h" 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ciint pcibios_map_platform_irq(const struct pci_dev *, u8 slot, u8 pin) 128c2ecf20Sopenharmony_ci{ 138c2ecf20Sopenharmony_ci switch (slot) { 148c2ecf20Sopenharmony_ci case 0: return evt2irq(0x3a0); 158c2ecf20Sopenharmony_ci case 1: return evt2irq(0x3a0); /* AMD Ethernet controller */ 168c2ecf20Sopenharmony_ci case 2: return -1; 178c2ecf20Sopenharmony_ci case 3: return -1; 188c2ecf20Sopenharmony_ci case 4: return -1; 198c2ecf20Sopenharmony_ci default: 208c2ecf20Sopenharmony_ci printk("PCI: Bad IRQ mapping request for slot %d\n", slot); 218c2ecf20Sopenharmony_ci return -1; 228c2ecf20Sopenharmony_ci } 238c2ecf20Sopenharmony_ci} 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#define PCIMCR_MRSET_OFF 0xBFFFFFFF 268c2ecf20Sopenharmony_ci#define PCIMCR_RFSH_OFF 0xFFFFFFFB 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci/* 298c2ecf20Sopenharmony_ci * Only long word accesses of the PCIC's internal local registers and the 308c2ecf20Sopenharmony_ci * configuration registers from the CPU is supported. 318c2ecf20Sopenharmony_ci */ 328c2ecf20Sopenharmony_ci#define PCIC_WRITE(x,v) writel((v), PCI_REG(x)) 338c2ecf20Sopenharmony_ci#define PCIC_READ(x) readl(PCI_REG(x)) 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci/* 368c2ecf20Sopenharmony_ci * Description: This function sets up and initializes the pcic, sets 378c2ecf20Sopenharmony_ci * up the BARS, maps the DRAM into the address space etc, etc. 388c2ecf20Sopenharmony_ci */ 398c2ecf20Sopenharmony_ciint pci_fixup_pcic(struct pci_channel *chan) 408c2ecf20Sopenharmony_ci{ 418c2ecf20Sopenharmony_ci unsigned long bcr1, wcr1, wcr2, wcr3, mcr; 428c2ecf20Sopenharmony_ci unsigned short bcr2; 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci /* 458c2ecf20Sopenharmony_ci * Initialize the slave bus controller on the pcic. The values used 468c2ecf20Sopenharmony_ci * here should not be hardcoded, but they should be taken from the bsc 478c2ecf20Sopenharmony_ci * on the processor, to make this function as generic as possible. 488c2ecf20Sopenharmony_ci * (i.e. Another sbc may usr different SDRAM timing settings -- in order 498c2ecf20Sopenharmony_ci * for the pcic to work, its settings need to be exactly the same.) 508c2ecf20Sopenharmony_ci */ 518c2ecf20Sopenharmony_ci bcr1 = (*(volatile unsigned long*)(SH7751_BCR1)); 528c2ecf20Sopenharmony_ci bcr2 = (*(volatile unsigned short*)(SH7751_BCR2)); 538c2ecf20Sopenharmony_ci wcr1 = (*(volatile unsigned long*)(SH7751_WCR1)); 548c2ecf20Sopenharmony_ci wcr2 = (*(volatile unsigned long*)(SH7751_WCR2)); 558c2ecf20Sopenharmony_ci wcr3 = (*(volatile unsigned long*)(SH7751_WCR3)); 568c2ecf20Sopenharmony_ci mcr = (*(volatile unsigned long*)(SH7751_MCR)); 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci bcr1 = bcr1 | 0x00080000; /* Enable Bit 19, BREQEN */ 598c2ecf20Sopenharmony_ci (*(volatile unsigned long*)(SH7751_BCR1)) = bcr1; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci bcr1 = bcr1 | 0x40080000; /* Enable Bit 19 BREQEN, set PCIC to slave */ 628c2ecf20Sopenharmony_ci PCIC_WRITE(SH7751_PCIBCR1, bcr1); /* PCIC BCR1 */ 638c2ecf20Sopenharmony_ci PCIC_WRITE(SH7751_PCIBCR2, bcr2); /* PCIC BCR2 */ 648c2ecf20Sopenharmony_ci PCIC_WRITE(SH7751_PCIWCR1, wcr1); /* PCIC WCR1 */ 658c2ecf20Sopenharmony_ci PCIC_WRITE(SH7751_PCIWCR2, wcr2); /* PCIC WCR2 */ 668c2ecf20Sopenharmony_ci PCIC_WRITE(SH7751_PCIWCR3, wcr3); /* PCIC WCR3 */ 678c2ecf20Sopenharmony_ci mcr = (mcr & PCIMCR_MRSET_OFF) & PCIMCR_RFSH_OFF; 688c2ecf20Sopenharmony_ci PCIC_WRITE(SH7751_PCIMCR, mcr); /* PCIC MCR */ 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci /* Enable all interrupts, so we know what to fix */ 728c2ecf20Sopenharmony_ci PCIC_WRITE(SH7751_PCIINTM, 0x0000c3ff); 738c2ecf20Sopenharmony_ci PCIC_WRITE(SH7751_PCIAINTM, 0x0000380f); 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci /* Set up standard PCI config registers */ 768c2ecf20Sopenharmony_ci PCIC_WRITE(SH7751_PCICONF1, 0xF39000C7); /* Bus Master, Mem & I/O access */ 778c2ecf20Sopenharmony_ci PCIC_WRITE(SH7751_PCICONF2, 0x00000000); /* PCI Class code & Revision ID */ 788c2ecf20Sopenharmony_ci PCIC_WRITE(SH7751_PCICONF4, 0xab000001); /* PCI I/O address (local regs) */ 798c2ecf20Sopenharmony_ci PCIC_WRITE(SH7751_PCICONF5, 0x0c000000); /* PCI MEM address (local RAM) */ 808c2ecf20Sopenharmony_ci PCIC_WRITE(SH7751_PCICONF6, 0xd0000000); /* PCI MEM address (unused) */ 818c2ecf20Sopenharmony_ci PCIC_WRITE(SH7751_PCICONF11, 0x35051054); /* PCI Subsystem ID & Vendor ID */ 828c2ecf20Sopenharmony_ci PCIC_WRITE(SH7751_PCILSR0, 0x03f00000); /* MEM (full 64M exposed) */ 838c2ecf20Sopenharmony_ci PCIC_WRITE(SH7751_PCILSR1, 0x00000000); /* MEM (unused) */ 848c2ecf20Sopenharmony_ci PCIC_WRITE(SH7751_PCILAR0, 0x0c000000); /* MEM (direct map from PCI) */ 858c2ecf20Sopenharmony_ci PCIC_WRITE(SH7751_PCILAR1, 0x00000000); /* MEM (unused) */ 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci /* Now turn it on... */ 888c2ecf20Sopenharmony_ci PCIC_WRITE(SH7751_PCICR, 0xa5000001); 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci /* 918c2ecf20Sopenharmony_ci * Set PCIMBR and PCIIOBR here, assuming a single window 928c2ecf20Sopenharmony_ci * (16M MEM, 256K IO) is enough. If a larger space is 938c2ecf20Sopenharmony_ci * needed, the readx/writex and inx/outx functions will 948c2ecf20Sopenharmony_ci * have to do more (e.g. setting registers for each call). 958c2ecf20Sopenharmony_ci */ 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci /* 988c2ecf20Sopenharmony_ci * Set the MBR so PCI address is one-to-one with window, 998c2ecf20Sopenharmony_ci * meaning all calls go straight through... use BUG_ON to 1008c2ecf20Sopenharmony_ci * catch erroneous assumption. 1018c2ecf20Sopenharmony_ci */ 1028c2ecf20Sopenharmony_ci BUG_ON(chan->resources[1].start != SH7751_PCI_MEMORY_BASE); 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci PCIC_WRITE(SH7751_PCIMBR, chan->resources[1].start); 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci /* Set IOBR for window containing area specified in pci.h */ 1078c2ecf20Sopenharmony_ci PCIC_WRITE(SH7751_PCIIOBR, (chan->resources[0].start & SH7751_PCIIOBR_MASK)); 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci /* All done, may as well say so... */ 1108c2ecf20Sopenharmony_ci printk("SH7751 PCI: Finished initialization of the PCI controller\n"); 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci return 1; 1138c2ecf20Sopenharmony_ci} 114