blob: 87a7f3b7a38f692e74145bb3de02fc0059c7bc66 [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
Paul Mundt9a7ef6d2006-11-20 13:55:34 +090025#define INTC_BASE 0xffd00000
26#define INTC_ICR0 (INTC_BASE+0x0)
27#define INTC_ICR1 (INTC_BASE+0x1c)
28#define INTC_INTPRI (INTC_BASE+0x10)
29#define INTC_INTREQ (INTC_BASE+0x24)
30#define INTC_INTMSK0 (INTC_BASE+0x44)
31#define INTC_INTMSK1 (INTC_BASE+0x48)
32#define INTC_INTMSK2 (INTC_BASE+0x40080)
33#define INTC_INTMSKCLR0 (INTC_BASE+0x64)
34#define INTC_INTMSKCLR1 (INTC_BASE+0x68)
35#define INTC_INTMSKCLR2 (INTC_BASE+0x40084)
36#define INTC_INT2MSKR (INTC_BASE+0x40038)
37#define INTC_INT2MSKCR (INTC_BASE+0x4003c)
38
Paul Mundt5283ecb2006-09-27 15:59:17 +090039/*
40 * Initialization. Try all known PCI access methods. Note that we support
41 * using both PCI BIOS and direct access: in such cases, we use I/O ports
42 * to access config space.
43 *
44 * Note that the platform specific initialization (BSC registers, and memory
Paul Mundt959f85f2006-09-27 16:43:28 +090045 * space mapping) will be called via the platform defined function
46 * pcibios_init_platform().
Paul Mundt5283ecb2006-09-27 15:59:17 +090047 */
Magnus Dammd0e3db42009-03-11 15:46:14 +090048int __init sh7780_pci_init(struct pci_channel *chan)
Paul Mundt5283ecb2006-09-27 15:59:17 +090049{
Paul Mundt959f85f2006-09-27 16:43:28 +090050 unsigned int id;
Paul Mundt32351a22007-03-12 14:38:59 +090051 int ret, match = 0;
Paul Mundt5283ecb2006-09-27 15:59:17 +090052
53 pr_debug("PCI: Starting intialization.\n");
54
Magnus Damme4c6a362008-02-19 21:35:04 +090055 chan->reg_base = 0xfe040000;
Magnus Dammef53fde2008-02-19 21:35:14 +090056 chan->io_base = 0xfe200000;
Magnus Damme4c6a362008-02-19 21:35:04 +090057
Magnus Damme036eaa2008-02-14 13:52:43 +090058 ctrl_outl(0x00000001, SH7780_PCI_VCR2); /* Enable PCIC */
Paul Mundt959f85f2006-09-27 16:43:28 +090059
60 /* check for SH7780/SH7780R hardware */
Magnus Dammd0e3db42009-03-11 15:46:14 +090061 id = pci_read_reg(chan, SH7780_PCIVID);
Paul Mundt32351a22007-03-12 14:38:59 +090062 if ((id & 0xffff) == SH7780_VENDOR_ID) {
63 switch ((id >> 16) & 0xffff) {
Yoshihiro Shimoda7d740a02008-01-07 14:40:07 +090064 case SH7763_DEVICE_ID:
Paul Mundt32351a22007-03-12 14:38:59 +090065 case SH7780_DEVICE_ID:
66 case SH7781_DEVICE_ID:
67 case SH7785_DEVICE_ID:
68 match = 1;
69 break;
70 }
71 }
72
73 if (unlikely(!match)) {
Paul Mundt959f85f2006-09-27 16:43:28 +090074 printk(KERN_ERR "PCI: This is not an SH7780 (%x)\n", id);
75 return -ENODEV;
76 }
77
Paul Mundt5283ecb2006-09-27 15:59:17 +090078 /* Setup the INTC */
Nobuhiro Iwamatsub7576232007-03-29 00:07:35 +090079 if (mach_is_7780se()) {
80 /* ICR0: IRL=use separately */
81 ctrl_outl(0x00C00020, INTC_ICR0);
82 /* ICR1: detect low level(for 2ndcut) */
83 ctrl_outl(0xAAAA0000, INTC_ICR1);
84 /* INTPRI: priority=3(all) */
85 ctrl_outl(0x33333333, INTC_INTPRI);
Nobuhiro Iwamatsub7576232007-03-29 00:07:35 +090086 }
Paul Mundt5283ecb2006-09-27 15:59:17 +090087
Magnus Dammd0e3db42009-03-11 15:46:14 +090088 if ((ret = sh4_pci_check_direct(chan)) != 0)
Paul Mundt5283ecb2006-09-27 15:59:17 +090089 return ret;
90
91 return pcibios_init_platform();
92}
Paul Mundt5283ecb2006-09-27 15:59:17 +090093
Magnus Dammb8b47bf2009-03-11 15:41:51 +090094int __init sh7780_pcic_init(struct pci_channel *chan,
95 struct sh4_pci_address_map *map)
Paul Mundt5283ecb2006-09-27 15:59:17 +090096{
97 u32 word;
98
99 /*
100 * This code is unused for some boards as it is done in the
101 * bootloader and doing it here means the MAC addresses loaded
102 * by the bootloader get lost.
103 */
Paul Mundt959f85f2006-09-27 16:43:28 +0900104 if (!(map->flags & SH4_PCIC_NO_RESET)) {
Paul Mundt5283ecb2006-09-27 15:59:17 +0900105 /* toggle PCI reset pin */
Paul Mundt959f85f2006-09-27 16:43:28 +0900106 word = SH4_PCICR_PREFIX | SH4_PCICR_PRST;
Magnus Dammb8b47bf2009-03-11 15:41:51 +0900107 pci_write_reg(chan, word, SH4_PCICR);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900108 /* Wait for a long time... not 1 sec. but long enough */
109 mdelay(100);
Paul Mundt959f85f2006-09-27 16:43:28 +0900110 word = SH4_PCICR_PREFIX;
Magnus Dammb8b47bf2009-03-11 15:41:51 +0900111 pci_write_reg(chan, word, SH4_PCICR);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900112 }
113
114 /* set the command/status bits to:
115 * Wait Cycle Control + Parity Enable + Bus Master +
116 * Mem space enable
117 */
Magnus Dammb8b47bf2009-03-11 15:41:51 +0900118 pci_write_reg(chan, 0x00000046, SH7780_PCICMD);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900119
120 /* define this host as the host bridge */
Paul Mundt959f85f2006-09-27 16:43:28 +0900121 word = PCI_BASE_CLASS_BRIDGE << 24;
Magnus Dammb8b47bf2009-03-11 15:41:51 +0900122 pci_write_reg(chan, word, SH7780_PCIRID);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900123
124 /* Set IO and Mem windows to local address
125 * Make PCI and local address the same for easy 1 to 1 mapping
Paul Mundt5283ecb2006-09-27 15:59:17 +0900126 */
Magnus Dammb8b47bf2009-03-11 15:41:51 +0900127 pci_write_reg(chan, map->window0.size - 0xfffff, SH4_PCILSR0);
128 pci_write_reg(chan, map->window1.size - 0xfffff, SH4_PCILSR1);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900129 /* Set the values on window 0 PCI config registers */
Magnus Dammb8b47bf2009-03-11 15:41:51 +0900130 pci_write_reg(chan, map->window0.base, SH4_PCILAR0);
131 pci_write_reg(chan, map->window0.base, SH7780_PCIMBAR0);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900132 /* Set the values on window 1 PCI config registers */
Magnus Dammb8b47bf2009-03-11 15:41:51 +0900133 pci_write_reg(chan, map->window1.base, SH4_PCILAR1);
134 pci_write_reg(chan, map->window1.base, SH7780_PCIMBAR1);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900135
Magnus Damm710fa3c2009-03-11 15:47:23 +0900136 /* Map IO space into PCI IO window:
137 * IO addresses will be translated to the PCI IO window base address
Paul Mundt5283ecb2006-09-27 15:59:17 +0900138 */
Magnus Dammef53fde2008-02-19 21:35:14 +0900139 pr_debug("PCI: Mapping IO address 0x%x - 0x%x to base 0x%lx\n",
Magnus Damm710fa3c2009-03-11 15:47:23 +0900140 chan->io_resource->start, chan->io_resource->end,
Magnus Dammef53fde2008-02-19 21:35:14 +0900141 chan->io_base + chan->io_resource->start);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900142
143 /* NOTE: I'm ignoring the PCI error IRQs for now..
144 * TODO: add support for the internal error interrupts and
145 * DMA interrupts...
146 */
147
Nobuhiro Iwamatsub7576232007-03-29 00:07:35 +0900148 /* Apply any last-minute PCIC fixups */
Magnus Dammb8b47bf2009-03-11 15:41:51 +0900149 pci_fixup_pcic(chan);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900150
151 /* SH7780 init done, set central function init complete */
152 /* use round robin mode to stop a device starving/overruning */
Paul Mundt959f85f2006-09-27 16:43:28 +0900153 word = SH4_PCICR_PREFIX | SH4_PCICR_CFIN | SH4_PCICR_FTO;
Magnus Dammb8b47bf2009-03-11 15:41:51 +0900154 pci_write_reg(chan, word, SH4_PCICR);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900155
Magnus Dammd0e3db42009-03-11 15:46:14 +0900156 return 0;
Paul Mundt5283ecb2006-09-27 15:59:17 +0900157}