omap3: cm-t35: extract the splash code from board
[oweals/u-boot.git] / board / compulab / cm_t35 / cm_t35.c
index 3caa5be8455677bd0c5f5e4ef5b74dc1b9e74597..a3b38ae2d358dab08e3bb8648942d7a88f13e771 100644 (file)
@@ -19,9 +19,7 @@
 #include <i2c.h>
 #include <usb.h>
 #include <mmc.h>
-#include <nand.h>
 #include <twl4030.h>
-#include <bmp_layout.h>
 #include <linux/compiler.h>
 
 #include <asm/io.h>
@@ -33,7 +31,8 @@
 #include <asm/ehci-omap.h>
 #include <asm/gpio.h>
 
-#include "eeprom.h"
+#include "../common/common.h"
+#include "../common/eeprom.h"
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -53,76 +52,28 @@ static u32 gpmc_net_config[GPMC_MAX_REG] = {
        0
 };
 
-static u32 gpmc_nand_config[GPMC_MAX_REG] = {
-       SMNAND_GPMC_CONFIG1,
-       SMNAND_GPMC_CONFIG2,
-       SMNAND_GPMC_CONFIG3,
-       SMNAND_GPMC_CONFIG4,
-       SMNAND_GPMC_CONFIG5,
-       SMNAND_GPMC_CONFIG6,
-       0,
-};
-
-#ifdef CONFIG_LCD
-#ifdef CONFIG_CMD_NAND
-static int splash_load_from_nand(u32 bmp_load_addr)
-{
-       struct bmp_header *bmp_hdr;
-       int res, splash_screen_nand_offset = 0x100000;
-       size_t bmp_size, bmp_header_size = sizeof(struct bmp_header);
-
-       if (bmp_load_addr + bmp_header_size >= gd->start_addr_sp)
-               goto splash_address_too_high;
-
-       res = nand_read_skip_bad(&nand_info[nand_curr_device],
-                       splash_screen_nand_offset, &bmp_header_size,
-                       NULL, nand_info[nand_curr_device].size,
-                       (u_char *)bmp_load_addr);
-       if (res < 0)
-               return res;
-
-       bmp_hdr = (struct bmp_header *)bmp_load_addr;
-       bmp_size = le32_to_cpu(bmp_hdr->file_size);
-
-       if (bmp_load_addr + bmp_size >= gd->start_addr_sp)
-               goto splash_address_too_high;
-
-       return nand_read_skip_bad(&nand_info[nand_curr_device],
-                       splash_screen_nand_offset, &bmp_size,
-                       NULL, nand_info[nand_curr_device].size,
-                       (u_char *)bmp_load_addr);
-
-splash_address_too_high:
-       printf("Error: splashimage address too high. Data overwrites U-Boot "
-               "and/or placed beyond DRAM boundaries.\n");
-
-       return -1;
-}
-#else
-static inline int splash_load_from_nand(void)
+#ifdef CONFIG_SPL_BUILD
+/*
+ * Routine: get_board_mem_timings
+ * Description: If we use SPL then there is no x-loader nor config header
+ * so we have to setup the DDR timings ourself on both banks.
+ */
+void get_board_mem_timings(struct board_sdrc_timings *timings)
 {
-       return -1;
+       timings->mr = MICRON_V_MR_165;
+       timings->mcfg = MICRON_V_MCFG_200(256 << 20); /* raswidth 14 needed */
+       timings->ctrla = MICRON_V_ACTIMA_165;
+       timings->ctrlb = MICRON_V_ACTIMB_165;
+       timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
 }
-#endif /* CONFIG_CMD_NAND */
+#endif
+
+#define CM_T35_SPLASH_NAND_OFFSET 0x100000
 
 int splash_screen_prepare(void)
 {
-       char *env_splashimage_value;
-       u32 bmp_load_addr;
-
-       env_splashimage_value = getenv("splashimage");
-       if (env_splashimage_value == NULL)
-               return -1;
-
-       bmp_load_addr = simple_strtoul(env_splashimage_value, 0, 16);
-       if (bmp_load_addr == 0) {
-               printf("Error: bad splashimage address specified\n");
-               return -1;
-       }
-
-       return splash_load_from_nand(bmp_load_addr);
+       return cl_splash_screen_prepare(CM_T35_SPLASH_NAND_OFFSET);
 }
-#endif /* CONFIG_LCD */
 
 /*
  * Routine: board_init
@@ -132,9 +83,6 @@ int board_init(void)
 {
        gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
 
-       enable_gpmc_cs_config(gpmc_nand_config, &gpmc_cfg->cs[0],
-                             CONFIG_SYS_NAND_BASE, GPMC_SIZE_16M);
-
        /* board id for Linux */
        if (get_cpu_family() == CPU_OMAP34XX)
                gd->bd->bi_arch_number = MACH_TYPE_CM_T35;
@@ -151,34 +99,18 @@ int board_init(void)
        return 0;
 }
 
-static u32 cm_t3x_rev;
-
 /*
  * Routine: get_board_rev
  * Description: read system revision
  */
 u32 get_board_rev(void)
 {
-       if (!cm_t3x_rev)
-               cm_t3x_rev = cm_t3x_eeprom_get_board_rev();
-
-       return cm_t3x_rev;
+       return cl_eeprom_get_board_rev();
 };
 
-/*
- * Routine: misc_init_r
- * Description: display die ID
- */
 int misc_init_r(void)
 {
-       u32 board_rev = get_board_rev();
-       u32 rev_major = board_rev / 100;
-       u32 rev_minor = board_rev - (rev_major * 100);
-
-       if ((rev_minor / 10) * 10 == rev_minor)
-               rev_minor = rev_minor / 10;
-
-       printf("PCB:   %u.%u\n", rev_major, rev_minor);
+       cl_print_pcb_info();
        dieid_num_r();
 
        return 0;
@@ -268,6 +200,9 @@ static void cm_t3x_set_common_muxconf(void)
        /* DVI enable */
        MUX_VAL(CP(GPMC_NCS3),          (IDIS  | PTU | DIS  | M4));/*GPMC_nCS3*/
 
+       /* DataImage backlight */
+       MUX_VAL(CP(GPMC_NCS7),          (IDIS  | PTU | DIS  | M4));/*GPIO_58*/
+
        /* CM-T3x Ethernet */
        MUX_VAL(CP(GPMC_NCS5),          (IDIS | PTU | DIS | M0)); /*GPMC_nCS5*/
        MUX_VAL(CP(GPMC_CLK),           (IEN  | PTD | DIS | M4)); /*GPIO_59*/
@@ -362,7 +297,7 @@ static void cm_t3x_set_common_muxconf(void)
        MUX_VAL(CP(SYS_OFF_MODE),       (IEN  | PTD | DIS | M0)); /*OFF_MODE*/
        MUX_VAL(CP(SYS_CLKOUT1),        (IEN  | PTD | DIS | M0)); /*CLKOUT1*/
        MUX_VAL(CP(SYS_CLKOUT2),        (IDIS | PTU | DIS | M4)); /*green LED*/
-       MUX_VAL(CP(JTAG_nTRST),         (IEN  | PTD | DIS | M0)); /*JTAG_nTRST*/
+       MUX_VAL(CP(JTAG_NTRST),         (IEN  | PTD | DIS | M0)); /*JTAG_NTRST*/
        MUX_VAL(CP(JTAG_TCK),           (IEN  | PTD | DIS | M0)); /*JTAG_TCK*/
        MUX_VAL(CP(JTAG_TMS),           (IEN  | PTD | DIS | M0)); /*JTAG_TMS*/
        MUX_VAL(CP(JTAG_TDI),           (IEN  | PTD | DIS | M0)); /*JTAG_TDI*/
@@ -374,6 +309,15 @@ static void cm_t3x_set_common_muxconf(void)
        MUX_VAL(CP(MMC1_DAT1),          (IEN  | PTU | EN  | M0)); /*MMC1_DAT1*/
        MUX_VAL(CP(MMC1_DAT2),          (IEN  | PTU | EN  | M0)); /*MMC1_DAT2*/
        MUX_VAL(CP(MMC1_DAT3),          (IEN  | PTU | EN  | M0)); /*MMC1_DAT3*/
+
+       /* SPI */
+       MUX_VAL(CP(MCBSP1_CLKR),        (IEN | PTD | DIS | M1)); /*MCSPI4_CLK*/
+       MUX_VAL(CP(MCBSP1_DX),          (IEN | PTD | DIS | M1)); /*MCSPI4_SIMO*/
+       MUX_VAL(CP(MCBSP1_DR),          (IEN | PTD | DIS | M1)); /*MCSPI4_SOMI*/
+       MUX_VAL(CP(MCBSP1_FSX),         (IEN | PTU | EN  | M1)); /*MCSPI4_CS0*/
+
+       /* display controls */
+       MUX_VAL(CP(MCBSP1_FSR),         (IDIS | PTU | DIS | M4)); /*GPIO_157*/
 }
 
 static void cm_t35_set_muxconf(void)
@@ -428,7 +372,9 @@ void set_muxconf_regs(void)
                cm_t3730_set_muxconf();
 }
 
-#ifdef CONFIG_GENERIC_MMC
+#if defined(CONFIG_GENERIC_MMC) && !defined(CONFIG_SPL_BUILD)
+#define SB_T35_WP_GPIO 59
+
 int board_mmc_getcd(struct mmc *mmc)
 {
        u8 val;
@@ -441,7 +387,7 @@ int board_mmc_getcd(struct mmc *mmc)
 
 int board_mmc_init(bd_t *bis)
 {
-       return omap_mmc_init(0, 0, 0, -1, 59);
+       return omap_mmc_init(0, 0, 0, -1, SB_T35_WP_GPIO);
 }
 #endif
 
@@ -470,7 +416,7 @@ static void setup_net_chip_gmpc(void)
                &ctrl_base->gpmc_nadv_ale);
 }
 
-#ifdef CONFIG_DRIVER_OMAP34XX_I2C
+#ifdef CONFIG_SYS_I2C_OMAP34XX
 /*
  * Routine: reset_net_chip
  * Description: reset the Ethernet controller via TPS65930 GPIO
@@ -509,7 +455,7 @@ static int handle_mac_address(void)
        if (rc)
                return 0;
 
-       rc = cm_t3x_eeprom_read_mac_addr(enetaddr);
+       rc = cl_eeprom_read_mac_addr(enetaddr);
        if (rc)
                return rc;
 
@@ -565,21 +511,13 @@ struct omap_usbhs_board_data usbhs_bdata = {
 };
 
 #define SB_T35_USB_HUB_RESET_GPIO      167
-int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
+int ehci_hcd_init(int index, enum usb_init_type init,
+                 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
 {
        u8 val;
        int offset;
 
-       if (gpio_request(SB_T35_USB_HUB_RESET_GPIO, "SB-T35 usb hub reset")) {
-               printf("Error: can't obtain GPIO %d for SB-T35 usb hub reset",
-                               SB_T35_USB_HUB_RESET_GPIO);
-               return -1;
-       }
-
-       gpio_direction_output(SB_T35_USB_HUB_RESET_GPIO, 0);
-       udelay(10);
-       gpio_set_value(SB_T35_USB_HUB_RESET_GPIO, 1);
-       udelay(1000);
+       cl_usb_hub_init(SB_T35_USB_HUB_RESET_GPIO, "sb-t35 hub rst");
 
        offset = TWL4030_BASEADD_GPIO + TWL4030_GPIO_GPIODATADIR1;
        twl4030_i2c_read_u8(TWL4030_CHIP_GPIO, offset, &val);
@@ -591,12 +529,12 @@ int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
        twl4030_i2c_write_u8(TWL4030_CHIP_GPIO, offset, 0xC0);
        udelay(1);
 
-       return omap_ehci_hcd_init(&usbhs_bdata, hccr, hcor);
+       return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
 }
 
 int ehci_hcd_stop(void)
 {
+       cl_usb_hub_deinit(SB_T35_USB_HUB_RESET_GPIO);
        return omap_ehci_hcd_stop();
 }
-
 #endif /* CONFIG_USB_EHCI_OMAP */