xref: /freebsd/sys/dev/sdhci/sdhci_xenon.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
16f207f5bSLuiz Otavio O Souza /*-
26f207f5bSLuiz Otavio O Souza  * Copyright (c) 2018 Rubicon Communications, LLC (Netgate)
36f207f5bSLuiz Otavio O Souza  * All rights reserved.
46f207f5bSLuiz Otavio O Souza  *
56f207f5bSLuiz Otavio O Souza  * Redistribution and use in source and binary forms, with or without
66f207f5bSLuiz Otavio O Souza  * modification, are permitted provided that the following conditions
76f207f5bSLuiz Otavio O Souza  * are met:
86f207f5bSLuiz Otavio O Souza  * 1. Redistributions of source code must retain the above copyright
96f207f5bSLuiz Otavio O Souza  *    notice, this list of conditions and the following disclaimer.
106f207f5bSLuiz Otavio O Souza  * 2. Redistributions in binary form must reproduce the above copyright
116f207f5bSLuiz Otavio O Souza  *    notice, this list of conditions and the following disclaimer in the
126f207f5bSLuiz Otavio O Souza  *    documentation and/or other materials provided with the distribution.
136f207f5bSLuiz Otavio O Souza  *
146f207f5bSLuiz Otavio O Souza  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
156f207f5bSLuiz Otavio O Souza  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
166f207f5bSLuiz Otavio O Souza  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
176f207f5bSLuiz Otavio O Souza  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
186f207f5bSLuiz Otavio O Souza  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
196f207f5bSLuiz Otavio O Souza  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
206f207f5bSLuiz Otavio O Souza  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
216f207f5bSLuiz Otavio O Souza  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
226f207f5bSLuiz Otavio O Souza  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
236f207f5bSLuiz Otavio O Souza  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
246f207f5bSLuiz Otavio O Souza  */
256f207f5bSLuiz Otavio O Souza 
266f207f5bSLuiz Otavio O Souza /*
276f207f5bSLuiz Otavio O Souza  * Marvel Xenon SDHCI driver defines.
286f207f5bSLuiz Otavio O Souza  */
296f207f5bSLuiz Otavio O Souza 
306f207f5bSLuiz Otavio O Souza #ifndef	_SDHCI_XENON_H_
316f207f5bSLuiz Otavio O Souza #define	_SDHCI_XENON_H_
326f207f5bSLuiz Otavio O Souza 
336f207f5bSLuiz Otavio O Souza #define	XENON_LOWEST_SDCLK_FREQ			100000
346f207f5bSLuiz Otavio O Souza #define	XENON_MMC_MAX_CLK			400000000
356f207f5bSLuiz Otavio O Souza 
366f207f5bSLuiz Otavio O Souza #define	XENON_SYS_OP_CTRL			0x0108
376f207f5bSLuiz Otavio O Souza #define	 XENON_AUTO_CLKGATE_DISABLE		(1 << 20)
386f207f5bSLuiz Otavio O Souza #define	 XENON_SDCLK_IDLEOFF_ENABLE_SHIFT	8
396f207f5bSLuiz Otavio O Souza 
406f207f5bSLuiz Otavio O Souza #define	XENON_SYS_EXT_OP_CTRL			0x010C
416f207f5bSLuiz Otavio O Souza #define	 XENON_MASK_CMD_CONFLICT_ERR		(1 << 8)
426f207f5bSLuiz Otavio O Souza 
436f207f5bSLuiz Otavio O Souza #define	XENON_SLOT_EMMC_CTRL			0x0130
446f207f5bSLuiz Otavio O Souza #define	 XENON_ENABLE_DATA_STROBE		(1 << 24)
456f207f5bSLuiz Otavio O Souza #define	 XENON_ENABLE_RESP_STROBE		(1 << 25)
466f207f5bSLuiz Otavio O Souza 
474fa977f8SMarcin Wojtas /* Custom HS200 / HS400 Mode Select values in SDHCI_HOST_CONTROL2 register. */
484fa977f8SMarcin Wojtas #define	XENON_CTRL2_MMC_HS200			0x5
494fa977f8SMarcin Wojtas #define	XENON_CTRL2_MMC_HS400			0x6
504fa977f8SMarcin Wojtas 
516f207f5bSLuiz Otavio O Souza /* eMMC PHY */
526f207f5bSLuiz Otavio O Souza #define	XENON_EMMC_PHY_REG_BASE			0x170
536f207f5bSLuiz Otavio O Souza 
546f207f5bSLuiz Otavio O Souza #define	XENON_EMMC_PHY_TIMING_ADJUST		XENON_EMMC_PHY_REG_BASE
556f207f5bSLuiz Otavio O Souza #define	 XENON_SAMPL_INV_QSP_PHASE_SELECT	(1 << 18)
566f207f5bSLuiz Otavio O Souza #define	 XENON_TIMING_ADJUST_SDIO_MODE		(1 << 28)
576f207f5bSLuiz Otavio O Souza #define	 XENON_TIMING_ADJUST_SLOW_MODE		(1 << 29)
586f207f5bSLuiz Otavio O Souza #define	 XENON_PHY_INITIALIZATION		(1U << 31)
596f207f5bSLuiz Otavio O Souza #define	 XENON_WAIT_CYCLE_BEFORE_USING_MASK	0xF
606f207f5bSLuiz Otavio O Souza #define	 XENON_WAIT_CYCLE_BEFORE_USING_SHIFT	12
616f207f5bSLuiz Otavio O Souza #define	 XENON_FC_SYNC_EN_DURATION_MASK		0xF
626f207f5bSLuiz Otavio O Souza #define	 XENON_FC_SYNC_EN_DURATION_SHIFT	8
636f207f5bSLuiz Otavio O Souza #define	 XENON_FC_SYNC_RST_EN_DURATION_MASK	0xF
646f207f5bSLuiz Otavio O Souza #define	 XENON_FC_SYNC_RST_EN_DURATION_SHIFT	4
656f207f5bSLuiz Otavio O Souza #define	 XENON_FC_SYNC_RST_DURATION_MASK	0xF
666f207f5bSLuiz Otavio O Souza #define	 XENON_FC_SYNC_RST_DURATION_SHIFT	0
676f207f5bSLuiz Otavio O Souza 
686f207f5bSLuiz Otavio O Souza #define	XENON_EMMC_PHY_FUNC_CONTROL		(XENON_EMMC_PHY_REG_BASE + 0x4)
696f207f5bSLuiz Otavio O Souza #define	 XENON_DQ_ASYNC_MODE			(1 << 4)
706f207f5bSLuiz Otavio O Souza #define	 XENON_CMD_DDR_MODE			(1 << 16)
716f207f5bSLuiz Otavio O Souza #define	 XENON_DQ_DDR_MODE_SHIFT		8
726f207f5bSLuiz Otavio O Souza #define	 XENON_DQ_DDR_MODE_MASK			0xFF
736f207f5bSLuiz Otavio O Souza #define	 XENON_ASYNC_DDRMODE_MASK		(1 << 23)
746f207f5bSLuiz Otavio O Souza #define	 XENON_ASYNC_DDRMODE_SHIFT		23
756f207f5bSLuiz Otavio O Souza 
766f207f5bSLuiz Otavio O Souza #define	XENON_EMMC_PHY_PAD_CONTROL		(XENON_EMMC_PHY_REG_BASE + 0x8)
776f207f5bSLuiz Otavio O Souza #define	 XENON_FC_DQ_RECEN			(1 << 24)
786f207f5bSLuiz Otavio O Souza #define	 XENON_FC_CMD_RECEN			(1 << 25)
796f207f5bSLuiz Otavio O Souza #define	 XENON_FC_QSP_RECEN			(1 << 26)
806f207f5bSLuiz Otavio O Souza #define	 XENON_FC_QSN_RECEN			(1 << 27)
816f207f5bSLuiz Otavio O Souza #define	 XENON_OEN_QSN				(1 << 28)
826f207f5bSLuiz Otavio O Souza #define	 XENON_FC_ALL_CMOS_RECEIVER		0xF000
836f207f5bSLuiz Otavio O Souza 
846f207f5bSLuiz Otavio O Souza #define	XENON_EMMC_PHY_PAD_CONTROL1		(XENON_EMMC_PHY_REG_BASE + 0xC)
856f207f5bSLuiz Otavio O Souza #define	 XENON_EMMC_FC_CMD_PD			(1 << 8)
866f207f5bSLuiz Otavio O Souza #define	 XENON_EMMC_FC_QSP_PD			(1 << 9)
876f207f5bSLuiz Otavio O Souza #define	 XENON_EMMC_FC_CMD_PU			(1 << 24)
886f207f5bSLuiz Otavio O Souza #define	 XENON_EMMC_FC_QSP_PU			(1 << 25)
896f207f5bSLuiz Otavio O Souza #define	 XENON_EMMC_FC_DQ_PD			0xFF
906f207f5bSLuiz Otavio O Souza #define	 XENON_EMMC_FC_DQ_PU			(0xFF << 16)
916f207f5bSLuiz Otavio O Souza 
926f207f5bSLuiz Otavio O Souza #define	XENON_EMMC_PHY_PAD_CONTROL2		(XENON_EMMC_PHY_REG_BASE + 0x10)
936f207f5bSLuiz Otavio O Souza #define	 XENON_ZNR_MASK				0x1F
946f207f5bSLuiz Otavio O Souza #define	 XENON_ZNR_SHIFT			8
956f207f5bSLuiz Otavio O Souza #define	 XENON_ZPR_MASK				0x1F
966f207f5bSLuiz Otavio O Souza #define	 XENON_ZNR_DEF_VALUE			0xF
976f207f5bSLuiz Otavio O Souza #define	 XENON_ZPR_DEF_VALUE			0xF
986f207f5bSLuiz Otavio O Souza 
996f207f5bSLuiz Otavio O Souza #define	XENON_EMMC_PHY_LOGIC_TIMING_ADJUST	(XENON_EMMC_PHY_REG_BASE + 0x18)
1006f207f5bSLuiz Otavio O Souza #define	 XENON_LOGIC_TIMING_VALUE		0x00AA8977
1016f207f5bSLuiz Otavio O Souza 
102*d78e464dSBartlomiej Grzesik DECLARE_CLASS(sdhci_xenon_driver);
103*d78e464dSBartlomiej Grzesik 
104*d78e464dSBartlomiej Grzesik struct sdhci_xenon_softc {
105*d78e464dSBartlomiej Grzesik 	device_t	dev;		/* Controller device */
106*d78e464dSBartlomiej Grzesik 	int		slot_id;	/* Controller ID */
107*d78e464dSBartlomiej Grzesik 
108*d78e464dSBartlomiej Grzesik 	struct resource	*mem_res;	/* Memory resource */
109*d78e464dSBartlomiej Grzesik 	struct resource *irq_res;	/* IRQ resource */
110*d78e464dSBartlomiej Grzesik 	void		*intrhand;	/* Interrupt handle */
111*d78e464dSBartlomiej Grzesik 
112*d78e464dSBartlomiej Grzesik 	struct sdhci_slot *slot;	/* SDHCI internal data */
113*d78e464dSBartlomiej Grzesik 
114*d78e464dSBartlomiej Grzesik 	uint8_t		znr;		/* PHY ZNR */
115*d78e464dSBartlomiej Grzesik 	uint8_t		zpr;		/* PHY ZPR */
116*d78e464dSBartlomiej Grzesik 	bool		slow_mode;	/* PHY slow mode */
117*d78e464dSBartlomiej Grzesik 	bool		wp_inverted;
118*d78e464dSBartlomiej Grzesik 	bool		skip_regulators; /* Don't switch regulators */
119*d78e464dSBartlomiej Grzesik 
120*d78e464dSBartlomiej Grzesik 	regulator_t	vmmc_supply;
121*d78e464dSBartlomiej Grzesik 	regulator_t	vqmmc_supply;
122*d78e464dSBartlomiej Grzesik 
123*d78e464dSBartlomiej Grzesik #ifdef FDT
124*d78e464dSBartlomiej Grzesik 	struct sdhci_fdt_gpio *gpio;	/* GPIO pins for CD detection. */
125*d78e464dSBartlomiej Grzesik #endif
126*d78e464dSBartlomiej Grzesik };
127*d78e464dSBartlomiej Grzesik 
128*d78e464dSBartlomiej Grzesik device_attach_t sdhci_xenon_attach;
129*d78e464dSBartlomiej Grzesik device_detach_t sdhci_xenon_detach;
130*d78e464dSBartlomiej Grzesik 
1316f207f5bSLuiz Otavio O Souza #endif	/* _SDHCI_XENON_H_ */
132