wl1271_io.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 __WL1271_IO_H__
  25. #define __WL1271_IO_H__
  26. #include "wl1271_reg.h"
  27. #define HW_ACCESS_MEMORY_MAX_RANGE 0x1FFC0
  28. #define HW_PARTITION_REGISTERS_ADDR 0x1FFC0
  29. #define HW_PART0_SIZE_ADDR (HW_PARTITION_REGISTERS_ADDR)
  30. #define HW_PART0_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 4)
  31. #define HW_PART1_SIZE_ADDR (HW_PARTITION_REGISTERS_ADDR + 8)
  32. #define HW_PART1_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 12)
  33. #define HW_PART2_SIZE_ADDR (HW_PARTITION_REGISTERS_ADDR + 16)
  34. #define HW_PART2_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 20)
  35. #define HW_PART3_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 24)
  36. #define HW_ACCESS_REGISTER_SIZE 4
  37. #define HW_ACCESS_PRAM_MAX_RANGE 0x3c000
  38. struct wl1271;
  39. void wl1271_disable_interrupts(struct wl1271 *wl);
  40. void wl1271_enable_interrupts(struct wl1271 *wl);
  41. void wl1271_io_reset(struct wl1271 *wl);
  42. void wl1271_io_init(struct wl1271 *wl);
  43. static inline struct device *wl1271_wl_to_dev(struct wl1271 *wl)
  44. {
  45. return wl->if_ops->dev(wl);
  46. }
  47. /* Raw target IO, address is not translated */
  48. static inline void wl1271_raw_write(struct wl1271 *wl, int addr, void *buf,
  49. size_t len, bool fixed)
  50. {
  51. wl->if_ops->write(wl, addr, buf, len, fixed);
  52. }
  53. static inline void wl1271_raw_read(struct wl1271 *wl, int addr, void *buf,
  54. size_t len, bool fixed)
  55. {
  56. wl->if_ops->read(wl, addr, buf, len, fixed);
  57. }
  58. static inline u32 wl1271_raw_read32(struct wl1271 *wl, int addr)
  59. {
  60. wl1271_raw_read(wl, addr, &wl->buffer_32,
  61. sizeof(wl->buffer_32), false);
  62. return le32_to_cpu(wl->buffer_32);
  63. }
  64. static inline void wl1271_raw_write32(struct wl1271 *wl, int addr, u32 val)
  65. {
  66. wl->buffer_32 = cpu_to_le32(val);
  67. wl1271_raw_write(wl, addr, &wl->buffer_32,
  68. sizeof(wl->buffer_32), false);
  69. }
  70. /* Translated target IO */
  71. static inline int wl1271_translate_addr(struct wl1271 *wl, int addr)
  72. {
  73. /*
  74. * To translate, first check to which window of addresses the
  75. * particular address belongs. Then subtract the starting address
  76. * of that window from the address. Then, add offset of the
  77. * translated region.
  78. *
  79. * The translated regions occur next to each other in physical device
  80. * memory, so just add the sizes of the preceeding address regions to
  81. * get the offset to the new region.
  82. *
  83. * Currently, only the two first regions are addressed, and the
  84. * assumption is that all addresses will fall into either of those
  85. * two.
  86. */
  87. if ((addr >= wl->part.reg.start) &&
  88. (addr < wl->part.reg.start + wl->part.reg.size))
  89. return addr - wl->part.reg.start + wl->part.mem.size;
  90. else
  91. return addr - wl->part.mem.start;
  92. }
  93. static inline void wl1271_read(struct wl1271 *wl, int addr, void *buf,
  94. size_t len, bool fixed)
  95. {
  96. int physical;
  97. physical = wl1271_translate_addr(wl, addr);
  98. wl1271_raw_read(wl, physical, buf, len, fixed);
  99. }
  100. static inline void wl1271_write(struct wl1271 *wl, int addr, void *buf,
  101. size_t len, bool fixed)
  102. {
  103. int physical;
  104. physical = wl1271_translate_addr(wl, addr);
  105. wl1271_raw_write(wl, physical, buf, len, fixed);
  106. }
  107. static inline u32 wl1271_read32(struct wl1271 *wl, int addr)
  108. {
  109. return wl1271_raw_read32(wl, wl1271_translate_addr(wl, addr));
  110. }
  111. static inline void wl1271_write32(struct wl1271 *wl, int addr, u32 val)
  112. {
  113. wl1271_raw_write32(wl, wl1271_translate_addr(wl, addr), val);
  114. }
  115. static inline void wl1271_power_off(struct wl1271 *wl)
  116. {
  117. wl->if_ops->power(wl, false);
  118. clear_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
  119. }
  120. static inline void wl1271_power_on(struct wl1271 *wl)
  121. {
  122. wl->if_ops->power(wl, true);
  123. set_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
  124. }
  125. /* Top Register IO */
  126. void wl1271_top_reg_write(struct wl1271 *wl, int addr, u16 val);
  127. u16 wl1271_top_reg_read(struct wl1271 *wl, int addr);
  128. int wl1271_set_partition(struct wl1271 *wl,
  129. struct wl1271_partition_set *p);
  130. /* Functions from wl1271_main.c */
  131. int wl1271_register_hw(struct wl1271 *wl);
  132. void wl1271_unregister_hw(struct wl1271 *wl);
  133. int wl1271_init_ieee80211(struct wl1271 *wl);
  134. struct ieee80211_hw *wl1271_alloc_hw(void);
  135. int wl1271_free_hw(struct wl1271 *wl);
  136. #endif