• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef HIMCI_H
17 #define HIMCI_H
18 
19 #include "asm/dma.h"
20 #include "asm/io.h"
21 #include "asm/platform.h"
22 #include "device_resource_if.h"
23 #include "linux/scatterlist.h"
24 #include "los_bitmap.h"
25 #include "los_event.h"
26 #include "los_vm_iomap.h"
27 #include "los_vm_zone.h"
28 #include "mmc_corex.h"
29 #include "osal_io.h"
30 #include "osal_irq.h"
31 #include "osal_time.h"
32 
33 #ifdef __cplusplus
34 #if __cplusplus
35 extern "C" {
36 #endif /* __cplusplus */
37 #endif /* __cplusplus */
38 
39 #define HIMCI_MAX_RETRY_COUNT 100
40 #define HIMCI_PAGE_SIZE 4096
41 #define HIMCI_DMA_MAX_BUFF_SIZE 0x1000
42 
43 #define HIMCI_MMC_FREQ_150M 150000000
44 #define HIMCI_MMC_FREQ_100M 100000000
45 #define HIMCI_MMC_FREQ_50M  50000000
46 #define HIMCI_MMC_FREQ_25M  25000000
47 
48 /* register mapping */
49 #define PERI_CRG49  (CRG_REG_BASE + 0xC4)
50 #define PERI_CRG50  (CRG_REG_BASE + 0xC8)
51 #define PERI_CRG82  (CRG_REG_BASE + 0x0148)
52 #define PERI_CRG83  (CRG_REG_BASE + 0x014C)
53 #define PERI_CRG84  (CRG_REG_BASE + 0x0150)
54 #define PERI_CRG85  (CRG_REG_BASE + 0x0154)
55 #define PERI_CRG86  (CRG_REG_BASE + 0x0158)
56 #define PERI_CRG87  (CRG_REG_BASE + 0x015C)
57 #define PERI_CRG88  (CRG_REG_BASE + 0x0160)
58 #define PERI_CRG89  (CRG_REG_BASE + 0x0164)
59 #define PERI_CRG90  (CRG_REG_BASE + 0x0168)
60 
61 /*
62  * PERI_CRG82/PERI_CRG88/PERI_CRG85 details.
63  * [3:2]Working clock selection. 01: 100MHz; 10: 50MHz; 11: 25MHz.
64  * [1]Clock gating. 0: disabled; 1: enabled.
65  * [0]Soft reset request. 0: reset deasserted; 1: reset.
66  */
67 #define HIMCI_CLK_SEL_MASK (3U << 2)
68 #define HIMCI_CLK_SEL_100M (1U << 2)
69 #define HIMCI_CLK_SEL_50M (2U << 2)
70 #define HIMCI_CLK_SEL_25M (3U << 2)
71 #define HIMCI_CKEN (1U << 1)
72 #define HIMCI_RESET (1U << 0)
73 
74 /*
75  * PERI_CRG83/PERI_CRG89/PERI_CRG86 details.
76  * [19]SAP_DLL device delay line enable. 0: The device stops working. 1: The device starts to work.
77  * [18]SAP_DLL host calculation clock cycle disable signal. 0: enabled; 1: Disable clock detection.
78  * [17]SAP_DLL device LINE bypass. 0: normal mode; 1: device line bypass.
79  * [16]SAP_DLL mode select. 0: normal mode; 1: The device line is controlled by the SAP_DLL_dllssel.
80  * [15:8]SAP_DLL device LINE delay level select, valid when SAP_DLL_dllmode is high.
81  * [7:4]SAP_DLL device tap calibration.
82  * [1]SAP_DLL soft reset. 0: reset deasserted; 1: reset. [0]SAP_DLL clock gating. 0: disabled; 1: enabled.
83  */
84 #define HIMCI_SAP_DLL_DEVICE_DELAY_ENABLE (1U << 19)
85 #define HIMCI_SAP_DLL_MODE_DLLSSEL        (1U << 16)
86 #define HIMCI_SAP_DLL_SOFT_RESET          (1U << 0)
87 #define HIMCI_SAP_DLL_ELEMENT_SHIFT       8
88 
89 /* HI MCI CONFIGS */
90 #define HIMCI_REQUEST_TIMEOUT    (10 * LOSCFG_BASE_CORE_TICK_PER_SECOND) /* 10s */
91 #define HIMCI_TUNINT_REQ_TIMEOUT (LOSCFG_BASE_CORE_TICK_PER_SECOND / 5)  /* 0.2s */
92 #define HIMCI_CARD_COMPLETE_TIMEOUT (5 * LOSCFG_BASE_CORE_TICK_PER_SECOND) /* 5s */
93 
94 #define HIMCI_READL(addr) OSAL_READL((uintptr_t)(addr))
95 
96 #define HIMCI_WRITEL(v, addr) OSAL_WRITEL((v), (uintptr_t)(addr))
97 
98 #define HIMCI_CLEARL(host, reg, v) OSAL_WRITEL(OSAL_READL((uintptr_t)(host)->base + (reg)) & (~(v)), \
99     (uintptr_t)(host)->base + (reg));
100 
101 #define HIMCI_SETL(host, reg, v) OSAL_WRITEL(OSAL_READL((uintptr_t)(host)->base + (reg)) | (v), \
102     (uintptr_t)(host)->base + (reg));
103 
104 /* define event lock */
105 typedef EVENT_CB_S HIMCI_EVENT;
106 #define HIMCI_EVENT_INIT(event) LOS_EventInit(event)
107 #define HIMCI_EVENT_SIGNAL(event, bit) LOS_EventWrite(event, bit)
108 #define HIMCI_EVENT_WAIT(event, bit, timeout) LOS_EventRead(event, bit, (LOS_WAITMODE_OR + LOS_WAITMODE_CLR), timeout)
109 #define HIMCI_EVENT_DELETE(event) LOS_EventDestroy(event)
110 
111 /* define task/irq lock */
112 #define HIMCI_TASK_LOCK(lock)    do { LOS_TaskLock(); } while (0)
113 #define HIMCI_TASK_UNLOCK(lock)  do { LOS_TaskUnlock(); } while (0)
114 #define HIMCI_IRQ_LOCK(flags)    do { (*(flags)) = LOS_IntLock(); } while (0)
115 #define HIMCI_IRQ_UNLOCK(flags)  do { LOS_IntRestore(flags); } while (0)
116 
117 #define HIMCI_SG_DMA_ADDRESS(sg) ((sg)->dma_address)
118 #ifdef CONFIG_NEED_SG_DMA_LENGTH
119 #define HIMCI_SG_DMA_LEN(sg)     ((sg)->dma_length)
120 #else
121 #define HIMCI_SG_DMA_LEN(sg)     ((sg)->length)
122 #endif
123 
124 #define REG_CTRL_NUM 4
125 #define REG_CTRL_EMMC_START IO_DEVICE_ADDR(0x10ff0000 + 0x0) /* eMMC pad ctrl reg */
126 #define REG_CTRL_SD_START IO_DEVICE_ADDR(0x10ff0000 + 0x24)  /* sd pad ctrl reg */
127 #define REG_CTRL_SDIO_START IO_DEVICE_ADDR(0x112f0000 + 0x8) /* sdio pad ctrl reg */
128 
129 enum HimciPowerStatus {
130     HOST_POWER_OFF,
131     HOST_POWER_ON,
132 };
133 
134 enum HimciDmaDataDirection {
135     DMA_BIDIRECTIONAL = 0,
136     DMA_TO_DEVICE = 1,
137     DMA_FROM_DEVICE = 2,
138     DMA_NONE = 3,
139 };
140 
141 enum HimciHostRegister {
142     MMC_CTRL = 0x0000,
143     MMC_PWREN = 0x0004,
144     MMC_CLKDIV = 0x0008,
145     MMC_CLKENA = 0x0010,
146     MMC_TMOUT = 0x0014,
147     MMC_CTYPE = 0x0018,
148     MMC_BLKSIZ = 0x001c,
149     MMC_BYTCNT = 0x0020,
150     MMC_INTMASK = 0x0024,
151     MMC_CMDARG = 0x0028,
152     MMC_CMD = 0x002C,
153     MMC_RESP0 = 0x0030,
154     MMC_RESP1 = 0x0034,
155     MMC_RESP2 = 0x0038,
156     MMC_RESP3 = 0x003C,
157     MMC_MINTSTS = 0x0040,
158     MMC_RINTSTS = 0x0044,
159     MMC_STATUS = 0x0048,
160     MMC_FIFOTH = 0x004C,
161     MMC_CDETECT = 0x0050,
162     MMC_WRTPRT = 0x0054,
163     MMC_GPIO = 0x0058,
164     MMC_TCBCNT = 0x005C,
165     MMC_TBBCNT = 0x0060,
166     MMC_DEBNCE = 0x0064,
167     MMC_UHS_REG = 0x0074,
168     MMC_CARD_RSTN = 0x0078,
169     MMC_BMOD = 0x0080,
170     MMC_DBADDR = 0x0088,
171     MMC_IDSTS = 0x008C,
172     MMC_IDINTEN = 0x0090,
173     MMC_DSCADDR = 0x0094,
174     MMC_BUFADDR = 0x0098,
175     MMC_CARDTHRCTL = 0x0100,
176     MMC_UHS_REG_EXT = 0x0108,
177     MMC_EMMC_DDR_REG = 0x010c,
178     MMC_ENABLE_SHIFT = 0x0110,
179     MMC_TUNING_CTRL = 0x0118,
180     MMC_DATA = 0x0200
181 };
182 
183 /*
184  * MMC_CTRL(0x0000) details.
185  * [25]Whether to use the built-in DMA to transfer data.
186  * 0: The CPU uses the slave interface to transfer data. 1: The internal DMA is used to transfer data.
187  * [4]Global interrupt enable. 0: disabled; 1: enabled.
188  * The interrupt output is valid only when this bit is valid and an interrupt source is enabled.
189  * [2]Soft reset control for the internal DMAC. 0: invalid; 1: Reset the internal DMA interface.
190  * This bit is automatically reset after two AHB clock cycles.
191  * [1]Soft reset control for the internal FIFO. 0: invalid; 1: Reset the FIFO pointer.
192  * This bit is automatically reset after the reset operation is complete.
193  * [0]Soft reset control for the controller. 0: invalid; 1: Reset the eMMC/SD/SDIO host module.
194  */
195 #define CTRL_RESET       (1U << 0)
196 #define FIFO_RESET       (1U << 1)
197 #define DMA_RESET        (1U << 2)
198 #define INTR_EN          (1U << 4)
199 #define USE_INTERNAL_DMA (1U << 25)
200 
201 /*
202  * MMC_PWREN(0x0004) details.
203  * [0]POWER control. 0: power off; 1: The power supply is turned on.
204  */
205 #define POWER_ENABLE (1U << 0)
206 
207 /*
208  * MMC_CLKDIV(0x0008) details.
209  * [7:0]Clock divider. The clock frequency division coefficient is 2 * n.
210  * For example, 0 indicates no frequency division, 1 indicates frequency division by 2,
211  * and ff indicates frequency division by 510.
212  */
213 #define CLK_DIVIDER    (0xff * 2)
214 #define MAX_CLKDIV_VAL 0xff
215 
216 /*
217  * MMC_CLKENA(0x0010) details.
218  * [16]Low-power control of the card, used to disable the card clock. 0: no low-power mode; 1: low-power mode.
219  * When the card is in the idle state, the card clock is stopped. This function applies only to the SD card and eMMC.
220  * For the SDIO, the clock cannot be stopped to detect interrupts.
221  * [0]Card clock enable. 0: disabled; 1: enabled.
222  */
223 #define CCLK_LOW_POWER (1U << 16)
224 #define CCLK_ENABLE    (1U << 0)
225 
226 /*
227  * MMC_TMOUT(0x14) details.
228  * [31:8]data read timeout param.
229  * [7:0]response timeout param.
230  */
231 #define DATA_TIMEOUT     (0xffffffU << 8)
232 #define RESPONSE_TIMEOUT 0xff
233 
234 /*
235  * MCI_CTYPE(0x0018) details.
236  * [16]Bus width of the card. 0: non-8-bit mode, depending on the configuration of bit[0];
237  * 1: 8-bit mode, the value of bit[0] is ignored.
238  * [0]Bus width of the card. 0: 1-bit mode; 1: 4-bit mode.
239  */
240 #define CARD_WIDTH_1  (1U << 0)
241 #define CARD_WIDTH_0  (1U << 16)
242 
243 /* MCI_INTMASK(0x24) details.
244  * [16:0]mask MMC host controller each interrupt. 0: disable; 1: enabled.
245  * [16]SDIO interrupt; [3]data transfer over(DTO).
246  */
247 #define ALL_INT_MASK   0x1ffff
248 #define DTO_INT_MASK   (1 << 3)
249 #define SDIO_INT_MASK  (1 << 16)
250 
251 /*
252  * MCI_CMD(0x2c) details:
253  * [31]cmd execute or load start param of interface clk bit.
254  */
255 #define START_CMD (1U << 31)
256 
257 /*
258  * MCI_INTSTS(0x44) details.
259  * [16]sdio interrupt status; [15]end-bit error (read)/write no CRC interrupt status;
260  * [14]auto command done interrupt status; [13]start bit error interrupt status;
261  * [12]hardware locked write error interrupt status; [11]FIFO underrun/overrun error interrupt status;
262  * [10]data starvation-by-host timeout/volt_switch to 1.8v for sdxc interrupt status;
263  * [9]data read timeout interrupt status; [8]response timeout interrupt status; [7]data CRC error interrupt status;
264  * [6]response CRC error interrupt status; [5]receive FIFO data request interrupt status;
265  * [4]transmit FIFO data request interrupt status; [3]data transfer Over interrupt status;
266  * [2]command done interrupt status; [1]response error interrupt status; [0]card detect interrupt status.
267  */
268 #define SDIO_INT_STATUS        (1U << 16)
269 #define EBE_INT_STATUS         (1U << 15)
270 #define ACD_INT_STATUS         (1U << 14)
271 #define SBE_INT_STATUS         (1U << 13)
272 #define HLE_INT_STATUS         (1U << 12)
273 #define FRUN_INT_STATUS        (1U << 11)
274 #define HTO_INT_STATUS         (1U << 10)
275 #define VOLT_SWITCH_INT_STATUS (1U << 10)
276 #define DRTO_INT_STATUS        (1U << 9)
277 #define RTO_INT_STATUS         (1U << 8)
278 #define DCRC_INT_STATUS        (1U << 7)
279 #define RCRC_INT_STATUS        (1U << 6)
280 #define RXDR_INT_STATUS        (1U << 5)
281 #define TXDR_INT_STATUS        (1U << 4)
282 #define DTO_INT_STATUS         (1U << 3)
283 #define CD_INT_STATUS          (1U << 2)
284 #define RE_INT_STATUS          (1U << 1)
285 #define CARD_DETECT_INT_STATUS (1U << 0)
286 #define DATA_INT_MASK (DTO_INT_STATUS | DCRC_INT_STATUS | SBE_INT_STATUS | EBE_INT_STATUS)
287 #define CMD_INT_MASK  (RTO_INT_STATUS | RCRC_INT_STATUS | RE_INT_STATUS | CD_INT_STATUS | VOLT_SWITCH_INT_STATUS)
288 #define ALL_INT_CLR   0x1efff
289 
290 /*
291  * MMC_STATUS(0x48) details.
292  * [9]Status of data_busy indicated by DAT[0]. 0: idle; 1: The card is busy.
293  */
294 #define DATA_BUSY (1U << 9)
295 
296 /* MMC_FIFOTH(0x4c) details.
297  * [30:28]Indicates the transmission burst length.
298  * 000: 1; 001: 4; 010: 8; 011: 16; 100: 32; 101: 64; 110: 128; 111:256.
299  * [27:16]FIFO threshold watermarklevel when data is read.
300  * When the FIFO count is greater than the value of this parameter, the DMA request is enabled.
301  * To complete the remaining data after data transfer, a DMA request is generated.
302  * [11:0]FIFO threshold watermark level when data is transmitted.
303  * When the FIFO count is less than the value of this parameter, the DMA request is enabled.
304  * To complete the remaining data after data transfer, a DMA request is generated.
305  */
306 #define BURST_SIZE      (0x6 << 28)
307 #define RX_WMARK        (0x7f << 16)
308 #define TX_WMARK        0x80
309 
310 /*
311  * MMC_CDETECT(0x0050) details.
312  * [0]Card detection signal. 0: The card is detected; 1: The card is not detected.
313  */
314 #define CARD_UNPLUGED (1U << 0)
315 
316 /*
317  * MMC_WRTPRT(0x0054) details.
318  * [0] 0: card read/write; 1: card readonly.
319  */
320 #define CARD_READONLY (1U << 0)
321 
322 /*
323  * MMC_GPIO(0x0058) details.
324  * [23] 0: dto fix bypass; 1: dto fix enable.
325  */
326 #define DTO_FIX_ENABLE (1U << 23)
327 
328 /*
329  * MMC_DEBNCE(0x0064) details.
330  * [23:0]Number of bus clock cycles used by the dejitter filter logic. The dejitter time is 5ms to 25ms.
331  */
332 #define DEBNCE_MS 25
333 #define DEBOUNCE_E (DEBNCE_MS * 150000)
334 #define DEBOUNCE_H (DEBNCE_MS * 100000)
335 #define DEBOUNCE_M (DEBNCE_MS * 50000)
336 #define DEBOUNCE_L (DEBNCE_MS * 25000)
337 
338 /*
339  * MMC_UHS_REG(0x0074) details.
340  * [16] DDR Mode control register, 0: non-DDR mode, 1: DDR mode.
341  * [0] Voltage mode control register, 0: 3.3V, 1: 1.8V.
342  */
343 #define HI_SDXC_CTRL_DDR_REG    (1U << 16)
344 #define HI_SDXC_CTRL_VDD_180    (1U << 0)
345 
346 /*
347  * MMC_CARD_RSTN(0x0078) details.
348  * [16] eMMC reset controller. 0: reset; 1: reset deasserted.
349  */
350 #define CARD_RESET (1U << 0)
351 
352 /* MMC_BMOD(0x80) details.
353  * [10:8]Indicates the length of the IDMAC burst transmission.
354  * 000: 1; 001: 4; 010: 8; 011: 16; 100: 32; 101: 64; 110: 128; 111:256.
355  * [7]IDMAC enable. 0: disabled; 1: enabled.
356  * [1]Fixed burst length.
357  * 0: SINGLE and INCR burst types are used; 1: SINGLE, INCR4, INCR8, and INCR16 burst types are used.
358  * [0]Soft reset control for IDMAC internal registers. 0: not reset; 1: reset.
359  * This bit is automatically cleared one clock cycle after this bit is set.
360  *
361  */
362 #define BMOD_SWR    (1U << 0)
363 #define BURST_INCR  (1U << 1)
364 #define BMOD_DMA_EN (1U << 7)
365 #define BURST_8     (1U << 8)
366 #define BURST_16    (3U << 8)
367 
368 /* MMC_CARDTHRCTL(0x0100) details.
369  * [27:16]Read threshold. The maximum value is 512.
370  * [1]Busy clear interrupt enable. 0: disabled; 1: enabled.
371  * [0]Read threshold enable. 0: disabled; 1: enabled.
372  */
373 #define READ_THRESHOLD_SIZE    0x2000005
374 #define BUSY_CLEAR_INT_ENABLE  (1U << 1)
375 
376 /* MMC_UHS_REG_EXT(0x0108) details.
377  * [25:23]Clock phase of clk_in_drv, in degrees.
378  * [18:16]Clock phase of clk_in_sample, in degrees.
379  * 000: 0; 001: 45; 010: 90; 011: 135; 100: 180; 101: 225; 110: 270; 111: 315.
380  */
381 #define CLK_SMPL_PHS_OFFSET   16
382 #define CLK_SMPL_PHS_MASK     (0x7 << CLK_SMPL_PHS_OFFSET)
383 #define CLK_DRV_PHS_OFFSET    23
384 #define CLK_DRV_PHS_MASK      (0x7 << CLK_DRV_PHS_OFFSET)
385 #define DRV_PHASE_180         (0x4 << 23)
386 #define DRV_PHASE_135         (0x3 << 23)
387 #define DRV_PHASE_90          (0x2 << 23)
388 #define SMP_PHASE_45          (0x1 << 16)
389 #define SMP_PHASE_0           (0x0 << 16)
390 #define DRV_PHASE_SHIFT       0x4
391 #define SMPL_PHASE_SHIFT      0x1
392 
393 #define TUNING_START_PHASE    0
394 #define TUNING_END_PHASE      7
395 #define HIMCI_PHASE_SCALE     8
396 #define DRV_PHASE_DFLT        DRV_PHASE_180
397 #define SMPL_PHASE_DFLT       SMP_PHASE_0
398 
399 /*
400  * MMC_TUNING_CTRL(0x118) details.
401  */
402 #define HW_TUNING_EN    (1U << 0)
403 #define EDGE_CTRL       (1U << 1)
404 #define FOUND_EDGE      (1U << 5)
405 
406 /* IDMAC DEST0 details */
407 #define DMA_DES_OWN         (1U << 31)
408 #define DMA_DES_NEXT_DES    (1U << 4)
409 #define DMA_DES_FIRST_DES   (1U << 3)
410 #define DMA_DES_LAST_DES    (1U << 2)
411 
412 /* MMC_CMD(0x002C) register bits define. */
413 union HimciCmdRegArg {
414     uint32_t arg;
415     struct CmdBits {
416         uint32_t cmdIndex : 6;   /* [5:0]Command sequence number. */
417         uint32_t rspExpect : 1;  /*
418                                   * Indicates whether a response exists.
419                                   * 0: No response is output from the slave card.
420                                   * 1: A response is output from the slave card.
421                                   */
422         uint32_t rspLen : 1;     /*
423                                   * Response length. 0: The short response is output from the card.
424                                   * 1: The long response is output from the card.
425                                   * The long response is 128 bits, and the short response is 32 bits.
426                                   */
427         uint32_t checkRspCrc : 1; /*
428                                    * Indicates whether the CRC check is performed.
429                                    * 0: The CRC response is not checked. 1: Check the CRC response.
430                                    */
431         uint32_t dataTransferExpected : 1; /*
432                                             * Data transfer indicator.
433                                             * 0: No data is output from the card. 1: Data is output from the card.
434                                             */
435         uint32_t readWrite : 1;  /*
436                                   * Read/write control. 0: Read data from the card. 1: Write data to the card.
437                                   * This bit is ignored in non-data transmission.
438                                   */
439         uint32_t transferMode : 1; /*
440                                     * 0: block transfer command; 1: stream transmission command.
441                                     * This bit is ignored in non-data transmission.
442                                     */
443         uint32_t sendAutoStop : 1; /*
444                                     * Indicates whether to send the stop command.
445                                     * 0: The stop command is not sent after the data transfer is complete.
446                                     * 1: The stop command is sent after data transfer is complete.
447                                     * This bit is ignored in non-data transmission.
448                                     */
449         uint32_t waitDataComplete : 1; /*
450                                         * Indicates whether to send an instruction immediately.
451                                         * 0: Send the command immediately;
452                                         * 1: Send the command after the previous data transfer is complete.
453                                         * 0 is a typical value, which is used to read the status or interrupt the
454                                         * transfer during data transfer.
455                                         */
456         uint32_t stopAbortCmd : 1; /*
457                                     * When the data transfer operation is in progress, the values are as follows:
458                                     * 0: The stop/abort command is not sent.
459                                     * 1: The stop/abort command is sent to stop the ongoing data transfer.
460                                     */
461         uint32_t sendInitialization : 1; /*
462                                           * Indicates whether to send the initial sequence.
463                                           * 0: The initial sequence is not sent before the Send_initialization is sent.
464                                           * 1: The initial sequence is sent before the Send_initialization is sent.
465                                           * When the card is powered on, the initial sequence must be sent for
466                                           * initialization before any command is sent. That is, this bit is set to 1.
467                                           */
468         uint32_t cardNumber : 5;  /* Sequence number of the card in use. */
469         uint32_t updateClkRegOnly : 1; /*
470                                         * Indicates whether to automatically update.
471                                         * 0: normal command sequence; 1: No command is sent. Only the clock register
472                                         * value of the card clock domain is updated.
473                                         * Set this bit to 1 each time the card clock is changed. In this case,
474                                         * no command is transmitted to the card,
475                                         * and no command-done interrupt is generated.
476                                         */
477         uint32_t reserved1 : 2;
478         uint32_t enableBoot : 1; /*
479                                   * Enable the boot function. This bit can be used only in forcible boot mode.
480                                   * When software enables this bit and Start_cmd at the same time,
481                                   * the controller pulls down the CMD signal to start the boot process.
482                                   * Enable_boot and Disable_boot cannot be enabled at the same time.
483                                   */
484         uint32_t expectBootAck : 1; /*
485                                      * Enables the boot response. When the software enables this bit and Enable_boot at
486                                      * the same time, the controller detects the boot response signal,
487                                      * that is, the 0-1-0 sequence.
488                                      */
489         uint32_t disableBoot : 1; /*
490                                    * Disable the boot. When the software enables this bit and Start_cmd at the same
491                                    * time, the controller stops the boot operation.
492                                    * Enable_boot and Disable_boot cannot be enabled at the same time.
493                                    */
494         uint32_t bootMode : 1;    /* Boot mode. 0: forcible boot mode; 1: alternate boot mode. */
495         uint32_t voltSwitch : 1;  /* Voltage switching control. 0: The voltage switching is disabled. 1: enabled. */
496         uint32_t useHoldReg : 1;  /*
497                                    * 0: The CMD and DATA signals sent to the card do not pass through the HOLD register.
498                                    * 1: The CMD and DATA signals sent to the card pass through the HOLD register.
499                                    */
500         uint32_t reserved2 : 1;
501         uint32_t startCmd : 1;    /*
502                                    * Start control. 0: not enabled; 1: start command.
503                                    * This bit is cleared when the command has been sent to the CIU.
504                                    * The CPU cannot modify this register.
505                                    * If the value is changed, a hardware lock error interrupt is generated.
506                                    * After sending a command, the CPU needs to query this bit.
507                                    * After the bit becomes 0, the CPU sends the next command.
508                                    */
509     } bits;
510 };
511 
512 struct HimciDes {
513     unsigned long dmaDesCtrl;
514     unsigned long dmaDesBufSize;
515     unsigned long dmaDesBufAddr;
516     unsigned long dmaDesNextAddr;
517 };
518 
519 #define HIMCI_PEND_DTO_M     (1U << 0)
520 #define HIMCI_PEND_ACCIDENT  (1U << 1)
521 #define HIMCI_HOST_INIT_DONE (1U << 2)
522 struct HimciHost {
523     struct MmcCntlr *mmc;
524     struct MmcCmd *cmd;
525     void *base;
526     enum HimciPowerStatus powerStatus;
527     uint8_t *alignedBuff;
528     uint32_t buffLen;
529     struct scatterlist dmaSg;
530     struct scatterlist *sg;
531     uint32_t dmaSgNum;
532     DMA_ADDR_T dmaPaddr;
533     uint32_t *dmaVaddr;
534     uint32_t irqNum;
535     bool isTuning;
536     uint32_t id;
537     struct OsalMutex mutex;
538     bool waitForEvent;
539     HIMCI_EVENT himciEvent;
540 };
541 
542 struct HimciTuneParam {
543     uint32_t cmdCode;
544     uint32_t edgeP2f;
545     uint32_t edgeF2p;
546     uint32_t startp;
547     uint32_t endp;
548     uint32_t endpInit;
549 };
550 
551 #ifdef __cplusplus
552 #if __cplusplus
553 }
554 #endif /* __cplusplus */
555 #endif /* __cplusplus */
556 
557 #endif /* HIMCI_H */
558