ops-gt96100.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. *
  3. * BRIEF MODULE DESCRIPTION
  4. * Galileo EV96100 board specific pci support.
  5. *
  6. * Copyright 2000 MontaVista Software Inc.
  7. * Author: MontaVista Software, Inc.
  8. * ppopov@mvista.com or source@mvista.com
  9. *
  10. * This file was derived from Carsten Langgaard's
  11. * arch/mips/mips-boards/generic/pci.c
  12. *
  13. * Carsten Langgaard, carstenl@mips.com
  14. * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
  15. *
  16. * This program is free software; you can redistribute it and/or modify it
  17. * under the terms of the GNU General Public License as published by the
  18. * Free Software Foundation; either version 2 of the License, or (at your
  19. * option) any later version.
  20. *
  21. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  22. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  23. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  24. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  26. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  27. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  28. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  30. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. * You should have received a copy of the GNU General Public License along
  33. * with this program; if not, write to the Free Software Foundation, Inc.,
  34. * 675 Mass Ave, Cambridge, MA 02139, USA.
  35. */
  36. #include <linux/types.h>
  37. #include <linux/pci.h>
  38. #include <linux/kernel.h>
  39. #include <linux/init.h>
  40. #include <asm/delay.h>
  41. #include <asm/gt64120.h>
  42. #include <asm/galileo-boards/ev96100.h>
  43. #define PCI_ACCESS_READ 0
  44. #define PCI_ACCESS_WRITE 1
  45. static int static gt96100_config_access(unsigned char access_type,
  46. struct pci_bus *bus, unsigned int devfn, int where, u32 * data)
  47. {
  48. unsigned char bus = bus->number;
  49. u32 intr;
  50. /*
  51. * Because of a bug in the galileo (for slot 31).
  52. */
  53. if (bus == 0 && devfn >= PCI_DEVFN(31, 0))
  54. return PCIBIOS_DEVICE_NOT_FOUND;
  55. /* Clear cause register bits */
  56. GT_WRITE(GT_INTRCAUSE_OFS, ~(GT_INTRCAUSE_MASABORT0_BIT |
  57. GT_INTRCAUSE_TARABORT0_BIT));
  58. /* Setup address */
  59. GT_WRITE(GT_PCI0_CFGADDR_OFS,
  60. (bus << GT_PCI0_CFGADDR_BUSNUM_SHF) |
  61. (devfn << GT_PCI0_CFGADDR_FUNCTNUM_SHF) |
  62. ((where / 4) << GT_PCI0_CFGADDR_REGNUM_SHF) |
  63. GT_PCI0_CFGADDR_CONFIGEN_BIT);
  64. udelay(2);
  65. if (access_type == PCI_ACCESS_WRITE) {
  66. if (devfn != 0)
  67. *data = le32_to_cpu(*data);
  68. GT_WRITE(GT_PCI0_CFGDATA_OFS, *data);
  69. } else {
  70. *data = GT_READ(GT_PCI0_CFGDATA_OFS);
  71. if (devfn != 0)
  72. *data = le32_to_cpu(*data);
  73. }
  74. udelay(2);
  75. /* Check for master or target abort */
  76. intr = GT_READ(GT_INTRCAUSE_OFS);
  77. if (intr & (GT_INTRCAUSE_MASABORT0_BIT | GT_INTRCAUSE_TARABORT0_BIT)) {
  78. /* Error occured */
  79. /* Clear bits */
  80. GT_WRITE(GT_INTRCAUSE_OFS, ~(GT_INTRCAUSE_MASABORT0_BIT |
  81. GT_INTRCAUSE_TARABORT0_BIT));
  82. return -1;
  83. }
  84. return 0;
  85. }
  86. /*
  87. * We can't address 8 and 16 bit words directly. Instead we have to
  88. * read/write a 32bit word and mask/modify the data we actually want.
  89. */
  90. static int gt96100_pcibios_read(struct pci_bus *bus, unsigned int devfn,
  91. int where, int size, u32 * val)
  92. {
  93. u32 data = 0;
  94. if (gt96100_config_access(PCI_ACCESS_READ, bus, devfn, where, &data))
  95. return PCIBIOS_DEVICE_NOT_FOUND;
  96. switch (size) {
  97. case 1:
  98. *val = (data >> ((where & 3) << 3)) & 0xff;
  99. break;
  100. case 2:
  101. *val = (data >> ((where & 3) << 3)) & 0xffff;
  102. break;
  103. case 4:
  104. *val = data;
  105. break;
  106. }
  107. return PCIBIOS_SUCCESSFUL;
  108. }
  109. static int gt96100_pcibios_write(struct pci_bus *bus, unsigned int devfn,
  110. int where, int size, u32 val)
  111. {
  112. u32 data = 0;
  113. switch (size) {
  114. case 1:
  115. if (gt96100_config_access(PCI_ACCESS_READ, bus, devfn, where, &data))
  116. return -1;
  117. data = (data & ~(0xff << ((where & 3) << 3))) |
  118. (val << ((where & 3) << 3));
  119. if (gt96100_config_access(PCI_ACCESS_WRITE, bus, devfn, where, &data))
  120. return -1;
  121. return PCIBIOS_SUCCESSFUL;
  122. case 2:
  123. if (gt96100_config_access(PCI_ACCESS_READ, bus, devfn, where, &data))
  124. return -1;
  125. data = (data & ~(0xffff << ((where & 3) << 3))) |
  126. (val << ((where & 3) << 3));
  127. if (gt96100_config_access(PCI_ACCESS_WRITE, dev, where, &data))
  128. return -1;
  129. return PCIBIOS_SUCCESSFUL;
  130. case 4:
  131. if (gt96100_config_access(PCI_ACCESS_WRITE, dev, where, &val))
  132. return -1;
  133. return PCIBIOS_SUCCESSFUL;
  134. }
  135. }
  136. struct pci_ops gt96100_pci_ops = {
  137. .read = gt96100_pcibios_read,
  138. .write = gt96100_pcibios_write
  139. };