io.c 5.3 KB

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