blob: 59d5a0e22e9fa22c929ca2c661f81e6dbd290906 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Marek Vasutcb0b6b02018-04-13 23:51:33 +02002/*
3 * Copyright (C) 2016 Socionext Inc.
4 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
Marek Vasutcb0b6b02018-04-13 23:51:33 +02005 */
6
7#ifndef __TMIO_COMMON_H__
8#define __TMIO_COMMON_H__
9
Simon Glasscd93d622020-05-10 11:40:13 -060010#include <linux/bitops.h>
Marek Vasutcb0b6b02018-04-13 23:51:33 +020011#define TMIO_SD_CMD 0x000 /* command */
12#define TMIO_SD_CMD_NOSTOP BIT(14) /* No automatic CMD12 issue */
13#define TMIO_SD_CMD_MULTI BIT(13) /* multiple block transfer */
14#define TMIO_SD_CMD_RD BIT(12) /* 1: read, 0: write */
15#define TMIO_SD_CMD_DATA BIT(11) /* data transfer */
16#define TMIO_SD_CMD_APP BIT(6) /* ACMD preceded by CMD55 */
17#define TMIO_SD_CMD_NORMAL (0 << 8)/* auto-detect of resp-type */
18#define TMIO_SD_CMD_RSP_NONE (3 << 8)/* response: none */
19#define TMIO_SD_CMD_RSP_R1 (4 << 8)/* response: R1, R5, R6, R7 */
20#define TMIO_SD_CMD_RSP_R1B (5 << 8)/* response: R1b, R5b */
21#define TMIO_SD_CMD_RSP_R2 (6 << 8)/* response: R2 */
22#define TMIO_SD_CMD_RSP_R3 (7 << 8)/* response: R3, R4 */
23#define TMIO_SD_ARG 0x008 /* command argument */
24#define TMIO_SD_STOP 0x010 /* stop action control */
25#define TMIO_SD_STOP_SEC BIT(8) /* use sector count */
26#define TMIO_SD_STOP_STP BIT(0) /* issue CMD12 */
27#define TMIO_SD_SECCNT 0x014 /* sector counter */
28#define TMIO_SD_RSP10 0x018 /* response[39:8] */
29#define TMIO_SD_RSP32 0x020 /* response[71:40] */
30#define TMIO_SD_RSP54 0x028 /* response[103:72] */
31#define TMIO_SD_RSP76 0x030 /* response[127:104] */
32#define TMIO_SD_INFO1 0x038 /* IRQ status 1 */
33#define TMIO_SD_INFO1_CD BIT(5) /* state of card detect */
34#define TMIO_SD_INFO1_INSERT BIT(4) /* card inserted */
35#define TMIO_SD_INFO1_REMOVE BIT(3) /* card removed */
36#define TMIO_SD_INFO1_CMP BIT(2) /* data complete */
37#define TMIO_SD_INFO1_RSP BIT(0) /* response complete */
38#define TMIO_SD_INFO2 0x03c /* IRQ status 2 */
39#define TMIO_SD_INFO2_ERR_ILA BIT(15) /* illegal access err */
40#define TMIO_SD_INFO2_CBSY BIT(14) /* command busy */
41#define TMIO_SD_INFO2_SCLKDIVEN BIT(13) /* command setting reg ena */
42#define TMIO_SD_INFO2_BWE BIT(9) /* write buffer ready */
43#define TMIO_SD_INFO2_BRE BIT(8) /* read buffer ready */
44#define TMIO_SD_INFO2_DAT0 BIT(7) /* SDDAT0 */
45#define TMIO_SD_INFO2_ERR_RTO BIT(6) /* response time out */
46#define TMIO_SD_INFO2_ERR_ILR BIT(5) /* illegal read err */
47#define TMIO_SD_INFO2_ERR_ILW BIT(4) /* illegal write err */
48#define TMIO_SD_INFO2_ERR_TO BIT(3) /* time out error */
49#define TMIO_SD_INFO2_ERR_END BIT(2) /* END bit error */
50#define TMIO_SD_INFO2_ERR_CRC BIT(1) /* CRC error */
51#define TMIO_SD_INFO2_ERR_IDX BIT(0) /* cmd index error */
52#define TMIO_SD_INFO1_MASK 0x040
53#define TMIO_SD_INFO2_MASK 0x044
54#define TMIO_SD_CLKCTL 0x048 /* clock divisor */
55#define TMIO_SD_CLKCTL_DIV_MASK 0x104ff
56#define TMIO_SD_CLKCTL_DIV1024 BIT(16) /* SDCLK = CLK / 1024 */
57#define TMIO_SD_CLKCTL_DIV512 BIT(7) /* SDCLK = CLK / 512 */
58#define TMIO_SD_CLKCTL_DIV256 BIT(6) /* SDCLK = CLK / 256 */
59#define TMIO_SD_CLKCTL_DIV128 BIT(5) /* SDCLK = CLK / 128 */
60#define TMIO_SD_CLKCTL_DIV64 BIT(4) /* SDCLK = CLK / 64 */
61#define TMIO_SD_CLKCTL_DIV32 BIT(3) /* SDCLK = CLK / 32 */
62#define TMIO_SD_CLKCTL_DIV16 BIT(2) /* SDCLK = CLK / 16 */
63#define TMIO_SD_CLKCTL_DIV8 BIT(1) /* SDCLK = CLK / 8 */
64#define TMIO_SD_CLKCTL_DIV4 BIT(0) /* SDCLK = CLK / 4 */
65#define TMIO_SD_CLKCTL_DIV2 0 /* SDCLK = CLK / 2 */
66#define TMIO_SD_CLKCTL_DIV1 BIT(10) /* SDCLK = CLK */
67#define TMIO_SD_CLKCTL_RCAR_DIV1 0xff /* SDCLK = CLK (RCar ver.) */
68#define TMIO_SD_CLKCTL_OFFEN BIT(9) /* stop SDCLK when unused */
69#define TMIO_SD_CLKCTL_SCLKEN BIT(8) /* SDCLK output enable */
70#define TMIO_SD_SIZE 0x04c /* block size */
71#define TMIO_SD_OPTION 0x050
72#define TMIO_SD_OPTION_WIDTH_MASK (5 << 13)
73#define TMIO_SD_OPTION_WIDTH_1 (4 << 13)
74#define TMIO_SD_OPTION_WIDTH_4 (0 << 13)
75#define TMIO_SD_OPTION_WIDTH_8 (1 << 13)
76#define TMIO_SD_BUF 0x060 /* read/write buffer */
77#define TMIO_SD_EXTMODE 0x1b0
78#define TMIO_SD_EXTMODE_DMA_EN BIT(1) /* transfer 1: DMA, 0: pio */
79#define TMIO_SD_SOFT_RST 0x1c0
80#define TMIO_SD_SOFT_RST_RSTX BIT(0) /* reset deassert */
81#define TMIO_SD_VERSION 0x1c4 /* version register */
82#define TMIO_SD_VERSION_IP 0xff /* IP version */
83#define TMIO_SD_HOST_MODE 0x1c8
84#define TMIO_SD_IF_MODE 0x1cc
85#define TMIO_SD_IF_MODE_DDR BIT(0) /* DDR mode */
86#define TMIO_SD_VOLT 0x1e4 /* voltage switch */
87#define TMIO_SD_VOLT_MASK (3 << 0)
88#define TMIO_SD_VOLT_OFF (0 << 0)
89#define TMIO_SD_VOLT_330 (1 << 0)/* 3.3V signal */
90#define TMIO_SD_VOLT_180 (2 << 0)/* 1.8V signal */
91#define TMIO_SD_DMA_MODE 0x410
92#define TMIO_SD_DMA_MODE_DIR_RD BIT(16) /* 1: from device, 0: to dev */
Marek Vasut8a73bef2021-01-03 11:38:25 +010093#define TMIO_SD_DMA_MODE_BUS_WIDTH (BIT(5) | BIT(4)) /* RCar, 64bit */
Marek Vasutcb0b6b02018-04-13 23:51:33 +020094#define TMIO_SD_DMA_MODE_ADDR_INC BIT(0) /* 1: address inc, 0: fixed */
95#define TMIO_SD_DMA_CTL 0x414
96#define TMIO_SD_DMA_CTL_START BIT(0) /* start DMA (auto cleared) */
97#define TMIO_SD_DMA_RST 0x418
98#define TMIO_SD_DMA_RST_RD BIT(9)
99#define TMIO_SD_DMA_RST_WR BIT(8)
100#define TMIO_SD_DMA_INFO1 0x420
101#define TMIO_SD_DMA_INFO1_END_RD2 BIT(20) /* DMA from device is complete (uniphier) */
102#define TMIO_SD_DMA_INFO1_END_RD BIT(17) /* DMA from device is complete (renesas) */
103#define TMIO_SD_DMA_INFO1_END_WR BIT(16) /* DMA to device is complete */
104#define TMIO_SD_DMA_INFO1_MASK 0x424
105#define TMIO_SD_DMA_INFO2 0x428
106#define TMIO_SD_DMA_INFO2_ERR_RD BIT(17)
107#define TMIO_SD_DMA_INFO2_ERR_WR BIT(16)
108#define TMIO_SD_DMA_INFO2_MASK 0x42c
109#define TMIO_SD_DMA_ADDR_L 0x440
110#define TMIO_SD_DMA_ADDR_H 0x444
111
112/* alignment required by the DMA engine of this controller */
113#define TMIO_SD_DMA_MINALIGN 0x10
114
115struct tmio_sd_plat {
116 struct mmc_config cfg;
117 struct mmc mmc;
118};
119
120struct tmio_sd_priv {
121 void __iomem *regbase;
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200122 unsigned int version;
123 u32 caps;
Marek Vasut992bcf42019-01-11 23:45:54 +0100124 u32 read_poll_flag;
Marek Vasut8a73bef2021-01-03 11:38:25 +0100125 u32 idma_bus_width;
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200126#define TMIO_SD_CAP_NONREMOVABLE BIT(0) /* Nonremovable e.g. eMMC */
127#define TMIO_SD_CAP_DMA_INTERNAL BIT(1) /* have internal DMA engine */
128#define TMIO_SD_CAP_DIV1024 BIT(2) /* divisor 1024 is available */
129#define TMIO_SD_CAP_64BIT BIT(3) /* Controller is 64bit */
130#define TMIO_SD_CAP_16BIT BIT(4) /* Controller is 16bit */
131#define TMIO_SD_CAP_RCAR_GEN2 BIT(5) /* Renesas RCar version of IP */
132#define TMIO_SD_CAP_RCAR_GEN3 BIT(6) /* Renesas RCar version of IP */
133#define TMIO_SD_CAP_RCAR_UHS BIT(7) /* Renesas RCar UHS/SDR modes */
134#define TMIO_SD_CAP_RCAR \
135 (TMIO_SD_CAP_RCAR_GEN2 | TMIO_SD_CAP_RCAR_GEN3)
136#ifdef CONFIG_DM_REGULATOR
137 struct udevice *vqmmc_dev;
138#endif
Marek Vasut8ec6a042018-06-13 08:02:55 +0200139#if CONFIG_IS_ENABLED(CLK)
140 struct clk clk;
141#endif
Marek Vasut95ead3d2018-06-13 08:02:55 +0200142#if CONFIG_IS_ENABLED(RENESAS_SDHI)
Marek Vasut37c39902019-11-23 13:36:18 +0100143 unsigned int smpcmp;
Marek Vasut95ead3d2018-06-13 08:02:55 +0200144 u8 tap_set;
Marek Vasut0196a582019-11-23 13:36:17 +0100145 u8 tap_num;
Marek Vasut50aa1d92018-06-13 08:02:55 +0200146 u8 nrtaps;
Marek Vasutb5900a52019-05-19 03:47:07 +0200147 bool needs_adjust_hs400;
148 bool adjust_hs400_enable;
149 u8 adjust_hs400_offset;
150 u8 adjust_hs400_calibrate;
Marek Vasut1bdcb832019-11-23 13:36:24 +0100151 u8 hs400_bad_tap;
Marek Vasut56b0bb92019-11-23 13:36:25 +0100152 const u8 *adjust_hs400_calib_table;
Marek Vasut4a66d4e2020-04-04 12:45:06 +0200153 u32 quirks;
Marek Vasut95ead3d2018-06-13 08:02:55 +0200154#endif
Marek Vasut8ec6a042018-06-13 08:02:55 +0200155 ulong (*clk_get_rate)(struct tmio_sd_priv *);
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200156};
157
158int tmio_sd_send_cmd(struct udevice *dev, struct mmc_cmd *cmd,
159 struct mmc_data *data);
160int tmio_sd_set_ios(struct udevice *dev);
161int tmio_sd_get_cd(struct udevice *dev);
162
163int tmio_sd_bind(struct udevice *dev);
164int tmio_sd_probe(struct udevice *dev, u32 quirks);
165
166u32 tmio_sd_readl(struct tmio_sd_priv *priv, unsigned int reg);
167void tmio_sd_writel(struct tmio_sd_priv *priv,
168 u32 val, unsigned int reg);
169
170#endif /* __TMIO_COMMON_H__ */