io.c 5.6 KB

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