blob: 5bc81d5b660a3a786f35d1d5842903f308eecf0a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Uwe Zeisbergerf30c2262006-10-03 23:01:26 +02002 * arch/sh/drivers/pci/ops-dreamcast.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * PCI operations for the Sega Dreamcast
5 *
6 * Copyright (C) 2001, 2002 M. R. Brown
7 * Copyright (C) 2002, 2003 Paul Mundt
8 *
9 * This file originally bore the message (with enclosed-$):
10 * Id: pci.c,v 1.3 2003/05/04 19:29:46 lethal Exp
11 * Dreamcast PCI: Supports SEGA Broadband Adaptor only.
12 *
13 * This file is subject to the terms and conditions of the GNU General Public
14 * License. See the file "COPYING" in the main directory of this archive
15 * for more details.
16 */
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/sched.h>
19#include <linux/kernel.h>
20#include <linux/param.h>
21#include <linux/interrupt.h>
22#include <linux/init.h>
23#include <linux/irq.h>
24#include <linux/pci.h>
Adrian Bunk7223ce22008-06-18 01:30:40 +030025#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27#include <asm/io.h>
28#include <asm/irq.h>
Paul Mundtf15cbe62008-07-29 08:09:44 +090029#include <mach/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31static struct resource gapspci_io_resource = {
32 .name = "GAPSPCI IO",
33 .start = GAPSPCI_BBA_CONFIG,
34 .end = GAPSPCI_BBA_CONFIG + GAPSPCI_BBA_CONFIG_SIZE - 1,
35 .flags = IORESOURCE_IO,
36};
37
38static struct resource gapspci_mem_resource = {
39 .name = "GAPSPCI mem",
40 .start = GAPSPCI_DMA_BASE,
41 .end = GAPSPCI_DMA_BASE + GAPSPCI_DMA_SIZE - 1,
42 .flags = IORESOURCE_MEM,
43};
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045/*
46 * The !gapspci_config_access case really shouldn't happen, ever, unless
47 * someone implicitly messes around with the last devfn value.. otherwise we
48 * only support a single device anyways, and if we didn't have a BBA, we
49 * wouldn't make it terribly far through the PCI setup anyways.
50 *
51 * Also, we could very easily support both Type 0 and Type 1 configurations
52 * here, but since it doesn't seem that there is any such implementation in
Simon Arlotte868d612007-05-14 08:15:10 +090053 * existence, we don't bother.
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 *
55 * I suppose if someone actually gets around to ripping the chip out of
56 * the BBA and hanging some more devices off of it, then this might be
57 * something to take into consideration. However, due to the cost of the BBA,
58 * and the general lack of activity by DC hardware hackers, this doesn't seem
59 * likely to happen anytime soon.
60 */
61static int gapspci_config_access(unsigned char bus, unsigned int devfn)
62{
63 return (bus == 0) && (devfn == 0);
64}
65
66/*
67 * We can also actually read and write in b/w/l sizes! Thankfully this part
68 * was at least done right, and we don't have to do the stupid masking and
69 * shifting that we do on the 7751! Small wonders never cease to amaze.
70 */
71static int gapspci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *val)
72{
73 *val = 0xffffffff;
74
75 if (!gapspci_config_access(bus->number, devfn))
76 return PCIBIOS_DEVICE_NOT_FOUND;
77
78 switch (size) {
Magnus Damm763a4952008-02-26 14:14:56 +090079 case 1: *val = inb(GAPSPCI_BBA_CONFIG+where); break;
80 case 2: *val = inw(GAPSPCI_BBA_CONFIG+where); break;
81 case 4: *val = inl(GAPSPCI_BBA_CONFIG+where); break;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 }
83
84 return PCIBIOS_SUCCESSFUL;
85}
86
87static int gapspci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 val)
88{
89 if (!gapspci_config_access(bus->number, devfn))
90 return PCIBIOS_DEVICE_NOT_FOUND;
91
92 switch (size) {
Magnus Damm763a4952008-02-26 14:14:56 +090093 case 1: outb(( u8)val, GAPSPCI_BBA_CONFIG+where); break;
94 case 2: outw((u16)val, GAPSPCI_BBA_CONFIG+where); break;
95 case 4: outl((u32)val, GAPSPCI_BBA_CONFIG+where); break;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 }
97
98 return PCIBIOS_SUCCESSFUL;
99}
100
101static struct pci_ops gapspci_pci_ops = {
102 .read = gapspci_read,
103 .write = gapspci_write,
104};
105
106/*
107 * gapspci init
108 */
109
Magnus Dammd0e3db42009-03-11 15:46:14 +0900110static int __init gapspci_init(struct pci_channel *chan)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
112 char idbuf[16];
113 int i;
114
115 /*
116 * FIXME: All of this wants documenting to some degree,
117 * even some basic register definitions would be nice.
118 *
119 * I haven't seen anything this ugly since.. maple.
120 */
121
122 for (i=0; i<16; i++)
Magnus Damm763a4952008-02-26 14:14:56 +0900123 idbuf[i] = inb(GAPSPCI_REGS+i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125 if (strncmp(idbuf, "GAPSPCI_BRIDGE_2", 16))
126 return -ENODEV;
127
Magnus Damm763a4952008-02-26 14:14:56 +0900128 outl(0x5a14a501, GAPSPCI_REGS+0x18);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130 for (i=0; i<1000000; i++)
131 ;
132
Magnus Damm763a4952008-02-26 14:14:56 +0900133 if (inl(GAPSPCI_REGS+0x18) != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 return -EINVAL;
135
Magnus Damm763a4952008-02-26 14:14:56 +0900136 outl(0x01000000, GAPSPCI_REGS+0x20);
137 outl(0x01000000, GAPSPCI_REGS+0x24);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Magnus Damm763a4952008-02-26 14:14:56 +0900139 outl(GAPSPCI_DMA_BASE, GAPSPCI_REGS+0x28);
140 outl(GAPSPCI_DMA_BASE+GAPSPCI_DMA_SIZE, GAPSPCI_REGS+0x2c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Magnus Damm763a4952008-02-26 14:14:56 +0900142 outl(1, GAPSPCI_REGS+0x14);
143 outl(1, GAPSPCI_REGS+0x34);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145 /* Setting Broadband Adapter */
Magnus Damm763a4952008-02-26 14:14:56 +0900146 outw(0xf900, GAPSPCI_BBA_CONFIG+0x06);
147 outl(0x00000000, GAPSPCI_BBA_CONFIG+0x30);
148 outb(0x00, GAPSPCI_BBA_CONFIG+0x3c);
149 outb(0xf0, GAPSPCI_BBA_CONFIG+0x0d);
150 outw(0x0006, GAPSPCI_BBA_CONFIG+0x04);
151 outl(0x00002001, GAPSPCI_BBA_CONFIG+0x10);
152 outl(0x01000000, GAPSPCI_BBA_CONFIG+0x14);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154 return 0;
155}
156
157/* Haven't done anything here as yet */
158char * __devinit pcibios_setup(char *str)
159{
160 return str;
161}
Magnus Dammd0e3db42009-03-11 15:46:14 +0900162
163struct pci_channel board_pci_channels[] = {
164 { gapspci_init, &gapspci_pci_ops, &gapspci_io_resource,
165 &gapspci_mem_resource, 0, 1 },
166 { 0, }
167};