xref: /openbmc/u-boot/drivers/mmc/arm_pl180_mmci.h (revision 83d290c5)
1*83d290c5STom Rini /* SPDX-License-Identifier: GPL-2.0+ */
223b93e1dSMatt Waddel /*
323b93e1dSMatt Waddel  * ARM PrimeCell MultiMedia Card Interface - PL180
423b93e1dSMatt Waddel  *
523b93e1dSMatt Waddel  * Copyright (C) ST-Ericsson SA 2010
623b93e1dSMatt Waddel  *
723b93e1dSMatt Waddel  * Author: Ulf Hansson <ulf.hansson@stericsson.com>
823b93e1dSMatt Waddel  * Author: Martin Lundholm <martin.xa.lundholm@stericsson.com>
923b93e1dSMatt Waddel  * Ported to drivers/mmc/ by: Matt Waddel <matt.waddel@linaro.org>
1023b93e1dSMatt Waddel  */
1123b93e1dSMatt Waddel 
1223b93e1dSMatt Waddel #ifndef __ARM_PL180_MMCI_H__
1323b93e1dSMatt Waddel #define __ARM_PL180_MMCI_H__
1423b93e1dSMatt Waddel 
1593bfd616SPantelis Antoniou /* need definition of struct mmc_config */
1693bfd616SPantelis Antoniou #include <mmc.h>
1793bfd616SPantelis Antoniou 
1823b93e1dSMatt Waddel #define COMMAND_REG_DELAY	300
1923b93e1dSMatt Waddel #define DATA_REG_DELAY		1000
2023b93e1dSMatt Waddel #define CLK_CHANGE_DELAY	2000
2123b93e1dSMatt Waddel 
2223b93e1dSMatt Waddel #define INIT_PWR		0xBF /* Power on, full power, not open drain */
2323b93e1dSMatt Waddel #define ARM_MCLK		(100*1000*1000)
2423b93e1dSMatt Waddel 
2523b93e1dSMatt Waddel /* SDI Power Control register bits */
2623b93e1dSMatt Waddel #define SDI_PWR_PWRCTRL_MASK	0x00000003
2723b93e1dSMatt Waddel #define SDI_PWR_PWRCTRL_ON	0x00000003
2823b93e1dSMatt Waddel #define SDI_PWR_PWRCTRL_OFF	0x00000000
2923b93e1dSMatt Waddel #define SDI_PWR_DAT2DIREN	0x00000004
3023b93e1dSMatt Waddel #define SDI_PWR_CMDDIREN	0x00000008
3123b93e1dSMatt Waddel #define SDI_PWR_DAT0DIREN	0x00000010
3223b93e1dSMatt Waddel #define SDI_PWR_DAT31DIREN	0x00000020
3323b93e1dSMatt Waddel #define SDI_PWR_OPD		0x00000040
3423b93e1dSMatt Waddel #define SDI_PWR_FBCLKEN		0x00000080
3523b93e1dSMatt Waddel #define SDI_PWR_DAT74DIREN	0x00000100
3623b93e1dSMatt Waddel #define SDI_PWR_RSTEN		0x00000200
3723b93e1dSMatt Waddel 
3823b93e1dSMatt Waddel #define VOLTAGE_WINDOW_MMC	0x00FF8080
3923b93e1dSMatt Waddel #define VOLTAGE_WINDOW_SD	0x80010000
4023b93e1dSMatt Waddel 
4123b93e1dSMatt Waddel /* SDI clock control register bits */
4223b93e1dSMatt Waddel #define SDI_CLKCR_CLKDIV_MASK	0x000000FF
4323b93e1dSMatt Waddel #define SDI_CLKCR_CLKEN		0x00000100
4423b93e1dSMatt Waddel #define SDI_CLKCR_PWRSAV	0x00000200
4523b93e1dSMatt Waddel #define SDI_CLKCR_BYPASS	0x00000400
4623b93e1dSMatt Waddel #define SDI_CLKCR_WIDBUS_MASK	0x00001800
4723b93e1dSMatt Waddel #define SDI_CLKCR_WIDBUS_1	0x00000000
4823b93e1dSMatt Waddel #define SDI_CLKCR_WIDBUS_4	0x00000800
4910ed93dcSJohn Rigby /* V2 only */
5010ed93dcSJohn Rigby #define SDI_CLKCR_WIDBUS_8	0x00001000
5110ed93dcSJohn Rigby #define SDI_CLKCR_NEDGE		0x00002000
5210ed93dcSJohn Rigby #define SDI_CLKCR_HWFC_EN	0x00004000
5323b93e1dSMatt Waddel 
5410ed93dcSJohn Rigby #define SDI_CLKCR_CLKDIV_INIT_V1 0x000000C6 /* MCLK/(2*(0xC6+1)) => 505KHz */
5510ed93dcSJohn Rigby #define SDI_CLKCR_CLKDIV_INIT_V2 0x000000FD
5623b93e1dSMatt Waddel 
5723b93e1dSMatt Waddel /* SDI command register bits */
5823b93e1dSMatt Waddel #define SDI_CMD_CMDINDEX_MASK	0x000000FF
5923b93e1dSMatt Waddel #define SDI_CMD_WAITRESP	0x00000040
6023b93e1dSMatt Waddel #define SDI_CMD_LONGRESP	0x00000080
6123b93e1dSMatt Waddel #define SDI_CMD_WAITINT		0x00000100
6223b93e1dSMatt Waddel #define SDI_CMD_WAITPEND	0x00000200
6323b93e1dSMatt Waddel #define SDI_CMD_CPSMEN		0x00000400
6423b93e1dSMatt Waddel #define SDI_CMD_SDIOSUSPEND	0x00000800
6523b93e1dSMatt Waddel #define SDI_CMD_ENDCMDCOMPL	0x00001000
6623b93e1dSMatt Waddel #define SDI_CMD_NIEN		0x00002000
6723b93e1dSMatt Waddel #define SDI_CMD_CE_ATACMD	0x00004000
6823b93e1dSMatt Waddel #define SDI_CMD_CBOOTMODEEN	0x00008000
6923b93e1dSMatt Waddel 
7023b93e1dSMatt Waddel #define SDI_DTIMER_DEFAULT	0xFFFF0000
7123b93e1dSMatt Waddel 
7223b93e1dSMatt Waddel /* SDI Status register bits */
7323b93e1dSMatt Waddel #define SDI_STA_CCRCFAIL	0x00000001
7423b93e1dSMatt Waddel #define SDI_STA_DCRCFAIL	0x00000002
7523b93e1dSMatt Waddel #define SDI_STA_CTIMEOUT	0x00000004
7623b93e1dSMatt Waddel #define SDI_STA_DTIMEOUT	0x00000008
7723b93e1dSMatt Waddel #define SDI_STA_TXUNDERR	0x00000010
7823b93e1dSMatt Waddel #define SDI_STA_RXOVERR		0x00000020
7923b93e1dSMatt Waddel #define SDI_STA_CMDREND		0x00000040
8023b93e1dSMatt Waddel #define SDI_STA_CMDSENT		0x00000080
8123b93e1dSMatt Waddel #define SDI_STA_DATAEND		0x00000100
8223b93e1dSMatt Waddel #define SDI_STA_STBITERR	0x00000200
8323b93e1dSMatt Waddel #define SDI_STA_DBCKEND		0x00000400
8423b93e1dSMatt Waddel #define SDI_STA_CMDACT		0x00000800
8523b93e1dSMatt Waddel #define SDI_STA_TXACT		0x00001000
8623b93e1dSMatt Waddel #define SDI_STA_RXACT		0x00002000
8723b93e1dSMatt Waddel #define SDI_STA_TXFIFOBW	0x00004000
8823b93e1dSMatt Waddel #define SDI_STA_RXFIFOBR	0x00008000
8923b93e1dSMatt Waddel #define SDI_STA_TXFIFOF		0x00010000
9023b93e1dSMatt Waddel #define SDI_STA_RXFIFOF		0x00020000
9123b93e1dSMatt Waddel #define SDI_STA_TXFIFOE		0x00040000
9223b93e1dSMatt Waddel #define SDI_STA_RXFIFOE		0x00080000
9323b93e1dSMatt Waddel #define SDI_STA_TXDAVL		0x00100000
9423b93e1dSMatt Waddel #define SDI_STA_RXDAVL		0x00200000
9523b93e1dSMatt Waddel #define SDI_STA_SDIOIT		0x00400000
9623b93e1dSMatt Waddel #define SDI_STA_CEATAEND	0x00800000
9723b93e1dSMatt Waddel #define SDI_STA_CARDBUSY	0x01000000
9823b93e1dSMatt Waddel #define SDI_STA_BOOTMODE	0x02000000
9923b93e1dSMatt Waddel #define SDI_STA_BOOTACKERR	0x04000000
10023b93e1dSMatt Waddel #define SDI_STA_BOOTACKTIMEOUT	0x08000000
10123b93e1dSMatt Waddel #define SDI_STA_RSTNEND		0x10000000
10223b93e1dSMatt Waddel 
10323b93e1dSMatt Waddel /* SDI Interrupt Clear register bits */
10423b93e1dSMatt Waddel #define SDI_ICR_MASK		0x1DC007FF
10523b93e1dSMatt Waddel #define SDI_ICR_CCRCFAILC	0x00000001
10623b93e1dSMatt Waddel #define SDI_ICR_DCRCFAILC	0x00000002
10723b93e1dSMatt Waddel #define SDI_ICR_CTIMEOUTC	0x00000004
10823b93e1dSMatt Waddel #define SDI_ICR_DTIMEOUTC	0x00000008
10923b93e1dSMatt Waddel #define SDI_ICR_TXUNDERRC	0x00000010
11023b93e1dSMatt Waddel #define SDI_ICR_RXOVERRC	0x00000020
11123b93e1dSMatt Waddel #define SDI_ICR_CMDRENDC	0x00000040
11223b93e1dSMatt Waddel #define SDI_ICR_CMDSENTC	0x00000080
11323b93e1dSMatt Waddel #define SDI_ICR_DATAENDC	0x00000100
11423b93e1dSMatt Waddel #define SDI_ICR_STBITERRC	0x00000200
11523b93e1dSMatt Waddel #define SDI_ICR_DBCKENDC	0x00000400
11623b93e1dSMatt Waddel #define SDI_ICR_SDIOITC		0x00400000
11723b93e1dSMatt Waddel #define SDI_ICR_CEATAENDC	0x00800000
11823b93e1dSMatt Waddel #define SDI_ICR_BUSYENDC	0x01000000
11923b93e1dSMatt Waddel #define SDI_ICR_BOOTACKERRC	0x04000000
12023b93e1dSMatt Waddel #define SDI_ICR_BOOTACKTIMEOUTC	0x08000000
12123b93e1dSMatt Waddel #define SDI_ICR_RSTNENDC	0x10000000
12223b93e1dSMatt Waddel 
12323b93e1dSMatt Waddel #define SDI_MASK0_MASK		0x1FFFFFFF
12423b93e1dSMatt Waddel 
12523b93e1dSMatt Waddel /* SDI Data control register bits */
12623b93e1dSMatt Waddel #define SDI_DCTRL_DTEN		0x00000001
12723b93e1dSMatt Waddel #define SDI_DCTRL_DTDIR_IN	0x00000002
12823b93e1dSMatt Waddel #define SDI_DCTRL_DTMODE_STREAM	0x00000004
12923b93e1dSMatt Waddel #define SDI_DCTRL_DMAEN		0x00000008
13023b93e1dSMatt Waddel #define SDI_DCTRL_DBLKSIZE_MASK	0x000000F0
13123b93e1dSMatt Waddel #define SDI_DCTRL_RWSTART	0x00000100
13223b93e1dSMatt Waddel #define SDI_DCTRL_RWSTOP	0x00000200
13323b93e1dSMatt Waddel #define SDI_DCTRL_RWMOD		0x00000200
13423b93e1dSMatt Waddel #define SDI_DCTRL_SDIOEN	0x00000800
13523b93e1dSMatt Waddel #define SDI_DCTRL_DMAREQCTL	0x00001000
13623b93e1dSMatt Waddel #define SDI_DCTRL_DBOOTMODEEN	0x00002000
13723b93e1dSMatt Waddel #define SDI_DCTRL_BUSYMODE	0x00004000
13823b93e1dSMatt Waddel #define SDI_DCTRL_DDR_MODE	0x00008000
13910ed93dcSJohn Rigby #define SDI_DCTRL_DBLOCKSIZE_V2_MASK   0x7fff0000
14010ed93dcSJohn Rigby #define SDI_DCTRL_DBLOCKSIZE_V2_SHIFT  16
14123b93e1dSMatt Waddel 
14223b93e1dSMatt Waddel #define SDI_FIFO_BURST_SIZE	8
14323b93e1dSMatt Waddel 
1443c0dbed2SPatrice Chotard #define VERSION1	false
1453c0dbed2SPatrice Chotard #define VERSION2	true
1463c0dbed2SPatrice Chotard 
14723b93e1dSMatt Waddel struct sdi_registers {
14823b93e1dSMatt Waddel 	u32 power;		/* 0x00*/
14923b93e1dSMatt Waddel 	u32 clock;		/* 0x04*/
15023b93e1dSMatt Waddel 	u32 argument;		/* 0x08*/
15123b93e1dSMatt Waddel 	u32 command;		/* 0x0c*/
15223b93e1dSMatt Waddel 	u32 respcommand;	/* 0x10*/
15323b93e1dSMatt Waddel 	u32 response0;		/* 0x14*/
15423b93e1dSMatt Waddel 	u32 response1;		/* 0x18*/
15523b93e1dSMatt Waddel 	u32 response2;		/* 0x1c*/
15623b93e1dSMatt Waddel 	u32 response3;		/* 0x20*/
15723b93e1dSMatt Waddel 	u32 datatimer;		/* 0x24*/
15823b93e1dSMatt Waddel 	u32 datalength;		/* 0x28*/
15923b93e1dSMatt Waddel 	u32 datactrl;		/* 0x2c*/
16023b93e1dSMatt Waddel 	u32 datacount;		/* 0x30*/
16123b93e1dSMatt Waddel 	u32 status;		/* 0x34*/
16223b93e1dSMatt Waddel 	u32 status_clear;	/* 0x38*/
16323b93e1dSMatt Waddel 	u32 mask0;		/* 0x3c*/
16423b93e1dSMatt Waddel 	u32 mask1;		/* 0x40*/
16523b93e1dSMatt Waddel 	u32 card_select;	/* 0x44*/
16623b93e1dSMatt Waddel 	u32 fifo_count;		/* 0x48*/
16723b93e1dSMatt Waddel 	u32 padding1[(0x80-0x4C)>>2];
16823b93e1dSMatt Waddel 	u32 fifo;		/* 0x80*/
16923b93e1dSMatt Waddel 	u32 padding2[(0xFE0-0x84)>>2];
17023b93e1dSMatt Waddel 	u32 periph_id0;		/* 0xFE0 mmc Peripheral Identifcation Register*/
17123b93e1dSMatt Waddel 	u32 periph_id1;		/* 0xFE4*/
17223b93e1dSMatt Waddel 	u32 periph_id2;		/* 0xFE8*/
17323b93e1dSMatt Waddel 	u32 periph_id3;		/* 0xFEC*/
17423b93e1dSMatt Waddel 	u32 pcell_id0;		/* 0xFF0*/
17523b93e1dSMatt Waddel 	u32 pcell_id1;		/* 0xFF4*/
17623b93e1dSMatt Waddel 	u32 pcell_id2;		/* 0xFF8*/
17723b93e1dSMatt Waddel 	u32 pcell_id3;		/* 0xFFC*/
17823b93e1dSMatt Waddel };
17923b93e1dSMatt Waddel 
18010ed93dcSJohn Rigby struct pl180_mmc_host {
18110ed93dcSJohn Rigby 	struct sdi_registers *base;
18210ed93dcSJohn Rigby 	char name[32];
18310ed93dcSJohn Rigby 	unsigned int b_max;
18410ed93dcSJohn Rigby 	unsigned int voltages;
18510ed93dcSJohn Rigby 	unsigned int caps;
18610ed93dcSJohn Rigby 	unsigned int clock_in;
18710ed93dcSJohn Rigby 	unsigned int clock_min;
18810ed93dcSJohn Rigby 	unsigned int clock_max;
18910ed93dcSJohn Rigby 	unsigned int clkdiv_init;
19010ed93dcSJohn Rigby 	unsigned int pwr_init;
19110ed93dcSJohn Rigby 	int version2;
19293bfd616SPantelis Antoniou 	struct mmc_config cfg;
1935829fe2dSPatrice Chotard #ifdef CONFIG_DM_MMC
1945829fe2dSPatrice Chotard 	struct gpio_desc cd_gpio;
1955829fe2dSPatrice Chotard 	bool cd_inverted;
1965829fe2dSPatrice Chotard #endif
19710ed93dcSJohn Rigby };
19810ed93dcSJohn Rigby 
199cb0060e8SPatrice Chotard int arm_pl180_mmci_init(struct pl180_mmc_host *host, struct mmc **mmc);
20010ed93dcSJohn Rigby 
20123b93e1dSMatt Waddel #endif
202