Skip to content

[components][drivers][sd] add uhs-i mode support to sd driver #8987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions components/drivers/include/drivers/mmcsd_card.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Date Author Notes
* 2011-07-25 weety first version
* 2024-05-24 HPMicro add HS400 support
* 2024-05-26 HPMicro add UHS-I support for SD card
*/

#ifndef __MMCSD_CARD_H__
Expand Down Expand Up @@ -84,6 +85,51 @@ struct rt_sdio_cccr {

};

/*
* SD Status
*/
union rt_sd_status {
rt_uint32_t status_words[16];
struct {
rt_uint32_t reserved[12];
rt_uint64_t : 8;
rt_uint64_t uhs_au_size: 4;
rt_uint64_t uhs_speed_grade: 4;
rt_uint64_t erase_offset: 2;
rt_uint64_t erase_timeout: 6;
rt_uint64_t erase_size: 16;
rt_uint64_t : 4;
rt_uint64_t au_size: 4;
rt_uint64_t performance_move: 8;
rt_uint64_t speed_class: 8;

rt_uint32_t size_of_protected_area;

rt_uint32_t sd_card_type: 16;
rt_uint32_t : 6;
rt_uint32_t : 7;
rt_uint32_t secured_mode: 1;
rt_uint32_t data_bus_width: 2;
};
};

/*
* SD Speed Class
*/
#define SD_SPEED_CLASS_0 0
#define SD_SPEED_CLASS_2 1
#define SD_SPEED_CLASS_4 2
#define SD_SPEED_CLASS_6 3
#define SD_SPEED_CLASS_10 4

/*
* UHS Speed Grade
*/
#define UHS_SPEED_GRADE_0 0
#define UHS_SPEED_GRADE_1 1
#define UHS_SPEED_GRADE_3 3


struct rt_sdio_cis {
rt_uint16_t manufacturer;
rt_uint16_t product;
Expand Down Expand Up @@ -161,6 +207,9 @@ struct rt_mmcsd_card {
#define CARD_FLAG_HIGHSPEED_DDR (1 << 3) /* HIGH SPEED DDR */
#define CARD_FLAG_HS200 (1 << 4) /* BUS SPEED 200MHz */
#define CARD_FLAG_HS400 (1 << 5) /* BUS SPEED 400MHz */
#define CARD_FLAG_SDR50 (1 << 6) /* BUS SPEED 100MHz */
#define CARD_FLAG_SDR104 (1 << 7) /* BUS SPEED 200MHz */
#define CARD_FLAG_DDR50 (1 << 8) /* DDR50, works on 1.8V only */
struct rt_sd_scr scr;
struct rt_mmcsd_csd csd;
rt_uint32_t hs_max_data_rate; /* max data transfer rate in high speed mode */
Expand Down
5 changes: 3 additions & 2 deletions components/drivers/include/drivers/mmcsd_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
*
* Change Logs:
* Date Author Notes
* 2011-07-25 weety first version
* 2011-07-25 weety first version
* 2024-05-26 HPMicro add VOLTAGE_SWITCH definition
*/

#ifndef __CMD_H__
Expand All @@ -26,7 +27,7 @@ extern "C" {
#define SEND_EXT_CSD 8 /* adtc R1 */
#define SEND_CSD 9 /* ac [31:16] RCA R2 */
#define SEND_CID 10 /* ac [31:16] RCA R2 */
#define READ_DAT_UNTIL_STOP 11 /* adtc [31:0] dadr R1 */
#define VOLTAGE_SWITCH 11 /* ac [31:0] R1 */
#define STOP_TRANSMISSION 12 /* ac R1b */
#define SEND_STATUS 13 /* ac [31:16] RCA R1 */
#define GO_INACTIVE_STATE 15 /* ac [31:16] RCA */
Expand Down
6 changes: 6 additions & 0 deletions components/drivers/include/drivers/mmcsd_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Date Author Notes
* 2011-07-25 weety first version
* 2024-05-25 HPMicro add HS400 support
* 2024-05-26 HPMicro add UHS-I support
*/

#ifndef __HOST_H__
Expand Down Expand Up @@ -87,6 +88,7 @@ struct rt_mmcsd_host_ops
rt_int32_t (*get_card_status)(struct rt_mmcsd_host *host);
void (*enable_sdio_irq)(struct rt_mmcsd_host *host, rt_int32_t en);
rt_int32_t (*execute_tuning)(struct rt_mmcsd_host *host, rt_int32_t opcode);
rt_int32_t (*switch_uhs_voltage)(struct rt_mmcsd_host *host);
};

struct rt_mmcsd_host
Expand Down Expand Up @@ -115,6 +117,7 @@ struct rt_mmcsd_host
#define VDD_33_34 (1 << 21) /* VDD voltage 3.3 ~ 3.4 */
#define VDD_34_35 (1 << 22) /* VDD voltage 3.4 ~ 3.5 */
#define VDD_35_36 (1 << 23) /* VDD voltage 3.5 ~ 3.6 */
#define OCR_S18R (1 << 24) /* Switch to 1V8 Request */
rt_uint32_t flags; /* define device capabilities */
#define MMCSD_BUSWIDTH_4 (1 << 0)
#define MMCSD_BUSWIDTH_8 (1 << 1)
Expand All @@ -135,6 +138,9 @@ struct rt_mmcsd_host
#define MMCSD_SUP_HS400_1V2 (1 << 13)
#define MMCSD_SUP_HS400 (MMCSD_SUP_HS400_1V2 | MMCSD_SUP_HS400_1V8) /* hs400 ddr */
#define MMCSD_SUP_ENH_DS (1 << 14)
#define MMCSD_SUP_SDR50 (1 << 15)
#define MMCSD_SUP_SDR104 (1 << 16)
#define MMCSD_SUP_DDR50 (1 << 17)

rt_uint32_t max_seg_size; /* maximum size of one dma segment */
rt_uint32_t max_dma_segs; /* maximum number of dma segments in one request */
Expand Down
14 changes: 13 additions & 1 deletion components/drivers/include/drivers/sd.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
* Copyright (c) 2006-2024, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2011-07-25 weety first version
* 2024-05-26 HPMicro Add UHS-I support
*/

#ifndef __SD_H__
Expand All @@ -18,6 +19,17 @@
extern "C" {
#endif


/*
* SWITCH_FUNC timing
*/
#define SD_SWITCH_FUNC_TIMING_DEFAULT 0
#define SD_SWITCH_FUNC_TIMING_HS 1
#define SD_SWITCH_FUNC_TIMING_SDR50 2
#define SD_SWITCH_FUNC_TIMING_SDR104 3
#define SD_SWITCH_FUNC_TIMING_DDR50 4


rt_err_t mmcsd_send_if_cond(struct rt_mmcsd_host *host, rt_uint32_t ocr);
rt_err_t mmcsd_send_app_op_cond(struct rt_mmcsd_host *host, rt_uint32_t ocr, rt_uint32_t *rocr);

Expand Down
Loading
Loading