ops-sh4.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Generic SH-4 / SH-4A PCIC operations (SH7751, SH7780).
  4. *
  5. * Copyright (C) 2002 - 2009 Paul Mundt
  6. */
  7. #include <linux/pci.h>
  8. #include <linux/io.h>
  9. #include <linux/spinlock.h>
  10. #include <asm/addrspace.h>
  11. #include "pci-sh4.h"
  12. /*
  13. * Direct access to PCI hardware...
  14. */
  15. #define CONFIG_CMD(bus, devfn, where) \
  16. (0x80000000 | (bus->number << 16) | (devfn << 8) | (where & ~3))
  17. /*
  18. * Functions for accessing PCI configuration space with type 1 accesses
  19. */
  20. static int sh4_pci_read(struct pci_bus *bus, unsigned int devfn,
  21. int where, int size, u32 *val)
  22. {
  23. struct pci_channel *chan = bus->sysdata;
  24. unsigned long flags;
  25. u32 data;
  26. /*
  27. * PCIPDR may only be accessed as 32 bit words,
  28. * so we must do byte alignment by hand
  29. */
  30. raw_spin_lock_irqsave(&pci_config_lock, flags);
  31. pci_write_reg(chan, CONFIG_CMD(bus, devfn, where), SH4_PCIPAR);
  32. data = pci_read_reg(chan, SH4_PCIPDR);
  33. raw_spin_unlock_irqrestore(&pci_config_lock, flags);
  34. switch (size) {
  35. case 1:
  36. *val = (data >> ((where & 3) << 3)) & 0xff;
  37. break;
  38. case 2:
  39. *val = (data >> ((where & 2) << 3)) & 0xffff;
  40. break;
  41. case 4:
  42. *val = data;
  43. break;
  44. default:
  45. return PCIBIOS_FUNC_NOT_SUPPORTED;
  46. }
  47. return PCIBIOS_SUCCESSFUL;
  48. }
  49. /*
  50. * Since SH4 only does 32bit access we'll have to do a read,
  51. * mask,write operation.
  52. * We'll allow an odd byte offset, though it should be illegal.
  53. */
  54. static int sh4_pci_write(struct pci_bus *bus, unsigned int devfn,
  55. int where, int size, u32 val)
  56. {
  57. struct pci_channel *chan = bus->sysdata;
  58. unsigned long flags;
  59. int shift;
  60. u32 data;
  61. raw_spin_lock_irqsave(&pci_config_lock, flags);
  62. pci_write_reg(chan, CONFIG_CMD(bus, devfn, where), SH4_PCIPAR);
  63. data = pci_read_reg(chan, SH4_PCIPDR);
  64. raw_spin_unlock_irqrestore(&pci_config_lock, flags);
  65. switch (size) {
  66. case 1:
  67. shift = (where & 3) << 3;
  68. data &= ~(0xff << shift);
  69. data |= ((val & 0xff) << shift);
  70. break;
  71. case 2:
  72. shift = (where & 2) << 3;
  73. data &= ~(0xffff << shift);
  74. data |= ((val & 0xffff) << shift);
  75. break;
  76. case 4:
  77. data = val;
  78. break;
  79. default:
  80. return PCIBIOS_FUNC_NOT_SUPPORTED;
  81. }
  82. pci_write_reg(chan, data, SH4_PCIPDR);
  83. return PCIBIOS_SUCCESSFUL;
  84. }
  85. struct pci_ops sh4_pci_ops = {
  86. .read = sh4_pci_read,
  87. .write = sh4_pci_write,
  88. };
  89. int __attribute__((weak)) pci_fixup_pcic(struct pci_channel *chan)
  90. {
  91. /* Nothing to do. */
  92. return 0;
  93. }