io.h 6.5 KB

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