io.h 6.0 KB

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