11bd4fe43Sopenharmony_ci/* 21bd4fe43Sopenharmony_ci * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 31bd4fe43Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 41bd4fe43Sopenharmony_ci * you may not use this file except in compliance with the License. 51bd4fe43Sopenharmony_ci * You may obtain a copy of the License at 61bd4fe43Sopenharmony_ci * 71bd4fe43Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 81bd4fe43Sopenharmony_ci * 91bd4fe43Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 101bd4fe43Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 111bd4fe43Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 121bd4fe43Sopenharmony_ci * See the License for the specific language governing permissions and 131bd4fe43Sopenharmony_ci * limitations under the License. 141bd4fe43Sopenharmony_ci */ 151bd4fe43Sopenharmony_ci 161bd4fe43Sopenharmony_ci#ifndef HIMCI_H 171bd4fe43Sopenharmony_ci#define HIMCI_H 181bd4fe43Sopenharmony_ci 191bd4fe43Sopenharmony_ci#include "asm/dma.h" 201bd4fe43Sopenharmony_ci#include "asm/io.h" 211bd4fe43Sopenharmony_ci#include "asm/platform.h" 221bd4fe43Sopenharmony_ci#include "device_resource_if.h" 231bd4fe43Sopenharmony_ci#include "linux/scatterlist.h" 241bd4fe43Sopenharmony_ci#include "los_event.h" 251bd4fe43Sopenharmony_ci#include "los_vm_iomap.h" 261bd4fe43Sopenharmony_ci#include "los_vm_zone.h" 271bd4fe43Sopenharmony_ci#include "mmc_corex.h" 281bd4fe43Sopenharmony_ci#include "osal_io.h" 291bd4fe43Sopenharmony_ci#include "osal_irq.h" 301bd4fe43Sopenharmony_ci#include "osal_time.h" 311bd4fe43Sopenharmony_ci 321bd4fe43Sopenharmony_ci#ifdef __cplusplus 331bd4fe43Sopenharmony_ci#if __cplusplus 341bd4fe43Sopenharmony_ciextern "C" { 351bd4fe43Sopenharmony_ci#endif /* __cplusplus */ 361bd4fe43Sopenharmony_ci#endif /* __cplusplus */ 371bd4fe43Sopenharmony_ci 381bd4fe43Sopenharmony_ci#define HIMCI_MAX_RETRY_COUNT 100 391bd4fe43Sopenharmony_ci#define HIMCI_PAGE_SIZE 4096 401bd4fe43Sopenharmony_ci#define HIMCI_DMA_MAX_BUFF_SIZE 0x1000 411bd4fe43Sopenharmony_ci 421bd4fe43Sopenharmony_ci#define HIMCI_MMC_FREQ_150M 150000000 431bd4fe43Sopenharmony_ci#define HIMCI_MMC_FREQ_100M 100000000 441bd4fe43Sopenharmony_ci#define HIMCI_MMC_FREQ_50M 50000000 451bd4fe43Sopenharmony_ci#define HIMCI_MMC_FREQ_25M 25000000 461bd4fe43Sopenharmony_ci 471bd4fe43Sopenharmony_ci/* register mapping */ 481bd4fe43Sopenharmony_ci#define PERI_CRG49 (CRG_REG_BASE + 0xC4) 491bd4fe43Sopenharmony_ci#define PERI_CRG50 (CRG_REG_BASE + 0xC8) 501bd4fe43Sopenharmony_ci#define PERI_CRG82 (CRG_REG_BASE + 0x0148) 511bd4fe43Sopenharmony_ci#define PERI_CRG83 (CRG_REG_BASE + 0x014C) 521bd4fe43Sopenharmony_ci#define PERI_CRG84 (CRG_REG_BASE + 0x0150) 531bd4fe43Sopenharmony_ci#define PERI_CRG85 (CRG_REG_BASE + 0x0154) 541bd4fe43Sopenharmony_ci#define PERI_CRG86 (CRG_REG_BASE + 0x0158) 551bd4fe43Sopenharmony_ci#define PERI_CRG87 (CRG_REG_BASE + 0x015C) 561bd4fe43Sopenharmony_ci#define PERI_CRG88 (CRG_REG_BASE + 0x0160) 571bd4fe43Sopenharmony_ci#define PERI_CRG89 (CRG_REG_BASE + 0x0164) 581bd4fe43Sopenharmony_ci#define PERI_CRG90 (CRG_REG_BASE + 0x0168) 591bd4fe43Sopenharmony_ci 601bd4fe43Sopenharmony_ci/* 611bd4fe43Sopenharmony_ci * PERI_CRG82/PERI_CRG88/PERI_CRG85 details. 621bd4fe43Sopenharmony_ci * [3:2]Working clock selection. 01: 100MHz; 10: 50MHz; 11: 25MHz. 631bd4fe43Sopenharmony_ci * [1]Clock gating. 0: disabled; 1: enabled. 641bd4fe43Sopenharmony_ci * [0]Soft reset request. 0: reset deasserted; 1: reset. 651bd4fe43Sopenharmony_ci */ 661bd4fe43Sopenharmony_ci#define HIMCI_CLK_SEL_MASK (3U << 2) 671bd4fe43Sopenharmony_ci#define HIMCI_CLK_SEL_100M (1U << 2) 681bd4fe43Sopenharmony_ci#define HIMCI_CLK_SEL_50M (2U << 2) 691bd4fe43Sopenharmony_ci#define HIMCI_CLK_SEL_25M (3U << 2) 701bd4fe43Sopenharmony_ci#define HIMCI_CKEN (1U << 1) 711bd4fe43Sopenharmony_ci#define HIMCI_RESET (1U << 0) 721bd4fe43Sopenharmony_ci 731bd4fe43Sopenharmony_ci/* 741bd4fe43Sopenharmony_ci * PERI_CRG83/PERI_CRG89/PERI_CRG86 details. 751bd4fe43Sopenharmony_ci * [19]SAP_DLL device delay line enable. 0: The device stops working. 1: The device starts to work. 761bd4fe43Sopenharmony_ci * [18]SAP_DLL host calculation clock cycle disable signal. 0: enabled; 1: Disable clock detection. 771bd4fe43Sopenharmony_ci * [17]SAP_DLL device LINE bypass. 0: normal mode; 1: device line bypass. 781bd4fe43Sopenharmony_ci * [16]SAP_DLL mode select. 0: normal mode; 1: The device line is controlled by the SAP_DLL_dllssel. 791bd4fe43Sopenharmony_ci * [15:8]SAP_DLL device LINE delay level select, valid when SAP_DLL_dllmode is high. 801bd4fe43Sopenharmony_ci * [7:4]SAP_DLL device tap calibration. 811bd4fe43Sopenharmony_ci * [1]SAP_DLL soft reset. 0: reset deasserted; 1: reset. [0]SAP_DLL clock gating. 0: disabled; 1: enabled. 821bd4fe43Sopenharmony_ci */ 831bd4fe43Sopenharmony_ci#define HIMCI_SAP_DLL_DEVICE_DELAY_ENABLE (1U << 19) 841bd4fe43Sopenharmony_ci#define HIMCI_SAP_DLL_MODE_DLLSSEL (1U << 16) 851bd4fe43Sopenharmony_ci#define HIMCI_SAP_DLL_SOFT_RESET (1U << 0) 861bd4fe43Sopenharmony_ci#define HIMCI_SAP_DLL_ELEMENT_SHIFT 8 871bd4fe43Sopenharmony_ci 881bd4fe43Sopenharmony_ci/* HI MCI CONFIGS */ 891bd4fe43Sopenharmony_ci#define HIMCI_REQUEST_TIMEOUT (10 * LOSCFG_BASE_CORE_TICK_PER_SECOND) /* 10s */ 901bd4fe43Sopenharmony_ci#define HIMCI_TUNINT_REQ_TIMEOUT (LOSCFG_BASE_CORE_TICK_PER_SECOND / 5) /* 0.2s */ 911bd4fe43Sopenharmony_ci#define HIMCI_CARD_COMPLETE_TIMEOUT (5 * LOSCFG_BASE_CORE_TICK_PER_SECOND) /* 5s */ 921bd4fe43Sopenharmony_ci 931bd4fe43Sopenharmony_ci#define HIMCI_READL(addr) OSAL_READL((uintptr_t)(addr)) 941bd4fe43Sopenharmony_ci 951bd4fe43Sopenharmony_ci#define HIMCI_WRITEL(v, addr) OSAL_WRITEL((v), (uintptr_t)(addr)) 961bd4fe43Sopenharmony_ci 971bd4fe43Sopenharmony_ci#define HIMCI_CLEARL(host, reg, v) OSAL_WRITEL(OSAL_READL((uintptr_t)(host)->base + (reg)) & (~(v)), \ 981bd4fe43Sopenharmony_ci (uintptr_t)(host)->base + (reg)); 991bd4fe43Sopenharmony_ci 1001bd4fe43Sopenharmony_ci#define HIMCI_SETL(host, reg, v) OSAL_WRITEL(OSAL_READL((uintptr_t)(host)->base + (reg)) | (v), \ 1011bd4fe43Sopenharmony_ci (uintptr_t)(host)->base + (reg)); 1021bd4fe43Sopenharmony_ci 1031bd4fe43Sopenharmony_ci/* define event lock */ 1041bd4fe43Sopenharmony_citypedef EVENT_CB_S HIMCI_EVENT; 1051bd4fe43Sopenharmony_ci#define HIMCI_EVENT_INIT(event) LOS_EventInit(event) 1061bd4fe43Sopenharmony_ci#define HIMCI_EVENT_SIGNAL(event, bit) LOS_EventWrite(event, bit) 1071bd4fe43Sopenharmony_ci#define HIMCI_EVENT_WAIT(event, bit, timeout) LOS_EventRead(event, bit, (LOS_WAITMODE_OR + LOS_WAITMODE_CLR), timeout) 1081bd4fe43Sopenharmony_ci#define HIMCI_EVENT_DELETE(event) LOS_EventDestroy(event) 1091bd4fe43Sopenharmony_ci 1101bd4fe43Sopenharmony_ci/* define task/irq lock */ 1111bd4fe43Sopenharmony_ci#define HIMCI_TASK_LOCK(lock) do { LOS_TaskLock(); } while (0) 1121bd4fe43Sopenharmony_ci#define HIMCI_TASK_UNLOCK(lock) do { LOS_TaskUnlock(); } while (0) 1131bd4fe43Sopenharmony_ci#define HIMCI_IRQ_LOCK(flags) do { (*(flags)) = LOS_IntLock(); } while (0) 1141bd4fe43Sopenharmony_ci#define HIMCI_IRQ_UNLOCK(flags) do { LOS_IntRestore(flags); } while (0) 1151bd4fe43Sopenharmony_ci 1161bd4fe43Sopenharmony_ci#define HIMCI_SG_DMA_ADDRESS(sg) ((sg)->dma_address) 1171bd4fe43Sopenharmony_ci#ifdef CONFIG_NEED_SG_DMA_LENGTH 1181bd4fe43Sopenharmony_ci#define HIMCI_SG_DMA_LEN(sg) ((sg)->dma_length) 1191bd4fe43Sopenharmony_ci#else 1201bd4fe43Sopenharmony_ci#define HIMCI_SG_DMA_LEN(sg) ((sg)->length) 1211bd4fe43Sopenharmony_ci#endif 1221bd4fe43Sopenharmony_ci 1231bd4fe43Sopenharmony_ci#define REG_CTRL_NUM 4 1241bd4fe43Sopenharmony_ci#define REG_CTRL_EMMC_START IO_DEVICE_ADDR(0x10ff0000 + 0x0) /* eMMC pad ctrl reg */ 1251bd4fe43Sopenharmony_ci#define REG_CTRL_SD_START IO_DEVICE_ADDR(0x10ff0000 + 0x24) /* sd pad ctrl reg */ 1261bd4fe43Sopenharmony_ci#define REG_CTRL_SDIO_START IO_DEVICE_ADDR(0x112f0000 + 0x8) /* sdio pad ctrl reg */ 1271bd4fe43Sopenharmony_ci 1281bd4fe43Sopenharmony_cienum HimciPowerStatus { 1291bd4fe43Sopenharmony_ci HOST_POWER_OFF, 1301bd4fe43Sopenharmony_ci HOST_POWER_ON, 1311bd4fe43Sopenharmony_ci}; 1321bd4fe43Sopenharmony_ci 1331bd4fe43Sopenharmony_cienum HimciDmaDataDirection { 1341bd4fe43Sopenharmony_ci DMA_BIDIRECTIONAL = 0, 1351bd4fe43Sopenharmony_ci DMA_TO_DEVICE = 1, 1361bd4fe43Sopenharmony_ci DMA_FROM_DEVICE = 2, 1371bd4fe43Sopenharmony_ci DMA_NONE = 3, 1381bd4fe43Sopenharmony_ci}; 1391bd4fe43Sopenharmony_ci 1401bd4fe43Sopenharmony_cienum HimciHostRegister { 1411bd4fe43Sopenharmony_ci MMC_CTRL = 0x0000, 1421bd4fe43Sopenharmony_ci MMC_PWREN = 0x0004, 1431bd4fe43Sopenharmony_ci MMC_CLKDIV = 0x0008, 1441bd4fe43Sopenharmony_ci MMC_CLKENA = 0x0010, 1451bd4fe43Sopenharmony_ci MMC_TMOUT = 0x0014, 1461bd4fe43Sopenharmony_ci MMC_CTYPE = 0x0018, 1471bd4fe43Sopenharmony_ci MMC_BLKSIZ = 0x001c, 1481bd4fe43Sopenharmony_ci MMC_BYTCNT = 0x0020, 1491bd4fe43Sopenharmony_ci MMC_INTMASK = 0x0024, 1501bd4fe43Sopenharmony_ci MMC_CMDARG = 0x0028, 1511bd4fe43Sopenharmony_ci MMC_CMD = 0x002C, 1521bd4fe43Sopenharmony_ci MMC_RESP0 = 0x0030, 1531bd4fe43Sopenharmony_ci MMC_RESP1 = 0x0034, 1541bd4fe43Sopenharmony_ci MMC_RESP2 = 0x0038, 1551bd4fe43Sopenharmony_ci MMC_RESP3 = 0x003C, 1561bd4fe43Sopenharmony_ci MMC_MINTSTS = 0x0040, 1571bd4fe43Sopenharmony_ci MMC_RINTSTS = 0x0044, 1581bd4fe43Sopenharmony_ci MMC_STATUS = 0x0048, 1591bd4fe43Sopenharmony_ci MMC_FIFOTH = 0x004C, 1601bd4fe43Sopenharmony_ci MMC_CDETECT = 0x0050, 1611bd4fe43Sopenharmony_ci MMC_WRTPRT = 0x0054, 1621bd4fe43Sopenharmony_ci MMC_GPIO = 0x0058, 1631bd4fe43Sopenharmony_ci MMC_TCBCNT = 0x005C, 1641bd4fe43Sopenharmony_ci MMC_TBBCNT = 0x0060, 1651bd4fe43Sopenharmony_ci MMC_DEBNCE = 0x0064, 1661bd4fe43Sopenharmony_ci MMC_UHS_REG = 0x0074, 1671bd4fe43Sopenharmony_ci MMC_CARD_RSTN = 0x0078, 1681bd4fe43Sopenharmony_ci MMC_BMOD = 0x0080, 1691bd4fe43Sopenharmony_ci MMC_DBADDR = 0x0088, 1701bd4fe43Sopenharmony_ci MMC_IDSTS = 0x008C, 1711bd4fe43Sopenharmony_ci MMC_IDINTEN = 0x0090, 1721bd4fe43Sopenharmony_ci MMC_DSCADDR = 0x0094, 1731bd4fe43Sopenharmony_ci MMC_BUFADDR = 0x0098, 1741bd4fe43Sopenharmony_ci MMC_CARDTHRCTL = 0x0100, 1751bd4fe43Sopenharmony_ci MMC_UHS_REG_EXT = 0x0108, 1761bd4fe43Sopenharmony_ci MMC_EMMC_DDR_REG = 0x010c, 1771bd4fe43Sopenharmony_ci MMC_ENABLE_SHIFT = 0x0110, 1781bd4fe43Sopenharmony_ci MMC_TUNING_CTRL = 0x0118, 1791bd4fe43Sopenharmony_ci MMC_DATA = 0x0200 1801bd4fe43Sopenharmony_ci}; 1811bd4fe43Sopenharmony_ci 1821bd4fe43Sopenharmony_ci/* 1831bd4fe43Sopenharmony_ci * MMC_CTRL(0x0000) details. 1841bd4fe43Sopenharmony_ci * [25]Whether to use the built-in DMA to transfer data. 1851bd4fe43Sopenharmony_ci * 0: The CPU uses the device interface to transfer data. 1: The internal DMA is used to transfer data. 1861bd4fe43Sopenharmony_ci * [4]Global interrupt enable. 0: disabled; 1: enabled. 1871bd4fe43Sopenharmony_ci * The interrupt output is valid only when this bit is valid and an interrupt source is enabled. 1881bd4fe43Sopenharmony_ci * [2]Soft reset control for the internal DMAC. 0: invalid; 1: Reset the internal DMA interface. 1891bd4fe43Sopenharmony_ci * This bit is automatically reset after two AHB clock cycles. 1901bd4fe43Sopenharmony_ci * [1]Soft reset control for the internal FIFO. 0: invalid; 1: Reset the FIFO pointer. 1911bd4fe43Sopenharmony_ci * This bit is automatically reset after the reset operation is complete. 1921bd4fe43Sopenharmony_ci * [0]Soft reset control for the controller. 0: invalid; 1: Reset the eMMC/SD/SDIO host module. 1931bd4fe43Sopenharmony_ci */ 1941bd4fe43Sopenharmony_ci#define CTRL_RESET (1U << 0) 1951bd4fe43Sopenharmony_ci#define FIFO_RESET (1U << 1) 1961bd4fe43Sopenharmony_ci#define DMA_RESET (1U << 2) 1971bd4fe43Sopenharmony_ci#define INTR_EN (1U << 4) 1981bd4fe43Sopenharmony_ci#define USE_INTERNAL_DMA (1U << 25) 1991bd4fe43Sopenharmony_ci 2001bd4fe43Sopenharmony_ci/* 2011bd4fe43Sopenharmony_ci * MMC_PWREN(0x0004) details. 2021bd4fe43Sopenharmony_ci * [0]POWER control. 0: power off; 1: The power supply is turned on. 2031bd4fe43Sopenharmony_ci */ 2041bd4fe43Sopenharmony_ci#define POWER_ENABLE (1U << 0) 2051bd4fe43Sopenharmony_ci 2061bd4fe43Sopenharmony_ci/* 2071bd4fe43Sopenharmony_ci * MMC_CLKDIV(0x0008) details. 2081bd4fe43Sopenharmony_ci * [7:0]Clock divider. The clock frequency division coefficient is 2 * n. 2091bd4fe43Sopenharmony_ci * For example, 0 indicates no frequency division, 1 indicates frequency division by 2, 2101bd4fe43Sopenharmony_ci * and ff indicates frequency division by 510. 2111bd4fe43Sopenharmony_ci */ 2121bd4fe43Sopenharmony_ci#define CLK_DIVIDER (0xff * 2) 2131bd4fe43Sopenharmony_ci#define MAX_CLKDIV_VAL 0xff 2141bd4fe43Sopenharmony_ci 2151bd4fe43Sopenharmony_ci/* 2161bd4fe43Sopenharmony_ci * MMC_CLKENA(0x0010) details. 2171bd4fe43Sopenharmony_ci * [16]Low-power control of the card, used to disable the card clock. 0: no low-power mode; 1: low-power mode. 2181bd4fe43Sopenharmony_ci * When the card is in the idle state, the card clock is stopped. This function applies only to the SD card and eMMC. 2191bd4fe43Sopenharmony_ci * For the SDIO, the clock cannot be stopped to detect interrupts. 2201bd4fe43Sopenharmony_ci * [0]Card clock enable. 0: disabled; 1: enabled. 2211bd4fe43Sopenharmony_ci */ 2221bd4fe43Sopenharmony_ci#define CCLK_LOW_POWER (1U << 16) 2231bd4fe43Sopenharmony_ci#define CCLK_ENABLE (1U << 0) 2241bd4fe43Sopenharmony_ci 2251bd4fe43Sopenharmony_ci/* 2261bd4fe43Sopenharmony_ci * MMC_TMOUT(0x14) details. 2271bd4fe43Sopenharmony_ci * [31:8]data read timeout param. 2281bd4fe43Sopenharmony_ci * [7:0]response timeout param. 2291bd4fe43Sopenharmony_ci */ 2301bd4fe43Sopenharmony_ci#define DATA_TIMEOUT (0xffffffU << 8) 2311bd4fe43Sopenharmony_ci#define RESPONSE_TIMEOUT 0xff 2321bd4fe43Sopenharmony_ci 2331bd4fe43Sopenharmony_ci/* 2341bd4fe43Sopenharmony_ci * MCI_CTYPE(0x0018) details. 2351bd4fe43Sopenharmony_ci * [16]Bus width of the card. 0: non-8-bit mode, depending on the configuration of bit[0]; 2361bd4fe43Sopenharmony_ci * 1: 8-bit mode, the value of bit[0] is ignored. 2371bd4fe43Sopenharmony_ci * [0]Bus width of the card. 0: 1-bit mode; 1: 4-bit mode. 2381bd4fe43Sopenharmony_ci */ 2391bd4fe43Sopenharmony_ci#define CARD_WIDTH_1 (1U << 0) 2401bd4fe43Sopenharmony_ci#define CARD_WIDTH_0 (1U << 16) 2411bd4fe43Sopenharmony_ci 2421bd4fe43Sopenharmony_ci/* MCI_INTMASK(0x24) details. 2431bd4fe43Sopenharmony_ci * [16:0]mask MMC host controller each interrupt. 0: disable; 1: enabled. 2441bd4fe43Sopenharmony_ci * [16]SDIO interrupt; [3]data transfer over(DTO). 2451bd4fe43Sopenharmony_ci */ 2461bd4fe43Sopenharmony_ci#define ALL_INT_MASK 0x1ffff 2471bd4fe43Sopenharmony_ci#define DTO_INT_MASK (1 << 3) 2481bd4fe43Sopenharmony_ci#define SDIO_INT_MASK (1 << 16) 2491bd4fe43Sopenharmony_ci 2501bd4fe43Sopenharmony_ci/* 2511bd4fe43Sopenharmony_ci * MCI_CMD(0x2c) details: 2521bd4fe43Sopenharmony_ci * [31]cmd execute or load start param of interface clk bit. 2531bd4fe43Sopenharmony_ci */ 2541bd4fe43Sopenharmony_ci#define START_CMD (1U << 31) 2551bd4fe43Sopenharmony_ci 2561bd4fe43Sopenharmony_ci/* 2571bd4fe43Sopenharmony_ci * MCI_INTSTS(0x44) details. 2581bd4fe43Sopenharmony_ci * [16]sdio interrupt status; [15]end-bit error (read)/write no CRC interrupt status; 2591bd4fe43Sopenharmony_ci * [14]auto command done interrupt status; [13]start bit error interrupt status; 2601bd4fe43Sopenharmony_ci * [12]hardware locked write error interrupt status; [11]FIFO underrun/overrun error interrupt status; 2611bd4fe43Sopenharmony_ci * [10]data starvation-by-host timeout/volt_switch to 1.8v for sdxc interrupt status; 2621bd4fe43Sopenharmony_ci * [9]data read timeout interrupt status; [8]response timeout interrupt status; [7]data CRC error interrupt status; 2631bd4fe43Sopenharmony_ci * [6]response CRC error interrupt status; [5]receive FIFO data request interrupt status; 2641bd4fe43Sopenharmony_ci * [4]transmit FIFO data request interrupt status; [3]data transfer Over interrupt status; 2651bd4fe43Sopenharmony_ci * [2]command done interrupt status; [1]response error interrupt status; [0]card detect interrupt status. 2661bd4fe43Sopenharmony_ci */ 2671bd4fe43Sopenharmony_ci#define SDIO_INT_STATUS (1U << 16) 2681bd4fe43Sopenharmony_ci#define EBE_INT_STATUS (1U << 15) 2691bd4fe43Sopenharmony_ci#define ACD_INT_STATUS (1U << 14) 2701bd4fe43Sopenharmony_ci#define SBE_INT_STATUS (1U << 13) 2711bd4fe43Sopenharmony_ci#define HLE_INT_STATUS (1U << 12) 2721bd4fe43Sopenharmony_ci#define FRUN_INT_STATUS (1U << 11) 2731bd4fe43Sopenharmony_ci#define HTO_INT_STATUS (1U << 10) 2741bd4fe43Sopenharmony_ci#define VOLT_SWITCH_INT_STATUS (1U << 10) 2751bd4fe43Sopenharmony_ci#define DRTO_INT_STATUS (1U << 9) 2761bd4fe43Sopenharmony_ci#define RTO_INT_STATUS (1U << 8) 2771bd4fe43Sopenharmony_ci#define DCRC_INT_STATUS (1U << 7) 2781bd4fe43Sopenharmony_ci#define RCRC_INT_STATUS (1U << 6) 2791bd4fe43Sopenharmony_ci#define RXDR_INT_STATUS (1U << 5) 2801bd4fe43Sopenharmony_ci#define TXDR_INT_STATUS (1U << 4) 2811bd4fe43Sopenharmony_ci#define DTO_INT_STATUS (1U << 3) 2821bd4fe43Sopenharmony_ci#define CD_INT_STATUS (1U << 2) 2831bd4fe43Sopenharmony_ci#define RE_INT_STATUS (1U << 1) 2841bd4fe43Sopenharmony_ci#define CARD_DETECT_INT_STATUS (1U << 0) 2851bd4fe43Sopenharmony_ci#define DATA_INT_MASK (DTO_INT_STATUS | DCRC_INT_STATUS | SBE_INT_STATUS | EBE_INT_STATUS) 2861bd4fe43Sopenharmony_ci#define CMD_INT_MASK (RTO_INT_STATUS | RCRC_INT_STATUS | RE_INT_STATUS | CD_INT_STATUS | VOLT_SWITCH_INT_STATUS) 2871bd4fe43Sopenharmony_ci#define ALL_INT_CLR 0x1efff 2881bd4fe43Sopenharmony_ci 2891bd4fe43Sopenharmony_ci/* 2901bd4fe43Sopenharmony_ci * MMC_STATUS(0x48) details. 2911bd4fe43Sopenharmony_ci * [9]Status of data_busy indicated by DAT[0]. 0: idle; 1: The card is busy. 2921bd4fe43Sopenharmony_ci */ 2931bd4fe43Sopenharmony_ci#define DATA_BUSY (1U << 9) 2941bd4fe43Sopenharmony_ci 2951bd4fe43Sopenharmony_ci/* MMC_FIFOTH(0x4c) details. 2961bd4fe43Sopenharmony_ci * [30:28]Indicates the transmission burst length. 2971bd4fe43Sopenharmony_ci * 000: 1; 001: 4; 010: 8; 011: 16; 100: 32; 101: 64; 110: 128; 111:256. 2981bd4fe43Sopenharmony_ci * [27:16]FIFO threshold watermarklevel when data is read. 2991bd4fe43Sopenharmony_ci * When the FIFO count is greater than the value of this parameter, the DMA request is enabled. 3001bd4fe43Sopenharmony_ci * To complete the remaining data after data transfer, a DMA request is generated. 3011bd4fe43Sopenharmony_ci * [11:0]FIFO threshold watermark level when data is transmitted. 3021bd4fe43Sopenharmony_ci * When the FIFO count is less than the value of this parameter, the DMA request is enabled. 3031bd4fe43Sopenharmony_ci * To complete the remaining data after data transfer, a DMA request is generated. 3041bd4fe43Sopenharmony_ci */ 3051bd4fe43Sopenharmony_ci#define BURST_SIZE (0x6 << 28) 3061bd4fe43Sopenharmony_ci#define RX_WMARK (0x7f << 16) 3071bd4fe43Sopenharmony_ci#define TX_WMARK 0x80 3081bd4fe43Sopenharmony_ci 3091bd4fe43Sopenharmony_ci/* 3101bd4fe43Sopenharmony_ci * MMC_CDETECT(0x0050) details. 3111bd4fe43Sopenharmony_ci * [0]Card detection signal. 0: The card is detected; 1: The card is not detected. 3121bd4fe43Sopenharmony_ci */ 3131bd4fe43Sopenharmony_ci#define CARD_UNPLUGED (1U << 0) 3141bd4fe43Sopenharmony_ci 3151bd4fe43Sopenharmony_ci/* 3161bd4fe43Sopenharmony_ci * MMC_WRTPRT(0x0054) details. 3171bd4fe43Sopenharmony_ci * [0] 0: card read/write; 1: card readonly. 3181bd4fe43Sopenharmony_ci */ 3191bd4fe43Sopenharmony_ci#define CARD_READONLY (1U << 0) 3201bd4fe43Sopenharmony_ci 3211bd4fe43Sopenharmony_ci/* 3221bd4fe43Sopenharmony_ci * MMC_GPIO(0x0058) details. 3231bd4fe43Sopenharmony_ci * [23] 0: dto fix bypass; 1: dto fix enable. 3241bd4fe43Sopenharmony_ci */ 3251bd4fe43Sopenharmony_ci#define DTO_FIX_ENABLE (1U << 23) 3261bd4fe43Sopenharmony_ci 3271bd4fe43Sopenharmony_ci/* 3281bd4fe43Sopenharmony_ci * MMC_DEBNCE(0x0064) details. 3291bd4fe43Sopenharmony_ci * [23:0]Number of bus clock cycles used by the dejitter filter logic. The dejitter time is 5ms to 25ms. 3301bd4fe43Sopenharmony_ci */ 3311bd4fe43Sopenharmony_ci#define DEBNCE_MS 25 3321bd4fe43Sopenharmony_ci#define DEBOUNCE_E (DEBNCE_MS * 150000) 3331bd4fe43Sopenharmony_ci#define DEBOUNCE_H (DEBNCE_MS * 100000) 3341bd4fe43Sopenharmony_ci#define DEBOUNCE_M (DEBNCE_MS * 50000) 3351bd4fe43Sopenharmony_ci#define DEBOUNCE_L (DEBNCE_MS * 25000) 3361bd4fe43Sopenharmony_ci 3371bd4fe43Sopenharmony_ci/* 3381bd4fe43Sopenharmony_ci * MMC_UHS_REG(0x0074) details. 3391bd4fe43Sopenharmony_ci * [16] DDR Mode control register, 0: non-DDR mode, 1: DDR mode. 3401bd4fe43Sopenharmony_ci * [0] Voltage mode control register, 0: 3.3V, 1: 1.8V. 3411bd4fe43Sopenharmony_ci */ 3421bd4fe43Sopenharmony_ci#define HI_SDXC_CTRL_DDR_REG (1U << 16) 3431bd4fe43Sopenharmony_ci#define HI_SDXC_CTRL_VDD_180 (1U << 0) 3441bd4fe43Sopenharmony_ci 3451bd4fe43Sopenharmony_ci/* 3461bd4fe43Sopenharmony_ci * MMC_CARD_RSTN(0x0078) details. 3471bd4fe43Sopenharmony_ci * [16] eMMC reset controller. 0: reset; 1: reset deasserted. 3481bd4fe43Sopenharmony_ci */ 3491bd4fe43Sopenharmony_ci#define CARD_RESET (1U << 0) 3501bd4fe43Sopenharmony_ci 3511bd4fe43Sopenharmony_ci/* MMC_BMOD(0x80) details. 3521bd4fe43Sopenharmony_ci * [10:8]Indicates the length of the IDMAC burst transmission. 3531bd4fe43Sopenharmony_ci * 000: 1; 001: 4; 010: 8; 011: 16; 100: 32; 101: 64; 110: 128; 111:256. 3541bd4fe43Sopenharmony_ci * [7]IDMAC enable. 0: disabled; 1: enabled. 3551bd4fe43Sopenharmony_ci * [1]Fixed burst length. 3561bd4fe43Sopenharmony_ci * 0: SINGLE and INCR burst types are used; 1: SINGLE, INCR4, INCR8, and INCR16 burst types are used. 3571bd4fe43Sopenharmony_ci * [0]Soft reset control for IDMAC internal registers. 0: not reset; 1: reset. 3581bd4fe43Sopenharmony_ci * This bit is automatically cleared one clock cycle after this bit is set. 3591bd4fe43Sopenharmony_ci * 3601bd4fe43Sopenharmony_ci */ 3611bd4fe43Sopenharmony_ci#define BMOD_SWR (1U << 0) 3621bd4fe43Sopenharmony_ci#define BURST_INCR (1U << 1) 3631bd4fe43Sopenharmony_ci#define BMOD_DMA_EN (1U << 7) 3641bd4fe43Sopenharmony_ci#define BURST_8 (1U << 8) 3651bd4fe43Sopenharmony_ci#define BURST_16 (3U << 8) 3661bd4fe43Sopenharmony_ci 3671bd4fe43Sopenharmony_ci/* MMC_CARDTHRCTL(0x0100) details. 3681bd4fe43Sopenharmony_ci * [27:16]Read threshold. The maximum value is 512. 3691bd4fe43Sopenharmony_ci * [1]Busy clear interrupt enable. 0: disabled; 1: enabled. 3701bd4fe43Sopenharmony_ci * [0]Read threshold enable. 0: disabled; 1: enabled. 3711bd4fe43Sopenharmony_ci */ 3721bd4fe43Sopenharmony_ci#define READ_THRESHOLD_SIZE 0x2000005 3731bd4fe43Sopenharmony_ci#define BUSY_CLEAR_INT_ENABLE (1U << 1) 3741bd4fe43Sopenharmony_ci 3751bd4fe43Sopenharmony_ci/* MMC_UHS_REG_EXT(0x0108) details. 3761bd4fe43Sopenharmony_ci * [25:23]Clock phase of clk_in_drv, in degrees. 3771bd4fe43Sopenharmony_ci * [18:16]Clock phase of clk_in_sample, in degrees. 3781bd4fe43Sopenharmony_ci * 000: 0; 001: 45; 010: 90; 011: 135; 100: 180; 101: 225; 110: 270; 111: 315. 3791bd4fe43Sopenharmony_ci */ 3801bd4fe43Sopenharmony_ci#define CLK_SMPL_PHS_OFFSET 16 3811bd4fe43Sopenharmony_ci#define CLK_SMPL_PHS_MASK (0x7 << CLK_SMPL_PHS_OFFSET) 3821bd4fe43Sopenharmony_ci#define CLK_DRV_PHS_OFFSET 23 3831bd4fe43Sopenharmony_ci#define CLK_DRV_PHS_MASK (0x7 << CLK_DRV_PHS_OFFSET) 3841bd4fe43Sopenharmony_ci#define DRV_PHASE_180 (0x4 << 23) 3851bd4fe43Sopenharmony_ci#define DRV_PHASE_135 (0x3 << 23) 3861bd4fe43Sopenharmony_ci#define DRV_PHASE_90 (0x2 << 23) 3871bd4fe43Sopenharmony_ci#define SMP_PHASE_45 (0x1 << 16) 3881bd4fe43Sopenharmony_ci#define SMP_PHASE_0 (0x0 << 16) 3891bd4fe43Sopenharmony_ci#define DRV_PHASE_SHIFT 0x4 3901bd4fe43Sopenharmony_ci#define SMPL_PHASE_SHIFT 0x1 3911bd4fe43Sopenharmony_ci 3921bd4fe43Sopenharmony_ci#define TUNING_START_PHASE 0 3931bd4fe43Sopenharmony_ci#define TUNING_END_PHASE 7 3941bd4fe43Sopenharmony_ci#define HIMCI_PHASE_SCALE 8 3951bd4fe43Sopenharmony_ci#define DRV_PHASE_DFLT DRV_PHASE_180 3961bd4fe43Sopenharmony_ci#define SMPL_PHASE_DFLT SMP_PHASE_0 3971bd4fe43Sopenharmony_ci 3981bd4fe43Sopenharmony_ci/* 3991bd4fe43Sopenharmony_ci * MMC_TUNING_CTRL(0x118) details. 4001bd4fe43Sopenharmony_ci */ 4011bd4fe43Sopenharmony_ci#define HW_TUNING_EN (1U << 0) 4021bd4fe43Sopenharmony_ci#define EDGE_CTRL (1U << 1) 4031bd4fe43Sopenharmony_ci#define FOUND_EDGE (1U << 5) 4041bd4fe43Sopenharmony_ci 4051bd4fe43Sopenharmony_ci/* IDMAC DEST0 details */ 4061bd4fe43Sopenharmony_ci#define DMA_DES_OWN (1U << 31) 4071bd4fe43Sopenharmony_ci#define DMA_DES_NEXT_DES (1U << 4) 4081bd4fe43Sopenharmony_ci#define DMA_DES_FIRST_DES (1U << 3) 4091bd4fe43Sopenharmony_ci#define DMA_DES_LAST_DES (1U << 2) 4101bd4fe43Sopenharmony_ci 4111bd4fe43Sopenharmony_ci/* MMC_CMD(0x002C) register bits define. */ 4121bd4fe43Sopenharmony_ciunion HimciCmdRegArg { 4131bd4fe43Sopenharmony_ci uint32_t arg; 4141bd4fe43Sopenharmony_ci struct CmdBits { 4151bd4fe43Sopenharmony_ci uint32_t cmdIndex : 6; /* [5:0]Command sequence number. */ 4161bd4fe43Sopenharmony_ci uint32_t rspExpect : 1; /* 4171bd4fe43Sopenharmony_ci * Indicates whether a response exists. 4181bd4fe43Sopenharmony_ci * 0: No response is output from the card. 4191bd4fe43Sopenharmony_ci * 1: A response is output from the card. 4201bd4fe43Sopenharmony_ci */ 4211bd4fe43Sopenharmony_ci uint32_t rspLen : 1; /* 4221bd4fe43Sopenharmony_ci * Response length. 0: The short response is output from the card. 4231bd4fe43Sopenharmony_ci * 1: The long response is output from the card. 4241bd4fe43Sopenharmony_ci * The long response is 128 bits, and the short response is 32 bits. 4251bd4fe43Sopenharmony_ci */ 4261bd4fe43Sopenharmony_ci uint32_t checkRspCrc : 1; /* 4271bd4fe43Sopenharmony_ci * Indicates whether the CRC check is performed. 4281bd4fe43Sopenharmony_ci * 0: The CRC response is not checked. 1: Check the CRC response. 4291bd4fe43Sopenharmony_ci */ 4301bd4fe43Sopenharmony_ci uint32_t dataTransferExpected : 1; /* 4311bd4fe43Sopenharmony_ci * Data transfer indicator. 4321bd4fe43Sopenharmony_ci * 0: No data is output from the card. 1: Data is output from the card. 4331bd4fe43Sopenharmony_ci */ 4341bd4fe43Sopenharmony_ci uint32_t readWrite : 1; /* 4351bd4fe43Sopenharmony_ci * Read/write control. 0: Read data from the card. 1: Write data to the card. 4361bd4fe43Sopenharmony_ci * This bit is ignored in non-data transmission. 4371bd4fe43Sopenharmony_ci */ 4381bd4fe43Sopenharmony_ci uint32_t transferMode : 1; /* 4391bd4fe43Sopenharmony_ci * 0: block transfer command; 1: stream transmission command. 4401bd4fe43Sopenharmony_ci * This bit is ignored in non-data transmission. 4411bd4fe43Sopenharmony_ci */ 4421bd4fe43Sopenharmony_ci uint32_t sendAutoStop : 1; /* 4431bd4fe43Sopenharmony_ci * Indicates whether to send the stop command. 4441bd4fe43Sopenharmony_ci * 0: The stop command is not sent after the data transfer is complete. 4451bd4fe43Sopenharmony_ci * 1: The stop command is sent after data transfer is complete. 4461bd4fe43Sopenharmony_ci * This bit is ignored in non-data transmission. 4471bd4fe43Sopenharmony_ci */ 4481bd4fe43Sopenharmony_ci uint32_t waitDataComplete : 1; /* 4491bd4fe43Sopenharmony_ci * Indicates whether to send an instruction immediately. 4501bd4fe43Sopenharmony_ci * 0: Send the command immediately; 4511bd4fe43Sopenharmony_ci * 1: Send the command after the previous data transfer is complete. 4521bd4fe43Sopenharmony_ci * 0 is a typical value, which is used to read the status or interrupt the 4531bd4fe43Sopenharmony_ci * transfer during data transfer. 4541bd4fe43Sopenharmony_ci */ 4551bd4fe43Sopenharmony_ci uint32_t stopAbortCmd : 1; /* 4561bd4fe43Sopenharmony_ci * When the data transfer operation is in progress, the values are as follows: 4571bd4fe43Sopenharmony_ci * 0: The stop/abort command is not sent. 4581bd4fe43Sopenharmony_ci * 1: The stop/abort command is sent to stop the ongoing data transfer. 4591bd4fe43Sopenharmony_ci */ 4601bd4fe43Sopenharmony_ci uint32_t sendInitialization : 1; /* 4611bd4fe43Sopenharmony_ci * Indicates whether to send the initial sequence. 4621bd4fe43Sopenharmony_ci * 0: The initial sequence is not sent before the Send_initialization is sent. 4631bd4fe43Sopenharmony_ci * 1: The initial sequence is sent before the Send_initialization is sent. 4641bd4fe43Sopenharmony_ci * When the card is powered on, the initial sequence must be sent for 4651bd4fe43Sopenharmony_ci * initialization before any command is sent. That is, this bit is set to 1. 4661bd4fe43Sopenharmony_ci */ 4671bd4fe43Sopenharmony_ci uint32_t cardNumber : 5; /* Sequence number of the card in use. */ 4681bd4fe43Sopenharmony_ci uint32_t updateClkRegOnly : 1; /* 4691bd4fe43Sopenharmony_ci * Indicates whether to automatically update. 4701bd4fe43Sopenharmony_ci * 0: normal command sequence; 1: No command is sent. Only the clock register 4711bd4fe43Sopenharmony_ci * value of the card clock domain is updated. 4721bd4fe43Sopenharmony_ci * Set this bit to 1 each time the card clock is changed. In this case, 4731bd4fe43Sopenharmony_ci * no command is transmitted to the card, 4741bd4fe43Sopenharmony_ci * and no command-done interrupt is generated. 4751bd4fe43Sopenharmony_ci */ 4761bd4fe43Sopenharmony_ci uint32_t reserved1 : 2; 4771bd4fe43Sopenharmony_ci uint32_t enableBoot : 1; /* 4781bd4fe43Sopenharmony_ci * Enable the boot function. This bit can be used only in forcible boot mode. 4791bd4fe43Sopenharmony_ci * When software enables this bit and Start_cmd at the same time, 4801bd4fe43Sopenharmony_ci * the controller pulls down the CMD signal to start the boot process. 4811bd4fe43Sopenharmony_ci * Enable_boot and Disable_boot cannot be enabled at the same time. 4821bd4fe43Sopenharmony_ci */ 4831bd4fe43Sopenharmony_ci uint32_t expectBootAck : 1; /* 4841bd4fe43Sopenharmony_ci * Enables the boot response. When the software enables this bit and Enable_boot at 4851bd4fe43Sopenharmony_ci * the same time, the controller detects the boot response signal, 4861bd4fe43Sopenharmony_ci * that is, the 0-1-0 sequence. 4871bd4fe43Sopenharmony_ci */ 4881bd4fe43Sopenharmony_ci uint32_t disableBoot : 1; /* 4891bd4fe43Sopenharmony_ci * Disable the boot. When the software enables this bit and Start_cmd at the same 4901bd4fe43Sopenharmony_ci * time, the controller stops the boot operation. 4911bd4fe43Sopenharmony_ci * Enable_boot and Disable_boot cannot be enabled at the same time. 4921bd4fe43Sopenharmony_ci */ 4931bd4fe43Sopenharmony_ci uint32_t bootMode : 1; /* Boot mode. 0: forcible boot mode; 1: alternate boot mode. */ 4941bd4fe43Sopenharmony_ci uint32_t voltSwitch : 1; /* Voltage switching control. 0: The voltage switching is disabled. 1: enabled. */ 4951bd4fe43Sopenharmony_ci uint32_t useHoldReg : 1; /* 4961bd4fe43Sopenharmony_ci * 0: The CMD and DATA signals sent to the card do not pass through the HOLD register. 4971bd4fe43Sopenharmony_ci * 1: The CMD and DATA signals sent to the card pass through the HOLD register. 4981bd4fe43Sopenharmony_ci */ 4991bd4fe43Sopenharmony_ci uint32_t reserved2 : 1; 5001bd4fe43Sopenharmony_ci uint32_t startCmd : 1; /* 5011bd4fe43Sopenharmony_ci * Start control. 0: not enabled; 1: start command. 5021bd4fe43Sopenharmony_ci * This bit is cleared when the command has been sent to the CIU. 5031bd4fe43Sopenharmony_ci * The CPU cannot modify this register. 5041bd4fe43Sopenharmony_ci * If the value is changed, a hardware lock error interrupt is generated. 5051bd4fe43Sopenharmony_ci * After sending a command, the CPU needs to query this bit. 5061bd4fe43Sopenharmony_ci * After the bit becomes 0, the CPU sends the next command. 5071bd4fe43Sopenharmony_ci */ 5081bd4fe43Sopenharmony_ci } bits; 5091bd4fe43Sopenharmony_ci}; 5101bd4fe43Sopenharmony_ci 5111bd4fe43Sopenharmony_cistruct HimciDes { 5121bd4fe43Sopenharmony_ci unsigned long dmaDesCtrl; 5131bd4fe43Sopenharmony_ci unsigned long dmaDesBufSize; 5141bd4fe43Sopenharmony_ci unsigned long dmaDesBufAddr; 5151bd4fe43Sopenharmony_ci unsigned long dmaDesNextAddr; 5161bd4fe43Sopenharmony_ci}; 5171bd4fe43Sopenharmony_ci 5181bd4fe43Sopenharmony_ci#define HIMCI_PEND_DTO_M (1U << 0) 5191bd4fe43Sopenharmony_ci#define HIMCI_PEND_ACCIDENT (1U << 1) 5201bd4fe43Sopenharmony_ci#define HIMCI_HOST_INIT_DONE (1U << 2) 5211bd4fe43Sopenharmony_cistruct HimciHost { 5221bd4fe43Sopenharmony_ci struct MmcCntlr *mmc; 5231bd4fe43Sopenharmony_ci struct MmcCmd *cmd; 5241bd4fe43Sopenharmony_ci void *base; 5251bd4fe43Sopenharmony_ci enum HimciPowerStatus powerStatus; 5261bd4fe43Sopenharmony_ci uint8_t *alignedBuff; 5271bd4fe43Sopenharmony_ci uint32_t buffLen; 5281bd4fe43Sopenharmony_ci struct scatterlist dmaSg; 5291bd4fe43Sopenharmony_ci struct scatterlist *sg; 5301bd4fe43Sopenharmony_ci uint32_t dmaSgNum; 5311bd4fe43Sopenharmony_ci DMA_ADDR_T dmaPaddr; 5321bd4fe43Sopenharmony_ci uint32_t *dmaVaddr; 5331bd4fe43Sopenharmony_ci uint32_t irqNum; 5341bd4fe43Sopenharmony_ci bool isTuning; 5351bd4fe43Sopenharmony_ci uint32_t id; 5361bd4fe43Sopenharmony_ci struct OsalMutex mutex; 5371bd4fe43Sopenharmony_ci bool waitForEvent; 5381bd4fe43Sopenharmony_ci HIMCI_EVENT himciEvent; 5391bd4fe43Sopenharmony_ci}; 5401bd4fe43Sopenharmony_ci 5411bd4fe43Sopenharmony_cistruct HimciTuneParam { 5421bd4fe43Sopenharmony_ci uint32_t cmdCode; 5431bd4fe43Sopenharmony_ci uint32_t edgeP2f; 5441bd4fe43Sopenharmony_ci uint32_t edgeF2p; 5451bd4fe43Sopenharmony_ci uint32_t startp; 5461bd4fe43Sopenharmony_ci uint32_t endp; 5471bd4fe43Sopenharmony_ci uint32_t endpInit; 5481bd4fe43Sopenharmony_ci}; 5491bd4fe43Sopenharmony_ci 5501bd4fe43Sopenharmony_ci#ifdef __cplusplus 5511bd4fe43Sopenharmony_ci#if __cplusplus 5521bd4fe43Sopenharmony_ci} 5531bd4fe43Sopenharmony_ci#endif /* __cplusplus */ 5541bd4fe43Sopenharmony_ci#endif /* __cplusplus */ 5551bd4fe43Sopenharmony_ci 5561bd4fe43Sopenharmony_ci#endif /* HIMCI_H */ 557