io.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * This file is part of wl1271
  3. *
  4. * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
  5. * Copyright (C) 2008-2010 Nokia Corporation
  6. *
  7. * Contact: Luciano Coelho <luciano.coelho@nokia.com>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * version 2 as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  21. * 02110-1301 USA
  22. *
  23. */
  24. #ifndef __IO_H__
  25. #define __IO_H__
  26. #include <linux/irqreturn.h>
  27. #include "reg.h"
  28. #define HW_ACCESS_MEMORY_MAX_RANGE 0x1FFC0
  29. #define HW_PARTITION_REGISTERS_ADDR 0x1FFC0
  30. #define HW_PART0_SIZE_ADDR (HW_PARTITION_REGISTERS_ADDR)
  31. #define HW_PART0_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 4)
  32. #define HW_PART1_SIZE_ADDR (HW_PARTITION_REGISTERS_ADDR + 8)
  33. #define HW_PART1_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 12)
  34. #define HW_PART2_SIZE_ADDR (HW_PARTITION_REGISTERS_ADDR + 16)
  35. #define HW_PART2_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 20)
  36. #define HW_PART3_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 24)
  37. #define HW_ACCESS_REGISTER_SIZE 4
  38. #define HW_ACCESS_PRAM_MAX_RANGE 0x3c000
  39. extern struct wl1271_partition_set wl12xx_part_table[PART_TABLE_LEN];
  40. struct wl1271;
  41. void wl1271_disable_interrupts(struct wl1271 *wl);
  42. void wl1271_enable_interrupts(struct wl1271 *wl);
  43. void wl1271_io_reset(struct wl1271 *wl);
  44. void wl1271_io_init(struct wl1271 *wl);
  45. /* Raw target IO, address is not translated */
  46. static inline void wl1271_raw_write(struct wl1271 *wl, int addr, void *buf,
  47. size_t len, bool fixed)
  48. {
  49. wl->if_ops->write(wl->dev, addr, buf, len, fixed);
  50. }
  51. static inline void wl1271_raw_read(struct wl1271 *wl, int addr, void *buf,
  52. size_t len, bool fixed)
  53. {
  54. wl->if_ops->read(wl->dev, addr, buf, len, fixed);
  55. }
  56. static inline u32 wl1271_raw_read32(struct wl1271 *wl, int addr)
  57. {
  58. wl1271_raw_read(wl, addr, &wl->buffer_32,
  59. sizeof(wl->buffer_32), false);
  60. return le32_to_cpu(wl->buffer_32);
  61. }
  62. static inline void wl1271_raw_write32(struct wl1271 *wl, int addr, u32 val)
  63. {
  64. wl->buffer_32 = cpu_to_le32(val);
  65. wl1271_raw_write(wl, addr, &wl->buffer_32,
  66. sizeof(wl->buffer_32), false);
  67. }
  68. /* Translated target IO */
  69. static inline int wl1271_translate_addr(struct wl1271 *wl, int addr)
  70. {
  71. /*
  72. * To translate, first check to which window of addresses the
  73. * particular address belongs. Then subtract the starting address
  74. * of that window from the address. Then, add offset of the
  75. * translated region.
  76. *
  77. * The translated regions occur next to each other in physical device
  78. * memory, so just add the sizes of the preceding address regions to
  79. * get the offset to the new region.
  80. *
  81. * Currently, only the two first regions are addressed, and the
  82. * assumption is that all addresses will fall into either of those
  83. * two.
  84. */
  85. if ((addr >= wl->part.reg.start) &&
  86. (addr < wl->part.reg.start + wl->part.reg.size))
  87. return addr - wl->part.reg.start + wl->part.mem.size;
  88. else
  89. return addr - wl->part.mem.start;
  90. }
  91. static inline void wl1271_read(struct wl1271 *wl, int addr, void *buf,
  92. size_t len, bool fixed)
  93. {
  94. int physical;
  95. physical = wl1271_translate_addr(wl, addr);
  96. wl1271_raw_read(wl, physical, buf, len, fixed);
  97. }
  98. static inline void wl1271_write(struct wl1271 *wl, int addr, void *buf,
  99. size_t len, bool fixed)
  100. {
  101. int physical;
  102. physical = wl1271_translate_addr(wl, addr);
  103. wl1271_raw_write(wl, physical, buf, len, fixed);
  104. }
  105. static inline void wl1271_read_hwaddr(struct wl1271 *wl, int hwaddr,
  106. void *buf, size_t len, bool fixed)
  107. {
  108. int physical;
  109. int addr;
  110. /* Addresses are stored internally as addresses to 32 bytes blocks */
  111. addr = hwaddr << 5;
  112. physical = wl1271_translate_addr(wl, addr);
  113. wl1271_raw_read(wl, physical, buf, len, fixed);
  114. }
  115. static inline u32 wl1271_read32(struct wl1271 *wl, int addr)
  116. {
  117. return wl1271_raw_read32(wl, wl1271_translate_addr(wl, addr));
  118. }
  119. static inline void wl1271_write32(struct wl1271 *wl, int addr, u32 val)
  120. {
  121. wl1271_raw_write32(wl, wl1271_translate_addr(wl, addr), val);
  122. }
  123. static inline void wl1271_power_off(struct wl1271 *wl)
  124. {
  125. wl->if_ops->power(wl->dev, false);
  126. clear_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
  127. }
  128. static inline int wl1271_power_on(struct wl1271 *wl)
  129. {
  130. int ret = wl->if_ops->power(wl->dev, true);
  131. if (ret == 0)
  132. set_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
  133. return ret;
  134. }
  135. /* Top Register IO */
  136. void wl1271_top_reg_write(struct wl1271 *wl, int addr, u16 val);
  137. u16 wl1271_top_reg_read(struct wl1271 *wl, int addr);
  138. int wl1271_set_partition(struct wl1271 *wl,
  139. struct wl1271_partition_set *p);
  140. bool wl1271_set_block_size(struct wl1271 *wl);
  141. /* Functions from wl1271_main.c */
  142. int wl1271_tx_dummy_packet(struct wl1271 *wl);
  143. #endif