io.c 5.0 KB

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