162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
262306a36Sopenharmony_ci/* Copyright (C) 2021 Martin Blumenstingl <martin.blumenstingl@googlemail.com>
362306a36Sopenharmony_ci * Copyright (C) 2021 Jernej Skrabec <jernej.skrabec@gmail.com>
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#ifndef __REG_SDIO_H_
762306a36Sopenharmony_ci#define __REG_SDIO_H_
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci/* I/O bus domain address mapping */
1062306a36Sopenharmony_ci#define SDIO_LOCAL_OFFSET			0x10250000
1162306a36Sopenharmony_ci#define WLAN_IOREG_OFFSET			0x10260000
1262306a36Sopenharmony_ci#define FIRMWARE_FIFO_OFFSET			0x10270000
1362306a36Sopenharmony_ci#define TX_HIQ_OFFSET				0x10310000
1462306a36Sopenharmony_ci#define TX_MIQ_OFFSET				0x10320000
1562306a36Sopenharmony_ci#define TX_LOQ_OFFSET				0x10330000
1662306a36Sopenharmony_ci#define TX_EPQ_OFFSET				0x10350000
1762306a36Sopenharmony_ci#define RX_RX0FF_OFFSET				0x10340000
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci#define RTW_SDIO_BUS_MSK			0xffff0000
2062306a36Sopenharmony_ci#define SDIO_LOCAL_REG_MSK			0x00000fff
2162306a36Sopenharmony_ci#define WLAN_IOREG_REG_MSK			0x0000ffff
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci/* SDIO Tx Control */
2462306a36Sopenharmony_ci#define REG_SDIO_TX_CTRL			(SDIO_LOCAL_OFFSET + 0x0000)
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci/*SDIO status timeout*/
2762306a36Sopenharmony_ci#define REG_SDIO_TIMEOUT			(SDIO_LOCAL_OFFSET + 0x0002)
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci/* SDIO Host Interrupt Mask */
3062306a36Sopenharmony_ci#define REG_SDIO_HIMR				(SDIO_LOCAL_OFFSET + 0x0014)
3162306a36Sopenharmony_ci#define REG_SDIO_HIMR_RX_REQUEST		BIT(0)
3262306a36Sopenharmony_ci#define REG_SDIO_HIMR_AVAL			BIT(1)
3362306a36Sopenharmony_ci#define REG_SDIO_HIMR_TXERR			BIT(2)
3462306a36Sopenharmony_ci#define REG_SDIO_HIMR_RXERR			BIT(3)
3562306a36Sopenharmony_ci#define REG_SDIO_HIMR_TXFOVW			BIT(4)
3662306a36Sopenharmony_ci#define REG_SDIO_HIMR_RXFOVW			BIT(5)
3762306a36Sopenharmony_ci#define REG_SDIO_HIMR_TXBCNOK			BIT(6)
3862306a36Sopenharmony_ci#define REG_SDIO_HIMR_TXBCNERR			BIT(7)
3962306a36Sopenharmony_ci#define REG_SDIO_HIMR_BCNERLY_INT		BIT(16)
4062306a36Sopenharmony_ci#define REG_SDIO_HIMR_C2HCMD			BIT(17)
4162306a36Sopenharmony_ci#define REG_SDIO_HIMR_CPWM1			BIT(18)
4262306a36Sopenharmony_ci#define REG_SDIO_HIMR_CPWM2			BIT(19)
4362306a36Sopenharmony_ci#define REG_SDIO_HIMR_HSISR_IND			BIT(20)
4462306a36Sopenharmony_ci#define REG_SDIO_HIMR_GTINT3_IND		BIT(21)
4562306a36Sopenharmony_ci#define REG_SDIO_HIMR_GTINT4_IND		BIT(22)
4662306a36Sopenharmony_ci#define REG_SDIO_HIMR_PSTIMEOUT			BIT(23)
4762306a36Sopenharmony_ci#define REG_SDIO_HIMR_OCPINT			BIT(24)
4862306a36Sopenharmony_ci#define REG_SDIO_HIMR_ATIMEND			BIT(25)
4962306a36Sopenharmony_ci#define REG_SDIO_HIMR_ATIMEND_E			BIT(26)
5062306a36Sopenharmony_ci#define REG_SDIO_HIMR_CTWEND			BIT(27)
5162306a36Sopenharmony_ci/* the following two are RTL8188 SDIO Specific */
5262306a36Sopenharmony_ci#define REG_SDIO_HIMR_MCU_ERR			BIT(28)
5362306a36Sopenharmony_ci#define REG_SDIO_HIMR_TSF_BIT32_TOGGLE		BIT(29)
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci/* SDIO Host Interrupt Service Routine */
5662306a36Sopenharmony_ci#define REG_SDIO_HISR				(SDIO_LOCAL_OFFSET + 0x0018)
5762306a36Sopenharmony_ci#define REG_SDIO_HISR_RX_REQUEST		BIT(0)
5862306a36Sopenharmony_ci#define REG_SDIO_HISR_AVAL			BIT(1)
5962306a36Sopenharmony_ci#define REG_SDIO_HISR_TXERR			BIT(2)
6062306a36Sopenharmony_ci#define REG_SDIO_HISR_RXERR			BIT(3)
6162306a36Sopenharmony_ci#define REG_SDIO_HISR_TXFOVW			BIT(4)
6262306a36Sopenharmony_ci#define REG_SDIO_HISR_RXFOVW			BIT(5)
6362306a36Sopenharmony_ci#define REG_SDIO_HISR_TXBCNOK			BIT(6)
6462306a36Sopenharmony_ci#define REG_SDIO_HISR_TXBCNERR			BIT(7)
6562306a36Sopenharmony_ci#define REG_SDIO_HISR_BCNERLY_INT		BIT(16)
6662306a36Sopenharmony_ci#define REG_SDIO_HISR_C2HCMD			BIT(17)
6762306a36Sopenharmony_ci#define REG_SDIO_HISR_CPWM1			BIT(18)
6862306a36Sopenharmony_ci#define REG_SDIO_HISR_CPWM2			BIT(19)
6962306a36Sopenharmony_ci#define REG_SDIO_HISR_HSISR_IND			BIT(20)
7062306a36Sopenharmony_ci#define REG_SDIO_HISR_GTINT3_IND		BIT(21)
7162306a36Sopenharmony_ci#define REG_SDIO_HISR_GTINT4_IND		BIT(22)
7262306a36Sopenharmony_ci#define REG_SDIO_HISR_PSTIMEOUT			BIT(23)
7362306a36Sopenharmony_ci#define REG_SDIO_HISR_OCPINT			BIT(24)
7462306a36Sopenharmony_ci#define REG_SDIO_HISR_ATIMEND			BIT(25)
7562306a36Sopenharmony_ci#define REG_SDIO_HISR_ATIMEND_E			BIT(26)
7662306a36Sopenharmony_ci#define REG_SDIO_HISR_CTWEND			BIT(27)
7762306a36Sopenharmony_ci/* the following two are RTL8188 SDIO Specific */
7862306a36Sopenharmony_ci#define REG_SDIO_HISR_MCU_ERR			BIT(28)
7962306a36Sopenharmony_ci#define REG_SDIO_HISR_TSF_BIT32_TOGGLE		BIT(29)
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci/* HCI Current Power Mode */
8262306a36Sopenharmony_ci#define REG_SDIO_HCPWM				(SDIO_LOCAL_OFFSET + 0x0019)
8362306a36Sopenharmony_ci/* RXDMA Request Length */
8462306a36Sopenharmony_ci#define REG_SDIO_RX0_REQ_LEN			(SDIO_LOCAL_OFFSET + 0x001C)
8562306a36Sopenharmony_ci/* OQT Free Page */
8662306a36Sopenharmony_ci#define REG_SDIO_OQT_FREE_PG			(SDIO_LOCAL_OFFSET + 0x001E)
8762306a36Sopenharmony_ci/* Free Tx Buffer Page */
8862306a36Sopenharmony_ci#define REG_SDIO_FREE_TXPG			(SDIO_LOCAL_OFFSET + 0x0020)
8962306a36Sopenharmony_ci/* HCI Current Power Mode 1 */
9062306a36Sopenharmony_ci#define REG_SDIO_HCPWM1				(SDIO_LOCAL_OFFSET + 0x0024)
9162306a36Sopenharmony_ci/* HCI Current Power Mode 2 */
9262306a36Sopenharmony_ci#define REG_SDIO_HCPWM2				(SDIO_LOCAL_OFFSET + 0x0026)
9362306a36Sopenharmony_ci/* Free Tx Page Sequence */
9462306a36Sopenharmony_ci#define REG_SDIO_FREE_TXPG_SEQ			(SDIO_LOCAL_OFFSET + 0x0028)
9562306a36Sopenharmony_ci/* HTSF Information */
9662306a36Sopenharmony_ci#define REG_SDIO_HTSFR_INFO			(SDIO_LOCAL_OFFSET + 0x0030)
9762306a36Sopenharmony_ci#define REG_SDIO_HCPWM1_V2			(SDIO_LOCAL_OFFSET + 0x0038)
9862306a36Sopenharmony_ci/* H2C */
9962306a36Sopenharmony_ci#define REG_SDIO_H2C				(SDIO_LOCAL_OFFSET + 0x0060)
10062306a36Sopenharmony_ci/* HCI Request Power Mode 1 */
10162306a36Sopenharmony_ci#define REG_SDIO_HRPWM1				(SDIO_LOCAL_OFFSET + 0x0080)
10262306a36Sopenharmony_ci/* HCI Request Power Mode 2 */
10362306a36Sopenharmony_ci#define REG_SDIO_HRPWM2				(SDIO_LOCAL_OFFSET + 0x0082)
10462306a36Sopenharmony_ci/* HCI Power Save Clock */
10562306a36Sopenharmony_ci#define REG_SDIO_HPS_CLKR			(SDIO_LOCAL_OFFSET + 0x0084)
10662306a36Sopenharmony_ci/* SDIO HCI Suspend Control */
10762306a36Sopenharmony_ci#define REG_SDIO_HSUS_CTRL			(SDIO_LOCAL_OFFSET + 0x0086)
10862306a36Sopenharmony_ci#define BIT_HCI_SUS_REQ				BIT(0)
10962306a36Sopenharmony_ci#define BIT_HCI_RESUME_RDY			BIT(1)
11062306a36Sopenharmony_ci/* SDIO Host Extension Interrupt Mask Always */
11162306a36Sopenharmony_ci#define REG_SDIO_HIMR_ON			(SDIO_LOCAL_OFFSET + 0x0090)
11262306a36Sopenharmony_ci/* SDIO Host Extension Interrupt Status Always */
11362306a36Sopenharmony_ci#define REG_SDIO_HISR_ON			(SDIO_LOCAL_OFFSET + 0x0091)
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci#define REG_SDIO_INDIRECT_REG_CFG		(SDIO_LOCAL_OFFSET + 0x0040)
11662306a36Sopenharmony_ci#define BIT_SDIO_INDIRECT_REG_CFG_WORD		BIT(16)
11762306a36Sopenharmony_ci#define BIT_SDIO_INDIRECT_REG_CFG_DWORD		BIT(17)
11862306a36Sopenharmony_ci#define BIT_SDIO_INDIRECT_REG_CFG_WRITE		BIT(18)
11962306a36Sopenharmony_ci#define BIT_SDIO_INDIRECT_REG_CFG_READ		BIT(19)
12062306a36Sopenharmony_ci#define BIT_SDIO_INDIRECT_REG_CFG_UNK20		BIT(20)
12162306a36Sopenharmony_ci#define REG_SDIO_INDIRECT_REG_DATA		(SDIO_LOCAL_OFFSET + 0x0044)
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_ci/* Sdio Address for SDIO Local Reg, TRX FIFO, MAC Reg */
12462306a36Sopenharmony_ci#define REG_SDIO_CMD_ADDR_MSK			GENMASK(16, 13)
12562306a36Sopenharmony_ci#define REG_SDIO_CMD_ADDR_SDIO_REG		0
12662306a36Sopenharmony_ci#define REG_SDIO_CMD_ADDR_MAC_REG		8
12762306a36Sopenharmony_ci#define REG_SDIO_CMD_ADDR_TXFF_HIGH		4
12862306a36Sopenharmony_ci#define REG_SDIO_CMD_ADDR_TXFF_LOW		6
12962306a36Sopenharmony_ci#define REG_SDIO_CMD_ADDR_TXFF_NORMAL		5
13062306a36Sopenharmony_ci#define REG_SDIO_CMD_ADDR_TXFF_EXTRA		7
13162306a36Sopenharmony_ci#define REG_SDIO_CMD_ADDR_RXFF			7
13262306a36Sopenharmony_ci
13362306a36Sopenharmony_ci#define RTW_SDIO_BLOCK_SIZE			512
13462306a36Sopenharmony_ci#define RTW_SDIO_ADDR_RX_RX0FF_GEN(_id)		(0x0e000 | ((_id) & 0x3))
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci#define RTW_SDIO_DATA_PTR_ALIGN			8
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_cistruct sdio_func;
13962306a36Sopenharmony_cistruct sdio_device_id;
14062306a36Sopenharmony_ci
14162306a36Sopenharmony_cistruct rtw_sdio_tx_data {
14262306a36Sopenharmony_ci	u8 sn;
14362306a36Sopenharmony_ci};
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_cistruct rtw_sdio_work_data {
14662306a36Sopenharmony_ci	struct work_struct work;
14762306a36Sopenharmony_ci	struct rtw_dev *rtwdev;
14862306a36Sopenharmony_ci};
14962306a36Sopenharmony_ci
15062306a36Sopenharmony_cistruct rtw_sdio {
15162306a36Sopenharmony_ci	struct sdio_func *sdio_func;
15262306a36Sopenharmony_ci
15362306a36Sopenharmony_ci	u32 irq_mask;
15462306a36Sopenharmony_ci	u8 rx_addr;
15562306a36Sopenharmony_ci	bool sdio3_bus_mode;
15662306a36Sopenharmony_ci
15762306a36Sopenharmony_ci	void *irq_thread;
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_ci	struct workqueue_struct *txwq;
16062306a36Sopenharmony_ci	struct rtw_sdio_work_data *tx_handler_data;
16162306a36Sopenharmony_ci	struct sk_buff_head tx_queue[RTK_MAX_TX_QUEUE_NUM];
16262306a36Sopenharmony_ci};
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_ciextern const struct dev_pm_ops rtw_sdio_pm_ops;
16562306a36Sopenharmony_ci
16662306a36Sopenharmony_ciint rtw_sdio_probe(struct sdio_func *sdio_func,
16762306a36Sopenharmony_ci		   const struct sdio_device_id *id);
16862306a36Sopenharmony_civoid rtw_sdio_remove(struct sdio_func *sdio_func);
16962306a36Sopenharmony_civoid rtw_sdio_shutdown(struct device *dev);
17062306a36Sopenharmony_ci
17162306a36Sopenharmony_cistatic inline bool rtw_sdio_is_sdio30_supported(struct rtw_dev *rtwdev)
17262306a36Sopenharmony_ci{
17362306a36Sopenharmony_ci	struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
17462306a36Sopenharmony_ci
17562306a36Sopenharmony_ci	return rtwsdio->sdio3_bus_mode;
17662306a36Sopenharmony_ci}
17762306a36Sopenharmony_ci
17862306a36Sopenharmony_ci#endif
179