]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - board/karo/common/fdt.c
karo: fdt: fix error handling for reg-can-xcvr
[karo-tx-uboot.git] / board / karo / common / fdt.c
index 997239a04acd4b9c7e81d5810cbc358a6502b3a2..fe3520b8639bcdcb50e51fd6aba7ad912369c707 100644 (file)
@@ -51,7 +51,11 @@ static void karo_set_fdtsize(void *fdt)
 static void *karo_fdt_load_dtb(void)
 {
        int ret;
-       void *fdt = (void *)getenv_ulong("fdtaddr", 16, CONFIG_SYS_FDT_ADDR);
+       void *fdt;
+
+       if (getenv("fdtaddr") == NULL)
+               setenv_hex("fdtaddr", CONFIG_SYS_FDT_ADDR);
+       fdt = (void *)getenv_ulong("fdtaddr", 16, CONFIG_SYS_FDT_ADDR);
 
        if (had_ctrlc()) {
                printf("aborting DTB load\n");
@@ -119,7 +123,7 @@ void karo_fdt_move_fdt(void)
                        fdt_addr, fdt_addr + fdt_totalsize(fdt) - 1);
                memmove((void *)fdt_addr, fdt, fdt_totalsize(fdt));
        }
-       set_working_fdt_addr((void *)fdt_addr);
+       set_working_fdt_addr(fdt_addr);
        gd->fdt_blob = fdt;
        karo_set_fdtsize(fdt);
 }
@@ -381,11 +385,15 @@ void karo_fdt_fixup_flexcan(void *blob, int xcvr_present)
                if (karo_fdt_flexcan_enabled(blob)) {
                        if (!is_lvds()) {
                                debug("Changing LCD to use 23bits only\n");
+                               karo_fdt_set_lcd_pins(blob, "lcdif-23bit-pins-a");
+                               /* handle legacy alias name */
                                karo_fdt_set_lcd_pins(blob, "lcdif_23bit_pins_a");
                                xcvr_status = NULL;
                        }
                } else if (!is_lvds()) {
                        debug("Changing LCD to use 24bits\n");
+                       karo_fdt_set_lcd_pins(blob, "lcdif-24bit-pins-a");
+                       /* handle legacy alias name */
                        karo_fdt_set_lcd_pins(blob, "lcdif_24bit_pins_a");
                }
        } else {
@@ -396,8 +404,11 @@ void karo_fdt_fixup_flexcan(void *blob, int xcvr_present)
                off = fdt_path_offset(blob, "can1");
                if (off >= 0)
                        fdt_delprop(blob, off, "xceiver-supply");
-               if (!is_lvds())
+               if (!is_lvds()) {
+                       karo_fdt_set_lcd_pins(blob, "lcdif-24bit-pins-a");
+                       /* handle legacy alias name */
                        karo_fdt_set_lcd_pins(blob, "lcdif_24bit_pins_a");
+               }
        }
 
        if (otg_mode && strcasecmp(otg_mode, "host") == 0)
@@ -405,9 +416,12 @@ void karo_fdt_fixup_flexcan(void *blob, int xcvr_present)
 
        if (xcvr_status) {
                debug("Disabling CAN XCVR\n");
-               ret = fdt_find_and_setprop(blob, "reg_can_xcvr", "status",
+               ret = fdt_find_and_setprop(blob, "reg-can-xcvr", "status",
                                        xcvr_status, strlen(xcvr_status) + 1, 1);
-               if (ret)
+               if (ret == -FDT_ERR_NOTFOUND || ret == -FDT_ERR_BADPATH)
+                       ret = fdt_find_and_setprop(blob, "reg_can_xcvr", "status",
+                                                  xcvr_status, strlen(xcvr_status) + 1, 1);
+               if (ret && ret != -FDT_ERR_NOTFOUND && ret != -FDT_ERR_BADPATH)
                        printf("Failed to disable CAN transceiver switch: %s\n",
                                fdt_strerror(ret));
        }
@@ -549,15 +563,27 @@ static int karo_fdt_find_video_timings(void *blob)
        return off;
 }
 
-int karo_fdt_get_fb_mode(void *blob, const char *name, struct fb_videomode *fb_mode)
+static int karo_fdt_check_panel_name(const char *pn, const char *name, int len)
 {
-       int off = karo_fdt_find_video_timings(blob);
+       const char *endp = pn + len;
 
-       if (off < 0)
-               return off;
+       if (len < 0)
+               return 0;
+       while (pn < endp) {
+               if (strcasecmp(pn, name) == 0)
+                       return 1;
+               pn += strlen(pn) + 1;
+       }
+       return 0;
+}
+
+static int karo_fdt_find_panel(const void *blob, int off, const char *name)
+{
+       debug("Searching panel '%s'\n", name);
        while (off > 0) {
-               const char *n, *endp;
-               int len, d = 1;
+               const char *pn;
+               int d = 1;
+               int len;
 
                off = fdt_next_node(blob, off, &d);
                if (off < 0)
@@ -570,28 +596,30 @@ int karo_fdt_get_fb_mode(void *blob, const char *name, struct fb_videomode *fb_m
                        continue;
                }
 
-               n = fdt_getprop(blob, off, "panel-name", &len);
-               if (!n) {
-                       n = fdt_get_name(blob, off, NULL);
-                       if (strcasecmp(n, name) == 0) {
-                               break;
-                       }
-               } else {
-                       int found = 0;
-
-                       for (endp = n + len; n < endp; n += strlen(n) + 1) {
-                               debug("Checking panel-name '%s'\n", n);
-                               if (strcasecmp(n, name) == 0) {
-                                       debug("Using node %s @ %04x\n",
-                                               fdt_get_name(blob, off, NULL), off);
-                                       found = 1;
-                                       break;
-                               }
-                       }
-                       if (found)
-                               break;
-               }
+               pn = fdt_get_name(blob, off, NULL);
+               debug("Checking node name '%s'\n", pn);
+               if (strcasecmp(pn, name) == 0)
+                       break;
+               pn = fdt_getprop(blob, off, "u-boot,panel-name", &len);
+               if (!pn)
+                       continue;
+               if (karo_fdt_check_panel_name(pn, name, len))
+                       break;
        }
+       if (off > 0)
+               debug("Found LCD panel: '%s' @ off %03x\n",
+                     fdt_get_name(blob, off, NULL), off);
+       return off;
+}
+
+int karo_fdt_get_fb_mode(void *blob, const char *name,
+                        struct fb_videomode *fb_mode)
+{
+       int off = karo_fdt_find_video_timings(blob);
+
+       if (off < 0)
+               return off;
+       off = karo_fdt_find_panel(blob, off, name);
        if (off > 0) {
                return fdt_init_fb_mode(blob, off, fb_mode);
        }
@@ -694,21 +722,36 @@ out:
        return ret;
 }
 
-int karo_fdt_update_fb_mode(void *blob, const char *name)
+int karo_fdt_update_fb_mode(void *blob, const char *name,
+                           const char *panel_name)
 {
+       int ret;
        int off = fdt_path_offset(blob, "display");
+       int panel_off = -1;
        const char *subnode = "display-timings";
 
-       if (off < 0)
+       if (panel_name)
+               panel_off = fdt_path_offset(blob, panel_name);
+
+       if (off < 0 && panel_off < 0)
                return off;
 
        if (name == NULL) {
-               int ret;
-
                debug("Disabling node '%s' at %03x\n",
                        fdt_get_name(blob, off, NULL), off);
                ret = fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0);
-               return ret;
+               if (ret)
+                       printf("Failed to disable node '%s': %s\n",
+                              fdt_get_name(blob, off, NULL),
+                              fdt_strerror(ret));
+               if (!panel_name)
+                       return ret;
+
+               panel_off = fdt_path_offset(blob, panel_name);
+               if (panel_off < 0)
+                       return 0;
+               return fdt_set_node_status(blob, panel_off,
+                                          FDT_STATUS_DISABLED, 0);
        }
 
        off = fdt_subnode_offset(blob, off, subnode);
@@ -717,46 +760,41 @@ int karo_fdt_update_fb_mode(void *blob, const char *name)
                        fdt_strerror(off));
                return off;
        }
-       while (off > 0) {
-               const char *n, *endp;
-               int len, d = 1;
-
-               off = fdt_next_node(blob, off, &d);
-               if (off < 0)
-                       return off;
-               if (d < 1)
-                       return -EINVAL;
-               if (d > 2) {
-                       debug("Skipping node @ %04x %s depth %d\n", off,
-                               fdt_get_name(blob, off, NULL), d);
-                       continue;
-               }
+       off = karo_fdt_find_panel(blob, off, name);
+       if (off > 0)
+               ret = fdt_update_native_fb_mode(blob, off);
+       else
+               ret = 0;
+       if (!panel_name)
+               return ret;
 
-               n = fdt_getprop(blob, off, "panel-name", &len);
-               if (!n) {
-                       n = fdt_get_name(blob, off, NULL);
-                       if (strcasecmp(n, name) == 0) {
-                               break;
-                       }
-               } else {
-                       int found = 0;
-
-                       for (endp = n + len; n < endp; n += strlen(n) + 1) {
-                               debug("Checking panel-name '%s'\n", n);
-                               if (strcasecmp(n, name) == 0) {
-                                       debug("Using node %s @ %04x\n",
-                                               fdt_get_name(blob, off, NULL), off);
-                                       found = 1;
-                                       break;
-                               }
-                       }
-                       if (found)
-                               break;
-               }
+       off = fdt_path_offset(blob, "display/display-timings");
+       off = karo_fdt_find_panel(blob, off, name);
+       panel_off = fdt_path_offset(blob, panel_name);
+       if (panel_off > 0) {
+               char *pn;
+
+               name = fdt_getprop(blob, off, "u-boot,panel-name",
+                                  NULL);
+               if (!name)
+                       return 0;
+               pn = strdup(name);
+               if (!pn)
+                       return -ENOMEM;
+               debug("%s@%d: Updating 'compatible' property of '%s' from '%s' to '%s'\n",
+                     __func__, __LINE__, fdt_get_name(blob, panel_off, NULL),
+                     (char *)fdt_getprop(blob, panel_off, "compatible", NULL),
+                     pn);
+
+               ret = fdt_setprop_string(blob, panel_off, "compatible",
+                                        pn);
+               if (ret)
+                       printf("Failed to set 'compatible' property of node '%s': %s\n",
+                              fdt_get_name(blob, panel_off, NULL),
+                              fdt_strerror(off));
+               free(pn);
        }
-       if (off > 0)
-               return fdt_update_native_fb_mode(blob, off);
-       return off;
+       return ret;
 }
 
 #ifdef CONFIG_SYS_LVDS_IF