io.c 5.3 KB

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