io.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. struct wl1271;
  40. void wl1271_disable_interrupts(struct wl1271 *wl);
  41. void wl1271_enable_interrupts(struct wl1271 *wl);
  42. void wl1271_io_reset(struct wl1271 *wl);
  43. void wl1271_io_init(struct wl1271 *wl);
  44. static inline struct device *wl1271_wl_to_dev(struct wl1271 *wl)
  45. {
  46. return wl->if_ops->dev(wl);
  47. }
  48. /* Raw target IO, address is not translated */
  49. static inline void wl1271_raw_write(struct wl1271 *wl, int addr, void *buf,
  50. size_t len, bool fixed)
  51. {
  52. wl->if_ops->write(wl, addr, buf, len, fixed);
  53. }
  54. static inline void wl1271_raw_read(struct wl1271 *wl, int addr, void *buf,
  55. size_t len, bool fixed)
  56. {
  57. wl->if_ops->read(wl, addr, buf, len, fixed);
  58. }
  59. static inline u32 wl1271_raw_read32(struct wl1271 *wl, int addr)
  60. {
  61. wl1271_raw_read(wl, addr, &wl->buffer_32,
  62. sizeof(wl->buffer_32), false);
  63. return le32_to_cpu(wl->buffer_32);
  64. }
  65. static inline void wl1271_raw_write32(struct wl1271 *wl, int addr, u32 val)
  66. {
  67. wl->buffer_32 = cpu_to_le32(val);
  68. wl1271_raw_write(wl, addr, &wl->buffer_32,
  69. sizeof(wl->buffer_32), false);
  70. }
  71. /* Translated target IO */
  72. static inline int wl1271_translate_addr(struct wl1271 *wl, int addr)
  73. {
  74. /*
  75. * To translate, first check to which window of addresses the
  76. * particular address belongs. Then subtract the starting address
  77. * of that window from the address. Then, add offset of the
  78. * translated region.
  79. *
  80. * The translated regions occur next to each other in physical device
  81. * memory, so just add the sizes of the preceding address regions to
  82. * get the offset to the new region.
  83. *
  84. * Currently, only the two first regions are addressed, and the
  85. * assumption is that all addresses will fall into either of those
  86. * two.
  87. */
  88. if ((addr >= wl->part.reg.start) &&
  89. (addr < wl->part.reg.start + wl->part.reg.size))
  90. return addr - wl->part.reg.start + wl->part.mem.size;
  91. else
  92. return addr - wl->part.mem.start;
  93. }
  94. static inline void wl1271_read(struct wl1271 *wl, int addr, void *buf,
  95. size_t len, bool fixed)
  96. {
  97. int physical;
  98. physical = wl1271_translate_addr(wl, addr);
  99. wl1271_raw_read(wl, physical, buf, len, fixed);
  100. }
  101. static inline void wl1271_write(struct wl1271 *wl, int addr, void *buf,
  102. size_t len, bool fixed)
  103. {
  104. int physical;
  105. physical = wl1271_translate_addr(wl, addr);
  106. wl1271_raw_write(wl, physical, buf, len, fixed);
  107. }
  108. static inline void wl1271_read_hwaddr(struct wl1271 *wl, int hwaddr,
  109. void *buf, size_t len, bool fixed)
  110. {
  111. int physical;
  112. int addr;
  113. /* Addresses are stored internally as addresses to 32 bytes blocks */
  114. addr = hwaddr << 5;
  115. physical = wl1271_translate_addr(wl, addr);
  116. wl1271_raw_read(wl, physical, buf, len, fixed);
  117. }
  118. static inline u32 wl1271_read32(struct wl1271 *wl, int addr)
  119. {
  120. return wl1271_raw_read32(wl, wl1271_translate_addr(wl, addr));
  121. }
  122. static inline void wl1271_write32(struct wl1271 *wl, int addr, u32 val)
  123. {
  124. wl1271_raw_write32(wl, wl1271_translate_addr(wl, addr), val);
  125. }
  126. static inline void wl1271_power_off(struct wl1271 *wl)
  127. {
  128. wl->if_ops->power(wl, false);
  129. clear_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
  130. }
  131. static inline int wl1271_power_on(struct wl1271 *wl)
  132. {
  133. int ret = wl->if_ops->power(wl, true);
  134. if (ret == 0)
  135. set_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
  136. return ret;
  137. }
  138. /* Top Register IO */
  139. void wl1271_top_reg_write(struct wl1271 *wl, int addr, u16 val);
  140. u16 wl1271_top_reg_read(struct wl1271 *wl, int addr);
  141. int wl1271_set_partition(struct wl1271 *wl,
  142. struct wl1271_partition_set *p);
  143. /* Functions from wl1271_main.c */
  144. int wl1271_register_hw(struct wl1271 *wl);
  145. void wl1271_unregister_hw(struct wl1271 *wl);
  146. int wl1271_init_ieee80211(struct wl1271 *wl);
  147. struct ieee80211_hw *wl1271_alloc_hw(void);
  148. int wl1271_free_hw(struct wl1271 *wl);
  149. irqreturn_t wl1271_irq(int irq, void *data);
  150. bool wl1271_set_block_size(struct wl1271 *wl);
  151. int wl1271_tx_dummy_packet(struct wl1271 *wl);
  152. void wl1271_configure_filters(struct wl1271 *wl, unsigned int filters);
  153. #endif