Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2010 |
| 4 | * Rob Emanuele <rob@emanuele.us> |
| 5 | * Reinhard Meyer, EMK Elektronik <reinhard.meyer@emk-elektronik.de> |
| 6 | * |
| 7 | * Original Driver: |
| 8 | * Copyright (C) 2004-2006 Atmel Corporation |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 9 | */ |
| 10 | |
Tom Rini | abb9a04 | 2024-05-18 20:20:43 -0600 | [diff] [blame] | 11 | #include <common.h> |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 12 | #include <clk.h> |
Simon Glass | 1ab1692 | 2022-07-31 12:28:48 -0600 | [diff] [blame] | 13 | #include <display_options.h> |
Simon Glass | 11c89f3 | 2017-05-17 17:18:03 -0600 | [diff] [blame] | 14 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 15 | #include <log.h> |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 16 | #include <mmc.h> |
| 17 | #include <part.h> |
| 18 | #include <malloc.h> |
| 19 | #include <asm/io.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 20 | #include <linux/delay.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 21 | #include <linux/errno.h> |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 22 | #include <asm/byteorder.h> |
| 23 | #include <asm/arch/clk.h> |
Reinhard Meyer | 7f619cb | 2010-11-03 16:32:56 +0100 | [diff] [blame] | 24 | #include <asm/arch/hardware.h> |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 25 | #include "atmel_mci.h" |
| 26 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 27 | #ifndef CFG_SYS_MMC_CLK_OD |
| 28 | # define CFG_SYS_MMC_CLK_OD 150000 |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 29 | #endif |
| 30 | |
| 31 | #define MMC_DEFAULT_BLKLEN 512 |
| 32 | |
| 33 | #if defined(CONFIG_ATMEL_MCI_PORTB) |
| 34 | # define MCI_BUS 1 |
| 35 | #else |
| 36 | # define MCI_BUS 0 |
| 37 | #endif |
| 38 | |
Wenyou.Yang@microchip.com | edc1dff | 2017-07-26 14:35:42 +0800 | [diff] [blame] | 39 | #ifdef CONFIG_DM_MMC |
| 40 | struct atmel_mci_plat { |
| 41 | struct mmc mmc; |
| 42 | struct mmc_config cfg; |
| 43 | struct atmel_mci *mci; |
| 44 | }; |
| 45 | #endif |
| 46 | |
Marek Vasut | 903fc1d | 2015-10-23 20:46:30 +0200 | [diff] [blame] | 47 | struct atmel_mci_priv { |
Wenyou.Yang@microchip.com | edc1dff | 2017-07-26 14:35:42 +0800 | [diff] [blame] | 48 | #ifndef CONFIG_DM_MMC |
Marek Vasut | 903fc1d | 2015-10-23 20:46:30 +0200 | [diff] [blame] | 49 | struct mmc_config cfg; |
| 50 | struct atmel_mci *mci; |
Wenyou.Yang@microchip.com | edc1dff | 2017-07-26 14:35:42 +0800 | [diff] [blame] | 51 | #endif |
Marek Vasut | 0b7d54e | 2015-10-23 20:46:31 +0200 | [diff] [blame] | 52 | unsigned int initialized:1; |
Gregory CLEMENT | 31f8a00 | 2015-11-05 20:58:30 +0100 | [diff] [blame] | 53 | unsigned int curr_clk; |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 54 | #ifdef CONFIG_DM_MMC |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 55 | ulong bus_clk_rate; |
| 56 | #endif |
Marek Vasut | 903fc1d | 2015-10-23 20:46:30 +0200 | [diff] [blame] | 57 | }; |
| 58 | |
Bo Shen | 644b476 | 2013-04-26 00:27:06 +0000 | [diff] [blame] | 59 | /* Read Atmel MCI IP version */ |
| 60 | static unsigned int atmel_mci_get_version(struct atmel_mci *mci) |
| 61 | { |
| 62 | return readl(&mci->version) & 0x00000fff; |
| 63 | } |
| 64 | |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 65 | /* |
| 66 | * Print command and status: |
| 67 | * |
| 68 | * - always when DEBUG is defined |
| 69 | * - on command errors |
| 70 | */ |
| 71 | static void dump_cmd(u32 cmdr, u32 arg, u32 status, const char* msg) |
| 72 | { |
Marek Vasut | 34524b1 | 2015-10-23 20:46:28 +0200 | [diff] [blame] | 73 | debug("gen_atmel_mci: CMDR %08x (%2u) ARGR %08x (SR: %08x) %s\n", |
| 74 | cmdr, cmdr & 0x3F, arg, status, msg); |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 75 | } |
| 76 | |
Jean-Jacques Hiblot | dcfb625 | 2018-01-04 15:23:29 +0100 | [diff] [blame] | 77 | static inline void mci_set_blklen(atmel_mci_t *mci, int blklen) |
| 78 | { |
| 79 | unsigned int version = atmel_mci_get_version(mci); |
| 80 | |
| 81 | blklen &= 0xfffc; |
| 82 | |
| 83 | /* MCI IP version >= 0x200 has blkr */ |
| 84 | if (version >= 0x200) |
| 85 | writel(MMCI_BFINS(BLKLEN, blklen, readl(&mci->blkr)), |
| 86 | &mci->blkr); |
| 87 | else |
| 88 | writel(MMCI_BFINS(BLKLEN, blklen, readl(&mci->mr)), &mci->mr); |
| 89 | } |
| 90 | |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 91 | /* Setup for MCI Clock and Block Size */ |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 92 | #ifdef CONFIG_DM_MMC |
Wenyou.Yang@microchip.com | edc1dff | 2017-07-26 14:35:42 +0800 | [diff] [blame] | 93 | static void mci_set_mode(struct udevice *dev, u32 hz, u32 blklen) |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 94 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 95 | struct atmel_mci_plat *plat = dev_get_plat(dev); |
Wenyou.Yang@microchip.com | edc1dff | 2017-07-26 14:35:42 +0800 | [diff] [blame] | 96 | struct atmel_mci_priv *priv = dev_get_priv(dev); |
| 97 | struct mmc *mmc = &plat->mmc; |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 98 | u32 bus_hz = priv->bus_clk_rate; |
Wenyou.Yang@microchip.com | edc1dff | 2017-07-26 14:35:42 +0800 | [diff] [blame] | 99 | atmel_mci_t *mci = plat->mci; |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 100 | #else |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 101 | static void mci_set_mode(struct mmc *mmc, u32 hz, u32 blklen) |
| 102 | { |
Marek Vasut | 903fc1d | 2015-10-23 20:46:30 +0200 | [diff] [blame] | 103 | struct atmel_mci_priv *priv = mmc->priv; |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 104 | u32 bus_hz = get_mci_clk_rate(); |
Wenyou.Yang@microchip.com | edc1dff | 2017-07-26 14:35:42 +0800 | [diff] [blame] | 105 | atmel_mci_t *mci = priv->mci; |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 106 | #endif |
| 107 | |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 108 | u32 clkdiv = 255; |
Bo Shen | 02d7728 | 2014-07-31 14:39:30 +0800 | [diff] [blame] | 109 | unsigned int version = atmel_mci_get_version(mci); |
| 110 | u32 clkodd = 0; |
| 111 | u32 mr; |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 112 | |
| 113 | debug("mci: bus_hz is %u, setting clock %u Hz, block size %u\n", |
| 114 | bus_hz, hz, blklen); |
| 115 | if (hz > 0) { |
Bo Shen | 02d7728 | 2014-07-31 14:39:30 +0800 | [diff] [blame] | 116 | if (version >= 0x500) { |
| 117 | clkdiv = DIV_ROUND_UP(bus_hz, hz) - 2; |
| 118 | if (clkdiv > 511) |
| 119 | clkdiv = 511; |
| 120 | |
| 121 | clkodd = clkdiv & 1; |
| 122 | clkdiv >>= 1; |
| 123 | |
Marek Vasut | 34524b1 | 2015-10-23 20:46:28 +0200 | [diff] [blame] | 124 | debug("mci: setting clock %u Hz, block size %u\n", |
| 125 | bus_hz / (clkdiv * 2 + clkodd + 2), blklen); |
Bo Shen | 02d7728 | 2014-07-31 14:39:30 +0800 | [diff] [blame] | 126 | } else { |
| 127 | /* find clkdiv yielding a rate <= than requested */ |
| 128 | for (clkdiv = 0; clkdiv < 255; clkdiv++) { |
| 129 | if ((bus_hz / (clkdiv + 1) / 2) <= hz) |
| 130 | break; |
| 131 | } |
Marek Vasut | 34524b1 | 2015-10-23 20:46:28 +0200 | [diff] [blame] | 132 | debug("mci: setting clock %u Hz, block size %u\n", |
| 133 | (bus_hz / (clkdiv + 1)) / 2, blklen); |
Bo Shen | 02d7728 | 2014-07-31 14:39:30 +0800 | [diff] [blame] | 134 | |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 135 | } |
| 136 | } |
Gregory CLEMENT | 31f8a00 | 2015-11-05 20:58:30 +0100 | [diff] [blame] | 137 | if (version >= 0x500) |
| 138 | priv->curr_clk = bus_hz / (clkdiv * 2 + clkodd + 2); |
| 139 | else |
| 140 | priv->curr_clk = (bus_hz / (clkdiv + 1)) / 2; |
Bo Shen | 02d7728 | 2014-07-31 14:39:30 +0800 | [diff] [blame] | 141 | |
| 142 | mr = MMCI_BF(CLKDIV, clkdiv); |
| 143 | |
| 144 | /* MCI IP version >= 0x200 has R/WPROOF */ |
| 145 | if (version >= 0x200) |
| 146 | mr |= MMCI_BIT(RDPROOF) | MMCI_BIT(WRPROOF); |
| 147 | |
Wu, Josh | d1e486b | 2012-09-13 22:22:04 +0000 | [diff] [blame] | 148 | /* |
Bo Shen | 02d7728 | 2014-07-31 14:39:30 +0800 | [diff] [blame] | 149 | * MCI IP version >= 0x500 use bit 16 as clkodd. |
| 150 | * MCI IP version < 0x500 use upper 16 bits for blklen. |
Wu, Josh | d1e486b | 2012-09-13 22:22:04 +0000 | [diff] [blame] | 151 | */ |
Bo Shen | 02d7728 | 2014-07-31 14:39:30 +0800 | [diff] [blame] | 152 | if (version >= 0x500) |
| 153 | mr |= MMCI_BF(CLKODD, clkodd); |
Bo Shen | 02d7728 | 2014-07-31 14:39:30 +0800 | [diff] [blame] | 154 | |
| 155 | writel(mr, &mci->mr); |
| 156 | |
Jean-Jacques Hiblot | dcfb625 | 2018-01-04 15:23:29 +0100 | [diff] [blame] | 157 | mci_set_blklen(mci, blklen); |
Bo Shen | 02d7728 | 2014-07-31 14:39:30 +0800 | [diff] [blame] | 158 | |
Bo Shen | 1dc856d | 2014-07-31 14:39:32 +0800 | [diff] [blame] | 159 | if (mmc->card_caps & mmc->cfg->host_caps & MMC_MODE_HS) |
| 160 | writel(MMCI_BIT(HSMODE), &mci->cfg); |
| 161 | |
Marek Vasut | 0b7d54e | 2015-10-23 20:46:31 +0200 | [diff] [blame] | 162 | priv->initialized = 1; |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | /* Return the CMDR with flags for a given command and data packet */ |
| 166 | static u32 mci_encode_cmd( |
| 167 | struct mmc_cmd *cmd, struct mmc_data *data, u32* error_flags) |
| 168 | { |
| 169 | u32 cmdr = 0; |
| 170 | |
| 171 | /* Default Flags for Errors */ |
| 172 | *error_flags |= (MMCI_BIT(DTOE) | MMCI_BIT(RDIRE) | MMCI_BIT(RENDE) | |
| 173 | MMCI_BIT(RINDE) | MMCI_BIT(RTOE)); |
| 174 | |
| 175 | /* Default Flags for the Command */ |
| 176 | cmdr |= MMCI_BIT(MAXLAT); |
| 177 | |
| 178 | if (data) { |
| 179 | cmdr |= MMCI_BF(TRCMD, 1); |
| 180 | if (data->blocks > 1) |
| 181 | cmdr |= MMCI_BF(TRTYP, 1); |
| 182 | if (data->flags & MMC_DATA_READ) |
| 183 | cmdr |= MMCI_BIT(TRDIR); |
| 184 | } |
| 185 | |
| 186 | if (cmd->resp_type & MMC_RSP_CRC) |
| 187 | *error_flags |= MMCI_BIT(RCRCE); |
| 188 | if (cmd->resp_type & MMC_RSP_136) |
| 189 | cmdr |= MMCI_BF(RSPTYP, 2); |
| 190 | else if (cmd->resp_type & MMC_RSP_BUSY) |
| 191 | cmdr |= MMCI_BF(RSPTYP, 3); |
| 192 | else if (cmd->resp_type & MMC_RSP_PRESENT) |
| 193 | cmdr |= MMCI_BF(RSPTYP, 1); |
| 194 | |
| 195 | return cmdr | MMCI_BF(CMDNB, cmd->cmdidx); |
| 196 | } |
| 197 | |
| 198 | /* Entered into function pointer in mci_send_cmd */ |
| 199 | static u32 mci_data_read(atmel_mci_t *mci, u32* data, u32 error_flags) |
| 200 | { |
| 201 | u32 status; |
| 202 | |
| 203 | do { |
| 204 | status = readl(&mci->sr); |
| 205 | if (status & (error_flags | MMCI_BIT(OVRE))) |
| 206 | goto io_fail; |
| 207 | } while (!(status & MMCI_BIT(RXRDY))); |
| 208 | |
| 209 | if (status & MMCI_BIT(RXRDY)) { |
| 210 | *data = readl(&mci->rdr); |
| 211 | status = 0; |
| 212 | } |
| 213 | io_fail: |
| 214 | return status; |
| 215 | } |
| 216 | |
| 217 | /* Entered into function pointer in mci_send_cmd */ |
| 218 | static u32 mci_data_write(atmel_mci_t *mci, u32* data, u32 error_flags) |
| 219 | { |
| 220 | u32 status; |
| 221 | |
| 222 | do { |
| 223 | status = readl(&mci->sr); |
| 224 | if (status & (error_flags | MMCI_BIT(UNRE))) |
| 225 | goto io_fail; |
| 226 | } while (!(status & MMCI_BIT(TXRDY))); |
| 227 | |
| 228 | if (status & MMCI_BIT(TXRDY)) { |
| 229 | writel(*data, &mci->tdr); |
| 230 | status = 0; |
| 231 | } |
| 232 | io_fail: |
| 233 | return status; |
| 234 | } |
| 235 | |
| 236 | /* |
| 237 | * Entered into mmc structure during driver init |
| 238 | * |
| 239 | * Sends a command out on the bus and deals with the block data. |
| 240 | * Takes the mmc pointer, a command pointer, and an optional data pointer. |
| 241 | */ |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 242 | #ifdef CONFIG_DM_MMC |
| 243 | static int atmel_mci_send_cmd(struct udevice *dev, struct mmc_cmd *cmd, |
| 244 | struct mmc_data *data) |
| 245 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 246 | struct atmel_mci_plat *plat = dev_get_plat(dev); |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 247 | struct atmel_mci_priv *priv = dev_get_priv(dev); |
Wenyou.Yang@microchip.com | edc1dff | 2017-07-26 14:35:42 +0800 | [diff] [blame] | 248 | atmel_mci_t *mci = plat->mci; |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 249 | #else |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 250 | static int |
| 251 | mci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data) |
| 252 | { |
Marek Vasut | 903fc1d | 2015-10-23 20:46:30 +0200 | [diff] [blame] | 253 | struct atmel_mci_priv *priv = mmc->priv; |
| 254 | atmel_mci_t *mci = priv->mci; |
Wenyou.Yang@microchip.com | edc1dff | 2017-07-26 14:35:42 +0800 | [diff] [blame] | 255 | #endif |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 256 | u32 cmdr; |
| 257 | u32 error_flags = 0; |
| 258 | u32 status; |
| 259 | |
Marek Vasut | 0b7d54e | 2015-10-23 20:46:31 +0200 | [diff] [blame] | 260 | if (!priv->initialized) { |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 261 | puts ("MCI not initialized!\n"); |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 262 | return -ECOMM; |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | /* Figure out the transfer arguments */ |
| 266 | cmdr = mci_encode_cmd(cmd, data, &error_flags); |
| 267 | |
Jean-Jacques Hiblot | dcfb625 | 2018-01-04 15:23:29 +0100 | [diff] [blame] | 268 | mci_set_blklen(mci, data->blocksize); |
| 269 | |
Wu, Josh | d1e486b | 2012-09-13 22:22:04 +0000 | [diff] [blame] | 270 | /* For multi blocks read/write, set the block register */ |
| 271 | if ((cmd->cmdidx == MMC_CMD_READ_MULTIPLE_BLOCK) |
| 272 | || (cmd->cmdidx == MMC_CMD_WRITE_MULTIPLE_BLOCK)) |
Jean-Jacques Hiblot | dcfb625 | 2018-01-04 15:23:29 +0100 | [diff] [blame] | 273 | writel(data->blocks | MMCI_BF(BLKLEN, data->blocksize), |
| 274 | &mci->blkr); |
Wu, Josh | d1e486b | 2012-09-13 22:22:04 +0000 | [diff] [blame] | 275 | |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 276 | /* Send the command */ |
| 277 | writel(cmd->cmdarg, &mci->argr); |
| 278 | writel(cmdr, &mci->cmdr); |
| 279 | |
| 280 | #ifdef DEBUG |
| 281 | dump_cmd(cmdr, cmd->cmdarg, 0, "DEBUG"); |
| 282 | #endif |
| 283 | |
| 284 | /* Wait for the command to complete */ |
| 285 | while (!((status = readl(&mci->sr)) & MMCI_BIT(CMDRDY))); |
| 286 | |
Bo Shen | 03a743f | 2013-04-26 00:27:07 +0000 | [diff] [blame] | 287 | if ((status & error_flags) & MMCI_BIT(RTOE)) { |
| 288 | dump_cmd(cmdr, cmd->cmdarg, status, "Command Time Out"); |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 289 | return -ETIMEDOUT; |
Bo Shen | 03a743f | 2013-04-26 00:27:07 +0000 | [diff] [blame] | 290 | } else if (status & error_flags) { |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 291 | dump_cmd(cmdr, cmd->cmdarg, status, "Command Failed"); |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 292 | return -ECOMM; |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | /* Copy the response to the response buffer */ |
| 296 | if (cmd->resp_type & MMC_RSP_136) { |
| 297 | cmd->response[0] = readl(&mci->rspr); |
| 298 | cmd->response[1] = readl(&mci->rspr1); |
| 299 | cmd->response[2] = readl(&mci->rspr2); |
| 300 | cmd->response[3] = readl(&mci->rspr3); |
| 301 | } else |
| 302 | cmd->response[0] = readl(&mci->rspr); |
| 303 | |
| 304 | /* transfer all of the blocks */ |
| 305 | if (data) { |
| 306 | u32 word_count, block_count; |
| 307 | u32* ioptr; |
Jean-Jacques Hiblot | dcfb625 | 2018-01-04 15:23:29 +0100 | [diff] [blame] | 308 | u32 i; |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 309 | u32 (*mci_data_op) |
| 310 | (atmel_mci_t *mci, u32* data, u32 error_flags); |
| 311 | |
| 312 | if (data->flags & MMC_DATA_READ) { |
| 313 | mci_data_op = mci_data_read; |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 314 | ioptr = (u32*)data->dest; |
| 315 | } else { |
| 316 | mci_data_op = mci_data_write; |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 317 | ioptr = (u32*)data->src; |
| 318 | } |
| 319 | |
| 320 | status = 0; |
| 321 | for (block_count = 0; |
| 322 | block_count < data->blocks && !status; |
| 323 | block_count++) { |
| 324 | word_count = 0; |
| 325 | do { |
| 326 | status = mci_data_op(mci, ioptr, error_flags); |
| 327 | word_count++; |
| 328 | ioptr++; |
| 329 | } while (!status && word_count < (data->blocksize/4)); |
| 330 | #ifdef DEBUG |
| 331 | if (data->flags & MMC_DATA_READ) |
| 332 | { |
Wu, Josh | 6bcb562 | 2014-05-07 17:06:08 +0800 | [diff] [blame] | 333 | u32 cnt = word_count * 4; |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 334 | printf("Read Data:\n"); |
Wu, Josh | 6bcb562 | 2014-05-07 17:06:08 +0800 | [diff] [blame] | 335 | print_buffer(0, data->dest + cnt * block_count, |
| 336 | 1, cnt, 0); |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 337 | } |
| 338 | #endif |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 339 | if (status) { |
| 340 | dump_cmd(cmdr, cmd->cmdarg, status, |
| 341 | "Data Transfer Failed"); |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 342 | return -ECOMM; |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 343 | } |
| 344 | } |
| 345 | |
| 346 | /* Wait for Transfer End */ |
| 347 | i = 0; |
| 348 | do { |
| 349 | status = readl(&mci->sr); |
| 350 | |
| 351 | if (status & error_flags) { |
| 352 | dump_cmd(cmdr, cmd->cmdarg, status, |
| 353 | "DTIP Wait Failed"); |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 354 | return -ECOMM; |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 355 | } |
| 356 | i++; |
| 357 | } while ((status & MMCI_BIT(DTIP)) && i < 10000); |
| 358 | if (status & MMCI_BIT(DTIP)) { |
| 359 | dump_cmd(cmdr, cmd->cmdarg, status, |
| 360 | "XFER DTIP never unset, ignoring"); |
| 361 | } |
| 362 | } |
| 363 | |
Gregory CLEMENT | 31f8a00 | 2015-11-05 20:58:30 +0100 | [diff] [blame] | 364 | /* |
| 365 | * After the switch command, wait for 8 clocks before the next |
| 366 | * command |
| 367 | */ |
| 368 | if (cmd->cmdidx == MMC_CMD_SWITCH) |
| 369 | udelay(8*1000000 / priv->curr_clk); /* 8 clk in us */ |
| 370 | |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 371 | return 0; |
| 372 | } |
| 373 | |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 374 | #ifdef CONFIG_DM_MMC |
| 375 | static int atmel_mci_set_ios(struct udevice *dev) |
| 376 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 377 | struct atmel_mci_plat *plat = dev_get_plat(dev); |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 378 | struct mmc *mmc = mmc_get_mmc_dev(dev); |
Wenyou.Yang@microchip.com | edc1dff | 2017-07-26 14:35:42 +0800 | [diff] [blame] | 379 | atmel_mci_t *mci = plat->mci; |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 380 | #else |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 381 | /* Entered into mmc structure during driver init */ |
Jaehoon Chung | b6cd1d3 | 2016-12-30 15:30:16 +0900 | [diff] [blame] | 382 | static int mci_set_ios(struct mmc *mmc) |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 383 | { |
Marek Vasut | 903fc1d | 2015-10-23 20:46:30 +0200 | [diff] [blame] | 384 | struct atmel_mci_priv *priv = mmc->priv; |
| 385 | atmel_mci_t *mci = priv->mci; |
Wenyou.Yang@microchip.com | edc1dff | 2017-07-26 14:35:42 +0800 | [diff] [blame] | 386 | #endif |
Bo Shen | 644b476 | 2013-04-26 00:27:06 +0000 | [diff] [blame] | 387 | int bus_width = mmc->bus_width; |
| 388 | unsigned int version = atmel_mci_get_version(mci); |
| 389 | int busw; |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 390 | |
| 391 | /* Set the clock speed */ |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 392 | #ifdef CONFIG_DM_MMC |
Wenyou.Yang@microchip.com | edc1dff | 2017-07-26 14:35:42 +0800 | [diff] [blame] | 393 | mci_set_mode(dev, mmc->clock, MMC_DEFAULT_BLKLEN); |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 394 | #else |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 395 | mci_set_mode(mmc, mmc->clock, MMC_DEFAULT_BLKLEN); |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 396 | #endif |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 397 | |
| 398 | /* |
| 399 | * set the bus width and select slot for this interface |
| 400 | * there is no capability for multiple slots on the same interface yet |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 401 | */ |
Bo Shen | 644b476 | 2013-04-26 00:27:06 +0000 | [diff] [blame] | 402 | if ((version & 0xf00) >= 0x300) { |
| 403 | switch (bus_width) { |
| 404 | case 8: |
| 405 | busw = 3; |
| 406 | break; |
| 407 | case 4: |
| 408 | busw = 2; |
| 409 | break; |
| 410 | default: |
| 411 | busw = 0; |
| 412 | break; |
| 413 | } |
| 414 | |
| 415 | writel(busw << 6 | MMCI_BF(SCDSEL, MCI_BUS), &mci->sdcr); |
| 416 | } else { |
| 417 | busw = (bus_width == 4) ? 1 : 0; |
| 418 | |
| 419 | writel(busw << 7 | MMCI_BF(SCDSEL, MCI_BUS), &mci->sdcr); |
| 420 | } |
Jaehoon Chung | b6cd1d3 | 2016-12-30 15:30:16 +0900 | [diff] [blame] | 421 | |
| 422 | return 0; |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 423 | } |
| 424 | |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 425 | #ifdef CONFIG_DM_MMC |
Wenyou.Yang@microchip.com | edc1dff | 2017-07-26 14:35:42 +0800 | [diff] [blame] | 426 | static int atmel_mci_hw_init(struct udevice *dev) |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 427 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 428 | struct atmel_mci_plat *plat = dev_get_plat(dev); |
Wenyou.Yang@microchip.com | edc1dff | 2017-07-26 14:35:42 +0800 | [diff] [blame] | 429 | atmel_mci_t *mci = plat->mci; |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 430 | #else |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 431 | /* Entered into mmc structure during driver init */ |
| 432 | static int mci_init(struct mmc *mmc) |
| 433 | { |
Marek Vasut | 903fc1d | 2015-10-23 20:46:30 +0200 | [diff] [blame] | 434 | struct atmel_mci_priv *priv = mmc->priv; |
| 435 | atmel_mci_t *mci = priv->mci; |
Wenyou.Yang@microchip.com | edc1dff | 2017-07-26 14:35:42 +0800 | [diff] [blame] | 436 | #endif |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 437 | |
| 438 | /* Initialize controller */ |
| 439 | writel(MMCI_BIT(SWRST), &mci->cr); /* soft reset */ |
| 440 | writel(MMCI_BIT(PWSDIS), &mci->cr); /* disable power save */ |
| 441 | writel(MMCI_BIT(MCIEN), &mci->cr); /* enable mci */ |
Reinhard Meyer | f267557 | 2010-11-16 09:24:41 +0100 | [diff] [blame] | 442 | writel(MMCI_BF(SCDSEL, MCI_BUS), &mci->sdcr); /* select port */ |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 443 | |
Wu, Josh | ec35c91 | 2012-09-13 22:22:06 +0000 | [diff] [blame] | 444 | /* This delay can be optimized, but stick with max value */ |
| 445 | writel(0x7f, &mci->dtor); |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 446 | /* Disable Interrupts */ |
| 447 | writel(~0UL, &mci->idr); |
| 448 | |
| 449 | /* Set default clocks and blocklen */ |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 450 | #ifdef CONFIG_DM_MMC |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 451 | mci_set_mode(dev, CFG_SYS_MMC_CLK_OD, MMC_DEFAULT_BLKLEN); |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 452 | #else |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 453 | mci_set_mode(mmc, CFG_SYS_MMC_CLK_OD, MMC_DEFAULT_BLKLEN); |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 454 | #endif |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 455 | |
| 456 | return 0; |
| 457 | } |
| 458 | |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 459 | #ifndef CONFIG_DM_MMC |
Pantelis Antoniou | c9e7591 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 460 | static const struct mmc_ops atmel_mci_ops = { |
| 461 | .send_cmd = mci_send_cmd, |
| 462 | .set_ios = mci_set_ios, |
| 463 | .init = mci_init, |
| 464 | }; |
| 465 | |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 466 | /* |
| 467 | * This is the only exported function |
| 468 | * |
| 469 | * Call it with the MCI register base address |
| 470 | */ |
| 471 | int atmel_mci_init(void *regs) |
| 472 | { |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 473 | struct mmc *mmc; |
| 474 | struct mmc_config *cfg; |
Marek Vasut | 903fc1d | 2015-10-23 20:46:30 +0200 | [diff] [blame] | 475 | struct atmel_mci_priv *priv; |
Bo Shen | 644b476 | 2013-04-26 00:27:06 +0000 | [diff] [blame] | 476 | unsigned int version; |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 477 | |
Marek Vasut | 903fc1d | 2015-10-23 20:46:30 +0200 | [diff] [blame] | 478 | priv = calloc(1, sizeof(*priv)); |
| 479 | if (!priv) |
| 480 | return -ENOMEM; |
Bo Shen | 644b476 | 2013-04-26 00:27:06 +0000 | [diff] [blame] | 481 | |
Marek Vasut | 903fc1d | 2015-10-23 20:46:30 +0200 | [diff] [blame] | 482 | cfg = &priv->cfg; |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 483 | |
| 484 | cfg->name = "mci"; |
| 485 | cfg->ops = &atmel_mci_ops; |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 486 | |
Marek Vasut | 903fc1d | 2015-10-23 20:46:30 +0200 | [diff] [blame] | 487 | priv->mci = (struct atmel_mci *)regs; |
Marek Vasut | 0b7d54e | 2015-10-23 20:46:31 +0200 | [diff] [blame] | 488 | priv->initialized = 0; |
Marek Vasut | 903fc1d | 2015-10-23 20:46:30 +0200 | [diff] [blame] | 489 | |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 490 | /* need to be able to pass these in on a board by board basis */ |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 491 | cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34; |
Marek Vasut | 903fc1d | 2015-10-23 20:46:30 +0200 | [diff] [blame] | 492 | version = atmel_mci_get_version(priv->mci); |
Bo Shen | 1dc856d | 2014-07-31 14:39:32 +0800 | [diff] [blame] | 493 | if ((version & 0xf00) >= 0x300) { |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 494 | cfg->host_caps = MMC_MODE_8BIT; |
Bo Shen | 1dc856d | 2014-07-31 14:39:32 +0800 | [diff] [blame] | 495 | cfg->host_caps |= MMC_MODE_HS | MMC_MODE_HS_52MHz; |
| 496 | } |
Bo Shen | 644b476 | 2013-04-26 00:27:06 +0000 | [diff] [blame] | 497 | |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 498 | cfg->host_caps |= MMC_MODE_4BIT; |
Bo Shen | 644b476 | 2013-04-26 00:27:06 +0000 | [diff] [blame] | 499 | |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 500 | /* |
| 501 | * min and max frequencies determined by |
| 502 | * max and min of clock divider |
| 503 | */ |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 504 | cfg->f_min = get_mci_clk_rate() / (2*256); |
| 505 | cfg->f_max = get_mci_clk_rate() / (2*1); |
| 506 | |
| 507 | cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT; |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 508 | |
Marek Vasut | 903fc1d | 2015-10-23 20:46:30 +0200 | [diff] [blame] | 509 | mmc = mmc_create(cfg, priv); |
John Rigby | f2f4366 | 2011-04-18 05:50:08 +0000 | [diff] [blame] | 510 | |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 511 | if (mmc == NULL) { |
Marek Vasut | 903fc1d | 2015-10-23 20:46:30 +0200 | [diff] [blame] | 512 | free(priv); |
| 513 | return -ENODEV; |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 514 | } |
Marek Vasut | 903fc1d | 2015-10-23 20:46:30 +0200 | [diff] [blame] | 515 | /* NOTE: possibly leaking the priv structure */ |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 516 | |
| 517 | return 0; |
| 518 | } |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 519 | #endif |
| 520 | |
| 521 | #ifdef CONFIG_DM_MMC |
| 522 | static const struct dm_mmc_ops atmel_mci_mmc_ops = { |
| 523 | .send_cmd = atmel_mci_send_cmd, |
| 524 | .set_ios = atmel_mci_set_ios, |
| 525 | }; |
| 526 | |
Wenyou.Yang@microchip.com | edc1dff | 2017-07-26 14:35:42 +0800 | [diff] [blame] | 527 | static void atmel_mci_setup_cfg(struct udevice *dev) |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 528 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 529 | struct atmel_mci_plat *plat = dev_get_plat(dev); |
Wenyou.Yang@microchip.com | edc1dff | 2017-07-26 14:35:42 +0800 | [diff] [blame] | 530 | struct atmel_mci_priv *priv = dev_get_priv(dev); |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 531 | struct mmc_config *cfg; |
| 532 | u32 version; |
| 533 | |
Wenyou.Yang@microchip.com | edc1dff | 2017-07-26 14:35:42 +0800 | [diff] [blame] | 534 | cfg = &plat->cfg; |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 535 | cfg->name = "Atmel mci"; |
| 536 | cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34; |
| 537 | |
| 538 | /* |
| 539 | * If the version is above 3.0, the capabilities of the 8-bit |
| 540 | * bus width and high speed are supported. |
| 541 | */ |
Wenyou.Yang@microchip.com | edc1dff | 2017-07-26 14:35:42 +0800 | [diff] [blame] | 542 | version = atmel_mci_get_version(plat->mci); |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 543 | if ((version & 0xf00) >= 0x300) { |
| 544 | cfg->host_caps = MMC_MODE_8BIT | |
| 545 | MMC_MODE_HS | MMC_MODE_HS_52MHz; |
| 546 | } |
| 547 | |
| 548 | cfg->host_caps |= MMC_MODE_4BIT; |
| 549 | cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT; |
| 550 | cfg->f_min = priv->bus_clk_rate / (2 * 256); |
| 551 | cfg->f_max = priv->bus_clk_rate / 2; |
| 552 | } |
| 553 | |
| 554 | static int atmel_mci_enable_clk(struct udevice *dev) |
| 555 | { |
| 556 | struct atmel_mci_priv *priv = dev_get_priv(dev); |
| 557 | struct clk clk; |
| 558 | ulong clk_rate; |
| 559 | int ret = 0; |
| 560 | |
| 561 | ret = clk_get_by_index(dev, 0, &clk); |
Sean Anderson | d318eb3 | 2023-12-16 14:38:42 -0500 | [diff] [blame] | 562 | if (ret) |
| 563 | return -EINVAL; |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 564 | |
| 565 | ret = clk_enable(&clk); |
| 566 | if (ret) |
Sean Anderson | d318eb3 | 2023-12-16 14:38:42 -0500 | [diff] [blame] | 567 | return ret; |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 568 | |
| 569 | clk_rate = clk_get_rate(&clk); |
Sean Anderson | d318eb3 | 2023-12-16 14:38:42 -0500 | [diff] [blame] | 570 | if (!clk_rate) |
| 571 | return -EINVAL; |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 572 | |
| 573 | priv->bus_clk_rate = clk_rate; |
| 574 | |
Sean Anderson | d318eb3 | 2023-12-16 14:38:42 -0500 | [diff] [blame] | 575 | return 0; |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | static int atmel_mci_probe(struct udevice *dev) |
| 579 | { |
| 580 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 581 | struct atmel_mci_plat *plat = dev_get_plat(dev); |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 582 | struct mmc *mmc; |
| 583 | int ret; |
| 584 | |
| 585 | ret = atmel_mci_enable_clk(dev); |
| 586 | if (ret) |
| 587 | return ret; |
| 588 | |
Masahiro Yamada | 32822d0 | 2020-08-04 14:14:43 +0900 | [diff] [blame] | 589 | plat->mci = dev_read_addr_ptr(dev); |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 590 | |
Wenyou.Yang@microchip.com | edc1dff | 2017-07-26 14:35:42 +0800 | [diff] [blame] | 591 | atmel_mci_setup_cfg(dev); |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 592 | |
Wenyou.Yang@microchip.com | edc1dff | 2017-07-26 14:35:42 +0800 | [diff] [blame] | 593 | mmc = &plat->mmc; |
| 594 | mmc->cfg = &plat->cfg; |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 595 | mmc->dev = dev; |
| 596 | upriv->mmc = mmc; |
| 597 | |
Wenyou.Yang@microchip.com | edc1dff | 2017-07-26 14:35:42 +0800 | [diff] [blame] | 598 | atmel_mci_hw_init(dev); |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 599 | |
| 600 | return 0; |
| 601 | } |
| 602 | |
| 603 | static int atmel_mci_bind(struct udevice *dev) |
| 604 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 605 | struct atmel_mci_plat *plat = dev_get_plat(dev); |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 606 | |
Wenyou.Yang@microchip.com | edc1dff | 2017-07-26 14:35:42 +0800 | [diff] [blame] | 607 | return mmc_bind(dev, &plat->mmc, &plat->cfg); |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | static const struct udevice_id atmel_mci_ids[] = { |
| 611 | { .compatible = "atmel,hsmci" }, |
| 612 | { } |
| 613 | }; |
| 614 | |
| 615 | U_BOOT_DRIVER(atmel_mci) = { |
| 616 | .name = "atmel-mci", |
| 617 | .id = UCLASS_MMC, |
| 618 | .of_match = atmel_mci_ids, |
| 619 | .bind = atmel_mci_bind, |
| 620 | .probe = atmel_mci_probe, |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 621 | .plat_auto = sizeof(struct atmel_mci_plat), |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 622 | .priv_auto = sizeof(struct atmel_mci_priv), |
Wenyou Yang | 7a7a64c | 2017-04-13 10:29:22 +0800 | [diff] [blame] | 623 | .ops = &atmel_mci_mmc_ops, |
| 624 | }; |
| 625 | #endif |