18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  linux/drivers/mmc/host/wbsd.h - Winbond W83L51xD SD/MMC driver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  Copyright (C) 2004-2007 Pierre Ossman, All Rights Reserved.
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#define LOCK_CODE		0xAA
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#define WBSD_CONF_SWRST		0x02
118c2ecf20Sopenharmony_ci#define WBSD_CONF_DEVICE	0x07
128c2ecf20Sopenharmony_ci#define WBSD_CONF_ID_HI		0x20
138c2ecf20Sopenharmony_ci#define WBSD_CONF_ID_LO		0x21
148c2ecf20Sopenharmony_ci#define WBSD_CONF_POWER		0x22
158c2ecf20Sopenharmony_ci#define WBSD_CONF_PME		0x23
168c2ecf20Sopenharmony_ci#define WBSD_CONF_PMES		0x24
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#define WBSD_CONF_ENABLE	0x30
198c2ecf20Sopenharmony_ci#define WBSD_CONF_PORT_HI	0x60
208c2ecf20Sopenharmony_ci#define WBSD_CONF_PORT_LO	0x61
218c2ecf20Sopenharmony_ci#define WBSD_CONF_IRQ		0x70
228c2ecf20Sopenharmony_ci#define WBSD_CONF_DRQ		0x74
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#define WBSD_CONF_PINS		0xF0
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#define DEVICE_SD		0x03
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#define WBSD_PINS_DAT3_HI	0x20
298c2ecf20Sopenharmony_ci#define WBSD_PINS_DAT3_OUT	0x10
308c2ecf20Sopenharmony_ci#define WBSD_PINS_GP11_HI	0x04
318c2ecf20Sopenharmony_ci#define WBSD_PINS_DETECT_GP11	0x02
328c2ecf20Sopenharmony_ci#define WBSD_PINS_DETECT_DAT3	0x01
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define WBSD_CMDR		0x00
358c2ecf20Sopenharmony_ci#define WBSD_DFR		0x01
368c2ecf20Sopenharmony_ci#define WBSD_EIR		0x02
378c2ecf20Sopenharmony_ci#define WBSD_ISR		0x03
388c2ecf20Sopenharmony_ci#define WBSD_FSR		0x04
398c2ecf20Sopenharmony_ci#define WBSD_IDXR		0x05
408c2ecf20Sopenharmony_ci#define WBSD_DATAR		0x06
418c2ecf20Sopenharmony_ci#define WBSD_CSR		0x07
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#define WBSD_EINT_CARD		0x40
448c2ecf20Sopenharmony_ci#define WBSD_EINT_FIFO_THRE	0x20
458c2ecf20Sopenharmony_ci#define WBSD_EINT_CRC		0x10
468c2ecf20Sopenharmony_ci#define WBSD_EINT_TIMEOUT	0x08
478c2ecf20Sopenharmony_ci#define WBSD_EINT_PROGEND	0x04
488c2ecf20Sopenharmony_ci#define WBSD_EINT_BUSYEND	0x02
498c2ecf20Sopenharmony_ci#define WBSD_EINT_TC		0x01
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#define WBSD_INT_PENDING	0x80
528c2ecf20Sopenharmony_ci#define WBSD_INT_CARD		0x40
538c2ecf20Sopenharmony_ci#define WBSD_INT_FIFO_THRE	0x20
548c2ecf20Sopenharmony_ci#define WBSD_INT_CRC		0x10
558c2ecf20Sopenharmony_ci#define WBSD_INT_TIMEOUT	0x08
568c2ecf20Sopenharmony_ci#define WBSD_INT_PROGEND	0x04
578c2ecf20Sopenharmony_ci#define WBSD_INT_BUSYEND	0x02
588c2ecf20Sopenharmony_ci#define WBSD_INT_TC		0x01
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci#define WBSD_FIFO_EMPTY		0x80
618c2ecf20Sopenharmony_ci#define WBSD_FIFO_FULL		0x40
628c2ecf20Sopenharmony_ci#define WBSD_FIFO_EMTHRE	0x20
638c2ecf20Sopenharmony_ci#define WBSD_FIFO_FUTHRE	0x10
648c2ecf20Sopenharmony_ci#define WBSD_FIFO_SZMASK	0x0F
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci#define WBSD_MSLED		0x20
678c2ecf20Sopenharmony_ci#define WBSD_POWER_N		0x10
688c2ecf20Sopenharmony_ci#define WBSD_WRPT		0x04
698c2ecf20Sopenharmony_ci#define WBSD_CARDPRESENT	0x01
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci#define WBSD_IDX_CLK		0x01
728c2ecf20Sopenharmony_ci#define WBSD_IDX_PBSMSB		0x02
738c2ecf20Sopenharmony_ci#define WBSD_IDX_TAAC		0x03
748c2ecf20Sopenharmony_ci#define WBSD_IDX_NSAC		0x04
758c2ecf20Sopenharmony_ci#define WBSD_IDX_PBSLSB		0x05
768c2ecf20Sopenharmony_ci#define WBSD_IDX_SETUP		0x06
778c2ecf20Sopenharmony_ci#define WBSD_IDX_DMA		0x07
788c2ecf20Sopenharmony_ci#define WBSD_IDX_FIFOEN		0x08
798c2ecf20Sopenharmony_ci#define WBSD_IDX_STATUS		0x10
808c2ecf20Sopenharmony_ci#define WBSD_IDX_RSPLEN		0x1E
818c2ecf20Sopenharmony_ci#define WBSD_IDX_RESP0		0x1F
828c2ecf20Sopenharmony_ci#define WBSD_IDX_RESP1		0x20
838c2ecf20Sopenharmony_ci#define WBSD_IDX_RESP2		0x21
848c2ecf20Sopenharmony_ci#define WBSD_IDX_RESP3		0x22
858c2ecf20Sopenharmony_ci#define WBSD_IDX_RESP4		0x23
868c2ecf20Sopenharmony_ci#define WBSD_IDX_RESP5		0x24
878c2ecf20Sopenharmony_ci#define WBSD_IDX_RESP6		0x25
888c2ecf20Sopenharmony_ci#define WBSD_IDX_RESP7		0x26
898c2ecf20Sopenharmony_ci#define WBSD_IDX_RESP8		0x27
908c2ecf20Sopenharmony_ci#define WBSD_IDX_RESP9		0x28
918c2ecf20Sopenharmony_ci#define WBSD_IDX_RESP10		0x29
928c2ecf20Sopenharmony_ci#define WBSD_IDX_RESP11		0x2A
938c2ecf20Sopenharmony_ci#define WBSD_IDX_RESP12		0x2B
948c2ecf20Sopenharmony_ci#define WBSD_IDX_RESP13		0x2C
958c2ecf20Sopenharmony_ci#define WBSD_IDX_RESP14		0x2D
968c2ecf20Sopenharmony_ci#define WBSD_IDX_RESP15		0x2E
978c2ecf20Sopenharmony_ci#define WBSD_IDX_RESP16		0x2F
988c2ecf20Sopenharmony_ci#define WBSD_IDX_CRCSTATUS	0x30
998c2ecf20Sopenharmony_ci#define WBSD_IDX_ISR		0x3F
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci#define WBSD_CLK_375K		0x00
1028c2ecf20Sopenharmony_ci#define WBSD_CLK_12M		0x01
1038c2ecf20Sopenharmony_ci#define WBSD_CLK_16M		0x02
1048c2ecf20Sopenharmony_ci#define WBSD_CLK_24M		0x03
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci#define WBSD_DATA_WIDTH		0x01
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci#define WBSD_DAT3_H		0x08
1098c2ecf20Sopenharmony_ci#define WBSD_FIFO_RESET		0x04
1108c2ecf20Sopenharmony_ci#define WBSD_SOFT_RESET		0x02
1118c2ecf20Sopenharmony_ci#define WBSD_INC_INDEX		0x01
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci#define WBSD_DMA_SINGLE		0x02
1148c2ecf20Sopenharmony_ci#define WBSD_DMA_ENABLE		0x01
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci#define WBSD_FIFOEN_EMPTY	0x20
1178c2ecf20Sopenharmony_ci#define WBSD_FIFOEN_FULL	0x10
1188c2ecf20Sopenharmony_ci#define WBSD_FIFO_THREMASK	0x0F
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci#define WBSD_BLOCK_READ		0x80
1218c2ecf20Sopenharmony_ci#define WBSD_BLOCK_WRITE	0x40
1228c2ecf20Sopenharmony_ci#define WBSD_BUSY		0x20
1238c2ecf20Sopenharmony_ci#define WBSD_CARDTRAFFIC	0x04
1248c2ecf20Sopenharmony_ci#define WBSD_SENDCMD		0x02
1258c2ecf20Sopenharmony_ci#define WBSD_RECVRES		0x01
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci#define WBSD_RSP_SHORT		0x00
1288c2ecf20Sopenharmony_ci#define WBSD_RSP_LONG		0x01
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci#define WBSD_CRC_MASK		0x1F
1318c2ecf20Sopenharmony_ci#define WBSD_CRC_OK		0x05 /* S010E (00101) */
1328c2ecf20Sopenharmony_ci#define WBSD_CRC_FAIL		0x0B /* S101E (01011) */
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci#define WBSD_DMA_SIZE		65536
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_cistruct wbsd_host
1378c2ecf20Sopenharmony_ci{
1388c2ecf20Sopenharmony_ci	struct mmc_host*	mmc;		/* MMC structure */
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci	spinlock_t		lock;		/* Mutex */
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci	int			flags;		/* Driver states */
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci#define WBSD_FCARD_PRESENT	(1<<0)		/* Card is present */
1458c2ecf20Sopenharmony_ci#define WBSD_FIGNORE_DETECT	(1<<1)		/* Ignore card detection */
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci	struct mmc_request*	mrq;		/* Current request */
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci	u8			isr;		/* Accumulated ISR */
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci	struct scatterlist*	cur_sg;		/* Current SG entry */
1528c2ecf20Sopenharmony_ci	unsigned int		num_sg;		/* Number of entries left */
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci	unsigned int		offset;		/* Offset into current entry */
1558c2ecf20Sopenharmony_ci	unsigned int		remain;		/* Data left in curren entry */
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci	char*			dma_buffer;	/* ISA DMA buffer */
1588c2ecf20Sopenharmony_ci	dma_addr_t		dma_addr;	/* Physical address for same */
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci	int			firsterr;	/* See fifo functions */
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci	u8			clk;		/* Current clock speed */
1638c2ecf20Sopenharmony_ci	unsigned char		bus_width;	/* Current bus width */
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ci	int			config;		/* Config port */
1668c2ecf20Sopenharmony_ci	u8			unlock_code;	/* Code to unlock config */
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci	int			chip_id;	/* ID of controller */
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci	int			base;		/* I/O port base */
1718c2ecf20Sopenharmony_ci	int			irq;		/* Interrupt */
1728c2ecf20Sopenharmony_ci	int			dma;		/* DMA channel */
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci	struct tasklet_struct	card_tasklet;	/* Tasklet structures */
1758c2ecf20Sopenharmony_ci	struct tasklet_struct	fifo_tasklet;
1768c2ecf20Sopenharmony_ci	struct tasklet_struct	crc_tasklet;
1778c2ecf20Sopenharmony_ci	struct tasklet_struct	timeout_tasklet;
1788c2ecf20Sopenharmony_ci	struct tasklet_struct	finish_tasklet;
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci	struct timer_list	ignore_timer;	/* Ignore detection timer */
1818c2ecf20Sopenharmony_ci};
182