io.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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 wlcore_raw_write(struct wl1271 *wl, int addr, void *buf,
  47. size_t len, bool fixed)
  48. {
  49. return wl->if_ops->write(wl->dev, addr, buf, len, fixed);
  50. }
  51. static inline int wlcore_raw_read(struct wl1271 *wl, int addr, void *buf,
  52. size_t len, bool fixed)
  53. {
  54. return wl->if_ops->read(wl->dev, addr, buf, len, fixed);
  55. }
  56. static inline int wlcore_raw_read_data(struct wl1271 *wl, int reg, void *buf,
  57. size_t len, bool fixed)
  58. {
  59. return wlcore_raw_read(wl, wl->rtable[reg], buf, len, fixed);
  60. }
  61. static inline int wlcore_raw_write_data(struct wl1271 *wl, int reg, void *buf,
  62. size_t len, bool fixed)
  63. {
  64. return wlcore_raw_write(wl, wl->rtable[reg], buf, len, fixed);
  65. }
  66. static inline u32 wl1271_raw_read32(struct wl1271 *wl, int addr)
  67. {
  68. wlcore_raw_read(wl, addr, &wl->buffer_32,
  69. sizeof(wl->buffer_32), false);
  70. return le32_to_cpu(wl->buffer_32);
  71. }
  72. static inline void wl1271_raw_write32(struct wl1271 *wl, int addr, u32 val)
  73. {
  74. wl->buffer_32 = cpu_to_le32(val);
  75. wlcore_raw_write(wl, addr, &wl->buffer_32,
  76. sizeof(wl->buffer_32), false);
  77. }
  78. static inline int wlcore_read(struct wl1271 *wl, int addr, void *buf,
  79. size_t len, bool fixed)
  80. {
  81. int physical;
  82. physical = wlcore_translate_addr(wl, addr);
  83. return wlcore_raw_read(wl, physical, buf, len, fixed);
  84. }
  85. static inline void wl1271_write(struct wl1271 *wl, int addr, void *buf,
  86. size_t len, bool fixed)
  87. {
  88. int physical;
  89. physical = wlcore_translate_addr(wl, addr);
  90. wlcore_raw_write(wl, physical, buf, len, fixed);
  91. }
  92. static inline void wlcore_write_data(struct wl1271 *wl, int reg, void *buf,
  93. size_t len, bool fixed)
  94. {
  95. wl1271_write(wl, wl->rtable[reg], buf, len, fixed);
  96. }
  97. static inline int wlcore_read_data(struct wl1271 *wl, int reg, void *buf,
  98. size_t len, bool fixed)
  99. {
  100. return wlcore_read(wl, wl->rtable[reg], buf, len, fixed);
  101. }
  102. static inline void wl1271_read_hwaddr(struct wl1271 *wl, int hwaddr,
  103. void *buf, size_t len, bool fixed)
  104. {
  105. int physical;
  106. int addr;
  107. /* Addresses are stored internally as addresses to 32 bytes blocks */
  108. addr = hwaddr << 5;
  109. physical = wlcore_translate_addr(wl, addr);
  110. wlcore_raw_read(wl, physical, buf, len, fixed);
  111. }
  112. static inline u32 wl1271_read32(struct wl1271 *wl, int addr)
  113. {
  114. return wl1271_raw_read32(wl, wlcore_translate_addr(wl, addr));
  115. }
  116. static inline void wl1271_write32(struct wl1271 *wl, int addr, u32 val)
  117. {
  118. wl1271_raw_write32(wl, wlcore_translate_addr(wl, addr), val);
  119. }
  120. static inline u32 wlcore_read_reg(struct wl1271 *wl, int reg)
  121. {
  122. return wl1271_raw_read32(wl,
  123. wlcore_translate_addr(wl, wl->rtable[reg]));
  124. }
  125. static inline void wlcore_write_reg(struct wl1271 *wl, int reg, u32 val)
  126. {
  127. wl1271_raw_write32(wl, wlcore_translate_addr(wl, wl->rtable[reg]), val);
  128. }
  129. static inline void wl1271_power_off(struct wl1271 *wl)
  130. {
  131. int ret;
  132. if (!test_bit(WL1271_FLAG_GPIO_POWER, &wl->flags))
  133. return;
  134. ret = wl->if_ops->power(wl->dev, false);
  135. if (!ret)
  136. clear_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
  137. }
  138. static inline int wl1271_power_on(struct wl1271 *wl)
  139. {
  140. int ret = wl->if_ops->power(wl->dev, true);
  141. if (ret == 0)
  142. set_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
  143. return ret;
  144. }
  145. void wlcore_set_partition(struct wl1271 *wl,
  146. const struct wlcore_partition_set *p);
  147. bool wl1271_set_block_size(struct wl1271 *wl);
  148. /* Functions from wl1271_main.c */
  149. int wl1271_tx_dummy_packet(struct wl1271 *wl);
  150. void wlcore_select_partition(struct wl1271 *wl, u8 part);
  151. #endif