wl1251_io.c 6.7 KB

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