blob: 37fa7a49c434e66903abd8e6359699c9c9c6c55e [file] [log] [blame]
Sukumar Ghoraide941242010-09-18 20:32:33 -07001/*
2 * (C) Copyright 2008
3 * Texas Instruments, <www.ti.com>
4 * Sukumar Ghorai <s-ghorai@ti.com>
5 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation's version 2 of
12 * the License.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
23 */
24
25#include <config.h>
26#include <common.h>
Pantelis Antoniou93bfd612014-03-11 19:34:20 +020027#include <malloc.h>
Kishon Vijay Abraham If0d53e82017-09-21 16:51:34 +020028#include <memalign.h>
Sukumar Ghoraide941242010-09-18 20:32:33 -070029#include <mmc.h>
30#include <part.h>
31#include <i2c.h>
Felix Brack339d5782017-10-11 17:05:28 +020032#if defined(CONFIG_OMAP54XX) || defined(CONFIG_OMAP44XX)
Nishanth Menoncb199102013-03-26 05:20:54 +000033#include <palmas.h>
Felix Brack339d5782017-10-11 17:05:28 +020034#endif
Sukumar Ghoraide941242010-09-18 20:32:33 -070035#include <asm/io.h>
36#include <asm/arch/mmc_host_def.h>
Kishon Vijay Abraham I33c1d772018-01-30 16:01:40 +010037#ifdef CONFIG_OMAP54XX
38#include <asm/arch/mux_dra7xx.h>
39#include <asm/arch/dra7xx_iodelay.h>
40#endif
Roger Quadros3b689392015-09-19 16:26:53 +053041#if !defined(CONFIG_SOC_KEYSTONE)
42#include <asm/gpio.h>
Dirk Behme96e0e7b2011-05-15 09:04:47 +000043#include <asm/arch/sys_proto.h>
Roger Quadros3b689392015-09-19 16:26:53 +053044#endif
Tom Rini2a48b3a2017-02-09 13:41:28 -050045#ifdef CONFIG_MMC_OMAP36XX_PINS
46#include <asm/arch/mux.h>
47#endif
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +053048#include <dm.h>
49
50DECLARE_GLOBAL_DATA_PTR;
Sukumar Ghoraide941242010-09-18 20:32:33 -070051
Pantelis Antoniouab769f22014-02-26 19:28:45 +020052/* simplify defines to OMAP_HSMMC_USE_GPIO */
53#if (defined(CONFIG_OMAP_GPIO) && !defined(CONFIG_SPL_BUILD)) || \
54 (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_GPIO_SUPPORT))
55#define OMAP_HSMMC_USE_GPIO
56#else
57#undef OMAP_HSMMC_USE_GPIO
58#endif
59
Grazvydas Ignotas25c719e2012-03-19 12:12:06 +000060/* common definitions for all OMAPs */
61#define SYSCTL_SRC (1 << 25)
62#define SYSCTL_SRD (1 << 26)
63
Kishon Vijay Abraham I33c1d772018-01-30 16:01:40 +010064#ifdef CONFIG_IODELAY_RECALIBRATION
65struct omap_hsmmc_pinctrl_state {
66 struct pad_conf_entry *padconf;
67 int npads;
68 struct iodelay_cfg_entry *iodelay;
69 int niodelays;
70};
71#endif
72
Nikita Kiryanovcc22b0c2012-12-03 02:19:43 +000073struct omap_hsmmc_data {
74 struct hsmmc *base_addr;
Simon Glassc4d660d2017-07-04 13:31:19 -060075#if !CONFIG_IS_ENABLED(DM_MMC)
Pantelis Antoniou93bfd612014-03-11 19:34:20 +020076 struct mmc_config cfg;
Jean-Jacques Hiblot3d673ff2017-03-22 16:00:33 +010077#endif
Kishon Vijay Abraham I48a2f112018-01-30 16:01:31 +010078 uint bus_width;
Jean-Jacques Hiblot5baf5432018-01-30 16:01:30 +010079 uint clock;
Pantelis Antoniouab769f22014-02-26 19:28:45 +020080#ifdef OMAP_HSMMC_USE_GPIO
Simon Glassc4d660d2017-07-04 13:31:19 -060081#if CONFIG_IS_ENABLED(DM_MMC)
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +053082 struct gpio_desc cd_gpio; /* Change Detect GPIO */
83 struct gpio_desc wp_gpio; /* Write Protect GPIO */
84 bool cd_inverted;
85#else
Nikita Kiryanove874d5b2012-12-03 02:19:44 +000086 int cd_gpio;
Nikita Kiryanove3913f52012-12-03 02:19:47 +000087 int wp_gpio;
Pantelis Antoniouab769f22014-02-26 19:28:45 +020088#endif
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +053089#endif
Kishon Vijay Abraham Ib5944812018-01-30 16:01:32 +010090#if CONFIG_IS_ENABLED(DM_MMC)
91 uint iov;
Jean-Jacques Hiblot8fc238b2018-01-30 16:01:33 +010092 enum bus_mode mode;
Kishon Vijay Abraham Ib5944812018-01-30 16:01:32 +010093#endif
Kishon Vijay Abraham If0d53e82017-09-21 16:51:34 +020094 u8 controller_flags;
95#ifndef CONFIG_OMAP34XX
96 struct omap_hsmmc_adma_desc *adma_desc_table;
97 uint desc_slot;
98#endif
Kishon Vijay Abraham I2d28eed2018-01-30 16:01:41 +010099 const char *hw_rev;
Kishon Vijay Abraham I33c1d772018-01-30 16:01:40 +0100100#ifdef CONFIG_IODELAY_RECALIBRATION
101 struct omap_hsmmc_pinctrl_state *default_pinctrl_state;
102 struct omap_hsmmc_pinctrl_state *hs_pinctrl_state;
103 struct omap_hsmmc_pinctrl_state *hs200_1_8v_pinctrl_state;
104 struct omap_hsmmc_pinctrl_state *ddr_1_8v_pinctrl_state;
105 struct omap_hsmmc_pinctrl_state *sdr12_pinctrl_state;
106 struct omap_hsmmc_pinctrl_state *sdr25_pinctrl_state;
107 struct omap_hsmmc_pinctrl_state *ddr50_pinctrl_state;
108 struct omap_hsmmc_pinctrl_state *sdr50_pinctrl_state;
109 struct omap_hsmmc_pinctrl_state *sdr104_pinctrl_state;
110#endif
111};
112
113struct omap_mmc_of_data {
114 u8 controller_flags;
Nikita Kiryanovcc22b0c2012-12-03 02:19:43 +0000115};
116
Kishon Vijay Abraham If0d53e82017-09-21 16:51:34 +0200117#ifndef CONFIG_OMAP34XX
118struct omap_hsmmc_adma_desc {
119 u8 attr;
120 u8 reserved;
121 u16 len;
122 u32 addr;
123};
124
125#define ADMA_MAX_LEN 63488
126
127/* Decriptor table defines */
128#define ADMA_DESC_ATTR_VALID BIT(0)
129#define ADMA_DESC_ATTR_END BIT(1)
130#define ADMA_DESC_ATTR_INT BIT(2)
131#define ADMA_DESC_ATTR_ACT1 BIT(4)
132#define ADMA_DESC_ATTR_ACT2 BIT(5)
133
134#define ADMA_DESC_TRANSFER_DATA ADMA_DESC_ATTR_ACT2
135#define ADMA_DESC_LINK_DESC (ADMA_DESC_ATTR_ACT1 | ADMA_DESC_ATTR_ACT2)
136#endif
137
Nishanth Menoneb9a28f2010-11-19 11:18:12 -0500138/* If we fail after 1 second wait, something is really bad */
139#define MAX_RETRY_MS 1000
Jean-Jacques Hiblota4efd732018-01-30 16:01:37 +0100140#define MMC_TIMEOUT_MS 20
Nishanth Menoneb9a28f2010-11-19 11:18:12 -0500141
Kishon Vijay Abraham If0d53e82017-09-21 16:51:34 +0200142/* DMA transfers can take a long time if a lot a data is transferred.
143 * The timeout must take in account the amount of data. Let's assume
144 * that the time will never exceed 333 ms per MB (in other word we assume
145 * that the bandwidth is always above 3MB/s).
146 */
147#define DMA_TIMEOUT_PER_MB 333
Kishon Vijay Abraham Ib5944812018-01-30 16:01:32 +0100148#define OMAP_HSMMC_SUPPORTS_DUAL_VOLT BIT(0)
149#define OMAP_HSMMC_NO_1_8_V BIT(1)
Kishon Vijay Abraham If0d53e82017-09-21 16:51:34 +0200150#define OMAP_HSMMC_USE_ADMA BIT(2)
Kishon Vijay Abraham I33c1d772018-01-30 16:01:40 +0100151#define OMAP_HSMMC_REQUIRE_IODELAY BIT(3)
Kishon Vijay Abraham If0d53e82017-09-21 16:51:34 +0200152
Sricharan933efe62011-11-15 09:49:53 -0500153static int mmc_read_data(struct hsmmc *mmc_base, char *buf, unsigned int size);
154static int mmc_write_data(struct hsmmc *mmc_base, const char *buf,
155 unsigned int siz);
Jean-Jacques Hiblot5baf5432018-01-30 16:01:30 +0100156static void omap_hsmmc_start_clock(struct hsmmc *mmc_base);
157static void omap_hsmmc_stop_clock(struct hsmmc *mmc_base);
Jean-Jacques Hiblot14761ca2018-01-30 16:01:35 +0100158static void mmc_reset_controller_fsm(struct hsmmc *mmc_base, u32 bit);
Balaji T K14fa2dd2011-09-08 06:34:57 +0000159
Jean-Jacques Hiblotae000e22017-03-22 16:00:31 +0100160static inline struct omap_hsmmc_data *omap_hsmmc_get_data(struct mmc *mmc)
161{
Simon Glassc4d660d2017-07-04 13:31:19 -0600162#if CONFIG_IS_ENABLED(DM_MMC)
Jean-Jacques Hiblotae000e22017-03-22 16:00:31 +0100163 return dev_get_priv(mmc->dev);
164#else
165 return (struct omap_hsmmc_data *)mmc->priv;
166#endif
167}
Jean-Jacques Hiblot3d673ff2017-03-22 16:00:33 +0100168static inline struct mmc_config *omap_hsmmc_get_cfg(struct mmc *mmc)
169{
Simon Glassc4d660d2017-07-04 13:31:19 -0600170#if CONFIG_IS_ENABLED(DM_MMC)
Jean-Jacques Hiblot3d673ff2017-03-22 16:00:33 +0100171 struct omap_hsmmc_plat *plat = dev_get_platdata(mmc->dev);
172 return &plat->cfg;
173#else
174 return &((struct omap_hsmmc_data *)mmc->priv)->cfg;
175#endif
176}
Jean-Jacques Hiblotae000e22017-03-22 16:00:31 +0100177
Simon Glassc4d660d2017-07-04 13:31:19 -0600178#if defined(OMAP_HSMMC_USE_GPIO) && !CONFIG_IS_ENABLED(DM_MMC)
Nikita Kiryanove874d5b2012-12-03 02:19:44 +0000179static int omap_mmc_setup_gpio_in(int gpio, const char *label)
180{
Simon Glass5915a2a2014-10-22 21:37:09 -0600181 int ret;
182
183#ifndef CONFIG_DM_GPIO
Nikita Kiryanove874d5b2012-12-03 02:19:44 +0000184 if (!gpio_is_valid(gpio))
185 return -1;
Simon Glass5915a2a2014-10-22 21:37:09 -0600186#endif
187 ret = gpio_request(gpio, label);
188 if (ret)
189 return ret;
Nikita Kiryanove874d5b2012-12-03 02:19:44 +0000190
Simon Glass5915a2a2014-10-22 21:37:09 -0600191 ret = gpio_direction_input(gpio);
192 if (ret)
193 return ret;
Nikita Kiryanove874d5b2012-12-03 02:19:44 +0000194
195 return gpio;
196}
Nikita Kiryanove874d5b2012-12-03 02:19:44 +0000197#endif
198
Jeroen Hofstee750121c2014-07-12 21:24:08 +0200199static unsigned char mmc_board_init(struct mmc *mmc)
Sukumar Ghoraide941242010-09-18 20:32:33 -0700200{
Sukumar Ghoraide941242010-09-18 20:32:33 -0700201#if defined(CONFIG_OMAP34XX)
Jean-Jacques Hiblot3d673ff2017-03-22 16:00:33 +0100202 struct mmc_config *cfg = omap_hsmmc_get_cfg(mmc);
Sukumar Ghoraide941242010-09-18 20:32:33 -0700203 t2_t *t2_base = (t2_t *)T2_BASE;
204 struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
Grazvydas Ignotasb1e725f2012-03-19 03:50:53 +0000205 u32 pbias_lite;
Adam Ford6aca17c2017-02-06 11:31:43 -0600206#ifdef CONFIG_MMC_OMAP36XX_PINS
207 u32 wkup_ctrl = readl(OMAP34XX_CTRL_WKUP_CTRL);
208#endif
Sukumar Ghoraide941242010-09-18 20:32:33 -0700209
Grazvydas Ignotasb1e725f2012-03-19 03:50:53 +0000210 pbias_lite = readl(&t2_base->pbias_lite);
211 pbias_lite &= ~(PBIASLITEPWRDNZ1 | PBIASLITEPWRDNZ0);
Albert ARIBAUD \(3ADEV\)5bfdd1f2015-01-16 09:09:50 +0100212#ifdef CONFIG_TARGET_OMAP3_CAIRO
213 /* for cairo board, we need to set up 1.8 Volt bias level on MMC1 */
214 pbias_lite &= ~PBIASLITEVMODE0;
215#endif
Adam Ford6aca17c2017-02-06 11:31:43 -0600216#ifdef CONFIG_MMC_OMAP36XX_PINS
217 if (get_cpu_family() == CPU_OMAP36XX) {
218 /* Disable extended drain IO before changing PBIAS */
219 wkup_ctrl &= ~OMAP34XX_CTRL_WKUP_CTRL_GPIO_IO_PWRDNZ;
220 writel(wkup_ctrl, OMAP34XX_CTRL_WKUP_CTRL);
221 }
222#endif
Grazvydas Ignotasb1e725f2012-03-19 03:50:53 +0000223 writel(pbias_lite, &t2_base->pbias_lite);
Paul Kocialkowskiaac54502014-11-08 20:55:47 +0100224
Grazvydas Ignotasb1e725f2012-03-19 03:50:53 +0000225 writel(pbias_lite | PBIASLITEPWRDNZ1 |
Sukumar Ghoraide941242010-09-18 20:32:33 -0700226 PBIASSPEEDCTRL0 | PBIASLITEPWRDNZ0,
227 &t2_base->pbias_lite);
228
Adam Ford6aca17c2017-02-06 11:31:43 -0600229#ifdef CONFIG_MMC_OMAP36XX_PINS
230 if (get_cpu_family() == CPU_OMAP36XX)
231 /* Enable extended drain IO after changing PBIAS */
232 writel(wkup_ctrl |
233 OMAP34XX_CTRL_WKUP_CTRL_GPIO_IO_PWRDNZ,
234 OMAP34XX_CTRL_WKUP_CTRL);
235#endif
Sukumar Ghoraide941242010-09-18 20:32:33 -0700236 writel(readl(&t2_base->devconf0) | MMCSDIO1ADPCLKISEL,
237 &t2_base->devconf0);
238
239 writel(readl(&t2_base->devconf1) | MMCSDIO2ADPCLKISEL,
240 &t2_base->devconf1);
241
Jonathan Solnitbbbc1ae2012-02-24 11:30:18 +0000242 /* Change from default of 52MHz to 26MHz if necessary */
Jean-Jacques Hiblot3d673ff2017-03-22 16:00:33 +0100243 if (!(cfg->host_caps & MMC_MODE_HS_52MHz))
Jonathan Solnitbbbc1ae2012-02-24 11:30:18 +0000244 writel(readl(&t2_base->ctl_prog_io1) & ~CTLPROGIO1SPEEDCTRL,
245 &t2_base->ctl_prog_io1);
246
Sukumar Ghoraide941242010-09-18 20:32:33 -0700247 writel(readl(&prcm_base->fclken1_core) |
248 EN_MMC1 | EN_MMC2 | EN_MMC3,
249 &prcm_base->fclken1_core);
250
251 writel(readl(&prcm_base->iclken1_core) |
252 EN_MMC1 | EN_MMC2 | EN_MMC3,
253 &prcm_base->iclken1_core);
254#endif
255
Lokesh Vutlab4b06002016-11-23 13:25:28 +0530256#if defined(CONFIG_OMAP54XX) || defined(CONFIG_OMAP44XX)
Balaji T K14fa2dd2011-09-08 06:34:57 +0000257 /* PBIAS config needed for MMC1 only */
Jean-Jacques Hiblotdc091272017-03-22 16:00:32 +0100258 if (mmc_get_blk_desc(mmc)->devnum == 0)
Lokesh Vutlab4b06002016-11-23 13:25:28 +0530259 vmmc_pbias_config(LDO_VOLT_3V0);
Balaji T Kdd23e592012-03-12 02:25:49 +0000260#endif
Sukumar Ghoraide941242010-09-18 20:32:33 -0700261
262 return 0;
263}
264
Sricharan933efe62011-11-15 09:49:53 -0500265void mmc_init_stream(struct hsmmc *mmc_base)
Sukumar Ghoraide941242010-09-18 20:32:33 -0700266{
Nishanth Menoneb9a28f2010-11-19 11:18:12 -0500267 ulong start;
Sukumar Ghoraide941242010-09-18 20:32:33 -0700268
269 writel(readl(&mmc_base->con) | INIT_INITSTREAM, &mmc_base->con);
270
271 writel(MMC_CMD0, &mmc_base->cmd);
Nishanth Menoneb9a28f2010-11-19 11:18:12 -0500272 start = get_timer(0);
273 while (!(readl(&mmc_base->stat) & CC_MASK)) {
274 if (get_timer(0) - start > MAX_RETRY_MS) {
275 printf("%s: timedout waiting for cc!\n", __func__);
276 return;
277 }
278 }
Sukumar Ghoraide941242010-09-18 20:32:33 -0700279 writel(CC_MASK, &mmc_base->stat)
280 ;
281 writel(MMC_CMD0, &mmc_base->cmd)
282 ;
Nishanth Menoneb9a28f2010-11-19 11:18:12 -0500283 start = get_timer(0);
284 while (!(readl(&mmc_base->stat) & CC_MASK)) {
285 if (get_timer(0) - start > MAX_RETRY_MS) {
286 printf("%s: timedout waiting for cc2!\n", __func__);
287 return;
288 }
289 }
Sukumar Ghoraide941242010-09-18 20:32:33 -0700290 writel(readl(&mmc_base->con) & ~INIT_INITSTREAM, &mmc_base->con);
291}
292
Kishon Vijay Abraham Ib5944812018-01-30 16:01:32 +0100293#if CONFIG_IS_ENABLED(DM_MMC)
Kishon Vijay Abraham I33c1d772018-01-30 16:01:40 +0100294#ifdef CONFIG_IODELAY_RECALIBRATION
295static void omap_hsmmc_io_recalibrate(struct mmc *mmc)
296{
297 struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc);
298 struct omap_hsmmc_pinctrl_state *pinctrl_state;
299
300 switch (priv->mode) {
301 case MMC_HS_200:
302 pinctrl_state = priv->hs200_1_8v_pinctrl_state;
303 break;
304 case UHS_SDR104:
305 pinctrl_state = priv->sdr104_pinctrl_state;
306 break;
307 case UHS_SDR50:
308 pinctrl_state = priv->sdr50_pinctrl_state;
309 break;
310 case UHS_DDR50:
311 pinctrl_state = priv->ddr50_pinctrl_state;
312 break;
313 case UHS_SDR25:
314 pinctrl_state = priv->sdr25_pinctrl_state;
315 break;
316 case UHS_SDR12:
317 pinctrl_state = priv->sdr12_pinctrl_state;
318 break;
319 case SD_HS:
320 case MMC_HS:
321 case MMC_HS_52:
322 pinctrl_state = priv->hs_pinctrl_state;
323 break;
324 case MMC_DDR_52:
325 pinctrl_state = priv->ddr_1_8v_pinctrl_state;
326 default:
327 pinctrl_state = priv->default_pinctrl_state;
328 break;
329 }
330
Jean-Jacques Hiblotbcc6bd82018-01-30 16:01:42 +0100331 if (!pinctrl_state)
332 pinctrl_state = priv->default_pinctrl_state;
333
Kishon Vijay Abraham I33c1d772018-01-30 16:01:40 +0100334 if (priv->controller_flags & OMAP_HSMMC_REQUIRE_IODELAY) {
335 if (pinctrl_state->iodelay)
336 late_recalibrate_iodelay(pinctrl_state->padconf,
337 pinctrl_state->npads,
338 pinctrl_state->iodelay,
339 pinctrl_state->niodelays);
340 else
341 do_set_mux32((*ctrl)->control_padconf_core_base,
342 pinctrl_state->padconf,
343 pinctrl_state->npads);
344 }
345}
346#endif
Jean-Jacques Hiblot8fc238b2018-01-30 16:01:33 +0100347static void omap_hsmmc_set_timing(struct mmc *mmc)
348{
349 u32 val;
350 struct hsmmc *mmc_base;
351 struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc);
352
353 mmc_base = priv->base_addr;
354
Kishon Vijay Abraham I33c1d772018-01-30 16:01:40 +0100355 omap_hsmmc_stop_clock(mmc_base);
Jean-Jacques Hiblot8fc238b2018-01-30 16:01:33 +0100356 val = readl(&mmc_base->ac12);
357 val &= ~AC12_UHSMC_MASK;
358 priv->mode = mmc->selected_mode;
359
Kishon Vijay Abraham I9b3fc212018-01-30 16:01:34 +0100360 if (mmc_is_mode_ddr(priv->mode))
361 writel(readl(&mmc_base->con) | DDR, &mmc_base->con);
362 else
363 writel(readl(&mmc_base->con) & ~DDR, &mmc_base->con);
364
Jean-Jacques Hiblot8fc238b2018-01-30 16:01:33 +0100365 switch (priv->mode) {
366 case MMC_HS_200:
367 case UHS_SDR104:
368 val |= AC12_UHSMC_SDR104;
369 break;
370 case UHS_SDR50:
371 val |= AC12_UHSMC_SDR50;
372 break;
373 case MMC_DDR_52:
374 case UHS_DDR50:
375 val |= AC12_UHSMC_DDR50;
376 break;
377 case SD_HS:
378 case MMC_HS_52:
379 case UHS_SDR25:
380 val |= AC12_UHSMC_SDR25;
381 break;
382 case MMC_LEGACY:
383 case MMC_HS:
384 case SD_LEGACY:
385 case UHS_SDR12:
386 val |= AC12_UHSMC_SDR12;
387 break;
388 default:
389 val |= AC12_UHSMC_RES;
390 break;
391 }
392 writel(val, &mmc_base->ac12);
Kishon Vijay Abraham I33c1d772018-01-30 16:01:40 +0100393
394#ifdef CONFIG_IODELAY_RECALIBRATION
395 omap_hsmmc_io_recalibrate(mmc);
396#endif
397 omap_hsmmc_start_clock(mmc_base);
Jean-Jacques Hiblot8fc238b2018-01-30 16:01:33 +0100398}
399
Kishon Vijay Abraham Ib5944812018-01-30 16:01:32 +0100400static void omap_hsmmc_conf_bus_power(struct mmc *mmc)
401{
402 struct hsmmc *mmc_base;
403 struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc);
404 u32 val;
405
406 mmc_base = priv->base_addr;
407
408 val = readl(&mmc_base->hctl) & ~SDVS_MASK;
409
410 switch (priv->iov) {
411 case IOV_3V3:
412 val |= SDVS_3V3;
413 break;
414 case IOV_3V0:
415 val |= SDVS_3V0;
416 break;
417 case IOV_1V8:
418 val |= SDVS_1V8;
419 break;
420 }
421
422 writel(val, &mmc_base->hctl);
423}
424
425static void omap_hsmmc_set_capabilities(struct mmc *mmc)
426{
427 struct hsmmc *mmc_base;
428 struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc);
429 u32 val;
430
431 mmc_base = priv->base_addr;
432 val = readl(&mmc_base->capa);
433
434 if (priv->controller_flags & OMAP_HSMMC_SUPPORTS_DUAL_VOLT) {
435 val |= (VS30_3V0SUP | VS18_1V8SUP);
436 priv->iov = IOV_3V0;
437 } else if (priv->controller_flags & OMAP_HSMMC_NO_1_8_V) {
438 val |= VS30_3V0SUP;
439 val &= ~VS18_1V8SUP;
440 priv->iov = IOV_3V0;
441 } else {
442 val |= VS18_1V8SUP;
443 val &= ~VS30_3V0SUP;
444 priv->iov = IOV_1V8;
445 }
446
447 writel(val, &mmc_base->capa);
448}
Jean-Jacques Hiblot14761ca2018-01-30 16:01:35 +0100449
450#ifdef MMC_SUPPORTS_TUNING
451static void omap_hsmmc_disable_tuning(struct mmc *mmc)
452{
453 struct hsmmc *mmc_base;
454 struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc);
455 u32 val;
456
457 mmc_base = priv->base_addr;
458 val = readl(&mmc_base->ac12);
459 val &= ~(AC12_SCLK_SEL);
460 writel(val, &mmc_base->ac12);
461
462 val = readl(&mmc_base->dll);
463 val &= ~(DLL_FORCE_VALUE | DLL_SWT);
464 writel(val, &mmc_base->dll);
465}
466
467static void omap_hsmmc_set_dll(struct mmc *mmc, int count)
468{
469 int i;
470 struct hsmmc *mmc_base;
471 struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc);
472 u32 val;
473
474 mmc_base = priv->base_addr;
475 val = readl(&mmc_base->dll);
476 val |= DLL_FORCE_VALUE;
477 val &= ~(DLL_FORCE_SR_C_MASK << DLL_FORCE_SR_C_SHIFT);
478 val |= (count << DLL_FORCE_SR_C_SHIFT);
479 writel(val, &mmc_base->dll);
480
481 val |= DLL_CALIB;
482 writel(val, &mmc_base->dll);
483 for (i = 0; i < 1000; i++) {
484 if (readl(&mmc_base->dll) & DLL_CALIB)
485 break;
486 }
487 val &= ~DLL_CALIB;
488 writel(val, &mmc_base->dll);
489}
490
491static int omap_hsmmc_execute_tuning(struct udevice *dev, uint opcode)
492{
493 struct omap_hsmmc_data *priv = dev_get_priv(dev);
494 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
495 struct mmc *mmc = upriv->mmc;
496 struct hsmmc *mmc_base;
497 u32 val;
498 u8 cur_match, prev_match = 0;
499 int ret;
500 u32 phase_delay = 0;
501 u32 start_window = 0, max_window = 0;
502 u32 length = 0, max_len = 0;
503
504 mmc_base = priv->base_addr;
505 val = readl(&mmc_base->capa2);
506
507 /* clock tuning is not needed for upto 52MHz */
508 if (!((mmc->selected_mode == MMC_HS_200) ||
509 (mmc->selected_mode == UHS_SDR104) ||
510 ((mmc->selected_mode == UHS_SDR50) && (val & CAPA2_TSDR50))))
511 return 0;
512
513 val = readl(&mmc_base->dll);
514 val |= DLL_SWT;
515 writel(val, &mmc_base->dll);
516 while (phase_delay <= MAX_PHASE_DELAY) {
517 omap_hsmmc_set_dll(mmc, phase_delay);
518
519 cur_match = !mmc_send_tuning(mmc, opcode, NULL);
520
521 if (cur_match) {
522 if (prev_match) {
523 length++;
524 } else {
525 start_window = phase_delay;
526 length = 1;
527 }
528 }
529
530 if (length > max_len) {
531 max_window = start_window;
532 max_len = length;
533 }
534
535 prev_match = cur_match;
536 phase_delay += 4;
537 }
538
539 if (!max_len) {
540 ret = -EIO;
541 goto tuning_error;
542 }
543
544 val = readl(&mmc_base->ac12);
545 if (!(val & AC12_SCLK_SEL)) {
546 ret = -EIO;
547 goto tuning_error;
548 }
549
550 phase_delay = max_window + 4 * ((3 * max_len) >> 2);
551 omap_hsmmc_set_dll(mmc, phase_delay);
552
553 mmc_reset_controller_fsm(mmc_base, SYSCTL_SRD);
554 mmc_reset_controller_fsm(mmc_base, SYSCTL_SRC);
555
556 return 0;
557
558tuning_error:
559
560 omap_hsmmc_disable_tuning(mmc);
561 mmc_reset_controller_fsm(mmc_base, SYSCTL_SRD);
562 mmc_reset_controller_fsm(mmc_base, SYSCTL_SRC);
563
564 return ret;
565}
566#endif
Kishon Vijay Abraham Ib5944812018-01-30 16:01:32 +0100567#endif
568
Jean-Jacques Hiblot2faa1a32018-01-30 16:01:36 +0100569static void mmc_enable_irq(struct mmc *mmc, struct mmc_cmd *cmd)
570{
571 struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc);
572 struct hsmmc *mmc_base = priv->base_addr;
573 u32 irq_mask = INT_EN_MASK;
574
575 /*
576 * TODO: Errata i802 indicates only DCRC interrupts can occur during
577 * tuning procedure and DCRC should be disabled. But see occurences
578 * of DEB, CIE, CEB, CCRC interupts during tuning procedure. These
579 * interrupts occur along with BRR, so the data is actually in the
580 * buffer. It has to be debugged why these interrutps occur
581 */
582 if (cmd && mmc_is_tuning_cmd(cmd->cmdidx))
583 irq_mask &= ~(IE_DEB | IE_DCRC | IE_CIE | IE_CEB | IE_CCRC);
584
585 writel(irq_mask, &mmc_base->ie);
586}
587
Pantelis Antoniouab769f22014-02-26 19:28:45 +0200588static int omap_hsmmc_init_setup(struct mmc *mmc)
Sukumar Ghoraide941242010-09-18 20:32:33 -0700589{
Jean-Jacques Hiblotae000e22017-03-22 16:00:31 +0100590 struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc);
Nikita Kiryanovcc22b0c2012-12-03 02:19:43 +0000591 struct hsmmc *mmc_base;
Sukumar Ghoraide941242010-09-18 20:32:33 -0700592 unsigned int reg_val;
593 unsigned int dsor;
Nishanth Menoneb9a28f2010-11-19 11:18:12 -0500594 ulong start;
Sukumar Ghoraide941242010-09-18 20:32:33 -0700595
Jean-Jacques Hiblotae000e22017-03-22 16:00:31 +0100596 mmc_base = priv->base_addr;
Balaji T K14fa2dd2011-09-08 06:34:57 +0000597 mmc_board_init(mmc);
Sukumar Ghoraide941242010-09-18 20:32:33 -0700598
599 writel(readl(&mmc_base->sysconfig) | MMC_SOFTRESET,
600 &mmc_base->sysconfig);
Nishanth Menoneb9a28f2010-11-19 11:18:12 -0500601 start = get_timer(0);
602 while ((readl(&mmc_base->sysstatus) & RESETDONE) == 0) {
603 if (get_timer(0) - start > MAX_RETRY_MS) {
604 printf("%s: timedout waiting for cc2!\n", __func__);
Jaehoon Chung915ffa52016-07-19 16:33:36 +0900605 return -ETIMEDOUT;
Nishanth Menoneb9a28f2010-11-19 11:18:12 -0500606 }
607 }
Sukumar Ghoraide941242010-09-18 20:32:33 -0700608 writel(readl(&mmc_base->sysctl) | SOFTRESETALL, &mmc_base->sysctl);
Nishanth Menoneb9a28f2010-11-19 11:18:12 -0500609 start = get_timer(0);
610 while ((readl(&mmc_base->sysctl) & SOFTRESETALL) != 0x0) {
611 if (get_timer(0) - start > MAX_RETRY_MS) {
612 printf("%s: timedout waiting for softresetall!\n",
613 __func__);
Jaehoon Chung915ffa52016-07-19 16:33:36 +0900614 return -ETIMEDOUT;
Nishanth Menoneb9a28f2010-11-19 11:18:12 -0500615 }
616 }
Kishon Vijay Abraham If0d53e82017-09-21 16:51:34 +0200617#ifndef CONFIG_OMAP34XX
618 reg_val = readl(&mmc_base->hl_hwinfo);
619 if (reg_val & MADMA_EN)
620 priv->controller_flags |= OMAP_HSMMC_USE_ADMA;
621#endif
Kishon Vijay Abraham Ib5944812018-01-30 16:01:32 +0100622
623#if CONFIG_IS_ENABLED(DM_MMC)
624 omap_hsmmc_set_capabilities(mmc);
625 omap_hsmmc_conf_bus_power(mmc);
626#else
Sukumar Ghoraide941242010-09-18 20:32:33 -0700627 writel(DTW_1_BITMODE | SDBP_PWROFF | SDVS_3V0, &mmc_base->hctl);
628 writel(readl(&mmc_base->capa) | VS30_3V0SUP | VS18_1V8SUP,
629 &mmc_base->capa);
Kishon Vijay Abraham Ib5944812018-01-30 16:01:32 +0100630#endif
Sukumar Ghoraide941242010-09-18 20:32:33 -0700631
632 reg_val = readl(&mmc_base->con) & RESERVED_MASK;
633
634 writel(CTPL_MMC_SD | reg_val | WPP_ACTIVEHIGH | CDP_ACTIVEHIGH |
635 MIT_CTO | DW8_1_4BITMODE | MODE_FUNC | STR_BLOCK |
636 HR_NOHOSTRESP | INIT_NOINIT | NOOPENDRAIN, &mmc_base->con);
637
638 dsor = 240;
639 mmc_reg_out(&mmc_base->sysctl, (ICE_MASK | DTO_MASK | CEN_MASK),
Kishon Vijay Abraham I29171dc2017-09-21 16:51:36 +0200640 (ICE_STOP | DTO_15THDTO));
Sukumar Ghoraide941242010-09-18 20:32:33 -0700641 mmc_reg_out(&mmc_base->sysctl, ICE_MASK | CLKD_MASK,
642 (dsor << CLKD_OFFSET) | ICE_OSCILLATE);
Nishanth Menoneb9a28f2010-11-19 11:18:12 -0500643 start = get_timer(0);
644 while ((readl(&mmc_base->sysctl) & ICS_MASK) == ICS_NOTREADY) {
645 if (get_timer(0) - start > MAX_RETRY_MS) {
646 printf("%s: timedout waiting for ics!\n", __func__);
Jaehoon Chung915ffa52016-07-19 16:33:36 +0900647 return -ETIMEDOUT;
Nishanth Menoneb9a28f2010-11-19 11:18:12 -0500648 }
649 }
Sukumar Ghoraide941242010-09-18 20:32:33 -0700650 writel(readl(&mmc_base->sysctl) | CEN_ENABLE, &mmc_base->sysctl);
651
652 writel(readl(&mmc_base->hctl) | SDBP_PWRON, &mmc_base->hctl);
653
Jean-Jacques Hiblot2faa1a32018-01-30 16:01:36 +0100654 mmc_enable_irq(mmc, NULL);
Sukumar Ghoraide941242010-09-18 20:32:33 -0700655 mmc_init_stream(mmc_base);
656
657 return 0;
658}
659
Grazvydas Ignotas25c719e2012-03-19 12:12:06 +0000660/*
661 * MMC controller internal finite state machine reset
662 *
663 * Used to reset command or data internal state machines, using respectively
664 * SRC or SRD bit of SYSCTL register
665 */
666static void mmc_reset_controller_fsm(struct hsmmc *mmc_base, u32 bit)
667{
668 ulong start;
669
670 mmc_reg_out(&mmc_base->sysctl, bit, bit);
671
Oleksandr Tyshchenko61a6cc22013-08-06 13:44:16 +0300672 /*
673 * CMD(DAT) lines reset procedures are slightly different
674 * for OMAP3 and OMAP4(AM335x,OMAP5,DRA7xx).
675 * According to OMAP3 TRM:
676 * Set SRC(SRD) bit in MMCHS_SYSCTL register to 0x1 and wait until it
677 * returns to 0x0.
678 * According to OMAP4(AM335x,OMAP5,DRA7xx) TRMs, CMD(DATA) lines reset
679 * procedure steps must be as follows:
680 * 1. Initiate CMD(DAT) line reset by writing 0x1 to SRC(SRD) bit in
681 * MMCHS_SYSCTL register (SD_SYSCTL for AM335x).
682 * 2. Poll the SRC(SRD) bit until it is set to 0x1.
683 * 3. Wait until the SRC (SRD) bit returns to 0x0
684 * (reset procedure is completed).
685 */
686#if defined(CONFIG_OMAP44XX) || defined(CONFIG_OMAP54XX) || \
Nikita Kiryanovdce55b92015-07-30 23:56:20 +0300687 defined(CONFIG_AM33XX) || defined(CONFIG_AM43XX)
Oleksandr Tyshchenko61a6cc22013-08-06 13:44:16 +0300688 if (!(readl(&mmc_base->sysctl) & bit)) {
689 start = get_timer(0);
690 while (!(readl(&mmc_base->sysctl) & bit)) {
Jean-Jacques Hiblota4efd732018-01-30 16:01:37 +0100691 if (get_timer(0) - start > MMC_TIMEOUT_MS)
Oleksandr Tyshchenko61a6cc22013-08-06 13:44:16 +0300692 return;
693 }
694 }
695#endif
Grazvydas Ignotas25c719e2012-03-19 12:12:06 +0000696 start = get_timer(0);
697 while ((readl(&mmc_base->sysctl) & bit) != 0) {
698 if (get_timer(0) - start > MAX_RETRY_MS) {
699 printf("%s: timedout waiting for sysctl %x to clear\n",
700 __func__, bit);
701 return;
702 }
703 }
704}
Kishon Vijay Abraham If0d53e82017-09-21 16:51:34 +0200705
706#ifndef CONFIG_OMAP34XX
707static void omap_hsmmc_adma_desc(struct mmc *mmc, char *buf, u16 len, bool end)
708{
709 struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc);
710 struct omap_hsmmc_adma_desc *desc;
711 u8 attr;
712
713 desc = &priv->adma_desc_table[priv->desc_slot];
714
715 attr = ADMA_DESC_ATTR_VALID | ADMA_DESC_TRANSFER_DATA;
716 if (!end)
717 priv->desc_slot++;
718 else
719 attr |= ADMA_DESC_ATTR_END;
720
721 desc->len = len;
722 desc->addr = (u32)buf;
723 desc->reserved = 0;
724 desc->attr = attr;
725}
726
727static void omap_hsmmc_prepare_adma_table(struct mmc *mmc,
728 struct mmc_data *data)
729{
730 uint total_len = data->blocksize * data->blocks;
731 uint desc_count = DIV_ROUND_UP(total_len, ADMA_MAX_LEN);
732 struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc);
733 int i = desc_count;
734 char *buf;
735
736 priv->desc_slot = 0;
737 priv->adma_desc_table = (struct omap_hsmmc_adma_desc *)
738 memalign(ARCH_DMA_MINALIGN, desc_count *
739 sizeof(struct omap_hsmmc_adma_desc));
740
741 if (data->flags & MMC_DATA_READ)
742 buf = data->dest;
743 else
744 buf = (char *)data->src;
745
746 while (--i) {
747 omap_hsmmc_adma_desc(mmc, buf, ADMA_MAX_LEN, false);
748 buf += ADMA_MAX_LEN;
749 total_len -= ADMA_MAX_LEN;
750 }
751
752 omap_hsmmc_adma_desc(mmc, buf, total_len, true);
753
754 flush_dcache_range((long)priv->adma_desc_table,
755 (long)priv->adma_desc_table +
756 ROUND(desc_count *
757 sizeof(struct omap_hsmmc_adma_desc),
758 ARCH_DMA_MINALIGN));
759}
760
761static void omap_hsmmc_prepare_data(struct mmc *mmc, struct mmc_data *data)
762{
763 struct hsmmc *mmc_base;
764 struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc);
765 u32 val;
766 char *buf;
767
768 mmc_base = priv->base_addr;
769 omap_hsmmc_prepare_adma_table(mmc, data);
770
771 if (data->flags & MMC_DATA_READ)
772 buf = data->dest;
773 else
774 buf = (char *)data->src;
775
776 val = readl(&mmc_base->hctl);
777 val |= DMA_SELECT;
778 writel(val, &mmc_base->hctl);
779
780 val = readl(&mmc_base->con);
781 val |= DMA_MASTER;
782 writel(val, &mmc_base->con);
783
784 writel((u32)priv->adma_desc_table, &mmc_base->admasal);
785
786 flush_dcache_range((u32)buf,
787 (u32)buf +
788 ROUND(data->blocksize * data->blocks,
789 ARCH_DMA_MINALIGN));
790}
791
792static void omap_hsmmc_dma_cleanup(struct mmc *mmc)
793{
794 struct hsmmc *mmc_base;
795 struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc);
796 u32 val;
797
798 mmc_base = priv->base_addr;
799
800 val = readl(&mmc_base->con);
801 val &= ~DMA_MASTER;
802 writel(val, &mmc_base->con);
803
804 val = readl(&mmc_base->hctl);
805 val &= ~DMA_SELECT;
806 writel(val, &mmc_base->hctl);
807
808 kfree(priv->adma_desc_table);
809}
810#else
811#define omap_hsmmc_adma_desc
812#define omap_hsmmc_prepare_adma_table
813#define omap_hsmmc_prepare_data
814#define omap_hsmmc_dma_cleanup
815#endif
816
Simon Glassc4d660d2017-07-04 13:31:19 -0600817#if !CONFIG_IS_ENABLED(DM_MMC)
Pantelis Antoniouab769f22014-02-26 19:28:45 +0200818static int omap_hsmmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
Sukumar Ghoraide941242010-09-18 20:32:33 -0700819 struct mmc_data *data)
820{
Jean-Jacques Hiblotae000e22017-03-22 16:00:31 +0100821 struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc);
Jean-Jacques Hiblotb5511d62017-04-14 19:50:02 +0200822#else
823static int omap_hsmmc_send_cmd(struct udevice *dev, struct mmc_cmd *cmd,
824 struct mmc_data *data)
825{
826 struct omap_hsmmc_data *priv = dev_get_priv(dev);
Kishon Vijay Abraham If0d53e82017-09-21 16:51:34 +0200827 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
828 struct mmc *mmc = upriv->mmc;
829#endif
Nikita Kiryanovcc22b0c2012-12-03 02:19:43 +0000830 struct hsmmc *mmc_base;
Sukumar Ghoraide941242010-09-18 20:32:33 -0700831 unsigned int flags, mmc_stat;
Nishanth Menoneb9a28f2010-11-19 11:18:12 -0500832 ulong start;
Sukumar Ghoraide941242010-09-18 20:32:33 -0700833
Jean-Jacques Hiblotae000e22017-03-22 16:00:31 +0100834 mmc_base = priv->base_addr;
Kishon Vijay Abraham I866bb982017-09-21 16:51:35 +0200835
836 if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
837 return 0;
838
Nishanth Menoneb9a28f2010-11-19 11:18:12 -0500839 start = get_timer(0);
Tom Rinia7778f82012-01-30 11:22:25 +0000840 while ((readl(&mmc_base->pstate) & (DATI_MASK | CMDI_MASK)) != 0) {
Nishanth Menoneb9a28f2010-11-19 11:18:12 -0500841 if (get_timer(0) - start > MAX_RETRY_MS) {
Tom Rinia7778f82012-01-30 11:22:25 +0000842 printf("%s: timedout waiting on cmd inhibit to clear\n",
843 __func__);
Jaehoon Chung915ffa52016-07-19 16:33:36 +0900844 return -ETIMEDOUT;
Nishanth Menoneb9a28f2010-11-19 11:18:12 -0500845 }
846 }
Sukumar Ghoraide941242010-09-18 20:32:33 -0700847 writel(0xFFFFFFFF, &mmc_base->stat);
Nishanth Menoneb9a28f2010-11-19 11:18:12 -0500848 start = get_timer(0);
849 while (readl(&mmc_base->stat)) {
850 if (get_timer(0) - start > MAX_RETRY_MS) {
Grazvydas Ignotas15ceb1d2012-03-19 12:11:43 +0000851 printf("%s: timedout waiting for STAT (%x) to clear\n",
852 __func__, readl(&mmc_base->stat));
Jaehoon Chung915ffa52016-07-19 16:33:36 +0900853 return -ETIMEDOUT;
Nishanth Menoneb9a28f2010-11-19 11:18:12 -0500854 }
855 }
Sukumar Ghoraide941242010-09-18 20:32:33 -0700856 /*
857 * CMDREG
858 * CMDIDX[13:8] : Command index
859 * DATAPRNT[5] : Data Present Select
860 * ENCMDIDX[4] : Command Index Check Enable
861 * ENCMDCRC[3] : Command CRC Check Enable
862 * RSPTYP[1:0]
863 * 00 = No Response
864 * 01 = Length 136
865 * 10 = Length 48
866 * 11 = Length 48 Check busy after response
867 */
868 /* Delay added before checking the status of frq change
869 * retry not supported by mmc.c(core file)
870 */
871 if (cmd->cmdidx == SD_CMD_APP_SEND_SCR)
872 udelay(50000); /* wait 50 ms */
873
874 if (!(cmd->resp_type & MMC_RSP_PRESENT))
875 flags = 0;
876 else if (cmd->resp_type & MMC_RSP_136)
877 flags = RSP_TYPE_LGHT136 | CICE_NOCHECK;
878 else if (cmd->resp_type & MMC_RSP_BUSY)
879 flags = RSP_TYPE_LGHT48B;
880 else
881 flags = RSP_TYPE_LGHT48;
882
883 /* enable default flags */
884 flags = flags | (CMD_TYPE_NORMAL | CICE_NOCHECK | CCCE_NOCHECK |
Kishon Vijay Abraham I29171dc2017-09-21 16:51:36 +0200885 MSBS_SGLEBLK);
886 flags &= ~(ACEN_ENABLE | BCE_ENABLE | DE_ENABLE);
Sukumar Ghoraide941242010-09-18 20:32:33 -0700887
888 if (cmd->resp_type & MMC_RSP_CRC)
889 flags |= CCCE_CHECK;
890 if (cmd->resp_type & MMC_RSP_OPCODE)
891 flags |= CICE_CHECK;
892
893 if (data) {
894 if ((cmd->cmdidx == MMC_CMD_READ_MULTIPLE_BLOCK) ||
895 (cmd->cmdidx == MMC_CMD_WRITE_MULTIPLE_BLOCK)) {
Kishon Vijay Abraham I866bb982017-09-21 16:51:35 +0200896 flags |= (MSBS_MULTIBLK | BCE_ENABLE | ACEN_ENABLE);
Sukumar Ghoraide941242010-09-18 20:32:33 -0700897 data->blocksize = 512;
898 writel(data->blocksize | (data->blocks << 16),
899 &mmc_base->blk);
900 } else
901 writel(data->blocksize | NBLK_STPCNT, &mmc_base->blk);
902
903 if (data->flags & MMC_DATA_READ)
904 flags |= (DP_DATA | DDIR_READ);
905 else
906 flags |= (DP_DATA | DDIR_WRITE);
Kishon Vijay Abraham If0d53e82017-09-21 16:51:34 +0200907
908#ifndef CONFIG_OMAP34XX
909 if ((priv->controller_flags & OMAP_HSMMC_USE_ADMA) &&
910 !mmc_is_tuning_cmd(cmd->cmdidx)) {
911 omap_hsmmc_prepare_data(mmc, data);
912 flags |= DE_ENABLE;
913 }
914#endif
Sukumar Ghoraide941242010-09-18 20:32:33 -0700915 }
916
Jean-Jacques Hiblot2faa1a32018-01-30 16:01:36 +0100917 mmc_enable_irq(mmc, cmd);
918
Sukumar Ghoraide941242010-09-18 20:32:33 -0700919 writel(cmd->cmdarg, &mmc_base->arg);
Lubomir Popov152ba362013-08-14 18:59:18 +0300920 udelay(20); /* To fix "No status update" error on eMMC */
Sukumar Ghoraide941242010-09-18 20:32:33 -0700921 writel((cmd->cmdidx << 24) | flags, &mmc_base->cmd);
922
Nishanth Menoneb9a28f2010-11-19 11:18:12 -0500923 start = get_timer(0);
Sukumar Ghoraide941242010-09-18 20:32:33 -0700924 do {
925 mmc_stat = readl(&mmc_base->stat);
Kishon Vijay Abraham If0d53e82017-09-21 16:51:34 +0200926 if (get_timer(start) > MAX_RETRY_MS) {
Nishanth Menoneb9a28f2010-11-19 11:18:12 -0500927 printf("%s : timeout: No status update\n", __func__);
Jaehoon Chung915ffa52016-07-19 16:33:36 +0900928 return -ETIMEDOUT;
Nishanth Menoneb9a28f2010-11-19 11:18:12 -0500929 }
930 } while (!mmc_stat);
Sukumar Ghoraide941242010-09-18 20:32:33 -0700931
Grazvydas Ignotas25c719e2012-03-19 12:12:06 +0000932 if ((mmc_stat & IE_CTO) != 0) {
933 mmc_reset_controller_fsm(mmc_base, SYSCTL_SRC);
Jaehoon Chung915ffa52016-07-19 16:33:36 +0900934 return -ETIMEDOUT;
Grazvydas Ignotas25c719e2012-03-19 12:12:06 +0000935 } else if ((mmc_stat & ERRI_MASK) != 0)
Sukumar Ghoraide941242010-09-18 20:32:33 -0700936 return -1;
937
938 if (mmc_stat & CC_MASK) {
939 writel(CC_MASK, &mmc_base->stat);
940 if (cmd->resp_type & MMC_RSP_PRESENT) {
941 if (cmd->resp_type & MMC_RSP_136) {
942 /* response type 2 */
943 cmd->response[3] = readl(&mmc_base->rsp10);
944 cmd->response[2] = readl(&mmc_base->rsp32);
945 cmd->response[1] = readl(&mmc_base->rsp54);
946 cmd->response[0] = readl(&mmc_base->rsp76);
947 } else
948 /* response types 1, 1b, 3, 4, 5, 6 */
949 cmd->response[0] = readl(&mmc_base->rsp10);
950 }
951 }
952
Kishon Vijay Abraham If0d53e82017-09-21 16:51:34 +0200953#ifndef CONFIG_OMAP34XX
954 if ((priv->controller_flags & OMAP_HSMMC_USE_ADMA) && data &&
955 !mmc_is_tuning_cmd(cmd->cmdidx)) {
956 u32 sz_mb, timeout;
957
958 if (mmc_stat & IE_ADMAE) {
959 omap_hsmmc_dma_cleanup(mmc);
960 return -EIO;
961 }
962
963 sz_mb = DIV_ROUND_UP(data->blocksize * data->blocks, 1 << 20);
964 timeout = sz_mb * DMA_TIMEOUT_PER_MB;
965 if (timeout < MAX_RETRY_MS)
966 timeout = MAX_RETRY_MS;
967
968 start = get_timer(0);
969 do {
970 mmc_stat = readl(&mmc_base->stat);
971 if (mmc_stat & TC_MASK) {
972 writel(readl(&mmc_base->stat) | TC_MASK,
973 &mmc_base->stat);
974 break;
975 }
976 if (get_timer(start) > timeout) {
977 printf("%s : DMA timeout: No status update\n",
978 __func__);
979 return -ETIMEDOUT;
980 }
981 } while (1);
982
983 omap_hsmmc_dma_cleanup(mmc);
984 return 0;
985 }
986#endif
987
Sukumar Ghoraide941242010-09-18 20:32:33 -0700988 if (data && (data->flags & MMC_DATA_READ)) {
989 mmc_read_data(mmc_base, data->dest,
990 data->blocksize * data->blocks);
991 } else if (data && (data->flags & MMC_DATA_WRITE)) {
992 mmc_write_data(mmc_base, data->src,
993 data->blocksize * data->blocks);
994 }
995 return 0;
996}
997
Sricharan933efe62011-11-15 09:49:53 -0500998static int mmc_read_data(struct hsmmc *mmc_base, char *buf, unsigned int size)
Sukumar Ghoraide941242010-09-18 20:32:33 -0700999{
1000 unsigned int *output_buf = (unsigned int *)buf;
1001 unsigned int mmc_stat;
1002 unsigned int count;
1003
1004 /*
1005 * Start Polled Read
1006 */
1007 count = (size > MMCSD_SECTOR_SIZE) ? MMCSD_SECTOR_SIZE : size;
1008 count /= 4;
1009
1010 while (size) {
Nishanth Menoneb9a28f2010-11-19 11:18:12 -05001011 ulong start = get_timer(0);
Sukumar Ghoraide941242010-09-18 20:32:33 -07001012 do {
1013 mmc_stat = readl(&mmc_base->stat);
Nishanth Menoneb9a28f2010-11-19 11:18:12 -05001014 if (get_timer(0) - start > MAX_RETRY_MS) {
1015 printf("%s: timedout waiting for status!\n",
1016 __func__);
Jaehoon Chung915ffa52016-07-19 16:33:36 +09001017 return -ETIMEDOUT;
Nishanth Menoneb9a28f2010-11-19 11:18:12 -05001018 }
Sukumar Ghoraide941242010-09-18 20:32:33 -07001019 } while (mmc_stat == 0);
1020
Grazvydas Ignotas25c719e2012-03-19 12:12:06 +00001021 if ((mmc_stat & (IE_DTO | IE_DCRC | IE_DEB)) != 0)
1022 mmc_reset_controller_fsm(mmc_base, SYSCTL_SRD);
1023
Sukumar Ghoraide941242010-09-18 20:32:33 -07001024 if ((mmc_stat & ERRI_MASK) != 0)
1025 return 1;
1026
1027 if (mmc_stat & BRR_MASK) {
1028 unsigned int k;
1029
1030 writel(readl(&mmc_base->stat) | BRR_MASK,
1031 &mmc_base->stat);
1032 for (k = 0; k < count; k++) {
1033 *output_buf = readl(&mmc_base->data);
1034 output_buf++;
1035 }
1036 size -= (count*4);
1037 }
1038
1039 if (mmc_stat & BWR_MASK)
1040 writel(readl(&mmc_base->stat) | BWR_MASK,
1041 &mmc_base->stat);
1042
1043 if (mmc_stat & TC_MASK) {
1044 writel(readl(&mmc_base->stat) | TC_MASK,
1045 &mmc_base->stat);
1046 break;
1047 }
1048 }
1049 return 0;
1050}
1051
Sricharan933efe62011-11-15 09:49:53 -05001052static int mmc_write_data(struct hsmmc *mmc_base, const char *buf,
1053 unsigned int size)
Sukumar Ghoraide941242010-09-18 20:32:33 -07001054{
1055 unsigned int *input_buf = (unsigned int *)buf;
1056 unsigned int mmc_stat;
1057 unsigned int count;
1058
1059 /*
Lubomir Popov152ba362013-08-14 18:59:18 +03001060 * Start Polled Write
Sukumar Ghoraide941242010-09-18 20:32:33 -07001061 */
1062 count = (size > MMCSD_SECTOR_SIZE) ? MMCSD_SECTOR_SIZE : size;
1063 count /= 4;
1064
1065 while (size) {
Nishanth Menoneb9a28f2010-11-19 11:18:12 -05001066 ulong start = get_timer(0);
Sukumar Ghoraide941242010-09-18 20:32:33 -07001067 do {
1068 mmc_stat = readl(&mmc_base->stat);
Nishanth Menoneb9a28f2010-11-19 11:18:12 -05001069 if (get_timer(0) - start > MAX_RETRY_MS) {
1070 printf("%s: timedout waiting for status!\n",
1071 __func__);
Jaehoon Chung915ffa52016-07-19 16:33:36 +09001072 return -ETIMEDOUT;
Nishanth Menoneb9a28f2010-11-19 11:18:12 -05001073 }
Sukumar Ghoraide941242010-09-18 20:32:33 -07001074 } while (mmc_stat == 0);
1075
Grazvydas Ignotas25c719e2012-03-19 12:12:06 +00001076 if ((mmc_stat & (IE_DTO | IE_DCRC | IE_DEB)) != 0)
1077 mmc_reset_controller_fsm(mmc_base, SYSCTL_SRD);
1078
Sukumar Ghoraide941242010-09-18 20:32:33 -07001079 if ((mmc_stat & ERRI_MASK) != 0)
1080 return 1;
1081
1082 if (mmc_stat & BWR_MASK) {
1083 unsigned int k;
1084
1085 writel(readl(&mmc_base->stat) | BWR_MASK,
1086 &mmc_base->stat);
1087 for (k = 0; k < count; k++) {
1088 writel(*input_buf, &mmc_base->data);
1089 input_buf++;
1090 }
1091 size -= (count*4);
1092 }
1093
1094 if (mmc_stat & BRR_MASK)
1095 writel(readl(&mmc_base->stat) | BRR_MASK,
1096 &mmc_base->stat);
1097
1098 if (mmc_stat & TC_MASK) {
1099 writel(readl(&mmc_base->stat) | TC_MASK,
1100 &mmc_base->stat);
1101 break;
1102 }
1103 }
1104 return 0;
1105}
1106
Jean-Jacques Hiblot5baf5432018-01-30 16:01:30 +01001107static void omap_hsmmc_stop_clock(struct hsmmc *mmc_base)
1108{
1109 writel(readl(&mmc_base->sysctl) & ~CEN_ENABLE, &mmc_base->sysctl);
1110}
1111
1112static void omap_hsmmc_start_clock(struct hsmmc *mmc_base)
1113{
1114 writel(readl(&mmc_base->sysctl) | CEN_ENABLE, &mmc_base->sysctl);
1115}
1116
1117static void omap_hsmmc_set_clock(struct mmc *mmc)
1118{
1119 struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc);
1120 struct hsmmc *mmc_base;
1121 unsigned int dsor = 0;
1122 ulong start;
1123
1124 mmc_base = priv->base_addr;
1125 omap_hsmmc_stop_clock(mmc_base);
1126
1127 /* TODO: Is setting DTO required here? */
1128 mmc_reg_out(&mmc_base->sysctl, (ICE_MASK | DTO_MASK),
1129 (ICE_STOP | DTO_15THDTO));
1130
1131 if (mmc->clock != 0) {
1132 dsor = DIV_ROUND_UP(MMC_CLOCK_REFERENCE * 1000000, mmc->clock);
1133 if (dsor > CLKD_MAX)
1134 dsor = CLKD_MAX;
1135 } else {
1136 dsor = CLKD_MAX;
1137 }
1138
1139 mmc_reg_out(&mmc_base->sysctl, ICE_MASK | CLKD_MASK,
1140 (dsor << CLKD_OFFSET) | ICE_OSCILLATE);
1141
1142 start = get_timer(0);
1143 while ((readl(&mmc_base->sysctl) & ICS_MASK) == ICS_NOTREADY) {
1144 if (get_timer(0) - start > MAX_RETRY_MS) {
1145 printf("%s: timedout waiting for ics!\n", __func__);
1146 return;
1147 }
1148 }
1149
1150 priv->clock = mmc->clock;
1151 omap_hsmmc_start_clock(mmc_base);
1152}
1153
Kishon Vijay Abraham I48a2f112018-01-30 16:01:31 +01001154static void omap_hsmmc_set_bus_width(struct mmc *mmc)
Sukumar Ghoraide941242010-09-18 20:32:33 -07001155{
Jean-Jacques Hiblotae000e22017-03-22 16:00:31 +01001156 struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc);
Nikita Kiryanovcc22b0c2012-12-03 02:19:43 +00001157 struct hsmmc *mmc_base;
Sukumar Ghoraide941242010-09-18 20:32:33 -07001158
Jean-Jacques Hiblotae000e22017-03-22 16:00:31 +01001159 mmc_base = priv->base_addr;
Sukumar Ghoraide941242010-09-18 20:32:33 -07001160 /* configue bus width */
1161 switch (mmc->bus_width) {
1162 case 8:
1163 writel(readl(&mmc_base->con) | DTW_8_BITMODE,
1164 &mmc_base->con);
1165 break;
1166
1167 case 4:
1168 writel(readl(&mmc_base->con) & ~DTW_8_BITMODE,
1169 &mmc_base->con);
1170 writel(readl(&mmc_base->hctl) | DTW_4_BITMODE,
1171 &mmc_base->hctl);
1172 break;
1173
1174 case 1:
1175 default:
1176 writel(readl(&mmc_base->con) & ~DTW_8_BITMODE,
1177 &mmc_base->con);
1178 writel(readl(&mmc_base->hctl) & ~DTW_4_BITMODE,
1179 &mmc_base->hctl);
1180 break;
1181 }
1182
Kishon Vijay Abraham I48a2f112018-01-30 16:01:31 +01001183 priv->bus_width = mmc->bus_width;
1184}
1185
1186#if !CONFIG_IS_ENABLED(DM_MMC)
1187static int omap_hsmmc_set_ios(struct mmc *mmc)
1188{
1189 struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc);
1190#else
1191static int omap_hsmmc_set_ios(struct udevice *dev)
1192{
1193 struct omap_hsmmc_data *priv = dev_get_priv(dev);
1194 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
1195 struct mmc *mmc = upriv->mmc;
1196#endif
1197
1198 if (priv->bus_width != mmc->bus_width)
1199 omap_hsmmc_set_bus_width(mmc);
1200
Jean-Jacques Hiblot5baf5432018-01-30 16:01:30 +01001201 if (priv->clock != mmc->clock)
1202 omap_hsmmc_set_clock(mmc);
Jaehoon Chung07b0b9c2016-12-30 15:30:16 +09001203
Jean-Jacques Hiblot8fc238b2018-01-30 16:01:33 +01001204#if CONFIG_IS_ENABLED(DM_MMC)
1205 if (priv->mode != mmc->selected_mode)
1206 omap_hsmmc_set_timing(mmc);
1207#endif
Jaehoon Chung07b0b9c2016-12-30 15:30:16 +09001208 return 0;
Sukumar Ghoraide941242010-09-18 20:32:33 -07001209}
1210
Pantelis Antoniouab769f22014-02-26 19:28:45 +02001211#ifdef OMAP_HSMMC_USE_GPIO
Simon Glassc4d660d2017-07-04 13:31:19 -06001212#if CONFIG_IS_ENABLED(DM_MMC)
Jean-Jacques Hiblotb5511d62017-04-14 19:50:02 +02001213static int omap_hsmmc_getcd(struct udevice *dev)
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301214{
Jean-Jacques Hiblotb5511d62017-04-14 19:50:02 +02001215 struct omap_hsmmc_data *priv = dev_get_priv(dev);
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301216 int value;
1217
1218 value = dm_gpio_get_value(&priv->cd_gpio);
1219 /* if no CD return as 1 */
1220 if (value < 0)
1221 return 1;
1222
1223 if (priv->cd_inverted)
1224 return !value;
1225 return value;
1226}
1227
Jean-Jacques Hiblotb5511d62017-04-14 19:50:02 +02001228static int omap_hsmmc_getwp(struct udevice *dev)
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301229{
Jean-Jacques Hiblotb5511d62017-04-14 19:50:02 +02001230 struct omap_hsmmc_data *priv = dev_get_priv(dev);
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301231 int value;
1232
1233 value = dm_gpio_get_value(&priv->wp_gpio);
1234 /* if no WP return as 0 */
1235 if (value < 0)
1236 return 0;
1237 return value;
1238}
1239#else
Pantelis Antoniouab769f22014-02-26 19:28:45 +02001240static int omap_hsmmc_getcd(struct mmc *mmc)
1241{
Jean-Jacques Hiblotae000e22017-03-22 16:00:31 +01001242 struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc);
Pantelis Antoniouab769f22014-02-26 19:28:45 +02001243 int cd_gpio;
1244
1245 /* if no CD return as 1 */
Jean-Jacques Hiblotae000e22017-03-22 16:00:31 +01001246 cd_gpio = priv->cd_gpio;
Pantelis Antoniouab769f22014-02-26 19:28:45 +02001247 if (cd_gpio < 0)
1248 return 1;
1249
Igor Grinberg0b03a932014-11-03 11:32:23 +02001250 /* NOTE: assumes card detect signal is active-low */
1251 return !gpio_get_value(cd_gpio);
Pantelis Antoniouab769f22014-02-26 19:28:45 +02001252}
1253
1254static int omap_hsmmc_getwp(struct mmc *mmc)
1255{
Jean-Jacques Hiblotae000e22017-03-22 16:00:31 +01001256 struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc);
Pantelis Antoniouab769f22014-02-26 19:28:45 +02001257 int wp_gpio;
1258
1259 /* if no WP return as 0 */
Jean-Jacques Hiblotae000e22017-03-22 16:00:31 +01001260 wp_gpio = priv->wp_gpio;
Pantelis Antoniouab769f22014-02-26 19:28:45 +02001261 if (wp_gpio < 0)
1262 return 0;
1263
Igor Grinberg0b03a932014-11-03 11:32:23 +02001264 /* NOTE: assumes write protect signal is active-high */
Pantelis Antoniouab769f22014-02-26 19:28:45 +02001265 return gpio_get_value(wp_gpio);
1266}
1267#endif
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301268#endif
Pantelis Antoniouab769f22014-02-26 19:28:45 +02001269
Simon Glassc4d660d2017-07-04 13:31:19 -06001270#if CONFIG_IS_ENABLED(DM_MMC)
Jean-Jacques Hiblotb5511d62017-04-14 19:50:02 +02001271static const struct dm_mmc_ops omap_hsmmc_ops = {
1272 .send_cmd = omap_hsmmc_send_cmd,
1273 .set_ios = omap_hsmmc_set_ios,
1274#ifdef OMAP_HSMMC_USE_GPIO
1275 .get_cd = omap_hsmmc_getcd,
1276 .get_wp = omap_hsmmc_getwp,
1277#endif
Jean-Jacques Hiblot14761ca2018-01-30 16:01:35 +01001278#ifdef MMC_SUPPORTS_TUNING
1279 .execute_tuning = omap_hsmmc_execute_tuning,
1280#endif
Jean-Jacques Hiblotb5511d62017-04-14 19:50:02 +02001281};
1282#else
Pantelis Antoniouab769f22014-02-26 19:28:45 +02001283static const struct mmc_ops omap_hsmmc_ops = {
1284 .send_cmd = omap_hsmmc_send_cmd,
1285 .set_ios = omap_hsmmc_set_ios,
1286 .init = omap_hsmmc_init_setup,
1287#ifdef OMAP_HSMMC_USE_GPIO
1288 .getcd = omap_hsmmc_getcd,
1289 .getwp = omap_hsmmc_getwp,
1290#endif
1291};
Jean-Jacques Hiblotb5511d62017-04-14 19:50:02 +02001292#endif
Pantelis Antoniouab769f22014-02-26 19:28:45 +02001293
Simon Glassc4d660d2017-07-04 13:31:19 -06001294#if !CONFIG_IS_ENABLED(DM_MMC)
Nikita Kiryanove3913f52012-12-03 02:19:47 +00001295int omap_mmc_init(int dev_index, uint host_caps_mask, uint f_max, int cd_gpio,
1296 int wp_gpio)
Sukumar Ghoraide941242010-09-18 20:32:33 -07001297{
Pantelis Antoniou93bfd612014-03-11 19:34:20 +02001298 struct mmc *mmc;
Jean-Jacques Hiblotae000e22017-03-22 16:00:31 +01001299 struct omap_hsmmc_data *priv;
Pantelis Antoniou93bfd612014-03-11 19:34:20 +02001300 struct mmc_config *cfg;
1301 uint host_caps_val;
Sukumar Ghoraide941242010-09-18 20:32:33 -07001302
Jean-Jacques Hiblotae000e22017-03-22 16:00:31 +01001303 priv = malloc(sizeof(*priv));
1304 if (priv == NULL)
Pantelis Antoniou93bfd612014-03-11 19:34:20 +02001305 return -1;
1306
Rob Herring5a203972015-03-23 17:56:59 -05001307 host_caps_val = MMC_MODE_4BIT | MMC_MODE_HS_52MHz | MMC_MODE_HS;
Sukumar Ghoraide941242010-09-18 20:32:33 -07001308
1309 switch (dev_index) {
1310 case 0:
Jean-Jacques Hiblotae000e22017-03-22 16:00:31 +01001311 priv->base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE;
Sukumar Ghoraide941242010-09-18 20:32:33 -07001312 break;
Tom Rini1037d582011-10-12 06:20:50 +00001313#ifdef OMAP_HSMMC2_BASE
Sukumar Ghoraide941242010-09-18 20:32:33 -07001314 case 1:
Jean-Jacques Hiblotae000e22017-03-22 16:00:31 +01001315 priv->base_addr = (struct hsmmc *)OMAP_HSMMC2_BASE;
Lubomir Popov152ba362013-08-14 18:59:18 +03001316#if (defined(CONFIG_OMAP44XX) || defined(CONFIG_OMAP54XX) || \
Nishanth Menon3891a542016-11-29 15:22:00 +05301317 defined(CONFIG_DRA7XX) || defined(CONFIG_AM33XX) || \
Roger Quadros3b689392015-09-19 16:26:53 +05301318 defined(CONFIG_AM43XX) || defined(CONFIG_SOC_KEYSTONE)) && \
1319 defined(CONFIG_HSMMC2_8BIT)
Lubomir Popov152ba362013-08-14 18:59:18 +03001320 /* Enable 8-bit interface for eMMC on OMAP4/5 or DRA7XX */
1321 host_caps_val |= MMC_MODE_8BIT;
1322#endif
Sukumar Ghoraide941242010-09-18 20:32:33 -07001323 break;
Tom Rini1037d582011-10-12 06:20:50 +00001324#endif
1325#ifdef OMAP_HSMMC3_BASE
Sukumar Ghoraide941242010-09-18 20:32:33 -07001326 case 2:
Jean-Jacques Hiblotae000e22017-03-22 16:00:31 +01001327 priv->base_addr = (struct hsmmc *)OMAP_HSMMC3_BASE;
Nishanth Menon3891a542016-11-29 15:22:00 +05301328#if defined(CONFIG_DRA7XX) && defined(CONFIG_HSMMC3_8BIT)
Lubomir Popov152ba362013-08-14 18:59:18 +03001329 /* Enable 8-bit interface for eMMC on DRA7XX */
1330 host_caps_val |= MMC_MODE_8BIT;
1331#endif
Sukumar Ghoraide941242010-09-18 20:32:33 -07001332 break;
Tom Rini1037d582011-10-12 06:20:50 +00001333#endif
Sukumar Ghoraide941242010-09-18 20:32:33 -07001334 default:
Jean-Jacques Hiblotae000e22017-03-22 16:00:31 +01001335 priv->base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE;
Sukumar Ghoraide941242010-09-18 20:32:33 -07001336 return 1;
1337 }
Pantelis Antoniouab769f22014-02-26 19:28:45 +02001338#ifdef OMAP_HSMMC_USE_GPIO
1339 /* on error gpio values are set to -1, which is what we want */
Jean-Jacques Hiblotae000e22017-03-22 16:00:31 +01001340 priv->cd_gpio = omap_mmc_setup_gpio_in(cd_gpio, "mmc_cd");
1341 priv->wp_gpio = omap_mmc_setup_gpio_in(wp_gpio, "mmc_wp");
Pantelis Antoniouab769f22014-02-26 19:28:45 +02001342#endif
Peter Korsgaard173ddc52013-03-21 04:00:04 +00001343
Jean-Jacques Hiblotae000e22017-03-22 16:00:31 +01001344 cfg = &priv->cfg;
Sukumar Ghoraide941242010-09-18 20:32:33 -07001345
Pantelis Antoniou93bfd612014-03-11 19:34:20 +02001346 cfg->name = "OMAP SD/MMC";
1347 cfg->ops = &omap_hsmmc_ops;
1348
1349 cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195;
1350 cfg->host_caps = host_caps_val & ~host_caps_mask;
1351
1352 cfg->f_min = 400000;
Jonathan Solnitbbbc1ae2012-02-24 11:30:18 +00001353
1354 if (f_max != 0)
Pantelis Antoniou93bfd612014-03-11 19:34:20 +02001355 cfg->f_max = f_max;
Jonathan Solnitbbbc1ae2012-02-24 11:30:18 +00001356 else {
Pantelis Antoniou93bfd612014-03-11 19:34:20 +02001357 if (cfg->host_caps & MMC_MODE_HS) {
1358 if (cfg->host_caps & MMC_MODE_HS_52MHz)
1359 cfg->f_max = 52000000;
Jonathan Solnitbbbc1ae2012-02-24 11:30:18 +00001360 else
Pantelis Antoniou93bfd612014-03-11 19:34:20 +02001361 cfg->f_max = 26000000;
Jonathan Solnitbbbc1ae2012-02-24 11:30:18 +00001362 } else
Pantelis Antoniou93bfd612014-03-11 19:34:20 +02001363 cfg->f_max = 20000000;
Jonathan Solnitbbbc1ae2012-02-24 11:30:18 +00001364 }
Sukumar Ghoraide941242010-09-18 20:32:33 -07001365
Pantelis Antoniou93bfd612014-03-11 19:34:20 +02001366 cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
John Rigby8feafcc2011-04-18 05:50:08 +00001367
John Rigby4ca92442011-04-19 05:48:14 +00001368#if defined(CONFIG_OMAP34XX)
1369 /*
1370 * Silicon revs 2.1 and older do not support multiblock transfers.
1371 */
1372 if ((get_cpu_family() == CPU_OMAP34XX) && (get_cpu_rev() <= CPU_3XX_ES21))
Pantelis Antoniou93bfd612014-03-11 19:34:20 +02001373 cfg->b_max = 1;
John Rigby4ca92442011-04-19 05:48:14 +00001374#endif
Kishon Vijay Abraham I2d28eed2018-01-30 16:01:41 +01001375
Jean-Jacques Hiblotae000e22017-03-22 16:00:31 +01001376 mmc = mmc_create(cfg, priv);
Pantelis Antoniou93bfd612014-03-11 19:34:20 +02001377 if (mmc == NULL)
1378 return -1;
Sukumar Ghoraide941242010-09-18 20:32:33 -07001379
1380 return 0;
1381}
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301382#else
Kishon Vijay Abraham I33c1d772018-01-30 16:01:40 +01001383
1384#ifdef CONFIG_IODELAY_RECALIBRATION
1385static struct pad_conf_entry *
1386omap_hsmmc_get_pad_conf_entry(const fdt32_t *pinctrl, int count)
1387{
1388 int index = 0;
1389 struct pad_conf_entry *padconf;
1390
1391 padconf = (struct pad_conf_entry *)malloc(sizeof(*padconf) * count);
1392 if (!padconf) {
1393 debug("failed to allocate memory\n");
1394 return 0;
1395 }
1396
1397 while (index < count) {
1398 padconf[index].offset = fdt32_to_cpu(pinctrl[2 * index]);
1399 padconf[index].val = fdt32_to_cpu(pinctrl[2 * index + 1]);
1400 index++;
1401 }
1402
1403 return padconf;
1404}
1405
1406static struct iodelay_cfg_entry *
1407omap_hsmmc_get_iodelay_cfg_entry(const fdt32_t *pinctrl, int count)
1408{
1409 int index = 0;
1410 struct iodelay_cfg_entry *iodelay;
1411
1412 iodelay = (struct iodelay_cfg_entry *)malloc(sizeof(*iodelay) * count);
1413 if (!iodelay) {
1414 debug("failed to allocate memory\n");
1415 return 0;
1416 }
1417
1418 while (index < count) {
1419 iodelay[index].offset = fdt32_to_cpu(pinctrl[3 * index]);
1420 iodelay[index].a_delay = fdt32_to_cpu(pinctrl[3 * index + 1]);
1421 iodelay[index].g_delay = fdt32_to_cpu(pinctrl[3 * index + 2]);
1422 index++;
1423 }
1424
1425 return iodelay;
1426}
1427
1428static const fdt32_t *omap_hsmmc_get_pinctrl_entry(u32 phandle,
1429 const char *name, int *len)
1430{
1431 const void *fdt = gd->fdt_blob;
1432 int offset;
1433 const fdt32_t *pinctrl;
1434
1435 offset = fdt_node_offset_by_phandle(fdt, phandle);
1436 if (offset < 0) {
1437 debug("failed to get pinctrl node %s.\n",
1438 fdt_strerror(offset));
1439 return 0;
1440 }
1441
1442 pinctrl = fdt_getprop(fdt, offset, name, len);
1443 if (!pinctrl) {
1444 debug("failed to get property %s\n", name);
1445 return 0;
1446 }
1447
1448 return pinctrl;
1449}
1450
1451static uint32_t omap_hsmmc_get_pad_conf_phandle(struct mmc *mmc,
1452 char *prop_name)
1453{
1454 const void *fdt = gd->fdt_blob;
1455 const __be32 *phandle;
1456 int node = dev_of_offset(mmc->dev);
1457
1458 phandle = fdt_getprop(fdt, node, prop_name, NULL);
1459 if (!phandle) {
1460 debug("failed to get property %s\n", prop_name);
1461 return 0;
1462 }
1463
1464 return fdt32_to_cpu(*phandle);
1465}
1466
1467static uint32_t omap_hsmmc_get_iodelay_phandle(struct mmc *mmc,
1468 char *prop_name)
1469{
1470 const void *fdt = gd->fdt_blob;
1471 const __be32 *phandle;
1472 int len;
1473 int count;
1474 int node = dev_of_offset(mmc->dev);
1475
1476 phandle = fdt_getprop(fdt, node, prop_name, &len);
1477 if (!phandle) {
1478 debug("failed to get property %s\n", prop_name);
1479 return 0;
1480 }
1481
1482 /* No manual mode iodelay values if count < 2 */
1483 count = len / sizeof(*phandle);
1484 if (count < 2)
1485 return 0;
1486
1487 return fdt32_to_cpu(*(phandle + 1));
1488}
1489
1490static struct pad_conf_entry *
1491omap_hsmmc_get_pad_conf(struct mmc *mmc, char *prop_name, int *npads)
1492{
1493 int len;
1494 int count;
1495 struct pad_conf_entry *padconf;
1496 u32 phandle;
1497 const fdt32_t *pinctrl;
1498
1499 phandle = omap_hsmmc_get_pad_conf_phandle(mmc, prop_name);
1500 if (!phandle)
1501 return ERR_PTR(-EINVAL);
1502
1503 pinctrl = omap_hsmmc_get_pinctrl_entry(phandle, "pinctrl-single,pins",
1504 &len);
1505 if (!pinctrl)
1506 return ERR_PTR(-EINVAL);
1507
1508 count = (len / sizeof(*pinctrl)) / 2;
1509 padconf = omap_hsmmc_get_pad_conf_entry(pinctrl, count);
1510 if (!padconf)
1511 return ERR_PTR(-EINVAL);
1512
1513 *npads = count;
1514
1515 return padconf;
1516}
1517
1518static struct iodelay_cfg_entry *
1519omap_hsmmc_get_iodelay(struct mmc *mmc, char *prop_name, int *niodelay)
1520{
1521 int len;
1522 int count;
1523 struct iodelay_cfg_entry *iodelay;
1524 u32 phandle;
1525 const fdt32_t *pinctrl;
1526
1527 phandle = omap_hsmmc_get_iodelay_phandle(mmc, prop_name);
1528 /* Not all modes have manual mode iodelay values. So its not fatal */
1529 if (!phandle)
1530 return 0;
1531
1532 pinctrl = omap_hsmmc_get_pinctrl_entry(phandle, "pinctrl-pin-array",
1533 &len);
1534 if (!pinctrl)
1535 return ERR_PTR(-EINVAL);
1536
1537 count = (len / sizeof(*pinctrl)) / 3;
1538 iodelay = omap_hsmmc_get_iodelay_cfg_entry(pinctrl, count);
1539 if (!iodelay)
1540 return ERR_PTR(-EINVAL);
1541
1542 *niodelay = count;
1543
1544 return iodelay;
1545}
1546
1547static struct omap_hsmmc_pinctrl_state *
1548omap_hsmmc_get_pinctrl_by_mode(struct mmc *mmc, char *mode)
1549{
1550 int index;
1551 int npads = 0;
1552 int niodelays = 0;
1553 const void *fdt = gd->fdt_blob;
1554 int node = dev_of_offset(mmc->dev);
1555 char prop_name[11];
1556 struct omap_hsmmc_pinctrl_state *pinctrl_state;
1557
1558 pinctrl_state = (struct omap_hsmmc_pinctrl_state *)
1559 malloc(sizeof(*pinctrl_state));
1560 if (!pinctrl_state) {
1561 debug("failed to allocate memory\n");
1562 return 0;
1563 }
1564
1565 index = fdt_stringlist_search(fdt, node, "pinctrl-names", mode);
1566 if (index < 0) {
1567 debug("fail to find %s mode %s\n", mode, fdt_strerror(index));
1568 goto err_pinctrl_state;
1569 }
1570
1571 sprintf(prop_name, "pinctrl-%d", index);
1572
1573 pinctrl_state->padconf = omap_hsmmc_get_pad_conf(mmc, prop_name,
1574 &npads);
1575 if (IS_ERR(pinctrl_state->padconf))
1576 goto err_pinctrl_state;
1577 pinctrl_state->npads = npads;
1578
1579 pinctrl_state->iodelay = omap_hsmmc_get_iodelay(mmc, prop_name,
1580 &niodelays);
1581 if (IS_ERR(pinctrl_state->iodelay))
1582 goto err_padconf;
1583 pinctrl_state->niodelays = niodelays;
1584
1585 return pinctrl_state;
1586
1587err_padconf:
1588 kfree(pinctrl_state->padconf);
1589
1590err_pinctrl_state:
1591 kfree(pinctrl_state);
1592 return 0;
1593}
1594
Jean-Jacques Hiblotbcc6bd82018-01-30 16:01:42 +01001595#define OMAP_HSMMC_SETUP_PINCTRL(capmask, mode, optional) \
Kishon Vijay Abraham I2d28eed2018-01-30 16:01:41 +01001596 do { \
1597 struct omap_hsmmc_pinctrl_state *s = NULL; \
1598 char str[20]; \
1599 if (!(cfg->host_caps & capmask)) \
1600 break; \
1601 \
1602 if (priv->hw_rev) { \
1603 sprintf(str, "%s-%s", #mode, priv->hw_rev); \
1604 s = omap_hsmmc_get_pinctrl_by_mode(mmc, str); \
1605 } \
1606 \
1607 if (!s) \
1608 s = omap_hsmmc_get_pinctrl_by_mode(mmc, #mode); \
1609 \
Jean-Jacques Hiblotbcc6bd82018-01-30 16:01:42 +01001610 if (!s && !optional) { \
Kishon Vijay Abraham I2d28eed2018-01-30 16:01:41 +01001611 debug("%s: no pinctrl for %s\n", \
1612 mmc->dev->name, #mode); \
1613 cfg->host_caps &= ~(capmask); \
1614 } else { \
1615 priv->mode##_pinctrl_state = s; \
1616 } \
Kishon Vijay Abraham I33c1d772018-01-30 16:01:40 +01001617 } while (0)
1618
1619static int omap_hsmmc_get_pinctrl_state(struct mmc *mmc)
1620{
1621 struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc);
1622 struct mmc_config *cfg = omap_hsmmc_get_cfg(mmc);
1623 struct omap_hsmmc_pinctrl_state *default_pinctrl;
1624
1625 if (!(priv->controller_flags & OMAP_HSMMC_REQUIRE_IODELAY))
1626 return 0;
1627
1628 default_pinctrl = omap_hsmmc_get_pinctrl_by_mode(mmc, "default");
1629 if (!default_pinctrl) {
1630 printf("no pinctrl state for default mode\n");
1631 return -EINVAL;
1632 }
1633
1634 priv->default_pinctrl_state = default_pinctrl;
1635
Jean-Jacques Hiblotbcc6bd82018-01-30 16:01:42 +01001636 OMAP_HSMMC_SETUP_PINCTRL(MMC_CAP(UHS_SDR104), sdr104, false);
1637 OMAP_HSMMC_SETUP_PINCTRL(MMC_CAP(UHS_SDR50), sdr50, false);
1638 OMAP_HSMMC_SETUP_PINCTRL(MMC_CAP(UHS_DDR50), ddr50, false);
1639 OMAP_HSMMC_SETUP_PINCTRL(MMC_CAP(UHS_SDR25), sdr25, false);
1640 OMAP_HSMMC_SETUP_PINCTRL(MMC_CAP(UHS_SDR12), sdr12, false);
Kishon Vijay Abraham I33c1d772018-01-30 16:01:40 +01001641
Jean-Jacques Hiblotbcc6bd82018-01-30 16:01:42 +01001642 OMAP_HSMMC_SETUP_PINCTRL(MMC_CAP(MMC_HS_200), hs200_1_8v, false);
1643 OMAP_HSMMC_SETUP_PINCTRL(MMC_CAP(MMC_DDR_52), ddr_1_8v, false);
1644 OMAP_HSMMC_SETUP_PINCTRL(MMC_MODE_HS, hs, true);
Kishon Vijay Abraham I33c1d772018-01-30 16:01:40 +01001645
1646 return 0;
1647}
1648#endif
1649
Lokesh Vutla2558c042017-04-26 13:37:05 +05301650#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
Kishon Vijay Abraham I2d28eed2018-01-30 16:01:41 +01001651#ifdef CONFIG_OMAP54XX
1652__weak const struct mmc_platform_fixups *platform_fixups_mmc(uint32_t addr)
1653{
1654 return NULL;
1655}
1656#endif
1657
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301658static int omap_hsmmc_ofdata_to_platdata(struct udevice *dev)
1659{
Jean-Jacques Hiblot3d673ff2017-03-22 16:00:33 +01001660 struct omap_hsmmc_plat *plat = dev_get_platdata(dev);
Kishon Vijay Abraham I33c1d772018-01-30 16:01:40 +01001661 struct omap_mmc_of_data *of_data = (void *)dev_get_driver_data(dev);
1662
Jean-Jacques Hiblot3d673ff2017-03-22 16:00:33 +01001663 struct mmc_config *cfg = &plat->cfg;
Kishon Vijay Abraham I2d28eed2018-01-30 16:01:41 +01001664#ifdef CONFIG_OMAP54XX
1665 const struct mmc_platform_fixups *fixups;
1666#endif
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301667 const void *fdt = gd->fdt_blob;
Simon Glasse160f7d2017-01-17 16:52:55 -07001668 int node = dev_of_offset(dev);
Kishon Vijay Abraham I2d7482c2018-01-30 16:01:38 +01001669 int ret;
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301670
Simon Glassa821c4a2017-05-17 17:18:05 -06001671 plat->base_addr = map_physmem(devfdt_get_addr(dev),
1672 sizeof(struct hsmmc *),
Jean-Jacques Hiblot741726a2017-09-21 16:51:32 +02001673 MAP_NOCACHE);
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301674
Kishon Vijay Abraham I2d7482c2018-01-30 16:01:38 +01001675 ret = mmc_of_parse(dev, cfg);
1676 if (ret < 0)
1677 return ret;
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301678
Kishon Vijay Abraham I2d7482c2018-01-30 16:01:38 +01001679 cfg->host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301680 cfg->f_min = 400000;
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301681 cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195;
1682 cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
Kishon Vijay Abraham Ib5944812018-01-30 16:01:32 +01001683 if (fdtdec_get_bool(fdt, node, "ti,dual-volt"))
1684 plat->controller_flags |= OMAP_HSMMC_SUPPORTS_DUAL_VOLT;
1685 if (fdtdec_get_bool(fdt, node, "no-1-8-v"))
1686 plat->controller_flags |= OMAP_HSMMC_NO_1_8_V;
Kishon Vijay Abraham I33c1d772018-01-30 16:01:40 +01001687 if (of_data)
1688 plat->controller_flags |= of_data->controller_flags;
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301689
Kishon Vijay Abraham I2d28eed2018-01-30 16:01:41 +01001690#ifdef CONFIG_OMAP54XX
1691 fixups = platform_fixups_mmc(devfdt_get_addr(dev));
1692 if (fixups) {
1693 plat->hw_rev = fixups->hw_rev;
1694 cfg->host_caps &= ~fixups->unsupported_caps;
1695 cfg->f_max = fixups->max_freq;
1696 }
1697#endif
1698
Sekhar Nori4de2de52016-08-10 19:24:03 +05301699#ifdef OMAP_HSMMC_USE_GPIO
Lokesh Vutla2558c042017-04-26 13:37:05 +05301700 plat->cd_inverted = fdtdec_get_bool(fdt, node, "cd-inverted");
Sekhar Nori4de2de52016-08-10 19:24:03 +05301701#endif
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301702
1703 return 0;
1704}
Lokesh Vutla2558c042017-04-26 13:37:05 +05301705#endif
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301706
Jean-Jacques Hiblot17c9a1c2017-03-22 16:00:34 +01001707#ifdef CONFIG_BLK
1708
1709static int omap_hsmmc_bind(struct udevice *dev)
1710{
1711 struct omap_hsmmc_plat *plat = dev_get_platdata(dev);
1712
1713 return mmc_bind(dev, &plat->mmc, &plat->cfg);
1714}
1715#endif
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301716static int omap_hsmmc_probe(struct udevice *dev)
1717{
Jean-Jacques Hiblot3d673ff2017-03-22 16:00:33 +01001718 struct omap_hsmmc_plat *plat = dev_get_platdata(dev);
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301719 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
1720 struct omap_hsmmc_data *priv = dev_get_priv(dev);
Jean-Jacques Hiblot3d673ff2017-03-22 16:00:33 +01001721 struct mmc_config *cfg = &plat->cfg;
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301722 struct mmc *mmc;
Kishon Vijay Abraham I33c1d772018-01-30 16:01:40 +01001723#ifdef CONFIG_IODELAY_RECALIBRATION
1724 int ret;
1725#endif
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301726
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301727 cfg->name = "OMAP SD/MMC";
Lokesh Vutla2558c042017-04-26 13:37:05 +05301728 priv->base_addr = plat->base_addr;
Kishon Vijay Abraham I33c1d772018-01-30 16:01:40 +01001729 priv->controller_flags = plat->controller_flags;
Kishon Vijay Abraham I2d28eed2018-01-30 16:01:41 +01001730 priv->hw_rev = plat->hw_rev;
Lokesh Vutla2558c042017-04-26 13:37:05 +05301731#ifdef OMAP_HSMMC_USE_GPIO
1732 priv->cd_inverted = plat->cd_inverted;
1733#endif
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301734
Jean-Jacques Hiblot17c9a1c2017-03-22 16:00:34 +01001735#ifdef CONFIG_BLK
1736 mmc = &plat->mmc;
1737#else
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301738 mmc = mmc_create(cfg, priv);
1739 if (mmc == NULL)
1740 return -1;
Jean-Jacques Hiblot17c9a1c2017-03-22 16:00:34 +01001741#endif
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301742
Lokesh Vutla2558c042017-04-26 13:37:05 +05301743#if defined(OMAP_HSMMC_USE_GPIO) && CONFIG_IS_ENABLED(OF_CONTROL)
Mugunthan V N5cc6a242016-04-04 17:28:01 +05301744 gpio_request_by_name(dev, "cd-gpios", 0, &priv->cd_gpio, GPIOD_IS_IN);
1745 gpio_request_by_name(dev, "wp-gpios", 0, &priv->wp_gpio, GPIOD_IS_IN);
1746#endif
1747
Simon Glasscffe5d82016-05-01 13:52:34 -06001748 mmc->dev = dev;
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301749 upriv->mmc = mmc;
1750
Kishon Vijay Abraham I33c1d772018-01-30 16:01:40 +01001751#ifdef CONFIG_IODELAY_RECALIBRATION
1752 ret = omap_hsmmc_get_pinctrl_state(mmc);
1753 /*
1754 * disable high speed modes for the platforms that require IO delay
1755 * and for which we don't have this information
1756 */
1757 if ((ret < 0) &&
1758 (priv->controller_flags & OMAP_HSMMC_REQUIRE_IODELAY)) {
1759 priv->controller_flags &= ~OMAP_HSMMC_REQUIRE_IODELAY;
1760 cfg->host_caps &= ~(MMC_CAP(MMC_HS_200) | MMC_CAP(MMC_DDR_52) |
1761 UHS_CAPS);
1762 }
1763#endif
1764
Jean-Jacques Hiblotb5511d62017-04-14 19:50:02 +02001765 return omap_hsmmc_init_setup(mmc);
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301766}
1767
Lokesh Vutla2558c042017-04-26 13:37:05 +05301768#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
Kishon Vijay Abraham I33c1d772018-01-30 16:01:40 +01001769
1770static const struct omap_mmc_of_data dra7_mmc_of_data = {
1771 .controller_flags = OMAP_HSMMC_REQUIRE_IODELAY,
1772};
1773
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301774static const struct udevice_id omap_hsmmc_ids[] = {
Jean-Jacques Hiblot741726a2017-09-21 16:51:32 +02001775 { .compatible = "ti,omap3-hsmmc" },
1776 { .compatible = "ti,omap4-hsmmc" },
1777 { .compatible = "ti,am33xx-hsmmc" },
Kishon Vijay Abraham I33c1d772018-01-30 16:01:40 +01001778 { .compatible = "ti,dra7-hsmmc", .data = (ulong)&dra7_mmc_of_data },
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301779 { }
1780};
Lokesh Vutla2558c042017-04-26 13:37:05 +05301781#endif
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301782
1783U_BOOT_DRIVER(omap_hsmmc) = {
1784 .name = "omap_hsmmc",
1785 .id = UCLASS_MMC,
Lokesh Vutla2558c042017-04-26 13:37:05 +05301786#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301787 .of_match = omap_hsmmc_ids,
1788 .ofdata_to_platdata = omap_hsmmc_ofdata_to_platdata,
Lokesh Vutla2558c042017-04-26 13:37:05 +05301789 .platdata_auto_alloc_size = sizeof(struct omap_hsmmc_plat),
1790#endif
Jean-Jacques Hiblot17c9a1c2017-03-22 16:00:34 +01001791#ifdef CONFIG_BLK
1792 .bind = omap_hsmmc_bind,
1793#endif
Jean-Jacques Hiblotb5511d62017-04-14 19:50:02 +02001794 .ops = &omap_hsmmc_ops,
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301795 .probe = omap_hsmmc_probe,
1796 .priv_auto_alloc_size = sizeof(struct omap_hsmmc_data),
Lokesh Vutlacbcb1702017-04-26 13:37:06 +05301797 .flags = DM_FLAG_PRE_RELOC,
Mugunthan V Na9d6a7e2015-09-28 12:56:30 +05301798};
1799#endif