162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * @section LICENSE
362306a36Sopenharmony_ci * Copyright (c) 2014 Redpine Signals Inc.
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Permission to use, copy, modify, and/or distribute this software for any
662306a36Sopenharmony_ci * purpose with or without fee is hereby granted, provided that the above
762306a36Sopenharmony_ci * copyright notice and this permission notice appear in all copies.
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1062306a36Sopenharmony_ci * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1162306a36Sopenharmony_ci * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1262306a36Sopenharmony_ci * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1362306a36Sopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1462306a36Sopenharmony_ci * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1562306a36Sopenharmony_ci * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1662306a36Sopenharmony_ci *
1762306a36Sopenharmony_ci */
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci#ifndef __RSI_SDIO_INTF__
2062306a36Sopenharmony_ci#define __RSI_SDIO_INTF__
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci#include <linux/mmc/card.h>
2362306a36Sopenharmony_ci#include <linux/mmc/mmc.h>
2462306a36Sopenharmony_ci#include <linux/mmc/host.h>
2562306a36Sopenharmony_ci#include <linux/mmc/sdio_func.h>
2662306a36Sopenharmony_ci#include <linux/mmc/sdio.h>
2762306a36Sopenharmony_ci#include <linux/mmc/sd.h>
2862306a36Sopenharmony_ci#include <linux/mmc/sdio_ids.h>
2962306a36Sopenharmony_ci#include "rsi_main.h"
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_cienum sdio_interrupt_type {
3262306a36Sopenharmony_ci	BUFFER_FULL         = 0x0,
3362306a36Sopenharmony_ci	BUFFER_AVAILABLE    = 0x2,
3462306a36Sopenharmony_ci	FIRMWARE_ASSERT_IND = 0x3,
3562306a36Sopenharmony_ci	MSDU_PACKET_PENDING = 0x4,
3662306a36Sopenharmony_ci	UNKNOWN_INT         = 0XE
3762306a36Sopenharmony_ci};
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci/* Buffer status register related info */
4062306a36Sopenharmony_ci#define PKT_BUFF_SEMI_FULL                      0
4162306a36Sopenharmony_ci#define PKT_BUFF_FULL                           1
4262306a36Sopenharmony_ci#define PKT_MGMT_BUFF_FULL                      2
4362306a36Sopenharmony_ci#define MSDU_PKT_PENDING                        3
4462306a36Sopenharmony_ci#define RECV_NUM_BLOCKS                         4
4562306a36Sopenharmony_ci/* Interrupt Bit Related Macros */
4662306a36Sopenharmony_ci#define PKT_BUFF_AVAILABLE                      1
4762306a36Sopenharmony_ci#define FW_ASSERT_IND                           2
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci#define RSI_MASTER_REG_BUF_SIZE			12
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci#define RSI_DEVICE_BUFFER_STATUS_REGISTER       0xf3
5262306a36Sopenharmony_ci#define RSI_FN1_INT_REGISTER                    0xf9
5362306a36Sopenharmony_ci#define RSI_INT_ENABLE_REGISTER			0x04
5462306a36Sopenharmony_ci#define RSI_INT_ENABLE_MASK			0xfc
5562306a36Sopenharmony_ci#define RSI_SD_REQUEST_MASTER                   0x10000
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci/* FOR SD CARD ONLY */
5862306a36Sopenharmony_ci#define SDIO_RX_NUM_BLOCKS_REG                  0x000F1
5962306a36Sopenharmony_ci#define SDIO_FW_STATUS_REG                      0x000F2
6062306a36Sopenharmony_ci#define SDIO_NXT_RD_DELAY2                      0x000F5
6162306a36Sopenharmony_ci#define SDIO_MASTER_ACCESS_MSBYTE               0x000FA
6262306a36Sopenharmony_ci#define SDIO_MASTER_ACCESS_LSBYTE               0x000FB
6362306a36Sopenharmony_ci#define SDIO_READ_START_LVL                     0x000FC
6462306a36Sopenharmony_ci#define SDIO_READ_FIFO_CTL                      0x000FD
6562306a36Sopenharmony_ci#define SDIO_WRITE_FIFO_CTL                     0x000FE
6662306a36Sopenharmony_ci#define SDIO_WAKEUP_REG				0x000FF
6762306a36Sopenharmony_ci#define SDIO_FUN1_INTR_CLR_REG                  0x0008
6862306a36Sopenharmony_ci#define SDIO_REG_HIGH_SPEED                     0x0013
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ci#define RSI_GET_SDIO_INTERRUPT_TYPE(_I, TYPE)      \
7162306a36Sopenharmony_ci	{					   \
7262306a36Sopenharmony_ci		TYPE =                             \
7362306a36Sopenharmony_ci		(_I & (1 << PKT_BUFF_AVAILABLE)) ? \
7462306a36Sopenharmony_ci		BUFFER_AVAILABLE :		   \
7562306a36Sopenharmony_ci		(_I & (1 << MSDU_PKT_PENDING)) ?   \
7662306a36Sopenharmony_ci		MSDU_PACKET_PENDING :              \
7762306a36Sopenharmony_ci		(_I & (1 << FW_ASSERT_IND)) ?      \
7862306a36Sopenharmony_ci		FIRMWARE_ASSERT_IND : UNKNOWN_INT; \
7962306a36Sopenharmony_ci	}
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci/* common registers in SDIO function1 */
8262306a36Sopenharmony_ci#define TA_SOFT_RESET_REG            0x0004
8362306a36Sopenharmony_ci#define TA_TH0_PC_REG                0x0400
8462306a36Sopenharmony_ci#define TA_HOLD_THREAD_REG           0x0844
8562306a36Sopenharmony_ci#define TA_RELEASE_THREAD_REG        0x0848
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci#define TA_SOFT_RST_CLR              0
8862306a36Sopenharmony_ci#define TA_SOFT_RST_SET              BIT(0)
8962306a36Sopenharmony_ci#define TA_PC_ZERO                   0
9062306a36Sopenharmony_ci#define TA_HOLD_THREAD_VALUE         0xF
9162306a36Sopenharmony_ci#define TA_RELEASE_THREAD_VALUE      0xF
9262306a36Sopenharmony_ci#define TA_BASE_ADDR                 0x2200
9362306a36Sopenharmony_ci#define MISC_CFG_BASE_ADDR           0x4105
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_cistruct receive_info {
9662306a36Sopenharmony_ci	bool buffer_full;
9762306a36Sopenharmony_ci	bool semi_buffer_full;
9862306a36Sopenharmony_ci	bool mgmt_buffer_full;
9962306a36Sopenharmony_ci	u32 mgmt_buf_full_counter;
10062306a36Sopenharmony_ci	u32 buf_semi_full_counter;
10162306a36Sopenharmony_ci	u8 watch_bufferfull_count;
10262306a36Sopenharmony_ci	u32 sdio_intr_status_zero;
10362306a36Sopenharmony_ci	u32 sdio_int_counter;
10462306a36Sopenharmony_ci	u32 total_sdio_msdu_pending_intr;
10562306a36Sopenharmony_ci	u32 total_sdio_unknown_intr;
10662306a36Sopenharmony_ci	u32 buf_full_counter;
10762306a36Sopenharmony_ci	u32 buf_available_counter;
10862306a36Sopenharmony_ci};
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_cistruct rsi_91x_sdiodev {
11162306a36Sopenharmony_ci	struct sdio_func *pfunction;
11262306a36Sopenharmony_ci	struct task_struct *sdio_irq_task;
11362306a36Sopenharmony_ci	struct receive_info rx_info;
11462306a36Sopenharmony_ci	u32 next_read_delay;
11562306a36Sopenharmony_ci	u32 sdio_high_speed_enable;
11662306a36Sopenharmony_ci	u8 sdio_clock_speed;
11762306a36Sopenharmony_ci	u32 cardcapability;
11862306a36Sopenharmony_ci	u8 prev_desc[16];
11962306a36Sopenharmony_ci	u16 tx_blk_size;
12062306a36Sopenharmony_ci	u8 write_fail;
12162306a36Sopenharmony_ci	bool buff_status_updated;
12262306a36Sopenharmony_ci	struct rsi_thread rx_thread;
12362306a36Sopenharmony_ci	u8 pktbuffer[8192] __aligned(4);
12462306a36Sopenharmony_ci};
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ciint rsi_init_sdio_slave_regs(struct rsi_hw *adapter);
12762306a36Sopenharmony_ciint rsi_sdio_read_register(struct rsi_hw *adapter, u32 addr, u8 *data);
12862306a36Sopenharmony_ciint rsi_sdio_host_intf_read_pkt(struct rsi_hw *adapter, u8 *pkt, u32 length);
12962306a36Sopenharmony_ciint rsi_sdio_write_register(struct rsi_hw *adapter, u8 function,
13062306a36Sopenharmony_ci			    u32 addr, u8 *data);
13162306a36Sopenharmony_ciint rsi_sdio_write_register_multiple(struct rsi_hw *adapter, u32 addr,
13262306a36Sopenharmony_ci				     u8 *data, u16 count);
13362306a36Sopenharmony_ciint rsi_sdio_master_access_msword(struct rsi_hw *adapter, u16 ms_word);
13462306a36Sopenharmony_civoid rsi_sdio_ack_intr(struct rsi_hw *adapter, u8 int_bit);
13562306a36Sopenharmony_ciint rsi_sdio_determine_event_timeout(struct rsi_hw *adapter);
13662306a36Sopenharmony_ciint rsi_sdio_check_buffer_status(struct rsi_hw *adapter, u8 q_num);
13762306a36Sopenharmony_civoid rsi_sdio_rx_thread(struct rsi_common *common);
13862306a36Sopenharmony_ci#endif
139