ops-tx3927.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright 2001 MontaVista Software Inc.
  3. * Author: MontaVista Software, Inc.
  4. * ahennessy@mvista.com
  5. *
  6. * Copyright (C) 2000-2001 Toshiba Corporation
  7. * Copyright (C) 2004 by Ralf Baechle (ralf@linux-mips.org)
  8. *
  9. * Based on arch/mips/ddb5xxx/ddb5477/pci_ops.c
  10. *
  11. * Define the pci_ops for JMR3927.
  12. *
  13. * Much of the code is derived from the original DDB5074 port by
  14. * Geert Uytterhoeven <geert@sonycom.com>
  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/addrspace.h>
  41. #include <asm/jmr3927/jmr3927.h>
  42. static inline int mkaddr(unsigned char bus, unsigned char dev_fn,
  43. unsigned char where)
  44. {
  45. if (bus == 0 && dev_fn >= PCI_DEVFN(TX3927_PCIC_MAX_DEVNU, 0))
  46. return PCIBIOS_DEVICE_NOT_FOUND;
  47. tx3927_pcicptr->ica = ((bus & 0xff) << 0x10) |
  48. ((dev_fn & 0xff) << 0x08) |
  49. (where & 0xfc);
  50. /* clear M_ABORT and Disable M_ABORT Int. */
  51. tx3927_pcicptr->pcistat |= PCI_STATUS_REC_MASTER_ABORT;
  52. tx3927_pcicptr->pcistatim &= ~PCI_STATUS_REC_MASTER_ABORT;
  53. return PCIBIOS_SUCCESSFUL;
  54. }
  55. static inline int check_abort(void)
  56. {
  57. if (tx3927_pcicptr->pcistat & PCI_STATUS_REC_MASTER_ABORT)
  58. tx3927_pcicptr->pcistat |= PCI_STATUS_REC_MASTER_ABORT;
  59. tx3927_pcicptr->pcistatim |= PCI_STATUS_REC_MASTER_ABORT;
  60. return PCIBIOS_DEVICE_NOT_FOUND;
  61. return PCIBIOS_SUCCESSFUL;
  62. }
  63. static int jmr3927_pci_read_config(struct pci_bus *bus, unsigned int devfn,
  64. int where, int size, u32 * val)
  65. {
  66. int ret;
  67. ret = mkaddr(bus->number, devfn, where);
  68. if (ret)
  69. return ret;
  70. switch (size) {
  71. case 1:
  72. *val = *(volatile u8 *) ((unsigned long) & tx3927_pcicptr->icd | (where & 3));
  73. break;
  74. case 2:
  75. *val = le16_to_cpu(*(volatile u16 *) ((unsigned long) & tx3927_pcicptr->icd | (where & 3)));
  76. break;
  77. case 4:
  78. *val = le32_to_cpu(tx3927_pcicptr->icd);
  79. break;
  80. }
  81. return check_abort();
  82. }
  83. static int jmr3927_pci_write_config(struct pci_bus *bus, unsigned int devfn,
  84. int where, int size, u32 val)
  85. {
  86. int ret;
  87. ret = mkaddr(bus->number, devfn, where);
  88. if (ret)
  89. return ret;
  90. switch (size) {
  91. case 1:
  92. *(volatile u8 *) ((unsigned long) & tx3927_pcicptr->icd | (where & 3)) = val;
  93. break;
  94. case 2:
  95. *(volatile u16 *) ((unsigned long) & tx3927_pcicptr->icd | (where & 2)) =
  96. cpu_to_le16(val);
  97. break;
  98. case 4:
  99. tx3927_pcicptr->icd = cpu_to_le32(val);
  100. }
  101. if (tx3927_pcicptr->pcistat & PCI_STATUS_REC_MASTER_ABORT)
  102. tx3927_pcicptr->pcistat |= PCI_STATUS_REC_MASTER_ABORT;
  103. tx3927_pcicptr->pcistatim |= PCI_STATUS_REC_MASTER_ABORT;
  104. return PCIBIOS_DEVICE_NOT_FOUND;
  105. return check_abort();
  106. }
  107. struct pci_ops jmr3927_pci_ops = {
  108. jmr3927_pci_read_config,
  109. jmr3927_pci_write_config,
  110. };