ops-sh4.c 3.8 KB

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