1 /* 2 * Copyright (c) 2017 Google, Inc 3 * Written by Simon Glass <sjg@chromium.org> 4 * 5 * SPDX-License-Identifier: GPL-2.0+ 6 */ 7 8 #include <common.h> 9 #include <dm.h> 10 #include <dm/of_addr.h> 11 #include <dm/read.h> 12 #include <linux/ioport.h> 13 14 int dev_read_resource(struct udevice *dev, uint index, struct resource *res) 15 { 16 ofnode node = dev_ofnode(dev); 17 18 #ifdef CONFIG_OF_LIVE 19 if (ofnode_is_np(node)) { 20 return of_address_to_resource(ofnode_to_np(node), index, res); 21 } else 22 #endif 23 { 24 struct fdt_resource fres; 25 int ret; 26 27 ret = fdt_get_resource(gd->fdt_blob, ofnode_to_offset(node), 28 "reg", index, &fres); 29 if (ret < 0) 30 return -EINVAL; 31 memset(res, '\0', sizeof(*res)); 32 res->start = fres.start; 33 res->end = fres.end; 34 35 return 0; 36 } 37 } 38