53 lines
929 B
C
53 lines
929 B
C
|
/*
|
||
|
* (C) Copyright 2007-2012
|
||
|
* Allwinner Technology Co., Ltd. <www.allwinnertech.com>
|
||
|
* Tom weidonghui <weidonghui@allwinnertech.com>
|
||
|
*/
|
||
|
|
||
|
#include "libfdt_env.h"
|
||
|
|
||
|
#include <fdt.h>
|
||
|
#include <libfdt.h>
|
||
|
|
||
|
#include "libfdt_internal.h"
|
||
|
|
||
|
int fdt_address_cells(const void *fdt, int nodeoffset)
|
||
|
{
|
||
|
const fdt32_t *ac;
|
||
|
int val;
|
||
|
int len;
|
||
|
|
||
|
ac = fdt_getprop(fdt, nodeoffset, "#address-cells", &len);
|
||
|
if (!ac)
|
||
|
return 2;
|
||
|
|
||
|
if (len != sizeof(*ac))
|
||
|
return -FDT_ERR_BADNCELLS;
|
||
|
|
||
|
val = fdt32_to_cpu(*ac);
|
||
|
if ((val <= 0) || (val > FDT_MAX_NCELLS))
|
||
|
return -FDT_ERR_BADNCELLS;
|
||
|
|
||
|
return val;
|
||
|
}
|
||
|
|
||
|
int fdt_size_cells(const void *fdt, int nodeoffset)
|
||
|
{
|
||
|
const fdt32_t *sc;
|
||
|
int val;
|
||
|
int len;
|
||
|
|
||
|
sc = fdt_getprop(fdt, nodeoffset, "#size-cells", &len);
|
||
|
if (!sc)
|
||
|
return 2;
|
||
|
|
||
|
if (len != sizeof(*sc))
|
||
|
return -FDT_ERR_BADNCELLS;
|
||
|
|
||
|
val = fdt32_to_cpu(*sc);
|
||
|
if ((val < 0) || (val > FDT_MAX_NCELLS))
|
||
|
return -FDT_ERR_BADNCELLS;
|
||
|
|
||
|
return val;
|
||
|
}
|