blob: 57a3b870a276b89b7eee510e9425a79190ccdacf [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 Mundte79066a2009-04-20 18:29:22 +090018extern u8 pci_cache_line_size;
19
20static 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
27static 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
34static struct pci_channel sh7780_pci_controller = {
35 .pci_ops = &sh4_pci_ops,
36 .mem_resource = &sh7785_mem_resource,
Paul Mundt09cfeb12009-04-20 18:42:00 +090037 .mem_offset = 0x00000000,
Paul Mundte79066a2009-04-20 18:29:22 +090038 .io_resource = &sh7785_io_resource,
Paul Mundt09cfeb12009-04-20 18:42:00 +090039 .io_offset = 0x00000000,
Paul Mundte79066a2009-04-20 18:29:22 +090040};
41
42static struct sh4_pci_address_map sh7780_pci_map = {
43 .window0 = {
44#if defined(CONFIG_32BIT)
45 .base = SH7780_32BIT_DDR_BASE_ADDR,
46 .size = 0x40000000,
47#else
48 .base = SH7780_CS0_BASE_ADDR,
49 .size = 0x20000000,
50#endif
51 },
52};
53
54static int __init sh7780_pci_init(void)
Paul Mundt5283ecb2006-09-27 15:59:17 +090055{
Paul Mundte79066a2009-04-20 18:29:22 +090056 struct pci_channel *chan = &sh7780_pci_controller;
Paul Mundt959f85f2006-09-27 16:43:28 +090057 unsigned int id;
Paul Mundt4e7b7fd2009-04-17 15:05:19 +090058 const char *type = NULL;
59 int ret;
Paul Mundte79066a2009-04-20 18:29:22 +090060 u32 word;
Paul Mundt5283ecb2006-09-27 15:59:17 +090061
Paul Mundt4e7b7fd2009-04-17 15:05:19 +090062 printk(KERN_NOTICE "PCI: Starting intialization.\n");
Paul Mundt5283ecb2006-09-27 15:59:17 +090063
Magnus Damme4c6a362008-02-19 21:35:04 +090064 chan->reg_base = 0xfe040000;
Magnus Dammef53fde2008-02-19 21:35:14 +090065 chan->io_base = 0xfe200000;
Magnus Damme4c6a362008-02-19 21:35:04 +090066
Paul Mundt4e7b7fd2009-04-17 15:05:19 +090067 /* Enable CPU access to the PCIC registers. */
68 __raw_writel(PCIECR_ENBL, PCIECR);
Paul Mundt959f85f2006-09-27 16:43:28 +090069
Paul Mundt4e7b7fd2009-04-17 15:05:19 +090070 id = __raw_readw(chan->reg_base + SH7780_PCIVID);
71 if (id != SH7780_VENDOR_ID) {
72 printk(KERN_ERR "PCI: Unknown vendor ID 0x%04x.\n", id);
Paul Mundt959f85f2006-09-27 16:43:28 +090073 return -ENODEV;
74 }
75
Paul Mundt4e7b7fd2009-04-17 15:05:19 +090076 id = __raw_readw(chan->reg_base + SH7780_PCIDID);
77 type = (id == SH7763_DEVICE_ID) ? "SH7763" :
78 (id == SH7780_DEVICE_ID) ? "SH7780" :
79 (id == SH7781_DEVICE_ID) ? "SH7781" :
80 (id == SH7785_DEVICE_ID) ? "SH7785" :
81 NULL;
82 if (unlikely(!type)) {
83 printk(KERN_ERR "PCI: Found an unsupported Renesas host "
84 "controller, device id 0x%04x.\n", id);
85 return -EINVAL;
86 }
87
88 printk(KERN_NOTICE "PCI: Found a Renesas %s host "
89 "controller, revision %d.\n", type,
90 __raw_readb(chan->reg_base + SH7780_PCIRID));
91
Magnus Dammd0e3db42009-03-11 15:46:14 +090092 if ((ret = sh4_pci_check_direct(chan)) != 0)
Paul Mundt5283ecb2006-09-27 15:59:17 +090093 return ret;
94
Paul Mundtc66c1d72009-04-17 16:38:00 +090095 /*
Paul Mundtc66c1d72009-04-17 16:38:00 +090096 * Set the class and sub-class codes.
97 */
Paul Mundtab78cbc2009-04-17 15:08:01 +090098 __raw_writeb(PCI_CLASS_BRIDGE_HOST >> 8,
99 chan->reg_base + SH7780_PCIBCC);
100 __raw_writeb(PCI_CLASS_BRIDGE_HOST & 0xff,
101 chan->reg_base + SH7780_PCISUB);
Paul Mundt0bbc9bc2009-04-17 14:09:09 +0900102
Paul Mundtc66c1d72009-04-17 16:38:00 +0900103 pci_cache_line_size = pci_read_reg(chan, SH7780_PCICLS) / 4;
104
Paul Mundt62c7ae82009-04-17 20:37:16 +0900105 /*
106 * Set IO and Mem windows to local address
Paul Mundt5283ecb2006-09-27 15:59:17 +0900107 * Make PCI and local address the same for easy 1 to 1 mapping
Paul Mundt5283ecb2006-09-27 15:59:17 +0900108 */
Paul Mundt4c7a47d2009-04-17 17:21:36 +0900109 pci_write_reg(chan, sh7780_pci_map.window0.size - 0xfffff, SH4_PCILSR0);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900110 /* Set the values on window 0 PCI config registers */
Paul Mundt4c7a47d2009-04-17 17:21:36 +0900111 pci_write_reg(chan, sh7780_pci_map.window0.base, SH4_PCILAR0);
112 pci_write_reg(chan, sh7780_pci_map.window0.base, SH7780_PCIMBAR0);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900113
Paul Mundt62c7ae82009-04-17 20:37:16 +0900114 pci_write_reg(chan, 0x0000380f, SH4_PCIAINTM);
115
116 /* Set up standard PCI config registers */
117 __raw_writew(0xFB00, chan->reg_base + SH7780_PCISTATUS);
118 __raw_writew(0x0047, chan->reg_base + SH7780_PCICMD);
119 __raw_writew(0x1912, chan->reg_base + SH7780_PCISVID);
120 __raw_writew(0x0001, chan->reg_base + SH7780_PCISID);
121
122 __raw_writeb(0x00, chan->reg_base + SH7780_PCIPIF);
123
Nobuhiro Iwamatsub7576232007-03-29 00:07:35 +0900124 /* Apply any last-minute PCIC fixups */
Magnus Dammb8b47bf2009-03-11 15:41:51 +0900125 pci_fixup_pcic(chan);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900126
Paul Mundt62c7ae82009-04-17 20:37:16 +0900127 pci_write_reg(chan, 0xfd000000, SH7780_PCIMBR0);
128 pci_write_reg(chan, 0x00fc0000, SH7780_PCIMBMR0);
129
130#ifdef CONFIG_32BIT
131 pci_write_reg(chan, 0xc0000000, SH7780_PCIMBR2);
132 pci_write_reg(chan, 0x20000000 - SH7780_PCI_IO_SIZE, SH7780_PCIMBMR2);
133#endif
134
135 /* Set IOBR for windows containing area specified in pci.h */
136 pci_write_reg(chan, chan->io_resource->start & ~(SH7780_PCI_IO_SIZE-1),
137 SH7780_PCIIOBR);
138 pci_write_reg(chan, ((SH7780_PCI_IO_SIZE-1) & (7<<18)),
139 SH7780_PCIIOBMR);
140
Paul Mundt5283ecb2006-09-27 15:59:17 +0900141 /* SH7780 init done, set central function init complete */
142 /* use round robin mode to stop a device starving/overruning */
Paul Mundt959f85f2006-09-27 16:43:28 +0900143 word = SH4_PCICR_PREFIX | SH4_PCICR_CFIN | SH4_PCICR_FTO;
Magnus Dammb8b47bf2009-03-11 15:41:51 +0900144 pci_write_reg(chan, word, SH4_PCICR);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900145
Paul Mundtf1dcab72009-04-17 17:00:27 +0900146 __set_io_port_base(SH7780_PCI_IO_BASE);
147
Paul Mundte79066a2009-04-20 18:29:22 +0900148 register_pci_controller(chan);
149
Magnus Dammd0e3db42009-03-11 15:46:14 +0900150 return 0;
Paul Mundt5283ecb2006-09-27 15:59:17 +0900151}
Paul Mundte79066a2009-04-20 18:29:22 +0900152arch_initcall(sh7780_pci_init);