wl1271_io.c 4.8 KB

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