io.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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 "wl12xx.h"
  28. #include "debug.h"
  29. #include "wl12xx_80211.h"
  30. #include "io.h"
  31. #include "tx.h"
  32. #define OCP_CMD_LOOP 32
  33. #define OCP_CMD_WRITE 0x1
  34. #define OCP_CMD_READ 0x2
  35. #define OCP_READY_MASK BIT(18)
  36. #define OCP_STATUS_MASK (BIT(16) | BIT(17))
  37. #define OCP_STATUS_NO_RESP 0x00000
  38. #define OCP_STATUS_OK 0x10000
  39. #define OCP_STATUS_REQ_FAILED 0x20000
  40. #define OCP_STATUS_RESP_ERROR 0x30000
  41. struct wl1271_partition_set wl12xx_part_table[PART_TABLE_LEN] = {
  42. [PART_DOWN] = {
  43. .mem = {
  44. .start = 0x00000000,
  45. .size = 0x000177c0
  46. },
  47. .reg = {
  48. .start = REGISTERS_BASE,
  49. .size = 0x00008800
  50. },
  51. .mem2 = {
  52. .start = 0x00000000,
  53. .size = 0x00000000
  54. },
  55. .mem3 = {
  56. .start = 0x00000000,
  57. .size = 0x00000000
  58. },
  59. },
  60. [PART_WORK] = {
  61. .mem = {
  62. .start = 0x00040000,
  63. .size = 0x00014fc0
  64. },
  65. .reg = {
  66. .start = REGISTERS_BASE,
  67. .size = 0x0000a000
  68. },
  69. .mem2 = {
  70. .start = 0x003004f8,
  71. .size = 0x00000004
  72. },
  73. .mem3 = {
  74. .start = 0x00040404,
  75. .size = 0x00000000
  76. },
  77. },
  78. [PART_DRPW] = {
  79. .mem = {
  80. .start = 0x00040000,
  81. .size = 0x00014fc0
  82. },
  83. .reg = {
  84. .start = DRPW_BASE,
  85. .size = 0x00006000
  86. },
  87. .mem2 = {
  88. .start = 0x00000000,
  89. .size = 0x00000000
  90. },
  91. .mem3 = {
  92. .start = 0x00000000,
  93. .size = 0x00000000
  94. }
  95. }
  96. };
  97. bool wl1271_set_block_size(struct wl1271 *wl)
  98. {
  99. if (wl->if_ops->set_block_size) {
  100. wl->if_ops->set_block_size(wl->dev, WL12XX_BUS_BLOCK_SIZE);
  101. return true;
  102. }
  103. return false;
  104. }
  105. void wl1271_disable_interrupts(struct wl1271 *wl)
  106. {
  107. disable_irq(wl->irq);
  108. }
  109. void wl1271_enable_interrupts(struct wl1271 *wl)
  110. {
  111. enable_irq(wl->irq);
  112. }
  113. /* Set the SPI partitions to access the chip addresses
  114. *
  115. * To simplify driver code, a fixed (virtual) memory map is defined for
  116. * register and memory addresses. Because in the chipset, in different stages
  117. * of operation, those addresses will move around, an address translation
  118. * mechanism is required.
  119. *
  120. * There are four partitions (three memory and one register partition),
  121. * which are mapped to two different areas of the hardware memory.
  122. *
  123. * Virtual address
  124. * space
  125. *
  126. * | |
  127. * ...+----+--> mem.start
  128. * Physical address ... | |
  129. * space ... | | [PART_0]
  130. * ... | |
  131. * 00000000 <--+----+... ...+----+--> mem.start + mem.size
  132. * | | ... | |
  133. * |MEM | ... | |
  134. * | | ... | |
  135. * mem.size <--+----+... | | {unused area)
  136. * | | ... | |
  137. * |REG | ... | |
  138. * mem.size | | ... | |
  139. * + <--+----+... ...+----+--> reg.start
  140. * reg.size | | ... | |
  141. * |MEM2| ... | | [PART_1]
  142. * | | ... | |
  143. * ...+----+--> reg.start + reg.size
  144. * | |
  145. *
  146. */
  147. int wl1271_set_partition(struct wl1271 *wl,
  148. struct wl1271_partition_set *p)
  149. {
  150. /* copy partition info */
  151. memcpy(&wl->part, p, sizeof(*p));
  152. wl1271_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
  153. p->mem.start, p->mem.size);
  154. wl1271_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
  155. p->reg.start, p->reg.size);
  156. wl1271_debug(DEBUG_SPI, "mem2_start %08X mem2_size %08X",
  157. p->mem2.start, p->mem2.size);
  158. wl1271_debug(DEBUG_SPI, "mem3_start %08X mem3_size %08X",
  159. p->mem3.start, p->mem3.size);
  160. /* write partition info to the chipset */
  161. wl1271_raw_write32(wl, HW_PART0_START_ADDR, p->mem.start);
  162. wl1271_raw_write32(wl, HW_PART0_SIZE_ADDR, p->mem.size);
  163. wl1271_raw_write32(wl, HW_PART1_START_ADDR, p->reg.start);
  164. wl1271_raw_write32(wl, HW_PART1_SIZE_ADDR, p->reg.size);
  165. wl1271_raw_write32(wl, HW_PART2_START_ADDR, p->mem2.start);
  166. wl1271_raw_write32(wl, HW_PART2_SIZE_ADDR, p->mem2.size);
  167. wl1271_raw_write32(wl, HW_PART3_START_ADDR, p->mem3.start);
  168. return 0;
  169. }
  170. EXPORT_SYMBOL_GPL(wl1271_set_partition);
  171. void wl1271_io_reset(struct wl1271 *wl)
  172. {
  173. if (wl->if_ops->reset)
  174. wl->if_ops->reset(wl->dev);
  175. }
  176. void wl1271_io_init(struct wl1271 *wl)
  177. {
  178. if (wl->if_ops->init)
  179. wl->if_ops->init(wl->dev);
  180. }
  181. void wl1271_top_reg_write(struct wl1271 *wl, int addr, u16 val)
  182. {
  183. /* write address >> 1 + 0x30000 to OCP_POR_CTR */
  184. addr = (addr >> 1) + 0x30000;
  185. wl1271_write32(wl, OCP_POR_CTR, addr);
  186. /* write value to OCP_POR_WDATA */
  187. wl1271_write32(wl, OCP_DATA_WRITE, val);
  188. /* write 1 to OCP_CMD */
  189. wl1271_write32(wl, OCP_CMD, OCP_CMD_WRITE);
  190. }
  191. u16 wl1271_top_reg_read(struct wl1271 *wl, int addr)
  192. {
  193. u32 val;
  194. int timeout = OCP_CMD_LOOP;
  195. /* write address >> 1 + 0x30000 to OCP_POR_CTR */
  196. addr = (addr >> 1) + 0x30000;
  197. wl1271_write32(wl, OCP_POR_CTR, addr);
  198. /* write 2 to OCP_CMD */
  199. wl1271_write32(wl, OCP_CMD, OCP_CMD_READ);
  200. /* poll for data ready */
  201. do {
  202. val = wl1271_read32(wl, OCP_DATA_READ);
  203. } while (!(val & OCP_READY_MASK) && --timeout);
  204. if (!timeout) {
  205. wl1271_warning("Top register access timed out.");
  206. return 0xffff;
  207. }
  208. /* check data status and return if OK */
  209. if ((val & OCP_STATUS_MASK) == OCP_STATUS_OK)
  210. return val & 0xffff;
  211. else {
  212. wl1271_warning("Top register access returned error.");
  213. return 0xffff;
  214. }
  215. }