pci-dreamcast.c 2.3 KB

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