Skip to content

Commit

Permalink
Merge pull request #109 from YuzukiHD/main
Browse files Browse the repository at this point in the history
[driver] add basic mmc_v2 sdhci driver
  • Loading branch information
SamulKyull authored Jun 15, 2024
2 parents 2cffab0 + c5aa332 commit 5ea453b
Show file tree
Hide file tree
Showing 31 changed files with 5,324 additions and 1,240 deletions.
37 changes: 36 additions & 1 deletion board/100ask-ros/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,41 @@ void clean_syterkit_data(void) {
printk_info("free interrupt ok...\n");
}

const uint32_t dram_para[32] = {
0x318,
0x8,
0x7070707,
0xd0d0d0d,
0xe0e,
0xd0a050c,
0x30fa,
0x8001000,
0x0,
0x34,
0x1b,
0x33,
0x3,
0x0,
0x0,
0x4,
0x72,
0x0,
0x7,
0x0,
0x0,
0x26,
0x6060606,
0x4040404,
0x0,
0x74000000,
0x48000000,
0x273333,
0x201c181f,
0x13151513,
0x7521,
0x2023211f,
};

#define RTC_DATA_COLD_START (7)
#define CPUS_CODE_LENGTH (0x1000)
#define CPUS_VECTOR_LENGTH (0x4000)
Expand All @@ -89,7 +124,7 @@ int ar100s_gpu_fix(void) {
uint32_t value;
uint32_t id = (readl(SUNXI_SYSCRL_BASE + 0x24)) & 0x07;
printk_debug("SUNXI_SYSCRL_BASE + 0x24 = 0x%08x, id = %d, RTC_DATA_COLD_START = %d\n",
readl(SUNXI_SYSCRL_BASE + 0x24), id, rtc_read_data(RTC_DATA_COLD_START));
readl(SUNXI_SYSCRL_BASE + 0x24), id, rtc_read_data(RTC_DATA_COLD_START));
if (((id == 0) || (id == 3) || (id == 4) || (id == 5))) {
if (rtc_read_data(RTC_DATA_COLD_START) == 0) {
rtc_write_data(RTC_DATA_COLD_START, 0x1);
Expand Down
6 changes: 3 additions & 3 deletions board/100ask-ros/init_dram/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#include <stdbool.h>
#include <stddef.h>
#include <types.h>
#include <stdint.h>
#include <types.h>

#include <log.h>

Expand All @@ -14,7 +14,7 @@
#include <sys-i2c.h>

extern sunxi_serial_t uart_dbg;

extern uint32_t dram_para[32];
extern sunxi_i2c_t i2c_pmu;

static void set_pmu_fin_voltage(char *power_name, uint32_t voltage) {
Expand Down Expand Up @@ -52,7 +52,7 @@ int main(void) {

pmu_axp2202_dump(&i2c_pmu);

printk_info("DRAM: DRAM Size = %dMB\n", sunxi_dram_init(NULL));
printk_info("DRAM: DRAM Size = %dMB\n", sunxi_dram_init(&dram_para));

sunxi_clk_dump();

Expand Down
2,412 changes: 1,267 additions & 1,145 deletions board/100ask-ros/payloads/init_dram_bin.c

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions board/100ask-ros/smhc_test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <sys-uart.h>

extern sunxi_serial_t uart_dbg;

extern uint32_t dram_para[32];
extern sunxi_i2c_t i2c_pmu;

static void set_pmu_fin_voltage(char *power_name, uint32_t voltage) {
Expand Down Expand Up @@ -56,7 +56,7 @@ int main(void) {

pmu_axp2202_dump(&i2c_pmu);

printk_info("DRAM: DRAM Size = %dMB\n", sunxi_dram_init(NULL));
printk_info("DRAM: DRAM Size = %dMB\n", sunxi_dram_init(&dram_para));

sunxi_clk_dump();

Expand Down
5 changes: 2 additions & 3 deletions board/100ask-ros/syter_boot/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@
#define CONFIG_HEAP_SIZE (16 * 1024 * 1024)

extern sunxi_serial_t uart_dbg;

extern sunxi_i2c_t i2c_pmu;

extern sdhci_t sdhci0;
extern uint32_t dram_para[32];

extern int ar100s_gpu_fix(void);

Expand Down Expand Up @@ -299,7 +298,7 @@ int main(void) {
pmu_axp2202_dump(&i2c_pmu);

/* Initialize the DRAM and enable memory management unit (MMU). */
uint64_t dram_size = sunxi_dram_init(NULL);
uint64_t dram_size = sunxi_dram_init(&dram_para);

arm32_mmu_enable(SDRAM_BASE, dram_size);

Expand Down
86 changes: 45 additions & 41 deletions board/avaota-a1/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@

#include <mmu.h>

#include <mmc/sys-sdhci.h>

#include <sys-dram.h>
#include <sys-gpio.h>
#include <sys-i2c.h>
#include <sys-sdcard.h>
#include <sys-sid.h>
#include <sys-spi.h>
#include <sys-uart.h>
Expand Down Expand Up @@ -50,52 +51,55 @@ sunxi_spi_t sunxi_spi0 = {
.gpio_hold = {GPIO_PIN(GPIO_PORTC, 5), GPIO_PERIPH_MUX4},
};

sdhci_t sdhci0 = {
sunxi_sdhci_t sdhci0 = {
.name = "sdhci0",
.id = 0,
.reg = (sdhci_reg_t *) SUNXI_SMHC0_BASE,
.voltage = MMC_VDD_27_36,
.width = MMC_BUS_WIDTH_4,
.clock = MMC_CLK_100M,
.sdio_type = SDHCI_TYPE_SD,
.removable = 0,
.isspi = FALSE,
.skew_auto_mode = TRUE,
.sdhci_pll = CCU_MMC_CTRL_PLL6X2,
.gpio_clk = {GPIO_PIN(GPIO_PORTF, 2), GPIO_PERIPH_MUX2},
.gpio_cmd = {GPIO_PIN(GPIO_PORTF, 3), GPIO_PERIPH_MUX2},
.gpio_d0 = {GPIO_PIN(GPIO_PORTF, 1), GPIO_PERIPH_MUX2},
.gpio_d1 = {GPIO_PIN(GPIO_PORTF, 0), GPIO_PERIPH_MUX2},
.gpio_d2 = {GPIO_PIN(GPIO_PORTF, 5), GPIO_PERIPH_MUX2},
.gpio_d3 = {GPIO_PIN(GPIO_PORTF, 4), GPIO_PERIPH_MUX2},
.id = MMC_CONTROLLER_0,
.reg_base = SUNXI_SMHC0_BASE,
.clk_ctrl_base = CCU_BASE + CCU_SMHC_BGR_REG,
.clk_base = CCU_BASE + CCU_SMHC0_CLK_REG,
.sdhci_mmc_type = MMC_TYPE_SD,
.max_clk = 200 * 1000 * 1000,
.width = SMHC_WIDTH_4BIT,
.dma_des_addr = SDRAM_BASE + 0x30080000,
.pinctrl = {
.gpio_clk = {GPIO_PIN(GPIO_PORTF, 2), GPIO_PERIPH_MUX2},
.gpio_cmd = {GPIO_PIN(GPIO_PORTF, 3), GPIO_PERIPH_MUX2},
.gpio_d0 = {GPIO_PIN(GPIO_PORTF, 1), GPIO_PERIPH_MUX2},
.gpio_d1 = {GPIO_PIN(GPIO_PORTF, 0), GPIO_PERIPH_MUX2},
.gpio_d2 = {GPIO_PIN(GPIO_PORTF, 5), GPIO_PERIPH_MUX2},
.gpio_d3 = {GPIO_PIN(GPIO_PORTF, 4), GPIO_PERIPH_MUX2},
.gpio_cd = {GPIO_PIN(GPIO_PORTF, 6), GPIO_INPUT},
.cd_level = GPIO_LEVEL_LOW,
},
};

sdhci_t sdhci2 = {
sunxi_sdhci_t sdhci2 = {
.name = "sdhci2",
.id = 2,
.reg = (sdhci_reg_t *) SUNXI_SMHC2_BASE,
.voltage = MMC_VDD_27_36,
.width = MMC_BUS_WIDTH_4,
.clock = MMC_CLK_25M,
.sdio_type = SDHCI_TYPE_MMC,
.removable = 0,
.isspi = FALSE,
.skew_auto_mode = TRUE,
.sdhci_pll = CCU_MMC_CTRL_PLL6X2,
.gpio_clk = {GPIO_PIN(GPIO_PORTC, 5), GPIO_PERIPH_MUX3},
.gpio_cmd = {GPIO_PIN(GPIO_PORTC, 6), GPIO_PERIPH_MUX3},
.gpio_d0 = {GPIO_PIN(GPIO_PORTC, 10), GPIO_PERIPH_MUX3},
.gpio_d1 = {GPIO_PIN(GPIO_PORTC, 13), GPIO_PERIPH_MUX3},
.gpio_d2 = {GPIO_PIN(GPIO_PORTC, 15), GPIO_PERIPH_MUX3},
.gpio_d3 = {GPIO_PIN(GPIO_PORTC, 8), GPIO_PERIPH_MUX3},
.gpio_d4 = {GPIO_PIN(GPIO_PORTC, 9), GPIO_PERIPH_MUX3},
.gpio_d5 = {GPIO_PIN(GPIO_PORTC, 11), GPIO_PERIPH_MUX3},
.gpio_d6 = {GPIO_PIN(GPIO_PORTC, 14), GPIO_PERIPH_MUX3},
.gpio_d7 = {GPIO_PIN(GPIO_PORTC, 16), GPIO_PERIPH_MUX3},
.gpio_ds = {GPIO_PIN(GPIO_PORTC, 0), GPIO_PERIPH_MUX3},
.gpio_rst = {GPIO_PIN(GPIO_PORTC, 1), GPIO_PERIPH_MUX3},
.id = MMC_CONTROLLER_2,
.reg_base = SUNXI_SMHC2_BASE,
.clk_ctrl_base = CCU_BASE + CCU_SMHC_BGR_REG,
.clk_base = CCU_BASE + CCU_SMHC2_CLK_REG,
.sdhci_mmc_type = MMC_TYPE_EMMC,
.max_clk = 25 * 1000 * 1000,
.width = SMHC_WIDTH_8BIT,
.dma_des_addr = SDRAM_BASE + 0x30080000,
.pinctrl = {
.gpio_clk = {GPIO_PIN(GPIO_PORTC, 5), GPIO_PERIPH_MUX3},
.gpio_cmd = {GPIO_PIN(GPIO_PORTC, 6), GPIO_PERIPH_MUX3},
.gpio_d0 = {GPIO_PIN(GPIO_PORTC, 10), GPIO_PERIPH_MUX3},
.gpio_d1 = {GPIO_PIN(GPIO_PORTC, 13), GPIO_PERIPH_MUX3},
.gpio_d2 = {GPIO_PIN(GPIO_PORTC, 15), GPIO_PERIPH_MUX3},
.gpio_d3 = {GPIO_PIN(GPIO_PORTC, 8), GPIO_PERIPH_MUX3},
.gpio_d4 = {GPIO_PIN(GPIO_PORTC, 9), GPIO_PERIPH_MUX3},
.gpio_d5 = {GPIO_PIN(GPIO_PORTC, 11), GPIO_PERIPH_MUX3},
.gpio_d6 = {GPIO_PIN(GPIO_PORTC, 14), GPIO_PERIPH_MUX3},
.gpio_d7 = {GPIO_PIN(GPIO_PORTC, 16), GPIO_PERIPH_MUX3},
.gpio_ds = {GPIO_PIN(GPIO_PORTC, 0), GPIO_PERIPH_MUX3},
.gpio_rst = {GPIO_PIN(GPIO_PORTC, 1), GPIO_PERIPH_MUX3},
},
};


sunxi_i2c_t i2c_pmu = {
.base = SUNXI_R_TWI0_BASE,
.id = SUNXI_R_I2C0,
Expand Down
19 changes: 5 additions & 14 deletions board/avaota-a1/extlinux_boot/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
#include <sstdlib.h>
#include <string.h>

#include <mmc/sys-sdcard.h>
#include <sys-clk.h>
#include <sys-dram.h>
#include <sys-i2c.h>
#include <sys-rtc.h>
#include <sys-sdcard.h>
#include <sys-sid.h>
#include <sys-spi.h>

Expand Down Expand Up @@ -62,8 +62,8 @@ extern sunxi_serial_t uart_dbg;

extern sunxi_i2c_t i2c_pmu;

extern sdhci_t sdhci0;
extern sdhci_t sdhci2;
extern sunxi_sdhci_t sdhci0;
extern sunxi_sdhci_t sdhci2;

extern uint32_t dram_para[32];

Expand Down Expand Up @@ -197,17 +197,7 @@ static int load_sdcard(image_info_t *image) {
FATFS fs;
FRESULT fret;
int ret;
uint32_t start;

uint32_t test_time;
start = time_ms();
sdmmc_blk_read(&card0, (uint8_t *) (SDRAM_BASE), 0, CONFIG_SDMMC_SPEED_TEST_SIZE);
test_time = time_ms() - start;
printk_debug("SDMMC: speedtest %uKB in %ums at %uKB/S\n",
(CONFIG_SDMMC_SPEED_TEST_SIZE * 512) / 1024, test_time,
(CONFIG_SDMMC_SPEED_TEST_SIZE * 512) / test_time);

start = time_ms();
uint32_t start = time_ms();

fret = f_mount(&fs, "", 1);
if (fret != FR_OK) {
Expand Down Expand Up @@ -832,6 +822,7 @@ int main(void) {
jmp_to_fel();

_fail:
printk_error("SyterKit Boot Failed\n");
LCD_ShowString(0, 0, "SyterKit Boot Failed", SPI_LCD_COLOR_RED, SPI_LCD_COLOR_BLACK, 12);
LCD_ShowString(0, 12, "Please Connect UART for Debug info", SPI_LCD_COLOR_RED, SPI_LCD_COLOR_BLACK, 12);
LCD_ShowString(0, 24, "Error Info:", SPI_LCD_COLOR_RED, SPI_LCD_COLOR_BLACK, 12);
Expand Down
2 changes: 1 addition & 1 deletion board/avaota-a1/load_e906/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ extern sunxi_serial_t uart_dbg;

extern sunxi_i2c_t i2c_pmu;

extern sdhci_t sdhci0;
extern sunxi_sdhci_t sdhci0;

extern uint32_t dram_para[32];

Expand Down
2 changes: 1 addition & 1 deletion board/avaota-a1/smhc2_test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extern sunxi_serial_t uart_dbg;

extern sunxi_i2c_t i2c_pmu;

extern sdhci_t sdhci2;
extern sunxi_sdhci_t sdhci2;

extern uint32_t dram_para[32];

Expand Down
5 changes: 4 additions & 1 deletion board/avaota-a1/smhc_test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

extern sunxi_serial_t uart_dbg;

extern sunxi_sdhci_t sdhci0;
extern sunxi_sdhci_t sdhci2;

extern sunxi_i2c_t i2c_pmu;

#define CONFIG_SDMMC_SPEED_TEST_SIZE 1024// (unit: 512B sectors)
Expand Down Expand Up @@ -61,7 +64,7 @@ int cmd_write(int argc, const char **argv) {
uint32_t test_time;

start = time_ms();
sdmmc_blk_write(&card0, (uint8_t *) (0x07380000), 0, 1024);
//sdmmc_blk_write(&card0, (uint8_t *) (0x07380000), 0, 1024);
test_time = time_ms() - start;
printk_debug("SDMMC: speedtest %uKB in %ums at %uKB/S\n",
(CONFIG_SDMMC_SPEED_TEST_SIZE * 512) / 1024, test_time,
Expand Down
2 changes: 1 addition & 1 deletion board/avaota-a1/syter_boot/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ extern sunxi_serial_t uart_dbg;

extern sunxi_i2c_t i2c_pmu;

extern sdhci_t sdhci0;
extern sunxi_sdhci_t sdhci0;

extern uint32_t dram_para[32];

Expand Down
2 changes: 1 addition & 1 deletion board/avaota-a1/syter_boot_uboot/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extern sunxi_serial_t uart_dbg;

extern sunxi_i2c_t i2c_pmu;

extern sdhci_t sdhci0;
extern sunxi_sdhci_t sdhci0;

extern uint32_t dram_para[32];

Expand Down
2 changes: 2 additions & 0 deletions cmake/board/avaota-a1.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ set(CONFIG_ARCH_ARM32_ARM64 True)
set(CONFIG_CHIP_SUN55IW3 True)
set(CONFIG_CHIP_WITHPMU True)
set(CONFIG_CHIP_DCACHE True)
set(CONFIG_CHIP_MMC_V2 True)
set(CONFIG_BOARD_AVAOTA-A1 True)

set(CONIFG_SPECIAL_LD_PATH "${CMAKE_SOURCE_DIR}/board/avaota-a1/")

add_definitions(-DCONFIG_CHIP_SUN55IW3)
add_definitions(-DCONFIG_CHIP_DCACHE)
add_definitions(-DCONFIG_CHIP_MMC_V2)
add_definitions(-DCONFIG_FATFS_CACHE_SIZE=0x2000000)
add_definitions(-DCONFIG_FATFS_CACHE_ADDR=0x60000000)

Expand Down
Loading

0 comments on commit 5ea453b

Please sign in to comment.