diff --git a/Kernel/Devices/Storage/SD/Registers.h b/Kernel/Devices/Storage/SD/Registers.h index cd077ab2d6..1f3489b4b9 100644 --- a/Kernel/Devices/Storage/SD/Registers.h +++ b/Kernel/Devices/Storage/SD/Registers.h @@ -42,7 +42,34 @@ struct HostControlRegisterMap { u32 response_2; u32 response_3; u32 buffer_data_port; - u32 present_state; + union PresentState { + struct { // SDHC 2.2.9 Present State Register (Cat.C Offset 024h) + u32 command_inhibit_cmd : 1; + u32 command_inhibit_dat : 1; + u32 dat_line_active : 1; + u32 re_tuning_request : 1; + u32 dat_7_4_line_signal_level : 4; + u32 write_transfer_active : 1; + u32 read_transfer_active : 1; + u32 buffer_write_enable : 1; + u32 buffer_read_enable : 1; + u32 : 4; + u32 card_inserted : 1; + u32 card_state_stable : 1; + u32 card_detect_pin_level : 1; + u32 write_protect_switch_pin_level : 1; + u32 dat_3_0_line_signal_level : 4; + u32 cmd_line_signal_level : 1; + u32 host_regulator_voltage_stable : 1; + u32 : 1; + u32 command_not_issued_by_error : 1; + u32 sub_command_status : 1; + u32 in_dormant_state : 1; + u32 lane_synchronization : 1; + u32 uhs_2_if_detection : 1; + }; + u32 raw; + } present_state; u32 host_configuration_0; u32 host_configuration_1; union InterruptStatus { diff --git a/Kernel/Devices/Storage/SD/SDHostController.cpp b/Kernel/Devices/Storage/SD/SDHostController.cpp index 582703cb3c..2b31e2cd42 100644 --- a/Kernel/Devices/Storage/SD/SDHostController.cpp +++ b/Kernel/Devices/Storage/SD/SDHostController.cpp @@ -270,14 +270,12 @@ bool SDHostController::retry_with_timeout(Function f, i64 delay_between_ ErrorOr SDHostController::issue_command(SD::Command const& cmd, u32 argument) { // SDHC 3.7.1: "Transaction Control without Data Transfer Using DAT Line" - constexpr u32 command_inhibit = 1 << 1; // 1. Check Command Inhibit (CMD) in the Present State register. // Repeat this step until Command Inhibit (CMD) is 0. // That is, when Command Inhibit (CMD) is 1, the Host Driver // shall not issue an SD Command. - if (!retry_with_timeout( - [&]() { return !(m_registers->present_state & command_inhibit); })) { + if (!retry_with_timeout([&]() { return !m_registers->present_state.command_inhibit_cmd; })) { return EIO; } @@ -290,8 +288,7 @@ ErrorOr SDHostController::issue_command(SD::Command const& cmd, u32 argume // 4. Check Command Inhibit (DAT) in the Present State register. Repeat // this step until Command Inhibit (DAT) is set to 0. - constexpr u32 data_inhibit = 1 << 2; - if (!retry_with_timeout([&]() { return !(m_registers->present_state & data_inhibit); })) { + if (!retry_with_timeout([&]() { return !m_registers->present_state.command_inhibit_dat; })) { return EIO; } } diff --git a/Kernel/Devices/Storage/SD/SDHostController.h b/Kernel/Devices/Storage/SD/SDHostController.h index 1d6d5af050..e95edb8458 100644 --- a/Kernel/Devices/Storage/SD/SDHostController.h +++ b/Kernel/Devices/Storage/SD/SDHostController.h @@ -43,8 +43,7 @@ private: bool is_card_inserted() const { - constexpr u32 card_inserted = 1 << 16; - return m_registers->present_state & card_inserted; + return m_registers->present_state.card_inserted; } SD::HostVersion host_version() { return m_registers->slot_interrupt_status_and_version.specification_version_number; }