imx: ventana: add dt fixup for watchdog external reset
[oweals/u-boot.git] / board / gateworks / gw_ventana / gw_ventana.c
index b3390a17b92606b559df955693d8332de10f79a7..5d871ceed91a882db6f4cd6ac8418335f96d541b 100644 (file)
@@ -700,13 +700,14 @@ static const struct boot_mode board_boot_modes[] = {
 int misc_init_r(void)
 {
        struct ventana_board_info *info = &ventana_info;
+       char buf[256];
+       int i;
 
        /* set env vars based on EEPROM data */
        if (ventana_info.model[0]) {
                char str[16], fdt[36];
                char *p;
                const char *cputype = "";
-               int i;
 
                /*
                 * FDT name will be prefixed with CPU type.  Three versions
@@ -769,6 +770,19 @@ int misc_init_r(void)
                setenv("mem_mb", str);
        }
 
+       /* Set a non-initialized hwconfig based on board configuration */
+       if (!strcmp(getenv("hwconfig"), "_UNKNOWN_")) {
+               sprintf(buf, "hwconfig=");
+               if (gpio_cfg[board_type].rs232_en)
+                       strcat(buf, "rs232;");
+               for (i = 0; i < gpio_cfg[board_type].dio_num; i++) {
+                       char buf1[32];
+                       sprintf(buf1, "dio%d:mode=gpio;", i);
+                       if (strlen(buf) + strlen(buf1) < sizeof(buf))
+                               strcat(buf, buf1);
+               }
+               setenv("hwconfig", buf);
+       }
 
        /* setup baseboard specific GPIO based on board and env */
        setup_board_gpio(board_type, info);
@@ -1069,6 +1083,10 @@ void ft_board_pci_fixup(void *blob, bd_t *bd)
  *  - board (full model from EEPROM)
  *  - peripherals removed from DTB if not loaded on board (per EEPROM config)
  */
+#define UART1_PATH     "/soc/aips-bus@02100000/serial@021ec000"
+#define WDOG1_PATH     "/soc/aips-bus@02000000/wdog@020bc000"
+#define WDOG2_PATH     "/soc/aips-bus@02000000/wdog@020c0000"
+#define GPIO3_PATH     "/soc/aips-bus@02000000/gpio@020a4000"
 int ft_board_setup(void *blob, bd_t *bd)
 {
        struct ventana_board_info *info = &ventana_info;
@@ -1122,94 +1140,140 @@ int ft_board_setup(void *blob, bd_t *bd)
        ft_sethdmiinfmt(blob, getenv("hdmiinfmt"));
 
        /*
-        * disable serial2 node for GW54xx for compatibility with older
-        * 3.10.x kernel that improperly had this node enabled in the DT
+        * Board model specific fixups
         */
-       if (board_type == GW54xx) {
-               i = fdt_path_offset(blob,
-                                   "/soc/aips-bus@02100000/serial@021ec000");
-               if (i)
-                       fdt_del_node(blob, i);
-       }
-
-       /*
-        * disable wdog1/wdog2 nodes for GW51xx below revC to work around
-        * errata causing wdog timer to be unreliable.
-        */
-       if (board_type == GW51xx && rev >= 'A' && rev < 'C') {
-               i = fdt_path_offset(blob,
-                                   "/soc/aips-bus@02000000/wdog@020bc000");
-               if (i)
-                       fdt_status_disabled(blob, i);
-       }
+       switch (board_type) {
+       case GW51xx:
+               /*
+                * disable wdog node for GW51xx-A/B to work around
+                * errata causing wdog timer to be unreliable.
+                */
+               if (rev >= 'A' && rev < 'C') {
+                       i = fdt_path_offset(blob, WDOG1_PATH);
+                       if (i)
+                               fdt_status_disabled(blob, i);
+               }
 
-       /* GW522x Uses GPIO3_IO23 instead of GPIO1_IO29 */
-       else if (board_type == GW52xx && info->model[4] == '2') {
-               u32 handle = 0;
-               u32 *range = NULL;
+               /* GW51xx-E adds WDOG1_B external reset */
+               if (rev < 'E')
+                       ft_delprop_path(blob, WDOG1_PATH,
+                                       "fsl,ext-reset-output");
+               break;
 
-               i = fdt_node_offset_by_compatible(blob, -1, "fsl,imx6q-pcie");
-               if (i)
-                       range = (u32 *)fdt_getprop(blob, i, "reset-gpio",
-                                                  NULL);
+       case GW52xx:
+               /* GW522x Uses GPIO3_IO23 instead of GPIO1_IO29 */
+               if (info->model[4] == '2') {
+                       u32 handle = 0;
+                       u32 *range = NULL;
 
-               if (range) {
-                       i = fdt_path_offset(blob,
-                                           "/soc/aips-bus@02000000/gpio@020a4000");
+                       i = fdt_node_offset_by_compatible(blob, -1,
+                                                         "fsl,imx6q-pcie");
                        if (i)
-                               handle = fdt_get_phandle(blob, i);
-                       if (handle) {
-                               range[0] = cpu_to_fdt32(handle);
-                               range[1] = cpu_to_fdt32(23);
+                               range = (u32 *)fdt_getprop(blob, i,
+                                                          "reset-gpio", NULL);
+
+                       if (range) {
+                               i = fdt_path_offset(blob, GPIO3_PATH);
+                               if (i)
+                                       handle = fdt_get_phandle(blob, i);
+                               if (handle) {
+                                       range[0] = cpu_to_fdt32(handle);
+                                       range[1] = cpu_to_fdt32(23);
+                               }
                        }
-               }
 
-               /* these have broken usd_vsel */
-               if (strstr((const char *)info->model, "SP318-B") ||
-                   strstr((const char *)info->model, "SP331-B"))
-                       gpio_cfg[board_type].usd_vsel = 0;
-       }
+                       /* these have broken usd_vsel */
+                       if (strstr((const char *)info->model, "SP318-B") ||
+                           strstr((const char *)info->model, "SP331-B"))
+                               gpio_cfg[board_type].usd_vsel = 0;
 
-       /*
-        * isolate CSI0_DATA_EN for GW551x below revB to work around
-        * errata causing non functional digital video in (it is not hooked up)
-        */
-       else if (board_type == GW551x && rev == 'A') {
-               u32 *range = NULL;
-               int len;
-               const u32 *handle = NULL;
+                       /* GW520x-E adds WDOG1_B external reset */
+                       if (info->model[4] == '0' && rev < 'E')
+                               ft_delprop_path(blob, WDOG1_PATH,
+                                               "fsl,ext-reset-output");
 
-               i = fdt_node_offset_by_compatible(blob, -1,
-                                                 "fsl,imx-tda1997x-video");
-               if (i)
-                       handle = fdt_getprop(blob, i, "pinctrl-0", NULL);
-               if (handle)
-                       i = fdt_node_offset_by_phandle(blob,
-                                                      fdt32_to_cpu(*handle));
+                       /* GW522x-B adds WDOG1_B external reset */
+                       if (info->model[4] == '2' && rev < 'B')
+                               ft_delprop_path(blob, WDOG1_PATH,
+                                               "fsl,ext-reset-output");
+               }
+               break;
+
+       case GW53xx:
+               /* GW53xx-E adds WDOG1_B external reset */
+               if (rev < 'E')
+                       ft_delprop_path(blob, WDOG1_PATH,
+                                       "fsl,ext-reset-output");
+               break;
+
+       case GW54xx:
+               /*
+                * disable serial2 node for GW54xx for compatibility with older
+                * 3.10.x kernel that improperly had this node enabled in the DT
+                */
+               i = fdt_path_offset(blob, UART1_PATH);
                if (i)
-                       range = (u32 *)fdt_getprop(blob, i, "fsl,pins", &len);
-               if (range) {
-                       len /= sizeof(u32);
-                       for (i = 0; i < len; i += 6) {
-                               u32 mux_reg = fdt32_to_cpu(range[i+0]);
-                               u32 conf_reg = fdt32_to_cpu(range[i+1]);
-                               /* mux PAD_CSI0_DATA_EN to GPIO */
-                               if (is_cpu_type(MXC_CPU_MX6Q) &&
-                                   mux_reg == 0x260 && conf_reg == 0x630)
-                                       range[i+3] = cpu_to_fdt32(0x5);
-                               else if (!is_cpu_type(MXC_CPU_MX6Q) &&
-                                   mux_reg == 0x08c && conf_reg == 0x3a0)
-                                       range[i+3] = cpu_to_fdt32(0x5);
+                       fdt_del_node(blob, i);
+
+               /* GW54xx-E adds WDOG2_B external reset */
+               if (rev < 'E')
+                       ft_delprop_path(blob, WDOG2_PATH,
+                                       "fsl,ext-reset-output");
+               break;
+
+       case GW551x:
+               /*
+                * isolate CSI0_DATA_EN for GW551x-A to work around errata
+                * causing non functional digital video in (it is not hooked up)
+                */
+               if (rev == 'A') {
+                       u32 *range = NULL;
+                       int len;
+                       const u32 *handle = NULL;
+
+                       i = fdt_node_offset_by_compatible(blob, -1,
+                                               "fsl,imx-tda1997x-video");
+                       if (i)
+                               handle = fdt_getprop(blob, i, "pinctrl-0",
+                                                    NULL);
+                       if (handle)
+                               i = fdt_node_offset_by_phandle(blob,
+                                                       fdt32_to_cpu(*handle));
+                       if (i)
+                               range = (u32 *)fdt_getprop(blob, i, "fsl,pins",
+                                                          &len);
+                       if (range) {
+                               len /= sizeof(u32);
+                               for (i = 0; i < len; i += 6) {
+                                       u32 mux_reg = fdt32_to_cpu(range[i+0]);
+                                       u32 conf_reg = fdt32_to_cpu(range[i+1]);
+                                       /* mux PAD_CSI0_DATA_EN to GPIO */
+                                       if (is_cpu_type(MXC_CPU_MX6Q) &&
+                                           mux_reg == 0x260 &&
+                                           conf_reg == 0x630)
+                                               range[i+3] = cpu_to_fdt32(0x5);
+                                       else if (!is_cpu_type(MXC_CPU_MX6Q) &&
+                                                mux_reg == 0x08c &&
+                                                conf_reg == 0x3a0)
+                                               range[i+3] = cpu_to_fdt32(0x5);
+                               }
+                               fdt_setprop_inplace(blob, i, "fsl,pins", range,
+                                                   len);
                        }
-                       fdt_setprop_inplace(blob, i, "fsl,pins", range, len);
+
+                       /* set BT656 video format */
+                       ft_sethdmiinfmt(blob, "yuv422bt656");
                }
 
-               /* set BT656 video format */
-               ft_sethdmiinfmt(blob, "yuv422bt656");
+               /* GW551x-C adds WDOG1_B external reset */
+               if (rev < 'C')
+                       ft_delprop_path(blob, WDOG1_PATH,
+                                       "fsl,ext-reset-output");
+               break;
        }
 
        /* Configure DIO */
-       for (i = 0; i < gpio_cfg[board_type].num_gpios; i++) {
+       for (i = 0; i < gpio_cfg[board_type].dio_num; i++) {
                struct dio_cfg *cfg = &gpio_cfg[board_type].dio_cfg[i];
                char arg[10];