OMAP: DISPC: Fix to disable also interface clocks. 2nd.
[linux-ginger.git] / arch / m68k / kernel / bios32.c
blobaf170c2be73550e100df3a0da78d137e3c0f8ab2
1 /*
2 * bios32.c - PCI BIOS functions for m68k systems.
4 * Written by Wout Klaren.
6 * Based on the DEC Alpha bios32.c by Dave Rusling and David Mosberger.
7 */
9 #include <linux/init.h>
10 #include <linux/kernel.h>
12 #if 0
13 # define DBG_DEVS(args) printk args
14 #else
15 # define DBG_DEVS(args)
16 #endif
18 #ifdef CONFIG_PCI
21 * PCI support for Linux/m68k. Currently only the Hades is supported.
23 * The support for PCI bridges in the DEC Alpha version has
24 * been removed in this version.
27 #include <linux/pci.h>
28 #include <linux/slab.h>
29 #include <linux/mm.h>
31 #include <asm/io.h>
32 #include <asm/pci.h>
33 #include <asm/uaccess.h>
35 #define KB 1024
36 #define MB (1024*KB)
37 #define GB (1024*MB)
39 #define MAJOR_REV 0
40 #define MINOR_REV 5
43 * Align VAL to ALIGN, which must be a power of two.
46 #define ALIGN(val,align) (((val) + ((align) - 1)) & ~((align) - 1))
49 * Offsets relative to the I/O and memory base addresses from where resources
50 * are allocated.
53 #define IO_ALLOC_OFFSET 0x00004000
54 #define MEM_ALLOC_OFFSET 0x04000000
57 * Declarations of hardware specific initialisation functions.
60 extern struct pci_bus_info *init_hades_pci(void);
63 * Bus info structure of the PCI bus. A pointer to this structure is
64 * put in the sysdata member of the pci_bus structure.
67 static struct pci_bus_info *bus_info;
69 static int pci_modify = 1; /* If set, layout the PCI bus ourself. */
70 static int skip_vga; /* If set do not modify base addresses
71 of vga cards.*/
72 static int disable_pci_burst; /* If set do not allow PCI bursts. */
74 static unsigned int io_base;
75 static unsigned int mem_base;
78 * static void disable_dev(struct pci_dev *dev)
80 * Disable PCI device DEV so that it does not respond to I/O or memory
81 * accesses.
83 * Parameters:
85 * dev - device to disable.
88 static void __init disable_dev(struct pci_dev *dev)
90 unsigned short cmd;
92 if (((dev->class >> 8 == PCI_CLASS_NOT_DEFINED_VGA) ||
93 (dev->class >> 8 == PCI_CLASS_DISPLAY_VGA) ||
94 (dev->class >> 8 == PCI_CLASS_DISPLAY_XGA)) && skip_vga)
95 return;
97 pci_read_config_word(dev, PCI_COMMAND, &cmd);
99 cmd &= (~PCI_COMMAND_IO & ~PCI_COMMAND_MEMORY & ~PCI_COMMAND_MASTER);
100 pci_write_config_word(dev, PCI_COMMAND, cmd);
104 * static void layout_dev(struct pci_dev *dev)
106 * Layout memory and I/O for a device.
108 * Parameters:
110 * device - device to layout memory and I/O for.
113 static void __init layout_dev(struct pci_dev *dev)
115 unsigned short cmd;
116 unsigned int base, mask, size, reg;
117 unsigned int alignto;
118 int i;
121 * Skip video cards if requested.
124 if (((dev->class >> 8 == PCI_CLASS_NOT_DEFINED_VGA) ||
125 (dev->class >> 8 == PCI_CLASS_DISPLAY_VGA) ||
126 (dev->class >> 8 == PCI_CLASS_DISPLAY_XGA)) && skip_vga)
127 return;
129 pci_read_config_word(dev, PCI_COMMAND, &cmd);
131 for (reg = PCI_BASE_ADDRESS_0, i = 0; reg <= PCI_BASE_ADDRESS_5; reg += 4, i++)
134 * Figure out how much space and of what type this
135 * device wants.
138 pci_write_config_dword(dev, reg, 0xffffffff);
139 pci_read_config_dword(dev, reg, &base);
141 if (!base)
143 /* this base-address register is unused */
144 dev->resource[i].start = 0;
145 dev->resource[i].end = 0;
146 dev->resource[i].flags = 0;
147 continue;
151 * We've read the base address register back after
152 * writing all ones and so now we must decode it.
155 if (base & PCI_BASE_ADDRESS_SPACE_IO)
158 * I/O space base address register.
161 cmd |= PCI_COMMAND_IO;
163 base &= PCI_BASE_ADDRESS_IO_MASK;
164 mask = (~base << 1) | 0x1;
165 size = (mask & base) & 0xffffffff;
168 * Align to multiple of size of minimum base.
171 alignto = max_t(unsigned int, 0x040, size);
172 base = ALIGN(io_base, alignto);
173 io_base = base + size;
174 pci_write_config_dword(dev, reg, base | PCI_BASE_ADDRESS_SPACE_IO);
176 dev->resource[i].start = base;
177 dev->resource[i].end = dev->resource[i].start + size - 1;
178 dev->resource[i].flags = IORESOURCE_IO | PCI_BASE_ADDRESS_SPACE_IO;
180 DBG_DEVS(("layout_dev: IO address: %lX\n", base));
182 else
184 unsigned int type;
187 * Memory space base address register.
190 cmd |= PCI_COMMAND_MEMORY;
191 type = base & PCI_BASE_ADDRESS_MEM_TYPE_MASK;
192 base &= PCI_BASE_ADDRESS_MEM_MASK;
193 mask = (~base << 1) | 0x1;
194 size = (mask & base) & 0xffffffff;
195 switch (type)
197 case PCI_BASE_ADDRESS_MEM_TYPE_32:
198 case PCI_BASE_ADDRESS_MEM_TYPE_64:
199 break;
201 case PCI_BASE_ADDRESS_MEM_TYPE_1M:
202 printk("bios32 WARNING: slot %d, function %d "
203 "requests memory below 1MB---don't "
204 "know how to do that.\n",
205 PCI_SLOT(dev->devfn),
206 PCI_FUNC(dev->devfn));
207 continue;
211 * Align to multiple of size of minimum base.
214 alignto = max_t(unsigned int, 0x1000, size);
215 base = ALIGN(mem_base, alignto);
216 mem_base = base + size;
217 pci_write_config_dword(dev, reg, base);
219 dev->resource[i].start = base;
220 dev->resource[i].end = dev->resource[i].start + size - 1;
221 dev->resource[i].flags = IORESOURCE_MEM;
223 if (type == PCI_BASE_ADDRESS_MEM_TYPE_64)
226 * 64-bit address, set the highest 32 bits
227 * to zero.
230 reg += 4;
231 pci_write_config_dword(dev, reg, 0);
233 i++;
234 dev->resource[i].start = 0;
235 dev->resource[i].end = 0;
236 dev->resource[i].flags = 0;
242 * Enable device:
245 if (dev->class >> 8 == PCI_CLASS_NOT_DEFINED ||
246 dev->class >> 8 == PCI_CLASS_NOT_DEFINED_VGA ||
247 dev->class >> 8 == PCI_CLASS_DISPLAY_VGA ||
248 dev->class >> 8 == PCI_CLASS_DISPLAY_XGA)
251 * All of these (may) have I/O scattered all around
252 * and may not use i/o-base address registers at all.
253 * So we just have to always enable I/O to these
254 * devices.
256 cmd |= PCI_COMMAND_IO;
259 pci_write_config_word(dev, PCI_COMMAND, cmd | PCI_COMMAND_MASTER);
261 pci_write_config_byte(dev, PCI_LATENCY_TIMER, (disable_pci_burst) ? 0 : 32);
263 if (bus_info != NULL)
264 bus_info->conf_device(dev); /* Machine dependent configuration. */
266 DBG_DEVS(("layout_dev: bus %d slot 0x%x VID 0x%x DID 0x%x class 0x%x\n",
267 dev->bus->number, PCI_SLOT(dev->devfn), dev->vendor, dev->device, dev->class));
271 * static void layout_bus(struct pci_bus *bus)
273 * Layout memory and I/O for all devices on the given bus.
275 * Parameters:
277 * bus - bus.
280 static void __init layout_bus(struct pci_bus *bus)
282 unsigned int bio, bmem;
283 struct pci_dev *dev;
285 DBG_DEVS(("layout_bus: starting bus %d\n", bus->number));
287 if (!bus->devices && !bus->children)
288 return;
291 * Align the current bases on appropriate boundaries (4K for
292 * IO and 1MB for memory).
295 bio = io_base = ALIGN(io_base, 4*KB);
296 bmem = mem_base = ALIGN(mem_base, 1*MB);
299 * PCI devices might have been setup by a PCI BIOS emulation
300 * running under TOS. In these cases there is a
301 * window during which two devices may have an overlapping
302 * address range. To avoid this causing trouble, we first
303 * turn off the I/O and memory address decoders for all PCI
304 * devices. They'll be re-enabled only once all address
305 * decoders are programmed consistently.
308 DBG_DEVS(("layout_bus: disable_dev for bus %d\n", bus->number));
310 for (dev = bus->devices; dev; dev = dev->sibling)
312 if ((dev->class >> 16 != PCI_BASE_CLASS_BRIDGE) ||
313 (dev->class >> 8 == PCI_CLASS_BRIDGE_PCMCIA))
314 disable_dev(dev);
318 * Allocate space to each device:
321 DBG_DEVS(("layout_bus: starting bus %d devices\n", bus->number));
323 for (dev = bus->devices; dev; dev = dev->sibling)
325 if ((dev->class >> 16 != PCI_BASE_CLASS_BRIDGE) ||
326 (dev->class >> 8 == PCI_CLASS_BRIDGE_PCMCIA))
327 layout_dev(dev);
330 DBG_DEVS(("layout_bus: bus %d finished\n", bus->number));
334 * static void pcibios_fixup(void)
336 * Layout memory and I/O of all devices on the PCI bus if 'pci_modify' is
337 * true. This might be necessary because not every m68k machine with a PCI
338 * bus has a PCI BIOS. This function should be called right after
339 * pci_scan_bus() in pcibios_init().
342 static void __init pcibios_fixup(void)
344 if (pci_modify)
347 * Set base addresses for allocation of I/O and memory space.
350 io_base = bus_info->io_space.start + IO_ALLOC_OFFSET;
351 mem_base = bus_info->mem_space.start + MEM_ALLOC_OFFSET;
354 * Scan the tree, allocating PCI memory and I/O space.
357 layout_bus(pci_bus_b(pci_root.next));
361 * Fix interrupt assignments, etc.
364 bus_info->fixup(pci_modify);
368 * static void pcibios_claim_resources(struct pci_bus *bus)
370 * Claim all resources that are assigned to devices on the given bus.
372 * Parameters:
374 * bus - bus.
377 static void __init pcibios_claim_resources(struct pci_bus *bus)
379 struct pci_dev *dev;
380 int i;
382 while (bus)
384 for (dev = bus->devices; (dev != NULL); dev = dev->sibling)
386 for (i = 0; i < PCI_NUM_RESOURCES; i++)
388 struct resource *r = &dev->resource[i];
389 struct resource *pr;
390 struct pci_bus_info *bus_info = (struct pci_bus_info *) dev->sysdata;
392 if ((r->start == 0) || (r->parent != NULL))
393 continue;
394 #if 1
395 if (r->flags & IORESOURCE_IO)
396 pr = &bus_info->io_space;
397 else
398 pr = &bus_info->mem_space;
399 #else
400 if (r->flags & IORESOURCE_IO)
401 pr = &ioport_resource;
402 else
403 pr = &iomem_resource;
404 #endif
405 if (request_resource(pr, r) < 0)
407 printk(KERN_ERR "PCI: Address space collision on region %d of device %s\n", i, dev->name);
412 if (bus->children)
413 pcibios_claim_resources(bus->children);
415 bus = bus->next;
420 * int pcibios_assign_resource(struct pci_dev *dev, int i)
422 * Assign a new address to a PCI resource.
424 * Parameters:
426 * dev - device.
427 * i - resource.
429 * Result: 0 if successful.
432 int __init pcibios_assign_resource(struct pci_dev *dev, int i)
434 struct resource *r = &dev->resource[i];
435 struct resource *pr = pci_find_parent_resource(dev, r);
436 unsigned long size = r->end + 1;
438 if (!pr)
439 return -EINVAL;
441 if (r->flags & IORESOURCE_IO)
443 if (size > 0x100)
444 return -EFBIG;
446 if (allocate_resource(pr, r, size, bus_info->io_space.start +
447 IO_ALLOC_OFFSET, bus_info->io_space.end, 1024))
448 return -EBUSY;
450 else
452 if (allocate_resource(pr, r, size, bus_info->mem_space.start +
453 MEM_ALLOC_OFFSET, bus_info->mem_space.end, size))
454 return -EBUSY;
457 if (i < 6)
458 pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + 4 * i, r->start);
460 return 0;
463 void __init pcibios_fixup_bus(struct pci_bus *bus)
465 struct pci_dev *dev;
466 void *sysdata;
468 sysdata = (bus->parent) ? bus->parent->sysdata : bus->sysdata;
470 for (dev = bus->devices; (dev != NULL); dev = dev->sibling)
471 dev->sysdata = sysdata;
474 void __init pcibios_init(void)
476 printk("Linux/m68k PCI BIOS32 revision %x.%02x\n", MAJOR_REV, MINOR_REV);
478 bus_info = NULL;
479 #ifdef CONFIG_HADES
480 if (MACH_IS_HADES)
481 bus_info = init_hades_pci();
482 #endif
483 if (bus_info != NULL)
485 printk("PCI: Probing PCI hardware\n");
486 pci_scan_bus(0, bus_info->m68k_pci_ops, bus_info);
487 pcibios_fixup();
488 pcibios_claim_resources(pci_root);
490 else
491 printk("PCI: No PCI bus detected\n");
494 char * __init pcibios_setup(char *str)
496 if (!strcmp(str, "nomodify"))
498 pci_modify = 0;
499 return NULL;
501 else if (!strcmp(str, "skipvga"))
503 skip_vga = 1;
504 return NULL;
506 else if (!strcmp(str, "noburst"))
508 disable_pci_burst = 1;
509 return NULL;
512 return str;
514 #endif /* CONFIG_PCI */