common: Move command functions out of common.h
[oweals/u-boot.git] / board / boundary / nitrogen6x / nitrogen6x.c
index 39e8013480664d46836cb5d28530bd5351129d7d..33653b594957551769d10ffe387cf5f445e89e49 100644 (file)
@@ -1,11 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) 2010-2013 Freescale Semiconductor, Inc.
  * Copyright (C) 2013, Boundary Devices <info@boundarydevices.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
+#include <env.h>
 #include <asm/io.h>
 #include <asm/arch/clock.h>
 #include <asm/arch/imx-regs.h>
 #include <asm/arch/sys_proto.h>
 #include <malloc.h>
 #include <asm/arch/mx6-pins.h>
-#include <asm/errno.h>
+#include <linux/errno.h>
 #include <asm/gpio.h>
-#include <asm/imx-common/iomux-v3.h>
-#include <asm/imx-common/mxc_i2c.h>
-#include <asm/imx-common/sata.h>
-#include <asm/imx-common/boot_mode.h>
-#include <asm/imx-common/video.h>
+#include <asm/mach-imx/iomux-v3.h>
+#include <asm/mach-imx/mxc_i2c.h>
+#include <asm/mach-imx/sata.h>
+#include <asm/mach-imx/spi.h>
+#include <asm/mach-imx/boot_mode.h>
+#include <asm/mach-imx/video.h>
 #include <mmc.h>
-#include <fsl_esdhc.h>
+#include <fsl_esdhc_imx.h>
 #include <micrel.h>
 #include <miiphy.h>
 #include <netdev.h>
@@ -30,7 +31,7 @@
 #include <i2c.h>
 #include <input.h>
 #include <netdev.h>
-#include <usb/ehci-fsl.h>
+#include <usb/ehci-ci.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 #define GP_USB_OTG_PWR IMX_GPIO_NR(3, 22)
@@ -283,7 +284,7 @@ int board_ehci_power(int port, int on)
 
 #endif
 
-#ifdef CONFIG_FSL_ESDHC
+#ifdef CONFIG_FSL_ESDHC_IMX
 static struct fsl_esdhc_cfg usdhc_cfg[2] = {
        {USDHC3_BASE_ADDR},
        {USDHC4_BASE_ADDR},
@@ -301,7 +302,7 @@ int board_mmc_getcd(struct mmc *mmc)
 
 int board_mmc_init(bd_t *bis)
 {
-       s32 status = 0;
+       int ret;
        u32 index = 0;
 
        usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
@@ -324,17 +325,24 @@ int board_mmc_init(bd_t *bis)
                       printf("Warning: you configured more USDHC controllers"
                               "(%d) then supported by the board (%d)\n",
                               index + 1, CONFIG_SYS_FSL_USDHC_NUM);
-                      return status;
+                      return -EINVAL;
                }
 
-               status |= fsl_esdhc_initialize(bis, &usdhc_cfg[index]);
+               ret = fsl_esdhc_initialize(bis, &usdhc_cfg[index]);
+               if (ret)
+                       return ret;
        }
 
-       return status;
+       return 0;
 }
 #endif
 
 #ifdef CONFIG_MXC_SPI
+int board_spi_cs_gpio(unsigned bus, unsigned cs)
+{
+       return (bus == 0 && cs == 0) ? (IMX_GPIO_NR(3, 19)) : -1;
+}
+
 static iomux_v3_cfg_t const ecspi1_pads[] = {
        /* SS1 */
        MX6_PAD_EIM_D19__GPIO3_IO19  | MUX_PAD_CTRL(NO_PAD_CTRL),
@@ -374,25 +382,31 @@ int board_eth_init(bd_t *bis)
        struct phy_device *phydev = NULL;
        int ret;
 
+       gpio_request(WL12XX_WL_IRQ_GP, "wifi_irq");
+       gpio_request(IMX_GPIO_NR(6, 30), "rgmii_rxc");
+       gpio_request(IMX_GPIO_NR(6, 25), "rgmii_rd0");
+       gpio_request(IMX_GPIO_NR(6, 27), "rgmii_rd1");
+       gpio_request(IMX_GPIO_NR(6, 28), "rgmii_rd2");
+       gpio_request(IMX_GPIO_NR(6, 29), "rgmii_rd3");
+       gpio_request(IMX_GPIO_NR(6, 24), "rgmii_rx_ctl");
+       gpio_request(IMX_GPIO_NR(3, 23), "rgmii_reset_sabrelite");
+       gpio_request(IMX_GPIO_NR(1, 27), "rgmii_reset_nitrogen6x");
        setup_iomux_enet();
 
 #ifdef CONFIG_FEC_MXC
        bus = fec_get_miibus(base, -1);
        if (!bus)
-               return 0;
+               return -EINVAL;
        /* scan phy 4,5,6,7 */
        phydev = phy_find_by_mask(bus, (0xf << 4), PHY_INTERFACE_MODE_RGMII);
        if (!phydev) {
-               free(bus);
-               return 0;
+               ret = -EINVAL;
+               goto free_bus;
        }
        printf("using phy at %d\n", phydev->addr);
        ret  = fec_probe(bis, -1, base, bus, phydev);
-       if (ret) {
-               printf("FEC MXC: %s:failed\n", __func__);
-               free(phydev);
-               free(bus);
-       }
+       if (ret)
+               goto free_phydev;
 #endif
 
 #ifdef CONFIG_CI_UDC
@@ -400,6 +414,12 @@ int board_eth_init(bd_t *bis)
        usb_eth_initialize(bis);
 #endif
        return 0;
+
+free_phydev:
+       free(phydev);
+free_bus:
+       free(bus);
+       return ret;
 }
 
 static void setup_buttons(void)
@@ -494,10 +514,10 @@ static void enable_rgb(struct display_info_t const *dev)
 }
 
 struct display_info_t const displays[] = {{
-       .bus    = -1,
-       .addr   = 0,
+       .bus    = 1,
+       .addr   = 0x50,
        .pixfmt = IPU_PIX_FMT_RGB24,
-       .detect = detect_hdmi,
+       .detect = detect_i2c,
        .enable = do_enable_hdmi,
        .mode   = {
                .name           = "HDMI",
@@ -533,6 +553,26 @@ struct display_info_t const displays[] = {{
                .vsync_len      = 10,
                .sync           = FB_SYNC_EXT,
                .vmode          = FB_VMODE_NONINTERLACED
+} }, {
+       .bus    = 0,
+       .addr   = 0,
+       .pixfmt = IPU_PIX_FMT_RGB24,
+       .detect = NULL,
+       .enable = enable_lvds,
+       .mode   = {
+               .name           = "LDB-WXGA-S",
+               .refresh        = 60,
+               .xres           = 1280,
+               .yres           = 800,
+               .pixclock       = 14065,
+               .left_margin    = 40,
+               .right_margin   = 40,
+               .upper_margin   = 3,
+               .lower_margin   = 80,
+               .hsync_len      = 10,
+               .vsync_len      = 10,
+               .sync           = FB_SYNC_EXT,
+               .vmode          = FB_VMODE_NONINTERLACED
 } }, {
        .bus    = 2,
        .addr   = 0x4,
@@ -553,6 +593,26 @@ struct display_info_t const displays[] = {{
                .vsync_len      = 10,
                .sync           = FB_SYNC_EXT,
                .vmode          = FB_VMODE_NONINTERLACED
+} }, {
+       .bus    = 0,
+       .addr   = 0,
+       .pixfmt = IPU_PIX_FMT_LVDS666,
+       .detect = NULL,
+       .enable = enable_lvds,
+       .mode   = {
+               .name           = "LG-9.7",
+               .refresh        = 60,
+               .xres           = 1024,
+               .yres           = 768,
+               .pixclock       = 15385, /* ~65MHz */
+               .left_margin    = 480,
+               .right_margin   = 260,
+               .upper_margin   = 16,
+               .lower_margin   = 6,
+               .hsync_len      = 250,
+               .vsync_len      = 10,
+               .sync           = FB_SYNC_EXT,
+               .vmode          = FB_VMODE_NONINTERLACED
 } }, {
        .bus    = 2,
        .addr   = 0x38,
@@ -573,6 +633,86 @@ struct display_info_t const displays[] = {{
                .vsync_len      = 10,
                .sync           = FB_SYNC_EXT,
                .vmode          = FB_VMODE_NONINTERLACED
+} }, {
+       .bus    = 2,
+       .addr   = 0x10,
+       .pixfmt = IPU_PIX_FMT_RGB666,
+       .detect = detect_i2c,
+       .enable = enable_rgb,
+       .mode   = {
+               .name           = "fusion7",
+               .refresh        = 60,
+               .xres           = 800,
+               .yres           = 480,
+               .pixclock       = 33898,
+               .left_margin    = 96,
+               .right_margin   = 24,
+               .upper_margin   = 3,
+               .lower_margin   = 10,
+               .hsync_len      = 72,
+               .vsync_len      = 7,
+               .sync           = 0x40000002,
+               .vmode          = FB_VMODE_NONINTERLACED
+} }, {
+       .bus    = 0,
+       .addr   = 0,
+       .pixfmt = IPU_PIX_FMT_RGB666,
+       .detect = NULL,
+       .enable = enable_rgb,
+       .mode   = {
+               .name           = "svga",
+               .refresh        = 60,
+               .xres           = 800,
+               .yres           = 600,
+               .pixclock       = 15385,
+               .left_margin    = 220,
+               .right_margin   = 40,
+               .upper_margin   = 21,
+               .lower_margin   = 7,
+               .hsync_len      = 60,
+               .vsync_len      = 10,
+               .sync           = 0,
+               .vmode          = FB_VMODE_NONINTERLACED
+} }, {
+       .bus    = 2,
+       .addr   = 0x41,
+       .pixfmt = IPU_PIX_FMT_LVDS666,
+       .detect = detect_i2c,
+       .enable = enable_lvds,
+       .mode   = {
+               .name           = "amp1024x600",
+               .refresh        = 60,
+               .xres           = 1024,
+               .yres           = 600,
+               .pixclock       = 15385,
+               .left_margin    = 220,
+               .right_margin   = 40,
+               .upper_margin   = 21,
+               .lower_margin   = 7,
+               .hsync_len      = 60,
+               .vsync_len      = 10,
+               .sync           = FB_SYNC_EXT,
+               .vmode          = FB_VMODE_NONINTERLACED
+} }, {
+       .bus    = 0,
+       .addr   = 0,
+       .pixfmt = IPU_PIX_FMT_LVDS666,
+       .detect = 0,
+       .enable = enable_lvds,
+       .mode   = {
+               .name           = "wvga-lvds",
+               .refresh        = 57,
+               .xres           = 800,
+               .yres           = 480,
+               .pixclock       = 15385,
+               .left_margin    = 220,
+               .right_margin   = 40,
+               .upper_margin   = 21,
+               .lower_margin   = 7,
+               .hsync_len      = 60,
+               .vsync_len      = 10,
+               .sync           = FB_SYNC_EXT,
+               .vmode          = FB_VMODE_NONINTERLACED
 } }, {
        .bus    = 2,
        .addr   = 0x48,
@@ -593,12 +733,32 @@ struct display_info_t const displays[] = {{
                .vsync_len      = 10,
                .sync           = 0,
                .vmode          = FB_VMODE_NONINTERLACED
+} }, {
+       .bus    = 0,
+       .addr   = 0,
+       .pixfmt = IPU_PIX_FMT_RGB24,
+       .detect = NULL,
+       .enable = enable_rgb,
+       .mode   = {
+               .name           = "qvga",
+               .refresh        = 60,
+               .xres           = 320,
+               .yres           = 240,
+               .pixclock       = 37037,
+               .left_margin    = 38,
+               .right_margin   = 37,
+               .upper_margin   = 16,
+               .lower_margin   = 15,
+               .hsync_len      = 30,
+               .vsync_len      = 3,
+               .sync           = 0,
+               .vmode          = FB_VMODE_NONINTERLACED
 } } };
 size_t display_count = ARRAY_SIZE(displays);
 
 int board_cfb_skip(void)
 {
-       return NULL != getenv("novideo");
+       return NULL != env_get("novideo");
 }
 
 static void setup_display(void)
@@ -752,7 +912,7 @@ int board_init(void)
        setup_i2c(1, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info1);
        setup_i2c(2, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info2);
 
-#ifdef CONFIG_CMD_SATA
+#ifdef CONFIG_SATA
        setup_sata();
 #endif
 
@@ -761,7 +921,16 @@ int board_init(void)
 
 int checkboard(void)
 {
-       if (gpio_get_value(WL12XX_WL_IRQ_GP))
+       int ret = gpio_get_value(WL12XX_WL_IRQ_GP);
+
+       if (ret < 0) {
+               /* The gpios have not been probed yet. Read it myself */
+               struct gpio_regs *regs = (struct gpio_regs *)GPIO6_BASE_ADDR;
+               int gpio = WL12XX_WL_IRQ_GP & 0x1f;
+
+               ret = (readl(&regs->gpio_psr) >> gpio) & 0x01;
+       }
+       if (ret)
                puts("Board: Nitrogen6X\n");
        else
                puts("Board: SABRE Lite\n");
@@ -803,7 +972,7 @@ static int do_kbd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
        char envvalue[ARRAY_SIZE(buttons)+1];
        int numpressed = read_keys(envvalue);
-       setenv("keybd", envvalue);
+       env_set("keybd", envvalue);
        return numpressed == 0;
 }
 
@@ -823,7 +992,7 @@ static void preboot_keys(void)
        char keypress[ARRAY_SIZE(buttons)+1];
        numpressed = read_keys(keypress);
        if (numpressed) {
-               char *kbd_magic_keys = getenv("magic_keys");
+               char *kbd_magic_keys = env_get("magic_keys");
                char *suffix;
                /*
                 * loop over all magic keys
@@ -832,7 +1001,7 @@ static void preboot_keys(void)
                        char *keys;
                        char magic[sizeof(kbd_magic_prefix) + 1];
                        sprintf(magic, "%s%c", kbd_magic_prefix, *suffix);
-                       keys = getenv(magic);
+                       keys = env_get(magic);
                        if (keys) {
                                if (!strcmp(keys, keypress))
                                        break;
@@ -842,9 +1011,9 @@ static void preboot_keys(void)
                        char cmd_name[sizeof(kbd_command_prefix) + 1];
                        char *cmd;
                        sprintf(cmd_name, "%s%c", kbd_command_prefix, *suffix);
-                       cmd = getenv(cmd_name);
+                       cmd = env_get(cmd_name);
                        if (cmd) {
-                               setenv("preboot", cmd);
+                               env_set("preboot", cmd);
                                return;
                        }
                }
@@ -863,6 +1032,16 @@ static const struct boot_mode board_boot_modes[] = {
 
 int misc_init_r(void)
 {
+       gpio_request(RGB_BACKLIGHT_GP, "lvds backlight");
+       gpio_request(LVDS_BACKLIGHT_GP, "lvds backlight");
+       gpio_request(GP_USB_OTG_PWR, "usbotg power");
+       gpio_request(IMX_GPIO_NR(7, 12), "usbh1 hub reset");
+       gpio_request(IMX_GPIO_NR(2, 2), "back");
+       gpio_request(IMX_GPIO_NR(2, 4), "home");
+       gpio_request(IMX_GPIO_NR(2, 1), "menu");
+       gpio_request(IMX_GPIO_NR(2, 3), "search");
+       gpio_request(IMX_GPIO_NR(7, 13), "volup");
+       gpio_request(IMX_GPIO_NR(4, 5), "voldown");
 #ifdef CONFIG_PREBOOT
        preboot_keys();
 #endif
@@ -870,5 +1049,6 @@ int misc_init_r(void)
 #ifdef CONFIG_CMD_BMODE
        add_board_boot_modes(board_boot_modes);
 #endif
+       env_set_hex("reset_cause", get_imx_reset_cause());
        return 0;
 }