litesdcard: use new clocker.
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Fri, 3 Jul 2020 18:06:42 +0000 (20:06 +0200)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Fri, 3 Jul 2020 18:06:42 +0000 (20:06 +0200)
litex/soc/integration/soc.py
litex/soc/software/liblitesdcard/sdcard.c

index acb3322e14b9228822999de6bc2bc0d92b29dd08..3c3f13bf21f9d0b0f4beb70c408edfc77b2985a6 100644 (file)
@@ -1283,7 +1283,3 @@ class LiteXSoC(SoC):
         self.submodules.sdwriter_fifo = stream.SyncFIFO([("data", self.bus.data_width)], 512//(self.bus.data_width//8))
         self.comb += self.sdwriter.source.connect(self.sdwriter_fifo.sink)
         self.comb += self.sdwriter_fifo.source.connect(self.sdcore.sink)
-
-        # Timing constraints
-        if not with_emulator:
-            self.platform.add_false_path_constraints(self.crg.cd_sys.clk, self.crg.cd_sd.clk)
index c5d803268f94d186ebd8d66084bf391083543767..b3ad3f3227cf7a0e8a62fdc544dde380de12cca6 100644 (file)
@@ -101,6 +101,31 @@ int sdcard_wait_response(void) {
        return status;
 }
 
+/*-----------------------------------------------------------------------*/
+/* SDCard clocker functions                                              */
+/*-----------------------------------------------------------------------*/
+
+static uint32_t log2(uint32_t x)
+{
+  uint32_t r = 0 ;
+  while(x >>= 1) r++;
+  return r;
+}
+
+static void sdcard_set_clk_freq(uint32_t clk_freq) {
+    uint32_t divider;
+    divider = CONFIG_CLOCK_FREQUENCY/clk_freq + 1;
+    divider = (1 << log2(divider));
+//#ifdef SDCARD_DEBUG
+    printf("Setting SDCard clk freq to ");
+    if (clk_freq > 1000000)
+        printf("%d MHz\n", (CONFIG_CLOCK_FREQUENCY/divider)/1000000);
+    else
+        printf("%d KHz\n", (CONFIG_CLOCK_FREQUENCY/divider)/1000);
+//#endif
+    sdphy_clocker_divider_write(divider);
+}
+
 /*-----------------------------------------------------------------------*/
 /* SDCard commands functions                                             */
 /*-----------------------------------------------------------------------*/
@@ -415,6 +440,9 @@ void sdcard_decode_csd(void) {
 int sdcard_init(void) {
        unsigned short rca;
 
+       /* initialize freq */
+       sdcard_set_clk_freq(16000000);
+
        /* initialize card */
        sdphy_init_initialize_write(1);
        busy_wait(1);