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 | ab1363a | 2009-04-17 17:07:47 +0900 | [diff] [blame^] | 25 | static int __init sh7780_pci_init(struct pci_channel *chan) |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 26 | { |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 27 | unsigned int id; |
Paul Mundt | 4e7b7fd | 2009-04-17 15:05:19 +0900 | [diff] [blame] | 28 | const char *type = NULL; |
| 29 | int ret; |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 30 | |
Paul Mundt | 4e7b7fd | 2009-04-17 15:05:19 +0900 | [diff] [blame] | 31 | printk(KERN_NOTICE "PCI: Starting intialization.\n"); |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 32 | |
Magnus Damm | e4c6a36 | 2008-02-19 21:35:04 +0900 | [diff] [blame] | 33 | chan->reg_base = 0xfe040000; |
Magnus Damm | ef53fde | 2008-02-19 21:35:14 +0900 | [diff] [blame] | 34 | chan->io_base = 0xfe200000; |
Magnus Damm | e4c6a36 | 2008-02-19 21:35:04 +0900 | [diff] [blame] | 35 | |
Paul Mundt | 4e7b7fd | 2009-04-17 15:05:19 +0900 | [diff] [blame] | 36 | /* Enable CPU access to the PCIC registers. */ |
| 37 | __raw_writel(PCIECR_ENBL, PCIECR); |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 38 | |
Paul Mundt | 4e7b7fd | 2009-04-17 15:05:19 +0900 | [diff] [blame] | 39 | id = __raw_readw(chan->reg_base + SH7780_PCIVID); |
| 40 | if (id != SH7780_VENDOR_ID) { |
| 41 | printk(KERN_ERR "PCI: Unknown vendor ID 0x%04x.\n", id); |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 42 | return -ENODEV; |
| 43 | } |
| 44 | |
Paul Mundt | 4e7b7fd | 2009-04-17 15:05:19 +0900 | [diff] [blame] | 45 | id = __raw_readw(chan->reg_base + SH7780_PCIDID); |
| 46 | type = (id == SH7763_DEVICE_ID) ? "SH7763" : |
| 47 | (id == SH7780_DEVICE_ID) ? "SH7780" : |
| 48 | (id == SH7781_DEVICE_ID) ? "SH7781" : |
| 49 | (id == SH7785_DEVICE_ID) ? "SH7785" : |
| 50 | NULL; |
| 51 | if (unlikely(!type)) { |
| 52 | printk(KERN_ERR "PCI: Found an unsupported Renesas host " |
| 53 | "controller, device id 0x%04x.\n", id); |
| 54 | return -EINVAL; |
| 55 | } |
| 56 | |
| 57 | printk(KERN_NOTICE "PCI: Found a Renesas %s host " |
| 58 | "controller, revision %d.\n", type, |
| 59 | __raw_readb(chan->reg_base + SH7780_PCIRID)); |
| 60 | |
Magnus Damm | d0e3db4 | 2009-03-11 15:46:14 +0900 | [diff] [blame] | 61 | if ((ret = sh4_pci_check_direct(chan)) != 0) |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 62 | return ret; |
| 63 | |
Paul Mundt | c66c1d7 | 2009-04-17 16:38:00 +0900 | [diff] [blame] | 64 | /* |
| 65 | * Platform specific initialization (BSC registers, and memory space |
| 66 | * mapping) will be called via the platform defined function |
| 67 | * pcibios_init_platform(). |
| 68 | */ |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 69 | return pcibios_init_platform(); |
| 70 | } |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 71 | |
Paul Mundt | c66c1d7 | 2009-04-17 16:38:00 +0900 | [diff] [blame] | 72 | extern u8 pci_cache_line_size; |
| 73 | |
Paul Mundt | ab1363a | 2009-04-17 17:07:47 +0900 | [diff] [blame^] | 74 | static struct resource sh7785_io_resource = { |
| 75 | .name = "SH7785_IO", |
| 76 | .start = SH7780_PCI_IO_BASE, |
| 77 | .end = SH7780_PCI_IO_BASE + SH7780_PCI_IO_SIZE - 1, |
| 78 | .flags = IORESOURCE_IO |
| 79 | }; |
| 80 | |
| 81 | static struct resource sh7785_mem_resource = { |
| 82 | .name = "SH7785_mem", |
| 83 | .start = SH7780_PCI_MEMORY_BASE, |
| 84 | .end = SH7780_PCI_MEMORY_BASE + SH7780_PCI_MEM_SIZE - 1, |
| 85 | .flags = IORESOURCE_MEM |
| 86 | }; |
| 87 | |
| 88 | struct pci_channel board_pci_channels[] = { |
| 89 | { sh7780_pci_init, &sh4_pci_ops, &sh7785_io_resource, &sh7785_mem_resource, 0, 0xff }, |
| 90 | { NULL, NULL, NULL, 0, 0 }, |
| 91 | }; |
| 92 | |
| 93 | int __init sh7780_pcic_init(struct sh4_pci_address_map *map) |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 94 | { |
Paul Mundt | ab1363a | 2009-04-17 17:07:47 +0900 | [diff] [blame^] | 95 | struct pci_channel *chan = &board_pci_channels[0]; |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 96 | u32 word; |
| 97 | |
Paul Mundt | c66c1d7 | 2009-04-17 16:38:00 +0900 | [diff] [blame] | 98 | /* |
| 99 | * Set the class and sub-class codes. |
| 100 | */ |
Paul Mundt | ab78cbc | 2009-04-17 15:08:01 +0900 | [diff] [blame] | 101 | __raw_writeb(PCI_CLASS_BRIDGE_HOST >> 8, |
| 102 | chan->reg_base + SH7780_PCIBCC); |
| 103 | __raw_writeb(PCI_CLASS_BRIDGE_HOST & 0xff, |
| 104 | chan->reg_base + SH7780_PCISUB); |
Paul Mundt | 0bbc9bc | 2009-04-17 14:09:09 +0900 | [diff] [blame] | 105 | |
Paul Mundt | c66c1d7 | 2009-04-17 16:38:00 +0900 | [diff] [blame] | 106 | pci_cache_line_size = pci_read_reg(chan, SH7780_PCICLS) / 4; |
| 107 | |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 108 | /* set the command/status bits to: |
| 109 | * Wait Cycle Control + Parity Enable + Bus Master + |
| 110 | * Mem space enable |
| 111 | */ |
Magnus Damm | b8b47bf | 2009-03-11 15:41:51 +0900 | [diff] [blame] | 112 | pci_write_reg(chan, 0x00000046, SH7780_PCICMD); |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 113 | |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 114 | /* Set IO and Mem windows to local address |
| 115 | * 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] | 116 | */ |
Magnus Damm | b8b47bf | 2009-03-11 15:41:51 +0900 | [diff] [blame] | 117 | pci_write_reg(chan, map->window0.size - 0xfffff, SH4_PCILSR0); |
| 118 | pci_write_reg(chan, map->window1.size - 0xfffff, SH4_PCILSR1); |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 119 | /* Set the values on window 0 PCI config registers */ |
Magnus Damm | b8b47bf | 2009-03-11 15:41:51 +0900 | [diff] [blame] | 120 | pci_write_reg(chan, map->window0.base, SH4_PCILAR0); |
| 121 | pci_write_reg(chan, map->window0.base, SH7780_PCIMBAR0); |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 122 | /* Set the values on window 1 PCI config registers */ |
Magnus Damm | b8b47bf | 2009-03-11 15:41:51 +0900 | [diff] [blame] | 123 | pci_write_reg(chan, map->window1.base, SH4_PCILAR1); |
| 124 | pci_write_reg(chan, map->window1.base, SH7780_PCIMBAR1); |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 125 | |
Nobuhiro Iwamatsu | b757623 | 2007-03-29 00:07:35 +0900 | [diff] [blame] | 126 | /* Apply any last-minute PCIC fixups */ |
Magnus Damm | b8b47bf | 2009-03-11 15:41:51 +0900 | [diff] [blame] | 127 | pci_fixup_pcic(chan); |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 128 | |
| 129 | /* SH7780 init done, set central function init complete */ |
| 130 | /* use round robin mode to stop a device starving/overruning */ |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 131 | word = SH4_PCICR_PREFIX | SH4_PCICR_CFIN | SH4_PCICR_FTO; |
Magnus Damm | b8b47bf | 2009-03-11 15:41:51 +0900 | [diff] [blame] | 132 | pci_write_reg(chan, word, SH4_PCICR); |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 133 | |
Paul Mundt | f1dcab7 | 2009-04-17 17:00:27 +0900 | [diff] [blame] | 134 | __set_io_port_base(SH7780_PCI_IO_BASE); |
| 135 | |
Magnus Damm | d0e3db4 | 2009-03-11 15:46:14 +0900 | [diff] [blame] | 136 | return 0; |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 137 | } |