Browse Source

update for sdio function

yanhong.wang 3 years ago
parent
commit
123700f03f
5 changed files with 77 additions and 24 deletions
  1. 3 3
      boot/bootmain.c
  2. 1 1
      build/Makefile
  3. 28 0
      build/fsz.sh
  4. 8 18
      sdio/dw_mmc.c
  5. 37 2
      sdio/sdio.c

+ 3 - 3
boot/bootmain.c

@@ -27,6 +27,7 @@
 #include "clkgen_ctrl_macro.h"
 #include "syscon_sysmain_ctrl_macro.h"
 
+#define BOOTLOADER_VERSION	"2020.9.16"
 
 extern void boot_sdio_init(void);
 extern int boot_load_gpt_partition(void* dst, const gpt_guid* partition_type_guid);
@@ -461,7 +462,7 @@ void BootMain(void)
 {	
 	int boot_mode = 0;
 	int ret=0;
-	
+
 	timer_init(0);
 	gpio_init();
 	uart_init(3);
@@ -470,7 +471,7 @@ void BootMain(void)
 	if(ret == 0)
 	{
 		_SET_SYSCON_REG_register68_SCFG_disable_u74_memaxi_remap(1);
-		printk("DDR clk 2133M,Version 20.8.21.0\r\n");
+		printk("DDR clk 2133M,Version %s\r\n",BOOTLOADER_VERSION);
 	}
 	else
 		printk("End init lpddr4, test ddr fail\r\n");
@@ -478,7 +479,6 @@ void BootMain(void)
 	boot_from_chiplink();
 	
 	boot_mode = get_boot_mode();
-//	boot_mode = 1;
 	switch(boot_mode){
 	 	case 0:
 		 	boot_from_spi(1);

+ 1 - 1
build/Makefile

@@ -87,9 +87,9 @@ $(TARGET).elf:$(OBJECTLIST)
 	$(CC) -o $(TARGET).elf  $(LDFLAGS) $(OBJECTLIST)
 	@echo $(TARGET).elf LINK SUCCEED!	
 
-
 %.bin: %.elf
 	$(OBJCOPY) -O binary $^ $@
+	@if [ -f fsz.sh ]; then ./fsz.sh $(TARGET).bin; fi
 
 %.asm: %.elf
 	$(OBJDUMP) -S $^ > $@

+ 28 - 0
build/fsz.sh

@@ -0,0 +1,28 @@
+#!/bin/bash
+
+function handle_file {
+	inFile=$1
+	echo inFile: $inFile
+	outFile=$inFile.out
+
+	inSize=`stat -c "%s" $inFile`
+	inSize32HexBe=`printf "%08x\n" $inSize`
+	inSize32HexLe=${inSize32HexBe:6:2}${inSize32HexBe:4:2}${inSize32HexBe:2:2}${inSize32HexBe:0:2}
+	echo "inSize: $inSize (0x$inSize32HexBe, LE:0x$inSize32HexLe)"
+
+	echo $inSize32HexLe | xxd -r -ps > $outFile
+	cat $inFile >> $outFile
+	echo outFile: $outFile
+
+	outSize=`stat -c "%s" $outFile`
+	outSize32HexBe=`printf "%08x\n" $outSize`
+	echo "outSize: $outSize (0x$outSize32HexBe)"
+}
+
+if [ "$1" = "" -o "$1" = "--help" ]; then
+	echo "Add file size(32bits, Little Endian) before the content."
+	echo "Usage: ./fsz.sh <file>"
+	exit 1
+fi
+
+handle_file "$@"

+ 8 - 18
sdio/dw_mmc.c

@@ -85,8 +85,8 @@ static void dwmci_prepare_data(struct dwmci_host *host,
 	dwmci_writel(host, DWMCI_CTRL, ctrl);
 
 	ctrl = dwmci_readl(host, DWMCI_BMOD);
-	//ctrl |= DWMCI_BMOD_IDMAC_FB | DWMCI_BMOD_IDMAC_EN;
-	ctrl |= DWMCI_BMOD_IDMAC_EN;
+	ctrl |= DWMCI_BMOD_IDMAC_FB | DWMCI_BMOD_IDMAC_EN;
+	//ctrl |= DWMCI_BMOD_IDMAC_EN;
 	dwmci_writel(host, DWMCI_BMOD, ctrl);
 
 	dwmci_writel(host, DWMCI_BLKSIZ, data->blocksize);
@@ -99,8 +99,7 @@ static int dwmci_data_transfer(struct dwmci_host *host, struct mmc_data *data)
 	u32 timeout = 40000000;
 	u32 mask=0, size, i, len = 0;
 	u32 *buf = NULL;
-	//unsigned int start = get_timer(0);
-	unsigned int start = 0;
+	unsigned int start = get_timer(0);
 	u32 fifo_depth = (((host->fifoth_val & RX_WMARK_MASK) >>
 			    RX_WMARK_SHIFT) + 1) * 2;
 
@@ -154,11 +153,8 @@ static int dwmci_data_transfer(struct dwmci_host *host, struct mmc_data *data)
 			ret = 0;
 			break;
 		}
-		start++;
-        udelay(100);
 		/* Check for timeout. */
-		//if (get_timer(start) > timeout) {
-			if(start > timeout){
+		if (get_timer(start) > timeout) {
 			printk("%s: Timeout waiting for data!\n",__func__);
 			ret = TIMEOUT;
 			break;
@@ -196,15 +192,12 @@ static int dwmci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
 	unsigned int timeout = 100000;
 	u32 retry = 10000;
 	u32 mask, ctrl;
-	//unsigned int start = get_timer(0);
-	unsigned int start = 0;
+	unsigned int start = get_timer(0);
 	struct bounce_buffer bbstate;
 
 	while ((dwmci_readl(host, DWMCI_STATUS) & DWMCI_BUSY)) {
 			start++;
-            udelay(10);
-		//if (get_timer(start) > timeout) {
-			if(start > timeout){
+		if (get_timer(start) > timeout) {
 
 			printk("%s: Timeout on data busy\r\n", __func__);
 			return TIMEOUT;
@@ -258,7 +251,7 @@ static int dwmci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
 
 	flags |= (cmd->cmdidx | DWMCI_CMD_START | DWMCI_CMD_USE_HOLD_REG);
 
-	printk("Sending CMD%d\r\n",cmd->cmdidx);
+//	printk("Sending CMD%d\r\n",cmd->cmdidx);
 
 	dwmci_writel(host, DWMCI_CMD, flags);
 
@@ -316,8 +309,6 @@ static int dwmci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
 		}
 	}
 
-	udelay(100);
-	//delay(100000);//libo
 	return ret;
 }
 
@@ -361,6 +352,7 @@ static int dwmci_setup_bus(struct dwmci_host *host, u32 freq)
 			//printf("%s: Timeout!\n", __func__);
 			return -1;
 		}
+		udelay(10);
 	} while (status & DWMCI_CMD_START);
 
 	dwmci_writel(host, DWMCI_CLKENA, DWMCI_CLKEN_ENABLE |
@@ -388,8 +380,6 @@ static void dwmci_set_ios(struct mmc *mmc)
 	struct dwmci_host *host = (struct dwmci_host *)mmc->priv;
 	u32 ctype, regs;
 
-	//printf("Buswidth = %d, clock: %d\r\n", mmc->bus_width, mmc->clock);
-
 	dwmci_setup_bus(host, mmc->clock);
 	switch (mmc->bus_width) {
 	case 8:

+ 37 - 2
sdio/sdio.c

@@ -7,6 +7,7 @@
 struct dwmci_host local_host0;
 struct mmc local_mmc0;
 
+#define DWMMC_BUS_FREQ		100000000
 #define DWMMC_MAX_FREQ		10000000
 #define DWMMC_MIN_FREQ		400000
 
@@ -15,6 +16,7 @@ struct mmc local_mmc0;
 
 static void sdio0_gpio_mux_select()
 {
+#if 0//for fpga 
     SET_GPIO_18_dout_sdio0_pad_cclk_out;
     //SET_GPIO_18_doen_sdio0_pad_cclk_out;
     SET_GPIO_18_doen_LOW;
@@ -47,6 +49,39 @@ static void sdio0_gpio_mux_select()
     SET_GPIO_16_doen_sdio0_pad_cdata_oe_bit3;
     SET_GPIO_16_dout_sdio0_pad_cdata_out_bit3;
     SET_GPIO_sdio0_pad_cdata_in_bit3(16);
+#endif
+	SET_GPIO_sdio0_pad_card_detect_n(26);
+	SET_GPIO_26_doen_HIGH;
+
+	SET_GPIO_33_dout_sdio0_pad_cclk_out;
+	SET_GPIO_33_doen_LOW;
+
+	SET_GPIO_34_doen_reverse_(1);
+	SET_GPIO_34_doen_sdio0_pad_ccmd_oe;
+	SET_GPIO_34_dout_sdio0_pad_ccmd_out;
+	SET_GPIO_sdio0_pad_ccmd_in(34);	
+
+	SET_GPIO_32_doen_reverse_(1);
+	SET_GPIO_31_doen_reverse_(1);
+	SET_GPIO_30_doen_reverse_(1);
+	SET_GPIO_36_doen_reverse_(1);
+
+	SET_GPIO_32_doen_sdio0_pad_cdata_oe_bit0;
+	SET_GPIO_32_dout_sdio0_pad_cdata_out_bit0;
+	SET_GPIO_sdio0_pad_cdata_in_bit0(32);
+
+	SET_GPIO_31_doen_sdio0_pad_cdata_oe_bit1;
+	SET_GPIO_31_dout_sdio0_pad_cdata_out_bit1;
+	SET_GPIO_sdio0_pad_cdata_in_bit1(31);
+
+	SET_GPIO_30_doen_sdio0_pad_cdata_oe_bit2;
+	SET_GPIO_30_dout_sdio0_pad_cdata_out_bit2;
+	SET_GPIO_sdio0_pad_cdata_in_bit2(30);
+
+	SET_GPIO_36_doen_sdio0_pad_cdata_oe_bit3;
+	SET_GPIO_36_dout_sdio0_pad_cdata_out_bit3;
+	SET_GPIO_sdio0_pad_cdata_in_bit3(36);
+
 }
 
 static struct mmc *init_mmc_device(int dev, unsigned int  force_init)
@@ -82,10 +117,10 @@ int boot_sdio_init(void)
 	RX_WMARK(fifo_depth / 2 - 1) | TX_WMARK(fifo_depth / 2);
 
 	host->buswidth = 4;
-	host->bus_hz = DWMMC_MAX_FREQ;
+	host->bus_hz = DWMMC_BUS_FREQ;
 	
 	/* Add the mmc channel to be registered with mmc core */
-	if (add_dwmci(host, host->bus_hz, DWMMC_MIN_FREQ, 0)) {
+	if (add_dwmci(host, DWMMC_MAX_FREQ, DWMMC_MIN_FREQ, 0)) {
 		printk("DWMMC0 registration failed\n");
 		return -1;
 	}