blob: 0d63279db00afbb31f23149b1ff3285f9211c1cc [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Sandeep Paulraj57418d22010-12-20 20:01:21 -05002/*
3 * Davinci MMC Controller Driver
4 *
5 * Copyright (C) 2010 Texas Instruments Incorporated
Sandeep Paulraj57418d22010-12-20 20:01:21 -05006 */
7
8#include <config.h>
9#include <common.h>
Adam Forddf6565c2018-08-09 06:15:12 -050010#include <dm.h>
Jaehoon Chung915ffa52016-07-19 16:33:36 +090011#include <errno.h>
Sandeep Paulraj57418d22010-12-20 20:01:21 -050012#include <mmc.h>
Adam Forddf6565c2018-08-09 06:15:12 -050013#include <command.h>
Sandeep Paulraj57418d22010-12-20 20:01:21 -050014#include <part.h>
15#include <malloc.h>
16#include <asm/io.h>
17#include <asm/arch/sdmmc_defs.h>
Adam Ford04355de2018-09-03 03:47:52 -050018#include <asm-generic/gpio.h>
Sandeep Paulraj57418d22010-12-20 20:01:21 -050019
20#define DAVINCI_MAX_BLOCKS (32)
21#define WATCHDOG_COUNT (100000)
22
23#define get_val(addr) REG(addr)
24#define set_val(addr, val) REG(addr) = (val)
25#define set_bit(addr, val) set_val((addr), (get_val(addr) | (val)))
26#define clear_bit(addr, val) set_val((addr), (get_val(addr) & ~(val)))
27
Adam Forddf6565c2018-08-09 06:15:12 -050028#ifdef CONFIG_DM_MMC
29struct davinci_of_data {
30 const char *name;
31 u8 version;
32};
33
34/* Davinci MMC board definitions */
35struct davinci_mmc_priv {
36 struct davinci_mmc_regs *reg_base; /* Register base address */
37 uint input_clk; /* Input clock to MMC controller */
38 uint version; /* MMC Controller version */
Adam Ford04355de2018-09-03 03:47:52 -050039 struct gpio_desc cd_gpio; /* Card Detect GPIO */
40 struct gpio_desc wp_gpio; /* Write Protect GPIO */
Adam Forddf6565c2018-08-09 06:15:12 -050041};
42
43struct davinci_mmc_plat
44{
45 struct mmc_config cfg;
46 struct mmc mmc;
47};
48#endif
49
Sandeep Paulraj57418d22010-12-20 20:01:21 -050050/* Set davinci clock prescalar value based on the required clock in HZ */
Adam Forddf6565c2018-08-09 06:15:12 -050051#if !CONFIG_IS_ENABLED(DM_MMC)
Sandeep Paulraj57418d22010-12-20 20:01:21 -050052static void dmmc_set_clock(struct mmc *mmc, uint clock)
53{
54 struct davinci_mmc *host = mmc->priv;
Adam Forddf6565c2018-08-09 06:15:12 -050055#else
56
57static void davinci_mmc_set_clock(struct udevice *dev, uint clock)
58{
59 struct davinci_mmc_priv *host = dev_get_priv(dev);
60 struct mmc *mmc = mmc_get_mmc_dev(dev);
61#endif
Sandeep Paulraj57418d22010-12-20 20:01:21 -050062 struct davinci_mmc_regs *regs = host->reg_base;
63 uint clkrt, sysclk2, act_clock;
64
Pantelis Antoniou93bfd612014-03-11 19:34:20 +020065 if (clock < mmc->cfg->f_min)
66 clock = mmc->cfg->f_min;
67 if (clock > mmc->cfg->f_max)
68 clock = mmc->cfg->f_max;
Sandeep Paulraj57418d22010-12-20 20:01:21 -050069
70 set_val(&regs->mmcclk, 0);
71 sysclk2 = host->input_clk;
72 clkrt = (sysclk2 / (2 * clock)) - 1;
73
74 /* Calculate the actual clock for the divider used */
75 act_clock = (sysclk2 / (2 * (clkrt + 1)));
76
77 /* Adjust divider if actual clock exceeds the required clock */
78 if (act_clock > clock)
79 clkrt++;
80
81 /* check clock divider boundary and correct it */
82 if (clkrt > 0xFF)
83 clkrt = 0xFF;
84
85 set_val(&regs->mmcclk, (clkrt | MMCCLK_CLKEN));
86}
87
88/* Status bit wait loop for MMCST1 */
89static int
90dmmc_wait_fifo_status(volatile struct davinci_mmc_regs *regs, uint status)
91{
Heiko Schocher79b05d52011-10-30 19:15:53 +000092 uint wdog = WATCHDOG_COUNT;
93
Sandeep Paulraj57418d22010-12-20 20:01:21 -050094 while (--wdog && ((get_val(&regs->mmcst1) & status) != status))
95 udelay(10);
96
97 if (!(get_val(&regs->mmcctl) & MMCCTL_WIDTH_4_BIT))
98 udelay(100);
99
100 if (wdog == 0)
Jaehoon Chung915ffa52016-07-19 16:33:36 +0900101 return -ECOMM;
Sandeep Paulraj57418d22010-12-20 20:01:21 -0500102
103 return 0;
104}
105
106/* Busy bit wait loop for MMCST1 */
107static int dmmc_busy_wait(volatile struct davinci_mmc_regs *regs)
108{
Heiko Schocher79b05d52011-10-30 19:15:53 +0000109 uint wdog = WATCHDOG_COUNT;
Sandeep Paulraj57418d22010-12-20 20:01:21 -0500110
Sandeep Paulraj57418d22010-12-20 20:01:21 -0500111 while (--wdog && (get_val(&regs->mmcst1) & MMCST1_BUSY))
112 udelay(10);
113
114 if (wdog == 0)
Jaehoon Chung915ffa52016-07-19 16:33:36 +0900115 return -ECOMM;
Sandeep Paulraj57418d22010-12-20 20:01:21 -0500116
117 return 0;
118}
119
120/* Status bit wait loop for MMCST0 - Checks for error bits as well */
121static int dmmc_check_status(volatile struct davinci_mmc_regs *regs,
122 uint *cur_st, uint st_ready, uint st_error)
123{
124 uint wdog = WATCHDOG_COUNT;
125 uint mmcstatus = *cur_st;
126
127 while (wdog--) {
128 if (mmcstatus & st_ready) {
129 *cur_st = mmcstatus;
130 mmcstatus = get_val(&regs->mmcst1);
131 return 0;
132 } else if (mmcstatus & st_error) {
133 if (mmcstatus & MMCST0_TOUTRS)
Jaehoon Chung915ffa52016-07-19 16:33:36 +0900134 return -ETIMEDOUT;
Sandeep Paulraj57418d22010-12-20 20:01:21 -0500135 printf("[ ST0 ERROR %x]\n", mmcstatus);
136 /*
137 * Ignore CRC errors as some MMC cards fail to
138 * initialize on DM365-EVM on the SD1 slot
139 */
140 if (mmcstatus & MMCST0_CRCRS)
141 return 0;
Jaehoon Chung915ffa52016-07-19 16:33:36 +0900142 return -ECOMM;
Sandeep Paulraj57418d22010-12-20 20:01:21 -0500143 }
144 udelay(10);
145
146 mmcstatus = get_val(&regs->mmcst0);
147 }
148
149 printf("Status %x Timeout ST0:%x ST1:%x\n", st_ready, mmcstatus,
150 get_val(&regs->mmcst1));
Jaehoon Chung915ffa52016-07-19 16:33:36 +0900151 return -ECOMM;
Sandeep Paulraj57418d22010-12-20 20:01:21 -0500152}
153
154/*
Adam Forddf6565c2018-08-09 06:15:12 -0500155 * Sends a command out on the bus. Takes the device pointer,
Sandeep Paulraj57418d22010-12-20 20:01:21 -0500156 * a command pointer, and an optional data pointer.
157 */
Adam Forddf6565c2018-08-09 06:15:12 -0500158#if !CONFIG_IS_ENABLED(DM_MMC)
159static int dmmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
Sandeep Paulraj57418d22010-12-20 20:01:21 -0500160{
161 struct davinci_mmc *host = mmc->priv;
Adam Forddf6565c2018-08-09 06:15:12 -0500162#else
163static int
164davinci_mmc_send_cmd(struct udevice *dev, struct mmc_cmd *cmd, struct mmc_data *data)
165{
166 struct davinci_mmc_priv *host = dev_get_priv(dev);
167#endif
Sandeep Paulraj57418d22010-12-20 20:01:21 -0500168 volatile struct davinci_mmc_regs *regs = host->reg_base;
169 uint mmcstatus, status_rdy, status_err;
170 uint i, cmddata, bytes_left = 0;
171 int fifo_words, fifo_bytes, err;
172 char *data_buf = NULL;
173
174 /* Clear status registers */
175 mmcstatus = get_val(&regs->mmcst0);
176 fifo_words = (host->version == MMC_CTLR_VERSION_2) ? 16 : 8;
177 fifo_bytes = fifo_words << 2;
178
179 /* Wait for any previous busy signal to be cleared */
180 dmmc_busy_wait(regs);
181
182 cmddata = cmd->cmdidx;
183 cmddata |= MMCCMD_PPLEN;
184
185 /* Send init clock for CMD0 */
186 if (cmd->cmdidx == MMC_CMD_GO_IDLE_STATE)
187 cmddata |= MMCCMD_INITCK;
188
189 switch (cmd->resp_type) {
190 case MMC_RSP_R1b:
191 cmddata |= MMCCMD_BSYEXP;
192 /* Fall-through */
193 case MMC_RSP_R1: /* R1, R1b, R5, R6, R7 */
194 cmddata |= MMCCMD_RSPFMT_R1567;
195 break;
196 case MMC_RSP_R2:
197 cmddata |= MMCCMD_RSPFMT_R2;
198 break;
199 case MMC_RSP_R3: /* R3, R4 */
200 cmddata |= MMCCMD_RSPFMT_R3;
201 break;
202 }
203
204 set_val(&regs->mmcim, 0);
205
206 if (data) {
207 /* clear previous data transfer if any and set new one */
208 bytes_left = (data->blocksize * data->blocks);
209
210 /* Reset FIFO - Always use 32 byte fifo threshold */
211 set_val(&regs->mmcfifoctl,
212 (MMCFIFOCTL_FIFOLEV | MMCFIFOCTL_FIFORST));
213
214 if (host->version == MMC_CTLR_VERSION_2)
215 cmddata |= MMCCMD_DMATRIG;
216
217 cmddata |= MMCCMD_WDATX;
218 if (data->flags == MMC_DATA_READ) {
219 set_val(&regs->mmcfifoctl, MMCFIFOCTL_FIFOLEV);
220 } else if (data->flags == MMC_DATA_WRITE) {
221 set_val(&regs->mmcfifoctl,
222 (MMCFIFOCTL_FIFOLEV |
223 MMCFIFOCTL_FIFODIR));
224 cmddata |= MMCCMD_DTRW;
225 }
226
227 set_val(&regs->mmctod, 0xFFFF);
228 set_val(&regs->mmcnblk, (data->blocks & MMCNBLK_NBLK_MASK));
229 set_val(&regs->mmcblen, (data->blocksize & MMCBLEN_BLEN_MASK));
230
231 if (data->flags == MMC_DATA_WRITE) {
232 uint val;
233 data_buf = (char *)data->src;
234 /* For write, fill FIFO with data before issue of CMD */
235 for (i = 0; (i < fifo_words) && bytes_left; i++) {
236 memcpy((char *)&val, data_buf, 4);
237 set_val(&regs->mmcdxr, val);
238 data_buf += 4;
239 bytes_left -= 4;
240 }
241 }
242 } else {
243 set_val(&regs->mmcblen, 0);
244 set_val(&regs->mmcnblk, 0);
245 }
246
247 set_val(&regs->mmctor, 0x1FFF);
248
249 /* Send the command */
250 set_val(&regs->mmcarghl, cmd->cmdarg);
251 set_val(&regs->mmccmd, cmddata);
252
253 status_rdy = MMCST0_RSPDNE;
254 status_err = (MMCST0_TOUTRS | MMCST0_TOUTRD |
255 MMCST0_CRCWR | MMCST0_CRCRD);
256 if (cmd->resp_type & MMC_RSP_CRC)
257 status_err |= MMCST0_CRCRS;
258
259 mmcstatus = get_val(&regs->mmcst0);
260 err = dmmc_check_status(regs, &mmcstatus, status_rdy, status_err);
261 if (err)
262 return err;
263
264 /* For R1b wait for busy done */
265 if (cmd->resp_type == MMC_RSP_R1b)
266 dmmc_busy_wait(regs);
267
268 /* Collect response from controller for specific commands */
269 if (mmcstatus & MMCST0_RSPDNE) {
270 /* Copy the response to the response buffer */
271 if (cmd->resp_type & MMC_RSP_136) {
272 cmd->response[0] = get_val(&regs->mmcrsp67);
273 cmd->response[1] = get_val(&regs->mmcrsp45);
274 cmd->response[2] = get_val(&regs->mmcrsp23);
275 cmd->response[3] = get_val(&regs->mmcrsp01);
276 } else if (cmd->resp_type & MMC_RSP_PRESENT) {
277 cmd->response[0] = get_val(&regs->mmcrsp67);
278 }
279 }
280
281 if (data == NULL)
282 return 0;
283
284 if (data->flags == MMC_DATA_READ) {
285 /* check for DATDNE along with DRRDY as the controller might
286 * set the DATDNE without DRRDY for smaller transfers with
287 * less than FIFO threshold bytes
288 */
289 status_rdy = MMCST0_DRRDY | MMCST0_DATDNE;
290 status_err = MMCST0_TOUTRD | MMCST0_CRCRD;
291 data_buf = data->dest;
292 } else {
293 status_rdy = MMCST0_DXRDY | MMCST0_DATDNE;
294 status_err = MMCST0_CRCWR;
295 }
296
297 /* Wait until all of the blocks are transferred */
298 while (bytes_left) {
299 err = dmmc_check_status(regs, &mmcstatus, status_rdy,
300 status_err);
301 if (err)
302 return err;
303
304 if (data->flags == MMC_DATA_READ) {
305 /*
306 * MMC controller sets the Data receive ready bit
307 * (DRRDY) in MMCST0 even before the entire FIFO is
308 * full. This results in erratic behavior if we start
309 * reading the FIFO soon after DRRDY. Wait for the
310 * FIFO full bit in MMCST1 for proper FIFO clearing.
311 */
312 if (bytes_left > fifo_bytes)
313 dmmc_wait_fifo_status(regs, 0x4a);
Davide Bonfanti3ba36d62012-11-29 01:06:53 +0000314 else if (bytes_left == fifo_bytes) {
Sandeep Paulraj57418d22010-12-20 20:01:21 -0500315 dmmc_wait_fifo_status(regs, 0x40);
Davide Bonfanti3ba36d62012-11-29 01:06:53 +0000316 if (cmd->cmdidx == MMC_CMD_SEND_EXT_CSD)
317 udelay(600);
318 }
Sandeep Paulraj57418d22010-12-20 20:01:21 -0500319
320 for (i = 0; bytes_left && (i < fifo_words); i++) {
321 cmddata = get_val(&regs->mmcdrr);
322 memcpy(data_buf, (char *)&cmddata, 4);
323 data_buf += 4;
324 bytes_left -= 4;
325 }
326 } else {
327 /*
328 * MMC controller sets the Data transmit ready bit
329 * (DXRDY) in MMCST0 even before the entire FIFO is
330 * empty. This results in erratic behavior if we start
331 * writing the FIFO soon after DXRDY. Wait for the
332 * FIFO empty bit in MMCST1 for proper FIFO clearing.
333 */
334 dmmc_wait_fifo_status(regs, MMCST1_FIFOEMP);
335 for (i = 0; bytes_left && (i < fifo_words); i++) {
336 memcpy((char *)&cmddata, data_buf, 4);
337 set_val(&regs->mmcdxr, cmddata);
338 data_buf += 4;
339 bytes_left -= 4;
340 }
341 dmmc_busy_wait(regs);
342 }
343 }
344
345 err = dmmc_check_status(regs, &mmcstatus, MMCST0_DATDNE, status_err);
346 if (err)
347 return err;
348
349 return 0;
350}
351
352/* Initialize Davinci MMC controller */
Adam Forddf6565c2018-08-09 06:15:12 -0500353#if !CONFIG_IS_ENABLED(DM_MMC)
Sandeep Paulraj57418d22010-12-20 20:01:21 -0500354static int dmmc_init(struct mmc *mmc)
355{
356 struct davinci_mmc *host = mmc->priv;
Adam Forddf6565c2018-08-09 06:15:12 -0500357#else
358static int davinci_dm_mmc_init(struct udevice *dev)
359{
360 struct davinci_mmc_priv *host = dev_get_priv(dev);
361#endif
Sandeep Paulraj57418d22010-12-20 20:01:21 -0500362 struct davinci_mmc_regs *regs = host->reg_base;
363
364 /* Clear status registers explicitly - soft reset doesn't clear it
365 * If Uboot is invoked from UBL with SDMMC Support, the status
366 * registers can have uncleared bits
367 */
368 get_val(&regs->mmcst0);
369 get_val(&regs->mmcst1);
370
371 /* Hold software reset */
372 set_bit(&regs->mmcctl, MMCCTL_DATRST);
373 set_bit(&regs->mmcctl, MMCCTL_CMDRST);
374 udelay(10);
375
376 set_val(&regs->mmcclk, 0x0);
377 set_val(&regs->mmctor, 0x1FFF);
378 set_val(&regs->mmctod, 0xFFFF);
379
380 /* Clear software reset */
381 clear_bit(&regs->mmcctl, MMCCTL_DATRST);
382 clear_bit(&regs->mmcctl, MMCCTL_CMDRST);
383
384 udelay(10);
385
386 /* Reset FIFO - Always use the maximum fifo threshold */
387 set_val(&regs->mmcfifoctl, (MMCFIFOCTL_FIFOLEV | MMCFIFOCTL_FIFORST));
388 set_val(&regs->mmcfifoctl, MMCFIFOCTL_FIFOLEV);
389
390 return 0;
391}
392
Masahiro Yamada4aa2ba32017-05-09 20:31:39 +0900393/* Set buswidth or clock as indicated by the MMC framework */
Adam Forddf6565c2018-08-09 06:15:12 -0500394#if !CONFIG_IS_ENABLED(DM_MMC)
Jaehoon Chung07b0b9c2016-12-30 15:30:16 +0900395static int dmmc_set_ios(struct mmc *mmc)
Sandeep Paulraj57418d22010-12-20 20:01:21 -0500396{
397 struct davinci_mmc *host = mmc->priv;
398 struct davinci_mmc_regs *regs = host->reg_base;
Adam Forddf6565c2018-08-09 06:15:12 -0500399#else
400static int davinci_mmc_set_ios(struct udevice *dev)
401{
402 struct mmc *mmc = mmc_get_mmc_dev(dev);
Sandeep Paulraj57418d22010-12-20 20:01:21 -0500403
Adam Forddf6565c2018-08-09 06:15:12 -0500404 struct davinci_mmc_priv *host = dev_get_priv(dev);
405 struct davinci_mmc_regs *regs = host->reg_base;
406#endif
Sandeep Paulraj57418d22010-12-20 20:01:21 -0500407 /* Set the bus width */
408 if (mmc->bus_width == 4)
409 set_bit(&regs->mmcctl, MMCCTL_WIDTH_4_BIT);
410 else
411 clear_bit(&regs->mmcctl, MMCCTL_WIDTH_4_BIT);
412
413 /* Set clock speed */
Adam Forddf6565c2018-08-09 06:15:12 -0500414 if (mmc->clock) {
415#if !CONFIG_IS_ENABLED(DM_MMC)
Sandeep Paulraj57418d22010-12-20 20:01:21 -0500416 dmmc_set_clock(mmc, mmc->clock);
Adam Forddf6565c2018-08-09 06:15:12 -0500417#else
418 davinci_mmc_set_clock(dev, mmc->clock);
419#endif
420 }
Jaehoon Chung07b0b9c2016-12-30 15:30:16 +0900421 return 0;
Sandeep Paulraj57418d22010-12-20 20:01:21 -0500422}
423
Adam Forddf6565c2018-08-09 06:15:12 -0500424#if !CONFIG_IS_ENABLED(DM_MMC)
Pantelis Antoniouab769f22014-02-26 19:28:45 +0200425static const struct mmc_ops dmmc_ops = {
Adam Forddf6565c2018-08-09 06:15:12 -0500426 .send_cmd = dmmc_send_cmd,
427 .set_ios = dmmc_set_ios,
428 .init = dmmc_init,
Pantelis Antoniouab769f22014-02-26 19:28:45 +0200429};
Adam Forddf6565c2018-08-09 06:15:12 -0500430#else
Adam Ford04355de2018-09-03 03:47:52 -0500431
432static int davinci_mmc_getcd(struct udevice *dev)
433{
434 int value = -1;
435#if CONFIG_IS_ENABLED(DM_GPIO)
436 struct davinci_mmc_priv *priv = dev_get_priv(dev);
437 value = dm_gpio_get_value(&priv->cd_gpio);
438#endif
439 /* if no CD return as 1 */
440 if (value < 0)
441 return 1;
442
443 return value;
444}
445
446static int davinci_mmc_getwp(struct udevice *dev)
447{
448 int value = -1;
449#if CONFIG_IS_ENABLED(DM_GPIO)
450 struct davinci_mmc_priv *priv = dev_get_priv(dev);
451
452 value = dm_gpio_get_value(&priv->wp_gpio);
453#endif
454 /* if no WP return as 0 */
455 if (value < 0)
456 return 0;
457
458 return value;
459}
460
Adam Forddf6565c2018-08-09 06:15:12 -0500461static const struct dm_mmc_ops davinci_mmc_ops = {
462 .send_cmd = davinci_mmc_send_cmd,
463 .set_ios = davinci_mmc_set_ios,
Adam Ford04355de2018-09-03 03:47:52 -0500464 .get_cd = davinci_mmc_getcd,
465 .get_wp = davinci_mmc_getwp,
Adam Forddf6565c2018-08-09 06:15:12 -0500466};
467#endif
Pantelis Antoniouab769f22014-02-26 19:28:45 +0200468
Adam Forddf6565c2018-08-09 06:15:12 -0500469#if !CONFIG_IS_ENABLED(DM_MMC)
Sandeep Paulraj57418d22010-12-20 20:01:21 -0500470/* Called from board_mmc_init during startup. Can be called multiple times
Adam Forddf6565c2018-08-09 06:15:12 -0500471* depending on the number of slots available on board and controller
472*/
Sandeep Paulraj57418d22010-12-20 20:01:21 -0500473int davinci_mmc_init(bd_t *bis, struct davinci_mmc *host)
474{
Pantelis Antoniou93bfd612014-03-11 19:34:20 +0200475 host->cfg.name = "davinci";
476 host->cfg.ops = &dmmc_ops;
477 host->cfg.f_min = 200000;
478 host->cfg.f_max = 25000000;
479 host->cfg.voltages = host->voltages;
480 host->cfg.host_caps = host->host_caps;
Sandeep Paulraj57418d22010-12-20 20:01:21 -0500481
Pantelis Antoniou93bfd612014-03-11 19:34:20 +0200482 host->cfg.b_max = DAVINCI_MAX_BLOCKS;
Sandeep Paulraj57418d22010-12-20 20:01:21 -0500483
Pantelis Antoniou93bfd612014-03-11 19:34:20 +0200484 mmc_create(&host->cfg, host);
Sandeep Paulraj57418d22010-12-20 20:01:21 -0500485
486 return 0;
487}
Adam Forddf6565c2018-08-09 06:15:12 -0500488#else
489
490
491static int davinci_mmc_probe(struct udevice *dev)
492{
493 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
494 struct davinci_mmc_plat *plat = dev_get_platdata(dev);
495 struct davinci_mmc_priv *priv = dev_get_priv(dev);
496 struct mmc_config *cfg = &plat->cfg;
497 struct davinci_of_data *data =
498 (struct davinci_of_data *)dev_get_driver_data(dev);
499 cfg->f_min = 200000;
500 cfg->f_max = 25000000;
501 cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34,
502 cfg->host_caps = MMC_MODE_4BIT, /* DA850 supports only 4-bit SD/MMC */
503 cfg->b_max = DAVINCI_MAX_BLOCKS;
504
505 if (data) {
506 cfg->name = data->name;
507 priv->version = data->version;
508 }
509
510 priv->reg_base = (struct davinci_mmc_regs *)dev_read_addr(dev);
511 priv->input_clk = clk_get(DAVINCI_MMCSD_CLKID);
512
Adam Ford04355de2018-09-03 03:47:52 -0500513#if CONFIG_IS_ENABLED(DM_GPIO)
514 /* These GPIOs are optional */
515 gpio_request_by_name(dev, "cd-gpios", 0, &priv->cd_gpio, GPIOD_IS_IN);
516 gpio_request_by_name(dev, "wp-gpios", 0, &priv->wp_gpio, GPIOD_IS_IN);
517#endif
518
Adam Forddf6565c2018-08-09 06:15:12 -0500519 upriv->mmc = &plat->mmc;
520
521 return davinci_dm_mmc_init(dev);
522}
523
524static int davinci_mmc_bind(struct udevice *dev)
525{
526 struct davinci_mmc_plat *plat = dev_get_platdata(dev);
527
528 return mmc_bind(dev, &plat->mmc, &plat->cfg);
529}
530
531
532const struct davinci_of_data davinci_mmc_host_info[] = {
533 {
534 .name = "dm6441-mmc",
535 .version = MMC_CTLR_VERSION_1,
536 },
537 {
538 .name = "da830-mmc",
539 .version = MMC_CTLR_VERSION_2,
540 },
541 {},
542};
543
544static const struct udevice_id davinci_mmc_ids[] = {
545 {
546 .compatible = "ti,dm6441-mmc",
547 .data = (ulong) &davinci_mmc_host_info[MMC_CTLR_VERSION_1]
548 },
549 {
550 .compatible = "ti,da830-mmc",
551 .data = (ulong) &davinci_mmc_host_info[MMC_CTLR_VERSION_2]
552 },
553 {},
554};
555
556U_BOOT_DRIVER(davinci_mmc_drv) = {
557 .name = "davinci_mmc",
558 .id = UCLASS_MMC,
559 .of_match = davinci_mmc_ids,
560#if CONFIG_BLK
561 .bind = davinci_mmc_bind,
562#endif
563 .probe = davinci_mmc_probe,
564 .ops = &davinci_mmc_ops,
565 .platdata_auto_alloc_size = sizeof(struct davinci_mmc_plat),
566 .priv_auto_alloc_size = sizeof(struct davinci_mmc_priv),
567};
568#endif