blob: f02d9dfcf252ff46cc2914c05d63f25fa0631ef0 [file] [log] [blame]
Paul Mundt5283ecb2006-09-27 15:59:17 +09001/*
Paul Mundt62c7ae82009-04-17 20:37:16 +09002 * Low-Level PCI Support for the SH7780
Paul Mundt5283ecb2006-09-27 15:59:17 +09003 *
Paul Mundt62c7ae82009-04-17 20:37:16 +09004 * Copyright (C) 2005 - 2009 Paul Mundt
Paul Mundt5283ecb2006-09-27 15:59:17 +09005 *
Paul Mundt62c7ae82009-04-17 20:37:16 +09006 * 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 Mundt5283ecb2006-09-27 15:59:17 +09009 */
Paul Mundt5283ecb2006-09-27 15:59:17 +090010#include <linux/types.h>
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/pci.h>
Paul Mundt5283ecb2006-09-27 15:59:17 +090014#include <linux/errno.h>
Paul Mundt5283ecb2006-09-27 15:59:17 +090015#include <linux/delay.h>
Paul Mundt959f85f2006-09-27 16:43:28 +090016#include "pci-sh4.h"
Paul Mundt5283ecb2006-09-27 15:59:17 +090017
Paul Mundtab1363a2009-04-17 17:07:47 +090018static int __init sh7780_pci_init(struct pci_channel *chan)
Paul Mundt5283ecb2006-09-27 15:59:17 +090019{
Paul Mundt959f85f2006-09-27 16:43:28 +090020 unsigned int id;
Paul Mundt4e7b7fd2009-04-17 15:05:19 +090021 const char *type = NULL;
22 int ret;
Paul Mundt5283ecb2006-09-27 15:59:17 +090023
Paul Mundt4e7b7fd2009-04-17 15:05:19 +090024 printk(KERN_NOTICE "PCI: Starting intialization.\n");
Paul Mundt5283ecb2006-09-27 15:59:17 +090025
Magnus Damme4c6a362008-02-19 21:35:04 +090026 chan->reg_base = 0xfe040000;
Magnus Dammef53fde2008-02-19 21:35:14 +090027 chan->io_base = 0xfe200000;
Magnus Damme4c6a362008-02-19 21:35:04 +090028
Paul Mundt4e7b7fd2009-04-17 15:05:19 +090029 /* Enable CPU access to the PCIC registers. */
30 __raw_writel(PCIECR_ENBL, PCIECR);
Paul Mundt959f85f2006-09-27 16:43:28 +090031
Paul Mundt4e7b7fd2009-04-17 15:05:19 +090032 id = __raw_readw(chan->reg_base + SH7780_PCIVID);
33 if (id != SH7780_VENDOR_ID) {
34 printk(KERN_ERR "PCI: Unknown vendor ID 0x%04x.\n", id);
Paul Mundt959f85f2006-09-27 16:43:28 +090035 return -ENODEV;
36 }
37
Paul Mundt4e7b7fd2009-04-17 15:05:19 +090038 id = __raw_readw(chan->reg_base + SH7780_PCIDID);
39 type = (id == SH7763_DEVICE_ID) ? "SH7763" :
40 (id == SH7780_DEVICE_ID) ? "SH7780" :
41 (id == SH7781_DEVICE_ID) ? "SH7781" :
42 (id == SH7785_DEVICE_ID) ? "SH7785" :
43 NULL;
44 if (unlikely(!type)) {
45 printk(KERN_ERR "PCI: Found an unsupported Renesas host "
46 "controller, device id 0x%04x.\n", id);
47 return -EINVAL;
48 }
49
50 printk(KERN_NOTICE "PCI: Found a Renesas %s host "
51 "controller, revision %d.\n", type,
52 __raw_readb(chan->reg_base + SH7780_PCIRID));
53
Magnus Dammd0e3db42009-03-11 15:46:14 +090054 if ((ret = sh4_pci_check_direct(chan)) != 0)
Paul Mundt5283ecb2006-09-27 15:59:17 +090055 return ret;
56
Paul Mundtc66c1d72009-04-17 16:38:00 +090057 /*
58 * Platform specific initialization (BSC registers, and memory space
59 * mapping) will be called via the platform defined function
60 * pcibios_init_platform().
61 */
Paul Mundt5283ecb2006-09-27 15:59:17 +090062 return pcibios_init_platform();
63}
Paul Mundt5283ecb2006-09-27 15:59:17 +090064
Paul Mundtc66c1d72009-04-17 16:38:00 +090065extern u8 pci_cache_line_size;
66
Paul Mundtab1363a2009-04-17 17:07:47 +090067static struct resource sh7785_io_resource = {
68 .name = "SH7785_IO",
69 .start = SH7780_PCI_IO_BASE,
70 .end = SH7780_PCI_IO_BASE + SH7780_PCI_IO_SIZE - 1,
71 .flags = IORESOURCE_IO
72};
73
74static struct resource sh7785_mem_resource = {
75 .name = "SH7785_mem",
76 .start = SH7780_PCI_MEMORY_BASE,
77 .end = SH7780_PCI_MEMORY_BASE + SH7780_PCI_MEM_SIZE - 1,
78 .flags = IORESOURCE_MEM
79};
80
81struct pci_channel board_pci_channels[] = {
82 { sh7780_pci_init, &sh4_pci_ops, &sh7785_io_resource, &sh7785_mem_resource, 0, 0xff },
83 { NULL, NULL, NULL, 0, 0 },
84};
85
Paul Mundt4c7a47d2009-04-17 17:21:36 +090086static struct sh4_pci_address_map sh7780_pci_map = {
87 .window0 = {
88#if defined(CONFIG_32BIT)
89 .base = SH7780_32BIT_DDR_BASE_ADDR,
90 .size = 0x40000000,
91#else
92 .base = SH7780_CS0_BASE_ADDR,
93 .size = 0x20000000,
94#endif
95 },
96};
97
98int __init pcibios_init_platform(void)
Paul Mundt5283ecb2006-09-27 15:59:17 +090099{
Paul Mundtab1363a2009-04-17 17:07:47 +0900100 struct pci_channel *chan = &board_pci_channels[0];
Paul Mundt5283ecb2006-09-27 15:59:17 +0900101 u32 word;
102
Paul Mundtc66c1d72009-04-17 16:38:00 +0900103 /*
104 * Set the class and sub-class codes.
105 */
Paul Mundtab78cbc2009-04-17 15:08:01 +0900106 __raw_writeb(PCI_CLASS_BRIDGE_HOST >> 8,
107 chan->reg_base + SH7780_PCIBCC);
108 __raw_writeb(PCI_CLASS_BRIDGE_HOST & 0xff,
109 chan->reg_base + SH7780_PCISUB);
Paul Mundt0bbc9bc2009-04-17 14:09:09 +0900110
Paul Mundtc66c1d72009-04-17 16:38:00 +0900111 pci_cache_line_size = pci_read_reg(chan, SH7780_PCICLS) / 4;
112
Paul Mundt62c7ae82009-04-17 20:37:16 +0900113 /*
114 * Set IO and Mem windows to local address
Paul Mundt5283ecb2006-09-27 15:59:17 +0900115 * Make PCI and local address the same for easy 1 to 1 mapping
Paul Mundt5283ecb2006-09-27 15:59:17 +0900116 */
Paul Mundt4c7a47d2009-04-17 17:21:36 +0900117 pci_write_reg(chan, sh7780_pci_map.window0.size - 0xfffff, SH4_PCILSR0);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900118 /* Set the values on window 0 PCI config registers */
Paul Mundt4c7a47d2009-04-17 17:21:36 +0900119 pci_write_reg(chan, sh7780_pci_map.window0.base, SH4_PCILAR0);
120 pci_write_reg(chan, sh7780_pci_map.window0.base, SH7780_PCIMBAR0);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900121
Paul Mundt62c7ae82009-04-17 20:37:16 +0900122 pci_write_reg(chan, 0x0000380f, SH4_PCIAINTM);
123
124 /* Set up standard PCI config registers */
125 __raw_writew(0xFB00, chan->reg_base + SH7780_PCISTATUS);
126 __raw_writew(0x0047, chan->reg_base + SH7780_PCICMD);
127 __raw_writew(0x1912, chan->reg_base + SH7780_PCISVID);
128 __raw_writew(0x0001, chan->reg_base + SH7780_PCISID);
129
130 __raw_writeb(0x00, chan->reg_base + SH7780_PCIPIF);
131
Nobuhiro Iwamatsub7576232007-03-29 00:07:35 +0900132 /* Apply any last-minute PCIC fixups */
Magnus Dammb8b47bf2009-03-11 15:41:51 +0900133 pci_fixup_pcic(chan);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900134
Paul Mundt62c7ae82009-04-17 20:37:16 +0900135 pci_write_reg(chan, 0xfd000000, SH7780_PCIMBR0);
136 pci_write_reg(chan, 0x00fc0000, SH7780_PCIMBMR0);
137
138#ifdef CONFIG_32BIT
139 pci_write_reg(chan, 0xc0000000, SH7780_PCIMBR2);
140 pci_write_reg(chan, 0x20000000 - SH7780_PCI_IO_SIZE, SH7780_PCIMBMR2);
141#endif
142
143 /* Set IOBR for windows containing area specified in pci.h */
144 pci_write_reg(chan, chan->io_resource->start & ~(SH7780_PCI_IO_SIZE-1),
145 SH7780_PCIIOBR);
146 pci_write_reg(chan, ((SH7780_PCI_IO_SIZE-1) & (7<<18)),
147 SH7780_PCIIOBMR);
148
Paul Mundt5283ecb2006-09-27 15:59:17 +0900149 /* SH7780 init done, set central function init complete */
150 /* use round robin mode to stop a device starving/overruning */
Paul Mundt959f85f2006-09-27 16:43:28 +0900151 word = SH4_PCICR_PREFIX | SH4_PCICR_CFIN | SH4_PCICR_FTO;
Magnus Dammb8b47bf2009-03-11 15:41:51 +0900152 pci_write_reg(chan, word, SH4_PCICR);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900153
Paul Mundtf1dcab72009-04-17 17:00:27 +0900154 __set_io_port_base(SH7780_PCI_IO_BASE);
155
Magnus Dammd0e3db42009-03-11 15:46:14 +0900156 return 0;
Paul Mundt5283ecb2006-09-27 15:59:17 +0900157}