ops-dreamcast.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * arch/sh/drivers/pci/ops-dreamcast.c
  3. *
  4. * PCI operations for the Sega Dreamcast
  5. *
  6. * Copyright (C) 2001, 2002 M. R. Brown
  7. * Copyright (C) 2002, 2003 Paul Mundt
  8. *
  9. * This file originally bore the message (with enclosed-$):
  10. * Id: pci.c,v 1.3 2003/05/04 19:29:46 lethal Exp
  11. * Dreamcast PCI: Supports SEGA Broadband Adaptor only.
  12. *
  13. * This file is subject to the terms and conditions of the GNU General Public
  14. * License. See the file "COPYING" in the main directory of this archive
  15. * for more details.
  16. */
  17. #include <linux/sched.h>
  18. #include <linux/kernel.h>
  19. #include <linux/param.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/init.h>
  22. #include <linux/irq.h>
  23. #include <linux/pci.h>
  24. #include <linux/module.h>
  25. #include <asm/io.h>
  26. #include <asm/irq.h>
  27. #include <mach/pci.h>
  28. static struct resource gapspci_io_resource = {
  29. .name = "GAPSPCI IO",
  30. .start = GAPSPCI_BBA_CONFIG,
  31. .end = GAPSPCI_BBA_CONFIG + GAPSPCI_BBA_CONFIG_SIZE - 1,
  32. .flags = IORESOURCE_IO,
  33. };
  34. static struct resource gapspci_mem_resource = {
  35. .name = "GAPSPCI mem",
  36. .start = GAPSPCI_DMA_BASE,
  37. .end = GAPSPCI_DMA_BASE + GAPSPCI_DMA_SIZE - 1,
  38. .flags = IORESOURCE_MEM,
  39. };
  40. static struct pci_ops gapspci_pci_ops;
  41. struct pci_channel board_pci_channels[] = {
  42. { &gapspci_pci_ops, &gapspci_io_resource,
  43. &gapspci_mem_resource, 0, 1 },
  44. { 0, }
  45. };
  46. EXPORT_SYMBOL(board_pci_channels);
  47. /*
  48. * The !gapspci_config_access case really shouldn't happen, ever, unless
  49. * someone implicitly messes around with the last devfn value.. otherwise we
  50. * only support a single device anyways, and if we didn't have a BBA, we
  51. * wouldn't make it terribly far through the PCI setup anyways.
  52. *
  53. * Also, we could very easily support both Type 0 and Type 1 configurations
  54. * here, but since it doesn't seem that there is any such implementation in
  55. * existence, we don't bother.
  56. *
  57. * I suppose if someone actually gets around to ripping the chip out of
  58. * the BBA and hanging some more devices off of it, then this might be
  59. * something to take into consideration. However, due to the cost of the BBA,
  60. * and the general lack of activity by DC hardware hackers, this doesn't seem
  61. * likely to happen anytime soon.
  62. */
  63. static int gapspci_config_access(unsigned char bus, unsigned int devfn)
  64. {
  65. return (bus == 0) && (devfn == 0);
  66. }
  67. /*
  68. * We can also actually read and write in b/w/l sizes! Thankfully this part
  69. * was at least done right, and we don't have to do the stupid masking and
  70. * shifting that we do on the 7751! Small wonders never cease to amaze.
  71. */
  72. static int gapspci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *val)
  73. {
  74. *val = 0xffffffff;
  75. if (!gapspci_config_access(bus->number, devfn))
  76. return PCIBIOS_DEVICE_NOT_FOUND;
  77. switch (size) {
  78. case 1: *val = inb(GAPSPCI_BBA_CONFIG+where); break;
  79. case 2: *val = inw(GAPSPCI_BBA_CONFIG+where); break;
  80. case 4: *val = inl(GAPSPCI_BBA_CONFIG+where); break;
  81. }
  82. return PCIBIOS_SUCCESSFUL;
  83. }
  84. static int gapspci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 val)
  85. {
  86. if (!gapspci_config_access(bus->number, devfn))
  87. return PCIBIOS_DEVICE_NOT_FOUND;
  88. switch (size) {
  89. case 1: outb(( u8)val, GAPSPCI_BBA_CONFIG+where); break;
  90. case 2: outw((u16)val, GAPSPCI_BBA_CONFIG+where); break;
  91. case 4: outl((u32)val, GAPSPCI_BBA_CONFIG+where); break;
  92. }
  93. return PCIBIOS_SUCCESSFUL;
  94. }
  95. static struct pci_ops gapspci_pci_ops = {
  96. .read = gapspci_read,
  97. .write = gapspci_write,
  98. };
  99. /*
  100. * gapspci init
  101. */
  102. int __init gapspci_init(void)
  103. {
  104. char idbuf[16];
  105. int i;
  106. /*
  107. * FIXME: All of this wants documenting to some degree,
  108. * even some basic register definitions would be nice.
  109. *
  110. * I haven't seen anything this ugly since.. maple.
  111. */
  112. for (i=0; i<16; i++)
  113. idbuf[i] = inb(GAPSPCI_REGS+i);
  114. if (strncmp(idbuf, "GAPSPCI_BRIDGE_2", 16))
  115. return -ENODEV;
  116. outl(0x5a14a501, GAPSPCI_REGS+0x18);
  117. for (i=0; i<1000000; i++)
  118. ;
  119. if (inl(GAPSPCI_REGS+0x18) != 1)
  120. return -EINVAL;
  121. outl(0x01000000, GAPSPCI_REGS+0x20);
  122. outl(0x01000000, GAPSPCI_REGS+0x24);
  123. outl(GAPSPCI_DMA_BASE, GAPSPCI_REGS+0x28);
  124. outl(GAPSPCI_DMA_BASE+GAPSPCI_DMA_SIZE, GAPSPCI_REGS+0x2c);
  125. outl(1, GAPSPCI_REGS+0x14);
  126. outl(1, GAPSPCI_REGS+0x34);
  127. /* Setting Broadband Adapter */
  128. outw(0xf900, GAPSPCI_BBA_CONFIG+0x06);
  129. outl(0x00000000, GAPSPCI_BBA_CONFIG+0x30);
  130. outb(0x00, GAPSPCI_BBA_CONFIG+0x3c);
  131. outb(0xf0, GAPSPCI_BBA_CONFIG+0x0d);
  132. outw(0x0006, GAPSPCI_BBA_CONFIG+0x04);
  133. outl(0x00002001, GAPSPCI_BBA_CONFIG+0x10);
  134. outl(0x01000000, GAPSPCI_BBA_CONFIG+0x14);
  135. return 0;
  136. }
  137. /* Haven't done anything here as yet */
  138. char * __devinit pcibios_setup(char *str)
  139. {
  140. return str;
  141. }