Skip to content

Commit 2cc2743

Browse files
helloeagleyangRbb666
authored andcommitted
[components][drivers][sd] add uhs-i mode support to sd driver
- added SDR50, SDR104 and DDR50 support to SD driver Signed-off-by: Fan YANG <fan.yang@hpmicro.com>
1 parent 09a0e4c commit 2cc2743

File tree

5 files changed

+266
-35
lines changed

5 files changed

+266
-35
lines changed

Diff for: components/drivers/include/drivers/mmcsd_card.h

+49
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Date Author Notes
88
* 2011-07-25 weety first version
99
* 2024-05-24 HPMicro add HS400 support
10+
* 2024-05-26 HPMicro add UHS-I support for SD card
1011
*/
1112

1213
#ifndef __MMCSD_CARD_H__
@@ -84,6 +85,51 @@ struct rt_sdio_cccr {
8485

8586
};
8687

88+
/*
89+
* SD Status
90+
*/
91+
union rt_sd_status {
92+
rt_uint32_t status_words[16];
93+
struct {
94+
rt_uint32_t reserved[12];
95+
rt_uint64_t : 8;
96+
rt_uint64_t uhs_au_size: 4;
97+
rt_uint64_t uhs_speed_grade: 4;
98+
rt_uint64_t erase_offset: 2;
99+
rt_uint64_t erase_timeout: 6;
100+
rt_uint64_t erase_size: 16;
101+
rt_uint64_t : 4;
102+
rt_uint64_t au_size: 4;
103+
rt_uint64_t performance_move: 8;
104+
rt_uint64_t speed_class: 8;
105+
106+
rt_uint32_t size_of_protected_area;
107+
108+
rt_uint32_t sd_card_type: 16;
109+
rt_uint32_t : 6;
110+
rt_uint32_t : 7;
111+
rt_uint32_t secured_mode: 1;
112+
rt_uint32_t data_bus_width: 2;
113+
};
114+
};
115+
116+
/*
117+
* SD Speed Class
118+
*/
119+
#define SD_SPEED_CLASS_0 0
120+
#define SD_SPEED_CLASS_2 1
121+
#define SD_SPEED_CLASS_4 2
122+
#define SD_SPEED_CLASS_6 3
123+
#define SD_SPEED_CLASS_10 4
124+
125+
/*
126+
* UHS Speed Grade
127+
*/
128+
#define UHS_SPEED_GRADE_0 0
129+
#define UHS_SPEED_GRADE_1 1
130+
#define UHS_SPEED_GRADE_3 3
131+
132+
87133
struct rt_sdio_cis {
88134
rt_uint16_t manufacturer;
89135
rt_uint16_t product;
@@ -161,6 +207,9 @@ struct rt_mmcsd_card {
161207
#define CARD_FLAG_HIGHSPEED_DDR (1 << 3) /* HIGH SPEED DDR */
162208
#define CARD_FLAG_HS200 (1 << 4) /* BUS SPEED 200MHz */
163209
#define CARD_FLAG_HS400 (1 << 5) /* BUS SPEED 400MHz */
210+
#define CARD_FLAG_SDR50 (1 << 6) /* BUS SPEED 100MHz */
211+
#define CARD_FLAG_SDR104 (1 << 7) /* BUS SPEED 200MHz */
212+
#define CARD_FLAG_DDR50 (1 << 8) /* DDR50, works on 1.8V only */
164213
struct rt_sd_scr scr;
165214
struct rt_mmcsd_csd csd;
166215
rt_uint32_t hs_max_data_rate; /* max data transfer rate in high speed mode */

Diff for: components/drivers/include/drivers/mmcsd_cmd.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
*
66
* Change Logs:
77
* Date Author Notes
8-
* 2011-07-25 weety first version
8+
* 2011-07-25 weety first version
9+
* 2024-05-26 HPMicro add VOLTAGE_SWITCH definition
910
*/
1011

1112
#ifndef __CMD_H__
@@ -26,7 +27,7 @@ extern "C" {
2627
#define SEND_EXT_CSD 8 /* adtc R1 */
2728
#define SEND_CSD 9 /* ac [31:16] RCA R2 */
2829
#define SEND_CID 10 /* ac [31:16] RCA R2 */
29-
#define READ_DAT_UNTIL_STOP 11 /* adtc [31:0] dadr R1 */
30+
#define VOLTAGE_SWITCH 11 /* ac [31:0] R1 */
3031
#define STOP_TRANSMISSION 12 /* ac R1b */
3132
#define SEND_STATUS 13 /* ac [31:16] RCA R1 */
3233
#define GO_INACTIVE_STATE 15 /* ac [31:16] RCA */

Diff for: components/drivers/include/drivers/mmcsd_host.h

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Date Author Notes
88
* 2011-07-25 weety first version
99
* 2024-05-25 HPMicro add HS400 support
10+
* 2024-05-26 HPMicro add UHS-I support
1011
*/
1112

1213
#ifndef __HOST_H__
@@ -87,6 +88,7 @@ struct rt_mmcsd_host_ops
8788
rt_int32_t (*get_card_status)(struct rt_mmcsd_host *host);
8889
void (*enable_sdio_irq)(struct rt_mmcsd_host *host, rt_int32_t en);
8990
rt_int32_t (*execute_tuning)(struct rt_mmcsd_host *host, rt_int32_t opcode);
91+
rt_int32_t (*switch_uhs_voltage)(struct rt_mmcsd_host *host);
9092
};
9193

9294
struct rt_mmcsd_host
@@ -115,6 +117,7 @@ struct rt_mmcsd_host
115117
#define VDD_33_34 (1 << 21) /* VDD voltage 3.3 ~ 3.4 */
116118
#define VDD_34_35 (1 << 22) /* VDD voltage 3.4 ~ 3.5 */
117119
#define VDD_35_36 (1 << 23) /* VDD voltage 3.5 ~ 3.6 */
120+
#define OCR_S18R (1 << 24) /* Switch to 1V8 Request */
118121
rt_uint32_t flags; /* define device capabilities */
119122
#define MMCSD_BUSWIDTH_4 (1 << 0)
120123
#define MMCSD_BUSWIDTH_8 (1 << 1)
@@ -135,6 +138,9 @@ struct rt_mmcsd_host
135138
#define MMCSD_SUP_HS400_1V2 (1 << 13)
136139
#define MMCSD_SUP_HS400 (MMCSD_SUP_HS400_1V2 | MMCSD_SUP_HS400_1V8) /* hs400 ddr */
137140
#define MMCSD_SUP_ENH_DS (1 << 14)
141+
#define MMCSD_SUP_SDR50 (1 << 15)
142+
#define MMCSD_SUP_SDR104 (1 << 16)
143+
#define MMCSD_SUP_DDR50 (1 << 17)
138144

139145
rt_uint32_t max_seg_size; /* maximum size of one dma segment */
140146
rt_uint32_t max_dma_segs; /* maximum number of dma segments in one request */

Diff for: components/drivers/include/drivers/sd.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/*
2-
* Copyright (c) 2006-2023, RT-Thread Development Team
2+
* Copyright (c) 2006-2024, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
66
* Change Logs:
77
* Date Author Notes
88
* 2011-07-25 weety first version
9+
* 2024-05-26 HPMicro Add UHS-I support
910
*/
1011

1112
#ifndef __SD_H__
@@ -18,6 +19,17 @@
1819
extern "C" {
1920
#endif
2021

22+
23+
/*
24+
* SWITCH_FUNC timing
25+
*/
26+
#define SD_SWITCH_FUNC_TIMING_DEFAULT 0
27+
#define SD_SWITCH_FUNC_TIMING_HS 1
28+
#define SD_SWITCH_FUNC_TIMING_SDR50 2
29+
#define SD_SWITCH_FUNC_TIMING_SDR104 3
30+
#define SD_SWITCH_FUNC_TIMING_DDR50 4
31+
32+
2133
rt_err_t mmcsd_send_if_cond(struct rt_mmcsd_host *host, rt_uint32_t ocr);
2234
rt_err_t mmcsd_send_app_op_cond(struct rt_mmcsd_host *host, rt_uint32_t ocr, rt_uint32_t *rocr);
2335

0 commit comments

Comments
 (0)