blob: 8405c8fded6f9cb891a14813550ad672159721a7 [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 Mundta45635d2010-01-29 22:19:04 +09004 * Copyright (C) 2005 - 2010 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 Mundtaee44672010-02-01 11:33:22 +090016#include <linux/log2.h>
Paul Mundt959f85f2006-09-27 16:43:28 +090017#include "pci-sh4.h"
Paul Mundta45635d2010-01-29 22:19:04 +090018#include <asm/mmu.h>
19#include <asm/sizes.h>
Paul Mundt5283ecb2006-09-27 15:59:17 +090020
Paul Mundte79066a2009-04-20 18:29:22 +090021static struct resource sh7785_io_resource = {
22 .name = "SH7785_IO",
Paul Mundta45635d2010-01-29 22:19:04 +090023 .start = 0x1000,
24 .end = SH7780_PCI_IO_SIZE - 1,
Paul Mundte79066a2009-04-20 18:29:22 +090025 .flags = IORESOURCE_IO
26};
27
28static struct resource sh7785_mem_resource = {
29 .name = "SH7785_mem",
30 .start = SH7780_PCI_MEMORY_BASE,
31 .end = SH7780_PCI_MEMORY_BASE + SH7780_PCI_MEM_SIZE - 1,
32 .flags = IORESOURCE_MEM
33};
34
35static struct pci_channel sh7780_pci_controller = {
36 .pci_ops = &sh4_pci_ops,
37 .mem_resource = &sh7785_mem_resource,
Paul Mundt09cfeb12009-04-20 18:42:00 +090038 .mem_offset = 0x00000000,
Paul Mundte79066a2009-04-20 18:29:22 +090039 .io_resource = &sh7785_io_resource,
Paul Mundt09cfeb12009-04-20 18:42:00 +090040 .io_offset = 0x00000000,
Paul Mundt5582b062009-05-27 00:12:58 +090041 .io_map_base = SH7780_PCI_IO_BASE,
Paul Mundte79066a2009-04-20 18:29:22 +090042};
43
Paul Mundte79066a2009-04-20 18:29:22 +090044static int __init sh7780_pci_init(void)
Paul Mundt5283ecb2006-09-27 15:59:17 +090045{
Paul Mundte79066a2009-04-20 18:29:22 +090046 struct pci_channel *chan = &sh7780_pci_controller;
Paul Mundta45635d2010-01-29 22:19:04 +090047 phys_addr_t memphys;
48 size_t memsize;
Paul Mundt959f85f2006-09-27 16:43:28 +090049 unsigned int id;
Paul Mundta45635d2010-01-29 22:19:04 +090050 const char *type;
Paul Mundt5283ecb2006-09-27 15:59:17 +090051
Paul Mundt4e7b7fd2009-04-17 15:05:19 +090052 printk(KERN_NOTICE "PCI: Starting intialization.\n");
Paul Mundt5283ecb2006-09-27 15:59:17 +090053
Magnus Damme4c6a362008-02-19 21:35:04 +090054 chan->reg_base = 0xfe040000;
55
Paul Mundt4e7b7fd2009-04-17 15:05:19 +090056 /* Enable CPU access to the PCIC registers. */
57 __raw_writel(PCIECR_ENBL, PCIECR);
Paul Mundt959f85f2006-09-27 16:43:28 +090058
Paul Mundta45635d2010-01-29 22:19:04 +090059 /* Reset */
60 __raw_writel(SH4_PCICR_PREFIX | SH4_PCICR_PRST,
61 chan->reg_base + SH4_PCICR);
62
Paul Mundtaee44672010-02-01 11:33:22 +090063 /*
64 * Wait for it to come back up. The spec says to allow for up to
65 * 1 second after toggling the reset pin, but in practice 100ms
66 * is more than enough.
67 */
Paul Mundta45635d2010-01-29 22:19:04 +090068 mdelay(100);
69
70 id = __raw_readw(chan->reg_base + PCI_VENDOR_ID);
71 if (id != PCI_VENDOR_ID_RENESAS) {
Paul Mundt4e7b7fd2009-04-17 15:05:19 +090072 printk(KERN_ERR "PCI: Unknown vendor ID 0x%04x.\n", id);
Paul Mundt959f85f2006-09-27 16:43:28 +090073 return -ENODEV;
74 }
75
Paul Mundta45635d2010-01-29 22:19:04 +090076 id = __raw_readw(chan->reg_base + PCI_DEVICE_ID);
77 type = (id == PCI_DEVICE_ID_RENESAS_SH7763) ? "SH7763" :
78 (id == PCI_DEVICE_ID_RENESAS_SH7780) ? "SH7780" :
79 (id == PCI_DEVICE_ID_RENESAS_SH7781) ? "SH7781" :
80 (id == PCI_DEVICE_ID_RENESAS_SH7785) ? "SH7785" :
Paul Mundt4e7b7fd2009-04-17 15:05:19 +090081 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,
Paul Mundta45635d2010-01-29 22:19:04 +090090 __raw_readb(chan->reg_base + PCI_REVISION_ID));
Paul Mundt4e7b7fd2009-04-17 15:05:19 +090091
Paul Mundtc66c1d72009-04-17 16:38:00 +090092 /*
Paul Mundta45635d2010-01-29 22:19:04 +090093 * Now throw it in to register initialization mode and
94 * start the real work.
Paul Mundtc66c1d72009-04-17 16:38:00 +090095 */
Paul Mundta45635d2010-01-29 22:19:04 +090096 __raw_writel(SH4_PCICR_PREFIX, chan->reg_base + SH4_PCICR);
97
Paul Mundta45635d2010-01-29 22:19:04 +090098 __raw_writel(0, chan->reg_base + PCI_BASE_ADDRESS_0);
Paul Mundt5283ecb2006-09-27 15:59:17 +090099
Paul Mundtaee44672010-02-01 11:33:22 +0900100 memphys = __pa(memory_start);
101 memsize = roundup_pow_of_two(memory_end - memory_start);
102
103 /*
104 * If there's more than 512MB of memory, we need to roll over to
105 * LAR1/LSR1.
106 */
107 if (memsize > SZ_512M) {
108 __raw_writel(memphys + SZ_512M, chan->reg_base + SH4_PCILAR1);
109 __raw_writel((((memsize - SZ_512M) - SZ_1M) & 0x1ff00000) | 1,
110 chan->reg_base + SH4_PCILSR1);
111 memsize = SZ_512M;
112 } else {
113 /*
114 * Otherwise just zero it out and disable it.
115 */
116 __raw_writel(0, chan->reg_base + SH4_PCILAR1);
117 __raw_writel(0, chan->reg_base + SH4_PCILSR1);
118 }
119
120 /*
121 * LAR0/LSR0 covers up to the first 512MB, which is enough to
122 * cover all of lowmem on most platforms.
123 */
Paul Mundta45635d2010-01-29 22:19:04 +0900124 __raw_writel(memphys, chan->reg_base + SH4_PCILAR0);
Paul Mundtaee44672010-02-01 11:33:22 +0900125 __raw_writel(((memsize - SZ_1M) & 0x1ff00000) | 1,
Paul Mundta45635d2010-01-29 22:19:04 +0900126 chan->reg_base + SH4_PCILSR0);
Paul Mundt62c7ae82009-04-17 20:37:16 +0900127
Paul Mundta45635d2010-01-29 22:19:04 +0900128 /* Clear out PCI arbiter IRQs */
129 __raw_writel(0, chan->reg_base + SH4_PCIAINT);
Paul Mundt62c7ae82009-04-17 20:37:16 +0900130
Paul Mundta45635d2010-01-29 22:19:04 +0900131 /* Unmask all of the arbiter IRQs. */
132 __raw_writel(SH4_PCIAINT_MBKN | SH4_PCIAINT_TBTO | SH4_PCIAINT_MBTO | \
133 SH4_PCIAINT_TABT | SH4_PCIAINT_MABT | SH4_PCIAINT_RDPE | \
134 SH4_PCIAINT_WDPE, chan->reg_base + SH4_PCIAINTM);
Paul Mundt62c7ae82009-04-17 20:37:16 +0900135
Paul Mundta45635d2010-01-29 22:19:04 +0900136 /* Clear all error conditions */
137 __raw_writew(PCI_STATUS_DETECTED_PARITY | \
138 PCI_STATUS_SIG_SYSTEM_ERROR | \
139 PCI_STATUS_REC_MASTER_ABORT | \
140 PCI_STATUS_REC_TARGET_ABORT | \
141 PCI_STATUS_SIG_TARGET_ABORT | \
142 PCI_STATUS_PARITY, chan->reg_base + PCI_STATUS);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900143
Paul Mundta45635d2010-01-29 22:19:04 +0900144 __raw_writew(PCI_COMMAND_SERR | PCI_COMMAND_WAIT | \
145 PCI_COMMAND_PARITY | PCI_COMMAND_MASTER | \
146 PCI_COMMAND_MEMORY, chan->reg_base + PCI_COMMAND);
Paul Mundt62c7ae82009-04-17 20:37:16 +0900147
Paul Mundta45635d2010-01-29 22:19:04 +0900148 /* Unmask all of the PCI IRQs */
149 __raw_writel(SH4_PCIINTM_TTADIM | SH4_PCIINTM_TMTOIM | \
150 SH4_PCIINTM_MDEIM | SH4_PCIINTM_APEDIM | \
151 SH4_PCIINTM_SDIM | SH4_PCIINTM_DPEITWM | \
152 SH4_PCIINTM_PEDITRM | SH4_PCIINTM_TADIMM | \
153 SH4_PCIINTM_MADIMM | SH4_PCIINTM_MWPDIM | \
154 SH4_PCIINTM_MRDPEIM, chan->reg_base + SH4_PCIINTM);
Paul Mundt62c7ae82009-04-17 20:37:16 +0900155
Paul Mundta45635d2010-01-29 22:19:04 +0900156 /*
157 * Disable the cache snoop controller for non-coherent DMA.
158 */
159 __raw_writel(0, chan->reg_base + SH7780_PCICSCR0);
160 __raw_writel(0, chan->reg_base + SH7780_PCICSAR0);
161 __raw_writel(0, chan->reg_base + SH7780_PCICSCR1);
162 __raw_writel(0, chan->reg_base + SH7780_PCICSAR1);
Paul Mundt62c7ae82009-04-17 20:37:16 +0900163
Paul Mundta45635d2010-01-29 22:19:04 +0900164 __raw_writel(0xfd000000, chan->reg_base + SH7780_PCIMBR0);
165 __raw_writel(0x00fc0000, chan->reg_base + SH7780_PCIMBMR0);
166
167 __raw_writel(0, chan->reg_base + SH7780_PCIIOBR);
168 __raw_writel(0, chan->reg_base + SH7780_PCIIOBMR);
169
170 /*
171 * Initialization mode complete, release the control register and
172 * enable round robin mode to stop device overruns/starvation.
173 */
174 __raw_writel(SH4_PCICR_PREFIX | SH4_PCICR_CFIN | SH4_PCICR_FTO,
175 chan->reg_base + SH4_PCICR);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900176
Paul Mundte79066a2009-04-20 18:29:22 +0900177 register_pci_controller(chan);
178
Magnus Dammd0e3db42009-03-11 15:46:14 +0900179 return 0;
Paul Mundt5283ecb2006-09-27 15:59:17 +0900180}
Paul Mundte79066a2009-04-20 18:29:22 +0900181arch_initcall(sh7780_pci_init);