Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Kuo-Jung Su | d123ab8 | 2013-05-06 20:32:51 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Faraday MMC/SD Host Controller |
| 4 | * |
| 5 | * (C) Copyright 2010 Faraday Technology |
| 6 | * Dante Su <dantesu@faraday-tech.com> |
| 7 | * |
Rick Chen | 47ec48b | 2018-03-20 15:52:58 +0800 | [diff] [blame] | 8 | * Copyright 2018 Andes Technology, Inc. |
| 9 | * Author: Rick Chen (rick@andestech.com) |
Kuo-Jung Su | d123ab8 | 2013-05-06 20:32:51 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
Rick Chen | 47ec48b | 2018-03-20 15:52:58 +0800 | [diff] [blame] | 12 | #include <clk.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Kuo-Jung Su | d123ab8 | 2013-05-06 20:32:51 +0000 | [diff] [blame] | 14 | #include <malloc.h> |
| 15 | #include <part.h> |
| 16 | #include <mmc.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 17 | #include <asm/global_data.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 18 | #include <linux/bitops.h> |
Rick Chen | f7a4adb | 2017-08-28 16:44:11 +0800 | [diff] [blame] | 19 | #include <linux/io.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 20 | #include <linux/errno.h> |
Kuo-Jung Su | d123ab8 | 2013-05-06 20:32:51 +0000 | [diff] [blame] | 21 | #include <asm/byteorder.h> |
| 22 | #include <faraday/ftsdc010.h> |
Rick Chen | f7a4adb | 2017-08-28 16:44:11 +0800 | [diff] [blame] | 23 | #include "ftsdc010_mci.h" |
Rick Chen | 47ec48b | 2018-03-20 15:52:58 +0800 | [diff] [blame] | 24 | #include <dm.h> |
| 25 | #include <dt-structs.h> |
| 26 | #include <errno.h> |
| 27 | #include <mapmem.h> |
| 28 | #include <pwrseq.h> |
| 29 | #include <syscon.h> |
| 30 | #include <linux/err.h> |
| 31 | |
Sergei Antonov | 391d0f3 | 2022-09-02 10:40:10 +0300 | [diff] [blame] | 32 | #define CFG_CMD_TIMEOUT (CONFIG_SYS_HZ >> 2) /* 250 ms */ |
Kuo-Jung Su | d123ab8 | 2013-05-06 20:32:51 +0000 | [diff] [blame] | 33 | #define CFG_RST_TIMEOUT CONFIG_SYS_HZ /* 1 sec reset timeout */ |
| 34 | |
Rick Chen | 47ec48b | 2018-03-20 15:52:58 +0800 | [diff] [blame] | 35 | #if CONFIG_IS_ENABLED(OF_PLATDATA) |
| 36 | struct ftsdc010 { |
| 37 | fdt32_t bus_width; |
| 38 | bool cap_mmc_highspeed; |
| 39 | bool cap_sd_highspeed; |
| 40 | fdt32_t clock_freq_min_max[2]; |
| 41 | struct phandle_2_cell clocks[4]; |
| 42 | fdt32_t fifo_depth; |
| 43 | fdt32_t reg[2]; |
| 44 | }; |
| 45 | #endif |
| 46 | |
| 47 | struct ftsdc010_plat { |
| 48 | #if CONFIG_IS_ENABLED(OF_PLATDATA) |
| 49 | struct ftsdc010 dtplat; |
| 50 | #endif |
| 51 | struct mmc_config cfg; |
| 52 | struct mmc mmc; |
| 53 | }; |
| 54 | |
| 55 | struct ftsdc_priv { |
| 56 | struct clk clk; |
| 57 | struct ftsdc010_chip chip; |
| 58 | int fifo_depth; |
| 59 | bool fifo_mode; |
| 60 | u32 minmax[2]; |
| 61 | }; |
| 62 | |
Kuo-Jung Su | d123ab8 | 2013-05-06 20:32:51 +0000 | [diff] [blame] | 63 | static inline int ftsdc010_send_cmd(struct mmc *mmc, struct mmc_cmd *mmc_cmd) |
| 64 | { |
| 65 | struct ftsdc010_chip *chip = mmc->priv; |
| 66 | struct ftsdc010_mmc __iomem *regs = chip->regs; |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 67 | int ret = -ETIMEDOUT; |
Kuo-Jung Su | d123ab8 | 2013-05-06 20:32:51 +0000 | [diff] [blame] | 68 | uint32_t ts, st; |
| 69 | uint32_t cmd = FTSDC010_CMD_IDX(mmc_cmd->cmdidx); |
| 70 | uint32_t arg = mmc_cmd->cmdarg; |
| 71 | uint32_t flags = mmc_cmd->resp_type; |
| 72 | |
| 73 | cmd |= FTSDC010_CMD_CMD_EN; |
| 74 | |
| 75 | if (chip->acmd) { |
| 76 | cmd |= FTSDC010_CMD_APP_CMD; |
| 77 | chip->acmd = 0; |
| 78 | } |
| 79 | |
| 80 | if (flags & MMC_RSP_PRESENT) |
| 81 | cmd |= FTSDC010_CMD_NEED_RSP; |
| 82 | |
| 83 | if (flags & MMC_RSP_136) |
| 84 | cmd |= FTSDC010_CMD_LONG_RSP; |
| 85 | |
| 86 | writel(FTSDC010_STATUS_RSP_MASK | FTSDC010_STATUS_CMD_SEND, |
| 87 | ®s->clr); |
| 88 | writel(arg, ®s->argu); |
| 89 | writel(cmd, ®s->cmd); |
| 90 | |
| 91 | if (!(flags & (MMC_RSP_PRESENT | MMC_RSP_136))) { |
| 92 | for (ts = get_timer(0); get_timer(ts) < CFG_CMD_TIMEOUT; ) { |
| 93 | if (readl(®s->status) & FTSDC010_STATUS_CMD_SEND) { |
| 94 | writel(FTSDC010_STATUS_CMD_SEND, ®s->clr); |
| 95 | ret = 0; |
| 96 | break; |
| 97 | } |
| 98 | } |
| 99 | } else { |
| 100 | st = 0; |
| 101 | for (ts = get_timer(0); get_timer(ts) < CFG_CMD_TIMEOUT; ) { |
| 102 | st = readl(®s->status); |
| 103 | writel(st & FTSDC010_STATUS_RSP_MASK, ®s->clr); |
| 104 | if (st & FTSDC010_STATUS_RSP_MASK) |
| 105 | break; |
| 106 | } |
| 107 | if (st & FTSDC010_STATUS_RSP_CRC_OK) { |
| 108 | if (flags & MMC_RSP_136) { |
| 109 | mmc_cmd->response[0] = readl(®s->rsp3); |
| 110 | mmc_cmd->response[1] = readl(®s->rsp2); |
| 111 | mmc_cmd->response[2] = readl(®s->rsp1); |
| 112 | mmc_cmd->response[3] = readl(®s->rsp0); |
| 113 | } else { |
| 114 | mmc_cmd->response[0] = readl(®s->rsp0); |
| 115 | } |
| 116 | ret = 0; |
| 117 | } else { |
| 118 | debug("ftsdc010: rsp err (cmd=%d, st=0x%x)\n", |
| 119 | mmc_cmd->cmdidx, st); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | if (ret) { |
| 124 | debug("ftsdc010: cmd timeout (op code=%d)\n", |
| 125 | mmc_cmd->cmdidx); |
| 126 | } else if (mmc_cmd->cmdidx == MMC_CMD_APP_CMD) { |
| 127 | chip->acmd = 1; |
| 128 | } |
| 129 | |
| 130 | return ret; |
| 131 | } |
| 132 | |
| 133 | static void ftsdc010_clkset(struct mmc *mmc, uint32_t rate) |
| 134 | { |
| 135 | struct ftsdc010_chip *chip = mmc->priv; |
| 136 | struct ftsdc010_mmc __iomem *regs = chip->regs; |
| 137 | uint32_t div; |
| 138 | |
| 139 | for (div = 0; div < 0x7f; ++div) { |
| 140 | if (rate >= chip->sclk / (2 * (div + 1))) |
| 141 | break; |
| 142 | } |
| 143 | chip->rate = chip->sclk / (2 * (div + 1)); |
| 144 | |
| 145 | writel(FTSDC010_CCR_CLK_DIV(div), ®s->ccr); |
| 146 | |
| 147 | if (IS_SD(mmc)) { |
| 148 | setbits_le32(®s->ccr, FTSDC010_CCR_CLK_SD); |
| 149 | |
| 150 | if (chip->rate > 25000000) |
| 151 | setbits_le32(®s->ccr, FTSDC010_CCR_CLK_HISPD); |
| 152 | else |
| 153 | clrbits_le32(®s->ccr, FTSDC010_CCR_CLK_HISPD); |
| 154 | } |
| 155 | } |
| 156 | |
Kuo-Jung Su | d123ab8 | 2013-05-06 20:32:51 +0000 | [diff] [blame] | 157 | static int ftsdc010_wait(struct ftsdc010_mmc __iomem *regs, uint32_t mask) |
| 158 | { |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 159 | int ret = -ETIMEDOUT; |
Rick Chen | f7a4adb | 2017-08-28 16:44:11 +0800 | [diff] [blame] | 160 | uint32_t st, timeout = 10000000; |
| 161 | while (timeout--) { |
Kuo-Jung Su | d123ab8 | 2013-05-06 20:32:51 +0000 | [diff] [blame] | 162 | st = readl(®s->status); |
| 163 | if (!(st & mask)) |
| 164 | continue; |
| 165 | writel(st & mask, ®s->clr); |
| 166 | ret = 0; |
| 167 | break; |
| 168 | } |
| 169 | |
Rick Chen | 22223f0 | 2017-08-25 14:02:13 +0800 | [diff] [blame] | 170 | if (ret){ |
Kuo-Jung Su | d123ab8 | 2013-05-06 20:32:51 +0000 | [diff] [blame] | 171 | debug("ftsdc010: wait st(0x%x) timeout\n", mask); |
Rick Chen | 22223f0 | 2017-08-25 14:02:13 +0800 | [diff] [blame] | 172 | } |
Kuo-Jung Su | d123ab8 | 2013-05-06 20:32:51 +0000 | [diff] [blame] | 173 | |
| 174 | return ret; |
| 175 | } |
| 176 | |
| 177 | /* |
| 178 | * u-boot mmc api |
| 179 | */ |
Rick Chen | f7a4adb | 2017-08-28 16:44:11 +0800 | [diff] [blame] | 180 | static int ftsdc010_request(struct udevice *dev, struct mmc_cmd *cmd, |
| 181 | struct mmc_data *data) |
| 182 | { |
| 183 | struct mmc *mmc = mmc_get_mmc_dev(dev); |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 184 | int ret = -EOPNOTSUPP; |
Kuo-Jung Su | d123ab8 | 2013-05-06 20:32:51 +0000 | [diff] [blame] | 185 | uint32_t len = 0; |
| 186 | struct ftsdc010_chip *chip = mmc->priv; |
| 187 | struct ftsdc010_mmc __iomem *regs = chip->regs; |
| 188 | |
| 189 | if (data && (data->flags & MMC_DATA_WRITE) && chip->wprot) { |
| 190 | printf("ftsdc010: the card is write protected!\n"); |
| 191 | return ret; |
| 192 | } |
| 193 | |
| 194 | if (data) { |
| 195 | uint32_t dcr; |
| 196 | |
| 197 | len = data->blocksize * data->blocks; |
| 198 | |
| 199 | /* 1. data disable + fifo reset */ |
Gabor Juhos | 67a38f1 | 2013-05-26 12:11:27 +0200 | [diff] [blame] | 200 | dcr = 0; |
| 201 | #ifdef CONFIG_FTSDC010_SDIO |
| 202 | dcr |= FTSDC010_DCR_FIFO_RST; |
| 203 | #endif |
| 204 | writel(dcr, ®s->dcr); |
Kuo-Jung Su | d123ab8 | 2013-05-06 20:32:51 +0000 | [diff] [blame] | 205 | |
| 206 | /* 2. clear status register */ |
| 207 | writel(FTSDC010_STATUS_DATA_MASK | FTSDC010_STATUS_FIFO_URUN |
| 208 | | FTSDC010_STATUS_FIFO_ORUN, ®s->clr); |
| 209 | |
| 210 | /* 3. data timeout (1 sec) */ |
| 211 | writel(chip->rate, ®s->dtr); |
| 212 | |
| 213 | /* 4. data length (bytes) */ |
| 214 | writel(len, ®s->dlr); |
| 215 | |
| 216 | /* 5. data enable */ |
| 217 | dcr = (ffs(data->blocksize) - 1) | FTSDC010_DCR_DATA_EN; |
| 218 | if (data->flags & MMC_DATA_WRITE) |
| 219 | dcr |= FTSDC010_DCR_DATA_WRITE; |
| 220 | writel(dcr, ®s->dcr); |
| 221 | } |
| 222 | |
| 223 | ret = ftsdc010_send_cmd(mmc, cmd); |
| 224 | if (ret) { |
| 225 | printf("ftsdc010: CMD%d failed\n", cmd->cmdidx); |
| 226 | return ret; |
| 227 | } |
| 228 | |
| 229 | if (!data) |
| 230 | return ret; |
| 231 | |
| 232 | if (data->flags & MMC_DATA_WRITE) { |
| 233 | const uint8_t *buf = (const uint8_t *)data->src; |
| 234 | |
| 235 | while (len > 0) { |
| 236 | int wlen; |
| 237 | |
| 238 | /* wait for tx ready */ |
| 239 | ret = ftsdc010_wait(regs, FTSDC010_STATUS_FIFO_URUN); |
| 240 | if (ret) |
| 241 | break; |
| 242 | |
| 243 | /* write bytes to ftsdc010 */ |
| 244 | for (wlen = 0; wlen < len && wlen < chip->fifo; ) { |
| 245 | writel(*(uint32_t *)buf, ®s->dwr); |
| 246 | buf += 4; |
| 247 | wlen += 4; |
| 248 | } |
| 249 | |
| 250 | len -= wlen; |
| 251 | } |
| 252 | |
| 253 | } else { |
| 254 | uint8_t *buf = (uint8_t *)data->dest; |
| 255 | |
| 256 | while (len > 0) { |
| 257 | int rlen; |
| 258 | |
| 259 | /* wait for rx ready */ |
| 260 | ret = ftsdc010_wait(regs, FTSDC010_STATUS_FIFO_ORUN); |
| 261 | if (ret) |
| 262 | break; |
| 263 | |
| 264 | /* fetch bytes from ftsdc010 */ |
| 265 | for (rlen = 0; rlen < len && rlen < chip->fifo; ) { |
| 266 | *(uint32_t *)buf = readl(®s->dwr); |
| 267 | buf += 4; |
| 268 | rlen += 4; |
| 269 | } |
| 270 | |
| 271 | len -= rlen; |
| 272 | } |
| 273 | |
| 274 | } |
| 275 | |
| 276 | if (!ret) { |
| 277 | ret = ftsdc010_wait(regs, |
Rick Chen | 22223f0 | 2017-08-25 14:02:13 +0800 | [diff] [blame] | 278 | FTSDC010_STATUS_DATA_END | FTSDC010_STATUS_DATA_CRC_OK); |
Kuo-Jung Su | d123ab8 | 2013-05-06 20:32:51 +0000 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | return ret; |
| 282 | } |
| 283 | |
Rick Chen | f7a4adb | 2017-08-28 16:44:11 +0800 | [diff] [blame] | 284 | static int ftsdc010_set_ios(struct udevice *dev) |
| 285 | { |
| 286 | struct mmc *mmc = mmc_get_mmc_dev(dev); |
Kuo-Jung Su | d123ab8 | 2013-05-06 20:32:51 +0000 | [diff] [blame] | 287 | struct ftsdc010_chip *chip = mmc->priv; |
| 288 | struct ftsdc010_mmc __iomem *regs = chip->regs; |
| 289 | |
| 290 | ftsdc010_clkset(mmc, mmc->clock); |
| 291 | |
| 292 | clrbits_le32(®s->bwr, FTSDC010_BWR_MODE_MASK); |
| 293 | switch (mmc->bus_width) { |
| 294 | case 4: |
| 295 | setbits_le32(®s->bwr, FTSDC010_BWR_MODE_4BIT); |
| 296 | break; |
| 297 | case 8: |
| 298 | setbits_le32(®s->bwr, FTSDC010_BWR_MODE_8BIT); |
| 299 | break; |
| 300 | default: |
| 301 | setbits_le32(®s->bwr, FTSDC010_BWR_MODE_1BIT); |
| 302 | break; |
| 303 | } |
Jaehoon Chung | b6cd1d3 | 2016-12-30 15:30:16 +0900 | [diff] [blame] | 304 | |
| 305 | return 0; |
Kuo-Jung Su | d123ab8 | 2013-05-06 20:32:51 +0000 | [diff] [blame] | 306 | } |
| 307 | |
Rick Chen | f7a4adb | 2017-08-28 16:44:11 +0800 | [diff] [blame] | 308 | static int ftsdc010_get_cd(struct udevice *dev) |
Kuo-Jung Su | d123ab8 | 2013-05-06 20:32:51 +0000 | [diff] [blame] | 309 | { |
Rick Chen | f7a4adb | 2017-08-28 16:44:11 +0800 | [diff] [blame] | 310 | struct mmc *mmc = mmc_get_mmc_dev(dev); |
Kuo-Jung Su | d123ab8 | 2013-05-06 20:32:51 +0000 | [diff] [blame] | 311 | struct ftsdc010_chip *chip = mmc->priv; |
| 312 | struct ftsdc010_mmc __iomem *regs = chip->regs; |
Rick Chen | f7a4adb | 2017-08-28 16:44:11 +0800 | [diff] [blame] | 313 | return !(readl(®s->status) & FTSDC010_STATUS_CARD_DETECT); |
| 314 | } |
Kuo-Jung Su | d123ab8 | 2013-05-06 20:32:51 +0000 | [diff] [blame] | 315 | |
Rick Chen | f7a4adb | 2017-08-28 16:44:11 +0800 | [diff] [blame] | 316 | static int ftsdc010_get_wp(struct udevice *dev) |
| 317 | { |
| 318 | struct mmc *mmc = mmc_get_mmc_dev(dev); |
Rick Chen | f7a4adb | 2017-08-28 16:44:11 +0800 | [diff] [blame] | 319 | struct ftsdc010_chip *chip = mmc->priv; |
| 320 | struct ftsdc010_mmc __iomem *regs = chip->regs; |
Kuo-Jung Su | d123ab8 | 2013-05-06 20:32:51 +0000 | [diff] [blame] | 321 | if (readl(®s->status) & FTSDC010_STATUS_WRITE_PROT) { |
| 322 | printf("ftsdc010: write protected\n"); |
| 323 | chip->wprot = 1; |
| 324 | } |
| 325 | |
Rick Chen | f7a4adb | 2017-08-28 16:44:11 +0800 | [diff] [blame] | 326 | return 0; |
| 327 | } |
| 328 | |
| 329 | static int ftsdc010_init(struct mmc *mmc) |
| 330 | { |
| 331 | struct ftsdc010_chip *chip = mmc->priv; |
| 332 | struct ftsdc010_mmc __iomem *regs = chip->regs; |
| 333 | uint32_t ts; |
| 334 | |
Kuo-Jung Su | d123ab8 | 2013-05-06 20:32:51 +0000 | [diff] [blame] | 335 | chip->fifo = (readl(®s->feature) & 0xff) << 2; |
| 336 | |
| 337 | /* 1. chip reset */ |
| 338 | writel(FTSDC010_CMD_SDC_RST, ®s->cmd); |
| 339 | for (ts = get_timer(0); get_timer(ts) < CFG_RST_TIMEOUT; ) { |
| 340 | if (readl(®s->cmd) & FTSDC010_CMD_SDC_RST) |
| 341 | continue; |
| 342 | break; |
| 343 | } |
| 344 | if (readl(®s->cmd) & FTSDC010_CMD_SDC_RST) { |
| 345 | printf("ftsdc010: reset failed\n"); |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 346 | return -EOPNOTSUPP; |
Kuo-Jung Su | d123ab8 | 2013-05-06 20:32:51 +0000 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | /* 2. enter low speed mode (400k card detection) */ |
| 350 | ftsdc010_clkset(mmc, 400000); |
| 351 | |
| 352 | /* 3. interrupt disabled */ |
| 353 | writel(0, ®s->int_mask); |
| 354 | |
| 355 | return 0; |
| 356 | } |
| 357 | |
Rick Chen | 47ec48b | 2018-03-20 15:52:58 +0800 | [diff] [blame] | 358 | static int ftsdc010_probe(struct udevice *dev) |
Rick Chen | f7a4adb | 2017-08-28 16:44:11 +0800 | [diff] [blame] | 359 | { |
| 360 | struct mmc *mmc = mmc_get_mmc_dev(dev); |
| 361 | return ftsdc010_init(mmc); |
| 362 | } |
| 363 | |
Rick Chen | 47ec48b | 2018-03-20 15:52:58 +0800 | [diff] [blame] | 364 | const struct dm_mmc_ops dm_ftsdc010_mmc_ops = { |
Rick Chen | f7a4adb | 2017-08-28 16:44:11 +0800 | [diff] [blame] | 365 | .send_cmd = ftsdc010_request, |
| 366 | .set_ios = ftsdc010_set_ios, |
| 367 | .get_cd = ftsdc010_get_cd, |
| 368 | .get_wp = ftsdc010_get_wp, |
| 369 | }; |
Rick Chen | f7a4adb | 2017-08-28 16:44:11 +0800 | [diff] [blame] | 370 | |
Rick Chen | 47ec48b | 2018-03-20 15:52:58 +0800 | [diff] [blame] | 371 | static void ftsdc_setup_cfg(struct mmc_config *cfg, const char *name, int buswidth, |
Rick Chen | f7a4adb | 2017-08-28 16:44:11 +0800 | [diff] [blame] | 372 | uint caps, u32 max_clk, u32 min_clk) |
| 373 | { |
| 374 | cfg->name = name; |
| 375 | cfg->f_min = min_clk; |
| 376 | cfg->f_max = max_clk; |
| 377 | cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195; |
| 378 | cfg->host_caps = caps; |
| 379 | if (buswidth == 8) { |
| 380 | cfg->host_caps |= MMC_MODE_8BIT; |
| 381 | cfg->host_caps &= ~MMC_MODE_4BIT; |
| 382 | } else { |
| 383 | cfg->host_caps |= MMC_MODE_4BIT; |
| 384 | cfg->host_caps &= ~MMC_MODE_8BIT; |
| 385 | } |
Rick Chen | f7a4adb | 2017-08-28 16:44:11 +0800 | [diff] [blame] | 386 | cfg->part_type = PART_TYPE_DOS; |
| 387 | cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT; |
| 388 | } |
| 389 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 390 | static int ftsdc010_mmc_of_to_plat(struct udevice *dev) |
Rick Chen | f7a4adb | 2017-08-28 16:44:11 +0800 | [diff] [blame] | 391 | { |
Rick Chen | 47ec48b | 2018-03-20 15:52:58 +0800 | [diff] [blame] | 392 | struct ftsdc_priv *priv = dev_get_priv(dev); |
| 393 | struct ftsdc010_chip *chip = &priv->chip; |
Simon Glass | 47f6469 | 2021-08-07 07:24:05 -0600 | [diff] [blame] | 394 | |
Simon Glass | 6d70ba0 | 2021-08-07 07:24:06 -0600 | [diff] [blame] | 395 | if (CONFIG_IS_ENABLED(OF_REAL)) { |
| 396 | chip->name = dev->name; |
| 397 | chip->ioaddr = dev_read_addr_ptr(dev); |
| 398 | chip->buswidth = dev_read_u32_default(dev, "bus-width", 4); |
| 399 | chip->priv = dev; |
| 400 | priv->fifo_depth = dev_read_u32_default(dev, "fifo-depth", 0); |
| 401 | priv->fifo_mode = dev_read_bool(dev, "fifo-mode"); |
| 402 | if (dev_read_u32_array(dev, "clock-freq-min-max", priv->minmax, 2)) { |
| 403 | if (dev_read_u32(dev, "max-frequency", &priv->minmax[1])) |
| 404 | return -EINVAL; |
Rick Chen | 47ec48b | 2018-03-20 15:52:58 +0800 | [diff] [blame] | 405 | |
Simon Glass | 6d70ba0 | 2021-08-07 07:24:06 -0600 | [diff] [blame] | 406 | priv->minmax[0] = 400000; /* 400 kHz */ |
| 407 | } else { |
| 408 | debug("%s: 'clock-freq-min-max' property was deprecated.\n", |
| 409 | __func__); |
| 410 | } |
Rick Chen | 47ec48b | 2018-03-20 15:52:58 +0800 | [diff] [blame] | 411 | } |
Rick Chen | 47ec48b | 2018-03-20 15:52:58 +0800 | [diff] [blame] | 412 | chip->sclk = priv->minmax[1]; |
| 413 | chip->regs = chip->ioaddr; |
Simon Glass | 6d70ba0 | 2021-08-07 07:24:06 -0600 | [diff] [blame] | 414 | |
Rick Chen | 47ec48b | 2018-03-20 15:52:58 +0800 | [diff] [blame] | 415 | return 0; |
Rick Chen | f7a4adb | 2017-08-28 16:44:11 +0800 | [diff] [blame] | 416 | } |
Rick Chen | 47ec48b | 2018-03-20 15:52:58 +0800 | [diff] [blame] | 417 | |
| 418 | static int ftsdc010_mmc_probe(struct udevice *dev) |
| 419 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 420 | struct ftsdc010_plat *plat = dev_get_plat(dev); |
Rick Chen | 47ec48b | 2018-03-20 15:52:58 +0800 | [diff] [blame] | 421 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
| 422 | struct ftsdc_priv *priv = dev_get_priv(dev); |
| 423 | struct ftsdc010_chip *chip = &priv->chip; |
| 424 | struct udevice *pwr_dev __maybe_unused; |
| 425 | |
| 426 | #if CONFIG_IS_ENABLED(OF_PLATDATA) |
| 427 | int ret; |
| 428 | struct ftsdc010 *dtplat = &plat->dtplat; |
| 429 | chip->name = dev->name; |
| 430 | chip->ioaddr = map_sysmem(dtplat->reg[0], dtplat->reg[1]); |
| 431 | chip->buswidth = dtplat->bus_width; |
| 432 | chip->priv = dev; |
| 433 | chip->dev_index = 1; |
| 434 | memcpy(priv->minmax, dtplat->clock_freq_min_max, sizeof(priv->minmax)); |
Simon Glass | 1257efc | 2021-08-07 07:24:09 -0600 | [diff] [blame] | 435 | ret = clk_get_by_phandle(dev, dtplat->clocks, &priv->clk); |
Rick Chen | 47ec48b | 2018-03-20 15:52:58 +0800 | [diff] [blame] | 436 | if (ret < 0) |
| 437 | return ret; |
| 438 | #endif |
| 439 | |
| 440 | if (dev_read_bool(dev, "cap-mmc-highspeed") || \ |
| 441 | dev_read_bool(dev, "cap-sd-highspeed")) |
| 442 | chip->caps |= MMC_MODE_HS | MMC_MODE_HS_52MHz; |
| 443 | |
| 444 | ftsdc_setup_cfg(&plat->cfg, dev->name, chip->buswidth, chip->caps, |
| 445 | priv->minmax[1] , priv->minmax[0]); |
| 446 | chip->mmc = &plat->mmc; |
| 447 | chip->mmc->priv = &priv->chip; |
| 448 | chip->mmc->dev = dev; |
| 449 | upriv->mmc = chip->mmc; |
| 450 | return ftsdc010_probe(dev); |
| 451 | } |
| 452 | |
| 453 | int ftsdc010_mmc_bind(struct udevice *dev) |
| 454 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 455 | struct ftsdc010_plat *plat = dev_get_plat(dev); |
Rick Chen | 47ec48b | 2018-03-20 15:52:58 +0800 | [diff] [blame] | 456 | |
| 457 | return mmc_bind(dev, &plat->mmc, &plat->cfg); |
| 458 | } |
| 459 | |
| 460 | static const struct udevice_id ftsdc010_mmc_ids[] = { |
Rick Chen | 7e1861c | 2018-05-29 11:00:28 +0800 | [diff] [blame] | 461 | { .compatible = "andestech,atfsdc010" }, |
Rick Chen | 47ec48b | 2018-03-20 15:52:58 +0800 | [diff] [blame] | 462 | { } |
| 463 | }; |
| 464 | |
| 465 | U_BOOT_DRIVER(ftsdc010_mmc) = { |
| 466 | .name = "ftsdc010_mmc", |
| 467 | .id = UCLASS_MMC, |
| 468 | .of_match = ftsdc010_mmc_ids, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 469 | .of_to_plat = ftsdc010_mmc_of_to_plat, |
Rick Chen | 47ec48b | 2018-03-20 15:52:58 +0800 | [diff] [blame] | 470 | .ops = &dm_ftsdc010_mmc_ops, |
| 471 | .bind = ftsdc010_mmc_bind, |
| 472 | .probe = ftsdc010_mmc_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 473 | .priv_auto = sizeof(struct ftsdc_priv), |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 474 | .plat_auto = sizeof(struct ftsdc010_plat), |
Rick Chen | 47ec48b | 2018-03-20 15:52:58 +0800 | [diff] [blame] | 475 | }; |