ops-sh4.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. int __init sh4_pci_check_direct(struct pci_channel *chan)
  97. {
  98. /*
  99. * Check if configuration works.
  100. */
  101. unsigned int tmp = pci_read_reg(chan, SH4_PCIPAR);
  102. pci_write_reg(chan, P1SEG, SH4_PCIPAR);
  103. if (pci_read_reg(chan, SH4_PCIPAR) == P1SEG) {
  104. pci_write_reg(chan, tmp, SH4_PCIPAR);
  105. printk(KERN_INFO "PCI: Using configuration type 1\n");
  106. request_region(chan->reg_base + SH4_PCIPAR, 8,
  107. "PCI conf1");
  108. return 0;
  109. }
  110. pci_write_reg(chan, tmp, SH4_PCIPAR);
  111. printk(KERN_ERR "PCI: %s failed\n", __func__);
  112. return -EINVAL;
  113. }
  114. int __attribute__((weak)) pci_fixup_pcic(struct pci_channel *chan)
  115. {
  116. /* Nothing to do. */
  117. return 0;
  118. }