diff --git a/litex/soc/software/bios/cmds/cmd_litesdcard.c b/litex/soc/software/bios/cmds/cmd_litesdcard.c index c95e71347..c9d0c9033 100644 --- a/litex/soc/software/bios/cmds/cmd_litesdcard.c +++ b/litex/soc/software/bios/cmds/cmd_litesdcard.c @@ -20,6 +20,34 @@ define_command(sdinit, sdcard_init, "Initialize SDCard", LITESDCARD_CMDS); #endif +/** + * Command "sdfreq" + * + * Set SDcard clock frequency + * + */ +#ifdef CSR_SDCORE_BASE +static void sdfreq(int nb_params, char **params) +{ + unsigned int freq; + char *c; + + if (nb_params < 1) { + printf("sdfreq "); + return; + } + + freq = strtoul(params[0], &c, 0); + if (*c != 0) { + printf("Incorrect freq"); + return; + } + + sdcard_set_clk_freq(freq); +} + +define_command(sdfreq, sdfreq, "Set SDCard clock freq", LITESDCARD_CMDS); +#endif /** * Command "sdread" diff --git a/litex/soc/software/liblitesdcard/sdcard.c b/litex/soc/software/liblitesdcard/sdcard.c index cf78ed9b0..e23fee862 100644 --- a/litex/soc/software/liblitesdcard/sdcard.c +++ b/litex/soc/software/liblitesdcard/sdcard.c @@ -96,7 +96,7 @@ static uint32_t log2(uint32_t x) return r; } -static void sdcard_set_clk_freq(uint32_t clk_freq) { +void sdcard_set_clk_freq(uint32_t clk_freq) { uint32_t divider; divider = CONFIG_CLOCK_FREQUENCY/clk_freq + 1; divider = (1 << log2(divider)); diff --git a/litex/soc/software/liblitesdcard/sdcard.h b/litex/soc/software/liblitesdcard/sdcard.h index bcc2f7ccf..eb29118dc 100644 --- a/litex/soc/software/liblitesdcard/sdcard.h +++ b/litex/soc/software/liblitesdcard/sdcard.h @@ -60,6 +60,12 @@ int sdcard_wait_cmd_done(void); int sdcard_wait_data_done(void); int sdcard_wait_response(void); +/*-----------------------------------------------------------------------*/ +/* SDCard clocker functions */ +/*-----------------------------------------------------------------------*/ + +void sdcard_set_clk_freq(uint32_t clk_freq); + /*-----------------------------------------------------------------------*/ /* SDCard commands functions */ /*-----------------------------------------------------------------------*/