software/liblitesdcard/spisdcard: rename #defines and allow external definition.
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Tue, 9 Jun 2020 11:50:16 +0000 (13:50 +0200)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Tue, 9 Jun 2020 11:50:28 +0000 (13:50 +0200)
litex/soc/software/liblitesdcard/spisdcard.c

index 9b66f7021832b6f3594bb81156e51051aa636dd0..993380a97e8d540895cf2cd591c4b8136108324f 100644 (file)
 
 #ifdef CSR_SPISDCARD_BASE
 
-#define SDCARD_DEBUG
+#define SPISDCARD_DEBUG
+
+#ifndef SPISDCARD_CLK_FREQ_INIT
+#define SPISDCARD_CLK_FREQ_INIT 400000
+#endif
+#ifndef SPISDCARD_CLK_FREQ
+#define SPISDCARD_CLK_FREQ 10000000
+#endif
 
 /*-----------------------------------------------------------------------*/
 /* SPI Master low-level functions                                        */
 /*-----------------------------------------------------------------------*/
 
-#define SPI_CLK_FREQ_INIT          400000
-#define SPI_CLK_FREQ_OPERATIONAL 10000000
-
 static void spi_set_clk_freq(uint32_t clk_freq) {
     uint32_t divider;
     divider = CONFIG_CLOCK_FREQUENCY/clk_freq + 1;
@@ -34,7 +38,7 @@ static void spi_set_clk_freq(uint32_t clk_freq) {
         divider = 65535;
     if (divider <= 2)     /* At least half CPU speed */
         divider = 2;
-#ifdef SDCARD_DEBUG
+#ifdef SPISDCARD_DEBUG
     printf("Setting SDCard clk freq to ");
     if (clk_freq > 1000000)
         printf("%d MHz\n", (CONFIG_CLOCK_FREQUENCY/divider)/1000000);
@@ -197,7 +201,7 @@ uint8_t spisdcard_init(void) {
     uint16_t timeout;
 
     /* Set SPI clk freq to initialization frequency */
-    spi_set_clk_freq(SPI_CLK_FREQ_INIT);
+    spi_set_clk_freq(SPISDCARD_CLK_FREQ_INIT);
 
     /* Wait 10ms */
     busy_wait(10);
@@ -227,7 +231,7 @@ uint8_t spisdcard_init(void) {
         return 0;
 
     /* Set SPI clk freq to operational frequency */
-    spi_set_clk_freq(SPI_CLK_FREQ_OPERATIONAL);
+    spi_set_clk_freq(SPISDCARD_CLK_FREQ);
 
     return 1;
 }