xref: /linux/drivers/mmc/host/dw_mmc-exynos.c (revision 79790b6818e96c58fe2bffee1b418c16e64e7b80)
12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2c3665006SThomas Abraham /*
3c3665006SThomas Abraham  * Exynos Specific Extensions for Synopsys DW Multimedia Card Interface driver
4c3665006SThomas Abraham  *
5c3665006SThomas Abraham  * Copyright (C) 2012, Samsung Electronics Co., Ltd.
6c3665006SThomas Abraham  */
7c3665006SThomas Abraham 
8c3665006SThomas Abraham #include <linux/module.h>
9c3665006SThomas Abraham #include <linux/platform_device.h>
10c3665006SThomas Abraham #include <linux/clk.h>
11c3665006SThomas Abraham #include <linux/mmc/host.h>
12c537a1c5SSeungwon Jeon #include <linux/mmc/mmc.h>
13c3665006SThomas Abraham #include <linux/of.h>
14cf5237efSShawn Lin #include <linux/pm_runtime.h>
15c537a1c5SSeungwon Jeon #include <linux/slab.h>
16c3665006SThomas Abraham 
17c3665006SThomas Abraham #include "dw_mmc.h"
18c3665006SThomas Abraham #include "dw_mmc-pltfm.h"
190b5fce48SSeungwon Jeon #include "dw_mmc-exynos.h"
20c6d9dedaSSeungwon Jeon 
21c3665006SThomas Abraham /* Variations in Exynos specific dw-mshc controller */
22c3665006SThomas Abraham enum dw_mci_exynos_type {
23c3665006SThomas Abraham 	DW_MCI_TYPE_EXYNOS4210,
24c3665006SThomas Abraham 	DW_MCI_TYPE_EXYNOS4412,
25c3665006SThomas Abraham 	DW_MCI_TYPE_EXYNOS5250,
2600fd041bSYuvaraj Kumar C D 	DW_MCI_TYPE_EXYNOS5420,
276bce431cSYuvaraj Kumar C D 	DW_MCI_TYPE_EXYNOS5420_SMU,
2889ad2be7SAbhilash Kesavan 	DW_MCI_TYPE_EXYNOS7,
2989ad2be7SAbhilash Kesavan 	DW_MCI_TYPE_EXYNOS7_SMU,
3091e2ca22SMårten Lindahl 	DW_MCI_TYPE_ARTPEC8,
31c3665006SThomas Abraham };
32c3665006SThomas Abraham 
33c3665006SThomas Abraham /* Exynos implementation specific driver private data */
34c3665006SThomas Abraham struct dw_mci_exynos_priv_data {
35c3665006SThomas Abraham 	enum dw_mci_exynos_type		ctrl_type;
36c3665006SThomas Abraham 	u8				ciu_div;
37c3665006SThomas Abraham 	u32				sdr_timing;
38c3665006SThomas Abraham 	u32				ddr_timing;
3980113132SSeungwon Jeon 	u32				hs400_timing;
4080113132SSeungwon Jeon 	u32				tuned_sample;
41c6d9dedaSSeungwon Jeon 	u32				cur_speed;
4280113132SSeungwon Jeon 	u32				dqs_delay;
4380113132SSeungwon Jeon 	u32				saved_dqs_en;
4480113132SSeungwon Jeon 	u32				saved_strobe_ctrl;
45c3665006SThomas Abraham };
46c3665006SThomas Abraham 
47c3665006SThomas Abraham static struct dw_mci_exynos_compatible {
48c3665006SThomas Abraham 	char				*compatible;
49c3665006SThomas Abraham 	enum dw_mci_exynos_type		ctrl_type;
50c3665006SThomas Abraham } exynos_compat[] = {
51c3665006SThomas Abraham 	{
52c3665006SThomas Abraham 		.compatible	= "samsung,exynos4210-dw-mshc",
53c3665006SThomas Abraham 		.ctrl_type	= DW_MCI_TYPE_EXYNOS4210,
54c3665006SThomas Abraham 	}, {
55c3665006SThomas Abraham 		.compatible	= "samsung,exynos4412-dw-mshc",
56c3665006SThomas Abraham 		.ctrl_type	= DW_MCI_TYPE_EXYNOS4412,
57c3665006SThomas Abraham 	}, {
58c3665006SThomas Abraham 		.compatible	= "samsung,exynos5250-dw-mshc",
59c3665006SThomas Abraham 		.ctrl_type	= DW_MCI_TYPE_EXYNOS5250,
6000fd041bSYuvaraj Kumar C D 	}, {
6100fd041bSYuvaraj Kumar C D 		.compatible	= "samsung,exynos5420-dw-mshc",
6200fd041bSYuvaraj Kumar C D 		.ctrl_type	= DW_MCI_TYPE_EXYNOS5420,
636bce431cSYuvaraj Kumar C D 	}, {
646bce431cSYuvaraj Kumar C D 		.compatible	= "samsung,exynos5420-dw-mshc-smu",
656bce431cSYuvaraj Kumar C D 		.ctrl_type	= DW_MCI_TYPE_EXYNOS5420_SMU,
6689ad2be7SAbhilash Kesavan 	}, {
6789ad2be7SAbhilash Kesavan 		.compatible	= "samsung,exynos7-dw-mshc",
6889ad2be7SAbhilash Kesavan 		.ctrl_type	= DW_MCI_TYPE_EXYNOS7,
6989ad2be7SAbhilash Kesavan 	}, {
7089ad2be7SAbhilash Kesavan 		.compatible	= "samsung,exynos7-dw-mshc-smu",
7189ad2be7SAbhilash Kesavan 		.ctrl_type	= DW_MCI_TYPE_EXYNOS7_SMU,
7291e2ca22SMårten Lindahl 	}, {
7391e2ca22SMårten Lindahl 		.compatible	= "axis,artpec8-dw-mshc",
7491e2ca22SMårten Lindahl 		.ctrl_type	= DW_MCI_TYPE_ARTPEC8,
75c3665006SThomas Abraham 	},
76c3665006SThomas Abraham };
77c3665006SThomas Abraham 
dw_mci_exynos_get_ciu_div(struct dw_mci * host)7880113132SSeungwon Jeon static inline u8 dw_mci_exynos_get_ciu_div(struct dw_mci *host)
7980113132SSeungwon Jeon {
8080113132SSeungwon Jeon 	struct dw_mci_exynos_priv_data *priv = host->priv;
8180113132SSeungwon Jeon 
8280113132SSeungwon Jeon 	if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4412)
8380113132SSeungwon Jeon 		return EXYNOS4412_FIXED_CIU_CLK_DIV;
8480113132SSeungwon Jeon 	else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4210)
8580113132SSeungwon Jeon 		return EXYNOS4210_FIXED_CIU_CLK_DIV;
8680113132SSeungwon Jeon 	else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 ||
8791e2ca22SMårten Lindahl 			priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU ||
8891e2ca22SMårten Lindahl 			priv->ctrl_type == DW_MCI_TYPE_ARTPEC8)
8980113132SSeungwon Jeon 		return SDMMC_CLKSEL_GET_DIV(mci_readl(host, CLKSEL64)) + 1;
9080113132SSeungwon Jeon 	else
9180113132SSeungwon Jeon 		return SDMMC_CLKSEL_GET_DIV(mci_readl(host, CLKSEL)) + 1;
9280113132SSeungwon Jeon }
9380113132SSeungwon Jeon 
dw_mci_exynos_config_smu(struct dw_mci * host)945659eeadSJaehoon Chung static void dw_mci_exynos_config_smu(struct dw_mci *host)
95c3665006SThomas Abraham {
96e6c784edSYuvaraj Kumar C D 	struct dw_mci_exynos_priv_data *priv = host->priv;
97c3665006SThomas Abraham 
985659eeadSJaehoon Chung 	/*
995659eeadSJaehoon Chung 	 * If Exynos is provided the Security management,
1005659eeadSJaehoon Chung 	 * set for non-ecryption mode at this time.
1015659eeadSJaehoon Chung 	 */
10289ad2be7SAbhilash Kesavan 	if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS5420_SMU ||
10389ad2be7SAbhilash Kesavan 		priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU) {
1046bce431cSYuvaraj Kumar C D 		mci_writel(host, MPSBEGIN0, 0);
1050b5fce48SSeungwon Jeon 		mci_writel(host, MPSEND0, SDMMC_ENDING_SEC_NR_MAX);
1060b5fce48SSeungwon Jeon 		mci_writel(host, MPSCTRL0, SDMMC_MPSCTRL_SECURE_WRITE_BIT |
1070b5fce48SSeungwon Jeon 			   SDMMC_MPSCTRL_NON_SECURE_READ_BIT |
1080b5fce48SSeungwon Jeon 			   SDMMC_MPSCTRL_VALID |
1090b5fce48SSeungwon Jeon 			   SDMMC_MPSCTRL_NON_SECURE_WRITE_BIT);
1106bce431cSYuvaraj Kumar C D 	}
1115659eeadSJaehoon Chung }
1125659eeadSJaehoon Chung 
dw_mci_exynos_priv_init(struct dw_mci * host)1135659eeadSJaehoon Chung static int dw_mci_exynos_priv_init(struct dw_mci *host)
1145659eeadSJaehoon Chung {
1155659eeadSJaehoon Chung 	struct dw_mci_exynos_priv_data *priv = host->priv;
1165659eeadSJaehoon Chung 
1175659eeadSJaehoon Chung 	dw_mci_exynos_config_smu(host);
1186bce431cSYuvaraj Kumar C D 
11980113132SSeungwon Jeon 	if (priv->ctrl_type >= DW_MCI_TYPE_EXYNOS5420) {
12080113132SSeungwon Jeon 		priv->saved_strobe_ctrl = mci_readl(host, HS400_DLINE_CTRL);
12180113132SSeungwon Jeon 		priv->saved_dqs_en = mci_readl(host, HS400_DQS_EN);
12280113132SSeungwon Jeon 		priv->saved_dqs_en |= AXI_NON_BLOCKING_WR;
12380113132SSeungwon Jeon 		mci_writel(host, HS400_DQS_EN, priv->saved_dqs_en);
12480113132SSeungwon Jeon 		if (!priv->dqs_delay)
12580113132SSeungwon Jeon 			priv->dqs_delay =
12680113132SSeungwon Jeon 				DQS_CTRL_GET_RD_DELAY(priv->saved_strobe_ctrl);
12780113132SSeungwon Jeon 	}
12880113132SSeungwon Jeon 
1291a6fe7bbSMårten Lindahl 	if (priv->ctrl_type == DW_MCI_TYPE_ARTPEC8) {
1301a6fe7bbSMårten Lindahl 		/* Quirk needed for the ARTPEC-8 SoC */
1311a6fe7bbSMårten Lindahl 		host->quirks |= DW_MMC_QUIRK_EXTENDED_TMOUT;
1321a6fe7bbSMårten Lindahl 	}
1331a6fe7bbSMårten Lindahl 
134a2a1fed8SSeungwon Jeon 	host->bus_hz /= (priv->ciu_div + 1);
135a2a1fed8SSeungwon Jeon 
136c3665006SThomas Abraham 	return 0;
137c3665006SThomas Abraham }
138c3665006SThomas Abraham 
dw_mci_exynos_set_clksel_timing(struct dw_mci * host,u32 timing)13980113132SSeungwon Jeon static void dw_mci_exynos_set_clksel_timing(struct dw_mci *host, u32 timing)
14080113132SSeungwon Jeon {
14180113132SSeungwon Jeon 	struct dw_mci_exynos_priv_data *priv = host->priv;
14280113132SSeungwon Jeon 	u32 clksel;
14380113132SSeungwon Jeon 
14480113132SSeungwon Jeon 	if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 ||
14591e2ca22SMårten Lindahl 		priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU ||
14691e2ca22SMårten Lindahl 		priv->ctrl_type == DW_MCI_TYPE_ARTPEC8)
14780113132SSeungwon Jeon 		clksel = mci_readl(host, CLKSEL64);
14880113132SSeungwon Jeon 	else
14980113132SSeungwon Jeon 		clksel = mci_readl(host, CLKSEL);
15080113132SSeungwon Jeon 
15180113132SSeungwon Jeon 	clksel = (clksel & ~SDMMC_CLKSEL_TIMING_MASK) | timing;
15280113132SSeungwon Jeon 
15380113132SSeungwon Jeon 	if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 ||
15491e2ca22SMårten Lindahl 		priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU ||
15591e2ca22SMårten Lindahl 		priv->ctrl_type == DW_MCI_TYPE_ARTPEC8)
15680113132SSeungwon Jeon 		mci_writel(host, CLKSEL64, clksel);
15780113132SSeungwon Jeon 	else
15880113132SSeungwon Jeon 		mci_writel(host, CLKSEL, clksel);
159aaaaeb7aSJaehoon Chung 
160aaaaeb7aSJaehoon Chung 	/*
161aaaaeb7aSJaehoon Chung 	 * Exynos4412 and Exynos5250 extends the use of CMD register with the
162aaaaeb7aSJaehoon Chung 	 * use of bit 29 (which is reserved on standard MSHC controllers) for
163aaaaeb7aSJaehoon Chung 	 * optionally bypassing the HOLD register for command and data. The
164aaaaeb7aSJaehoon Chung 	 * HOLD register should be bypassed in case there is no phase shift
165aaaaeb7aSJaehoon Chung 	 * applied on CMD/DATA that is sent to the card.
166aaaaeb7aSJaehoon Chung 	 */
16742f989c0SJaehoon Chung 	if (!SDMMC_CLKSEL_GET_DRV_WD3(clksel) && host->slot)
16842f989c0SJaehoon Chung 		set_bit(DW_MMC_CARD_NO_USE_HOLD, &host->slot->flags);
16980113132SSeungwon Jeon }
17080113132SSeungwon Jeon 
171cf5237efSShawn Lin #ifdef CONFIG_PM
dw_mci_exynos_runtime_resume(struct device * dev)172cf5237efSShawn Lin static int dw_mci_exynos_runtime_resume(struct device *dev)
173e2c63599SDoug Anderson {
174e2c63599SDoug Anderson 	struct dw_mci *host = dev_get_drvdata(dev);
175e22842ddSJaehoon Chung 	int ret;
176e22842ddSJaehoon Chung 
177e22842ddSJaehoon Chung 	ret = dw_mci_runtime_resume(dev);
178e22842ddSJaehoon Chung 	if (ret)
179e22842ddSJaehoon Chung 		return ret;
180e2c63599SDoug Anderson 
1815659eeadSJaehoon Chung 	dw_mci_exynos_config_smu(host);
182e22842ddSJaehoon Chung 
183e22842ddSJaehoon Chung 	return ret;
184e2c63599SDoug Anderson }
185ecf7c7c5SMarek Szyprowski #endif /* CONFIG_PM */
186ecf7c7c5SMarek Szyprowski 
187ecf7c7c5SMarek Szyprowski #ifdef CONFIG_PM_SLEEP
188ecf7c7c5SMarek Szyprowski /**
189ecf7c7c5SMarek Szyprowski  * dw_mci_exynos_suspend_noirq - Exynos-specific suspend code
190306c59cbSLee Jones  * @dev: Device to suspend (this device)
191ecf7c7c5SMarek Szyprowski  *
192ecf7c7c5SMarek Szyprowski  * This ensures that device will be in runtime active state in
193ecf7c7c5SMarek Szyprowski  * dw_mci_exynos_resume_noirq after calling pm_runtime_force_resume()
194ecf7c7c5SMarek Szyprowski  */
dw_mci_exynos_suspend_noirq(struct device * dev)195ecf7c7c5SMarek Szyprowski static int dw_mci_exynos_suspend_noirq(struct device *dev)
196ecf7c7c5SMarek Szyprowski {
197ecf7c7c5SMarek Szyprowski 	pm_runtime_get_noresume(dev);
198ecf7c7c5SMarek Szyprowski 	return pm_runtime_force_suspend(dev);
199ecf7c7c5SMarek Szyprowski }
200e2c63599SDoug Anderson 
201e2c63599SDoug Anderson /**
202e2c63599SDoug Anderson  * dw_mci_exynos_resume_noirq - Exynos-specific resume code
203306c59cbSLee Jones  * @dev: Device to resume (this device)
204e2c63599SDoug Anderson  *
205e2c63599SDoug Anderson  * On exynos5420 there is a silicon errata that will sometimes leave the
206e2c63599SDoug Anderson  * WAKEUP_INT bit in the CLKSEL register asserted.  This bit is 1 to indicate
207e2c63599SDoug Anderson  * that it fired and we can clear it by writing a 1 back.  Clear it to prevent
208e2c63599SDoug Anderson  * interrupts from going off constantly.
209e2c63599SDoug Anderson  *
210e2c63599SDoug Anderson  * We run this code on all exynos variants because it doesn't hurt.
211e2c63599SDoug Anderson  */
dw_mci_exynos_resume_noirq(struct device * dev)212e2c63599SDoug Anderson static int dw_mci_exynos_resume_noirq(struct device *dev)
213e2c63599SDoug Anderson {
214e2c63599SDoug Anderson 	struct dw_mci *host = dev_get_drvdata(dev);
21589ad2be7SAbhilash Kesavan 	struct dw_mci_exynos_priv_data *priv = host->priv;
216e2c63599SDoug Anderson 	u32 clksel;
217ecf7c7c5SMarek Szyprowski 	int ret;
218ecf7c7c5SMarek Szyprowski 
219ecf7c7c5SMarek Szyprowski 	ret = pm_runtime_force_resume(dev);
220ecf7c7c5SMarek Szyprowski 	if (ret)
221ecf7c7c5SMarek Szyprowski 		return ret;
222e2c63599SDoug Anderson 
22389ad2be7SAbhilash Kesavan 	if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 ||
22491e2ca22SMårten Lindahl 		priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU ||
22591e2ca22SMårten Lindahl 		priv->ctrl_type == DW_MCI_TYPE_ARTPEC8)
22689ad2be7SAbhilash Kesavan 		clksel = mci_readl(host, CLKSEL64);
22789ad2be7SAbhilash Kesavan 	else
228e2c63599SDoug Anderson 		clksel = mci_readl(host, CLKSEL);
22989ad2be7SAbhilash Kesavan 
23089ad2be7SAbhilash Kesavan 	if (clksel & SDMMC_CLKSEL_WAKEUP_INT) {
23189ad2be7SAbhilash Kesavan 		if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 ||
23291e2ca22SMårten Lindahl 			priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU ||
23391e2ca22SMårten Lindahl 			priv->ctrl_type == DW_MCI_TYPE_ARTPEC8)
23489ad2be7SAbhilash Kesavan 			mci_writel(host, CLKSEL64, clksel);
23589ad2be7SAbhilash Kesavan 		else
236e2c63599SDoug Anderson 			mci_writel(host, CLKSEL, clksel);
23789ad2be7SAbhilash Kesavan 	}
238e2c63599SDoug Anderson 
239ecf7c7c5SMarek Szyprowski 	pm_runtime_put(dev);
240ecf7c7c5SMarek Szyprowski 
241e2c63599SDoug Anderson 	return 0;
242e2c63599SDoug Anderson }
243ecf7c7c5SMarek Szyprowski #endif /* CONFIG_PM_SLEEP */
244e2c63599SDoug Anderson 
dw_mci_exynos_config_hs400(struct dw_mci * host,u32 timing)24580113132SSeungwon Jeon static void dw_mci_exynos_config_hs400(struct dw_mci *host, u32 timing)
246c3665006SThomas Abraham {
247c3665006SThomas Abraham 	struct dw_mci_exynos_priv_data *priv = host->priv;
24880113132SSeungwon Jeon 	u32 dqs, strobe;
249c3665006SThomas Abraham 
25080113132SSeungwon Jeon 	/*
25180113132SSeungwon Jeon 	 * Not supported to configure register
25280113132SSeungwon Jeon 	 * related to HS400
25380113132SSeungwon Jeon 	 */
25491e2ca22SMårten Lindahl 	if ((priv->ctrl_type < DW_MCI_TYPE_EXYNOS5420) ||
25591e2ca22SMårten Lindahl 		(priv->ctrl_type == DW_MCI_TYPE_ARTPEC8)) {
256941a659fSKrzysztof Kozlowski 		if (timing == MMC_TIMING_MMC_HS400)
257941a659fSKrzysztof Kozlowski 			dev_warn(host->dev,
258941a659fSKrzysztof Kozlowski 				 "cannot configure HS400, unsupported chipset\n");
25980113132SSeungwon Jeon 		return;
260941a659fSKrzysztof Kozlowski 	}
26180113132SSeungwon Jeon 
26280113132SSeungwon Jeon 	dqs = priv->saved_dqs_en;
26380113132SSeungwon Jeon 	strobe = priv->saved_strobe_ctrl;
26480113132SSeungwon Jeon 
26580113132SSeungwon Jeon 	if (timing == MMC_TIMING_MMC_HS400) {
26680113132SSeungwon Jeon 		dqs |= DATA_STROBE_EN;
26780113132SSeungwon Jeon 		strobe = DQS_CTRL_RD_DELAY(strobe, priv->dqs_delay);
26832b64b03SAnand Moon 	} else if (timing == MMC_TIMING_UHS_SDR104) {
26932b64b03SAnand Moon 		dqs &= 0xffffff00;
270c6d9dedaSSeungwon Jeon 	} else {
27180113132SSeungwon Jeon 		dqs &= ~DATA_STROBE_EN;
272c3665006SThomas Abraham 	}
273c3665006SThomas Abraham 
27480113132SSeungwon Jeon 	mci_writel(host, HS400_DQS_EN, dqs);
27580113132SSeungwon Jeon 	mci_writel(host, HS400_DLINE_CTRL, strobe);
27680113132SSeungwon Jeon }
27780113132SSeungwon Jeon 
dw_mci_exynos_adjust_clock(struct dw_mci * host,unsigned int wanted)27880113132SSeungwon Jeon static void dw_mci_exynos_adjust_clock(struct dw_mci *host, unsigned int wanted)
27980113132SSeungwon Jeon {
28080113132SSeungwon Jeon 	struct dw_mci_exynos_priv_data *priv = host->priv;
28180113132SSeungwon Jeon 	unsigned long actual;
28280113132SSeungwon Jeon 	u8 div;
28380113132SSeungwon Jeon 	int ret;
284a2a1fed8SSeungwon Jeon 	/*
285a2a1fed8SSeungwon Jeon 	 * Don't care if wanted clock is zero or
286a2a1fed8SSeungwon Jeon 	 * ciu clock is unavailable
287a2a1fed8SSeungwon Jeon 	 */
288a2a1fed8SSeungwon Jeon 	if (!wanted || IS_ERR(host->ciu_clk))
289c6d9dedaSSeungwon Jeon 		return;
290c6d9dedaSSeungwon Jeon 
291c6d9dedaSSeungwon Jeon 	/* Guaranteed minimum frequency for cclkin */
292c6d9dedaSSeungwon Jeon 	if (wanted < EXYNOS_CCLKIN_MIN)
293c6d9dedaSSeungwon Jeon 		wanted = EXYNOS_CCLKIN_MIN;
294c6d9dedaSSeungwon Jeon 
29580113132SSeungwon Jeon 	if (wanted == priv->cur_speed)
29680113132SSeungwon Jeon 		return;
29780113132SSeungwon Jeon 
29880113132SSeungwon Jeon 	div = dw_mci_exynos_get_ciu_div(host);
29980113132SSeungwon Jeon 	ret = clk_set_rate(host->ciu_clk, wanted * div);
300c6d9dedaSSeungwon Jeon 	if (ret)
301c6d9dedaSSeungwon Jeon 		dev_warn(host->dev,
302c6d9dedaSSeungwon Jeon 			"failed to set clk-rate %u error: %d\n",
303c6d9dedaSSeungwon Jeon 			wanted * div, ret);
304c6d9dedaSSeungwon Jeon 	actual = clk_get_rate(host->ciu_clk);
305c6d9dedaSSeungwon Jeon 	host->bus_hz = actual / div;
306c6d9dedaSSeungwon Jeon 	priv->cur_speed = wanted;
307c6d9dedaSSeungwon Jeon 	host->current_speed = 0;
308c6d9dedaSSeungwon Jeon }
30980113132SSeungwon Jeon 
dw_mci_exynos_set_ios(struct dw_mci * host,struct mmc_ios * ios)31080113132SSeungwon Jeon static void dw_mci_exynos_set_ios(struct dw_mci *host, struct mmc_ios *ios)
31180113132SSeungwon Jeon {
31280113132SSeungwon Jeon 	struct dw_mci_exynos_priv_data *priv = host->priv;
31380113132SSeungwon Jeon 	unsigned int wanted = ios->clock;
31480113132SSeungwon Jeon 	u32 timing = ios->timing, clksel;
31580113132SSeungwon Jeon 
31680113132SSeungwon Jeon 	switch (timing) {
31780113132SSeungwon Jeon 	case MMC_TIMING_MMC_HS400:
31880113132SSeungwon Jeon 		/* Update tuned sample timing */
31980113132SSeungwon Jeon 		clksel = SDMMC_CLKSEL_UP_SAMPLE(
32080113132SSeungwon Jeon 				priv->hs400_timing, priv->tuned_sample);
32180113132SSeungwon Jeon 		wanted <<= 1;
32280113132SSeungwon Jeon 		break;
32380113132SSeungwon Jeon 	case MMC_TIMING_MMC_DDR52:
32480113132SSeungwon Jeon 		clksel = priv->ddr_timing;
32580113132SSeungwon Jeon 		/* Should be double rate for DDR mode */
32680113132SSeungwon Jeon 		if (ios->bus_width == MMC_BUS_WIDTH_8)
32780113132SSeungwon Jeon 			wanted <<= 1;
32880113132SSeungwon Jeon 		break;
32932b64b03SAnand Moon 	case MMC_TIMING_UHS_SDR104:
33032b64b03SAnand Moon 	case MMC_TIMING_UHS_SDR50:
33132b64b03SAnand Moon 		clksel = (priv->sdr_timing & 0xfff8ffff) |
33232b64b03SAnand Moon 			(priv->ciu_div << 16);
33332b64b03SAnand Moon 		break;
33432b64b03SAnand Moon 	case MMC_TIMING_UHS_DDR50:
33532b64b03SAnand Moon 		clksel = (priv->ddr_timing & 0xfff8ffff) |
33632b64b03SAnand Moon 			(priv->ciu_div << 16);
33732b64b03SAnand Moon 		break;
33880113132SSeungwon Jeon 	default:
33980113132SSeungwon Jeon 		clksel = priv->sdr_timing;
34080113132SSeungwon Jeon 	}
34180113132SSeungwon Jeon 
34280113132SSeungwon Jeon 	/* Set clock timing for the requested speed mode*/
34380113132SSeungwon Jeon 	dw_mci_exynos_set_clksel_timing(host, clksel);
34480113132SSeungwon Jeon 
34580113132SSeungwon Jeon 	/* Configure setting for HS400 */
34680113132SSeungwon Jeon 	dw_mci_exynos_config_hs400(host, timing);
34780113132SSeungwon Jeon 
34880113132SSeungwon Jeon 	/* Configure clock rate */
34980113132SSeungwon Jeon 	dw_mci_exynos_adjust_clock(host, wanted);
350c6d9dedaSSeungwon Jeon }
351c6d9dedaSSeungwon Jeon 
dw_mci_exynos_parse_dt(struct dw_mci * host)352c3665006SThomas Abraham static int dw_mci_exynos_parse_dt(struct dw_mci *host)
353c3665006SThomas Abraham {
354e6c784edSYuvaraj Kumar C D 	struct dw_mci_exynos_priv_data *priv;
355c3665006SThomas Abraham 	struct device_node *np = host->dev->of_node;
356c3665006SThomas Abraham 	u32 timing[2];
357c3665006SThomas Abraham 	u32 div = 0;
358e6c784edSYuvaraj Kumar C D 	int idx;
359c3665006SThomas Abraham 	int ret;
360c3665006SThomas Abraham 
361e6c784edSYuvaraj Kumar C D 	priv = devm_kzalloc(host->dev, sizeof(*priv), GFP_KERNEL);
362bf3707eaSBeomho Seo 	if (!priv)
363e6c784edSYuvaraj Kumar C D 		return -ENOMEM;
364e6c784edSYuvaraj Kumar C D 
365e6c784edSYuvaraj Kumar C D 	for (idx = 0; idx < ARRAY_SIZE(exynos_compat); idx++) {
366e6c784edSYuvaraj Kumar C D 		if (of_device_is_compatible(np, exynos_compat[idx].compatible))
367e6c784edSYuvaraj Kumar C D 			priv->ctrl_type = exynos_compat[idx].ctrl_type;
368e6c784edSYuvaraj Kumar C D 	}
369e6c784edSYuvaraj Kumar C D 
370c6d9dedaSSeungwon Jeon 	if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4412)
371c6d9dedaSSeungwon Jeon 		priv->ciu_div = EXYNOS4412_FIXED_CIU_CLK_DIV - 1;
372c6d9dedaSSeungwon Jeon 	else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4210)
373c6d9dedaSSeungwon Jeon 		priv->ciu_div = EXYNOS4210_FIXED_CIU_CLK_DIV - 1;
374c6d9dedaSSeungwon Jeon 	else {
375c3665006SThomas Abraham 		of_property_read_u32(np, "samsung,dw-mshc-ciu-div", &div);
376c3665006SThomas Abraham 		priv->ciu_div = div;
377c6d9dedaSSeungwon Jeon 	}
378c3665006SThomas Abraham 
379c3665006SThomas Abraham 	ret = of_property_read_u32_array(np,
380c3665006SThomas Abraham 			"samsung,dw-mshc-sdr-timing", timing, 2);
381c3665006SThomas Abraham 	if (ret)
382c3665006SThomas Abraham 		return ret;
383c3665006SThomas Abraham 
3842d9f0bd1SYuvaraj Kumar C D 	priv->sdr_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], div);
3852d9f0bd1SYuvaraj Kumar C D 
386c3665006SThomas Abraham 	ret = of_property_read_u32_array(np,
387c3665006SThomas Abraham 			"samsung,dw-mshc-ddr-timing", timing, 2);
388c3665006SThomas Abraham 	if (ret)
389c3665006SThomas Abraham 		return ret;
390c3665006SThomas Abraham 
391c3665006SThomas Abraham 	priv->ddr_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], div);
39280113132SSeungwon Jeon 
39380113132SSeungwon Jeon 	ret = of_property_read_u32_array(np,
39480113132SSeungwon Jeon 			"samsung,dw-mshc-hs400-timing", timing, 2);
39580113132SSeungwon Jeon 	if (!ret && of_property_read_u32(np,
39680113132SSeungwon Jeon 				"samsung,read-strobe-delay", &priv->dqs_delay))
39780113132SSeungwon Jeon 		dev_dbg(host->dev,
39880113132SSeungwon Jeon 			"read-strobe-delay is not found, assuming usage of default value\n");
39980113132SSeungwon Jeon 
40080113132SSeungwon Jeon 	priv->hs400_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1],
40180113132SSeungwon Jeon 						HS400_FIXED_CIU_CLK_DIV);
402e6c784edSYuvaraj Kumar C D 	host->priv = priv;
403c3665006SThomas Abraham 	return 0;
404c3665006SThomas Abraham }
405c3665006SThomas Abraham 
dw_mci_exynos_get_clksmpl(struct dw_mci * host)406c537a1c5SSeungwon Jeon static inline u8 dw_mci_exynos_get_clksmpl(struct dw_mci *host)
407c537a1c5SSeungwon Jeon {
40889ad2be7SAbhilash Kesavan 	struct dw_mci_exynos_priv_data *priv = host->priv;
40989ad2be7SAbhilash Kesavan 
41089ad2be7SAbhilash Kesavan 	if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 ||
41191e2ca22SMårten Lindahl 		priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU ||
41291e2ca22SMårten Lindahl 		priv->ctrl_type == DW_MCI_TYPE_ARTPEC8)
41389ad2be7SAbhilash Kesavan 		return SDMMC_CLKSEL_CCLK_SAMPLE(mci_readl(host, CLKSEL64));
41489ad2be7SAbhilash Kesavan 	else
415c537a1c5SSeungwon Jeon 		return SDMMC_CLKSEL_CCLK_SAMPLE(mci_readl(host, CLKSEL));
416c537a1c5SSeungwon Jeon }
417c537a1c5SSeungwon Jeon 
dw_mci_exynos_set_clksmpl(struct dw_mci * host,u8 sample)418c537a1c5SSeungwon Jeon static inline void dw_mci_exynos_set_clksmpl(struct dw_mci *host, u8 sample)
419c537a1c5SSeungwon Jeon {
420c537a1c5SSeungwon Jeon 	u32 clksel;
42189ad2be7SAbhilash Kesavan 	struct dw_mci_exynos_priv_data *priv = host->priv;
42289ad2be7SAbhilash Kesavan 
42389ad2be7SAbhilash Kesavan 	if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 ||
42491e2ca22SMårten Lindahl 		priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU ||
42591e2ca22SMårten Lindahl 		priv->ctrl_type == DW_MCI_TYPE_ARTPEC8)
42689ad2be7SAbhilash Kesavan 		clksel = mci_readl(host, CLKSEL64);
42789ad2be7SAbhilash Kesavan 	else
428c537a1c5SSeungwon Jeon 		clksel = mci_readl(host, CLKSEL);
42980113132SSeungwon Jeon 	clksel = SDMMC_CLKSEL_UP_SAMPLE(clksel, sample);
43089ad2be7SAbhilash Kesavan 	if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 ||
43191e2ca22SMårten Lindahl 		priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU ||
43291e2ca22SMårten Lindahl 		priv->ctrl_type == DW_MCI_TYPE_ARTPEC8)
43389ad2be7SAbhilash Kesavan 		mci_writel(host, CLKSEL64, clksel);
43489ad2be7SAbhilash Kesavan 	else
435c537a1c5SSeungwon Jeon 		mci_writel(host, CLKSEL, clksel);
436c537a1c5SSeungwon Jeon }
437c537a1c5SSeungwon Jeon 
dw_mci_exynos_move_next_clksmpl(struct dw_mci * host)438c537a1c5SSeungwon Jeon static inline u8 dw_mci_exynos_move_next_clksmpl(struct dw_mci *host)
439c537a1c5SSeungwon Jeon {
44089ad2be7SAbhilash Kesavan 	struct dw_mci_exynos_priv_data *priv = host->priv;
441c537a1c5SSeungwon Jeon 	u32 clksel;
442c537a1c5SSeungwon Jeon 	u8 sample;
443c537a1c5SSeungwon Jeon 
44489ad2be7SAbhilash Kesavan 	if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 ||
44591e2ca22SMårten Lindahl 		priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU ||
44691e2ca22SMårten Lindahl 		priv->ctrl_type == DW_MCI_TYPE_ARTPEC8)
44789ad2be7SAbhilash Kesavan 		clksel = mci_readl(host, CLKSEL64);
44889ad2be7SAbhilash Kesavan 	else
449c537a1c5SSeungwon Jeon 		clksel = mci_readl(host, CLKSEL);
45080113132SSeungwon Jeon 
451c537a1c5SSeungwon Jeon 	sample = (clksel + 1) & 0x7;
45280113132SSeungwon Jeon 	clksel = SDMMC_CLKSEL_UP_SAMPLE(clksel, sample);
45380113132SSeungwon Jeon 
45489ad2be7SAbhilash Kesavan 	if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 ||
45591e2ca22SMårten Lindahl 		priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU ||
45691e2ca22SMårten Lindahl 		priv->ctrl_type == DW_MCI_TYPE_ARTPEC8)
45789ad2be7SAbhilash Kesavan 		mci_writel(host, CLKSEL64, clksel);
45889ad2be7SAbhilash Kesavan 	else
459c537a1c5SSeungwon Jeon 		mci_writel(host, CLKSEL, clksel);
46080113132SSeungwon Jeon 
461c537a1c5SSeungwon Jeon 	return sample;
462c537a1c5SSeungwon Jeon }
463c537a1c5SSeungwon Jeon 
dw_mci_exynos_get_best_clksmpl(u8 candidates)464c3ed0284SColin Ian King static s8 dw_mci_exynos_get_best_clksmpl(u8 candidates)
465c537a1c5SSeungwon Jeon {
466c537a1c5SSeungwon Jeon 	const u8 iter = 8;
467c537a1c5SSeungwon Jeon 	u8 __c;
468c537a1c5SSeungwon Jeon 	s8 i, loc = -1;
469c537a1c5SSeungwon Jeon 
470c537a1c5SSeungwon Jeon 	for (i = 0; i < iter; i++) {
471c3ed0284SColin Ian King 		__c = ror8(candidates, i);
472c537a1c5SSeungwon Jeon 		if ((__c & 0xc7) == 0xc7) {
473c537a1c5SSeungwon Jeon 			loc = i;
474c537a1c5SSeungwon Jeon 			goto out;
475c537a1c5SSeungwon Jeon 		}
476c537a1c5SSeungwon Jeon 	}
477c537a1c5SSeungwon Jeon 
478c537a1c5SSeungwon Jeon 	for (i = 0; i < iter; i++) {
479c3ed0284SColin Ian King 		__c = ror8(candidates, i);
480c537a1c5SSeungwon Jeon 		if ((__c & 0x83) == 0x83) {
481c537a1c5SSeungwon Jeon 			loc = i;
482c537a1c5SSeungwon Jeon 			goto out;
483c537a1c5SSeungwon Jeon 		}
484c537a1c5SSeungwon Jeon 	}
485c537a1c5SSeungwon Jeon 
486697542bcSJaehoon Chung 	/*
487697542bcSJaehoon Chung 	 * If there is no cadiates value, then it needs to return -EIO.
488c3ed0284SColin Ian King 	 * If there are candidates values and don't find bset clk sample value,
489c3ed0284SColin Ian King 	 * then use a first candidates clock sample value.
490697542bcSJaehoon Chung 	 */
491697542bcSJaehoon Chung 	for (i = 0; i < iter; i++) {
492c3ed0284SColin Ian King 		__c = ror8(candidates, i);
493697542bcSJaehoon Chung 		if ((__c & 0x1) == 0x1) {
494697542bcSJaehoon Chung 			loc = i;
495697542bcSJaehoon Chung 			goto out;
496697542bcSJaehoon Chung 		}
497697542bcSJaehoon Chung 	}
498c537a1c5SSeungwon Jeon out:
499c537a1c5SSeungwon Jeon 	return loc;
500c537a1c5SSeungwon Jeon }
501c537a1c5SSeungwon Jeon 
dw_mci_exynos_execute_tuning(struct dw_mci_slot * slot,u32 opcode)5029979dbe5SChaotian Jing static int dw_mci_exynos_execute_tuning(struct dw_mci_slot *slot, u32 opcode)
503c537a1c5SSeungwon Jeon {
504c537a1c5SSeungwon Jeon 	struct dw_mci *host = slot->host;
50580113132SSeungwon Jeon 	struct dw_mci_exynos_priv_data *priv = host->priv;
506c537a1c5SSeungwon Jeon 	struct mmc_host *mmc = slot->mmc;
507c3ed0284SColin Ian King 	u8 start_smpl, smpl, candidates = 0;
508479cb7cfSColin Ian King 	s8 found;
509c537a1c5SSeungwon Jeon 	int ret = 0;
510c537a1c5SSeungwon Jeon 
511c537a1c5SSeungwon Jeon 	start_smpl = dw_mci_exynos_get_clksmpl(host);
512c537a1c5SSeungwon Jeon 
513c537a1c5SSeungwon Jeon 	do {
514c537a1c5SSeungwon Jeon 		mci_writel(host, TMOUT, ~0);
515c537a1c5SSeungwon Jeon 		smpl = dw_mci_exynos_move_next_clksmpl(host);
516c537a1c5SSeungwon Jeon 
5179979dbe5SChaotian Jing 		if (!mmc_send_tuning(mmc, opcode, NULL))
518c3ed0284SColin Ian King 			candidates |= (1 << smpl);
5196c2c6506SUlf Hansson 
520c537a1c5SSeungwon Jeon 	} while (start_smpl != smpl);
521c537a1c5SSeungwon Jeon 
522c3ed0284SColin Ian King 	found = dw_mci_exynos_get_best_clksmpl(candidates);
52380113132SSeungwon Jeon 	if (found >= 0) {
524c537a1c5SSeungwon Jeon 		dw_mci_exynos_set_clksmpl(host, found);
52580113132SSeungwon Jeon 		priv->tuned_sample = found;
52680113132SSeungwon Jeon 	} else {
527c537a1c5SSeungwon Jeon 		ret = -EIO;
528697542bcSJaehoon Chung 		dev_warn(&mmc->class_dev,
529c3ed0284SColin Ian King 			"There is no candidates value about clksmpl!\n");
53080113132SSeungwon Jeon 	}
531c537a1c5SSeungwon Jeon 
532c537a1c5SSeungwon Jeon 	return ret;
533c537a1c5SSeungwon Jeon }
534c537a1c5SSeungwon Jeon 
dw_mci_exynos_prepare_hs400_tuning(struct dw_mci * host,struct mmc_ios * ios)535c22f5e1bSWu Fengguang static int dw_mci_exynos_prepare_hs400_tuning(struct dw_mci *host,
53680113132SSeungwon Jeon 					struct mmc_ios *ios)
53780113132SSeungwon Jeon {
53880113132SSeungwon Jeon 	struct dw_mci_exynos_priv_data *priv = host->priv;
53980113132SSeungwon Jeon 
54080113132SSeungwon Jeon 	dw_mci_exynos_set_clksel_timing(host, priv->hs400_timing);
54180113132SSeungwon Jeon 	dw_mci_exynos_adjust_clock(host, (ios->clock) << 1);
54280113132SSeungwon Jeon 
54380113132SSeungwon Jeon 	return 0;
54480113132SSeungwon Jeon }
54580113132SSeungwon Jeon 
dw_mci_exynos_set_data_timeout(struct dw_mci * host,unsigned int timeout_ns)54625d5417aSMårten Lindahl static void dw_mci_exynos_set_data_timeout(struct dw_mci *host,
54725d5417aSMårten Lindahl 					   unsigned int timeout_ns)
54825d5417aSMårten Lindahl {
54925d5417aSMårten Lindahl 	u32 clk_div, tmout;
55025d5417aSMårten Lindahl 	u64 tmp;
55125d5417aSMårten Lindahl 	unsigned int tmp2;
55225d5417aSMårten Lindahl 
55325d5417aSMårten Lindahl 	clk_div = (mci_readl(host, CLKDIV) & 0xFF) * 2;
55425d5417aSMårten Lindahl 	if (clk_div == 0)
55525d5417aSMårten Lindahl 		clk_div = 1;
55625d5417aSMårten Lindahl 
55725d5417aSMårten Lindahl 	tmp = DIV_ROUND_UP_ULL((u64)timeout_ns * host->bus_hz, NSEC_PER_SEC);
55825d5417aSMårten Lindahl 	tmp = DIV_ROUND_UP_ULL(tmp, clk_div);
55925d5417aSMårten Lindahl 
56025d5417aSMårten Lindahl 	/* TMOUT[7:0] (RESPONSE_TIMEOUT) */
56125d5417aSMårten Lindahl 	tmout = 0xFF; /* Set maximum */
56225d5417aSMårten Lindahl 
56325d5417aSMårten Lindahl 	/*
56425d5417aSMårten Lindahl 	 * Extended HW timer (max = 0x6FFFFF2):
56525d5417aSMårten Lindahl 	 * ((TMOUT[10:8] - 1) * 0xFFFFFF + TMOUT[31:11] * 8)
56625d5417aSMårten Lindahl 	 */
56725d5417aSMårten Lindahl 	if (!tmp || tmp > 0x6FFFFF2)
56825d5417aSMårten Lindahl 		tmout |= (0xFFFFFF << 8);
56925d5417aSMårten Lindahl 	else {
57025d5417aSMårten Lindahl 		/* TMOUT[10:8] */
57125d5417aSMårten Lindahl 		tmp2 = (((unsigned int)tmp / 0xFFFFFF) + 1) & 0x7;
57225d5417aSMårten Lindahl 		tmout |= tmp2 << 8;
57325d5417aSMårten Lindahl 
57425d5417aSMårten Lindahl 		/* TMOUT[31:11] */
57525d5417aSMårten Lindahl 		tmp = tmp - ((tmp2 - 1) * 0xFFFFFF);
57625d5417aSMårten Lindahl 		tmout |= (tmp & 0xFFFFF8) << 8;
57725d5417aSMårten Lindahl 	}
57825d5417aSMårten Lindahl 
57925d5417aSMårten Lindahl 	mci_writel(host, TMOUT, tmout);
58025d5417aSMårten Lindahl 	dev_dbg(host->dev, "timeout_ns: %u => TMOUT[31:8]: %#08x",
58125d5417aSMårten Lindahl 		timeout_ns, tmout >> 8);
58225d5417aSMårten Lindahl }
58325d5417aSMårten Lindahl 
dw_mci_exynos_get_drto_clks(struct dw_mci * host)58425d5417aSMårten Lindahl static u32 dw_mci_exynos_get_drto_clks(struct dw_mci *host)
58525d5417aSMårten Lindahl {
58625d5417aSMårten Lindahl 	u32 drto_clks;
58725d5417aSMårten Lindahl 
58825d5417aSMårten Lindahl 	drto_clks = mci_readl(host, TMOUT) >> 8;
58925d5417aSMårten Lindahl 
59025d5417aSMårten Lindahl 	return (((drto_clks & 0x7) - 1) * 0xFFFFFF) + ((drto_clks & 0xFFFFF8));
59125d5417aSMårten Lindahl }
59225d5417aSMårten Lindahl 
5930f6e73d0SDongjin Kim /* Common capabilities of Exynos4/Exynos5 SoC */
5940f6e73d0SDongjin Kim static unsigned long exynos_dwmmc_caps[4] = {
595a13e8ef6SJohn Keeping 	MMC_CAP_1_8V_DDR | MMC_CAP_8_BIT_DATA,
596a13e8ef6SJohn Keeping 	0,
597a13e8ef6SJohn Keeping 	0,
598a13e8ef6SJohn Keeping 	0,
599c3665006SThomas Abraham };
600c3665006SThomas Abraham 
6010f6e73d0SDongjin Kim static const struct dw_mci_drv_data exynos_drv_data = {
6020f6e73d0SDongjin Kim 	.caps			= exynos_dwmmc_caps,
6030d84b9e5SShawn Lin 	.num_caps		= ARRAY_SIZE(exynos_dwmmc_caps),
604a13e8ef6SJohn Keeping 	.common_caps		= MMC_CAP_CMD23,
605c3665006SThomas Abraham 	.init			= dw_mci_exynos_priv_init,
606c3665006SThomas Abraham 	.set_ios		= dw_mci_exynos_set_ios,
607c3665006SThomas Abraham 	.parse_dt		= dw_mci_exynos_parse_dt,
608c537a1c5SSeungwon Jeon 	.execute_tuning		= dw_mci_exynos_execute_tuning,
60980113132SSeungwon Jeon 	.prepare_hs400_tuning	= dw_mci_exynos_prepare_hs400_tuning,
610c3665006SThomas Abraham };
611c3665006SThomas Abraham 
61291e2ca22SMårten Lindahl static const struct dw_mci_drv_data artpec_drv_data = {
61391e2ca22SMårten Lindahl 	.common_caps		= MMC_CAP_CMD23,
61491e2ca22SMårten Lindahl 	.init			= dw_mci_exynos_priv_init,
61591e2ca22SMårten Lindahl 	.set_ios		= dw_mci_exynos_set_ios,
61691e2ca22SMårten Lindahl 	.parse_dt		= dw_mci_exynos_parse_dt,
61791e2ca22SMårten Lindahl 	.execute_tuning		= dw_mci_exynos_execute_tuning,
61825d5417aSMårten Lindahl 	.set_data_timeout		= dw_mci_exynos_set_data_timeout,
61925d5417aSMårten Lindahl 	.get_drto_clks		= dw_mci_exynos_get_drto_clks,
62091e2ca22SMårten Lindahl };
62191e2ca22SMårten Lindahl 
622c3665006SThomas Abraham static const struct of_device_id dw_mci_exynos_match[] = {
6230f6e73d0SDongjin Kim 	{ .compatible = "samsung,exynos4412-dw-mshc",
6240f6e73d0SDongjin Kim 			.data = &exynos_drv_data, },
625c3665006SThomas Abraham 	{ .compatible = "samsung,exynos5250-dw-mshc",
6260f6e73d0SDongjin Kim 			.data = &exynos_drv_data, },
62700fd041bSYuvaraj Kumar C D 	{ .compatible = "samsung,exynos5420-dw-mshc",
62800fd041bSYuvaraj Kumar C D 			.data = &exynos_drv_data, },
6296bce431cSYuvaraj Kumar C D 	{ .compatible = "samsung,exynos5420-dw-mshc-smu",
6306bce431cSYuvaraj Kumar C D 			.data = &exynos_drv_data, },
63189ad2be7SAbhilash Kesavan 	{ .compatible = "samsung,exynos7-dw-mshc",
63289ad2be7SAbhilash Kesavan 			.data = &exynos_drv_data, },
63389ad2be7SAbhilash Kesavan 	{ .compatible = "samsung,exynos7-dw-mshc-smu",
63489ad2be7SAbhilash Kesavan 			.data = &exynos_drv_data, },
63591e2ca22SMårten Lindahl 	{ .compatible = "axis,artpec8-dw-mshc",
63691e2ca22SMårten Lindahl 			.data = &artpec_drv_data, },
637c3665006SThomas Abraham 	{},
638c3665006SThomas Abraham };
639517cb9f1SArnd Bergmann MODULE_DEVICE_TABLE(of, dw_mci_exynos_match);
640c3665006SThomas Abraham 
dw_mci_exynos_probe(struct platform_device * pdev)6419665f7f2SSachin Kamat static int dw_mci_exynos_probe(struct platform_device *pdev)
642c3665006SThomas Abraham {
6438e2b36eaSArnd Bergmann 	const struct dw_mci_drv_data *drv_data;
644c3665006SThomas Abraham 	const struct of_device_id *match;
6459b93d392SJoonyoung Shim 	int ret;
646c3665006SThomas Abraham 
647c3665006SThomas Abraham 	match = of_match_node(dw_mci_exynos_match, pdev->dev.of_node);
648c3665006SThomas Abraham 	drv_data = match->data;
6499b93d392SJoonyoung Shim 
6509b93d392SJoonyoung Shim 	pm_runtime_get_noresume(&pdev->dev);
6519b93d392SJoonyoung Shim 	pm_runtime_set_active(&pdev->dev);
6529b93d392SJoonyoung Shim 	pm_runtime_enable(&pdev->dev);
6539b93d392SJoonyoung Shim 
6549b93d392SJoonyoung Shim 	ret = dw_mci_pltfm_register(pdev, drv_data);
6559b93d392SJoonyoung Shim 	if (ret) {
6569b93d392SJoonyoung Shim 		pm_runtime_disable(&pdev->dev);
6579b93d392SJoonyoung Shim 		pm_runtime_set_suspended(&pdev->dev);
6589b93d392SJoonyoung Shim 		pm_runtime_put_noidle(&pdev->dev);
6599b93d392SJoonyoung Shim 
6609b93d392SJoonyoung Shim 		return ret;
6619b93d392SJoonyoung Shim 	}
6629b93d392SJoonyoung Shim 
6639b93d392SJoonyoung Shim 	return 0;
6649b93d392SJoonyoung Shim }
6659b93d392SJoonyoung Shim 
dw_mci_exynos_remove(struct platform_device * pdev)666*41a734a7SYangtao Li static void dw_mci_exynos_remove(struct platform_device *pdev)
6679b93d392SJoonyoung Shim {
6689b93d392SJoonyoung Shim 	pm_runtime_disable(&pdev->dev);
6699b93d392SJoonyoung Shim 	pm_runtime_set_suspended(&pdev->dev);
6709b93d392SJoonyoung Shim 	pm_runtime_put_noidle(&pdev->dev);
6719b93d392SJoonyoung Shim 
67268eab517SUwe Kleine-König 	dw_mci_pltfm_remove(pdev);
673c3665006SThomas Abraham }
674c3665006SThomas Abraham 
67515a2e2abSSachin Kamat static const struct dev_pm_ops dw_mci_exynos_pmops = {
676ecf7c7c5SMarek Szyprowski 	SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(dw_mci_exynos_suspend_noirq,
677ecf7c7c5SMarek Szyprowski 				      dw_mci_exynos_resume_noirq)
678cf5237efSShawn Lin 	SET_RUNTIME_PM_OPS(dw_mci_runtime_suspend,
679cf5237efSShawn Lin 			   dw_mci_exynos_runtime_resume,
680cf5237efSShawn Lin 			   NULL)
681e2c63599SDoug Anderson };
682e2c63599SDoug Anderson 
683c3665006SThomas Abraham static struct platform_driver dw_mci_exynos_pltfm_driver = {
684c3665006SThomas Abraham 	.probe		= dw_mci_exynos_probe,
685*41a734a7SYangtao Li 	.remove_new	= dw_mci_exynos_remove,
686c3665006SThomas Abraham 	.driver		= {
687c3665006SThomas Abraham 		.name		= "dwmmc_exynos",
68821b2cec6SDouglas Anderson 		.probe_type	= PROBE_PREFER_ASYNCHRONOUS,
68920183d50SSachin Kamat 		.of_match_table	= dw_mci_exynos_match,
690e2c63599SDoug Anderson 		.pm		= &dw_mci_exynos_pmops,
691c3665006SThomas Abraham 	},
692c3665006SThomas Abraham };
693c3665006SThomas Abraham 
694c3665006SThomas Abraham module_platform_driver(dw_mci_exynos_pltfm_driver);
695c3665006SThomas Abraham 
696c3665006SThomas Abraham MODULE_DESCRIPTION("Samsung Specific DW-MSHC Driver Extension");
697c3665006SThomas Abraham MODULE_AUTHOR("Thomas Abraham <thomas.ab@samsung.com");
698c3665006SThomas Abraham MODULE_LICENSE("GPL v2");
6992fc546fdSZhangfei Gao MODULE_ALIAS("platform:dwmmc_exynos");
700