瀏覽代碼

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.
Daniel Bertalan 2 年之前
父節點
當前提交
6eb06384b3
共有 1 個文件被更改,包括 8 次插入0 次删除
  1. 8 0
      Kernel/Devices/Storage/SD/SDHostController.cpp

+ 8 - 0
Kernel/Devices/Storage/SD/SDHostController.cpp

@@ -47,6 +47,10 @@ constexpr u32 internal_clock_stable = 1 << 1;
 constexpr u32 sd_clock_enable = 1 << 2;
 constexpr u32 sd_clock_enable = 1 << 2;
 constexpr u32 sd_clock_divisor_mask = 0x0000ffc0;
 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"
 // In sub-register "Software Reset"
 constexpr u32 software_reset_for_all = 0x01000000;
 constexpr u32 software_reset_for_all = 0x01000000;
 
 
@@ -469,6 +473,10 @@ ErrorOr<void> SDHostController::sd_clock_supply(u32 frequency)
         return EIO;
         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
     // 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;
     m_registers->host_configuration_1 = m_registers->host_configuration_1 | sd_clock_enable;