| Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 1 | /* | 
|  | 2 | *	Low-Level PCI Support for the SH7780 | 
|  | 3 | * | 
|  | 4 | *  Dustin McIntire (dustin@sensoria.com) | 
|  | 5 | *	Derived from arch/i386/kernel/pci-*.c which bore the message: | 
|  | 6 | *	(c) 1999--2000 Martin Mares <mj@ucw.cz> | 
|  | 7 | * | 
|  | 8 | *  Ported to the new API by Paul Mundt <lethal@linux-sh.org> | 
|  | 9 | *  With cleanup by Paul van Gool <pvangool@mimotech.com> | 
|  | 10 | * | 
|  | 11 | *  May be copied or modified under the terms of the GNU General Public | 
|  | 12 | *  License.  See linux/COPYING for more information. | 
|  | 13 | * | 
|  | 14 | */ | 
| Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 15 | #undef DEBUG | 
|  | 16 |  | 
| Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 17 | #include <linux/types.h> | 
|  | 18 | #include <linux/kernel.h> | 
|  | 19 | #include <linux/init.h> | 
|  | 20 | #include <linux/pci.h> | 
| Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 21 | #include <linux/errno.h> | 
| Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 22 | #include <linux/delay.h> | 
| Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 23 | #include "pci-sh4.h" | 
| Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 24 |  | 
| Paul Mundt | 9a7ef6d | 2006-11-20 13:55:34 +0900 | [diff] [blame] | 25 | #define INTC_BASE	0xffd00000 | 
|  | 26 | #define INTC_ICR0	(INTC_BASE+0x0) | 
|  | 27 | #define INTC_ICR1	(INTC_BASE+0x1c) | 
|  | 28 | #define INTC_INTPRI	(INTC_BASE+0x10) | 
|  | 29 | #define INTC_INTREQ	(INTC_BASE+0x24) | 
|  | 30 | #define INTC_INTMSK0	(INTC_BASE+0x44) | 
|  | 31 | #define INTC_INTMSK1	(INTC_BASE+0x48) | 
|  | 32 | #define INTC_INTMSK2	(INTC_BASE+0x40080) | 
|  | 33 | #define INTC_INTMSKCLR0	(INTC_BASE+0x64) | 
|  | 34 | #define INTC_INTMSKCLR1	(INTC_BASE+0x68) | 
|  | 35 | #define INTC_INTMSKCLR2	(INTC_BASE+0x40084) | 
|  | 36 | #define INTC_INT2MSKR	(INTC_BASE+0x40038) | 
|  | 37 | #define INTC_INT2MSKCR	(INTC_BASE+0x4003c) | 
|  | 38 |  | 
| Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 39 | /* | 
|  | 40 | * Initialization. Try all known PCI access methods. Note that we support | 
|  | 41 | * using both PCI BIOS and direct access: in such cases, we use I/O ports | 
|  | 42 | * to access config space. | 
|  | 43 | * | 
|  | 44 | * Note that the platform specific initialization (BSC registers, and memory | 
| Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 45 | * space mapping) will be called via the platform defined function | 
|  | 46 | * pcibios_init_platform(). | 
| Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 47 | */ | 
| Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 48 | static int __init sh7780_pci_init(void) | 
|  | 49 | { | 
| Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 50 | unsigned int id; | 
| Paul Mundt | 32351a2 | 2007-03-12 14:38:59 +0900 | [diff] [blame] | 51 | int ret, match = 0; | 
| Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 52 |  | 
|  | 53 | pr_debug("PCI: Starting intialization.\n"); | 
|  | 54 |  | 
| Magnus Damm | e036eaa | 2008-02-14 13:52:43 +0900 | [diff] [blame] | 55 | ctrl_outl(0x00000001, SH7780_PCI_VCR2); /* Enable PCIC */ | 
| Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 56 |  | 
|  | 57 | /* check for SH7780/SH7780R hardware */ | 
|  | 58 | id = pci_read_reg(SH7780_PCIVID); | 
| Paul Mundt | 32351a2 | 2007-03-12 14:38:59 +0900 | [diff] [blame] | 59 | if ((id & 0xffff) == SH7780_VENDOR_ID) { | 
|  | 60 | switch ((id >> 16) & 0xffff) { | 
| Yoshihiro Shimoda | 7d740a0 | 2008-01-07 14:40:07 +0900 | [diff] [blame] | 61 | case SH7763_DEVICE_ID: | 
| Paul Mundt | 32351a2 | 2007-03-12 14:38:59 +0900 | [diff] [blame] | 62 | case SH7780_DEVICE_ID: | 
|  | 63 | case SH7781_DEVICE_ID: | 
|  | 64 | case SH7785_DEVICE_ID: | 
|  | 65 | match = 1; | 
|  | 66 | break; | 
|  | 67 | } | 
|  | 68 | } | 
|  | 69 |  | 
|  | 70 | if (unlikely(!match)) { | 
| Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 71 | printk(KERN_ERR "PCI: This is not an SH7780 (%x)\n", id); | 
|  | 72 | return -ENODEV; | 
|  | 73 | } | 
|  | 74 |  | 
| Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 75 | /* Setup the INTC */ | 
| Nobuhiro Iwamatsu | b757623 | 2007-03-29 00:07:35 +0900 | [diff] [blame] | 76 | if (mach_is_7780se()) { | 
|  | 77 | /* ICR0: IRL=use separately */ | 
|  | 78 | ctrl_outl(0x00C00020, INTC_ICR0); | 
|  | 79 | /* ICR1: detect low level(for 2ndcut) */ | 
|  | 80 | ctrl_outl(0xAAAA0000, INTC_ICR1); | 
|  | 81 | /* INTPRI: priority=3(all) */ | 
|  | 82 | ctrl_outl(0x33333333, INTC_INTPRI); | 
| Nobuhiro Iwamatsu | b757623 | 2007-03-29 00:07:35 +0900 | [diff] [blame] | 83 | } | 
| Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 84 |  | 
| Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 85 | if ((ret = sh4_pci_check_direct()) != 0) | 
| Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 86 | return ret; | 
|  | 87 |  | 
|  | 88 | return pcibios_init_platform(); | 
|  | 89 | } | 
| Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 90 | core_initcall(sh7780_pci_init); | 
|  | 91 |  | 
| Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 92 | int __init sh7780_pcic_init(struct sh4_pci_address_map *map) | 
| Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 93 | { | 
|  | 94 | u32 word; | 
|  | 95 |  | 
|  | 96 | /* | 
|  | 97 | * This code is unused for some boards as it is done in the | 
|  | 98 | * bootloader and doing it here means the MAC addresses loaded | 
|  | 99 | * by the bootloader get lost. | 
|  | 100 | */ | 
| Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 101 | if (!(map->flags & SH4_PCIC_NO_RESET)) { | 
| Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 102 | /* toggle PCI reset pin */ | 
| Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 103 | word = SH4_PCICR_PREFIX | SH4_PCICR_PRST; | 
|  | 104 | pci_write_reg(word, SH4_PCICR); | 
| Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 105 | /* Wait for a long time... not 1 sec. but long enough */ | 
|  | 106 | mdelay(100); | 
| Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 107 | word = SH4_PCICR_PREFIX; | 
|  | 108 | pci_write_reg(word, SH4_PCICR); | 
| Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 109 | } | 
|  | 110 |  | 
|  | 111 | /* set the command/status bits to: | 
|  | 112 | * Wait Cycle Control + Parity Enable + Bus Master + | 
|  | 113 | * Mem space enable | 
|  | 114 | */ | 
| Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 115 | pci_write_reg(0x00000046, SH7780_PCICMD); | 
| Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 116 |  | 
|  | 117 | /* define this host as the host bridge */ | 
| Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 118 | word = PCI_BASE_CLASS_BRIDGE << 24; | 
|  | 119 | pci_write_reg(word, SH7780_PCIRID); | 
| Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 120 |  | 
|  | 121 | /* Set IO and Mem windows to local address | 
|  | 122 | * Make PCI and local address the same for easy 1 to 1 mapping | 
|  | 123 | * Window0 = map->window0.size @ non-cached area base = SDRAM | 
|  | 124 | * Window1 = map->window1.size @ cached area base = SDRAM | 
|  | 125 | */ | 
| Yoshihiro Shimoda | 331ff10 | 2008-11-27 18:57:35 +0900 | [diff] [blame] | 126 | word = (CONFIG_MEMORY_SIZE - 0x00100000) | 0x00000001; | 
|  | 127 | pci_write_reg(word, SH4_PCILSR0); | 
| Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 128 | pci_write_reg(0x00000001, SH4_PCILSR1); | 
| Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 129 | /* Set the values on window 0 PCI config registers */ | 
| Yoshihiro Shimoda | 331ff10 | 2008-11-27 18:57:35 +0900 | [diff] [blame] | 130 | word = (CONFIG_MEMORY_SIZE > 0x08000000) ? 0x10000000 : 0x08000000; | 
|  | 131 | pci_write_reg(word | 0xa0000000, SH4_PCILAR0); | 
|  | 132 | pci_write_reg(word, SH7780_PCIMBAR0); | 
| Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 133 | /* Set the values on window 1 PCI config registers */ | 
| Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 134 | pci_write_reg(0x00000000, SH4_PCILAR1); | 
|  | 135 | pci_write_reg(0x00000000, SH7780_PCIMBAR1); | 
| Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 136 |  | 
|  | 137 | /* Map IO space into PCI IO window | 
|  | 138 | * The IO window is 64K-PCIBIOS_MIN_IO in size | 
|  | 139 | * IO addresses will be translated to the | 
|  | 140 | * PCI IO window base address | 
|  | 141 | */ | 
| Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 142 | pr_debug("PCI: Mapping IO address 0x%x - 0x%x to base 0x%x\n", | 
|  | 143 | PCIBIOS_MIN_IO, (64 << 10), | 
|  | 144 | SH7780_PCI_IO_BASE + PCIBIOS_MIN_IO); | 
| Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 145 |  | 
|  | 146 | /* NOTE: I'm ignoring the PCI error IRQs for now.. | 
|  | 147 | * TODO: add support for the internal error interrupts and | 
|  | 148 | * DMA interrupts... | 
|  | 149 | */ | 
|  | 150 |  | 
| Nobuhiro Iwamatsu | b757623 | 2007-03-29 00:07:35 +0900 | [diff] [blame] | 151 | /* Apply any last-minute PCIC fixups */ | 
| Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 152 | pci_fixup_pcic(); | 
| Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 153 |  | 
|  | 154 | /* SH7780 init done, set central function init complete */ | 
|  | 155 | /* use round robin mode to stop a device starving/overruning */ | 
| Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 156 | word = SH4_PCICR_PREFIX | SH4_PCICR_CFIN | SH4_PCICR_FTO; | 
|  | 157 | pci_write_reg(word, SH4_PCICR); | 
| Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 158 |  | 
|  | 159 | return 1; | 
|  | 160 | } |