io.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * This file is part of wl12xx
  3. *
  4. * Copyright (C) 2008 Nokia Corporation
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  18. * 02110-1301 USA
  19. *
  20. */
  21. #include "wl1251.h"
  22. #include "reg.h"
  23. #include "io.h"
  24. /* FIXME: this is static data nowadays and the table can be removed */
  25. static enum wl12xx_acx_int_reg wl1251_io_reg_table[ACX_REG_TABLE_LEN] = {
  26. [ACX_REG_INTERRUPT_TRIG] = (REGISTERS_BASE + 0x0474),
  27. [ACX_REG_INTERRUPT_TRIG_H] = (REGISTERS_BASE + 0x0478),
  28. [ACX_REG_INTERRUPT_MASK] = (REGISTERS_BASE + 0x0494),
  29. [ACX_REG_HINT_MASK_SET] = (REGISTERS_BASE + 0x0498),
  30. [ACX_REG_HINT_MASK_CLR] = (REGISTERS_BASE + 0x049C),
  31. [ACX_REG_INTERRUPT_NO_CLEAR] = (REGISTERS_BASE + 0x04B0),
  32. [ACX_REG_INTERRUPT_CLEAR] = (REGISTERS_BASE + 0x04A4),
  33. [ACX_REG_INTERRUPT_ACK] = (REGISTERS_BASE + 0x04A8),
  34. [ACX_REG_SLV_SOFT_RESET] = (REGISTERS_BASE + 0x0000),
  35. [ACX_REG_EE_START] = (REGISTERS_BASE + 0x080C),
  36. [ACX_REG_ECPU_CONTROL] = (REGISTERS_BASE + 0x0804)
  37. };
  38. static int wl1251_translate_reg_addr(struct wl1251 *wl, int addr)
  39. {
  40. /* If the address is lower than REGISTERS_BASE, it means that this is
  41. * a chip-specific register address, so look it up in the registers
  42. * table */
  43. if (addr < REGISTERS_BASE) {
  44. /* Make sure we don't go over the table */
  45. if (addr >= ACX_REG_TABLE_LEN) {
  46. wl1251_error("address out of range (%d)", addr);
  47. return -EINVAL;
  48. }
  49. addr = wl1251_io_reg_table[addr];
  50. }
  51. return addr - wl->physical_reg_addr + wl->virtual_reg_addr;
  52. }
  53. static int wl1251_translate_mem_addr(struct wl1251 *wl, int addr)
  54. {
  55. return addr - wl->physical_mem_addr + wl->virtual_mem_addr;
  56. }
  57. void wl1251_mem_read(struct wl1251 *wl, int addr, void *buf, size_t len)
  58. {
  59. int physical;
  60. physical = wl1251_translate_mem_addr(wl, addr);
  61. wl->if_ops->read(wl, physical, buf, len);
  62. }
  63. void wl1251_mem_write(struct wl1251 *wl, int addr, void *buf, size_t len)
  64. {
  65. int physical;
  66. physical = wl1251_translate_mem_addr(wl, addr);
  67. wl->if_ops->write(wl, physical, buf, len);
  68. }
  69. u32 wl1251_mem_read32(struct wl1251 *wl, int addr)
  70. {
  71. return wl1251_read32(wl, wl1251_translate_mem_addr(wl, addr));
  72. }
  73. void wl1251_mem_write32(struct wl1251 *wl, int addr, u32 val)
  74. {
  75. wl1251_write32(wl, wl1251_translate_mem_addr(wl, addr), val);
  76. }
  77. u32 wl1251_reg_read32(struct wl1251 *wl, int addr)
  78. {
  79. return wl1251_read32(wl, wl1251_translate_reg_addr(wl, addr));
  80. }
  81. void wl1251_reg_write32(struct wl1251 *wl, int addr, u32 val)
  82. {
  83. wl1251_write32(wl, wl1251_translate_reg_addr(wl, addr), val);
  84. }
  85. /* Set the partitions to access the chip addresses.
  86. *
  87. * There are two VIRTUAL partitions (the memory partition and the
  88. * registers partition), which are mapped to two different areas of the
  89. * PHYSICAL (hardware) memory. This function also makes other checks to
  90. * ensure that the partitions are not overlapping. In the diagram below, the
  91. * memory partition comes before the register partition, but the opposite is
  92. * also supported.
  93. *
  94. * PHYSICAL address
  95. * space
  96. *
  97. * | |
  98. * ...+----+--> mem_start
  99. * VIRTUAL address ... | |
  100. * space ... | | [PART_0]
  101. * ... | |
  102. * 0x00000000 <--+----+... ...+----+--> mem_start + mem_size
  103. * | | ... | |
  104. * |MEM | ... | |
  105. * | | ... | |
  106. * part_size <--+----+... | | {unused area)
  107. * | | ... | |
  108. * |REG | ... | |
  109. * part_size | | ... | |
  110. * + <--+----+... ...+----+--> reg_start
  111. * reg_size ... | |
  112. * ... | | [PART_1]
  113. * ... | |
  114. * ...+----+--> reg_start + reg_size
  115. * | |
  116. *
  117. */
  118. void wl1251_set_partition(struct wl1251 *wl,
  119. u32 mem_start, u32 mem_size,
  120. u32 reg_start, u32 reg_size)
  121. {
  122. struct wl1251_partition partition[2];
  123. wl1251_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
  124. mem_start, mem_size);
  125. wl1251_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
  126. reg_start, reg_size);
  127. /* Make sure that the two partitions together don't exceed the
  128. * address range */
  129. if ((mem_size + reg_size) > HW_ACCESS_MEMORY_MAX_RANGE) {
  130. wl1251_debug(DEBUG_SPI, "Total size exceeds maximum virtual"
  131. " address range. Truncating partition[0].");
  132. mem_size = HW_ACCESS_MEMORY_MAX_RANGE - reg_size;
  133. wl1251_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
  134. mem_start, mem_size);
  135. wl1251_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
  136. reg_start, reg_size);
  137. }
  138. if ((mem_start < reg_start) &&
  139. ((mem_start + mem_size) > reg_start)) {
  140. /* Guarantee that the memory partition doesn't overlap the
  141. * registers partition */
  142. wl1251_debug(DEBUG_SPI, "End of partition[0] is "
  143. "overlapping partition[1]. Adjusted.");
  144. mem_size = reg_start - mem_start;
  145. wl1251_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
  146. mem_start, mem_size);
  147. wl1251_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
  148. reg_start, reg_size);
  149. } else if ((reg_start < mem_start) &&
  150. ((reg_start + reg_size) > mem_start)) {
  151. /* Guarantee that the register partition doesn't overlap the
  152. * memory partition */
  153. wl1251_debug(DEBUG_SPI, "End of partition[1] is"
  154. " overlapping partition[0]. Adjusted.");
  155. reg_size = mem_start - reg_start;
  156. wl1251_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
  157. mem_start, mem_size);
  158. wl1251_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
  159. reg_start, reg_size);
  160. }
  161. partition[0].start = mem_start;
  162. partition[0].size = mem_size;
  163. partition[1].start = reg_start;
  164. partition[1].size = reg_size;
  165. wl->physical_mem_addr = mem_start;
  166. wl->physical_reg_addr = reg_start;
  167. wl->virtual_mem_addr = 0;
  168. wl->virtual_reg_addr = mem_size;
  169. wl->if_ops->write(wl, HW_ACCESS_PART0_SIZE_ADDR, partition,
  170. sizeof(partition));
  171. }