host_soc.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * Broadcom specific AMBA
  3. * System on Chip (SoC) Host
  4. *
  5. * Licensed under the GNU/GPL. See COPYING for details.
  6. */
  7. #include "bcma_private.h"
  8. #include "scan.h"
  9. #include <linux/bcma/bcma.h>
  10. #include <linux/bcma/bcma_soc.h>
  11. static u8 bcma_host_soc_read8(struct bcma_device *core, u16 offset)
  12. {
  13. return readb(core->io_addr + offset);
  14. }
  15. static u16 bcma_host_soc_read16(struct bcma_device *core, u16 offset)
  16. {
  17. return readw(core->io_addr + offset);
  18. }
  19. static u32 bcma_host_soc_read32(struct bcma_device *core, u16 offset)
  20. {
  21. return readl(core->io_addr + offset);
  22. }
  23. static void bcma_host_soc_write8(struct bcma_device *core, u16 offset,
  24. u8 value)
  25. {
  26. writeb(value, core->io_addr + offset);
  27. }
  28. static void bcma_host_soc_write16(struct bcma_device *core, u16 offset,
  29. u16 value)
  30. {
  31. writew(value, core->io_addr + offset);
  32. }
  33. static void bcma_host_soc_write32(struct bcma_device *core, u16 offset,
  34. u32 value)
  35. {
  36. writel(value, core->io_addr + offset);
  37. }
  38. #ifdef CONFIG_BCMA_BLOCKIO
  39. static void bcma_host_soc_block_read(struct bcma_device *core, void *buffer,
  40. size_t count, u16 offset, u8 reg_width)
  41. {
  42. void __iomem *addr = core->io_addr + offset;
  43. switch (reg_width) {
  44. case sizeof(u8): {
  45. u8 *buf = buffer;
  46. while (count) {
  47. *buf = __raw_readb(addr);
  48. buf++;
  49. count--;
  50. }
  51. break;
  52. }
  53. case sizeof(u16): {
  54. __le16 *buf = buffer;
  55. WARN_ON(count & 1);
  56. while (count) {
  57. *buf = (__force __le16)__raw_readw(addr);
  58. buf++;
  59. count -= 2;
  60. }
  61. break;
  62. }
  63. case sizeof(u32): {
  64. __le32 *buf = buffer;
  65. WARN_ON(count & 3);
  66. while (count) {
  67. *buf = (__force __le32)__raw_readl(addr);
  68. buf++;
  69. count -= 4;
  70. }
  71. break;
  72. }
  73. default:
  74. WARN_ON(1);
  75. }
  76. }
  77. static void bcma_host_soc_block_write(struct bcma_device *core,
  78. const void *buffer,
  79. size_t count, u16 offset, u8 reg_width)
  80. {
  81. void __iomem *addr = core->io_addr + offset;
  82. switch (reg_width) {
  83. case sizeof(u8): {
  84. const u8 *buf = buffer;
  85. while (count) {
  86. __raw_writeb(*buf, addr);
  87. buf++;
  88. count--;
  89. }
  90. break;
  91. }
  92. case sizeof(u16): {
  93. const __le16 *buf = buffer;
  94. WARN_ON(count & 1);
  95. while (count) {
  96. __raw_writew((__force u16)(*buf), addr);
  97. buf++;
  98. count -= 2;
  99. }
  100. break;
  101. }
  102. case sizeof(u32): {
  103. const __le32 *buf = buffer;
  104. WARN_ON(count & 3);
  105. while (count) {
  106. __raw_writel((__force u32)(*buf), addr);
  107. buf++;
  108. count -= 4;
  109. }
  110. break;
  111. }
  112. default:
  113. WARN_ON(1);
  114. }
  115. }
  116. #endif /* CONFIG_BCMA_BLOCKIO */
  117. static u32 bcma_host_soc_aread32(struct bcma_device *core, u16 offset)
  118. {
  119. return readl(core->io_wrap + offset);
  120. }
  121. static void bcma_host_soc_awrite32(struct bcma_device *core, u16 offset,
  122. u32 value)
  123. {
  124. writel(value, core->io_wrap + offset);
  125. }
  126. const struct bcma_host_ops bcma_host_soc_ops = {
  127. .read8 = bcma_host_soc_read8,
  128. .read16 = bcma_host_soc_read16,
  129. .read32 = bcma_host_soc_read32,
  130. .write8 = bcma_host_soc_write8,
  131. .write16 = bcma_host_soc_write16,
  132. .write32 = bcma_host_soc_write32,
  133. #ifdef CONFIG_BCMA_BLOCKIO
  134. .block_read = bcma_host_soc_block_read,
  135. .block_write = bcma_host_soc_block_write,
  136. #endif
  137. .aread32 = bcma_host_soc_aread32,
  138. .awrite32 = bcma_host_soc_awrite32,
  139. };
  140. int __init bcma_host_soc_register(struct bcma_soc *soc)
  141. {
  142. struct bcma_bus *bus = &soc->bus;
  143. int err;
  144. /* iomap only first core. We have to read some register on this core
  145. * to scan the bus.
  146. */
  147. bus->mmio = ioremap_nocache(BCMA_ADDR_BASE, BCMA_CORE_SIZE * 1);
  148. if (!bus->mmio)
  149. return -ENOMEM;
  150. /* Host specific */
  151. bus->hosttype = BCMA_HOSTTYPE_SOC;
  152. bus->ops = &bcma_host_soc_ops;
  153. /* Register */
  154. err = bcma_bus_early_register(bus, &soc->core_cc, &soc->core_mips);
  155. if (err)
  156. iounmap(bus->mmio);
  157. return err;
  158. }