1*ff4a7481SKuninori Morimoto // SPDX-License-Identifier: GPL-2.0 23444f5ecSPaul Mundt /* 33444f5ecSPaul Mundt * PCI support for the Sega Dreamcast 43444f5ecSPaul Mundt * 53444f5ecSPaul Mundt * Copyright (C) 2001, 2002 M. R. Brown 63444f5ecSPaul Mundt * Copyright (C) 2002, 2003 Paul Mundt 73444f5ecSPaul Mundt * 83444f5ecSPaul Mundt * This file originally bore the message (with enclosed-$): 93444f5ecSPaul Mundt * Id: pci.c,v 1.3 2003/05/04 19:29:46 lethal Exp 103444f5ecSPaul Mundt * Dreamcast PCI: Supports SEGA Broadband Adaptor only. 113444f5ecSPaul Mundt */ 123444f5ecSPaul Mundt 133444f5ecSPaul Mundt #include <linux/sched.h> 143444f5ecSPaul Mundt #include <linux/kernel.h> 153444f5ecSPaul Mundt #include <linux/param.h> 163444f5ecSPaul Mundt #include <linux/interrupt.h> 173444f5ecSPaul Mundt #include <linux/init.h> 183444f5ecSPaul Mundt #include <linux/irq.h> 193444f5ecSPaul Mundt #include <linux/pci.h> 203444f5ecSPaul Mundt #include <linux/module.h> 213444f5ecSPaul Mundt #include <asm/io.h> 223444f5ecSPaul Mundt #include <asm/irq.h> 233444f5ecSPaul Mundt #include <mach/pci.h> 243444f5ecSPaul Mundt 25b6c58b1dSPaul Mundt static struct resource gapspci_resources[] = { 26b6c58b1dSPaul Mundt { 273444f5ecSPaul Mundt .name = "GAPSPCI IO", 283444f5ecSPaul Mundt .start = GAPSPCI_BBA_CONFIG, 293444f5ecSPaul Mundt .end = GAPSPCI_BBA_CONFIG + GAPSPCI_BBA_CONFIG_SIZE - 1, 303444f5ecSPaul Mundt .flags = IORESOURCE_IO, 31b6c58b1dSPaul Mundt }, { 323444f5ecSPaul Mundt .name = "GAPSPCI mem", 333444f5ecSPaul Mundt .start = GAPSPCI_DMA_BASE, 343444f5ecSPaul Mundt .end = GAPSPCI_DMA_BASE + GAPSPCI_DMA_SIZE - 1, 353444f5ecSPaul Mundt .flags = IORESOURCE_MEM, 36b6c58b1dSPaul Mundt }, 373444f5ecSPaul Mundt }; 383444f5ecSPaul Mundt 39951a681bSPaul Mundt static struct pci_channel dreamcast_pci_controller = { 40951a681bSPaul Mundt .pci_ops = &gapspci_pci_ops, 41b6c58b1dSPaul Mundt .resources = gapspci_resources, 42b6c58b1dSPaul Mundt .nr_resources = ARRAY_SIZE(gapspci_resources), 43951a681bSPaul Mundt .io_offset = 0x00000000, 44951a681bSPaul Mundt .mem_offset = 0x00000000, 45951a681bSPaul Mundt }; 46951a681bSPaul Mundt 473444f5ecSPaul Mundt /* 483444f5ecSPaul Mundt * gapspci init 493444f5ecSPaul Mundt */ 503444f5ecSPaul Mundt 51951a681bSPaul Mundt static int __init gapspci_init(void) 523444f5ecSPaul Mundt { 533444f5ecSPaul Mundt char idbuf[16]; 543444f5ecSPaul Mundt int i; 553444f5ecSPaul Mundt 563444f5ecSPaul Mundt /* 573444f5ecSPaul Mundt * FIXME: All of this wants documenting to some degree, 583444f5ecSPaul Mundt * even some basic register definitions would be nice. 593444f5ecSPaul Mundt * 603444f5ecSPaul Mundt * I haven't seen anything this ugly since.. maple. 613444f5ecSPaul Mundt */ 623444f5ecSPaul Mundt 633444f5ecSPaul Mundt for (i=0; i<16; i++) 643444f5ecSPaul Mundt idbuf[i] = inb(GAPSPCI_REGS+i); 653444f5ecSPaul Mundt 663444f5ecSPaul Mundt if (strncmp(idbuf, "GAPSPCI_BRIDGE_2", 16)) 673444f5ecSPaul Mundt return -ENODEV; 683444f5ecSPaul Mundt 693444f5ecSPaul Mundt outl(0x5a14a501, GAPSPCI_REGS+0x18); 703444f5ecSPaul Mundt 713444f5ecSPaul Mundt for (i=0; i<1000000; i++) 723444f5ecSPaul Mundt cpu_relax(); 733444f5ecSPaul Mundt 743444f5ecSPaul Mundt if (inl(GAPSPCI_REGS+0x18) != 1) 753444f5ecSPaul Mundt return -EINVAL; 763444f5ecSPaul Mundt 773444f5ecSPaul Mundt outl(0x01000000, GAPSPCI_REGS+0x20); 783444f5ecSPaul Mundt outl(0x01000000, GAPSPCI_REGS+0x24); 793444f5ecSPaul Mundt 803444f5ecSPaul Mundt outl(GAPSPCI_DMA_BASE, GAPSPCI_REGS+0x28); 813444f5ecSPaul Mundt outl(GAPSPCI_DMA_BASE+GAPSPCI_DMA_SIZE, GAPSPCI_REGS+0x2c); 823444f5ecSPaul Mundt 833444f5ecSPaul Mundt outl(1, GAPSPCI_REGS+0x14); 843444f5ecSPaul Mundt outl(1, GAPSPCI_REGS+0x34); 853444f5ecSPaul Mundt 863444f5ecSPaul Mundt /* Setting Broadband Adapter */ 873444f5ecSPaul Mundt outw(0xf900, GAPSPCI_BBA_CONFIG+0x06); 883444f5ecSPaul Mundt outl(0x00000000, GAPSPCI_BBA_CONFIG+0x30); 893444f5ecSPaul Mundt outb(0x00, GAPSPCI_BBA_CONFIG+0x3c); 903444f5ecSPaul Mundt outb(0xf0, GAPSPCI_BBA_CONFIG+0x0d); 913444f5ecSPaul Mundt outw(0x0006, GAPSPCI_BBA_CONFIG+0x04); 923444f5ecSPaul Mundt outl(0x00002001, GAPSPCI_BBA_CONFIG+0x10); 933444f5ecSPaul Mundt outl(0x01000000, GAPSPCI_BBA_CONFIG+0x14); 943444f5ecSPaul Mundt 95bcf39352SPaul Mundt return register_pci_controller(&dreamcast_pci_controller); 963444f5ecSPaul Mundt } 97951a681bSPaul Mundt arch_initcall(gapspci_init); 98