]> git.sur5r.net Git - u-boot/commitdiff
board/BuR/common: simplify access to devicetree
authorHannes Petermaier <oe5hpm@oevsv.at>
Wed, 8 Apr 2015 05:38:33 +0000 (07:38 +0200)
committerTom Rini <trini@konsulko.com>
Thu, 23 Apr 2015 12:52:22 +0000 (08:52 -0400)
instead of polling everytime the environment, we take usage of the global
gd->fdt_blob variable and check it only against NULL.

Variable "dtbaddr" from environment is needed only one time on loading the
devicetree within "load_devicetree()"

Signed-off-by: Hannes Petermaier <oe5hpm@oevsv.at>
board/BuR/common/common.c

index 13f23fd7cec2c9c1da25f0c9c0ae0ec23760eacc..e85064a6774707c630e2e182b928e914a9e8f5a7 100644 (file)
@@ -39,7 +39,7 @@ static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
 DECLARE_GLOBAL_DATA_PTR;
 
 #ifdef CONFIG_USE_FDT
-  #define FDTPROP(a, b, c) fdt_getprop_u32_default((void *)a, b, c, ~0UL)
+  #define FDTPROP(b, c) fdt_getprop_u32_default(gd->fdt_blob, b, c, ~0UL)
   #define PATHTIM "/panel/display-timings/default"
   #define PATHINF "/panel/panel-info"
 #endif
@@ -50,51 +50,50 @@ int load_lcdtiming(struct am335x_lcdpanel *panel)
 {
        struct am335x_lcdpanel pnltmp;
 #ifdef CONFIG_USE_FDT
-       u32 dtbaddr = getenv_ulong("dtbaddr", 16, ~0UL);
        u32 dtbprop;
 
-       if (dtbaddr == ~0UL) {
-               puts("load_lcdtiming: failed to get 'dtbaddr' from env!\n");
+       if (gd->fdt_blob == NULL) {
+               printf("%s: don't have a valid gd->fdt_blob!\n", __func__);
                return -1;
        }
        memcpy(&pnltmp, (void *)panel, sizeof(struct am335x_lcdpanel));
 
-       pnltmp.hactive = FDTPROP(dtbaddr, PATHTIM, "hactive");
-       pnltmp.vactive = FDTPROP(dtbaddr, PATHTIM, "vactive");
-       pnltmp.bpp = FDTPROP(dtbaddr, PATHINF, "bpp");
-       pnltmp.hfp = FDTPROP(dtbaddr, PATHTIM, "hfront-porch");
-       pnltmp.hbp = FDTPROP(dtbaddr, PATHTIM, "hback-porch");
-       pnltmp.hsw = FDTPROP(dtbaddr, PATHTIM, "hsync-len");
-       pnltmp.vfp = FDTPROP(dtbaddr, PATHTIM, "vfront-porch");
-       pnltmp.vbp = FDTPROP(dtbaddr, PATHTIM, "vback-porch");
-       pnltmp.vsw = FDTPROP(dtbaddr, PATHTIM, "vsync-len");
-       pnltmp.pup_delay = FDTPROP(dtbaddr, PATHTIM, "pupdelay");
-       pnltmp.pon_delay = FDTPROP(dtbaddr, PATHTIM, "pondelay");
+       pnltmp.hactive = FDTPROP(PATHTIM, "hactive");
+       pnltmp.vactive = FDTPROP(PATHTIM, "vactive");
+       pnltmp.bpp = FDTPROP(PATHINF, "bpp");
+       pnltmp.hfp = FDTPROP(PATHTIM, "hfront-porch");
+       pnltmp.hbp = FDTPROP(PATHTIM, "hback-porch");
+       pnltmp.hsw = FDTPROP(PATHTIM, "hsync-len");
+       pnltmp.vfp = FDTPROP(PATHTIM, "vfront-porch");
+       pnltmp.vbp = FDTPROP(PATHTIM, "vback-porch");
+       pnltmp.vsw = FDTPROP(PATHTIM, "vsync-len");
+       pnltmp.pup_delay = FDTPROP(PATHTIM, "pupdelay");
+       pnltmp.pon_delay = FDTPROP(PATHTIM, "pondelay");
 
        /* calc. proper clk-divisor */
-       dtbprop = FDTPROP(dtbaddr, PATHTIM, "clock-frequency");
+       dtbprop = FDTPROP(PATHTIM, "clock-frequency");
        if (dtbprop != ~0UL)
                pnltmp.pxl_clk_div = 192000000 / dtbprop;
        else
                pnltmp.pxl_clk_div = ~0UL;
 
        /* check polarity of control-signals */
-       dtbprop = FDTPROP(dtbaddr, PATHTIM, "hsync-active");
+       dtbprop = FDTPROP(PATHTIM, "hsync-active");
        if (dtbprop == 0)
                pnltmp.pol |= HSYNC_INVERT;
-       dtbprop = FDTPROP(dtbaddr, PATHTIM, "vsync-active");
+       dtbprop = FDTPROP(PATHTIM, "vsync-active");
        if (dtbprop == 0)
                pnltmp.pol |= VSYNC_INVERT;
-       dtbprop = FDTPROP(dtbaddr, PATHINF, "sync-ctrl");
+       dtbprop = FDTPROP(PATHINF, "sync-ctrl");
        if (dtbprop == 1)
                pnltmp.pol |= HSVS_CONTROL;
-       dtbprop = FDTPROP(dtbaddr, PATHINF, "sync-edge");
+       dtbprop = FDTPROP(PATHINF, "sync-edge");
        if (dtbprop == 1)
                pnltmp.pol |= HSVS_RISEFALL;
-       dtbprop = FDTPROP(dtbaddr, PATHTIM, "pixelclk-active");
+       dtbprop = FDTPROP(PATHTIM, "pixelclk-active");
        if (dtbprop == 0)
                pnltmp.pol |= PXCLK_INVERT;
-       dtbprop = FDTPROP(dtbaddr, PATHTIM, "de-active");
+       dtbprop = FDTPROP(PATHTIM, "de-active");
        if (dtbprop == 0)
                pnltmp.pol |= DE_INVERT;
 #else
@@ -163,11 +162,16 @@ static int load_devicetree(void)
        char *dtbname = getenv("dtb");
        char *dtbdev = getenv("dtbdev");
        char *dtppart = getenv("dtbpart");
-       u32 dtbaddr = getenv_ulong("dtbaddr", 16, ~0UL);
+       u32 dtbaddr = getenv_ulong("dtbaddr", 16, 0UL);
+       int rc;
        loff_t dtbsize;
 
-       if (!dtbdev || !dtbdev) {
-               puts("load_devicetree: <dtbdev>/<dtbpart> missing.\n");
+       if (dtbaddr == 0) {
+               printf("%s: don't have a valid <dtbaddr> in env!\n", __func__);
+               return -1;
+       }
+       if (!dtbdev || !dtbdev || !dtbname) {
+               printf("%s: <dtbdev>/<dtbpart>/<dtb> missing.\n", __func__);
                return -1;
        }
 
@@ -175,18 +179,16 @@ static int load_devicetree(void)
                puts("load_devicetree: set_blk_dev failed.\n");
                return -1;
        }
-       if (dtbname && dtbaddr != ~0UL) {
-               if (fs_read(dtbname, dtbaddr, 0, 0, &dtbsize) == 0) {
-                       gd->fdt_blob = (void *)dtbaddr;
-                       gd->fdt_size = dtbsize;
-                       debug("loaded %d bytes of dtb onto 0x%08x\n",
-                             (u32)dtbsize, dtbaddr);
-                       return dtbsize;
-               }
-               puts("load_devicetree: load dtb failed,file does not exist!\n");
+       rc = fs_read(dtbname, (u32)dtbaddr, 0, 0, &dtbsize);
+       if (rc == 0) {
+               gd->fdt_blob = (void *)dtbaddr;
+               gd->fdt_size = dtbsize;
+               debug("loaded %d bytes of dtb onto 0x%08x\n",
+                     (u32)dtbsize, (u32)gd->fdt_blob);
+               return dtbsize;
        }
 
-       puts("load_devicetree: <dtb>/<dtbaddr> missing!\n");
+       printf("%s: load dtb failed!\n", __func__);
        return -1;
 }
 
@@ -196,26 +198,25 @@ static const char *dtbmacaddr(u32 ifno)
        char enet[16];
        const char *mac;
        const char *path;
-       u32 dtbaddr = getenv_ulong("dtbaddr", 16, ~0UL);
 
-       if (dtbaddr == ~0UL) {
-               puts("dtbmacaddr: failed to get 'dtbaddr' from env!\n");
+       if (gd->fdt_blob == NULL) {
+               printf("%s: don't have a valid gd->fdt_blob!\n", __func__);
                return NULL;
        }
 
-       node = fdt_path_offset((void *)dtbaddr, "/aliases");
+       node = fdt_path_offset(gd->fdt_blob, "/aliases");
        if (node < 0)
                return NULL;
 
        sprintf(enet, "ethernet%d", ifno);
-       path = fdt_getprop((void *)dtbaddr, node, enet, NULL);
+       path = fdt_getprop(gd->fdt_blob, node, enet, NULL);
        if (!path) {
                printf("no alias for %s\n", enet);
                return NULL;
        }
 
-       node = fdt_path_offset((void *)dtbaddr, path);
-       mac = fdt_getprop((void *)dtbaddr, node, "mac-address", &len);
+       node = fdt_path_offset(gd->fdt_blob, path);
+       mac = fdt_getprop(gd->fdt_blob, node, "mac-address", &len);
        if (mac && is_valid_ethaddr((u8 *)mac))
                return mac;
 
@@ -226,15 +227,14 @@ static void br_summaryscreen_printdtb(char *prefix,
                                       char *name,
                                       char *suffix)
 {
-       u32 dtbaddr = getenv_ulong("dtbaddr", 16, ~0UL);
        char buf[32] = { 0 };
        const char *nodep = buf;
        char *mac = 0;
        int nodeoffset;
        int len;
 
-       if (dtbaddr == ~0UL) {
-               puts("br_summaryscreen: failed to get 'dtbaddr' from env!\n");
+       if (gd->fdt_blob == NULL) {
+               printf("%s: don't have a valid gd->fdt_blob!\n", __func__);
                return;
        }
 
@@ -247,13 +247,13 @@ static void br_summaryscreen_printdtb(char *prefix,
                if (mac)
                        sprintf(buf, "%pM", mac);
        } else {
-               nodeoffset = fdt_path_offset((void *)dtbaddr,
+               nodeoffset = fdt_path_offset(gd->fdt_blob,
                                             "/factory-settings");
                if (nodeoffset < 0) {
                        puts("no 'factory-settings' in dtb!\n");
                        return;
                }
-               nodep = fdt_getprop((void *)dtbaddr, nodeoffset, name, &len);
+               nodep = fdt_getprop(gd->fdt_blob, nodeoffset, name, &len);
        }
        if (nodep && strlen(nodep) > 1)
                lcd_printf("%s %s %s", prefix, nodep, suffix);
@@ -318,13 +318,11 @@ void lcdpower(int on)
 {
        u32 pin, swval, i;
 #ifdef CONFIG_USE_FDT
-       u32 dtbaddr = getenv_ulong("dtbaddr", 16, ~0UL);
-
-       if (dtbaddr == ~0UL) {
-               puts("lcdpower: failed to get 'dtbaddr' from env!\n");
+       if (gd->fdt_blob == NULL) {
+               printf("%s: don't have a valid gd->fdt_blob!\n", __func__);
                return;
        }
-       pin = FDTPROP(dtbaddr, PATHINF, "pwrpin");
+       pin = FDTPROP(PATHINF, "pwrpin");
 #else
        pin = getenv_ulong("ds1_pwr", 16, ~0UL);
 #endif
@@ -385,15 +383,13 @@ void lcd_ctrl_init(void *lcdbase)
 void lcd_enable(void)
 {
 #ifdef CONFIG_USE_FDT
-       u32 dtbaddr = getenv_ulong("dtbaddr", 16, ~0UL);
-
-       if (dtbaddr == ~0UL) {
-               puts("lcdpower: failed to get 'dtbaddr' from env!\n");
+       if (gd->fdt_blob == NULL) {
+               printf("%s: don't have a valid gd->fdt_blob!\n", __func__);
                return;
        }
-       unsigned int driver = FDTPROP(dtbaddr, PATHINF, "brightdrv");
-       unsigned int bright = FDTPROP(dtbaddr, PATHINF, "brightdef");
-       unsigned int pwmfrq = FDTPROP(dtbaddr, PATHINF, "brightfdim");
+       unsigned int driver = FDTPROP(PATHINF, "brightdrv");
+       unsigned int bright = FDTPROP(PATHINF, "brightdef");
+       unsigned int pwmfrq = FDTPROP(PATHINF, "brightfdim");
 #else
        unsigned int driver = getenv_ulong("ds1_bright_drv", 16, 0UL);
        unsigned int bright = getenv_ulong("ds1_bright_def", 10, 50);