From a44810123f9ef069587beacdce7d6f488cf42973 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 12 Jun 2017 06:21:29 -0600 Subject: dm: core: Add dev_read_resource() to read device resources Add a function which reads resources from a device, such as the device hardware address. This uses the "reg" property in the device. Unlike other functions there is little sense in inlining this when livetree is not being used because it has some logic in it and this would just bloat the code size. Signed-off-by: Simon Glass Tested-by: Marcel Ziswiler Tested-on: Beaver, Jetson-TK1 --- drivers/core/Makefile | 2 +- drivers/core/read_extra.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 drivers/core/read_extra.c (limited to 'drivers/core') diff --git a/drivers/core/Makefile b/drivers/core/Makefile index 435cf98ae1..fd2d4de0c8 100644 --- a/drivers/core/Makefile +++ b/drivers/core/Makefile @@ -15,4 +15,4 @@ obj-$(CONFIG_OF_LIVE) += of_access.o of_addr.o ifndef CONFIG_DM_DEV_READ_INLINE obj-$(CONFIG_OF_CONTROL) += read.o endif -obj-$(CONFIG_OF_CONTROL) += of_extra.o ofnode.o +obj-$(CONFIG_OF_CONTROL) += of_extra.o ofnode.o read_extra.o diff --git a/drivers/core/read_extra.c b/drivers/core/read_extra.c new file mode 100644 index 0000000000..a6d2f342d9 --- /dev/null +++ b/drivers/core/read_extra.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2017 Google, Inc + * Written by Simon Glass + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include +#include + +int dev_read_resource(struct udevice *dev, uint index, struct resource *res) +{ + ofnode node = dev_ofnode(dev); + +#ifdef CONFIG_OF_LIVE + if (ofnode_is_np(node)) { + return of_address_to_resource(ofnode_to_np(node), index, res); + } else +#endif + { + struct fdt_resource fres; + int ret; + + ret = fdt_get_resource(gd->fdt_blob, ofnode_to_offset(node), + "reg", index, &fres); + if (ret < 0) + return -EINVAL; + memset(res, '\0', sizeof(*res)); + res->start = fres.start; + res->end = fres.end; + + return 0; + } +} -- cgit v1.2.3