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