Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2011, Marvell Semiconductor Inc. |
| 4 | * Lei Wen <leiwen@marvell.com> |
| 5 | * |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 6 | * Back ported to the 8xx platform (from the 8260 platform) by |
| 7 | * Murray.Jensen@cmst.csiro.au, 27-Jan-01. |
| 8 | */ |
| 9 | |
| 10 | #include <common.h> |
Simon Glass | 1eb69ae | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 11 | #include <cpu_func.h> |
Faiz Abbas | 3d29636 | 2019-06-11 00:43:34 +0530 | [diff] [blame] | 12 | #include <dm.h> |
Simon Glass | 2a80909 | 2016-06-12 23:30:27 -0600 | [diff] [blame] | 13 | #include <errno.h> |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 14 | #include <malloc.h> |
| 15 | #include <mmc.h> |
| 16 | #include <sdhci.h> |
T Karthik Reddy | da18c62 | 2019-06-25 13:39:04 +0200 | [diff] [blame] | 17 | #include <dm.h> |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 18 | |
Stefan Roese | 492d322 | 2015-06-29 14:58:09 +0200 | [diff] [blame] | 19 | #if defined(CONFIG_FIXED_SDHCI_ALIGNED_BUFFER) |
| 20 | void *aligned_buffer = (void *)CONFIG_FIXED_SDHCI_ALIGNED_BUFFER; |
| 21 | #else |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 22 | void *aligned_buffer; |
Stefan Roese | 492d322 | 2015-06-29 14:58:09 +0200 | [diff] [blame] | 23 | #endif |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 24 | |
| 25 | static void sdhci_reset(struct sdhci_host *host, u8 mask) |
| 26 | { |
| 27 | unsigned long timeout; |
| 28 | |
| 29 | /* Wait max 100 ms */ |
| 30 | timeout = 100; |
| 31 | sdhci_writeb(host, mask, SDHCI_SOFTWARE_RESET); |
| 32 | while (sdhci_readb(host, SDHCI_SOFTWARE_RESET) & mask) { |
| 33 | if (timeout == 0) { |
Darwin Rambo | 30e6d97 | 2013-12-19 15:13:25 -0800 | [diff] [blame] | 34 | printf("%s: Reset 0x%x never completed.\n", |
| 35 | __func__, (int)mask); |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 36 | return; |
| 37 | } |
| 38 | timeout--; |
| 39 | udelay(1000); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | static void sdhci_cmd_done(struct sdhci_host *host, struct mmc_cmd *cmd) |
| 44 | { |
| 45 | int i; |
| 46 | if (cmd->resp_type & MMC_RSP_136) { |
| 47 | /* CRC is stripped so we need to do some shifting. */ |
| 48 | for (i = 0; i < 4; i++) { |
| 49 | cmd->response[i] = sdhci_readl(host, |
| 50 | SDHCI_RESPONSE + (3-i)*4) << 8; |
| 51 | if (i != 3) |
| 52 | cmd->response[i] |= sdhci_readb(host, |
| 53 | SDHCI_RESPONSE + (3-i)*4-1); |
| 54 | } |
| 55 | } else { |
| 56 | cmd->response[0] = sdhci_readl(host, SDHCI_RESPONSE); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | static void sdhci_transfer_pio(struct sdhci_host *host, struct mmc_data *data) |
| 61 | { |
| 62 | int i; |
| 63 | char *offs; |
| 64 | for (i = 0; i < data->blocksize; i += 4) { |
| 65 | offs = data->dest + i; |
| 66 | if (data->flags == MMC_DATA_READ) |
| 67 | *(u32 *)offs = sdhci_readl(host, SDHCI_BUFFER); |
| 68 | else |
| 69 | sdhci_writel(host, *(u32 *)offs, SDHCI_BUFFER); |
| 70 | } |
| 71 | } |
Faiz Abbas | 37cb626 | 2019-04-16 23:06:58 +0530 | [diff] [blame] | 72 | |
| 73 | #if CONFIG_IS_ENABLED(MMC_SDHCI_ADMA) |
| 74 | static void sdhci_adma_desc(struct sdhci_host *host, char *buf, u16 len, |
| 75 | bool end) |
| 76 | { |
| 77 | struct sdhci_adma_desc *desc; |
| 78 | u8 attr; |
| 79 | |
| 80 | desc = &host->adma_desc_table[host->desc_slot]; |
| 81 | |
| 82 | attr = ADMA_DESC_ATTR_VALID | ADMA_DESC_TRANSFER_DATA; |
| 83 | if (!end) |
| 84 | host->desc_slot++; |
| 85 | else |
| 86 | attr |= ADMA_DESC_ATTR_END; |
| 87 | |
| 88 | desc->attr = attr; |
| 89 | desc->len = len; |
| 90 | desc->reserved = 0; |
| 91 | desc->addr_lo = (dma_addr_t)buf; |
| 92 | #ifdef CONFIG_DMA_ADDR_T_64BIT |
| 93 | desc->addr_hi = (u64)buf >> 32; |
| 94 | #endif |
| 95 | } |
| 96 | |
| 97 | static void sdhci_prepare_adma_table(struct sdhci_host *host, |
| 98 | struct mmc_data *data) |
| 99 | { |
| 100 | uint trans_bytes = data->blocksize * data->blocks; |
| 101 | uint desc_count = DIV_ROUND_UP(trans_bytes, ADMA_MAX_LEN); |
| 102 | int i = desc_count; |
| 103 | char *buf; |
| 104 | |
| 105 | host->desc_slot = 0; |
| 106 | |
| 107 | if (data->flags & MMC_DATA_READ) |
| 108 | buf = data->dest; |
| 109 | else |
| 110 | buf = (char *)data->src; |
| 111 | |
| 112 | while (--i) { |
| 113 | sdhci_adma_desc(host, buf, ADMA_MAX_LEN, false); |
| 114 | buf += ADMA_MAX_LEN; |
| 115 | trans_bytes -= ADMA_MAX_LEN; |
| 116 | } |
| 117 | |
| 118 | sdhci_adma_desc(host, buf, trans_bytes, true); |
| 119 | |
| 120 | flush_cache((dma_addr_t)host->adma_desc_table, |
| 121 | ROUND(desc_count * sizeof(struct sdhci_adma_desc), |
| 122 | ARCH_DMA_MINALIGN)); |
| 123 | } |
| 124 | #elif defined(CONFIG_MMC_SDHCI_SDMA) |
| 125 | static void sdhci_prepare_adma_table(struct sdhci_host *host, |
| 126 | struct mmc_data *data) |
| 127 | {} |
| 128 | #endif |
| 129 | #if (defined(CONFIG_MMC_SDHCI_SDMA) || CONFIG_IS_ENABLED(MMC_SDHCI_ADMA)) |
Faiz Abbas | 6d6af20 | 2019-04-16 23:06:57 +0530 | [diff] [blame] | 130 | static void sdhci_prepare_dma(struct sdhci_host *host, struct mmc_data *data, |
| 131 | int *is_aligned, int trans_bytes) |
| 132 | { |
Jaehoon Chung | 804c7f4 | 2012-09-20 20:31:55 +0000 | [diff] [blame] | 133 | unsigned char ctrl; |
Faiz Abbas | 6d6af20 | 2019-04-16 23:06:57 +0530 | [diff] [blame] | 134 | |
| 135 | if (data->flags == MMC_DATA_READ) |
| 136 | host->start_addr = (dma_addr_t)data->dest; |
| 137 | else |
| 138 | host->start_addr = (dma_addr_t)data->src; |
| 139 | |
Faiz Abbas | 37cb626 | 2019-04-16 23:06:58 +0530 | [diff] [blame] | 140 | ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); |
| 141 | ctrl &= ~SDHCI_CTRL_DMA_MASK; |
| 142 | if (host->flags & USE_ADMA64) |
| 143 | ctrl |= SDHCI_CTRL_ADMA64; |
| 144 | else if (host->flags & USE_ADMA) |
| 145 | ctrl |= SDHCI_CTRL_ADMA32; |
| 146 | sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); |
| 147 | |
| 148 | if (host->flags & USE_SDMA) { |
| 149 | if ((host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR) && |
| 150 | (host->start_addr & 0x7) != 0x0) { |
| 151 | *is_aligned = 0; |
| 152 | host->start_addr = (unsigned long)aligned_buffer; |
| 153 | if (data->flags != MMC_DATA_READ) |
| 154 | memcpy(aligned_buffer, data->src, trans_bytes); |
| 155 | } |
| 156 | |
| 157 | #if defined(CONFIG_FIXED_SDHCI_ALIGNED_BUFFER) |
| 158 | /* |
| 159 | * Always use this bounce-buffer when |
| 160 | * CONFIG_FIXED_SDHCI_ALIGNED_BUFFER is defined |
| 161 | */ |
Faiz Abbas | 6d6af20 | 2019-04-16 23:06:57 +0530 | [diff] [blame] | 162 | *is_aligned = 0; |
| 163 | host->start_addr = (unsigned long)aligned_buffer; |
| 164 | if (data->flags != MMC_DATA_READ) |
| 165 | memcpy(aligned_buffer, data->src, trans_bytes); |
Faiz Abbas | 37cb626 | 2019-04-16 23:06:58 +0530 | [diff] [blame] | 166 | #endif |
| 167 | sdhci_writel(host, host->start_addr, SDHCI_DMA_ADDRESS); |
| 168 | |
| 169 | } else if (host->flags & (USE_ADMA | USE_ADMA64)) { |
| 170 | sdhci_prepare_adma_table(host, data); |
| 171 | |
| 172 | sdhci_writel(host, (u32)host->adma_addr, SDHCI_ADMA_ADDRESS); |
| 173 | if (host->flags & USE_ADMA64) |
| 174 | sdhci_writel(host, (u64)host->adma_addr >> 32, |
| 175 | SDHCI_ADMA_ADDRESS_HI); |
Faiz Abbas | 6d6af20 | 2019-04-16 23:06:57 +0530 | [diff] [blame] | 176 | } |
| 177 | |
Faiz Abbas | 6d6af20 | 2019-04-16 23:06:57 +0530 | [diff] [blame] | 178 | flush_cache(host->start_addr, ROUND(trans_bytes, ARCH_DMA_MINALIGN)); |
| 179 | } |
| 180 | #else |
| 181 | static void sdhci_prepare_dma(struct sdhci_host *host, struct mmc_data *data, |
| 182 | int *is_aligned, int trans_bytes) |
| 183 | {} |
| 184 | #endif |
| 185 | static int sdhci_transfer_data(struct sdhci_host *host, struct mmc_data *data) |
| 186 | { |
| 187 | dma_addr_t start_addr = host->start_addr; |
| 188 | unsigned int stat, rdy, mask, timeout, block = 0; |
| 189 | bool transfer_done = false; |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 190 | |
Jaehoon Chung | 5d48e42 | 2012-09-20 20:31:54 +0000 | [diff] [blame] | 191 | timeout = 1000000; |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 192 | rdy = SDHCI_INT_SPACE_AVAIL | SDHCI_INT_DATA_AVAIL; |
| 193 | mask = SDHCI_DATA_AVAILABLE | SDHCI_SPACE_AVAILABLE; |
| 194 | do { |
| 195 | stat = sdhci_readl(host, SDHCI_INT_STATUS); |
| 196 | if (stat & SDHCI_INT_ERROR) { |
Masahiro Yamada | 61f2e5e | 2017-12-30 02:00:12 +0900 | [diff] [blame] | 197 | pr_debug("%s: Error detected in status(0x%X)!\n", |
| 198 | __func__, stat); |
Jaehoon Chung | 2cb5d67 | 2016-09-26 08:10:02 +0900 | [diff] [blame] | 199 | return -EIO; |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 200 | } |
Alex Deymo | 7dde50d | 2017-04-02 01:24:34 -0700 | [diff] [blame] | 201 | if (!transfer_done && (stat & rdy)) { |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 202 | if (!(sdhci_readl(host, SDHCI_PRESENT_STATE) & mask)) |
| 203 | continue; |
| 204 | sdhci_writel(host, rdy, SDHCI_INT_STATUS); |
| 205 | sdhci_transfer_pio(host, data); |
| 206 | data->dest += data->blocksize; |
Alex Deymo | 7dde50d | 2017-04-02 01:24:34 -0700 | [diff] [blame] | 207 | if (++block >= data->blocks) { |
| 208 | /* Keep looping until the SDHCI_INT_DATA_END is |
| 209 | * cleared, even if we finished sending all the |
| 210 | * blocks. |
| 211 | */ |
| 212 | transfer_done = true; |
| 213 | continue; |
| 214 | } |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 215 | } |
Faiz Abbas | 37cb626 | 2019-04-16 23:06:58 +0530 | [diff] [blame] | 216 | if ((host->flags & USE_DMA) && !transfer_done && |
Faiz Abbas | 6d6af20 | 2019-04-16 23:06:57 +0530 | [diff] [blame] | 217 | (stat & SDHCI_INT_DMA_END)) { |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 218 | sdhci_writel(host, SDHCI_INT_DMA_END, SDHCI_INT_STATUS); |
Faiz Abbas | 37cb626 | 2019-04-16 23:06:58 +0530 | [diff] [blame] | 219 | if (host->flags & USE_SDMA) { |
| 220 | start_addr &= |
| 221 | ~(SDHCI_DEFAULT_BOUNDARY_SIZE - 1); |
| 222 | start_addr += SDHCI_DEFAULT_BOUNDARY_SIZE; |
| 223 | sdhci_writel(host, start_addr, |
| 224 | SDHCI_DMA_ADDRESS); |
| 225 | } |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 226 | } |
Lei Wen | a004abd | 2011-10-08 04:14:57 +0000 | [diff] [blame] | 227 | if (timeout-- > 0) |
| 228 | udelay(10); |
| 229 | else { |
Darwin Rambo | 30e6d97 | 2013-12-19 15:13:25 -0800 | [diff] [blame] | 230 | printf("%s: Transfer data timeout\n", __func__); |
Jaehoon Chung | 2cb5d67 | 2016-09-26 08:10:02 +0900 | [diff] [blame] | 231 | return -ETIMEDOUT; |
Lei Wen | a004abd | 2011-10-08 04:14:57 +0000 | [diff] [blame] | 232 | } |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 233 | } while (!(stat & SDHCI_INT_DATA_END)); |
| 234 | return 0; |
| 235 | } |
| 236 | |
Przemyslaw Marczak | 56b34bc | 2013-10-08 18:12:09 +0200 | [diff] [blame] | 237 | /* |
| 238 | * No command will be sent by driver if card is busy, so driver must wait |
| 239 | * for card ready state. |
| 240 | * Every time when card is busy after timeout then (last) timeout value will be |
| 241 | * increased twice but only if it doesn't exceed global defined maximum. |
Masahiro Yamada | 65a25b2 | 2016-08-25 16:07:39 +0900 | [diff] [blame] | 242 | * Each function call will use last timeout value. |
Przemyslaw Marczak | 56b34bc | 2013-10-08 18:12:09 +0200 | [diff] [blame] | 243 | */ |
Masahiro Yamada | 65a25b2 | 2016-08-25 16:07:39 +0900 | [diff] [blame] | 244 | #define SDHCI_CMD_MAX_TIMEOUT 3200 |
Masahiro Yamada | d8ce77b | 2016-08-25 16:07:38 +0900 | [diff] [blame] | 245 | #define SDHCI_CMD_DEFAULT_TIMEOUT 100 |
Steve Rae | d90bb43 | 2016-06-29 13:42:01 -0700 | [diff] [blame] | 246 | #define SDHCI_READ_STATUS_TIMEOUT 1000 |
Przemyslaw Marczak | 56b34bc | 2013-10-08 18:12:09 +0200 | [diff] [blame] | 247 | |
Simon Glass | e7881d8 | 2017-07-29 11:35:31 -0600 | [diff] [blame] | 248 | #ifdef CONFIG_DM_MMC |
Simon Glass | ef1e4ed | 2016-06-12 23:30:28 -0600 | [diff] [blame] | 249 | static int sdhci_send_command(struct udevice *dev, struct mmc_cmd *cmd, |
| 250 | struct mmc_data *data) |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 251 | { |
Simon Glass | ef1e4ed | 2016-06-12 23:30:28 -0600 | [diff] [blame] | 252 | struct mmc *mmc = mmc_get_mmc_dev(dev); |
| 253 | |
| 254 | #else |
| 255 | static int sdhci_send_command(struct mmc *mmc, struct mmc_cmd *cmd, |
| 256 | struct mmc_data *data) |
| 257 | { |
| 258 | #endif |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 259 | struct sdhci_host *host = mmc->priv; |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 260 | unsigned int stat = 0; |
| 261 | int ret = 0; |
| 262 | int trans_bytes = 0, is_aligned = 1; |
| 263 | u32 mask, flags, mode; |
Faiz Abbas | 6d6af20 | 2019-04-16 23:06:57 +0530 | [diff] [blame] | 264 | unsigned int time = 0; |
Simon Glass | 19d2e34 | 2016-05-14 14:03:04 -0600 | [diff] [blame] | 265 | int mmc_dev = mmc_get_blk_desc(mmc)->devnum; |
Vipul Kumar | 36332b6 | 2018-05-03 12:20:54 +0530 | [diff] [blame] | 266 | ulong start = get_timer(0); |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 267 | |
Faiz Abbas | 6d6af20 | 2019-04-16 23:06:57 +0530 | [diff] [blame] | 268 | host->start_addr = 0; |
Przemyslaw Marczak | 56b34bc | 2013-10-08 18:12:09 +0200 | [diff] [blame] | 269 | /* Timeout unit - ms */ |
Masahiro Yamada | d8ce77b | 2016-08-25 16:07:38 +0900 | [diff] [blame] | 270 | static unsigned int cmd_timeout = SDHCI_CMD_DEFAULT_TIMEOUT; |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 271 | |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 272 | mask = SDHCI_CMD_INHIBIT | SDHCI_DATA_INHIBIT; |
| 273 | |
| 274 | /* We shouldn't wait for data inihibit for stop commands, even |
| 275 | though they might use busy signaling */ |
Siva Durga Prasad Paladugu | b88a7a4 | 2018-04-19 12:37:05 +0530 | [diff] [blame] | 276 | if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION || |
Siva Durga Prasad Paladugu | 1a7414f | 2018-06-13 11:43:01 +0530 | [diff] [blame] | 277 | ((cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK || |
| 278 | cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK_HS200) && !data)) |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 279 | mask &= ~SDHCI_DATA_INHIBIT; |
| 280 | |
| 281 | while (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) { |
Przemyslaw Marczak | 56b34bc | 2013-10-08 18:12:09 +0200 | [diff] [blame] | 282 | if (time >= cmd_timeout) { |
Darwin Rambo | 30e6d97 | 2013-12-19 15:13:25 -0800 | [diff] [blame] | 283 | printf("%s: MMC: %d busy ", __func__, mmc_dev); |
Masahiro Yamada | 65a25b2 | 2016-08-25 16:07:39 +0900 | [diff] [blame] | 284 | if (2 * cmd_timeout <= SDHCI_CMD_MAX_TIMEOUT) { |
Przemyslaw Marczak | 56b34bc | 2013-10-08 18:12:09 +0200 | [diff] [blame] | 285 | cmd_timeout += cmd_timeout; |
| 286 | printf("timeout increasing to: %u ms.\n", |
| 287 | cmd_timeout); |
| 288 | } else { |
| 289 | puts("timeout.\n"); |
Jaehoon Chung | 915ffa5 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 290 | return -ECOMM; |
Przemyslaw Marczak | 56b34bc | 2013-10-08 18:12:09 +0200 | [diff] [blame] | 291 | } |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 292 | } |
Przemyslaw Marczak | 56b34bc | 2013-10-08 18:12:09 +0200 | [diff] [blame] | 293 | time++; |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 294 | udelay(1000); |
| 295 | } |
| 296 | |
Jorge Ramirez-Ortiz | 713e681 | 2017-11-02 15:10:21 +0100 | [diff] [blame] | 297 | sdhci_writel(host, SDHCI_INT_ALL_MASK, SDHCI_INT_STATUS); |
| 298 | |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 299 | mask = SDHCI_INT_RESPONSE; |
Siva Durga Prasad Paladugu | 1a7414f | 2018-06-13 11:43:01 +0530 | [diff] [blame] | 300 | if ((cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK || |
| 301 | cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK_HS200) && !data) |
Siva Durga Prasad Paladugu | b88a7a4 | 2018-04-19 12:37:05 +0530 | [diff] [blame] | 302 | mask = SDHCI_INT_DATA_AVAIL; |
| 303 | |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 304 | if (!(cmd->resp_type & MMC_RSP_PRESENT)) |
| 305 | flags = SDHCI_CMD_RESP_NONE; |
| 306 | else if (cmd->resp_type & MMC_RSP_136) |
| 307 | flags = SDHCI_CMD_RESP_LONG; |
| 308 | else if (cmd->resp_type & MMC_RSP_BUSY) { |
| 309 | flags = SDHCI_CMD_RESP_SHORT_BUSY; |
Jaehoon Chung | 17ea3c8 | 2016-07-12 21:18:46 +0900 | [diff] [blame] | 310 | if (data) |
| 311 | mask |= SDHCI_INT_DATA_END; |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 312 | } else |
| 313 | flags = SDHCI_CMD_RESP_SHORT; |
| 314 | |
| 315 | if (cmd->resp_type & MMC_RSP_CRC) |
| 316 | flags |= SDHCI_CMD_CRC; |
| 317 | if (cmd->resp_type & MMC_RSP_OPCODE) |
| 318 | flags |= SDHCI_CMD_INDEX; |
Siva Durga Prasad Paladugu | 434f9d4 | 2018-05-29 20:03:10 +0530 | [diff] [blame] | 319 | if (data || cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK || |
| 320 | cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK_HS200) |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 321 | flags |= SDHCI_CMD_DATA; |
| 322 | |
Darwin Rambo | 30e6d97 | 2013-12-19 15:13:25 -0800 | [diff] [blame] | 323 | /* Set Transfer mode regarding to data flag */ |
Heinrich Schuchardt | bb7b4ef | 2017-11-10 21:13:34 +0100 | [diff] [blame] | 324 | if (data) { |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 325 | sdhci_writeb(host, 0xe, SDHCI_TIMEOUT_CONTROL); |
| 326 | mode = SDHCI_TRNS_BLK_CNT_EN; |
| 327 | trans_bytes = data->blocks * data->blocksize; |
| 328 | if (data->blocks > 1) |
| 329 | mode |= SDHCI_TRNS_MULTI; |
| 330 | |
| 331 | if (data->flags == MMC_DATA_READ) |
| 332 | mode |= SDHCI_TRNS_READ; |
| 333 | |
Faiz Abbas | 37cb626 | 2019-04-16 23:06:58 +0530 | [diff] [blame] | 334 | if (host->flags & USE_DMA) { |
Faiz Abbas | 6d6af20 | 2019-04-16 23:06:57 +0530 | [diff] [blame] | 335 | mode |= SDHCI_TRNS_DMA; |
| 336 | sdhci_prepare_dma(host, data, &is_aligned, trans_bytes); |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 337 | } |
| 338 | |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 339 | sdhci_writew(host, SDHCI_MAKE_BLKSZ(SDHCI_DEFAULT_BOUNDARY_ARG, |
| 340 | data->blocksize), |
| 341 | SDHCI_BLOCK_SIZE); |
| 342 | sdhci_writew(host, data->blocks, SDHCI_BLOCK_COUNT); |
| 343 | sdhci_writew(host, mode, SDHCI_TRANSFER_MODE); |
Kevin Liu | 5e1c23c | 2015-03-23 17:57:00 -0500 | [diff] [blame] | 344 | } else if (cmd->resp_type & MMC_RSP_BUSY) { |
| 345 | sdhci_writeb(host, 0xe, SDHCI_TIMEOUT_CONTROL); |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | sdhci_writel(host, cmd->cmdarg, SDHCI_ARGUMENT); |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 349 | sdhci_writew(host, SDHCI_MAKE_CMD(cmd->cmdidx, flags), SDHCI_COMMAND); |
Stefan Roese | 29905a4 | 2015-06-29 14:58:08 +0200 | [diff] [blame] | 350 | start = get_timer(0); |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 351 | do { |
| 352 | stat = sdhci_readl(host, SDHCI_INT_STATUS); |
| 353 | if (stat & SDHCI_INT_ERROR) |
| 354 | break; |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 355 | |
Masahiro Yamada | bae4a1f | 2016-07-10 00:40:22 +0900 | [diff] [blame] | 356 | if (get_timer(start) >= SDHCI_READ_STATUS_TIMEOUT) { |
| 357 | if (host->quirks & SDHCI_QUIRK_BROKEN_R1B) { |
| 358 | return 0; |
| 359 | } else { |
| 360 | printf("%s: Timeout for status update!\n", |
| 361 | __func__); |
Jaehoon Chung | 915ffa5 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 362 | return -ETIMEDOUT; |
Masahiro Yamada | bae4a1f | 2016-07-10 00:40:22 +0900 | [diff] [blame] | 363 | } |
Jaehoon Chung | 3a63832 | 2012-04-23 02:36:25 +0000 | [diff] [blame] | 364 | } |
Masahiro Yamada | bae4a1f | 2016-07-10 00:40:22 +0900 | [diff] [blame] | 365 | } while ((stat & mask) != mask); |
Jaehoon Chung | 3a63832 | 2012-04-23 02:36:25 +0000 | [diff] [blame] | 366 | |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 367 | if ((stat & (SDHCI_INT_ERROR | mask)) == mask) { |
| 368 | sdhci_cmd_done(host, cmd); |
| 369 | sdhci_writel(host, mask, SDHCI_INT_STATUS); |
| 370 | } else |
| 371 | ret = -1; |
| 372 | |
| 373 | if (!ret && data) |
Faiz Abbas | 6d6af20 | 2019-04-16 23:06:57 +0530 | [diff] [blame] | 374 | ret = sdhci_transfer_data(host, data); |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 375 | |
Tushar Behera | 13243f2 | 2012-09-20 20:31:57 +0000 | [diff] [blame] | 376 | if (host->quirks & SDHCI_QUIRK_WAIT_SEND_CMD) |
| 377 | udelay(1000); |
| 378 | |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 379 | stat = sdhci_readl(host, SDHCI_INT_STATUS); |
| 380 | sdhci_writel(host, SDHCI_INT_ALL_MASK, SDHCI_INT_STATUS); |
| 381 | if (!ret) { |
| 382 | if ((host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR) && |
| 383 | !is_aligned && (data->flags == MMC_DATA_READ)) |
| 384 | memcpy(data->dest, aligned_buffer, trans_bytes); |
| 385 | return 0; |
| 386 | } |
| 387 | |
| 388 | sdhci_reset(host, SDHCI_RESET_CMD); |
| 389 | sdhci_reset(host, SDHCI_RESET_DATA); |
| 390 | if (stat & SDHCI_INT_TIMEOUT) |
Jaehoon Chung | 915ffa5 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 391 | return -ETIMEDOUT; |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 392 | else |
Jaehoon Chung | 915ffa5 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 393 | return -ECOMM; |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 394 | } |
| 395 | |
Siva Durga Prasad Paladugu | ca992e8 | 2018-04-19 12:37:07 +0530 | [diff] [blame] | 396 | #if defined(CONFIG_DM_MMC) && defined(MMC_SUPPORTS_TUNING) |
| 397 | static int sdhci_execute_tuning(struct udevice *dev, uint opcode) |
| 398 | { |
| 399 | int err; |
| 400 | struct mmc *mmc = mmc_get_mmc_dev(dev); |
| 401 | struct sdhci_host *host = mmc->priv; |
| 402 | |
| 403 | debug("%s\n", __func__); |
| 404 | |
Ramon Fried | b70fe96 | 2018-05-14 15:02:30 +0300 | [diff] [blame] | 405 | if (host->ops && host->ops->platform_execute_tuning) { |
Siva Durga Prasad Paladugu | ca992e8 | 2018-04-19 12:37:07 +0530 | [diff] [blame] | 406 | err = host->ops->platform_execute_tuning(mmc, opcode); |
| 407 | if (err) |
| 408 | return err; |
| 409 | return 0; |
| 410 | } |
| 411 | return 0; |
| 412 | } |
| 413 | #endif |
Faiz Abbas | 3966c7d | 2019-06-11 00:43:35 +0530 | [diff] [blame] | 414 | int sdhci_set_clock(struct mmc *mmc, unsigned int clock) |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 415 | { |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 416 | struct sdhci_host *host = mmc->priv; |
Stefan Roese | 899fb9e | 2016-12-12 08:34:42 +0100 | [diff] [blame] | 417 | unsigned int div, clk = 0, timeout; |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 418 | |
Wenyou Yang | 79667b7 | 2015-09-22 14:59:25 +0800 | [diff] [blame] | 419 | /* Wait max 20 ms */ |
| 420 | timeout = 200; |
| 421 | while (sdhci_readl(host, SDHCI_PRESENT_STATE) & |
| 422 | (SDHCI_CMD_INHIBIT | SDHCI_DATA_INHIBIT)) { |
| 423 | if (timeout == 0) { |
| 424 | printf("%s: Timeout to wait cmd & data inhibit\n", |
| 425 | __func__); |
Jaehoon Chung | 2cb5d67 | 2016-09-26 08:10:02 +0900 | [diff] [blame] | 426 | return -EBUSY; |
Wenyou Yang | 79667b7 | 2015-09-22 14:59:25 +0800 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | timeout--; |
| 430 | udelay(100); |
| 431 | } |
| 432 | |
Stefan Roese | 899fb9e | 2016-12-12 08:34:42 +0100 | [diff] [blame] | 433 | sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL); |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 434 | |
| 435 | if (clock == 0) |
| 436 | return 0; |
| 437 | |
Ramon Fried | b70fe96 | 2018-05-14 15:02:30 +0300 | [diff] [blame] | 438 | if (host->ops && host->ops->set_delay) |
Siva Durga Prasad Paladugu | ca992e8 | 2018-04-19 12:37:07 +0530 | [diff] [blame] | 439 | host->ops->set_delay(host); |
| 440 | |
Jaehoon Chung | 113e5df | 2013-07-19 17:44:49 +0900 | [diff] [blame] | 441 | if (SDHCI_GET_VERSION(host) >= SDHCI_SPEC_300) { |
Wenyou Yang | 6dffdbc | 2016-09-18 09:01:22 +0800 | [diff] [blame] | 442 | /* |
| 443 | * Check if the Host Controller supports Programmable Clock |
| 444 | * Mode. |
| 445 | */ |
| 446 | if (host->clk_mul) { |
| 447 | for (div = 1; div <= 1024; div++) { |
Wenyou Yang | 0e0dcc1 | 2017-04-26 09:32:30 +0800 | [diff] [blame] | 448 | if ((host->max_clk / div) <= clock) |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 449 | break; |
| 450 | } |
Wenyou Yang | 6dffdbc | 2016-09-18 09:01:22 +0800 | [diff] [blame] | 451 | |
| 452 | /* |
| 453 | * Set Programmable Clock Mode in the Clock |
| 454 | * Control register. |
| 455 | */ |
| 456 | clk = SDHCI_PROG_CLOCK_MODE; |
| 457 | div--; |
| 458 | } else { |
| 459 | /* Version 3.00 divisors must be a multiple of 2. */ |
Stefan Herbrechtsmeier | 6d0e34b | 2017-01-17 15:58:48 +0100 | [diff] [blame] | 460 | if (host->max_clk <= clock) { |
Wenyou Yang | 6dffdbc | 2016-09-18 09:01:22 +0800 | [diff] [blame] | 461 | div = 1; |
| 462 | } else { |
| 463 | for (div = 2; |
| 464 | div < SDHCI_MAX_DIV_SPEC_300; |
| 465 | div += 2) { |
Stefan Herbrechtsmeier | 6d0e34b | 2017-01-17 15:58:48 +0100 | [diff] [blame] | 466 | if ((host->max_clk / div) <= clock) |
Wenyou Yang | 6dffdbc | 2016-09-18 09:01:22 +0800 | [diff] [blame] | 467 | break; |
| 468 | } |
| 469 | } |
| 470 | div >>= 1; |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 471 | } |
| 472 | } else { |
| 473 | /* Version 2.00 divisors must be a power of 2. */ |
| 474 | for (div = 1; div < SDHCI_MAX_DIV_SPEC_200; div *= 2) { |
Stefan Herbrechtsmeier | 6d0e34b | 2017-01-17 15:58:48 +0100 | [diff] [blame] | 475 | if ((host->max_clk / div) <= clock) |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 476 | break; |
| 477 | } |
Wenyou Yang | 6dffdbc | 2016-09-18 09:01:22 +0800 | [diff] [blame] | 478 | div >>= 1; |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 479 | } |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 480 | |
Masahiro Yamada | bf9c4d1 | 2017-01-13 11:51:51 +0900 | [diff] [blame] | 481 | if (host->ops && host->ops->set_clock) |
Jaehoon Chung | 62226b6 | 2016-12-30 15:30:18 +0900 | [diff] [blame] | 482 | host->ops->set_clock(host, div); |
Jaehoon Chung | b09ed6e | 2012-08-30 16:24:11 +0000 | [diff] [blame] | 483 | |
Wenyou Yang | 6dffdbc | 2016-09-18 09:01:22 +0800 | [diff] [blame] | 484 | clk |= (div & SDHCI_DIV_MASK) << SDHCI_DIVIDER_SHIFT; |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 485 | clk |= ((div & SDHCI_DIV_HI_MASK) >> SDHCI_DIV_MASK_LEN) |
| 486 | << SDHCI_DIVIDER_HI_SHIFT; |
| 487 | clk |= SDHCI_CLOCK_INT_EN; |
| 488 | sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); |
| 489 | |
| 490 | /* Wait max 20 ms */ |
| 491 | timeout = 20; |
| 492 | while (!((clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL)) |
| 493 | & SDHCI_CLOCK_INT_STABLE)) { |
| 494 | if (timeout == 0) { |
Darwin Rambo | 30e6d97 | 2013-12-19 15:13:25 -0800 | [diff] [blame] | 495 | printf("%s: Internal clock never stabilised.\n", |
| 496 | __func__); |
Jaehoon Chung | 2cb5d67 | 2016-09-26 08:10:02 +0900 | [diff] [blame] | 497 | return -EBUSY; |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 498 | } |
| 499 | timeout--; |
| 500 | udelay(1000); |
| 501 | } |
| 502 | |
| 503 | clk |= SDHCI_CLOCK_CARD_EN; |
| 504 | sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); |
| 505 | return 0; |
| 506 | } |
| 507 | |
| 508 | static void sdhci_set_power(struct sdhci_host *host, unsigned short power) |
| 509 | { |
| 510 | u8 pwr = 0; |
| 511 | |
| 512 | if (power != (unsigned short)-1) { |
| 513 | switch (1 << power) { |
| 514 | case MMC_VDD_165_195: |
| 515 | pwr = SDHCI_POWER_180; |
| 516 | break; |
| 517 | case MMC_VDD_29_30: |
| 518 | case MMC_VDD_30_31: |
| 519 | pwr = SDHCI_POWER_300; |
| 520 | break; |
| 521 | case MMC_VDD_32_33: |
| 522 | case MMC_VDD_33_34: |
| 523 | pwr = SDHCI_POWER_330; |
| 524 | break; |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | if (pwr == 0) { |
| 529 | sdhci_writeb(host, 0, SDHCI_POWER_CONTROL); |
| 530 | return; |
| 531 | } |
| 532 | |
| 533 | pwr |= SDHCI_POWER_ON; |
| 534 | |
| 535 | sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL); |
| 536 | } |
| 537 | |
Faiz Abbas | d1c0a22 | 2019-06-11 00:43:40 +0530 | [diff] [blame] | 538 | void sdhci_set_uhs_timing(struct sdhci_host *host) |
| 539 | { |
| 540 | struct mmc *mmc = (struct mmc *)host->mmc; |
| 541 | u32 reg; |
| 542 | |
| 543 | reg = sdhci_readw(host, SDHCI_HOST_CONTROL2); |
| 544 | reg &= ~SDHCI_CTRL_UHS_MASK; |
| 545 | |
| 546 | switch (mmc->selected_mode) { |
| 547 | case UHS_SDR50: |
| 548 | case MMC_HS_52: |
| 549 | reg |= SDHCI_CTRL_UHS_SDR50; |
| 550 | break; |
| 551 | case UHS_DDR50: |
| 552 | case MMC_DDR_52: |
| 553 | reg |= SDHCI_CTRL_UHS_DDR50; |
| 554 | break; |
| 555 | case UHS_SDR104: |
| 556 | case MMC_HS_200: |
| 557 | reg |= SDHCI_CTRL_UHS_SDR104; |
| 558 | break; |
| 559 | default: |
| 560 | reg |= SDHCI_CTRL_UHS_SDR12; |
| 561 | } |
| 562 | |
| 563 | sdhci_writew(host, reg, SDHCI_HOST_CONTROL2); |
| 564 | } |
| 565 | |
Simon Glass | e7881d8 | 2017-07-29 11:35:31 -0600 | [diff] [blame] | 566 | #ifdef CONFIG_DM_MMC |
Simon Glass | ef1e4ed | 2016-06-12 23:30:28 -0600 | [diff] [blame] | 567 | static int sdhci_set_ios(struct udevice *dev) |
| 568 | { |
| 569 | struct mmc *mmc = mmc_get_mmc_dev(dev); |
| 570 | #else |
Jaehoon Chung | 07b0b9c | 2016-12-30 15:30:16 +0900 | [diff] [blame] | 571 | static int sdhci_set_ios(struct mmc *mmc) |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 572 | { |
Simon Glass | ef1e4ed | 2016-06-12 23:30:28 -0600 | [diff] [blame] | 573 | #endif |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 574 | u32 ctrl; |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 575 | struct sdhci_host *host = mmc->priv; |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 576 | |
Masahiro Yamada | bf9c4d1 | 2017-01-13 11:51:51 +0900 | [diff] [blame] | 577 | if (host->ops && host->ops->set_control_reg) |
Jaehoon Chung | 62226b6 | 2016-12-30 15:30:18 +0900 | [diff] [blame] | 578 | host->ops->set_control_reg(host); |
Jaehoon Chung | 236bfec | 2012-04-23 02:36:26 +0000 | [diff] [blame] | 579 | |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 580 | if (mmc->clock != host->clock) |
| 581 | sdhci_set_clock(mmc, mmc->clock); |
| 582 | |
Siva Durga Prasad Paladugu | 2a2d7ef | 2018-04-19 12:37:04 +0530 | [diff] [blame] | 583 | if (mmc->clk_disable) |
| 584 | sdhci_set_clock(mmc, 0); |
| 585 | |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 586 | /* Set bus width */ |
| 587 | ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); |
| 588 | if (mmc->bus_width == 8) { |
| 589 | ctrl &= ~SDHCI_CTRL_4BITBUS; |
Jaehoon Chung | 113e5df | 2013-07-19 17:44:49 +0900 | [diff] [blame] | 590 | if ((SDHCI_GET_VERSION(host) >= SDHCI_SPEC_300) || |
| 591 | (host->quirks & SDHCI_QUIRK_USE_WIDE8)) |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 592 | ctrl |= SDHCI_CTRL_8BITBUS; |
| 593 | } else { |
Matt Reimer | f88a429 | 2015-02-19 11:22:53 -0700 | [diff] [blame] | 594 | if ((SDHCI_GET_VERSION(host) >= SDHCI_SPEC_300) || |
| 595 | (host->quirks & SDHCI_QUIRK_USE_WIDE8)) |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 596 | ctrl &= ~SDHCI_CTRL_8BITBUS; |
| 597 | if (mmc->bus_width == 4) |
| 598 | ctrl |= SDHCI_CTRL_4BITBUS; |
| 599 | else |
| 600 | ctrl &= ~SDHCI_CTRL_4BITBUS; |
| 601 | } |
| 602 | |
| 603 | if (mmc->clock > 26000000) |
| 604 | ctrl |= SDHCI_CTRL_HISPD; |
| 605 | else |
| 606 | ctrl &= ~SDHCI_CTRL_HISPD; |
| 607 | |
Hannes Schmelzer | 88a5712 | 2018-03-07 08:00:56 +0100 | [diff] [blame] | 608 | if ((host->quirks & SDHCI_QUIRK_NO_HISPD_BIT) || |
| 609 | (host->quirks & SDHCI_QUIRK_BROKEN_HISPD_MODE)) |
Jaehoon Chung | 236bfec | 2012-04-23 02:36:26 +0000 | [diff] [blame] | 610 | ctrl &= ~SDHCI_CTRL_HISPD; |
| 611 | |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 612 | sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); |
Jaehoon Chung | 07b0b9c | 2016-12-30 15:30:16 +0900 | [diff] [blame] | 613 | |
Stefan Roese | 210841c | 2016-12-12 08:24:56 +0100 | [diff] [blame] | 614 | /* If available, call the driver specific "post" set_ios() function */ |
| 615 | if (host->ops && host->ops->set_ios_post) |
Faiz Abbas | a8185c5 | 2019-06-11 00:43:37 +0530 | [diff] [blame] | 616 | return host->ops->set_ios_post(host); |
Stefan Roese | 210841c | 2016-12-12 08:24:56 +0100 | [diff] [blame] | 617 | |
Simon Glass | ef1e4ed | 2016-06-12 23:30:28 -0600 | [diff] [blame] | 618 | return 0; |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 619 | } |
| 620 | |
Jeroen Hofstee | 6588c78 | 2014-10-08 22:57:43 +0200 | [diff] [blame] | 621 | static int sdhci_init(struct mmc *mmc) |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 622 | { |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 623 | struct sdhci_host *host = mmc->priv; |
T Karthik Reddy | 451931e | 2019-06-25 13:39:03 +0200 | [diff] [blame] | 624 | #if CONFIG_IS_ENABLED(DM_MMC) && CONFIG_IS_ENABLED(DM_GPIO) |
| 625 | struct udevice *dev = mmc->dev; |
| 626 | |
Baruch Siach | 58d65d5 | 2019-07-22 19:14:06 +0300 | [diff] [blame] | 627 | gpio_request_by_name(dev, "cd-gpios", 0, |
T Karthik Reddy | 451931e | 2019-06-25 13:39:03 +0200 | [diff] [blame] | 628 | &host->cd_gpio, GPIOD_IS_IN); |
| 629 | #endif |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 630 | |
Masahiro Yamada | 8d549b6 | 2016-08-25 16:07:34 +0900 | [diff] [blame] | 631 | sdhci_reset(host, SDHCI_RESET_ALL); |
| 632 | |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 633 | if ((host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR) && !aligned_buffer) { |
| 634 | aligned_buffer = memalign(8, 512*1024); |
| 635 | if (!aligned_buffer) { |
Darwin Rambo | 30e6d97 | 2013-12-19 15:13:25 -0800 | [diff] [blame] | 636 | printf("%s: Aligned buffer alloc failed!!!\n", |
| 637 | __func__); |
Jaehoon Chung | 2cb5d67 | 2016-09-26 08:10:02 +0900 | [diff] [blame] | 638 | return -ENOMEM; |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 639 | } |
| 640 | } |
| 641 | |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 642 | sdhci_set_power(host, fls(mmc->cfg->voltages) - 1); |
Joe Hershberger | 470dcc7 | 2012-08-17 10:18:55 +0000 | [diff] [blame] | 643 | |
Masahiro Yamada | bf9c4d1 | 2017-01-13 11:51:51 +0900 | [diff] [blame] | 644 | if (host->ops && host->ops->get_cd) |
Jaehoon Chung | 6f88a3a | 2016-12-30 15:30:15 +0900 | [diff] [blame] | 645 | host->ops->get_cd(host); |
Joe Hershberger | 470dcc7 | 2012-08-17 10:18:55 +0000 | [diff] [blame] | 646 | |
Łukasz Majewski | ce0c1bc | 2013-01-11 05:08:54 +0000 | [diff] [blame] | 647 | /* Enable only interrupts served by the SD controller */ |
Darwin Rambo | 30e6d97 | 2013-12-19 15:13:25 -0800 | [diff] [blame] | 648 | sdhci_writel(host, SDHCI_INT_DATA_MASK | SDHCI_INT_CMD_MASK, |
| 649 | SDHCI_INT_ENABLE); |
Łukasz Majewski | ce0c1bc | 2013-01-11 05:08:54 +0000 | [diff] [blame] | 650 | /* Mask all sdhci interrupt sources */ |
| 651 | sdhci_writel(host, 0x0, SDHCI_SIGNAL_ENABLE); |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 652 | |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 653 | return 0; |
| 654 | } |
| 655 | |
Simon Glass | e7881d8 | 2017-07-29 11:35:31 -0600 | [diff] [blame] | 656 | #ifdef CONFIG_DM_MMC |
Simon Glass | ef1e4ed | 2016-06-12 23:30:28 -0600 | [diff] [blame] | 657 | int sdhci_probe(struct udevice *dev) |
| 658 | { |
| 659 | struct mmc *mmc = mmc_get_mmc_dev(dev); |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 660 | |
Simon Glass | ef1e4ed | 2016-06-12 23:30:28 -0600 | [diff] [blame] | 661 | return sdhci_init(mmc); |
| 662 | } |
| 663 | |
Baruch Siach | 1b71695 | 2019-11-03 12:00:27 +0200 | [diff] [blame] | 664 | static int sdhci_get_cd(struct udevice *dev) |
T Karthik Reddy | da18c62 | 2019-06-25 13:39:04 +0200 | [diff] [blame] | 665 | { |
| 666 | struct mmc *mmc = mmc_get_mmc_dev(dev); |
| 667 | struct sdhci_host *host = mmc->priv; |
| 668 | int value; |
| 669 | |
| 670 | /* If nonremovable, assume that the card is always present. */ |
| 671 | if (mmc->cfg->host_caps & MMC_CAP_NONREMOVABLE) |
| 672 | return 1; |
| 673 | /* If polling, assume that the card is always present. */ |
| 674 | if (mmc->cfg->host_caps & MMC_CAP_NEEDS_POLL) |
| 675 | return 1; |
| 676 | |
| 677 | #if CONFIG_IS_ENABLED(DM_GPIO) |
| 678 | value = dm_gpio_get_value(&host->cd_gpio); |
| 679 | if (value >= 0) { |
| 680 | if (mmc->cfg->host_caps & MMC_CAP_CD_ACTIVE_HIGH) |
| 681 | return !value; |
| 682 | else |
| 683 | return value; |
| 684 | } |
| 685 | #endif |
| 686 | value = !!(sdhci_readl(host, SDHCI_PRESENT_STATE) & |
| 687 | SDHCI_CARD_PRESENT); |
| 688 | if (mmc->cfg->host_caps & MMC_CAP_CD_ACTIVE_HIGH) |
| 689 | return !value; |
| 690 | else |
| 691 | return value; |
| 692 | } |
| 693 | |
Simon Glass | ef1e4ed | 2016-06-12 23:30:28 -0600 | [diff] [blame] | 694 | const struct dm_mmc_ops sdhci_ops = { |
| 695 | .send_cmd = sdhci_send_command, |
| 696 | .set_ios = sdhci_set_ios, |
T Karthik Reddy | da18c62 | 2019-06-25 13:39:04 +0200 | [diff] [blame] | 697 | .get_cd = sdhci_get_cd, |
Siva Durga Prasad Paladugu | ca992e8 | 2018-04-19 12:37:07 +0530 | [diff] [blame] | 698 | #ifdef MMC_SUPPORTS_TUNING |
| 699 | .execute_tuning = sdhci_execute_tuning, |
| 700 | #endif |
Simon Glass | ef1e4ed | 2016-06-12 23:30:28 -0600 | [diff] [blame] | 701 | }; |
| 702 | #else |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 703 | static const struct mmc_ops sdhci_ops = { |
| 704 | .send_cmd = sdhci_send_command, |
| 705 | .set_ios = sdhci_set_ios, |
| 706 | .init = sdhci_init, |
| 707 | }; |
Simon Glass | ef1e4ed | 2016-06-12 23:30:28 -0600 | [diff] [blame] | 708 | #endif |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 709 | |
Jaehoon Chung | 14bed52 | 2016-07-26 19:06:24 +0900 | [diff] [blame] | 710 | int sdhci_setup_cfg(struct mmc_config *cfg, struct sdhci_host *host, |
Stefan Herbrechtsmeier | 6d0e34b | 2017-01-17 15:58:48 +0100 | [diff] [blame] | 711 | u32 f_max, u32 f_min) |
Simon Glass | 2a80909 | 2016-06-12 23:30:27 -0600 | [diff] [blame] | 712 | { |
Siva Durga Prasad Paladugu | b8e25ef | 2018-04-19 12:37:08 +0530 | [diff] [blame] | 713 | u32 caps, caps_1 = 0; |
Faiz Abbas | 3d29636 | 2019-06-11 00:43:34 +0530 | [diff] [blame] | 714 | #if CONFIG_IS_ENABLED(DM_MMC) |
T Karthik Reddy | cd45d6f | 2019-09-02 16:34:31 +0200 | [diff] [blame] | 715 | u64 dt_caps, dt_caps_mask; |
Jaehoon Chung | 14bed52 | 2016-07-26 19:06:24 +0900 | [diff] [blame] | 716 | |
T Karthik Reddy | cd45d6f | 2019-09-02 16:34:31 +0200 | [diff] [blame] | 717 | dt_caps_mask = dev_read_u64_default(host->mmc->dev, |
| 718 | "sdhci-caps-mask", 0); |
| 719 | dt_caps = dev_read_u64_default(host->mmc->dev, |
| 720 | "sdhci-caps", 0); |
| 721 | caps = ~(u32)dt_caps_mask & |
| 722 | sdhci_readl(host, SDHCI_CAPABILITIES); |
| 723 | caps |= (u32)dt_caps; |
Faiz Abbas | 3d29636 | 2019-06-11 00:43:34 +0530 | [diff] [blame] | 724 | #else |
Jaehoon Chung | 14bed52 | 2016-07-26 19:06:24 +0900 | [diff] [blame] | 725 | caps = sdhci_readl(host, SDHCI_CAPABILITIES); |
Faiz Abbas | 3d29636 | 2019-06-11 00:43:34 +0530 | [diff] [blame] | 726 | #endif |
T Karthik Reddy | cd45d6f | 2019-09-02 16:34:31 +0200 | [diff] [blame] | 727 | debug("%s, caps: 0x%x\n", __func__, caps); |
Masahiro Yamada | 15bd099 | 2016-08-25 16:07:37 +0900 | [diff] [blame] | 728 | |
Masahiro Yamada | 45a68fe | 2016-12-07 22:10:29 +0900 | [diff] [blame] | 729 | #ifdef CONFIG_MMC_SDHCI_SDMA |
Masahiro Yamada | 15bd099 | 2016-08-25 16:07:37 +0900 | [diff] [blame] | 730 | if (!(caps & SDHCI_CAN_DO_SDMA)) { |
| 731 | printf("%s: Your controller doesn't support SDMA!!\n", |
| 732 | __func__); |
| 733 | return -EINVAL; |
| 734 | } |
Faiz Abbas | 6d6af20 | 2019-04-16 23:06:57 +0530 | [diff] [blame] | 735 | |
| 736 | host->flags |= USE_SDMA; |
Masahiro Yamada | 15bd099 | 2016-08-25 16:07:37 +0900 | [diff] [blame] | 737 | #endif |
Faiz Abbas | 37cb626 | 2019-04-16 23:06:58 +0530 | [diff] [blame] | 738 | #if CONFIG_IS_ENABLED(MMC_SDHCI_ADMA) |
| 739 | if (!(caps & SDHCI_CAN_DO_ADMA2)) { |
| 740 | printf("%s: Your controller doesn't support SDMA!!\n", |
| 741 | __func__); |
| 742 | return -EINVAL; |
| 743 | } |
| 744 | host->adma_desc_table = (struct sdhci_adma_desc *) |
| 745 | memalign(ARCH_DMA_MINALIGN, ADMA_TABLE_SZ); |
| 746 | |
| 747 | host->adma_addr = (dma_addr_t)host->adma_desc_table; |
| 748 | #ifdef CONFIG_DMA_ADDR_T_64BIT |
| 749 | host->flags |= USE_ADMA64; |
| 750 | #else |
| 751 | host->flags |= USE_ADMA; |
| 752 | #endif |
| 753 | #endif |
Jaehoon Chung | 895549a | 2016-09-26 08:10:01 +0900 | [diff] [blame] | 754 | if (host->quirks & SDHCI_QUIRK_REG32_RW) |
| 755 | host->version = |
| 756 | sdhci_readl(host, SDHCI_HOST_VERSION - 2) >> 16; |
| 757 | else |
| 758 | host->version = sdhci_readw(host, SDHCI_HOST_VERSION); |
Jaehoon Chung | 14bed52 | 2016-07-26 19:06:24 +0900 | [diff] [blame] | 759 | |
| 760 | cfg->name = host->name; |
Simon Glass | e7881d8 | 2017-07-29 11:35:31 -0600 | [diff] [blame] | 761 | #ifndef CONFIG_DM_MMC |
Simon Glass | 2a80909 | 2016-06-12 23:30:27 -0600 | [diff] [blame] | 762 | cfg->ops = &sdhci_ops; |
| 763 | #endif |
Wenyou Yang | 0e0dcc1 | 2017-04-26 09:32:30 +0800 | [diff] [blame] | 764 | |
| 765 | /* Check whether the clock multiplier is supported or not */ |
| 766 | if (SDHCI_GET_VERSION(host) >= SDHCI_SPEC_300) { |
Faiz Abbas | 3d29636 | 2019-06-11 00:43:34 +0530 | [diff] [blame] | 767 | #if CONFIG_IS_ENABLED(DM_MMC) |
T Karthik Reddy | cd45d6f | 2019-09-02 16:34:31 +0200 | [diff] [blame] | 768 | caps_1 = ~(u32)(dt_caps_mask >> 32) & |
| 769 | sdhci_readl(host, SDHCI_CAPABILITIES_1); |
| 770 | caps_1 |= (u32)(dt_caps >> 32); |
Faiz Abbas | 3d29636 | 2019-06-11 00:43:34 +0530 | [diff] [blame] | 771 | #else |
Wenyou Yang | 0e0dcc1 | 2017-04-26 09:32:30 +0800 | [diff] [blame] | 772 | caps_1 = sdhci_readl(host, SDHCI_CAPABILITIES_1); |
Faiz Abbas | 3d29636 | 2019-06-11 00:43:34 +0530 | [diff] [blame] | 773 | #endif |
T Karthik Reddy | cd45d6f | 2019-09-02 16:34:31 +0200 | [diff] [blame] | 774 | debug("%s, caps_1: 0x%x\n", __func__, caps_1); |
Wenyou Yang | 0e0dcc1 | 2017-04-26 09:32:30 +0800 | [diff] [blame] | 775 | host->clk_mul = (caps_1 & SDHCI_CLOCK_MUL_MASK) >> |
| 776 | SDHCI_CLOCK_MUL_SHIFT; |
| 777 | } |
| 778 | |
Stefan Herbrechtsmeier | 6d0e34b | 2017-01-17 15:58:48 +0100 | [diff] [blame] | 779 | if (host->max_clk == 0) { |
Jaehoon Chung | 14bed52 | 2016-07-26 19:06:24 +0900 | [diff] [blame] | 780 | if (SDHCI_GET_VERSION(host) >= SDHCI_SPEC_300) |
Stefan Herbrechtsmeier | 6d0e34b | 2017-01-17 15:58:48 +0100 | [diff] [blame] | 781 | host->max_clk = (caps & SDHCI_CLOCK_V3_BASE_MASK) >> |
Simon Glass | 2a80909 | 2016-06-12 23:30:27 -0600 | [diff] [blame] | 782 | SDHCI_CLOCK_BASE_SHIFT; |
| 783 | else |
Stefan Herbrechtsmeier | 6d0e34b | 2017-01-17 15:58:48 +0100 | [diff] [blame] | 784 | host->max_clk = (caps & SDHCI_CLOCK_BASE_MASK) >> |
Simon Glass | 2a80909 | 2016-06-12 23:30:27 -0600 | [diff] [blame] | 785 | SDHCI_CLOCK_BASE_SHIFT; |
Stefan Herbrechtsmeier | 6d0e34b | 2017-01-17 15:58:48 +0100 | [diff] [blame] | 786 | host->max_clk *= 1000000; |
Wenyou Yang | 0e0dcc1 | 2017-04-26 09:32:30 +0800 | [diff] [blame] | 787 | if (host->clk_mul) |
| 788 | host->max_clk *= host->clk_mul; |
Simon Glass | 2a80909 | 2016-06-12 23:30:27 -0600 | [diff] [blame] | 789 | } |
Stefan Herbrechtsmeier | 6d0e34b | 2017-01-17 15:58:48 +0100 | [diff] [blame] | 790 | if (host->max_clk == 0) { |
Masahiro Yamada | 6c67954 | 2016-08-25 16:07:35 +0900 | [diff] [blame] | 791 | printf("%s: Hardware doesn't specify base clock frequency\n", |
| 792 | __func__); |
Simon Glass | 2a80909 | 2016-06-12 23:30:27 -0600 | [diff] [blame] | 793 | return -EINVAL; |
Masahiro Yamada | 6c67954 | 2016-08-25 16:07:35 +0900 | [diff] [blame] | 794 | } |
Stefan Herbrechtsmeier | 6d0e34b | 2017-01-17 15:58:48 +0100 | [diff] [blame] | 795 | if (f_max && (f_max < host->max_clk)) |
| 796 | cfg->f_max = f_max; |
| 797 | else |
| 798 | cfg->f_max = host->max_clk; |
| 799 | if (f_min) |
| 800 | cfg->f_min = f_min; |
Simon Glass | 2a80909 | 2016-06-12 23:30:27 -0600 | [diff] [blame] | 801 | else { |
Jaehoon Chung | 14bed52 | 2016-07-26 19:06:24 +0900 | [diff] [blame] | 802 | if (SDHCI_GET_VERSION(host) >= SDHCI_SPEC_300) |
Simon Glass | 2a80909 | 2016-06-12 23:30:27 -0600 | [diff] [blame] | 803 | cfg->f_min = cfg->f_max / SDHCI_MAX_DIV_SPEC_300; |
| 804 | else |
| 805 | cfg->f_min = cfg->f_max / SDHCI_MAX_DIV_SPEC_200; |
| 806 | } |
| 807 | cfg->voltages = 0; |
| 808 | if (caps & SDHCI_CAN_VDD_330) |
| 809 | cfg->voltages |= MMC_VDD_32_33 | MMC_VDD_33_34; |
| 810 | if (caps & SDHCI_CAN_VDD_300) |
| 811 | cfg->voltages |= MMC_VDD_29_30 | MMC_VDD_30_31; |
| 812 | if (caps & SDHCI_CAN_VDD_180) |
| 813 | cfg->voltages |= MMC_VDD_165_195; |
| 814 | |
Masahiro Yamada | 3137e64 | 2016-08-25 16:07:36 +0900 | [diff] [blame] | 815 | if (host->quirks & SDHCI_QUIRK_BROKEN_VOLTAGE) |
| 816 | cfg->voltages |= host->voltages; |
| 817 | |
Masahiro Yamada | be165fb | 2017-12-30 02:00:08 +0900 | [diff] [blame] | 818 | cfg->host_caps |= MMC_MODE_HS | MMC_MODE_HS_52MHz | MMC_MODE_4BIT; |
Jaehoon Chung | 3fd0a9b | 2016-12-30 15:30:21 +0900 | [diff] [blame] | 819 | |
| 820 | /* Since Host Controller Version3.0 */ |
Jaehoon Chung | 14bed52 | 2016-07-26 19:06:24 +0900 | [diff] [blame] | 821 | if (SDHCI_GET_VERSION(host) >= SDHCI_SPEC_300) { |
Jaehoon Chung | ecd7b24 | 2016-12-30 15:30:11 +0900 | [diff] [blame] | 822 | if (!(caps & SDHCI_CAN_DO_8BIT)) |
| 823 | cfg->host_caps &= ~MMC_MODE_8BIT; |
Simon Glass | 2a80909 | 2016-06-12 23:30:27 -0600 | [diff] [blame] | 824 | } |
| 825 | |
Hannes Schmelzer | 88a5712 | 2018-03-07 08:00:56 +0100 | [diff] [blame] | 826 | if (host->quirks & SDHCI_QUIRK_BROKEN_HISPD_MODE) { |
| 827 | cfg->host_caps &= ~MMC_MODE_HS; |
| 828 | cfg->host_caps &= ~MMC_MODE_HS_52MHz; |
| 829 | } |
| 830 | |
Siva Durga Prasad Paladugu | b8e25ef | 2018-04-19 12:37:08 +0530 | [diff] [blame] | 831 | if (!(cfg->voltages & MMC_VDD_165_195) || |
| 832 | (host->quirks & SDHCI_QUIRK_NO_1_8_V)) |
| 833 | caps_1 &= ~(SDHCI_SUPPORT_SDR104 | SDHCI_SUPPORT_SDR50 | |
| 834 | SDHCI_SUPPORT_DDR50); |
| 835 | |
| 836 | if (caps_1 & (SDHCI_SUPPORT_SDR104 | SDHCI_SUPPORT_SDR50 | |
| 837 | SDHCI_SUPPORT_DDR50)) |
| 838 | cfg->host_caps |= MMC_CAP(UHS_SDR12) | MMC_CAP(UHS_SDR25); |
| 839 | |
| 840 | if (caps_1 & SDHCI_SUPPORT_SDR104) { |
| 841 | cfg->host_caps |= MMC_CAP(UHS_SDR104) | MMC_CAP(UHS_SDR50); |
| 842 | /* |
| 843 | * SD3.0: SDR104 is supported so (for eMMC) the caps2 |
| 844 | * field can be promoted to support HS200. |
| 845 | */ |
| 846 | cfg->host_caps |= MMC_CAP(MMC_HS_200); |
| 847 | } else if (caps_1 & SDHCI_SUPPORT_SDR50) { |
| 848 | cfg->host_caps |= MMC_CAP(UHS_SDR50); |
| 849 | } |
| 850 | |
| 851 | if (caps_1 & SDHCI_SUPPORT_DDR50) |
| 852 | cfg->host_caps |= MMC_CAP(UHS_DDR50); |
| 853 | |
Jaehoon Chung | 14bed52 | 2016-07-26 19:06:24 +0900 | [diff] [blame] | 854 | if (host->host_caps) |
| 855 | cfg->host_caps |= host->host_caps; |
Simon Glass | 2a80909 | 2016-06-12 23:30:27 -0600 | [diff] [blame] | 856 | |
| 857 | cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT; |
| 858 | |
| 859 | return 0; |
| 860 | } |
| 861 | |
Simon Glass | ef1e4ed | 2016-06-12 23:30:28 -0600 | [diff] [blame] | 862 | #ifdef CONFIG_BLK |
| 863 | int sdhci_bind(struct udevice *dev, struct mmc *mmc, struct mmc_config *cfg) |
| 864 | { |
| 865 | return mmc_bind(dev, mmc, cfg); |
| 866 | } |
| 867 | #else |
Stefan Herbrechtsmeier | 6d0e34b | 2017-01-17 15:58:48 +0100 | [diff] [blame] | 868 | int add_sdhci(struct sdhci_host *host, u32 f_max, u32 f_min) |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 869 | { |
Masahiro Yamada | 6c67954 | 2016-08-25 16:07:35 +0900 | [diff] [blame] | 870 | int ret; |
| 871 | |
Stefan Herbrechtsmeier | 6d0e34b | 2017-01-17 15:58:48 +0100 | [diff] [blame] | 872 | ret = sdhci_setup_cfg(&host->cfg, host, f_max, f_min); |
Masahiro Yamada | 6c67954 | 2016-08-25 16:07:35 +0900 | [diff] [blame] | 873 | if (ret) |
| 874 | return ret; |
Jaehoon Chung | 236bfec | 2012-04-23 02:36:26 +0000 | [diff] [blame] | 875 | |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 876 | host->mmc = mmc_create(&host->cfg, host); |
| 877 | if (host->mmc == NULL) { |
| 878 | printf("%s: mmc create fail!\n", __func__); |
Jaehoon Chung | 2cb5d67 | 2016-09-26 08:10:02 +0900 | [diff] [blame] | 879 | return -ENOMEM; |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 880 | } |
Lei Wen | af62a55 | 2011-06-28 21:50:06 +0000 | [diff] [blame] | 881 | |
| 882 | return 0; |
| 883 | } |
Simon Glass | ef1e4ed | 2016-06-12 23:30:28 -0600 | [diff] [blame] | 884 | #endif |