io.h 6.1 KB

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