9
0
Fork 0

Merge branch 'for-next/of'

Conflicts:
	drivers/of/base.c
	include/of.h
This commit is contained in:
Sascha Hauer 2012-11-16 14:02:44 +01:00
commit 05d251f15f
5 changed files with 110 additions and 8 deletions

View File

@ -113,15 +113,15 @@ void *sbrk(ptrdiff_t increment)
LIST_HEAD(memory_banks);
void barebox_add_memory_bank(const char *name, resource_size_t start,
int barebox_add_memory_bank(const char *name, resource_size_t start,
resource_size_t size)
{
struct memory_bank *bank = xzalloc(sizeof(*bank));
struct device_d *dev;
bank->res = request_iomem_region(name, start, start + size - 1);
BUG_ON(!bank->res);
if (!bank->res)
return -EBUSY;
dev = add_mem_device(name, start, size, IORESOURCE_MEM_WRITEABLE);
@ -130,6 +130,8 @@ void barebox_add_memory_bank(const char *name, resource_size_t start,
bank->size = size;
list_add_tail(&bank->list, &memory_banks);
return 0;
}
/*

View File

@ -1,6 +1,7 @@
#include <common.h>
#include <generated/compile.h>
#include <generated/utsrelease.h>
#include <of.h>
const char version_string[] =
"barebox " UTS_RELEASE " " UTS_VERSION "\n";
@ -8,7 +9,13 @@ EXPORT_SYMBOL(version_string);
void barebox_banner (void)
{
printf("\n\n%s\n\n", version_string);
printf("Board: " CONFIG_BOARDINFO "\n");
}
const char *board;
board = of_get_model();
if (!board)
board = CONFIG_BOARDINFO;
printf("\n\n%s\n\n", version_string);
printf("Board: %s\n", board);
}

View File

@ -23,6 +23,7 @@
#include <libfdt.h>
#include <malloc.h>
#include <init.h>
#include <memory.h>
#include <linux/ctype.h>
/**
@ -492,6 +493,36 @@ struct device_node *of_find_node_by_path(const char *path)
}
EXPORT_SYMBOL(of_find_node_by_path);
/**
* of_property_read_string - Find and read a string from a property
* @np: device node from which the property value is to be read.
* @propname: name of the property to be searched.
* @out_string: pointer to null terminated return string, modified only if
* return value is 0.
*
* Search for a property in a device tree node and retrieve a null
* terminated string value (pointer to data, not a copy). Returns 0 on
* success, -EINVAL if the property does not exist, -ENODATA if property
* does not have a value, and -EILSEQ if the string is not null-terminated
* within the length of the property data.
*
* The out_string pointer is modified only if a valid string can be decoded.
*/
int of_property_read_string(struct device_node *np, const char *propname,
const char **out_string)
{
struct property *prop = of_find_property(np, propname);
if (!prop)
return -EINVAL;
if (!prop->value)
return -ENODATA;
if (strnlen(prop->value, prop->length) >= prop->length)
return -EILSEQ;
*out_string = prop->value;
return 0;
}
EXPORT_SYMBOL_GPL(of_property_read_string);
struct device_node *of_get_root_node(void)
{
return root_node;
@ -615,9 +646,51 @@ static struct device_d *add_of_device(struct device_node *node)
}
EXPORT_SYMBOL(add_of_device);
u64 dt_mem_next_cell(int s, const __be32 **cellp)
{
const __be32 *p = *cellp;
*cellp = p + s;
return of_read_number(p, s);
}
static int of_add_memory(struct device_node *node)
{
int na, nc;
const __be32 *reg, *endp;
int len, r = 0;
static char str[6];
of_bus_count_cells(node, &na, &nc);
reg = of_get_property(node, "reg", &len);
if (!reg)
return 0;
endp = reg + (len / sizeof(__be32));
while ((endp - reg) >= (na + nc)) {
u64 base, size;
base = dt_mem_next_cell(na, &reg);
size = dt_mem_next_cell(nc, &reg);
if (size == 0)
continue;
sprintf(str, "ram%d", r);
barebox_add_memory_bank(str, base, size);
r++;
}
return 0;
}
static int add_of_device_resource(struct device_node *node)
{
struct property *reg;
struct property *reg, *type;
u64 address, size;
struct resource *res;
struct device_d *dev;
@ -630,6 +703,10 @@ static int add_of_device_resource(struct device_node *node)
list_add_tail(&node->phandles, &phandle_list);
}
type = of_find_property(node, "device_type");
if (type)
return of_add_memory(node);
reg = of_find_property(node, "reg");
if (!reg)
return -ENODEV;
@ -715,6 +792,12 @@ static void __of_probe(struct device_node *node)
}
struct device_node *of_chosen;
const char *of_model;
const char *of_get_model(void)
{
return of_model;
}
int of_probe(void)
{
@ -722,6 +805,7 @@ int of_probe(void)
return -ENODEV;
of_chosen = of_find_node_by_path("/chosen");
of_property_read_string(root_node, "model", &of_model);
__of_probe(root_node);

View File

@ -18,7 +18,7 @@ struct memory_bank {
extern struct list_head memory_banks;
void barebox_add_memory_bank(const char *name, resource_size_t start,
int barebox_add_memory_bank(const char *name, resource_size_t start,
resource_size_t size);
#define for_each_memory_bank(mem) list_for_each_entry(mem, &memory_banks, list)

View File

@ -108,6 +108,9 @@ void of_print_nodes(struct device_node *node, int indent);
int of_probe(void);
int of_parse_dtb(struct fdt_header *fdt);
int of_property_read_string(struct device_node *np, const char *propname,
const char **out_string);
#ifdef CONFIG_OFDEVICE
int of_parse_partitions(const char *cdevname,
struct device_node *node);
@ -115,6 +118,7 @@ int of_parse_partitions(const char *cdevname,
struct device_node *of_get_root_node(void);
int of_alias_get_id(struct device_node *np, const char *stem);
int of_device_is_stdout_path(struct device_d *dev);
const char *of_get_model(void);
#else
static inline int of_parse_partitions(const char *cdevname,
struct device_node *node)
@ -136,6 +140,11 @@ static inline int of_device_is_stdout_path(struct device_d *dev)
{
return 0;
}
static inline const char *of_get_model(void)
{
return NULL;
}
#endif
#endif /* __OF_H */