]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - board/karo/tx28/tx28.c
karo: tx28: add support for TX28-4033 (with 256MiB flash)
[karo-tx-uboot.git] / board / karo / tx28 / tx28.c
index c3e261690ff58bef8b4b6889607d1a1b9c03f8b9..8957b8c7db503476997ae6f0fff2b37531e24b70 100644 (file)
@@ -23,6 +23,7 @@
 #include <lcd.h>
 #include <netdev.h>
 #include <mmc.h>
+#include <mxcfb.h>
 #include <linux/list.h>
 #include <linux/fb.h>
 #include <asm/io.h>
@@ -231,8 +232,11 @@ static int fec_get_mac_addr(int index)
                        val = readl(&cust[index * 8 + i]);
                mac[i] = val >> shift;
        }
-       if (!is_valid_ether_addr(mac))
+       if (!is_valid_ether_addr(mac)) {
+               if (index == 0)
+                       printf("No valid MAC address programmed\n");
                return 0;
+       }
 
        if (index == 0) {
                printf("MAC addr from fuse: %pM\n", mac);
@@ -421,6 +425,7 @@ static struct fb_videomode tx28_fb_modes[] = {
                .upper_margin   = 2,
                .vsync_len      = 10,
                .lower_margin   = 2,
+               .sync           = FB_SYNC_CLK_LAT_FALL,
                .vmode          = FB_VMODE_NONINTERLACED,
        },
        {
@@ -481,6 +486,12 @@ static struct fb_videomode tx28_fb_modes[] = {
 };
 
 static int lcd_enabled = 1;
+static int lcd_bl_polarity;
+
+static int lcd_backlight_polarity(void)
+{
+       return lcd_bl_polarity;
+}
 
 void lcd_enable(void)
 {
@@ -498,7 +509,8 @@ void lcd_enable(void)
                udelay(100);
                gpio_set_value(TX28_LCD_RST_GPIO, 1);
                udelay(300000);
-               gpio_set_value(TX28_LCD_BACKLIGHT_GPIO, 0);
+               gpio_set_value(TX28_LCD_BACKLIGHT_GPIO,
+                       lcd_backlight_polarity());
        }
 }
 
@@ -510,7 +522,8 @@ void lcd_panel_disable(void)
 {
        if (lcd_enabled) {
                debug("Switching LCD off\n");
-               gpio_set_value(TX28_LCD_BACKLIGHT_GPIO, 1);
+               gpio_set_value(TX28_LCD_BACKLIGHT_GPIO,
+                       !lcd_backlight_polarity());
                gpio_set_value(TX28_LCD_RST_GPIO, 0);
                gpio_set_value(TX28_LCD_PWR_GPIO, 0);
        }
@@ -553,9 +566,6 @@ static const iomux_cfg_t stk5_lcd_pads[] = {
        MX28_PAD_LCD_WR_RWN__LCD_HSYNC | MXS_PAD_CTRL,
        MX28_PAD_LCD_RS__LCD_DOTCLK | MXS_PAD_CTRL,
        MX28_PAD_LCD_CS__LCD_CS | MXS_PAD_CTRL,
-       MX28_PAD_LCD_VSYNC__LCD_VSYNC | MXS_PAD_CTRL,
-       MX28_PAD_LCD_HSYNC__LCD_HSYNC | MXS_PAD_CTRL,
-       MX28_PAD_LCD_DOTCLK__LCD_DOTCLK | MXS_PAD_CTRL,
 };
 
 static const struct gpio stk5_lcd_gpios[] = {
@@ -569,7 +579,8 @@ extern void video_hw_init(void *lcdbase);
 void lcd_ctrl_init(void *lcdbase)
 {
        int color_depth = 24;
-       char *vm;
+       const char *video_mode = karo_get_vmode(getenv("video_mode"));
+       const char *vm;
        unsigned long val;
        int refresh = 60;
        struct fb_videomode *p = tx28_fb_modes;
@@ -581,24 +592,34 @@ void lcd_ctrl_init(void *lcdbase)
                return;
        }
 
-       if (tstc()) {
+       if (had_ctrlc()) {
                debug("Disabling LCD\n");
                lcd_enabled = 0;
+               setenv("splashimage", NULL);
                return;
        }
 
        karo_fdt_move_fdt();
+       lcd_bl_polarity = karo_fdt_get_backlight_polarity(working_fdt);
 
-       vm = getenv("video_mode");
-       if (vm == NULL) {
+       if (video_mode == NULL) {
                debug("Disabling LCD\n");
                lcd_enabled = 0;
                return;
        }
-       if (karo_fdt_get_fb_mode(working_fdt, vm, &fb_mode) == 0) {
+       vm = video_mode;
+       if (karo_fdt_get_fb_mode(working_fdt, video_mode, &fb_mode) == 0) {
                p = &fb_mode;
                debug("Using video mode from FDT\n");
                vm += strlen(vm);
+               if (fb_mode.xres > panel_info.vl_col ||
+                       fb_mode.yres > panel_info.vl_row) {
+                       printf("video resolution from DT: %dx%d exceeds hardware limits: %dx%d\n",
+                               fb_mode.xres, fb_mode.yres,
+                               panel_info.vl_col, panel_info.vl_row);
+                       lcd_enabled = 0;
+                       return;
+               }
        }
        if (p->name != NULL)
                debug("Trying compiled-in video modes\n");
@@ -622,11 +643,13 @@ void lcd_ctrl_init(void *lcdbase)
                                        if (val > panel_info.vl_col)
                                                val = panel_info.vl_col;
                                        p->xres = val;
+                                       panel_info.vl_col = val;
                                        xres_set = 1;
                                } else if (!yres_set) {
                                        if (val > panel_info.vl_row)
                                                val = panel_info.vl_row;
                                        p->yres = val;
+                                       panel_info.vl_row = val;
                                        yres_set = 1;
                                } else if (!bpp_set) {
                                        switch (val) {
@@ -679,6 +702,12 @@ void lcd_ctrl_init(void *lcdbase)
                printf("\n");
                return;
        }
+       if (p->xres > panel_info.vl_col || p->yres > panel_info.vl_row) {
+               printf("video resolution: %dx%d exceeds hardware limits: %dx%d\n",
+                       p->xres, p->yres, panel_info.vl_col, panel_info.vl_row);
+               lcd_enabled = 0;
+               return;
+       }
        panel_info.vl_col = p->xres;
        panel_info.vl_row = p->yres;
 
@@ -700,6 +729,17 @@ void lcd_ctrl_init(void *lcdbase)
        debug("Pixel clock set to %lu.%03lu MHz\n",
                PICOS2KHZ(p->pixclock) / 1000, PICOS2KHZ(p->pixclock) % 1000);
 
+       if (p != &fb_mode) {
+               int ret;
+
+               debug("Creating new display-timing node from '%s'\n",
+                       video_mode);
+               ret = karo_fdt_create_fb_mode(working_fdt, video_mode, p);
+               if (ret)
+                       printf("Failed to create new display-timing node from '%s': %d\n",
+                               video_mode, ret);
+       }
+
        gpio_request_array(stk5_lcd_gpios, ARRAY_SIZE(stk5_lcd_gpios));
        mxs_iomux_setup_multiple_pads(stk5_lcd_pads,
                                ARRAY_SIZE(stk5_lcd_pads));
@@ -708,11 +748,14 @@ void lcd_ctrl_init(void *lcdbase)
                color_depth, refresh);
 
        if (karo_load_splashimage(0) == 0) {
-               char vmode[32];
+               char vmode[128];
 
                /* setup env variable for mxsfb display driver */
-               snprintf(vmode, sizeof(vmode), "%dx%dMR-%d@%d",
-                       p->xres, p->yres, color_depth, refresh);
+               snprintf(vmode, sizeof(vmode),
+                       "x:%d,y:%d,le:%d,ri:%d,up:%d,lo:%d,hs:%d,vs:%d,sync:%d,pclk:%d,depth:%d",
+                       p->xres, p->yres, p->left_margin, p->right_margin,
+                       p->upper_margin, p->lower_margin, p->hsync_len,
+                       p->vsync_len, p->sync, p->pixclock, color_depth);
                setenv("videomode", vmode);
 
                debug("Initializing LCD controller\n");
@@ -763,19 +806,40 @@ int tx28_fec1_enabled(void)
        return status && (strcmp(status, "okay") == 0);
 }
 
-int board_late_init(void)
+static void tx28_init_mac(void)
 {
        int ret;
+
+       ret = fec_get_mac_addr(0);
+       if (ret < 0) {
+               printf("Failed to read FEC0 MAC address from OCOTP\n");
+               return;
+       }
+#ifdef CONFIG_FEC_MXC_MULTI
+       if (tx28_fec1_enabled()) {
+               ret = fec_get_mac_addr(1);
+               if (ret < 0) {
+                       printf("Failed to read FEC1 MAC address from OCOTP\n");
+                       return;
+               }
+       }
+#endif
+}
+
+int board_late_init(void)
+{
+       int ret = 0;
        const char *baseboard;
 
        karo_fdt_move_fdt();
 
        baseboard = getenv("baseboard");
        if (!baseboard)
-               return 0;
+               goto exit;
+
+       printf("Baseboard: %s\n", baseboard);
 
        if (strncmp(baseboard, "stk5", 4) == 0) {
-               printf("Baseboard: %s\n", baseboard);
                if ((strlen(baseboard) == 4) ||
                        strcmp(baseboard, "stk5-v3") == 0) {
                        stk5v3_board_init();
@@ -795,24 +859,13 @@ int board_late_init(void)
        } else {
                printf("WARNING: Unsupported baseboard: '%s'\n",
                        baseboard);
-               return -EINVAL;
+               ret = -EINVAL;
        }
 
-       ret = fec_get_mac_addr(0);
-       if (ret < 0) {
-               printf("Failed to read FEC0 MAC address from OCOTP\n");
-               return ret;
-       }
-#ifdef CONFIG_FEC_MXC_MULTI
-       if (tx28_fec1_enabled()) {
-               ret = fec_get_mac_addr(1);
-               if (ret < 0) {
-                       printf("Failed to read FEC1 MAC address from OCOTP\n");
-                       return ret;
-               }
-       }
-#endif
-       return 0;
+exit:
+       tx28_init_mac();
+       clear_ctrlc();
+       return ret;
 }
 
 #define BOOT_CAUSE_MASK                (RTC_PERSISTENT0_EXTERNAL_RESET |       \
@@ -841,7 +894,8 @@ int checkboard(void)
        const char *dlm = "";
 
        printf("Board: Ka-Ro TX28-4%sx%d\n", TX28_MOD_SUFFIX,
-               CONFIG_SDRAM_SIZE / SZ_128M);
+               CONFIG_SDRAM_SIZE / SZ_128M +
+               CONFIG_SYS_NAND_BLOCKS / 2048 * 2);
 
        printf("POWERUP Source: ");
        if (pwrup_src & (3 << 0)) {
@@ -901,7 +955,7 @@ int checkboard(void)
 #ifdef CONFIG_FDT_FIXUP_PARTITIONS
 #include <jffs2/jffs2.h>
 #include <mtd_node.h>
-struct node_info tx28_nand_nodes[] = {
+static struct node_info tx28_nand_nodes[] = {
        { "fsl,imx28-gpmi-nand", MTD_DEV_TYPE_NAND, },
 };
 #else
@@ -918,6 +972,12 @@ void ft_board_setup(void *blob, bd_t *bd)
 {
        const char *baseboard = getenv("baseboard");
        int stk5_v5 = baseboard != NULL && (strcmp(baseboard, "stk5-v5") == 0);
+       const char *video_mode = karo_get_vmode(getenv("video_mode"));
+       int ret;
+
+       ret = fdt_increase_size(blob, 4096);
+       if (ret)
+               printf("Failed to increase FDT size: %s\n", fdt_strerror(ret));
 
 #ifdef CONFIG_TX28_S
        /* TX28-41xx (aka TX28S) has no external RTC
@@ -926,17 +986,16 @@ void ft_board_setup(void *blob, bd_t *bd)
        karo_fdt_remove_node(blob, "ds1339");
        karo_fdt_remove_node(blob, "gpio5");
 #endif
-       if (stk5_v5) {
-               karo_fdt_remove_node(blob, "stk5led");
-       }
+       if (stk5_v5)
+               karo_fdt_enable_node(blob, "stk5led", 0);
 
        fdt_fixup_mtdparts(blob, tx28_nand_nodes, ARRAY_SIZE(tx28_nand_nodes));
        fdt_fixup_ethernet(blob);
 
        karo_fdt_fixup_touchpanel(blob, tx28_touchpanels,
                                ARRAY_SIZE(tx28_touchpanels));
-       karo_fdt_fixup_usb_otg(blob, "usbotg", "fsl,usbphy");
+       karo_fdt_fixup_usb_otg(blob, "usbotg", "fsl,usbphy", "vbus-supply");
        karo_fdt_fixup_flexcan(blob, stk5_v5);
-       karo_fdt_update_fb_mode(blob, getenv("video_mode"));
+       karo_fdt_update_fb_mode(blob, video_mode);
 }
 #endif /* CONFIG_OF_BOARD_SETUP */