#include #include #include #include DECLARE_GLOBAL_DATA_PTR; #define rSYS_AHB_CLK_EN *((volatile unsigned int *)(0x40408044)) #define rSYS_SD_CLK_CFG *((volatile unsigned int *)(0x40408058)) #define rSYS_SD1_CLK_CFG *((volatile unsigned int *)(0x4040805c)) #define rSYS_SOFT_RSTNA *((volatile unsigned int *)(0x40408074)) #define rSYS_PAD_CTRL03 *((volatile unsigned int *)(0x404081cc)) #define rSYS_PAD_CTRL08 *((volatile unsigned int *)(0x404081e0)) #define rSYS_PAD_CTRL09 *((volatile unsigned int *)(0x404081e4)) #define ARK1668_UPDATE_MAGIC "ada7f0c6-7c86-11e9-8f9e-2a86e4085a59" static void dwmci_select_pad(void) { /* use sd/mmc 0 */ rSYS_PAD_CTRL09 |= 0x7F; rSYS_SD_CLK_CFG = 0x00000420; /* use sd/mmc 1 pad sd1_0 */ rSYS_PAD_CTRL09 |= (0x7F << 7); rSYS_SD1_CLK_CFG = 0x00000420; } static void dwmci_reset(void) { rSYS_AHB_CLK_EN &= ~((1 << 4) | (1 << 3)); rSYS_SOFT_RSTNA &= ~((1 << 31) | (1 << 12)); udelay(100); rSYS_SOFT_RSTNA |= ((1 << 31) | (1 << 12)); rSYS_AHB_CLK_EN |= ((1 << 4) | (1 << 3)); } #define ARK_MMC_CLK 24000000 int ark_dwmci_init(char *name,u32 regbase, int bus_width, int index) { struct dwmci_host *host = NULL; host = malloc(sizeof(struct dwmci_host)); if (!host) { printf("dwmci_host malloc fail!\n"); return 1; } memset(host, 0, sizeof(struct dwmci_host)); dwmci_select_pad(); dwmci_reset(); host->name = name; host->ioaddr = (void *)regbase; host->buswidth = bus_width; host->dev_index = index; host->bus_hz = ARK_MMC_CLK; host->fifo_mode = 1; add_dwmci(host, host->bus_hz, 400000); return 0; } int board_mmc_init(bd_t *bis) { ark_dwmci_init("ARK_MMC0", 0x60000000, 4, 0); ark_dwmci_init("ARK_MMC1", 0x68000000, 4, 0); return 0; } int dram_init(void) { gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE, CONFIG_SYS_SDRAM_SIZE); return 0; } int board_init(void) { unsigned int tmp; #if 0 /* SPI pad enable */ tmp = rSYS_PAD_CTRL08; tmp &= ~(0xFF << 16); tmp |= (0xA8 << 16); rSYS_PAD_CTRL08 = tmp; /* power GPIO31 high for sdio wifi module in shangqi carcorder project */ rSYS_PAD_CTRL03 &= ~(0x7 << 3); gpio_direction_output(31, 1); #else /* nand pad enable */ tmp = rSYS_PAD_CTRL08; tmp &= ~0x0FFFFFFF; tmp |= 0x05555555; rSYS_PAD_CTRL08 = tmp; #endif #if 1 /*power GPIO30 PWR_OFF trigger High edge */ gpio_direction_output(30,1); #endif return 0; } int board_late_init(void) { char cmd[128]; char *need_update; unsigned int loadaddr; int do_update = 0; need_update = env_get("need_update"); printf("++++101+++++++%s++++++\n",need_update); printf("++++102+++++++%s++++++\n",env_get("update_dev_part")); if (!strcmp(need_update, "yes")) { loadaddr = env_get_hex("loadaddr", 0); sprintf(cmd, "fatload %s %s %s update-magic", "mmc", env_get("update_dev_part"), env_get("loadaddr")); run_command(cmd, 0); if (loadaddr && !memcmp((void *)loadaddr, ARK1668_UPDATE_MAGIC, strlen(ARK1668_UPDATE_MAGIC))) { do_update = 1; } else { printf("Wrong update magic, do not update from mmc.\n"); } } if (do_update){ run_command("nand erase.part userdata", 0); env_set("need_update", "no"); env_set("do_update", "yes"); } else{ env_set("do_update", "no"); } return 0; }