13444f5ecSPaul Mundt /* 23444f5ecSPaul Mundt * PCI support for the Sega Dreamcast 33444f5ecSPaul Mundt * 43444f5ecSPaul Mundt * Copyright (C) 2001, 2002 M. R. Brown 53444f5ecSPaul Mundt * Copyright (C) 2002, 2003 Paul Mundt 63444f5ecSPaul Mundt * 73444f5ecSPaul Mundt * This file originally bore the message (with enclosed-$): 83444f5ecSPaul Mundt * Id: pci.c,v 1.3 2003/05/04 19:29:46 lethal Exp 93444f5ecSPaul Mundt * Dreamcast PCI: Supports SEGA Broadband Adaptor only. 103444f5ecSPaul Mundt * 113444f5ecSPaul Mundt * This file is subject to the terms and conditions of the GNU General Public 123444f5ecSPaul Mundt * License. See the file "COPYING" in the main directory of this archive 133444f5ecSPaul Mundt * for more details. 143444f5ecSPaul Mundt */ 153444f5ecSPaul Mundt 163444f5ecSPaul Mundt #include <linux/sched.h> 173444f5ecSPaul Mundt #include <linux/kernel.h> 183444f5ecSPaul Mundt #include <linux/param.h> 193444f5ecSPaul Mundt #include <linux/interrupt.h> 203444f5ecSPaul Mundt #include <linux/init.h> 213444f5ecSPaul Mundt #include <linux/irq.h> 223444f5ecSPaul Mundt #include <linux/pci.h> 233444f5ecSPaul Mundt #include <linux/module.h> 243444f5ecSPaul Mundt #include <asm/io.h> 253444f5ecSPaul Mundt #include <asm/irq.h> 263444f5ecSPaul Mundt #include <mach/pci.h> 273444f5ecSPaul Mundt 28*b6c58b1dSPaul Mundt static struct resource gapspci_resources[] = { 29*b6c58b1dSPaul Mundt { 303444f5ecSPaul Mundt .name = "GAPSPCI IO", 313444f5ecSPaul Mundt .start = GAPSPCI_BBA_CONFIG, 323444f5ecSPaul Mundt .end = GAPSPCI_BBA_CONFIG + GAPSPCI_BBA_CONFIG_SIZE - 1, 333444f5ecSPaul Mundt .flags = IORESOURCE_IO, 34*b6c58b1dSPaul Mundt }, { 353444f5ecSPaul Mundt .name = "GAPSPCI mem", 363444f5ecSPaul Mundt .start = GAPSPCI_DMA_BASE, 373444f5ecSPaul Mundt .end = GAPSPCI_DMA_BASE + GAPSPCI_DMA_SIZE - 1, 383444f5ecSPaul Mundt .flags = IORESOURCE_MEM, 39*b6c58b1dSPaul Mundt }, 403444f5ecSPaul Mundt }; 413444f5ecSPaul Mundt 42951a681bSPaul Mundt static struct pci_channel dreamcast_pci_controller = { 43951a681bSPaul Mundt .pci_ops = &gapspci_pci_ops, 44*b6c58b1dSPaul Mundt .resources = gapspci_resources, 45*b6c58b1dSPaul Mundt .nr_resources = ARRAY_SIZE(gapspci_resources), 46951a681bSPaul Mundt .io_offset = 0x00000000, 47951a681bSPaul Mundt .mem_offset = 0x00000000, 48951a681bSPaul Mundt }; 49951a681bSPaul Mundt 503444f5ecSPaul Mundt /* 513444f5ecSPaul Mundt * gapspci init 523444f5ecSPaul Mundt */ 533444f5ecSPaul Mundt 54951a681bSPaul Mundt static int __init gapspci_init(void) 553444f5ecSPaul Mundt { 563444f5ecSPaul Mundt char idbuf[16]; 573444f5ecSPaul Mundt int i; 583444f5ecSPaul Mundt 593444f5ecSPaul Mundt /* 603444f5ecSPaul Mundt * FIXME: All of this wants documenting to some degree, 613444f5ecSPaul Mundt * even some basic register definitions would be nice. 623444f5ecSPaul Mundt * 633444f5ecSPaul Mundt * I haven't seen anything this ugly since.. maple. 643444f5ecSPaul Mundt */ 653444f5ecSPaul Mundt 663444f5ecSPaul Mundt for (i=0; i<16; i++) 673444f5ecSPaul Mundt idbuf[i] = inb(GAPSPCI_REGS+i); 683444f5ecSPaul Mundt 693444f5ecSPaul Mundt if (strncmp(idbuf, "GAPSPCI_BRIDGE_2", 16)) 703444f5ecSPaul Mundt return -ENODEV; 713444f5ecSPaul Mundt 723444f5ecSPaul Mundt outl(0x5a14a501, GAPSPCI_REGS+0x18); 733444f5ecSPaul Mundt 743444f5ecSPaul Mundt for (i=0; i<1000000; i++) 753444f5ecSPaul Mundt cpu_relax(); 763444f5ecSPaul Mundt 773444f5ecSPaul Mundt if (inl(GAPSPCI_REGS+0x18) != 1) 783444f5ecSPaul Mundt return -EINVAL; 793444f5ecSPaul Mundt 803444f5ecSPaul Mundt outl(0x01000000, GAPSPCI_REGS+0x20); 813444f5ecSPaul Mundt outl(0x01000000, GAPSPCI_REGS+0x24); 823444f5ecSPaul Mundt 833444f5ecSPaul Mundt outl(GAPSPCI_DMA_BASE, GAPSPCI_REGS+0x28); 843444f5ecSPaul Mundt outl(GAPSPCI_DMA_BASE+GAPSPCI_DMA_SIZE, GAPSPCI_REGS+0x2c); 853444f5ecSPaul Mundt 863444f5ecSPaul Mundt outl(1, GAPSPCI_REGS+0x14); 873444f5ecSPaul Mundt outl(1, GAPSPCI_REGS+0x34); 883444f5ecSPaul Mundt 893444f5ecSPaul Mundt /* Setting Broadband Adapter */ 903444f5ecSPaul Mundt outw(0xf900, GAPSPCI_BBA_CONFIG+0x06); 913444f5ecSPaul Mundt outl(0x00000000, GAPSPCI_BBA_CONFIG+0x30); 923444f5ecSPaul Mundt outb(0x00, GAPSPCI_BBA_CONFIG+0x3c); 933444f5ecSPaul Mundt outb(0xf0, GAPSPCI_BBA_CONFIG+0x0d); 943444f5ecSPaul Mundt outw(0x0006, GAPSPCI_BBA_CONFIG+0x04); 953444f5ecSPaul Mundt outl(0x00002001, GAPSPCI_BBA_CONFIG+0x10); 963444f5ecSPaul Mundt outl(0x01000000, GAPSPCI_BBA_CONFIG+0x14); 973444f5ecSPaul Mundt 98bcf39352SPaul Mundt return register_pci_controller(&dreamcast_pci_controller); 993444f5ecSPaul Mundt } 100951a681bSPaul Mundt arch_initcall(gapspci_init); 101