ops-sh4.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Generic SH-4 / SH-4A PCIC operations (SH7751, SH7780).
  3. *
  4. * Copyright (C) 2002 - 2006 Paul Mundt
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License v2. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. */
  10. #include <linux/pci.h>
  11. #include <asm/addrspace.h>
  12. #include <asm/io.h>
  13. #include "pci-sh4.h"
  14. /*
  15. * Direct access to PCI hardware...
  16. */
  17. #define CONFIG_CMD(bus, devfn, where) \
  18. P1SEGADDR((bus->number << 16) | (devfn << 8) | (where & ~3))
  19. static DEFINE_SPINLOCK(sh4_pci_lock);
  20. /*
  21. * Functions for accessing PCI configuration space with type 1 accesses
  22. */
  23. static int sh4_pci_read(struct pci_bus *bus, unsigned int devfn,
  24. int where, int size, u32 *val)
  25. {
  26. unsigned long flags;
  27. u32 data;
  28. /*
  29. * PCIPDR may only be accessed as 32 bit words,
  30. * so we must do byte alignment by hand
  31. */
  32. spin_lock_irqsave(&sh4_pci_lock, flags);
  33. pci_write_reg(CONFIG_CMD(bus, devfn, where), SH4_PCIPAR);
  34. data = pci_read_reg(SH4_PCIPDR);
  35. spin_unlock_irqrestore(&sh4_pci_lock, flags);
  36. switch (size) {
  37. case 1:
  38. *val = (data >> ((where & 3) << 3)) & 0xff;
  39. break;
  40. case 2:
  41. *val = (data >> ((where & 2) << 3)) & 0xffff;
  42. break;
  43. case 4:
  44. *val = data;
  45. break;
  46. default:
  47. return PCIBIOS_FUNC_NOT_SUPPORTED;
  48. }
  49. return PCIBIOS_SUCCESSFUL;
  50. }
  51. /*
  52. * Since SH4 only does 32bit access we'll have to do a read,
  53. * mask,write operation.
  54. * We'll allow an odd byte offset, though it should be illegal.
  55. */
  56. static int sh4_pci_write(struct pci_bus *bus, unsigned int devfn,
  57. int where, int size, u32 val)
  58. {
  59. unsigned long flags;
  60. int shift;
  61. u32 data;
  62. spin_lock_irqsave(&sh4_pci_lock, flags);
  63. pci_write_reg(CONFIG_CMD(bus, devfn, where), SH4_PCIPAR);
  64. data = pci_read_reg(SH4_PCIPDR);
  65. spin_unlock_irqrestore(&sh4_pci_lock, flags);
  66. switch (size) {
  67. case 1:
  68. shift = (where & 3) << 3;
  69. data &= ~(0xff << shift);
  70. data |= ((val & 0xff) << shift);
  71. break;
  72. case 2:
  73. shift = (where & 2) << 3;
  74. data &= ~(0xffff << shift);
  75. data |= ((val & 0xffff) << shift);
  76. break;
  77. case 4:
  78. data = val;
  79. break;
  80. default:
  81. return PCIBIOS_FUNC_NOT_SUPPORTED;
  82. }
  83. pci_write_reg(data, SH4_PCIPDR);
  84. return PCIBIOS_SUCCESSFUL;
  85. }
  86. struct pci_ops sh4_pci_ops = {
  87. .read = sh4_pci_read,
  88. .write = sh4_pci_write,
  89. };
  90. /*
  91. * Not really related to pci_ops, but it's common and not worth shoving
  92. * somewhere else for now..
  93. */
  94. static unsigned int pci_probe = PCI_PROBE_CONF1;
  95. int __init sh4_pci_check_direct(void)
  96. {
  97. /*
  98. * Check if configuration works.
  99. */
  100. if (pci_probe & PCI_PROBE_CONF1) {
  101. unsigned int tmp = pci_read_reg(SH4_PCIPAR);
  102. pci_write_reg(P1SEG, SH4_PCIPAR);
  103. if (pci_read_reg(SH4_PCIPAR) == P1SEG) {
  104. pci_write_reg(tmp, SH4_PCIPAR);
  105. printk(KERN_INFO "PCI: Using configuration type 1\n");
  106. request_region(PCI_REG(SH4_PCIPAR), 8, "PCI conf1");
  107. return 0;
  108. }
  109. pci_write_reg(tmp, SH4_PCIPAR);
  110. }
  111. pr_debug("PCI: pci_check_direct failed\n");
  112. return -EINVAL;
  113. }
  114. /* Handle generic fixups */
  115. static void __init pci_fixup_ide_bases(struct pci_dev *d)
  116. {
  117. int i;
  118. /*
  119. * PCI IDE controllers use non-standard I/O port decoding, respect it.
  120. */
  121. if ((d->class >> 8) != PCI_CLASS_STORAGE_IDE)
  122. return;
  123. pr_debug("PCI: IDE base address fixup for %s\n", pci_name(d));
  124. for(i = 0; i < 4; i++) {
  125. struct resource *r = &d->resource[i];
  126. if ((r->start & ~0x80) == 0x374) {
  127. r->start |= 2;
  128. r->end = r->start;
  129. }
  130. }
  131. }
  132. DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, pci_fixup_ide_bases);
  133. char * __init pcibios_setup(char *str)
  134. {
  135. if (!strcmp(str, "off")) {
  136. pci_probe = 0;
  137. return NULL;
  138. }
  139. return str;
  140. }