]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - board/karo/tx48/tx48.c
net: cosmetic: Name ethaddr variables consistently
[karo-tx-uboot.git] / board / karo / tx48 / tx48.c
index 48cb0c83da837031681307d1882482133570609b..95a98a92362a7528805bcc14fc752a29705b2065 100644 (file)
@@ -325,6 +325,23 @@ static u32 prm_rstst __attribute__((section(".data")));
 /*
  * Basic board specific setup
  */
+static const struct pin_mux tx48_pads[] = {
+       { OFFSET(i2c0_sda), MODE(7) | RXACTIVE | PULLUDEN | PULLUP_EN, },
+       { OFFSET(i2c0_scl), MODE(7) | RXACTIVE | PULLUDEN | PULLUP_EN, },
+       { OFFSET(emu1), MODE(7), }, /* ETH PHY Reset */
+};
+
+static const struct pin_mux tx48_i2c_pads[] = {
+       { OFFSET(i2c0_sda), MODE(0) | RXACTIVE | PULLUDEN | PULLUP_EN, },
+       { OFFSET(i2c0_scl), MODE(0) | RXACTIVE | PULLUDEN | PULLUP_EN, },
+};
+
+static const struct gpio tx48_gpios[] = {
+       { AM33XX_GPIO_NR(3, 5), GPIOFLAG_INPUT, "I2C1_SDA", },
+       { AM33XX_GPIO_NR(3, 6), GPIOFLAG_INPUT, "I2C1_SCL", },
+       { AM33XX_GPIO_NR(3, 8), GPIOFLAG_OUTPUT_INIT_LOW, "ETH_PHY_RESET", },
+};
+
 static const struct pin_mux stk5_pads[] = {
        /* heartbeat LED */
        { OFFSET(gpmc_a10), MODE(7) | PULLUDEN, },
@@ -339,8 +356,8 @@ static const struct pin_mux stk5_pads[] = {
 };
 
 static const struct gpio stk5_gpios[] = {
-       { TX48_LED_GPIO, GPIOF_OUTPUT_INIT_LOW, "HEARTBEAT LED", },
-       { TX48_MMC_CD_GPIO, GPIOF_INPUT, "HEARTBEAT LED", },
+       { TX48_LED_GPIO, GPIOFLAG_OUTPUT_INIT_LOW, "HEARTBEAT LED", },
+       { TX48_MMC_CD_GPIO, GPIOFLAG_INPUT, "MMC0 CD", },
 };
 
 static const struct pin_mux stk5_lcd_pads[] = {
@@ -369,9 +386,9 @@ static const struct pin_mux stk5_lcd_pads[] = {
 };
 
 static const struct gpio stk5_lcd_gpios[] = {
-       { AM33XX_GPIO_NR(1, 19), GPIOF_OUTPUT_INIT_LOW, "LCD RESET", },
-       { AM33XX_GPIO_NR(1, 22), GPIOF_OUTPUT_INIT_LOW, "LCD POWER", },
-       { AM33XX_GPIO_NR(3, 14), GPIOF_OUTPUT_INIT_HIGH, "LCD BACKLIGHT", },
+       { AM33XX_GPIO_NR(1, 19), GPIOFLAG_OUTPUT_INIT_LOW, "LCD RESET", },
+       { AM33XX_GPIO_NR(1, 22), GPIOFLAG_OUTPUT_INIT_LOW, "LCD POWER", },
+       { AM33XX_GPIO_NR(3, 14), GPIOFLAG_OUTPUT_INIT_HIGH, "LCD BACKLIGHT", },
 };
 
 static const struct pin_mux stk5v5_pads[] = {
@@ -380,7 +397,7 @@ static const struct pin_mux stk5v5_pads[] = {
 };
 
 static const struct gpio stk5v5_gpios[] = {
-       { AM33XX_GPIO_NR(0, 22), GPIOF_OUTPUT_INIT_HIGH, "CAN XCVR", },
+       { AM33XX_GPIO_NR(0, 22), GPIOFLAG_OUTPUT_INIT_HIGH, "CAN XCVR", },
 };
 
 #ifdef CONFIG_LCD
@@ -390,7 +407,7 @@ vidinfo_t panel_info = {
        .vl_col = 1366,
        .vl_row = 768,
 
-       .vl_bpix = LCD_COLOR24,    /* Bits per pixel, 0: 1bpp, 1: 2bpp, 2: 4bpp, 3: 8bpp ... */
+       .vl_bpix = LCD_COLOR32,    /* Bits per pixel, 0: 1bpp, 1: 2bpp, 2: 4bpp, 3: 8bpp ... */
        .cmap = tx48_cmap,
 };
 
@@ -637,13 +654,14 @@ void lcd_ctrl_init(void *lcdbase)
        }
 
        karo_fdt_move_fdt();
-       lcd_bl_polarity = karo_fdt_get_backlight_polarity(working_fdt);
 
        if (video_mode == NULL) {
                debug("Disabling LCD\n");
                lcd_enabled = 0;
                return;
        }
+
+       lcd_bl_polarity = karo_fdt_get_backlight_polarity(working_fdt);
        vm = video_mode;
        if (karo_fdt_get_fb_mode(working_fdt, video_mode, &fb_mode) == 0) {
                p = &fb_mode;
@@ -755,7 +773,7 @@ void lcd_ctrl_init(void *lcdbase)
                panel_info.vl_bpix = LCD_COLOR16;
                break;
        default:
-               panel_info.vl_bpix = LCD_COLOR24;
+               panel_info.vl_bpix = LCD_COLOR32;
        }
 
        p->pixclock = KHZ2PICOS(refresh *
@@ -819,6 +837,8 @@ static void stk5v5_board_init(void)
 /* called with default environment! */
 int board_init(void)
 {
+       int i;
+
        /* mach type passed to kernel */
 #ifdef CONFIG_OF_LIBFDT
        gd->bd->bi_arch_number = -1;
@@ -826,9 +846,24 @@ int board_init(void)
        /* address of boot parameters */
        gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
 
-       if (ctrlc())
-               printf("CTRL-C detected\n");
+       if (ctrlc() || (prm_rstst & PRM_RSTST_WDT1_RST)) {
+               if (prm_rstst & PRM_RSTST_WDT1_RST)
+                       printf("WDOG RESET detected\n");
+               else
+                       printf("<CTRL-C> detected; safeboot enabled\n");
+       }
+
+       gpio_request_array(tx48_gpios, ARRAY_SIZE(tx48_gpios));
+       tx48_set_pin_mux(tx48_pads, ARRAY_SIZE(tx48_pads));
+
+       for (i = 0; i < ARRAY_SIZE(tx48_gpios); i++) {
+               int gpio = tx48_gpios[i].gpio;
 
+               if (gpio_get_value(gpio) == 0)
+                       gpio_direction_output(gpio, 1);
+       }
+
+       tx48_set_pin_mux(tx48_pads, ARRAY_SIZE(tx48_i2c_pads));
        return 0;
 }
 
@@ -869,11 +904,8 @@ int checkboard(void)
        prm_rstst = readl(PRM_RSTST);
        show_reset_cause(prm_rstst);
 
-#ifdef CONFIG_OF_LIBFDT
-       printf("Board: Ka-Ro TX48-7020 with FDT support\n");
-#else
        printf("Board: Ka-Ro TX48-7020\n");
-#endif
+
        timer_init();
        return 0;
 }
@@ -881,18 +913,29 @@ int checkboard(void)
 static void tx48_set_cpu_clock(void)
 {
        unsigned long cpu_clk = getenv_ulong("cpu_clk", 10, 0);
+       unsigned long act_cpu_clk;
 
-       if (had_ctrlc() || (prm_rstst & PRM_RSTST_WDT1_RST))
+       if (cpu_clk == 0 || cpu_clk == mpu_clk_rate() / 1000000)
                return;
 
-       if (cpu_clk == 0 || cpu_clk == mpu_clk_rate() / 1000000)
+       if (had_ctrlc() || (prm_rstst & PRM_RSTST_WDT1_RST)) {
+               printf("%s detected; skipping cpu clock change\n",
+                       (prm_rstst & PRM_RSTST_WDT1_RST) ?
+                       "WDOG RESET" : "<CTRL-C>");
                return;
+       }
 
        mpu_pll_config_val(cpu_clk);
 
-       printf("CPU clock set to %lu.%03lu MHz\n",
-               mpu_clk_rate() / 1000000,
-               mpu_clk_rate() / 1000 % 1000);
+       act_cpu_clk = mpu_clk_rate();
+       if (cpu_clk * 1000000 != act_cpu_clk) {
+               printf("Failed to set CPU clock to %lu MHz; using %lu.%03lu MHz instead\n",
+                       cpu_clk, act_cpu_clk / 1000000,
+                       act_cpu_clk / 1000 % 1000);
+       } else {
+               printf("CPU clock set to %lu.%03lu MHz\n",
+                       act_cpu_clk / 1000000, act_cpu_clk / 1000 % 1000);
+       }
 }
 
 static void tx48_init_mac(void)
@@ -911,7 +954,7 @@ static void tx48_init_mac(void)
        mac_addr[4] = mac_lo & 0xFF;
        mac_addr[5] = (mac_lo & 0xFF00) >> 8;
 
-       if (!is_valid_ether_addr(mac_addr)) {
+       if (!is_valid_ethaddr(mac_addr)) {
                printf("No valid MAC address programmed\n");
                return;
        }
@@ -925,8 +968,16 @@ int board_late_init(void)
        int ret = 0;
        const char *baseboard;
 
+       env_cleanup();
+
        tx48_set_cpu_clock();
-       karo_fdt_move_fdt();
+
+       if (had_ctrlc())
+               setenv_ulong("safeboot", 1);
+       else if (prm_rstst & PRM_RSTST_WDT1_RST)
+               setenv_ulong("wdreset", 1);
+       else
+               karo_fdt_move_fdt();
 
        baseboard = getenv("baseboard");
        if (!baseboard)
@@ -956,7 +1007,7 @@ exit:
 }
 
 #ifdef CONFIG_DRIVER_TI_CPSW
-static void tx48_phy_init(char *name, int addr)
+static void tx48_phy_init(void)
 {
        debug("%s: Resetting ethernet PHY\n", __func__);
 
@@ -1005,7 +1056,6 @@ static struct cpsw_platform_data cpsw_data = {
        .hw_stats_reg_ofs       = 0x900,
        .mac_control            = (1 << 5) /* MIIEN */,
        .control                = cpsw_control,
-       .phy_init               = tx48_phy_init,
        .gigabit_en             = 0,
        .host_port_num          = 0,
        .version                = CPSW_CTRL_VERSION_2,
@@ -1015,6 +1065,7 @@ int board_eth_init(bd_t *bis)
 {
        __raw_writel(RMII_MODE_ENABLE, MAC_MII_SEL);
        __raw_writel(0x5D, GMII_SEL);
+       tx48_phy_init();
        return cpsw_register(&cpsw_data);
 }
 #endif /* CONFIG_DRIVER_TI_CPSW */
@@ -1085,7 +1136,7 @@ static const char *tx48_touchpanels[] = {
        "ti,am3359-tscadc",
 };
 
-void ft_board_setup(void *blob, bd_t *bd)
+int ft_board_setup(void *blob, bd_t *bd)
 {
        const char *baseboard = getenv("baseboard");
        int stk5_v5 = baseboard != NULL && (strcmp(baseboard, "stk5-v5") == 0);
@@ -1093,19 +1144,28 @@ void ft_board_setup(void *blob, bd_t *bd)
        int ret;
 
        ret = fdt_increase_size(blob, 4096);
-       if (ret)
+       if (ret) {
                printf("Failed to increase FDT size: %s\n", fdt_strerror(ret));
-
+               return ret;
+       }
        fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
        fdt_fixup_ethernet(blob);
 
        karo_fdt_fixup_touchpanel(blob, tx48_touchpanels,
                                ARRAY_SIZE(tx48_touchpanels));
-       karo_fdt_fixup_usb_otg(blob, "usb0", "phys");
+       karo_fdt_fixup_usb_otg(blob, "usb0", "phys", "vcc-supply");
        karo_fdt_fixup_flexcan(blob, stk5_v5);
 
        karo_fdt_update_fb_mode(blob, video_mode);
 
        tx48_disable_watchdog();
+
+       if (get_cpu_rev() == 0) {
+               karo_fdt_del_prop(blob, "lltc,ltc3589-2", 0x34, "interrupts");
+               karo_fdt_del_prop(blob, "lltc,ltc3589-2", 0x34,
+                               "interrupt-parent");
+       }
+
+       return 0;
 }
 #endif /* CONFIG_OF_BOARD_SETUP */