blob: 19bac2168f4ff37a219399a6036401161136deef [file] [log] [blame]
Paul Mundt5283ecb2006-09-27 15:59:17 +09001/*
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 Mundt5283ecb2006-09-27 15:59:17 +090015#undef DEBUG
16
Paul Mundt5283ecb2006-09-27 15:59:17 +090017#include <linux/types.h>
18#include <linux/kernel.h>
19#include <linux/init.h>
20#include <linux/pci.h>
Paul Mundt5283ecb2006-09-27 15:59:17 +090021#include <linux/errno.h>
Paul Mundt5283ecb2006-09-27 15:59:17 +090022#include <linux/delay.h>
Paul Mundt959f85f2006-09-27 16:43:28 +090023#include "pci-sh4.h"
Paul Mundt5283ecb2006-09-27 15:59:17 +090024
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 Mundt959f85f2006-09-27 16:43:28 +090031 * space mapping) will be called via the platform defined function
32 * pcibios_init_platform().
Paul Mundt5283ecb2006-09-27 15:59:17 +090033 */
Magnus Dammd0e3db42009-03-11 15:46:14 +090034int __init sh7780_pci_init(struct pci_channel *chan)
Paul Mundt5283ecb2006-09-27 15:59:17 +090035{
Paul Mundt959f85f2006-09-27 16:43:28 +090036 unsigned int id;
Paul Mundt4e7b7fd2009-04-17 15:05:19 +090037 const char *type = NULL;
38 int ret;
Paul Mundt5283ecb2006-09-27 15:59:17 +090039
Paul Mundt4e7b7fd2009-04-17 15:05:19 +090040 printk(KERN_NOTICE "PCI: Starting intialization.\n");
Paul Mundt5283ecb2006-09-27 15:59:17 +090041
Magnus Damme4c6a362008-02-19 21:35:04 +090042 chan->reg_base = 0xfe040000;
Magnus Dammef53fde2008-02-19 21:35:14 +090043 chan->io_base = 0xfe200000;
Magnus Damme4c6a362008-02-19 21:35:04 +090044
Paul Mundt4e7b7fd2009-04-17 15:05:19 +090045 /* Enable CPU access to the PCIC registers. */
46 __raw_writel(PCIECR_ENBL, PCIECR);
Paul Mundt959f85f2006-09-27 16:43:28 +090047
Paul Mundt4e7b7fd2009-04-17 15:05:19 +090048 id = __raw_readw(chan->reg_base + SH7780_PCIVID);
49 if (id != SH7780_VENDOR_ID) {
50 printk(KERN_ERR "PCI: Unknown vendor ID 0x%04x.\n", id);
Paul Mundt959f85f2006-09-27 16:43:28 +090051 return -ENODEV;
52 }
53
Paul Mundt4e7b7fd2009-04-17 15:05:19 +090054 id = __raw_readw(chan->reg_base + SH7780_PCIDID);
55 type = (id == SH7763_DEVICE_ID) ? "SH7763" :
56 (id == SH7780_DEVICE_ID) ? "SH7780" :
57 (id == SH7781_DEVICE_ID) ? "SH7781" :
58 (id == SH7785_DEVICE_ID) ? "SH7785" :
59 NULL;
60 if (unlikely(!type)) {
61 printk(KERN_ERR "PCI: Found an unsupported Renesas host "
62 "controller, device id 0x%04x.\n", id);
63 return -EINVAL;
64 }
65
66 printk(KERN_NOTICE "PCI: Found a Renesas %s host "
67 "controller, revision %d.\n", type,
68 __raw_readb(chan->reg_base + SH7780_PCIRID));
69
Magnus Dammd0e3db42009-03-11 15:46:14 +090070 if ((ret = sh4_pci_check_direct(chan)) != 0)
Paul Mundt5283ecb2006-09-27 15:59:17 +090071 return ret;
72
73 return pcibios_init_platform();
74}
Paul Mundt5283ecb2006-09-27 15:59:17 +090075
Magnus Dammb8b47bf2009-03-11 15:41:51 +090076int __init sh7780_pcic_init(struct pci_channel *chan,
77 struct sh4_pci_address_map *map)
Paul Mundt5283ecb2006-09-27 15:59:17 +090078{
79 u32 word;
80
Paul Mundtab78cbc2009-04-17 15:08:01 +090081 __raw_writeb(PCI_CLASS_BRIDGE_HOST >> 8,
82 chan->reg_base + SH7780_PCIBCC);
83 __raw_writeb(PCI_CLASS_BRIDGE_HOST & 0xff,
84 chan->reg_base + SH7780_PCISUB);
Paul Mundt0bbc9bc2009-04-17 14:09:09 +090085
Paul Mundt5283ecb2006-09-27 15:59:17 +090086 /* set the command/status bits to:
87 * Wait Cycle Control + Parity Enable + Bus Master +
88 * Mem space enable
89 */
Magnus Dammb8b47bf2009-03-11 15:41:51 +090090 pci_write_reg(chan, 0x00000046, SH7780_PCICMD);
Paul Mundt5283ecb2006-09-27 15:59:17 +090091
Paul Mundt5283ecb2006-09-27 15:59:17 +090092 /* Set IO and Mem windows to local address
93 * Make PCI and local address the same for easy 1 to 1 mapping
Paul Mundt5283ecb2006-09-27 15:59:17 +090094 */
Magnus Dammb8b47bf2009-03-11 15:41:51 +090095 pci_write_reg(chan, map->window0.size - 0xfffff, SH4_PCILSR0);
96 pci_write_reg(chan, map->window1.size - 0xfffff, SH4_PCILSR1);
Paul Mundt5283ecb2006-09-27 15:59:17 +090097 /* Set the values on window 0 PCI config registers */
Magnus Dammb8b47bf2009-03-11 15:41:51 +090098 pci_write_reg(chan, map->window0.base, SH4_PCILAR0);
99 pci_write_reg(chan, map->window0.base, SH7780_PCIMBAR0);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900100 /* Set the values on window 1 PCI config registers */
Magnus Dammb8b47bf2009-03-11 15:41:51 +0900101 pci_write_reg(chan, map->window1.base, SH4_PCILAR1);
102 pci_write_reg(chan, map->window1.base, SH7780_PCIMBAR1);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900103
Nobuhiro Iwamatsub7576232007-03-29 00:07:35 +0900104 /* Apply any last-minute PCIC fixups */
Magnus Dammb8b47bf2009-03-11 15:41:51 +0900105 pci_fixup_pcic(chan);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900106
107 /* SH7780 init done, set central function init complete */
108 /* use round robin mode to stop a device starving/overruning */
Paul Mundt959f85f2006-09-27 16:43:28 +0900109 word = SH4_PCICR_PREFIX | SH4_PCICR_CFIN | SH4_PCICR_FTO;
Magnus Dammb8b47bf2009-03-11 15:41:51 +0900110 pci_write_reg(chan, word, SH4_PCICR);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900111
Magnus Dammd0e3db42009-03-11 15:46:14 +0900112 return 0;
Paul Mundt5283ecb2006-09-27 15:59:17 +0900113}