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 | |
| 25 | /* |
| 26 | * Initialization. Try all known PCI access methods. Note that we support |
| 27 | * using both PCI BIOS and direct access: in such cases, we use I/O ports |
| 28 | * to access config space. |
| 29 | * |
| 30 | * Note that the platform specific initialization (BSC registers, and memory |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 31 | * space mapping) will be called via the platform defined function |
| 32 | * pcibios_init_platform(). |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 33 | */ |
Magnus Damm | d0e3db4 | 2009-03-11 15:46:14 +0900 | [diff] [blame] | 34 | int __init sh7780_pci_init(struct pci_channel *chan) |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 35 | { |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 36 | unsigned int id; |
Paul Mundt | 32351a2 | 2007-03-12 14:38:59 +0900 | [diff] [blame] | 37 | int ret, match = 0; |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 38 | |
| 39 | pr_debug("PCI: Starting intialization.\n"); |
| 40 | |
Magnus Damm | e4c6a36 | 2008-02-19 21:35:04 +0900 | [diff] [blame] | 41 | chan->reg_base = 0xfe040000; |
Magnus Damm | ef53fde | 2008-02-19 21:35:14 +0900 | [diff] [blame] | 42 | chan->io_base = 0xfe200000; |
Magnus Damm | e4c6a36 | 2008-02-19 21:35:04 +0900 | [diff] [blame] | 43 | |
Magnus Damm | e036eaa | 2008-02-14 13:52:43 +0900 | [diff] [blame] | 44 | ctrl_outl(0x00000001, SH7780_PCI_VCR2); /* Enable PCIC */ |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 45 | |
| 46 | /* check for SH7780/SH7780R hardware */ |
Magnus Damm | d0e3db4 | 2009-03-11 15:46:14 +0900 | [diff] [blame] | 47 | id = pci_read_reg(chan, SH7780_PCIVID); |
Paul Mundt | 32351a2 | 2007-03-12 14:38:59 +0900 | [diff] [blame] | 48 | if ((id & 0xffff) == SH7780_VENDOR_ID) { |
| 49 | switch ((id >> 16) & 0xffff) { |
Yoshihiro Shimoda | 7d740a0 | 2008-01-07 14:40:07 +0900 | [diff] [blame] | 50 | case SH7763_DEVICE_ID: |
Paul Mundt | 32351a2 | 2007-03-12 14:38:59 +0900 | [diff] [blame] | 51 | case SH7780_DEVICE_ID: |
| 52 | case SH7781_DEVICE_ID: |
| 53 | case SH7785_DEVICE_ID: |
| 54 | match = 1; |
| 55 | break; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | if (unlikely(!match)) { |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 60 | printk(KERN_ERR "PCI: This is not an SH7780 (%x)\n", id); |
| 61 | return -ENODEV; |
| 62 | } |
| 63 | |
Magnus Damm | d0e3db4 | 2009-03-11 15:46:14 +0900 | [diff] [blame] | 64 | if ((ret = sh4_pci_check_direct(chan)) != 0) |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 65 | return ret; |
| 66 | |
| 67 | return pcibios_init_platform(); |
| 68 | } |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 69 | |
Magnus Damm | b8b47bf | 2009-03-11 15:41:51 +0900 | [diff] [blame] | 70 | int __init sh7780_pcic_init(struct pci_channel *chan, |
| 71 | struct sh4_pci_address_map *map) |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 72 | { |
| 73 | u32 word; |
| 74 | |
Paul Mundt | 0bbc9bc | 2009-04-17 14:09:09 +0900 | [diff] [blame^] | 75 | pci_write_reg(chan, PCI_CLASS_BRIDGE_HOST >> 8, SH7780_PCIBCC); |
| 76 | pci_write_reg(chan, PCI_CLASS_BRIDGE_HOST & 0xff, SH7780_PCISUB); |
| 77 | |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 78 | /* set the command/status bits to: |
| 79 | * Wait Cycle Control + Parity Enable + Bus Master + |
| 80 | * Mem space enable |
| 81 | */ |
Magnus Damm | b8b47bf | 2009-03-11 15:41:51 +0900 | [diff] [blame] | 82 | pci_write_reg(chan, 0x00000046, SH7780_PCICMD); |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 83 | |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 84 | /* Set IO and Mem windows to local address |
| 85 | * 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] | 86 | */ |
Magnus Damm | b8b47bf | 2009-03-11 15:41:51 +0900 | [diff] [blame] | 87 | pci_write_reg(chan, map->window0.size - 0xfffff, SH4_PCILSR0); |
| 88 | pci_write_reg(chan, map->window1.size - 0xfffff, SH4_PCILSR1); |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 89 | /* Set the values on window 0 PCI config registers */ |
Magnus Damm | b8b47bf | 2009-03-11 15:41:51 +0900 | [diff] [blame] | 90 | pci_write_reg(chan, map->window0.base, SH4_PCILAR0); |
| 91 | pci_write_reg(chan, map->window0.base, SH7780_PCIMBAR0); |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 92 | /* Set the values on window 1 PCI config registers */ |
Magnus Damm | b8b47bf | 2009-03-11 15:41:51 +0900 | [diff] [blame] | 93 | pci_write_reg(chan, map->window1.base, SH4_PCILAR1); |
| 94 | pci_write_reg(chan, map->window1.base, SH7780_PCIMBAR1); |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 95 | |
Nobuhiro Iwamatsu | b757623 | 2007-03-29 00:07:35 +0900 | [diff] [blame] | 96 | /* Apply any last-minute PCIC fixups */ |
Magnus Damm | b8b47bf | 2009-03-11 15:41:51 +0900 | [diff] [blame] | 97 | pci_fixup_pcic(chan); |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 98 | |
| 99 | /* SH7780 init done, set central function init complete */ |
| 100 | /* use round robin mode to stop a device starving/overruning */ |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 101 | word = SH4_PCICR_PREFIX | SH4_PCICR_CFIN | SH4_PCICR_FTO; |
Magnus Damm | b8b47bf | 2009-03-11 15:41:51 +0900 | [diff] [blame] | 102 | pci_write_reg(chan, word, SH4_PCICR); |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 103 | |
Magnus Damm | d0e3db4 | 2009-03-11 15:46:14 +0900 | [diff] [blame] | 104 | return 0; |
Paul Mundt | 5283ecb | 2006-09-27 15:59:17 +0900 | [diff] [blame] | 105 | } |