Jun Nie | 988e3b6 | 2018-06-28 16:38:02 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. |
Ghennadi Procopciuc | 376534a | 2025-04-04 09:52:42 +0300 | [diff] [blame] | 3 | * Copyright 2025 NXP |
Jun Nie | 988e3b6 | 2018-06-28 16:38:02 +0800 | [diff] [blame] | 4 | * |
| 5 | * SPDX-License-Identifier: BSD-3-Clause |
| 6 | */ |
| 7 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 8 | #ifndef IMX_USDHC_H |
| 9 | #define IMX_USDHC_H |
Jun Nie | 988e3b6 | 2018-06-28 16:38:02 +0800 | [diff] [blame] | 10 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 11 | #include <drivers/mmc.h> |
Jun Nie | 988e3b6 | 2018-06-28 16:38:02 +0800 | [diff] [blame] | 12 | |
| 13 | typedef struct imx_usdhc_params { |
| 14 | uintptr_t reg_base; |
Ghennadi Procopciuc | a291874 | 2025-04-04 12:13:26 +0300 | [diff] [blame] | 15 | unsigned int clk_rate; |
| 16 | unsigned int bus_width; |
Jun Nie | 988e3b6 | 2018-06-28 16:38:02 +0800 | [diff] [blame] | 17 | unsigned int flags; |
| 18 | } imx_usdhc_params_t; |
| 19 | |
| 20 | void imx_usdhc_init(imx_usdhc_params_t *params, |
| 21 | struct mmc_device_info *mmc_dev_info); |
| 22 | |
| 23 | /* iMX MMC registers definition */ |
Ghennadi Procopciuc | 376534a | 2025-04-04 09:52:42 +0300 | [diff] [blame] | 24 | #define DSADDR 0x000U |
| 25 | #define BLKATT 0x004U |
Ghennadi Procopciuc | 8da3b43 | 2025-03-17 22:54:41 +0200 | [diff] [blame] | 26 | #define BLKATT_BLKCNT(x) (((x) << 16U) & GENMASK_32(31U, 16U)) |
| 27 | #define BLKATT_BLKSIZE(x) ((x) & GENMASK_32(12U, 0U)) |
Ghennadi Procopciuc | 376534a | 2025-04-04 09:52:42 +0300 | [diff] [blame] | 28 | #define CMDARG 0x008U |
| 29 | #define CMDRSP0 0x010U |
| 30 | #define CMDRSP1 0x014U |
| 31 | #define CMDRSP2 0x018U |
| 32 | #define CMDRSP3 0x01cU |
Jun Nie | 988e3b6 | 2018-06-28 16:38:02 +0800 | [diff] [blame] | 33 | |
Ghennadi Procopciuc | 376534a | 2025-04-04 09:52:42 +0300 | [diff] [blame] | 34 | #define XFERTYPE 0x00cU |
| 35 | #define XFERTYPE_CMD(x) (((x) & 0x3fU) << 24U) |
Ghennadi Procopciuc | 3f642e8 | 2025-03-17 12:21:13 +0200 | [diff] [blame] | 36 | #define XFERTYPE_GET_CMD(x) (((x) & GENMASK_32(29U, 24U)) >> 24U) |
Ghennadi Procopciuc | 376534a | 2025-04-04 09:52:42 +0300 | [diff] [blame] | 37 | #define XFERTYPE_CMDTYP_ABORT (3U << 22U) |
| 38 | #define XFERTYPE_DPSEL BIT_32(21U) |
| 39 | #define XFERTYPE_CICEN BIT_32(20U) |
| 40 | #define XFERTYPE_CCCEN BIT_32(19U) |
| 41 | #define XFERTYPE_RSPTYP_136 BIT_32(16U) |
| 42 | #define XFERTYPE_RSPTYP_48 BIT_32(17U) |
| 43 | #define XFERTYPE_RSPTYP_48_BUSY (BIT_32(16U) | BIT_32(17U)) |
Jun Nie | 988e3b6 | 2018-06-28 16:38:02 +0800 | [diff] [blame] | 44 | |
Ghennadi Procopciuc | 376534a | 2025-04-04 09:52:42 +0300 | [diff] [blame] | 45 | #define PSTATE 0x024U |
| 46 | #define PSTATE_DAT0 BIT_32(24U) |
Ghennadi Procopciuc | 8bad0c0 | 2025-03-28 08:44:47 +0200 | [diff] [blame^] | 47 | #define PSTATE_SDSTB BIT_32(3U) |
Ghennadi Procopciuc | 376534a | 2025-04-04 09:52:42 +0300 | [diff] [blame] | 48 | #define PSTATE_DLA BIT_32(2U) |
| 49 | #define PSTATE_CDIHB BIT_32(1U) |
| 50 | #define PSTATE_CIHB BIT_32(0U) |
Jun Nie | 988e3b6 | 2018-06-28 16:38:02 +0800 | [diff] [blame] | 51 | |
Ghennadi Procopciuc | 376534a | 2025-04-04 09:52:42 +0300 | [diff] [blame] | 52 | #define PROTCTRL 0x028U |
| 53 | #define PROTCTRL_LE BIT_32(5U) |
| 54 | #define PROTCTRL_WIDTH_4 BIT_32(1U) |
| 55 | #define PROTCTRL_WIDTH_8 BIT_32(2U) |
| 56 | #define PROTCTRL_WIDTH_MASK 0x6U |
Jun Nie | 988e3b6 | 2018-06-28 16:38:02 +0800 | [diff] [blame] | 57 | |
Ghennadi Procopciuc | 376534a | 2025-04-04 09:52:42 +0300 | [diff] [blame] | 58 | #define SYSCTRL 0x02cU |
| 59 | #define SYSCTRL_RSTD BIT_32(26U) |
| 60 | #define SYSCTRL_RSTC BIT_32(25U) |
| 61 | #define SYSCTRL_RSTA BIT_32(24U) |
| 62 | #define SYSCTRL_CLOCK_MASK GENMASK_32(15U, 4U) |
| 63 | #define SYSCTRL_TIMEOUT_MASK GENMASK_32(19U, 16U) |
| 64 | #define SYSCTRL_TIMEOUT(x) ((0xfU & (x)) << 16U) |
Jun Nie | 988e3b6 | 2018-06-28 16:38:02 +0800 | [diff] [blame] | 65 | |
Ghennadi Procopciuc | 376534a | 2025-04-04 09:52:42 +0300 | [diff] [blame] | 66 | #define INTSTAT 0x030U |
| 67 | #define INTSTAT_DMAE BIT_32(28U) |
| 68 | #define INTSTAT_DEBE BIT_32(22U) |
| 69 | #define INTSTAT_DCE BIT_32(21U) |
| 70 | #define INTSTAT_DTOE BIT_32(20U) |
| 71 | #define INTSTAT_CIE BIT_32(19U) |
| 72 | #define INTSTAT_CEBE BIT_32(18U) |
| 73 | #define INTSTAT_CCE BIT_32(17U) |
| 74 | #define INTSTAT_DINT BIT_32(3U) |
| 75 | #define INTSTAT_BGE BIT_32(2U) |
| 76 | #define INTSTAT_TC BIT_32(1U) |
| 77 | #define INTSTAT_CC BIT_32(0U) |
Jun Nie | 988e3b6 | 2018-06-28 16:38:02 +0800 | [diff] [blame] | 78 | #define CMD_ERR (INTSTAT_CIE | INTSTAT_CEBE | INTSTAT_CCE) |
| 79 | #define DATA_ERR (INTSTAT_DMAE | INTSTAT_DEBE | INTSTAT_DCE | \ |
| 80 | INTSTAT_DTOE) |
| 81 | #define DATA_COMPLETE (INTSTAT_DINT | INTSTAT_TC) |
| 82 | |
Ghennadi Procopciuc | 376534a | 2025-04-04 09:52:42 +0300 | [diff] [blame] | 83 | #define INTSTATEN 0x034U |
| 84 | #define INTSTATEN_DEBE BIT_32(22U) |
| 85 | #define INTSTATEN_DCE BIT_32(21U) |
| 86 | #define INTSTATEN_DTOE BIT_32(20U) |
| 87 | #define INTSTATEN_CIE BIT_32(19U) |
| 88 | #define INTSTATEN_CEBE BIT_32(18U) |
| 89 | #define INTSTATEN_CCE BIT_32(17U) |
| 90 | #define INTSTATEN_CTOE BIT_32(16U) |
| 91 | #define INTSTATEN_CINT BIT_32(8U) |
| 92 | #define INTSTATEN_BRR BIT_32(5U) |
| 93 | #define INTSTATEN_BWR BIT_32(4U) |
| 94 | #define INTSTATEN_DINT BIT_32(3U) |
| 95 | #define INTSTATEN_TC BIT_32(1U) |
| 96 | #define INTSTATEN_CC BIT_32(0U) |
Jun Nie | 988e3b6 | 2018-06-28 16:38:02 +0800 | [diff] [blame] | 97 | #define EMMC_INTSTATEN_BITS (INTSTATEN_CC | INTSTATEN_TC | INTSTATEN_DINT | \ |
| 98 | INTSTATEN_BWR | INTSTATEN_BRR | INTSTATEN_CINT | \ |
| 99 | INTSTATEN_CTOE | INTSTATEN_CCE | INTSTATEN_CEBE | \ |
| 100 | INTSTATEN_CIE | INTSTATEN_DTOE | INTSTATEN_DCE | \ |
| 101 | INTSTATEN_DEBE) |
| 102 | |
Ghennadi Procopciuc | 376534a | 2025-04-04 09:52:42 +0300 | [diff] [blame] | 103 | #define INTSIGEN 0x038U |
Jun Nie | 988e3b6 | 2018-06-28 16:38:02 +0800 | [diff] [blame] | 104 | |
Ghennadi Procopciuc | 376534a | 2025-04-04 09:52:42 +0300 | [diff] [blame] | 105 | #define WATERMARKLEV 0x044U |
| 106 | #define WMKLV_RD_MASK GENMASK_32(7U, 0U) |
| 107 | #define WMKLV_WR_MASK GENMASK_32(23U, 16U) |
Jun Nie | 988e3b6 | 2018-06-28 16:38:02 +0800 | [diff] [blame] | 108 | #define WMKLV_MASK (WMKLV_RD_MASK | WMKLV_WR_MASK) |
| 109 | |
Ghennadi Procopciuc | 376534a | 2025-04-04 09:52:42 +0300 | [diff] [blame] | 110 | #define MIXCTRL 0x048U |
| 111 | #define MIXCTRL_MSBSEL BIT_32(5U) |
| 112 | #define MIXCTRL_DTDSEL BIT_32(4U) |
| 113 | #define MIXCTRL_DDREN BIT_32(3U) |
| 114 | #define MIXCTRL_AC12EN BIT_32(2U) |
| 115 | #define MIXCTRL_BCEN BIT_32(1U) |
| 116 | #define MIXCTRL_DMAEN BIT_32(0U) |
| 117 | #define MIXCTRL_DATMASK 0x7fU |
Jun Nie | 988e3b6 | 2018-06-28 16:38:02 +0800 | [diff] [blame] | 118 | |
Ghennadi Procopciuc | 376534a | 2025-04-04 09:52:42 +0300 | [diff] [blame] | 119 | #define DLLCTRL 0x060U |
Jun Nie | 988e3b6 | 2018-06-28 16:38:02 +0800 | [diff] [blame] | 120 | |
Ghennadi Procopciuc | 376534a | 2025-04-04 09:52:42 +0300 | [diff] [blame] | 121 | #define CLKTUNECTRLSTS 0x068U |
Jun Nie | 988e3b6 | 2018-06-28 16:38:02 +0800 | [diff] [blame] | 122 | |
Ghennadi Procopciuc | 376534a | 2025-04-04 09:52:42 +0300 | [diff] [blame] | 123 | #define VENDSPEC 0x0c0U |
| 124 | #define VENDSPEC_RSRV1 BIT_32(29U) |
| 125 | #define VENDSPEC_CARD_CLKEN BIT_32(14U) |
| 126 | #define VENDSPEC_PER_CLKEN BIT_32(13U) |
| 127 | #define VENDSPEC_AHB_CLKEN BIT_32(12U) |
| 128 | #define VENDSPEC_IPG_CLKEN BIT_32(11U) |
| 129 | #define VENDSPEC_AC12_CHKBUSY BIT_32(3U) |
| 130 | #define VENDSPEC_EXTDMA BIT_32(0U) |
Jun Nie | 988e3b6 | 2018-06-28 16:38:02 +0800 | [diff] [blame] | 131 | #define VENDSPEC_INIT (VENDSPEC_RSRV1 | VENDSPEC_CARD_CLKEN | \ |
| 132 | VENDSPEC_PER_CLKEN | VENDSPEC_AHB_CLKEN | \ |
| 133 | VENDSPEC_IPG_CLKEN | VENDSPEC_AC12_CHKBUSY | \ |
| 134 | VENDSPEC_EXTDMA) |
| 135 | |
Ghennadi Procopciuc | 376534a | 2025-04-04 09:52:42 +0300 | [diff] [blame] | 136 | #define MMCBOOT 0x0c4U |
Jun Nie | 988e3b6 | 2018-06-28 16:38:02 +0800 | [diff] [blame] | 137 | |
| 138 | #define mmio_clrsetbits32(addr, clear, set) mmio_write_32(addr, (mmio_read_32(addr) & ~(clear)) | (set)) |
| 139 | #define mmio_clrbits32(addr, clear) mmio_write_32(addr, mmio_read_32(addr) & ~(clear)) |
| 140 | #define mmio_setbits32(addr, set) mmio_write_32(addr, mmio_read_32(addr) | (set)) |
| 141 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 142 | #endif /* IMX_USDHC_H */ |