^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * PCI support for the Sega Dreamcast
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2001, 2002 M. R. Brown
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2002, 2003 Paul Mundt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * This file originally bore the message (with enclosed-$):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Id: pci.c,v 1.3 2003/05/04 19:29:46 lethal Exp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Dreamcast PCI: Supports SEGA Broadband Adaptor only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/param.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <asm/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <mach/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) static struct resource gapspci_resources[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) .name = "GAPSPCI IO",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) .start = GAPSPCI_BBA_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) .end = GAPSPCI_BBA_CONFIG + GAPSPCI_BBA_CONFIG_SIZE - 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) .flags = IORESOURCE_IO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) .name = "GAPSPCI mem",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) .start = GAPSPCI_DMA_BASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) .end = GAPSPCI_DMA_BASE + GAPSPCI_DMA_SIZE - 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) .flags = IORESOURCE_MEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static struct pci_channel dreamcast_pci_controller = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) .pci_ops = &gapspci_pci_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) .resources = gapspci_resources,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) .nr_resources = ARRAY_SIZE(gapspci_resources),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) .io_offset = 0x00000000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) .mem_offset = 0x00000000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * gapspci init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static int __init gapspci_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) char idbuf[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * FIXME: All of this wants documenting to some degree,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * even some basic register definitions would be nice.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * I haven't seen anything this ugly since.. maple.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) for (i=0; i<16; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) idbuf[i] = inb(GAPSPCI_REGS+i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (strncmp(idbuf, "GAPSPCI_BRIDGE_2", 16))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) outl(0x5a14a501, GAPSPCI_REGS+0x18);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) for (i=0; i<1000000; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) cpu_relax();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (inl(GAPSPCI_REGS+0x18) != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) outl(0x01000000, GAPSPCI_REGS+0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) outl(0x01000000, GAPSPCI_REGS+0x24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) outl(GAPSPCI_DMA_BASE, GAPSPCI_REGS+0x28);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) outl(GAPSPCI_DMA_BASE+GAPSPCI_DMA_SIZE, GAPSPCI_REGS+0x2c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) outl(1, GAPSPCI_REGS+0x14);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) outl(1, GAPSPCI_REGS+0x34);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) /* Setting Broadband Adapter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) outw(0xf900, GAPSPCI_BBA_CONFIG+0x06);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) outl(0x00000000, GAPSPCI_BBA_CONFIG+0x30);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) outb(0x00, GAPSPCI_BBA_CONFIG+0x3c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) outb(0xf0, GAPSPCI_BBA_CONFIG+0x0d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) outw(0x0006, GAPSPCI_BBA_CONFIG+0x04);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) outl(0x00002001, GAPSPCI_BBA_CONFIG+0x10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) outl(0x01000000, GAPSPCI_BBA_CONFIG+0x14);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) return register_pci_controller(&dreamcast_pci_controller);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) arch_initcall(gapspci_init);