rsi_sdio.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /**
  2. * @section LICENSE
  3. * Copyright (c) 2014 Redpine Signals Inc.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. *
  17. */
  18. #ifndef __RSI_SDIO_INTF__
  19. #define __RSI_SDIO_INTF__
  20. #include <linux/mmc/card.h>
  21. #include <linux/mmc/mmc.h>
  22. #include <linux/mmc/host.h>
  23. #include <linux/mmc/sdio_func.h>
  24. #include <linux/mmc/sdio.h>
  25. #include <linux/mmc/sd.h>
  26. #include <linux/mmc/sdio_ids.h>
  27. #include "rsi_main.h"
  28. enum sdio_interrupt_type {
  29. BUFFER_FULL = 0x0,
  30. BUFFER_AVAILABLE = 0x2,
  31. FIRMWARE_ASSERT_IND = 0x3,
  32. MSDU_PACKET_PENDING = 0x4,
  33. UNKNOWN_INT = 0XE
  34. };
  35. /* Buffer status register related info */
  36. #define PKT_BUFF_SEMI_FULL 0
  37. #define PKT_BUFF_FULL 1
  38. #define PKT_MGMT_BUFF_FULL 2
  39. #define MSDU_PKT_PENDING 3
  40. /* Interrupt Bit Related Macros */
  41. #define PKT_BUFF_AVAILABLE 1
  42. #define FW_ASSERT_IND 2
  43. #define RSI_DEVICE_BUFFER_STATUS_REGISTER 0xf3
  44. #define RSI_FN1_INT_REGISTER 0xf9
  45. #define RSI_SD_REQUEST_MASTER 0x10000
  46. /* FOR SD CARD ONLY */
  47. #define SDIO_RX_NUM_BLOCKS_REG 0x000F1
  48. #define SDIO_FW_STATUS_REG 0x000F2
  49. #define SDIO_NXT_RD_DELAY2 0x000F5
  50. #define SDIO_MASTER_ACCESS_MSBYTE 0x000FA
  51. #define SDIO_MASTER_ACCESS_LSBYTE 0x000FB
  52. #define SDIO_READ_START_LVL 0x000FC
  53. #define SDIO_READ_FIFO_CTL 0x000FD
  54. #define SDIO_WRITE_FIFO_CTL 0x000FE
  55. #define SDIO_FUN1_INTR_CLR_REG 0x0008
  56. #define SDIO_REG_HIGH_SPEED 0x0013
  57. #define RSI_GET_SDIO_INTERRUPT_TYPE(_I, TYPE) \
  58. { \
  59. TYPE = \
  60. (_I & (1 << PKT_BUFF_AVAILABLE)) ? \
  61. BUFFER_AVAILABLE : \
  62. (_I & (1 << MSDU_PKT_PENDING)) ? \
  63. MSDU_PACKET_PENDING : \
  64. (_I & (1 << FW_ASSERT_IND)) ? \
  65. FIRMWARE_ASSERT_IND : UNKNOWN_INT; \
  66. }
  67. /* common registers in SDIO function1 */
  68. #define TA_SOFT_RESET_REG 0x0004
  69. #define TA_TH0_PC_REG 0x0400
  70. #define TA_HOLD_THREAD_REG 0x0844
  71. #define TA_RELEASE_THREAD_REG 0x0848
  72. #define TA_SOFT_RST_CLR 0
  73. #define TA_SOFT_RST_SET BIT(0)
  74. #define TA_PC_ZERO 0
  75. #define TA_HOLD_THREAD_VALUE cpu_to_le32(0xF)
  76. #define TA_RELEASE_THREAD_VALUE cpu_to_le32(0xF)
  77. #define TA_BASE_ADDR 0x2200
  78. #define MISC_CFG_BASE_ADDR 0x4105
  79. struct receive_info {
  80. bool buffer_full;
  81. bool semi_buffer_full;
  82. bool mgmt_buffer_full;
  83. u32 mgmt_buf_full_counter;
  84. u32 buf_semi_full_counter;
  85. u8 watch_bufferfull_count;
  86. u32 sdio_intr_status_zero;
  87. u32 sdio_int_counter;
  88. u32 total_sdio_msdu_pending_intr;
  89. u32 total_sdio_unknown_intr;
  90. u32 buf_full_counter;
  91. u32 buf_available_counter;
  92. };
  93. struct rsi_91x_sdiodev {
  94. struct sdio_func *pfunction;
  95. struct task_struct *in_sdio_litefi_irq;
  96. struct receive_info rx_info;
  97. u32 next_read_delay;
  98. u32 sdio_high_speed_enable;
  99. u8 sdio_clock_speed;
  100. u32 cardcapability;
  101. u8 prev_desc[16];
  102. u32 tx_blk_size;
  103. u8 write_fail;
  104. };
  105. void rsi_interrupt_handler(struct rsi_hw *adapter);
  106. int rsi_init_sdio_slave_regs(struct rsi_hw *adapter);
  107. int rsi_sdio_device_init(struct rsi_common *common);
  108. int rsi_sdio_read_register(struct rsi_hw *adapter, u32 addr, u8 *data);
  109. int rsi_sdio_host_intf_read_pkt(struct rsi_hw *adapter, u8 *pkt, u32 length);
  110. int rsi_sdio_write_register(struct rsi_hw *adapter, u8 function,
  111. u32 addr, u8 *data);
  112. int rsi_sdio_write_register_multiple(struct rsi_hw *adapter, u32 addr,
  113. u8 *data, u32 count);
  114. void rsi_sdio_ack_intr(struct rsi_hw *adapter, u8 int_bit);
  115. int rsi_sdio_determine_event_timeout(struct rsi_hw *adapter);
  116. int rsi_sdio_read_buffer_status_register(struct rsi_hw *adapter, u8 q_num);
  117. #endif