io.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*
  2. * This file is part of wl1271
  3. *
  4. * Copyright (C) 2008-2010 Nokia Corporation
  5. *
  6. * Contact: Luciano Coelho <luciano.coelho@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 <linux/module.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/spi/spi.h>
  26. #include <linux/interrupt.h>
  27. #include "wlcore.h"
  28. #include "debug.h"
  29. #include "wl12xx_80211.h"
  30. #include "io.h"
  31. #include "tx.h"
  32. /*
  33. * TODO: this is here just for now, it will be removed when we move
  34. * the top_reg stuff to wl12xx
  35. */
  36. #include "../wl12xx/reg.h"
  37. bool wl1271_set_block_size(struct wl1271 *wl)
  38. {
  39. if (wl->if_ops->set_block_size) {
  40. wl->if_ops->set_block_size(wl->dev, WL12XX_BUS_BLOCK_SIZE);
  41. return true;
  42. }
  43. return false;
  44. }
  45. void wl1271_disable_interrupts(struct wl1271 *wl)
  46. {
  47. disable_irq(wl->irq);
  48. }
  49. void wl1271_enable_interrupts(struct wl1271 *wl)
  50. {
  51. enable_irq(wl->irq);
  52. }
  53. int wlcore_translate_addr(struct wl1271 *wl, int addr)
  54. {
  55. struct wlcore_partition_set *part = &wl->curr_part;
  56. /*
  57. * To translate, first check to which window of addresses the
  58. * particular address belongs. Then subtract the starting address
  59. * of that window from the address. Then, add offset of the
  60. * translated region.
  61. *
  62. * The translated regions occur next to each other in physical device
  63. * memory, so just add the sizes of the preceding address regions to
  64. * get the offset to the new region.
  65. */
  66. if ((addr >= part->mem.start) &&
  67. (addr < part->mem.start + part->mem.size))
  68. return addr - part->mem.start;
  69. else if ((addr >= part->reg.start) &&
  70. (addr < part->reg.start + part->reg.size))
  71. return addr - part->reg.start + part->mem.size;
  72. else if ((addr >= part->mem2.start) &&
  73. (addr < part->mem2.start + part->mem2.size))
  74. return addr - part->mem2.start + part->mem.size +
  75. part->reg.size;
  76. else if ((addr >= part->mem3.start) &&
  77. (addr < part->mem3.start + part->mem3.size))
  78. return addr - part->mem3.start + part->mem.size +
  79. part->reg.size + part->mem2.size;
  80. WARN(1, "HW address 0x%x out of range", addr);
  81. return 0;
  82. }
  83. EXPORT_SYMBOL_GPL(wlcore_translate_addr);
  84. /* Set the partitions to access the chip addresses
  85. *
  86. * To simplify driver code, a fixed (virtual) memory map is defined for
  87. * register and memory addresses. Because in the chipset, in different stages
  88. * of operation, those addresses will move around, an address translation
  89. * mechanism is required.
  90. *
  91. * There are four partitions (three memory and one register partition),
  92. * which are mapped to two different areas of the hardware memory.
  93. *
  94. * Virtual address
  95. * space
  96. *
  97. * | |
  98. * ...+----+--> mem.start
  99. * Physical address ... | |
  100. * space ... | | [PART_0]
  101. * ... | |
  102. * 00000000 <--+----+... ...+----+--> mem.start + mem.size
  103. * | | ... | |
  104. * |MEM | ... | |
  105. * | | ... | |
  106. * mem.size <--+----+... | | {unused area)
  107. * | | ... | |
  108. * |REG | ... | |
  109. * mem.size | | ... | |
  110. * + <--+----+... ...+----+--> reg.start
  111. * reg.size | | ... | |
  112. * |MEM2| ... | | [PART_1]
  113. * | | ... | |
  114. * ...+----+--> reg.start + reg.size
  115. * | |
  116. *
  117. */
  118. void wlcore_set_partition(struct wl1271 *wl,
  119. const struct wlcore_partition_set *p)
  120. {
  121. /* copy partition info */
  122. memcpy(&wl->curr_part, p, sizeof(*p));
  123. wl1271_debug(DEBUG_IO, "mem_start %08X mem_size %08X",
  124. p->mem.start, p->mem.size);
  125. wl1271_debug(DEBUG_IO, "reg_start %08X reg_size %08X",
  126. p->reg.start, p->reg.size);
  127. wl1271_debug(DEBUG_IO, "mem2_start %08X mem2_size %08X",
  128. p->mem2.start, p->mem2.size);
  129. wl1271_debug(DEBUG_IO, "mem3_start %08X mem3_size %08X",
  130. p->mem3.start, p->mem3.size);
  131. wl1271_raw_write32(wl, HW_PART0_START_ADDR, p->mem.start);
  132. wl1271_raw_write32(wl, HW_PART0_SIZE_ADDR, p->mem.size);
  133. wl1271_raw_write32(wl, HW_PART1_START_ADDR, p->reg.start);
  134. wl1271_raw_write32(wl, HW_PART1_SIZE_ADDR, p->reg.size);
  135. wl1271_raw_write32(wl, HW_PART2_START_ADDR, p->mem2.start);
  136. wl1271_raw_write32(wl, HW_PART2_SIZE_ADDR, p->mem2.size);
  137. /*
  138. * We don't need the size of the last partition, as it is
  139. * automatically calculated based on the total memory size and
  140. * the sizes of the previous partitions.
  141. */
  142. wl1271_raw_write32(wl, HW_PART3_START_ADDR, p->mem3.start);
  143. }
  144. EXPORT_SYMBOL_GPL(wlcore_set_partition);
  145. void wlcore_select_partition(struct wl1271 *wl, u8 part)
  146. {
  147. wl1271_debug(DEBUG_IO, "setting partition %d", part);
  148. wlcore_set_partition(wl, &wl->ptable[part]);
  149. }
  150. EXPORT_SYMBOL_GPL(wlcore_select_partition);
  151. void wl1271_io_reset(struct wl1271 *wl)
  152. {
  153. if (wl->if_ops->reset)
  154. wl->if_ops->reset(wl->dev);
  155. }
  156. void wl1271_io_init(struct wl1271 *wl)
  157. {
  158. if (wl->if_ops->init)
  159. wl->if_ops->init(wl->dev);
  160. }
  161. void wl1271_top_reg_write(struct wl1271 *wl, int addr, u16 val)
  162. {
  163. /* write address >> 1 + 0x30000 to OCP_POR_CTR */
  164. addr = (addr >> 1) + 0x30000;
  165. wl1271_write32(wl, WL12XX_OCP_POR_CTR, addr);
  166. /* write value to OCP_POR_WDATA */
  167. wl1271_write32(wl, WL12XX_OCP_DATA_WRITE, val);
  168. /* write 1 to OCP_CMD */
  169. wl1271_write32(wl, WL12XX_OCP_CMD, OCP_CMD_WRITE);
  170. }
  171. u16 wl1271_top_reg_read(struct wl1271 *wl, int addr)
  172. {
  173. u32 val;
  174. int timeout = OCP_CMD_LOOP;
  175. /* write address >> 1 + 0x30000 to OCP_POR_CTR */
  176. addr = (addr >> 1) + 0x30000;
  177. wl1271_write32(wl, WL12XX_OCP_POR_CTR, addr);
  178. /* write 2 to OCP_CMD */
  179. wl1271_write32(wl, WL12XX_OCP_CMD, OCP_CMD_READ);
  180. /* poll for data ready */
  181. do {
  182. val = wl1271_read32(wl, WL12XX_OCP_DATA_READ);
  183. } while (!(val & OCP_READY_MASK) && --timeout);
  184. if (!timeout) {
  185. wl1271_warning("Top register access timed out.");
  186. return 0xffff;
  187. }
  188. /* check data status and return if OK */
  189. if ((val & OCP_STATUS_MASK) == OCP_STATUS_OK)
  190. return val & 0xffff;
  191. else {
  192. wl1271_warning("Top register access returned error.");
  193. return 0xffff;
  194. }
  195. }
  196. EXPORT_SYMBOL_GPL(wl1271_top_reg_read);