Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 1 | /* |
Paul Mundt | 62c7ae8 | 2009-04-17 20:37:16 +0900 | [diff] [blame] | 2 | * Low-Level PCI Support for the SH7780 |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 3 | * |
Paul Mundt | 62c7ae8 | 2009-04-17 20:37:16 +0900 | [diff] [blame] | 4 | * Copyright (C) 2005 - 2009 Paul Mundt |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 5 | * |
Paul Mundt | 62c7ae8 | 2009-04-17 20:37:16 +0900 | [diff] [blame] | 6 | * This file is subject to the terms and conditions of the GNU General Public |
| 7 | * License. See the file "COPYING" in the main directory of this archive |
| 8 | * for more details. |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 9 | */ |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 10 | #include <linux/types.h> |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/pci.h> |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 14 | #include <linux/errno.h> |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 15 | #include <linux/delay.h> |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 16 | #include "pci-sh4.h" |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 17 | |
Paul Mundt | e79066a | 2009-04-20 18:29:22 +0900 | [diff] [blame^] | 18 | extern u8 pci_cache_line_size; |
| 19 | |
| 20 | static struct resource sh7785_io_resource = { |
| 21 | .name = "SH7785_IO", |
| 22 | .start = SH7780_PCI_IO_BASE, |
| 23 | .end = SH7780_PCI_IO_BASE + SH7780_PCI_IO_SIZE - 1, |
| 24 | .flags = IORESOURCE_IO |
| 25 | }; |
| 26 | |
| 27 | static struct resource sh7785_mem_resource = { |
| 28 | .name = "SH7785_mem", |
| 29 | .start = SH7780_PCI_MEMORY_BASE, |
| 30 | .end = SH7780_PCI_MEMORY_BASE + SH7780_PCI_MEM_SIZE - 1, |
| 31 | .flags = IORESOURCE_MEM |
| 32 | }; |
| 33 | |
| 34 | static struct pci_channel sh7780_pci_controller = { |
| 35 | .pci_ops = &sh4_pci_ops, |
| 36 | .mem_resource = &sh7785_mem_resource, |
| 37 | .io_resource = &sh7785_io_resource, |
| 38 | }; |
| 39 | |
| 40 | static struct sh4_pci_address_map sh7780_pci_map = { |
| 41 | .window0 = { |
| 42 | #if defined(CONFIG_32BIT) |
| 43 | .base = SH7780_32BIT_DDR_BASE_ADDR, |
| 44 | .size = 0x40000000, |
| 45 | #else |
| 46 | .base = SH7780_CS0_BASE_ADDR, |
| 47 | .size = 0x20000000, |
| 48 | #endif |
| 49 | }, |
| 50 | }; |
| 51 | |
| 52 | static int __init sh7780_pci_init(void) |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 53 | { |
Paul Mundt | e79066a | 2009-04-20 18:29:22 +0900 | [diff] [blame^] | 54 | struct pci_channel *chan = &sh7780_pci_controller; |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 55 | unsigned int id; |
Paul Mundt | 4e7b7fd | 2009-04-17 15:05:19 +0900 | [diff] [blame] | 56 | const char *type = NULL; |
| 57 | int ret; |
Paul Mundt | e79066a | 2009-04-20 18:29:22 +0900 | [diff] [blame^] | 58 | u32 word; |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 59 | |
Paul Mundt | 4e7b7fd | 2009-04-17 15:05:19 +0900 | [diff] [blame] | 60 | printk(KERN_NOTICE "PCI: Starting intialization.\n"); |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 61 | |
Magnus Damm | e4c6a36 | 2008-02-19 21:35:04 +0900 | [diff] [blame] | 62 | chan->reg_base = 0xfe040000; |
Magnus Damm | ef53fde | 2008-02-19 21:35:14 +0900 | [diff] [blame] | 63 | chan->io_base = 0xfe200000; |
Magnus Damm | e4c6a36 | 2008-02-19 21:35:04 +0900 | [diff] [blame] | 64 | |
Paul Mundt | 4e7b7fd | 2009-04-17 15:05:19 +0900 | [diff] [blame] | 65 | /* Enable CPU access to the PCIC registers. */ |
| 66 | __raw_writel(PCIECR_ENBL, PCIECR); |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 67 | |
Paul Mundt | 4e7b7fd | 2009-04-17 15:05:19 +0900 | [diff] [blame] | 68 | id = __raw_readw(chan->reg_base + SH7780_PCIVID); |
| 69 | if (id != SH7780_VENDOR_ID) { |
| 70 | printk(KERN_ERR "PCI: Unknown vendor ID 0x%04x.\n", id); |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 71 | return -ENODEV; |
| 72 | } |
| 73 | |
Paul Mundt | 4e7b7fd | 2009-04-17 15:05:19 +0900 | [diff] [blame] | 74 | id = __raw_readw(chan->reg_base + SH7780_PCIDID); |
| 75 | type = (id == SH7763_DEVICE_ID) ? "SH7763" : |
| 76 | (id == SH7780_DEVICE_ID) ? "SH7780" : |
| 77 | (id == SH7781_DEVICE_ID) ? "SH7781" : |
| 78 | (id == SH7785_DEVICE_ID) ? "SH7785" : |
| 79 | NULL; |
| 80 | if (unlikely(!type)) { |
| 81 | printk(KERN_ERR "PCI: Found an unsupported Renesas host " |
| 82 | "controller, device id 0x%04x.\n", id); |
| 83 | return -EINVAL; |
| 84 | } |
| 85 | |
| 86 | printk(KERN_NOTICE "PCI: Found a Renesas %s host " |
| 87 | "controller, revision %d.\n", type, |
| 88 | __raw_readb(chan->reg_base + SH7780_PCIRID)); |
| 89 | |
Magnus Damm | d0e3db4 | 2009-03-11 15:46:14 +0900 | [diff] [blame] | 90 | if ((ret = sh4_pci_check_direct(chan)) != 0) |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 91 | return ret; |
| 92 | |
Paul Mundt | c66c1d7 | 2009-04-17 16:38:00 +0900 | [diff] [blame] | 93 | /* |
Paul Mundt | c66c1d7 | 2009-04-17 16:38:00 +0900 | [diff] [blame] | 94 | * Set the class and sub-class codes. |
| 95 | */ |
Paul Mundt | ab78cbc | 2009-04-17 15:08:01 +0900 | [diff] [blame] | 96 | __raw_writeb(PCI_CLASS_BRIDGE_HOST >> 8, |
| 97 | chan->reg_base + SH7780_PCIBCC); |
| 98 | __raw_writeb(PCI_CLASS_BRIDGE_HOST & 0xff, |
| 99 | chan->reg_base + SH7780_PCISUB); |
Paul Mundt | 0bbc9bc | 2009-04-17 14:09:09 +0900 | [diff] [blame] | 100 | |
Paul Mundt | c66c1d7 | 2009-04-17 16:38:00 +0900 | [diff] [blame] | 101 | pci_cache_line_size = pci_read_reg(chan, SH7780_PCICLS) / 4; |
| 102 | |
Paul Mundt | 62c7ae8 | 2009-04-17 20:37:16 +0900 | [diff] [blame] | 103 | /* |
| 104 | * Set IO and Mem windows to local address |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 105 | * Make PCI and local address the same for easy 1 to 1 mapping |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 106 | */ |
Paul Mundt | 4c7a47d | 2009-04-17 17:21:36 +0900 | [diff] [blame] | 107 | pci_write_reg(chan, sh7780_pci_map.window0.size - 0xfffff, SH4_PCILSR0); |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 108 | /* Set the values on window 0 PCI config registers */ |
Paul Mundt | 4c7a47d | 2009-04-17 17:21:36 +0900 | [diff] [blame] | 109 | pci_write_reg(chan, sh7780_pci_map.window0.base, SH4_PCILAR0); |
| 110 | pci_write_reg(chan, sh7780_pci_map.window0.base, SH7780_PCIMBAR0); |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 111 | |
Paul Mundt | 62c7ae8 | 2009-04-17 20:37:16 +0900 | [diff] [blame] | 112 | pci_write_reg(chan, 0x0000380f, SH4_PCIAINTM); |
| 113 | |
| 114 | /* Set up standard PCI config registers */ |
| 115 | __raw_writew(0xFB00, chan->reg_base + SH7780_PCISTATUS); |
| 116 | __raw_writew(0x0047, chan->reg_base + SH7780_PCICMD); |
| 117 | __raw_writew(0x1912, chan->reg_base + SH7780_PCISVID); |
| 118 | __raw_writew(0x0001, chan->reg_base + SH7780_PCISID); |
| 119 | |
| 120 | __raw_writeb(0x00, chan->reg_base + SH7780_PCIPIF); |
| 121 | |
Nobuhiro Iwamatsu | b757623 | 2007-03-29 00:07:35 +0900 | [diff] [blame] | 122 | /* Apply any last-minute PCIC fixups */ |
Magnus Damm | b8b47bf | 2009-03-11 15:41:51 +0900 | [diff] [blame] | 123 | pci_fixup_pcic(chan); |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 124 | |
Paul Mundt | 62c7ae8 | 2009-04-17 20:37:16 +0900 | [diff] [blame] | 125 | pci_write_reg(chan, 0xfd000000, SH7780_PCIMBR0); |
| 126 | pci_write_reg(chan, 0x00fc0000, SH7780_PCIMBMR0); |
| 127 | |
| 128 | #ifdef CONFIG_32BIT |
| 129 | pci_write_reg(chan, 0xc0000000, SH7780_PCIMBR2); |
| 130 | pci_write_reg(chan, 0x20000000 - SH7780_PCI_IO_SIZE, SH7780_PCIMBMR2); |
| 131 | #endif |
| 132 | |
| 133 | /* Set IOBR for windows containing area specified in pci.h */ |
| 134 | pci_write_reg(chan, chan->io_resource->start & ~(SH7780_PCI_IO_SIZE-1), |
| 135 | SH7780_PCIIOBR); |
| 136 | pci_write_reg(chan, ((SH7780_PCI_IO_SIZE-1) & (7<<18)), |
| 137 | SH7780_PCIIOBMR); |
| 138 | |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 139 | /* SH7780 init done, set central function init complete */ |
| 140 | /* use round robin mode to stop a device starving/overruning */ |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 141 | word = SH4_PCICR_PREFIX | SH4_PCICR_CFIN | SH4_PCICR_FTO; |
Magnus Damm | b8b47bf | 2009-03-11 15:41:51 +0900 | [diff] [blame] | 142 | pci_write_reg(chan, word, SH4_PCICR); |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 143 | |
Paul Mundt | f1dcab7 | 2009-04-17 17:00:27 +0900 | [diff] [blame] | 144 | __set_io_port_base(SH7780_PCI_IO_BASE); |
| 145 | |
Paul Mundt | e79066a | 2009-04-20 18:29:22 +0900 | [diff] [blame^] | 146 | register_pci_controller(chan); |
| 147 | |
Magnus Damm | d0e3db4 | 2009-03-11 15:46:14 +0900 | [diff] [blame] | 148 | return 0; |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 149 | } |
Paul Mundt | e79066a | 2009-04-20 18:29:22 +0900 | [diff] [blame^] | 150 | arch_initcall(sh7780_pci_init); |