ops-sh4.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 <linux/spinlock.h>
  13. #include <asm/addrspace.h>
  14. #include "pci-sh4.h"
  15. /*
  16. * Direct access to PCI hardware...
  17. */
  18. #define CONFIG_CMD(bus, devfn, where) \
  19. (0x80000000 | (bus->number << 16) | (devfn << 8) | (where & ~3))
  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. raw_spin_lock_irqsave(&pci_config_lock, flags);
  34. pci_write_reg(chan, CONFIG_CMD(bus, devfn, where), SH4_PCIPAR);
  35. data = pci_read_reg(chan, SH4_PCIPDR);
  36. raw_spin_unlock_irqrestore(&pci_config_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. raw_spin_lock_irqsave(&pci_config_lock, flags);
  65. pci_write_reg(chan, CONFIG_CMD(bus, devfn, where), SH4_PCIPAR);
  66. data = pci_read_reg(chan, SH4_PCIPDR);
  67. raw_spin_unlock_irqrestore(&pci_config_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. int __attribute__((weak)) pci_fixup_pcic(struct pci_channel *chan)
  93. {
  94. /* Nothing to do. */
  95. return 0;
  96. }