io.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. bool wl1271_set_block_size(struct wl1271 *wl)
  33. {
  34. if (wl->if_ops->set_block_size) {
  35. wl->if_ops->set_block_size(wl->dev, WL12XX_BUS_BLOCK_SIZE);
  36. return true;
  37. }
  38. return false;
  39. }
  40. void wlcore_disable_interrupts(struct wl1271 *wl)
  41. {
  42. disable_irq(wl->irq);
  43. }
  44. EXPORT_SYMBOL_GPL(wlcore_disable_interrupts);
  45. void wlcore_disable_interrupts_nosync(struct wl1271 *wl)
  46. {
  47. disable_irq_nosync(wl->irq);
  48. }
  49. EXPORT_SYMBOL_GPL(wlcore_disable_interrupts_nosync);
  50. void wlcore_enable_interrupts(struct wl1271 *wl)
  51. {
  52. enable_irq(wl->irq);
  53. }
  54. EXPORT_SYMBOL_GPL(wlcore_enable_interrupts);
  55. void wlcore_synchronize_interrupts(struct wl1271 *wl)
  56. {
  57. synchronize_irq(wl->irq);
  58. }
  59. EXPORT_SYMBOL_GPL(wlcore_synchronize_interrupts);
  60. int wlcore_translate_addr(struct wl1271 *wl, int addr)
  61. {
  62. struct wlcore_partition_set *part = &wl->curr_part;
  63. /*
  64. * To translate, first check to which window of addresses the
  65. * particular address belongs. Then subtract the starting address
  66. * of that window from the address. Then, add offset of the
  67. * translated region.
  68. *
  69. * The translated regions occur next to each other in physical device
  70. * memory, so just add the sizes of the preceding address regions to
  71. * get the offset to the new region.
  72. */
  73. if ((addr >= part->mem.start) &&
  74. (addr < part->mem.start + part->mem.size))
  75. return addr - part->mem.start;
  76. else if ((addr >= part->reg.start) &&
  77. (addr < part->reg.start + part->reg.size))
  78. return addr - part->reg.start + part->mem.size;
  79. else if ((addr >= part->mem2.start) &&
  80. (addr < part->mem2.start + part->mem2.size))
  81. return addr - part->mem2.start + part->mem.size +
  82. part->reg.size;
  83. else if ((addr >= part->mem3.start) &&
  84. (addr < part->mem3.start + part->mem3.size))
  85. return addr - part->mem3.start + part->mem.size +
  86. part->reg.size + part->mem2.size;
  87. WARN(1, "HW address 0x%x out of range", addr);
  88. return 0;
  89. }
  90. EXPORT_SYMBOL_GPL(wlcore_translate_addr);
  91. /* Set the partitions to access the chip addresses
  92. *
  93. * To simplify driver code, a fixed (virtual) memory map is defined for
  94. * register and memory addresses. Because in the chipset, in different stages
  95. * of operation, those addresses will move around, an address translation
  96. * mechanism is required.
  97. *
  98. * There are four partitions (three memory and one register partition),
  99. * which are mapped to two different areas of the hardware memory.
  100. *
  101. * Virtual address
  102. * space
  103. *
  104. * | |
  105. * ...+----+--> mem.start
  106. * Physical address ... | |
  107. * space ... | | [PART_0]
  108. * ... | |
  109. * 00000000 <--+----+... ...+----+--> mem.start + mem.size
  110. * | | ... | |
  111. * |MEM | ... | |
  112. * | | ... | |
  113. * mem.size <--+----+... | | {unused area)
  114. * | | ... | |
  115. * |REG | ... | |
  116. * mem.size | | ... | |
  117. * + <--+----+... ...+----+--> reg.start
  118. * reg.size | | ... | |
  119. * |MEM2| ... | | [PART_1]
  120. * | | ... | |
  121. * ...+----+--> reg.start + reg.size
  122. * | |
  123. *
  124. */
  125. int wlcore_set_partition(struct wl1271 *wl,
  126. const struct wlcore_partition_set *p)
  127. {
  128. int ret;
  129. /* copy partition info */
  130. memcpy(&wl->curr_part, p, sizeof(*p));
  131. wl1271_debug(DEBUG_IO, "mem_start %08X mem_size %08X",
  132. p->mem.start, p->mem.size);
  133. wl1271_debug(DEBUG_IO, "reg_start %08X reg_size %08X",
  134. p->reg.start, p->reg.size);
  135. wl1271_debug(DEBUG_IO, "mem2_start %08X mem2_size %08X",
  136. p->mem2.start, p->mem2.size);
  137. wl1271_debug(DEBUG_IO, "mem3_start %08X mem3_size %08X",
  138. p->mem3.start, p->mem3.size);
  139. ret = wlcore_raw_write32(wl, HW_PART0_START_ADDR, p->mem.start);
  140. if (ret < 0)
  141. goto out;
  142. ret = wlcore_raw_write32(wl, HW_PART0_SIZE_ADDR, p->mem.size);
  143. if (ret < 0)
  144. goto out;
  145. ret = wlcore_raw_write32(wl, HW_PART1_START_ADDR, p->reg.start);
  146. if (ret < 0)
  147. goto out;
  148. ret = wlcore_raw_write32(wl, HW_PART1_SIZE_ADDR, p->reg.size);
  149. if (ret < 0)
  150. goto out;
  151. ret = wlcore_raw_write32(wl, HW_PART2_START_ADDR, p->mem2.start);
  152. if (ret < 0)
  153. goto out;
  154. ret = wlcore_raw_write32(wl, HW_PART2_SIZE_ADDR, p->mem2.size);
  155. if (ret < 0)
  156. goto out;
  157. /*
  158. * We don't need the size of the last partition, as it is
  159. * automatically calculated based on the total memory size and
  160. * the sizes of the previous partitions.
  161. */
  162. ret = wlcore_raw_write32(wl, HW_PART3_START_ADDR, p->mem3.start);
  163. out:
  164. return ret;
  165. }
  166. EXPORT_SYMBOL_GPL(wlcore_set_partition);
  167. void wl1271_io_reset(struct wl1271 *wl)
  168. {
  169. if (wl->if_ops->reset)
  170. wl->if_ops->reset(wl->dev);
  171. }
  172. void wl1271_io_init(struct wl1271 *wl)
  173. {
  174. if (wl->if_ops->init)
  175. wl->if_ops->init(wl->dev);
  176. }