blob: fd3fc2af40a05b1a418981b5c8e8d05017cde3d0 [file] [log] [blame]
Ian Campbelle24ea552014-05-05 14:42:31 +01001/*
2 * (C) Copyright 2007-2011
3 * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
4 * Aaron <leafy.myeh@allwinnertech.com>
5 *
6 * MMC driver for allwinner sunxi platform.
7 *
8 * SPDX-License-Identifier: GPL-2.0+
9 */
10
11#include <common.h>
Hans de Goede90641f82015-04-22 17:03:17 +020012#include <errno.h>
Ian Campbelle24ea552014-05-05 14:42:31 +010013#include <malloc.h>
14#include <mmc.h>
15#include <asm/io.h>
16#include <asm/arch/clock.h>
17#include <asm/arch/cpu.h>
Hans de Goedecd821132014-10-02 20:29:26 +020018#include <asm/arch/gpio.h>
Ian Campbelle24ea552014-05-05 14:42:31 +010019#include <asm/arch/mmc.h>
Hans de Goedecd821132014-10-02 20:29:26 +020020#include <asm-generic/gpio.h>
Ian Campbelle24ea552014-05-05 14:42:31 +010021
Ian Campbelle24ea552014-05-05 14:42:31 +010022struct sunxi_mmc_host {
23 unsigned mmc_no;
24 uint32_t *mclkreg;
Ian Campbelle24ea552014-05-05 14:42:31 +010025 unsigned fatal_err;
Ian Campbelle24ea552014-05-05 14:42:31 +010026 struct sunxi_mmc *reg;
27 struct mmc_config cfg;
28};
29
30/* support 4 mmc hosts */
31struct sunxi_mmc_host mmc_host[4];
32
Hans de Goede967325f2014-10-31 16:55:02 +010033static int sunxi_mmc_getcd_gpio(int sdc_no)
34{
35 switch (sdc_no) {
36 case 0: return sunxi_name_to_gpio(CONFIG_MMC0_CD_PIN);
37 case 1: return sunxi_name_to_gpio(CONFIG_MMC1_CD_PIN);
38 case 2: return sunxi_name_to_gpio(CONFIG_MMC2_CD_PIN);
39 case 3: return sunxi_name_to_gpio(CONFIG_MMC3_CD_PIN);
40 }
Hans de Goede90641f82015-04-22 17:03:17 +020041 return -EINVAL;
Hans de Goede967325f2014-10-31 16:55:02 +010042}
43
Ian Campbelle24ea552014-05-05 14:42:31 +010044static int mmc_resource_init(int sdc_no)
45{
46 struct sunxi_mmc_host *mmchost = &mmc_host[sdc_no];
47 struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
Hans de Goede967325f2014-10-31 16:55:02 +010048 int cd_pin, ret = 0;
Ian Campbelle24ea552014-05-05 14:42:31 +010049
50 debug("init mmc %d resource\n", sdc_no);
51
52 switch (sdc_no) {
53 case 0:
54 mmchost->reg = (struct sunxi_mmc *)SUNXI_MMC0_BASE;
55 mmchost->mclkreg = &ccm->sd0_clk_cfg;
56 break;
57 case 1:
58 mmchost->reg = (struct sunxi_mmc *)SUNXI_MMC1_BASE;
59 mmchost->mclkreg = &ccm->sd1_clk_cfg;
60 break;
61 case 2:
62 mmchost->reg = (struct sunxi_mmc *)SUNXI_MMC2_BASE;
63 mmchost->mclkreg = &ccm->sd2_clk_cfg;
64 break;
65 case 3:
66 mmchost->reg = (struct sunxi_mmc *)SUNXI_MMC3_BASE;
67 mmchost->mclkreg = &ccm->sd3_clk_cfg;
68 break;
69 default:
70 printf("Wrong mmc number %d\n", sdc_no);
71 return -1;
72 }
Ian Campbelle24ea552014-05-05 14:42:31 +010073 mmchost->mmc_no = sdc_no;
74
Hans de Goede967325f2014-10-31 16:55:02 +010075 cd_pin = sunxi_mmc_getcd_gpio(sdc_no);
Hans de Goede90641f82015-04-22 17:03:17 +020076 if (cd_pin >= 0) {
Hans de Goede967325f2014-10-31 16:55:02 +010077 ret = gpio_request(cd_pin, "mmc_cd");
Hans de Goede1c09fa32015-05-30 16:39:10 +020078 if (!ret) {
79 sunxi_gpio_set_pull(cd_pin, SUNXI_GPIO_PULL_UP);
Axel Linb0c4ae12014-12-20 11:41:25 +080080 ret = gpio_direction_input(cd_pin);
Hans de Goede1c09fa32015-05-30 16:39:10 +020081 }
Axel Linb0c4ae12014-12-20 11:41:25 +080082 }
Hans de Goede967325f2014-10-31 16:55:02 +010083
84 return ret;
Ian Campbelle24ea552014-05-05 14:42:31 +010085}
86
Hans de Goedefc3a8322014-12-07 20:55:10 +010087static int mmc_set_mod_clk(struct sunxi_mmc_host *mmchost, unsigned int hz)
88{
89 unsigned int pll, pll_hz, div, n, oclk_dly, sclk_dly;
90
91 if (hz <= 24000000) {
92 pll = CCM_MMC_CTRL_OSCM24;
93 pll_hz = 24000000;
94 } else {
Hans de Goededaf22632015-01-14 19:05:03 +010095#ifdef CONFIG_MACH_SUN9I
96 pll = CCM_MMC_CTRL_PLL_PERIPH0;
97 pll_hz = clock_get_pll4_periph0();
98#else
Hans de Goedefc3a8322014-12-07 20:55:10 +010099 pll = CCM_MMC_CTRL_PLL6;
100 pll_hz = clock_get_pll6();
Hans de Goededaf22632015-01-14 19:05:03 +0100101#endif
Hans de Goedefc3a8322014-12-07 20:55:10 +0100102 }
103
104 div = pll_hz / hz;
105 if (pll_hz % hz)
106 div++;
107
108 n = 0;
109 while (div > 16) {
110 n++;
111 div = (div + 1) / 2;
112 }
113
114 if (n > 3) {
115 printf("mmc %u error cannot set clock to %u\n",
116 mmchost->mmc_no, hz);
117 return -1;
118 }
119
120 /* determine delays */
121 if (hz <= 400000) {
122 oclk_dly = 0;
Hans de Goedebe909742015-09-23 16:13:10 +0200123 sclk_dly = 0;
Hans de Goedefc3a8322014-12-07 20:55:10 +0100124 } else if (hz <= 25000000) {
125 oclk_dly = 0;
126 sclk_dly = 5;
Hans de Goedebe909742015-09-23 16:13:10 +0200127#ifdef CONFIG_MACH_SUN9I
Hans de Goedefc3a8322014-12-07 20:55:10 +0100128 } else if (hz <= 50000000) {
Hans de Goedebe909742015-09-23 16:13:10 +0200129 oclk_dly = 5;
130 sclk_dly = 4;
Hans de Goedefc3a8322014-12-07 20:55:10 +0100131 } else {
132 /* hz > 50000000 */
133 oclk_dly = 2;
134 sclk_dly = 4;
Hans de Goedebe909742015-09-23 16:13:10 +0200135#else
136 } else if (hz <= 50000000) {
137 oclk_dly = 3;
138 sclk_dly = 4;
139 } else {
140 /* hz > 50000000 */
141 oclk_dly = 1;
142 sclk_dly = 4;
143#endif
Hans de Goedefc3a8322014-12-07 20:55:10 +0100144 }
145
146 writel(CCM_MMC_CTRL_ENABLE | pll | CCM_MMC_CTRL_SCLK_DLY(sclk_dly) |
147 CCM_MMC_CTRL_N(n) | CCM_MMC_CTRL_OCLK_DLY(oclk_dly) |
148 CCM_MMC_CTRL_M(div), mmchost->mclkreg);
149
150 debug("mmc %u set mod-clk req %u parent %u n %u m %u rate %u\n",
151 mmchost->mmc_no, hz, pll_hz, 1u << n, div,
152 pll_hz / (1u << n) / div);
153
154 return 0;
155}
156
Ian Campbelle24ea552014-05-05 14:42:31 +0100157static int mmc_clk_io_on(int sdc_no)
158{
Ian Campbelle24ea552014-05-05 14:42:31 +0100159 struct sunxi_mmc_host *mmchost = &mmc_host[sdc_no];
160 struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
161
162 debug("init mmc %d clock and io\n", sdc_no);
163
164 /* config ahb clock */
165 setbits_le32(&ccm->ahb_gate0, 1 << AHB_GATE_OFFSET_MMC(sdc_no));
166
Hans de Goede44d8ae52015-04-06 20:33:34 +0200167#ifdef CONFIG_SUNXI_GEN_SUN6I
Hans de Goede1d1bd422014-10-03 20:16:26 +0800168 /* unassert reset */
169 setbits_le32(&ccm->ahb_reset0_cfg, 1 << AHB_RESET_OFFSET_MMC(sdc_no));
170#endif
Hans de Goededaf22632015-01-14 19:05:03 +0100171#if defined(CONFIG_MACH_SUN9I)
172 /* sun9i has a mmc-common module, also set the gate and reset there */
173 writel(SUNXI_MMC_COMMON_CLK_GATE | SUNXI_MMC_COMMON_RESET,
174 SUNXI_MMC_COMMON_BASE + 4 * sdc_no);
175#endif
Hans de Goede1d1bd422014-10-03 20:16:26 +0800176
Hans de Goedefc3a8322014-12-07 20:55:10 +0100177 return mmc_set_mod_clk(mmchost, 24000000);
Ian Campbelle24ea552014-05-05 14:42:31 +0100178}
179
180static int mmc_update_clk(struct mmc *mmc)
181{
182 struct sunxi_mmc_host *mmchost = mmc->priv;
183 unsigned int cmd;
184 unsigned timeout_msecs = 2000;
185
186 cmd = SUNXI_MMC_CMD_START |
187 SUNXI_MMC_CMD_UPCLK_ONLY |
188 SUNXI_MMC_CMD_WAIT_PRE_OVER;
189 writel(cmd, &mmchost->reg->cmd);
190 while (readl(&mmchost->reg->cmd) & SUNXI_MMC_CMD_START) {
191 if (!timeout_msecs--)
192 return -1;
193 udelay(1000);
194 }
195
196 /* clock update sets various irq status bits, clear these */
197 writel(readl(&mmchost->reg->rint), &mmchost->reg->rint);
198
199 return 0;
200}
201
Hans de Goedefc3a8322014-12-07 20:55:10 +0100202static int mmc_config_clock(struct mmc *mmc)
Ian Campbelle24ea552014-05-05 14:42:31 +0100203{
204 struct sunxi_mmc_host *mmchost = mmc->priv;
205 unsigned rval = readl(&mmchost->reg->clkcr);
206
207 /* Disable Clock */
208 rval &= ~SUNXI_MMC_CLK_ENABLE;
209 writel(rval, &mmchost->reg->clkcr);
210 if (mmc_update_clk(mmc))
211 return -1;
212
Hans de Goedefc3a8322014-12-07 20:55:10 +0100213 /* Set mod_clk to new rate */
214 if (mmc_set_mod_clk(mmchost, mmc->clock))
Ian Campbelle24ea552014-05-05 14:42:31 +0100215 return -1;
Hans de Goedefc3a8322014-12-07 20:55:10 +0100216
217 /* Clear internal divider */
218 rval &= ~SUNXI_MMC_CLK_DIVIDER_MASK;
219 writel(rval, &mmchost->reg->clkcr);
220
Ian Campbelle24ea552014-05-05 14:42:31 +0100221 /* Re-enable Clock */
222 rval |= SUNXI_MMC_CLK_ENABLE;
223 writel(rval, &mmchost->reg->clkcr);
Ian Campbelle24ea552014-05-05 14:42:31 +0100224 if (mmc_update_clk(mmc))
225 return -1;
226
227 return 0;
228}
229
Jaehoon Chung07b0b9c2016-12-30 15:30:16 +0900230static int sunxi_mmc_set_ios(struct mmc *mmc)
Ian Campbelle24ea552014-05-05 14:42:31 +0100231{
232 struct sunxi_mmc_host *mmchost = mmc->priv;
Ian Campbelle24ea552014-05-05 14:42:31 +0100233
Hans de Goedefc3a8322014-12-07 20:55:10 +0100234 debug("set ios: bus_width: %x, clock: %d\n",
235 mmc->bus_width, mmc->clock);
Ian Campbelle24ea552014-05-05 14:42:31 +0100236
237 /* Change clock first */
Hans de Goedefc3a8322014-12-07 20:55:10 +0100238 if (mmc->clock && mmc_config_clock(mmc) != 0) {
239 mmchost->fatal_err = 1;
Jaehoon Chung07b0b9c2016-12-30 15:30:16 +0900240 return -EINVAL;
Ian Campbelle24ea552014-05-05 14:42:31 +0100241 }
242
243 /* Change bus width */
244 if (mmc->bus_width == 8)
245 writel(0x2, &mmchost->reg->width);
246 else if (mmc->bus_width == 4)
247 writel(0x1, &mmchost->reg->width);
248 else
249 writel(0x0, &mmchost->reg->width);
Jaehoon Chung07b0b9c2016-12-30 15:30:16 +0900250
251 return 0;
Ian Campbelle24ea552014-05-05 14:42:31 +0100252}
253
Siarhei Siamashka5abdb152015-02-01 00:42:14 +0200254static int sunxi_mmc_core_init(struct mmc *mmc)
Ian Campbelle24ea552014-05-05 14:42:31 +0100255{
256 struct sunxi_mmc_host *mmchost = mmc->priv;
257
258 /* Reset controller */
259 writel(SUNXI_MMC_GCTRL_RESET, &mmchost->reg->gctrl);
Hans de Goedeb6ae6762014-06-09 11:36:55 +0200260 udelay(1000);
Ian Campbelle24ea552014-05-05 14:42:31 +0100261
262 return 0;
263}
264
265static int mmc_trans_data_by_cpu(struct mmc *mmc, struct mmc_data *data)
266{
267 struct sunxi_mmc_host *mmchost = mmc->priv;
268 const int reading = !!(data->flags & MMC_DATA_READ);
269 const uint32_t status_bit = reading ? SUNXI_MMC_STATUS_FIFO_EMPTY :
270 SUNXI_MMC_STATUS_FIFO_FULL;
271 unsigned i;
Ian Campbelle24ea552014-05-05 14:42:31 +0100272 unsigned *buff = (unsigned int *)(reading ? data->dest : data->src);
Yousong Zhou28f69b92015-08-29 21:26:11 +0800273 unsigned byte_cnt = data->blocksize * data->blocks;
Tobias Doerffel26c0c152016-07-08 12:40:14 +0200274 unsigned timeout_usecs = (byte_cnt >> 8) * 1000;
275 if (timeout_usecs < 2000000)
276 timeout_usecs = 2000000;
Ian Campbelle24ea552014-05-05 14:42:31 +0100277
Hans de Goedeb6ae6762014-06-09 11:36:55 +0200278 /* Always read / write data through the CPU */
279 setbits_le32(&mmchost->reg->gctrl, SUNXI_MMC_GCTRL_ACCESS_BY_AHB);
280
Ian Campbelle24ea552014-05-05 14:42:31 +0100281 for (i = 0; i < (byte_cnt >> 2); i++) {
282 while (readl(&mmchost->reg->status) & status_bit) {
Tobias Doerffel26c0c152016-07-08 12:40:14 +0200283 if (!timeout_usecs--)
Ian Campbelle24ea552014-05-05 14:42:31 +0100284 return -1;
Tobias Doerffel26c0c152016-07-08 12:40:14 +0200285 udelay(1);
Ian Campbelle24ea552014-05-05 14:42:31 +0100286 }
287
288 if (reading)
Hans de Goede1d1bd422014-10-03 20:16:26 +0800289 buff[i] = readl(&mmchost->reg->fifo);
Ian Campbelle24ea552014-05-05 14:42:31 +0100290 else
Hans de Goede1d1bd422014-10-03 20:16:26 +0800291 writel(buff[i], &mmchost->reg->fifo);
Ian Campbelle24ea552014-05-05 14:42:31 +0100292 }
293
294 return 0;
295}
296
Ian Campbelle24ea552014-05-05 14:42:31 +0100297static int mmc_rint_wait(struct mmc *mmc, unsigned int timeout_msecs,
298 unsigned int done_bit, const char *what)
299{
300 struct sunxi_mmc_host *mmchost = mmc->priv;
301 unsigned int status;
302
303 do {
304 status = readl(&mmchost->reg->rint);
305 if (!timeout_msecs-- ||
306 (status & SUNXI_MMC_RINT_INTERRUPT_ERROR_BIT)) {
307 debug("%s timeout %x\n", what,
308 status & SUNXI_MMC_RINT_INTERRUPT_ERROR_BIT);
Jaehoon Chung915ffa52016-07-19 16:33:36 +0900309 return -ETIMEDOUT;
Ian Campbelle24ea552014-05-05 14:42:31 +0100310 }
311 udelay(1000);
312 } while (!(status & done_bit));
313
314 return 0;
315}
316
Siarhei Siamashka5abdb152015-02-01 00:42:14 +0200317static int sunxi_mmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
318 struct mmc_data *data)
Ian Campbelle24ea552014-05-05 14:42:31 +0100319{
320 struct sunxi_mmc_host *mmchost = mmc->priv;
321 unsigned int cmdval = SUNXI_MMC_CMD_START;
322 unsigned int timeout_msecs;
323 int error = 0;
324 unsigned int status = 0;
Ian Campbelle24ea552014-05-05 14:42:31 +0100325 unsigned int bytecnt = 0;
326
327 if (mmchost->fatal_err)
328 return -1;
329 if (cmd->resp_type & MMC_RSP_BUSY)
330 debug("mmc cmd %d check rsp busy\n", cmd->cmdidx);
331 if (cmd->cmdidx == 12)
332 return 0;
333
334 if (!cmd->cmdidx)
335 cmdval |= SUNXI_MMC_CMD_SEND_INIT_SEQ;
336 if (cmd->resp_type & MMC_RSP_PRESENT)
337 cmdval |= SUNXI_MMC_CMD_RESP_EXPIRE;
338 if (cmd->resp_type & MMC_RSP_136)
339 cmdval |= SUNXI_MMC_CMD_LONG_RESPONSE;
340 if (cmd->resp_type & MMC_RSP_CRC)
341 cmdval |= SUNXI_MMC_CMD_CHK_RESPONSE_CRC;
342
343 if (data) {
Alexander Graf0ea5a042016-03-29 17:29:09 +0200344 if ((u32)(long)data->dest & 0x3) {
Ian Campbelle24ea552014-05-05 14:42:31 +0100345 error = -1;
346 goto out;
347 }
348
349 cmdval |= SUNXI_MMC_CMD_DATA_EXPIRE|SUNXI_MMC_CMD_WAIT_PRE_OVER;
350 if (data->flags & MMC_DATA_WRITE)
351 cmdval |= SUNXI_MMC_CMD_WRITE;
352 if (data->blocks > 1)
353 cmdval |= SUNXI_MMC_CMD_AUTO_STOP;
354 writel(data->blocksize, &mmchost->reg->blksz);
355 writel(data->blocks * data->blocksize, &mmchost->reg->bytecnt);
356 }
357
358 debug("mmc %d, cmd %d(0x%08x), arg 0x%08x\n", mmchost->mmc_no,
359 cmd->cmdidx, cmdval | cmd->cmdidx, cmd->cmdarg);
360 writel(cmd->cmdarg, &mmchost->reg->arg);
361
362 if (!data)
363 writel(cmdval | cmd->cmdidx, &mmchost->reg->cmd);
364
365 /*
366 * transfer data and check status
367 * STATREG[2] : FIFO empty
368 * STATREG[3] : FIFO full
369 */
370 if (data) {
371 int ret = 0;
372
373 bytecnt = data->blocksize * data->blocks;
374 debug("trans data %d bytes\n", bytecnt);
Hans de Goedeb6ae6762014-06-09 11:36:55 +0200375 writel(cmdval | cmd->cmdidx, &mmchost->reg->cmd);
376 ret = mmc_trans_data_by_cpu(mmc, data);
Ian Campbelle24ea552014-05-05 14:42:31 +0100377 if (ret) {
378 error = readl(&mmchost->reg->rint) & \
379 SUNXI_MMC_RINT_INTERRUPT_ERROR_BIT;
Jaehoon Chung915ffa52016-07-19 16:33:36 +0900380 error = -ETIMEDOUT;
Ian Campbelle24ea552014-05-05 14:42:31 +0100381 goto out;
382 }
383 }
384
Hans de Goede5b8d7fb2015-01-15 13:50:35 +0100385 error = mmc_rint_wait(mmc, 1000, SUNXI_MMC_RINT_COMMAND_DONE, "cmd");
Ian Campbelle24ea552014-05-05 14:42:31 +0100386 if (error)
387 goto out;
388
389 if (data) {
Hans de Goedeb6ae6762014-06-09 11:36:55 +0200390 timeout_msecs = 120;
Ian Campbelle24ea552014-05-05 14:42:31 +0100391 debug("cacl timeout %x msec\n", timeout_msecs);
392 error = mmc_rint_wait(mmc, timeout_msecs,
393 data->blocks > 1 ?
394 SUNXI_MMC_RINT_AUTO_COMMAND_DONE :
395 SUNXI_MMC_RINT_DATA_OVER,
396 "data");
397 if (error)
398 goto out;
399 }
400
401 if (cmd->resp_type & MMC_RSP_BUSY) {
402 timeout_msecs = 2000;
403 do {
404 status = readl(&mmchost->reg->status);
405 if (!timeout_msecs--) {
406 debug("busy timeout\n");
Jaehoon Chung915ffa52016-07-19 16:33:36 +0900407 error = -ETIMEDOUT;
Ian Campbelle24ea552014-05-05 14:42:31 +0100408 goto out;
409 }
410 udelay(1000);
411 } while (status & SUNXI_MMC_STATUS_CARD_DATA_BUSY);
412 }
413
414 if (cmd->resp_type & MMC_RSP_136) {
415 cmd->response[0] = readl(&mmchost->reg->resp3);
416 cmd->response[1] = readl(&mmchost->reg->resp2);
417 cmd->response[2] = readl(&mmchost->reg->resp1);
418 cmd->response[3] = readl(&mmchost->reg->resp0);
419 debug("mmc resp 0x%08x 0x%08x 0x%08x 0x%08x\n",
420 cmd->response[3], cmd->response[2],
421 cmd->response[1], cmd->response[0]);
422 } else {
423 cmd->response[0] = readl(&mmchost->reg->resp0);
424 debug("mmc resp 0x%08x\n", cmd->response[0]);
425 }
426out:
Ian Campbelle24ea552014-05-05 14:42:31 +0100427 if (error < 0) {
428 writel(SUNXI_MMC_GCTRL_RESET, &mmchost->reg->gctrl);
429 mmc_update_clk(mmc);
430 }
431 writel(0xffffffff, &mmchost->reg->rint);
432 writel(readl(&mmchost->reg->gctrl) | SUNXI_MMC_GCTRL_FIFO_RESET,
433 &mmchost->reg->gctrl);
434
435 return error;
436}
437
Hans de Goedecd821132014-10-02 20:29:26 +0200438static int sunxi_mmc_getcd(struct mmc *mmc)
439{
440 struct sunxi_mmc_host *mmchost = mmc->priv;
Hans de Goede967325f2014-10-31 16:55:02 +0100441 int cd_pin;
Hans de Goedecd821132014-10-02 20:29:26 +0200442
Hans de Goede967325f2014-10-31 16:55:02 +0100443 cd_pin = sunxi_mmc_getcd_gpio(mmchost->mmc_no);
Hans de Goede90641f82015-04-22 17:03:17 +0200444 if (cd_pin < 0)
Hans de Goedecd821132014-10-02 20:29:26 +0200445 return 1;
446
Axel Linb0c4ae12014-12-20 11:41:25 +0800447 return !gpio_get_value(cd_pin);
Hans de Goedecd821132014-10-02 20:29:26 +0200448}
449
Ian Campbelle24ea552014-05-05 14:42:31 +0100450static const struct mmc_ops sunxi_mmc_ops = {
Siarhei Siamashka5abdb152015-02-01 00:42:14 +0200451 .send_cmd = sunxi_mmc_send_cmd,
452 .set_ios = sunxi_mmc_set_ios,
453 .init = sunxi_mmc_core_init,
Hans de Goedecd821132014-10-02 20:29:26 +0200454 .getcd = sunxi_mmc_getcd,
Ian Campbelle24ea552014-05-05 14:42:31 +0100455};
456
Hans de Goedee79c7c82014-10-02 21:13:54 +0200457struct mmc *sunxi_mmc_init(int sdc_no)
Ian Campbelle24ea552014-05-05 14:42:31 +0100458{
459 struct mmc_config *cfg = &mmc_host[sdc_no].cfg;
460
461 memset(&mmc_host[sdc_no], 0, sizeof(struct sunxi_mmc_host));
462
463 cfg->name = "SUNXI SD/MMC";
464 cfg->ops = &sunxi_mmc_ops;
465
466 cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
467 cfg->host_caps = MMC_MODE_4BIT;
Maxime Ripardfb013182016-11-04 16:18:09 +0100468#if defined(CONFIG_MACH_SUN50I) || defined(CONFIG_MACH_SUN8I)
Siarhei Siamashkad96ebc42016-03-29 17:29:10 +0200469 if (sdc_no == 2)
470 cfg->host_caps = MMC_MODE_8BIT;
471#endif
Rob Herring5a203972015-03-23 17:56:59 -0500472 cfg->host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;
Ian Campbelle24ea552014-05-05 14:42:31 +0100473 cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
474
475 cfg->f_min = 400000;
476 cfg->f_max = 52000000;
477
Hans de Goede967325f2014-10-31 16:55:02 +0100478 if (mmc_resource_init(sdc_no) != 0)
479 return NULL;
480
Ian Campbelle24ea552014-05-05 14:42:31 +0100481 mmc_clk_io_on(sdc_no);
482
Hans de Goedee79c7c82014-10-02 21:13:54 +0200483 return mmc_create(cfg, &mmc_host[sdc_no]);
Ian Campbelle24ea552014-05-05 14:42:31 +0100484}