From 901f2bb5bd5174a3f1473058f78a9e2b4f920a9a Mon Sep 17 00:00:00 2001 From: Kostas Missos Date: Sat, 23 Jun 2018 06:37:58 +0300 Subject: [PATCH] Replace hardcoded values --- ipl/di.c | 12 ++++----- ipl/integer.h | 2 -- ipl/main.c | 4 +-- ipl/pinmux.c | 8 +++--- ipl/pinmux.h | 61 +++++++++++++++++++++++++++++++--------------- ipl/sd.h | 15 ++++++++++++ ipl/sdmmc.c | 11 +++++---- ipl/sdmmc_driver.c | 16 ++++++------ 8 files changed, 83 insertions(+), 46 deletions(-) diff --git a/ipl/di.c b/ipl/di.c index 662e97f..d63fa9c 100755 --- a/ipl/di.c +++ b/ipl/di.c @@ -59,11 +59,11 @@ void display_init() PMC(APBDEV_PMC_IO_DPD2_REQ) = 0x40000000; //Config pins. - PINMUX_AUX(PINMUX_AUX_NFC_EN) &= 0xFFFFFFEF; - PINMUX_AUX(PINMUX_AUX_NFC_INT) &= 0xFFFFFFEF; - PINMUX_AUX(PINMUX_AUX_LCD_BL_PWM) &= 0xFFFFFFEF; - PINMUX_AUX(PINMUX_AUX_LCD_BL_EN) &= 0xFFFFFFEF; - PINMUX_AUX(PINMUX_AUX_LCD_RST) &= 0xFFFFFFEF; + PINMUX_AUX(PINMUX_AUX_NFC_EN) &= ~PINMUX_TRISTATE; + PINMUX_AUX(PINMUX_AUX_NFC_INT) &= ~PINMUX_TRISTATE; + PINMUX_AUX(PINMUX_AUX_LCD_BL_PWM) &= ~PINMUX_TRISTATE; + PINMUX_AUX(PINMUX_AUX_LCD_BL_EN) &= ~PINMUX_TRISTATE; + PINMUX_AUX(PINMUX_AUX_LCD_RST) &= ~PINMUX_TRISTATE; gpio_config(GPIO_PORT_I, GPIO_PIN_0 | GPIO_PIN_1, GPIO_MODE_GPIO); //Backlight +-5V. gpio_output_enable(GPIO_PORT_I, GPIO_PIN_0 | GPIO_PIN_1, GPIO_OUTPUT_ENABLE); //Backlight +-5V. @@ -193,7 +193,7 @@ void display_end() gpio_config(GPIO_PORT_V, GPIO_PIN_0, GPIO_MODE_SPIO); //Backlight PWM. - PINMUX_AUX(PINMUX_AUX_LCD_BL_PWM) = (PINMUX_AUX(PINMUX_AUX_LCD_BL_PWM) & 0xFFFFFFEF) | 0x10; + PINMUX_AUX(PINMUX_AUX_LCD_BL_PWM) = (PINMUX_AUX(PINMUX_AUX_LCD_BL_PWM) & ~PINMUX_TRISTATE) | PINMUX_TRISTATE; PINMUX_AUX(PINMUX_AUX_LCD_BL_PWM) = (PINMUX_AUX(PINMUX_AUX_LCD_BL_PWM) >> 2) << 2 | 1; } diff --git a/ipl/integer.h b/ipl/integer.h index 4fcf5c4..b3c70ca 100755 --- a/ipl/integer.h +++ b/ipl/integer.h @@ -8,10 +8,8 @@ #ifdef _WIN32 /* FatFs development platform */ #include -#include typedef unsigned __int64 QWORD; - #else /* Embedded platform */ /* These types MUST be 16-bit or 32-bit */ diff --git a/ipl/main.c b/ipl/main.c index 6035a62..ab38d5f 100755 --- a/ipl/main.c +++ b/ipl/main.c @@ -186,8 +186,8 @@ void config_gpios() PINMUX_AUX(PINMUX_AUX_UART2_TX) = 0; PINMUX_AUX(PINMUX_AUX_UART3_TX) = 0; - PINMUX_AUX(PINMUX_AUX_GPIO_PE6) = 0x40; - PINMUX_AUX(PINMUX_AUX_GPIO_PH6) = 0x40; + PINMUX_AUX(PINMUX_AUX_GPIO_PE6) = PINMUX_INPUT_ENABLE; + PINMUX_AUX(PINMUX_AUX_GPIO_PH6) = PINMUX_INPUT_ENABLE; gpio_config(GPIO_PORT_G, GPIO_PIN_0, GPIO_MODE_GPIO); gpio_config(GPIO_PORT_D, GPIO_PIN_1, GPIO_MODE_GPIO); diff --git a/ipl/pinmux.c b/ipl/pinmux.c index d0c03d8..5dae384 100755 --- a/ipl/pinmux.c +++ b/ipl/pinmux.c @@ -20,13 +20,13 @@ void pinmux_config_uart(u32 idx) { PINMUX_AUX(PINMUX_AUX_UARTX_RX(idx)) = 0; - PINMUX_AUX(PINMUX_AUX_UARTX_TX(idx)) = 0x48; + PINMUX_AUX(PINMUX_AUX_UARTX_TX(idx)) = PINMUX_INPUT_ENABLE | PINMUX_PULL_UP; PINMUX_AUX(PINMUX_AUX_UARTX_RTS(idx)) = 0; - PINMUX_AUX(PINMUX_AUX_UARTX_CTS(idx)) = 0x44; + PINMUX_AUX(PINMUX_AUX_UARTX_CTS(idx)) = PINMUX_INPUT_ENABLE | PINMUX_PULL_DOWN; } void pinmux_config_i2c(u32 idx) { - PINMUX_AUX(PINMUX_AUX_X_I2C_SCL(idx)) = 0x40; - PINMUX_AUX(PINMUX_AUX_X_I2C_SDA(idx)) = 0x40; + PINMUX_AUX(PINMUX_AUX_X_I2C_SCL(idx)) = PINMUX_INPUT_ENABLE; + PINMUX_AUX(PINMUX_AUX_X_I2C_SDA(idx)) = PINMUX_INPUT_ENABLE; } diff --git a/ipl/pinmux.h b/ipl/pinmux.h index eae897c..82dda29 100755 --- a/ipl/pinmux.h +++ b/ipl/pinmux.h @@ -22,42 +22,65 @@ /*! APB MISC registers. */ #define APB_MISC_GP_SDMMC1_CLK_LPBK_CONTROL 0x8D4 #define APB_MISC_GP_SDMMC3_CLK_LPBK_CONTROL 0x8D8 -#define APB_MISC_GP_SDMMC1_PAD_CFGPADCTRL 0xA98 -#define APB_MISC_GP_VGPIO_GPIO_MUX_SEL 0xB74 +#define APB_MISC_GP_SDMMC1_PAD_CFGPADCTRL 0xA98 +#define APB_MISC_GP_VGPIO_GPIO_MUX_SEL 0xB74 /*! Pinmux registers. */ -#define PINMUX_AUX_SDMMC1_CLK 0x00 -#define PINMUX_AUX_SDMMC1_CMD 0x04 +#define PINMUX_AUX_SDMMC1_CLK 0x00 +#define PINMUX_AUX_SDMMC1_CMD 0x04 #define PINMUX_AUX_SDMMC1_DAT3 0x08 #define PINMUX_AUX_SDMMC1_DAT2 0x0C #define PINMUX_AUX_SDMMC1_DAT1 0x10 #define PINMUX_AUX_SDMMC1_DAT0 0x14 -#define PINMUX_AUX_SDMMC3_CLK 0x1C -#define PINMUX_AUX_SDMMC3_CMD 0x20 +#define PINMUX_AUX_SDMMC3_CLK 0x1C +#define PINMUX_AUX_SDMMC3_CMD 0x20 #define PINMUX_AUX_SDMMC3_DAT0 0x24 #define PINMUX_AUX_SDMMC3_DAT1 0x28 #define PINMUX_AUX_SDMMC3_DAT2 0x2C #define PINMUX_AUX_SDMMC3_DAT3 0x30 -#define PINMUX_AUX_DMIC3_CLK 0xB4 -#define PINMUX_AUX_UART2_TX 0xF4 -#define PINMUX_AUX_UART3_TX 0x104 -#define PINMUX_AUX_NFC_EN 0x1D0 -#define PINMUX_AUX_NFC_INT 0x1D4 -#define PINMUX_AUX_LCD_BL_PWM 0x1FC -#define PINMUX_AUX_LCD_BL_EN 0x200 -#define PINMUX_AUX_LCD_RST 0x204 -#define PINMUX_AUX_GPIO_PE6 0x248 -#define PINMUX_AUX_GPIO_PH6 0x250 -#define PINMUX_AUX_GPIO_PZ1 0x280 +#define PINMUX_AUX_DMIC3_CLK 0xB4 +#define PINMUX_AUX_UART2_TX 0xF4 +#define PINMUX_AUX_UART3_TX 0x104 +#define PINMUX_AUX_NFC_EN 0x1D0 +#define PINMUX_AUX_NFC_INT 0x1D4 +#define PINMUX_AUX_LCD_BL_PWM 0x1FC +#define PINMUX_AUX_LCD_BL_EN 0x200 +#define PINMUX_AUX_LCD_RST 0x204 +#define PINMUX_AUX_GPIO_PE6 0x248 +#define PINMUX_AUX_GPIO_PH6 0x250 +#define PINMUX_AUX_GPIO_PZ1 0x280 /*! 0:UART-A, 1:UART-B, 3:UART-C, 3:UART-D */ -#define PINMUX_AUX_UARTX_TX(x) (0xE4 + 0x10 * (x)) -#define PINMUX_AUX_UARTX_RX(x) (0xE8 + 0x10 * (x)) +#define PINMUX_AUX_UARTX_TX(x) (0xE4 + 0x10 * (x)) +#define PINMUX_AUX_UARTX_RX(x) (0xE8 + 0x10 * (x)) #define PINMUX_AUX_UARTX_RTS(x) (0xEC + 0x10 * (x)) #define PINMUX_AUX_UARTX_CTS(x) (0xF0 + 0x10 * (x)) /*! 0:GEN1, 1:GEN2, 2:GEN3, 3:CAM, 4:PWR */ #define PINMUX_AUX_X_I2C_SCL(x) (0xBC + 8 * (x)) #define PINMUX_AUX_X_I2C_SDA(x) (0xC0 + 8 * (x)) +#define PINMUX_FUNC_MASK (3 << 0) + +#define PINMUX_PULL_MASK (3 << 2) +#define PINMUX_PULL_NONE (0 << 2) +#define PINMUX_PULL_DOWN (1 << 2) +#define PINMUX_PULL_UP (2 << 2) + +#define PINMUX_TRISTATE (1 << 4) +#define PINMUX_PARKED (1 << 5) +#define PINMUX_INPUT_ENABLE (1 << 6) +#define PINMUX_LOCK (1 << 7) +#define PINMUX_LPDR (1 << 8) +#define PINMUX_HSM (1 << 9) + +#define PINMUX_IO_HV (1 << 10) +#define PINMUX_OPEN_DRAIN (1 << 11) +#define PINMUX_SCHMT (1 << 12) + +#define PINMUX_DRIVE_1X (0 << 13) +#define PINMUX_DRIVE_2X (1 << 13) +#define PINMUX_DRIVE_3X (2 << 13) +#define PINMUX_DRIVE_4X (3 << 13) + void pinmux_config_uart(u32 idx); void pinmux_config_i2c(u32 idx); diff --git a/ipl/sd.h b/ipl/sd.h index 8fc328b..fd15eea 100755 --- a/ipl/sd.h +++ b/ipl/sd.h @@ -89,6 +89,21 @@ #define UHS_DDR50_BUS_SPEED 4 #define HS400_BUS_SPEED 5 +#define SD_MODE_HIGH_SPEED (1 << HIGH_SPEED_BUS_SPEED) +#define SD_MODE_UHS_SDR12 (1 << UHS_SDR12_BUS_SPEED) +#define SD_MODE_UHS_SDR25 (1 << UHS_SDR25_BUS_SPEED) +#define SD_MODE_UHS_SDR50 (1 << UHS_SDR50_BUS_SPEED) +#define SD_MODE_UHS_SDR104 (1 << UHS_SDR104_BUS_SPEED) +#define SD_MODE_UHS_DDR50 (1 << UHS_DDR50_BUS_SPEED) + +#define SD_DRIVER_TYPE_B 0x01 +#define SD_DRIVER_TYPE_A 0x02 + +#define SD_SET_CURRENT_LIMIT_200 0 +#define SD_SET_CURRENT_LIMIT_400 1 +#define SD_SET_CURRENT_LIMIT_600 2 +#define SD_SET_CURRENT_LIMIT_800 3 + /* * SD_SWITCH mode */ diff --git a/ipl/sdmmc.c b/ipl/sdmmc.c index 30ec1fb..bd21237 100755 --- a/ipl/sdmmc.c +++ b/ipl/sdmmc.c @@ -761,7 +761,7 @@ int _sd_storage_switch(sdmmc_storage_t *storage, void *buf, int flag, u32 arg) int _sd_storage_enable_highspeed(sdmmc_storage_t *storage, u32 hs_type, u8 *buf) { - if (!_sd_storage_switch(storage, buf, 0, hs_type)) + if (!_sd_storage_switch(storage, buf, SD_SWITCH_CHECK, 0, hs_type)) return 0; u32 type_out = buf[16] & 0xF; @@ -770,7 +770,7 @@ int _sd_storage_enable_highspeed(sdmmc_storage_t *storage, u32 hs_type, u8 *buf) if ((((u16)buf[0] << 8) | buf[1]) < 0x320) { - if (!_sd_storage_switch(storage, buf, 1, hs_type)) + if (!_sd_storage_switch(storage, buf, SD_SWITCH_SET, 0, hs_type)) return 0; if (type_out != (buf[16] & 0xF)) @@ -787,12 +787,13 @@ int _sd_storage_enable_highspeed_low_volt(sdmmc_storage_t *storage, u32 type, u8 if (!_sd_storage_switch_get(storage, buf)) return 0; + //gfx_hexdump(&gfx_con, 0, (u8 *)buf, 64); u32 hs_type = 0; switch (type) { case 11: - if (buf[13] & 8) + if (buf[13] & SD_MODE_UHS_SDR104) { type = 11; hs_type = UHS_SDR104_BUS_SPEED; @@ -800,7 +801,7 @@ int _sd_storage_enable_highspeed_low_volt(sdmmc_storage_t *storage, u32 type, u8 } //Fall through. case 10: - if (!(buf[13] & 4)) + if (!(buf[13] & SD_MODE_UHS_SDR50)) return 0; type = 10; hs_type = UHS_SDR50_BUS_SPEED; @@ -823,7 +824,7 @@ int _sd_storage_enable_highspeed_high_volt(sdmmc_storage_t *storage, u8 *buf) { if (!_sd_storage_switch_get(storage, buf)) return 0; - + //gfx_hexdump(&gfx_con, 0, (u8 *)buf, 64); if (!(buf[13] & 2)) return 1; diff --git a/ipl/sdmmc_driver.c b/ipl/sdmmc_driver.c index 4d08473..77a9db1 100755 --- a/ipl/sdmmc_driver.c +++ b/ipl/sdmmc_driver.c @@ -908,7 +908,7 @@ static int _sdmmc_execute_cmd_inner(sdmmc_t *sdmmc, sdmmc_cmd_t *cmd, sdmmc_req_ static int _sdmmc_config_sdmmc1() { //Configure SD card detect. - PINMUX_AUX(PINMUX_AUX_GPIO_PZ1) = 0x49; //GPIO control, pull up. + PINMUX_AUX(PINMUX_AUX_GPIO_PZ1) = PINMUX_INPUT_ENABLE | PINMUX_PULL_UP | 1; //GPIO control, pull up. APB_MISC(APB_MISC_GP_VGPIO_GPIO_MUX_SEL) = 0; gpio_config(GPIO_PORT_Z, GPIO_PIN_1, GPIO_MODE_GPIO); gpio_output_enable(GPIO_PORT_Z, GPIO_PIN_1, GPIO_OUTPUT_DISABLE); @@ -927,12 +927,12 @@ static int _sdmmc_config_sdmmc1() //Configure SDMMC1 pinmux. APB_MISC(APB_MISC_GP_SDMMC1_CLK_LPBK_CONTROL) = 1; - PINMUX_AUX(PINMUX_AUX_SDMMC1_CLK) = 0x2060; - PINMUX_AUX(PINMUX_AUX_SDMMC1_CMD) = 0x2068; - PINMUX_AUX(PINMUX_AUX_SDMMC1_DAT3) = 0x2068; - PINMUX_AUX(PINMUX_AUX_SDMMC1_DAT2) = 0x2068; - PINMUX_AUX(PINMUX_AUX_SDMMC1_DAT1) = 0x2068; - PINMUX_AUX(PINMUX_AUX_SDMMC1_DAT0) = 0x2068; + PINMUX_AUX(PINMUX_AUX_SDMMC1_CLK) = PINMUX_DRIVE_2X | PINMUX_INPUT_ENABLE | PINMUX_PARKED; + PINMUX_AUX(PINMUX_AUX_SDMMC1_CMD) = PINMUX_DRIVE_2X | PINMUX_INPUT_ENABLE | PINMUX_PARKED | PINMUX_PULL_UP; + PINMUX_AUX(PINMUX_AUX_SDMMC1_DAT3) = PINMUX_DRIVE_2X | PINMUX_INPUT_ENABLE | PINMUX_PARKED | PINMUX_PULL_UP; + PINMUX_AUX(PINMUX_AUX_SDMMC1_DAT2) = PINMUX_DRIVE_2X | PINMUX_INPUT_ENABLE | PINMUX_PARKED | PINMUX_PULL_UP; + PINMUX_AUX(PINMUX_AUX_SDMMC1_DAT1) = PINMUX_DRIVE_2X | PINMUX_INPUT_ENABLE | PINMUX_PARKED | PINMUX_PULL_UP; + PINMUX_AUX(PINMUX_AUX_SDMMC1_DAT0) = PINMUX_DRIVE_2X | PINMUX_INPUT_ENABLE | PINMUX_PARKED | PINMUX_PULL_UP; //Make sure the SDMMC1 controller is powered. PMC(APBDEV_PMC_NO_IOPOWER) &= ~(1 << 12); @@ -940,7 +940,7 @@ static int _sdmmc_config_sdmmc1() PMC(APBDEV_PMC_PWR_DET_VAL) |= (1 << 12); //Set enable SD card power. - PINMUX_AUX(PINMUX_AUX_DMIC3_CLK) = 0x45; //GPIO control, pull down. + PINMUX_AUX(PINMUX_AUX_DMIC3_CLK) = PINMUX_INPUT_ENABLE | PINMUX_PULL_DOWN | 1; //GPIO control, pull down. gpio_config(GPIO_PORT_E, GPIO_PIN_4, GPIO_MODE_GPIO); gpio_write(GPIO_PORT_E, GPIO_PIN_4, GPIO_HIGH); gpio_output_enable(GPIO_PORT_E, GPIO_PIN_4, GPIO_OUTPUT_ENABLE);