.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (c) 2014-2015 MediaTek Inc. |
---|
3 | 4 | * Author: Chaotian.Jing <chaotian.jing@mediatek.com> |
---|
4 | | - * |
---|
5 | | - * This program is free software; you can redistribute it and/or modify |
---|
6 | | - * it under the terms of the GNU General Public License version 2 as |
---|
7 | | - * published by the Free Software Foundation. |
---|
8 | | - * |
---|
9 | | - * This program is distributed in the hope that it will be useful, |
---|
10 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | | - * GNU General Public License for more details. |
---|
13 | 5 | */ |
---|
14 | 6 | |
---|
15 | 7 | #include <linux/module.h> |
---|
16 | 8 | #include <linux/clk.h> |
---|
17 | 9 | #include <linux/delay.h> |
---|
18 | 10 | #include <linux/dma-mapping.h> |
---|
| 11 | +#include <linux/iopoll.h> |
---|
19 | 12 | #include <linux/ioport.h> |
---|
20 | 13 | #include <linux/irq.h> |
---|
21 | 14 | #include <linux/of_address.h> |
---|
.. | .. |
---|
30 | 23 | #include <linux/slab.h> |
---|
31 | 24 | #include <linux/spinlock.h> |
---|
32 | 25 | #include <linux/interrupt.h> |
---|
| 26 | +#include <linux/reset.h> |
---|
33 | 27 | |
---|
34 | 28 | #include <linux/mmc/card.h> |
---|
35 | 29 | #include <linux/mmc/core.h> |
---|
.. | .. |
---|
38 | 32 | #include <linux/mmc/sd.h> |
---|
39 | 33 | #include <linux/mmc/sdio.h> |
---|
40 | 34 | #include <linux/mmc/slot-gpio.h> |
---|
| 35 | + |
---|
| 36 | +#include "cqhci.h" |
---|
41 | 37 | |
---|
42 | 38 | #define MAX_BD_NUM 1024 |
---|
43 | 39 | |
---|
.. | .. |
---|
87 | 83 | #define SDC_FIFO_CFG 0x228 |
---|
88 | 84 | |
---|
89 | 85 | /*--------------------------------------------------------------------------*/ |
---|
| 86 | +/* Top Pad Register Offset */ |
---|
| 87 | +/*--------------------------------------------------------------------------*/ |
---|
| 88 | +#define EMMC_TOP_CONTROL 0x00 |
---|
| 89 | +#define EMMC_TOP_CMD 0x04 |
---|
| 90 | +#define EMMC50_PAD_DS_TUNE 0x0c |
---|
| 91 | + |
---|
| 92 | +/*--------------------------------------------------------------------------*/ |
---|
90 | 93 | /* Register Mask */ |
---|
91 | 94 | /*--------------------------------------------------------------------------*/ |
---|
92 | 95 | |
---|
.. | .. |
---|
129 | 132 | #define MSDC_PS_CDSTS (0x1 << 1) /* R */ |
---|
130 | 133 | #define MSDC_PS_CDDEBOUNCE (0xf << 12) /* RW */ |
---|
131 | 134 | #define MSDC_PS_DAT (0xff << 16) /* R */ |
---|
| 135 | +#define MSDC_PS_DATA1 (0x1 << 17) /* R */ |
---|
132 | 136 | #define MSDC_PS_CMD (0x1 << 24) /* R */ |
---|
133 | 137 | #define MSDC_PS_WP (0x1 << 31) /* R */ |
---|
134 | 138 | |
---|
.. | .. |
---|
152 | 156 | #define MSDC_INT_DMA_BDCSERR (0x1 << 17) /* W1C */ |
---|
153 | 157 | #define MSDC_INT_DMA_GPDCSERR (0x1 << 18) /* W1C */ |
---|
154 | 158 | #define MSDC_INT_DMA_PROTECT (0x1 << 19) /* W1C */ |
---|
| 159 | +#define MSDC_INT_CMDQ (0x1 << 28) /* W1C */ |
---|
155 | 160 | |
---|
156 | 161 | /* MSDC_INTEN mask */ |
---|
157 | 162 | #define MSDC_INTEN_MMCIRQ (0x1 << 0) /* RW */ |
---|
.. | .. |
---|
182 | 187 | /* SDC_CFG mask */ |
---|
183 | 188 | #define SDC_CFG_SDIOINTWKUP (0x1 << 0) /* RW */ |
---|
184 | 189 | #define SDC_CFG_INSWKUP (0x1 << 1) /* RW */ |
---|
| 190 | +#define SDC_CFG_WRDTOC (0x1fff << 2) /* RW */ |
---|
185 | 191 | #define SDC_CFG_BUSWIDTH (0x3 << 16) /* RW */ |
---|
186 | 192 | #define SDC_CFG_SDIO (0x1 << 19) /* RW */ |
---|
187 | 193 | #define SDC_CFG_SDIOIDE (0x1 << 20) /* RW */ |
---|
.. | .. |
---|
193 | 199 | #define SDC_STS_CMDBUSY (0x1 << 1) /* RW */ |
---|
194 | 200 | #define SDC_STS_SWR_COMPL (0x1 << 31) /* RW */ |
---|
195 | 201 | |
---|
| 202 | +#define SDC_DAT1_IRQ_TRIGGER (0x1 << 19) /* RW */ |
---|
196 | 203 | /* SDC_ADV_CFG0 mask */ |
---|
197 | 204 | #define SDC_RX_ENHANCE_EN (0x1 << 20) /* RW */ |
---|
198 | 205 | |
---|
.. | .. |
---|
229 | 236 | #define MSDC_PATCH_BIT_DECRCTMO (0x1 << 30) /* RW */ |
---|
230 | 237 | |
---|
231 | 238 | #define MSDC_PATCH_BIT1_CMDTA (0x7 << 3) /* RW */ |
---|
| 239 | +#define MSDC_PB1_BUSY_CHECK_SEL (0x1 << 7) /* RW */ |
---|
232 | 240 | #define MSDC_PATCH_BIT1_STOP_DLY (0xf << 8) /* RW */ |
---|
233 | 241 | |
---|
234 | 242 | #define MSDC_PATCH_BIT2_CFGRESP (0x1 << 15) /* RW */ |
---|
.. | .. |
---|
262 | 270 | #define SDC_FIFO_CFG_WRVALIDSEL (0x1 << 24) /* RW */ |
---|
263 | 271 | #define SDC_FIFO_CFG_RDVALIDSEL (0x1 << 25) /* RW */ |
---|
264 | 272 | |
---|
| 273 | +/* EMMC_TOP_CONTROL mask */ |
---|
| 274 | +#define PAD_RXDLY_SEL (0x1 << 0) /* RW */ |
---|
| 275 | +#define DELAY_EN (0x1 << 1) /* RW */ |
---|
| 276 | +#define PAD_DAT_RD_RXDLY2 (0x1f << 2) /* RW */ |
---|
| 277 | +#define PAD_DAT_RD_RXDLY (0x1f << 7) /* RW */ |
---|
| 278 | +#define PAD_DAT_RD_RXDLY2_SEL (0x1 << 12) /* RW */ |
---|
| 279 | +#define PAD_DAT_RD_RXDLY_SEL (0x1 << 13) /* RW */ |
---|
| 280 | +#define DATA_K_VALUE_SEL (0x1 << 14) /* RW */ |
---|
| 281 | +#define SDC_RX_ENH_EN (0x1 << 15) /* TW */ |
---|
| 282 | + |
---|
| 283 | +/* EMMC_TOP_CMD mask */ |
---|
| 284 | +#define PAD_CMD_RXDLY2 (0x1f << 0) /* RW */ |
---|
| 285 | +#define PAD_CMD_RXDLY (0x1f << 5) /* RW */ |
---|
| 286 | +#define PAD_CMD_RD_RXDLY2_SEL (0x1 << 10) /* RW */ |
---|
| 287 | +#define PAD_CMD_RD_RXDLY_SEL (0x1 << 11) /* RW */ |
---|
| 288 | +#define PAD_CMD_TX_DLY (0x1f << 12) /* RW */ |
---|
| 289 | + |
---|
265 | 290 | #define REQ_CMD_EIO (0x1 << 0) |
---|
266 | 291 | #define REQ_CMD_TMO (0x1 << 1) |
---|
267 | 292 | #define REQ_DAT_ERR (0x1 << 2) |
---|
.. | .. |
---|
276 | 301 | #define MTK_MMC_AUTOSUSPEND_DELAY 50 |
---|
277 | 302 | #define CMD_TIMEOUT (HZ/10 * 5) /* 100ms x5 */ |
---|
278 | 303 | #define DAT_TIMEOUT (HZ * 5) /* 1000ms x5 */ |
---|
| 304 | + |
---|
| 305 | +#define DEFAULT_DEBOUNCE (8) /* 8 cycles CD debounce */ |
---|
279 | 306 | |
---|
280 | 307 | #define PAD_DELAY_MAX 32 /* PAD delay cells */ |
---|
281 | 308 | /*--------------------------------------------------------------------------*/ |
---|
.. | .. |
---|
311 | 338 | u32 ptr; |
---|
312 | 339 | u32 bd_data_len; |
---|
313 | 340 | #define BDMA_DESC_BUFLEN (0xffff) /* bit0 ~ bit15 */ |
---|
| 341 | +#define BDMA_DESC_BUFLEN_EXT (0xffffff) /* bit0 ~ bit23 */ |
---|
314 | 342 | }; |
---|
315 | 343 | |
---|
316 | 344 | struct msdc_dma { |
---|
.. | .. |
---|
334 | 362 | u32 emmc50_cfg0; |
---|
335 | 363 | u32 emmc50_cfg3; |
---|
336 | 364 | u32 sdc_fifo_cfg; |
---|
| 365 | + u32 emmc_top_control; |
---|
| 366 | + u32 emmc_top_cmd; |
---|
| 367 | + u32 emmc50_pad_ds_tune; |
---|
337 | 368 | }; |
---|
338 | 369 | |
---|
339 | 370 | struct mtk_mmc_compatible { |
---|
340 | 371 | u8 clk_div_bits; |
---|
| 372 | + bool recheck_sdio_irq; |
---|
341 | 373 | bool hs400_tune; /* only used for MT8173 */ |
---|
342 | 374 | u32 pad_tune_reg; |
---|
343 | 375 | bool async_fifo; |
---|
.. | .. |
---|
346 | 378 | bool stop_clk_fix; |
---|
347 | 379 | bool enhance_rx; |
---|
348 | 380 | bool support_64g; |
---|
| 381 | + bool use_internal_cd; |
---|
349 | 382 | }; |
---|
350 | 383 | |
---|
351 | 384 | struct msdc_tune_para { |
---|
352 | 385 | u32 iocon; |
---|
353 | 386 | u32 pad_tune; |
---|
354 | 387 | u32 pad_cmd_tune; |
---|
| 388 | + u32 emmc_top_control; |
---|
| 389 | + u32 emmc_top_cmd; |
---|
355 | 390 | }; |
---|
356 | 391 | |
---|
357 | 392 | struct msdc_delay_phase { |
---|
.. | .. |
---|
363 | 398 | struct msdc_host { |
---|
364 | 399 | struct device *dev; |
---|
365 | 400 | const struct mtk_mmc_compatible *dev_comp; |
---|
366 | | - struct mmc_host *mmc; /* mmc structure */ |
---|
367 | 401 | int cmd_rsp; |
---|
368 | 402 | |
---|
369 | 403 | spinlock_t lock; |
---|
.. | .. |
---|
373 | 407 | int error; |
---|
374 | 408 | |
---|
375 | 409 | void __iomem *base; /* host base address */ |
---|
| 410 | + void __iomem *top_base; /* host top register base address */ |
---|
376 | 411 | |
---|
377 | 412 | struct msdc_dma dma; /* dma channel */ |
---|
378 | 413 | u64 dma_mask; |
---|
.. | .. |
---|
385 | 420 | struct pinctrl_state *pins_uhs; |
---|
386 | 421 | struct delayed_work req_timeout; |
---|
387 | 422 | int irq; /* host interrupt */ |
---|
| 423 | + struct reset_control *reset; |
---|
388 | 424 | |
---|
389 | 425 | struct clk *src_clk; /* msdc source clock */ |
---|
390 | 426 | struct clk *h_clk; /* msdc h_clk */ |
---|
| 427 | + struct clk *bus_clk; /* bus clock which used to access register */ |
---|
391 | 428 | struct clk *src_clk_cg; /* msdc source clock control gate */ |
---|
392 | 429 | u32 mclk; /* mmc subsystem clock frequency */ |
---|
393 | 430 | u32 src_clk_freq; /* source clock frequency */ |
---|
.. | .. |
---|
400 | 437 | bool hs400_cmd_resp_sel_rising; |
---|
401 | 438 | /* cmd response sample selection for HS400 */ |
---|
402 | 439 | bool hs400_mode; /* current eMMC will run at hs400 mode */ |
---|
| 440 | + bool internal_cd; /* Use internal card-detect logic */ |
---|
| 441 | + bool cqhci; /* support eMMC hw cmdq */ |
---|
403 | 442 | struct msdc_save_para save_para; /* used when gate HCLK */ |
---|
404 | 443 | struct msdc_tune_para def_tune_para; /* default tune setting */ |
---|
405 | 444 | struct msdc_tune_para saved_tune_para; /* tune result of CMD21/CMD19 */ |
---|
| 445 | + struct cqhci_host *cq_host; |
---|
406 | 446 | }; |
---|
407 | 447 | |
---|
408 | 448 | static const struct mtk_mmc_compatible mt8135_compat = { |
---|
409 | 449 | .clk_div_bits = 8, |
---|
| 450 | + .recheck_sdio_irq = true, |
---|
410 | 451 | .hs400_tune = false, |
---|
411 | 452 | .pad_tune_reg = MSDC_PAD_TUNE, |
---|
412 | 453 | .async_fifo = false, |
---|
.. | .. |
---|
419 | 460 | |
---|
420 | 461 | static const struct mtk_mmc_compatible mt8173_compat = { |
---|
421 | 462 | .clk_div_bits = 8, |
---|
| 463 | + .recheck_sdio_irq = true, |
---|
422 | 464 | .hs400_tune = true, |
---|
423 | 465 | .pad_tune_reg = MSDC_PAD_TUNE, |
---|
424 | 466 | .async_fifo = false, |
---|
.. | .. |
---|
429 | 471 | .support_64g = false, |
---|
430 | 472 | }; |
---|
431 | 473 | |
---|
| 474 | +static const struct mtk_mmc_compatible mt8183_compat = { |
---|
| 475 | + .clk_div_bits = 12, |
---|
| 476 | + .recheck_sdio_irq = false, |
---|
| 477 | + .hs400_tune = false, |
---|
| 478 | + .pad_tune_reg = MSDC_PAD_TUNE0, |
---|
| 479 | + .async_fifo = true, |
---|
| 480 | + .data_tune = true, |
---|
| 481 | + .busy_check = true, |
---|
| 482 | + .stop_clk_fix = true, |
---|
| 483 | + .enhance_rx = true, |
---|
| 484 | + .support_64g = true, |
---|
| 485 | +}; |
---|
| 486 | + |
---|
432 | 487 | static const struct mtk_mmc_compatible mt2701_compat = { |
---|
433 | 488 | .clk_div_bits = 12, |
---|
| 489 | + .recheck_sdio_irq = true, |
---|
434 | 490 | .hs400_tune = false, |
---|
435 | 491 | .pad_tune_reg = MSDC_PAD_TUNE0, |
---|
436 | 492 | .async_fifo = true, |
---|
.. | .. |
---|
443 | 499 | |
---|
444 | 500 | static const struct mtk_mmc_compatible mt2712_compat = { |
---|
445 | 501 | .clk_div_bits = 12, |
---|
| 502 | + .recheck_sdio_irq = false, |
---|
446 | 503 | .hs400_tune = false, |
---|
447 | 504 | .pad_tune_reg = MSDC_PAD_TUNE0, |
---|
448 | 505 | .async_fifo = true, |
---|
.. | .. |
---|
455 | 512 | |
---|
456 | 513 | static const struct mtk_mmc_compatible mt7622_compat = { |
---|
457 | 514 | .clk_div_bits = 12, |
---|
| 515 | + .recheck_sdio_irq = true, |
---|
458 | 516 | .hs400_tune = false, |
---|
459 | 517 | .pad_tune_reg = MSDC_PAD_TUNE0, |
---|
460 | 518 | .async_fifo = true, |
---|
.. | .. |
---|
465 | 523 | .support_64g = false, |
---|
466 | 524 | }; |
---|
467 | 525 | |
---|
| 526 | +static const struct mtk_mmc_compatible mt8516_compat = { |
---|
| 527 | + .clk_div_bits = 12, |
---|
| 528 | + .recheck_sdio_irq = true, |
---|
| 529 | + .hs400_tune = false, |
---|
| 530 | + .pad_tune_reg = MSDC_PAD_TUNE0, |
---|
| 531 | + .async_fifo = true, |
---|
| 532 | + .data_tune = true, |
---|
| 533 | + .busy_check = true, |
---|
| 534 | + .stop_clk_fix = true, |
---|
| 535 | +}; |
---|
| 536 | + |
---|
| 537 | +static const struct mtk_mmc_compatible mt7620_compat = { |
---|
| 538 | + .clk_div_bits = 8, |
---|
| 539 | + .recheck_sdio_irq = true, |
---|
| 540 | + .hs400_tune = false, |
---|
| 541 | + .pad_tune_reg = MSDC_PAD_TUNE, |
---|
| 542 | + .async_fifo = false, |
---|
| 543 | + .data_tune = false, |
---|
| 544 | + .busy_check = false, |
---|
| 545 | + .stop_clk_fix = false, |
---|
| 546 | + .enhance_rx = false, |
---|
| 547 | + .use_internal_cd = true, |
---|
| 548 | +}; |
---|
| 549 | + |
---|
| 550 | +static const struct mtk_mmc_compatible mt6779_compat = { |
---|
| 551 | + .clk_div_bits = 12, |
---|
| 552 | + .recheck_sdio_irq = false, |
---|
| 553 | + .hs400_tune = false, |
---|
| 554 | + .pad_tune_reg = MSDC_PAD_TUNE0, |
---|
| 555 | + .async_fifo = true, |
---|
| 556 | + .data_tune = true, |
---|
| 557 | + .busy_check = true, |
---|
| 558 | + .stop_clk_fix = true, |
---|
| 559 | + .enhance_rx = true, |
---|
| 560 | + .support_64g = true, |
---|
| 561 | +}; |
---|
| 562 | + |
---|
468 | 563 | static const struct of_device_id msdc_of_ids[] = { |
---|
469 | 564 | { .compatible = "mediatek,mt8135-mmc", .data = &mt8135_compat}, |
---|
470 | 565 | { .compatible = "mediatek,mt8173-mmc", .data = &mt8173_compat}, |
---|
| 566 | + { .compatible = "mediatek,mt8183-mmc", .data = &mt8183_compat}, |
---|
471 | 567 | { .compatible = "mediatek,mt2701-mmc", .data = &mt2701_compat}, |
---|
472 | 568 | { .compatible = "mediatek,mt2712-mmc", .data = &mt2712_compat}, |
---|
473 | 569 | { .compatible = "mediatek,mt7622-mmc", .data = &mt7622_compat}, |
---|
| 570 | + { .compatible = "mediatek,mt8516-mmc", .data = &mt8516_compat}, |
---|
| 571 | + { .compatible = "mediatek,mt7620-mmc", .data = &mt7620_compat}, |
---|
| 572 | + { .compatible = "mediatek,mt6779-mmc", .data = &mt6779_compat}, |
---|
474 | 573 | {} |
---|
475 | 574 | }; |
---|
476 | 575 | MODULE_DEVICE_TABLE(of, msdc_of_ids); |
---|
.. | .. |
---|
525 | 624 | |
---|
526 | 625 | static void msdc_cmd_next(struct msdc_host *host, |
---|
527 | 626 | struct mmc_request *mrq, struct mmc_command *cmd); |
---|
| 627 | +static void __msdc_enable_sdio_irq(struct msdc_host *host, int enb); |
---|
528 | 628 | |
---|
529 | 629 | static const u32 cmd_ints_mask = MSDC_INTEN_CMDRDY | MSDC_INTEN_RSPCRCERR | |
---|
530 | 630 | MSDC_INTEN_CMDTMO | MSDC_INTEN_ACMDRDY | |
---|
.. | .. |
---|
578 | 678 | bd[j].bd_info |= (upper_32_bits(dma_address) & 0xf) |
---|
579 | 679 | << 28; |
---|
580 | 680 | } |
---|
581 | | - bd[j].bd_data_len &= ~BDMA_DESC_BUFLEN; |
---|
582 | | - bd[j].bd_data_len |= (dma_len & BDMA_DESC_BUFLEN); |
---|
| 681 | + |
---|
| 682 | + if (host->dev_comp->support_64g) { |
---|
| 683 | + bd[j].bd_data_len &= ~BDMA_DESC_BUFLEN_EXT; |
---|
| 684 | + bd[j].bd_data_len |= (dma_len & BDMA_DESC_BUFLEN_EXT); |
---|
| 685 | + } else { |
---|
| 686 | + bd[j].bd_data_len &= ~BDMA_DESC_BUFLEN; |
---|
| 687 | + bd[j].bd_data_len |= (dma_len & BDMA_DESC_BUFLEN); |
---|
| 688 | + } |
---|
583 | 689 | |
---|
584 | 690 | if (j == data->sg_count - 1) /* the last bd */ |
---|
585 | 691 | bd[j].bd_info |= BDMA_DESC_EOL; |
---|
.. | .. |
---|
627 | 733 | } |
---|
628 | 734 | } |
---|
629 | 735 | |
---|
630 | | -/* clock control primitives */ |
---|
631 | | -static void msdc_set_timeout(struct msdc_host *host, u32 ns, u32 clks) |
---|
| 736 | +static u64 msdc_timeout_cal(struct msdc_host *host, u64 ns, u64 clks) |
---|
632 | 737 | { |
---|
633 | | - u32 timeout, clk_ns; |
---|
| 738 | + struct mmc_host *mmc = mmc_from_priv(host); |
---|
| 739 | + u64 timeout, clk_ns; |
---|
634 | 740 | u32 mode = 0; |
---|
635 | 741 | |
---|
636 | | - host->timeout_ns = ns; |
---|
637 | | - host->timeout_clks = clks; |
---|
638 | | - if (host->mmc->actual_clock == 0) { |
---|
| 742 | + if (mmc->actual_clock == 0) { |
---|
639 | 743 | timeout = 0; |
---|
640 | 744 | } else { |
---|
641 | | - clk_ns = 1000000000UL / host->mmc->actual_clock; |
---|
642 | | - timeout = (ns + clk_ns - 1) / clk_ns + clks; |
---|
| 745 | + clk_ns = 1000000000ULL; |
---|
| 746 | + do_div(clk_ns, mmc->actual_clock); |
---|
| 747 | + timeout = ns + clk_ns - 1; |
---|
| 748 | + do_div(timeout, clk_ns); |
---|
| 749 | + timeout += clks; |
---|
643 | 750 | /* in 1048576 sclk cycle unit */ |
---|
644 | | - timeout = (timeout + (0x1 << 20) - 1) >> 20; |
---|
| 751 | + timeout = DIV_ROUND_UP(timeout, (0x1 << 20)); |
---|
645 | 752 | if (host->dev_comp->clk_div_bits == 8) |
---|
646 | 753 | sdr_get_field(host->base + MSDC_CFG, |
---|
647 | 754 | MSDC_CFG_CKMOD, &mode); |
---|
.. | .. |
---|
651 | 758 | /*DDR mode will double the clk cycles for data timeout */ |
---|
652 | 759 | timeout = mode >= 2 ? timeout * 2 : timeout; |
---|
653 | 760 | timeout = timeout > 1 ? timeout - 1 : 0; |
---|
654 | | - timeout = timeout > 255 ? 255 : timeout; |
---|
655 | 761 | } |
---|
656 | | - sdr_set_field(host->base + SDC_CFG, SDC_CFG_DTOC, timeout); |
---|
| 762 | + return timeout; |
---|
| 763 | +} |
---|
| 764 | + |
---|
| 765 | +/* clock control primitives */ |
---|
| 766 | +static void msdc_set_timeout(struct msdc_host *host, u64 ns, u64 clks) |
---|
| 767 | +{ |
---|
| 768 | + u64 timeout; |
---|
| 769 | + |
---|
| 770 | + host->timeout_ns = ns; |
---|
| 771 | + host->timeout_clks = clks; |
---|
| 772 | + |
---|
| 773 | + timeout = msdc_timeout_cal(host, ns, clks); |
---|
| 774 | + sdr_set_field(host->base + SDC_CFG, SDC_CFG_DTOC, |
---|
| 775 | + (u32)(timeout > 255 ? 255 : timeout)); |
---|
| 776 | +} |
---|
| 777 | + |
---|
| 778 | +static void msdc_set_busy_timeout(struct msdc_host *host, u64 ns, u64 clks) |
---|
| 779 | +{ |
---|
| 780 | + u64 timeout; |
---|
| 781 | + |
---|
| 782 | + timeout = msdc_timeout_cal(host, ns, clks); |
---|
| 783 | + sdr_set_field(host->base + SDC_CFG, SDC_CFG_WRDTOC, |
---|
| 784 | + (u32)(timeout > 8191 ? 8191 : timeout)); |
---|
657 | 785 | } |
---|
658 | 786 | |
---|
659 | 787 | static void msdc_gate_clock(struct msdc_host *host) |
---|
660 | 788 | { |
---|
661 | 789 | clk_disable_unprepare(host->src_clk_cg); |
---|
662 | 790 | clk_disable_unprepare(host->src_clk); |
---|
| 791 | + clk_disable_unprepare(host->bus_clk); |
---|
663 | 792 | clk_disable_unprepare(host->h_clk); |
---|
664 | 793 | } |
---|
665 | 794 | |
---|
666 | 795 | static void msdc_ungate_clock(struct msdc_host *host) |
---|
667 | 796 | { |
---|
668 | 797 | clk_prepare_enable(host->h_clk); |
---|
| 798 | + clk_prepare_enable(host->bus_clk); |
---|
669 | 799 | clk_prepare_enable(host->src_clk); |
---|
670 | 800 | clk_prepare_enable(host->src_clk_cg); |
---|
671 | 801 | while (!(readl(host->base + MSDC_CFG) & MSDC_CFG_CKSTB)) |
---|
.. | .. |
---|
674 | 804 | |
---|
675 | 805 | static void msdc_set_mclk(struct msdc_host *host, unsigned char timing, u32 hz) |
---|
676 | 806 | { |
---|
| 807 | + struct mmc_host *mmc = mmc_from_priv(host); |
---|
677 | 808 | u32 mode; |
---|
678 | 809 | u32 flags; |
---|
679 | 810 | u32 div; |
---|
.. | .. |
---|
683 | 814 | if (!hz) { |
---|
684 | 815 | dev_dbg(host->dev, "set mclk to 0\n"); |
---|
685 | 816 | host->mclk = 0; |
---|
686 | | - host->mmc->actual_clock = 0; |
---|
| 817 | + mmc->actual_clock = 0; |
---|
687 | 818 | sdr_clr_bits(host->base + MSDC_CFG, MSDC_CFG_CKPDN); |
---|
688 | 819 | return; |
---|
689 | 820 | } |
---|
.. | .. |
---|
762 | 893 | while (!(readl(host->base + MSDC_CFG) & MSDC_CFG_CKSTB)) |
---|
763 | 894 | cpu_relax(); |
---|
764 | 895 | sdr_set_bits(host->base + MSDC_CFG, MSDC_CFG_CKPDN); |
---|
765 | | - host->mmc->actual_clock = sclk; |
---|
| 896 | + mmc->actual_clock = sclk; |
---|
766 | 897 | host->mclk = hz; |
---|
767 | 898 | host->timing = timing; |
---|
768 | 899 | /* need because clk changed. */ |
---|
.. | .. |
---|
773 | 904 | * mmc_select_hs400() will drop to 50Mhz and High speed mode, |
---|
774 | 905 | * tune result of hs200/200Mhz is not suitable for 50Mhz |
---|
775 | 906 | */ |
---|
776 | | - if (host->mmc->actual_clock <= 52000000) { |
---|
| 907 | + if (mmc->actual_clock <= 52000000) { |
---|
777 | 908 | writel(host->def_tune_para.iocon, host->base + MSDC_IOCON); |
---|
778 | | - writel(host->def_tune_para.pad_tune, host->base + tune_reg); |
---|
| 909 | + if (host->top_base) { |
---|
| 910 | + writel(host->def_tune_para.emmc_top_control, |
---|
| 911 | + host->top_base + EMMC_TOP_CONTROL); |
---|
| 912 | + writel(host->def_tune_para.emmc_top_cmd, |
---|
| 913 | + host->top_base + EMMC_TOP_CMD); |
---|
| 914 | + } else { |
---|
| 915 | + writel(host->def_tune_para.pad_tune, |
---|
| 916 | + host->base + tune_reg); |
---|
| 917 | + } |
---|
779 | 918 | } else { |
---|
780 | 919 | writel(host->saved_tune_para.iocon, host->base + MSDC_IOCON); |
---|
781 | | - writel(host->saved_tune_para.pad_tune, host->base + tune_reg); |
---|
782 | 920 | writel(host->saved_tune_para.pad_cmd_tune, |
---|
783 | 921 | host->base + PAD_CMD_TUNE); |
---|
| 922 | + if (host->top_base) { |
---|
| 923 | + writel(host->saved_tune_para.emmc_top_control, |
---|
| 924 | + host->top_base + EMMC_TOP_CONTROL); |
---|
| 925 | + writel(host->saved_tune_para.emmc_top_cmd, |
---|
| 926 | + host->top_base + EMMC_TOP_CMD); |
---|
| 927 | + } else { |
---|
| 928 | + writel(host->saved_tune_para.pad_tune, |
---|
| 929 | + host->base + tune_reg); |
---|
| 930 | + } |
---|
784 | 931 | } |
---|
785 | 932 | |
---|
786 | 933 | if (timing == MMC_TIMING_MMC_HS400 && |
---|
.. | .. |
---|
788 | 935 | sdr_set_field(host->base + tune_reg, |
---|
789 | 936 | MSDC_PAD_TUNE_CMDRRDLY, |
---|
790 | 937 | host->hs400_cmd_int_delay); |
---|
791 | | - dev_dbg(host->dev, "sclk: %d, timing: %d\n", host->mmc->actual_clock, |
---|
| 938 | + dev_dbg(host->dev, "sclk: %d, timing: %d\n", mmc->actual_clock, |
---|
792 | 939 | timing); |
---|
793 | 940 | } |
---|
794 | 941 | |
---|
.. | .. |
---|
823 | 970 | static inline u32 msdc_cmd_prepare_raw_cmd(struct msdc_host *host, |
---|
824 | 971 | struct mmc_request *mrq, struct mmc_command *cmd) |
---|
825 | 972 | { |
---|
| 973 | + struct mmc_host *mmc = mmc_from_priv(host); |
---|
826 | 974 | /* rawcmd : |
---|
827 | 975 | * vol_swt << 30 | auto_cmd << 28 | blklen << 16 | go_irq << 15 | |
---|
828 | 976 | * stop << 14 | rw << 13 | dtype << 11 | rsptyp << 7 | brk << 6 | opcode |
---|
.. | .. |
---|
849 | 997 | struct mmc_data *data = cmd->data; |
---|
850 | 998 | |
---|
851 | 999 | if (mmc_op_multi(opcode)) { |
---|
852 | | - if (mmc_card_mmc(host->mmc->card) && mrq->sbc && |
---|
| 1000 | + if (mmc_card_mmc(mmc->card) && mrq->sbc && |
---|
853 | 1001 | !(mrq->sbc->arg & 0xFFFF0000)) |
---|
854 | 1002 | rawcmd |= 0x2 << 28; /* AutoCMD23 */ |
---|
855 | 1003 | } |
---|
.. | .. |
---|
917 | 1065 | return cmd->error; |
---|
918 | 1066 | } |
---|
919 | 1067 | |
---|
| 1068 | +/* |
---|
| 1069 | + * msdc_recheck_sdio_irq - recheck whether the SDIO irq is lost |
---|
| 1070 | + * |
---|
| 1071 | + * Host controller may lost interrupt in some special case. |
---|
| 1072 | + * Add SDIO irq recheck mechanism to make sure all interrupts |
---|
| 1073 | + * can be processed immediately |
---|
| 1074 | + */ |
---|
| 1075 | +static void msdc_recheck_sdio_irq(struct msdc_host *host) |
---|
| 1076 | +{ |
---|
| 1077 | + struct mmc_host *mmc = mmc_from_priv(host); |
---|
| 1078 | + u32 reg_int, reg_inten, reg_ps; |
---|
| 1079 | + |
---|
| 1080 | + if (mmc->caps & MMC_CAP_SDIO_IRQ) { |
---|
| 1081 | + reg_inten = readl(host->base + MSDC_INTEN); |
---|
| 1082 | + if (reg_inten & MSDC_INTEN_SDIOIRQ) { |
---|
| 1083 | + reg_int = readl(host->base + MSDC_INT); |
---|
| 1084 | + reg_ps = readl(host->base + MSDC_PS); |
---|
| 1085 | + if (!(reg_int & MSDC_INT_SDIOIRQ || |
---|
| 1086 | + reg_ps & MSDC_PS_DATA1)) { |
---|
| 1087 | + __msdc_enable_sdio_irq(host, 0); |
---|
| 1088 | + sdio_signal_irq(mmc); |
---|
| 1089 | + } |
---|
| 1090 | + } |
---|
| 1091 | + } |
---|
| 1092 | +} |
---|
| 1093 | + |
---|
920 | 1094 | static void msdc_track_cmd_data(struct msdc_host *host, |
---|
921 | 1095 | struct mmc_command *cmd, struct mmc_data *data) |
---|
922 | 1096 | { |
---|
.. | .. |
---|
942 | 1116 | msdc_track_cmd_data(host, mrq->cmd, mrq->data); |
---|
943 | 1117 | if (mrq->data) |
---|
944 | 1118 | msdc_unprepare_data(host, mrq); |
---|
945 | | - mmc_request_done(host->mmc, mrq); |
---|
| 1119 | + if (host->error) |
---|
| 1120 | + msdc_reset_hw(host); |
---|
| 1121 | + mmc_request_done(mmc_from_priv(host), mrq); |
---|
| 1122 | + if (host->dev_comp->recheck_sdio_irq) |
---|
| 1123 | + msdc_recheck_sdio_irq(host); |
---|
946 | 1124 | } |
---|
947 | 1125 | |
---|
948 | 1126 | /* returns true if command is fully handled; returns false otherwise */ |
---|
.. | .. |
---|
989 | 1167 | } |
---|
990 | 1168 | |
---|
991 | 1169 | if (!sbc_error && !(events & MSDC_INT_CMDRDY)) { |
---|
992 | | - if (cmd->opcode != MMC_SEND_TUNING_BLOCK && |
---|
993 | | - cmd->opcode != MMC_SEND_TUNING_BLOCK_HS200) |
---|
| 1170 | + if (events & MSDC_INT_CMDTMO || |
---|
| 1171 | + (cmd->opcode != MMC_SEND_TUNING_BLOCK && |
---|
| 1172 | + cmd->opcode != MMC_SEND_TUNING_BLOCK_HS200)) |
---|
994 | 1173 | /* |
---|
995 | 1174 | * should not clear fifo/interrupt as the tune data |
---|
996 | | - * may have alreay come. |
---|
| 1175 | + * may have alreay come when cmd19/cmd21 gets response |
---|
| 1176 | + * CRC error. |
---|
997 | 1177 | */ |
---|
998 | 1178 | msdc_reset_hw(host); |
---|
999 | 1179 | if (events & MSDC_INT_RSPCRCERR) { |
---|
.. | .. |
---|
1054 | 1234 | struct mmc_request *mrq, struct mmc_command *cmd) |
---|
1055 | 1235 | { |
---|
1056 | 1236 | u32 rawcmd; |
---|
| 1237 | + unsigned long flags; |
---|
1057 | 1238 | |
---|
1058 | 1239 | WARN_ON(host->cmd); |
---|
1059 | 1240 | host->cmd = cmd; |
---|
.. | .. |
---|
1071 | 1252 | cmd->error = 0; |
---|
1072 | 1253 | rawcmd = msdc_cmd_prepare_raw_cmd(host, mrq, cmd); |
---|
1073 | 1254 | |
---|
| 1255 | + spin_lock_irqsave(&host->lock, flags); |
---|
1074 | 1256 | sdr_set_bits(host->base + MSDC_INTEN, cmd_ints_mask); |
---|
| 1257 | + spin_unlock_irqrestore(&host->lock, flags); |
---|
| 1258 | + |
---|
1075 | 1259 | writel(cmd->arg, host->base + SDC_ARG); |
---|
1076 | 1260 | writel(rawcmd, host->base + SDC_CMD); |
---|
1077 | 1261 | } |
---|
.. | .. |
---|
1234 | 1418 | static int msdc_ops_switch_volt(struct mmc_host *mmc, struct mmc_ios *ios) |
---|
1235 | 1419 | { |
---|
1236 | 1420 | struct msdc_host *host = mmc_priv(mmc); |
---|
1237 | | - int ret = 0; |
---|
| 1421 | + int ret; |
---|
1238 | 1422 | |
---|
1239 | 1423 | if (!IS_ERR(mmc->supply.vqmmc)) { |
---|
1240 | 1424 | if (ios->signal_voltage != MMC_SIGNAL_VOLTAGE_330 && |
---|
.. | .. |
---|
1244 | 1428 | } |
---|
1245 | 1429 | |
---|
1246 | 1430 | ret = mmc_regulator_set_vqmmc(mmc, ios); |
---|
1247 | | - if (ret) { |
---|
| 1431 | + if (ret < 0) { |
---|
1248 | 1432 | dev_dbg(host->dev, "Regulator set error %d (%d)\n", |
---|
1249 | 1433 | ret, ios->signal_voltage); |
---|
1250 | | - } else { |
---|
1251 | | - /* Apply different pinctrl settings for different signal voltage */ |
---|
1252 | | - if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_180) |
---|
1253 | | - pinctrl_select_state(host->pinctrl, host->pins_uhs); |
---|
1254 | | - else |
---|
1255 | | - pinctrl_select_state(host->pinctrl, host->pins_default); |
---|
| 1434 | + return ret; |
---|
1256 | 1435 | } |
---|
| 1436 | + |
---|
| 1437 | + /* Apply different pinctrl settings for different signal voltage */ |
---|
| 1438 | + if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_180) |
---|
| 1439 | + pinctrl_select_state(host->pinctrl, host->pins_uhs); |
---|
| 1440 | + else |
---|
| 1441 | + pinctrl_select_state(host->pinctrl, host->pins_default); |
---|
1257 | 1442 | } |
---|
1258 | | - return ret; |
---|
| 1443 | + return 0; |
---|
1259 | 1444 | } |
---|
1260 | 1445 | |
---|
1261 | 1446 | static int msdc_card_busy(struct mmc_host *mmc) |
---|
.. | .. |
---|
1292 | 1477 | } |
---|
1293 | 1478 | } |
---|
1294 | 1479 | |
---|
| 1480 | +static void __msdc_enable_sdio_irq(struct msdc_host *host, int enb) |
---|
| 1481 | +{ |
---|
| 1482 | + if (enb) { |
---|
| 1483 | + sdr_set_bits(host->base + MSDC_INTEN, MSDC_INTEN_SDIOIRQ); |
---|
| 1484 | + sdr_set_bits(host->base + SDC_CFG, SDC_CFG_SDIOIDE); |
---|
| 1485 | + if (host->dev_comp->recheck_sdio_irq) |
---|
| 1486 | + msdc_recheck_sdio_irq(host); |
---|
| 1487 | + } else { |
---|
| 1488 | + sdr_clr_bits(host->base + MSDC_INTEN, MSDC_INTEN_SDIOIRQ); |
---|
| 1489 | + sdr_clr_bits(host->base + SDC_CFG, SDC_CFG_SDIOIDE); |
---|
| 1490 | + } |
---|
| 1491 | +} |
---|
| 1492 | + |
---|
| 1493 | +static void msdc_enable_sdio_irq(struct mmc_host *mmc, int enb) |
---|
| 1494 | +{ |
---|
| 1495 | + unsigned long flags; |
---|
| 1496 | + struct msdc_host *host = mmc_priv(mmc); |
---|
| 1497 | + |
---|
| 1498 | + spin_lock_irqsave(&host->lock, flags); |
---|
| 1499 | + __msdc_enable_sdio_irq(host, enb); |
---|
| 1500 | + spin_unlock_irqrestore(&host->lock, flags); |
---|
| 1501 | + |
---|
| 1502 | + if (enb) |
---|
| 1503 | + pm_runtime_get_noresume(host->dev); |
---|
| 1504 | + else |
---|
| 1505 | + pm_runtime_put_noidle(host->dev); |
---|
| 1506 | +} |
---|
| 1507 | + |
---|
| 1508 | +static irqreturn_t msdc_cmdq_irq(struct msdc_host *host, u32 intsts) |
---|
| 1509 | +{ |
---|
| 1510 | + struct mmc_host *mmc = mmc_from_priv(host); |
---|
| 1511 | + int cmd_err = 0, dat_err = 0; |
---|
| 1512 | + |
---|
| 1513 | + if (intsts & MSDC_INT_RSPCRCERR) { |
---|
| 1514 | + cmd_err = -EILSEQ; |
---|
| 1515 | + dev_err(host->dev, "%s: CMD CRC ERR", __func__); |
---|
| 1516 | + } else if (intsts & MSDC_INT_CMDTMO) { |
---|
| 1517 | + cmd_err = -ETIMEDOUT; |
---|
| 1518 | + dev_err(host->dev, "%s: CMD TIMEOUT ERR", __func__); |
---|
| 1519 | + } |
---|
| 1520 | + |
---|
| 1521 | + if (intsts & MSDC_INT_DATCRCERR) { |
---|
| 1522 | + dat_err = -EILSEQ; |
---|
| 1523 | + dev_err(host->dev, "%s: DATA CRC ERR", __func__); |
---|
| 1524 | + } else if (intsts & MSDC_INT_DATTMO) { |
---|
| 1525 | + dat_err = -ETIMEDOUT; |
---|
| 1526 | + dev_err(host->dev, "%s: DATA TIMEOUT ERR", __func__); |
---|
| 1527 | + } |
---|
| 1528 | + |
---|
| 1529 | + if (cmd_err || dat_err) { |
---|
| 1530 | + dev_err(host->dev, "cmd_err = %d, dat_err =%d, intsts = 0x%x", |
---|
| 1531 | + cmd_err, dat_err, intsts); |
---|
| 1532 | + } |
---|
| 1533 | + |
---|
| 1534 | + return cqhci_irq(mmc, 0, cmd_err, dat_err); |
---|
| 1535 | +} |
---|
| 1536 | + |
---|
1295 | 1537 | static irqreturn_t msdc_irq(int irq, void *dev_id) |
---|
1296 | 1538 | { |
---|
1297 | 1539 | struct msdc_host *host = (struct msdc_host *) dev_id; |
---|
| 1540 | + struct mmc_host *mmc = mmc_from_priv(host); |
---|
1298 | 1541 | |
---|
1299 | 1542 | while (true) { |
---|
1300 | 1543 | unsigned long flags; |
---|
.. | .. |
---|
1306 | 1549 | spin_lock_irqsave(&host->lock, flags); |
---|
1307 | 1550 | events = readl(host->base + MSDC_INT); |
---|
1308 | 1551 | event_mask = readl(host->base + MSDC_INTEN); |
---|
| 1552 | + if ((events & event_mask) & MSDC_INT_SDIOIRQ) |
---|
| 1553 | + __msdc_enable_sdio_irq(host, 0); |
---|
1309 | 1554 | /* clear interrupts */ |
---|
1310 | 1555 | writel(events & event_mask, host->base + MSDC_INT); |
---|
1311 | 1556 | |
---|
.. | .. |
---|
1314 | 1559 | data = host->data; |
---|
1315 | 1560 | spin_unlock_irqrestore(&host->lock, flags); |
---|
1316 | 1561 | |
---|
1317 | | - if (!(events & event_mask)) |
---|
| 1562 | + if ((events & event_mask) & MSDC_INT_SDIOIRQ) |
---|
| 1563 | + sdio_signal_irq(mmc); |
---|
| 1564 | + |
---|
| 1565 | + if ((events & event_mask) & MSDC_INT_CDSC) { |
---|
| 1566 | + if (host->internal_cd) |
---|
| 1567 | + mmc_detect_change(mmc, msecs_to_jiffies(20)); |
---|
| 1568 | + events &= ~MSDC_INT_CDSC; |
---|
| 1569 | + } |
---|
| 1570 | + |
---|
| 1571 | + if (!(events & (event_mask & ~MSDC_INT_SDIOIRQ))) |
---|
1318 | 1572 | break; |
---|
| 1573 | + |
---|
| 1574 | + if ((mmc->caps2 & MMC_CAP2_CQE) && |
---|
| 1575 | + (events & MSDC_INT_CMDQ)) { |
---|
| 1576 | + msdc_cmdq_irq(host, events); |
---|
| 1577 | + /* clear interrupts */ |
---|
| 1578 | + writel(events, host->base + MSDC_INT); |
---|
| 1579 | + return IRQ_HANDLED; |
---|
| 1580 | + } |
---|
1319 | 1581 | |
---|
1320 | 1582 | if (!mrq) { |
---|
1321 | 1583 | dev_err(host->dev, |
---|
.. | .. |
---|
1341 | 1603 | u32 val; |
---|
1342 | 1604 | u32 tune_reg = host->dev_comp->pad_tune_reg; |
---|
1343 | 1605 | |
---|
| 1606 | + if (host->reset) { |
---|
| 1607 | + reset_control_assert(host->reset); |
---|
| 1608 | + usleep_range(10, 50); |
---|
| 1609 | + reset_control_deassert(host->reset); |
---|
| 1610 | + } |
---|
| 1611 | + |
---|
1344 | 1612 | /* Configure to MMC/SD mode, clock free running */ |
---|
1345 | 1613 | sdr_set_bits(host->base + MSDC_CFG, MSDC_CFG_MODE | MSDC_CFG_CKPDN); |
---|
1346 | 1614 | |
---|
1347 | 1615 | /* Reset */ |
---|
1348 | 1616 | msdc_reset_hw(host); |
---|
1349 | 1617 | |
---|
1350 | | - /* Disable card detection */ |
---|
1351 | | - sdr_clr_bits(host->base + MSDC_PS, MSDC_PS_CDEN); |
---|
1352 | | - |
---|
1353 | 1618 | /* Disable and clear all interrupts */ |
---|
1354 | 1619 | writel(0, host->base + MSDC_INTEN); |
---|
1355 | 1620 | val = readl(host->base + MSDC_INT); |
---|
1356 | 1621 | writel(val, host->base + MSDC_INT); |
---|
1357 | 1622 | |
---|
1358 | | - writel(0, host->base + tune_reg); |
---|
| 1623 | + /* Configure card detection */ |
---|
| 1624 | + if (host->internal_cd) { |
---|
| 1625 | + sdr_set_field(host->base + MSDC_PS, MSDC_PS_CDDEBOUNCE, |
---|
| 1626 | + DEFAULT_DEBOUNCE); |
---|
| 1627 | + sdr_set_bits(host->base + MSDC_PS, MSDC_PS_CDEN); |
---|
| 1628 | + sdr_set_bits(host->base + MSDC_INTEN, MSDC_INTEN_CDSC); |
---|
| 1629 | + sdr_set_bits(host->base + SDC_CFG, SDC_CFG_INSWKUP); |
---|
| 1630 | + } else { |
---|
| 1631 | + sdr_clr_bits(host->base + SDC_CFG, SDC_CFG_INSWKUP); |
---|
| 1632 | + sdr_clr_bits(host->base + MSDC_PS, MSDC_PS_CDEN); |
---|
| 1633 | + sdr_clr_bits(host->base + MSDC_INTEN, MSDC_INTEN_CDSC); |
---|
| 1634 | + } |
---|
| 1635 | + |
---|
| 1636 | + if (host->top_base) { |
---|
| 1637 | + writel(0, host->top_base + EMMC_TOP_CONTROL); |
---|
| 1638 | + writel(0, host->top_base + EMMC_TOP_CMD); |
---|
| 1639 | + } else { |
---|
| 1640 | + writel(0, host->base + tune_reg); |
---|
| 1641 | + } |
---|
1359 | 1642 | writel(0, host->base + MSDC_IOCON); |
---|
1360 | 1643 | sdr_set_field(host->base + MSDC_IOCON, MSDC_IOCON_DDLSEL, 0); |
---|
1361 | 1644 | writel(0x403c0046, host->base + MSDC_PATCH_BIT); |
---|
.. | .. |
---|
1379 | 1662 | sdr_set_field(host->base + MSDC_PATCH_BIT2, |
---|
1380 | 1663 | MSDC_PB2_RESPWAIT, 3); |
---|
1381 | 1664 | if (host->dev_comp->enhance_rx) { |
---|
1382 | | - sdr_set_bits(host->base + SDC_ADV_CFG0, |
---|
1383 | | - SDC_RX_ENHANCE_EN); |
---|
| 1665 | + if (host->top_base) |
---|
| 1666 | + sdr_set_bits(host->top_base + EMMC_TOP_CONTROL, |
---|
| 1667 | + SDC_RX_ENH_EN); |
---|
| 1668 | + else |
---|
| 1669 | + sdr_set_bits(host->base + SDC_ADV_CFG0, |
---|
| 1670 | + SDC_RX_ENHANCE_EN); |
---|
1384 | 1671 | } else { |
---|
1385 | 1672 | sdr_set_field(host->base + MSDC_PATCH_BIT2, |
---|
1386 | 1673 | MSDC_PB2_RESPSTSENSEL, 2); |
---|
.. | .. |
---|
1398 | 1685 | sdr_set_bits(host->base + MSDC_PATCH_BIT2, |
---|
1399 | 1686 | MSDC_PB2_SUPPORT_64G); |
---|
1400 | 1687 | if (host->dev_comp->data_tune) { |
---|
1401 | | - sdr_set_bits(host->base + tune_reg, |
---|
1402 | | - MSDC_PAD_TUNE_RD_SEL | MSDC_PAD_TUNE_CMD_SEL); |
---|
| 1688 | + if (host->top_base) { |
---|
| 1689 | + sdr_set_bits(host->top_base + EMMC_TOP_CONTROL, |
---|
| 1690 | + PAD_DAT_RD_RXDLY_SEL); |
---|
| 1691 | + sdr_clr_bits(host->top_base + EMMC_TOP_CONTROL, |
---|
| 1692 | + DATA_K_VALUE_SEL); |
---|
| 1693 | + sdr_set_bits(host->top_base + EMMC_TOP_CMD, |
---|
| 1694 | + PAD_CMD_RD_RXDLY_SEL); |
---|
| 1695 | + } else { |
---|
| 1696 | + sdr_set_bits(host->base + tune_reg, |
---|
| 1697 | + MSDC_PAD_TUNE_RD_SEL | |
---|
| 1698 | + MSDC_PAD_TUNE_CMD_SEL); |
---|
| 1699 | + } |
---|
1403 | 1700 | } else { |
---|
1404 | 1701 | /* choose clock tune */ |
---|
1405 | | - sdr_set_bits(host->base + tune_reg, MSDC_PAD_TUNE_RXDLYSEL); |
---|
| 1702 | + if (host->top_base) |
---|
| 1703 | + sdr_set_bits(host->top_base + EMMC_TOP_CONTROL, |
---|
| 1704 | + PAD_RXDLY_SEL); |
---|
| 1705 | + else |
---|
| 1706 | + sdr_set_bits(host->base + tune_reg, |
---|
| 1707 | + MSDC_PAD_TUNE_RXDLYSEL); |
---|
1406 | 1708 | } |
---|
1407 | 1709 | |
---|
1408 | 1710 | /* Configure to enable SDIO mode. |
---|
.. | .. |
---|
1410 | 1712 | */ |
---|
1411 | 1713 | sdr_set_bits(host->base + SDC_CFG, SDC_CFG_SDIO); |
---|
1412 | 1714 | |
---|
1413 | | - /* disable detect SDIO device interrupt function */ |
---|
| 1715 | + /* Config SDIO device detect interrupt function */ |
---|
1414 | 1716 | sdr_clr_bits(host->base + SDC_CFG, SDC_CFG_SDIOIDE); |
---|
| 1717 | + sdr_set_bits(host->base + SDC_ADV_CFG0, SDC_DAT1_IRQ_TRIGGER); |
---|
1415 | 1718 | |
---|
1416 | 1719 | /* Configure to default data timeout */ |
---|
1417 | 1720 | sdr_set_field(host->base + SDC_CFG, SDC_CFG_DTOC, 3); |
---|
1418 | 1721 | |
---|
1419 | 1722 | host->def_tune_para.iocon = readl(host->base + MSDC_IOCON); |
---|
1420 | | - host->def_tune_para.pad_tune = readl(host->base + tune_reg); |
---|
1421 | 1723 | host->saved_tune_para.iocon = readl(host->base + MSDC_IOCON); |
---|
1422 | | - host->saved_tune_para.pad_tune = readl(host->base + tune_reg); |
---|
| 1724 | + if (host->top_base) { |
---|
| 1725 | + host->def_tune_para.emmc_top_control = |
---|
| 1726 | + readl(host->top_base + EMMC_TOP_CONTROL); |
---|
| 1727 | + host->def_tune_para.emmc_top_cmd = |
---|
| 1728 | + readl(host->top_base + EMMC_TOP_CMD); |
---|
| 1729 | + host->saved_tune_para.emmc_top_control = |
---|
| 1730 | + readl(host->top_base + EMMC_TOP_CONTROL); |
---|
| 1731 | + host->saved_tune_para.emmc_top_cmd = |
---|
| 1732 | + readl(host->top_base + EMMC_TOP_CMD); |
---|
| 1733 | + } else { |
---|
| 1734 | + host->def_tune_para.pad_tune = readl(host->base + tune_reg); |
---|
| 1735 | + host->saved_tune_para.pad_tune = readl(host->base + tune_reg); |
---|
| 1736 | + } |
---|
1423 | 1737 | dev_dbg(host->dev, "init hardware done!"); |
---|
1424 | 1738 | } |
---|
1425 | 1739 | |
---|
1426 | 1740 | static void msdc_deinit_hw(struct msdc_host *host) |
---|
1427 | 1741 | { |
---|
1428 | 1742 | u32 val; |
---|
| 1743 | + |
---|
| 1744 | + if (host->internal_cd) { |
---|
| 1745 | + /* Disabled card-detect */ |
---|
| 1746 | + sdr_clr_bits(host->base + MSDC_PS, MSDC_PS_CDEN); |
---|
| 1747 | + sdr_clr_bits(host->base + SDC_CFG, SDC_CFG_INSWKUP); |
---|
| 1748 | + } |
---|
| 1749 | + |
---|
1429 | 1750 | /* Disable and clear all interrupts */ |
---|
1430 | 1751 | writel(0, host->base + MSDC_INTEN); |
---|
1431 | 1752 | |
---|
.. | .. |
---|
1567 | 1888 | return delay_phase; |
---|
1568 | 1889 | } |
---|
1569 | 1890 | |
---|
| 1891 | +static inline void msdc_set_cmd_delay(struct msdc_host *host, u32 value) |
---|
| 1892 | +{ |
---|
| 1893 | + u32 tune_reg = host->dev_comp->pad_tune_reg; |
---|
| 1894 | + |
---|
| 1895 | + if (host->top_base) |
---|
| 1896 | + sdr_set_field(host->top_base + EMMC_TOP_CMD, PAD_CMD_RXDLY, |
---|
| 1897 | + value); |
---|
| 1898 | + else |
---|
| 1899 | + sdr_set_field(host->base + tune_reg, MSDC_PAD_TUNE_CMDRDLY, |
---|
| 1900 | + value); |
---|
| 1901 | +} |
---|
| 1902 | + |
---|
| 1903 | +static inline void msdc_set_data_delay(struct msdc_host *host, u32 value) |
---|
| 1904 | +{ |
---|
| 1905 | + u32 tune_reg = host->dev_comp->pad_tune_reg; |
---|
| 1906 | + |
---|
| 1907 | + if (host->top_base) |
---|
| 1908 | + sdr_set_field(host->top_base + EMMC_TOP_CONTROL, |
---|
| 1909 | + PAD_DAT_RD_RXDLY, value); |
---|
| 1910 | + else |
---|
| 1911 | + sdr_set_field(host->base + tune_reg, MSDC_PAD_TUNE_DATRRDLY, |
---|
| 1912 | + value); |
---|
| 1913 | +} |
---|
| 1914 | + |
---|
1570 | 1915 | static int msdc_tune_response(struct mmc_host *mmc, u32 opcode) |
---|
1571 | 1916 | { |
---|
1572 | 1917 | struct msdc_host *host = mmc_priv(mmc); |
---|
.. | .. |
---|
1587 | 1932 | |
---|
1588 | 1933 | sdr_clr_bits(host->base + MSDC_IOCON, MSDC_IOCON_RSPL); |
---|
1589 | 1934 | for (i = 0 ; i < PAD_DELAY_MAX; i++) { |
---|
1590 | | - sdr_set_field(host->base + tune_reg, |
---|
1591 | | - MSDC_PAD_TUNE_CMDRDLY, i); |
---|
| 1935 | + msdc_set_cmd_delay(host, i); |
---|
1592 | 1936 | /* |
---|
1593 | 1937 | * Using the same parameters, it may sometimes pass the test, |
---|
1594 | 1938 | * but sometimes it may fail. To make sure the parameters are |
---|
.. | .. |
---|
1612 | 1956 | |
---|
1613 | 1957 | sdr_set_bits(host->base + MSDC_IOCON, MSDC_IOCON_RSPL); |
---|
1614 | 1958 | for (i = 0; i < PAD_DELAY_MAX; i++) { |
---|
1615 | | - sdr_set_field(host->base + tune_reg, |
---|
1616 | | - MSDC_PAD_TUNE_CMDRDLY, i); |
---|
| 1959 | + msdc_set_cmd_delay(host, i); |
---|
1617 | 1960 | /* |
---|
1618 | 1961 | * Using the same parameters, it may sometimes pass the test, |
---|
1619 | 1962 | * but sometimes it may fail. To make sure the parameters are |
---|
.. | .. |
---|
1637 | 1980 | final_maxlen = final_fall_delay.maxlen; |
---|
1638 | 1981 | if (final_maxlen == final_rise_delay.maxlen) { |
---|
1639 | 1982 | sdr_clr_bits(host->base + MSDC_IOCON, MSDC_IOCON_RSPL); |
---|
1640 | | - sdr_set_field(host->base + tune_reg, MSDC_PAD_TUNE_CMDRDLY, |
---|
1641 | | - final_rise_delay.final_phase); |
---|
1642 | 1983 | final_delay = final_rise_delay.final_phase; |
---|
1643 | 1984 | } else { |
---|
1644 | 1985 | sdr_set_bits(host->base + MSDC_IOCON, MSDC_IOCON_RSPL); |
---|
1645 | | - sdr_set_field(host->base + tune_reg, MSDC_PAD_TUNE_CMDRDLY, |
---|
1646 | | - final_fall_delay.final_phase); |
---|
1647 | 1986 | final_delay = final_fall_delay.final_phase; |
---|
1648 | 1987 | } |
---|
| 1988 | + msdc_set_cmd_delay(host, final_delay); |
---|
| 1989 | + |
---|
1649 | 1990 | if (host->dev_comp->async_fifo || host->hs200_cmd_int_delay) |
---|
1650 | 1991 | goto skip_internal; |
---|
1651 | 1992 | |
---|
.. | .. |
---|
1721 | 2062 | u32 rise_delay = 0, fall_delay = 0; |
---|
1722 | 2063 | struct msdc_delay_phase final_rise_delay, final_fall_delay = { 0,}; |
---|
1723 | 2064 | u8 final_delay, final_maxlen; |
---|
1724 | | - u32 tune_reg = host->dev_comp->pad_tune_reg; |
---|
1725 | 2065 | int i, ret; |
---|
1726 | 2066 | |
---|
1727 | 2067 | sdr_set_field(host->base + MSDC_PATCH_BIT, MSDC_INT_DAT_LATCH_CK_SEL, |
---|
.. | .. |
---|
1729 | 2069 | sdr_clr_bits(host->base + MSDC_IOCON, MSDC_IOCON_DSPL); |
---|
1730 | 2070 | sdr_clr_bits(host->base + MSDC_IOCON, MSDC_IOCON_W_DSPL); |
---|
1731 | 2071 | for (i = 0 ; i < PAD_DELAY_MAX; i++) { |
---|
1732 | | - sdr_set_field(host->base + tune_reg, |
---|
1733 | | - MSDC_PAD_TUNE_DATRRDLY, i); |
---|
| 2072 | + msdc_set_data_delay(host, i); |
---|
1734 | 2073 | ret = mmc_send_tuning(mmc, opcode, NULL); |
---|
1735 | 2074 | if (!ret) |
---|
1736 | 2075 | rise_delay |= (1 << i); |
---|
.. | .. |
---|
1744 | 2083 | sdr_set_bits(host->base + MSDC_IOCON, MSDC_IOCON_DSPL); |
---|
1745 | 2084 | sdr_set_bits(host->base + MSDC_IOCON, MSDC_IOCON_W_DSPL); |
---|
1746 | 2085 | for (i = 0; i < PAD_DELAY_MAX; i++) { |
---|
1747 | | - sdr_set_field(host->base + tune_reg, |
---|
1748 | | - MSDC_PAD_TUNE_DATRRDLY, i); |
---|
| 2086 | + msdc_set_data_delay(host, i); |
---|
1749 | 2087 | ret = mmc_send_tuning(mmc, opcode, NULL); |
---|
1750 | 2088 | if (!ret) |
---|
1751 | 2089 | fall_delay |= (1 << i); |
---|
.. | .. |
---|
1757 | 2095 | if (final_maxlen == final_rise_delay.maxlen) { |
---|
1758 | 2096 | sdr_clr_bits(host->base + MSDC_IOCON, MSDC_IOCON_DSPL); |
---|
1759 | 2097 | sdr_clr_bits(host->base + MSDC_IOCON, MSDC_IOCON_W_DSPL); |
---|
1760 | | - sdr_set_field(host->base + tune_reg, |
---|
1761 | | - MSDC_PAD_TUNE_DATRRDLY, |
---|
1762 | | - final_rise_delay.final_phase); |
---|
1763 | 2098 | final_delay = final_rise_delay.final_phase; |
---|
1764 | 2099 | } else { |
---|
1765 | 2100 | sdr_set_bits(host->base + MSDC_IOCON, MSDC_IOCON_DSPL); |
---|
1766 | 2101 | sdr_set_bits(host->base + MSDC_IOCON, MSDC_IOCON_W_DSPL); |
---|
1767 | | - sdr_set_field(host->base + tune_reg, |
---|
1768 | | - MSDC_PAD_TUNE_DATRRDLY, |
---|
1769 | | - final_fall_delay.final_phase); |
---|
| 2102 | + final_delay = final_fall_delay.final_phase; |
---|
| 2103 | + } |
---|
| 2104 | + msdc_set_data_delay(host, final_delay); |
---|
| 2105 | + |
---|
| 2106 | + dev_dbg(host->dev, "Final data pad delay: %x\n", final_delay); |
---|
| 2107 | + return final_delay == 0xff ? -EIO : 0; |
---|
| 2108 | +} |
---|
| 2109 | + |
---|
| 2110 | +/* |
---|
| 2111 | + * MSDC IP which supports data tune + async fifo can do CMD/DAT tune |
---|
| 2112 | + * together, which can save the tuning time. |
---|
| 2113 | + */ |
---|
| 2114 | +static int msdc_tune_together(struct mmc_host *mmc, u32 opcode) |
---|
| 2115 | +{ |
---|
| 2116 | + struct msdc_host *host = mmc_priv(mmc); |
---|
| 2117 | + u32 rise_delay = 0, fall_delay = 0; |
---|
| 2118 | + struct msdc_delay_phase final_rise_delay, final_fall_delay = { 0,}; |
---|
| 2119 | + u8 final_delay, final_maxlen; |
---|
| 2120 | + int i, ret; |
---|
| 2121 | + |
---|
| 2122 | + sdr_set_field(host->base + MSDC_PATCH_BIT, MSDC_INT_DAT_LATCH_CK_SEL, |
---|
| 2123 | + host->latch_ck); |
---|
| 2124 | + |
---|
| 2125 | + sdr_clr_bits(host->base + MSDC_IOCON, MSDC_IOCON_RSPL); |
---|
| 2126 | + sdr_clr_bits(host->base + MSDC_IOCON, |
---|
| 2127 | + MSDC_IOCON_DSPL | MSDC_IOCON_W_DSPL); |
---|
| 2128 | + for (i = 0 ; i < PAD_DELAY_MAX; i++) { |
---|
| 2129 | + msdc_set_cmd_delay(host, i); |
---|
| 2130 | + msdc_set_data_delay(host, i); |
---|
| 2131 | + ret = mmc_send_tuning(mmc, opcode, NULL); |
---|
| 2132 | + if (!ret) |
---|
| 2133 | + rise_delay |= (1 << i); |
---|
| 2134 | + } |
---|
| 2135 | + final_rise_delay = get_best_delay(host, rise_delay); |
---|
| 2136 | + /* if rising edge has enough margin, then do not scan falling edge */ |
---|
| 2137 | + if (final_rise_delay.maxlen >= 12 || |
---|
| 2138 | + (final_rise_delay.start == 0 && final_rise_delay.maxlen >= 4)) |
---|
| 2139 | + goto skip_fall; |
---|
| 2140 | + |
---|
| 2141 | + sdr_set_bits(host->base + MSDC_IOCON, MSDC_IOCON_RSPL); |
---|
| 2142 | + sdr_set_bits(host->base + MSDC_IOCON, |
---|
| 2143 | + MSDC_IOCON_DSPL | MSDC_IOCON_W_DSPL); |
---|
| 2144 | + for (i = 0; i < PAD_DELAY_MAX; i++) { |
---|
| 2145 | + msdc_set_cmd_delay(host, i); |
---|
| 2146 | + msdc_set_data_delay(host, i); |
---|
| 2147 | + ret = mmc_send_tuning(mmc, opcode, NULL); |
---|
| 2148 | + if (!ret) |
---|
| 2149 | + fall_delay |= (1 << i); |
---|
| 2150 | + } |
---|
| 2151 | + final_fall_delay = get_best_delay(host, fall_delay); |
---|
| 2152 | + |
---|
| 2153 | +skip_fall: |
---|
| 2154 | + final_maxlen = max(final_rise_delay.maxlen, final_fall_delay.maxlen); |
---|
| 2155 | + if (final_maxlen == final_rise_delay.maxlen) { |
---|
| 2156 | + sdr_clr_bits(host->base + MSDC_IOCON, MSDC_IOCON_RSPL); |
---|
| 2157 | + sdr_clr_bits(host->base + MSDC_IOCON, |
---|
| 2158 | + MSDC_IOCON_DSPL | MSDC_IOCON_W_DSPL); |
---|
| 2159 | + final_delay = final_rise_delay.final_phase; |
---|
| 2160 | + } else { |
---|
| 2161 | + sdr_set_bits(host->base + MSDC_IOCON, MSDC_IOCON_RSPL); |
---|
| 2162 | + sdr_set_bits(host->base + MSDC_IOCON, |
---|
| 2163 | + MSDC_IOCON_DSPL | MSDC_IOCON_W_DSPL); |
---|
1770 | 2164 | final_delay = final_fall_delay.final_phase; |
---|
1771 | 2165 | } |
---|
1772 | 2166 | |
---|
1773 | | - dev_dbg(host->dev, "Final data pad delay: %x\n", final_delay); |
---|
| 2167 | + msdc_set_cmd_delay(host, final_delay); |
---|
| 2168 | + msdc_set_data_delay(host, final_delay); |
---|
| 2169 | + |
---|
| 2170 | + dev_dbg(host->dev, "Final pad delay: %x\n", final_delay); |
---|
1774 | 2171 | return final_delay == 0xff ? -EIO : 0; |
---|
1775 | 2172 | } |
---|
1776 | 2173 | |
---|
.. | .. |
---|
1780 | 2177 | int ret; |
---|
1781 | 2178 | u32 tune_reg = host->dev_comp->pad_tune_reg; |
---|
1782 | 2179 | |
---|
| 2180 | + if (host->dev_comp->data_tune && host->dev_comp->async_fifo) { |
---|
| 2181 | + ret = msdc_tune_together(mmc, opcode); |
---|
| 2182 | + if (host->hs400_mode) { |
---|
| 2183 | + sdr_clr_bits(host->base + MSDC_IOCON, |
---|
| 2184 | + MSDC_IOCON_DSPL | MSDC_IOCON_W_DSPL); |
---|
| 2185 | + msdc_set_data_delay(host, 0); |
---|
| 2186 | + } |
---|
| 2187 | + goto tune_done; |
---|
| 2188 | + } |
---|
1783 | 2189 | if (host->hs400_mode && |
---|
1784 | 2190 | host->dev_comp->hs400_tune) |
---|
1785 | 2191 | ret = hs400_tune_response(mmc, opcode); |
---|
.. | .. |
---|
1795 | 2201 | dev_err(host->dev, "Tune data fail!\n"); |
---|
1796 | 2202 | } |
---|
1797 | 2203 | |
---|
| 2204 | +tune_done: |
---|
1798 | 2205 | host->saved_tune_para.iocon = readl(host->base + MSDC_IOCON); |
---|
1799 | 2206 | host->saved_tune_para.pad_tune = readl(host->base + tune_reg); |
---|
1800 | 2207 | host->saved_tune_para.pad_cmd_tune = readl(host->base + PAD_CMD_TUNE); |
---|
| 2208 | + if (host->top_base) { |
---|
| 2209 | + host->saved_tune_para.emmc_top_control = readl(host->top_base + |
---|
| 2210 | + EMMC_TOP_CONTROL); |
---|
| 2211 | + host->saved_tune_para.emmc_top_cmd = readl(host->top_base + |
---|
| 2212 | + EMMC_TOP_CMD); |
---|
| 2213 | + } |
---|
1801 | 2214 | return ret; |
---|
1802 | 2215 | } |
---|
1803 | 2216 | |
---|
.. | .. |
---|
1806 | 2219 | struct msdc_host *host = mmc_priv(mmc); |
---|
1807 | 2220 | host->hs400_mode = true; |
---|
1808 | 2221 | |
---|
1809 | | - writel(host->hs400_ds_delay, host->base + PAD_DS_TUNE); |
---|
| 2222 | + if (host->top_base) |
---|
| 2223 | + writel(host->hs400_ds_delay, |
---|
| 2224 | + host->top_base + EMMC50_PAD_DS_TUNE); |
---|
| 2225 | + else |
---|
| 2226 | + writel(host->hs400_ds_delay, host->base + PAD_DS_TUNE); |
---|
1810 | 2227 | /* hs400 mode must set it to 0 */ |
---|
1811 | 2228 | sdr_clr_bits(host->base + MSDC_PATCH_BIT2, MSDC_PATCH_BIT2_CFGCRCSTS); |
---|
1812 | 2229 | /* to improve read performance, set outstanding to 2 */ |
---|
.. | .. |
---|
1824 | 2241 | sdr_clr_bits(host->base + EMMC_IOCON, 1); |
---|
1825 | 2242 | } |
---|
1826 | 2243 | |
---|
| 2244 | +static void msdc_ack_sdio_irq(struct mmc_host *mmc) |
---|
| 2245 | +{ |
---|
| 2246 | + unsigned long flags; |
---|
| 2247 | + struct msdc_host *host = mmc_priv(mmc); |
---|
| 2248 | + |
---|
| 2249 | + spin_lock_irqsave(&host->lock, flags); |
---|
| 2250 | + __msdc_enable_sdio_irq(host, 1); |
---|
| 2251 | + spin_unlock_irqrestore(&host->lock, flags); |
---|
| 2252 | +} |
---|
| 2253 | + |
---|
| 2254 | +static int msdc_get_cd(struct mmc_host *mmc) |
---|
| 2255 | +{ |
---|
| 2256 | + struct msdc_host *host = mmc_priv(mmc); |
---|
| 2257 | + int val; |
---|
| 2258 | + |
---|
| 2259 | + if (mmc->caps & MMC_CAP_NONREMOVABLE) |
---|
| 2260 | + return 1; |
---|
| 2261 | + |
---|
| 2262 | + if (!host->internal_cd) |
---|
| 2263 | + return mmc_gpio_get_cd(mmc); |
---|
| 2264 | + |
---|
| 2265 | + val = readl(host->base + MSDC_PS) & MSDC_PS_CDSTS; |
---|
| 2266 | + if (mmc->caps2 & MMC_CAP2_CD_ACTIVE_HIGH) |
---|
| 2267 | + return !!val; |
---|
| 2268 | + else |
---|
| 2269 | + return !val; |
---|
| 2270 | +} |
---|
| 2271 | + |
---|
| 2272 | +static void msdc_cqe_enable(struct mmc_host *mmc) |
---|
| 2273 | +{ |
---|
| 2274 | + struct msdc_host *host = mmc_priv(mmc); |
---|
| 2275 | + |
---|
| 2276 | + /* enable cmdq irq */ |
---|
| 2277 | + writel(MSDC_INT_CMDQ, host->base + MSDC_INTEN); |
---|
| 2278 | + /* enable busy check */ |
---|
| 2279 | + sdr_set_bits(host->base + MSDC_PATCH_BIT1, MSDC_PB1_BUSY_CHECK_SEL); |
---|
| 2280 | + /* default write data / busy timeout 20s */ |
---|
| 2281 | + msdc_set_busy_timeout(host, 20 * 1000000000ULL, 0); |
---|
| 2282 | + /* default read data timeout 1s */ |
---|
| 2283 | + msdc_set_timeout(host, 1000000000ULL, 0); |
---|
| 2284 | +} |
---|
| 2285 | + |
---|
| 2286 | +static void msdc_cqe_disable(struct mmc_host *mmc, bool recovery) |
---|
| 2287 | +{ |
---|
| 2288 | + struct msdc_host *host = mmc_priv(mmc); |
---|
| 2289 | + unsigned int val = 0; |
---|
| 2290 | + |
---|
| 2291 | + /* disable cmdq irq */ |
---|
| 2292 | + sdr_clr_bits(host->base + MSDC_INTEN, MSDC_INT_CMDQ); |
---|
| 2293 | + /* disable busy check */ |
---|
| 2294 | + sdr_clr_bits(host->base + MSDC_PATCH_BIT1, MSDC_PB1_BUSY_CHECK_SEL); |
---|
| 2295 | + |
---|
| 2296 | + val = readl(host->base + MSDC_INT); |
---|
| 2297 | + writel(val, host->base + MSDC_INT); |
---|
| 2298 | + |
---|
| 2299 | + if (recovery) { |
---|
| 2300 | + sdr_set_field(host->base + MSDC_DMA_CTRL, |
---|
| 2301 | + MSDC_DMA_CTRL_STOP, 1); |
---|
| 2302 | + if (WARN_ON(readl_poll_timeout(host->base + MSDC_DMA_CFG, val, |
---|
| 2303 | + !(val & MSDC_DMA_CFG_STS), 1, 3000))) |
---|
| 2304 | + return; |
---|
| 2305 | + msdc_reset_hw(host); |
---|
| 2306 | + } |
---|
| 2307 | +} |
---|
| 2308 | + |
---|
| 2309 | +static void msdc_cqe_pre_enable(struct mmc_host *mmc) |
---|
| 2310 | +{ |
---|
| 2311 | + struct cqhci_host *cq_host = mmc->cqe_private; |
---|
| 2312 | + u32 reg; |
---|
| 2313 | + |
---|
| 2314 | + reg = cqhci_readl(cq_host, CQHCI_CFG); |
---|
| 2315 | + reg |= CQHCI_ENABLE; |
---|
| 2316 | + cqhci_writel(cq_host, reg, CQHCI_CFG); |
---|
| 2317 | +} |
---|
| 2318 | + |
---|
| 2319 | +static void msdc_cqe_post_disable(struct mmc_host *mmc) |
---|
| 2320 | +{ |
---|
| 2321 | + struct cqhci_host *cq_host = mmc->cqe_private; |
---|
| 2322 | + u32 reg; |
---|
| 2323 | + |
---|
| 2324 | + reg = cqhci_readl(cq_host, CQHCI_CFG); |
---|
| 2325 | + reg &= ~CQHCI_ENABLE; |
---|
| 2326 | + cqhci_writel(cq_host, reg, CQHCI_CFG); |
---|
| 2327 | +} |
---|
| 2328 | + |
---|
1827 | 2329 | static const struct mmc_host_ops mt_msdc_ops = { |
---|
1828 | 2330 | .post_req = msdc_post_req, |
---|
1829 | 2331 | .pre_req = msdc_pre_req, |
---|
1830 | 2332 | .request = msdc_ops_request, |
---|
1831 | 2333 | .set_ios = msdc_ops_set_ios, |
---|
1832 | 2334 | .get_ro = mmc_gpio_get_ro, |
---|
1833 | | - .get_cd = mmc_gpio_get_cd, |
---|
| 2335 | + .get_cd = msdc_get_cd, |
---|
| 2336 | + .enable_sdio_irq = msdc_enable_sdio_irq, |
---|
| 2337 | + .ack_sdio_irq = msdc_ack_sdio_irq, |
---|
1834 | 2338 | .start_signal_voltage_switch = msdc_ops_switch_volt, |
---|
1835 | 2339 | .card_busy = msdc_card_busy, |
---|
1836 | 2340 | .execute_tuning = msdc_execute_tuning, |
---|
1837 | 2341 | .prepare_hs400_tuning = msdc_prepare_hs400_tuning, |
---|
1838 | 2342 | .hw_reset = msdc_hw_reset, |
---|
| 2343 | +}; |
---|
| 2344 | + |
---|
| 2345 | +static const struct cqhci_host_ops msdc_cmdq_ops = { |
---|
| 2346 | + .enable = msdc_cqe_enable, |
---|
| 2347 | + .disable = msdc_cqe_disable, |
---|
| 2348 | + .pre_enable = msdc_cqe_pre_enable, |
---|
| 2349 | + .post_disable = msdc_cqe_post_disable, |
---|
1839 | 2350 | }; |
---|
1840 | 2351 | |
---|
1841 | 2352 | static void msdc_of_property_parse(struct platform_device *pdev, |
---|
.. | .. |
---|
1858 | 2369 | host->hs400_cmd_resp_sel_rising = true; |
---|
1859 | 2370 | else |
---|
1860 | 2371 | host->hs400_cmd_resp_sel_rising = false; |
---|
| 2372 | + |
---|
| 2373 | + if (of_property_read_bool(pdev->dev.of_node, |
---|
| 2374 | + "supports-cqe")) |
---|
| 2375 | + host->cqhci = true; |
---|
| 2376 | + else |
---|
| 2377 | + host->cqhci = false; |
---|
1861 | 2378 | } |
---|
1862 | 2379 | |
---|
1863 | 2380 | static int msdc_drv_probe(struct platform_device *pdev) |
---|
.. | .. |
---|
1882 | 2399 | if (ret) |
---|
1883 | 2400 | goto host_free; |
---|
1884 | 2401 | |
---|
1885 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
---|
1886 | | - host->base = devm_ioremap_resource(&pdev->dev, res); |
---|
| 2402 | + host->base = devm_platform_ioremap_resource(pdev, 0); |
---|
1887 | 2403 | if (IS_ERR(host->base)) { |
---|
1888 | 2404 | ret = PTR_ERR(host->base); |
---|
1889 | 2405 | goto host_free; |
---|
| 2406 | + } |
---|
| 2407 | + |
---|
| 2408 | + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
---|
| 2409 | + if (res) { |
---|
| 2410 | + host->top_base = devm_ioremap_resource(&pdev->dev, res); |
---|
| 2411 | + if (IS_ERR(host->top_base)) |
---|
| 2412 | + host->top_base = NULL; |
---|
1890 | 2413 | } |
---|
1891 | 2414 | |
---|
1892 | 2415 | ret = mmc_regulator_get_supply(mmc); |
---|
.. | .. |
---|
1905 | 2428 | goto host_free; |
---|
1906 | 2429 | } |
---|
1907 | 2430 | |
---|
| 2431 | + host->bus_clk = devm_clk_get(&pdev->dev, "bus_clk"); |
---|
| 2432 | + if (IS_ERR(host->bus_clk)) |
---|
| 2433 | + host->bus_clk = NULL; |
---|
1908 | 2434 | /*source clock control gate is optional clock*/ |
---|
1909 | 2435 | host->src_clk_cg = devm_clk_get(&pdev->dev, "source_cg"); |
---|
1910 | 2436 | if (IS_ERR(host->src_clk_cg)) |
---|
1911 | 2437 | host->src_clk_cg = NULL; |
---|
1912 | 2438 | |
---|
| 2439 | + host->reset = devm_reset_control_get_optional_exclusive(&pdev->dev, |
---|
| 2440 | + "hrst"); |
---|
| 2441 | + if (IS_ERR(host->reset)) |
---|
| 2442 | + return PTR_ERR(host->reset); |
---|
| 2443 | + |
---|
1913 | 2444 | host->irq = platform_get_irq(pdev, 0); |
---|
1914 | 2445 | if (host->irq < 0) { |
---|
1915 | | - ret = -EINVAL; |
---|
| 2446 | + ret = host->irq; |
---|
1916 | 2447 | goto host_free; |
---|
1917 | 2448 | } |
---|
1918 | 2449 | |
---|
.. | .. |
---|
1941 | 2472 | |
---|
1942 | 2473 | host->dev = &pdev->dev; |
---|
1943 | 2474 | host->dev_comp = of_device_get_match_data(&pdev->dev); |
---|
1944 | | - host->mmc = mmc; |
---|
1945 | 2475 | host->src_clk_freq = clk_get_rate(host->src_clk); |
---|
1946 | 2476 | /* Set host parameters to mmc */ |
---|
1947 | 2477 | mmc->ops = &mt_msdc_ops; |
---|
.. | .. |
---|
1950 | 2480 | else |
---|
1951 | 2481 | mmc->f_min = DIV_ROUND_UP(host->src_clk_freq, 4 * 4095); |
---|
1952 | 2482 | |
---|
1953 | | - mmc->caps |= MMC_CAP_ERASE | MMC_CAP_CMD23; |
---|
| 2483 | + if (!(mmc->caps & MMC_CAP_NONREMOVABLE) && |
---|
| 2484 | + !mmc_can_gpio_cd(mmc) && |
---|
| 2485 | + host->dev_comp->use_internal_cd) { |
---|
| 2486 | + /* |
---|
| 2487 | + * Is removable but no GPIO declared, so |
---|
| 2488 | + * use internal functionality. |
---|
| 2489 | + */ |
---|
| 2490 | + host->internal_cd = true; |
---|
| 2491 | + } |
---|
| 2492 | + |
---|
| 2493 | + if (mmc->caps & MMC_CAP_SDIO_IRQ) |
---|
| 2494 | + mmc->caps2 |= MMC_CAP2_SDIO_IRQ_NOTHREAD; |
---|
| 2495 | + |
---|
| 2496 | + mmc->caps |= MMC_CAP_CMD23; |
---|
| 2497 | + if (host->cqhci) |
---|
| 2498 | + mmc->caps2 |= MMC_CAP2_CQE | MMC_CAP2_CQE_DCMD; |
---|
1954 | 2499 | /* MMC core transfer sizes tunable parameters */ |
---|
1955 | 2500 | mmc->max_segs = MAX_BD_NUM; |
---|
1956 | | - mmc->max_seg_size = BDMA_DESC_BUFLEN; |
---|
| 2501 | + if (host->dev_comp->support_64g) |
---|
| 2502 | + mmc->max_seg_size = BDMA_DESC_BUFLEN_EXT; |
---|
| 2503 | + else |
---|
| 2504 | + mmc->max_seg_size = BDMA_DESC_BUFLEN; |
---|
1957 | 2505 | mmc->max_blk_size = 2048; |
---|
1958 | 2506 | mmc->max_req_size = 512 * 1024; |
---|
1959 | 2507 | mmc->max_blk_count = mmc->max_req_size / 512; |
---|
.. | .. |
---|
1982 | 2530 | msdc_ungate_clock(host); |
---|
1983 | 2531 | msdc_init_hw(host); |
---|
1984 | 2532 | |
---|
| 2533 | + if (mmc->caps2 & MMC_CAP2_CQE) { |
---|
| 2534 | + host->cq_host = devm_kzalloc(mmc->parent, |
---|
| 2535 | + sizeof(*host->cq_host), |
---|
| 2536 | + GFP_KERNEL); |
---|
| 2537 | + if (!host->cq_host) { |
---|
| 2538 | + ret = -ENOMEM; |
---|
| 2539 | + goto host_free; |
---|
| 2540 | + } |
---|
| 2541 | + host->cq_host->caps |= CQHCI_TASK_DESC_SZ_128; |
---|
| 2542 | + host->cq_host->mmio = host->base + 0x800; |
---|
| 2543 | + host->cq_host->ops = &msdc_cmdq_ops; |
---|
| 2544 | + ret = cqhci_init(host->cq_host, mmc, true); |
---|
| 2545 | + if (ret) |
---|
| 2546 | + goto host_free; |
---|
| 2547 | + mmc->max_segs = 128; |
---|
| 2548 | + /* cqhci 16bit length */ |
---|
| 2549 | + /* 0 size, means 65536 so we don't have to -1 here */ |
---|
| 2550 | + mmc->max_seg_size = 64 * 1024; |
---|
| 2551 | + } |
---|
| 2552 | + |
---|
1985 | 2553 | ret = devm_request_irq(&pdev->dev, host->irq, msdc_irq, |
---|
1986 | | - IRQF_TRIGGER_LOW | IRQF_ONESHOT, pdev->name, host); |
---|
| 2554 | + IRQF_TRIGGER_NONE, pdev->name, host); |
---|
1987 | 2555 | if (ret) |
---|
1988 | 2556 | goto release; |
---|
1989 | 2557 | |
---|
.. | .. |
---|
2029 | 2597 | pm_runtime_get_sync(host->dev); |
---|
2030 | 2598 | |
---|
2031 | 2599 | platform_set_drvdata(pdev, NULL); |
---|
2032 | | - mmc_remove_host(host->mmc); |
---|
| 2600 | + mmc_remove_host(mmc); |
---|
2033 | 2601 | msdc_deinit_hw(host); |
---|
2034 | 2602 | msdc_gate_clock(host); |
---|
2035 | 2603 | |
---|
.. | .. |
---|
2041 | 2609 | dma_free_coherent(&pdev->dev, MAX_BD_NUM * sizeof(struct mt_bdma_desc), |
---|
2042 | 2610 | host->dma.bd, host->dma.bd_addr); |
---|
2043 | 2611 | |
---|
2044 | | - mmc_free_host(host->mmc); |
---|
| 2612 | + mmc_free_host(mmc); |
---|
2045 | 2613 | |
---|
2046 | 2614 | return 0; |
---|
2047 | 2615 | } |
---|
2048 | 2616 | |
---|
2049 | | -#ifdef CONFIG_PM |
---|
2050 | 2617 | static void msdc_save_reg(struct msdc_host *host) |
---|
2051 | 2618 | { |
---|
2052 | 2619 | u32 tune_reg = host->dev_comp->pad_tune_reg; |
---|
.. | .. |
---|
2054 | 2621 | host->save_para.msdc_cfg = readl(host->base + MSDC_CFG); |
---|
2055 | 2622 | host->save_para.iocon = readl(host->base + MSDC_IOCON); |
---|
2056 | 2623 | host->save_para.sdc_cfg = readl(host->base + SDC_CFG); |
---|
2057 | | - host->save_para.pad_tune = readl(host->base + tune_reg); |
---|
2058 | 2624 | host->save_para.patch_bit0 = readl(host->base + MSDC_PATCH_BIT); |
---|
2059 | 2625 | host->save_para.patch_bit1 = readl(host->base + MSDC_PATCH_BIT1); |
---|
2060 | 2626 | host->save_para.patch_bit2 = readl(host->base + MSDC_PATCH_BIT2); |
---|
.. | .. |
---|
2063 | 2629 | host->save_para.emmc50_cfg0 = readl(host->base + EMMC50_CFG0); |
---|
2064 | 2630 | host->save_para.emmc50_cfg3 = readl(host->base + EMMC50_CFG3); |
---|
2065 | 2631 | host->save_para.sdc_fifo_cfg = readl(host->base + SDC_FIFO_CFG); |
---|
| 2632 | + if (host->top_base) { |
---|
| 2633 | + host->save_para.emmc_top_control = |
---|
| 2634 | + readl(host->top_base + EMMC_TOP_CONTROL); |
---|
| 2635 | + host->save_para.emmc_top_cmd = |
---|
| 2636 | + readl(host->top_base + EMMC_TOP_CMD); |
---|
| 2637 | + host->save_para.emmc50_pad_ds_tune = |
---|
| 2638 | + readl(host->top_base + EMMC50_PAD_DS_TUNE); |
---|
| 2639 | + } else { |
---|
| 2640 | + host->save_para.pad_tune = readl(host->base + tune_reg); |
---|
| 2641 | + } |
---|
2066 | 2642 | } |
---|
2067 | 2643 | |
---|
2068 | 2644 | static void msdc_restore_reg(struct msdc_host *host) |
---|
2069 | 2645 | { |
---|
| 2646 | + struct mmc_host *mmc = mmc_from_priv(host); |
---|
2070 | 2647 | u32 tune_reg = host->dev_comp->pad_tune_reg; |
---|
2071 | 2648 | |
---|
2072 | 2649 | writel(host->save_para.msdc_cfg, host->base + MSDC_CFG); |
---|
2073 | 2650 | writel(host->save_para.iocon, host->base + MSDC_IOCON); |
---|
2074 | 2651 | writel(host->save_para.sdc_cfg, host->base + SDC_CFG); |
---|
2075 | | - writel(host->save_para.pad_tune, host->base + tune_reg); |
---|
2076 | 2652 | writel(host->save_para.patch_bit0, host->base + MSDC_PATCH_BIT); |
---|
2077 | 2653 | writel(host->save_para.patch_bit1, host->base + MSDC_PATCH_BIT1); |
---|
2078 | 2654 | writel(host->save_para.patch_bit2, host->base + MSDC_PATCH_BIT2); |
---|
.. | .. |
---|
2081 | 2657 | writel(host->save_para.emmc50_cfg0, host->base + EMMC50_CFG0); |
---|
2082 | 2658 | writel(host->save_para.emmc50_cfg3, host->base + EMMC50_CFG3); |
---|
2083 | 2659 | writel(host->save_para.sdc_fifo_cfg, host->base + SDC_FIFO_CFG); |
---|
| 2660 | + if (host->top_base) { |
---|
| 2661 | + writel(host->save_para.emmc_top_control, |
---|
| 2662 | + host->top_base + EMMC_TOP_CONTROL); |
---|
| 2663 | + writel(host->save_para.emmc_top_cmd, |
---|
| 2664 | + host->top_base + EMMC_TOP_CMD); |
---|
| 2665 | + writel(host->save_para.emmc50_pad_ds_tune, |
---|
| 2666 | + host->top_base + EMMC50_PAD_DS_TUNE); |
---|
| 2667 | + } else { |
---|
| 2668 | + writel(host->save_para.pad_tune, host->base + tune_reg); |
---|
| 2669 | + } |
---|
| 2670 | + |
---|
| 2671 | + if (sdio_irq_claimed(mmc)) |
---|
| 2672 | + __msdc_enable_sdio_irq(host, 1); |
---|
2084 | 2673 | } |
---|
2085 | 2674 | |
---|
2086 | | -static int msdc_runtime_suspend(struct device *dev) |
---|
| 2675 | +static int __maybe_unused msdc_runtime_suspend(struct device *dev) |
---|
2087 | 2676 | { |
---|
2088 | 2677 | struct mmc_host *mmc = dev_get_drvdata(dev); |
---|
2089 | 2678 | struct msdc_host *host = mmc_priv(mmc); |
---|
.. | .. |
---|
2093 | 2682 | return 0; |
---|
2094 | 2683 | } |
---|
2095 | 2684 | |
---|
2096 | | -static int msdc_runtime_resume(struct device *dev) |
---|
| 2685 | +static int __maybe_unused msdc_runtime_resume(struct device *dev) |
---|
2097 | 2686 | { |
---|
2098 | 2687 | struct mmc_host *mmc = dev_get_drvdata(dev); |
---|
2099 | 2688 | struct msdc_host *host = mmc_priv(mmc); |
---|
.. | .. |
---|
2102 | 2691 | msdc_restore_reg(host); |
---|
2103 | 2692 | return 0; |
---|
2104 | 2693 | } |
---|
2105 | | -#endif |
---|
| 2694 | + |
---|
| 2695 | +static int __maybe_unused msdc_suspend(struct device *dev) |
---|
| 2696 | +{ |
---|
| 2697 | + struct mmc_host *mmc = dev_get_drvdata(dev); |
---|
| 2698 | + int ret; |
---|
| 2699 | + u32 val; |
---|
| 2700 | + |
---|
| 2701 | + if (mmc->caps2 & MMC_CAP2_CQE) { |
---|
| 2702 | + ret = cqhci_suspend(mmc); |
---|
| 2703 | + if (ret) |
---|
| 2704 | + return ret; |
---|
| 2705 | + val = readl(((struct msdc_host *)mmc_priv(mmc))->base + MSDC_INT); |
---|
| 2706 | + writel(val, ((struct msdc_host *)mmc_priv(mmc))->base + MSDC_INT); |
---|
| 2707 | + } |
---|
| 2708 | + |
---|
| 2709 | + return pm_runtime_force_suspend(dev); |
---|
| 2710 | +} |
---|
| 2711 | + |
---|
| 2712 | +static int __maybe_unused msdc_resume(struct device *dev) |
---|
| 2713 | +{ |
---|
| 2714 | + return pm_runtime_force_resume(dev); |
---|
| 2715 | +} |
---|
2106 | 2716 | |
---|
2107 | 2717 | static const struct dev_pm_ops msdc_dev_pm_ops = { |
---|
2108 | | - SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, |
---|
2109 | | - pm_runtime_force_resume) |
---|
| 2718 | + SET_SYSTEM_SLEEP_PM_OPS(msdc_suspend, msdc_resume) |
---|
2110 | 2719 | SET_RUNTIME_PM_OPS(msdc_runtime_suspend, msdc_runtime_resume, NULL) |
---|
2111 | 2720 | }; |
---|
2112 | 2721 | |
---|
.. | .. |
---|
2115 | 2724 | .remove = msdc_drv_remove, |
---|
2116 | 2725 | .driver = { |
---|
2117 | 2726 | .name = "mtk-msdc", |
---|
| 2727 | + .probe_type = PROBE_PREFER_ASYNCHRONOUS, |
---|
2118 | 2728 | .of_match_table = msdc_of_ids, |
---|
2119 | 2729 | .pm = &msdc_dev_pm_ops, |
---|
2120 | 2730 | }, |
---|