1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:58:11 +00:00

Kernel: Increase SD Data Timeout

Otherwise, reading will sometimes fail on the Raspberry Pi.

This is mostly a hack, the spec has some info about how the correct
divisor should be calculated and how we can recover from timeouts.
This commit is contained in:
Daniel Bertalan 2023-06-24 11:43:10 +02:00 committed by Jelle Raaijmakers
parent bbe614c6c5
commit 6eb06384b3

View file

@ -47,6 +47,10 @@ constexpr u32 internal_clock_stable = 1 << 1;
constexpr u32 sd_clock_enable = 1 << 2;
constexpr u32 sd_clock_divisor_mask = 0x0000ffc0;
// In sub-register "Timeout Control"
constexpr u32 data_timeout_counter_value_mask = 0b1111 << 16;
constexpr u32 data_timeout_counter_value_max = 0b1110 << 16;
// In sub-register "Software Reset"
constexpr u32 software_reset_for_all = 0x01000000;
@ -469,6 +473,10 @@ ErrorOr<void> SDHostController::sd_clock_supply(u32 frequency)
return EIO;
}
// FIXME: With the default timeout value, reading will sometimes fail on the Raspberry Pi.
// We should be a bit smarter with choosing the right timeout value and handling errors.
m_registers->host_configuration_1 = (m_registers->host_configuration_1 & ~data_timeout_counter_value_mask) | data_timeout_counter_value_max;
// 4. Set SD Clock Enable in the Clock Control register to 1
m_registers->host_configuration_1 = m_registers->host_configuration_1 | sd_clock_enable;