1 /* 2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * 4 * This program is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU General Public License as published by the 6 * Free Software Foundation; either version 2 of the License, or (at your 7 * option) any later version. 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 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * 17 */ 18 19 #ifndef _HIMCI_V200_H_ 20 #define _HIMCI_V200_H_ 21 22 #define POWER_ON 0x1 23 #define POWER_OFF 0x0 24 25 #define CARD_UNPLUGED 0x1 26 #define CARD_PLUGED 0x0 27 28 #define ENABLE 0x1 29 #define DISABLE 0x0 30 31 #define HI_MCI_DETECT_TIMEOUT (HZ/2) 32 33 #define HI_MCI_REQUEST_TIMEOUT (5 * HZ) 34 35 #define MAX_RETRY_COUNT 100000 36 37 #if defined(CONFIG_TARGET_HI3559V200) || defined(CONFIG_TARGET_HI3556V200) ||\ 38 defined(CONFIG_TARGET_HI3562V100) || defined(CONFIG_TARGET_HI3566V100) 39 #define MMC_CLK 150000000 40 #else 41 #define MMC_CLK 100000000 42 #endif 43 #define MMC_CCLK_MIN 400000 44 45 #define HI_MCI_DEBUG DISABLE 46 //#define HI_MCI_DEBUG ENABLE 47 48 #if HI_MCI_DEBUG 49 extern int debug_type; 50 #define HIMCI_DEBUG_TYPE (HIMCI_DEBUG_TYPE_REG | \ 51 HIMCI_DEBUG_TYPE_FUN | \ 52 HIMCI_DEBUG_TYPE_CMD | \ 53 HIMCI_DEBUG_TYPE_INFO | \ 54 HIMCI_DEBUG_TYPE_ERR) 55 56 #define HIMCI_DEBUG_TYPE_REG (0x01 << 0) 57 #define HIMCI_DEBUG_TYPE_FUN (0x01 << 1) 58 #define HIMCI_DEBUG_TYPE_CMD (0x01 << 2) 59 #define HIMCI_DEBUG_TYPE_INFO (0x01 << 3) 60 #define HIMCI_DEBUG_TYPE_ERR (0x01 << 4) 61 62 #define HIMCI_DEBUG_FMT "HIMCI_DEBUG " 63 64 extern char *get_debug_type_string(int type); 65 #define HIMCI_DEBUG(type, msg...) do { \ 66 if (debug_type & type) { \ 67 printf(HIMCI_DEBUG_FMT "(%s) %s:%d: ", \ 68 get_debug_type_string(type), \ 69 __func__, __LINE__); \ 70 printf(msg); \ 71 printf("\n"); \ 72 } \ 73 } while (0) 74 75 #define HIMCI_DEBUG_REG(msg...) HIMCI_DEBUG(HIMCI_DEBUG_TYPE_REG, msg) 76 #define HIMCI_DEBUG_FUN(msg...) HIMCI_DEBUG(HIMCI_DEBUG_TYPE_FUN, msg) 77 #define HIMCI_DEBUG_CMD(msg...) HIMCI_DEBUG(HIMCI_DEBUG_TYPE_CMD, msg) 78 #define HIMCI_DEBUG_INFO(msg...) HIMCI_DEBUG(HIMCI_DEBUG_TYPE_INFO, msg) 79 #define HIMCI_DEBUG_ERR(msg...) HIMCI_DEBUG(HIMCI_DEBUG_TYPE_ERR, msg) 80 81 #define HIMCI_ASSERT_FMT "HIMCI_ASSERT " 82 83 #define HIMCI_ASSERT(cond) do { \ 84 if (!(cond)) {\ 85 printf(HIMCI_ASSERT_FMT "%s:%d\n", __func__, __LINE__); \ 86 BUG(); \ 87 } \ 88 } while (0) 89 #else 90 #define HIMCI_DEBUG(type, msg...) 91 #define HIMCI_DEBUG_REG(msg...) 92 #define HIMCI_DEBUG_FUN(msg...) 93 #define HIMCI_DEBUG_CMD(msg...) 94 #define HIMCI_DEBUG_INFO(msg...) 95 #define HIMCI_DEBUG_ERR(msg...) 96 #define HIMCI_ASSERT(cond) 97 #endif 98 99 #define HIMCI_ERROR_FMT "HIMCI_ERROR " 100 101 #define HIMCI_ERROR(s...) do { \ 102 printf(HIMCI_ERROR_FMT "%s:%d: ", __func__, __LINE__); \ 103 printf(s); \ 104 printf("\n"); \ 105 } while (0) 106 107 #define himci_readl(addr)({unsigned int reg = readl((uintptr_t)addr); \ 108 HIMCI_DEBUG_REG("readl(0x%04X) = 0x%08X", (uintptr_t)addr, reg); \ 109 reg; }) 110 111 #define himci_writel(v, addr) do { writel(v, (uintptr_t)addr); \ 112 HIMCI_DEBUG_REG("writel(0x%04X) = 0x%08X", (uintptr_t)addr,\ 113 (unsigned int)(v)); \ 114 } while (0) 115 116 117 struct himci_dma_des { 118 unsigned long idmac_des_ctrl; 119 unsigned long idmac_des_buf_size; 120 unsigned long idmac_des_buf_addr; 121 unsigned long idmac_des_next_addr; 122 }; 123 124 struct himci_host { 125 const char *name; 126 struct mmc *mmc; 127 unsigned long base; 128 unsigned int card_status; 129 unsigned int dev_id; 130 unsigned int port; 131 struct mmc_cmd *cmd; 132 struct himci_dma_des *dma_des; 133 struct mmc_config cfg; 134 unsigned int is_tuning; 135 }; 136 137 typedef union { 138 unsigned int cmd_arg; 139 struct cmd_bits_arg { 140 unsigned int cmd_index:6; 141 unsigned int response_expect:1; 142 unsigned int response_length:1; 143 unsigned int check_response_crc:1; 144 unsigned int data_transfer_expected:1; 145 unsigned int read_write:1; 146 unsigned int transfer_mode:1; 147 unsigned int send_auto_stop:1; 148 unsigned int wait_prvdata_complete:1; 149 unsigned int stop_abort_cmd:1; 150 unsigned int send_initialization:1; 151 unsigned int card_number:5; 152 unsigned int update_clk_reg_only:1; /* bit 21 */ 153 unsigned int reserved:9; 154 unsigned int start_cmd:1; /* HSB */ 155 } bits; 156 } cmd_arg_s; 157 158 #endif 159 160 161