io.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. #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 wlcore_disable_interrupts(struct wl1271 *wl);
  40. void wlcore_disable_interrupts_nosync(struct wl1271 *wl);
  41. void wlcore_enable_interrupts(struct wl1271 *wl);
  42. void wlcore_synchronize_interrupts(struct wl1271 *wl);
  43. void wl1271_io_reset(struct wl1271 *wl);
  44. void wl1271_io_init(struct wl1271 *wl);
  45. int wlcore_translate_addr(struct wl1271 *wl, int addr);
  46. /* Raw target IO, address is not translated */
  47. static inline int __must_check wlcore_raw_write(struct wl1271 *wl, int addr,
  48. void *buf, size_t len,
  49. bool fixed)
  50. {
  51. int ret;
  52. if (test_bit(WL1271_FLAG_IO_FAILED, &wl->flags) ||
  53. WARN_ON((test_bit(WL1271_FLAG_IN_ELP, &wl->flags) &&
  54. addr != HW_ACCESS_ELP_CTRL_REG)))
  55. return -EIO;
  56. ret = wl->if_ops->write(wl->dev, addr, buf, len, fixed);
  57. if (ret && wl->state != WLCORE_STATE_OFF)
  58. set_bit(WL1271_FLAG_IO_FAILED, &wl->flags);
  59. return ret;
  60. }
  61. static inline int __must_check wlcore_raw_read(struct wl1271 *wl, int addr,
  62. void *buf, size_t len,
  63. bool fixed)
  64. {
  65. int ret;
  66. if (test_bit(WL1271_FLAG_IO_FAILED, &wl->flags) ||
  67. WARN_ON((test_bit(WL1271_FLAG_IN_ELP, &wl->flags) &&
  68. addr != HW_ACCESS_ELP_CTRL_REG)))
  69. return -EIO;
  70. ret = wl->if_ops->read(wl->dev, addr, buf, len, fixed);
  71. if (ret && wl->state != WLCORE_STATE_OFF)
  72. set_bit(WL1271_FLAG_IO_FAILED, &wl->flags);
  73. return ret;
  74. }
  75. static inline int __must_check wlcore_raw_read_data(struct wl1271 *wl, int reg,
  76. void *buf, size_t len,
  77. bool fixed)
  78. {
  79. return wlcore_raw_read(wl, wl->rtable[reg], buf, len, fixed);
  80. }
  81. static inline int __must_check wlcore_raw_write_data(struct wl1271 *wl, int reg,
  82. void *buf, size_t len,
  83. bool fixed)
  84. {
  85. return wlcore_raw_write(wl, wl->rtable[reg], buf, len, fixed);
  86. }
  87. static inline int __must_check wlcore_raw_read32(struct wl1271 *wl, int addr,
  88. u32 *val)
  89. {
  90. int ret;
  91. ret = wlcore_raw_read(wl, addr, wl->buffer_32,
  92. sizeof(*wl->buffer_32), false);
  93. if (ret < 0)
  94. return ret;
  95. if (val)
  96. *val = le32_to_cpu(*wl->buffer_32);
  97. return 0;
  98. }
  99. static inline int __must_check wlcore_raw_write32(struct wl1271 *wl, int addr,
  100. u32 val)
  101. {
  102. *wl->buffer_32 = cpu_to_le32(val);
  103. return wlcore_raw_write(wl, addr, wl->buffer_32,
  104. sizeof(*wl->buffer_32), false);
  105. }
  106. static inline int __must_check wlcore_read(struct wl1271 *wl, int addr,
  107. void *buf, size_t len, bool fixed)
  108. {
  109. int physical;
  110. physical = wlcore_translate_addr(wl, addr);
  111. return wlcore_raw_read(wl, physical, buf, len, fixed);
  112. }
  113. static inline int __must_check wlcore_write(struct wl1271 *wl, int addr,
  114. void *buf, size_t len, bool fixed)
  115. {
  116. int physical;
  117. physical = wlcore_translate_addr(wl, addr);
  118. return wlcore_raw_write(wl, physical, buf, len, fixed);
  119. }
  120. static inline int __must_check wlcore_write_data(struct wl1271 *wl, int reg,
  121. void *buf, size_t len,
  122. bool fixed)
  123. {
  124. return wlcore_write(wl, wl->rtable[reg], buf, len, fixed);
  125. }
  126. static inline int __must_check wlcore_read_data(struct wl1271 *wl, int reg,
  127. void *buf, size_t len,
  128. bool fixed)
  129. {
  130. return wlcore_read(wl, wl->rtable[reg], buf, len, fixed);
  131. }
  132. static inline int __must_check wlcore_read_hwaddr(struct wl1271 *wl, int hwaddr,
  133. void *buf, size_t len,
  134. bool fixed)
  135. {
  136. int physical;
  137. int addr;
  138. /* Convert from FW internal address which is chip arch dependent */
  139. addr = wl->ops->convert_hwaddr(wl, hwaddr);
  140. physical = wlcore_translate_addr(wl, addr);
  141. return wlcore_raw_read(wl, physical, buf, len, fixed);
  142. }
  143. static inline int __must_check wlcore_read32(struct wl1271 *wl, int addr,
  144. u32 *val)
  145. {
  146. return wlcore_raw_read32(wl, wlcore_translate_addr(wl, addr), val);
  147. }
  148. static inline int __must_check wlcore_write32(struct wl1271 *wl, int addr,
  149. u32 val)
  150. {
  151. return wlcore_raw_write32(wl, wlcore_translate_addr(wl, addr), val);
  152. }
  153. static inline int __must_check wlcore_read_reg(struct wl1271 *wl, int reg,
  154. u32 *val)
  155. {
  156. return wlcore_raw_read32(wl,
  157. wlcore_translate_addr(wl, wl->rtable[reg]),
  158. val);
  159. }
  160. static inline int __must_check wlcore_write_reg(struct wl1271 *wl, int reg,
  161. u32 val)
  162. {
  163. return wlcore_raw_write32(wl,
  164. wlcore_translate_addr(wl, wl->rtable[reg]),
  165. val);
  166. }
  167. static inline void wl1271_power_off(struct wl1271 *wl)
  168. {
  169. int ret;
  170. if (!test_bit(WL1271_FLAG_GPIO_POWER, &wl->flags))
  171. return;
  172. ret = wl->if_ops->power(wl->dev, false);
  173. if (!ret)
  174. clear_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
  175. }
  176. static inline int wl1271_power_on(struct wl1271 *wl)
  177. {
  178. int ret = wl->if_ops->power(wl->dev, true);
  179. if (ret == 0)
  180. set_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
  181. return ret;
  182. }
  183. int wlcore_set_partition(struct wl1271 *wl,
  184. const struct wlcore_partition_set *p);
  185. bool wl1271_set_block_size(struct wl1271 *wl);
  186. /* Functions from wl1271_main.c */
  187. int wl1271_tx_dummy_packet(struct wl1271 *wl);
  188. #endif