io.h 5.1 KB

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