karo: tx6: Finalize support for TX6Q-1020
authorLothar Waßmann <LW@KARO-electronics.de>
Fri, 25 Apr 2014 11:48:29 +0000 (13:48 +0200)
committerLothar Waßmann <LW@KARO-electronics.de>
Fri, 25 Apr 2014 11:48:29 +0000 (13:48 +0200)
- don't setup NAND related pads when CONFIG_NAND_MXS is not defined
- initialize USDHC4 interface (internal eMMC) as mmc0
- enable all LDOs
- calculate DTB partition size and number of blocks in config.mk
- enable 'fat write' command
- disable GPT and EFI partitions
- setup 'fdtsave' command to write the dtb inside the boot partition
- interpret 'splashimage' env variable as DOS filename rather than
  partition name

board/karo/common/Makefile
board/karo/common/karo.h
board/karo/common/mmc.c
board/karo/tx6/config.mk
board/karo/tx6/lowlevel_init.S
board/karo/tx6/tx6-1020.c
include/configs/tx6.h

index f951e49..64fe06c 100644 (file)
@@ -27,7 +27,7 @@ ifeq ($(CONFIG_SPL_BUILD),)
        COBJS-$(CONFIG_SPLASH_SCREEN)   += splashimage.o
 endif
 COBJS-$(CONFIG_CMD_NAND)               += nand.o
-COBJS-$(CONFIG_CMD_MMC)                        += mmc.o
+COBJS-$(CONFIG_ENV_IS_IN_MMC)          += mmc.o
 
 COBJS   := $(COBJS-y)
 SOBJS  := 
index f2a9f92..4aee302 100644 (file)
@@ -133,7 +133,7 @@ static inline int karo_load_nand_part(const char *part, void *addr, size_t len)
 }
 #endif
 
-#ifdef CONFIG_CMD_MMC
+#ifdef CONFIG_ENV_IS_IN_MMC
 int karo_load_mmc_part(const char *part, void *addr, size_t len);
 #else
 static inline int karo_load_mmc_part(const char *part, void *addr, size_t len)
index eb88043..f88e1cf 100644 (file)
 #include <fdt_support.h>
 #include <mmc.h>
 #include <mxcfb.h>
+#include <fs.h>
+#include <fat.h>
+#include <malloc.h>
 #include <linux/list.h>
 #include <linux/fb.h>
 #include <jffs2/load_kernel.h>
-#include <malloc.h>
 
 #include "karo.h"
 
-#define CONFIG_MMC_BOOT_DEV 0
-
 DECLARE_GLOBAL_DATA_PTR;
 
 #define MAX_SEARCH_PARTITIONS 16
 
-static int find_efi_partition(const char *ifname, int devno, const char *part_str,
-                            block_dev_desc_t **dev_desc,
-                            disk_partition_t *info)
+static int find_partitions(const char *ifname, int devno, int fstype,
+                       block_dev_desc_t **dev_desc, disk_partition_t *info)
 {
        int ret = -1;
        char *dup_str = NULL;
@@ -56,8 +55,8 @@ static int find_efi_partition(const char *ifname, int devno, const char *part_st
         * or user requested partition 0 (entire device).
         */
        if (dd->part_type == PART_TYPE_UNKNOWN) {
-               printf("** No partition table - %s %d **\n", ifname,
-                       devno);
+               printf("** No partition table on device %s %d **\n",
+                       ifname, devno);
                goto cleanup;
        }
 
@@ -67,14 +66,15 @@ static int find_efi_partition(const char *ifname, int devno, const char *part_st
                if (ret)
                        continue;
 
-               if (strcmp((char *)info->name, part_str) == 0) {
+               if (fat_register_device(dd, p) == 0) {
                        part = p;
                        dd->log2blksz = LOG2(dd->blksz);
                        break;
                }
        }
        if (!part) {
-               printf("** No valid partitions found **\n");
+               printf("** No valid partition on device %s %d **\n",
+                       ifname, devno);
                ret = -1;
                goto cleanup;
        }
@@ -87,14 +87,40 @@ cleanup:
        return ret;
 }
 
+static int karo_mmc_find_part(struct mmc *mmc, const char *part, int devno,
+                       disk_partition_t *part_info)
+{
+       int ret;
+       block_dev_desc_t *mmc_dev;
+
+       if (strcmp(part, "dtb") == 0) {
+               const int partnum = CONFIG_SYS_MMC_ENV_PART;
+
+               part_info->blksz = mmc->read_bl_len;
+               part_info->start = CONFIG_SYS_DTB_OFFSET / part_info->blksz;
+               part_info->size = CONFIG_SYS_DTB_PART_SIZE / part_info->blksz;
+               printf("Using virtual partition %s(%d) ["LBAF".."LBAF"]\n",
+                       part, partnum, part_info->start,
+                       part_info->start + part_info->size - 1);
+               return partnum;
+       }
+
+       ret = find_partitions("mmc", devno, FS_TYPE_FAT, &mmc_dev, part_info);
+       if (ret < 0) {
+               printf("No eMMC partition found: %d\n", ret);
+               return ret;
+       }
+       return 0;
+}
+
 int karo_load_mmc_part(const char *part, void *addr, size_t len)
 {
        int ret;
        struct mmc *mmc;
        disk_partition_t part_info;
        int devno = CONFIG_MMC_BOOT_DEV;
-       uint blk_start, blk_cnt;
-       block_dev_desc_t *mmc_dev;
+       lbaint_t blk_cnt;
+       int partnum;
 
        mmc = find_mmc_device(devno);
        if (!mmc) {
@@ -102,34 +128,52 @@ int karo_load_mmc_part(const char *part, void *addr, size_t len)
                return -ENODEV;
        }
 
-       mmc_init(mmc);
-
-       ret = find_efi_partition("mmc", devno, part, &mmc_dev, &part_info);
-       if (ret < 0) {
-               printf("eMMC partition '%s' not found: %d\n", part, ret);
-               goto out;
+       if (mmc_init(mmc)) {
+               printf("Failed to init MMC device %d\n", devno);
+               return -EIO;
        }
-       mmc_switch_part(devno, ret);
-
-       blk_start = 0;
-       blk_cnt = DIV_ROUND_UP(len, part_info.blksz);
-
-       debug("Found partition '%s': offset=%08x size=%08lx\n",
-               part, blk_start, part_info.size);
-       if (part_info.size < blk_cnt)
-               blk_cnt = part_info.size;
-
-       debug("Reading %u blks from MMC partition '%s' offset %u to %p\n",
-               blk_cnt, part, blk_start, addr);
-       ret = mmc->block_dev.block_read(devno, blk_start, blk_cnt, addr);
-       if (ret == 0) {
-               printf("Failed to read MMC partition %s\n", part);
-               ret = -EIO;
+
+       blk_cnt = DIV_ROUND_UP(len, mmc->read_bl_len);
+
+       partnum = karo_mmc_find_part(mmc, part, devno, &part_info);
+       if (partnum > 0) {
+               if (part_info.start + blk_cnt < part_info.start) {
+                       printf("%s: given length 0x%08x exceeds size of partition\n",
+                               __func__, len);
+                       return -EINVAL;
+               }
+               if (part_info.start + blk_cnt > mmc->block_dev.lba)
+                       blk_cnt = mmc->block_dev.lba - part_info.start;
+
+               mmc_switch_part(devno, partnum);
+
+               memset(addr, 0xee, len);
+
+               debug("Reading 0x"LBAF" blks from MMC partition %d offset 0x"LBAF" to %p\n",
+                       blk_cnt, partnum, part_info.start, addr);
+               ret = mmc->block_dev.block_read(devno, part_info.start, blk_cnt, addr);
+               if (ret == 0) {
+                       printf("Failed to read MMC partition %s\n", part);
+                       ret = -EIO;
+                       goto out;
+               }
+               debug("Read %u (%u) byte from partition '%s' @ offset 0x"LBAF"\n",
+                       ret * mmc->read_bl_len, len, part, part_info.start);
+       } else if (partnum == 0) {
+               int len_read;
+
+               printf("Reading file %s from mmc partition %d\n", part, 0);
+               len_read = fs_read(part, (ulong)addr, 0, len);
+               if (len_read < len) {
+                       printf("Read only %u of %u bytes\n", len_read, len);
+               }
+       } else {
+               ret = partnum;
                goto out;
        }
-       debug("Read %u byte from partition '%s' @ offset %08x\n",
-               ret * mmc->read_bl_len, part, blk_start);
+       ret = 0;
 out:
-       mmc_switch_part(devno, 0);
+       if (partnum > 0)
+               mmc_switch_part(devno, 0);
        return ret < 0 ? ret : 0;
 }
index c899960..08782ef 100644 (file)
@@ -8,6 +8,7 @@ LOGO_BMP = logos/karo.bmp
 #PLATFORM_CPPFLAGS += -Wno-unused-but-set-variable
 PLATFORM_CPPFLAGS += -Werror
 
+ifeq ($(CONFIG_TX6_V2),)
 # calculate U_BOOT_IMG_SIZE to be at least 3 eraseblocks larger than the maximum expected image size
 CONFIG_SYS_NAND_BLOCK_SIZE := 131072
 CONFIG_SYS_NAND_BLOCKS := 1024
@@ -26,4 +27,22 @@ PLATFORM_CPPFLAGS += -DCONFIG_SYS_USERFS_PART_SIZE2=$(shell printf "%uk" `expr $
 PLATFORM_CPPFLAGS += -DCONFIG_SYS_DTB_PART_SIZE=$(shell printf "%uk" `expr $(CONFIG_SYS_NAND_BLOCK_SIZE) / 1024`)
 PLATFORM_CPPFLAGS += -DCONFIG_SYS_NAND_BBT_SIZE=$(shell printf "%uk" `expr 4 \* $(CONFIG_SYS_NAND_BLOCK_SIZE) / 1024`)
 PLATFORM_CPPFLAGS += -DCONFIG_SYS_NAND_BBT_OFFSET=$(shell printf "0x%x" `expr \( $(CONFIG_SYS_NAND_BLOCKS) - 4 \) \* $(CONFIG_SYS_NAND_BLOCK_SIZE)`)
-endif
+endif # CONFIG_SYS_NAND_BLOCK_SIZE
+else
+CONFIG_SYS_MMC_BOOT_PART_SIZE = $(shell expr 4096 \* 1024)
+CONFIG_U_BOOT_IMG_SIZE = $(shell expr 1 \* 1048576)
+CONFIG_MAX_DTB_SIZE = $(shell expr 64 \* 1024)
+CONFIG_ENV_SIZE = $(shell expr 128 \* 1024)
+CONFIG_ENV_OFFSET = $(shell expr $(CONFIG_SYS_MMC_BOOT_PART_SIZE) - $(CONFIG_ENV_SIZE))
+CONFIG_SYS_DTB_OFFSET=$(shell expr $(CONFIG_ENV_OFFSET) - $(CONFIG_MAX_DTB_SIZE))
+
+PLATFORM_CPPFLAGS += -DCONFIG_ENV_SIZE=$(CONFIG_ENV_SIZE)
+PLATFORM_CPPFLAGS += -DCONFIG_U_BOOT_IMG_SIZE=$(CONFIG_U_BOOT_IMG_SIZE)
+PLATFORM_CPPFLAGS += -DCONFIG_MAX_DTB_SIZE=$(CONFIG_MAX_DTB_SIZE)
+PLATFORM_CPPFLAGS += -DCONFIG_SYS_DTB_PART_SIZE=$(CONFIG_MAX_DTB_SIZE)
+PLATFORM_CPPFLAGS += -DCONFIG_SYS_MMC_BOOT_PART_SIZE=$(CONFIG_SYS_MMC_BOOT_PART_SIZE)
+PLATFORM_CPPFLAGS += -DCONFIG_ENV_OFFSET=$(shell printf "0x%x" $(CONFIG_ENV_OFFSET))
+PLATFORM_CPPFLAGS += -DCONFIG_SYS_DTB_OFFSET=$(shell printf "0x%x" $(CONFIG_SYS_DTB_OFFSET))
+PLATFORM_CPPFLAGS += -DCONFIG_SYS_DTB_BLKNO=$(shell printf "0x%x" `expr $(CONFIG_SYS_DTB_OFFSET) / 512`)
+#PLATFORM_CPPFLAGS += -D
+endif # CONFIG_TX6_V2
index 7abaadd..7d38c68 100644 (file)
@@ -673,6 +673,7 @@ dcd_hdr:
        MXC_DCD_ITEM(IOMUXC_SW_MUX_CTL_PAD_SD3_DATA1,        0x00000001)        /* UART1 RTS */
        MXC_DCD_ITEM(IOMUXC_UART1_UART_RTS_B_SELECT_INPUT,   0x00000003)        /* UART1 RTS INPUT_SEL */
 
+#ifdef CONFIG_NAND_MXS
        /* NAND */
        MXC_DCD_ITEM(IOMUXC_SW_MUX_CTL_PAD_NAND_CLE,    0x00000000)     /* NANDF_CLE: NANDF_CLE */
        MXC_DCD_ITEM(IOMUXC_SW_MUX_CTL_PAD_NAND_ALE,    0x00000000)     /* NANDF_ALE: NANDF_ALE */
@@ -689,7 +690,7 @@ dcd_hdr:
        MXC_DCD_ITEM(IOMUXC_SW_MUX_CTL_PAD_NAND_DATA05, 0x00000000)     /* NANDF_D5: NANDF_D5 */
        MXC_DCD_ITEM(IOMUXC_SW_MUX_CTL_PAD_NAND_DATA06, 0x00000000)     /* NANDF_D6: NANDF_D6 */
        MXC_DCD_ITEM(IOMUXC_SW_MUX_CTL_PAD_NAND_DATA07, 0x00000000)     /* NANDF_D7: NANDF_D7 */
-
+#endif
        /* ext. mem CS */
        MXC_DCD_ITEM(IOMUXC_SW_MUX_CTL_PAD_NAND_CS2_B, 0x00000000)      /* NANDF_CS2: NANDF_CS2 */
        /* DRAM_DQM[0..7] */
index de766ff..88712ba 100644 (file)
@@ -239,15 +239,19 @@ static void tx6qdl_print_cpuinfo(void)
 #define VDD_DDR_VAL_LP         mV_to_regval(1500 * 10)
 
 /* calculate voltages in 10mV */
+/* DCDC1-3 */
 #define mV_to_regval(mV)       DIV_ROUND(((((mV) < 6000) ? 6000 : (mV)) - 6000), 125)
 #define regval_to_mV(v)                (((v) * 125 + 6000))
 
+/* LDO1-2 */
 #define mV_to_regval2(mV)      DIV_ROUND(((((mV) < 9000) ? 9000 : (mV)) - 9000), 250)
 #define regval2_to_mV(v)       (((v) * 250 + 9000))
 
+/* LDO3 */
 #define mV_to_regval3(mV)      DIV_ROUND(((((mV) < 6000) ? 6000 : (mV)) - 6000), 250)
 #define regval3_to_mV(v)       (((v) * 250 + 6000))
 
+/* LDORTC */
 #define mV_to_regval_rtc(mV)   DIV_ROUND(((((mV) < 17000) ? 17000 : (mV)) - 17000), 250)
 #define regval_rtc_to_mV(v)    (((v) * 250 + 17000))
 
@@ -263,7 +267,7 @@ static struct rn5t618_regs {
        { RN5T618_DC1DAC_SLP, VDD_CORE_VAL_LP, },
        { RN5T618_DC2DAC_SLP, VDD_SOC_VAL_LP, },
        { RN5T618_DC3DAC_SLP, VDD_DDR_VAL_LP, },
-       { RN5T618_LDOEN1, 0x04, ~0x1f, },
+       { RN5T618_LDOEN1, 0x01f, ~0x1f, },
        { RN5T618_LDOEN2, 0x10, ~0x30, },
        { RN5T618_LDODIS, 0x00, },
        { RN5T618_LDO3DAC, VDD_HIGH_VAL, },
@@ -411,13 +415,14 @@ static const iomux_v3_cfg_t mmc1_pads[] = {
        MX6_PAD_SD3_CLK__GPIO_7_3,
 };
 
-static const iomux_v3_cfg_t mmc4_pads[] = {
+static const iomux_v3_cfg_t mmc3_pads[] = {
        MX6_PAD_SD4_CMD__USDHC4_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
        MX6_PAD_SD4_CLK__USDHC4_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
        MX6_PAD_SD4_DAT0__USDHC4_DAT0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
        MX6_PAD_SD4_DAT1__USDHC4_DAT1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
        MX6_PAD_SD4_DAT2__USDHC4_DAT2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
        MX6_PAD_SD4_DAT3__USDHC4_DAT3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
+       /* eMMC RESET */
        MX6_PAD_NANDF_ALE__USDHC4_RST,
 };
 
@@ -429,6 +434,16 @@ static struct tx6_esdhc_cfg {
        int cd_gpio;
 } tx6qdl_esdhc_cfg[] = {
        {
+               .pads = mmc3_pads,
+               .num_pads = ARRAY_SIZE(mmc3_pads),
+               .clkid = MXC_ESDHC4_CLK,
+               .cfg = {
+                       .esdhc_base = (void __iomem *)USDHC4_BASE_ADDR,
+                       .max_bus_width = 4,
+               },
+               .cd_gpio = -EINVAL,
+       },
+       {
                .pads = mmc0_pads,
                .num_pads = ARRAY_SIZE(mmc0_pads),
                .clkid = MXC_ESDHC_CLK,
@@ -448,16 +463,6 @@ static struct tx6_esdhc_cfg {
                },
                .cd_gpio = IMX_GPIO_NR(7, 3),
        },
-       {
-               .pads = mmc4_pads,
-               .num_pads = ARRAY_SIZE(mmc4_pads),
-               .clkid = MXC_ESDHC4_CLK,
-               .cfg = {
-                       .esdhc_base = (void __iomem *)USDHC4_BASE_ADDR,
-                       .max_bus_width = 4,
-               },
-               .cd_gpio = -EINVAL,
-       },
 };
 
 static inline struct tx6_esdhc_cfg *to_tx6_esdhc_cfg(struct fsl_esdhc_cfg *cfg)
@@ -844,9 +849,9 @@ void lcd_enable(void)
         */
        lcd_is_enabled = 0;
 
-       karo_load_splashimage(1);
-
        if (lcd_enabled) {
+               karo_load_splashimage(1);
+
                debug("Switching LCD on\n");
                gpio_set_value(TX6_LCD_PWR_GPIO, 1);
                udelay(100);
index 85c7582..ac1f997 100644 (file)
 /* LCD Logo and Splash screen support */
 #define CONFIG_LCD
 #ifdef CONFIG_LCD
-#ifndef CONFIG_TX6_V2
 #define CONFIG_SPLASH_SCREEN
 #define CONFIG_SPLASH_SCREEN_ALIGN
-#endif
 #define CONFIG_VIDEO_IPUV3
 #define CONFIG_IPUV3_CLK               266000000
 #define CONFIG_LCD_LOGO
        "default_bootargs=set bootargs " CONFIG_BOOTARGS                \
        " ${append_bootargs}\0"                                         \
        "fdtaddr=11000000\0"                                            \
-       "fdtsave=nand erase.part dtb"                                   \
-       ";nand write ${fdtaddr} dtb ${fdtsize}\0"                       \
+       CONFIG_SYS_FDTSAVE_CMD                                          \
        "mtdids=" MTDIDS_DEFAULT "\0"                                   \
        "mtdparts=" MTDPARTS_DEFAULT "\0"                               \
        "nfsroot=/tftpboot/rootfs\0"                                    \
 #endif /*  CONFIG_MFG */
 
 #ifndef CONFIG_TX6_V2
+#define CONFIG_SYS_FDTSAVE_CMD                         \
+       "fdtsave=nand erase.part dtb"                   \
+       ";nand write ${fdtaddr} dtb ${fdtsize}\0"
 #define MTD_NAME                       "gpmi-nand"
 #define MTDIDS_DEFAULT                 "nand0=" MTD_NAME
 #define CONFIG_SYS_NAND_ONFI_DETECTION
 #else
+#define CONFIG_SYS_FDTSAVE_CMD                                         \
+       "fdtsave=mmc open 0 1;mmc write ${fdtaddr} " xstr(CONFIG_SYS_DTB_BLKNO) " 80;mmc close 0 1\0"
 #define MTD_NAME                       ""
 #define MTDIDS_DEFAULT                 ""
 #define CONFIG_SUPPORT_EMMC_BOOT
+#define CONFIG_MMC_BOOT_DEV            0
 #endif
 
 /*
 #ifndef CONFIG_TX6_V2
 #define CONFIG_CMD_NAND
 #define CONFIG_CMD_MTDPARTS
-#else
-#define CONFIG_PARTITION_UUIDS
-#define CONFIG_EFI_PARTITION
-#define CONFIG_CMD_GPT
 #endif
 #define CONFIG_CMD_BOOTCE
 #define CONFIG_CMD_TIME
 #define CONFIG_SYS_NAND_USE_FLASH_BBT
 #define CONFIG_SYS_NAND_BASE           0x00000000
 #define CONFIG_CMD_ROMUPDATE
-#else
-#undef CONFIG_ENV_IS_IN_NAND
-#endif /* CONFIG_CMD_NAND */
 
 #define CONFIG_ENV_OFFSET              (CONFIG_U_BOOT_IMG_SIZE + CONFIG_SYS_NAND_U_BOOT_OFFS)
 #define CONFIG_ENV_SIZE                        SZ_128K
 #define CONFIG_ENV_RANGE               (3 * CONFIG_SYS_NAND_BLOCK_SIZE)
+#else
+#undef CONFIG_ENV_IS_IN_NAND
+#endif /* CONFIG_CMD_NAND */
+
 #ifdef CONFIG_ENV_OFFSET_REDUND
 #define CONFIG_SYS_ENV_PART_STR                xstr(CONFIG_SYS_ENV_PART_SIZE)  \
        "(env),"                                                        \
 
 #define CONFIG_DOS_PARTITION
 #define CONFIG_CMD_FAT
+#define CONFIG_FAT_WRITE
 #define CONFIG_CMD_EXT2
 
 /*
  */
 #ifdef CONFIG_ENV_IS_IN_MMC
 #define CONFIG_SYS_MMC_ENV_DEV         0
-#undef CONFIG_ENV_OFFSET
-#undef CONFIG_ENV_SIZE
-#define CONFIG_ENV_OFFSET              (CONFIG_U_BOOT_IMG_SIZE + CONFIG_SYS_NAND_U_BOOT_OFFS)
-#define CONFIG_ENV_SIZE                        SZ_128K
+#define CONFIG_SYS_MMC_ENV_PART                1
 #define CONFIG_DYNAMIC_MMC_DEVNO
 #endif /* CONFIG_ENV_IS_IN_MMC */
 #else