summaryrefslogtreecommitdiffstats
path: root/arch/mips/ddb5074/pci.c
blob: 50dffdcc2a22536d3d1310e3ae48cf6a52812301 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
/*
 *  arch/mips/ddb5074/pci.c -- NEC DDB Vrc-5074 PCI access routines
 *
 *  Copyright (C) 2000 Geert Uytterhoeven <geert@sonycom.com>
 *                     Albert Dorofeev <albert@sonycom.com>
 *                     Sony Suprastructure Center Europe (SUPC-E), Brussels
 *
 *  $Id: pci.c,v 1.3 2000/02/16 01:45:55 ralf Exp $
 */

#include <linux/init.h>
#include <linux/config.h>
#include <linux/kernel.h>
#include <linux/pci.h>
#include <linux/types.h>
#include <linux/sched.h>
#include <linux/pci.h>
#include <linux/ioport.h>
#include <asm-mips/nile4.h>


static u32 nile4_pre_pci_access0(int slot_num)
{
    u32 pci_addr = 0;
    u32 virt_addr = NILE4_PCI_CFG_BASE;

    /* Set window 1 address 8000000 - 64 bit - 2 MB (PCI config space) */
    nile4_set_pdar(NILE4_PCIW1, PHYSADDR(virt_addr), 0x00200000, 64, 0, 0);
    if (slot_num > 2)
	pci_addr = 0x00040000 << slot_num;
    else
	virt_addr += 0x00040000 << slot_num;
    nile4_set_pmr(NILE4_PCIINIT1, NILE4_PCICMD_CFG, pci_addr);
    return virt_addr;
}

static void nile4_post_pci_access0(void)
{
    /* Set window 1 back to address 8000000 - 64 bit - 128 MB (PCI IO space) */
    nile4_set_pdar(NILE4_PCIW1, PHYSADDR(NILE4_PCI_MEM_BASE), 0x08000000, 64,
    		   1, 1);
    nile4_set_pmr(NILE4_PCIINIT1, NILE4_PCICMD_MEM, 0);
}


static int nile4_pci_read_config_dword( struct pci_dev *dev,
				int where, u32 *val)
{
    int slot_num, func_num;
    u32 base;

    /*
     *  For starters let's do configuration cycle 0 only (one bus only)
     */
    if (dev->bus->number)
	return PCIBIOS_FUNC_NOT_SUPPORTED;

    slot_num = PCI_SLOT(dev->devfn);
    func_num = PCI_FUNC(dev->devfn);
    if (slot_num == 5) {
	/*
	 *  This is Nile 4 and it will crash if we access it like other
	 *   devices
	 */
	*val = nile4_in32(NILE4_PCI_BASE + where);
	return PCIBIOS_SUCCESSFUL;
    }
    base = nile4_pre_pci_access0(slot_num);
    *val = *((volatile u32 *)(base + (func_num << 8) + (where & 0xfc)));
    nile4_post_pci_access0();
    return PCIBIOS_SUCCESSFUL;
}

static int nile4_pci_write_config_dword(struct pci_dev *dev, int where,
					u32 val)
{
    int slot_num, func_num;
    u32 base;

    /*
     *  For starters let's do configuration cycle 0 only (one bus only)
     */
    if (dev->bus->number)
	return PCIBIOS_FUNC_NOT_SUPPORTED;

    slot_num = PCI_SLOT(dev->devfn);
    func_num = PCI_FUNC(dev->devfn);
    if (slot_num == 5) {
	/*
	 *  This is Nile 4 and it will crash if we access it like other
	 *   devices
	 */
	nile4_out32(NILE4_PCI_BASE + where, val);
	return PCIBIOS_SUCCESSFUL;
    }
    base = nile4_pre_pci_access0(slot_num);
    *((volatile u32 *)(base + (func_num << 8) + (where & 0xfc))) = val;
    nile4_post_pci_access0();
    return PCIBIOS_SUCCESSFUL;
}

static int nile4_pci_read_config_word(struct pci_dev *dev, int where, u16 *val)
{
    int status;
    u32 result;

    status = nile4_pci_read_config_dword(dev, where, &result);
    if (status != PCIBIOS_SUCCESSFUL)
	return status;
    if (where & 2)
	result >>= 16;
    *val = result & 0xffff;
    return PCIBIOS_SUCCESSFUL;
}

static int nile4_pci_read_config_byte(struct pci_dev *dev, int where, u8 *val)
{
    int status;
    u32 result;

    status = nile4_pci_read_config_dword(dev, where, &result);
    if (status != PCIBIOS_SUCCESSFUL)
	return status;
    if (where & 1)
	result >>= 8;
    if (where & 2)
	result >>= 16;
    *val = result & 0xff;
    return PCIBIOS_SUCCESSFUL;
}

static int nile4_pci_write_config_word(struct pci_dev *dev, int where, u16 val)
{
    int status, shift = 0;
    u32 result;

    status = nile4_pci_read_config_dword(dev, where, &result);
    if (status != PCIBIOS_SUCCESSFUL)
	return status;
    if (where & 2)
	shift += 16;
    result &= ~(0xffff << shift);
    result |= val << shift;
    return nile4_pci_write_config_dword(dev, where, result);
}

static int nile4_pci_write_config_byte( struct pci_dev *dev, int where, u8 val)
{
    int status, shift = 0;
    u32 result;

    status = nile4_pci_read_config_dword(dev, where, &result);
    if (status != PCIBIOS_SUCCESSFUL)
	return status;
    if (where & 2)
	shift += 16;
    if (where & 1)
	shift += 8;
    result &= ~(0xff << shift);
    result |= val << shift;
    return nile4_pci_write_config_dword(dev, where, result);
}

struct pci_ops nile4_pci_ops = {
    nile4_pci_read_config_byte,
    nile4_pci_read_config_word,
    nile4_pci_read_config_dword,
    nile4_pci_write_config_byte,
    nile4_pci_write_config_word,
    nile4_pci_write_config_dword
};


static void __init pcibios_claim_resources(struct list_head *bus_list)
{
    struct list_head *ln, *dn;
    struct pci_bus *bus;
    struct pci_dev *dev;
    int idx;

    for (ln = bus_list->next; ln != bus_list; ln = ln->next) {
	bus = pci_bus_b(ln);
	for (dn = bus->devices.next; dn != &bus->devices; dn = dn->next) {
	    dev = pci_dev_b(dn);
	    for (idx = 0; idx < PCI_NUM_RESOURCES; idx++) {
		struct resource *r = &dev->resource[idx];
		struct resource *pr;
		if (!r->start)
		    continue;
		pr = pci_find_parent_resource(dev, r);
		if (!pr || request_resource(pr, r) < 0) {
		    printk(KERN_ERR "PCI: Address space collision on region %d of device %s\n", idx, dev->name);
		    /* We probably should disable the region, shouldn't we? */
		}
	    }
	}
	pcibios_claim_resources(&bus->children);
    }
}


void pcibios_init(void)
{
    printk("PCI: Probing PCI hardware\n");
    ioport_resource.end = 0x1ffffff;
    pci_scan_bus(0, &nile4_pci_ops, NULL);
    pcibios_claim_resources(&pci_root_buses);
}

void pcibios_fixup_bus(struct pci_bus *bus)
{
    struct list_head *dn;
    struct pci_dev *dev;
    extern struct pci_dev *pci_pmu;	/* for LEDs D2 and D3 */
    int slot_num, func_num;
    u8 t8;

    /*
     *  FIXME: PMON doesn't autoconfigure the PCI devices
     *         For now we just hardcode them for our configuration
     */
    printk("PCI: Configuring PCI devices (hardcoded)\n");
    for (dn = bus->devices.next; dn != &bus->devices; dn = dn->next) {
	dev = pci_dev_b(dn);

	slot_num = PCI_SLOT(dev->devfn);
	func_num = PCI_FUNC(dev->devfn);
	printk("  Device %2d: ", slot_num);
	switch (slot_num) {
	    case 0:
		printk("[onboard] Acer Labs M1533 Aladdin IV\n");
		dev->irq = nile4_to_irq(NILE4_INT_INTE);
		break;
	    case 1:
		printk("[onboard] DEC DC21140\n");
		dev->irq = nile4_to_irq(NILE4_INT_INTA);
		dev->resource[0].start = 0x100000;
		dev->resource[0].end = dev->resource[0].start+0x7f;
		nile4_pci_write_config_dword(dev, PCI_BASE_ADDRESS_0,
					     dev->resource[0].start);
		dev->resource[1].start = 0x1000000;
		dev->resource[1].end = dev->resource[1].start+0x7f;
		nile4_pci_write_config_dword(dev, PCI_BASE_ADDRESS_0,
					     dev->resource[1].start);
		break;
	    case 2:
		printk("[slot 1]  Realtek 8029\n");
		dev->irq = nile4_to_irq(NILE4_INT_INTA);
		dev->resource[0].start = 0x800000;
		dev->resource[0].end = dev->resource[0].start+0x1f;
		nile4_pci_write_config_dword(dev, PCI_BASE_ADDRESS_0,
					     dev->resource[0].start);
		break;
	    case 3:
		printk("[slot 2]  DEC DC21140 (#2)\n");
		dev->irq = nile4_to_irq(NILE4_INT_INTB);
		dev->resource[0].start = 0x1000000;
		dev->resource[0].end = dev->resource[0].start+0x7f;
		nile4_pci_write_config_dword(dev, PCI_BASE_ADDRESS_0,
					     dev->resource[0].start);
		dev->resource[1].start = 0x4000000;
		dev->resource[1].end = dev->resource[1].start+0x7f;
		nile4_pci_write_config_dword(dev, PCI_BASE_ADDRESS_0,
					     dev->resource[1].start);
		break;
	    case 4:
		printk("[slot 3]  Promise Technology IDE UltraDMA/33");
		printk(" or 3Com 3c905 :-)\n");
		dev->irq = nile4_to_irq(NILE4_INT_INTC);
		dev->resource[0].start = 0x1800000;
		dev->resource[0].end = dev->resource[0].start+0x7fffff;
		nile4_pci_write_config_dword(dev, PCI_BASE_ADDRESS_0,
					     dev->resource[0].start);
		break;
	    case 5:
		printk("[onboard] NEC Vrc-5074 Nile 4 Host Bridge\n");
		/*
		 * Fixup so the serial driver can use the UART
		 */
		dev->irq = nile4_to_irq(NILE4_INT_UART);
		dev->resource[0].start = PHYSADDR(NILE4_BASE);
		dev->resource[0].end = dev->resource[0].start+NILE4_SIZE-1;
		dev->resource[0].flags = IORESOURCE_MEM |
					 PCI_BASE_ADDRESS_MEM_TYPE_64;
		
		break;
	    case 10:
		printk("[onboard] Acer Labs M7101 PMU\n");
		pci_pmu = dev;
		/* Program the lines for LEDs D2 and D3 to output */
		nile4_pci_read_config_byte(dev, 0x7d, &t8);
		t8 |= 0xc0;
		nile4_pci_write_config_byte(dev, 0x7d, t8);
		/* Turn LEDs D2 and D3 off */
		nile4_pci_read_config_byte(dev, 0x7e, &t8);
		t8 |= 0xc0;
		nile4_pci_write_config_byte(dev, 0x7e, t8);
		break;
	    case 13:
		printk("[onboard] Acer Labs M5237 USB\n");
		dev->irq = nile4_to_irq(NILE4_INT_INTE);
		dev->resource[0].start = 0x1001000;
		dev->resource[0].end = dev->resource[0].start+0xfff;
		nile4_pci_write_config_dword(dev, PCI_BASE_ADDRESS_0,
					     dev->resource[0].start);
		break;
	    default:
		printk("\n");
		break;
	}
    }
}

char *pcibios_setup (char *str)
{
    return str;
}

void __init pcibios_update_resource(struct pci_dev *dev, struct resource *root,
				    struct resource *res, int resource)
{
    unsigned long where, size;
    u32 reg;

    where = PCI_BASE_ADDRESS_0 + (resource * 4);
    size = res->end - res->start;
    pci_read_config_dword(dev, where, &reg);
    reg = (reg & size) | (((u32)(res->start - root->start)) & ~size);
    pci_write_config_dword(dev, where, reg);
}

void __init pcibios_update_irq(struct pci_dev *dev, int irq)
{
    pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);
}

void __init pcibios_fixup_pbus_ranges(struct pci_bus *bus,
				      struct pbus_set_ranges_data *ranges)
{
    ranges->io_start -= bus->resource[0]->start;
    ranges->io_end -= bus->resource[0]->start;
    ranges->mem_start -= bus->resource[1]->start;
    ranges->mem_end -= bus->resource[1]->start;
}

int __init pcibios_enable_device(struct pci_dev *dev)
{
    printk("pcibios_enable_device for %04x:%04x\n", dev->vendor, dev->device);
    panic("pcibios_enable_device: not yet implemented\n");
}

void __init pcibios_align_resource(void *data, struct resource *res,
				   unsigned long size)
{}

struct pci_fixup pcibios_fixups[] = {};