18c2ecf20Sopenharmony_ci/**
28c2ecf20Sopenharmony_ci * @section LICENSE
38c2ecf20Sopenharmony_ci * Copyright (c) 2014 Redpine Signals Inc.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Permission to use, copy, modify, and/or distribute this software for any
68c2ecf20Sopenharmony_ci * purpose with or without fee is hereby granted, provided that the above
78c2ecf20Sopenharmony_ci * copyright notice and this permission notice appear in all copies.
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
108c2ecf20Sopenharmony_ci * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
118c2ecf20Sopenharmony_ci * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
128c2ecf20Sopenharmony_ci * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
138c2ecf20Sopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
148c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
158c2ecf20Sopenharmony_ci * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
168c2ecf20Sopenharmony_ci *
178c2ecf20Sopenharmony_ci */
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#ifndef __RSI_SDIO_INTF__
208c2ecf20Sopenharmony_ci#define __RSI_SDIO_INTF__
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#include <linux/mmc/card.h>
238c2ecf20Sopenharmony_ci#include <linux/mmc/mmc.h>
248c2ecf20Sopenharmony_ci#include <linux/mmc/host.h>
258c2ecf20Sopenharmony_ci#include <linux/mmc/sdio_func.h>
268c2ecf20Sopenharmony_ci#include <linux/mmc/sdio.h>
278c2ecf20Sopenharmony_ci#include <linux/mmc/sd.h>
288c2ecf20Sopenharmony_ci#include <linux/mmc/sdio_ids.h>
298c2ecf20Sopenharmony_ci#include "rsi_main.h"
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_cienum sdio_interrupt_type {
328c2ecf20Sopenharmony_ci	BUFFER_FULL         = 0x0,
338c2ecf20Sopenharmony_ci	BUFFER_AVAILABLE    = 0x2,
348c2ecf20Sopenharmony_ci	FIRMWARE_ASSERT_IND = 0x3,
358c2ecf20Sopenharmony_ci	MSDU_PACKET_PENDING = 0x4,
368c2ecf20Sopenharmony_ci	UNKNOWN_INT         = 0XE
378c2ecf20Sopenharmony_ci};
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci/* Buffer status register related info */
408c2ecf20Sopenharmony_ci#define PKT_BUFF_SEMI_FULL                      0
418c2ecf20Sopenharmony_ci#define PKT_BUFF_FULL                           1
428c2ecf20Sopenharmony_ci#define PKT_MGMT_BUFF_FULL                      2
438c2ecf20Sopenharmony_ci#define MSDU_PKT_PENDING                        3
448c2ecf20Sopenharmony_ci#define RECV_NUM_BLOCKS                         4
458c2ecf20Sopenharmony_ci/* Interrupt Bit Related Macros */
468c2ecf20Sopenharmony_ci#define PKT_BUFF_AVAILABLE                      1
478c2ecf20Sopenharmony_ci#define FW_ASSERT_IND                           2
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci#define RSI_MASTER_REG_BUF_SIZE			12
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#define RSI_DEVICE_BUFFER_STATUS_REGISTER       0xf3
528c2ecf20Sopenharmony_ci#define RSI_FN1_INT_REGISTER                    0xf9
538c2ecf20Sopenharmony_ci#define RSI_INT_ENABLE_REGISTER			0x04
548c2ecf20Sopenharmony_ci#define RSI_INT_ENABLE_MASK			0xfc
558c2ecf20Sopenharmony_ci#define RSI_SD_REQUEST_MASTER                   0x10000
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci/* FOR SD CARD ONLY */
588c2ecf20Sopenharmony_ci#define SDIO_RX_NUM_BLOCKS_REG                  0x000F1
598c2ecf20Sopenharmony_ci#define SDIO_FW_STATUS_REG                      0x000F2
608c2ecf20Sopenharmony_ci#define SDIO_NXT_RD_DELAY2                      0x000F5
618c2ecf20Sopenharmony_ci#define SDIO_MASTER_ACCESS_MSBYTE               0x000FA
628c2ecf20Sopenharmony_ci#define SDIO_MASTER_ACCESS_LSBYTE               0x000FB
638c2ecf20Sopenharmony_ci#define SDIO_READ_START_LVL                     0x000FC
648c2ecf20Sopenharmony_ci#define SDIO_READ_FIFO_CTL                      0x000FD
658c2ecf20Sopenharmony_ci#define SDIO_WRITE_FIFO_CTL                     0x000FE
668c2ecf20Sopenharmony_ci#define SDIO_WAKEUP_REG				0x000FF
678c2ecf20Sopenharmony_ci#define SDIO_FUN1_INTR_CLR_REG                  0x0008
688c2ecf20Sopenharmony_ci#define SDIO_REG_HIGH_SPEED                     0x0013
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci#define RSI_GET_SDIO_INTERRUPT_TYPE(_I, TYPE)      \
718c2ecf20Sopenharmony_ci	{					   \
728c2ecf20Sopenharmony_ci		TYPE =                             \
738c2ecf20Sopenharmony_ci		(_I & (1 << PKT_BUFF_AVAILABLE)) ? \
748c2ecf20Sopenharmony_ci		BUFFER_AVAILABLE :		   \
758c2ecf20Sopenharmony_ci		(_I & (1 << MSDU_PKT_PENDING)) ?   \
768c2ecf20Sopenharmony_ci		MSDU_PACKET_PENDING :              \
778c2ecf20Sopenharmony_ci		(_I & (1 << FW_ASSERT_IND)) ?      \
788c2ecf20Sopenharmony_ci		FIRMWARE_ASSERT_IND : UNKNOWN_INT; \
798c2ecf20Sopenharmony_ci	}
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci/* common registers in SDIO function1 */
828c2ecf20Sopenharmony_ci#define TA_SOFT_RESET_REG            0x0004
838c2ecf20Sopenharmony_ci#define TA_TH0_PC_REG                0x0400
848c2ecf20Sopenharmony_ci#define TA_HOLD_THREAD_REG           0x0844
858c2ecf20Sopenharmony_ci#define TA_RELEASE_THREAD_REG        0x0848
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci#define TA_SOFT_RST_CLR              0
888c2ecf20Sopenharmony_ci#define TA_SOFT_RST_SET              BIT(0)
898c2ecf20Sopenharmony_ci#define TA_PC_ZERO                   0
908c2ecf20Sopenharmony_ci#define TA_HOLD_THREAD_VALUE         0xF
918c2ecf20Sopenharmony_ci#define TA_RELEASE_THREAD_VALUE      0xF
928c2ecf20Sopenharmony_ci#define TA_BASE_ADDR                 0x2200
938c2ecf20Sopenharmony_ci#define MISC_CFG_BASE_ADDR           0x4105
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_cistruct receive_info {
968c2ecf20Sopenharmony_ci	bool buffer_full;
978c2ecf20Sopenharmony_ci	bool semi_buffer_full;
988c2ecf20Sopenharmony_ci	bool mgmt_buffer_full;
998c2ecf20Sopenharmony_ci	u32 mgmt_buf_full_counter;
1008c2ecf20Sopenharmony_ci	u32 buf_semi_full_counter;
1018c2ecf20Sopenharmony_ci	u8 watch_bufferfull_count;
1028c2ecf20Sopenharmony_ci	u32 sdio_intr_status_zero;
1038c2ecf20Sopenharmony_ci	u32 sdio_int_counter;
1048c2ecf20Sopenharmony_ci	u32 total_sdio_msdu_pending_intr;
1058c2ecf20Sopenharmony_ci	u32 total_sdio_unknown_intr;
1068c2ecf20Sopenharmony_ci	u32 buf_full_counter;
1078c2ecf20Sopenharmony_ci	u32 buf_available_counter;
1088c2ecf20Sopenharmony_ci};
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_cistruct rsi_91x_sdiodev {
1118c2ecf20Sopenharmony_ci	struct sdio_func *pfunction;
1128c2ecf20Sopenharmony_ci	struct task_struct *sdio_irq_task;
1138c2ecf20Sopenharmony_ci	struct receive_info rx_info;
1148c2ecf20Sopenharmony_ci	u32 next_read_delay;
1158c2ecf20Sopenharmony_ci	u32 sdio_high_speed_enable;
1168c2ecf20Sopenharmony_ci	u8 sdio_clock_speed;
1178c2ecf20Sopenharmony_ci	u32 cardcapability;
1188c2ecf20Sopenharmony_ci	u8 prev_desc[16];
1198c2ecf20Sopenharmony_ci	u16 tx_blk_size;
1208c2ecf20Sopenharmony_ci	u8 write_fail;
1218c2ecf20Sopenharmony_ci	bool buff_status_updated;
1228c2ecf20Sopenharmony_ci	struct rsi_thread rx_thread;
1238c2ecf20Sopenharmony_ci	u8 pktbuffer[8192] __aligned(4);
1248c2ecf20Sopenharmony_ci};
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ciint rsi_init_sdio_slave_regs(struct rsi_hw *adapter);
1278c2ecf20Sopenharmony_ciint rsi_sdio_read_register(struct rsi_hw *adapter, u32 addr, u8 *data);
1288c2ecf20Sopenharmony_ciint rsi_sdio_host_intf_read_pkt(struct rsi_hw *adapter, u8 *pkt, u32 length);
1298c2ecf20Sopenharmony_ciint rsi_sdio_write_register(struct rsi_hw *adapter, u8 function,
1308c2ecf20Sopenharmony_ci			    u32 addr, u8 *data);
1318c2ecf20Sopenharmony_ciint rsi_sdio_write_register_multiple(struct rsi_hw *adapter, u32 addr,
1328c2ecf20Sopenharmony_ci				     u8 *data, u16 count);
1338c2ecf20Sopenharmony_ciint rsi_sdio_master_access_msword(struct rsi_hw *adapter, u16 ms_word);
1348c2ecf20Sopenharmony_civoid rsi_sdio_ack_intr(struct rsi_hw *adapter, u8 int_bit);
1358c2ecf20Sopenharmony_ciint rsi_sdio_determine_event_timeout(struct rsi_hw *adapter);
1368c2ecf20Sopenharmony_ciint rsi_sdio_check_buffer_status(struct rsi_hw *adapter, u8 q_num);
1378c2ecf20Sopenharmony_civoid rsi_sdio_rx_thread(struct rsi_common *common);
1388c2ecf20Sopenharmony_ci#endif
139