pci-ocelot.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * BRIEF MODULE DESCRIPTION
  3. * Galileo Evaluation Boards PCI support.
  4. *
  5. * The general-purpose functions to read/write and configure the GT64120A's
  6. * PCI registers (function names start with pci0 or pci1) are either direct
  7. * copies of functions written by Galileo Technology, or are modifications
  8. * of their functions to work with Linux 2.4 vs Linux 2.2. These functions
  9. * are Copyright - Galileo Technology.
  10. *
  11. * Other functions are derived from other MIPS PCI implementations, or were
  12. * written by RidgeRun, Inc, Copyright (C) 2000 RidgeRun, Inc.
  13. * glonnon@ridgerun.com, skranz@ridgerun.com, stevej@ridgerun.com
  14. *
  15. * Copyright 2001 MontaVista Software Inc.
  16. * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
  17. *
  18. * This program is free software; you can redistribute it and/or modify it
  19. * under the terms of the GNU General Public License as published by the
  20. * Free Software Foundation; either version 2 of the License, or (at your
  21. * option) any later version.
  22. *
  23. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  24. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  25. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  26. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  27. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  28. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  29. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  32. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. * You should have received a copy of the GNU General Public License along
  35. * with this program; if not, write to the Free Software Foundation, Inc.,
  36. * 675 Mass Ave, Cambridge, MA 02139, USA.
  37. */
  38. #include <linux/init.h>
  39. #include <linux/types.h>
  40. #include <linux/pci.h>
  41. #include <linux/kernel.h>
  42. #include <linux/slab.h>
  43. #include <linux/cache.h>
  44. #include <asm/pci.h>
  45. #include <asm/io.h>
  46. #include <asm/gt64120.h>
  47. static inline unsigned int pci0ReadConfigReg(unsigned int offset)
  48. {
  49. unsigned int DataForRegCf8;
  50. unsigned int data;
  51. DataForRegCf8 = ((PCI_SLOT(device->devfn) << 11) |
  52. (PCI_FUNC(device->devfn) << 8) |
  53. (offset & ~0x3)) | 0x80000000;
  54. GT_WRITE(GT_PCI0_CFGADDR_OFS, DataForRegCf8);
  55. GT_READ(GT_PCI0_CFGDATA_OFS, &data);
  56. return data;
  57. }
  58. static inline void pci0WriteConfigReg(unsigned int offset, unsigned int data)
  59. {
  60. unsigned int DataForRegCf8;
  61. DataForRegCf8 = ((PCI_SLOT(device->devfn) << 11) |
  62. (PCI_FUNC(device->devfn) << 8) |
  63. (offset & ~0x3)) | 0x80000000;
  64. GT_WRITE(GT_PCI0_CFGADDR_OFS, DataForRegCf8);
  65. GT_WRITE(GT_PCI0_CFGDATA_OFS, data);
  66. }
  67. static struct resource ocelot_mem_resource = {
  68. iomem_resource.start = GT_PCI_MEM_BASE;
  69. iomem_resource.end = GT_PCI_MEM_BASE + GT_PCI_MEM_BASE - 1;
  70. };
  71. static struct resource ocelot_io_resource = {
  72. ioport_resource.start = GT_PCI_IO_BASE;
  73. ioport_resource.end = GT_PCI_IO_BASE + GT_PCI_IO_SIZE - 1;
  74. };
  75. static struct pci_controller ocelot_pci_controller = {
  76. .pci_ops = gt64120_pci_ops;
  77. .mem_resource = &ocelot_mem_resource;
  78. .io_resource = &ocelot_io_resource;
  79. };
  80. static int __init ocelot_pcibios_init(void)
  81. {
  82. u32 tmp;
  83. GT_READ(GT_PCI0_CMD_OFS, &tmp);
  84. GT_READ(GT_PCI0_BARE_OFS, &tmp);
  85. /*
  86. * You have to enable bus mastering to configure any other
  87. * card on the bus.
  88. */
  89. tmp = pci0ReadConfigReg(PCI_COMMAND);
  90. tmp |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | PCI_COMMAND_SERR;
  91. pci0WriteConfigReg(PCI_COMMAND, tmp);
  92. register_pci_controller(&ocelot_pci_controller);
  93. }
  94. arch_initcall(ocelot_pcibios_init);