xref: /openbmc/u-boot/drivers/mmc/tmio-common.h (revision 992bcf4f)
183d290c5STom Rini /* SPDX-License-Identifier: GPL-2.0+ */
2cb0b6b03SMarek Vasut /*
3cb0b6b03SMarek Vasut  * Copyright (C) 2016 Socionext Inc.
4cb0b6b03SMarek Vasut  *   Author: Masahiro Yamada <yamada.masahiro@socionext.com>
5cb0b6b03SMarek Vasut  */
6cb0b6b03SMarek Vasut 
7cb0b6b03SMarek Vasut #ifndef __TMIO_COMMON_H__
8cb0b6b03SMarek Vasut #define __TMIO_COMMON_H__
9cb0b6b03SMarek Vasut 
10cb0b6b03SMarek Vasut #define TMIO_SD_CMD			0x000	/* command */
11cb0b6b03SMarek Vasut #define   TMIO_SD_CMD_NOSTOP		BIT(14)	/* No automatic CMD12 issue */
12cb0b6b03SMarek Vasut #define   TMIO_SD_CMD_MULTI		BIT(13)	/* multiple block transfer */
13cb0b6b03SMarek Vasut #define   TMIO_SD_CMD_RD		BIT(12)	/* 1: read, 0: write */
14cb0b6b03SMarek Vasut #define   TMIO_SD_CMD_DATA		BIT(11)	/* data transfer */
15cb0b6b03SMarek Vasut #define   TMIO_SD_CMD_APP		BIT(6)	/* ACMD preceded by CMD55 */
16cb0b6b03SMarek Vasut #define   TMIO_SD_CMD_NORMAL		(0 << 8)/* auto-detect of resp-type */
17cb0b6b03SMarek Vasut #define   TMIO_SD_CMD_RSP_NONE		(3 << 8)/* response: none */
18cb0b6b03SMarek Vasut #define   TMIO_SD_CMD_RSP_R1		(4 << 8)/* response: R1, R5, R6, R7 */
19cb0b6b03SMarek Vasut #define   TMIO_SD_CMD_RSP_R1B		(5 << 8)/* response: R1b, R5b */
20cb0b6b03SMarek Vasut #define   TMIO_SD_CMD_RSP_R2		(6 << 8)/* response: R2 */
21cb0b6b03SMarek Vasut #define   TMIO_SD_CMD_RSP_R3		(7 << 8)/* response: R3, R4 */
22cb0b6b03SMarek Vasut #define TMIO_SD_ARG			0x008	/* command argument */
23cb0b6b03SMarek Vasut #define TMIO_SD_STOP			0x010	/* stop action control */
24cb0b6b03SMarek Vasut #define   TMIO_SD_STOP_SEC		BIT(8)	/* use sector count */
25cb0b6b03SMarek Vasut #define   TMIO_SD_STOP_STP		BIT(0)	/* issue CMD12 */
26cb0b6b03SMarek Vasut #define TMIO_SD_SECCNT			0x014	/* sector counter */
27cb0b6b03SMarek Vasut #define TMIO_SD_RSP10			0x018	/* response[39:8] */
28cb0b6b03SMarek Vasut #define TMIO_SD_RSP32			0x020	/* response[71:40] */
29cb0b6b03SMarek Vasut #define TMIO_SD_RSP54			0x028	/* response[103:72] */
30cb0b6b03SMarek Vasut #define TMIO_SD_RSP76			0x030	/* response[127:104] */
31cb0b6b03SMarek Vasut #define TMIO_SD_INFO1			0x038	/* IRQ status 1 */
32cb0b6b03SMarek Vasut #define   TMIO_SD_INFO1_CD		BIT(5)	/* state of card detect */
33cb0b6b03SMarek Vasut #define   TMIO_SD_INFO1_INSERT		BIT(4)	/* card inserted */
34cb0b6b03SMarek Vasut #define   TMIO_SD_INFO1_REMOVE		BIT(3)	/* card removed */
35cb0b6b03SMarek Vasut #define   TMIO_SD_INFO1_CMP		BIT(2)	/* data complete */
36cb0b6b03SMarek Vasut #define   TMIO_SD_INFO1_RSP		BIT(0)	/* response complete */
37cb0b6b03SMarek Vasut #define TMIO_SD_INFO2			0x03c	/* IRQ status 2 */
38cb0b6b03SMarek Vasut #define   TMIO_SD_INFO2_ERR_ILA	BIT(15)	/* illegal access err */
39cb0b6b03SMarek Vasut #define   TMIO_SD_INFO2_CBSY		BIT(14)	/* command busy */
40cb0b6b03SMarek Vasut #define   TMIO_SD_INFO2_SCLKDIVEN	BIT(13)	/* command setting reg ena */
41cb0b6b03SMarek Vasut #define   TMIO_SD_INFO2_BWE		BIT(9)	/* write buffer ready */
42cb0b6b03SMarek Vasut #define   TMIO_SD_INFO2_BRE		BIT(8)	/* read buffer ready */
43cb0b6b03SMarek Vasut #define   TMIO_SD_INFO2_DAT0		BIT(7)	/* SDDAT0 */
44cb0b6b03SMarek Vasut #define   TMIO_SD_INFO2_ERR_RTO	BIT(6)	/* response time out */
45cb0b6b03SMarek Vasut #define   TMIO_SD_INFO2_ERR_ILR	BIT(5)	/* illegal read err */
46cb0b6b03SMarek Vasut #define   TMIO_SD_INFO2_ERR_ILW	BIT(4)	/* illegal write err */
47cb0b6b03SMarek Vasut #define   TMIO_SD_INFO2_ERR_TO		BIT(3)	/* time out error */
48cb0b6b03SMarek Vasut #define   TMIO_SD_INFO2_ERR_END	BIT(2)	/* END bit error */
49cb0b6b03SMarek Vasut #define   TMIO_SD_INFO2_ERR_CRC	BIT(1)	/* CRC error */
50cb0b6b03SMarek Vasut #define   TMIO_SD_INFO2_ERR_IDX	BIT(0)	/* cmd index error */
51cb0b6b03SMarek Vasut #define TMIO_SD_INFO1_MASK		0x040
52cb0b6b03SMarek Vasut #define TMIO_SD_INFO2_MASK		0x044
53cb0b6b03SMarek Vasut #define TMIO_SD_CLKCTL			0x048	/* clock divisor */
54cb0b6b03SMarek Vasut #define   TMIO_SD_CLKCTL_DIV_MASK	0x104ff
55cb0b6b03SMarek Vasut #define   TMIO_SD_CLKCTL_DIV1024	BIT(16)	/* SDCLK = CLK / 1024 */
56cb0b6b03SMarek Vasut #define   TMIO_SD_CLKCTL_DIV512	BIT(7)	/* SDCLK = CLK / 512 */
57cb0b6b03SMarek Vasut #define   TMIO_SD_CLKCTL_DIV256	BIT(6)	/* SDCLK = CLK / 256 */
58cb0b6b03SMarek Vasut #define   TMIO_SD_CLKCTL_DIV128	BIT(5)	/* SDCLK = CLK / 128 */
59cb0b6b03SMarek Vasut #define   TMIO_SD_CLKCTL_DIV64		BIT(4)	/* SDCLK = CLK / 64 */
60cb0b6b03SMarek Vasut #define   TMIO_SD_CLKCTL_DIV32		BIT(3)	/* SDCLK = CLK / 32 */
61cb0b6b03SMarek Vasut #define   TMIO_SD_CLKCTL_DIV16		BIT(2)	/* SDCLK = CLK / 16 */
62cb0b6b03SMarek Vasut #define   TMIO_SD_CLKCTL_DIV8		BIT(1)	/* SDCLK = CLK / 8 */
63cb0b6b03SMarek Vasut #define   TMIO_SD_CLKCTL_DIV4		BIT(0)	/* SDCLK = CLK / 4 */
64cb0b6b03SMarek Vasut #define   TMIO_SD_CLKCTL_DIV2		0	/* SDCLK = CLK / 2 */
65cb0b6b03SMarek Vasut #define   TMIO_SD_CLKCTL_DIV1		BIT(10)	/* SDCLK = CLK */
66cb0b6b03SMarek Vasut #define   TMIO_SD_CLKCTL_RCAR_DIV1	0xff	/* SDCLK = CLK (RCar ver.) */
67cb0b6b03SMarek Vasut #define   TMIO_SD_CLKCTL_OFFEN		BIT(9)	/* stop SDCLK when unused */
68cb0b6b03SMarek Vasut #define   TMIO_SD_CLKCTL_SCLKEN	BIT(8)	/* SDCLK output enable */
69cb0b6b03SMarek Vasut #define TMIO_SD_SIZE			0x04c	/* block size */
70cb0b6b03SMarek Vasut #define TMIO_SD_OPTION			0x050
71cb0b6b03SMarek Vasut #define   TMIO_SD_OPTION_WIDTH_MASK	(5 << 13)
72cb0b6b03SMarek Vasut #define   TMIO_SD_OPTION_WIDTH_1	(4 << 13)
73cb0b6b03SMarek Vasut #define   TMIO_SD_OPTION_WIDTH_4	(0 << 13)
74cb0b6b03SMarek Vasut #define   TMIO_SD_OPTION_WIDTH_8	(1 << 13)
75cb0b6b03SMarek Vasut #define TMIO_SD_BUF			0x060	/* read/write buffer */
76cb0b6b03SMarek Vasut #define TMIO_SD_EXTMODE		0x1b0
77cb0b6b03SMarek Vasut #define   TMIO_SD_EXTMODE_DMA_EN	BIT(1)	/* transfer 1: DMA, 0: pio */
78cb0b6b03SMarek Vasut #define TMIO_SD_SOFT_RST		0x1c0
79cb0b6b03SMarek Vasut #define TMIO_SD_SOFT_RST_RSTX		BIT(0)	/* reset deassert */
80cb0b6b03SMarek Vasut #define TMIO_SD_VERSION		0x1c4	/* version register */
81cb0b6b03SMarek Vasut #define TMIO_SD_VERSION_IP		0xff	/* IP version */
82cb0b6b03SMarek Vasut #define TMIO_SD_HOST_MODE		0x1c8
83cb0b6b03SMarek Vasut #define TMIO_SD_IF_MODE		0x1cc
84cb0b6b03SMarek Vasut #define   TMIO_SD_IF_MODE_DDR		BIT(0)	/* DDR mode */
85cb0b6b03SMarek Vasut #define TMIO_SD_VOLT			0x1e4	/* voltage switch */
86cb0b6b03SMarek Vasut #define   TMIO_SD_VOLT_MASK		(3 << 0)
87cb0b6b03SMarek Vasut #define   TMIO_SD_VOLT_OFF		(0 << 0)
88cb0b6b03SMarek Vasut #define   TMIO_SD_VOLT_330		(1 << 0)/* 3.3V signal */
89cb0b6b03SMarek Vasut #define   TMIO_SD_VOLT_180		(2 << 0)/* 1.8V signal */
90cb0b6b03SMarek Vasut #define TMIO_SD_DMA_MODE		0x410
91cb0b6b03SMarek Vasut #define   TMIO_SD_DMA_MODE_DIR_RD	BIT(16)	/* 1: from device, 0: to dev */
92cb0b6b03SMarek Vasut #define   TMIO_SD_DMA_MODE_ADDR_INC	BIT(0)	/* 1: address inc, 0: fixed */
93cb0b6b03SMarek Vasut #define TMIO_SD_DMA_CTL		0x414
94cb0b6b03SMarek Vasut #define   TMIO_SD_DMA_CTL_START	BIT(0)	/* start DMA (auto cleared) */
95cb0b6b03SMarek Vasut #define TMIO_SD_DMA_RST		0x418
96cb0b6b03SMarek Vasut #define   TMIO_SD_DMA_RST_RD		BIT(9)
97cb0b6b03SMarek Vasut #define   TMIO_SD_DMA_RST_WR		BIT(8)
98cb0b6b03SMarek Vasut #define TMIO_SD_DMA_INFO1		0x420
99cb0b6b03SMarek Vasut #define   TMIO_SD_DMA_INFO1_END_RD2	BIT(20)	/* DMA from device is complete (uniphier) */
100cb0b6b03SMarek Vasut #define   TMIO_SD_DMA_INFO1_END_RD	BIT(17)	/* DMA from device is complete (renesas) */
101cb0b6b03SMarek Vasut #define   TMIO_SD_DMA_INFO1_END_WR	BIT(16)	/* DMA to device is complete */
102cb0b6b03SMarek Vasut #define TMIO_SD_DMA_INFO1_MASK		0x424
103cb0b6b03SMarek Vasut #define TMIO_SD_DMA_INFO2		0x428
104cb0b6b03SMarek Vasut #define   TMIO_SD_DMA_INFO2_ERR_RD	BIT(17)
105cb0b6b03SMarek Vasut #define   TMIO_SD_DMA_INFO2_ERR_WR	BIT(16)
106cb0b6b03SMarek Vasut #define TMIO_SD_DMA_INFO2_MASK		0x42c
107cb0b6b03SMarek Vasut #define TMIO_SD_DMA_ADDR_L		0x440
108cb0b6b03SMarek Vasut #define TMIO_SD_DMA_ADDR_H		0x444
109cb0b6b03SMarek Vasut 
110cb0b6b03SMarek Vasut /* alignment required by the DMA engine of this controller */
111cb0b6b03SMarek Vasut #define TMIO_SD_DMA_MINALIGN		0x10
112cb0b6b03SMarek Vasut 
113cb0b6b03SMarek Vasut struct tmio_sd_plat {
114cb0b6b03SMarek Vasut 	struct mmc_config		cfg;
115cb0b6b03SMarek Vasut 	struct mmc			mmc;
116cb0b6b03SMarek Vasut };
117cb0b6b03SMarek Vasut 
118cb0b6b03SMarek Vasut struct tmio_sd_priv {
119cb0b6b03SMarek Vasut 	void __iomem			*regbase;
120cb0b6b03SMarek Vasut 	unsigned int			version;
121cb0b6b03SMarek Vasut 	u32				caps;
122*992bcf4fSMarek Vasut 	u32				read_poll_flag;
123cb0b6b03SMarek Vasut #define TMIO_SD_CAP_NONREMOVABLE	BIT(0)	/* Nonremovable e.g. eMMC */
124cb0b6b03SMarek Vasut #define TMIO_SD_CAP_DMA_INTERNAL	BIT(1)	/* have internal DMA engine */
125cb0b6b03SMarek Vasut #define TMIO_SD_CAP_DIV1024		BIT(2)	/* divisor 1024 is available */
126cb0b6b03SMarek Vasut #define TMIO_SD_CAP_64BIT		BIT(3)	/* Controller is 64bit */
127cb0b6b03SMarek Vasut #define TMIO_SD_CAP_16BIT		BIT(4)	/* Controller is 16bit */
128cb0b6b03SMarek Vasut #define TMIO_SD_CAP_RCAR_GEN2		BIT(5)	/* Renesas RCar version of IP */
129cb0b6b03SMarek Vasut #define TMIO_SD_CAP_RCAR_GEN3		BIT(6)	/* Renesas RCar version of IP */
130cb0b6b03SMarek Vasut #define TMIO_SD_CAP_RCAR_UHS		BIT(7)	/* Renesas RCar UHS/SDR modes */
131cb0b6b03SMarek Vasut #define TMIO_SD_CAP_RCAR		\
132cb0b6b03SMarek Vasut 	(TMIO_SD_CAP_RCAR_GEN2 | TMIO_SD_CAP_RCAR_GEN3)
133cb0b6b03SMarek Vasut #ifdef CONFIG_DM_REGULATOR
134cb0b6b03SMarek Vasut 	struct udevice *vqmmc_dev;
135cb0b6b03SMarek Vasut #endif
1368ec6a04bSMarek Vasut #if CONFIG_IS_ENABLED(CLK)
1378ec6a04bSMarek Vasut 	struct clk			clk;
1388ec6a04bSMarek Vasut #endif
13995ead3d9SMarek Vasut #if CONFIG_IS_ENABLED(RENESAS_SDHI)
14095ead3d9SMarek Vasut 	u8				tap_set;
14150aa1d99SMarek Vasut 	u8				nrtaps;
14295ead3d9SMarek Vasut #endif
1438ec6a04bSMarek Vasut 	ulong (*clk_get_rate)(struct tmio_sd_priv *);
144cb0b6b03SMarek Vasut };
145cb0b6b03SMarek Vasut 
146cb0b6b03SMarek Vasut int tmio_sd_send_cmd(struct udevice *dev, struct mmc_cmd *cmd,
147cb0b6b03SMarek Vasut 		      struct mmc_data *data);
148cb0b6b03SMarek Vasut int tmio_sd_set_ios(struct udevice *dev);
149cb0b6b03SMarek Vasut int tmio_sd_get_cd(struct udevice *dev);
150cb0b6b03SMarek Vasut 
151cb0b6b03SMarek Vasut int tmio_sd_bind(struct udevice *dev);
152cb0b6b03SMarek Vasut int tmio_sd_probe(struct udevice *dev, u32 quirks);
153cb0b6b03SMarek Vasut 
154cb0b6b03SMarek Vasut u32 tmio_sd_readl(struct tmio_sd_priv *priv, unsigned int reg);
155cb0b6b03SMarek Vasut void tmio_sd_writel(struct tmio_sd_priv *priv,
156cb0b6b03SMarek Vasut 		     u32 val, unsigned int reg);
157cb0b6b03SMarek Vasut 
158cb0b6b03SMarek Vasut #endif /* __TMIO_COMMON_H__ */
159