ops-gt64111.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1995, 1996, 1997, 2002 by Ralf Baechle
  7. * Copyright (C) 2001, 2002, 2003 by Liam Davies (ldavies@agile.tv)
  8. */
  9. #include <linux/types.h>
  10. #include <linux/pci.h>
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <asm/pci.h>
  14. #include <asm/io.h>
  15. #include <asm/gt64120.h>
  16. #include <asm/cobalt/cobalt.h>
  17. /*
  18. * Accessing device 31 hangs the GT64120. Not sure if this will also hang
  19. * the GT64111, let's be paranoid for now.
  20. */
  21. static inline int pci_range_ck(struct pci_bus *bus, unsigned int devfn)
  22. {
  23. if (bus->number == 0 && devfn == PCI_DEVFN(31, 0))
  24. return -1;
  25. return 0;
  26. }
  27. static int gt64111_pci_read_config(struct pci_bus *bus, unsigned int devfn,
  28. int where, int size, u32 * val)
  29. {
  30. if (pci_range_ck(bus, devfn))
  31. return PCIBIOS_DEVICE_NOT_FOUND;
  32. switch (size) {
  33. case 4:
  34. PCI_CFG_SET(devfn, where);
  35. *val = GALILEO_INL(GT_PCI0_CFGDATA_OFS);
  36. return PCIBIOS_SUCCESSFUL;
  37. case 2:
  38. PCI_CFG_SET(devfn, (where & ~0x3));
  39. *val = GALILEO_INL(GT_PCI0_CFGDATA_OFS)
  40. >> ((where & 3) * 8);
  41. return PCIBIOS_SUCCESSFUL;
  42. case 1:
  43. PCI_CFG_SET(devfn, (where & ~0x3));
  44. *val = GALILEO_INL(GT_PCI0_CFGDATA_OFS)
  45. >> ((where & 3) * 8);
  46. return PCIBIOS_SUCCESSFUL;
  47. }
  48. return PCIBIOS_BAD_REGISTER_NUMBER;
  49. }
  50. static int gt64111_pci_write_config(struct pci_bus *bus, unsigned int devfn,
  51. int where, int size, u32 val)
  52. {
  53. u32 tmp;
  54. if (pci_range_ck(bus, devfn))
  55. return PCIBIOS_DEVICE_NOT_FOUND;
  56. switch (size) {
  57. case 4:
  58. PCI_CFG_SET(devfn, where);
  59. GALILEO_OUTL(val, GT_PCI0_CFGDATA_OFS);
  60. return PCIBIOS_SUCCESSFUL;
  61. case 2:
  62. PCI_CFG_SET(devfn, (where & ~0x3));
  63. tmp = GALILEO_INL(GT_PCI0_CFGDATA_OFS);
  64. tmp &= ~(0xffff << ((where & 0x3) * 8));
  65. tmp |= (val << ((where & 0x3) * 8));
  66. GALILEO_OUTL(tmp, GT_PCI0_CFGDATA_OFS);
  67. return PCIBIOS_SUCCESSFUL;
  68. case 1:
  69. PCI_CFG_SET(devfn, (where & ~0x3));
  70. tmp = GALILEO_INL(GT_PCI0_CFGDATA_OFS);
  71. tmp &= ~(0xff << ((where & 0x3) * 8));
  72. tmp |= (val << ((where & 0x3) * 8));
  73. GALILEO_OUTL(tmp, GT_PCI0_CFGDATA_OFS);
  74. return PCIBIOS_SUCCESSFUL;
  75. }
  76. return PCIBIOS_BAD_REGISTER_NUMBER;
  77. }
  78. struct pci_ops gt64111_pci_ops = {
  79. .read = gt64111_pci_read_config,
  80. .write = gt64111_pci_write_config,
  81. };