]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/karo/common/fdt.c
karo: tx6: add support for TX6-V2 (eMMC)
[karo-tx-uboot.git] / board / karo / common / fdt.c
1 /*
2  * (C) Copyright 2012,2013 Lothar Waßmann <LW@KARO-electronics.de>
3  *
4  * See file CREDITS for list of people who contributed to this
5  * project.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * version 2 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16 */
17
18 #include <common.h>
19 #include <errno.h>
20 #include <libfdt.h>
21 #include <fdt_support.h>
22 #include <nand.h>
23 #include <mxcfb.h>
24 #include <linux/list.h>
25 #include <linux/fb.h>
26 #include <jffs2/load_kernel.h>
27 #include <malloc.h>
28
29 #include "karo.h"
30
31 #ifdef CONFIG_MAX_DTB_SIZE
32 #define MAX_DTB_SIZE    CONFIG_MAX_DTB_SIZE
33 #else
34 #define MAX_DTB_SIZE    SZ_64K
35 #endif
36
37 DECLARE_GLOBAL_DATA_PTR;
38
39 static void karo_set_fdtsize(void *fdt)
40 {
41         size_t fdtsize = getenv_ulong("fdtsize", 16, 0);
42
43         if (fdtsize == fdt_totalsize(fdt)) {
44                 return;
45         }
46         debug("FDT size changed from %u to %u\n",
47                 fdtsize, fdt_totalsize(fdt));
48         setenv_hex("fdtsize", fdt_totalsize(fdt));
49 }
50
51 static void *karo_fdt_load_dtb(void)
52 {
53         int ret;
54         void *fdt = (void *)getenv_ulong("fdtaddr", 16, CONFIG_SYS_FDT_ADDR);
55
56         if (had_ctrlc()) {
57                 printf("aborting DTB load\n");
58                 return NULL;
59         }
60
61         /* clear FDT header in memory */
62         memset(fdt, 0, 4);
63
64         ret = karo_load_part("dtb", fdt, MAX_DTB_SIZE);
65         if (ret) {
66                 printf("Failed to load dtb from flash: %d\n", ret);
67                 return NULL;
68         }
69
70         if (fdt_check_header(fdt)) {
71                 debug("No valid DTB in flash\n");
72                 return NULL;
73         }
74         debug("Using DTB from flash\n");
75         karo_set_fdtsize(fdt);
76         return fdt;
77 }
78
79 void karo_fdt_move_fdt(void)
80 {
81         void *fdt;
82         unsigned long fdt_addr = getenv_ulong("fdtaddr", 16, 0);
83
84         if (working_fdt) {
85                 debug("DTB already loaded\n");
86                 return;
87         }
88
89         setenv("fdtsize", 0);
90
91         if (!fdt_addr) {
92                 fdt_addr = CONFIG_SYS_FDT_ADDR;
93                 printf("fdtaddr is not set; using default: %08lx\n",
94                         fdt_addr);
95         }
96
97         fdt = karo_fdt_load_dtb();
98         if (fdt == NULL) {
99                 fdt = (void *)gd->fdt_blob;
100                 if (fdt == NULL) {
101 #ifdef CONFIG_OF_EMBED
102                         printf("Compiled in FDT not found");
103 #else
104                         printf("No FDT found");
105 #endif
106                         printf("; creating empty DTB\n");
107                         fdt = (void *)fdt_addr;
108                         fdt_create_empty_tree(fdt, 256);
109                 } else {
110                         printf("No DTB in flash; using default DTB\n");
111                 }
112                 debug("Checking FDT header @ %p\n", fdt);
113                 if (fdt_check_header(fdt)) {
114                         printf("ERROR: No valid DTB found at %p\n", fdt);
115                         return;
116                 }
117                 debug("Moving FDT from %p..%p to %08lx..%08lx\n",
118                         fdt, fdt + fdt_totalsize(fdt) - 1,
119                         fdt_addr, fdt_addr + fdt_totalsize(fdt) - 1);
120                 memmove((void *)fdt_addr, fdt, fdt_totalsize(fdt));
121         }
122         set_working_fdt_addr((void *)fdt_addr);
123         gd->fdt_blob = fdt;
124         karo_set_fdtsize(fdt);
125 }
126
127 void karo_fdt_remove_node(void *blob, const char *node)
128 {
129         int off = fdt_path_offset(blob, node);
130         int ret;
131
132         debug("Removing node '%s' from DT\n", node);
133
134         if (off < 0) {
135                 printf("Could not find node '%s': %s\n", node,
136                         fdt_strerror(off));
137         } else {
138                 ret = fdt_del_node(blob, off);
139                 if (ret)
140                         printf("Failed to remove node '%s': %s\n",
141                                 node, fdt_strerror(ret));
142         }
143         karo_set_fdtsize(blob);
144 }
145
146 void karo_fdt_enable_node(void *blob, const char *node, int enable)
147 {
148         int off = fdt_path_offset(blob, node);
149
150         debug("%sabling node '%s'\n", enable ? "En" : "Dis", node);
151         if (off < 0) {
152                 printf("Could not find node '%s': %s\n", node,
153                         fdt_strerror(off));
154                 return;
155         }
156         fdt_set_node_status(blob, off,
157                         enable ? FDT_STATUS_OKAY : FDT_STATUS_DISABLED, 0);
158
159         karo_set_fdtsize(blob);
160 }
161
162 static void fdt_disable_tp_node(void *blob, const char *name)
163 {
164         int offs = fdt_node_offset_by_compatible(blob, -1, name);
165
166         while (offs >= 0) {
167                 debug("Disabling node '%s'\n", name);
168                 fdt_set_node_status(blob, offs, FDT_STATUS_DISABLED, 0);
169                 offs = fdt_node_offset_by_compatible(blob, offs, name);
170         }
171 }
172
173 void karo_fdt_fixup_touchpanel(void *blob, const char *panels[],
174                         size_t num_panels)
175 {
176         int i;
177         const char *model = getenv("touchpanel");
178
179         for (i = 0; i < num_panels; i++) {
180                 const char *tp = panels[i];
181
182                 if (model != NULL) {
183                         if (strcmp(model, tp) == 0)
184                                 continue;
185                         while (tp != NULL) {
186                                 if (*tp != '\0' && strcmp(model, tp + 1) == 0)
187                                         break;
188                                 tp = strpbrk(tp + 1, ",-");
189                         }
190                         if (tp != NULL)
191                                 continue;
192                 }
193                 fdt_disable_tp_node(blob, panels[i]);
194         }
195         karo_set_fdtsize(blob);
196 }
197
198 static int karo_fdt_disable_node_phandle(void *blob, const char *parent,
199                                         const char *name)
200 {
201         const uint32_t *ph;
202         int off;
203
204         off = fdt_path_offset(blob, parent);
205         if (off < 0) {
206                 printf("Failed to find node '%s'\n", parent);
207                 return off;
208         }
209
210         ph = fdt_getprop(blob, off, name, NULL);
211         if (ph == NULL) {
212                 printf("Failed to find '%s' phandle in node '%s'\n", name,
213                         fdt_get_name(blob, off, NULL));
214                 return -FDT_ERR_NOTFOUND;
215         }
216
217         off = fdt_node_offset_by_phandle(blob, fdt32_to_cpu(*ph));
218         if (off <= 0) {
219                 printf("Failed to find '%s' node via phandle %04x\n",
220                         name, fdt32_to_cpu(*ph));
221                 return -FDT_ERR_NOTFOUND;
222         }
223         return fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0);
224 }
225
226 void karo_fdt_fixup_usb_otg(void *blob, const char *node, const char *phy)
227 {
228         const char *otg_mode = getenv("otg_mode");
229         int off;
230         int ret;
231         int disable_otg = 0;
232         int disable_phy_pins = 1;
233
234         debug("OTG mode is '%s'\n", otg_mode ? otg_mode : "<UNSET>");
235
236         off = fdt_path_offset(blob, node);
237         if (off < 0) {
238                 debug("Failed to find node %s\n", node);
239                 return;
240         }
241
242         if (otg_mode && (strcmp(otg_mode, "device") == 0 ||
243                                 strcmp(otg_mode, "gadget") == 0)) {
244                 debug("Setting dr_mode to 'peripheral'\n");
245                 ret = fdt_setprop_string(blob, off, "dr_mode", "peripheral");
246         } else if (otg_mode && strcmp(otg_mode, "host") == 0) {
247                 debug("Setting dr_mode to 'host'\n");
248                 ret = fdt_setprop_string(blob, off, "dr_mode", "host");
249                 disable_phy_pins = 0;
250         } else if (otg_mode && strcmp(otg_mode, "otg") == 0) {
251                 debug("Setting dr_mode to 'host'\n");
252                 ret = fdt_setprop_string(blob, off, "dr_mode", "otg");
253         } else {
254                 if (otg_mode && strcmp(otg_mode, "none") != 0)
255                         printf("Invalid 'otg_mode' setting '%s'; disabling usbotg port\n",
256                                 otg_mode);
257                 disable_otg = 1;
258                 ret = 0;
259         }
260
261         if ((!disable_phy_pins && !disable_otg) || ret)
262                 goto out;
263
264         ret = karo_fdt_disable_node_phandle(blob, node, "vbus-supply");
265         if (ret)
266                 goto out;
267
268         if (disable_otg) {
269                 debug("Disabling usbphy\n");
270                 ret = fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0);
271                 if (ret)
272                         goto out;
273
274                 ret = karo_fdt_disable_node_phandle(blob, node, phy);
275         }
276 out:
277         if (ret)
278                 printf("Failed to update usbotg: %s\n", fdt_strerror(ret));
279         else
280                 debug("node '%s' updated\n", node);
281         karo_set_fdtsize(blob);
282 }
283
284 static inline int karo_fdt_flexcan_enabled(void *blob)
285 {
286         static const char *can_ifs[] = {
287                 "can0",
288                 "can1",
289         };
290         size_t i;
291
292         for (i = 0; i < ARRAY_SIZE(can_ifs); i++) {
293                 const char *status;
294                 int off = fdt_path_offset(blob, can_ifs[i]);
295
296                 if (off < 0) {
297                         debug("node '%s' not found\n", can_ifs[i]);
298                         continue;
299                 }
300                 status = fdt_getprop(blob, off, "status", NULL);
301                 if (status && strcmp(status, "okay") == 0) {
302                         debug("%s is enabled\n", can_ifs[i]);
303                         return 1;
304                 }
305         }
306         debug("can driver is disabled\n");
307         return 0;
308 }
309
310 static inline void karo_fdt_set_lcd_pins(void *blob, const char *name)
311 {
312         int off = fdt_path_offset(blob, name);
313         u32 ph;
314         const struct fdt_property *pc;
315         int len;
316
317         if (off < 0)
318                 return;
319
320         ph = fdt_create_phandle(blob, off);
321         if (!ph)
322                 return;
323
324         off = fdt_path_offset(blob, "display");
325         if (off < 0)
326                 return;
327
328         pc = fdt_get_property(blob, off, "pinctrl-0", &len);
329         if (!pc || len < sizeof(ph))
330                 return;
331
332         memcpy((void *)pc->data, &ph, sizeof(ph));
333         fdt_setprop_cell(blob, off, "pinctrl-0", ph);
334 }
335
336 void karo_fdt_fixup_flexcan(void *blob, int xcvr_present)
337 {
338         int ret;
339         const char *xcvr_status = xcvr_present ? "disabled" : NULL;
340         const char *otg_mode = getenv("otg_mode");
341
342 #ifndef CONFIG_SYS_LVDS_IF
343         if (xcvr_present) {
344                 if (karo_fdt_flexcan_enabled(blob)) {
345                         karo_fdt_set_lcd_pins(blob, "lcdif_23bit_pins_a");
346                         xcvr_status = NULL;
347                 } else {
348                         karo_fdt_set_lcd_pins(blob, "lcdif_24bit_pins_a");
349                 }
350         } else {
351                 karo_fdt_set_lcd_pins(blob, "lcdif_24bit_pins_a");
352         }
353 #endif
354         if (otg_mode && strcmp(otg_mode, "host") == 0)
355                 karo_fdt_enable_node(blob, "can1", 0);
356
357         if (xcvr_status) {
358                 debug("Disabling CAN XCVR\n");
359                 ret = fdt_find_and_setprop(blob, "reg_can_xcvr", "status",
360                                         xcvr_status, strlen(xcvr_status) + 1, 1);
361                 if (ret)
362                         printf("Failed to disable CAN transceiver switch: %s\n",
363                                 fdt_strerror(ret));
364         }
365 }
366
367 void karo_fdt_del_prop(void *blob, const char *compat, phys_addr_t offs,
368                         const char *prop)
369 {
370         int ret;
371         int offset;
372         const uint32_t *phandle;
373         uint32_t ph = 0;
374
375         offset = fdt_node_offset_by_compat_reg(blob, compat, offs);
376         if (offset <= 0)
377                 return;
378
379         phandle = fdt_getprop(blob, offset, prop, NULL);
380         if (phandle) {
381                 ph = fdt32_to_cpu(*phandle);
382         }
383
384         debug("Removing property '%s' from node %s@%08lx\n", prop, compat, offs);
385         ret = fdt_delprop(blob, offset, prop);
386         if (ret == 0)
387                 karo_set_fdtsize(blob);
388
389         if (!ph)
390                 return;
391
392         offset = fdt_node_offset_by_phandle(blob, ph);
393         if (offset <= 0)
394                 return;
395
396         debug("Removing node @ %08x\n", offset);
397         fdt_del_node(blob, offset);
398         karo_set_fdtsize(blob);
399 }
400
401 static int fdt_init_fb_mode(const void *blob, int off, struct fb_videomode *fb_mode)
402 {
403         const uint32_t *prop;
404
405         memset(fb_mode, 0, sizeof(*fb_mode));
406
407         prop = fdt_getprop(blob, off, "clock-frequency", NULL);
408         if (prop)
409                 fb_mode->pixclock = KHZ2PICOS(fdt32_to_cpu(*prop) / 1000);
410
411         prop = fdt_getprop(blob, off, "hactive", NULL);
412         if (prop)
413                 fb_mode->xres = fdt32_to_cpu(*prop);
414
415         prop = fdt_getprop(blob, off, "vactive", NULL);
416         if (prop)
417                 fb_mode->yres = fdt32_to_cpu(*prop);
418
419         prop = fdt_getprop(blob, off, "hback-porch", NULL);
420         if (prop)
421                 fb_mode->left_margin = fdt32_to_cpu(*prop);
422
423         prop = fdt_getprop(blob, off, "hsync-len", NULL);
424         if (prop)
425                 fb_mode->hsync_len = fdt32_to_cpu(*prop);
426
427         prop = fdt_getprop(blob, off, "hfront-porch", NULL);
428         if (prop)
429                 fb_mode->right_margin = fdt32_to_cpu(*prop);
430
431         prop = fdt_getprop(blob, off, "vback-porch", NULL);
432         if (prop)
433                 fb_mode->upper_margin = fdt32_to_cpu(*prop);
434
435         prop = fdt_getprop(blob, off, "vsync-len", NULL);
436         if (prop)
437                 fb_mode->vsync_len = fdt32_to_cpu(*prop);
438
439         prop = fdt_getprop(blob, off, "vfront-porch", NULL);
440         if (prop)
441                 fb_mode->lower_margin = fdt32_to_cpu(*prop);
442
443         prop = fdt_getprop(blob, off, "hsync-active", NULL);
444         if (prop)
445                 fb_mode->sync |= *prop ? FB_SYNC_VERT_HIGH_ACT : 0;
446
447         prop = fdt_getprop(blob, off, "vsync-active", NULL);
448         if (prop)
449                 fb_mode->sync |= *prop ? FB_SYNC_VERT_HIGH_ACT : 0;
450
451         prop = fdt_getprop(blob, off, "de-active", NULL);
452         if (prop)
453                 fb_mode->sync |= *prop ? 0 : FB_SYNC_OE_LOW_ACT;
454
455         prop = fdt_getprop(blob, off, "pixelclk-active", NULL);
456         if (prop)
457                 fb_mode->sync |= *prop ? 0 : FB_SYNC_CLK_LAT_FALL;
458
459         return 0;
460 }
461
462 static int fdt_update_native_fb_mode(void *blob, int off)
463 {
464         int ret;
465         uint32_t ph;
466
467         ret = fdt_increase_size(blob, 64);
468         if (ret) {
469                 printf("Warning: Failed to increase FDT size: %s\n",
470                         fdt_strerror(ret));
471         }
472         debug("Creating phandle at offset %d\n", off);
473         ph = fdt_create_phandle(blob, off);
474         if (!ph) {
475                 printf("Failed to create phandle for video timing\n");
476                 return -ENOMEM;
477         }
478
479         debug("phandle of %s @ %06x=%04x\n", fdt_get_name(blob, off, NULL),
480                 off, ph);
481         off = fdt_parent_offset(blob, off);
482         if (off < 0)
483                 return off;
484         debug("parent offset=%06x\n", off);
485         ret = fdt_setprop_cell(blob, off, "native-mode", ph);
486         if (ret)
487                 printf("Failed to set property 'native-mode': %s\n",
488                         fdt_strerror(ret));
489         karo_set_fdtsize(blob);
490         return ret;
491 }
492
493 static int karo_fdt_find_video_timings(void *blob)
494 {
495         int off = fdt_path_offset(blob, "display");
496         const char *subnode = "display-timings";
497
498         if (off < 0) {
499                 debug("Could not find node 'display' in FDT: %s\n",
500                         fdt_strerror(off));
501                 return off;
502         }
503
504         off = fdt_subnode_offset(blob, off, subnode);
505         if (off < 0) {
506                 debug("Could not find node '%s' in FDT: %s\n", subnode,
507                         fdt_strerror(off));
508         }
509         return off;
510 }
511
512 int karo_fdt_get_fb_mode(void *blob, const char *name, struct fb_videomode *fb_mode)
513 {
514         int off = karo_fdt_find_video_timings(blob);
515
516         if (off < 0)
517                 return off;
518         while (off > 0) {
519                 const char *n, *endp;
520                 int len, d = 1;
521
522                 off = fdt_next_node(blob, off, &d);
523                 if (off < 0)
524                         return off;
525                 if (d < 1)
526                         return -EINVAL;
527                 if (d > 2) {
528                         debug("Skipping node @ %04x %s depth %d\n", off,
529                                 fdt_get_name(blob, off, NULL), d);
530                         continue;
531                 }
532                 debug("parsing subnode @ %04x %s depth %d\n", off,
533                         fdt_get_name(blob, off, NULL), d);
534
535                 n = fdt_getprop(blob, off, "panel-name", &len);
536                 if (!n) {
537                         n = fdt_get_name(blob, off, NULL);
538                         if (strcasecmp(n, name) == 0) {
539                                 break;
540                         }
541                 } else {
542                         int found = 0;
543
544                         for (endp = n + len; n < endp; n += strlen(n) + 1) {
545                                 debug("Checking panel-name '%s'\n", n);
546                                 if (strcasecmp(n, name) == 0) {
547                                         debug("Using node %s @ %04x\n",
548                                                 fdt_get_name(blob, off, NULL), off);
549                                         found = 1;
550                                         break;
551                                 }
552                         }
553                         if (found)
554                                 break;
555                 }
556         }
557         if (off > 0) {
558                 return fdt_init_fb_mode(blob, off, fb_mode);
559         }
560         return -EINVAL;
561 }
562
563 #define SET_FB_PROP(n, v) ({                                            \
564         int ret;                                                        \
565         ret = fdt_setprop_u32(blob, off, n, v);                         \
566         if (ret) {                                                      \
567                 printf("Failed to set property %s: %s\n", name,         \
568                         fdt_strerror(ret));                             \
569         }                                                               \
570         ret;                                                            \
571 })
572
573
574 int karo_fdt_create_fb_mode(void *blob, const char *name,
575                         struct fb_videomode *fb_mode)
576 {
577         int off = fdt_path_offset(blob, "display");
578         int ret;
579         const char *subnode = "display-timings";
580
581         if (off < 0) {
582                 printf("'display' node not found in FDT\n");
583                 return off;
584         }
585
586         ret = fdt_increase_size(blob, 512);
587         if (ret) {
588                 printf("Failed to increase FDT size: %s\n", fdt_strerror(ret));
589                 return ret;
590         }
591
592         ret = fdt_subnode_offset(blob, off, subnode);
593         if (ret < 0) {
594                 debug("Could not find node '%s' in FDT: %s\n", subnode,
595                         fdt_strerror(ret));
596                 ret = fdt_add_subnode(blob, off, subnode);
597                 if (ret < 0) {
598                         printf("Failed to add %s subnode: %s\n", subnode,
599                                 fdt_strerror(ret));
600                         return ret;
601                 }
602         }
603
604         ret = fdt_add_subnode(blob, ret, name);
605         if (ret < 0) {
606                 printf("Failed to add %s subnode: %s\n", name,
607                         fdt_strerror(ret));
608                 return ret;
609         }
610         off = ret;
611
612         ret = SET_FB_PROP("clock-frequency",
613                         PICOS2KHZ(fb_mode->pixclock) * 1000);
614         if (ret)
615                 goto out;
616         ret = SET_FB_PROP("hactive", fb_mode->xres);
617         if (ret)
618                 goto out;
619         ret = SET_FB_PROP("vactive", fb_mode->yres);
620         if (ret)
621                 goto out;
622         ret = SET_FB_PROP("hback-porch", fb_mode->left_margin);
623         if (ret)
624                 goto out;
625         ret = SET_FB_PROP("hsync-len", fb_mode->hsync_len);
626         if (ret)
627                 goto out;
628         ret = SET_FB_PROP("hfront-porch", fb_mode->right_margin);
629         if (ret)
630                 goto out;
631         ret = SET_FB_PROP("vback-porch", fb_mode->upper_margin);
632         if (ret)
633                 goto out;
634         ret = SET_FB_PROP("vsync-len", fb_mode->vsync_len);
635         if (ret)
636                 goto out;
637         ret = SET_FB_PROP("vfront-porch", fb_mode->lower_margin);
638         if (ret)
639                 goto out;
640         ret = SET_FB_PROP("hsync-active",
641                         fb_mode->sync & FB_SYNC_VERT_HIGH_ACT ? 1 : 0);
642         if (ret)
643                 goto out;
644         ret = SET_FB_PROP("vsync-active",
645                         fb_mode->sync & FB_SYNC_VERT_HIGH_ACT ? 1 : 0);
646         if (ret)
647                 goto out;
648         ret = SET_FB_PROP("de-active",
649                         !(fb_mode->sync & FB_SYNC_OE_LOW_ACT));
650         if (ret)
651                 goto out;
652         ret = SET_FB_PROP("pixelclk-active",
653                         !(fb_mode->sync & FB_SYNC_CLK_LAT_FALL));
654 out:
655         karo_set_fdtsize(blob);
656         return ret;
657 }
658
659 int karo_fdt_update_fb_mode(void *blob, const char *name)
660 {
661         int off = fdt_path_offset(blob, "display");
662         const char *subnode = "display-timings";
663
664         if (off < 0)
665                 return off;
666
667         if (name == NULL) {
668                 int ret;
669
670                 debug("Disabling node '%s' at %03x\n",
671                         fdt_get_name(blob, off, NULL), off);
672                 ret = fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0);
673                 return ret;
674         }
675
676         off = fdt_subnode_offset(blob, off, subnode);
677         if (off < 0) {
678                 debug("Could not find node '%s' in FDT: %s\n", subnode,
679                         fdt_strerror(off));
680                 return off;
681         }
682         while (off > 0) {
683                 const char *n, *endp;
684                 int len, d = 1;
685
686                 off = fdt_next_node(blob, off, &d);
687                 if (off < 0)
688                         return off;
689                 if (d < 1)
690                         return -EINVAL;
691                 if (d > 2) {
692                         debug("Skipping node @ %04x %s depth %d\n", off,
693                                 fdt_get_name(blob, off, NULL), d);
694                         continue;
695                 }
696                 debug("parsing subnode @ %04x %s depth %d\n", off,
697                         fdt_get_name(blob, off, NULL), d);
698
699                 n = fdt_getprop(blob, off, "panel-name", &len);
700                 if (!n) {
701                         n = fdt_get_name(blob, off, NULL);
702                         if (strcasecmp(n, name) == 0) {
703                                 break;
704                         }
705                 } else {
706                         int found = 0;
707
708                         for (endp = n + len; n < endp; n += strlen(n) + 1) {
709                                 debug("Checking panel-name '%s'\n", n);
710                                 if (strcasecmp(n, name) == 0) {
711                                         debug("Using node %s @ %04x\n",
712                                                 fdt_get_name(blob, off, NULL), off);
713                                         found = 1;
714                                         break;
715                                 }
716                         }
717                         if (found)
718                                 break;
719                 }
720         }
721         if (off > 0)
722                 return fdt_update_native_fb_mode(blob, off);
723         return off;
724 }
725
726 int karo_fdt_get_lcd_bus_width(const void *blob, int default_width)
727 {
728         int off = fdt_path_offset(blob, "display");
729
730         if (off >= 0) {
731                 const uint32_t *prop;
732
733                 prop = fdt_getprop(blob, off, "fsl,data-width", NULL);
734                 if (prop)
735                         return fdt32_to_cpu(*prop);
736         }
737         return default_width;
738 }
739
740 int karo_fdt_get_lvds_mapping(const void *blob, int default_mapping)
741 {
742         int off = fdt_path_offset(blob, "display");
743
744         if (off >= 0) {
745                 const char *prop;
746
747                 prop = fdt_getprop(blob, off, "fsl,data-mapping", NULL);
748                 if (prop)
749                         return strcmp(prop, "jeida") == 0;
750         }
751         return default_mapping;
752 }
753
754 u8 karo_fdt_get_lvds_channels(const void *blob)
755 {
756         static const char *lvds_chans[] = {
757                 "lvds0",
758                 "lvds1",
759         };
760         u8 lvds_chan_mask = 0;
761         int i;
762
763         for (i = 0; i < ARRAY_SIZE(lvds_chans); i++) {
764                 const char *status;
765                 int off = fdt_path_offset(blob, lvds_chans[i]);
766
767                 if (off < 0)
768                         continue;
769
770                 status = fdt_getprop(blob, off, "status", NULL);
771                 if (status && strcmp(status, "okay") == 0) {
772                         debug("%s is enabled\n", lvds_chans[i]);
773                         lvds_chan_mask |= 1 << i;
774                 }
775         }
776         return lvds_chan_mask;
777 }