1 /*
2  * Copyright (c) 2024 Renesas Electronics Corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #define SDHI_PRV_ACCESS_TIMEOUT_US       100000U
8 #define SDHI_PRV_SD_OPTION_DEFAULT       0x40E0U
9 #define SDHI_PRV_SD_OPTION_WIDTH8_BIT    13
10 #define SDHI_PRV_BYTES_PER_KILOBYTE      1024
11 #define SDHI_PRV_SECTOR_COUNT_IN_EXT_CSD 0xFFFU
12 #define SDHI_TIME_OUT_MAX                0xFFFFFFFF
13 #define SDHI_PRV_RESPONSE_BIT            0
14 
15 struct sdmmc_ra_event {
16 	volatile bool transfer_completed;
17 	struct k_sem transfer_sem;
18 };
19 
20 struct sdmmc_ra_command {
21 	uint32_t opcode;
22 	uint32_t arg;
23 	void *data;
24 	unsigned int sector_count;
25 	unsigned int sector_size;
26 	int timeout_ms;
27 };
28 
err_fsp2zep(int fsp_err)29 static ALWAYS_INLINE int err_fsp2zep(int fsp_err)
30 {
31 	int ret;
32 
33 	switch (fsp_err) {
34 	/* Treating the error codes most relevant to be individuated */
35 	case FSP_SUCCESS:
36 		ret = 0;
37 		break;
38 	case FSP_ERR_TIMEOUT:
39 		ret = -ETIMEDOUT;
40 		break;
41 	case FSP_ERR_NOT_FOUND:
42 		ret = -ENODEV; /* SD card not inserted (requires CD signal) */
43 		break;
44 	case FSP_ERR_INVALID_STATE:
45 		ret = -EACCES; /* SD card write-protected (requires WP sinal) */
46 		break;
47 	case FSP_ERR_RESPONSE:
48 	default:
49 		ret = -EIO;
50 		break;
51 	}
52 
53 	return ret;
54 }
55